@sdxc/kit 2026.11.26 → 2026.11.29

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.
Files changed (39) hide show
  1. package/changelog.jsonl +193 -0
  2. package/dist/pkg/catalog.js +1 -0
  3. package/dist/scaffold/render.js +2 -2
  4. package/package.json +2 -2
  5. package/registry/ui/anchor-heading.json +19 -0
  6. package/registry/ui/autocomplete.json +3 -3
  7. package/registry/ui/banner.json +3 -3
  8. package/registry/ui/button.json +3 -3
  9. package/registry/ui/callout.json +16 -0
  10. package/registry/ui/checkbox.json +2 -2
  11. package/registry/ui/code-block.json +18 -0
  12. package/registry/ui/confirm.json +3 -3
  13. package/registry/ui/copy-button.json +14 -0
  14. package/registry/ui/date-field.json +4 -7
  15. package/registry/ui/date-picker.json +3 -5
  16. package/registry/ui/date-range-picker.json +2 -3
  17. package/registry/ui/dialog-dismiss.json +2 -2
  18. package/registry/ui/field-parts.json +30 -0
  19. package/registry/ui/filter-links.json +16 -0
  20. package/registry/ui/form.json +3 -3
  21. package/registry/ui/lightbox.json +3 -3
  22. package/registry/ui/listbox.json +2 -2
  23. package/registry/ui/media-grid.json +3 -3
  24. package/registry/ui/pager.json +16 -0
  25. package/registry/ui/property-list.json +3 -3
  26. package/registry/ui/radio-group.json +2 -2
  27. package/registry/ui/range-calendar.json +2 -2
  28. package/registry/ui/range-months.json +3 -3
  29. package/registry/ui/rating-input.json +3 -3
  30. package/registry/ui/rating.json +3 -3
  31. package/registry/ui/review-card.json +3 -3
  32. package/registry/ui/search-field.json +6 -3
  33. package/registry/ui/section-bar.json +3 -3
  34. package/registry/ui/sidebar.json +2 -2
  35. package/registry/ui/table-of-contents.json +17 -0
  36. package/registry/ui/text-field.json +5 -9
  37. package/registry/ui/time-field.json +4 -7
  38. package/registry/ui/timeline.json +3 -3
  39. package/registry/ui/typeset.json +2 -2
@@ -69,6 +69,7 @@ export const PACKAGES_WITHOUT_COMMAND_LINES = [
69
69
  "cloudflare-mocks",
70
70
  "cloudflare-pricing",
71
71
  "codemod",
72
+ "color",
72
73
  "csv",
73
74
  "data-model",
74
75
  "data-table-d1",
@@ -378,7 +378,7 @@ function formControl(field, copy, plural) {
378
378
  return `<Checkbox name=${name} value="true" defaultChecked={${value} === "true"}>\n\t{${label}}\n</Checkbox>`;
379
379
  }
380
380
  if (field.type === "date") {
381
- return `<DateField label={${label}} name=${name} defaultValue={${value}}${required} />`;
381
+ return `<DateField name=${name} defaultValue={${value}}${required}>\n\t<DateField.Label>{${label}}</DateField.Label>\n</DateField>`;
382
382
  }
383
383
  if (field.type === "text" || field.type === "timestamp") {
384
384
  let id = JSON.stringify(`${plural}-${field.column}`);
@@ -398,7 +398,7 @@ function formControl(field, copy, plural) {
398
398
  url: "url",
399
399
  };
400
400
  let type = types[field.type] === undefined ? "" : ` type="${types[field.type]}"`;
401
- return `<TextField${type} label={${label}} name=${name} defaultValue={${value}}${required} />`;
401
+ return `<TextField${type} name=${name} defaultValue={${value}}${required}>\n\t<TextField.Label>{${label}}</TextField.Label>\n</TextField>`;
402
402
  }
403
403
  /** One line per field, each indented by `depth` tabs. */
404
404
  function lines(fields, depth, line) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdxc/kit",
3
- "version": "2026.11.26",
3
+ "version": "2026.11.29",
4
4
  "description": "The sdxc command line: start a Remix v3 app, generate its files, copy UI components into it and upgrade it",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -33,7 +33,7 @@
33
33
  "peerDependencies": {
34
34
  "remix": "3.2.0"
35
35
  },
36
- "gitHead": "a6d84fa08849d9318c95ac92e15cc77973a91561",
36
+ "gitHead": "53d47034d778b0a422b06fd515a375bbfbb122d5",
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "anchor-heading",
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [
5
+ "heading-scope"
6
+ ],
7
+ "exports": [
8
+ "ANCHOR_HEADING_SCROLL_MARGIN",
9
+ "AnchorHeading"
10
+ ],
11
+ "source": {
12
+ "path": "anchor-heading.tsx",
13
+ "content": "/**\n * A docs section heading a reader can link to: it carries an `id`, a `#` link that shows\n * on hover and focus, room above it for a sticky header, and a short highlight when a jump\n * lands on it. Its typography comes from the surrounding prose, such as `Typeset`.\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 { animationHost, keyframes } from \"@sdxc/u/animation\";\nimport { fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { motionSafe } from \"@sdxc/u/responsive\";\nimport { mis } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { textDecoration, weight } from \"@sdxc/u/typography\";\n\nimport type { HeadingLevel } from \"@sdxc/ui/heading-scope\";\n\nimport { readAmbientLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Custom property setting the space a jump leaves above the heading; set it on any\n * ancestor to the sticky header's height plus breathing room.\n */\nexport const ANCHOR_HEADING_SCROLL_MARGIN = \"--ui-docs-scroll-margin\";\n\n/** Level with no `level` prop and no `HeadingScope` around the heading: a page section. */\nconst DEFAULT_LEVEL: HeadingLevel = 2;\n\n/** `@keyframes` name of the highlight a heading shows when it is the URL's target. */\nconst FLASH = \"ui-anchor-heading-flash\";\n\n/**\n * Prop types for {@link AnchorHeading}.\n */\nexport namespace AnchorHeading {\n\t/** Props accepted by {@link AnchorHeading}. */\n\texport interface Props extends Omit<TagProps<\"h2\">, \"id\"> {\n\t\t/** Fragment the heading answers to, and the `#` link's target. */\n\t\tid: string;\n\t\t/** Defaults to the ambient `HeadingScope` level, else {@link DEFAULT_LEVEL}. */\n\t\tlevel?: HeadingLevel;\n\t\t/** Accessible name of the `#` link, such as \"Link to Install\". */\n\t\tlinkLabel: string;\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Renders the heading with its `#` link after the text. The link stays in the tab order\n * at all times, shows on hover of the heading or on its own focus, and shows always on\n * devices without hover. Jumps clear `--ui-docs-scroll-margin` (default `5rem`).\n *\n * @param handle Runtime handle carrying the heading's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <AnchorHeading id=\"install\" linkLabel=\"Link to Install\">Install</AnchorHeading>\n */\nexport function AnchorHeading(handle: Handle<AnchorHeading.Props>) {\n\treturn () => {\n\t\tlet { id, level, linkLabel, children, mix, ...rest } = handle.props;\n\t\tlet Tag = TAG_BY_LEVEL[level ?? readAmbientLevel(handle) ?? DEFAULT_LEVEL];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\tdata-slot=\"anchor-heading\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({ scrollMarginBlockStart: `var(${ANCHOR_HEADING_SCROLL_MARGIN}, 5rem)` }),\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\tkeyframes(FLASH, {\n\t\t\t\t\t\t\tfrom: { backgroundColor: \"var(--ui-brand-bg-tint)\" },\n\t\t\t\t\t\t\tto: { backgroundColor: \"transparent\" },\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tmotionSafe(\n\t\t\t\t\t\t\twhen(\"&:target\", animationHost(FLASH, { duration: \"1.2s\", easing: \"ease-out\" })),\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{children}\n\t\t\t\t<a\n\t\t\t\t\thref={`#${id}`}\n\t\t\t\t\taria-label={linkLabel}\n\t\t\t\t\tdata-slot=\"anchor-heading-link\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tmis(\"0.35em\"),\n\t\t\t\t\t\tweight(\"normal\"),\n\t\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\thover(fg(\"brand\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Hidden and shown in one rule, so the shown states always outrank the\n\t\t\t\t\t\t * hidden one whatever order the stylesheet layers land in.\n\t\t\t\t\t\t */\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\topacity: 0,\n\t\t\t\t\t\t\t\"&:focus-visible, &:where([data-slot='anchor-heading']:hover > *)\": { opacity: 1 },\n\t\t\t\t\t\t\t\"@media (hover: none)\": { opacity: 1 },\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tmotionSafe(transition(\"opacity, color\", { duration: 150 })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<span aria-hidden=\"true\">#</span>\n\t\t\t\t</a>\n\t\t\t</Tag>\n\t\t);\n\t};\n}\n"
14
+ },
15
+ "test": {
16
+ "path": "anchor-heading.browser.test.tsx",
17
+ "content": "/**\n * Runs the anchor heading in a real browser: the `#` link is named, reachable by Tab and\n * shown on focus and on hover, a jump clears the scroll-margin property, `:target` flashes\n * except under reduced motion, and the level follows the HeadingScope.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, beforeEach, describe, expect, test } from \"vitest\";\nimport { cdp, page, userEvent } from \"vitest/browser\";\n\nimport { AnchorHeading } from \"@sdxc/ui/anchor-heading\";\nimport { HeadingScope } from \"@sdxc/ui/heading-scope\";\n\n/** Mounts `node` in a host `width` pixels wide and returns the host. */\nfunction mount(node: JSX.Element, width = 720): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tdocument.body.appendChild(host);\n\trender(node, { container: host });\n\treturn host;\n}\n\n/** The heading's `#` link. */\nfunction link(host: HTMLElement): HTMLAnchorElement {\n\treturn host.querySelector<HTMLAnchorElement>('[data-slot=\"anchor-heading-link\"]')!;\n}\n\nbeforeEach(async () => {\n\tawait page.viewport(1024, 768);\n});\n\nafterEach(async () => {\n\tdocument.body.replaceChildren();\n\thistory.replaceState(null, \"\", location.pathname + location.search);\n\tawait cdp().send(\"Emulation.setEmulatedMedia\", { features: [] });\n});\n\ndescribe(\"AnchorHeading\", () => {\n\ttest(\"links to its own id under the given accessible name\", () => {\n\t\tlet host = mount(\n\t\t\t<AnchorHeading id=\"install\" linkLabel=\"Link to Install\">\n\t\t\t\tInstall\n\t\t\t</AnchorHeading>,\n\t\t);\n\t\tlet heading = host.querySelector(\"h2\")!;\n\n\t\texpect(heading.id).toBe(\"install\");\n\t\texpect(link(host).getAttribute(\"href\")).toBe(\"#install\");\n\t\texpect(link(host).getAttribute(\"aria-label\")).toBe(\"Link to Install\");\n\t});\n\n\ttest(\"keeps the link hidden at rest and shows it when Tab reaches it\", async () => {\n\t\tlet host = mount(\n\t\t\t<AnchorHeading id=\"install\" linkLabel=\"Link to Install\">\n\t\t\t\tInstall\n\t\t\t</AnchorHeading>,\n\t\t);\n\n\t\texpect(getComputedStyle(link(host)).opacity).toBe(\"0\");\n\t\tawait userEvent.tab();\n\t\texpect(document.activeElement).toBe(link(host));\n\t\tawait expect.poll(() => getComputedStyle(link(host)).opacity).toBe(\"1\");\n\t});\n\n\ttest(\"shows the link while the heading is hovered\", async () => {\n\t\tlet host = mount(\n\t\t\t<AnchorHeading id=\"install\" linkLabel=\"Link to Install\">\n\t\t\t\tInstall\n\t\t\t</AnchorHeading>,\n\t\t);\n\n\t\tawait userEvent.hover(host.querySelector(\"h2\")!);\n\t\tawait expect.poll(() => getComputedStyle(link(host)).opacity).toBe(\"1\");\n\t});\n\n\ttest(\"clears the scroll margin set through the custom property\", () => {\n\t\tlet host = mount(\n\t\t\t<div style=\"--ui-docs-scroll-margin: 72px\">\n\t\t\t\t<AnchorHeading id=\"install\" linkLabel=\"Link to Install\">\n\t\t\t\t\tInstall\n\t\t\t\t</AnchorHeading>\n\t\t\t</div>,\n\t\t);\n\n\t\texpect(getComputedStyle(host.querySelector(\"h2\")!).scrollMarginTop).toBe(\"72px\");\n\t});\n\n\ttest(\"flashes when it is the URL's target, and holds still under reduced motion\", async () => {\n\t\tlet host = mount(\n\t\t\t<AnchorHeading id=\"install\" linkLabel=\"Link to Install\">\n\t\t\t\tInstall\n\t\t\t</AnchorHeading>,\n\t\t);\n\t\tlet heading = host.querySelector(\"h2\")!;\n\n\t\tlocation.hash = \"install\";\n\t\texpect(getComputedStyle(heading).animationName).toBe(\"ui-anchor-heading-flash\");\n\n\t\tawait cdp().send(\"Emulation.setEmulatedMedia\", {\n\t\t\tfeatures: [{ name: \"prefers-reduced-motion\", value: \"reduce\" }],\n\t\t});\n\t\texpect(getComputedStyle(heading).animationName).toBe(\"none\");\n\t});\n\n\ttest(\"takes the HeadingScope level, and an explicit level over it\", () => {\n\t\tlet host = mount(\n\t\t\t<HeadingScope level={3}>\n\t\t\t\t<AnchorHeading id=\"a\" linkLabel=\"Link to A\">\n\t\t\t\t\tA\n\t\t\t\t</AnchorHeading>\n\t\t\t\t<AnchorHeading id=\"b\" level={4} linkLabel=\"Link to B\">\n\t\t\t\t\tB\n\t\t\t\t</AnchorHeading>\n\t\t\t</HeadingScope>,\n\t\t);\n\n\t\texpect(host.querySelector(\"#a\")?.tagName).toBe(\"H3\");\n\t\texpect(host.querySelector(\"#b\")?.tagName).toBe(\"H4\");\n\t});\n});\n"
18
+ }
19
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autocomplete",
3
- "changedIn": "2026.11.22",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [
5
5
  "input"
6
6
  ],
@@ -10,10 +10,10 @@
10
10
  ],
