@sdxc/kit 2026.10.30 → 2026.11.3
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.
- package/README.md +59 -0
- package/changelog.jsonl +346 -0
- package/config.schema.json +14 -0
- package/dist/ci/install.d.ts +15 -0
- package/dist/ci/install.js +27 -0
- package/dist/ci/locate.d.ts +23 -0
- package/dist/ci/locate.js +43 -0
- package/dist/cli.js +5 -0
- package/dist/commands/ci/list.d.ts +16 -0
- package/dist/commands/ci/list.js +24 -0
- package/dist/commands/ci/run.d.ts +65 -0
- package/dist/commands/ci/run.js +36 -0
- package/dist/commands/ci/signoff.d.ts +15 -0
- package/dist/commands/ci/signoff.js +15 -0
- package/dist/commands/ci/verify.d.ts +17 -0
- package/dist/commands/ci/verify.js +15 -0
- package/dist/commands/create.js +3 -0
- package/dist/commands/pkg.d.ts +16 -0
- package/dist/commands/pkg.js +71 -0
- package/dist/commands/routes.d.ts +1 -1
- package/dist/config.d.ts +10 -4
- package/dist/config.js +8 -0
- package/dist/contract.d.ts +60 -1
- package/dist/contract.js +46 -0
- package/dist/create/workspace.d.ts +15 -0
- package/dist/create/workspace.js +42 -0
- package/dist/doctor/checks.js +4 -0
- package/dist/doctor/ci.d.ts +15 -0
- package/dist/doctor/ci.js +63 -0
- package/dist/doctor/translations.d.ts +19 -0
- package/dist/doctor/translations.js +144 -0
- package/dist/make/declare.js +32 -11
- package/dist/package-manager.d.ts +2 -0
- package/dist/package-manager.js +16 -2
- package/dist/pkg/catalog.d.ts +12 -0
- package/dist/pkg/catalog.js +153 -0
- package/dist/pkg/resolve.d.ts +67 -0
- package/dist/pkg/resolve.js +147 -0
- package/dist/upgrade/changelog.d.ts +2 -2
- package/dist/upgrade/project.d.ts +2 -2
- package/package.json +10 -8
- package/registry/ui/accordion.json +2 -2
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/alert.json +2 -2
- package/registry/ui/aspect-ratio.json +2 -2
- package/registry/ui/avatar.json +6 -3
- package/registry/ui/badge.json +2 -2
- package/registry/ui/banner.json +16 -0
- package/registry/ui/breadcrumbs.json +2 -2
- package/registry/ui/button.json +5 -3
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/card.json +2 -2
- package/registry/ui/carousel.json +2 -2
- package/registry/ui/checkbox-group.json +2 -2
- package/registry/ui/checkbox.json +2 -2
- package/registry/ui/combobox.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/confirm.json +8 -4
- package/registry/ui/cta-group.json +2 -2
- package/registry/ui/date-field.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/description.json +2 -2
- package/registry/ui/dialog-dismiss.json +13 -0
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/disclosure.json +2 -2
- package/registry/ui/drawer.json +2 -2
- package/registry/ui/field-error.json +2 -2
- package/registry/ui/form.json +2 -2
- package/registry/ui/group.json +2 -2
- package/registry/ui/header.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/heading.json +3 -3
- package/registry/ui/highlight.json +3 -3
- package/registry/ui/hover-card.json +2 -2
- package/registry/ui/image-placeholder.json +2 -2
- package/registry/ui/input.json +2 -2
- package/registry/ui/item.json +2 -2
- package/registry/ui/keyboard.json +2 -2
- package/registry/ui/label.json +2 -2
- package/registry/ui/link-button.json +5 -3
- package/registry/ui/link.json +2 -2
- package/registry/ui/listbox.json +2 -2
- package/registry/ui/menu.json +2 -2
- package/registry/ui/meter.json +2 -2
- package/registry/ui/modal.json +2 -2
- package/registry/ui/nav-link.json +2 -2
- package/registry/ui/navigation-menu.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/otp-field.json +2 -2
- package/registry/ui/overlay-arrow.json +2 -2
- package/registry/ui/pagination.json +2 -2
- package/registry/ui/popover.json +2 -2
- package/registry/ui/progress-bar.json +2 -2
- package/registry/ui/property-list.json +18 -0
- package/registry/ui/radio-group.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/relative-time.json +17 -0
- package/registry/ui/scroll-area.json +2 -2
- package/registry/ui/search-field.json +2 -2
- package/registry/ui/section.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/selection-indicator.json +2 -2
- package/registry/ui/sentinel-row.json +2 -2
- package/registry/ui/separator.json +2 -2
- package/registry/ui/shared-element.json +2 -2
- package/registry/ui/sheet.json +2 -2
- package/registry/ui/sidebar.json +2 -2
- package/registry/ui/slider.json +2 -2
- package/registry/ui/spinner.json +2 -2
- package/registry/ui/status-dot.json +16 -0
- package/registry/ui/switch.json +2 -2
- package/registry/ui/tabs.json +2 -2
- package/registry/ui/tag-group.json +2 -2
- package/registry/ui/text-field.json +7 -3
- package/registry/ui/text.json +2 -2
- package/registry/ui/textarea.json +2 -2
- package/registry/ui/time-field.json +2 -2
- package/registry/ui/timeline.json +16 -0
- package/registry/ui/toggle-button.json +2 -2
- package/registry/ui/tooltip.json +2 -2
- package/registry/ui/typeset.json +2 -2
- package/registry/ui/youtube-embed.json +2 -2
- package/stubs/scaffold.controller.index.stub +1 -1
- package/templates/app/.config/sdxc/ci.ts +26 -0
- package/templates/app/.github/workflows/ci.yml +46 -0
- package/templates/app/README.md +4 -0
- package/templates/app/package.json +1 -0
- package/templates/app/public/_headers +4 -0
- package/registry/ui/attachment.json +0 -15
- package/registry/ui/bubble.json +0 -13
- package/registry/ui/chart.json +0 -13
- package/registry/ui/color-area.json +0 -13
- package/registry/ui/color-field.json +0 -20
- package/registry/ui/color-picker.json +0 -17
- package/registry/ui/color-slider.json +0 -13
- package/registry/ui/color-swatch-picker.json +0 -15
- package/registry/ui/color-swatch.json +0 -13
- package/registry/ui/color-wheel.json +0 -13
- package/registry/ui/context-menu.json +0 -16
- package/registry/ui/drop-indicator.json +0 -13
- package/registry/ui/drop-zone.json +0 -13
- package/registry/ui/empty.json +0 -15
- package/registry/ui/feature.json +0 -18
- package/registry/ui/file-trigger.json +0 -13
- package/registry/ui/grid-list.json +0 -18
- package/registry/ui/logo-cloud.json +0 -16
- package/registry/ui/marker.json +0 -13
- package/registry/ui/marketing-header.json +0 -18
- package/registry/ui/marketing-section.json +0 -16
- package/registry/ui/menubar.json +0 -13
- package/registry/ui/message-scroller.json +0 -16
- package/registry/ui/message.json +0 -13
- package/registry/ui/resizable.json +0 -13
- package/registry/ui/shortcut-list.json +0 -18
- package/registry/ui/skeleton.json +0 -13
- package/registry/ui/split.json +0 -16
- package/registry/ui/stat-strip.json +0 -16
- package/registry/ui/table.json +0 -16
- package/registry/ui/toast.json +0 -16
- package/registry/ui/toolbar.json +0 -13
- package/registry/ui/tree.json +0 -18
package/registry/ui/tabs.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tabs",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Tabs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
],
|
|
9
9
|
"source": {
|
|
10
10
|
"path": "tabs.tsx",
|
|
11
|
-
"content": "/**\n * A set of tabs whose active view comes from routing rather than tracked\n * selection state: each tab renders as a native link carrying the `tab`\n * role, and whichever one points at the page currently being viewed carries\n * `aria-selected=\"true\"` to read as the active tab. `Tabs.List` lays the\n * links out along `Tabs`' orientation axis, sharing that axis with every\n * `Tabs.Tab` through component context, and `Tabs.Panel` holds the content\n * the current tab's page renders inside `Tabs.Panels`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { UtilityMixin } from \"@sdxc/u\";\nimport type { SizeValue, SpacingValue } from \"@sdxc/u/tokens\";\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, borderEdge, fg, outline, outlineStyle } from \"@sdxc/u/color\";\nimport { opacity, transition } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tbasis,\n\tflexCol,\n\tflexRow,\n\tgrow,\n\thstack,\n\tinsBe,\n\tinsIs,\n\tinset,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { bs, is, mbe, mie, pb, pi } from \"@sdxc/u/size\";\nimport { after, data, when } from \"@sdxc/u/state\";\nimport { boxLength, spacing } from \"@sdxc/u/tokens\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** Default {@link Tabs.Props} orientation, applied when `orientation` is omitted. */\nconst DEFAULT_ORIENTATION: Tabs.Orientation = \"horizontal\";\n\n/** `role=\"tablist\"` applied to {@link Tabs.List} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_LIST_ROLE = \"tablist\";\n\n/** `role=\"tab\"` applied to {@link Tabs.Tab} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_TAB_ROLE = \"tab\";\n\n/** `role=\"tabpanel\"` applied to {@link Tabs.Panel} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_PANEL_ROLE = \"tabpanel\";\n\n/**\n * {@link Tabs.List}'s own inter-tab gap, applied through `hstack({ gap:\n * LIST_GAP })` and reused when computing a controlled `activeIndex`'s\n * indicator offset (see {@link tabIndicatorMix}), keeping the two in sync.\n */\nconst LIST_GAP: SpacingValue = 1;\n\n/**\n * Default {@link Tabs.PanelProps.tabIndex}, applied through {@link attrs}\n * unless a consumer supplies its own, so a keyboard user can move focus\n * straight into the panel's content after activating a tab.\n */\nconst DEFAULT_PANEL_TAB_INDEX = 0;\n\n/**\n * Prop types for {@link Tabs} and its compound parts.\n */\nexport namespace Tabs {\n\t/**\n\t * Axis {@link Tabs.List}'s links lay out along: a single row with the\n\t * active indicator running beneath it, or a single column with the\n\t * indicator running alongside it.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Value {@link Tabs} stores in component context so every\n\t * {@link Tabs.List} and {@link Tabs.Tab} nested inside mirrors the same\n\t * orientation automatically.\n\t */\n\texport interface Context {\n\t\t/** The root's resolved layout axis. */\n\t\torientation: Orientation;\n\t}\n\n\t/**\n\t * Props accepted by {@link Tabs}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n\n\t/**\n\t * Props accepted by {@link Tabs.List}.\n\t */\n\texport interface ListProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Index of the currently active tab, for a route-driven tab bar with\n\t\t * no client-side measurement of the active tab's bounds. Given with\n\t\t * `tabSize`, {@link Tabs.List} computes its own indicator position.\n\t\t */\n\t\tactiveIndex?: number;\n\n\t\t/**\n\t\t * Every {@link Tabs.Tab}'s fixed size along the enclosing\n\t\t * {@link Tabs}'s layout axis, required alongside `activeIndex` since\n\t\t * the indicator's offset depends on how far apart the tabs sit.\n\t\t */\n\t\ttabSize?: SizeValue;\n\t}\n\n\t/**\n\t * Props accepted by {@link Tabs.Tab}. A type alias, since the native\n\t * anchor props already encode `href`/`role` as a union; `href` is\n\t * narrowed to required, since every tab is link-mode and needs one.\n\t */\n\texport type TabProps = TagProps<\"a\"> & {\n\t\t/** The page this tab navigates to. */\n\t\thref: string;\n\t};\n\n\t/**\n\t * Props accepted by {@link Tabs.Panels}.\n\t */\n\texport interface PanelsProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Tabs.Panel}.\n\t */\n\texport interface PanelProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders the root host: a plain `<div>` stacking {@link Tabs.List} above\n * {@link Tabs.Panels}, switching to a side-by-side row when `orientation`\n * is `\"vertical\"` and sharing that axis through component context.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link Tabs.Context}.\n * @returns The render function producing the root's markup.\n * @example\n * <Tabs>\n * \t<Tabs.List aria-label={t(\"settings.sections\")}>\n * \t\t<Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * \t\t<Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\">{t(\"settings.billing\")}</Tabs.Tab>\n * \t</Tabs.List>\n * \t<Tabs.Panels>\n * \t\t<Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n * \t</Tabs.Panels>\n * </Tabs>\n * @example\n * <Tabs orientation=\"vertical\">\n * \t<Tabs.List aria-label={t(\"settings.sections\")}>\n * \t\t<Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * \t\t<Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\">{t(\"settings.billing\")}</Tabs.Tab>\n * \t</Tabs.List>\n * \t<Tabs.Panels>\n * \t\t<Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n * \t</Tabs.Panels>\n * </Tabs>\n */\nexport function Tabs(handle: Handle<Tabs.Props, Tabs.Context>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;\n\n\t\thandle.context.set({ orientation: resolvedOrientation });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[vstack(), data(\"orientation\", \"vertical\", flexRow()), mix]}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Computes the `--ui-tab-indicator-*` custom properties {@link Tabs.List}'s\n * sliding indicator reads for a controlled `activeIndex`. Assumes every\n * {@link Tabs.Tab} shares one fixed `tabSize` and sits `LIST_GAP` apart.\n *\n * @param orientation The enclosing {@link Tabs}'s layout axis.\n * @param activeIndex Index of the active tab among its siblings.\n * @param tabSize Every tab's fixed size along `orientation`'s axis.\n * @returns A `raw()` mixin setting the indicator's offset, length, and opacity.\n */\nexport function tabIndicatorMix(\n\torientation: Tabs.Orientation,\n\tactiveIndex: number,\n\ttabSize: SizeValue,\n): UtilityMixin {\n\tlet size = boxLength(tabSize);\n\tlet offset = `calc((${size} + ${spacing(LIST_GAP)}) * ${activeIndex})`;\n\n\tif (orientation === \"vertical\") {\n\t\treturn raw({\n\t\t\t\"--ui-tab-indicator-block-start\": offset,\n\t\t\t\"--ui-tab-indicator-block-size\": size,\n\t\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t\t});\n\t}\n\n\treturn raw({\n\t\t\"--ui-tab-indicator-inline-start\": offset,\n\t\t\"--ui-tab-indicator-inline-size\": size,\n\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t});\n}\n\n/**\n * Renders the tab strip: a `role=\"tablist\"` host laying {@link Tabs.Tab}\n * links out in a row, or a column when `orientation` is `\"vertical\"`, with\n * a sliding accent bar reading `--ui-tab-indicator-*` custom properties.\n *\n * @param handle Runtime handle carrying the host's props.\n * @returns The render function producing the tab strip's markup.\n * @example\n * <Tabs.List aria-label={t(\"settings.sections\")}>\n * \t<Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * \t<Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\">{t(\"settings.billing\")}</Tabs.Tab>\n * </Tabs.List>\n * @example\n * // A link-based, server-controlled tab bar: `activeIndex` comes from the\n * // current route, so `Tabs.List` computes its own sliding indicator\n * // directly from server-rendered state.\n * <Tabs.List aria-label={t(\"dashboard.tabs\")} activeIndex={activeIndex} tabSize=\"110px\">\n * \t<Tabs.Tab href=\"/dashboard/overview\" aria-selected={activeIndex === 0}>\n * \t\t{t(\"dashboard.overview\")}\n * \t</Tabs.Tab>\n * \t<Tabs.Tab href=\"/dashboard/incidents\" aria-selected={activeIndex === 1}>\n * \t\t{t(\"dashboard.incidents\")}\n * \t</Tabs.Tab>\n * </Tabs.List>\n */\nTabs.List = function TabsList(handle: Handle<Tabs.ListProps>) {\n\treturn () => {\n\t\tlet { mix, activeIndex, tabSize, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Tabs);\n\t\tlet indicatorMix =\n\t\t\tactiveIndex !== undefined && tabSize !== undefined\n\t\t\t\t? tabIndicatorMix(context.orientation, activeIndex, tabSize)\n\t\t\t\t: undefined;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={context.orientation}\n\t\t\t\taria-orientation={context.orientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_LIST_ROLE }),\n\t\t\t\t\trelative(),\n\t\t\t\t\thstack({ gap: LIST_GAP }),\n\t\t\t\t\tborderEdge(\"block-end\", { color: \"neutral\", width: 1 }),\n\t\t\t\t\tafter([\n\t\t\t\t\t\tabsolute(),\n\t\t\t\t\t\tis(\"var(--ui-tab-indicator-inline-size, 0px)\"),\n\t\t\t\t\t\tbs(\"0.125rem\"),\n\t\t\t\t\t\ttransition(\"inset-inline-start, inset-block-start, inline-size, block-size, opacity\", {\n\t\t\t\t\t\t\tduration: \"200ms\",\n\t\t\t\t\t\t\teasing: \"ease-out\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tinsIs(\"var(--ui-tab-indicator-inline-start, 0px)\"),\n\t\t\t\t\t\tinsBe(\"-0.0625rem\"),\n\t\t\t\t\t\tbg(\"var(--ui-brand-fg)\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tcontent: '\"\"',\n\t\t\t\t\t\t\topacity: \"var(--ui-tab-indicator-opacity, 0)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"orientation\", \"vertical\", [\n\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\tborderEdge(\"block-end\", { width: \"0\" }),\n\t\t\t\t\t\tborderEdge(\"inline-end\", { color: \"neutral\", width: 1 }),\n\t\t\t\t\t\tafter([\n\t\t\t\t\t\t\tinset(\"var(--ui-tab-indicator-block-start, 0px)\", \"0\", \"auto\", \"auto\"),\n\t\t\t\t\t\t\tis(\"0.125rem\"),\n\t\t\t\t\t\t\tbs(\"var(--ui-tab-indicator-block-size, 0px)\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\tindicatorMix,\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single tab: a native `<a>` carrying the `tab` role, its own\n * border edge kept transparent to reserve space for the sliding indicator.\n * Omitting `href` disables navigation; pair it with `aria-disabled=\"true\"`.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the tab's markup.\n * @example\n * <Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * @example\n * <Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\" aria-disabled=\"true\">\n * \t{t(\"settings.billing\")}\n * </Tabs.Tab>\n */\nTabs.Tab = function TabsTab(handle: Handle<Tabs.TabProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Tabs);\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\tdata-orientation={context.orientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tattrs({ role: DEFAULT_TAB_ROLE }),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tpi(4),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"&:hover\", fg(\"neutral.emphasis\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', fg(\"brand\")),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\tmbe(\"-0.0625rem\"),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tborderEdge(\"block-end\", { color: \"transparent\", width: 2 }),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', cursor(\"not-allowed\")),\n\t\t\t\t\tdata(\"orientation\", \"vertical\", [\n\t\t\t\t\t\tmbe(\"0\"),\n\t\t\t\t\t\tmie(\"-0.0625rem\"),\n\t\t\t\t\t\tborderEdge(\"block-end\", { width: \"0\" }),\n\t\t\t\t\t\tborderEdge(\"inline-end\", { color: \"transparent\", width: 2 }),\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 * Renders the panel region: a `<div>` growing to fill whatever space is left\n * beside or beneath {@link Tabs.List}. Nest the current tab's\n * {@link Tabs.Panel} inside it.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the panel region's markup.\n * @example\n * <Tabs.Panels>\n * \t<Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n * </Tabs.Panels>\n */\nTabs.Panels = function TabsPanels(handle: Handle<Tabs.PanelsProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} mix={[grow(), shrink(1), basis(\"0%\"), mix]} />;\n\t};\n};\n\n/**\n * Renders the current tab's content: a padded `<div>` carrying the\n * `tabpanel` role, focusable by default so a keyboard user can jump\n * straight into it after activating a tab, with a focus-visible ring.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n */\nTabs.Panel = function TabsPanel(handle: Handle<Tabs.PanelProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_PANEL_ROLE, tabIndex: DEFAULT_PANEL_TAB_INDEX }),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tpb(4),\n\t\t\t\t\tpi(4),\n\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
11
|
+
"content": "/**\n * A set of tabs whose active view comes from routing rather than tracked\n * selection state: each tab renders as a native link carrying the `tab`\n * role, and whichever one points at the page currently being viewed carries\n * `aria-selected=\"true\"` to read as the active tab. `Tabs.List` lays the\n * links out along `Tabs`' orientation axis, sharing that axis with every\n * `Tabs.Tab` through component context, and `Tabs.Panel` holds the content\n * the current tab's page renders inside `Tabs.Panels`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { UtilityMixin } from \"@sdxc/u\";\nimport type { SizeValue, SpacingValue } from \"@sdxc/u/tokens\";\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, borderEdge, fg, outline, outlineStyle } from \"@sdxc/u/color\";\nimport { opacity, transition } from \"@sdxc/u/effects\";\nimport { cursor, raw, mergeMix } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tbasis,\n\tflexCol,\n\tflexRow,\n\tgrow,\n\thstack,\n\tinsBe,\n\tinsIs,\n\tinset,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { bs, is, mbe, mie, pb, pi } from \"@sdxc/u/size\";\nimport { after, data, when } from \"@sdxc/u/state\";\nimport { boxLength, spacing } from \"@sdxc/u/tokens\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** Default {@link Tabs.Props} orientation, applied when `orientation` is omitted. */\nconst DEFAULT_ORIENTATION: Tabs.Orientation = \"horizontal\";\n\n/** `role=\"tablist\"` applied to {@link Tabs.List} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_LIST_ROLE = \"tablist\";\n\n/** `role=\"tab\"` applied to {@link Tabs.Tab} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_TAB_ROLE = \"tab\";\n\n/** `role=\"tabpanel\"` applied to {@link Tabs.Panel} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_PANEL_ROLE = \"tabpanel\";\n\n/**\n * {@link Tabs.List}'s own inter-tab gap, applied through `hstack({ gap:\n * LIST_GAP })` and reused when computing a controlled `activeIndex`'s\n * indicator offset (see {@link tabIndicatorMix}), keeping the two in sync.\n */\nconst LIST_GAP: SpacingValue = 1;\n\n/**\n * Default {@link Tabs.PanelProps.tabIndex}, applied through {@link attrs}\n * unless a consumer supplies its own, so a keyboard user can move focus\n * straight into the panel's content after activating a tab.\n */\nconst DEFAULT_PANEL_TAB_INDEX = 0;\n\n/**\n * Prop types for {@link Tabs} and its compound parts.\n */\nexport namespace Tabs {\n\t/**\n\t * Axis {@link Tabs.List}'s links lay out along: a single row with the\n\t * active indicator running beneath it, or a single column with the\n\t * indicator running alongside it.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Value {@link Tabs} stores in component context so every\n\t * {@link Tabs.List} and {@link Tabs.Tab} nested inside mirrors the same\n\t * orientation automatically.\n\t */\n\texport interface Context {\n\t\t/** The root's resolved layout axis. */\n\t\torientation: Orientation;\n\t}\n\n\t/**\n\t * Props accepted by {@link Tabs}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n\n\t/**\n\t * Props accepted by {@link Tabs.List}.\n\t */\n\texport interface ListProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Index of the currently active tab, for a route-driven tab bar with\n\t\t * no client-side measurement of the active tab's bounds. Given with\n\t\t * `tabSize`, {@link Tabs.List} computes its own indicator position.\n\t\t */\n\t\tactiveIndex?: number;\n\n\t\t/**\n\t\t * Every {@link Tabs.Tab}'s fixed size along the enclosing\n\t\t * {@link Tabs}'s layout axis, required alongside `activeIndex` since\n\t\t * the indicator's offset depends on how far apart the tabs sit.\n\t\t */\n\t\ttabSize?: SizeValue;\n\t}\n\n\t/**\n\t * Props accepted by {@link Tabs.Tab}. A type alias, since the native\n\t * anchor props already encode `href`/`role` as a union; `href` is\n\t * narrowed to required, since every tab is link-mode and needs one.\n\t */\n\texport type TabProps = TagProps<\"a\"> & {\n\t\t/** The page this tab navigates to. */\n\t\thref: string;\n\t};\n\n\t/**\n\t * Props accepted by {@link Tabs.Panels}.\n\t */\n\texport interface PanelsProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Tabs.Panel}.\n\t */\n\texport interface PanelProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders the root host: a plain `<div>` stacking {@link Tabs.List} above\n * {@link Tabs.Panels}, switching to a side-by-side row when `orientation`\n * is `\"vertical\"` and sharing that axis through component context.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link Tabs.Context}.\n * @returns The render function producing the root's markup.\n * @example\n * <Tabs>\n * \t<Tabs.List aria-label={t(\"settings.sections\")}>\n * \t\t<Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * \t\t<Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\">{t(\"settings.billing\")}</Tabs.Tab>\n * \t</Tabs.List>\n * \t<Tabs.Panels>\n * \t\t<Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n * \t</Tabs.Panels>\n * </Tabs>\n * @example\n * <Tabs orientation=\"vertical\">\n * \t<Tabs.List aria-label={t(\"settings.sections\")}>\n * \t\t<Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * \t\t<Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\">{t(\"settings.billing\")}</Tabs.Tab>\n * \t</Tabs.List>\n * \t<Tabs.Panels>\n * \t\t<Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n * \t</Tabs.Panels>\n * </Tabs>\n */\nexport function Tabs(handle: Handle<Tabs.Props, Tabs.Context>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;\n\n\t\thandle.context.set({ orientation: resolvedOrientation });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix([vstack(), data(\"orientation\", \"vertical\", flexRow())], mix)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Computes the `--ui-tab-indicator-*` custom properties {@link Tabs.List}'s\n * sliding indicator reads for a controlled `activeIndex`. Assumes every\n * {@link Tabs.Tab} shares one fixed `tabSize` and sits `LIST_GAP` apart.\n *\n * @param orientation The enclosing {@link Tabs}'s layout axis.\n * @param activeIndex Index of the active tab among its siblings.\n * @param tabSize Every tab's fixed size along `orientation`'s axis.\n * @returns A `raw()` mixin setting the indicator's offset, length, and opacity.\n */\nexport function tabIndicatorMix(\n\torientation: Tabs.Orientation,\n\tactiveIndex: number,\n\ttabSize: SizeValue,\n): UtilityMixin {\n\tlet size = boxLength(tabSize);\n\tlet offset = `calc((${size} + ${spacing(LIST_GAP)}) * ${activeIndex})`;\n\n\tif (orientation === \"vertical\") {\n\t\treturn raw({\n\t\t\t\"--ui-tab-indicator-block-start\": offset,\n\t\t\t\"--ui-tab-indicator-block-size\": size,\n\t\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t\t});\n\t}\n\n\treturn raw({\n\t\t\"--ui-tab-indicator-inline-start\": offset,\n\t\t\"--ui-tab-indicator-inline-size\": size,\n\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t});\n}\n\n/**\n * Renders the tab strip: a `role=\"tablist\"` host laying {@link Tabs.Tab}\n * links out in a row, or a column when `orientation` is `\"vertical\"`, with\n * a sliding accent bar reading `--ui-tab-indicator-*` custom properties.\n *\n * @param handle Runtime handle carrying the host's props.\n * @returns The render function producing the tab strip's markup.\n * @example\n * <Tabs.List aria-label={t(\"settings.sections\")}>\n * \t<Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * \t<Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\">{t(\"settings.billing\")}</Tabs.Tab>\n * </Tabs.List>\n * @example\n * // A link-based, server-controlled tab bar: `activeIndex` comes from the\n * // current route, so `Tabs.List` computes its own sliding indicator\n * // directly from server-rendered state.\n * <Tabs.List aria-label={t(\"dashboard.tabs\")} activeIndex={activeIndex} tabSize=\"110px\">\n * \t<Tabs.Tab href=\"/dashboard/overview\" aria-selected={activeIndex === 0}>\n * \t\t{t(\"dashboard.overview\")}\n * \t</Tabs.Tab>\n * \t<Tabs.Tab href=\"/dashboard/incidents\" aria-selected={activeIndex === 1}>\n * \t\t{t(\"dashboard.incidents\")}\n * \t</Tabs.Tab>\n * </Tabs.List>\n */\nTabs.List = function TabsList(handle: Handle<Tabs.ListProps>) {\n\treturn () => {\n\t\tlet { mix, activeIndex, tabSize, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Tabs);\n\t\tlet indicatorMix =\n\t\t\tactiveIndex !== undefined && tabSize !== undefined\n\t\t\t\t? tabIndicatorMix(context.orientation, activeIndex, tabSize)\n\t\t\t\t: undefined;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={context.orientation}\n\t\t\t\taria-orientation={context.orientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_LIST_ROLE }),\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\thstack({ gap: LIST_GAP }),\n\t\t\t\t\t\tborderEdge(\"block-end\", { color: \"neutral\", width: 1 }),\n\t\t\t\t\t\tafter([\n\t\t\t\t\t\t\tabsolute(),\n\t\t\t\t\t\t\tis(\"var(--ui-tab-indicator-inline-size, 0px)\"),\n\t\t\t\t\t\t\tbs(\"0.125rem\"),\n\t\t\t\t\t\t\ttransition(\n\t\t\t\t\t\t\t\t\"inset-inline-start, inset-block-start, inline-size, block-size, opacity\",\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tduration: \"200ms\",\n\t\t\t\t\t\t\t\t\teasing: \"ease-out\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tinsIs(\"var(--ui-tab-indicator-inline-start, 0px)\"),\n\t\t\t\t\t\t\tinsBe(\"-0.0625rem\"),\n\t\t\t\t\t\t\tbg(\"var(--ui-brand-fg)\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tcontent: '\"\"',\n\t\t\t\t\t\t\t\topacity: \"var(--ui-tab-indicator-opacity, 0)\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"orientation\", \"vertical\", [\n\t\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\t\tborderEdge(\"block-end\", { width: \"0\" }),\n\t\t\t\t\t\t\tborderEdge(\"inline-end\", { color: \"neutral\", width: 1 }),\n\t\t\t\t\t\t\tafter([\n\t\t\t\t\t\t\t\tinset(\"var(--ui-tab-indicator-block-start, 0px)\", \"0\", \"auto\", \"auto\"),\n\t\t\t\t\t\t\t\tis(\"0.125rem\"),\n\t\t\t\t\t\t\t\tbs(\"var(--ui-tab-indicator-block-size, 0px)\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tindicatorMix,\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 * Renders a single tab: a native `<a>` carrying the `tab` role, its own\n * border edge kept transparent to reserve space for the sliding indicator.\n * Omitting `href` disables navigation; pair it with `aria-disabled=\"true\"`.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the tab's markup.\n * @example\n * <Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">{t(\"settings.profile\")}</Tabs.Tab>\n * @example\n * <Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\" aria-disabled=\"true\">\n * \t{t(\"settings.billing\")}\n * </Tabs.Tab>\n */\nTabs.Tab = function TabsTab(handle: Handle<Tabs.TabProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(Tabs);\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\tdata-orientation={context.orientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\tattrs({ role: DEFAULT_TAB_ROLE }),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\tpi(4),\n\t\t\t\t\t\tpb(2),\n\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\twhen(\"&:hover\", fg(\"neutral.emphasis\")),\n\t\t\t\t\t\twhen('&[aria-selected=\"true\"]', fg(\"brand\")),\n\t\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\t\tmbe(\"-0.0625rem\"),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tborderEdge(\"block-end\", { color: \"transparent\", width: 2 }),\n\t\t\t\t\t\twhen('&[aria-disabled=\"true\"]', cursor(\"not-allowed\")),\n\t\t\t\t\t\tdata(\"orientation\", \"vertical\", [\n\t\t\t\t\t\t\tmbe(\"0\"),\n\t\t\t\t\t\t\tmie(\"-0.0625rem\"),\n\t\t\t\t\t\t\tborderEdge(\"block-end\", { width: \"0\" }),\n\t\t\t\t\t\t\tborderEdge(\"inline-end\", { color: \"transparent\", width: 2 }),\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 * Renders the panel region: a `<div>` growing to fill whatever space is left\n * beside or beneath {@link Tabs.List}. Nest the current tab's\n * {@link Tabs.Panel} inside it.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the panel region's markup.\n * @example\n * <Tabs.Panels>\n * \t<Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n * </Tabs.Panels>\n */\nTabs.Panels = function TabsPanels(handle: Handle<Tabs.PanelsProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} mix={mergeMix([grow(), shrink(1), basis(\"0%\")], mix)} />;\n\t};\n};\n\n/**\n * Renders the current tab's content: a padded `<div>` carrying the\n * `tabpanel` role, focusable by default so a keyboard user can jump\n * straight into it after activating a tab, with a focus-visible ring.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Tabs.Panel>{t(\"settings.profile.body\")}</Tabs.Panel>\n */\nTabs.Panel = function TabsPanel(handle: Handle<Tabs.PanelProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_PANEL_ROLE, tabIndex: DEFAULT_PANEL_TAB_INDEX }),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\tpb(4),\n\t\t\t\t\t\tpi(4),\n\t\t\t\t\t\toutlineStyle(\"none\"),\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"
|
|
12
12
|
},
|
|
13
13
|
"test": {
|
|
14
14
|
"path": "tabs.test.tsx",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tag-group",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "tag-group.tsx",
|
|
12
|
-
"content": "/**\n * A labeled set of pill-shaped tags with an optional dismiss control per tag,\n * composing a grouping host, a wrapped list, and each tag's own pill and\n * remove button. A tag reads its color and size through the same `data-*`\n * contract as {@link Badge}, and its remove control renders through\n * {@link Button} as a native form submit, so removing a tag is an ordinary\n * server round-trip through whatever form the group sits inside, driven\n * entirely by the submitted control's `name`/`value` pair.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as ElementProps } from \"remix/component\";\n\nimport { XIcon } from \"@sdxc/icons\";\nimport { bg, fg, outline, outlineColor } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, listStyle, vars } from \"@sdxc/u/general\";\nimport { flex, flexWrap, gap, inlineFlex, items, vstack } from \"@sdxc/u/layout\";\nimport { bs, is, m, mie, p, pb, pi } from \"@sdxc/u/size\";\nimport { active, data, hover, when } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\n/** `role=\"group\"` applied to {@link TagGroup} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_ROLE = \"group\";\n\n/** Semantic color role {@link TagGroup.Tag} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: TagGroup.Color = \"neutral\";\n\n/** Size variant {@link TagGroup.Tag} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: TagGroup.Size = \"md\";\n\n/** Visible edge of {@link TagGroup.Remove}'s round glyph, small enough to sit inside a pill's line. */\nconst REMOVE_SIZE = \"var(--ui-tag-remove-size, 1rem)\";\n\n/**\n * Prop types for {@link TagGroup} and its compound parts.\n */\nexport namespace TagGroup {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables —\n\t * the same set {@link Badge} and {@link Button} use.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Size variant controlling a tag's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\";\n\n\t/**\n\t * Props accepted by {@link TagGroup}.\n\t */\n\texport interface Props extends ElementProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link TagGroup.List}.\n\t */\n\texport interface ListProps extends ElementProps<\"ul\"> {}\n\n\t/**\n\t * Props accepted by {@link TagGroup.Tag}. Set `aria-selected=\"true\"` to\n\t * mark a tag as the active member of a selectable set, and\n\t * `aria-disabled=\"true\"` to mute one, both read from native ARIA state.\n\t */\n\texport interface TagProps extends ElementProps<\"li\"> {\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t}\n\n\t/**\n\t * Props accepted by {@link TagGroup.Remove}: every {@link Button.Props}\n\t * field except the ones this component fixes, plus every native\n\t * `<button>` attribute — `name`/`value` tell the form which tag to remove.\n\t */\n\texport interface RemoveProps extends Omit<\n\t\tButton.Props,\n\t\t\"children\" | \"variant\" | \"color\" | \"size\" | \"type\" | \"aria-label\"\n\t> {\n\t\t/**\n\t\t * Accessible label for the icon-only control — required, since the\n\t\t * button carries no visible text for assistive technology to read.\n\t\t */\n\t\t\"aria-label\": string;\n\t}\n}\n\n/**\n * Renders the group's `<div>` host, laying its {@link TagGroup.List} child\n * (and any preceding `Label`) out in a column with a small gap. Dev mode\n * warns when it lacks an accessible name for assistive technology.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the group's markup.\n * @example\n * <TagGroup aria-label={t(\"skills.label\")}>\n * \t<TagGroup.List>\n * \t\t<TagGroup.Tag color=\"brand\">{t(\"skills.design\")}</TagGroup.Tag>\n * \t\t<TagGroup.Tag color=\"success\">{t(\"skills.shipped\")}</TagGroup.Tag>\n * \t</TagGroup.List>\n * </TagGroup>\n */\nexport function TagGroup(handle: Handle<TagGroup.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'TagGroup: a group with no \"aria-label\" or \"aria-labelledby\" needs one describing the set of tags — assistive technology has no accessible name to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"tag-group\"\n\t\t\t\tmix={[attrs({ role: DEFAULT_ROLE }), vstack({ gap: 1 }), mix]}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders the group's `<ul>` list, resetting native list markers and spacing\n * and laying {@link TagGroup.Tag} children out as a wrapped row with a small\n * gap between them.\n *\n * @param handle Runtime handle carrying the host `<ul>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <TagGroup.List>\n * \t<TagGroup.Tag color=\"neutral\">{t(\"filters.active\")}</TagGroup.Tag>\n * \t<TagGroup.Tag color=\"neutral\" size=\"sm\">{t(\"filters.archived\")}</TagGroup.Tag>\n * </TagGroup.List>\n */\nTagGroup.List = function TagGroupList(handle: Handle<TagGroup.ListProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<ul\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"list\"\n\t\t\t\tmix={[flex(), flexWrap(\"wrap\"), gap(2), m(0), p(0), listStyle(), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single pill-shaped `<li>`, colored through the `data-color`\n * attribute contract shared with {@link Badge} and sized through\n * `data-size`. Compose {@link TagGroup.Remove} inside it for a dismissible tag.\n *\n * @param handle Runtime handle carrying the host `<li>`'s props.\n * @returns The render function producing the pill's markup.\n * @example\n * <TagGroup.Tag color=\"success\">{t(\"status.shipped\")}</TagGroup.Tag>\n * @example\n * <TagGroup.Tag color=\"danger\" size=\"sm\" aria-selected=\"true\">\n * \t{t(\"status.blocked\")}\n * </TagGroup.Tag>\n */\nTagGroup.Tag = function TagGroupTag(handle: Handle<TagGroup.TagProps>) {\n\treturn () => {\n\t\tlet { color, size, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\n\t\treturn (\n\t\t\t<li\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tdata-slot=\"tag\"\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", outline(\"neutral.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"success\", outline(\"success.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"warning\", outline(\"warning.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"danger\", outline(\"danger.ring\")),\n\t\t\t\t\t]),\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(1),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpb(1),\n\t\t\t\t\tdata(\"size\", \"sm\", [pi(2), pb(0.5)]),\n\t\t\t\t\tdata(\"color\", \"brand\", [bg(\"brand.tint\"), fg(\"brand\")]),\n\t\t\t\t\tdata(\"color\", \"success\", [bg(\"success.tint\"), fg(\"success\")]),\n\t\t\t\t\tdata(\"color\", \"warning\", [bg(\"warning.tint\"), fg(\"warning\")]),\n\t\t\t\t\tdata(\"color\", \"danger\", [bg(\"danger.tint\"), fg(\"danger\")]),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.solid\"), fg(\"brand.onSolid\"), weight(600)]),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tdata(\"size\", \"sm\", text(\"xs\")),\n\t\t\t\t\tdata(\"color\", \"neutral\", [bg(\"neutral.bg-tint-hover\"), fg(\"neutral\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a dismiss control for the tag it's composed inside: a small,\n * ghost-styled {@link Button} with an \"X\" glyph submitting as\n * `type=\"submit\"`, colored from the ambient {@link TagGroup.Tag}'s `data-color`.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the dismiss control's markup.\n * @example\n * <form method=\"post\">\n * \t<TagGroup aria-label={t(\"filters.label\")}>\n * \t\t<TagGroup.List>\n * \t\t\t<TagGroup.Tag color=\"brand\">\n * \t\t\t\t{t(\"filters.remote\")}\n * \t\t\t\t<TagGroup.Remove name=\"remove\" value=\"remote\" aria-label={t(\"filters.removeRemote\")} />\n * \t\t\t</TagGroup.Tag>\n * \t\t</TagGroup.List>\n * \t</TagGroup>\n * </form>\n */\nTagGroup.Remove = function TagGroupRemove(handle: Handle<TagGroup.RemoveProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"submit\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tdata-slot=\"remove\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * The control shrinks through Button's own icon-only measure, so it sits inside\n\t\t\t\t\t * the pill's line instead of stretching the tag to a full button row, while\n\t\t\t\t\t * Button's own hit area keeps its pointer target at `--ui-target-size`.\n\t\t\t\t\t */\n\t\t\t\t\tvars({ \"ui-button-icon-size-md\": REMOVE_SIZE }),\n\t\t\t\t\tmie(-1),\n\t\t\t\t\twhen('&[data-slot=\"remove\"] > svg', [is(3), bs(3)]),\n\t\t\t\t\tfg(\"currentColor\"),\n\t\t\t\t\thover(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\twhen('[data-color=\"neutral\"] &:hover', bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('[data-color=\"success\"] &:hover', bg(\"success.bg-tint-hover\")),\n\t\t\t\t\twhen('[data-color=\"danger\"] &:hover', bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\twhen('[data-color=\"warning\"] &:hover', bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\tactive(bg(\"brand.bg-tint-pressed\")),\n\t\t\t\t\twhen('[data-color=\"neutral\"] &:active', bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\twhen('[data-color=\"success\"] &:active', bg(\"success.bg-tint-pressed\")),\n\t\t\t\t\twhen('[data-color=\"danger\"] &:active', bg(\"danger.bg-tint-pressed\")),\n\t\t\t\t\twhen('[data-color=\"warning\"] &:active', bg(\"warning.bg-tint-pressed\")),\n\t\t\t\t\twhen(\"&:focus-visible\", outlineColor(\"brand\")),\n\t\t\t\t\twhen('[data-color=\"neutral\"] &:focus-visible', outlineColor(\"neutral\")),\n\t\t\t\t\twhen('[data-color=\"success\"] &:focus-visible', outlineColor(\"success\")),\n\t\t\t\t\twhen('[data-color=\"danger\"] &:focus-visible', outlineColor(\"danger\")),\n\t\t\t\t\twhen('[data-color=\"warning\"] &:focus-visible', outlineColor(\"warning\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<XIcon size={12} />\n\t\t\t</Button>\n\t\t);\n\t};\n};\n"
|
|
12
|
+
"content": "/**\n * A labeled set of pill-shaped tags with an optional dismiss control per tag,\n * composing a grouping host, a wrapped list, and each tag's own pill and\n * remove button. A tag reads its color and size through the same `data-*`\n * contract as {@link Badge}, and its remove control renders through\n * {@link Button} as a native form submit, so removing a tag is an ordinary\n * server round-trip through whatever form the group sits inside, driven\n * entirely by the submitted control's `name`/`value` pair.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as ElementProps } from \"remix/component\";\n\nimport { XIcon } from \"@sdxc/icons\";\nimport { bg, fg, outline, outlineColor } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, listStyle, vars, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexWrap, gap, inlineFlex, items, vstack } from \"@sdxc/u/layout\";\nimport { bs, is, m, mie, p, pb, pi } from \"@sdxc/u/size\";\nimport { active, data, hover, when } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\n/** `role=\"group\"` applied to {@link TagGroup} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_ROLE = \"group\";\n\n/** Semantic color role {@link TagGroup.Tag} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: TagGroup.Color = \"neutral\";\n\n/** Size variant {@link TagGroup.Tag} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: TagGroup.Size = \"md\";\n\n/** Visible edge of {@link TagGroup.Remove}'s round glyph, small enough to sit inside a pill's line. */\nconst REMOVE_SIZE = \"var(--ui-tag-remove-size, 1rem)\";\n\n/**\n * Prop types for {@link TagGroup} and its compound parts.\n */\nexport namespace TagGroup {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables —\n\t * the same set {@link Badge} and {@link Button} use.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Size variant controlling a tag's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\";\n\n\t/**\n\t * Props accepted by {@link TagGroup}.\n\t */\n\texport interface Props extends ElementProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link TagGroup.List}.\n\t */\n\texport interface ListProps extends ElementProps<\"ul\"> {}\n\n\t/**\n\t * Props accepted by {@link TagGroup.Tag}. Set `aria-selected=\"true\"` to\n\t * mark a tag as the active member of a selectable set, and\n\t * `aria-disabled=\"true\"` to mute one, both read from native ARIA state.\n\t */\n\texport interface TagProps extends ElementProps<\"li\"> {\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t}\n\n\t/**\n\t * Props accepted by {@link TagGroup.Remove}: every {@link Button.Props}\n\t * field except the ones this component fixes, plus every native\n\t * `<button>` attribute — `name`/`value` tell the form which tag to remove.\n\t */\n\texport interface RemoveProps extends Omit<\n\t\tButton.Props,\n\t\t\"children\" | \"variant\" | \"color\" | \"size\" | \"type\" | \"aria-label\"\n\t> {\n\t\t/**\n\t\t * Accessible label for the icon-only control — required, since the\n\t\t * button carries no visible text for assistive technology to read.\n\t\t */\n\t\t\"aria-label\": string;\n\t}\n}\n\n/**\n * Renders the group's `<div>` host, laying its {@link TagGroup.List} child\n * (and any preceding `Label`) out in a column with a small gap. Dev mode\n * warns when it lacks an accessible name for assistive technology.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the group's markup.\n * @example\n * <TagGroup aria-label={t(\"skills.label\")}>\n * \t<TagGroup.List>\n * \t\t<TagGroup.Tag color=\"brand\">{t(\"skills.design\")}</TagGroup.Tag>\n * \t\t<TagGroup.Tag color=\"success\">{t(\"skills.shipped\")}</TagGroup.Tag>\n * \t</TagGroup.List>\n * </TagGroup>\n */\nexport function TagGroup(handle: Handle<TagGroup.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'TagGroup: a group with no \"aria-label\" or \"aria-labelledby\" needs one describing the set of tags — assistive technology has no accessible name to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"tag-group\"\n\t\t\t\tmix={mergeMix([attrs({ role: DEFAULT_ROLE }), vstack({ gap: 1 })], mix)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders the group's `<ul>` list, resetting native list markers and spacing\n * and laying {@link TagGroup.Tag} children out as a wrapped row with a small\n * gap between them.\n *\n * @param handle Runtime handle carrying the host `<ul>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <TagGroup.List>\n * \t<TagGroup.Tag color=\"neutral\">{t(\"filters.active\")}</TagGroup.Tag>\n * \t<TagGroup.Tag color=\"neutral\" size=\"sm\">{t(\"filters.archived\")}</TagGroup.Tag>\n * </TagGroup.List>\n */\nTagGroup.List = function TagGroupList(handle: Handle<TagGroup.ListProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<ul\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"list\"\n\t\t\t\tmix={mergeMix([flex(), flexWrap(\"wrap\"), gap(2), m(0), p(0), listStyle()], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single pill-shaped `<li>`, colored through the `data-color`\n * attribute contract shared with {@link Badge} and sized through\n * `data-size`. Compose {@link TagGroup.Remove} inside it for a dismissible tag.\n *\n * @param handle Runtime handle carrying the host `<li>`'s props.\n * @returns The render function producing the pill's markup.\n * @example\n * <TagGroup.Tag color=\"success\">{t(\"status.shipped\")}</TagGroup.Tag>\n * @example\n * <TagGroup.Tag color=\"danger\" size=\"sm\" aria-selected=\"true\">\n * \t{t(\"status.blocked\")}\n * </TagGroup.Tag>\n */\nTagGroup.Tag = function TagGroupTag(handle: Handle<TagGroup.TagProps>) {\n\treturn () => {\n\t\tlet { color, size, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\n\t\treturn (\n\t\t\t<li\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tdata-slot=\"tag\"\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\tdata(\"color\", \"neutral\", outline(\"neutral.ring\")),\n\t\t\t\t\t\t\tdata(\"color\", \"success\", outline(\"success.ring\")),\n\t\t\t\t\t\t\tdata(\"color\", \"warning\", outline(\"warning.ring\")),\n\t\t\t\t\t\t\tdata(\"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\tgap(1),\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tpb(1),\n\t\t\t\t\t\tdata(\"size\", \"sm\", [pi(2), pb(0.5)]),\n\t\t\t\t\t\tdata(\"color\", \"brand\", [bg(\"brand.tint\"), fg(\"brand\")]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [bg(\"success.tint\"), fg(\"success\")]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [bg(\"warning.tint\"), fg(\"warning\")]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [bg(\"danger.tint\"), fg(\"danger\")]),\n\t\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.solid\"), fg(\"brand.onSolid\"), weight(600)]),\n\t\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tdata(\"size\", \"sm\", text(\"xs\")),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [bg(\"neutral.bg-tint-hover\"), fg(\"neutral\")]),\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 * Renders a dismiss control for the tag it's composed inside: a small,\n * ghost-styled {@link Button} with an \"X\" glyph submitting as\n * `type=\"submit\"`, colored from the ambient {@link TagGroup.Tag}'s `data-color`.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the dismiss control's markup.\n * @example\n * <form method=\"post\">\n * \t<TagGroup aria-label={t(\"filters.label\")}>\n * \t\t<TagGroup.List>\n * \t\t\t<TagGroup.Tag color=\"brand\">\n * \t\t\t\t{t(\"filters.remote\")}\n * \t\t\t\t<TagGroup.Remove name=\"remove\" value=\"remote\" aria-label={t(\"filters.removeRemote\")} />\n * \t\t\t</TagGroup.Tag>\n * \t\t</TagGroup.List>\n * \t</TagGroup>\n * </form>\n */\nTagGroup.Remove = function TagGroupRemove(handle: Handle<TagGroup.RemoveProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"submit\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tdata-slot=\"remove\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The control shrinks through Button's own icon-only measure, so it sits inside\n\t\t\t\t\t\t * the pill's line instead of stretching the tag to a full button row, while\n\t\t\t\t\t\t * Button's own hit area keeps its pointer target at `--ui-target-size`.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tvars({ \"ui-button-icon-size-md\": REMOVE_SIZE }),\n\t\t\t\t\t\tmie(-1),\n\t\t\t\t\t\twhen('&[data-slot=\"remove\"] > svg', [is(3), bs(3)]),\n\t\t\t\t\t\tfg(\"currentColor\"),\n\t\t\t\t\t\thover(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\twhen('[data-color=\"neutral\"] &:hover', bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\twhen('[data-color=\"success\"] &:hover', bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\twhen('[data-color=\"danger\"] &:hover', bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\twhen('[data-color=\"warning\"] &:hover', bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\tactive(bg(\"brand.bg-tint-pressed\")),\n\t\t\t\t\t\twhen('[data-color=\"neutral\"] &:active', bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\twhen('[data-color=\"success\"] &:active', bg(\"success.bg-tint-pressed\")),\n\t\t\t\t\t\twhen('[data-color=\"danger\"] &:active', bg(\"danger.bg-tint-pressed\")),\n\t\t\t\t\t\twhen('[data-color=\"warning\"] &:active', bg(\"warning.bg-tint-pressed\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outlineColor(\"brand\")),\n\t\t\t\t\t\twhen('[data-color=\"neutral\"] &:focus-visible', outlineColor(\"neutral\")),\n\t\t\t\t\t\twhen('[data-color=\"success\"] &:focus-visible', outlineColor(\"success\")),\n\t\t\t\t\t\twhen('[data-color=\"danger\"] &:focus-visible', outlineColor(\"danger\")),\n\t\t\t\t\t\twhen('[data-color=\"warning\"] &:focus-visible', outlineColor(\"warning\")),\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<XIcon size={12} />\n\t\t\t</Button>\n\t\t);\n\t};\n};\n"
|
|
13
13
|
},
|
|
14
14
|
"test": {
|
|
15
15
|
"path": "tag-group.test.tsx",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "text-field",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.3",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"description",
|
|
6
6
|
"field-error",
|
|
7
7
|
"form",
|
|
8
|
+
"group",
|
|
8
9
|
"input",
|
|
9
10
|
"label"
|
|
10
11
|
],
|
|
@@ -13,7 +14,10 @@
|
|
|
13
14
|
],
|
|
14
15
|
"source": {
|
|
15
16
|
"path": "text-field.tsx",
|
|
16
|
-
"content": "/**\n * A convenience wrapper composing a labeled, described, and validated field\n * in one call: a caption through {@link Label}, the control through\n * {@link Input}, an optional supporting passage through {@link Description},\n * and an optional validation message through {@link FieldError}. Every id\n * and `aria-describedby` relationship between the parts is computed from\n * this instance's own stable identifier, leaving no id bookkeeping to the\n * consumer.\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 type { FieldPartsProps } from \"@sdxc/ui/utils\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { resolveFieldWiring } from \"@sdxc/ui/utils\";\n\nimport { Description } from \"@sdxc/ui/description\";\nimport { FieldError } from \"@sdxc/ui/field-error\";\nimport { resolveFieldIssue } from \"@sdxc/ui/form\";\nimport { Input } from \"@sdxc/ui/input\";\nimport { Label } from \"@sdxc/ui/label\";\n\n/** Native `<input>` `type` {@link TextField} falls back to when `type` is omitted. */\nconst DEFAULT_TYPE: TextField.Type = \"text\";\n\n/**\n * Prop types for {@link TextField}.\n */\nexport namespace TextField {\n\t/**\n\t * Semantic color role for the control's keyboard focus ring, each mapped\n\t * to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Native `<input>` `type` this wrapper renders a single-line, text-like\n\t * control for. A checkbox, radio, or file control each has its own\n\t * dedicated component instead of a `type` value here.\n\t */\n\texport type Type = \"text\" | \"email\" | \"password\" | \"tel\" | \"url\" | \"search\" | \"number\";\n\n\t/**\n\t * Per-part styling for the elements this convenience wrapper composes in\n\t * one call, layered after each part's own built-in styling.\n\t */\n\texport
|
|
17
|
+
"content": "/**\n * A convenience wrapper composing a labeled, described, and validated field\n * in one call: a caption through {@link Label}, the control through\n * {@link Input}, an optional supporting passage through {@link Description},\n * and an optional validation message through {@link FieldError}. Every id\n * and `aria-describedby` relationship between the parts is computed from\n * this instance's own stable identifier, leaving no id bookkeeping to the\n * consumer.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix } from \"@sdxc/u/general\";\n\nimport type { FieldPartsProps } from \"@sdxc/ui/utils\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { resolveFieldWiring } from \"@sdxc/ui/utils\";\n\nimport { Description } from \"@sdxc/ui/description\";\nimport { FieldError } from \"@sdxc/ui/field-error\";\nimport { resolveFieldIssue } from \"@sdxc/ui/form\";\nimport { Group } from \"@sdxc/ui/group\";\nimport { Input } from \"@sdxc/ui/input\";\nimport { Label } from \"@sdxc/ui/label\";\n\n/** Native `<input>` `type` {@link TextField} falls back to when `type` is omitted. */\nconst DEFAULT_TYPE: TextField.Type = \"text\";\n\n/**\n * Prop types for {@link TextField}.\n */\nexport namespace TextField {\n\t/**\n\t * Semantic color role for the control's keyboard focus ring, each mapped\n\t * to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Native `<input>` `type` this wrapper renders a single-line, text-like\n\t * control for. A checkbox, radio, or file control each has its own\n\t * dedicated component instead of a `type` value here.\n\t */\n\texport type Type = \"text\" | \"email\" | \"password\" | \"tel\" | \"url\" | \"search\" | \"number\";\n\n\t/**\n\t * Per-part styling for the elements this convenience wrapper composes in\n\t * one call, layered after each part's own built-in styling.\n\t */\n\texport interface PartsProps extends FieldPartsProps {\n\t\t/** Styling for the row joining the control to its addons, rendered only with a `prefix` or `suffix`. */\n\t\tgroup?: TagProps<\"div\">[\"mix\"];\n\t\tprefix?: TagProps<\"label\">[\"mix\"];\n\t\tsuffix?: TagProps<\"label\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link TextField}. `mix` styles the root element\n\t * grouping the field's parts; style the composed label, control,\n\t * description, and error individually through `parts` instead.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\" | \"prefix\"> {\n\t\t/** Semantic color role for the control's focus ring. Defaults to `\"neutral\"` when omitted. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * The field's caption, rendered through {@link Label} and associated\n\t\t * with the control through a native `for`/`id` relationship computed\n\t\t * from this instance's own identifier.\n\t\t */\n\t\tlabel: RemixNode;\n\t\t/**\n\t\t * Supporting copy rendered through {@link Description} beneath the\n\t\t * control and referenced by the control's `aria-describedby`. Omit to\n\t\t * render no description.\n\t\t */\n\t\tdescription?: RemixNode;\n\t\t/**\n\t\t * Static text joined to the control's leading edge as one field — a currency, a\n\t\t * domain. It describes the control through `aria-describedby`, stays out of its\n\t\t * name, and focuses the control when clicked.\n\t\t */\n\t\tprefix?: RemixNode;\n\t\t/** Static text joined to the control's trailing edge as one field — a unit, a domain suffix. */\n\t\tsuffix?: RemixNode;\n\t\t/**\n\t\t * Validation message rendered through {@link FieldError} beneath the\n\t\t * control, marking `aria-invalid` unless set explicitly. Falls back to\n\t\t * a {@link Form}'s own `issues` message by `name`; an explicit value wins.\n\t\t */\n\t\terrorMessage?: RemixNode;\n\t\t/**\n\t\t * Native `autofocus`. Defaults to `true` for the first invalid field of\n\t\t * an enclosing {@link Form}'s `issues`, landing keyboard focus on the\n\t\t * problem with no client JavaScript; pass explicitly to override.\n\t\t */\n\t\tautoFocus?: boolean;\n\t\t/** Native `<input>` `type`. Defaults to {@link DEFAULT_TYPE}. */\n\t\ttype?: Type;\n\t\t/** Native `name` submitted with an enclosing form. */\n\t\tname?: string;\n\t\t/** Current value, for a control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, for a control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Placeholder copy shown while the control is empty. */\n\t\tplaceholder?: string;\n\t\t/** Marks the control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint, e.g. `\"email\"` or `\"current-password\"`. */\n\t\tautoComplete?: string;\n\t\t/** Native validation pattern the control's value must match. */\n\t\tpattern?: string;\n\t\t/** Minimum accepted value length. */\n\t\tminLength?: number;\n\t\t/** Maximum accepted value length. */\n\t\tmaxLength?: number;\n\t\t/** Per-part styling for this wrapper's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Composes {@link Label}, {@link Input}, {@link Description}, and\n * {@link FieldError} into one field, computing every id and\n * `aria-describedby` link from this instance's own stable identifier.\n *\n * @param handle Runtime handle carrying the root element's props and this instance's stable identifier.\n * @returns The render function producing the field's markup.\n * @example\n * <TextField label={t(\"form.email.label\")} type=\"email\" name=\"email\" required />\n * @example\n * <TextField\n * \tlabel={t(\"form.password.label\")}\n * \ttype=\"password\"\n * \tname=\"password\"\n * \tdescription={t(\"form.password.hint\")}\n * />\n * @example\n * <TextField label={t(\"settings.slug.label\")} name=\"slug\" prefix=\"pulse.dev/\" />\n * @example\n * <TextField\n * \tlabel={t(\"form.username.label\")}\n * \tname=\"username\"\n * \tdefaultValue=\"ab\"\n * \terrorMessage={t(\"form.username.tooShort\")}\n * />\n */\nexport function TextField(handle: Handle<TextField.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\tprefix,\n\t\t\tsuffix,\n\t\t\terrorMessage: errorMessageProp,\n\t\t\tautoFocus,\n\t\t\ttype,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tplaceholder,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tpattern,\n\t\t\tminLength,\n\t\t\tmaxLength,\n\t\t\t\"aria-invalid\": ariaInvalidProp,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_TYPE;\n\t\tlet { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, name, errorMessageProp);\n\t\tlet resolvedAutoFocus = autoFocus ?? (isFirstInvalid || undefined);\n\t\tlet { resolvedColor, resolvedInvalid, descriptionId, errorId, describedBy } =\n\t\t\tresolveFieldWiring(handle.id, {\n\t\t\t\tcolor,\n\t\t\t\terrorMessage,\n\t\t\t\tdescription,\n\t\t\t\tariaInvalid: ariaInvalidProp,\n\t\t\t});\n\t\tlet hasAddon = Boolean(prefix || suffix);\n\t\tlet labelId = hasAddon ? `${handle.id}-label` : undefined;\n\t\tlet prefixId = prefix ? `${handle.id}-prefix` : undefined;\n\t\tlet suffixId = suffix ? `${handle.id}-suffix` : undefined;\n\t\tlet controlDescribedBy =\n\t\t\t[prefixId, suffixId, describedBy].filter(Boolean).join(\" \") || undefined;\n\n\t\tlet control = (\n\t\t\t<Input\n\t\t\t\tid={handle.id}\n\t\t\t\ttype={resolvedType as never}\n\t\t\t\tname={name}\n\t\t\t\tvalue={value}\n\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\tplaceholder={placeholder}\n\t\t\t\trequired={required}\n\t\t\t\tdisabled={disabled}\n\t\t\t\treadOnly={readOnly}\n\t\t\t\tautoComplete={autoComplete}\n\t\t\t\tpattern={pattern}\n\t\t\t\tminLength={minLength}\n\t\t\t\tmaxLength={maxLength}\n\t\t\t\t// oxlint-disable-next-line jsx-a11y/no-autofocus -- Not a focus grab on page load: this only ever resolves true for the first field an enclosing Form reports as invalid, so a failed submit lands the user on the problem instead of leaving them to hunt for it.\n\t\t\t\tautoFocus={resolvedAutoFocus}\n\t\t\t\taria-invalid={resolvedInvalid}\n\t\t\t\taria-labelledby={labelId}\n\t\t\t\taria-describedby={controlDescribedBy}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tmix={parts?.input}\n\t\t\t/>\n\t\t);\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"text-field\" mix={mergeMix(fieldStackLayout(), mix)}>\n\t\t\t\t<Label id={labelId} htmlFor={handle.id} mix={parts?.label}>\n\t\t\t\t\t{label}\n\t\t\t\t</Label>\n\t\t\t\t{hasAddon ? (\n\t\t\t\t\t<Group role=\"presentation\" mix={parts?.group}>\n\t\t\t\t\t\t{prefix ? (\n\t\t\t\t\t\t\t<Group.Text id={prefixId} htmlFor={handle.id} mix={parts?.prefix}>\n\t\t\t\t\t\t\t\t{prefix}\n\t\t\t\t\t\t\t</Group.Text>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t{control}\n\t\t\t\t\t\t{suffix ? (\n\t\t\t\t\t\t\t<Group.Text id={suffixId} htmlFor={handle.id} mix={parts?.suffix}>\n\t\t\t\t\t\t\t\t{suffix}\n\t\t\t\t\t\t\t</Group.Text>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</Group>\n\t\t\t\t) : (\n\t\t\t\t\tcontrol\n\t\t\t\t)}\n\t\t\t\t{description ? (\n\t\t\t\t\t<Description id={descriptionId} mix={parts?.description}>\n\t\t\t\t\t\t{description}\n\t\t\t\t\t</Description>\n\t\t\t\t) : null}\n\t\t\t\t{errorMessage ? (\n\t\t\t\t\t<FieldError id={errorId} mix={parts?.error}>\n\t\t\t\t\t\t{errorMessage}\n\t\t\t\t\t</FieldError>\n\t\t\t\t) : null}\n\t\t\t</div>\n\t\t);\n\t};\n}\n"
|
|
17
18
|
},
|
|
18
|
-
"test":
|
|
19
|
+
"test": {
|
|
20
|
+
"path": "text-field.browser.test.tsx",
|
|
21
|
+
"content": "/**\n * Lays a text field with a prefix or suffix out in a real browser: the addon and the\n * input share one border with rounding on the outer corners only, the addon describes\n * the input and focuses it when clicked, and the field's rings wrap the whole group.\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, userEvent } from \"vitest/browser\";\n\nimport { Group } from \"@sdxc/ui/group\";\nimport { Input } from \"@sdxc/ui/input\";\nimport { TextField } from \"@sdxc/ui/text-field\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.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 = 480): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\thost.style.padding = \"8px\";\n\tdocument.body.appendChild(host);\n\tmounted = render(node, { container: host });\n\treturn host;\n}\n\n/** The parts of the one field rendered in `host`. */\nfunction parts(host: HTMLElement) {\n\tlet input = host.querySelector<HTMLInputElement>(\"input\")!;\n\tlet addons = [...host.querySelectorAll<HTMLElement>('[data-slot=\"group-text\"]')];\n\tlet group = input.parentElement!;\n\treturn { input, addons, group };\n}\n\n/** Whether an element's computed outline is drawn. */\nfunction hasOutline(element: Element): boolean {\n\tlet style = getComputedStyle(element);\n\treturn style.outlineStyle !== \"none\" && Number.parseFloat(style.outlineWidth) > 0;\n}\n\ndescribe(\"TextField with a prefix or suffix\", () => {\n\ttest(\"joins the prefix to the input as one bordered field, rounded on the outer corners only\", () => {\n\t\tlet host = mount(<TextField label=\"Workspace URL\" name=\"slug\" prefix=\"pulse.dev/\" />);\n\t\tlet { input, addons } = parts(host);\n\t\tlet [prefix] = addons;\n\t\tlet prefixStyle = getComputedStyle(prefix!);\n\t\tlet inputStyle = getComputedStyle(input);\n\n\t\texpect(addons).toHaveLength(1);\n\t\texpect(prefix!.textContent).toBe(\"pulse.dev/\");\n\t\texpect(prefixStyle.borderTopWidth).toBe(\"1px\");\n\t\texpect(\n\t\t\tMath.abs(prefix!.getBoundingClientRect().right - input.getBoundingClientRect().left),\n\t\t).toBeLessThanOrEqual(1);\n\t\texpect(prefix!.getBoundingClientRect().height).toBeCloseTo(\n\t\t\tinput.getBoundingClientRect().height,\n\t\t\t0,\n\t\t);\n\n\t\texpect(Number.parseFloat(prefixStyle.borderStartStartRadius)).toBeGreaterThan(0);\n\t\texpect(Number.parseFloat(prefixStyle.borderEndStartRadius)).toBeGreaterThan(0);\n\t\texpect(prefixStyle.borderStartEndRadius).toBe(\"0px\");\n\t\texpect(prefixStyle.borderEndEndRadius).toBe(\"0px\");\n\t\texpect(inputStyle.borderStartStartRadius).toBe(\"0px\");\n\t\texpect(inputStyle.borderEndStartRadius).toBe(\"0px\");\n\t\texpect(Number.parseFloat(inputStyle.borderStartEndRadius)).toBeGreaterThan(0);\n\t\texpect(Number.parseFloat(inputStyle.borderEndEndRadius)).toBeGreaterThan(0);\n\t});\n\n\ttest(\"rounds a suffix on its trailing corners and the input on its leading ones\", () => {\n\t\tlet host = mount(<TextField label=\"Timeout\" name=\"timeout\" type=\"number\" suffix=\"ms\" />);\n\t\tlet { input, addons } = parts(host);\n\t\tlet [suffix] = addons;\n\t\tlet suffixStyle = getComputedStyle(suffix!);\n\t\tlet inputStyle = getComputedStyle(input);\n\n\t\texpect(\n\t\t\tMath.abs(input.getBoundingClientRect().right - suffix!.getBoundingClientRect().left),\n\t\t).toBeLessThanOrEqual(1);\n\t\texpect(suffixStyle.borderStartStartRadius).toBe(\"0px\");\n\t\texpect(Number.parseFloat(suffixStyle.borderStartEndRadius)).toBeGreaterThan(0);\n\t\texpect(Number.parseFloat(inputStyle.borderStartStartRadius)).toBeGreaterThan(0);\n\t\texpect(inputStyle.borderStartEndRadius).toBe(\"0px\");\n\t});\n\n\ttest(\"describes the input with its addons and keeps its name to the label\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField\n\t\t\t\tlabel=\"Price\"\n\t\t\t\tname=\"price\"\n\t\t\t\tprefix=\"$\"\n\t\t\t\tsuffix=\"USD\"\n\t\t\t\tdescription=\"Charged monthly.\"\n\t\t\t/>,\n\t\t);\n\t\tlet { input, addons } = parts(host);\n\t\tlet describedBy = input.getAttribute(\"aria-describedby\")!.split(\" \");\n\n\t\tfor (let addon of addons) expect(describedBy).toContain(addon.id);\n\t\texpect(describedBy).toHaveLength(3);\n\t\tlet labelledBy = input.getAttribute(\"aria-labelledby\")!;\n\t\texpect(document.getElementById(labelledBy)!.textContent).toBe(\"Price\");\n\t\tfor (let addon of addons) expect(addon.tabIndex).toBeLessThan(0);\n\t});\n\n\ttest(\"focuses the input when the addon is clicked\", async () => {\n\t\tlet host = mount(<TextField label=\"Workspace URL\" name=\"slug\" prefix=\"pulse.dev/\" />);\n\t\tlet { input, addons } = parts(host);\n\n\t\tawait userEvent.click(addons[0]!);\n\n\t\texpect(document.activeElement).toBe(input);\n\t});\n\n\ttest(\"draws the focus ring around the whole group, not the input\", async () => {\n\t\tlet host = mount(<TextField label=\"Workspace URL\" name=\"slug\" prefix=\"pulse.dev/\" />);\n\t\tlet { input, group } = parts(host);\n\n\t\tawait userEvent.click(input);\n\n\t\texpect(hasOutline(group)).toBe(true);\n\t\texpect(hasOutline(input)).toBe(false);\n\t});\n\n\ttest(\"draws the invalid ring around the whole group, not the input\", () => {\n\t\tlet host = mount(\n\t\t\t<TextField label=\"Workspace URL\" name=\"slug\" prefix=\"pulse.dev/\" errorMessage=\"Taken.\" />,\n\t\t);\n\t\tlet { input, group, addons } = parts(host);\n\n\t\texpect(input.getAttribute(\"aria-invalid\")).toBe(\"true\");\n\t\texpect(hasOutline(group)).toBe(true);\n\t\texpect(hasOutline(input)).toBe(false);\n\t\texpect(getComputedStyle(addons[0]!).borderTopColor).toBe(\n\t\t\tgetComputedStyle(input).borderTopColor,\n\t\t);\n\t});\n\n\ttest(\"dims the addon with a disabled field\", () => {\n\t\tlet host = mount(<TextField label=\"Amount\" name=\"amount\" prefix=\"$\" disabled />);\n\t\tlet { addons } = parts(host);\n\n\t\texpect(Number(getComputedStyle(addons[0]!).opacity)).toBeLessThan(1);\n\t});\n\n\ttest(\"shrinks the input and keeps a long addon on one line at 320px\", async () => {\n\t\tawait page.viewport(320, 640);\n\t\tlet host = mount(\n\t\t\t<TextField label=\"Subdomain\" name=\"subdomain\" suffix=\".northwind.example.com\" />,\n\t\t\t304,\n\t\t);\n\t\tlet { input, addons, group } = parts(host);\n\t\tlet [suffix] = addons;\n\n\t\texpect(document.documentElement.scrollWidth).toBeLessThanOrEqual(320);\n\t\texpect(group.getBoundingClientRect().right).toBeLessThanOrEqual(\n\t\t\thost.getBoundingClientRect().right,\n\t\t);\n\t\texpect(suffix!.getBoundingClientRect().height).toBeCloseTo(\n\t\t\tinput.getBoundingClientRect().height,\n\t\t\t0,\n\t\t);\n\t\texpect(suffix!.scrollWidth).toBeLessThanOrEqual(suffix!.clientWidth);\n\t});\n});\n\ndescribe(\"Group.Text\", () => {\n\ttest(\"composes an addon onto an Input by hand\", async () => {\n\t\tlet host = mount(\n\t\t\t<Group>\n\t\t\t\t<Group.Text id=\"slug-prefix\" htmlFor=\"slug\">\n\t\t\t\t\tpulse.dev/\n\t\t\t\t</Group.Text>\n\t\t\t\t<Input id=\"slug\" aria-label=\"Workspace URL\" aria-describedby=\"slug-prefix\" />\n\t\t\t</Group>,\n\t\t);\n\t\tlet { input, addons, group } = parts(host);\n\n\t\tawait userEvent.click(addons[0]!);\n\n\t\texpect(document.activeElement).toBe(input);\n\t\texpect(hasOutline(group)).toBe(true);\n\t\texpect(hasOutline(input)).toBe(false);\n\t});\n});\n"
|
|
22
|
+
}
|
|
19
23
|
}
|
package/registry/ui/text.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "text",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Text"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "text.tsx",
|
|
10
|
-
"content": "/**\n * A run of small body copy, styled at the library's default text size and\n * the neutral muted foreground color. It carries no color, variant, or size\n * contract of its own — a description beneath a heading, a caption beside a\n * control, or any other passage of supporting copy renders through it at a\n * single, consistent intensity.\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 { fg } from \"@sdxc/u/color\";\nimport { pretty, text } from \"@sdxc/u/typography\";\n\n/**\n * Prop types for {@link Text}.\n */\nexport namespace Text {\n\t/**\n\t * Every native `<span>` attribute, unchanged, plus the `mix` passthrough.\n\t * Carries no color, variant, or size prop of its own — always rendering\n\t * at the library's default body-copy size and muted foreground color.\n\t */\n\texport interface Props extends TagProps<\"span\"> {}\n}\n\n/**\n * Renders its children inside a `<span>` sized and colored as a small run of\n * body copy: the library's default text size paired with the neutral muted\n * foreground color.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the text run's markup.\n * @example\n * <Text>{t(\"client.description\")}</Text>\n */\nexport function Text(handle: Handle<Text.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <span {...rest} mix={[fg(\"neutral\"), text(\"sm\"), pretty(), mix
|
|
10
|
+
"content": "/**\n * A run of small body copy, styled at the library's default text size and\n * the neutral muted foreground color. It carries no color, variant, or size\n * contract of its own — a description beneath a heading, a caption beside a\n * control, or any other passage of supporting copy renders through it at a\n * single, consistent intensity.\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 { fg } from \"@sdxc/u/color\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { pretty, text } from \"@sdxc/u/typography\";\n\n/**\n * Prop types for {@link Text}.\n */\nexport namespace Text {\n\t/**\n\t * Every native `<span>` attribute, unchanged, plus the `mix` passthrough.\n\t * Carries no color, variant, or size prop of its own — always rendering\n\t * at the library's default body-copy size and muted foreground color.\n\t */\n\texport interface Props extends TagProps<\"span\"> {}\n}\n\n/**\n * Renders its children inside a `<span>` sized and colored as a small run of\n * body copy: the library's default text size paired with the neutral muted\n * foreground color.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the text run's markup.\n * @example\n * <Text>{t(\"client.description\")}</Text>\n */\nexport function Text(handle: Handle<Text.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <span {...rest} mix={mergeMix([fg(\"neutral\"), text(\"sm\"), pretty()], mix)} />;\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": null
|
|
13
13
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textarea",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"TextArea"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "textarea.tsx",
|
|
10
|
-
"content": "/**\n * A multi-line native form field for free text entry, rendered as a bordered,\n * rounded `<textarea>` that shares {@link Input}'s border, background, and\n * focus-ring contract. It starts at a comfortable minimum block size and\n * grows with its content through `field-sizing: content`, so a reply box or\n * a comment field never clips what's already been typed.\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 { border, bg, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, opacity } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { block } from \"@sdxc/u/layout\";\nimport { is, bs, minBs, pi, pb } from \"@sdxc/u/size\";\nimport { when, hover, invalid } from \"@sdxc/u/state\";\nimport { text } from \"@sdxc/u/typography\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** Semantic color role {@link TextArea} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: TextArea.Color = \"neutral\";\n\n/**\n * Prop types for {@link TextArea}.\n */\nexport namespace TextArea {\n\t/**\n\t * Semantic color role for the focus-visible ring, each mapped to its\n\t * matching `--ui-*` variables. A field marked invalid always reads the\n\t * danger tone for its ring instead, regardless of `color`.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Every native `<textarea>` attribute, unchanged, plus the `mix`\n\t * passthrough. `aria-invalid` together with the platform's own\n\t * post-interaction validity state drives the invalid styling.\n\t */\n\texport type Props = TagProps<\"textarea\"> & {\n\t\t/** Semantic color role for the focus-visible ring. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t};\n}\n\n/**\n * Renders a native `<textarea>` host styled as a bordered, rounded field,\n * colored through the `data-color` attribute contract — the same visual\n * language as {@link Input}, rendering only the field itself.\n *\n * @param handle Runtime handle carrying the host `<textarea>`'s props.\n * @returns The render function producing the field's markup.\n * @example\n * <Label htmlFor=\"bio\">{t(\"form.bio.label\")}</Label>\n * <TextArea id=\"bio\" name=\"bio\" />\n * @example\n * <TextArea\n * \taria-label={t(\"form.comment.label\")}\n * \tcolor=\"brand\"\n * \tplaceholder={t(\"form.comment.placeholder\")}\n * />\n * @example\n * <TextArea id=\"notes\" aria-describedby=\"notes-error\" aria-invalid=\"true\" />\n * <FieldError id=\"notes-error\">{t(\"form.notes.tooLong\")}</FieldError>\n */\nexport function TextArea(handle: Handle<TextArea.Props>) {\n\treturn () => {\n\t\tlet { color, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\treturn (\n\t\t\t<textarea\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tblock(),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\tbs(\"auto\"),\n\t\t\t\t\tminBs(\"6rem\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\tbg(\"neutral.bg-tint\"),\n\t\t\t\t\tfg(\"neutral.fg-emphasis\"),\n\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\twhen(\"&::placeholder\", fg(\"neutral.fg-muted\")),\n\t\t\t\t\thover(border(\"neutral.border-strong\")),\n\t\t\t\t\twhen(\"&:focus\", border(\"neutral.border-strong\")),\n\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\toutline({ color: \"neutral.ring\", offset: 0 }),\n\t\t\t\t\t\tborder(\"neutral.border-strong\"),\n\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\tborder(\"brand.border-strong\"),\n\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 0 }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\tborder(\"success.border-strong\"),\n\t\t\t\t\t\t\toutline({ color: \"success.ring\", offset: 0 }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\tborder(\"warning.border-strong\"),\n\t\t\t\t\t\t\toutline({ color: \"warning.ring\", offset: 0 }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\tborder(\"danger.border-strong\"),\n\t\t\t\t\t\t\toutline({ color: \"danger.ring\", offset: 0 }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\tinvalid([outline({ color: \"danger.ring\", offset: 0 }), border(\"danger.border-strong\")]),\n\t\t\t\t\twhen(\"&:disabled\", [opacity(50), bg(\"neutral.bg-tint-hover\"), cursor(\"not-allowed\")]),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\tresize: \"block\",\n\t\t\t\t\t\tfieldSizing: \"content\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"&:focus\", outline(\"none\")),\n\t\t\t\t\tmix,\n\t\t\t\t
|
|
10
|
+
"content": "/**\n * A multi-line native form field for free text entry, rendered as a bordered,\n * rounded `<textarea>` that shares {@link Input}'s border, background, and\n * focus-ring contract. It starts at a comfortable minimum block size and\n * grows with its content through `field-sizing: content`, so a reply box or\n * a comment field never clips what's already been typed.\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 { border, bg, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, opacity } from \"@sdxc/u/effects\";\nimport { cursor, raw, mergeMix } from \"@sdxc/u/general\";\nimport { block } from \"@sdxc/u/layout\";\nimport { is, bs, minBs, pi, pb } from \"@sdxc/u/size\";\nimport { when, hover, invalid } from \"@sdxc/u/state\";\nimport { text } from \"@sdxc/u/typography\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** Semantic color role {@link TextArea} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: TextArea.Color = \"neutral\";\n\n/**\n * Prop types for {@link TextArea}.\n */\nexport namespace TextArea {\n\t/**\n\t * Semantic color role for the focus-visible ring, each mapped to its\n\t * matching `--ui-*` variables. A field marked invalid always reads the\n\t * danger tone for its ring instead, regardless of `color`.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Every native `<textarea>` attribute, unchanged, plus the `mix`\n\t * passthrough. `aria-invalid` together with the platform's own\n\t * post-interaction validity state drives the invalid styling.\n\t */\n\texport type Props = TagProps<\"textarea\"> & {\n\t\t/** Semantic color role for the focus-visible ring. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t};\n}\n\n/**\n * Renders a native `<textarea>` host styled as a bordered, rounded field,\n * colored through the `data-color` attribute contract — the same visual\n * language as {@link Input}, rendering only the field itself.\n *\n * @param handle Runtime handle carrying the host `<textarea>`'s props.\n * @returns The render function producing the field's markup.\n * @example\n * <Label htmlFor=\"bio\">{t(\"form.bio.label\")}</Label>\n * <TextArea id=\"bio\" name=\"bio\" />\n * @example\n * <TextArea\n * \taria-label={t(\"form.comment.label\")}\n * \tcolor=\"brand\"\n * \tplaceholder={t(\"form.comment.placeholder\")}\n * />\n * @example\n * <TextArea id=\"notes\" aria-describedby=\"notes-error\" aria-invalid=\"true\" />\n * <FieldError id=\"notes-error\">{t(\"form.notes.tooLong\")}</FieldError>\n */\nexport function TextArea(handle: Handle<TextArea.Props>) {\n\treturn () => {\n\t\tlet { color, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\treturn (\n\t\t\t<textarea\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\tblock(),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tbs(\"auto\"),\n\t\t\t\t\t\tminBs(\"6rem\"),\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\t\tbg(\"neutral.bg-tint\"),\n\t\t\t\t\t\tfg(\"neutral.fg-emphasis\"),\n\t\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t\twhen(\"&::placeholder\", fg(\"neutral.fg-muted\")),\n\t\t\t\t\t\thover(border(\"neutral.border-strong\")),\n\t\t\t\t\t\twhen(\"&:focus\", border(\"neutral.border-strong\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\t\toutline({ color: \"neutral.ring\", offset: 0 }),\n\t\t\t\t\t\t\tborder(\"neutral.border-strong\"),\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tborder(\"brand.border-strong\"),\n\t\t\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 0 }),\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.border-strong\"),\n\t\t\t\t\t\t\t\toutline({ color: \"success.ring\", offset: 0 }),\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.border-strong\"),\n\t\t\t\t\t\t\t\toutline({ color: \"warning.ring\", offset: 0 }),\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.border-strong\"),\n\t\t\t\t\t\t\t\toutline({ color: \"danger.ring\", offset: 0 }),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tinvalid([outline({ color: \"danger.ring\", offset: 0 }), border(\"danger.border-strong\")]),\n\t\t\t\t\t\twhen(\"&:disabled\", [opacity(50), bg(\"neutral.bg-tint-hover\"), cursor(\"not-allowed\")]),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tresize: \"block\",\n\t\t\t\t\t\t\tfieldSizing: \"content\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twhen(\"&:focus\", outline(\"none\")),\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"
|
|
11
11
|
},
|
|
12
12
|
"test": null
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "time-field",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"description",
|
|
6
6
|
"field-error",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"source": {
|
|
15
15
|
"path": "time-field.tsx",
|
|
16
|
-
"content": "/**\n * A convenience wrapper composing a labeled, described, and validated time\n * field in one call: a caption through {@link Label}, a native\n * `<input type=\"time\">` control through {@link Input}, an optional\n * supporting passage through {@link Description}, and an optional\n * validation message through {@link FieldError}. Every id and\n * `aria-describedby` relationship between the parts is computed from this\n * instance's own stable identifier, leaving no id bookkeeping to the\n * consumer.\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 { tabularNums } from \"@sdxc/u/typography\";\n\nimport type { FieldPartsProps } from \"@sdxc/ui/utils\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { resolveFieldWiring } from \"@sdxc/ui/utils\";\n\nimport { Description } from \"@sdxc/ui/description\";\nimport { FieldError } from \"@sdxc/ui/field-error\";\nimport { resolveFieldIssue } from \"@sdxc/ui/form\";\nimport { Input } from \"@sdxc/ui/input\";\nimport { Label } from \"@sdxc/ui/label\";\n\n/**\n * Prop types for {@link TimeField}.\n */\nexport namespace TimeField {\n\t/**\n\t * Semantic color role for the control's keyboard focus ring, each mapped\n\t * 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 in\n\t * one call, layered after each part's own built-in styling.\n\t */\n\texport type PartsProps = FieldPartsProps;\n\n\t/**\n\t * Props accepted by {@link TimeField}. `mix` styles the root element\n\t * grouping the field's parts; style the composed label, control,\n\t * description, and error individually through `parts` instead.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the control's focus ring. Defaults to `\"neutral\"` when omitted. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * The field's caption, rendered through {@link Label} and associated\n\t\t * with the control through a native `for`/`id` relationship computed\n\t\t * from this instance's own identifier.\n\t\t */\n\t\tlabel: RemixNode;\n\t\t/**\n\t\t * Supporting copy rendered through {@link Description} beneath the\n\t\t * control and referenced by the control's `aria-describedby`. Omit to\n\t\t * render no description.\n\t\t */\n\t\tdescription?: RemixNode;\n\t\t/**\n\t\t * Validation message rendered through {@link FieldError} beneath the\n\t\t * control, marking `aria-invalid` unless set explicitly. Falls back to\n\t\t * a {@link Form}'s own `issues` message by `name`; an explicit value wins.\n\t\t */\n\t\terrorMessage?: RemixNode;\n\t\t/**\n\t\t * Native `autofocus`. Defaults to `true` for the first invalid field of\n\t\t * an enclosing {@link Form}'s `issues`, landing keyboard focus on the\n\t\t * problem with no client JavaScript; pass explicitly to override.\n\t\t */\n\t\tautoFocus?: boolean;\n\t\t/** Native `name` submitted with an enclosing form. */\n\t\tname?: string;\n\t\t/** Current value, in the platform's `\"HH:mm\"` (or `\"HH:mm:ss\"`) format, for a control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in that same format, for a control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted time, in the same `\"HH:mm\"`/`\"HH:mm:ss\"` format. */\n\t\tmin?: string;\n\t\t/** Latest accepted time, in the same `\"HH:mm\"`/`\"HH:mm:ss\"` format. */\n\t\tmax?: string;\n\t\t/** Granularity of the accepted value, in seconds — set to `1` to surface a seconds digit alongside hours and minutes. */\n\t\tstep?: number;\n\t\t/** Marks the control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for this wrapper's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Composes {@link Label}, a native `<input type=\"time\">` control through\n * {@link Input}, {@link Description}, and {@link FieldError} into one field,\n * computing every id and `aria-describedby` link from this identifier.\n *\n * @param handle Runtime handle carrying the root element's props and this instance's stable identifier.\n * @returns The render function producing the field's markup.\n * @example\n * <TimeField label={t(\"event.startTime.label\")} name=\"startTime\" required />\n * @example\n * <TimeField\n * \tlabel={t(\"event.reminderTime.label\")}\n * \tmin=\"09:00\"\n * \tmax=\"18:00\"\n * \tdescription={t(\"event.reminderTime.hint\")}\n * />\n * @example\n * <TimeField\n * \tlabel={t(\"event.endTime.label\")}\n * \tname=\"endTime\"\n * \tdefaultValue=\"09:00\"\n * \terrorMessage={t(\"event.endTime.beforeStart\")}\n * />\n */\nexport function TimeField(handle: Handle<TimeField.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage: errorMessageProp,\n\t\t\tautoFocus,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-invalid\": ariaInvalidProp,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, name, errorMessageProp);\n\t\tlet resolvedAutoFocus = autoFocus ?? (isFirstInvalid || undefined);\n\t\tlet { resolvedColor, resolvedInvalid, descriptionId, errorId, describedBy } =\n\t\t\tresolveFieldWiring(handle.id, {\n\t\t\t\tcolor,\n\t\t\t\terrorMessage,\n\t\t\t\tdescription,\n\t\t\t\tariaInvalid: ariaInvalidProp,\n\t\t\t});\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"time-field\" mix={
|
|
16
|
+
"content": "/**\n * A convenience wrapper composing a labeled, described, and validated time\n * field in one call: a caption through {@link Label}, a native\n * `<input type=\"time\">` control through {@link Input}, an optional\n * supporting passage through {@link Description}, and an optional\n * validation message through {@link FieldError}. Every id and\n * `aria-describedby` relationship between the parts is computed from this\n * instance's own stable identifier, leaving no id bookkeeping to the\n * consumer.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { tabularNums } from \"@sdxc/u/typography\";\n\nimport type { FieldPartsProps } from \"@sdxc/ui/utils\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { resolveFieldWiring } from \"@sdxc/ui/utils\";\n\nimport { Description } from \"@sdxc/ui/description\";\nimport { FieldError } from \"@sdxc/ui/field-error\";\nimport { resolveFieldIssue } from \"@sdxc/ui/form\";\nimport { Input } from \"@sdxc/ui/input\";\nimport { Label } from \"@sdxc/ui/label\";\n\n/**\n * Prop types for {@link TimeField}.\n */\nexport namespace TimeField {\n\t/**\n\t * Semantic color role for the control's keyboard focus ring, each mapped\n\t * 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 in\n\t * one call, layered after each part's own built-in styling.\n\t */\n\texport type PartsProps = FieldPartsProps;\n\n\t/**\n\t * Props accepted by {@link TimeField}. `mix` styles the root element\n\t * grouping the field's parts; style the composed label, control,\n\t * description, and error individually through `parts` instead.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the control's focus ring. Defaults to `\"neutral\"` when omitted. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * The field's caption, rendered through {@link Label} and associated\n\t\t * with the control through a native `for`/`id` relationship computed\n\t\t * from this instance's own identifier.\n\t\t */\n\t\tlabel: RemixNode;\n\t\t/**\n\t\t * Supporting copy rendered through {@link Description} beneath the\n\t\t * control and referenced by the control's `aria-describedby`. Omit to\n\t\t * render no description.\n\t\t */\n\t\tdescription?: RemixNode;\n\t\t/**\n\t\t * Validation message rendered through {@link FieldError} beneath the\n\t\t * control, marking `aria-invalid` unless set explicitly. Falls back to\n\t\t * a {@link Form}'s own `issues` message by `name`; an explicit value wins.\n\t\t */\n\t\terrorMessage?: RemixNode;\n\t\t/**\n\t\t * Native `autofocus`. Defaults to `true` for the first invalid field of\n\t\t * an enclosing {@link Form}'s `issues`, landing keyboard focus on the\n\t\t * problem with no client JavaScript; pass explicitly to override.\n\t\t */\n\t\tautoFocus?: boolean;\n\t\t/** Native `name` submitted with an enclosing form. */\n\t\tname?: string;\n\t\t/** Current value, in the platform's `\"HH:mm\"` (or `\"HH:mm:ss\"`) format, for a control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in that same format, for a control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted time, in the same `\"HH:mm\"`/`\"HH:mm:ss\"` format. */\n\t\tmin?: string;\n\t\t/** Latest accepted time, in the same `\"HH:mm\"`/`\"HH:mm:ss\"` format. */\n\t\tmax?: string;\n\t\t/** Granularity of the accepted value, in seconds — set to `1` to surface a seconds digit alongside hours and minutes. */\n\t\tstep?: number;\n\t\t/** Marks the control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for this wrapper's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Composes {@link Label}, a native `<input type=\"time\">` control through\n * {@link Input}, {@link Description}, and {@link FieldError} into one field,\n * computing every id and `aria-describedby` link from this identifier.\n *\n * @param handle Runtime handle carrying the root element's props and this instance's stable identifier.\n * @returns The render function producing the field's markup.\n * @example\n * <TimeField label={t(\"event.startTime.label\")} name=\"startTime\" required />\n * @example\n * <TimeField\n * \tlabel={t(\"event.reminderTime.label\")}\n * \tmin=\"09:00\"\n * \tmax=\"18:00\"\n * \tdescription={t(\"event.reminderTime.hint\")}\n * />\n * @example\n * <TimeField\n * \tlabel={t(\"event.endTime.label\")}\n * \tname=\"endTime\"\n * \tdefaultValue=\"09:00\"\n * \terrorMessage={t(\"event.endTime.beforeStart\")}\n * />\n */\nexport function TimeField(handle: Handle<TimeField.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage: errorMessageProp,\n\t\t\tautoFocus,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-invalid\": ariaInvalidProp,\n\t\t\tparts,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, name, errorMessageProp);\n\t\tlet resolvedAutoFocus = autoFocus ?? (isFirstInvalid || undefined);\n\t\tlet { resolvedColor, resolvedInvalid, descriptionId, errorId, describedBy } =\n\t\t\tresolveFieldWiring(handle.id, {\n\t\t\t\tcolor,\n\t\t\t\terrorMessage,\n\t\t\t\tdescription,\n\t\t\t\tariaInvalid: ariaInvalidProp,\n\t\t\t});\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"time-field\" mix={mergeMix(fieldStackLayout(), mix)}>\n\t\t\t\t<Label htmlFor={handle.id} mix={parts?.label}>\n\t\t\t\t\t{label}\n\t\t\t\t</Label>\n\t\t\t\t<Input\n\t\t\t\t\tid={handle.id}\n\t\t\t\t\ttype=\"time\"\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tmin={min}\n\t\t\t\t\tmax={max}\n\t\t\t\t\tstep={step}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t// oxlint-disable-next-line jsx-a11y/no-autofocus -- Not a focus grab on page load: this only ever resolves true for the first field an enclosing Form reports as invalid, so a failed submit lands the user on the problem instead of leaving them to hunt for it.\n\t\t\t\t\tautoFocus={resolvedAutoFocus}\n\t\t\t\t\taria-invalid={resolvedInvalid}\n\t\t\t\t\taria-describedby={describedBy}\n\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\tmix={[tabularNums(), parts?.input]}\n\t\t\t\t/>\n\t\t\t\t{description ? (\n\t\t\t\t\t<Description id={descriptionId} mix={parts?.description}>\n\t\t\t\t\t\t{description}\n\t\t\t\t\t</Description>\n\t\t\t\t) : null}\n\t\t\t\t{errorMessage ? (\n\t\t\t\t\t<FieldError id={errorId} mix={parts?.error}>\n\t\t\t\t\t\t{errorMessage}\n\t\t\t\t\t</FieldError>\n\t\t\t\t) : null}\n\t\t\t</div>\n\t\t);\n\t};\n}\n"
|
|
17
17
|
},
|
|
18
18
|
"test": null
|
|
19
19
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "timeline",
|
|
3
|
+
"changedIn": "2026.11.3",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Timeline"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "timeline.tsx",
|
|
10
|
+
"content": "/**\n * A record's activity as an ordered list: a 2px rail threading 16px event icons toned by\n * what happened, one line per event (avatar, bold actor, muted verb, time), an optional\n * comment card, and a native `<details>` folding a run of quiet events into \"N more\".\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 { EllipsisIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { cursor, listStyle, pseudoContent, raw, mergeMix } from \"@sdxc/u/general\";\nimport { flex, gap, grid, inlineFlex, items, justify, relative, vstack } from \"@sdxc/u/layout\";\nimport { bs, is, m, minIs, p } from \"@sdxc/u/size\";\nimport { before, data, focusVisible, hover, when } from \"@sdxc/u/state\";\nimport { leading, text, weight } from \"@sdxc/u/typography\";\n\n/** The side of the square each event's icon sits centred in; the rail runs through its middle. */\nconst ICON_BOX = \"var(--ui-timeline-icon-box, 1.5rem)\";\n\n/** Tone an event's icon takes when `tone` is left unset. */\nconst DEFAULT_TONE: Timeline.Tone = \"neutral\";\n\n/**\n * Prop types for {@link Timeline} and its compound parts.\n */\nexport namespace Timeline {\n\t/** The semantic role an event's icon is drawn in. */\n\texport type Tone = \"neutral\" | \"brand\" | \"success\" | \"warning\" | \"danger\";\n\n\t/** Every native `<ol>` attribute. */\n\texport interface Props extends TagProps<\"ol\"> {}\n\n\t/** Every native `<li>` attribute, plus the event's parts. */\n\texport interface EventProps extends Omit<TagProps<\"li\">, \"children\"> {\n\t\t/** A 16px glyph naming the kind of event, decorative beside the line's words. */\n\t\ticon: RemixNode;\n\t\t/** @default {@link DEFAULT_TONE} */\n\t\ttone?: Tone;\n\t\t/** A small avatar of the actor, shown before the name. */\n\t\tavatar?: RemixNode;\n\t\t/** Who did it, set in bold. */\n\t\tactor?: RemixNode;\n\t\t/** When it happened: a `RelativeTime` or plain text. */\n\t\ttime?: RemixNode;\n\t\t/** A comment or other body, set as a card under the line. */\n\t\tbody?: RemixNode;\n\t\t/** What happened, in muted text after the actor: \"resolved the incident\". */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/** Every native `<li>` attribute, plus the folded events. */\n\texport interface MoreProps extends Omit<TagProps<\"li\">, \"children\"> {\n\t\t/** The disclosure's label, such as \"4 more events\". */\n\t\tsummary: RemixNode;\n\t\t/** Starts unfolded. */\n\t\topen?: boolean;\n\t\t/** The folded {@link Timeline.Event} items. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The two-column track every row shares: the icon box, then the line. Folded events use\n * it too, so their icons stay on the one rail the list draws.\n */\nfunction rowTrack() {\n\treturn [\n\t\tgrid(),\n\t\traw({ gridTemplateColumns: `${ICON_BOX} minmax(0, 1fr)` }),\n\t\tgap(3),\n\t\traw({ rowGap: \"0.5rem\" }),\n\t\titems(\"start\"),\n\t];\n}\n\n/**\n * Renders the `<ol>` and its rail. The rail is drawn once, behind every icon from the\n * first to the last, so a folded run keeps the line continuous when it opens; icons sit on\n * the page's background, `--ui-timeline-surface`, which masks the rail where they meet it.\n *\n * @param handle Runtime handle carrying the `<ol>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <Timeline>\n * \t<Timeline.Event icon={<CircleDotIcon />} tone=\"danger\" actor=\"Uptime\" time={<RelativeTime date={opened} />}>\n * \t\topened the incident\n * \t</Timeline.Event>\n * \t<Timeline.Event icon={<MessageSquareIcon />} avatar={<Avatar size=\"xs\" />} actor=\"Ana\" body={<p>Rolling back.</p>}>\n * \t\tcommented\n * \t</Timeline.Event>\n * </Timeline>\n */\nexport function Timeline(handle: Handle<Timeline.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<ol\n\t\t\t\tdata-slot=\"timeline\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\tm(0),\n\t\t\t\t\t\tp(0),\n\t\t\t\t\t\tlistStyle(\"none\"),\n\t\t\t\t\t\tvstack({ gap: 3 }),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tbefore([\n\t\t\t\t\t\t\tpseudoContent('\"\"'),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\t\t\tinsetBlock: `calc(${ICON_BOX} / 2)`,\n\t\t\t\t\t\t\t\tinsetInlineStart: `calc(${ICON_BOX} / 2 - 1px)`,\n\t\t\t\t\t\t\t\tinlineSize: \"2px\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tbg(\"neutral.border\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders one event: its toned icon on the rail, then a single wrapping line of avatar,\n * actor, description and time, then the body card when one is given.\n *\n * @param handle Runtime handle carrying the `<li>`'s props.\n * @returns The render function producing the event's markup.\n * @example\n * <Timeline.Event icon={<RocketIcon />} tone=\"brand\" actor=\"deploy-bot\" time=\"2m ago\">\n * \tdeployed v4.2.1\n * </Timeline.Event>\n */\nTimeline.Event = function TimelineEvent(handle: Handle<Timeline.EventProps>) {\n\treturn () => {\n\t\tlet { icon, tone, avatar, actor, time, body, children, mix, ...rest } = handle.props;\n\t\tlet resolvedTone = tone ?? DEFAULT_TONE;\n\n\t\treturn (\n\t\t\t<li\n\t\t\t\tdata-slot=\"timeline-event\"\n\t\t\t\tdata-tone={resolvedTone}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(rowTrack(), mix)}\n\t\t\t>\n\t\t\t\t<TimelineIcon tone={resolvedTone}>{icon}</TimelineIcon>\n\t\t\t\t<div mix={[vstack({ gap: 2 }), minIs(0)]}>\n\t\t\t\t\t<p\n\t\t\t\t\t\tdata-slot=\"timeline-line\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\tm(0),\n\t\t\t\t\t\t\tflex(),\n\t\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\t\traw({ flexWrap: \"wrap\", minBlockSize: ICON_BOX }),\n\t\t\t\t\t\t\tgap(1.5),\n\t\t\t\t\t\t\tleading(\"1.25rem\"),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{avatar ? <span mix={[inlineFlex()]}>{avatar}</span> : null}\n\t\t\t\t\t\t{actor ? (\n\t\t\t\t\t\t\t<span data-slot=\"timeline-actor\" mix={[weight(\"semibold\")]}>\n\t\t\t\t\t\t\t\t{actor}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t{children ? (\n\t\t\t\t\t\t\t<span data-slot=\"timeline-description\" mix={[fg(\"neutral.muted\")]}>\n\t\t\t\t\t\t\t\t{children}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t{time ? (\n\t\t\t\t\t\t\t<span data-slot=\"timeline-time\" mix={[fg(\"neutral.muted\"), text(\"xs\")]}>\n\t\t\t\t\t\t\t\t{time}\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) : null}\n\t\t\t\t\t</p>\n\t\t\t\t\t{body ? (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tdata-slot=\"timeline-body\"\n\t\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t\tp(3),\n\t\t\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\t\t\tborder({ color: \"neutral.border\", width: 1 }),\n\t\t\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\t\t\"& > :first-child\": { marginBlockStart: 0 },\n\t\t\t\t\t\t\t\t\t\"& > :last-child\": { marginBlockEnd: 0 },\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{body}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t</li>\n\t\t);\n\t};\n};\n\n/**\n * Renders a run of events folded behind a `<details>`: its summary sits on the rail with\n * an ellipsis glyph, and its events open in place, in the same list and on the same rail.\n *\n * @param handle Runtime handle carrying the `<li>`'s props.\n * @returns The render function producing the folded run's markup.\n * @example\n * <Timeline.More summary=\"4 more events\">\n * \t{checks.map((check) => <Timeline.Event icon={<CheckIcon />} actor=\"Uptime\">{check.text}</Timeline.Event>)}\n * </Timeline.More>\n */\nTimeline.More = function TimelineMore(handle: Handle<Timeline.MoreProps>) {\n\treturn () => {\n\t\tlet { summary, open, children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<li data-slot=\"timeline-more\" {...rest} mix={mergeMix([], mix)}>\n\t\t\t\t<details open={open} mix={[raw({ \"&[open] > summary\": { display: \"none\" } })]}>\n\t\t\t\t\t<summary\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\t...rowTrack(),\n\t\t\t\t\t\t\tlistStyle(\"none\"),\n\t\t\t\t\t\t\traw({ \"&::-webkit-details-marker\": { display: \"none\" } }),\n\t\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\t\tfocusVisible(outline({ color: \"brand.ring\", width: 2, offset: 2 })),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<TimelineIcon tone=\"neutral\">\n\t\t\t\t\t\t\t<EllipsisIcon size={16} aria-hidden=\"true\" />\n\t\t\t\t\t\t</TimelineIcon>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tmix={[\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\tbs(ICON_BOX),\n\t\t\t\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\t\t\t\thover(fg(\"neutral.emphasis\")),\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{summary}\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</summary>\n\t\t\t\t\t<ol mix={[m(0), p(0), listStyle(\"none\"), vstack({ gap: 3 })]}>{children}</ol>\n\t\t\t\t</details>\n\t\t\t</li>\n\t\t);\n\t};\n};\n\n/** Props {@link TimelineIcon} reads. */\ninterface TimelineIconProps {\n\ttone: Timeline.Tone;\n\tchildren: RemixNode;\n}\n\n/**\n * The icon box on the rail: the glyph in its tone, on the surface colour so the rail\n * reads as passing behind it.\n *\n * @param handle Runtime handle carrying the tone and glyph.\n * @returns The render function producing the icon box.\n */\nfunction TimelineIcon(handle: Handle<TimelineIconProps>) {\n\treturn () => {\n\t\tlet { tone, children } = handle.props;\n\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"timeline-icon\"\n\t\t\t\tdata-tone={tone}\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tis(ICON_BOX),\n\t\t\t\t\tbs(ICON_BOX),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tbg(\"var(--ui-timeline-surface, var(--ui-bg, Canvas))\"),\n\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\tdata(\"tone\", \"brand\", fg(\"brand\")),\n\t\t\t\t\tdata(\"tone\", \"success\", fg(\"success\")),\n\t\t\t\t\tdata(\"tone\", \"warning\", fg(\"warning\")),\n\t\t\t\t\tdata(\"tone\", \"danger\", fg(\"danger\")),\n\t\t\t\t\twhen(\"& > svg\", raw({ inlineSize: \"1rem\", blockSize: \"1rem\" })),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
},
|
|
12
|
+
"test": {
|
|
13
|
+
"path": "timeline.browser.test.tsx",
|
|
14
|
+
"content": "/**\n * Lays Timeline out in a real browser: an ordered list whose rail runs through the centre\n * of every icon, a line per event, a comment card in the text column, and a \"N more\"\n * disclosure whose folded events open on the same rail.\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, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { Timeline } from \"@sdxc/ui/timeline\";\n\nimport \"@sdxc/ui/theme.css\";\n\n/** A 16px stand-in glyph. */\nfunction Glyph() {\n\treturn () => (\n\t\t<svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n\t\t\t<circle cx=\"8\" cy=\"8\" r=\"6\" fill=\"currentColor\" />\n\t\t</svg>\n\t);\n}\n\n/** An incident's activity: opened, a folded run of checks, a comment, resolved. */\nfunction Incident() {\n\treturn () => (\n\t\t<Timeline aria-label=\"Activity\">\n\t\t\t<Timeline.Event icon={<Glyph />} tone=\"danger\" actor=\"Uptime\" time=\"12m ago\">\n\t\t\t\topened the incident\n\t\t\t</Timeline.Event>\n\t\t\t<Timeline.More summary=\"2 more events\">\n\t\t\t\t<Timeline.Event icon={<Glyph />} actor=\"Uptime\" time=\"11m ago\">\n\t\t\t\t\tchecked from Frankfurt\n\t\t\t\t</Timeline.Event>\n\t\t\t\t<Timeline.Event icon={<Glyph />} actor=\"Uptime\" time=\"10m ago\">\n\t\t\t\t\tchecked from Singapore\n\t\t\t\t</Timeline.Event>\n\t\t\t</Timeline.More>\n\t\t\t<Timeline.Event\n\t\t\t\ticon={<Glyph />}\n\t\t\t\tactor=\"Ana Souza\"\n\t\t\t\ttime=\"8m ago\"\n\t\t\t\tbody={<p>Rolling back the 14:02 deploy.</p>}\n\t\t\t>\n\t\t\t\tcommented\n\t\t\t</Timeline.Event>\n\t\t\t<Timeline.Event icon={<Glyph />} tone=\"success\" actor=\"Ana Souza\" time=\"2m ago\">\n\t\t\t\tresolved the incident\n\t\t\t</Timeline.Event>\n\t\t</Timeline>\n\t);\n}\n\n/** Mounts the incident timeline in a 480px host. */\nfunction mount(): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = \"480px\";\n\tdocument.body.appendChild(host);\n\trender(<Incident />, { container: host });\n\treturn host;\n}\n\n/** Horizontal centre of a box. */\nfunction centerX(element: Element): number {\n\tlet box = element.getBoundingClientRect();\n\treturn box.left + box.width / 2;\n}\n\nafterEach(() => {\n\tdocument.body.replaceChildren();\n});\n\ndescribe(\"Timeline\", () => {\n\ttest(\"is an ordered list of events\", () => {\n\t\tlet host = mount();\n\t\tlet list = host.querySelector(\"ol\")!;\n\n\t\texpect(list.getAttribute(\"aria-label\")).toBe(\"Activity\");\n\t\texpect(list.querySelectorAll(\":scope > li\")).toHaveLength(4);\n\t});\n\n\ttest(\"runs a 2px rail through the centre of every 16px icon\", () => {\n\t\tlet host = mount();\n\t\tlet list = host.querySelector(\"ol\")!;\n\t\tlet rail = getComputedStyle(list, \"::before\");\n\t\tlet railCenter = list.getBoundingClientRect().left + parseFloat(rail.left) + 1;\n\n\t\texpect(rail.width).toBe(\"2px\");\n\t\tfor (let icon of host.querySelectorAll('[data-slot=\"timeline-icon\"]')) {\n\t\t\tif (icon.getClientRects().length === 0) continue;\n\t\t\texpect(centerX(icon)).toBeCloseTo(railCenter, 0);\n\t\t\texpect(icon.querySelector(\"svg\")!.getBoundingClientRect().width).toBe(16);\n\t\t}\n\t});\n\n\ttest(\"tones each icon by what happened\", () => {\n\t\tdocument.documentElement.style.setProperty(\"--ui-color-danger-600\", \"rgb(220, 38, 38)\");\n\t\tdocument.documentElement.style.setProperty(\"--ui-color-success-600\", \"rgb(22, 163, 74)\");\n\t\tlet host = mount();\n\t\tlet [opened] = host.querySelectorAll<HTMLElement>('[data-slot=\"timeline-icon\"]');\n\t\tlet resolved = [...host.querySelectorAll<HTMLElement>('[data-slot=\"timeline-icon\"]')].at(-1)!;\n\n\t\texpect(getComputedStyle(opened!).color).toBe(\"rgb(220, 38, 38)\");\n\t\texpect(getComputedStyle(resolved).color).toBe(\"rgb(22, 163, 74)\");\n\t});\n\n\ttest(\"keeps each event on one line with the actor in bold\", () => {\n\t\tlet host = mount();\n\t\tlet line = host.querySelector<HTMLElement>('[data-slot=\"timeline-line\"]')!;\n\t\tlet actor = line.querySelector('[data-slot=\"timeline-actor\"]')!;\n\n\t\texpect(line.getBoundingClientRect().height).toBeLessThanOrEqual(24);\n\t\texpect(Number(getComputedStyle(actor).fontWeight)).toBeGreaterThanOrEqual(600);\n\t});\n\n\ttest(\"sets a comment as a card in the text column\", () => {\n\t\tlet host = mount();\n\t\tlet body = host.querySelector<HTMLElement>('[data-slot=\"timeline-body\"]')!;\n\t\tlet line = body.parentElement!.querySelector('[data-slot=\"timeline-line\"]')!;\n\n\t\texpect(body.getBoundingClientRect().left).toBeCloseTo(line.getBoundingClientRect().left, 0);\n\t\texpect(getComputedStyle(body).borderTopWidth).toBe(\"1px\");\n\t});\n\n\ttest(\"folds quiet events behind a disclosure that opens them on the same rail\", async () => {\n\t\tlet host = mount();\n\t\tlet details = host.querySelector(\"details\")!;\n\t\tlet summary = details.querySelector(\"summary\")!;\n\t\tlet folded = details.querySelectorAll<HTMLElement>('[data-slot=\"timeline-event\"]');\n\t\tlet first = host.querySelector('[data-slot=\"timeline-icon\"]')!;\n\n\t\texpect(summary.textContent).toBe(\"2 more events\");\n\t\texpect(folded[0]!.checkVisibility()).toBe(false);\n\n\t\tawait userEvent.click(summary);\n\n\t\texpect(details.open).toBe(true);\n\t\texpect(folded[0]!.checkVisibility()).toBe(true);\n\t\tlet icon = folded[0]!.querySelector('[data-slot=\"timeline-icon\"]')!;\n\t\texpect(centerX(icon)).toBeCloseTo(centerX(first), 0);\n\t});\n});\n"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toggle-button",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"ToggleButton",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
],
|
|
9
9
|
"source": {
|
|
10
10
|
"path": "toggle-button.tsx",
|
|
11
|
-
"content": "/**\n * A native `<button>` that reflects an on/off state through its own\n * `aria-pressed` attribute instead of a separate boolean prop — muting a\n * track, toggling bold text, filtering a view. Shares {@link Button}'s\n * semantic color role, visual weight variant, and size, and layers a tinted\n * background on top of the outline and ghost variants once pressed, so a\n * toggled control reads as active without a fourth variant of its own.\n * {@link ToggleButtonGroup} lays a run of these out along a shared axis.\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 { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, opacity } from \"@sdxc/u/effects\";\nimport { cursor, userSelect } from \"@sdxc/u/general\";\nimport { flex, flexCol, inlineFlex, items, justify, gap, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minBs, pi, pb, pie, pis } from \"@sdxc/u/size\";\nimport { when, hover, active, data } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { glyphEdges } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link ToggleButton} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: ToggleButton.Color = \"neutral\";\n\n/** Visual weight {@link ToggleButton} falls back to when `variant` is omitted. */\nconst DEFAULT_VARIANT: ToggleButton.Variant = \"outline\";\n\n/** Size variant {@link ToggleButton} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: ToggleButton.Size = \"md\";\n\n/** Role {@link ToggleButtonGroup} carries by default, matching the arrow-key-navigable pattern a row of grouped toggle buttons follows. */\nconst DEFAULT_GROUP_ROLE = \"toolbar\";\n\n/** Layout axis {@link ToggleButtonGroup} falls back to when `orientation` is omitted. */\nconst DEFAULT_GROUP_ORIENTATION: ToggleButtonGroup.Orientation = \"horizontal\";\n\n/**\n * Folds the pressed state a consumer passed into the token the host renders.\n * ARIA reads text, so a boolean `true`/`false` would serialize as the bare\n * name or vanish; `\"false\"` stays explicit since its absence would leave the button with no toggle semantics at all.\n *\n * @param pressed The state as the consumer expressed it.\n * @returns The token to render.\n */\nfunction resolveAriaPressed(\n\tpressed: ToggleButton.Props[\"aria-pressed\"],\n): \"true\" | \"false\" | \"mixed\" {\n\tif (pressed === \"mixed\") return \"mixed\";\n\tif (pressed === true || pressed === \"true\") return \"true\";\n\treturn \"false\";\n}\n\n/**\n * Prop types for {@link ToggleButton}.\n */\nexport namespace ToggleButton {\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: a solid fill with an on-solid foreground, a transparent\n\t * fill with a strong colored border, or a fully transparent fill with\n\t * just a colored label. Pressing tints `\"outline\"`/`\"ghost\"`; `\"solid\"` already reads filled.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\";\n\n\t/**\n\t * Size variant controlling the button's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Props accepted by {@link ToggleButton}, with `aria-pressed` made\n\t * required: it carries the entire pressed state, read straight off the\n\t * rendered attribute by this component's styling and the `pressToggle()` mixin.\n\t */\n\texport interface Props extends Omit<TagProps<\"button\">, \"aria-pressed\"> {\n\t\t/** The button's pressed state, reflected directly onto the host's own `aria-pressed` attribute. */\n\t\t\"aria-pressed\": NonNullable<TagProps<\"button\">[\"aria-pressed\"]>;\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}\n}\n\n/**\n * Renders a native `<button aria-pressed>` host clicking which submits its\n * enclosing form by default, flipping the state through a server round-trip\n * with no script required; pair `pressToggle()` through `mix` in a hydrated island to skip the round-trip.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the toggle button's markup.\n * @example\n * <ToggleButton aria-pressed={isMuted} aria-label={t(\"player.mute\")}>\n * \t<VolumeXIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={isBold} variant=\"ghost\" size=\"sm\" aria-label={t(\"editor.bold\")}>\n * \t<BoldIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={filter === \"active\"} color=\"brand\" name=\"filter\" value=\"active\">\n * \t{t(\"tasks.filterActive\")}\n * </ToggleButton>\n */\nexport function ToggleButton(handle: Handle<ToggleButton.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, children, mix, \"aria-pressed\": pressed, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\t\tlet resolvedPressed = resolveAriaPressed(pressed);\n\t\tlet edges = glyphEdges(children);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"ToggleButton: an icon-only toggle needs an `aria-label` describing what it does — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\t{...rest}\n\t\t\t\taria-pressed={resolvedPressed}\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-glyph-start={edges.start || undefined}\n\t\t\t\tdata-glyph-end={edges.end || undefined}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', outline(\"neutral.ring\")),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', outline(\"success.ring\")),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', outline(\"warning.ring\")),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', outline(\"danger.ring\")),\n\t\t\t\t\t]),\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tgap(\"0.5rem\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * A glyph is sized against the label beside it and holds that size, so the row keeps the\n\t\t\t\t\t * height its text and padding ask for; the default `flex-shrink: 1` would squash the glyph\n\t\t\t\t\t * ahead of the words.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& > svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t/** A small control reaches `--ui-target-size` however a consumer positions it. */\n\t\t\t\t\thitArea({ anchor: \"flex-center\" }),\n\t\t\t\t\tuserSelect(),\n\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The row measure is stated, so the control lines up with a field of the same size when\n\t\t\t\t\t * a Group fuses the two, and still grows when a long label wraps.\n\t\t\t\t\t */\n\t\t\t\t\tminBs(\"2.5rem\"),\n\n\t\t\t\t\twhen('&[data-size=\"sm\"]', [\n\t\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\t\tpb(\"0.375rem\"),\n\t\t\t\t\t\tminBs(\"2rem\"),\n\t\t\t\t\t\twhen(\"& > svg\", [is(3), bs(3)]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-size=\"lg\"]', [\n\t\t\t\t\t\tpi(\"1.25rem\"),\n\t\t\t\t\t\tpb(\"0.625rem\"),\n\t\t\t\t\t\tminBs(\"3rem\"),\n\t\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\t]),\n\t\t\t\t\t/**\n\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 * side drops one step and the glyph and the words read as evenly inset.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&[data-glyph-start]:has(> svg:first-child)\", [\n\t\t\t\t\t\tpis(\"0.75rem\"),\n\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pis(\"0.5rem\")),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pis(\"1rem\")),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&[data-glyph-end]:has(> svg:last-child)\", [\n\t\t\t\t\t\tpie(\"0.75rem\"),\n\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pie(\"0.5rem\")),\n\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pie(\"1rem\")),\n\t\t\t\t\t]),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tdata(\"size\", \"sm\", text(\"xs\")),\n\t\t\t\t\tdata(\"size\", \"lg\", text(\"base\")),\n\t\t\t\t\twhen('&[data-variant=\"solid\"]', [\n\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\tbg(\"brand.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"brand.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"brand.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\tbg(\"neutral.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"neutral.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\tbg(\"success.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"success.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"success.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\tbg(\"warning.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"warning.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"warning.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\tbg(\"danger.bg-solid\"),\n\t\t\t\t\t\t\tfg(\"danger.fg-on-solid\"),\n\t\t\t\t\t\t\thover(bg(\"danger.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-variant=\"ghost\"]', bg(\"transparent\")),\n\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\tborder(\"brand.border\"),\n\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\thover([bg(\"brand.bg-tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\tborder(\"neutral.border\"),\n\t\t\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\t\t\thover([bg(\"neutral.bg-tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\tborder(\"success.border\"),\n\t\t\t\t\t\t\tfg(\"success.fg\"),\n\t\t\t\t\t\t\thover([bg(\"success.bg-tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\tborder(\"danger.border\"),\n\t\t\t\t\t\t\tfg(\"danger.fg\"),\n\t\t\t\t\t\t\thover([bg(\"danger.bg-tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\tborder(\"warning.border\"),\n\t\t\t\t\t\t\tfg(\"warning.fg\"),\n\t\t\t\t\t\t\thover([bg(\"warning.bg-tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-variant=\"ghost\"]', [\n\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\thover(bg(\"brand.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"neutral\"]', [\n\t\t\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"success\"]', [\n\t\t\t\t\t\t\tfg(\"success.fg\"),\n\t\t\t\t\t\t\thover(bg(\"success.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"danger\"]', [\n\t\t\t\t\t\t\tfg(\"danger.fg\"),\n\t\t\t\t\t\t\thover(bg(\"danger.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-color=\"warning\"]', [\n\t\t\t\t\t\t\tfg(\"warning.fg\"),\n\t\t\t\t\t\t\thover(bg(\"warning.bg-tint\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[aria-pressed=\"true\"]', [\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"brand\"], &[data-variant=\"ghost\"][data-color=\"brand\"]',\n\t\t\t\t\t\t\tbg(\"brand.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"neutral\"], &[data-variant=\"ghost\"][data-color=\"neutral\"]',\n\t\t\t\t\t\t\tbg(\"neutral.bg-tint-pressed\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"success\"], &[data-variant=\"ghost\"][data-color=\"success\"]',\n\t\t\t\t\t\t\tbg(\"success.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"danger\"], &[data-variant=\"ghost\"][data-color=\"danger\"]',\n\t\t\t\t\t\t\tbg(\"danger.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"warning\"], &[data-variant=\"ghost\"][data-color=\"warning\"]',\n\t\t\t\t\t\t\tbg(\"warning.bg-tint\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&:disabled\", opacity(50)),\n\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\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</button>\n\t\t);\n\t};\n}\n\n/**\n * Prop types for {@link ToggleButtonGroup}.\n */\nexport namespace ToggleButtonGroup {\n\t/**\n\t * Axis a group's toggle buttons lay out along: a single row, or a single\n\t * column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus `mix`. Each nested\n\t * {@link ToggleButton} tracks its own `aria-pressed` and `name`/`value`\n\t * independently; this host only contributes shared grouping and layout.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_GROUP_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n}\n\n/**\n * Renders a `role=\"toolbar\"` `<div>` laying a run of independently pressed\n * {@link ToggleButton} children out in a row, or a column when `orientation`\n * is `\"vertical\"`; each toggle button owns its own `aria-pressed` state, and this host contributes only shared layout and grouping.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the group's markup.\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.textStyle\")}>\n * \t<ToggleButton aria-pressed={isBold} aria-label={t(\"editor.bold\")}>\n * \t\t<BoldIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={isItalic} aria-label={t(\"editor.italic\")}>\n * \t\t<ItalicIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.alignment\")} orientation=\"vertical\">\n * \t<ToggleButton aria-pressed={align === \"start\"} aria-label={t(\"editor.alignStart\")}>\n * \t\t<AlignStartIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={align === \"center\"} aria-label={t(\"editor.alignCenter\")}>\n * \t\t<AlignCenterIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n */\nexport function ToggleButtonGroup(handle: Handle<ToggleButtonGroup.Props>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_GROUP_ORIENTATION;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_GROUP_ROLE }),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(\"0.25rem\"),\n\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [flexCol(), items(\"start\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
"content": "/**\n * A native `<button>` that reflects an on/off state through its own\n * `aria-pressed` attribute instead of a separate boolean prop — muting a\n * track, toggling bold text, filtering a view. Shares {@link Button}'s\n * semantic color role, visual weight variant, and size, and layers a tinted\n * background on top of the outline and ghost variants once pressed, so a\n * toggled control reads as active without a fourth variant of its own.\n * {@link ToggleButtonGroup} lays a run of these out along a shared axis.\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 { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, opacity } from \"@sdxc/u/effects\";\nimport { cursor, userSelect, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, inlineFlex, items, justify, gap, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minBs, pi, pb, pie, pis } from \"@sdxc/u/size\";\nimport { when, hover, active, data } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { glyphEdges } from \"@sdxc/ui/utils\";\nimport { warnIfNoAccessibleName } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link ToggleButton} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: ToggleButton.Color = \"neutral\";\n\n/** Visual weight {@link ToggleButton} falls back to when `variant` is omitted. */\nconst DEFAULT_VARIANT: ToggleButton.Variant = \"outline\";\n\n/** Size variant {@link ToggleButton} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: ToggleButton.Size = \"md\";\n\n/** Role {@link ToggleButtonGroup} carries by default, matching the arrow-key-navigable pattern a row of grouped toggle buttons follows. */\nconst DEFAULT_GROUP_ROLE = \"toolbar\";\n\n/** Layout axis {@link ToggleButtonGroup} falls back to when `orientation` is omitted. */\nconst DEFAULT_GROUP_ORIENTATION: ToggleButtonGroup.Orientation = \"horizontal\";\n\n/**\n * Folds the pressed state a consumer passed into the token the host renders.\n * ARIA reads text, so a boolean `true`/`false` would serialize as the bare\n * name or vanish; `\"false\"` stays explicit since its absence would leave the button with no toggle semantics at all.\n *\n * @param pressed The state as the consumer expressed it.\n * @returns The token to render.\n */\nfunction resolveAriaPressed(\n\tpressed: ToggleButton.Props[\"aria-pressed\"],\n): \"true\" | \"false\" | \"mixed\" {\n\tif (pressed === \"mixed\") return \"mixed\";\n\tif (pressed === true || pressed === \"true\") return \"true\";\n\treturn \"false\";\n}\n\n/**\n * Prop types for {@link ToggleButton}.\n */\nexport namespace ToggleButton {\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: a solid fill with an on-solid foreground, a transparent\n\t * fill with a strong colored border, or a fully transparent fill with\n\t * just a colored label. Pressing tints `\"outline\"`/`\"ghost\"`; `\"solid\"` already reads filled.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\";\n\n\t/**\n\t * Size variant controlling the button's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Props accepted by {@link ToggleButton}, with `aria-pressed` made\n\t * required: it carries the entire pressed state, read straight off the\n\t * rendered attribute by this component's styling and the `pressToggle()` mixin.\n\t */\n\texport interface Props extends Omit<TagProps<\"button\">, \"aria-pressed\"> {\n\t\t/** The button's pressed state, reflected directly onto the host's own `aria-pressed` attribute. */\n\t\t\"aria-pressed\": NonNullable<TagProps<\"button\">[\"aria-pressed\"]>;\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}\n}\n\n/**\n * Renders a native `<button aria-pressed>` host clicking which submits its\n * enclosing form by default, flipping the state through a server round-trip\n * with no script required; pair `pressToggle()` through `mix` in a hydrated island to skip the round-trip.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the toggle button's markup.\n * @example\n * <ToggleButton aria-pressed={isMuted} aria-label={t(\"player.mute\")}>\n * \t<VolumeXIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={isBold} variant=\"ghost\" size=\"sm\" aria-label={t(\"editor.bold\")}>\n * \t<BoldIcon />\n * </ToggleButton>\n * @example\n * <ToggleButton aria-pressed={filter === \"active\"} color=\"brand\" name=\"filter\" value=\"active\">\n * \t{t(\"tasks.filterActive\")}\n * </ToggleButton>\n */\nexport function ToggleButton(handle: Handle<ToggleButton.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, children, mix, \"aria-pressed\": pressed, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\t\tlet resolvedPressed = resolveAriaPressed(pressed);\n\t\tlet edges = glyphEdges(children);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t\"ToggleButton: an icon-only toggle needs an `aria-label` describing what it does — assistive technology has no accessible name to announce otherwise.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\t{...rest}\n\t\t\t\taria-pressed={resolvedPressed}\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-glyph-start={edges.start || undefined}\n\t\t\t\tdata-glyph-end={edges.end || undefined}\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(\"0.5rem\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A glyph is sized against the label beside it and holds that size, so the row keeps the\n\t\t\t\t\t\t * height its text and padding ask for; the default `flex-shrink: 1` would squash the glyph\n\t\t\t\t\t\t * ahead of the words.\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\trounded(\"md\"),\n\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\t/** A small control reaches `--ui-target-size` however a consumer positions it. */\n\t\t\t\t\t\thitArea({ anchor: \"flex-center\" }),\n\t\t\t\t\t\tuserSelect(),\n\t\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The row measure is stated, so the control lines up with a field of the same size when\n\t\t\t\t\t\t * a 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(\"0.75rem\"),\n\t\t\t\t\t\t\tpb(\"0.375rem\"),\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(\"1.25rem\"),\n\t\t\t\t\t\t\tpb(\"0.625rem\"),\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\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(\"0.75rem\"),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pis(\"0.5rem\")),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pis(\"1rem\")),\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(\"0.75rem\"),\n\t\t\t\t\t\t\twhen('&[data-size=\"sm\"]', pie(\"0.5rem\")),\n\t\t\t\t\t\t\twhen('&[data-size=\"lg\"]', pie(\"1rem\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tdata(\"size\", \"sm\", text(\"xs\")),\n\t\t\t\t\t\tdata(\"size\", \"lg\", text(\"base\")),\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.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"brand.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"brand.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"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.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"neutral.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"neutral.bg-solid-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\tbg(\"success.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"success.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"success.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"success.bg-solid-pressed\")),\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.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"warning.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"warning.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"warning.bg-solid-pressed\")),\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.bg-solid\"),\n\t\t\t\t\t\t\t\tfg(\"danger.fg-on-solid\"),\n\t\t\t\t\t\t\t\thover(bg(\"danger.bg-solid-hover\")),\n\t\t\t\t\t\t\t\tactive(bg(\"danger.bg-solid-pressed\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\t\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-variant=\"ghost\"]', bg(\"transparent\")),\n\t\t\t\t\t\twhen('&[data-variant=\"outline\"]', [\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tborder(\"brand.border\"),\n\t\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"brand.bg-tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(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.border\"),\n\t\t\t\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"neutral.bg-tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(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.border\"),\n\t\t\t\t\t\t\t\tfg(\"success.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"success.bg-tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"success.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.border\"),\n\t\t\t\t\t\t\t\tfg(\"danger.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"danger.bg-tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"danger.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.border\"),\n\t\t\t\t\t\t\t\tfg(\"warning.fg\"),\n\t\t\t\t\t\t\t\thover([bg(\"warning.bg-tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[data-variant=\"ghost\"]', [\n\t\t\t\t\t\t\twhen('&[data-color=\"brand\"]', [\n\t\t\t\t\t\t\t\tfg(\"brand.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"brand.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(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.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\t\tactive(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.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"success.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(bg(\"success.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.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"danger.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(bg(\"danger.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.fg\"),\n\t\t\t\t\t\t\t\thover(bg(\"warning.bg-tint\")),\n\t\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[aria-pressed=\"true\"]', [\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"brand\"], &[data-variant=\"ghost\"][data-color=\"brand\"]',\n\t\t\t\t\t\t\t\tbg(\"brand.bg-tint\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"neutral\"], &[data-variant=\"ghost\"][data-color=\"neutral\"]',\n\t\t\t\t\t\t\t\tbg(\"neutral.bg-tint-pressed\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"success\"], &[data-variant=\"ghost\"][data-color=\"success\"]',\n\t\t\t\t\t\t\t\tbg(\"success.bg-tint\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"danger\"], &[data-variant=\"ghost\"][data-color=\"danger\"]',\n\t\t\t\t\t\t\t\tbg(\"danger.bg-tint\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t\t'&[data-variant=\"outline\"][data-color=\"warning\"], &[data-variant=\"ghost\"][data-color=\"warning\"]',\n\t\t\t\t\t\t\t\tbg(\"warning.bg-tint\"),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&:disabled\", opacity(50)),\n\t\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\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</button>\n\t\t);\n\t};\n}\n\n/**\n * Prop types for {@link ToggleButtonGroup}.\n */\nexport namespace ToggleButtonGroup {\n\t/**\n\t * Axis a group's toggle buttons lay out along: a single row, or a single\n\t * column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus `mix`. Each nested\n\t * {@link ToggleButton} tracks its own `aria-pressed` and `name`/`value`\n\t * independently; this host only contributes shared grouping and layout.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_GROUP_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n}\n\n/**\n * Renders a `role=\"toolbar\"` `<div>` laying a run of independently pressed\n * {@link ToggleButton} children out in a row, or a column when `orientation`\n * is `\"vertical\"`; each toggle button owns its own `aria-pressed` state, and this host contributes only shared layout and grouping.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the group's markup.\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.textStyle\")}>\n * \t<ToggleButton aria-pressed={isBold} aria-label={t(\"editor.bold\")}>\n * \t\t<BoldIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={isItalic} aria-label={t(\"editor.italic\")}>\n * \t\t<ItalicIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n * @example\n * <ToggleButtonGroup aria-label={t(\"editor.alignment\")} orientation=\"vertical\">\n * \t<ToggleButton aria-pressed={align === \"start\"} aria-label={t(\"editor.alignStart\")}>\n * \t\t<AlignStartIcon />\n * \t</ToggleButton>\n * \t<ToggleButton aria-pressed={align === \"center\"} aria-label={t(\"editor.alignCenter\")}>\n * \t\t<AlignCenterIcon />\n * \t</ToggleButton>\n * </ToggleButtonGroup>\n */\nexport function ToggleButtonGroup(handle: Handle<ToggleButtonGroup.Props>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_GROUP_ORIENTATION;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_GROUP_ROLE }),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(\"0.25rem\"),\n\t\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [flexCol(), items(\"start\")]),\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"
|
|
12
12
|
},
|
|
13
13
|
"test": {
|
|
14
14
|
"path": "toggle-button.test.tsx",
|