runs queue order manipulation and whitespace tightnening

This commit is contained in:
Abel Luck 2026-03-31 10:23:46 +02:00
parent a88eba7dd1
commit 99fd33f770
10 changed files with 478 additions and 121 deletions

View file

@ -1,17 +1,18 @@
from __future__ import annotations
from collections.abc import Mapping
import htpy as h
from htpy import Node, Renderable
def _button_classes(*, tone: str, emphasis: str, disabled: bool = False) -> str:
base = (
"inline-flex items-center justify-center rounded-full font-semibold transition "
)
base = "inline-flex shrink-0 items-center justify-center rounded-full font-semibold transition "
emphasis_classes = {
"compact": "px-3 py-1.5 text-sm",
"regular": "px-4 py-2.5 text-sm",
"soft": "px-3.5 py-2 text-sm",
"icon": "size-8 p-0",
}
tone_classes = {
"amber": "bg-amber-400 text-slate-950 hover:bg-amber-300",
@ -168,20 +169,24 @@ def inline_link(*, href: str, label: str, tone: str = "default") -> Renderable:
def action_button(
*,
label: str,
label: Node,
tone: str = "default",
emphasis: str = "compact",
disabled: bool = False,
button_type: str = "button",
post_path: str | None = None,
title: str | None = None,
) -> Renderable:
attributes: dict[str, str] = {}
if post_path is not None and not disabled:
attributes["data-on:pointerdown"] = f"@post('{post_path}')"
if title is not None:
attributes["aria-label"] = title
return h.button(
attributes,
type=button_type,
disabled=disabled,
title=title,
class_=_button_classes(tone=tone, emphasis=emphasis, disabled=disabled),
)[label]
@ -269,14 +274,24 @@ def table_section(
empty_message: str,
headers: tuple[str, ...],
rows: tuple[tuple[Node, ...], ...],
row_attrs: tuple[Mapping[str, str], ...] | None = None,
first_header_class: str | None = None,
first_cell_class: str | None = None,
actions: Node | None = None,
) -> Renderable:
def render_row(row: tuple[Node, ...]) -> Renderable:
def render_row(
row: tuple[Node, ...], attrs: Mapping[str, str] | None = None
) -> Renderable:
first_cell, *other_cells = row
return h.tr(class_="align-top")[
h.td(class_="py-3 pr-5 pl-3 text-sm font-medium text-slate-950 sm:pl-4")[
first_cell
],
row_attributes = dict(attrs or {})
row_attributes["class"] = f"align-top {row_attributes.get('class', '')}".strip()
return h.tr(row_attributes)[
h.td(
class_=(
first_cell_class
or "py-3 pr-5 pl-3 text-sm font-medium text-slate-950 sm:pl-4"
)
)[first_cell],
(
h.td(
class_="px-2.5 py-3 align-top text-sm whitespace-nowrap text-slate-600"
@ -287,7 +302,11 @@ def table_section(
body_rows: Node
if rows:
body_rows = (render_row(row) for row in rows)
row_attributes = row_attrs or tuple({} for _ in rows)
body_rows = (
render_row(row, attrs)
for row, attrs in zip(rows, row_attributes, strict=False)
)
else:
body_rows = h.tr[
h.td(
@ -322,9 +341,13 @@ def table_section(
(
h.th(
scope="col",
class_="px-2.5 py-2.5 text-left text-xs font-semibold uppercase tracking-[0.18em] whitespace-nowrap text-slate-500 first:pl-3 sm:first:pl-4",
class_=(
first_header_class
if index == 0 and first_header_class is not None
else "px-2.5 py-2.5 text-left text-xs font-semibold uppercase tracking-[0.18em] whitespace-nowrap text-slate-500 first:pl-3 sm:first:pl-4"
),
)[header]
for header in headers
for index, header in enumerate(headers)
)
]
],