11
11
  "source": {
12
12
  "path": "autocomplete.tsx",
13
- "content": "/**\n * A text field with a styled suggestion list under it, for a \"Where are you going?\" box or an\n * address field. The server renders a plain input with a native `<datalist>`, and the\n * {@link AutocompleteSync} island upgrades it to a combobox over a filtered, iconed listbox.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { bg, fg } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix, raw } from \"@sdxc/u/general\";\nimport { hstack } from \"@sdxc/u/layout\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { text, truncate } from \"@sdxc/u/typography\";\nimport { clientEntry } from \"remix/component\";\n\nimport { autocomplete } from \"@sdxc/ui/mixins\";\nimport { floatingSurface, surfaceInset } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { Input } from \"@sdxc/ui/input\";\n\nexport { AUTOCOMPLETE_SELECT_EVENT } from \"@sdxc/ui/mixins\";\nexport type { AutocompleteSelectDetail } from \"@sdxc/ui/mixins\";\n\n/** What the list says when the typed text matches no option and the caller names nothing. */\nconst DEFAULT_EMPTY_LABEL = \"No matches\";\n\n/** Prop types for {@link Autocomplete}. */\nexport namespace Autocomplete {\n\t/** One suggestion: what the hidden field submits, what the field shows, and how it reads. */\n\texport interface Option {\n\t\t/** Submitted through `valueName` when picked, such as a place id. */\n\t\tvalue: string;\n\t\t/** Shown in the list and written into the field when picked. */\n\t\tlabel: string;\n\t\t/** A second line under the label, also searched as the reader types. */\n\t\tdescription?: string;\n\t\t/** A glyph before the label, such as an icon from `@sdxc/icons`. */\n\t\ticon?: RemixNode;\n\t}\n\n\t/** Per-part styling for the elements the autocomplete composes. */\n\texport interface PartsProps {\n\t\t/** The text field. */\n\t\tinput?: TagProps<\"input\">[\"mix\"];\n\t\t/** The floating list surface. */\n\t\tlist?: TagProps<\"div\">[\"mix\"];\n\t\t/** Every option row. */\n\t\toption?: TagProps<\"div\">[\"mix\"];\n\t}\n\n\t/**\n\t * Every native `<input>` attribute but the ones the combobox owns, which land on the field;\n\t * `mix` styles the wrapper around the field and its list.\n\t */\n\texport interface Props extends Omit<\n\t\tTagProps<\"input\">,\n\t\t\"type\" | \"list\" | \"role\" | \"children\" | \"mix\" | \"value\" | \"color\"\n\t> {\n\t\t/** The field's `id`, from which every other id the autocomplete needs derives. */\n\t\tid: string;\n\t\t/** The field's accessible name; pass `aria-labelledby` instead to point at a visible label. */\n\t\tlabel?: string;\n\t\t/** The suggestions, in the order the list shows them. */\n\t\toptions: Array<Option>;\n\t\t/** Shown at the top of the list while the field is empty, such as \"Suggested destinations\". */\n\t\theading?: RemixNode;\n\t\t/** Shown in the list when nothing matches. @default \"No matches\" */\n\t\temptyLabel?: RemixNode;\n\t\t/** Names a hidden field carrying the picked option's `value`, emptied once the text is edited. */\n\t\tvalueName?: string;\n\t\t/**\n\t\t * `\"field\"` draws the bordered input; `\"bare\"` drops its border, background, padding and focus\n\t\t * ring, for a field set inside a pill that draws them with `:focus-within`.\n\t\t * @default \"field\"\n\t\t */\n\t\tvariant?: \"field\" | \"bare\";\n\t\t/** Styling for the wrapper. */\n\t\tmix?: TagProps<\"div\">[\"mix\"];\n\t\t/** Per-part styling. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Renders the field, its `<datalist>`, a hidden list of styled options and the island that\n * swaps one for the other. Picking fires `change` and an `autocomplete-select` event on the\n * field with `{ value, label }`; Enter on an option never submits the form.\n *\n * @example\n * <Autocomplete id=\"where\" name=\"where\" label=\"Where to?\" heading=\"Suggested destinations\"\n * \tvalueName=\"placeId\" options={[{ value: \"lis\", label: \"Lisbon\", description: \"Portugal\" }]} />\n * @example\n * <Autocomplete id=\"q\" name=\"q\" variant=\"bare\" aria-labelledby=\"where-label\" options={places} />\n */\nexport function Autocomplete(handle: Handle<Autocomplete.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\toptions,\n\t\t\theading,\n\t\t\temptyLabel = DEFAULT_EMPTY_LABEL,\n\t\t\tvalueName,\n\t\t\tvariant = \"field\",\n\t\t\tmix,\n\t\t\tparts,\n\t\t\tautoComplete = \"off\",\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet labelledBy = rest[\"aria-labelledby\"];\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\t{ \"aria-label\": label, \"aria-labelledby\": labelledBy },\n\t\t\t\"Autocomplete: pass `label` or `aria-labelledby` so the field and its list have a name.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"autocomplete\"\n\t\t\t\tdata-variant={variant}\n\t\t\t\tmix={mergeMix([raw({ position: \"relative\", inlineSize: \"100%\", minInlineSize: \"0\" })], mix)}\n\t\t\t>\n\t\t\t\t<Input\n\t\t\t\t\t{...rest}\n\t\t\t\t\tid={id}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tlist={`${id}-suggestions`}\n\t\t\t\t\tdata-autocomplete-input=\"\"\n\t\t\t\t\tmix={mergeMix(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\traw({ minInlineSize: \"0\", textOverflow: \"ellipsis\" }),\n\t\t\t\t\t\t\twhen('[data-variant=\"bare\"] > &', [\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tborderWidth: \"0\",\n\t\t\t\t\t\t\t\t\tbackgroundColor: \"transparent\",\n\t\t\t\t\t\t\t\t\tpaddingInline: \"0\",\n\t\t\t\t\t\t\t\t\toutline: \"none\",\n\t\t\t\t\t\t\t\t\tboxShadow: \"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],\n\t\t\t\t\t\tparts?.input,\n\t\t\t\t\t)}\n\t\t\t\t/>\n\t\t\t\t{valueName ? (\n\t\t\t\t\t<input type=\"hidden\" name={valueName} value=\"\" data-autocomplete-value=\"\" />\n\t\t\t\t) : null}\n\t\t\t\t<datalist id={`${id}-suggestions`}>\n\t\t\t\t\t{options.map((option) => (\n\t\t\t\t\t\t<option value={option.label} />\n\t\t\t\t\t))}\n\t\t\t\t</datalist>\n\t\t\t\t<div\n\t\t\t\t\tid={`${id}-popup`}\n\t\t\t\t\tpopover=\"manual\"\n\t\t\t\t\tdata-autocomplete-popup=\"\"\n\t\t\t\t\tmix={mergeMix(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tfloatingSurface(),\n\t\t\t\t\t\t\tsurfaceInset(),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tposition: \"fixed\",\n\t\t\t\t\t\t\t\tinset: \"auto\",\n\t\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t\t\tboxSizing: \"border-box\",\n\t\t\t\t\t\t\t\toverflowY: \"auto\",\n\t\t\t\t\t\t\t\toverscrollBehavior: \"contain\",\n\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\twhen(\"&:not(:popover-open)\", raw({ display: \"none !important\" })),\n\t\t\t\t\t\t],\n\t\t\t\t\t\tparts?.list,\n\t\t\t\t\t)}\n\t\t\t\t>\n\t\t\t\t\t{heading ? (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tid={`${id}-heading`}\n\t\t\t\t\t\t\tdata-autocomplete-heading=\"\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\tpaddingBlock: \"0.375rem\",\n\t\t\t\t\t\t\t\t\tfontSize: \"0.75rem\",\n\t\t\t\t\t\t\t\t\tfontWeight: \"600\",\n\t\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\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{heading}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<div\n\t\t\t\t\t\tid={`${id}-listbox`}\n\t\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\t\taria-label={label}\n\t\t\t\t\t\taria-labelledby={labelledBy}\n\t\t\t\t\t\tdata-autocomplete-listbox=\"\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{options.map((option, index) => (\n\t\t\t\t\t\t\t<AutocompleteOption\n\t\t\t\t\t\t\t\tid={`${id}-option-${index}`}\n\t\t\t\t\t\t\t\toption={option}\n\t\t\t\t\t\t\t\tmix={parts?.option}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-autocomplete-empty=\"\"\n\t\t\t\t\t\thidden\n\t\t\t\t\t\tmix={[pi(3), pb(2), text(\"sm\"), fg(\"neutral.muted\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{emptyLabel}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<AutocompleteSync />\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * One row of the list: the icon in a tinted square, the label over its description, both\n * truncating so a long place name never widens the list. A row is at least the pointer\n * target size tall, which grows to 44px on a touch screen.\n */\nfunction AutocompleteOption(\n\thandle: Handle<{ id: string; option: Autocomplete.Option; mix?: TagProps<\"div\">[\"mix\"] }>,\n) {\n\treturn () => {\n\t\tlet { id, option, mix } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tid={id}\n\t\t\t\trole=\"option\"\n\t\t\t\taria-selected=\"false\"\n\t\t\t\tdata-autocomplete-option=\"\"\n\t\t\t\tdata-value={option.value}\n\t\t\t\tdata-label={option.label}\n\t\t\t\tdata-description={option.description}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\thstack({ align: \"center\", gap: 3 }),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tpb(1.5),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tminBlockSize: \"max(2.75rem, var(--ui-target-size))\",\n\t\t\t\t\t\t\tscrollMarginBlock: \"0.25rem\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.bg-tint-pressed\")]),\n\t\t\t\t\t\twhen(\"&[hidden]\", raw({ display: \"none\" })),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\"& mark\",\n\t\t\t\t\t\t\traw({ backgroundColor: \"transparent\", color: \"inherit\", fontWeight: \"700\" }),\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{option.icon ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\traw({\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\tflexShrink: \"0\",\n\t\t\t\t\t\t\t\tinlineSize: \"2rem\",\n\t\t\t\t\t\t\t\tblockSize: \"2rem\",\n\t\t\t\t\t\t\t\t\"& svg\": { inlineSize: \"1rem\", blockSize: \"1rem\" },\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{option.icon}\n\t\t\t\t\t</span>\n\t\t\t\t) : null}\n\t\t\t\t<span mix={[raw({ display: \"grid\", minInlineSize: \"0\", flex: \"1\" })]}>\n\t\t\t\t\t<span data-autocomplete-label=\"\" mix={[truncate(), text(\"sm\"), fg(\"neutral.emphasis\")]}>\n\t\t\t\t\t\t{option.label}\n\t\t\t\t\t</span>\n\t\t\t\t\t{option.description ? (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tdata-autocomplete-description=\"\"\n\t\t\t\t\t\t\tmix={[truncate(), text(\"xs\"), fg(\"neutral.muted\")]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{option.description}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The island inside every {@link Autocomplete}: once hydrated it drops the field's datalist,\n * makes the field a combobox and opens the styled list on focus and typing. It renders only a\n * hidden marker, so the field and options stay server markup styled by the caller's mixins.\n *\n * @example <AutocompleteSync />\n */\nexport const AutocompleteSync: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/autocomplete#AutocompleteSync\",\n\tfunction AutocompleteSync() {\n\t\treturn () => <span hidden mix={[autocomplete()]} />;\n\t},\n);\n"
13
+ "content": "/**\n * A text field with a styled suggestion list under it, for a \"Where are you going?\" box or an\n * address field. The server renders a plain input with a native `<datalist>`, and the\n * {@link AutocompleteSync} island upgrades it to a combobox over a filtered, iconed listbox.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { EntryComponent, Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { bg, fg } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix, raw } from \"@sdxc/u/general\";\nimport { hstack } from \"@sdxc/u/layout\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { text, truncate } from \"@sdxc/u/typography\";\nimport { clientEntry } from \"remix/component\";\n\nimport { autocomplete } from \"@sdxc/ui/mixins\";\nimport { floatingSurface, surfaceInset } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { Input } from \"@sdxc/ui/input\";\n\nexport { AUTOCOMPLETE_SELECT_EVENT } from \"@sdxc/ui/mixins\";\nexport type { AutocompleteSelectDetail } from \"@sdxc/ui/mixins\";\n\n/** What an {@link Autocomplete.Empty} says when the caller names nothing. */\nconst DEFAULT_EMPTY_LABEL = \"No matches\";\n\n/** Prop types for {@link Autocomplete} and its parts. */\nexport namespace Autocomplete {\n\t/** One suggestion: what the hidden field submits, what the field shows, and how it reads. */\n\texport interface Option {\n\t\t/** Submitted through `valueName` when picked, such as a place id. */\n\t\tvalue: string;\n\t\t/** Shown in the list and written into the field when picked. */\n\t\tlabel: string;\n\t\t/** A second line under the label, also searched as the reader types. */\n\t\tdescription?: string;\n\t\t/** A glyph before the label, such as an icon from `@sdxc/icons`. */\n\t\ticon?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<input>` attribute but the ones the combobox owns, which land on the field;\n\t * `mix` styles the wrapper around the field and its list. The field's type size and height\n\t * read `--ui-autocomplete-font-size` and `--ui-autocomplete-block-size`, set on any ancestor.\n\t */\n\texport interface Props extends Omit<\n\t\tTagProps<\"input\">,\n\t\t\"type\" | \"list\" | \"role\" | \"mix\" | \"value\" | \"color\"\n\t> {\n\t\t/** The field's `id`, from which every other id the autocomplete needs derives. */\n\t\tid: string;\n\t\t/** The field's accessible name; pass `aria-labelledby` instead to point at a visible label. */\n\t\tlabel?: string;\n\t\t/** The suggestions, in the order the list shows them. */\n\t\toptions: Array<Option>;\n\t\t/** An {@link Autocomplete.Heading} and an {@link Autocomplete.Empty}, drawn in the list. */\n\t\tchildren?: RemixNode;\n\t\t/** Names a hidden field carrying the picked option's `value`, emptied once the text is edited. */\n\t\tvalueName?: string;\n\t\t/**\n\t\t * `\"field\"` draws the bordered input; `\"bare\"` drops its border, background, padding and focus\n\t\t * ring, for a field set inside a pill that draws them with `:focus-within`.\n\t\t * @default \"field\"\n\t\t */\n\t\tvariant?: \"field\" | \"bare\";\n\t\t/** Styling for the wrapper. */\n\t\tmix?: TagProps<\"div\">[\"mix\"];\n\t}\n\n\t/** Every native `<div>` attribute. */\n\texport interface PartProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders the field, its `<datalist>`, a hidden list of styled options (opened by any\n * {@link Autocomplete.Heading} and closed by any {@link Autocomplete.Empty}) and the island that\n * swaps one for the other. Picking fires `change` and an `autocomplete-select` event on the\n * field with `{ value, label }`; Enter on an option never submits the form.\n *\n * @example\n * <Autocomplete id=\"where\" name=\"where\" label=\"Where to?\" valueName=\"placeId\" options={[{ value: \"lis\", label: \"Lisbon\", description: \"Portugal\" }]}>\n * \t<Autocomplete.Heading>Suggested destinations</Autocomplete.Heading>\n * \t<Autocomplete.Empty>No places match</Autocomplete.Empty>\n * </Autocomplete>\n * @example\n * <Autocomplete id=\"q\" name=\"q\" variant=\"bare\" aria-labelledby=\"where-label\" options={places} />\n */\nexport function Autocomplete(handle: Handle<Autocomplete.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tid,\n\t\t\tlabel,\n\t\t\toptions,\n\t\t\tchildren,\n\t\t\tvalueName,\n\t\t\tvariant = \"field\",\n\t\t\tmix,\n\t\t\tautoComplete = \"off\",\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet labelledBy = rest[\"aria-labelledby\"];\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\t{ \"aria-label\": label, \"aria-labelledby\": labelledBy },\n\t\t\t\"Autocomplete: pass `label` or `aria-labelledby` so the field and its list have a name.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"autocomplete\"\n\t\t\t\tdata-variant={variant}\n\t\t\t\tmix={mergeMix([raw({ position: \"relative\", inlineSize: \"100%\", minInlineSize: \"0\" })], mix)}\n\t\t\t>\n\t\t\t\t<Input\n\t\t\t\t\t{...rest}\n\t\t\t\t\tid={id}\n\t\t\t\t\taria-label={label}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tlist={`${id}-suggestions`}\n\t\t\t\t\tdata-autocomplete-input=\"\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tminInlineSize: \"0\",\n\t\t\t\t\t\t\ttextOverflow: \"ellipsis\",\n\t\t\t\t\t\t\tfontSize: \"var(--ui-autocomplete-font-size, var(--ui-text-sm, 0.875rem))\",\n\t\t\t\t\t\t\tblockSize: \"var(--ui-autocomplete-block-size, calc(var(--ui-spacing, 0.25rem) * 10))\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen('[data-variant=\"bare\"] > &', [\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tborderWidth: \"0\",\n\t\t\t\t\t\t\t\tbackgroundColor: \"transparent\",\n\t\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\t\toutline: \"none\",\n\t\t\t\t\t\t\t\tboxShadow: \"none\",\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{valueName ? (\n\t\t\t\t\t<input type=\"hidden\" name={valueName} value=\"\" data-autocomplete-value=\"\" />\n\t\t\t\t) : null}\n\t\t\t\t<datalist id={`${id}-suggestions`}>\n\t\t\t\t\t{options.map((option) => (\n\t\t\t\t\t\t<option value={option.label} />\n\t\t\t\t\t))}\n\t\t\t\t</datalist>\n\t\t\t\t<div\n\t\t\t\t\tid={`${id}-popup`}\n\t\t\t\t\tpopover=\"manual\"\n\t\t\t\t\tdata-autocomplete-popup=\"\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tfloatingSurface(),\n\t\t\t\t\t\tsurfaceInset(),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"fixed\",\n\t\t\t\t\t\t\tinset: \"auto\",\n\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t\tboxSizing: \"border-box\",\n\t\t\t\t\t\t\toverflowY: \"auto\",\n\t\t\t\t\t\t\toverscrollBehavior: \"contain\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\tflexDirection: \"column\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\"&:not(:popover-open)\", raw({ display: \"none !important\" })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t\t<div\n\t\t\t\t\t\tid={`${id}-listbox`}\n\t\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\t\taria-label={label}\n\t\t\t\t\t\taria-labelledby={labelledBy}\n\t\t\t\t\t\tdata-autocomplete-listbox=\"\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{options.map((option, index) => (\n\t\t\t\t\t\t\t<AutocompleteOption id={`${id}-option-${index}`} option={option} />\n\t\t\t\t\t\t))}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<AutocompleteSync />\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * A line at the top of the list, shown while the field is empty, such as \"Suggested destinations\".\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the heading.\n */\nAutocomplete.Heading = function AutocompleteHeading(handle: Handle<Autocomplete.PartProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"autocomplete-heading\"\n\t\t\t\t{...rest}\n\t\t\t\tdata-autocomplete-heading=\"\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\torder: \"-1\",\n\t\t\t\t\t\t\tpaddingBlock: \"0.375rem\",\n\t\t\t\t\t\t\tfontSize: \"0.75rem\",\n\t\t\t\t\t\t\tfontWeight: \"600\",\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\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * What the list says under its options when the typed text matches none; \"No matches\" when\n * given no words of its own. Hidden until nothing matches.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the message.\n */\nAutocomplete.Empty = function AutocompleteEmpty(handle: Handle<Autocomplete.PartProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"autocomplete-empty\"\n\t\t\t\thidden\n\t\t\t\t{...rest}\n\t\t\t\tdata-autocomplete-empty=\"\"\n\t\t\t\tmix={mergeMix([pi(3), pb(2), text(\"sm\"), fg(\"neutral.muted\"), raw({ order: \"1\" })], mix)}\n\t\t\t>\n\t\t\t\t{children ?? DEFAULT_EMPTY_LABEL}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * One row of the list: the icon in a tinted square, the label over its description, both\n * truncating so a long place name never widens the list. A row is at least the pointer\n * target size tall, which grows to 44px on a touch screen.\n */\nfunction AutocompleteOption(handle: Handle<{ id: string; option: Autocomplete.Option }>) {\n\treturn () => {\n\t\tlet { id, option } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tid={id}\n\t\t\t\trole=\"option\"\n\t\t\t\taria-selected=\"false\"\n\t\t\t\tdata-autocomplete-option=\"\"\n\t\t\t\tdata-value={option.value}\n\t\t\t\tdata-label={option.label}\n\t\t\t\tdata-description={option.description}\n\t\t\t\tmix={[\n\t\t\t\t\thstack({ align: \"center\", gap: 3 }),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpb(1.5),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\tminBlockSize: \"max(2.75rem, var(--ui-target-size))\",\n\t\t\t\t\t\tscrollMarginBlock: \"0.25rem\",\n\t\t\t\t\t}),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.bg-tint-pressed\")]),\n\t\t\t\t\twhen(\"&[hidden]\", raw({ display: \"none\" })),\n\t\t\t\t\twhen(\n\t\t\t\t\t\t\"& mark\",\n\t\t\t\t\t\traw({ backgroundColor: \"transparent\", color: \"inherit\", fontWeight: \"700\" }),\n\t\t\t\t\t),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{option.icon ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\traw({\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\tflexShrink: \"0\",\n\t\t\t\t\t\t\t\tinlineSize: \"2rem\",\n\t\t\t\t\t\t\t\tblockSize: \"2rem\",\n\t\t\t\t\t\t\t\t\"& svg\": { inlineSize: \"1rem\", blockSize: \"1rem\" },\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{option.icon}\n\t\t\t\t\t</span>\n\t\t\t\t) : null}\n\t\t\t\t<span mix={[raw({ display: \"grid\", minInlineSize: \"0\", flex: \"1\" })]}>\n\t\t\t\t\t<span data-autocomplete-label=\"\" mix={[truncate(), text(\"sm\"), fg(\"neutral.emphasis\")]}>\n\t\t\t\t\t\t{option.label}\n\t\t\t\t\t</span>\n\t\t\t\t\t{option.description ? (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tdata-autocomplete-description=\"\"\n\t\t\t\t\t\t\tmix={[truncate(), text(\"xs\"), fg(\"neutral.muted\")]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{option.description}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) : null}\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The island inside every {@link Autocomplete}: once hydrated it drops the field's datalist,\n * makes the field a combobox and opens the styled list on focus and typing. It renders only a\n * hidden marker, so the field and options stay server markup styled by the caller's mixins.\n *\n * @example <AutocompleteSync />\n */\nexport const AutocompleteSync: EntryComponent<Record<never, never>> = clientEntry(\n\t\"@sdxc/ui/autocomplete#AutocompleteSync\",\n\tfunction AutocompleteSync() {\n\t\treturn () => <span hidden mix={[autocomplete()]} />;\n\t},\n);\n"
14
14
  },
