refactor(web): controls, toggles and segments as utilities

look.ts builds each control's class list from its whole state, so no
two utilities fight over a property. The contextual overrides from rows,
trays, page heads and the removal panel become props.

Refs #280

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-11-11 17:40:50 +00:00
co-authored by Claude Opus 5.5
parent 288d4b26ad
commit e07db5a042
15 changed files with 277 additions and 408 deletions
+2 -1
View File
@@ -40,7 +40,8 @@ function walk(dir, out = []) {
}
const COLOR_LITERAL = /#[0-9a-fA-F]{3,8}\b|\b(?:oklch|oklab|lab|lch|rgba?|hsla?|hwb|color)\(/;
const RELATIVE_FROM_TOKEN = /\b(?:oklch|oklab|lab|lch|rgb|hsl|hwb|color)\(\s*from\s+var\(--/g;
// `_` is a space inside a Tailwind arbitrary value
const RELATIVE_FROM_TOKEN = /\b(?:oklch|oklab|lab|lch|rgb|hsl|hwb|color)\([\s_]*from[\s_]+var\(--/g;
const SPACING_PROP = /^(?:margin|padding|gap|row-gap|column-gap|inset)(?:-[a-z-]+)?$/;
const SPACING_VALUE = /^(?:var\(--[\w-]+\)|0|auto|-?[\d.]+%)$/;
const FONT_SIZE_VALUE = /^var\(--text-[\w-]+\)$/;
+6 -2
View File
@@ -16,6 +16,7 @@ import { LAYER, LiveContext, type Nav, NavContext, type TvDeckRequest, useEscape
import { type Download, fetchDownloads } from "./downloads";
import { type Probe, probeHealth } from "./health";
import { Icon, type IconName } from "./icons";
import { control, cx } from "./look";
import { two } from "./parts";
import {
currentRoute,
@@ -586,7 +587,7 @@ export function App() {
</span>
<button
type="button"
className="control control-icon flex-none ml-2 sm:hidden"
className={cx(control({ shape: "icon" }), "flex-none ml-2 sm:hidden")}
aria-label="close search"
onClick={() => {
setSearching(false);
@@ -598,7 +599,10 @@ export function App() {
</div>
<button
type="button"
className="control control-icon group-data-searching/rail:hidden sm:hidden"
className={cx(
control({ shape: "icon" }),
"group-data-searching/rail:hidden sm:hidden",
)}
aria-label="search"
onClick={openSearch}
>
+1 -354
View File
@@ -314,111 +314,7 @@ body {
color: var(--ink-faint);
}
/* ---- controls ------------------------------------------------------------- */
/* primary: cyan word on a raised plate — one per header or panel */
.control {
display: inline-flex;
align-items: center;
justify-content: center;
gap: var(--space-2);
min-height: var(--control-h);
padding: 0 var(--space-4);
font-family: var(--font-readout);
font-size: var(--text-xs);
font-weight: 600;
font-variant-numeric: tabular-nums;
line-height: 1;
text-transform: uppercase;
letter-spacing: 0.08em;
white-space: nowrap;
text-decoration: none;
color: var(--accent);
background: var(--panel-raised);
border: 1px solid var(--line-strong);
border-radius: var(--radius);
box-shadow: inset 0 1px var(--highlight);
cursor: pointer;
transition:
border-color 150ms var(--ease-out),
color 150ms var(--ease-out),
background 150ms var(--ease-out);
}
.control:hover:not(:disabled) {
border-color: var(--accent);
color: var(--accent-bright);
}
.control:active:not(:disabled) {
box-shadow: inset 0 1px var(--lowlight);
}
.control:disabled {
color: var(--ink-faint);
border-color: var(--line);
cursor: default;
}
.control[data-busy] {
color: var(--ink-faint);
border-style: dashed;
cursor: progress;
}
.control[data-done] {
color: var(--signal-ok);
border-color: oklch(from var(--signal-ok) l c h / 55%);
}
.control[data-failed] {
color: var(--signal-fault);
border-color: oklch(from var(--signal-fault) l c h / 55%);
}
/* quiet: secondary actions — cancel, add, back, retry. Never a toggle. */
.control-quiet {
color: var(--ink);
background: transparent;
border-color: var(--line);
box-shadow: none;
}
/* a word control whose label changes keeps one width */
.control-fixed {
min-width: var(--word-w);
}
/* icon: a square glyph, the accessible name carries the meaning */
.control-icon {
width: var(--control-h);
min-width: var(--control-h);
padding: 0;
}
.control[aria-expanded="true"] {
border-color: var(--accent);
color: var(--accent-bright);
}
/* destructive rests red, so delete never reads like the glyph beside it */
.control[data-kind="delete"]:not(:disabled) {
color: var(--signal-fault);
}
.control[data-kind="delete"]:hover:not(:disabled),
.control[data-kind="delete"]:focus-visible:not(:disabled) {
border-color: var(--signal-fault);
color: var(--signal-fault);
}
/* armed: the same square, now an amber check — the next tap fires */
.control[data-armed="true"]:not(:disabled),
.control[data-armed="true"]:hover:not(:disabled) {
color: var(--ground);
background: var(--signal-warn);
border-color: var(--signal-warn);
}
/* ---- glyphs ---------------------------------------------------------------- */
.icon {
display: block;
@@ -459,189 +355,6 @@ body {
letter-spacing: 0.06em;
}
/* the chip-scale delete (#251): no plate, the armed glyph does the word's job */
.control-micro {
display: inline-flex;
align-items: center;
justify-content: center;
width: 1rem;
height: 1rem;
padding: 0;
margin-inline-start: var(--space-1);
color: var(--ink-faint);
background: none;
border: 0;
border-radius: 2px;
cursor: pointer;
}
.control-micro .icon {
width: 0.75rem;
height: 0.75rem;
}
.control-micro:hover:not(:disabled),
.control-micro:focus-visible {
color: var(--signal-fault);
background: oklch(from var(--signal-fault) l c h / 15%);
}
.control-micro[data-armed="true"] {
color: var(--ground);
background: var(--signal-warn);
}
.control-micro:disabled {
opacity: 0.5;
}
/* disclosure: full control height, the chevron turns, the plate holds its width */
.disclose {
justify-content: space-between;
min-width: 9rem;
}
.disclose .icon {
transition: transform 200ms var(--ease-out);
}
.disclose[aria-expanded="true"] .icon {
transform: rotate(180deg);
}
/* lamp toggle: a rule that is on or off, lamp plus word */
.toggle {
display: inline-flex;
align-items: center;
gap: var(--space-2);
min-height: var(--control-h);
padding: 0 var(--space-3);
font-family: var(--font-readout);
font-size: var(--text-xs);
font-weight: 600;
line-height: 1;
text-transform: uppercase;
letter-spacing: 0.08em;
white-space: nowrap;
color: var(--ink-muted);
background: transparent;
border: 1px solid var(--line);
border-radius: var(--radius);
cursor: pointer;
transition:
border-color 150ms var(--ease-out),
color 150ms var(--ease-out);
}
.toggle:hover:not(:disabled) {
border-color: var(--accent);
}
.toggle:disabled {
cursor: progress;
opacity: 0.6;
}
.toggle-lamp {
width: 0.5rem;
height: 0.5rem;
flex: none;
border-radius: 50%;
background: var(--lamp-off);
transition:
background 300ms var(--ease-out),
box-shadow 300ms var(--ease-out);
}
.toggle-state {
min-width: 3ch;
margin-left: auto;
text-align: left;
color: var(--ink-faint);
}
.toggle[aria-pressed="true"] {
color: var(--ink);
border-color: var(--line-strong);
}
.toggle[aria-pressed="true"] .toggle-lamp {
background: var(--accent);
box-shadow: 0 0 6px oklch(from var(--accent) l c h / 60%);
}
.toggle[aria-pressed="true"] .toggle-state {
color: var(--accent);
}
/* segmented: one choice of a few, the engaged side lit */
.segmented {
display: inline-flex;
flex: none;
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}
.seg {
display: inline-flex;
align-items: center;
justify-content: center;
gap: var(--space-2);
min-height: var(--control-h);
padding: 0 var(--space-3);
font-family: var(--font-readout);
font-size: var(--text-xs);
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--ink-muted);
background: transparent;
border: 1px solid var(--line);
cursor: pointer;
transition:
border-color 150ms var(--ease-out),
color 150ms var(--ease-out);
}
.seg:first-child {
border-radius: var(--radius) 0 0 var(--radius);
}
.seg:last-child {
border-radius: 0 var(--radius) var(--radius) 0;
}
.seg + .seg {
border-left-width: 0;
}
.seg-icon {
width: var(--control-h);
padding: 0;
}
.seg:hover {
color: var(--accent-bright);
}
/* the lit edge is drawn inside, so the joined borders never double */
.seg[aria-pressed="true"] {
color: var(--accent-bright);
background: var(--panel-raised);
box-shadow: inset 0 0 0 1px var(--accent);
}
.filter-count {
color: var(--ink-faint);
font-variant-numeric: tabular-nums;
}
.seg[aria-pressed="true"] .filter-count {
color: var(--ink-muted);
}
/* ---- chips ---------------------------------------------------------------- */
/* a label, not a target: shorter than a control, one line always */
@@ -948,18 +661,10 @@ button.chip {
width: var(--toggle-w);
}
.r-slot[data-width="toggle"] > .toggle {
width: 100%;
}
.r-slot[data-width="word"] {
min-width: var(--word-w);
}
.r-slot[data-width="word"] > .control {
width: 100%;
}
.r-slot[data-wide] {
display: none;
}
@@ -1044,16 +749,6 @@ button.chip {
gap: var(--space-2);
}
.r-morepanel .control,
.r-morepanel .toggle {
width: 100%;
justify-content: flex-start;
}
.r-morepanel .control .icon {
margin-right: var(--space-1);
}
.r-empty {
display: flex;
align-items: center;
@@ -1141,13 +836,6 @@ button.chip {
}
/* season disclosure: the lead of a season row */
.r-lead .disclose-lead {
border-color: var(--line);
background: transparent;
box-shadow: none;
color: var(--ink-muted);
}
.disclose-lead .icon {
transition: transform 200ms var(--ease-out);
}
@@ -1514,13 +1202,6 @@ button.chip {
flex: 0 1 auto;
}
.page-head > .control-icon {
flex: none;
border-color: transparent;
background: transparent;
box-shadow: none;
}
.page-id {
display: grid;
min-width: 0;
@@ -1658,14 +1339,6 @@ button.chip {
min-width: 0;
}
.actionbar > .control-icon:last-child {
margin-left: auto;
}
.trailer-link .control-word {
display: none;
}
.more-panel {
display: grid;
gap: var(--space-3);
@@ -1692,12 +1365,6 @@ button.chip {
gap: var(--space-2);
}
.more-toggles .toggle,
.more-panel > .control {
width: 100%;
justify-content: flex-start;
}
.more-field {
display: grid;
}
@@ -1726,15 +1393,6 @@ button.chip {
font-size: var(--text-xl);
}
.trailer-link .control-word {
display: inline;
}
.trailer-link {
width: auto;
padding: 0 var(--space-4);
}
.more-panel {
grid-template-columns: repeat(2, minmax(0, 1fr));
align-items: end;
@@ -1805,11 +1463,6 @@ button.chip {
gap: var(--space-2);
}
.remove-body[data-armed="true"] .remove-actions .control:first-child:not(:disabled) {
color: var(--signal-warn);
border-color: oklch(from var(--signal-warn) l c h / 55%);
}
/* ---- release deck (§9.3) ------------------------------------------------- */
.buckets {
@@ -1943,12 +1596,6 @@ button.chip {
padding-top: var(--space-3);
}
.subs-langs {
display: flex;
flex-wrap: wrap;
gap: var(--space-1);
}
.subs-field {
flex: 1 1 12rem;
min-width: 9rem;
+8 -5
View File
@@ -3,6 +3,7 @@
import { type CSSProperties, type ReactNode, useEffect, useRef, useState } from "react";
import { Icon, ProviderMark, Star } from "./icons";
import { control } from "./look";
import { formatMetaLine, formatRating, formatVoteCount, tmdbImage } from "./movie";
import { type ActionOutcome, formatSize, totalSize } from "./releases";
import { cx, flag, IconControl, IconLink, type Note, NoteLine } from "./ui";
@@ -64,7 +65,7 @@ export function Hero({
data-bleed=""
>
<header className="page-head">
<IconControl glyph="back" label="back" onClick={onBack} />
<IconControl glyph="back" label="back" look="bare" onClick={onBack} />
<h2 className="page-title" tabIndex={-1} ref={heading}>
{title === "" ? " " : title}
</h2>
@@ -116,9 +117,9 @@ export function Hero({
/** The trailer: the play glyph, and the word wherever there is room for it. */
export function TrailerLink({ href, title }: { href: string; title: string }) {
return (
<IconLink className="trailer-link" label={`watch the ${title} trailer`} href={href}>
<IconLink shape="trailer" label={`watch the ${title} trailer`} href={href}>
<Icon name="play" />
<span className="control-word">trailer</span>
<span className="hidden @row:inline">trailer</span>
</IconLink>
);
}
@@ -258,16 +259,18 @@ export function RemovePanel({
{note.text}
</p>
<div className="remove-actions">
{/* armed: the confirm turns caution amber with the rest of the panel */}
<button
type="button"
className="control"
className={control({ state: hasFiles ? "warn" : null })}
data-tone={hasFiles ? "warn" : undefined}
aria-describedby="remove-note"
disabled={busy}
onClick={confirm}
>
remove and delete files
</button>
<button type="button" className="control" ref={keep} disabled={busy} onClick={onCancel}>
<button type="button" className={control()} ref={keep} disabled={busy} onClick={onCancel}>
keep
</button>
</div>
+14 -4
View File
@@ -1,4 +1,5 @@
import { useEffect, useRef, useState } from "react";
import { control, microControl } from "./look";
// The shared icon-only control block (#230), consumed by the title pages,
// decks and readouts, the settings rows (#231) and the subtitle chips and
@@ -64,9 +65,14 @@ const ICON_PATHS = {
export type IconName = keyof typeof ICON_PATHS;
/** Stroke glyph on the shared 16-grid; the control's aria-label carries the meaning. */
export function Icon({ name }: { name: IconName }) {
export function Icon({ name, className }: { name: IconName; className?: string }) {
return (
<svg viewBox="0 0 16 16" className="icon" aria-hidden="true" data-icon={name}>
<svg
viewBox="0 0 16 16"
className={className === undefined ? "icon" : `icon ${className}`}
aria-hidden="true"
data-icon={name}
>
{ICON_PATHS[name].map((d) => (
<path key={d} d={d} />
))}
@@ -186,7 +192,11 @@ export function ArmedDeleteIcon({
return (
<button
type="button"
className={compact ? "control-micro" : "control control-icon"}
className={
compact
? microControl(armed)
: control({ shape: "icon", danger: true, state: armed ? "armed" : null })
}
data-kind="delete"
data-armed={armed ? "true" : undefined}
aria-label={armed ? `confirm — ${label}` : label}
@@ -202,7 +212,7 @@ export function ArmedDeleteIcon({
}
}}
>
<Icon name={armed ? "check" : "trash"} />
<Icon name={armed ? "check" : "trash"} className={compact ? "size-3" : undefined} />
</button>
);
}
+145
View File
@@ -0,0 +1,145 @@
// The control vocabulary as Tailwind class lists. Each builder takes the
// control's whole state and returns one list with no two classes fighting
// over a property: Tailwind orders its output by variant, not by the order
// classes are written, so a conflict here would be settled by accident.
export function cx(...names: (string | false | null | undefined)[]): string {
return names.filter(Boolean).join(" ");
}
const TRANSITION =
"[transition:border-color_150ms_var(--ease-out),color_150ms_var(--ease-out),background_150ms_var(--ease-out)]";
export interface ControlLook {
/**
* primary: cyan word on a raised plate, one per header or panel.
* quiet: secondary actions — cancel, add, back, retry. Never a toggle.
* bare: no plate, for a page head's back control.
* lead: a row's leading disclosure, muted.
* faint: a chip-sized info glyph beside a group's note.
*/
look?: "primary" | "quiet" | "bare" | "lead" | "faint";
/**
* word: a label. fixed: a label that changes but keeps one width.
* icon: a square glyph. trailer: a glyph that grows its word from 40rem.
* disclose: show / hide, chevron at the far end. chip: a glyph at chip height.
*/
shape?: "word" | "fixed" | "icon" | "trailer" | "disclose" | "chip";
/** Full width with the content at the start: a phone tray or a settings panel. */
fill?: boolean;
/** Destructive: rests red so delete never reads like the glyph beside it. */
danger?: boolean;
/**
* armed: the next tap fires — amber, whatever else it was (`data-armed`).
* warn: the confirm of a removal that deletes files (`data-tone="warn"`).
* busy, done and failed need no look: `data-busy` and friends carry them.
*/
state?: "armed" | "warn" | null;
}
const SHAPE = {
word: "min-h-control-h py-0 px-4",
fixed: "min-h-control-h py-0 px-4 min-w-word-w",
icon: "min-h-control-h w-control-h min-w-control-h p-0",
trailer: "min-h-control-h w-control-h min-w-control-h p-0 @row:w-auto @row:px-4",
disclose: "min-h-control-h py-0 px-4 min-w-disclose",
chip: "min-h-chip-h size-chip-h min-w-chip-h p-0",
} as const;
const LOOK = {
primary:
"text-accent bg-panel-raised border-line-strong [box-shadow:inset_0_1px_var(--highlight)]",
quiet: "text-ink bg-transparent border-line [box-shadow:none]",
bare: "text-accent bg-transparent border-transparent [box-shadow:none] flex-none",
lead: "text-ink-muted bg-transparent border-line [box-shadow:none]",
faint: "text-ink-faint bg-transparent border-transparent [box-shadow:none]",
} as const;
/** The class list for a control in one state. */
export function control({
look = "primary",
shape = "word",
fill = false,
danger = false,
state = null,
}: ControlLook = {}): string {
let tone: string;
if (state === "armed") {
tone =
"data-[armed=true]:not-disabled:text-ground data-[armed=true]:not-disabled:bg-signal-warn data-[armed=true]:not-disabled:border-signal-warn";
} else if (state === "warn") {
tone =
"data-[tone=warn]:not-disabled:text-signal-warn data-[tone=warn]:not-disabled:[border-color:oklch(from_var(--signal-warn)_l_c_h/55%)]";
} else if (danger) {
tone =
"data-[kind=delete]:not-disabled:text-signal-fault data-[kind=delete]:not-disabled:hover:border-signal-fault data-[kind=delete]:not-disabled:focus-visible:border-signal-fault";
} else {
tone = cx(
"not-disabled:hover:border-accent not-disabled:hover:text-accent-bright",
// a row's lead disclosure keeps its muted plate open or closed
look !== "lead" && "aria-expanded:border-accent aria-expanded:text-accent-bright",
);
}
return cx(
"inline-flex items-center gap-2 font-readout text-xs font-semibold tabular-nums leading-none uppercase tracking-label whitespace-nowrap no-underline border rounded-panel",
fill ? "w-full justify-start" : shape === "disclose" ? "justify-between" : "justify-center",
SHAPE[shape],
LOOK[look],
TRANSITION,
"cursor-pointer disabled:text-ink-faint disabled:border-line disabled:cursor-default",
"not-disabled:active:[box-shadow:inset_0_1px_var(--lowlight)]",
// a request's outcome, read off the control's own data attributes
"data-busy:border-dashed data-busy:text-ink-faint data-busy:cursor-progress",
"data-done:text-signal-ok data-done:[border-color:oklch(from_var(--signal-ok)_l_c_h/55%)]",
"data-failed:not-hover:text-signal-fault data-failed:not-hover:[border-color:oklch(from_var(--signal-fault)_l_c_h/55%)]",
tone,
);
}
/** The chip-scale delete (#251): no plate, the armed glyph does the word's job. */
export function microControl(armed: boolean): string {
return cx(
"inline-flex items-center justify-center size-4 p-0 ms-1 [border:0] rounded-micro cursor-pointer disabled:opacity-50",
armed
? "text-ground bg-signal-warn"
: "text-ink-faint bg-transparent not-disabled:hover:text-signal-fault not-disabled:hover:[background:oklch(from_var(--signal-fault)_l_c_h/15%)] focus-visible:text-signal-fault focus-visible:[background:oklch(from_var(--signal-fault)_l_c_h/15%)]",
);
}
/** A rule that is on or off; `fill` stretches it across a tray. */
export function toggle(pressed: boolean, fill = false): string {
return cx(
"inline-flex items-center gap-2 min-h-control-h py-0 px-3 font-readout text-xs font-semibold leading-none uppercase tracking-label whitespace-nowrap bg-transparent border rounded-panel cursor-pointer [transition:border-color_150ms_var(--ease-out),color_150ms_var(--ease-out)] not-disabled:hover:border-accent disabled:cursor-progress disabled:opacity-60",
pressed ? "text-ink border-line-strong" : "text-ink-muted border-line",
fill && "w-full justify-start",
);
}
export function toggleLamp(pressed: boolean): string {
return cx(
"w-2 h-2 flex-none rounded-round [transition:background_300ms_var(--ease-out),box-shadow_300ms_var(--ease-out)]",
pressed ? "bg-accent [box-shadow:0_0_6px_oklch(from_var(--accent)_l_c_h/60%)]" : "bg-lamp-off",
);
}
export function toggleState(pressed: boolean): string {
return cx("min-w-state ml-auto text-left", pressed ? "text-accent" : "text-ink-faint");
}
/** One choice of a few, the engaged side lit; `wrap` lets a long set break lines. */
export function segmented(wrap = false): string {
return wrap
? "flex flex-wrap flex-none gap-1 min-w-0 m-0 p-0 [border:0]"
: "inline-flex flex-none min-w-0 m-0 p-0 [border:0]";
}
export function seg(pressed: boolean, icon = false): string {
return cx(
"inline-flex items-center justify-center gap-2 min-h-control-h font-readout text-xs font-semibold uppercase tracking-label border border-line cursor-pointer [transition:border-color_150ms_var(--ease-out),color_150ms_var(--ease-out)] first:rounded-l-panel last:rounded-r-panel not-first:border-l-0 hover:text-accent-bright",
icon ? "w-control-h p-0" : "py-0 px-3",
// the lit edge is drawn inside, so the joined borders never double
pressed
? "text-accent-bright bg-panel-raised [box-shadow:inset_0_0_0_1px_var(--accent)]"
: "text-ink-muted bg-transparent",
);
}
+5
View File
@@ -76,6 +76,9 @@
--spacing-rule: 2px;
/* a count badge's round */
--spacing-badge: 1.1rem;
--spacing-disclose: 9rem;
/* a toggle's on / off word */
--spacing-state: 3ch;
--container-deck: var(--deck-max);
--container-measure: var(--measure);
@@ -100,6 +103,8 @@
--radius-panel: var(--radius);
--radius-pill: 999px;
--radius-round: 50%;
--radius-micro: 2px;
--font-weight-semibold: 600;
--font-weight-bold: 700;
+5 -4
View File
@@ -4,6 +4,7 @@
import { type ReactNode, useEffect, useRef, useState } from "react";
import { ArmedDeleteIcon, Icon } from "./icons";
import { control, seg, segmented } from "./look";
import { fileName } from "./movie";
import {
cachedSubtitleOptions,
@@ -152,12 +153,12 @@ function LanguagePicker({
}) {
return (
// biome-ignore lint/a11y/useSemanticElements: a fieldset brings its own border, padding and min-width, which this group does not want
<div className="segmented subs-langs" role="group" aria-label={label}>
<div className={segmented(true)} role="group" aria-label={label}>
{languages.map((language) => (
<button
key={language}
type="button"
className="seg"
className={seg(language === choice)}
data-language={language}
aria-pressed={language === choice}
disabled={language === barred}
@@ -773,7 +774,7 @@ export function useSubtitleSection(
choice={searchChoice}
onPick={setSearchLanguage}
/>
<button type="button" className="control" disabled={searching} onClick={search}>
<button type="button" className={control()} disabled={searching} onClick={search}>
search
</button>
</div>
@@ -859,7 +860,7 @@ export function useSubtitleSection(
</SubtitleField>
<button
type="button"
className="control"
className={control()}
disabled={translateDisabled}
onClick={translate}
>
+58 -23
View File
@@ -16,13 +16,11 @@ import {
useState,
} from "react";
import { Icon, type IconName, useArmed } from "./icons";
import { type ControlLook, control, cx, toggle, toggleLamp, toggleState } from "./look";
export type Tone = "fault" | "warn";
/** Joins class names, dropping the falsy ones. */
export function cx(...names: (string | false | null | undefined)[]): string {
return names.filter(Boolean).join(" ");
}
export { cx } from "./look";
/** A boolean data attribute: present (empty) or absent. */
export function flag(on: boolean | undefined): "" | undefined {
@@ -40,6 +38,10 @@ export interface ControlProps extends ComponentProps<"button"> {
glyph?: IconName;
/** Fixed width, so a label that changes (GRAB → SENDING → SENT) never moves the row. */
fixed?: boolean;
/** Full width, content at the start: a phone tray or a settings panel. */
fill?: boolean;
danger?: boolean;
state?: ControlLook["state"];
busy?: boolean;
done?: boolean;
failed?: boolean;
@@ -51,6 +53,9 @@ export function Control({
quiet,
glyph,
fixed,
fill,
danger,
state,
busy,
done,
failed,
@@ -60,14 +65,23 @@ export function Control({
return (
<button
type="button"
className={cx("control", quiet && "control-quiet", fixed && "control-fixed", className)}
className={cx(
control({
look: quiet ? "quiet" : "primary",
shape: fixed ? "fixed" : "word",
fill,
danger,
state,
}),
className,
)}
data-busy={flag(busy)}
data-done={flag(done)}
data-failed={flag(failed)}
{...rest}
>
{glyph && <Icon name={glyph} />}
<span className="control-word">{text}</span>
{glyph && <Icon name={glyph} className={fill ? "mr-1" : undefined} />}
<span>{text}</span>
</button>
);
}
@@ -76,13 +90,20 @@ export function Control({
export function IconControl({
glyph,
label,
look,
shape = "icon",
className,
...rest
}: ComponentProps<"button"> & { glyph: IconName; label: string }) {
}: ComponentProps<"button"> & {
glyph: IconName;
label: string;
look?: ControlLook["look"];
shape?: "icon" | "chip";
}) {
return (
<button
type="button"
className={cx("control control-icon", className)}
className={cx(control({ look, shape }), className)}
aria-label={label}
{...rest}
>
@@ -95,17 +116,17 @@ export function IconControl({
export function IconLink({
label,
href,
className,
shape = "icon",
children,
}: {
label: string;
href: string;
className?: string;
shape?: "icon" | "trailer";
children: ReactNode;
}) {
return (
<a
className={cx("control control-icon", className)}
className={control({ shape })}
href={href}
target="_blank"
rel="noreferrer"
@@ -124,17 +145,20 @@ export function IconLink({
export function LampToggle({
label,
pressed,
fill = false,
...rest
}: ComponentProps<"button"> & {
label: string;
pressed: boolean;
/** Full width, content at the start: a phone tray or a settings panel. */
fill?: boolean;
"data-focus-id"?: string;
}) {
return (
<button type="button" className="toggle" aria-pressed={pressed} {...rest}>
<span className="toggle-lamp" aria-hidden="true" />
<span className="toggle-label">{label}</span>
<span className="toggle-state" aria-hidden="true">
<button type="button" className={toggle(pressed, fill)} aria-pressed={pressed} {...rest}>
<span className={toggleLamp(pressed)} aria-hidden="true" />
<span>{label}</span>
<span className={toggleState(pressed)} aria-hidden="true">
{pressed ? "on" : "off"}
</span>
</button>
@@ -159,14 +183,18 @@ export function Disclosure({
return (
<button
type="button"
className="control control-quiet disclose ml-auto"
className={cx(control({ look: "quiet", shape: "disclose" }), "ml-auto")}
aria-expanded={open}
onClick={onToggle}
>
<span className="control-word">
{`${open ? "hide" : "show"} ${count}${noun === "" ? "" : ` ${noun}`}`}
</span>
<Icon name="chevronDown" />
<span>{`${open ? "hide" : "show"} ${count}${noun === "" ? "" : ` ${noun}`}`}</span>
<Icon
name="chevronDown"
className={cx(
"[transition:transform_200ms_var(--ease-out)]",
open && "[transform:rotate(180deg)]",
)}
/>
</button>
);
}
@@ -188,6 +216,9 @@ export function ArmedDeleteWord({
text={armed ? `tap again to ${label}` : label}
glyph={armed ? "check" : "trash"}
quiet
fill
danger
state={armed ? "armed" : null}
data-kind="delete"
data-armed={armed ? "true" : undefined}
disabled={spent}
@@ -355,6 +386,8 @@ export interface ActionSlot {
wide?: boolean;
/** Shown below 40rem only — an empty cell that keeps a phone column aligned. */
narrow?: boolean;
/** A word or toggle control fills its column; an input keeps its own width. */
fill?: boolean;
}
export interface RowProps {
@@ -447,7 +480,8 @@ export function Row(props: RowProps) {
// the column is positional: a slot is its index
// biome-ignore lint/suspicious/noArrayIndexKey: see above
key={index}
className="r-slot"
// a word or a toggle fills its column, so every row's plates line up
className={cx("r-slot", slot.width !== "icon" && slot.fill !== false && "*:w-full")}
data-width={slot.width}
data-wide={flag(slot.wide)}
data-narrow={flag(slot.narrow)}
@@ -695,7 +729,8 @@ export function GroupNote({ short, more }: { short: string; more?: string }) {
label="more about this list"
aria-expanded={open}
onClick={() => setOpen(!open)}
className="size-chip-h min-w-chip-h min-h-chip-h border-transparent bg-none bg-transparent [box-shadow:none] text-ink-faint aria-expanded:border-accent aria-expanded:text-accent-bright"
look="faint"
shape="chip"
/>
<p className="m-0 basis-full max-w-measure text-xs" hidden={!open}>
{more}
+4 -3
View File
@@ -10,6 +10,7 @@ import {
movieNeedsAttention,
seriesNeedsAttention,
} from "../library";
import { seg, segmented } from "../look";
import { MovieCard, MovieRow, SeriesCard, SeriesRow } from "../rows";
import { allRoots, type LibraryMovie, type Root } from "../search";
import { Deck, DeckHead, PageBar, Rows, Section, SkeletonRows, useStatus } from "../ui";
@@ -168,10 +169,10 @@ export function LibraryView({ hidden }: { hidden: boolean }) {
count={total === 0 ? "" : `${total} ${total === 1 ? "title" : "titles"}`}
status={status}
>
<fieldset className="segmented" aria-label="layout">
<fieldset className={segmented()} aria-label="layout">
<button
type="button"
className="seg seg-icon"
className={seg(shape === "grid", true)}
aria-pressed={shape === "grid"}
aria-label="poster grid"
onClick={() => setShape("grid")}
@@ -180,7 +181,7 @@ export function LibraryView({ hidden }: { hidden: boolean }) {
</button>
<button
type="button"
className="seg seg-icon"
className={seg(shape === "list", true)}
aria-pressed={shape === "list"}
aria-label="list"
onClick={() => setShape("list")}
+6 -2
View File
@@ -5,6 +5,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { Buckets, type DeckState, type ReleaseActions } from "../buckets";
import { LAYER, useEscape, useNav } from "../context";
import { Hero, ProviderLink, RemovePanel, type RemoveSubject, TrailerLink } from "../detail";
import { control } from "../look";
import {
fileName,
imdbLink,
@@ -431,7 +432,7 @@ export function MovieView({ movieId, toReleases }: { movieId: number; toReleases
/>
<div className="actionbar">
<button type="button" className="control" disabled={sweeping} onClick={sweep}>
<button type="button" className={control()} disabled={sweeping} onClick={sweep}>
search indexers
</button>
<span className="actionbar-links">
@@ -444,6 +445,7 @@ export function MovieView({ movieId, toReleases }: { movieId: number; toReleases
<IconControl
glyph="more"
label="library settings for this title"
className="ml-auto"
aria-expanded={moreOpen}
aria-controls="movie-more-panel"
onClick={() => setMoreOpen(!moreOpen)}
@@ -477,12 +479,14 @@ export function MovieView({ movieId, toReleases }: { movieId: number; toReleases
</div>
<div className="more-toggles">
<LampToggle
fill
label="wanted"
pressed={movie?.wanted ?? false}
disabled={busy === "wanted"}
onClick={() => toggle("wanted", "wanted")}
/>
<LampToggle
fill
label="targeted search"
pressed={!(movie?.blocked ?? false)}
// the accessible name carries what the label cannot, at rest and on
@@ -523,7 +527,7 @@ export function MovieView({ movieId, toReleases }: { movieId: number; toReleases
</label>
<button
type="button"
className="control control-quiet"
className={control({ look: "quiet", fill: true, danger: true })}
data-kind="delete"
ref={removeButton}
aria-expanded={removeOpen}
+7 -3
View File
@@ -5,6 +5,7 @@
import { type KeyboardEvent, useEffect, useRef, useState } from "react";
import { useNav } from "../context";
import { Icon } from "../icons";
import { cx, seg, segmented } from "../look";
import { RatingChip, RowPoster, TitleText } from "../parts";
import { MovieRow, SeriesHitRow } from "../rows";
import {
@@ -411,7 +412,7 @@ export function SearchView({
<PageBar title="search" status={status} />
<div
className="segmented deck-filter"
className={cx(segmented(), "deck-filter")}
role="toolbar"
aria-label="show only one kind"
hidden={!listed}
@@ -426,13 +427,16 @@ export function SearchView({
<button
key={value}
type="button"
className="seg"
className={seg(kind === value)}
data-kind={value}
aria-pressed={kind === value}
onClick={() => setKind(value)}
>
{label}
<span className="filter-count" data-role="count">
<span
className={cx("tabular-nums", kind === value ? "text-ink-muted" : "text-ink-faint")}
data-role="count"
>
{listed ? countOf(value) : ""}
</span>
</button>
+9 -3
View File
@@ -6,6 +6,7 @@ import { LAYER, type TvDeckRequest, useEscape, useNav } from "../context";
import { Hero, ProviderLink, RemovePanel, type RemoveSubject, TrailerLink } from "../detail";
import { ArmedDeleteIcon } from "../icons";
import { seriesStatusChipRedundant } from "../library";
import { control } from "../look";
import { rottenTomatoesSearch, tmdbSeriesLink, tvdbLink, youtubeLink } from "../movie";
import {
audienceOf,
@@ -93,15 +94,18 @@ function WritingToggle({
pressed,
write,
focusId,
fill,
}: {
label: string;
pressed: boolean;
write: () => Promise<boolean>;
focusId?: string;
fill?: boolean;
}) {
const [busy, setBusy] = useState(false);
return (
<LampToggle
fill={fill}
label={label}
pressed={pressed}
disabled={busy}
@@ -178,6 +182,7 @@ function SeasonRow({
<IconControl
glyph="chevronRight"
label={`${short} episodes`}
look="lead"
className="disclose-lead"
aria-expanded={open}
aria-controls={`episodes-${season.number}`}
@@ -273,7 +278,7 @@ function SeasonRow({
]}
more={
<>
<WritingToggle label="tracked" pressed={season.tracked} write={track} />
<WritingToggle fill label="tracked" pressed={season.tracked} write={track} />
{hasFiles && <ArmedDeleteWord label={deleteLabel} execute={removeFiles} />}
</>
}
@@ -430,7 +435,7 @@ function EpisodeRow({
onDisk ? (
<ArmedDeleteWord label={deleteLabel} execute={removeFile} />
) : (
<WritingToggle label="wanted" pressed={episode.wanted} write={want} />
<WritingToggle fill label="wanted" pressed={episode.wanted} write={want} />
)
) : undefined
}
@@ -733,6 +738,7 @@ export function SeriesView({ seriesId, covered }: { seriesId: number; covered: b
<IconControl
glyph="more"
label="library settings for this title"
className="ml-auto"
aria-expanded={moreOpen}
aria-controls="series-more-panel"
onClick={() => setMoreOpen(!moreOpen)}
@@ -789,7 +795,7 @@ export function SeriesView({ seriesId, covered }: { seriesId: number; covered: b
</label>
<button
type="button"
className="control control-quiet"
className={control({ look: "quiet", fill: true, danger: true })}
data-kind="delete"
ref={removeButton}
aria-expanded={removeOpen}
+4 -2
View File
@@ -12,6 +12,7 @@ import {
import { LAYER, useEscape, useLive, useNav } from "../context";
import type { Check, CheckStatus } from "../health";
import { ArmedDeleteIcon, type IconName } from "../icons";
import { control } from "../look";
import type { Root } from "../search";
import {
deleteRow,
@@ -1032,6 +1033,7 @@ function SubtitlesPanel({
/>
),
width: "word",
fill: false,
},
{
node: (
@@ -1137,7 +1139,7 @@ export function SettingsView({ hidden }: { hidden: boolean }) {
<DeckHead label="roots" labelId="label-roots" labelClass="section-title">
<button
type="button"
className="control control-quiet head-action ml-auto"
className={cx(control({ look: "quiet" }), "ml-auto")}
onClick={() => setAddingRoot(true)}
>
add root
@@ -1180,7 +1182,7 @@ export function SettingsView({ hidden }: { hidden: boolean }) {
<DeckHead label="policies" labelId="label-policies" labelClass="section-title">
<button
type="button"
className="control control-quiet head-action ml-auto"
className={cx(control({ look: "quiet" }), "ml-auto")}
onClick={() => setAddingPolicy(true)}
>
add policy
+3 -2
View File
@@ -4,6 +4,7 @@
import { useEffect, useRef, useState } from "react";
import { Buckets, type DeckState, type ReleaseActions } from "../buckets";
import { LAYER, type TvDeckRequest, useEscape, useNav } from "../context";
import { control } from "../look";
import {
blacklistAdvice,
blacklistClass,
@@ -361,7 +362,7 @@ export function TvDeckView({ request }: { request: TvDeckRequest }) {
<Deck detail label="season and episode releases">
{/* a detail page without a hero still gives its head room under the rail */}
<header className="page-head pt-2">
<IconControl glyph="back" label="back" ref={back} onClick={nav.close} />
<IconControl glyph="back" label="back" look="bare" ref={back} onClick={nav.close} />
<div className="page-id">
<h2 className="page-title">{request.title}</h2>
<span className="page-sub readout">{request.sub ?? ""}</span>
@@ -370,7 +371,7 @@ export function TvDeckView({ request }: { request: TvDeckRequest }) {
<div className="actionbar">
<button
type="button"
className="control"
className={control()}
disabled={sweeping}
onClick={() => void startSweep()}
>