@sdxc/kit 2026.11.18 → 2026.11.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "range-months",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [
5
+ "calendar",
6
+ "heading"
7
+ ],
8
+ "exports": [
9
+ "RangeMonths"
10
+ ],
11
+ "source": {
12
+ "path": "range-months.tsx",
13
+ "content": "/**\n * A server-rendered run of consecutive month grids for picking a stay's check-in and check-out,\n * or a single date. Every selectable day is a link the caller builds, so picking works without\n * script; a CSS-only band previews the range under the pointer once a start is chosen.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { borderSpacing } from \"@sdxc/u/layout\";\n\nimport type { DaySelection, RangePosition } from \"@sdxc/ui/utils\";\n\nimport { CALENDAR_DAY_DATE_ATTRIBUTE } from \"@sdxc/ui/mixins\";\nimport {\n\tdayTime,\n\tfirstUnavailableAfter,\n\tmonthWeeks,\n\tnextSelection,\n\trangePosition,\n\tshiftMonth,\n\tweekdayTime,\n} from \"@sdxc/ui/utils\";\n\nimport { Calendar } from \"@sdxc/ui/calendar\";\nimport { Heading } from \"@sdxc/ui/heading\";\n\n/** How many months show when `months` is unset: a stay's two ends usually fit across two. */\nconst DEFAULT_MONTHS = 2;\n\n/** The first weekday column when `weekStartsOn` is unset: Sunday. */\nconst DEFAULT_WEEK_STARTS_ON = 0;\n\n/** The custom property every day cell sizes from: 40px, or the 44px touch target on a coarse pointer. */\nconst CELL = \"var(--ui-range-months-cell)\";\n\n/** The previous and next links' size: 32px, or the touch target on a coarse pointer. */\nconst NAV = \"max(2rem, var(--ui-target-size, 0px))\";\n\n/** The band colour for the days between the two ends of a chosen or previewed range. */\nconst BAND = \"var(--ui-brand-bg-tint-hover)\";\n\n/** The lighter band a pending range previews toward the hovered or focused day. */\nconst PREVIEW = \"var(--ui-brand-bg-tint)\";\n\n/** Matches a day cell the pointer or keyboard focus is on. */\nconst ACTIVE = \":is(:hover, :focus-within)\";\n\n/** Prop types for {@link RangeMonths}. */\nexport namespace RangeMonths {\n\t/** What a link asks the page to show next: the selection it makes and the first month on view. */\n\texport interface Next {\n\t\t/** First day of the range, or the picked day in single mode, `YYYY-MM-DD`. */\n\t\tstart?: string;\n\t\t/** Last day of the range, `YYYY-MM-DD`; absent while only a start is chosen. */\n\t\tend?: string;\n\t\t/** First month on view, `YYYY-MM`. */\n\t\tmonth: string;\n\t}\n\n\t/** Words read to assistive technology, in the page's language. */\n\texport interface Labels {\n\t\t/** Name of the previous-month link, e.g. \"Previous month\". */\n\t\tprevious: string;\n\t\t/** Name of the next-month link, e.g. \"Next month\". */\n\t\tnext: string;\n\t\t/** Appended to the start day's name, e.g. \"check-in\". */\n\t\tstart?: string;\n\t\t/** Appended to the end day's name, e.g. \"check-out\". */\n\t\tend?: string;\n\t\t/** Appended to the picked day's name in single mode. */\n\t\tselected?: string;\n\t}\n\n\t/** Every native `<div>` attribute, plus the months, selection and links to draw. */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** First month shown, `YYYY-MM`. */\n\t\tmonth: string;\n\t\t/** How many consecutive months to show, side by side while they fit and one per row below. Defaults to {@link DEFAULT_MONTHS}. */\n\t\tmonths?: number;\n\t\t/** Chosen start day (the picked day in single mode), `YYYY-MM-DD`. */\n\t\tstart?: string;\n\t\t/** Chosen end day, `YYYY-MM-DD`; read in range mode only. */\n\t\tend?: string;\n\t\t/** Picks one day: a day link carries `start` alone and no band is drawn. */\n\t\tsingle?: boolean;\n\t\t/** Today, `YYYY-MM-DD`, passed in so the server and the browser draw the same marker. */\n\t\ttoday?: string;\n\t\t/** Earliest selectable day, `YYYY-MM-DD`; also hides the previous link before its month. */\n\t\tmin?: string;\n\t\t/** Latest selectable day, `YYYY-MM-DD`; also hides the next link from its month on. */\n\t\tmax?: string;\n\t\t/** Days already taken: drawn struck through, never a link, and never crossed by a range. */\n\t\tisUnavailable?: (date: string) => boolean;\n\t\t/**\n\t\t * Counts each day as a night, as a stay calendar does: the first taken day after a pending\n\t\t * start still links as its end, since checking out that morning leaves the night free.\n\t\t */\n\t\tnights?: boolean;\n\t\t/** Builds the URL of every day and month link from what that link selects. */\n\t\thref: (next: Next) => string;\n\t\t/** A small line under each day's number, such as the nightly price or event dots. */\n\t\tdayNote?: (date: string) => RemixNode;\n\t\t/** First weekday column, 0 for Sunday through 6 for Saturday. Defaults to {@link DEFAULT_WEEK_STARTS_ON}. */\n\t\tweekStartsOn?: number;\n\t\t/** BCP 47 locale for the month, weekday and day names; pass it so server and browser agree. */\n\t\tlocale?: string;\n\t\t/** Names the whole calendar, e.g. \"Stay dates\". */\n\t\tlabel: string;\n\t\t/** Level of each month's heading; resolved from the surrounding heading scope when unset. */\n\t\theadingLevel?: Heading.Level;\n\t\t/** Words read to assistive technology. */\n\t\tlabels: Labels;\n\t}\n}\n\n/**\n * Renders `months` month grids from `month`, each day a link to `href`'s URL for the selection\n * a click makes: with no start, or both ends set, the day becomes a new start; with only a start,\n * a later day becomes the end and an earlier or equal one the new start. Single mode links each day\n * as `{ start: day }`. Unavailable days, days outside `min`–`max`, and, while a start waits for its\n * end, days past the first unavailable day after it render as plain text.\n *\n * @example\n * <RangeMonths\n * \tlabel={t(\"stay.dates\")}\n * \tlabels={{ previous: t(\"calendar.previous\"), next: t(\"calendar.next\"), start: t(\"stay.checkIn\"), end: t(\"stay.checkOut\") }}\n * \tlocale={locale}\n * \tmonth=\"2026-03\"\n * \tstart={query.checkIn}\n * \tend={query.checkOut}\n * \ttoday=\"2026-03-02\"\n * \tmin=\"2026-03-02\"\n * \tisUnavailable={(date) => booked.has(date)}\n * \tdayNote={(date) => `$${prices[date]}`}\n * \thref={(next) => `?${new URLSearchParams({ ...next })}`}\n * />\n * @example\n * <RangeMonths single months={1} label={t(\"jump\")} labels={labels} month=\"2026-03\" start={day} today={today} href={({ start, month }) => `/day/${start ?? month}`} />\n */\nexport function RangeMonths(handle: Handle<RangeMonths.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tmonth,\n\t\t\tmonths,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tsingle = false,\n\t\t\ttoday,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tisUnavailable,\n\t\t\tnights = false,\n\t\t\thref,\n\t\t\tdayNote,\n\t\t\tweekStartsOn,\n\t\t\tlocale,\n\t\t\tlabel,\n\t\t\theadingLevel,\n\t\t\tlabels,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet firstWeekday = weekStartsOn ?? DEFAULT_WEEK_STARTS_ON;\n\t\tlet shown = Array.from({ length: Math.max(1, months ?? DEFAULT_MONTHS) }, (_, index) =>\n\t\t\tshiftMonth(month, index),\n\t\t);\n\t\tlet lastShown = shown[shown.length - 1] ?? month;\n\t\tlet selection: DaySelection = { start, end: single ? undefined : end, single };\n\t\tlet block =\n\t\t\t!single && start !== undefined && end === undefined\n\t\t\t\t? firstUnavailableAfter(start, `${lastShown}-31`, isUnavailable)\n\t\t\t\t: undefined;\n\t\tlet previousMonth = shiftMonth(month, -1);\n\t\tlet showPrevious = min === undefined || previousMonth >= min.slice(0, 7);\n\t\tlet showNext = max === undefined || lastShown < max.slice(0, 7);\n\t\tlet monthName = new Intl.DateTimeFormat(locale, {\n\t\t\tmonth: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\ttimeZone: \"UTC\",\n\t\t});\n\t\tlet dayName = new Intl.DateTimeFormat(locale, { dateStyle: \"full\", timeZone: \"UTC\" });\n\t\tlet weekdayName = new Intl.DateTimeFormat(locale, { weekday: \"short\", timeZone: \"UTC\" });\n\t\tlet weekdays = Array.from({ length: 7 }, (_, index) =>\n\t\t\tweekdayName.format(weekdayTime(firstWeekday, index)),\n\t\t);\n\n\t\t/** The URL a day link points at, following the click rules in {@link RangeMonths}. */\n\t\tfunction dayHref(date: string): string {\n\t\t\treturn href(withMonth(nextSelection(date, selection), month));\n\t\t}\n\n\t\t/** Whether a click on `date` may produce a selection at all. */\n\t\tfunction isSelectable(date: string): boolean {\n\t\t\tif (min !== undefined && date < min) return false;\n\t\t\tif (max !== undefined && date > max) return false;\n\t\t\tif (nights && date === block) return true;\n\t\t\tif (isUnavailable?.(date)) return false;\n\t\t\treturn block === undefined || date < block;\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={label}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"range-months\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-range-months-cell\": \"max(2.5rem, var(--ui-target-size, 0px))\",\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tfontVariantNumeric: \"tabular-nums\",\n\t\t\t\t\t\t\t[`& [data-pending]${ACTIVE}, & td[data-pending]:has(~ td[data-pending]${ACTIVE}), & tr:has(~ tr td[data-pending]${ACTIVE}) td[data-pending], & [data-slot=range-months-month]:has(~ [data-slot=range-months-month] td[data-pending]${ACTIVE}) td[data-pending]`]:\n\t\t\t\t\t\t\t\t{ backgroundColor: PREVIEW },\n\t\t\t\t\t\t\t[`&:has(td[data-pending]${ACTIVE}) td[data-range=only]:not(:last-child)`]: {\n\t\t\t\t\t\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${PREVIEW} 50%)`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[`&:has(td[data-pending]${ACTIVE}) td[data-range=only]:not(:last-child):dir(rtl)`]: {\n\t\t\t\t\t\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${PREVIEW} 50%)`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{showPrevious ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href(withMonth({ start, end: selection.end }, previousMonth))}\n\t\t\t\t\t\taria-label={labels.previous}\n\t\t\t\t\t\tdata-slot=\"range-months-previous\"\n\t\t\t\t\t\tmix={[navLinkStyle(\"start\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ChevronLeftIcon aria-hidden=\"true\" />\n\t\t\t\t\t</a>\n\t\t\t\t) : null}\n\t\t\t\t{showNext ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href(withMonth({ start, end: selection.end }, shiftMonth(month, 1)))}\n\t\t\t\t\t\taria-label={labels.next}\n\t\t\t\t\t\tdata-slot=\"range-months-next\"\n\t\t\t\t\t\tmix={[navLinkStyle(\"end\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ChevronRightIcon aria-hidden=\"true\" />\n\t\t\t\t\t</a>\n\t\t\t\t) : null}\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"range-months-months\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\tgridTemplateColumns: `repeat(auto-fit, minmax(min(100%, calc(7 * ${CELL})), calc(7 * ${CELL})))`,\n\t\t\t\t\t\t\tjustifyContent: \"start\",\n\t\t\t\t\t\t\tcolumnGap: \"2rem\",\n\t\t\t\t\t\t\trowGap: \"1.5rem\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{shown.map((key) => {\n\t\t\t\t\t\tlet monthLabel = monthName.format(dayTime(key));\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<section key={key} data-slot=\"range-months-month\" data-month={key}>\n\t\t\t\t\t\t\t\t<Calendar.Header\n\t\t\t\t\t\t\t\t\tmix={[raw({ minBlockSize: NAV, marginBlockEnd: \"0.5rem\", paddingInline: NAV })]}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Calendar.Heading level={headingLevel}>{monthLabel}</Calendar.Heading>\n\t\t\t\t\t\t\t\t</Calendar.Header>\n\t\t\t\t\t\t\t\t<Calendar.Grid\n\t\t\t\t\t\t\t\t\taria-label={monthLabel}\n\t\t\t\t\t\t\t\t\tmix={[borderSpacing(\"0\"), raw({ inlineSize: \"100%\", tableLayout: \"fixed\" })]}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Calendar.GridHeader>\n\t\t\t\t\t\t\t\t\t\t<Calendar.Row>\n\t\t\t\t\t\t\t\t\t\t\t{weekdays.map((weekday) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<Calendar.HeaderCell key={weekday}>{weekday}</Calendar.HeaderCell>\n\t\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t\t</Calendar.Row>\n\t\t\t\t\t\t\t\t\t</Calendar.GridHeader>\n\t\t\t\t\t\t\t\t\t<Calendar.GridBody>\n\t\t\t\t\t\t\t\t\t\t{monthWeeks(key, firstWeekday).map((week, row) => (\n\t\t\t\t\t\t\t\t\t\t\t<Calendar.Row key={`${key}-${row}`}>\n\t\t\t\t\t\t\t\t\t\t\t\t{week.map((date, column) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (date === null) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td key={`${key}-${row}-${column}`} data-slot=\"range-months-blank\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet position = rangePosition(date, selection);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet unavailable = isUnavailable?.(date) ?? false;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet selectable = isSelectable(date);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet pending =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tselectable &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t!single &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstart !== undefined &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tend === undefined &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate > start;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet note = dayNote === undefined ? undefined : dayNote(date);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet stateLabel = dayStateLabel(position, single, labels);\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey={date}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-slot=\"range-months-day\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-range={position}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-pending={pending ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-unavailable={unavailable ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taria-disabled={selectable ? undefined : \"true\"}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmix={[dayCellStyle()]}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<RangeMonthsDay\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate={date}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thref={selectable ? dayHref(date) : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstateLabel === undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t? dayName.format(dayTime(date))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t: `${dayName.format(dayTime(date))}, ${stateLabel}`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttoday={date === today}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnote={note}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thasNotes={dayNote !== undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t\t</Calendar.Row>\n\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t</Calendar.GridBody>\n\t\t\t\t\t\t\t\t</Calendar.Grid>\n\t\t\t\t\t\t\t</section>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/** Props of {@link RangeMonthsDay}. */\ninterface RangeMonthsDayProps {\n\t/** The day, `YYYY-MM-DD`; exposed on the focusable element for `calendarKeys()`. */\n\tdate: string;\n\t/** Where a click goes; absent for a day that cannot be picked. */\n\thref?: string;\n\t/** The day's full spoken name, with its selection state. */\n\tlabel: string;\n\t/** Marks the day with `aria-current=\"date\"`. */\n\ttoday: boolean;\n\t/** The caller's note under the number. */\n\tnote: RemixNode;\n\t/** Reserves the note line on every day, so rows keep one height. */\n\thasNotes: boolean;\n}\n\n/**\n * One day's content: a link when it can be picked, otherwise plain text, each holding the day\n * number and, when the calendar carries notes, the note line under it.\n */\nfunction RangeMonthsDay(handle: Handle<RangeMonthsDayProps>) {\n\treturn () => {\n\t\tlet { date, href, label, today, note, hasNotes } = handle.props;\n\t\tlet content = (\n\t\t\t<>\n\t\t\t\t<span data-slot=\"range-months-number\">{Number(date.slice(8, 10))}</span>\n\t\t\t\t{hasNotes ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-slot=\"range-months-note\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tminBlockSize: \"1em\",\n\t\t\t\t\t\t\t\tfontSize: \"0.625rem\",\n\t\t\t\t\t\t\t\tlineHeight: \"1\",\n\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t\t\t\t\t\t\t\"[data-range=start] &, [data-range=end] &, [data-range=only] &\": {\n\t\t\t\t\t\t\t\t\tcolor: \"inherit\",\n\t\t\t\t\t\t\t\t\topacity: \"0.85\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{note}\n\t\t\t\t\t</span>\n\t\t\t\t) : null}\n\t\t\t</>\n\t\t);\n\t\tlet attributes = {\n\t\t\t[CALENDAR_DAY_DATE_ATTRIBUTE]: date,\n\t\t\t\"aria-current\": today ? (\"date\" as const) : undefined,\n\t\t\t\"data-today\": today ? \"\" : undefined,\n\t\t};\n\t\tif (href === undefined) {\n\t\t\treturn (\n\t\t\t\t<span {...attributes} data-slot=\"range-months-day-text\" mix={[dayContentStyle()]}>\n\t\t\t\t\t{content}\n\t\t\t\t</span>\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\t<a {...attributes} href={href} aria-label={label} mix={[dayContentStyle()]}>\n\t\t\t\t{content}\n\t\t\t</a>\n\t\t);\n\t};\n}\n\n/** Adds the first month on view to a selection, leaving out the ends that are unset. */\nfunction withMonth(selection: Omit<RangeMonths.Next, \"month\">, month: string): RangeMonths.Next {\n\tlet next: RangeMonths.Next = { month };\n\tif (selection.start !== undefined) next.start = selection.start;\n\tif (selection.end !== undefined) next.end = selection.end;\n\treturn next;\n}\n\n/** The selection state appended to a day's spoken name, when the caller supplied its word. */\nfunction dayStateLabel(\n\tposition: RangePosition | undefined,\n\tsingle: boolean,\n\twords: RangeMonths.Labels,\n): string | undefined {\n\tif (position === \"only\") return single ? words.selected : words.start;\n\tif (position === \"start\") return words.start;\n\tif (position === \"end\") return words.end;\n\treturn undefined;\n}\n\n/**\n * A day's `<td>`: the band behind a chosen range, squared where it runs on and rounded where it\n * meets a week's edge, with the two ends' cells half-filled toward the days between.\n */\nfunction dayCellStyle() {\n\treturn raw({\n\t\tpadding: \"0\",\n\t\ttextAlign: \"center\",\n\t\tverticalAlign: \"middle\",\n\t\t\"&[data-range=middle]\": { backgroundColor: BAND },\n\t\t\"&[data-range=middle]:first-child\": {\n\t\t\tborderStartStartRadius: \"9999px\",\n\t\t\tborderEndStartRadius: \"9999px\",\n\t\t},\n\t\t\"&[data-range=middle]:last-child\": {\n\t\t\tborderStartEndRadius: \"9999px\",\n\t\t\tborderEndEndRadius: \"9999px\",\n\t\t},\n\t\t\"&[data-range=start]:not(:last-child)\": {\n\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=end]:not(:first-child)\": {\n\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=start]:not(:last-child):dir(rtl)\": {\n\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=end]:not(:first-child):dir(rtl)\": {\n\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t});\n}\n\n/**\n * A day's link or text: a round target at least {@link CELL} tall, solid at either end of the\n * range, muted and struck through when taken, faded when outside `min`–`max`, underlined for today.\n */\nfunction dayContentStyle() {\n\treturn raw({\n\t\tdisplay: \"grid\",\n\t\tplaceContent: \"center\",\n\t\tjustifyItems: \"center\",\n\t\tgap: \"0.125rem\",\n\t\tinlineSize: \"100%\",\n\t\tminBlockSize: CELL,\n\t\tpaddingBlock: \"0.25rem\",\n\t\tborderRadius: \"9999px\",\n\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\tfontSize: \"0.875rem\",\n\t\tlineHeight: \"1.1\",\n\t\ttextDecoration: \"none\",\n\t\toutlineOffset: \"-2px\",\n\t\t\"&:is(a):hover\": { backgroundColor: \"var(--ui-neutral-bg-tint-hover)\" },\n\t\t\"&:is(a):focus-visible\": { outline: \"2px solid var(--ui-brand-ring)\" },\n\t\t\"[data-range=middle] &\": { color: \"var(--ui-brand-fg-emphasis)\" },\n\t\t\"[data-range=middle] &:is(a):hover, [data-pending] &:is(a):hover\": {\n\t\t\tbackgroundColor: \"var(--ui-brand-bg-tint-pressed)\",\n\t\t},\n\t\t\"[data-range=start] &:is(a), [data-range=end] &:is(a), [data-range=only] &:is(a), [data-range=only] &\":\n\t\t\t{\n\t\t\t\tbackgroundColor: \"var(--ui-brand-bg-solid)\",\n\t\t\t\tcolor: \"var(--ui-brand-fg-on-solid)\",\n\t\t\t},\n\t\t\"[aria-disabled=true] &\": { color: \"var(--ui-neutral-fg-muted)\", opacity: \"0.45\" },\n\t\t\"[data-unavailable] &\": { opacity: \"1\" },\n\t\t\"[data-unavailable] & [data-slot=range-months-number]\": { textDecoration: \"line-through\" },\n\t\t\"&[data-today] [data-slot=range-months-number]\": {\n\t\t\tfontWeight: \"700\",\n\t\t\ttextDecorationLine: \"underline\",\n\t\t\ttextDecorationThickness: \"2px\",\n\t\t\ttextUnderlineOffset: \"3px\",\n\t\t},\n\t\t\"[data-unavailable] &[data-today] [data-slot=range-months-number]\": {\n\t\t\ttextDecorationLine: \"underline line-through\",\n\t\t},\n\t});\n}\n\n/**\n * A previous or next link: a round chevron button pinned to the heading row's `side`, so the\n * pair flanks the first month's heading however the months wrap.\n */\nfunction navLinkStyle(side: \"start\" | \"end\") {\n\treturn raw({\n\t\tposition: \"absolute\",\n\t\tinsetBlockStart: \"0\",\n\t\tinsetInlineStart: side === \"start\" ? \"0\" : \"auto\",\n\t\tinsetInlineEnd: side === \"end\" ? \"0\" : \"auto\",\n\t\tzIndex: \"1\",\n\t\tdisplay: \"grid\",\n\t\tplaceItems: \"center\",\n\t\tinlineSize: NAV,\n\t\tblockSize: NAV,\n\t\tborderRadius: \"9999px\",\n\t\tcolor: \"var(--ui-neutral-fg)\",\n\t\t\"&:hover\": { backgroundColor: \"var(--ui-neutral-bg-tint-hover)\" },\n\t\t\"&:focus-visible\": { outline: \"2px solid var(--ui-brand-ring)\", outlineOffset: \"2px\" },\n\t\t\"& svg\": { inlineSize: \"1rem\", blockSize: \"1rem\" },\n\t\t\"&:dir(rtl) svg\": { scale: \"-1 1\" },\n\t});\n}\n"
14
+ },
15
+ "test": {
16
+ "path": "range-months.browser.test.tsx",
17
+ "content": "/**\n * Renders `RangeMonths` in a real browser: the weeks and weekday columns each month lays out, the\n * link every day carries in each selection state, the days that are never links, the band a\n * range draws, and a single month fitting a 320px phone without scrolling sideways.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { RangeMonths } from \"@sdxc/ui/range-months\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The words read to assistive technology. */\nconst LABELS: RangeMonths.Labels = {\n\tprevious: \"Previous month\",\n\tnext: \"Next month\",\n\tstart: \"check-in\",\n\tend: \"check-out\",\n};\n\n/** The tokens the band and the ends read, which an app's palette would otherwise supply. */\nconst TOKENS = {\n\t\"--ui-brand-bg-solid\": \"rgb(30, 90, 200)\",\n\t\"--ui-brand-fg-on-solid\": \"rgb(255, 255, 255)\",\n\t\"--ui-brand-bg-tint-hover\": \"rgb(220, 230, 250)\",\n\t\"--ui-brand-bg-tint\": \"rgb(240, 244, 252)\",\n};\n\n/** Encodes a link's selection as a query string, so a test reads back what a click selects. */\nfunction href(next: RangeMonths.Next): string {\n\treturn `/stay?${new URLSearchParams({ ...next })}`;\n}\n\n/** Mounts a calendar `width` pixels wide with `props` over a March 2026 default and returns its root. */\nfunction mount(props: Partial<RangeMonths.Props> = {}, width = 800): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tfor (let [name, value] of Object.entries(TOKENS)) host.style.setProperty(name, value);\n\tdocument.body.appendChild(host);\n\trender(\n\t\t<RangeMonths\n\t\t\tlabel=\"Stay dates\"\n\t\t\tlabels={LABELS}\n\t\t\tlocale=\"en-US\"\n\t\t\tmonth=\"2026-03\"\n\t\t\thref={href}\n\t\t\t{...props}\n\t\t/>,\n\t\t{\n\t\t\tcontainer: host,\n\t\t},\n\t);\n\treturn host.querySelector<HTMLElement>(\"[data-slot=range-months]\")!;\n}\n\n/** The query a day's link carries, or `null` when the day is not a link. */\nfunction linkOf(root: HTMLElement, date: string): string | null {\n\tlet link = root.querySelector(`a[data-date=\"${date}\"]`);\n\treturn link === null ? null : link.getAttribute(\"href\")!.replace(\"/stay?\", \"\");\n}\n\n/** A day's `<td>`. */\nfunction cellOf(root: HTMLElement, date: string): HTMLElement {\n\treturn root.querySelector<HTMLElement>(`[data-date=\"${date}\"]`)!.closest(\"td\")!;\n}\n\nafterEach(() => {\n\tdocument.body.replaceChildren();\n});\n\ndescribe(\"RangeMonths\", () => {\n\ttest(\"lays out each month's weeks with every day once\", () => {\n\t\tlet root = mount({ months: 2 });\n\t\tlet months = root.querySelectorAll(\"[data-slot=range-months-month]\");\n\t\texpect(months).toHaveLength(2);\n\t\texpect(months[0]?.querySelectorAll(\"tbody tr\")).toHaveLength(5);\n\t\texpect(months[0]?.querySelectorAll(\"[data-date]\")).toHaveLength(31);\n\t\texpect(months[1]?.querySelectorAll(\"[data-date]\")).toHaveLength(30);\n\t\texpect(months[0]?.querySelector(\"table\")?.getAttribute(\"aria-label\")).toBe(\"March 2026\");\n\t\texpect(months[1]?.querySelector(\"h2, h3, h4, h5, h6, h1\")?.textContent).toBe(\"April 2026\");\n\t\tlet firstRow = [...months[0]!.querySelectorAll(\"tbody tr:first-child td\")];\n\t\texpect(firstRow.findIndex((cell) => cell.querySelector(\"[data-date]\") !== null)).toBe(0);\n\t});\n\n\ttest(\"orders the weekday columns from weekStartsOn\", () => {\n\t\tlet sunday = mount({ months: 1 });\n\t\texpect([...sunday.querySelectorAll(\"th\")].map((cell) => cell.textContent)).toEqual([\n\t\t\t\"Sun\",\n\t\t\t\"Mon\",\n\t\t\t\"Tue\",\n\t\t\t\"Wed\",\n\t\t\t\"Thu\",\n\t\t\t\"Fri\",\n\t\t\t\"Sat\",\n\t\t]);\n\t\tdocument.body.replaceChildren();\n\t\tlet monday = mount({ months: 1, weekStartsOn: 1 });\n\t\texpect(monday.querySelector(\"th\")?.textContent).toBe(\"Mon\");\n\t\texpect(monday.querySelectorAll(\"tbody tr:first-child td\")[6]?.textContent).toBe(\"1\");\n\t});\n\n\ttest(\"links each day to a new start when nothing is chosen\", () => {\n\t\tlet root = mount();\n\t\texpect(linkOf(root, \"2026-03-10\")).toBe(\"month=2026-03&start=2026-03-10\");\n\t});\n\n\ttest(\"links a later day to the end and an earlier one to a new start once a start is chosen\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\" });\n\t\texpect(linkOf(root, \"2026-03-14\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-14\");\n\t\texpect(linkOf(root, \"2026-03-08\")).toBe(\"month=2026-03&start=2026-03-08\");\n\t\texpect(linkOf(root, \"2026-03-10\")).toBe(\"month=2026-03&start=2026-03-10\");\n\t});\n\n\ttest(\"restarts at the clicked day once both ends are chosen\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\", end: \"2026-03-14\" });\n\t\texpect(linkOf(root, \"2026-03-20\")).toBe(\"month=2026-03&start=2026-03-20\");\n\t});\n\n\ttest(\"links each day as the start alone in single mode, with no band\", () => {\n\t\tlet root = mount({ single: true, start: \"2026-03-10\", end: \"2026-03-14\" });\n\t\texpect(linkOf(root, \"2026-03-20\")).toBe(\"month=2026-03&start=2026-03-20\");\n\t\texpect(cellOf(root, \"2026-03-10\").dataset.range).toBe(\"only\");\n\t\texpect(cellOf(root, \"2026-03-12\").dataset.range).toBeUndefined();\n\t});\n\n\ttest(\"keeps the selection on the month links and hides previous before min's month\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\", end: \"2026-03-14\", min: \"2026-03-05\" });\n\t\texpect(root.querySelector(\"[data-slot=range-months-previous]\")).toBeNull();\n\t\texpect(root.querySelector(\"[data-slot=range-months-next]\")?.getAttribute(\"href\")).toBe(\n\t\t\t\"/stay?month=2026-04&start=2026-03-10&end=2026-03-14\",\n\t\t);\n\t\tdocument.body.replaceChildren();\n\t\tlet later = mount({ month: \"2026-04\", min: \"2026-03-05\", max: \"2026-05-20\" });\n\t\texpect(later.querySelector(\"[data-slot=range-months-previous]\")?.getAttribute(\"href\")).toBe(\n\t\t\t\"/stay?month=2026-03\",\n\t\t);\n\t\texpect(later.querySelector(\"[data-slot=range-months-next]\")).toBeNull();\n\t});\n\n\ttest(\"draws unavailable days and days before min as text, not links\", () => {\n\t\tlet root = mount({\n\t\t\tmin: \"2026-03-05\",\n\t\t\tisUnavailable: (date) => date === \"2026-03-12\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-04\")).toBeNull();\n\t\texpect(cellOf(root, \"2026-03-04\").getAttribute(\"aria-disabled\")).toBe(\"true\");\n\t\texpect(linkOf(root, \"2026-03-12\")).toBeNull();\n\t\texpect(cellOf(root, \"2026-03-12\").hasAttribute(\"data-unavailable\")).toBe(true);\n\t\tlet number = cellOf(root, \"2026-03-12\").querySelector(\"[data-slot=range-months-number]\")!;\n\t\texpect(getComputedStyle(number).textDecorationLine).toContain(\"line-through\");\n\t\texpect(linkOf(root, \"2026-03-05\")).not.toBeNull();\n\t});\n\n\ttest(\"ends a pending range before the first unavailable day after its start\", () => {\n\t\tlet root = mount({\n\t\t\tstart: \"2026-03-10\",\n\t\t\tisUnavailable: (date) => date === \"2026-03-15\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-14\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-14\");\n\t\texpect(cellOf(root, \"2026-03-14\").hasAttribute(\"data-pending\")).toBe(true);\n\t\texpect(linkOf(root, \"2026-03-16\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-04-02\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-03-05\")).toBe(\"month=2026-03&start=2026-03-05\");\n\t});\n\n\ttest(\"in a nights calendar, ends a pending range on the first taken day after its start\", () => {\n\t\tlet root = mount({\n\t\t\tstart: \"2026-03-10\",\n\t\t\tnights: true,\n\t\t\tisUnavailable: (date) => date === \"2026-03-15\" || date === \"2026-03-16\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-15\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-15\");\n\t\texpect(cellOf(root, \"2026-03-15\").hasAttribute(\"data-pending\")).toBe(true);\n\t\texpect(linkOf(root, \"2026-03-16\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-03-17\")).toBeNull();\n\t});\n\n\ttest(\"marks today with aria-current\", () => {\n\t\tlet root = mount({ today: \"2026-03-18\" });\n\t\texpect(root.querySelector(\"[aria-current=date]\")?.getAttribute(\"data-date\")).toBe(\"2026-03-18\");\n\t\texpect(root.querySelectorAll(\"[aria-current]\")).toHaveLength(1);\n\t});\n\n\ttest(\"draws a chosen range as one band from its start to its end\", () => {\n\t\tlet root = mount({ start: \"2026-03-30\", end: \"2026-04-03\" });\n\t\texpect(cellOf(root, \"2026-03-30\").dataset.range).toBe(\"start\");\n\t\texpect(cellOf(root, \"2026-03-31\").dataset.range).toBe(\"middle\");\n\t\texpect(cellOf(root, \"2026-04-02\").dataset.range).toBe(\"middle\");\n\t\texpect(cellOf(root, \"2026-04-03\").dataset.range).toBe(\"end\");\n\t\texpect(cellOf(root, \"2026-03-29\").dataset.range).toBeUndefined();\n\t\texpect(root.querySelector('a[data-date=\"2026-03-30\"]')?.getAttribute(\"aria-label\")).toBe(\n\t\t\t\"Monday, March 30, 2026, check-in\",\n\t\t);\n\t\tlet start = cellOf(root, \"2026-03-30\").getBoundingClientRect();\n\t\tlet next = cellOf(root, \"2026-03-31\").getBoundingClientRect();\n\t\texpect(next.left - start.right).toBe(0);\n\t\tlet solid = getComputedStyle(root.querySelector('a[data-date=\"2026-03-30\"]')!).backgroundColor;\n\t\tlet plain = getComputedStyle(root.querySelector('a[data-date=\"2026-03-20\"]')!).backgroundColor;\n\t\texpect(solid).toBe(\"rgb(30, 90, 200)\");\n\t\texpect(plain).not.toBe(solid);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-31\")).backgroundColor).toBe(\"rgb(220, 230, 250)\");\n\t});\n\n\ttest(\"puts the caller's note under each day\", () => {\n\t\tlet root = mount({ months: 1, dayNote: (date) => `$${Number(date.slice(8))}0` });\n\t\texpect(\n\t\t\troot.querySelector('[data-date=\"2026-03-07\"] [data-slot=range-months-note]')?.textContent,\n\t\t).toBe(\"$70\");\n\t});\n\n\ttest(\"fits one month inside a 320px phone without scrolling sideways\", () => {\n\t\tlet root = mount({ months: 1, dayNote: () => \"$120\" }, 320);\n\t\texpect(root.scrollWidth).toBeLessThanOrEqual(320);\n\t\texpect(root.getBoundingClientRect().width).toBeLessThanOrEqual(320);\n\t\tlet day = root.querySelector('a[data-date=\"2026-03-10\"]')!.getBoundingClientRect();\n\t\texpect(day.width).toBeGreaterThanOrEqual(40);\n\t\texpect(day.height).toBeGreaterThanOrEqual(40);\n\t});\n\n\ttest(\"sets two months side by side when wide and one per row when narrow\", () => {\n\t\tlet tops = (root: HTMLElement) =>\n\t\t\tnew Set(\n\t\t\t\t[...root.querySelectorAll(\"[data-slot=range-months-month]\")].map((month) =>\n\t\t\t\t\tMath.round(month.getBoundingClientRect().top),\n\t\t\t\t),\n\t\t\t).size;\n\t\texpect(tops(mount({}, 800))).toBe(1);\n\t\tdocument.body.replaceChildren();\n\t\texpect(tops(mount({}, 400))).toBe(2);\n\t});\n\n\ttest(\"previews the pending range up to the hovered day across rows\", async () => {\n\t\tlet root = mount({ start: \"2026-03-05\" });\n\t\tlet preview = \"rgb(240, 244, 252)\";\n\t\tawait userEvent.hover(root.querySelector('a[data-date=\"2026-03-10\"]')!);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-06\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-09\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-10\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-11\")).backgroundColor).not.toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-04\")).backgroundColor).not.toBe(preview);\n\t});\n});\n"
18
+ }
19
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "rating-input",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [
5
+ "rating"
6
+ ],
7
+ "exports": [
8
+ "RatingInput"
9
+ ],
10
+ "source": {
11
+ "path": "rating-input.tsx",
12
+ "content": "/**\n * A star picker for a review form: a fieldset of native radios drawn as stars, where the\n * picked star and every one before it fill, and hovering previews a score. It posts a plain\n * number, the arrow keys move between stars, and it works with no script at all.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\n\nimport { STAR_PATH } from \"@sdxc/ui/rating\";\n\n/** Painted on a filled star. */\nconst FILLED = \"var(--ui-rating-color, var(--ui-warning-bg-solid))\";\n\n/** Painted on a star past the score. */\nconst EMPTY = \"var(--ui-neutral-border-strong, var(--ui-neutral-border))\";\n\n/** Prop types for {@link RatingInput}. */\nexport namespace RatingInput {\n\t/** Props accepted by {@link RatingInput}; the host is a `<fieldset>`. */\n\texport interface Props extends Omit<TagProps<\"fieldset\">, \"children\" | \"name\"> {\n\t\t/** The field the score posts as. */\n\t\tname: string;\n\t\t/** The score picked now, from 1 to the number of labels. */\n\t\tvalue?: number;\n\t\trequired?: boolean;\n\t\t/** The question the stars answer, such as \"Your rating\". */\n\t\tlegend: RemixNode;\n\t\t/** One name per star, lowest first, such as \"1 star — Poor\"; their count sets the scale. */\n\t\tlabels: string[];\n\t}\n}\n\n/**\n * Renders one radio and its star label per entry of `labels`, in score order so the native\n * arrow keys step up and down the scale. A star fills when its own radio or any later one is\n * checked, and hovering a star fills it and every earlier one in place of the checked score.\n *\n * @example\n * <RatingInput name=\"rating\" legend=\"Your rating\" required labels={[\"1 star — Poor\", \"2 stars — Fair\", \"3 stars — Good\", \"4 stars — Great\", \"5 stars — Excellent\"]} />\n */\nexport function RatingInput(handle: Handle<RatingInput.Props>) {\n\treturn () => {\n\t\tlet { id, labels, legend, mix, name, required, value, ...rest } = handle.props;\n\t\tlet base = id ?? handle.id;\n\t\treturn (\n\t\t\t<fieldset\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\tdata-slot=\"rating-input\"\n\t\t\t\tmix={mergeMix([raw({ margin: \"0\", padding: \"0\", border: \"0\", minInlineSize: \"0\" })], mix)}\n\t\t\t>\n\t\t\t\t<legend\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\tmarginBlockEnd: \"0.5rem\",\n\t\t\t\t\t\t\tfontSize: \"0.875rem\",\n\t\t\t\t\t\t\tfontWeight: \"600\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{legend}\n\t\t\t\t</legend>\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"rating-input-stars\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\tgap: \"0.125rem\",\n\t\t\t\t\t\t\t\"& label\": {\n\t\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\t\tplaceItems: \"center\",\n\t\t\t\t\t\t\t\tinlineSize: \"2.75rem\",\n\t\t\t\t\t\t\t\tblockSize: \"2.75rem\",\n\t\t\t\t\t\t\t\tborderRadius: \"0.5rem\",\n\t\t\t\t\t\t\t\tcolor: EMPTY,\n\t\t\t\t\t\t\t\tcursor: \"pointer\",\n\t\t\t\t\t\t\t\ttransition: \"color 120ms ease, transform 120ms ease\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& svg\": { inlineSize: \"1.75rem\", blockSize: \"1.75rem\" },\n\t\t\t\t\t\t\t\"& input:checked + label, & label:has(~ input:checked)\": { color: FILLED },\n\t\t\t\t\t\t\t\"&:has(label:hover) label\": { color: EMPTY },\n\t\t\t\t\t\t\t\"&:has(label:hover) label:hover, &:has(label:hover) label:has(~ label:hover)\": {\n\t\t\t\t\t\t\t\tcolor: FILLED,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& input:focus-visible + label\": {\n\t\t\t\t\t\t\t\toutline: \"2px solid var(--ui-brand-ring)\",\n\t\t\t\t\t\t\t\toutlineOffset: \"-2px\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& input:disabled + label\": { cursor: \"not-allowed\", opacity: \"0.5\" },\n\t\t\t\t\t\t\t\"@media (prefers-reduced-motion: reduce)\": { \"& label\": { transition: \"none\" } },\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{labels.map((label, index) => {\n\t\t\t\t\t\tlet score = index + 1;\n\t\t\t\t\t\tlet inputId = `${base}-${score}`;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\t\t\tvalue={String(score)}\n\t\t\t\t\t\t\t\t\tdefaultChecked={value === score}\n\t\t\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\t\t\tmix={[visuallyHidden()]}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<label htmlFor={inputId} title={label} data-score={String(score)}>\n\t\t\t\t\t\t\t\t\t<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\">\n\t\t\t\t\t\t\t\t\t\t<path d={STAR_PATH} fill=\"currentColor\" />\n\t\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t\t\t<span mix={[visuallyHidden()]}>{label}</span>\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t</fieldset>\n\t\t);\n\t};\n}\n"
13
+ },
14
+ "test": {
15
+ "path": "rating-input.browser.test.tsx",
16
+ "content": "/**\n * Holds the star picker to its contract in a real browser: one radio per label in score\n * order, the picked star and every earlier one filled, hovering previewing a score, and the\n * arrow keys stepping along the scale.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterAll, afterEach, beforeAll, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { RatingInput } from \"@sdxc/ui/rating-input\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** One name per star. */\nconst LABELS = [\n\t\"1 star — Poor\",\n\t\"2 stars — Fair\",\n\t\"3 stars — Good\",\n\t\"4 stars — Great\",\n\t\"5 stars — Excellent\",\n];\n\n/** The palette steps the stars paint with, which an app defines and a test stands in for. */\nconst PALETTE = {\n\t\"--ui-color-warning-600\": \"rgb(217, 119, 6)\",\n\t\"--ui-color-neutral-600\": \"rgb(82, 82, 91)\",\n\t\"--ui-color-neutral-400\": \"rgb(161, 161, 170)\",\n};\n\nlet mounted: RenderResult | undefined;\n\nbeforeAll(() => {\n\tfor (let [name, value] of Object.entries(PALETTE)) {\n\t\tdocument.documentElement.style.setProperty(name, value);\n\t}\n});\n\nafterAll(() => {\n\tfor (let name of Object.keys(PALETTE)) document.documentElement.style.removeProperty(name);\n});\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\n/** Each star's painted colour, lowest first. */\nfunction colors(root: HTMLElement): string[] {\n\treturn [...root.querySelectorAll<HTMLElement>(\"label\")].map(\n\t\t(label) => getComputedStyle(label).color,\n\t);\n}\n\n/** Which stars read as filled, lowest first, against the colour of the last star. */\nfunction filled(root: HTMLElement, empty: string): boolean[] {\n\treturn colors(root).map((color) => color !== empty);\n}\n\n/** Waits until a check passes, for a colour that eases between stars. */\nasync function until(check: () => boolean, timeout = 1000): Promise<void> {\n\tlet start = performance.now();\n\twhile (!check()) {\n\t\tif (performance.now() - start > timeout) throw new Error(\"timed out\");\n\t\tawait new Promise((resolve) => setTimeout(resolve, 20));\n\t}\n}\n\n/** Whether the stars read filled exactly as `expected`, lowest first. */\nfunction reads(root: HTMLElement, empty: string, expected: boolean[]): boolean {\n\treturn filled(root, empty).join() === expected.join();\n}\n\ndescribe(\"RatingInput\", () => {\n\ttest(\"renders one named radio per label in score order inside a fieldset\", () => {\n\t\tmounted = render(<RatingInput name=\"rating\" legend=\"Your rating\" required labels={LABELS} />);\n\t\tlet fieldset = mounted.container.querySelector(\"fieldset\")!;\n\t\texpect(fieldset.querySelector(\"legend\")!.textContent).toBe(\"Your rating\");\n\t\tlet radios = [...fieldset.querySelectorAll<HTMLInputElement>('input[type=\"radio\"]')];\n\t\texpect(radios.map((radio) => radio.value)).toEqual([\"1\", \"2\", \"3\", \"4\", \"5\"]);\n\t\texpect(radios.every((radio) => radio.name === \"rating\" && radio.required)).toBe(true);\n\t\texpect(radios[2]!.labels![0]!.textContent).toBe(\"3 stars — Good\");\n\t});\n\n\ttest(\"fills the picked star and every earlier one, and previews on hover\", async () => {\n\t\tmounted = render(<RatingInput name=\"rating\" legend=\"Your rating\" value={2} labels={LABELS} />);\n\t\tlet root = mounted.container;\n\t\tlet empty = colors(root)[4]!;\n\t\texpect(filled(root, empty)).toEqual([true, true, false, false, false]);\n\t\tlet labels = root.querySelectorAll<HTMLElement>(\"label\");\n\t\tawait userEvent.click(labels[3]!);\n\t\texpect(root.querySelector<HTMLInputElement>(\"input:checked\")!.value).toBe(\"4\");\n\t\tawait until(() => reads(root, empty, [true, true, true, true, false]));\n\t\tawait userEvent.hover(labels[0]!);\n\t\tawait until(() => reads(root, empty, [true, false, false, false, false]));\n\t\tawait userEvent.unhover(labels[0]!);\n\t\tawait until(() => reads(root, empty, [true, true, true, true, false]));\n\t});\n\n\ttest(\"steps up the scale with the arrow keys\", async () => {\n\t\tmounted = render(<RatingInput name=\"rating\" legend=\"Your rating\" value={3} labels={LABELS} />);\n\t\tlet checked = mounted.container.querySelector<HTMLInputElement>(\"input:checked\")!;\n\t\tchecked.focus();\n\t\tawait userEvent.keyboard(\"{ArrowRight}\");\n\t\texpect(mounted.container.querySelector<HTMLInputElement>(\"input:checked\")!.value).toBe(\"4\");\n\t});\n});\n"
17
+ }
18
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "rating",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "STAR_PATH",
7
+ "Rating"
8
+ ],
9
+ "source": {
10
+ "path": "rating.tsx",
11
+ "content": "/**\n * A score out of a few stars, read at a glance: a muted row of stars with a filled row laid\n * over it and clipped to the score's share, so 4.3 shows the fourth star whole and a third of\n * the fifth. Assistive tech reads one sentence instead of five pictures.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix, raw } from \"@sdxc/u/general\";\n\n/** The outline of a five-pointed star in a 24 × 24 box. */\nexport const STAR_PATH =\n\t\"M12 2.5l2.94 5.96 6.56.95-4.75 4.63 1.12 6.54L12 17.5l-5.87 3.08 1.12-6.54L2.5 9.41l6.56-.95L12 2.5z\";\n\n/** Top of the scale when `max` is left out. */\nconst DEFAULT_MAX = 5;\n\n/** Edge of one star, by size. */\nconst STAR_SIZE = { sm: \"0.875rem\", md: \"1.125rem\" } as const;\n\n/** Prop types for {@link Rating}. */\nexport namespace Rating {\n\t/** Props accepted by {@link Rating}; the host is a `<span>`. */\n\texport interface Props extends Omit<TagProps<\"span\">, \"children\"> {\n\t\t/** The score, fractional, between 0 and `max`; a value outside is held to the scale. */\n\t\tvalue: number;\n\t\t/** How many ratings the score averages, shown after the stars as \"(128)\". */\n\t\tcount?: number;\n\t\t/** @default 5 */\n\t\tmax?: number;\n\t\t/** @default \"md\" */\n\t\tsize?: \"sm\" | \"md\";\n\t\t/** What assistive tech reads; `{value}` and `{max}` fill in. @default \"{value} out of {max} stars\" */\n\t\tlabel?: string;\n\t\t/** Replaces the \"(128)\" text, such as \"128 reviews\" or a link to them. */\n\t\tcountLabel?: RemixNode;\n\t}\n}\n\n/** A row of `count` stars painted in the current colour. */\nfunction Stars(handle: Handle<{ count: number }>) {\n\treturn () => (\n\t\t<>\n\t\t\t{Array.from({ length: handle.props.count }, () => (\n\t\t\t\t<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\">\n\t\t\t\t\t<path d={STAR_PATH} fill=\"currentColor\" />\n\t\t\t\t</svg>\n\t\t\t))}\n\t\t</>\n\t);\n}\n\n/**\n * Renders the stars as one `role=\"img\"` whose name states the score, followed by the count.\n * Stars take `--ui-rating-color` (the warning tone by default) and empty ones the border tone,\n * so a theme recolours every rating at once.\n *\n * @example <Rating value={4.3} count={128} />\n * @example <Rating value={5} size=\"sm\" label=\"Rated {value} of {max}\" />\n */\nexport function Rating(handle: Handle<Rating.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcount,\n\t\t\tcountLabel,\n\t\t\tlabel = \"{value} out of {max} stars\",\n\t\t\tmax = DEFAULT_MAX,\n\t\t\tmix,\n\t\t\tsize = \"md\",\n\t\t\tvalue,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet score = Math.min(Math.max(value, 0), max);\n\t\tlet share = max > 0 ? (score / max) * 100 : 0;\n\t\tlet spoken = label\n\t\t\t.replace(\"{value}\", String(Math.round(score * 10) / 10))\n\t\t\t.replace(\"{max}\", String(max));\n\t\tlet star = STAR_SIZE[size];\n\t\tlet tail = countLabel ?? (count === undefined ? undefined : `(${count})`);\n\t\treturn (\n\t\t\t<span\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"rating\"\n\t\t\t\tdata-size={size}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tgap: \"0.375rem\",\n\t\t\t\t\t\t\tfontSize: size === \"sm\" ? \"0.8125rem\" : \"0.875rem\",\n\t\t\t\t\t\t\tlineHeight: \"1\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t\t\t\t\t\tverticalAlign: \"middle\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label={spoken}\n\t\t\t\t\tdata-slot=\"rating-stars\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\tflex: \"none\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-border-strong, var(--ui-neutral-border))\",\n\t\t\t\t\t\t\t\"& svg\": {\n\t\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\t\tflex: \"none\",\n\t\t\t\t\t\t\t\tinlineSize: star,\n\t\t\t\t\t\t\t\tblockSize: star,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<Stars count={max} />\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-slot=\"rating-fill\"\n\t\t\t\t\t\tstyle={{ inlineSize: `${Math.round(share * 100) / 100}%` }}\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\t\t\tinsetBlock: \"0\",\n\t\t\t\t\t\t\t\tinsetInlineStart: \"0\",\n\t\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\t\toverflow: \"clip\",\n\t\t\t\t\t\t\t\twhiteSpace: \"nowrap\",\n\t\t\t\t\t\t\t\tcolor: \"var(--ui-rating-color, var(--ui-warning-bg-solid))\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stars count={max} />\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t\t{tail === undefined ? null : (\n\t\t\t\t\t<span data-slot=\"rating-count\" mix={[raw({ fontVariantNumeric: \"tabular-nums\" })]}>\n\t\t\t\t\t\t{tail}\n\t\t\t\t\t</span>\n\t\t\t\t)}\n\t\t\t</span>\n\t\t);\n\t};\n}\n"
12
+ },
13
+ "test": {
14
+ "path": "rating.browser.test.tsx",
15
+ "content": "/**\n * Holds the star rating to its contract in a real browser: the filled row covers the score's\n * share, the score is read as one sentence held to the scale, and the count follows the stars.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterAll, afterEach, beforeAll, describe, expect, test } from \"vitest\";\n\nimport { Rating } from \"@sdxc/ui/rating\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The palette steps the stars paint with, which an app defines and a test stands in for. */\nconst PALETTE = {\n\t\"--ui-color-warning-600\": \"rgb(217, 119, 6)\",\n\t\"--ui-color-neutral-600\": \"rgb(82, 82, 91)\",\n\t\"--ui-color-neutral-400\": \"rgb(161, 161, 170)\",\n};\n\nlet mounted: RenderResult | undefined;\n\nbeforeAll(() => {\n\tfor (let [name, value] of Object.entries(PALETTE)) {\n\t\tdocument.documentElement.style.setProperty(name, value);\n\t}\n});\n\nafterAll(() => {\n\tfor (let name of Object.keys(PALETTE)) document.documentElement.style.removeProperty(name);\n});\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\ndescribe(\"Rating\", () => {\n\ttest(\"fills the score's share of the stars and reads it as one sentence\", () => {\n\t\tmounted = render(<Rating value={4.3} count={128} />);\n\t\tlet stars = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-stars\"]')!;\n\t\tlet fill = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-fill\"]')!;\n\t\texpect(stars.getAttribute(\"role\")).toBe(\"img\");\n\t\texpect(stars.getAttribute(\"aria-label\")).toBe(\"4.3 out of 5 stars\");\n\t\texpect(stars.querySelectorAll(\":scope > svg\")).toHaveLength(5);\n\t\tlet share = fill.getBoundingClientRect().width / stars.getBoundingClientRect().width;\n\t\texpect(share).toBeCloseTo(0.86, 2);\n\t\texpect(getComputedStyle(fill).color).not.toBe(getComputedStyle(stars).color);\n\t\texpect(mounted.container.querySelector('[data-slot=\"rating-count\"]')!.textContent).toBe(\n\t\t\t\"(128)\",\n\t\t);\n\t});\n\n\ttest(\"holds a score to the scale, names it in the caller's words and takes a count label\", () => {\n\t\tmounted = render(\n\t\t\t<Rating value={7} max={4} size=\"sm\" label=\"Rated {value} of {max}\" countLabel=\"12 reviews\" />,\n\t\t);\n\t\tlet fill = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-fill\"]')!;\n\t\tlet stars = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-stars\"]')!;\n\t\texpect(stars.getAttribute(\"aria-label\")).toBe(\"Rated 4 of 4\");\n\t\texpect(fill.getBoundingClientRect().width).toBeCloseTo(stars.getBoundingClientRect().width, 0);\n\t\texpect(mounted.container.textContent).toBe(\"12 reviews\");\n\t});\n\n\ttest(\"leaves the count out when none is given\", () => {\n\t\tmounted = render(<Rating value={0} />);\n\t\texpect(mounted.container.querySelector('[data-slot=\"rating-count\"]')).toBeNull();\n\t\texpect(\n\t\t\tmounted.container\n\t\t\t\t.querySelector<HTMLElement>('[data-slot=\"rating-fill\"]')!\n\t\t\t\t.getBoundingClientRect().width,\n\t\t).toBe(0);\n\t});\n});\n"
16
+ }
17
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "review-card",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [
5
+ "rating"
6
+ ],
7
+ "exports": [
8
+ "ReviewCard"
9
+ ],
10
+ "source": {
11
+ "path": "review-card.tsx",
12
+ "content": "/**\n * One customer review: the stars, a title and the words, then who wrote it and when, a\n * verified mark, what they bought, any photos, and room for a \"Was this helpful?\" form. Reviews\n * stack in a list separated by hairlines.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { CircleCheckIcon } from \"@sdxc/icons\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\n\nimport { Rating } from \"@sdxc/ui/rating\";\n\n/** Prop types for {@link ReviewCard}. */\nexport namespace ReviewCard {\n\t/** Props accepted by {@link ReviewCard}; the host is an `<article>`. */\n\texport interface Props extends Omit<TagProps<\"article\">, \"children\" | \"title\"> {\n\t\tauthor: RemixNode;\n\t\t/** The stars the reviewer gave, out of five. */\n\t\trating: number;\n\t\ttitle?: RemixNode;\n\t\tbody: RemixNode;\n\t\t/** When it was written, such as a `<time>` or a relative date. */\n\t\tdate: RemixNode;\n\t\t/** The mark of a confirmed purchase, such as \"Verified buyer\"; shown with a check. */\n\t\tverified?: RemixNode;\n\t\t/** What the reviewer bought, such as \"Size: 50×70 · Oak frame\". */\n\t\tmeta?: RemixNode;\n\t\t/** Photos the reviewer added, laid out by the caller. */\n\t\tmedia?: RemixNode;\n\t\t/** A slot at the end of the footer, such as a POST form voting the review helpful. */\n\t\thelpful?: RemixNode;\n\t}\n}\n\n/**\n * Renders the review as an `<article>`: small stars and the title on top, the body in reading\n * size, photos beneath, and a wrapping footer row of author, date, verified mark and purchase\n * with the helpful slot pushed to the end.\n *\n * @example\n * <ReviewCard author=\"Maya R.\" rating={5} title=\"Better in person\" body=\"The paper is heavy and the colours are rich.\" date=\"2 weeks ago\" verified=\"Verified buyer\" meta=\"50×70 · Oak frame\" />\n */\nexport function ReviewCard(handle: Handle<ReviewCard.Props>) {\n\treturn () => {\n\t\tlet { author, body, date, helpful, media, meta, mix, rating, title, verified, ...rest } =\n\t\t\thandle.props;\n\t\treturn (\n\t\t\t<article\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"review-card\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\tgap: \"0.625rem\",\n\t\t\t\t\t\t\tpaddingBlock: \"1.25rem\",\n\t\t\t\t\t\t\tborderBlockEnd: \"1px solid var(--ui-neutral-border)\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<div mix={[raw({ display: \"grid\", gap: \"0.375rem\" })]}>\n\t\t\t\t\t<Rating value={rating} size=\"sm\" />\n\t\t\t\t\t{title === undefined ? null : (\n\t\t\t\t\t\t<p\n\t\t\t\t\t\t\tdata-slot=\"review-card-title\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t\t\t\tfontSize: \"1rem\",\n\t\t\t\t\t\t\t\t\tfontWeight: \"650\",\n\t\t\t\t\t\t\t\t\tlineHeight: \"1.35\",\n\t\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{title}\n\t\t\t\t\t\t</p>\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"review-card-body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tfontSize: \"0.9375rem\",\n\t\t\t\t\t\t\tlineHeight: \"1.6\",\n\t\t\t\t\t\t\t\"& > p\": { margin: \"0\" },\n\t\t\t\t\t\t\t\"& > p + p\": { marginBlockStart: \"0.75em\" },\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{body}\n\t\t\t\t</div>\n\t\t\t\t{media === undefined ? null : <div data-slot=\"review-card-media\">{media}</div>}\n\t\t\t\t<footer\n\t\t\t\t\tdata-slot=\"review-card-footer\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\tflexWrap: \"wrap\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tcolumnGap: \"0.75rem\",\n\t\t\t\t\t\t\trowGap: \"0.375rem\",\n\t\t\t\t\t\t\tfontSize: \"0.8125rem\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<span mix={[raw({ fontWeight: \"600\", color: \"var(--ui-neutral-fg-emphasis)\" })]}>\n\t\t\t\t\t\t{author}\n\t\t\t\t\t</span>\n\t\t\t\t\t<span>{date}</span>\n\t\t\t\t\t{verified === undefined ? null : (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tdata-slot=\"review-card-verified\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\t\t\tgap: \"0.25rem\",\n\t\t\t\t\t\t\t\t\tcolor: \"var(--ui-success-fg)\",\n\t\t\t\t\t\t\t\t\t\"& > svg\": { inlineSize: \"0.875rem\", blockSize: \"0.875rem\" },\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<CircleCheckIcon aria-hidden=\"true\" />\n\t\t\t\t\t\t\t{verified}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t)}\n\t\t\t\t\t{meta === undefined ? null : <span data-slot=\"review-card-meta\">{meta}</span>}\n\t\t\t\t\t{helpful === undefined ? null : (\n\t\t\t\t\t\t<span data-slot=\"review-card-helpful\" mix={[raw({ marginInlineStart: \"auto\" })]}>\n\t\t\t\t\t\t\t{helpful}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t)}\n\t\t\t\t</footer>\n\t\t\t</article>\n\t\t);\n\t};\n}\n"
13
+ },
14
+ "test": {
15
+ "path": "review-card.browser.test.tsx",
16
+ "content": "/**\n * Holds the review card to its contract in a real browser: a review lays out its stars, title,\n * words and a footer with the helpful slot pushed to the end, and leaves out what it lacks.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\n\nimport { ReviewCard } from \"@sdxc/ui/review-card\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\ndescribe(\"ReviewCard\", () => {\n\ttest(\"lays out the stars, title, words and a footer with the helpful slot at the end\", () => {\n\t\tmounted = render(\n\t\t\t<div style={{ inlineSize: \"40rem\" }}>\n\t\t\t\t<ReviewCard\n\t\t\t\t\tauthor=\"Maya R.\"\n\t\t\t\t\trating={5}\n\t\t\t\t\ttitle=\"Better in person\"\n\t\t\t\t\tbody={<p>The paper is heavy and the colours are rich.</p>}\n\t\t\t\t\tdate=\"2 weeks ago\"\n\t\t\t\t\tverified=\"Verified buyer\"\n\t\t\t\t\tmeta=\"50×70 · Oak frame\"\n\t\t\t\t\thelpful={<button type=\"button\">Helpful (3)</button>}\n\t\t\t\t/>\n\t\t\t</div>,\n\t\t);\n\t\tlet card = mounted.container.querySelector<HTMLElement>('[data-slot=\"review-card\"]')!;\n\t\texpect(card.tagName).toBe(\"ARTICLE\");\n\t\texpect(card.querySelector('[role=\"img\"]')!.getAttribute(\"aria-label\")).toBe(\"5 out of 5 stars\");\n\t\texpect(card.querySelector('[data-slot=\"review-card-title\"]')!.textContent).toBe(\n\t\t\t\"Better in person\",\n\t\t);\n\t\tlet footer = card.querySelector<HTMLElement>('[data-slot=\"review-card-footer\"]')!;\n\t\texpect(footer.textContent).toBe(\"Maya R.2 weeks agoVerified buyer50×70 · Oak frameHelpful (3)\");\n\t\tlet helpful = footer.querySelector<HTMLElement>('[data-slot=\"review-card-helpful\"]')!;\n\t\texpect(Math.round(helpful.getBoundingClientRect().right)).toBe(\n\t\t\tMath.round(footer.getBoundingClientRect().right),\n\t\t);\n\t});\n\n\ttest(\"leaves out the parts it was not given\", () => {\n\t\tmounted = render(<ReviewCard author=\"Sam\" rating={3} body=\"Fine.\" date=\"Today\" />);\n\t\tlet card = mounted.container.querySelector<HTMLElement>('[data-slot=\"review-card\"]')!;\n\t\texpect(card.querySelector('[data-slot=\"review-card-title\"]')).toBeNull();\n\t\texpect(card.querySelector('[data-slot=\"review-card-verified\"]')).toBeNull();\n\t\texpect(card.querySelector('[data-slot=\"review-card-helpful\"]')).toBeNull();\n\t});\n});\n"
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "section-bar",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "SectionBar",
7
+ "SECTION_BAR_BLOCK_SIZE",
8
+ "SectionBarSpy"
9
+ ],
10
+ "source": {
11
+ "path": "section-bar.tsx",
12
+ "content": "/**\n * A sticky row of chips linking to the sections of one long page, such as a menu's\n * categories or a product's specs. The links work as plain anchors; once its island loads,\n * the chip of the section being read is marked and slides into view inside the row.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps } from \"remix/component\";\n\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { motionReduce } from \"@sdxc/u/responsive\";\nimport { when } from \"@sdxc/u/state\";\nimport { clientEntry } from \"remix/component\";\n\n/** Prop types for {@link SectionBar}. */\nexport namespace SectionBar {\n\t/** One section the bar links to. */\n\texport interface Item {\n\t\t/** The section element's `id`, which the chip links to as `#id`. */\n\t\tid: string;\n\t\tlabel: string;\n\t\t/** A count after the label, such as how many dishes the category holds. */\n\t\tcount?: number;\n\t}\n\n\t/** Props accepted by {@link SectionBar}; the host is a `<nav>`. */\n\texport interface Props extends Omit<TagProps<\"nav\">, \"children\"> {\n\t\t/** The bar's `id`, unique on the page; its island finds the bar by it. */\n\t\tid: string;\n\t\t/** The landmark's name, such as \"Menu categories\". */\n\t\tlabel: string;\n\t\titems: Item[];\n\t\t/**\n\t\t * Where the bar sticks, as a CSS length from the top of the viewport, such as the\n\t\t * height of a sticky top bar above it. Each section gives itself a `scroll-margin-top`\n\t\t * of at least this plus the bar's own height, so a jump lands below the bar.\n\t\t *\n\t\t * @default \"0px\"\n\t\t */\n\t\ttop?: string;\n\t}\n\n\t/** Props {@link SectionBarSpy} serializes for hydration. */\n\texport type SpyProps = {\n\t\t/** The bar's `id`. */\n\t\tbar: string;\n\t};\n}\n\n/** The bar's own height, which a section's `scroll-margin-top` adds to the sticky offset. */\nexport const SECTION_BAR_BLOCK_SIZE = \"3.25rem\";\n\n/**\n * Renders the bar: a `<nav>` holding a sideways-scrolling row of chip links, the first one\n * marked current until the island reads the scroll.\n *\n * @example\n * <SectionBar id=\"menu-bar\" label=\"Menu categories\" top=\"4rem\" items={[{ id: \"tacos\", label: \"Tacos\", count: 3 }]} />\n */\nexport function SectionBar(handle: Handle<SectionBar.Props>) {\n\treturn () => {\n\t\tlet { id, label, items, top = \"0px\", mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<nav\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\taria-label={label}\n\t\t\t\tdata-slot=\"section-bar\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"sticky\",\n\t\t\t\t\t\t\tinsetBlockStart: top,\n\t\t\t\t\t\t\tzIndex: \"10\",\n\t\t\t\t\t\t\tblockSize: SECTION_BAR_BLOCK_SIZE,\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tbackgroundColor: \"color-mix(in oklch, var(--ui-bg, Canvas) 92%, transparent)\",\n\t\t\t\t\t\t\tbackdropFilter: \"blur(12px) saturate(1.3)\",\n\t\t\t\t\t\t\tWebkitBackdropFilter: \"blur(12px) saturate(1.3)\",\n\t\t\t\t\t\t\tborderBlockEnd: \"1px solid var(--ui-neutral-border)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<ul\n\t\t\t\t\tdata-slot=\"section-bar-row\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\tgap: \"0.375rem\",\n\t\t\t\t\t\t\tinlineSize: \"100%\",\n\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t\tpaddingBlock: \"0.5rem\",\n\t\t\t\t\t\t\tpaddingInline: \"var(--ui-section-bar-inset, 1rem)\",\n\t\t\t\t\t\t\tlistStyle: \"none\",\n\t\t\t\t\t\t\toverflowX: \"auto\",\n\t\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\t\tscrollbarWidth: \"none\",\n\t\t\t\t\t\t\tscrollPaddingInline: \"var(--ui-section-bar-inset, 1rem)\",\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar\": { display: \"none\" },\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{items.map((item, index) => (\n\t\t\t\t\t\t<li mix={[raw({ flexShrink: \"0\" })]}>\n\t\t\t\t\t\t\t<a\n\t\t\t\t\t\t\t\thref={`#${item.id}`}\n\t\t\t\t\t\t\t\tdata-section={item.id}\n\t\t\t\t\t\t\t\taria-current={index === 0 ? \"true\" : undefined}\n\t\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\t\t\t\tgap: \"0.375rem\",\n\t\t\t\t\t\t\t\t\t\tblockSize: \"2.25rem\",\n\t\t\t\t\t\t\t\t\t\tpaddingInline: \"0.875rem\",\n\t\t\t\t\t\t\t\t\t\tborderRadius: \"999px\",\n\t\t\t\t\t\t\t\t\t\tfontSize: \"0.875rem\",\n\t\t\t\t\t\t\t\t\t\tfontWeight: \"550\",\n\t\t\t\t\t\t\t\t\t\twhiteSpace: \"nowrap\",\n\t\t\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg)\",\n\t\t\t\t\t\t\t\t\t\ttextDecoration: \"none\",\n\t\t\t\t\t\t\t\t\t\ttransition: \"background-color 160ms ease, color 160ms ease\",\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t\t\t\"&:hover\",\n\t\t\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\t\t\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-bg-tint)\",\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t\t\t\"&[aria-current='true']\",\n\t\t\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-on-solid)\",\n\t\t\t\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-bg-solid)\",\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t\t\t\"&:focus-visible\",\n\t\t\t\t\t\t\t\t\t\traw({ outline: \"2px solid var(--ui-brand-ring)\", outlineOffset: \"2px\" }),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tmotionReduce(raw({ transition: \"none\" })),\n\t\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{item.label}\n\t\t\t\t\t\t\t\t{item.count === undefined ? null : (\n\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\tdata-slot=\"section-bar-count\"\n\t\t\t\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\t\t\t\tfontVariantNumeric: \"tabular-nums\",\n\t\t\t\t\t\t\t\t\t\t\t\tfontWeight: \"500\",\n\t\t\t\t\t\t\t\t\t\t\t\topacity: \"0.65\",\n\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{item.count}\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t))}\n\t\t\t\t</ul>\n\t\t\t\t<SectionBarSpy bar={id} />\n\t\t\t</nav>\n\t\t);\n\t};\n}\n\n/**\n * The island that follows the scroll: on each frame the page scrolls, the current section is\n * the last one whose top has passed under the bar, and its chip is marked and scrolled into\n * the row's view. A page scrolled to its end marks the last section, however short it is.\n */\nexport const SectionBarSpy: EntryComponent<SectionBar.SpyProps> = clientEntry(\n\t\"@sdxc/ui/section-bar#SectionBarSpy\",\n\tfunction SectionBarSpy(handle: Handle<SectionBar.SpyProps>) {\n\t\tlet pending = false;\n\t\tlet current = \"\";\n\n\t\t/** Marks one chip current and brings it into the row's view. */\n\t\tfunction mark(bar: HTMLElement, links: HTMLAnchorElement[], id: string) {\n\t\t\tif (id === current) return;\n\t\t\tcurrent = id;\n\t\t\tlet row = bar.querySelector<HTMLElement>('[data-slot=\"section-bar-row\"]');\n\t\t\tfor (let link of links) {\n\t\t\t\tlet on = link.dataset.section === id;\n\t\t\t\tif (on) link.setAttribute(\"aria-current\", \"true\");\n\t\t\t\telse link.removeAttribute(\"aria-current\");\n\t\t\t\tif (on && row !== null) {\n\t\t\t\t\tlet left = link.offsetLeft - (row.clientWidth - link.offsetWidth) / 2;\n\t\t\t\t\tlet smooth = !matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\t\t\t\t\trow.scrollTo({ left: Math.max(left, 0), behavior: smooth ? \"smooth\" : \"instant\" });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/** Reads which section is under the bar now. */\n\t\tfunction update(bar: HTMLElement) {\n\t\t\tpending = false;\n\t\t\tlet links = [...bar.querySelectorAll<HTMLAnchorElement>(\"a[data-section]\")];\n\t\t\tlet line = bar.getBoundingClientRect().bottom + 8;\n\t\t\tlet found = links[0]?.dataset.section ?? \"\";\n\t\t\tfor (let link of links) {\n\t\t\t\tlet section = document.getElementById(link.dataset.section ?? \"\");\n\t\t\t\tif (section !== null && section.getBoundingClientRect().top <= line) {\n\t\t\t\t\tfound = link.dataset.section ?? found;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet atEnd =\n\t\t\t\tMath.ceil(window.scrollY + window.innerHeight) >= document.documentElement.scrollHeight - 2;\n\t\t\tif (atEnd) found = links.at(-1)?.dataset.section ?? found;\n\t\t\tmark(bar, links, found);\n\t\t}\n\n\t\thandle.queueTask(() => {\n\t\t\tlet bar = document.getElementById(handle.props.bar);\n\t\t\tif (bar === null || handle.signal.aborted) return;\n\t\t\tlet target = bar;\n\t\t\tlet schedule = () => {\n\t\t\t\tif (pending) return;\n\t\t\t\tpending = true;\n\t\t\t\trequestAnimationFrame(() => update(target));\n\t\t\t};\n\t\t\twindow.addEventListener(\"scroll\", schedule, { passive: true, signal: handle.signal });\n\t\t\twindow.addEventListener(\"resize\", schedule, { passive: true, signal: handle.signal });\n\t\t\tupdate(target);\n\t\t});\n\n\t\treturn () => <span hidden data-slot=\"section-bar-spy\" />;\n\t},\n);\n"
13
+ },
14
+ "test": {
15
+ "path": "section-bar.browser.test.tsx",
16
+ "content": "/**\n * Holds the section bar to its contract in a real browser: it links each chip to its section,\n * sticks at its `top`, marks the first chip before any scroll, and once its island runs marks\n * the section under the bar as the page scrolls, down to the last one at the page's end.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\n\nimport { SectionBar } from \"@sdxc/ui/section-bar\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\twindow.scrollTo(0, 0);\n});\n\n/** The sections the bar links to. */\nconst ITEMS: SectionBar.Item[] = [\n\t{ id: \"starters\", label: \"Starters\", count: 3 },\n\t{ id: \"mains\", label: \"Mains\", count: 5 },\n\t{ id: \"sides\", label: \"Sides\" },\n\t{ id: \"drinks\", label: \"Drinks\", count: 2 },\n];\n\n/** Mounts the bar over four tall sections and returns its chips. */\nfunction mount(): HTMLAnchorElement[] {\n\tmounted = render(\n\t\t<div>\n\t\t\t<SectionBar id=\"menu-bar\" label=\"Menu categories\" items={ITEMS} top=\"0px\" />\n\t\t\t{ITEMS.map((item, index) => (\n\t\t\t\t<section id={item.id} style={`block-size:${index === 3 ? 120 : 700}px`}>\n\t\t\t\t\t<h2>{item.label}</h2>\n\t\t\t\t</section>\n\t\t\t))}\n\t\t</div>,\n\t);\n\treturn [...mounted.container.querySelectorAll<HTMLAnchorElement>(\"a[data-section]\")];\n}\n\n/** Waits until a check passes, for an island that answers a scroll on the next frame. */\nasync function until(check: () => boolean, timeout = 2000): Promise<void> {\n\tlet start = performance.now();\n\twhile (!check()) {\n\t\tif (performance.now() - start > timeout) throw new Error(\"timed out\");\n\t\tawait new Promise((resolve) => requestAnimationFrame(resolve));\n\t}\n}\n\n/** Which chip is marked current. */\nfunction currentChip(links: HTMLAnchorElement[]): string | undefined {\n\treturn links.find((link) => link.getAttribute(\"aria-current\") === \"true\")?.dataset.section;\n}\n\ndescribe(\"SectionBar\", () => {\n\ttest(\"links every chip to its section and names its landmark\", () => {\n\t\tlet links = mount();\n\t\texpect(links.map((link) => link.getAttribute(\"href\"))).toEqual([\n\t\t\t\"#starters\",\n\t\t\t\"#mains\",\n\t\t\t\"#sides\",\n\t\t\t\"#drinks\",\n\t\t]);\n\t\tlet nav = mounted!.container.querySelector(\"nav\")!;\n\t\texpect(nav.getAttribute(\"aria-label\")).toBe(\"Menu categories\");\n\t\texpect(links[1]!.textContent).toBe(\"Mains5\");\n\t});\n\n\ttest(\"marks the first chip before the page scrolls\", () => {\n\t\tlet links = mount();\n\t\texpect(currentChip(links)).toBe(\"starters\");\n\t});\n\n\ttest(\"sticks to the top while its sections scroll under it\", async () => {\n\t\tmount();\n\t\tlet nav = mounted!.container.querySelector(\"nav\")!;\n\t\twindow.scrollTo(0, 900);\n\t\tawait until(() => Math.abs(nav.getBoundingClientRect().top) < 1);\n\t\texpect(getComputedStyle(nav).position).toBe(\"sticky\");\n\t});\n\n\ttest(\"follows the section under the bar, and the last one at the page's end\", async () => {\n\t\tlet links = mount();\n\t\tlet mains = document.getElementById(\"mains\")!;\n\t\twindow.scrollTo(0, mains.offsetTop - 20);\n\t\tawait until(() => currentChip(links) === \"mains\");\n\t\twindow.scrollTo(0, document.documentElement.scrollHeight);\n\t\tawait until(() => currentChip(links) === \"drinks\");\n\t\texpect(links.filter((link) => link.hasAttribute(\"aria-current\"))).toHaveLength(1);\n\t});\n});\n"
17
+ }
18
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "step-indicator",
3
+ "changedIn": "2026.11.22",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "StepIndicator"
7
+ ],
8
+ "source": {
9
+ "path": "step-indicator.tsx",
10
+ "content": "/**\n * Where the reader is in a flow spread over several pages, such as payee, amount and review:\n * a numbered row of steps joined by a line, done steps checked and linkable back, the current\n * one marked for assistive tech. On a narrow screen only the current step keeps its name.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { CheckIcon } from \"@sdxc/icons\";\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { atQuery } from \"@sdxc/u/responsive\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\n\n/** Prop types for {@link StepIndicator} and {@link StepIndicator.Step}. */\nexport namespace StepIndicator {\n\t/** Where a step stands: behind the reader, where they are, or still ahead. */\n\texport type State = \"complete\" | \"current\" | \"upcoming\";\n\n\t/** Props accepted by {@link StepIndicator}. */\n\texport interface Props extends TagProps<\"nav\"> {\n\t\t/** The landmark's name, such as \"Transfer steps\". */\n\t\tlabel: string;\n\t\t/** {@link StepIndicator.Step}s in order. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/** Props accepted by {@link StepIndicator.Step}. */\n\texport interface StepProps extends Omit<TagProps<\"li\">, \"children\"> {\n\t\t/** The step's place in the flow, from 1. */\n\t\tnumber: number;\n\t\tstate: State;\n\t\t/** The address of a done step, so the reader can go back and change it. */\n\t\thref?: string;\n\t\t/** The step's name. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Renders the row of steps as an ordered list in a `nav` spanning its container, so a\n * screen reader announces how many steps there are and which one is current.\n *\n * @example\n * <StepIndicator label=\"Transfer steps\">\n * \t<StepIndicator.Step number={1} state=\"complete\" href=\"/transfer\">Payee</StepIndicator.Step>\n * \t<StepIndicator.Step number={2} state=\"current\">Amount</StepIndicator.Step>\n * \t<StepIndicator.Step number={3} state=\"upcoming\">Review</StepIndicator.Step>\n * </StepIndicator>\n */\nexport function StepIndicator(handle: Handle<StepIndicator.Props>) {\n\treturn () => {\n\t\tlet { label, children, mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<nav\n\t\t\t\taria-label={label}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"step-indicator\"\n\t\t\t\tmix={mergeMix([raw({ containerType: \"inline-size\" })], mix)}\n\t\t\t>\n\t\t\t\t<ol\n\t\t\t\t\tmix={raw({\n\t\t\t\t\t\tlistStyle: \"none\",\n\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\tgap: \"0.5rem\",\n\t\t\t\t\t})}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</ol>\n\t\t\t</nav>\n\t\t);\n\t};\n}\n\n/**\n * Renders one step: its number (a check once done) in a circle, then its name, with a line\n * leading in from the step before. A done step with `href` is a link back to it.\n */\nStepIndicator.Step = function StepIndicatorStep(handle: Handle<StepIndicator.StepProps>) {\n\treturn () => {\n\t\tlet { number, state, href, children, mix, ...rest } = handle.props;\n\t\tlet marker = (\n\t\t\t<span\n\t\t\t\tdata-slot=\"step-indicator-marker\"\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tmix={raw({\n\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\tplaceItems: \"center\",\n\t\t\t\t\tflex: \"none\",\n\t\t\t\t\tinlineSize: \"1.5rem\",\n\t\t\t\t\tblockSize: \"1.5rem\",\n\t\t\t\t\tborderRadius: \"999px\",\n\t\t\t\t\tfontSize: \"0.75rem\",\n\t\t\t\t\tfontWeight: \"600\",\n\t\t\t\t\tborder: \"1.5px solid currentcolor\",\n\t\t\t\t})}\n\t\t\t>\n\t\t\t\t{state === \"complete\" ? <CheckIcon size={14} strokeWidth={3} /> : number}\n\t\t\t</span>\n\t\t);\n\t\tlet name = (\n\t\t\t<span\n\t\t\t\tdata-slot=\"step-indicator-label\"\n\t\t\t\tmix={[\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\traw({ whiteSpace: \"nowrap\" }),\n\t\t\t\t\twhen(\"[data-state='current'] &\", weight(\"semibold\")),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t);\n\t\tlet content = (\n\t\t\t<>\n\t\t\t\t{marker}\n\t\t\t\t{name}\n\t\t\t</>\n\t\t);\n\t\treturn (\n\t\t\t<li\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"step-indicator-step\"\n\t\t\t\tdata-state={state}\n\t\t\t\taria-current={state === \"current\" ? \"step\" : undefined}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tgap: \"0.5rem\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted, GrayText)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Every step after the first grows to share the row, and a line leads into it that\n\t\t\t\t\t\t * stretches across the gap; the line fills in the brand colour once the reader has\n\t\t\t\t\t\t * reached that step, so the row reads as how far along the flow they are.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&:not(:first-child)\", raw({ flex: \"1 1 0\", minInlineSize: \"0\" })),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&:not(:first-child)::before\",\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tcontent: \"''\",\n\t\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\t\tflex: \"1 1 auto\",\n\t\t\t\t\t\t\t\tminInlineSize: \"0.75rem\",\n\t\t\t\t\t\t\t\tblockSize: \"2px\",\n\t\t\t\t\t\t\t\tborderRadius: \"1px\",\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border, GrayText)\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&[data-state='complete']::before, &[data-state='current']::before\",\n\t\t\t\t\t\t\traw({ backgroundColor: \"var(--ui-brand-bg-solid, LinkText)\" }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&[data-state='complete'], &[data-state='current']\",\n\t\t\t\t\t\t\traw({ color: \"var(--ui-brand-fg, LinkText)\" }),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"&[data-state='complete'] [data-slot='step-indicator-marker'], &[data-state='current'] [data-slot='step-indicator-marker']\",\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-brand-bg-solid, LinkText)\",\n\t\t\t\t\t\t\t\tborderColor: \"var(--ui-brand-bg-solid, LinkText)\",\n\t\t\t\t\t\t\t\tcolor: \"var(--ui-brand-fg-on-solid, white)\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\"&[data-state='current']\", raw({ color: \"var(--ui-fg, CanvasText)\" })),\n\t\t\t\t\t\t/** Under 24rem a non-current step keeps only its numbered circle. */\n\t\t\t\t\t\tatQuery(\n\t\t\t\t\t\t\t\"(max-width: 24rem)\",\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t\"&:not([data-state='current']) [data-slot='step-indicator-label']\",\n\t\t\t\t\t\t\t\tvisuallyHidden(),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{href !== undefined && state === \"complete\" ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href}\n\t\t\t\t\t\tmix={raw({\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tgap: \"0.5rem\",\n\t\t\t\t\t\t\tcolor: \"inherit\",\n\t\t\t\t\t\t\ttextDecorationLine: \"none\",\n\t\t\t\t\t\t})}\n\t\t\t\t\t>\n\t\t\t\t\t\t{content}\n\t\t\t\t\t</a>\n\t\t\t\t) : (\n\t\t\t\t\tcontent\n\t\t\t\t)}\n\t\t\t</li>\n\t\t);\n\t};\n};\n"
11
+ },
12
+ "test": {
13
+ "path": "step-indicator.browser.test.tsx",
14
+ "content": "/**\n * Lays out a step indicator in a real browser: an ordered list in a named landmark, the\n * current step marked for assistive tech, done steps that link back, and only the current\n * step's name left visible in a narrow box.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\n\nimport { StepIndicator } from \"@sdxc/ui/step-indicator\";\n\nimport \"@sdxc/ui/reset.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n});\n\n/** Mounts a three-step flow on its second step in a host `width` pixels wide. */\nfunction mount(width: number): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tdocument.body.appendChild(host);\n\tmounted = render(\n\t\t<StepIndicator label=\"Transfer steps\">\n\t\t\t<StepIndicator.Step number={1} state=\"complete\" href=\"/transfer\">\n\t\t\t\tPayee\n\t\t\t</StepIndicator.Step>\n\t\t\t<StepIndicator.Step number={2} state=\"current\">\n\t\t\t\tAmount\n\t\t\t</StepIndicator.Step>\n\t\t\t<StepIndicator.Step number={3} state=\"upcoming\">\n\t\t\t\tReview\n\t\t\t</StepIndicator.Step>\n\t\t</StepIndicator>,\n\t\t{ container: host },\n\t);\n\treturn host;\n}\n\ndescribe(\"StepIndicator\", () => {\n\ttest(\"lists the steps in a named nav and marks the current one\", () => {\n\t\tlet host = mount(640);\n\t\tlet nav = host.querySelector(\"nav\")!;\n\t\texpect(nav.getAttribute(\"aria-label\")).toBe(\"Transfer steps\");\n\t\tlet steps = [...nav.querySelectorAll(\"ol > li\")];\n\t\texpect(steps.map((step) => step.getAttribute(\"data-state\"))).toEqual([\n\t\t\t\"complete\",\n\t\t\t\"current\",\n\t\t\t\"upcoming\",\n\t\t]);\n\t\texpect(steps[1]!.getAttribute(\"aria-current\")).toBe(\"step\");\n\t\texpect(steps[0]!.querySelector(\"a\")?.getAttribute(\"href\")).toBe(\"/transfer\");\n\t\texpect(steps[0]!.querySelector(\"svg\")).not.toBeNull();\n\t\texpect(steps[2]!.querySelector(\"a\")).toBeNull();\n\t});\n\n\ttest(\"fills the done and current markers with the theme's brand colour\", () => {\n\t\tdocument.documentElement.style.setProperty(\"--ui-brand-bg-solid\", \"rgb(200, 80, 40)\");\n\t\tlet host = mount(640);\n\t\tlet markers = [...host.querySelectorAll<HTMLElement>('[data-slot=\"step-indicator-marker\"]')];\n\t\texpect(markers.map((marker) => getComputedStyle(marker).backgroundColor)).toEqual([\n\t\t\t\"rgb(200, 80, 40)\",\n\t\t\t\"rgb(200, 80, 40)\",\n\t\t\t\"rgba(0, 0, 0, 0)\",\n\t\t]);\n\t\tdocument.documentElement.removeAttribute(\"style\");\n\t});\n\n\ttest(\"spans its container and fills the lines up to the current step\", () => {\n\t\tdocument.documentElement.style.setProperty(\"--ui-brand-bg-solid\", \"rgb(200, 80, 40)\");\n\t\tdocument.documentElement.style.setProperty(\"--ui-neutral-border\", \"rgb(220, 220, 220)\");\n\t\tlet host = mount(640);\n\t\tlet steps = [...host.querySelectorAll<HTMLElement>(\"ol > li\")];\n\t\tlet last = steps[2]!.getBoundingClientRect();\n\t\texpect(Math.round(last.right)).toBe(Math.round(host.getBoundingClientRect().right));\n\t\tlet lines = steps.map((step) => getComputedStyle(step, \"::before\"));\n\t\texpect(lines[1]!.backgroundColor).toBe(\"rgb(200, 80, 40)\");\n\t\texpect(lines[2]!.backgroundColor).toBe(\"rgb(220, 220, 220)\");\n\t\texpect(Number.parseFloat(lines[2]!.width)).toBeGreaterThan(100);\n\t\tdocument.documentElement.removeAttribute(\"style\");\n\t});\n\n\ttest(\"keeps every name visible where the row fits\", () => {\n\t\tlet host = mount(640);\n\t\tfor (let label of host.querySelectorAll<HTMLElement>('[data-slot=\"step-indicator-label\"]')) {\n\t\t\texpect(label.getBoundingClientRect().width).toBeGreaterThan(10);\n\t\t}\n\t});\n\n\ttest(\"keeps only the current name visible in a narrow box, without overflowing\", () => {\n\t\tlet host = mount(280);\n\t\tlet labels = [...host.querySelectorAll<HTMLElement>('[data-slot=\"step-indicator-label\"]')];\n\t\texpect(labels.map((label) => label.getBoundingClientRect().width > 10)).toEqual([\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t\tfalse,\n\t\t]);\n\t\texpect(labels[0]!.textContent).toBe(\"Payee\");\n\t\tlet list = host.querySelector(\"ol\")!;\n\t\texpect(list.scrollWidth).toBeLessThanOrEqual(280);\n\t});\n});\n"
15
+ }
16
+ }
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * The app's languages and message bundles, in one place so the page middleware, a job and an
3
- * email reach the same copy. Add a language by adding its bundle under `resources/locales/` and
4
- * listing it in {@link SUPPORTED_LANGUAGES}.
3
+ * email reach the same copy. Add a language by adding its bundle under `resources/locales/`, typed
4
+ * `satisfies LocaleMessages<typeof en>` so it holds English's keys, and listing it below.
5
5
  */