15
15
  "test": {
16
16
  "path": "autocomplete.browser.test.tsx",
17
- "content": "/**\n * Types into an autocomplete in a real browser: the server markup suggests through a native\n * datalist, and once its island mounts the field opens a styled list with a heading, filters\n * as it is typed in, walks with the arrows, picks on Enter or a press without submitting the\n * form, closes on Escape, carries the picked value in a hidden field and fits a 320px screen.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { renderToString } from \"remix/component/server\";\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test, vi } from \"vitest\";\nimport { page, userEvent } from \"vitest/browser\";\n\nimport type { AutocompleteSelectDetail } from \"@sdxc/ui/autocomplete\";\n\nimport { Autocomplete } from \"@sdxc/ui/autocomplete\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The destinations every test searches. */\nconst OPTIONS: Array<Autocomplete.Option> = [\n\t{ value: \"lis\", label: \"Lisbon\", description: \"Portugal\", icon: <svg viewBox=\"0 0 16 16\" /> },\n\t{ value: \"por\", label: \"Porto\", description: \"Portugal\" },\n\t{ value: \"mad\", label: \"Madrid\", description: \"Spain\" },\n\t{ value: \"bcn\", label: \"Barcelona\", description: \"Catalonia, Spain\" },\n];\n\nlet mounted: RenderResult | undefined;\n\nafterEach(async () => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n\tawait page.viewport(1024, 768);\n});\n\n/** Mounts the autocomplete in a form, letting the island enhance it. */\nasync function mount(props: Partial<Autocomplete.Props> = {}) {\n\tlet submit = vi.fn((event: SubmitEvent) => event.preventDefault());\n\tmounted = render(\n\t\t<form>\n\t\t\t<Autocomplete\n\t\t\t\tid=\"where\"\n\t\t\t\tname=\"where\"\n\t\t\t\tlabel=\"Where to?\"\n\t\t\t\theading=\"Suggested destinations\"\n\t\t\t\tplaceholder=\"Search destinations\"\n\t\t\t\toptions={OPTIONS}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<button type=\"submit\">Search</button>\n\t\t</form>,\n\t);\n\tawait new Promise((resolve) => requestAnimationFrame(resolve));\n\tlet root = mounted.container;\n\troot.querySelector(\"form\")!.addEventListener(\"submit\", submit);\n\treturn {\n\t\troot,\n\t\tsubmit,\n\t\tinput: root.querySelector<HTMLInputElement>(\"#where\")!,\n\t\tpopup: root.querySelector<HTMLElement>(\"#where-popup\")!,\n\t\theading: root.querySelector<HTMLElement>(\"[data-autocomplete-heading]\")!,\n\t\tempty: root.querySelector<HTMLElement>(\"[data-autocomplete-empty]\")!,\n\t};\n}\n\n/** The labels of the options the list shows. */\nfunction shownLabels(root: HTMLElement): Array<string> {\n\treturn Array.from(root.querySelectorAll<HTMLElement>('[role=\"option\"]'))\n\t\t.filter((option) => !option.hidden)\n\t\t.map((option) => option.dataset.label ?? \"\");\n}\n\ndescribe(\"Autocomplete\", () => {\n\ttest(\"renders a plain field suggesting through a native datalist before any script\", async () => {\n\t\tdocument.body.innerHTML = await renderToString(\n\t\t\t<Autocomplete id=\"where\" name=\"where\" label=\"Where to?\" options={OPTIONS} />,\n\t\t);\n\t\tlet input = document.querySelector<HTMLInputElement>(\"#where\")!;\n\t\tlet datalist = document.getElementById(input.getAttribute(\"list\") ?? \"\");\n\n\t\texpect(input.getAttribute(\"role\")).toBeNull();\n\t\texpect(datalist?.tagName).toBe(\"DATALIST\");\n\t\texpect(Array.from(datalist!.querySelectorAll(\"option\")).map((o) => o.value)).toEqual([\n\t\t\t\"Lisbon\",\n\t\t\t\"Porto\",\n\t\t\t\"Madrid\",\n\t\t\t\"Barcelona\",\n\t\t]);\n\t\texpect(document.querySelector<HTMLElement>(\"#where-popup\")!.matches(\":popover-open\")).toBe(\n\t\t\tfalse,\n\t\t);\n\t});\n\n\ttest(\"becomes a combobox that opens its list with the heading on focus\", async () => {\n\t\tlet { input, popup, heading } = await mount();\n\n\t\texpect(input.hasAttribute(\"list\")).toBe(false);\n\t\texpect(input.getAttribute(\"role\")).toBe(\"combobox\");\n\t\texpect(input.getAttribute(\"aria-autocomplete\")).toBe(\"list\");\n\t\texpect(input.getAttribute(\"aria-controls\")).toBe(\"where-listbox\");\n\t\texpect(input.getAttribute(\"aria-expanded\")).toBe(\"false\");\n\n\t\tinput.focus();\n\t\texpect(popup.matches(\":popover-open\")).toBe(true);\n\t\texpect(input.getAttribute(\"aria-expanded\")).toBe(\"true\");\n\t\texpect(heading.hidden).toBe(false);\n\t\texpect(popup.getBoundingClientRect().top).toBeGreaterThanOrEqual(\n\t\t\tinput.getBoundingClientRect().bottom,\n\t\t);\n\t});\n\n\ttest(\"filters by label and description as the reader types, marking the match\", async () => {\n\t\tlet { root, input, heading, empty } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"spain\");\n\t\texpect(shownLabels(root)).toEqual([\"Madrid\", \"Barcelona\"]);\n\t\texpect(heading.hidden).toBe(true);\n\n\t\tawait userEvent.clear(input);\n\t\tawait userEvent.keyboard(\"POR\");\n\t\texpect(shownLabels(root)).toEqual([\"Lisbon\", \"Porto\"]);\n\t\texpect(root.querySelector(\"#where-option-1 [data-autocomplete-label] mark\")?.textContent).toBe(\n\t\t\t\"Por\",\n\t\t);\n\n\t\tawait userEvent.keyboard(\"xyz\");\n\t\texpect(shownLabels(root)).toEqual([]);\n\t\texpect(empty.hidden).toBe(false);\n\t\texpect(empty.textContent).toBe(\"No matches\");\n\t});\n\n\ttest(\"walks the shown options with the arrows through aria-activedescendant\", async () => {\n\t\tlet { input } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"spain\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-2\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-3\");\n\t\texpect(document.getElementById(\"where-option-3\")?.getAttribute(\"aria-selected\")).toBe(\"true\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-2\");\n\t\tawait userEvent.keyboard(\"{ArrowUp}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-3\");\n\t});\n\n\ttest(\"picks on Enter, firing change and autocomplete-select, without submitting\", async () => {\n\t\tlet { root, input, popup, submit } = await mount();\n\t\tlet change = vi.fn();\n\t\tlet select = vi.fn((event: CustomEvent<AutocompleteSelectDetail>) => event.detail);\n\t\troot.addEventListener(\"change\", change);\n\t\troot.addEventListener(\"autocomplete-select\", select);\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"{ArrowDown}{ArrowDown}{Enter}\");\n\n\t\texpect(input.value).toBe(\"Porto\");\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t\texpect(change).toHaveBeenCalledTimes(1);\n\t\texpect(select).toHaveReturnedWith({ value: \"por\", label: \"Porto\" });\n\t\texpect(submit).not.toHaveBeenCalled();\n\t});\n\n\ttest(\"closes on the first Escape and clears the field on the second\", async () => {\n\t\tlet { input, popup } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"Lis\");\n\t\tawait userEvent.keyboard(\"{Escape}\");\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t\texpect(input.value).toBe(\"Lis\");\n\t\tawait userEvent.keyboard(\"{Escape}\");\n\t\texpect(input.value).toBe(\"\");\n\t});\n\n\ttest(\"picks an option pressed with the pointer, and closes on a press elsewhere\", async () => {\n\t\tlet { input, popup } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.click(page.getByRole(\"option\", { name: /Madrid/ }));\n\t\texpect(input.value).toBe(\"Madrid\");\n\t\texpect(document.activeElement).toBe(input);\n\n\t\tawait userEvent.click(input);\n\t\texpect(popup.matches(\":popover-open\")).toBe(true);\n\t\tawait userEvent.click(document.body, { position: { x: 5, y: 700 } });\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t});\n\n\ttest(\"carries the picked value in a hidden field until the text is edited\", async () => {\n\t\tlet { root, input } = await mount({ valueName: \"placeId\" });\n\t\tlet hidden = root.querySelector<HTMLInputElement>('input[name=\"placeId\"]')!;\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"Barc{ArrowDown}{Enter}\");\n\t\texpect(input.value).toBe(\"Barcelona\");\n\t\texpect(hidden.value).toBe(\"bcn\");\n\t\texpect(new FormData(root.querySelector(\"form\")!).get(\"where\")).toBe(\"Barcelona\");\n\n\t\tawait userEvent.keyboard(\"{Backspace}\");\n\t\texpect(hidden.value).toBe(\"\");\n\t});\n\n\ttest(\"draws a bare field with no border or background\", async () => {\n\t\tlet { input } = await mount({ variant: \"bare\" });\n\t\tlet style = getComputedStyle(input);\n\n\t\texpect(style.borderTopWidth).toBe(\"0px\");\n\t\texpect(style.backgroundColor).toBe(\"rgba(0, 0, 0, 0)\");\n\t});\n\n\ttest(\"fits a 320px screen, field and open list alike\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet { input, popup } = await mount();\n\n\t\tinput.focus();\n\t\tlet list = popup.getBoundingClientRect();\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\texpect(input.getBoundingClientRect().right).toBeLessThanOrEqual(320);\n\t\texpect(list.left).toBeGreaterThanOrEqual(0);\n\t\texpect(list.right).toBeLessThanOrEqual(320);\n\t});\n});\n"
17
+ "content": "/**\n * Types into an autocomplete in a real browser: the server markup suggests through a native\n * datalist, and once its island mounts the field opens a styled list with a heading, filters\n * as it is typed in, walks with the arrows, picks on Enter or a press without submitting the\n * form, closes on Escape, carries the picked value in a hidden field and fits a 320px screen.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { raw } from \"@sdxc/u/general\";\nimport { renderToString } from \"remix/component/server\";\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test, vi } from \"vitest\";\nimport { page, userEvent } from \"vitest/browser\";\n\nimport type { AutocompleteSelectDetail } from \"@sdxc/ui/autocomplete\";\n\nimport { Autocomplete } from \"@sdxc/ui/autocomplete\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The destinations every test searches. */\nconst OPTIONS: Array<Autocomplete.Option> = [\n\t{ value: \"lis\", label: \"Lisbon\", description: \"Portugal\", icon: <svg viewBox=\"0 0 16 16\" /> },\n\t{ value: \"por\", label: \"Porto\", description: \"Portugal\" },\n\t{ value: \"mad\", label: \"Madrid\", description: \"Spain\" },\n\t{ value: \"bcn\", label: \"Barcelona\", description: \"Catalonia, Spain\" },\n];\n\nlet mounted: RenderResult | undefined;\n\nafterEach(async () => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n\tawait page.viewport(1024, 768);\n});\n\n/** Mounts the autocomplete in a form, letting the island enhance it. */\nasync function mount(props: Partial<Autocomplete.Props> = {}) {\n\tlet submit = vi.fn((event: SubmitEvent) => event.preventDefault());\n\tmounted = render(\n\t\t<form>\n\t\t\t<Autocomplete\n\t\t\t\tid=\"where\"\n\t\t\t\tname=\"where\"\n\t\t\t\tlabel=\"Where to?\"\n\t\t\t\tplaceholder=\"Search destinations\"\n\t\t\t\toptions={OPTIONS}\n\t\t\t\t{...props}\n\t\t\t>\n\t\t\t\t<Autocomplete.Heading>Suggested destinations</Autocomplete.Heading>\n\t\t\t\t<Autocomplete.Empty />\n\t\t\t</Autocomplete>\n\t\t\t<button type=\"submit\">Search</button>\n\t\t</form>,\n\t);\n\tawait new Promise((resolve) => requestAnimationFrame(resolve));\n\tlet root = mounted.container;\n\troot.querySelector(\"form\")!.addEventListener(\"submit\", submit);\n\treturn {\n\t\troot,\n\t\tsubmit,\n\t\tinput: root.querySelector<HTMLInputElement>(\"#where\")!,\n\t\tpopup: root.querySelector<HTMLElement>(\"#where-popup\")!,\n\t\theading: root.querySelector<HTMLElement>(\"[data-autocomplete-heading]\")!,\n\t\tempty: root.querySelector<HTMLElement>(\"[data-autocomplete-empty]\")!,\n\t};\n}\n\n/** The labels of the options the list shows. */\nfunction shownLabels(root: HTMLElement): Array<string> {\n\treturn Array.from(root.querySelectorAll<HTMLElement>('[role=\"option\"]'))\n\t\t.filter((option) => !option.hidden)\n\t\t.map((option) => option.dataset.label ?? \"\");\n}\n\ndescribe(\"Autocomplete\", () => {\n\ttest(\"renders a plain field suggesting through a native datalist before any script\", async () => {\n\t\tdocument.body.innerHTML = await renderToString(\n\t\t\t<Autocomplete id=\"where\" name=\"where\" label=\"Where to?\" options={OPTIONS} />,\n\t\t);\n\t\tlet input = document.querySelector<HTMLInputElement>(\"#where\")!;\n\t\tlet datalist = document.getElementById(input.getAttribute(\"list\") ?? \"\");\n\n\t\texpect(input.getAttribute(\"role\")).toBeNull();\n\t\texpect(datalist?.tagName).toBe(\"DATALIST\");\n\t\texpect(Array.from(datalist!.querySelectorAll(\"option\")).map((o) => o.value)).toEqual([\n\t\t\t\"Lisbon\",\n\t\t\t\"Porto\",\n\t\t\t\"Madrid\",\n\t\t\t\"Barcelona\",\n\t\t]);\n\t\texpect(document.querySelector<HTMLElement>(\"#where-popup\")!.matches(\":popover-open\")).toBe(\n\t\t\tfalse,\n\t\t);\n\t});\n\n\ttest(\"becomes a combobox that opens its list with the heading on focus\", async () => {\n\t\tlet { input, popup, heading } = await mount();\n\n\t\texpect(input.hasAttribute(\"list\")).toBe(false);\n\t\texpect(input.getAttribute(\"role\")).toBe(\"combobox\");\n\t\texpect(input.getAttribute(\"aria-autocomplete\")).toBe(\"list\");\n\t\texpect(input.getAttribute(\"aria-controls\")).toBe(\"where-listbox\");\n\t\texpect(input.getAttribute(\"aria-expanded\")).toBe(\"false\");\n\n\t\tinput.focus();\n\t\texpect(popup.matches(\":popover-open\")).toBe(true);\n\t\texpect(input.getAttribute(\"aria-expanded\")).toBe(\"true\");\n\t\texpect(heading.hidden).toBe(false);\n\t\texpect(popup.getBoundingClientRect().top).toBeGreaterThanOrEqual(\n\t\t\tinput.getBoundingClientRect().bottom,\n\t\t);\n\t});\n\n\ttest(\"filters by label and description as the reader types, marking the match\", async () => {\n\t\tlet { root, input, heading, empty } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"spain\");\n\t\texpect(shownLabels(root)).toEqual([\"Madrid\", \"Barcelona\"]);\n\t\texpect(heading.hidden).toBe(true);\n\n\t\tawait userEvent.clear(input);\n\t\tawait userEvent.keyboard(\"POR\");\n\t\texpect(shownLabels(root)).toEqual([\"Lisbon\", \"Porto\"]);\n\t\texpect(root.querySelector(\"#where-option-1 [data-autocomplete-label] mark\")?.textContent).toBe(\n\t\t\t\"Por\",\n\t\t);\n\n\t\tawait userEvent.keyboard(\"xyz\");\n\t\texpect(shownLabels(root)).toEqual([]);\n\t\texpect(empty.hidden).toBe(false);\n\t\texpect(empty.textContent).toBe(\"No matches\");\n\t});\n\n\ttest(\"walks the shown options with the arrows through aria-activedescendant\", async () => {\n\t\tlet { input } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"spain\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-2\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-3\");\n\t\texpect(document.getElementById(\"where-option-3\")?.getAttribute(\"aria-selected\")).toBe(\"true\");\n\t\tawait userEvent.keyboard(\"{ArrowDown}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-2\");\n\t\tawait userEvent.keyboard(\"{ArrowUp}\");\n\t\texpect(input.getAttribute(\"aria-activedescendant\")).toBe(\"where-option-3\");\n\t});\n\n\ttest(\"picks on Enter, firing change and autocomplete-select, without submitting\", async () => {\n\t\tlet { root, input, popup, submit } = await mount();\n\t\tlet change = vi.fn();\n\t\tlet select = vi.fn((event: CustomEvent<AutocompleteSelectDetail>) => event.detail);\n\t\troot.addEventListener(\"change\", change);\n\t\troot.addEventListener(\"autocomplete-select\", select);\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"{ArrowDown}{ArrowDown}{Enter}\");\n\n\t\texpect(input.value).toBe(\"Porto\");\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t\texpect(change).toHaveBeenCalledTimes(1);\n\t\texpect(select).toHaveReturnedWith({ value: \"por\", label: \"Porto\" });\n\t\texpect(submit).not.toHaveBeenCalled();\n\t});\n\n\ttest(\"closes on the first Escape and clears the field on the second\", async () => {\n\t\tlet { input, popup } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"Lis\");\n\t\tawait userEvent.keyboard(\"{Escape}\");\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t\texpect(input.value).toBe(\"Lis\");\n\t\tawait userEvent.keyboard(\"{Escape}\");\n\t\texpect(input.value).toBe(\"\");\n\t});\n\n\ttest(\"picks an option pressed with the pointer, and closes on a press elsewhere\", async () => {\n\t\tlet { input, popup } = await mount();\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.click(page.getByRole(\"option\", { name: /Madrid/ }));\n\t\texpect(input.value).toBe(\"Madrid\");\n\t\texpect(document.activeElement).toBe(input);\n\n\t\tawait userEvent.click(input);\n\t\texpect(popup.matches(\":popover-open\")).toBe(true);\n\t\tawait userEvent.click(document.body, { position: { x: 5, y: 700 } });\n\t\texpect(popup.matches(\":popover-open\")).toBe(false);\n\t});\n\n\ttest(\"carries the picked value in a hidden field until the text is edited\", async () => {\n\t\tlet { root, input } = await mount({ valueName: \"placeId\" });\n\t\tlet hidden = root.querySelector<HTMLInputElement>('input[name=\"placeId\"]')!;\n\n\t\tawait userEvent.click(input);\n\t\tawait userEvent.keyboard(\"Barc{ArrowDown}{Enter}\");\n\t\texpect(input.value).toBe(\"Barcelona\");\n\t\texpect(hidden.value).toBe(\"bcn\");\n\t\texpect(new FormData(root.querySelector(\"form\")!).get(\"where\")).toBe(\"Barcelona\");\n\n\t\tawait userEvent.keyboard(\"{Backspace}\");\n\t\texpect(hidden.value).toBe(\"\");\n\t});\n\n\ttest(\"draws a bare field with no border or background\", async () => {\n\t\tlet { input } = await mount({ variant: \"bare\" });\n\t\tlet style = getComputedStyle(input);\n\n\t\texpect(style.borderTopWidth).toBe(\"0px\");\n\t\texpect(style.backgroundColor).toBe(\"rgba(0, 0, 0, 0)\");\n\t});\n\n\ttest(\"sizes the field from the custom properties set on its wrapper\", async () => {\n\t\tlet { input } = await mount({\n\t\t\tvariant: \"bare\",\n\t\t\tmix: [raw({ \"--ui-autocomplete-font-size\": \"20px\", \"--ui-autocomplete-block-size\": \"auto\" })],\n\t\t});\n\t\tlet style = getComputedStyle(input);\n\n\t\texpect(style.fontSize).toBe(\"20px\");\n\t\texpect(style.paddingBlockStart).toBe(\"0px\");\n\t\texpect(input.getBoundingClientRect().height).toBeLessThan(40);\n\t});\n\n\ttest(\"fits a 320px screen, field and open list alike\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet { input, popup } = await mount();\n\n\t\tinput.focus();\n\t\tlet list = popup.getBoundingClientRect();\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\texpect(input.getBoundingClientRect().right).toBeLessThanOrEqual(320);\n\t\texpect(list.left).toBeGreaterThanOrEqual(0);\n\t\texpect(list.right).toBeLessThanOrEqual(320);\n\t});\n});\n"
18
18
  }
19
19
  }
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "banner",
3
- "changedIn": "2026.11.3",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [],
5
5
  "exports": [
6
6
  "Banner"
7
7
  ],
8
8
  "source": {
9
9
  "path": "banner.tsx",
10
- "content": "/**\n * A full-width strip above a page or the whole app for state that outlives one\n * action: an overdue invoice, a failing integration, a maintenance window. It\n * sits in the flow and pushes the frame down, so it never covers what it warns about.\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 { CircleAlertIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, XIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { flex, flexWrap, gap, grow, inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minIs, pb, pi } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { fontSize, leading, overflowWrap, pretty, weight } from \"@sdxc/u/typography\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { semanticColorPanel } from \"@sdxc/ui/styles\";\n\n/** Default {@link Banner.Props.color}: an informational strip. */\nconst DEFAULT_COLOR: Banner.Color = \"brand\";\n\n/** Prop types for {@link Banner}. */\nexport namespace Banner {\n\t/** Semantic tone of the strip: warning for billing, danger for a failing integration. */\n\texport type Color = SemanticColor;\n\n\t/** Props accepted by {@link Banner}. */\n\texport interface Props extends Omit<TagProps<\"section\">, \"children\"> {\n\t\t/** Accessible name of the strip's region landmark, such as \"Billing\". */\n\t\tlabel: string;\n\t\t/** Default: `\"brand\"`. */\n\t\tcolor?: Color;\n\t\t/** Leading icon in place of the tone's own, or `null` for none. */\n\t\ticon?: RemixNode;\n\t\t/** The one fixing action, such as an \"Update Payment Method\" button or link. */\n\t\taction?: RemixNode;\n\t\t/**\n\t\t * Lets the reader close the strip through a form, so the server records it\n\t\t * and stops rendering the banner. Leave it out for state that needs resolving.\n\t\t */\n\t\tdismiss?: Dismiss;\n\t\t/** The message: what is wrong and what fixing it changes, in a sentence or two. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/** How a dismissible {@link Banner} closes. */\n\texport interface Dismiss {\n\t\t/** Accessible name of the close button, such as \"Dismiss\". */\n\t\tlabel: string;\n\t\t/** URL the dismissal submits to. */\n\t\taction: string;\n\t\t/** Default: `\"post\"`. */\n\t\tmethod?: \"get\" | \"post\";\n\t\t/** Hidden fields sent with it, such as the banner's id. */\n\t\tfields?: Record<string, string>;\n\t}\n}\n\n/**\n * Renders the strip as a named region: tone icon, message, one action, and a\n * close form only when `dismiss` is given. One banner at a time; it wraps on a\n * phone and flows above the app frame, pushing it down.\n *\n * @param handle Runtime handle carrying the host `<section>`'s props.\n * @returns The render function producing the strip's markup.\n * @example\n * <Banner color=\"warning\" label={t(\"billing.region\")} action={<Button href=\"/billing\">{t(\"billing.update\")}</Button>}>\n * \t{t(\"billing.declined\")}\n * </Banner>\n * @example\n * <Banner label={t(\"maintenance.region\")} dismiss={{ label: t(\"actions.dismiss\"), action: \"/banners/dismiss\", fields: { id: \"maintenance\" } }}>\n * \t{t(\"maintenance.message\")}\n * </Banner>\n */\nexport function Banner(handle: Handle<Banner.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tlabel,\n\t\t\tcolor = DEFAULT_COLOR,\n\t\t\ticon,\n\t\t\taction,\n\t\t\tdismiss,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet toneIcon = icon === null ? null : (icon ?? <BannerToneIcon color={color} />);\n\n\t\treturn (\n\t\t\t<section\n\t\t\t\taria-label={label}\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={color}\n\t\t\t\tdata-slot=\"banner\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tsemanticColorPanel(),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexWrap(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(3),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\t\traw({ borderWidth: \"0\", borderBlockEndWidth: \"1px\", borderStyle: \"solid\" }),\n\t\t\t\t\t\tfontSize(\"sm\"),\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{toneIcon ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tdata-slot=\"banner-icon\"\n\t\t\t\t\t\tmix={[inlineFlex(), shrink(0), fg(\"currentcolor\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{toneIcon}\n\t\t\t\t\t</span>\n\t\t\t\t) : null}\n\t\t\t\t<p\n\t\t\t\t\tdata-slot=\"banner-message\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tgrow(),\n\t\t\t\t\t\traw({ flexBasis: \"16rem\" }),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\tleading(\"snug\"),\n\t\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\t\tpretty(),\n\t\t\t\t\t\toverflowWrap(\"anywhere\"),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</p>\n\t\t\t\t{action ? (\n\t\t\t\t\t<div data-slot=\"banner-action\" mix={[flex(), items(\"center\"), shrink(0)]}>\n\t\t\t\t\t\t{action}\n\t\t\t\t\t</div>\n\t\t\t\t) : null}\n\t\t\t\t{dismiss ? <BannerDismiss dismiss={dismiss} /> : null}\n\t\t\t</section>\n\t\t);\n\t};\n}\n\n/**\n * Picks the icon a tone carries, so a warning and a failure read apart before\n * the message does.\n *\n * @param handle Runtime handle carrying the banner's tone.\n * @returns The render function producing the icon.\n */\nfunction BannerToneIcon(handle: Handle<{ color: Banner.Color }>) {\n\treturn () => {\n\t\tlet { color } = handle.props;\n\t\tif (color === \"success\") return <CircleCheckIcon size={16} />;\n\t\tif (color === \"danger\") return <CircleAlertIcon size={16} />;\n\t\tif (color === \"warning\") return <TriangleAlertIcon size={16} />;\n\t\treturn <InfoIcon size={16} />;\n\t};\n}\n\n/**\n * The close control of a dismissible {@link Banner}: an icon button that\n * submits its form, so the dismissal reaches the server with or without\n * JavaScript and the banner stays gone on the next page.\n *\n * @param handle Runtime handle carrying the dismissal form.\n * @returns The render function producing the form's markup.\n */\nfunction BannerDismiss(handle: Handle<{ dismiss: Banner.Dismiss }>) {\n\treturn () => {\n\t\tlet { dismiss } = handle.props;\n\n\t\treturn (\n\t\t\t<form\n\t\t\t\tmethod={dismiss.method ?? \"post\"}\n\t\t\t\taction={dismiss.action}\n\t\t\t\tdata-slot=\"banner-dismiss\"\n\t\t\t\tmix={[flex(), shrink(0), raw({ marginInlineStart: \"auto\" })]}\n\t\t\t>\n\t\t\t\t{Object.entries(dismiss.fields ?? {}).map(([name, value]) => (\n\t\t\t\t\t<input key={name} type=\"hidden\" name={name} value={value} />\n\t\t\t\t))}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\taria-label={dismiss.label}\n\t\t\t\t\ttitle={dismiss.label}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tinlineFlex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tis(\"2rem\"),\n\t\t\t\t\t\tbs(\"2rem\"),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ width: 0 }),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tfg(\"currentcolor\"),\n\t\t\t\t\t\ttransition(\"background-color\"),\n\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", width: 2 })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<XIcon size={16} />\n\t\t\t\t</button>\n\t\t\t</form>\n\t\t);\n\t};\n}\n"
10
+ "content": "/**\n * A full-width strip above a page or the whole app for state that outlives one action, built\n * from parts: the tone's icon, the message, one fixing action and a close form. It sits in\n * the flow and pushes the frame down, so it never covers what it warns about.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { CircleAlertIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, XIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { flex, flexWrap, gap, grow, inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minIs, pb, pi } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { fontSize, leading, overflowWrap, pretty, weight } from \"@sdxc/u/typography\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { semanticColorPanel } from \"@sdxc/ui/styles\";\n\n/** Default {@link Banner.Props.color}: an informational strip. */\nconst DEFAULT_COLOR: Banner.Color = \"brand\";\n\n/** Prop types for {@link Banner} and its parts. */\nexport namespace Banner {\n\t/** Semantic tone of the strip: warning for billing, danger for a failing integration. */\n\texport type Color = SemanticColor;\n\n\t/** What the strip shares with its parts. */\n\texport interface Context {\n\t\tcolor: Color;\n\t}\n\n\t/**\n\t * Every native `<section>` attribute, plus the tone; name the region landmark with\n\t * `aria-label`, such as \"Billing\".\n\t */\n\texport interface Props extends TagProps<\"section\"> {\n\t\t/** @default \"brand\" */\n\t\tcolor?: Color;\n\t}\n\n\t/** Every native `<span>` attribute; with no children it draws the tone's own icon. */\n\texport interface IconProps extends TagProps<\"span\"> {}\n\n\t/** Every native `<p>` attribute. */\n\texport interface MessageProps extends TagProps<\"p\"> {}\n\n\t/** Every native `<div>` attribute. */\n\texport interface ActionProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<form>` attribute, plus the close button's accessible name; hidden inputs\n\t * go in as children.\n\t */\n\texport interface DismissProps extends Omit<TagProps<\"form\">, \"method\"> {\n\t\t/** Accessible name of the close button, such as \"Dismiss\". */\n\t\tcloseLabel: string;\n\t\t/** @default \"post\" */\n\t\tmethod?: \"get\" | \"post\";\n\t}\n}\n\n/**\n * Renders the strip as a named region laying out whichever parts it holds in a wrapping row.\n * One banner at a time; it wraps on a phone and flows above the app frame, pushing it down.\n *\n * @param handle Runtime handle carrying the host `<section>`'s props.\n * @returns The render function producing the strip's markup.\n * @example\n * <Banner color=\"warning\" aria-label=\"Billing\">\n * \t<Banner.Icon />\n * \t<Banner.Message>Your card was declined.</Banner.Message>\n * \t<Banner.Action><LinkButton href=\"/billing\">Update card</LinkButton></Banner.Action>\n * </Banner>\n * @example\n * <Banner aria-label=\"Maintenance\">\n * \t<Banner.Icon />\n * \t<Banner.Message>Checks pause on Sunday.</Banner.Message>\n * \t<Banner.Dismiss action=\"/banners/dismiss\" closeLabel=\"Dismiss\"><input type=\"hidden\" name=\"id\" value=\"maintenance\" /></Banner.Dismiss>\n * </Banner>\n */\nexport function Banner(handle: Handle<Banner.Props, Banner.Context>) {\n\treturn () => {\n\t\tlet { color = DEFAULT_COLOR, mix, ...rest } = handle.props;\n\t\thandle.context.set({ color });\n\n\t\treturn (\n\t\t\t<section\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={color}\n\t\t\t\tdata-slot=\"banner\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tsemanticColorPanel(),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexWrap(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(3),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\t\traw({ borderWidth: \"0\", borderBlockEndWidth: \"1px\", borderStyle: \"solid\" }),\n\t\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * The leading icon, hidden from assistive technology: the tone's own glyph, so a warning and a\n * failure read apart before the message does, or the children in its place.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the icon.\n */\nBanner.Icon = function BannerIcon(handle: Handle<Banner.IconProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Banner) as Banner.Context | undefined;\n\t\treturn (\n\t\t\t<span\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tdata-slot=\"banner-icon\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix([inlineFlex(), shrink(0), fg(\"currentcolor\")], mix)}\n\t\t\t>\n\t\t\t\t{children ?? <BannerToneIcon color={context?.color ?? DEFAULT_COLOR} />}\n\t\t\t</span>\n\t\t);\n\t};\n};\n\n/**\n * The message: what is wrong and what fixing it changes, in a sentence or two. It takes the\n * row's spare width and wraps above the action on a phone.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the message.\n */\nBanner.Message = function BannerMessage(handle: Handle<Banner.MessageProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<p\n\t\t\t\tdata-slot=\"banner-message\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tgrow(),\n\t\t\t\t\t\traw({ flexBasis: \"16rem\" }),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\tleading(\"snug\"),\n\t\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\t\tpretty(),\n\t\t\t\t\t\toverflowWrap(\"anywhere\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * The one fixing action, such as an \"Update payment method\" button or link.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action's box.\n */\nBanner.Action = function BannerAction(handle: Handle<Banner.ActionProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-slot=\"banner-action\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix([flex(), items(\"center\"), shrink(0)], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Picks the icon a tone carries, so a warning and a failure read apart before\n * the message does.\n *\n * @param handle Runtime handle carrying the banner's tone.\n * @returns The render function producing the icon.\n */\nfunction BannerToneIcon(handle: Handle<{ color: Banner.Color }>) {\n\treturn () => {\n\t\tlet { color } = handle.props;\n\t\tif (color === \"success\") return <CircleCheckIcon size={16} />;\n\t\tif (color === \"danger\") return <CircleAlertIcon size={16} />;\n\t\tif (color === \"warning\") return <TriangleAlertIcon size={16} />;\n\t\treturn <InfoIcon size={16} />;\n\t};\n}\n\n/**\n * The close control of a dismissible strip: an icon button submitting its form, so the\n * dismissal reaches the server with or without JavaScript and the banner stays gone on the\n * next page. Leave it out for state that needs resolving.\n *\n * @param handle Runtime handle carrying the dismissal form's props.\n * @returns The render function producing the form's markup.\n */\nBanner.Dismiss = function BannerDismiss(handle: Handle<Banner.DismissProps>) {\n\treturn () => {\n\t\tlet { closeLabel, method = \"post\", children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<form\n\t\t\t\tdata-slot=\"banner-dismiss\"\n\t\t\t\t{...rest}\n\t\t\t\tmethod={method}\n\t\t\t\tmix={mergeMix([flex(), shrink(0), raw({ marginInlineStart: \"auto\" })], mix)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t\t<button\n\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\taria-label={closeLabel}\n\t\t\t\t\ttitle={closeLabel}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tinlineFlex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tis(\"2rem\"),\n\t\t\t\t\t\tbs(\"2rem\"),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ width: 0 }),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tfg(\"currentcolor\"),\n\t\t\t\t\t\ttransition(\"background-color\"),\n\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", width: 2 })),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<XIcon size={16} />\n\t\t\t\t</button>\n\t\t\t</form>\n\t\t);\n\t};\n};\n"
11
11
  },