6
6
 
7
7
  import { createTranslator } from "@sdxc/i18n";
8
8
 
9
- import en from "~/resources/locales/en.json";
9
+ import en from "~/resources/locales/en";
10
10
 
11
11
  /** The languages a page can render in; a request asking for any other gets the fallback. */
12
12
  export const SUPPORTED_LANGUAGES = ["en"];
@@ -14,6 +14,13 @@ export const SUPPORTED_LANGUAGES = ["en"];
14
14
  /** The language that answers a request asking for none the app speaks, and any key a bundle lacks. */
15
15
  export const FALLBACK_LANGUAGE = "en";
16
16
 
17
+ declare module "@sdxc/i18n" {
18
+ /** Types every translator's keys and values by the English bundle, which every language mirrors. */
19
+ interface I18nTypes {
20
+ messages: typeof en;
21
+ }
22
+ }
23
+
17
24
  /** The message bundles, one per supported language, as MessageFormat 2 strings. */
18
25
  export const RESOURCES = { en };
19
26
 
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The app's English copy, the bundle every other language mirrors. Declared `as const`, so
3
+ * each message's text types the values its key takes wherever the app translates.
4
+ */
5
+
6
+ export default {
7
+ home: {
8
+ title: "Welcome",
9
+ body: "Edit {#file}app/http/controllers/home.tsx{/file}, or add a page with {#command}sdxc make controller <name>{/command}.",
10
+ },
11
+ notFound: {
12
+ title: "Not found",
13
+ back: "Back home",
14
+ },
15
+ } as const;
@@ -1,10 +0,0 @@
1
- {
2
- "home": {
3
- "title": "Welcome",
4
- "body": "Edit {#file}app/http/controllers/home.tsx{/file}, or add a page with {#command}sdxc make controller <name>{/command}."
5
- },
6
- "notFound": {
7
- "title": "Not found",
8
- "back": "Back home"
9
- }
10
- }