12
12
  "test": {
13
13
  "path": "banner.browser.test.tsx",
14
- "content": "/**\n * Lays the banner out in a real browser: a named region in the flow that pushes the\n * app frame down instead of covering it, no close control unless dismissible, a\n * dismissal that is a real form, and a 320px phone that wraps instead of overflowing.\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\";\nimport { page } from \"vitest/browser\";\n\nimport { Banner } from \"@sdxc/ui/banner\";\n\nimport \"@sdxc/ui/reset.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(async () => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n\tawait page.viewport(1280, 800);\n});\n\n/** Mounts `node` in a host `width` pixels wide and returns the host. */\nfunction mount(node: JSX.Element, width = 1024): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tdocument.body.appendChild(host);\n\tmounted = render(node, { container: host });\n\treturn host;\n}\n\n/** The fixing action a billing banner offers. */\nfunction UpdateLink() {\n\treturn () => <a href=\"/billing\">Update Payment Method</a>;\n}\n\ndescribe(\"Banner\", () => {\n\ttest(\"is a named region in the flow that pushes the app frame down\", () => {\n\t\tlet host = mount(\n\t\t\t<>\n\t\t\t\t<Banner color=\"warning\" label=\"Billing\" action={<UpdateLink />}>\n\t\t\t\t\tYour card was declined. Update it to keep monitors running.\n\t\t\t\t</Banner>\n\t\t\t\t<main data-testid=\"frame\">Dashboard</main>\n\t\t\t</>,\n\t\t);\n\t\tlet banner = host.querySelector<HTMLElement>('[data-slot=\"banner\"]')!;\n\t\tlet frame = host.querySelector<HTMLElement>('[data-testid=\"frame\"]')!;\n\n\t\texpect(banner.tagName).toBe(\"SECTION\");\n\t\texpect(banner.getAttribute(\"aria-label\")).toBe(\"Billing\");\n\t\texpect(getComputedStyle(banner).position).toBe(\"static\");\n\t\texpect(frame.getBoundingClientRect().top).toBeCloseTo(banner.getBoundingClientRect().bottom, 1);\n\t\texpect(banner.getBoundingClientRect().width).toBe(1024);\n\t});\n\n\ttest(\"draws the tone's icon, hidden from assistive technology, unless told otherwise\", () => {\n\t\tlet host = mount(\n\t\t\t<>\n\t\t\t\t<Banner color=\"danger\" label=\"Integrations\" data-testid=\"toned\">\n\t\t\t\t\tSlack stopped accepting alerts.\n\t\t\t\t</Banner>\n\t\t\t\t<Banner color=\"danger\" label=\"Integrations\" icon={null} data-testid=\"bare\">\n\t\t\t\t\tSlack stopped accepting alerts.\n\t\t\t\t</Banner>\n\t\t\t</>,\n\t\t);\n\n\t\tlet icon = host.querySelector('[data-testid=\"toned\"] [data-slot=\"banner-icon\"]')!;\n\t\texpect(icon.getAttribute(\"aria-hidden\")).toBe(\"true\");\n\t\texpect(icon.querySelector(\"svg\")).not.toBeNull();\n\t\texpect(host.querySelector('[data-testid=\"bare\"] [data-slot=\"banner-icon\"]')).toBeNull();\n\t});\n\n\ttest(\"offers no close control while the state needs resolving\", () => {\n\t\tlet host = mount(\n\t\t\t<Banner color=\"warning\" label=\"Billing\" action={<UpdateLink />}>\n\t\t\t\tYour card was declined.\n\t\t\t</Banner>,\n\t\t);\n\n\t\texpect(host.querySelector(\"button\")).toBeNull();\n\t\texpect(host.querySelector(\"form\")).toBeNull();\n\t\texpect(host.querySelectorAll('[data-slot=\"banner-action\"] a')).toHaveLength(1);\n\t});\n\n\ttest(\"dismisses through a real form when dismissible\", () => {\n\t\tlet host = mount(\n\t\t\t<Banner\n\t\t\t\tlabel=\"Maintenance\"\n\t\t\t\tdismiss={{\n\t\t\t\t\tlabel: \"Dismiss\",\n\t\t\t\t\taction: \"/banners/dismiss\",\n\t\t\t\t\tfields: { id: \"maintenance-nov\" },\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\tChecks pause for 10 minutes on Sunday at 02:00 UTC.\n\t\t\t</Banner>,\n\t\t);\n\t\tlet form = host.querySelector(\"form\")!;\n\t\tlet button = form.querySelector(\"button\")!;\n\n\t\texpect(form.getAttribute(\"method\")).toBe(\"post\");\n\t\texpect(form.getAttribute(\"action\")).toBe(\"/banners/dismiss\");\n\t\texpect(new FormData(form).get(\"id\")).toBe(\"maintenance-nov\");\n\t\texpect(button.type).toBe(\"submit\");\n\t\texpect(button.getAttribute(\"aria-label\")).toBe(\"Dismiss\");\n\t});\n\n\ttest(\"wraps on a 320px phone without scrolling sideways\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet host = mount(\n\t\t\t<Banner\n\t\t\t\tcolor=\"warning\"\n\t\t\t\tlabel=\"Billing\"\n\t\t\t\taction={<UpdateLink />}\n\t\t\t\tdismiss={{ label: \"Dismiss\", action: \"/banners/dismiss\" }}\n\t\t\t>\n\t\t\t\tYour card ending 4242 was declined three times. Update it to keep 48 monitors running.\n\t\t\t</Banner>,\n\t\t\t320,\n\t\t);\n\t\tlet banner = host.querySelector<HTMLElement>('[data-slot=\"banner\"]')!;\n\n\t\texpect(banner.scrollWidth).toBeLessThanOrEqual(banner.clientWidth);\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\tlet action = host.querySelector('[data-slot=\"banner-action\"]')!.getBoundingClientRect();\n\t\tlet message = host.querySelector('[data-slot=\"banner-message\"]')!.getBoundingClientRect();\n\t\texpect(action.top).toBeGreaterThanOrEqual(message.bottom);\n\t});\n});\n"
14
+ "content": "/**\n * Lays the banner out in a real browser: a named region in the flow that pushes the\n * app frame down instead of covering it, no close control unless dismissible, a\n * dismissal that is a real form, and a 320px phone that wraps instead of overflowing.\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\";\nimport { page } from \"vitest/browser\";\n\nimport { Banner } from \"@sdxc/ui/banner\";\n\nimport \"@sdxc/ui/reset.css\";\n\nlet mounted: RenderResult | undefined;\n\nafterEach(async () => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n\tdocument.body.replaceChildren();\n\tawait page.viewport(1280, 800);\n});\n\n/** Mounts `node` in a host `width` pixels wide and returns the host. */\nfunction mount(node: JSX.Element, width = 1024): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tdocument.body.appendChild(host);\n\tmounted = render(node, { container: host });\n\treturn host;\n}\n\n/** The fixing action a billing banner offers. */\nfunction UpdateLink() {\n\treturn () => <a href=\"/billing\">Update Payment Method</a>;\n}\n\ndescribe(\"Banner\", () => {\n\ttest(\"is a named region in the flow that pushes the app frame down\", () => {\n\t\tlet host = mount(\n\t\t\t<>\n\t\t\t\t<Banner color=\"warning\" aria-label=\"Billing\">\n\t\t\t\t\t<Banner.Icon />\n\t\t\t\t\t<Banner.Message>\n\t\t\t\t\t\tYour card was declined. Update it to keep monitors running.\n\t\t\t\t\t</Banner.Message>\n\t\t\t\t\t<Banner.Action>\n\t\t\t\t\t\t<UpdateLink />\n\t\t\t\t\t</Banner.Action>\n\t\t\t\t</Banner>\n\t\t\t\t<main data-testid=\"frame\">Dashboard</main>\n\t\t\t</>,\n\t\t);\n\t\tlet banner = host.querySelector<HTMLElement>('[data-slot=\"banner\"]')!;\n\t\tlet frame = host.querySelector<HTMLElement>('[data-testid=\"frame\"]')!;\n\n\t\texpect(banner.tagName).toBe(\"SECTION\");\n\t\texpect(banner.getAttribute(\"aria-label\")).toBe(\"Billing\");\n\t\texpect(getComputedStyle(banner).position).toBe(\"static\");\n\t\texpect(frame.getBoundingClientRect().top).toBeCloseTo(banner.getBoundingClientRect().bottom, 1);\n\t\texpect(banner.getBoundingClientRect().width).toBe(1024);\n\t});\n\n\ttest(\"draws the tone's icon, hidden from assistive technology, only when given an Icon\", () => {\n\t\tlet host = mount(\n\t\t\t<>\n\t\t\t\t<Banner color=\"danger\" aria-label=\"Integrations\" data-testid=\"toned\">\n\t\t\t\t\t<Banner.Icon />\n\t\t\t\t\t<Banner.Message>Slack stopped accepting alerts.</Banner.Message>\n\t\t\t\t</Banner>\n\t\t\t\t<Banner color=\"danger\" aria-label=\"Integrations\" data-testid=\"bare\">\n\t\t\t\t\t<Banner.Message>Slack stopped accepting alerts.</Banner.Message>\n\t\t\t\t</Banner>\n\t\t\t</>,\n\t\t);\n\n\t\tlet icon = host.querySelector('[data-testid=\"toned\"] [data-slot=\"banner-icon\"]')!;\n\t\texpect(icon.getAttribute(\"aria-hidden\")).toBe(\"true\");\n\t\texpect(icon.querySelector(\"svg\")).not.toBeNull();\n\t\texpect(host.querySelector('[data-testid=\"bare\"] [data-slot=\"banner-icon\"]')).toBeNull();\n\t});\n\n\ttest(\"offers no close control while the state needs resolving\", () => {\n\t\tlet host = mount(\n\t\t\t<Banner color=\"warning\" aria-label=\"Billing\">\n\t\t\t\t<Banner.Message>Your card was declined.</Banner.Message>\n\t\t\t\t<Banner.Action>\n\t\t\t\t\t<UpdateLink />\n\t\t\t\t</Banner.Action>\n\t\t\t</Banner>,\n\t\t);\n\n\t\texpect(host.querySelector(\"button\")).toBeNull();\n\t\texpect(host.querySelector(\"form\")).toBeNull();\n\t\texpect(host.querySelectorAll('[data-slot=\"banner-action\"] a')).toHaveLength(1);\n\t});\n\n\ttest(\"dismisses through a real form when dismissible\", () => {\n\t\tlet host = mount(\n\t\t\t<Banner aria-label=\"Maintenance\">\n\t\t\t\t<Banner.Message>Checks pause for 10 minutes on Sunday at 02:00 UTC.</Banner.Message>\n\t\t\t\t<Banner.Dismiss action=\"/banners/dismiss\" closeLabel=\"Dismiss\">\n\t\t\t\t\t<input type=\"hidden\" name=\"id\" value=\"maintenance-nov\" />\n\t\t\t\t</Banner.Dismiss>\n\t\t\t</Banner>,\n\t\t);\n\t\tlet form = host.querySelector(\"form\")!;\n\t\tlet button = form.querySelector(\"button\")!;\n\n\t\texpect(form.getAttribute(\"method\")).toBe(\"post\");\n\t\texpect(form.getAttribute(\"action\")).toBe(\"/banners/dismiss\");\n\t\texpect(new FormData(form).get(\"id\")).toBe(\"maintenance-nov\");\n\t\texpect(button.type).toBe(\"submit\");\n\t\texpect(button.getAttribute(\"aria-label\")).toBe(\"Dismiss\");\n\t});\n\n\ttest(\"wraps on a 320px phone without scrolling sideways\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet host = mount(\n\t\t\t<Banner color=\"warning\" aria-label=\"Billing\">\n\t\t\t\t<Banner.Icon />\n\t\t\t\t<Banner.Message>\n\t\t\t\t\tYour card ending 4242 was declined three times. Update it to keep 48 monitors running.\n\t\t\t\t</Banner.Message>\n\t\t\t\t<Banner.Action>\n\t\t\t\t\t<UpdateLink />\n\t\t\t\t</Banner.Action>\n\t\t\t\t<Banner.Dismiss action=\"/banners/dismiss\" closeLabel=\"Dismiss\" />\n\t\t\t</Banner>,\n\t\t\t320,\n\t\t);\n\t\tlet banner = host.querySelector<HTMLElement>('[data-slot=\"banner\"]')!;\n\n\t\texpect(banner.scrollWidth).toBeLessThanOrEqual(banner.clientWidth);\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\tlet action = host.querySelector('[data-slot=\"banner-action\"]')!.getBoundingClientRect();\n\t\tlet message = host.querySelector('[data-slot=\"banner-message\"]')!.getBoundingClientRect();\n\t\texpect(action.top).toBeGreaterThanOrEqual(message.bottom);\n\t});\n\n\ttest(\"draws a part alone with the default tone's icon\", () => {\n\t\tlet host = mount(<Banner.Icon />);\n\n\t\texpect(host.querySelector('[data-slot=\"banner-icon\"] svg')).not.toBeNull();\n\t});\n});\n"
15
15
  }
16
16
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "button",
3
- "changedIn": "2026.11.14",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [
5
5
  "cta-group"
6
6
  ],
@@ -9,10 +9,10 @@
9
9
  ],
10
10
  "source": {
11
11
  "path": "button.tsx",
12
- "content": "/**\n * An interactive control for a single, immediate action — submitting a form,\n * triggering a command, opening a dialog. Its host renders as a native\n * `<button>` shaped by a semantic color role, a visual weight variant, and a\n * size, and holds its footprint while rendering a busy pending state.\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 { LoaderCircleIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, visibility } from \"@sdxc/u/effects\";\nimport { cursor, raw, userSelect, mergeMix } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tflex,\n\tgap,\n\tinlineFlex,\n\tinset,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { bs, is, minBs, p, pb, pi, pie, pis } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text } from \"@sdxc/u/typography\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { surfaceControl } from \"@sdxc/ui/styles\";\nimport { glyphEdges } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\nimport { CtaGroup } from \"@sdxc/ui/cta-group\";\n\nconst DEFAULT_COLOR: Button.Color = \"neutral\";\n\nconst DEFAULT_VARIANT: Button.Variant = \"solid\";\n\nconst DEFAULT_SIZE: Button.Size = \"md\";\n\n/** Edge of a small icon-only button, matching the `sm` row height. */\nconst ICON_ONLY_SIZE_SM = \"var(--ui-button-icon-size-sm, 2rem)\";\n\n/** Edge of a medium icon-only button, matching the `md` row height. */\nconst ICON_ONLY_SIZE_MD = \"var(--ui-button-icon-size-md, 2.5rem)\";\n\n/** Edge of a large icon-only button, matching the `lg` row height. */\nconst ICON_ONLY_SIZE_LG = \"var(--ui-button-icon-size-lg, 3rem)\";\n\n/**\n * Native `type` given to a button carrying `command`/`commandfor` and no\n * `type` of its own: the platform treats a button that could also submit as an\n * ambiguous invoker and skips its command, so an invoker needs this type.\n */\nconst INVOKER_TYPE = \"button\";\n\n/**\n * Prop types for {@link Button}.\n */\nexport namespace Button {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Visual weight the button renders with: a solid fill with an on-solid\n\t * foreground, a transparent fill with a strong colored border, a fully\n\t * transparent fill with just a colored label, or a raised `surface` fill with\n\t * the emphasis ink and a tactile edge — a secondary that reads as a control\n\t * beside a solid primary, and turns translucent inside inverse and brand bands.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\" | \"surface\";\n\n\t/**\n\t * Size variant controlling the button's padding and font size.\n\t * Inside a {@link CtaGroup} an omitted size takes the group's, so a hero row\n\t * sizes every action at once; `\"md\"` is the 40px landing CTA.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Per-part styling for the elements a pending button renders besides its\n\t * own host.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the decorative rotating glyph shown while pending. */\n\t\tspinner?: TagProps<\"span\">[\"mix\"];\n\t\t/**\n\t\t * Styling for the wrapper holding the button's own children while\n\t\t * pending; kept in the layout to preserve the button's footprint, but\n\t\t * hidden from view and from assistive technology.\n\t\t */\n\t\tcontent?: TagProps<\"span\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link Button}.\n\t */\n\texport interface Props extends TagProps<\"button\"> {\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */\n\t\tvariant?: Variant;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t\t/**\n\t\t * Marks the button busy: merges into the native `disabled` attribute and\n\t\t * swaps the visible content for a spinner glyph while holding the rendered\n\t\t * footprint, so a page mid-request keeps its layout.\n\t\t */\n\t\tisPending?: boolean;\n\t\t/** Per-part styling for the pending state's internal elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Reports whether `children` is a lone glyph, which is what makes a button a target for\n * that glyph rather than for a label. A selector cannot answer this: `:only-child`\n * counts elements, so a button holding text beside one icon still matches it.\n *\n * @param children The button's own children.\n * @returns Whether the button renders a single element and no text of its own.\n */\nfunction holdsOnlyAGlyph(children: RemixNode): boolean {\n\treturn typeof children === \"object\" && children !== null && !Array.isArray(children);\n}\n\n/**\n * Visual state lives in `data-color`/`data-variant`/`data-size` on the host, so\n * hover, pressed, and focus-visible stay on native pseudo-classes. `type` precedes\n * the spread so the platform sees it while parsing `command`/`commandfor`.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the button's markup.\n * @example\n * <Button type=\"submit\">{t(\"actions.save\")}</Button>\n * @example\n * <Button color=\"danger\" variant=\"outline\" size=\"sm\">{t(\"actions.delete\")}</Button>\n * @example\n * <Button type=\"submit\" isPending={isSubmitting}>{t(\"actions.save\")}</Button>\n * @example\n * <Button size=\"lg\" color=\"brand\" mix={[landingCtaChrome()]}>{t(\"hero.cta\")}</Button>\n */\nexport function Button(handle: Handle<Button.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, isPending, disabled, type, parts, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isInvoker = rest.command !== undefined || rest.commandfor !== undefined;\n\t\tlet resolvedType = type ?? (isInvoker ? INVOKER_TYPE : undefined);\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet group = handle.context.get(CtaGroup) as CtaGroup.Context | undefined;\n\t\tlet resolvedSize = size ?? group?.size ?? DEFAULT_SIZE;\n\t\tlet resolvedDisabled = disabled || isPending;\n\t\tlet iconOnly = holdsOnlyAGlyph(children);\n\t\tlet edges = glyphEdges(children);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"Button: an icon-only button needs an `aria-label` describing what it does — assistive technology has no accessible text to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-variant={resolvedVariant}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tdata-pending={isPending || undefined}\n\t\t\t\tdata-icon-only={iconOnly || undefined}\n\t\t\t\tdata-glyph-start={edges.start || undefined}\n\t\t\t\tdata-glyph-end={edges.end || undefined}\n\t\t\t\tdisabled={resolvedDisabled}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', outline(\"neutral.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', outline(\"success.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', outline(\"warning.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', outline(\"danger.ring\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\tinlineFlex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tgap(2),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A glyph is measured against the label it sits beside rather than against\n\t\t\t\t\t\t * whatever an icon set draws at, so the row keeps the height its text and\n\t\t\t\t\t\t * padding ask for. It never shrinks either: squeeze the row and the default\n\t\t\t\t\t\t * `flex-shrink: 1` compresses the glyph rather than the words, and a squashed\n\t\t\t\t\t\t * icon reads as a rendering fault.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tborderRadius: \"var(--ui-button-radius, var(--ui-radius-md, 0.375rem))\",\n\t\t\t\t\t\t\tfontWeight: \"var(--ui-button-weight, 500)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A small control reaches `--ui-target-size` however a consumer positions it. The\n\t\t\t\t\t\t * control is its target's containing block, so a scrolling row of buttons clips\n\t\t\t\t\t\t * every target and the page never grows to fit one; a consumer's own position\n\t\t\t\t\t\t * utility in `mix` replaces it.\n\t\t\t\t\t\t */\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\thitArea({ anchor: \"flex-center\" }),\n\t\t\t\t\t\tuserSelect(),\n\n\t\t\t\t\t\tpi(4),\n\t\t\t\t\t\tpb(2),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Every variant carries the same border width, colored to match its own\n\t\t\t\t\t\t * fill (transparent for ghost), so solid and ghost render the exact\n\t\t\t\t\t\t * footprint outline does.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The row measure is stated rather than left to fall out of the padding and\n\t\t\t\t\t\t * the border, so the control lines up with a field of the same size when a\n\t\t\t\t\t\t * Group fuses the two, and still grows when a long label wraps.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tminBs(\"2.5rem\"),\n\n\t\t\t\t\t\twhen('&[data-size=\"sm\"]', [\n\t\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\t\tpb(1.5),\n\t\t\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\t\t\tminBs(\"2rem\"),\n\t\t\t\t\t\t\twhen(\"& > svg\", [is(3), bs(3)]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"]', [\n\t\t\t\t\t\t\tpi(5),\n\t\t\t\t\t\t\tpb(2.5),\n\t\t\t\t\t\t\ttext(\"base\"),\n\t\t\t\t\t\t\tminBs(\"3rem\"),\n\t\t\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A glyph beside a label carries its own side bearing, so the padding on that\n\t\t\t\t\t\t * side drops one step and the glyph and the words read as evenly inset.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-glyph-start]:has(> svg:first-child)\", [\n\t\t\t\t\t\t\tpis(3),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pis(2)),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pis(4)),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&[data-glyph-end]:has(> svg:last-child)\", [\n\t\t\t\t\t\t\tpie(3),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pie(2)),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pie(4)),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A button holding a glyph and nothing else is a target for that glyph alone, so\n\t\t\t\t\t\t * it takes a round footprint as tall as the row it would otherwise fill. The\n\t\t\t\t\t\t * measure is a custom property per size, since a box sized by its own content on\n\t\t\t\t\t\t * both axes has no ratio to resolve against, and an app or a composing part can\n\t\t\t\t\t\t * resize it without touching the rule.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-icon-only]\", [\n\t\t\t\t\t\t\tp(0),\n\t\t\t\t\t\t\tis(ICON_ONLY_SIZE_MD),\n\t\t\t\t\t\t\tbs(ICON_ONLY_SIZE_MD),\n\t\t\t\t\t\t\tminBs(ICON_ONLY_SIZE_MD),\n\t\t\t\t\t\t\tshrink(),\n\t\t\t\t\t\t\traw({ \"--ui-button-radius\": \"9999px\" }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-size=\"sm\"][data-icon-only]', [\n\t\t\t\t\t\t\tis(ICON_ONLY_SIZE_SM),\n\t\t\t\t\t\t\tbs(ICON_ONLY_SIZE_SM),\n\t\t\t\t\t\t\tminBs(ICON_ONLY_SIZE_SM),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"][data-icon-only]', [\n\t\t\t\t\t\t\tis(ICON_ONLY_SIZE_LG),\n\t\t\t\t\t\t\tbs(ICON_ONLY_SIZE_LG),\n\t\t\t\t\t\t\tminBs(ICON_ONLY_SIZE_LG),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen('&[data-variant=\"solid\"]', [\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\t\tborder(\"brand.solid\"),\n\t\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"brand.bg-solid-hover\"), border(\"brand.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [bg(\"brand.bg-solid-pressed\"), border(\"brand.bg-solid-pressed\")]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tborder(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"neutral.bg-solid-hover\"), border(\"neutral.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"neutral.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"neutral.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tbg(\"success.solid\"),\n\t\t\t\t\t\t\t\tborder(\"success.solid\"),\n\t\t\t\t\t\t\t\tfg(\"success.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"success.bg-solid-hover\"), border(\"success.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"success.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"success.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tbg(\"warning.solid\"),\n\t\t\t\t\t\t\t\tborder(\"warning.solid\"),\n\t\t\t\t\t\t\t\tfg(\"warning.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"warning.bg-solid-hover\"), border(\"warning.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"warning.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"warning.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tbg(\"danger.solid\"),\n\t\t\t\t\t\t\t\tborder(\"danger.solid\"),\n\t\t\t\t\t\t\t\tfg(\"danger.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"danger.bg-solid-hover\"), border(\"danger.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"danger.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"danger.bg-solid-pressed\"),\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\n\t\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tborder(\"brand\"),\n\t\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"brand.tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"neutral.tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tborder(\"success\"),\n\t\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"success.tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tborder(\"warning\"),\n\t\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"warning.tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"danger.tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen('&[data-variant=\"ghost\"]', [\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t\tborder(\"transparent\"),\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"brand.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"success.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"warning.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"danger.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen('&[data-variant=\"surface\"]', [surfaceControl()]),\n\n\t\t\t\t\t\twhen(\"&:disabled:not([data-pending])\", [cursor(\"not-allowed\"), opacity(50)]),\n\n\t\t\t\t\t\twhen(\"&[data-pending]\", [relative(), cursor(\"wait\")]),\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{isPending ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\tdata-slot=\"spinner\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\tabsolute(),\n\t\t\t\t\t\t\t\tinset(0),\n\t\t\t\t\t\t\t\tflex(),\n\t\t\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\t\t\twhen(\"& svg\", [\n\t\t\t\t\t\t\t\t\tis(\"var(--ui-spinner-icon-size-sm, 1rem)\"),\n\t\t\t\t\t\t\t\t\tbs(\"var(--ui-spinner-icon-size-sm, 1rem)\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\twhen('[data-size=\"lg\"] & svg', [\n\t\t\t\t\t\t\t\t\tis(\"var(--ui-spinner-icon-size-md, 1.25rem)\"),\n\t\t\t\t\t\t\t\t\tbs(\"var(--ui-spinner-icon-size-md, 1.25rem)\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\tparts?.spinner,\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<LoaderCircleIcon />\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tdata-slot=\"content\"\n\t\t\t\t\t\t\tmix={[visibility(\"hidden\"), inlineFlex(), items(\"center\"), gap(2), parts?.content]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\tchildren\n\t\t\t\t)}\n\t\t\t</button>\n\t\t);\n\t};\n}\n"
12
+ "content": "/**\n * An interactive control for a single, immediate action — submitting a form,\n * triggering a command, opening a dialog. Its host renders as a native\n * `<button>` shaped by a semantic color role, a visual weight variant, and a\n * size, and holds its footprint while rendering a busy pending state.\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 { LoaderCircleIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, visibility } from \"@sdxc/u/effects\";\nimport { cursor, raw, userSelect, mergeMix } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tflex,\n\tgap,\n\tinlineFlex,\n\tinset,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { bs, is, minBs, p, pb, pi, pie, pis } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text } from \"@sdxc/u/typography\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { spin } from \"@sdxc/ui/animations\";\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { surfaceControl } from \"@sdxc/ui/styles\";\nimport { glyphEdges } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\nimport { CtaGroup } from \"@sdxc/ui/cta-group\";\n\nconst DEFAULT_COLOR: Button.Color = \"neutral\";\n\nconst DEFAULT_VARIANT: Button.Variant = \"solid\";\n\nconst DEFAULT_SIZE: Button.Size = \"md\";\n\n/** Edge of a small icon-only button, matching the `sm` row height. */\nconst ICON_ONLY_SIZE_SM = \"var(--ui-button-icon-size-sm, 2rem)\";\n\n/** Edge of a medium icon-only button, matching the `md` row height. */\nconst ICON_ONLY_SIZE_MD = \"var(--ui-button-icon-size-md, 2.5rem)\";\n\n/** Edge of a large icon-only button, matching the `lg` row height. */\nconst ICON_ONLY_SIZE_LG = \"var(--ui-button-icon-size-lg, 3rem)\";\n\n/**\n * Native `type` given to a button carrying `command`/`commandfor` and no\n * `type` of its own: the platform treats a button that could also submit as an\n * ambiguous invoker and skips its command, so an invoker needs this type.\n */\nconst INVOKER_TYPE = \"button\";\n\n/**\n * Prop types for {@link Button}.\n */\nexport namespace Button {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Visual weight the button renders with: a solid fill with an on-solid\n\t * foreground, a transparent fill with a strong colored border, a fully\n\t * transparent fill with just a colored label, or a raised `surface` fill with\n\t * the emphasis ink and a tactile edge — a secondary that reads as a control\n\t * beside a solid primary, and turns translucent inside inverse and brand bands.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\" | \"surface\";\n\n\t/**\n\t * Size variant controlling the button's padding and font size.\n\t * Inside a {@link CtaGroup} an omitted size takes the group's, so a hero row\n\t * sizes every action at once; `\"md\"` is the 40px landing CTA.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Props accepted by {@link Button}.\n\t */\n\texport interface Props extends TagProps<\"button\"> {\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */\n\t\tvariant?: Variant;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t\t/**\n\t\t * Marks the button busy: merges into the native `disabled` attribute and\n\t\t * swaps the visible content for a rotating spinner glyph while holding the\n\t\t * rendered footprint, so a page mid-request keeps its layout.\n\t\t */\n\t\tisPending?: boolean;\n\t}\n}\n\n/**\n * Reports whether `children` is a lone glyph, which is what makes a button a target for\n * that glyph rather than for a label. A selector cannot answer this: `:only-child`\n * counts elements, so a button holding text beside one icon still matches it.\n *\n * @param children The button's own children.\n * @returns Whether the button renders a single element and no text of its own.\n */\nfunction holdsOnlyAGlyph(children: RemixNode): boolean {\n\treturn typeof children === \"object\" && children !== null && !Array.isArray(children);\n}\n\n/**\n * Visual state lives in `data-color`/`data-variant`/`data-size` on the host, so\n * hover, pressed, and focus-visible stay on native pseudo-classes. `type` precedes\n * the spread so the platform sees it while parsing `command`/`commandfor`.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the button's markup.\n * @example\n * <Button type=\"submit\">{t(\"actions.save\")}</Button>\n * @example\n * <Button color=\"danger\" variant=\"outline\" size=\"sm\">{t(\"actions.delete\")}</Button>\n * @example\n * <Button type=\"submit\" isPending={isSubmitting}>{t(\"actions.save\")}</Button>\n * @example\n * <Button size=\"lg\" color=\"brand\" mix={[landingCtaChrome()]}>{t(\"hero.cta\")}</Button>\n */\nexport function Button(handle: Handle<Button.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, isPending, disabled, type, children, mix, ...rest } = handle.props;\n\t\tlet isInvoker = rest.command !== undefined || rest.commandfor !== undefined;\n\t\tlet resolvedType = type ?? (isInvoker ? INVOKER_TYPE : undefined);\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet group = handle.context.get(CtaGroup) as CtaGroup.Context | undefined;\n\t\tlet resolvedSize = size ?? group?.size ?? DEFAULT_SIZE;\n\t\tlet resolvedDisabled = disabled || isPending;\n\t\tlet iconOnly = holdsOnlyAGlyph(children);\n\t\tlet edges = glyphEdges(children);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"Button: an icon-only button needs an `aria-label` describing what it does — assistive technology has no accessible text to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-variant={resolvedVariant}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tdata-pending={isPending || undefined}\n\t\t\t\tdata-icon-only={iconOnly || undefined}\n\t\t\t\tdata-glyph-start={edges.start || undefined}\n\t\t\t\tdata-glyph-end={edges.end || undefined}\n\t\t\t\tdisabled={resolvedDisabled}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', outline(\"neutral.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', outline(\"success.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', outline(\"warning.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', outline(\"danger.ring\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\tinlineFlex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tgap(2),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A glyph is measured against the label it sits beside rather than against\n\t\t\t\t\t\t * whatever an icon set draws at, so the row keeps the height its text and\n\t\t\t\t\t\t * padding ask for. It never shrinks either: squeeze the row and the default\n\t\t\t\t\t\t * `flex-shrink: 1` compresses the glyph rather than the words, and a squashed\n\t\t\t\t\t\t * icon reads as a rendering fault.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tborderRadius: \"var(--ui-button-radius, var(--ui-radius-md, 0.375rem))\",\n\t\t\t\t\t\t\tfontWeight: \"var(--ui-button-weight, 500)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A small control reaches `--ui-target-size` however a consumer positions it. The\n\t\t\t\t\t\t * control is its target's containing block, so a scrolling row of buttons clips\n\t\t\t\t\t\t * every target and the page never grows to fit one; a consumer's own position\n\t\t\t\t\t\t * utility in `mix` replaces it.\n\t\t\t\t\t\t */\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\thitArea({ anchor: \"flex-center\" }),\n\t\t\t\t\t\tuserSelect(),\n\n\t\t\t\t\t\tpi(4),\n\t\t\t\t\t\tpb(2),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Every variant carries the same border width, colored to match its own\n\t\t\t\t\t\t * fill (transparent for ghost), so solid and ghost render the exact\n\t\t\t\t\t\t * footprint outline does.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The row measure is stated rather than left to fall out of the padding and\n\t\t\t\t\t\t * the border, so the control lines up with a field of the same size when a\n\t\t\t\t\t\t * Group fuses the two, and still grows when a long label wraps.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tminBs(\"2.5rem\"),\n\n\t\t\t\t\t\twhen('&[data-size=\"sm\"]', [\n\t\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\t\tpb(1.5),\n\t\t\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\t\t\tminBs(\"2rem\"),\n\t\t\t\t\t\t\twhen(\"& > svg\", [is(3), bs(3)]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"]', [\n\t\t\t\t\t\t\tpi(5),\n\t\t\t\t\t\t\tpb(2.5),\n\t\t\t\t\t\t\ttext(\"base\"),\n\t\t\t\t\t\t\tminBs(\"3rem\"),\n\t\t\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A glyph beside a label carries its own side bearing, so the padding on that\n\t\t\t\t\t\t * side drops one step and the glyph and the words read as evenly inset.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-glyph-start]:has(> svg:first-child)\", [\n\t\t\t\t\t\t\tpis(3),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pis(2)),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pis(4)),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&[data-glyph-end]:has(> svg:last-child)\", [\n\t\t\t\t\t\t\tpie(3),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pie(2)),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pie(4)),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A button holding a glyph and nothing else is a target for that glyph alone, so\n\t\t\t\t\t\t * it takes a round footprint as tall as the row it would otherwise fill. The\n\t\t\t\t\t\t * measure is a custom property per size, since a box sized by its own content on\n\t\t\t\t\t\t * both axes has no ratio to resolve against, and an app or a composing part can\n\t\t\t\t\t\t * resize it without touching the rule.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-icon-only]\", [\n\t\t\t\t\t\t\tp(0),\n\t\t\t\t\t\t\tis(ICON_ONLY_SIZE_MD),\n\t\t\t\t\t\t\tbs(ICON_ONLY_SIZE_MD),\n\t\t\t\t\t\t\tminBs(ICON_ONLY_SIZE_MD),\n\t\t\t\t\t\t\tshrink(),\n\t\t\t\t\t\t\traw({ \"--ui-button-radius\": \"9999px\" }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-size=\"sm\"][data-icon-only]', [\n\t\t\t\t\t\t\tis(ICON_ONLY_SIZE_SM),\n\t\t\t\t\t\t\tbs(ICON_ONLY_SIZE_SM),\n\t\t\t\t\t\t\tminBs(ICON_ONLY_SIZE_SM),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"][data-icon-only]', [\n\t\t\t\t\t\t\tis(ICON_ONLY_SIZE_LG),\n\t\t\t\t\t\t\tbs(ICON_ONLY_SIZE_LG),\n\t\t\t\t\t\t\tminBs(ICON_ONLY_SIZE_LG),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen('&[data-variant=\"solid\"]', [\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\t\tborder(\"brand.solid\"),\n\t\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"brand.bg-solid-hover\"), border(\"brand.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [bg(\"brand.bg-solid-pressed\"), border(\"brand.bg-solid-pressed\")]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tborder(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"neutral.bg-solid-hover\"), border(\"neutral.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"neutral.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"neutral.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tbg(\"success.solid\"),\n\t\t\t\t\t\t\t\tborder(\"success.solid\"),\n\t\t\t\t\t\t\t\tfg(\"success.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"success.bg-solid-hover\"), border(\"success.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"success.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"success.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tbg(\"warning.solid\"),\n\t\t\t\t\t\t\t\tborder(\"warning.solid\"),\n\t\t\t\t\t\t\t\tfg(\"warning.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"warning.bg-solid-hover\"), border(\"warning.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"warning.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"warning.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tbg(\"danger.solid\"),\n\t\t\t\t\t\t\t\tborder(\"danger.solid\"),\n\t\t\t\t\t\t\t\tfg(\"danger.onSolid\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"danger.bg-solid-hover\"), border(\"danger.bg-solid-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", [\n\t\t\t\t\t\t\t\t\tbg(\"danger.bg-solid-pressed\"),\n\t\t\t\t\t\t\t\t\tborder(\"danger.bg-solid-pressed\"),\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\n\t\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tborder(\"brand\"),\n\t\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"brand.tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"neutral.tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tborder(\"success\"),\n\t\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"success.tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tborder(\"warning\"),\n\t\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"warning.tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", [bg(\"danger.tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen('&[data-variant=\"ghost\"]', [\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t\tborder(\"transparent\"),\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"brand.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"success.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"warning.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\t\twhen(\"&:hover\", bg(\"danger.tint\")),\n\t\t\t\t\t\t\t\twhen(\"&:active\", bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen('&[data-variant=\"surface\"]', [surfaceControl()]),\n\n\t\t\t\t\t\twhen(\"&:disabled:not([data-pending])\", [cursor(\"not-allowed\"), opacity(50)]),\n\n\t\t\t\t\t\twhen(\"&[data-pending]\", [relative(), cursor(\"wait\")]),\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{isPending ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t\tdata-slot=\"spinner\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\tabsolute(),\n\t\t\t\t\t\t\t\tinset(0),\n\t\t\t\t\t\t\t\tflex(),\n\t\t\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\t\t\twhen(\"& svg\", [\n\t\t\t\t\t\t\t\t\tis(\"var(--ui-spinner-icon-size-sm, 1rem)\"),\n\t\t\t\t\t\t\t\t\tbs(\"var(--ui-spinner-icon-size-sm, 1rem)\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\twhen('[data-size=\"lg\"] & svg', [\n\t\t\t\t\t\t\t\t\tis(\"var(--ui-spinner-icon-size-md, 1.25rem)\"),\n\t\t\t\t\t\t\t\t\tbs(\"var(--ui-spinner-icon-size-md, 1.25rem)\"),\n\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\tspin(),\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<LoaderCircleIcon />\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tdata-slot=\"content\"\n\t\t\t\t\t\t\tmix={[visibility(\"hidden\"), inlineFlex(), items(\"center\"), gap(2)]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\tchildren\n\t\t\t\t)}\n\t\t\t</button>\n\t\t);\n\t};\n}\n"
13
13
  },
14
14
  "test": {
15
15
  "path": "button.test.tsx",
16
- "content": "/**\n * Tests for {@link Button}: the `type` an Invoker Command needs (and where it is written),\n * the per-size icon-only measure, the glyph-edge markers that trim padding beside a\n * leading or trailing glyph, and the pointer target box drawn however it is positioned.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\ndescribe(Button.name, () => {\n\ttest('types itself \"button\" when it carries a command, so its command survives inside a form', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button commandfor=\"confirm-delete\" command=\"show-modal\">\n\t\t\t\tDelete\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest('types itself \"button\" when it carries only a commandfor', async () => {\n\t\tlet html = await renderToString(<Button commandfor=\"confirm-delete\">Delete</Button>);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest(\"renders no type of its own for a button carrying no command\", async () => {\n\t\tlet html = await renderToString(<Button>Save</Button>);\n\n\t\texpect(html).not.toContain(\"type=\");\n\t});\n\n\ttest(\"leaves an explicitly typed submit button alone\", async () => {\n\t\tlet html = await renderToString(<Button type=\"submit\">Save</Button>);\n\n\t\texpect(html).toContain('type=\"submit\"');\n\t});\n\n\ttest(\"writes type before the command attributes, which is where the platform reads it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button commandfor=\"confirm-delete\" command=\"show-modal\">\n\t\t\t\tDelete\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"command=\"));\n\t});\n\n\ttest(\"writes an explicit type before the command attributes too\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button type=\"button\" commandfor=\"confirm-delete\" command=\"close\">\n\t\t\t\tCancel\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t});\n\n\ttest(\"respects an explicit type even on a command invoker\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button type=\"reset\" commandfor=\"confirm-delete\" command=\"close\">\n\t\t\t\tReset\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"reset\"');\n\t\texpect(html).not.toContain('type=\"button\"');\n\t});\n\n\ttest(\"sizes an icon-only button from a per-size custom property\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button size=\"sm\" aria-label=\"Close\">\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toContain(\"data-icon-only\");\n\t\texpect(html).toContain(\"inline-size: var(--ui-button-icon-size-sm, 2rem);\");\n\t\texpect(html).toContain(\"inline-size: var(--ui-button-icon-size-md, 2.5rem);\");\n\t\texpect(html).toContain(\"inline-size: var(--ui-button-icon-size-lg, 3rem);\");\n\t});\n\n\ttest(\"marks a leading glyph beside a label so its side's padding drops a step\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button>\n\t\t\t\t<svg />\n\t\t\t\tSave\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toMatch(/<button[^>]*data-glyph-start/);\n\t\texpect(html).not.toMatch(/<button[^>]*data-glyph-end/);\n\t});\n\n\ttest(\"marks a trailing glyph after a label, even though :first-child would also match it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button>\n\t\t\t\tNext\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toMatch(/<button[^>]*data-glyph-end/);\n\t\texpect(html).not.toMatch(/<button[^>]*data-glyph-start/);\n\t});\n\n\ttest(\"marks neither edge on an icon-only or text-only button\", async () => {\n\t\tlet iconOnly = await renderToString(\n\t\t\t<Button aria-label=\"Close\">\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\t\tlet textOnly = await renderToString(<Button>Save</Button>);\n\n\t\texpect(iconOnly).not.toMatch(/<button[^>]*data-glyph-/);\n\t\texpect(textOnly).not.toMatch(/<button[^>]*data-glyph-/);\n\t});\n\n\ttest(\"draws an unanchored target box, so it reaches --ui-target-size however it is positioned\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button size=\"sm\" aria-label=\"Close\">\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toMatch(\n\t\t\t/&::after \\{[^}]*position: absolute;[^}]*inline-size: var\\(--ui-target-size, 1\\.5rem\\);[^}]*block-size: var\\(--ui-target-size, 1\\.5rem\\);/,\n\t\t);\n\t\texpect(html).not.toMatch(/&::after \\{[^}]*inset/);\n\t});\n});\n"
16
+ "content": "/**\n * Tests for {@link Button}: the `type` an Invoker Command needs (and where it is written),\n * the per-size icon-only measure, the glyph-edge markers that trim padding beside a\n * leading or trailing glyph, and the pointer target box drawn however it is positioned.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\ndescribe(Button.name, () => {\n\ttest('types itself \"button\" when it carries a command, so its command survives inside a form', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button commandfor=\"confirm-delete\" command=\"show-modal\">\n\t\t\t\tDelete\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest('types itself \"button\" when it carries only a commandfor', async () => {\n\t\tlet html = await renderToString(<Button commandfor=\"confirm-delete\">Delete</Button>);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest(\"rotates the spinner a pending button shows in place of its label\", async () => {\n\t\tlet html = await renderToString(<Button isPending>Publishing</Button>);\n\n\t\texpect(html).toContain('data-slot=\"spinner\"');\n\t\texpect(html).toContain(\"ui-spin-rotate\");\n\t});\n\n\ttest(\"renders no type of its own for a button carrying no command\", async () => {\n\t\tlet html = await renderToString(<Button>Save</Button>);\n\n\t\texpect(html).not.toContain(\"type=\");\n\t});\n\n\ttest(\"leaves an explicitly typed submit button alone\", async () => {\n\t\tlet html = await renderToString(<Button type=\"submit\">Save</Button>);\n\n\t\texpect(html).toContain('type=\"submit\"');\n\t});\n\n\ttest(\"writes type before the command attributes, which is where the platform reads it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button commandfor=\"confirm-delete\" command=\"show-modal\">\n\t\t\t\tDelete\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"command=\"));\n\t});\n\n\ttest(\"writes an explicit type before the command attributes too\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button type=\"button\" commandfor=\"confirm-delete\" command=\"close\">\n\t\t\t\tCancel\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t});\n\n\ttest(\"respects an explicit type even on a command invoker\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button type=\"reset\" commandfor=\"confirm-delete\" command=\"close\">\n\t\t\t\tReset\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"reset\"');\n\t\texpect(html).not.toContain('type=\"button\"');\n\t});\n\n\ttest(\"sizes an icon-only button from a per-size custom property\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button size=\"sm\" aria-label=\"Close\">\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toContain(\"data-icon-only\");\n\t\texpect(html).toContain(\"inline-size: var(--ui-button-icon-size-sm, 2rem);\");\n\t\texpect(html).toContain(\"inline-size: var(--ui-button-icon-size-md, 2.5rem);\");\n\t\texpect(html).toContain(\"inline-size: var(--ui-button-icon-size-lg, 3rem);\");\n\t});\n\n\ttest(\"marks a leading glyph beside a label so its side's padding drops a step\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button>\n\t\t\t\t<svg />\n\t\t\t\tSave\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toMatch(/<button[^>]*data-glyph-start/);\n\t\texpect(html).not.toMatch(/<button[^>]*data-glyph-end/);\n\t});\n\n\ttest(\"marks a trailing glyph after a label, even though :first-child would also match it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button>\n\t\t\t\tNext\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toMatch(/<button[^>]*data-glyph-end/);\n\t\texpect(html).not.toMatch(/<button[^>]*data-glyph-start/);\n\t});\n\n\ttest(\"marks neither edge on an icon-only or text-only button\", async () => {\n\t\tlet iconOnly = await renderToString(\n\t\t\t<Button aria-label=\"Close\">\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\t\tlet textOnly = await renderToString(<Button>Save</Button>);\n\n\t\texpect(iconOnly).not.toMatch(/<button[^>]*data-glyph-/);\n\t\texpect(textOnly).not.toMatch(/<button[^>]*data-glyph-/);\n\t});\n\n\ttest(\"draws an unanchored target box, so it reaches --ui-target-size however it is positioned\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Button size=\"sm\" aria-label=\"Close\">\n\t\t\t\t<svg />\n\t\t\t</Button>,\n\t\t);\n\n\t\texpect(html).toMatch(\n\t\t\t/&::after \\{[^}]*position: absolute;[^}]*inline-size: var\\(--ui-target-size, 1\\.5rem\\);[^}]*block-size: var\\(--ui-target-size, 1\\.5rem\\);/,\n\t\t);\n\t\texpect(html).not.toMatch(/&::after \\{[^}]*inset/);\n\t});\n});\n"
17
17
  }
18
18
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "callout",
3
+ "changedIn": "2026.11.29",
4
+ "dependencies": [],
5
+ "exports": [
6
+ "Callout"
7
+ ],
8
+ "source": {
9
+ "path": "callout.tsx",
10
+ "content": "/**\n * A docs aside for the one thing a reader must not miss: a note, a tip, a warning or a\n * danger, tinted lightly in its kind's colour and opened by a title led by the kind's icon.\n * It is static content present at load, so it is a named `<aside>` and never a live region.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { InfoIcon, LightbulbIcon, OctagonAlertIcon, TriangleAlertIcon } from \"@sdxc/icons\";\nimport { bg, border, colorMix, fg } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { hstack, inlineFlex, vstack } from \"@sdxc/u/layout\";\nimport { m, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { leading, overflowWrap, text, weight } from \"@sdxc/u/typography\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\n/**\n * Prop types for {@link Callout} and its parts.\n */\nexport namespace Callout {\n\t/**\n\t * How serious the aside is, from adding context to warning of loss. Each kind draws\n\t * its own icon as well as its own colour, so kinds read apart without colour.\n\t */\n\texport type Kind = \"note\" | \"tip\" | \"warning\" | \"danger\";\n\n\t/** What the aside shares with its title. */\n\texport interface Context {\n\t\tkind: Kind;\n\t\t/** The id {@link Callout.Title} takes, which names the aside. */\n\t\ttitleId: string;\n\t}\n\n\t/**\n\t * Native `<aside>` attributes plus the kind. The aside is named by its\n\t * {@link Callout.Title}, or by `aria-label` when it has none.\n\t */\n\texport interface Props extends TagProps<\"aside\"> {\n\t\tkind: Kind;\n\t}\n\n\t/** Every native `<p>` attribute. */\n\texport interface TitleProps extends TagProps<\"p\"> {}\n}\n\n/** The marker attribute the aside's layout selects its title by. */\nconst PART = \"data-callout-part\";\n\n/** The semantic tone and glyph each kind draws with. */\nconst CALLOUT_KINDS: Record<Callout.Kind, { tone: SemanticColor; Glyph: typeof InfoIcon }> = {\n\tnote: { tone: \"brand\", Glyph: InfoIcon },\n\ttip: { tone: \"success\", Glyph: LightbulbIcon },\n\twarning: { tone: \"warning\", Glyph: TriangleAlertIcon },\n\tdanger: { tone: \"danger\", Glyph: OctagonAlertIcon },\n};\n\n/**\n * Mixes a share of a tone's text colour into transparency, so the tint and the border\n * follow the theme's light and dark values of that tone.\n *\n * @param tone Semantic tone to mix from.\n * @param weight Percentage of the tone in the mix.\n */\nfunction toneMix(tone: SemanticColor, weight: number) {\n\treturn colorMix(\"oklab\", { color: `var(--ui-${tone}-fg)`, weight }, \"transparent\");\n}\n\n/**\n * Renders the aside: a 6% tint with a 30% border of the kind's colour and a small radius,\n * named by its {@link Callout.Title}. Text keeps the page's ink in both themes, so a long\n * callout reads like the prose around it.\n *\n * @param handle Runtime handle carrying the host `<aside>`'s props.\n * @returns The render function producing the callout's markup.\n * @example\n * <Callout kind=\"warning\">\n * \t<Callout.Title>{t(\"callout.warning\")}</Callout.Title>\n * \t<p>Rotate the key before you deploy.</p>\n * </Callout>\n */\nexport function Callout(handle: Handle<Callout.Props, Callout.Context>) {\n\treturn () => {\n\t\tlet { kind, mix, ...rest } = handle.props;\n\t\tlet { tone } = CALLOUT_KINDS[kind] ?? CALLOUT_KINDS.note;\n\t\tlet titleId = `${handle.id}-title`;\n\t\thandle.context.set({ kind, titleId });\n\n\t\treturn (\n\t\t\t<aside\n\t\t\t\taria-labelledby={rest[\"aria-label\"] === undefined ? titleId : undefined}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"callout\"\n\t\t\t\tdata-kind={kind}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tvstack({ gap: 2, align: \"stretch\" }),\n\t\t\t\t\t\tminIs(0),\n\t\t\t\t\t\tp(3, 4),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ color: toneMix(tone, 30), width: 1, style: \"solid\" }),\n\t\t\t\t\t\tbg(toneMix(tone, 6)),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tleading(\"relaxed\"),\n\t\t\t\t\t\toverflowWrap(\"anywhere\"),\n\t\t\t\t\t\twhen(`& > :where(:not([${PART}=title]))`, m(0)),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * The heading line that opens the aside, led by the kind's glyph in the kind's colour: the\n * kind's name in the reader's language (\"Note\", \"Warning\") or a specific heading.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the heading line.\n * @example <Callout.Title>Faster local runs</Callout.Title>\n */\nCallout.Title = function CalloutTitle(handle: Handle<Callout.TitleProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Callout) as Callout.Context | undefined;\n\t\tlet { tone, Glyph } = CALLOUT_KINDS[context?.kind ?? \"note\"] ?? CALLOUT_KINDS.note;\n\t\treturn (\n\t\t\t<p\n\t\t\t\tid={context?.titleId}\n\t\t\t\tdata-slot=\"callout-title\"\n\t\t\t\t{...rest}\n\t\t\t\tdata-callout-part=\"title\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[m(0), hstack({ gap: 2, align: \"center\" }), weight(\"semibold\"), fg(\"neutral.emphasis\")],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<span data-slot=\"callout-icon\" mix={[inlineFlex(), fg(tone)]}>\n\t\t\t\t\t<Glyph size={16} aria-hidden=\"true\" />\n\t\t\t\t</span>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n"
11
+ },
12
+ "test": {
13
+ "path": "callout.browser.test.tsx",
14
+ "content": "/**\n * Mounts callouts in a real browser and checks they stay static named asides, draw a\n * light tint with a stronger border in the kind's colour, and wrap long content inside\n * a phone-width column.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { RemixNode } from \"remix/component\";\n\nimport { render } from \"remix/component/test\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Callout } from \"@sdxc/ui/callout\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/**\n * Opaque text colours for each tone, set on the host because an app's palette, not the\n * package, defines the tone tokens.\n */\nconst TONE_INKS: Record<string, string> = {\n\t\"--ui-brand-fg\": \"rgb(37, 99, 235)\",\n\t\"--ui-success-fg\": \"rgb(22, 163, 74)\",\n\t\"--ui-warning-fg\": \"rgb(202, 138, 4)\",\n\t\"--ui-danger-fg\": \"rgb(220, 38, 38)\",\n};\n\n/** Mounts a node in a column of the given width and returns its first child. */\nfunction mount(node: RemixNode, width = 640): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tfor (let [name, value] of Object.entries(TONE_INKS)) host.style.setProperty(name, value);\n\tdocument.body.appendChild(host);\n\treturn render(node, { container: host }).container.firstElementChild as HTMLElement;\n}\n\n/** Reads a colour's alpha channel from any computed `rgb()`, `rgba()` or `color()` value. */\nfunction alpha(value: string): number {\n\tlet probe = document.createElement(\"canvas\").getContext(\"2d\")!;\n\tprobe.fillStyle = value;\n\tprobe.clearRect(0, 0, 1, 1);\n\tprobe.fillRect(0, 0, 1, 1);\n\treturn probe.getImageData(0, 0, 1, 1).data[3]! / 255;\n}\n\ndescribe(\"Callout\", () => {\n\ttest(\"is a named aside and never an alert or live region\", () => {\n\t\tlet aside = mount(\n\t\t\t<Callout kind=\"warning\">\n\t\t\t\t<Callout.Title>Warning</Callout.Title>\n\t\t\t\t<p>Rotate the key first.</p>\n\t\t\t</Callout>,\n\t\t);\n\n\t\texpect(aside.tagName).toBe(\"ASIDE\");\n\t\texpect(aside.getAttribute(\"role\")).toBeNull();\n\t\texpect(aside.getAttribute(\"aria-live\")).toBeNull();\n\t\tlet title = aside.querySelector<HTMLElement>('[data-slot=\"callout-title\"]')!;\n\t\texpect(aside.getAttribute(\"aria-labelledby\")).toBe(title.id);\n\t\texpect(title.textContent).toBe(\"Warning\");\n\t});\n\n\ttest(\"takes an explicit name over its title's\", () => {\n\t\tlet aside = mount(\n\t\t\t<Callout kind=\"tip\" aria-label=\"Tip: Faster local runs\">\n\t\t\t\t<Callout.Title>Faster local runs</Callout.Title>\n\t\t\t\t<p>Pass the watch flag.</p>\n\t\t\t</Callout>,\n\t\t);\n\n\t\texpect(aside.getAttribute(\"aria-label\")).toBe(\"Tip: Faster local runs\");\n\t\texpect(aside.getAttribute(\"aria-labelledby\")).toBeNull();\n\t\texpect(aside.querySelector('[data-slot=\"callout-title\"]')!.textContent).toBe(\n\t\t\t\"Faster local runs\",\n\t\t);\n\t});\n\n\ttest(\"tints lightly and borders more strongly in the kind's colour\", () => {\n\t\tfor (let kind of [\"note\", \"tip\", \"warning\", \"danger\"] as const) {\n\t\t\tlet style = getComputedStyle(\n\t\t\t\tmount(\n\t\t\t\t\t<Callout kind={kind}>\n\t\t\t\t\t\t<Callout.Title>{kind}</Callout.Title>\n\t\t\t\t\t\tBody\n\t\t\t\t\t</Callout>,\n\t\t\t\t),\n\t\t\t);\n\t\t\tlet fill = alpha(style.backgroundColor);\n\t\t\tlet edge = alpha(style.borderTopColor);\n\n\t\t\texpect(fill, kind).toBeGreaterThan(0.03);\n\t\t\texpect(fill, kind).toBeLessThan(0.1);\n\t\t\texpect(edge, kind).toBeGreaterThan(0.2);\n\t\t\texpect(edge, kind).toBeLessThan(0.4);\n\t\t\texpect(style.borderTopWidth).toBe(\"1px\");\n\t\t}\n\t});\n\n\ttest(\"draws each kind's icon in a different colour\", () => {\n\t\tlet colors = new Set(\n\t\t\t([\"note\", \"tip\", \"warning\", \"danger\"] as const).map((kind) => {\n\t\t\t\tlet aside = mount(\n\t\t\t\t\t<Callout kind={kind}>\n\t\t\t\t\t\t<Callout.Title>{kind}</Callout.Title>\n\t\t\t\t\t\tBody\n\t\t\t\t\t</Callout>,\n\t\t\t\t);\n\t\t\t\treturn getComputedStyle(aside.querySelector('[data-slot=\"callout-icon\"]')!).color;\n\t\t\t}),\n\t\t);\n\n\t\texpect(colors.size).toBe(4);\n\t});\n\n\ttest(\"wraps an unbroken string inside a 320px column\", () => {\n\t\tlet aside = mount(\n\t\t\t<Callout kind=\"note\" aria-label=\"Note\">\n\t\t\t\t<p>Set SDXC_SUPER_LONG_ENVIRONMENT_VARIABLE_NAME_THAT_NEVER_BREAKS before you run it.</p>\n\t\t\t</Callout>,\n\t\t\t320,\n\t\t);\n\n\t\texpect(aside.getBoundingClientRect().width).toBeLessThanOrEqual(320);\n\t\texpect(aside.scrollWidth).toBeLessThanOrEqual(aside.clientWidth);\n\t});\n\n\ttest(\"draws a title alone with the note's icon\", () => {\n\t\tlet host = document.createElement(\"div\");\n\t\tdocument.body.appendChild(host);\n\t\trender(<Callout.Title>Heads up</Callout.Title>, { container: host });\n\n\t\texpect(host.querySelector('[data-slot=\"callout-icon\"] svg')).not.toBeNull();\n\t\texpect(host.textContent).toBe(\"Heads up\");\n\t});\n});\n"
15
+ }
16
+ }
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "checkbox",
3
- "changedIn": "2026.11.1",
3
+ "changedIn": "2026.11.29",
4
4
  "dependencies": [],
5
5
  "exports": [
6
6
  "Checkbox"
7
7
  ],
8
8
  "source": {
9
9
  "path": "checkbox.tsx",
10
- "content": "/**\n * A styled native checkbox: an `<input type=\"checkbox\">` paired with a\n * decorative glyph box that renders its check or dash mark purely from the\n * input's own state, wrapped in a `<label>` so clicking or tapping anywhere\n * in the row — box, glyph, or label text alike — toggles the control.\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, MinusIcon } from \"@sdxc/icons\";\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix } from \"@sdxc/u/general\";\nimport { block, center, hidden, hstack, relative, shrink } from \"@sdxc/u/layout\";\nimport { bs, is } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link Checkbox} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: Checkbox.Color = \"neutral\";\n\n/**\n * Prop types for {@link Checkbox}.\n */\nexport namespace Checkbox {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Per-part styling for the elements this convenience wrapper composes\n\t * internally alongside its own host `<input>`.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the decorative box rendering the checkmark or dash glyph. */\n\t\tbox?: TagProps<\"span\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link Checkbox}. Extends every native `<input>`\n\t * attribute except `type`, fixed to `\"checkbox\"`; `mix` styles that same\n\t * `<input>` host, and `role` is narrowed to what a checkbox input allows.\n\t */\n\texport interface Props extends Omit<TagProps<\"input\">, \"type\" | \"role\"> {\n\t\t/** ARIA role override, restricted to what a checkbox input may carry. */\n\t\trole?: \"checkbox\" | \"button\" | \"menuitemcheckbox\" | \"option\" | \"switch\";\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * Label content rendered after the box, inside the same native\n\t\t * `<label>` wrapping the row — clicking any of it toggles the checkbox\n\t\t * natively, with no separate `htmlFor`/`id` pair required.\n\t\t */\n\t\tchildren?: RemixNode;\n\t\t/** Per-part styling for this wrapper's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * The box precedes the input in source order so its `:has(~ input:…)` rules\n * can read state directly off it, keeping the whole control CSS-driven;\n * `shrink(0)` also keeps the box square regardless of label length.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the checkbox's markup.\n * @example\n * <Checkbox name=\"terms\" required>{t(\"signup.acceptTerms\")}</Checkbox>\n * @example\n * <Checkbox color=\"danger\" checked={row.flagged} aria-label={t(\"table.flagRow\")} />\n * @example\n * <Checkbox disabled defaultChecked>{t(\"settings.legacyOptIn\")}</Checkbox>\n */\nexport function Checkbox(handle: Handle<Checkbox.Props>) {\n\treturn () => {\n\t\tlet { color, children, parts, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"Checkbox: a checkbox with no visible label text needs an `aria-label` describing what it toggles — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<label mix={[relative(), hstack({ gap: 2, align: \"center\" })]}>\n\t\t\t\t<span\n\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\tdata-slot=\"box\"\n\t\t\t\t\tdata-color={resolvedColor}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tcenter(),\n\t\t\t\t\t\tis(\"var(--ui-checkbox-size, 1.25rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-checkbox-size, 1.25rem)\"),\n\t\t\t\t\t\tshrink(0),\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\tborder({ width: 2, color: \"neutral.strong\" }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tinteractiveTransition(),\n\n\t\t\t\t\t\twhen(\"& > svg\", [hidden(), is(\"0.75rem\"), bs(\"0.75rem\")]),\n\t\t\t\t\t\twhen(\"&:has(~ input:checked) > svg:first-child\", block()),\n\t\t\t\t\t\twhen(\"&:has(~ input:indeterminate) > svg:last-child\", block()),\n\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-color=\"brand\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"brand.solid\"),\n\t\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\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-color=\"neutral\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.onSolid\"),\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-color=\"success\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"success.solid\"),\n\t\t\t\t\t\t\t\tbg(\"success.solid\"),\n\t\t\t\t\t\t\t\tfg(\"success.onSolid\"),\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-color=\"warning\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"warning.solid\"),\n\t\t\t\t\t\t\t\tbg(\"warning.solid\"),\n\t\t\t\t\t\t\t\tfg(\"warning.onSolid\"),\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-color=\"danger\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"danger.solid\"),\n\t\t\t\t\t\t\t\tbg(\"danger.solid\"),\n\t\t\t\t\t\t\t\tfg(\"danger.onSolid\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t),\n\n\t\t\t\t\t\twhen(\"&:has(~ input:focus-visible)\", [\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', outline(\"neutral.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', outline(\"success.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', outline(\"warning.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', outline(\"danger.ring\")),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen(\"&:has(~ input:disabled)\", [cursor(\"not-allowed\"), opacity(50)]),\n\n\t\t\t\t\t\tparts?.box,\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<CheckIcon />\n\t\t\t\t\t<MinusIcon />\n\t\t\t\t</span>\n\t\t\t\t<input type=\"checkbox\" {...rest} mix={mergeMix(visuallyHidden(), mix)} />\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t};\n}\n"
10
+ "content": "/**\n * A styled native checkbox: an `<input type=\"checkbox\">` paired with a\n * decorative glyph box that renders its check or dash mark purely from the\n * input's own state, wrapped in a `<label>` so clicking or tapping anywhere\n * in the row — box, glyph, or label text alike — toggles the control.\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, MinusIcon } from \"@sdxc/icons\";\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, mergeMix } from \"@sdxc/u/general\";\nimport { block, center, hidden, hstack, relative, shrink } from \"@sdxc/u/layout\";\nimport { bs, is } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link Checkbox} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: Checkbox.Color = \"neutral\";\n\n/**\n * Prop types for {@link Checkbox}.\n */\nexport namespace Checkbox {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Props accepted by {@link Checkbox}. Extends every native `<input>`\n\t * attribute except `type`, fixed to `\"checkbox\"`; `mix` styles that same `<input>` host,\n\t * `role` is narrowed to what a checkbox input allows, and `--ui-checkbox-size` set on an\n\t * ancestor sizes the decorative box.\n\t */\n\texport interface Props extends Omit<TagProps<\"input\">, \"type\" | \"role\"> {\n\t\t/** ARIA role override, restricted to what a checkbox input may carry. */\n\t\trole?: \"checkbox\" | \"button\" | \"menuitemcheckbox\" | \"option\" | \"switch\";\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * Label content rendered after the box, inside the same native\n\t\t * `<label>` wrapping the row — clicking any of it toggles the checkbox\n\t\t * natively, with no separate `htmlFor`/`id` pair required.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n}\n\n/**\n * The box precedes the input in source order so its `:has(~ input:…)` rules\n * can read state directly off it, keeping the whole control CSS-driven;\n * `shrink(0)` also keeps the box square regardless of label length.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the checkbox's markup.\n * @example\n * <Checkbox name=\"terms\" required>{t(\"signup.acceptTerms\")}</Checkbox>\n * @example\n * <Checkbox color=\"danger\" checked={row.flagged} aria-label={t(\"table.flagRow\")} />\n * @example\n * <Checkbox disabled defaultChecked>{t(\"settings.legacyOptIn\")}</Checkbox>\n */\nexport function Checkbox(handle: Handle<Checkbox.Props>) {\n\treturn () => {\n\t\tlet { color, children, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"Checkbox: a checkbox with no visible label text needs an `aria-label` describing what it toggles — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<label mix={[relative(), hstack({ gap: 2, align: \"center\" })]}>\n\t\t\t\t<span\n\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\tdata-slot=\"box\"\n\t\t\t\t\tdata-color={resolvedColor}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tcenter(),\n\t\t\t\t\t\tis(\"var(--ui-checkbox-size, 1.25rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-checkbox-size, 1.25rem)\"),\n\t\t\t\t\t\tshrink(0),\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\tborder({ width: 2, color: \"neutral.strong\" }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tinteractiveTransition(),\n\n\t\t\t\t\t\twhen(\"& > svg\", [hidden(), is(\"0.75rem\"), bs(\"0.75rem\")]),\n\t\t\t\t\t\twhen(\"&:has(~ input:checked) > svg:first-child\", block()),\n\t\t\t\t\t\twhen(\"&:has(~ input:indeterminate) > svg:last-child\", block()),\n\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-color=\"brand\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"brand.solid\"),\n\t\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\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-color=\"neutral\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.onSolid\"),\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-color=\"success\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"success.solid\"),\n\t\t\t\t\t\t\t\tbg(\"success.solid\"),\n\t\t\t\t\t\t\t\tfg(\"success.onSolid\"),\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-color=\"warning\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"warning.solid\"),\n\t\t\t\t\t\t\t\tbg(\"warning.solid\"),\n\t\t\t\t\t\t\t\tfg(\"warning.onSolid\"),\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-color=\"danger\"]',\n\t\t\t\t\t\t\twhen(\"&:has(~ input:checked), &:has(~ input:indeterminate)\", [\n\t\t\t\t\t\t\t\tborder(\"danger.solid\"),\n\t\t\t\t\t\t\t\tbg(\"danger.solid\"),\n\t\t\t\t\t\t\t\tfg(\"danger.onSolid\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t),\n\n\t\t\t\t\t\twhen(\"&:has(~ input:focus-visible)\", [\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', outline(\"neutral.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"success\"]', outline(\"success.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"warning\"]', outline(\"warning.ring\")),\n\t\t\t\t\t\t\twhen('&[data-color=\"danger\"]', outline(\"danger.ring\")),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\twhen(\"&:has(~ input:disabled)\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<CheckIcon />\n\t\t\t\t\t<MinusIcon />\n\t\t\t\t</span>\n\t\t\t\t<input type=\"checkbox\" {...rest} mix={mergeMix(visuallyHidden(), mix)} />\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t};\n}\n"
11
11
  },
12
12
  "test": {
13
13
  "path": "checkbox.test.tsx",