@sdxc/kit 0.0.0-stage → 2026.10.16
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/LICENSE.md +21 -0
- package/README.md +92 -2
- package/changelog.jsonl +1040 -0
- package/config.schema.json +89 -0
- package/dist/bin.d.ts +9 -0
- package/dist/bin.js +10 -0
- package/dist/cli.d.ts +33 -0
- package/dist/cli.js +58 -0
- package/dist/commands/create.d.ts +20 -0
- package/dist/commands/create.js +164 -0
- package/dist/commands/init.d.ts +16 -0
- package/dist/commands/init.js +27 -0
- package/dist/commands/make.d.ts +335 -0
- package/dist/commands/make.js +152 -0
- package/dist/commands/run.d.ts +23 -0
- package/dist/commands/run.js +51 -0
- package/dist/commands/ui/add.d.ts +23 -0
- package/dist/commands/ui/add.js +50 -0
- package/dist/commands/ui/diff.d.ts +20 -0
- package/dist/commands/ui/diff.js +28 -0
- package/dist/commands/ui/list.d.ts +24 -0
- package/dist/commands/ui/list.js +45 -0
- package/dist/commands/ui/remove.d.ts +22 -0
- package/dist/commands/ui/remove.js +48 -0
- package/dist/commands/ui/update.d.ts +23 -0
- package/dist/commands/ui/update.js +37 -0
- package/dist/commands/upgrade.d.ts +30 -0
- package/dist/commands/upgrade.js +184 -0
- package/dist/config.d.ts +81 -0
- package/dist/config.js +157 -0
- package/dist/contract.d.ts +161 -0
- package/dist/contract.js +308 -0
- package/dist/create/github.d.ts +63 -0
- package/dist/create/github.js +172 -0
- package/dist/create/target.d.ts +31 -0
- package/dist/create/target.js +56 -0
- package/dist/create/templates.d.ts +62 -0
- package/dist/create/templates.js +228 -0
- package/dist/dependencies.d.ts +34 -0
- package/dist/dependencies.js +76 -0
- package/dist/diff.d.ts +14 -0
- package/dist/diff.js +103 -0
- package/dist/format.d.ts +21 -0
- package/dist/format.js +40 -0
- package/dist/init.d.ts +38 -0
- package/dist/init.js +92 -0
- package/dist/lock.d.ts +74 -0
- package/dist/lock.js +214 -0
- package/dist/make/declare.d.ts +54 -0
- package/dist/make/declare.js +495 -0
- package/dist/make/generate.d.ts +62 -0
- package/dist/make/generate.js +154 -0
- package/dist/make/imports.d.ts +43 -0
- package/dist/make/imports.js +105 -0
- package/dist/make/index.d.ts +43 -0
- package/dist/make/index.js +136 -0
- package/dist/make/kinds.d.ts +39 -0
- package/dist/make/kinds.js +95 -0
- package/dist/make/migrations.d.ts +41 -0
- package/dist/make/migrations.js +116 -0
- package/dist/make/names.d.ts +31 -0
- package/dist/make/names.js +47 -0
- package/dist/make/stubs.d.ts +44 -0
- package/dist/make/stubs.js +89 -0
- package/dist/middleware.d.ts +44 -0
- package/dist/middleware.js +49 -0
- package/dist/package-manager.d.ts +41 -0
- package/dist/package-manager.js +80 -0
- package/dist/project.d.ts +19 -0
- package/dist/project.js +42 -0
- package/dist/releases.d.ts +40 -0
- package/dist/releases.js +110 -0
- package/dist/testing.d.ts +50 -0
- package/dist/testing.js +129 -0
- package/dist/ui/commands.d.ts +114 -0
- package/dist/ui/commands.js +432 -0
- package/dist/ui/imports.d.ts +46 -0
- package/dist/ui/imports.js +160 -0
- package/dist/ui/layout.d.ts +48 -0
- package/dist/ui/layout.js +138 -0
- package/dist/ui/registry.d.ts +58 -0
- package/dist/ui/registry.js +82 -0
- package/dist/upgrade/changelog.d.ts +50 -0
- package/dist/upgrade/changelog.js +69 -0
- package/dist/upgrade/project.d.ts +62 -0
- package/dist/upgrade/project.js +132 -0
- package/dist/upgrade/prompt.d.ts +51 -0
- package/dist/upgrade/prompt.js +227 -0
- package/dist/upgrade/registry.d.ts +33 -0
- package/dist/upgrade/registry.js +50 -0
- package/lock.schema.json +60 -0
- package/package.json +44 -5
- package/registry/ui/accordion.json +15 -0
- package/registry/ui/alert-dialog.json +20 -0
- package/registry/ui/alert.json +15 -0
- package/registry/ui/aspect-ratio.json +13 -0
- package/registry/ui/attachment.json +15 -0
- package/registry/ui/avatar.json +15 -0
- package/registry/ui/badge.json +13 -0
- package/registry/ui/breadcrumbs.json +15 -0
- package/registry/ui/bubble.json +13 -0
- package/registry/ui/button.json +16 -0
- package/registry/ui/calendar.json +16 -0
- package/registry/ui/card.json +18 -0
- package/registry/ui/carousel.json +15 -0
- package/registry/ui/chart.json +13 -0
- package/registry/ui/checkbox-group.json +13 -0
- package/registry/ui/checkbox.json +16 -0
- package/registry/ui/color-area.json +13 -0
- package/registry/ui/color-field.json +20 -0
- package/registry/ui/color-picker.json +17 -0
- package/registry/ui/color-slider.json +13 -0
- package/registry/ui/color-swatch-picker.json +15 -0
- package/registry/ui/color-swatch.json +13 -0
- package/registry/ui/color-wheel.json +13 -0
- package/registry/ui/combobox.json +15 -0
- package/registry/ui/command.json +13 -0
- package/registry/ui/confirm.json +19 -0
- package/registry/ui/context-menu.json +16 -0
- package/registry/ui/date-field.json +19 -0
- package/registry/ui/date-picker.json +15 -0
- package/registry/ui/date-range-picker.json +16 -0
- package/registry/ui/description.json +13 -0
- package/registry/ui/dialog.json +19 -0
- package/registry/ui/disclosure.json +18 -0
- package/registry/ui/drawer.json +18 -0
- package/registry/ui/drop-indicator.json +13 -0
- package/registry/ui/drop-zone.json +13 -0
- package/registry/ui/empty.json +15 -0
- package/registry/ui/field-error.json +13 -0
- package/registry/ui/file-trigger.json +13 -0
- package/registry/ui/form.json +21 -0
- package/registry/ui/grid-list.json +18 -0
- package/registry/ui/group.json +13 -0
- package/registry/ui/header.json +13 -0
- package/registry/ui/heading-scope.json +20 -0
- package/registry/ui/heading.json +15 -0
- package/registry/ui/highlight.json +16 -0
- package/registry/ui/hover-card.json +13 -0
- package/registry/ui/image-placeholder.json +16 -0
- package/registry/ui/input.json +13 -0
- package/registry/ui/item.json +13 -0
- package/registry/ui/keyboard.json +13 -0
- package/registry/ui/label.json +13 -0
- package/registry/ui/link-button.json +16 -0
- package/registry/ui/link.json +13 -0
- package/registry/ui/listbox.json +15 -0
- package/registry/ui/logo.json +15 -0
- package/registry/ui/marker.json +13 -0
- package/registry/ui/menu.json +19 -0
- package/registry/ui/menubar.json +13 -0
- package/registry/ui/message-scroller.json +16 -0
- package/registry/ui/message.json +13 -0
- package/registry/ui/meter.json +13 -0
- package/registry/ui/modal.json +15 -0
- package/registry/ui/nav-link.json +13 -0
- package/registry/ui/navigation-menu.json +15 -0
- package/registry/ui/number-field.json +15 -0
- package/registry/ui/otp-field.json +15 -0
- package/registry/ui/overlay-arrow.json +13 -0
- package/registry/ui/pagination.json +16 -0
- package/registry/ui/popover.json +13 -0
- package/registry/ui/progress-bar.json +13 -0
- package/registry/ui/radio-group.json +13 -0
- package/registry/ui/range-calendar.json +16 -0
- package/registry/ui/resizable.json +13 -0
- package/registry/ui/scroll-area.json +13 -0
- package/registry/ui/search-field.json +16 -0
- package/registry/ui/section.json +13 -0
- package/registry/ui/select.json +13 -0
- package/registry/ui/selection-indicator.json +13 -0
- package/registry/ui/sentinel-row.json +16 -0
- package/registry/ui/separator.json +13 -0
- package/registry/ui/shared-element.json +13 -0
- package/registry/ui/sheet.json +15 -0
- package/registry/ui/shortcut-list.json +18 -0
- package/registry/ui/sidebar.json +20 -0
- package/registry/ui/skeleton.json +13 -0
- package/registry/ui/slider.json +16 -0
- package/registry/ui/spinner.json +13 -0
- package/registry/ui/switch.json +16 -0
- package/registry/ui/table.json +16 -0
- package/registry/ui/tabs.json +17 -0
- package/registry/ui/tag-group.json +18 -0
- package/registry/ui/text-field.json +19 -0
- package/registry/ui/text.json +13 -0
- package/registry/ui/textarea.json +13 -0
- package/registry/ui/time-field.json +19 -0
- package/registry/ui/toast.json +16 -0
- package/registry/ui/toggle-button.json +17 -0
- package/registry/ui/toolbar.json +13 -0
- package/registry/ui/tooltip.json +16 -0
- package/registry/ui/tree.json +18 -0
- package/registry/ui/typeset.json +16 -0
- package/registry/ui/youtube-embed.json +16 -0
- package/stubs/command.stub +12 -0
- package/stubs/command.test.stub +18 -0
- package/stubs/controller.form.stub +33 -0
- package/stubs/controller.stub +17 -0
- package/stubs/controller.test.stub +15 -0
- package/stubs/email.stub +44 -0
- package/stubs/email.test.stub +16 -0
- package/stubs/factory.stub +10 -0
- package/stubs/initializer.stub +7 -0
- package/stubs/initializer.test.stub +13 -0
- package/stubs/job.cron.stub +12 -0
- package/stubs/job.stub +11 -0
- package/stubs/job.test.stub +15 -0
- package/stubs/mcp.resource.stub +12 -0
- package/stubs/mcp.stub +10 -0
- package/stubs/mcp.test.stub +15 -0
- package/stubs/middleware.stub +11 -0
- package/stubs/middleware.test.stub +13 -0
- package/stubs/migration.stub +1 -0
- package/stubs/model.stub +24 -0
- package/stubs/model.test.stub +15 -0
- package/stubs/policy.stub +13 -0
- package/stubs/policy.test.stub +17 -0
- package/stubs/service.stub +13 -0
- package/stubs/service.test.stub +14 -0
- package/stubs/validator.stub +14 -0
- package/stubs/validator.test.stub +22 -0
- package/templates/app/README.md +57 -0
- package/templates/app/app/commands/about.test.ts +29 -0
- package/templates/app/app/commands/about.ts +34 -0
- package/templates/app/app/commands/index.ts +15 -0
- package/templates/app/app/http/controllers/home.tsx +22 -0
- package/templates/app/app/http/controllers/not-found.tsx +25 -0
- package/templates/app/app/initializers/assets.ts +11 -0
- package/templates/app/app/initializers/cli.ts +35 -0
- package/templates/app/app/initializers/dispatcher.ts +18 -0
- package/templates/app/app/initializers/logger.ts +10 -0
- package/templates/app/app/initializers/mcp.ts +16 -0
- package/templates/app/app/initializers/router.tsx +65 -0
- package/templates/app/app/jobs/index.ts +10 -0
- package/templates/app/app/mcp/resources/index.ts +9 -0
- package/templates/app/app/mcp/tools/index.ts +10 -0
- package/templates/app/bootstrap/browser.ts +27 -0
- package/templates/app/bootstrap/cli.ts +9 -0
- package/templates/app/bootstrap/worker.ts +31 -0
- package/templates/app/cloudflare.config.ts +28 -0
- package/templates/app/config/router-context.d.ts +20 -0
- package/templates/app/gitignore +9 -0
- package/templates/app/package.json +38 -0
- package/templates/app/resources/layouts/document.tsx +58 -0
- package/templates/app/routes/web.ts +12 -0
- package/templates/app/tsconfig.json +40 -0
- package/templates/app/vite.config.ts +40 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "spinner",
|
|
3
|
+
"changedIn": "2026.10.2",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Spinner"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "spinner.tsx",
|
|
10
|
+
"content": "/**\n * A busy indicator rendered as a rotating icon inside a `role=\"progressbar\"`\n * host, colored by a semantic color role and sized by a size variant. Its own\n * styling holds still — compose the `spin()` factory from the animation\n * layer through `mix` for the rotating loop, so a page can render the\n * indicator's shape before any motion-driving CSS lands.\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 { LoaderCircleIcon } from \"@sdxc/icons\";\nimport { bs, fg, inlineFlex, is, items, justify, when } from \"@sdxc/u\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link Spinner} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: Spinner.Color = \"neutral\";\n\n/** Size variant {@link Spinner} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: Spinner.Size = \"md\";\n\n/**\n * Prop types for {@link Spinner}.\n */\nexport namespace Spinner {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*-fg` variable.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Size variant controlling the rotating icon's rendered dimensions.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Props accepted by {@link Spinner}.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"aria-label\"> {\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\t/**\n\t\t * Accessible label announced by assistive technology for as long as\n\t\t * the spinner is on screen. Required — the component ships no\n\t\t * built-in copy, so a consumer's own localized string drives it.\n\t\t */\n\t\t\"aria-label\": string;\n\t}\n}\n\n/**\n * Renders a busy indicator: a `role=\"progressbar\"` host with no\n * `aria-valuenow`, so assistive technology reads it as indeterminate. Pair\n * it with the `spin()` mixin from the animation layer for the rotating loop.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the indicator's markup.\n * @example\n * <Spinner aria-label={t(\"status.loading\")} />\n * @example\n * <Spinner color=\"danger\" size=\"lg\" aria-label={t(\"status.retrying\")} />\n * @example\n * <Spinner mix={[spin()]} aria-label={t(\"status.loading\")} />\n */\nexport function Spinner(handle: Handle<Spinner.Props>) {\n\treturn () => {\n\t\tlet { mix, color, size, \"aria-label\": ariaLabel, ...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<div\n\t\t\t\trole=\"progressbar\"\n\t\t\t\taria-label={ariaLabel}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\n\t\t\t\t\twhen('&[data-color=\"brand\"]', fg(\"brand\")),\n\t\t\t\t\twhen('&[data-color=\"neutral\"]', fg(\"neutral\")),\n\t\t\t\t\twhen('&[data-color=\"success\"]', fg(\"success\")),\n\t\t\t\t\twhen('&[data-color=\"warning\"]', fg(\"warning\")),\n\t\t\t\t\twhen('&[data-color=\"danger\"]', fg(\"danger\")),\n\n\t\t\t\t\twhen(\"& svg\", [\n\t\t\t\t\t\tis(\"var(--ui-spinner-icon-size-md, 1.25rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-spinner-icon-size-md, 1.25rem)\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-size=\"sm\"] svg', [\n\t\t\t\t\t\tis(\"var(--ui-spinner-icon-size-sm, 1rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-spinner-icon-size-sm, 1rem)\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[data-size=\"lg\"] svg', [\n\t\t\t\t\t\tis(\"var(--ui-spinner-icon-size-lg, 1.75rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-spinner-icon-size-lg, 1.75rem)\"),\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<LoaderCircleIcon />\n\t\t\t</div>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
},
|
|
12
|
+
"test": null
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "switch",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Switch"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "switch.tsx",
|
|
10
|
+
"content": "/**\n * A native checkbox styled and wired as an on/off switch: a pill-shaped\n * track whose thumb slides from the inline-start edge to the inline-end\n * edge when checked, tinting with the semantic primary color along the way.\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 {\n\tabsolute,\n\tappearance,\n\tbefore,\n\tbg,\n\tbs,\n\tcursor,\n\tfocusVisible,\n\thstack,\n\tinlineBlock,\n\tinsBs,\n\tinsIs,\n\tis,\n\tm,\n\tmedia,\n\topacity,\n\toutline,\n\tpseudoContent,\n\tverticalAlign,\n\trelative,\n\trounded,\n\tscaleProperty,\n\tshadow,\n\tshrink,\n\ttransition,\n\ttransitionDuration,\n\twhen,\n} from \"@sdxc/u\";\nimport { attrs } from \"remix/component\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\n\n/**\n * Applied through {@link attrs} so the host always carries the platform's\n * boolean `switch` attribute, letting recognizing browsers render native\n * switch semantics while others fall back to the host's own CSS and `role=\"switch\"`.\n */\nconst DEFAULT_SWITCH_ATTRIBUTE = true;\n\n/**\n * Prop types for {@link Switch}.\n */\nexport namespace Switch {\n\t/**\n\t * Every native `<input>` attribute except `type`, `role`, and\n\t * `aria-checked` — the host fixes the first two and withholds the third\n\t * so the control's own live checkedness stays the switch's only state.\n\t */\n\texport interface Props extends Omit<TagProps<\"input\">, \"type\" | \"role\" | \"aria-checked\"> {\n\t\t/**\n\t\t * Visible label text rendered after the track, inside the same native\n\t\t * `<label>` wrapping both, so clicking either half toggles the switch\n\t\t * with no separate `htmlFor`/`id` pairing required.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n}\n\n/**\n * Renders a single `<input type=\"checkbox\" role=\"switch\">`. It carries no\n * `aria-checked` because an authored value would go stale the instant the\n * switch is flipped; the live control's own checkedness is what persists.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the switch's markup.\n * @example\n * <Switch name=\"notifications\" defaultChecked>{t(\"settings.notifications.label\")}</Switch>\n * @example\n * <Label>\n * \t{t(\"settings.notifications.label\")}\n * \t<Switch name=\"notifications\" defaultChecked />\n * </Label>\n * @example\n * <Switch aria-label={t(\"settings.darkMode\")} checked={isDark} disabled={isLocked} />\n * @example\n * <Switch aria-label={t(\"settings.notifications\")} mix={[ariaChecked()]} />\n */\nexport function Switch(handle: Handle<Switch.Props>) {\n\treturn () => {\n\t\tlet { mix, children, ...rest } = handle.props;\n\n\t\tlet track = (\n\t\t\t<input\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"checkbox\"\n\t\t\t\t// oxlint-disable-next-line jsx-a11y/role-has-required-aria-props -- The host is a native checkbox, so its own checkedness supplies the switch's checked state; see the note above for why authoring one would be worse than omitting it.\n\t\t\t\trole=\"switch\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ switch: DEFAULT_SWITCH_ATTRIBUTE }),\n\t\t\t\t\tappearance(),\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineBlock(),\n\t\t\t\t\tm(\"0\"),\n\t\t\t\t\tis(\"var(--ui-switch-track-inline-size, 2.75rem)\"),\n\t\t\t\t\tbs(\"var(--ui-switch-track-block-size, 1.5rem)\"),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tbg(\"neutral.border\"),\n\t\t\t\t\tbefore([\n\t\t\t\t\t\tabsolute(),\n\t\t\t\t\t\tis(\"var(--ui-switch-thumb-size, 1.25rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-switch-thumb-size, 1.25rem)\"),\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tbg(\"brand.onSolid\"),\n\t\t\t\t\t\ttransition(\"inset-inline-start, scale\", { duration: 150 }),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&:checked\", bg(\"brand.solid\")),\n\t\t\t\t\twhen(\"&:active\", bg(\"neutral.strong\")),\n\t\t\t\t\twhen(\"&:checked:active\", bg(\"brand.bg-solid-hover\")),\n\t\t\t\t\tfocusVisible(outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\twhen(\"&:disabled\", opacity(50)),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\ttransition(\"background-color\", { duration: durations.fast, easing: easings.standard }),\n\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\n\t\t\t\t\tverticalAlign(\"middle\"),\n\t\t\t\t\tbefore([\n\t\t\t\t\t\tpseudoContent('\"\"'),\n\t\t\t\t\t\tinsBs(\"var(--ui-switch-thumb-inset, 0.125rem)\"),\n\t\t\t\t\t\tinsIs(\"var(--ui-switch-thumb-inset, 0.125rem)\"),\n\t\t\t\t\t\tshadow(\"base\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\n\t\t\t\t\t\t\"&:checked\",\n\t\t\t\t\t\tbefore(\n\t\t\t\t\t\t\tinsIs(\n\t\t\t\t\t\t\t\t\"calc(var(--ui-switch-track-inline-size, 2.75rem) - var(--ui-switch-thumb-size, 1.25rem) - var(--ui-switch-thumb-inset, 0.125rem))\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\twhen(\"&:active\", before(scaleProperty(\"0.95\"))),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", before(transitionDuration(\"0s\"))),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\n\t\tif (children === undefined) return track;\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\tmix={[\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\twhen(\"&:has(input:disabled)\", cursor(\"not-allowed\")),\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{track}\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
},
|
|
12
|
+
"test": {
|
|
13
|
+
"path": "switch.test.tsx",
|
|
14
|
+
"content": "/**\n * Tests for {@link Switch}: covers its bare-track rendering (unchanged from\n * before `children` existed), the native `<label>` wrapping it grows once\n * `children` is passed, and that a consumer-supplied `mix` still lands on\n * the track itself in both cases.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { css } from \"remix/component\";\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Switch } from \"@sdxc/ui/switch\";\n\ndescribe(Switch.name, () => {\n\ttest(\"renders a bare input with no wrapping label when children is omitted\", async () => {\n\t\tlet html = await renderToString(<Switch name=\"notifications\" aria-label=\"Notifications\" />);\n\n\t\texpect(html).not.toContain(\"<label\");\n\t\texpect(html).toContain(\"<input\");\n\t\texpect(html).toContain('type=\"checkbox\"');\n\t\texpect(html).toContain('role=\"switch\"');\n\t});\n\n\ttest(\"wraps the track in a label alongside the visible text when children is set\", async () => {\n\t\tlet html = await renderToString(<Switch name=\"notifications\">Notifications</Switch>);\n\n\t\texpect(html).toContain(\"<label\");\n\t\texpect(html).toContain(\"<input\");\n\t\texpect(html).toContain(\"Notifications\");\n\t\texpect(html.indexOf(\"<label\")).toBeLessThan(html.indexOf(\"<input\"));\n\t});\n\n\ttest(\"keeps a consumer-supplied mix on the track when wrapped in a label\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Switch name=\"notifications\" mix={css({ color: \"red\" })}>\n\t\t\t\tNotifications\n\t\t\t</Switch>,\n\t\t);\n\n\t\texpect(html).toContain(\"color: red;\");\n\t});\n\n\t/**\n\t * Asserts no `aria-checked` is rendered: an authored value can only hold\n\t * what this render produced, so it would turn stale — and misleading —\n\t * the instant somebody flips the switch, which is the switch's whole point.\n\t */\n\tdescribe(\"checked state\", () => {\n\t\ttest(\"carries no aria-checked of its own, whichever way it is rendered\", async () => {\n\t\t\tlet on = await renderToString(<Switch name=\"notifications\" defaultChecked />);\n\t\t\tlet off = await renderToString(<Switch name=\"notifications\" />);\n\t\t\tlet controlled = await renderToString(<Switch name=\"notifications\" checked={false} />);\n\n\t\t\texpect(on).not.toContain(\"aria-checked\");\n\t\t\texpect(off).not.toContain(\"aria-checked\");\n\t\t\texpect(controlled).not.toContain(\"aria-checked\");\n\t\t});\n\n\t\ttest(\"keeps the role and the native checkedness that carries the state for it\", async () => {\n\t\t\tlet html = await renderToString(<Switch name=\"notifications\" defaultChecked />);\n\n\t\t\texpect(html).toContain('role=\"switch\"');\n\t\t\texpect(html).toContain(\"checked\");\n\t\t});\n\t});\n\n\ttest(\"disables the track and dims the label's cursor together\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Switch name=\"notifications\" disabled>\n\t\t\t\tNotifications\n\t\t\t</Switch>,\n\t\t);\n\n\t\texpect(html).toContain(\"disabled\");\n\t\texpect(html).toContain(\"cursor: not-allowed;\");\n\t});\n});\n"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "table",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Table"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "table.tsx",
|
|
10
|
+
"content": "/**\n * A tabular data display built on the native `<table>` element, with column\n * headers that become sort links and a trailing row that becomes a\n * \"load more\" link — both driven entirely by URLs a consumer computes, so the\n * sorted or paginated result renders back from the server with no client\n * state to track.\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 { ArrowDownIcon, ArrowUpDownIcon, ArrowUpIcon } from \"@sdxc/icons\";\nimport {\n\tbg,\n\tborderEdge,\n\tcenter,\n\tcontainer,\n\tcursor,\n\tfg,\n\tflex,\n\tfontSize,\n\tgap,\n\thover,\n\tis,\n\titems,\n\tjustify,\n\topacity,\n\toutline,\n\toverflow,\n\tp,\n\tpb,\n\tpi,\n\traw,\n\trelative,\n\tshrink,\n\ttabularNums,\n\ttextAlign,\n\ttextDecoration,\n\tuserSelect,\n\tvirtualize,\n\tweight,\n\twhen,\n} from \"@sdxc/u\";\nimport { attrs } from \"remix/component\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\n/**\n * Named container {@link Table.Container} declares on its own host, so a\n * consumer's own descendant styles can query the wrapper's width instead of\n * the page's.\n */\nconst CONTAINER_NAME = \"ui-table\";\n\n/** Text alignment {@link Table.Column} falls back to when `align` is omitted. */\nconst DEFAULT_ALIGN: Table.Align = \"start\";\n\n/**\n * Text alignment a `numeric` {@link Table.Column} falls back to when `align` is\n * omitted, lining its header up with the end-aligned figures beneath it.\n */\nconst DEFAULT_NUMERIC_ALIGN: Table.Align = \"end\";\n\n/**\n * Flex alignment a sortable header's link takes for each column alignment, so the\n * link fills the whole cell and still places its label where `align` puts it.\n */\nconst JUSTIFY_BY_ALIGN = { start: \"start\", center: \"center\", end: \"end\" } as const;\n\n/**\n * Prop types for {@link Table} and its compound parts.\n */\nexport namespace Table {\n\t/**\n\t * Text alignment for a column's header and, by convention, its cells.\n\t * `\"start\"`/`\"end\"` follow the writing direction, so a column stays\n\t * left- or right-aligned correctly under `dir=\"rtl\"`.\n\t */\n\texport type Align = \"start\" | \"center\" | \"end\";\n\n\t/**\n\t * Current sort direction for a sortable column, matching the values the\n\t * native `aria-sort` attribute accepts. Leaving it unset while `href` is\n\t * set renders the column as sortable but not the active sort key.\n\t */\n\texport type SortDirection = \"ascending\" | \"descending\";\n\n\t/**\n\t * Every native `<table>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface Props extends TagProps<\"table\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ContainerProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<thead>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderProps extends TagProps<\"thead\"> {}\n\n\t/**\n\t * Every native `<tbody>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface BodyProps extends TagProps<\"tbody\"> {}\n\n\t/**\n\t * Per-part styling for the elements a sortable {@link Table.Column} renders\n\t * besides its own `<th>` host.\n\t */\n\texport interface ColumnPartsProps {\n\t\t/** Styling for the header's inner link, rendered only when `href` is set. */\n\t\tlink?: TagProps<\"a\">[\"mix\"];\n\t}\n\n\t/**\n\t * Every native `<th>` attribute, plus the `mix` passthrough. Setting\n\t * `href` turns the header into a sort link exposing `aria-sort`; `align`\n\t * shadows the deprecated native `align` with the logical values above.\n\t */\n\texport interface ColumnProps extends Omit<TagProps<\"th\">, \"align\"> {\n\t\t/**\n\t\t * Text alignment for the header and its indicator. Defaults to {@link DEFAULT_ALIGN},\n\t\t * or {@link DEFAULT_NUMERIC_ALIGN} for a `numeric` column.\n\t\t */\n\t\talign?: Align;\n\t\t/**\n\t\t * Marks the column as holding numbers, exposed as `data-numeric`: the header aligns\n\t\t * to the end unless `align` says otherwise, matching `numeric` cells beneath it.\n\t\t */\n\t\tnumeric?: boolean;\n\t\t/** Target URL that re-requests the table sorted by this column. Omit for an unsortable column. */\n\t\thref?: string;\n\t\t/** This column's current sort direction, when it's the active sort key. */\n\t\tsortDirection?: SortDirection;\n\t\t/** Per-part styling for the sortable header's internal elements. */\n\t\tparts?: ColumnPartsProps;\n\t}\n\n\t/**\n\t * Every native `<tr>` attribute, unchanged, plus the `mix` passthrough.\n\t * Set `aria-selected=\"true\"` directly to mark a row selected — the row's\n\t * own selection tint rides that native attribute.\n\t */\n\texport interface RowProps extends TagProps<\"tr\"> {}\n\n\t/**\n\t * Every native `<td>` attribute plus the `mix` passthrough and `numeric`.\n\t */\n\texport interface CellProps extends TagProps<\"td\"> {\n\t\t/**\n\t\t * Marks the cell as a number, exposed as `data-numeric`: its figures render at\n\t\t * tabular widths and align to the end, so digits line up down the column.\n\t\t */\n\t\tnumeric?: boolean;\n\t}\n\n\t/**\n\t * Per-part styling for the elements {@link Table.LoadMore} renders besides\n\t * its own `<tr>` host.\n\t */\n\texport interface LoadMorePartsProps {\n\t\t/** Styling for the `<td>` spanning the row beneath the link. */\n\t\tcell?: TagProps<\"td\">[\"mix\"];\n\t\t/** Styling for the link itself. */\n\t\tlink?: TagProps<\"a\">[\"mix\"];\n\t}\n\n\t/**\n\t * Every native `<tr>` attribute, plus the `mix` passthrough. `colSpan`\n\t * should match the number of columns the surrounding table renders so\n\t * the link spans the full row width.\n\t */\n\texport interface LoadMoreProps extends TagProps<\"tr\"> {\n\t\t/** Target URL that renders the next page of results. */\n\t\thref: string;\n\t\t/** Number of columns the surrounding table renders, so the link spans the full row width. */\n\t\tcolSpan: number;\n\t\t/** The link's visible label, e.g. \"Load more\" or \"Next page\". */\n\t\tchildren: RemixNode;\n\t\t/** Per-part styling for the row's internal cell and link. */\n\t\tparts?: LoadMorePartsProps;\n\t}\n}\n\n/**\n * Renders the table's `<table>` host: a full-width, border-collapsed grid\n * with a small base font size, ready to hold {@link Table.Header} and\n * {@link Table.Body}. Dev mode warns when it lacks an accessible name.\n *\n * @param handle Runtime handle carrying the host `<table>`'s props.\n * @returns The render function producing the table's markup.\n * @example\n * <Table aria-label={t(\"subjects.title\")}>\n * \t<Table.Header>\n * \t\t<Table.Row>\n * \t\t\t<Table.Column>{t(\"subjects.name\")}</Table.Column>\n * \t\t</Table.Row>\n * \t</Table.Header>\n * \t<Table.Body>\n * \t\t<Table.Row>\n * \t\t\t<Table.Cell>{subject.name}</Table.Cell>\n * \t\t</Table.Row>\n * \t</Table.Body>\n * </Table>\n */\nexport function Table(handle: Handle<Table.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Table: needs an \"aria-label\" or \"aria-labelledby\" describing its contents for assistive technology.',\n\t\t);\n\n\t\treturn (\n\t\t\t<table\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"table\"\n\t\t\t\tmix={[is(\"100%\"), raw({ borderCollapse: \"collapse\" }), fontSize(\"sm\"), mix]}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders an optional wrapper around {@link Table}: a relatively positioned\n * `<div>` that scrolls its own inline axis when the table grows wider than\n * the available space, and declares the `ui-table` named container.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Table.Container>\n * \t<Table aria-label={t(\"subjects.title\")}>...</Table>\n * </Table.Container>\n */\nTable.Container = function TableContainer(handle: Handle<Table.ContainerProps>) {\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\tdata-slot=\"container\"\n\t\t\t\tmix={[relative(), is(\"100%\"), overflow(\"auto\"), container(CONTAINER_NAME), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the table's `<thead>` host: a plain wrapper for the header\n * {@link Table.Row}, separated from {@link Table.Body} by a block-end border.\n *\n * @param handle Runtime handle carrying the host `<thead>`'s props.\n * @returns The render function producing the header section's markup.\n * @example\n * <Table.Header>\n * \t<Table.Row>\n * \t\t<Table.Column>{t(\"subjects.name\")}</Table.Column>\n * \t</Table.Row>\n * </Table.Header>\n */\nTable.Header = function TableHeader(handle: Handle<Table.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<thead\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header\"\n\t\t\t\tmix={[borderEdge(\"block-end\", { color: \"neutral\", width: 1 }), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the table's `<tbody>` host: a block-start border rules the space\n * between direct row children, and `content-visibility: auto` lets a long\n * body's off-screen rows skip layout and paint until they scroll into view.\n *\n * @param handle Runtime handle carrying the host `<tbody>`'s props.\n * @returns The render function producing the body section's markup.\n * @example\n * <Table.Body>\n * \t{subjects.map((subject) => (\n * \t\t<Table.Row key={subject.id}>\n * \t\t\t<Table.Cell>{subject.name}</Table.Cell>\n * \t\t</Table.Row>\n * \t))}\n * </Table.Body>\n */\nTable.Body = function TableBody(handle: Handle<Table.BodyProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<tbody\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"body\"\n\t\t\t\tmix={[\n\t\t\t\t\tvirtualize(\"auto var(--ui-table-body-intrinsic-size, 32rem)\"),\n\t\t\t\t\twhen(\n\t\t\t\t\t\t\"& > :not([hidden]) ~ :not([hidden])\",\n\t\t\t\t\t\tborderEdge(\"block-start\", { color: \"neutral\", width: 1 }),\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 column header inside a native `<th scope=\"col\">`, aligned by `data-align`.\n * Setting `href` makes the header a cell-filling sort link with `aria-sort` and a direction\n * indicator held square, so a header narrow enough to squeeze the link keeps both arrows legible.\n *\n * @param handle Runtime handle carrying the host `<th>`'s props.\n * @returns The render function producing the column header's markup.\n * @example\n * <Table.Column>{t(\"subjects.email\")}</Table.Column>\n * @example\n * <Table.Column numeric>{t(\"invoices.amount\")}</Table.Column>\n * @example\n * <Table.Column href={sortUrl(\"name\", nextDirection)} sortDirection={activeSort === \"name\" ? currentDirection : undefined}>\n * \t{t(\"subjects.name\")}\n * </Table.Column>\n */\nTable.Column = function TableColumn(handle: Handle<Table.ColumnProps>) {\n\treturn () => {\n\t\tlet { align, numeric, href, sortDirection, parts, children, mix, ...rest } = handle.props;\n\t\tlet resolvedAlign = align ?? (numeric ? DEFAULT_NUMERIC_ALIGN : DEFAULT_ALIGN);\n\n\t\treturn (\n\t\t\t<th\n\t\t\t\t{...rest}\n\t\t\t\tdata-align={resolvedAlign}\n\t\t\t\tdata-numeric={numeric ? \"\" : undefined}\n\t\t\t\taria-sort={href ? (sortDirection ?? \"none\") : undefined}\n\t\t\t\tdata-slot=\"column\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ scope: \"col\" }),\n\t\t\t\t\thref ? undefined : [pi(\"1rem\"), pb(\"0.75rem\")],\n\t\t\t\t\ttextAlign(\"start\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen('&[data-align=\"center\"]', textAlign(\"center\")),\n\t\t\t\t\twhen('&[data-align=\"end\"]', textAlign(\"end\")),\n\t\t\t\t\twhen(\"&[aria-sort]\", when(\"&:hover\", bg(\"neutral.tint\"))),\n\t\t\t\t\twhen(\"&[aria-sort]\", [cursor(\"pointer\"), userSelect()]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{href ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href}\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: -2 })),\n\t\t\t\t\t\t\tflex(),\n\t\t\t\t\t\t\tjustify(JUSTIFY_BY_ALIGN[resolvedAlign]),\n\t\t\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\t\t\tpb(\"0.75rem\"),\n\t\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\t\tgap(\"0.25rem\"),\n\t\t\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\t\t\thover(textDecoration(\"underline\")),\n\t\t\t\t\t\t\tparts?.link,\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t\t{sortDirection === \"ascending\" && <ArrowUpIcon size={14} mix={[shrink()]} />}\n\t\t\t\t\t\t{sortDirection === \"descending\" && <ArrowDownIcon size={14} mix={[shrink()]} />}\n\t\t\t\t\t\t{!sortDirection && <ArrowUpDownIcon size={14} mix={[shrink(), opacity(40)]} />}\n\t\t\t\t\t</a>\n\t\t\t\t) : (\n\t\t\t\t\tchildren\n\t\t\t\t)}\n\t\t\t</th>\n\t\t);\n\t};\n};\n\n/**\n * Renders a native `<tr>` host: transitions its background smoothly, tints\n * it on hover, and tints it more strongly when it carries\n * `aria-selected=\"true\"`, set directly since selection state is native.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Table.Row>\n * \t<Table.Cell>{subject.name}</Table.Cell>\n * </Table.Row>\n * @example\n * <Table.Row aria-selected=\"true\">\n * \t<Table.Cell>{subject.name}</Table.Cell>\n * </Table.Row>\n */\nTable.Row = function TableRow(handle: Handle<Table.RowProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<tr\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"row\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\thover(bg(\"neutral.tint\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', bg(\"brand.tint\")),\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 native `<td>` host, padded on every side and colored as the\n * table's emphasized foreground text; a `numeric` cell end-aligns tabular figures.\n *\n * @param handle Runtime handle carrying the host `<td>`'s props.\n * @returns The render function producing the cell's markup.\n * @example\n * <Table.Cell>{subject.name}</Table.Cell>\n * @example\n * <Table.Cell numeric>{formatCurrency(invoice.amount)}</Table.Cell>\n */\nTable.Cell = function TableCell(handle: Handle<Table.CellProps>) {\n\treturn () => {\n\t\tlet { numeric, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<td\n\t\t\t\t{...rest}\n\t\t\t\tdata-numeric={numeric ? \"\" : undefined}\n\t\t\t\tdata-slot=\"cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\tpb(\"0.75rem\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\twhen(\"&[data-numeric]\", [tabularNums(), textAlign(\"end\")]),\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 trailing row carrying a single link that spans every column,\n * standing in for an auto-loading \"next page\" trigger since fetching more\n * rows without a full navigation requires script a consumer attaches.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Table.LoadMore href={nextPageUrl} colSpan={4}>\n * \t{t(\"subjects.loadMore\")}\n * </Table.LoadMore>\n */\nTable.LoadMore = function TableLoadMore(handle: Handle<Table.LoadMoreProps>) {\n\treturn () => {\n\t\tlet { href, colSpan, parts, children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<tr {...rest} data-slot=\"load-more\" mix={[mix]}>\n\t\t\t\t<td colSpan={colSpan} mix={[p(\"0\"), parts?.cell]}>\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href}\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\t\tcenter(),\n\t\t\t\t\t\t\tpb(\"1rem\"),\n\t\t\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\t\t\thover(fg(\"neutral\")),\n\t\t\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\t\t\tparts?.link,\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{children}\n\t\t\t\t\t</a>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t);\n\t};\n};\n"
|
|
11
|
+
},
|
|
12
|
+
"test": {
|
|
13
|
+
"path": "table.test.tsx",
|
|
14
|
+
"content": "/**\n * Tests for {@link Table}'s numeric opt-in and sortable headers, asserted over\n * `renderToString` output: numeric cells line their digits up down a column, and\n * a sort link fills its header cell so the whole cell answers a click.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Table } from \"@sdxc/ui/table\";\n\ndescribe(\"Table.Cell\", () => {\n\ttest(\"marks a numeric cell and sets it in end-aligned tabular figures\", async () => {\n\t\tlet html = String(await renderToString(<Table.Cell numeric>1,240</Table.Cell>));\n\n\t\texpect(html).toMatch(/<td[^>]*data-numeric=\"\"/);\n\t\texpect(html).toContain(\"font-variant-numeric: tabular-nums\");\n\t\texpect(html).toContain(\"text-align: end\");\n\t});\n\n\ttest(\"leaves a plain cell unmarked\", async () => {\n\t\tlet html = String(await renderToString(<Table.Cell>Ada</Table.Cell>));\n\n\t\texpect(html).not.toMatch(/<td[^>]*data-numeric/);\n\t});\n});\n\ndescribe(\"Table.Column\", () => {\n\ttest(\"end-aligns a numeric column unless align says otherwise\", async () => {\n\t\tlet numeric = String(await renderToString(<Table.Column numeric>Amount</Table.Column>));\n\t\tlet centered = String(\n\t\t\tawait renderToString(\n\t\t\t\t<Table.Column numeric align=\"center\">\n\t\t\t\t\tAmount\n\t\t\t\t</Table.Column>,\n\t\t\t),\n\t\t);\n\n\t\texpect(numeric).toMatch(/<th[^>]*data-align=\"end\"/);\n\t\texpect(numeric).toMatch(/<th[^>]*data-numeric=\"\"/);\n\t\texpect(centered).toMatch(/<th[^>]*data-align=\"center\"/);\n\t});\n\n\ttest(\"moves a sortable header's padding onto its link, so the whole cell is the target\", async () => {\n\t\tlet html = String(\n\t\t\tawait renderToString(\n\t\t\t\t<Table.Column href=\"?sort=name\" sortDirection=\"ascending\">\n\t\t\t\t\tName\n\t\t\t\t</Table.Column>,\n\t\t\t),\n\t\t);\n\n\t\tlet [, thClasses] = html.match(/<th[^>]*class=\"([^\"]*)\"/) ?? [];\n\t\tlet [, linkClasses] = html.match(/<a[^>]*class=\"([^\"]*)\"/) ?? [];\n\t\tlet paddingClass = html.match(/\\.(rmxc-[\\w-]+) \\{\\s*padding-inline: 1rem;/)?.[1];\n\n\t\texpect(paddingClass).toBeDefined();\n\t\texpect(linkClasses?.split(\" \")).toContain(paddingClass);\n\t\texpect(thClasses?.split(\" \")).not.toContain(paddingClass);\n\t});\n});\n"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tabs",
|
|
3
|
+
"changedIn": "2026.10.2",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Tabs",
|
|
7
|
+
"tabIndicatorMix"
|
|
8
|
+
],
|
|
9
|
+
"source": {
|
|
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"
|
|
12
|
+
},
|
|
13
|
+
"test": {
|
|
14
|
+
"path": "tabs.test.tsx",
|
|
15
|
+
"content": "/**\n * Tests for {@link Tabs}'s compound parts, focused on {@link Tabs.List}'s\n * sliding indicator: {@link tabIndicatorMix} covers the offset/length/opacity\n * math directly (pure `raw()` output, no DOM), and the `renderToString`\n * suites confirm it's wired into `Tabs.List` correctly, that omitting\n * `activeIndex`/`tabSize` leaves the pre-existing client-measured behavior\n * untouched, and that {@link Tabs.Tab} still renders as a real `<a>` with a\n * manually-set `aria-selected`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { CSSMixinDescriptor } from \"remix/component\";\n\nimport { css } from \"remix/component\";\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Tabs, tabIndicatorMix } from \"@sdxc/ui/tabs\";\n\n/** Unwraps a `raw()`/`css()` mixin descriptor back to the style object it was built from. */\nfunction styles(mixin: CSSMixinDescriptor): Record<string, unknown> {\n\treturn mixin.args[0] as Record<string, unknown>;\n}\n\ndescribe(tabIndicatorMix.name, () => {\n\ttest(\"computes the inline-axis offset/length/opacity for a fixed pixel tab size\", () => {\n\t\texpect(styles(tabIndicatorMix(\"horizontal\", 2, \"110px\"))).toEqual({\n\t\t\t\"--ui-tab-indicator-inline-start\": \"calc((110px + calc(var(--ui-spacing, 0.25rem) * 1)) * 2)\",\n\t\t\t\"--ui-tab-indicator-inline-size\": \"110px\",\n\t\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t\t});\n\t});\n\n\ttest(\"computes the block-axis custom properties instead when orientation is vertical\", () => {\n\t\texpect(styles(tabIndicatorMix(\"vertical\", 1, \"80px\"))).toEqual({\n\t\t\t\"--ui-tab-indicator-block-start\": \"calc((80px + calc(var(--ui-spacing, 0.25rem) * 1)) * 1)\",\n\t\t\t\"--ui-tab-indicator-block-size\": \"80px\",\n\t\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t\t});\n\t});\n\n\ttest(\"resolves a spacing-scale number tabSize the same way every other sizing prop does\", () => {\n\t\texpect(styles(tabIndicatorMix(\"horizontal\", 1, 4))).toEqual({\n\t\t\t\"--ui-tab-indicator-inline-start\":\n\t\t\t\t\"calc((calc(var(--ui-spacing, 0.25rem) * 4) + calc(var(--ui-spacing, 0.25rem) * 1)) * 1)\",\n\t\t\t\"--ui-tab-indicator-inline-size\": \"calc(var(--ui-spacing, 0.25rem) * 4)\",\n\t\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t\t});\n\t});\n\n\ttest(\"treats an explicit activeIndex of 0 as a real offset, not a no-op\", () => {\n\t\texpect(styles(tabIndicatorMix(\"horizontal\", 0, \"110px\"))).toEqual({\n\t\t\t\"--ui-tab-indicator-inline-start\": \"calc((110px + calc(var(--ui-spacing, 0.25rem) * 1)) * 0)\",\n\t\t\t\"--ui-tab-indicator-inline-size\": \"110px\",\n\t\t\t\"--ui-tab-indicator-opacity\": \"1\",\n\t\t});\n\t});\n\n\ttest(\"returns a fresh mixin descriptor on every call\", () => {\n\t\texpect(tabIndicatorMix(\"horizontal\", 1, \"110px\")).not.toBe(\n\t\t\ttabIndicatorMix(\"horizontal\", 1, \"110px\"),\n\t\t);\n\t});\n});\n\ndescribe(Tabs.List.name, () => {\n\ttest(\"leaves the indicator at its default resting fallback when activeIndex/tabSize are omitted\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs>\n\t\t\t\t<Tabs.List aria-label=\"Sections\">\n\t\t\t\t\t<Tabs.Tab href=\"/a\" aria-selected=\"true\">\n\t\t\t\t\t\tA\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t<Tabs.Tab href=\"/b\" aria-selected=\"false\">\n\t\t\t\t\t\tB\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t</Tabs.List>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).toContain(\"var(--ui-tab-indicator-inline-size, 0px)\");\n\t\texpect(html).toContain(\"var(--ui-tab-indicator-inline-start, 0px)\");\n\t\texpect(html).toContain(\"var(--ui-tab-indicator-opacity, 0)\");\n\t\texpect(html).not.toContain(\"--ui-tab-indicator-inline-start: calc(\");\n\t\texpect(html).not.toContain(\"--ui-tab-indicator-inline-size: \");\n\t\texpect(html).not.toContain(\"--ui-tab-indicator-opacity: 1;\");\n\t});\n\n\ttest(\"computes and sets the three inline-axis custom properties when both activeIndex and tabSize are given\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs>\n\t\t\t\t<Tabs.List aria-label=\"Sections\" activeIndex={1} tabSize=\"110px\">\n\t\t\t\t\t<Tabs.Tab href=\"/a\" aria-selected=\"false\">\n\t\t\t\t\t\tA\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t<Tabs.Tab href=\"/b\" aria-selected=\"true\">\n\t\t\t\t\t\tB\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t</Tabs.List>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).toContain(\n\t\t\t\"--ui-tab-indicator-inline-start: calc((110px + calc(var(--ui-spacing, 0.25rem) * 1)) * 1);\",\n\t\t);\n\t\texpect(html).toContain(\"--ui-tab-indicator-inline-size: 110px;\");\n\t\texpect(html).toContain(\"--ui-tab-indicator-opacity: 1;\");\n\t});\n\n\ttest(\"computes the block-axis custom properties instead for a vertical Tabs root\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs orientation=\"vertical\">\n\t\t\t\t<Tabs.List aria-label=\"Sections\" activeIndex={2} tabSize=\"80px\">\n\t\t\t\t\t<Tabs.Tab href=\"/a\" aria-selected=\"false\">\n\t\t\t\t\t\tA\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t<Tabs.Tab href=\"/b\" aria-selected=\"false\">\n\t\t\t\t\t\tB\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t\t<Tabs.Tab href=\"/c\" aria-selected=\"true\">\n\t\t\t\t\t\tC\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t</Tabs.List>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).toContain(\n\t\t\t\"--ui-tab-indicator-block-start: calc((80px + calc(var(--ui-spacing, 0.25rem) * 1)) * 2);\",\n\t\t);\n\t\texpect(html).toContain(\"--ui-tab-indicator-block-size: 80px;\");\n\t\texpect(html).toContain(\"--ui-tab-indicator-opacity: 1;\");\n\t});\n\n\ttest.each([\n\t\t[\"activeIndex only\", { activeIndex: 1 }],\n\t\t[\"tabSize only\", { tabSize: \"110px\" }],\n\t])(\"does not override the indicator when only %s is given\", async (_label, partial) => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs>\n\t\t\t\t<Tabs.List aria-label=\"Sections\" {...partial}>\n\t\t\t\t\t<Tabs.Tab href=\"/a\" aria-selected=\"true\">\n\t\t\t\t\t\tA\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t</Tabs.List>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"--ui-tab-indicator-inline-start: calc(\");\n\t\texpect(html).not.toContain(\"--ui-tab-indicator-opacity: 1;\");\n\t});\n\n\ttest(\"still merges a consumer-supplied mix alongside the computed indicator\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs>\n\t\t\t\t<Tabs.List\n\t\t\t\t\taria-label=\"Sections\"\n\t\t\t\t\tactiveIndex={0}\n\t\t\t\t\ttabSize=\"110px\"\n\t\t\t\t\tmix={css({ color: \"red\" })}\n\t\t\t\t>\n\t\t\t\t\t<Tabs.Tab href=\"/a\" aria-selected=\"true\">\n\t\t\t\t\t\tA\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t</Tabs.List>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).toContain(\"color: red;\");\n\t\texpect(html).toContain(\"--ui-tab-indicator-opacity: 1;\");\n\t});\n\n\ttest(\"keeps role=tablist and the orientation attributes unchanged by the new props\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs>\n\t\t\t\t<Tabs.List aria-label=\"Sections\" activeIndex={0} tabSize=\"110px\">\n\t\t\t\t\t<Tabs.Tab href=\"/a\" aria-selected=\"true\">\n\t\t\t\t\t\tA\n\t\t\t\t\t</Tabs.Tab>\n\t\t\t\t</Tabs.List>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).toContain('role=\"tablist\"');\n\t\texpect(html).toContain('data-orientation=\"horizontal\"');\n\t\texpect(html).toContain('aria-orientation=\"horizontal\"');\n\t});\n});\n\ndescribe(Tabs.Tab.name, () => {\n\ttest(\"renders as a real <a> carrying the tab role and a manually-set aria-selected\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs>\n\t\t\t\t<Tabs.Tab href=\"/settings/profile\" aria-selected=\"true\">\n\t\t\t\t\tProfile\n\t\t\t\t</Tabs.Tab>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).toContain(\"<a\");\n\t\texpect(html).toContain('href=\"/settings/profile\"');\n\t\texpect(html).toContain('role=\"tab\"');\n\t\texpect(html).toContain('aria-selected=\"true\"');\n\t\texpect(html).toContain(\"Profile\");\n\t});\n\n\ttest(\"carries aria-selected=false for an inactive tab, unaffected by the indicator work\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Tabs>\n\t\t\t\t<Tabs.Tab href=\"/settings/billing\" aria-selected=\"false\">\n\t\t\t\t\tBilling\n\t\t\t\t</Tabs.Tab>\n\t\t\t</Tabs>,\n\t\t);\n\n\t\texpect(html).toContain('aria-selected=\"false\"');\n\t});\n});\n"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tag-group",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"button"
|
|
6
|
+
],
|
|
7
|
+
"exports": [
|
|
8
|
+
"TagGroup"
|
|
9
|
+
],
|
|
10
|
+
"source": {
|
|
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"
|
|
13
|
+
},
|
|
14
|
+
"test": {
|
|
15
|
+
"path": "tag-group.test.tsx",
|
|
16
|
+
"content": "/**\n * Tests for {@link TagGroup.Remove}'s footprint: it renders through Button's icon-only\n * branch, whose fixed 2.5rem row measure used to stretch a ~24px pill to a full button\n * row. The control now resizes that measure, keeping Button's invisible pointer target.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { TagGroup } from \"@sdxc/ui/tag-group\";\n\n/**\n * Server-renders one dismissible tag, styles included.\n *\n * @returns The rendered markup with every emitted `<style>` block.\n */\nasync function renderDismissibleTag(): Promise<string> {\n\treturn await renderToString(\n\t\t<TagGroup.Tag color=\"brand\">\n\t\t\tRemote\n\t\t\t<TagGroup.Remove name=\"remove\" value=\"remote\" aria-label=\"Remove remote\" />\n\t\t</TagGroup.Tag>,\n\t);\n}\n\ndescribe(\"TagGroup.Remove\", () => {\n\ttest(\"sizes the icon-only button from a custom property rather than a fixed 2.5rem row\", async () => {\n\t\tlet html = await renderDismissibleTag();\n\n\t\texpect(html).toContain(\"data-icon-only\");\n\t\texpect(html).not.toMatch(/\\sinline-size: 2\\.5rem;/);\n\t\texpect(html).not.toMatch(/\\sblock-size: 2\\.5rem;/);\n\t\texpect(html).toContain(\"--ui-button-icon-size-md: var(--ui-tag-remove-size, 1rem);\");\n\t\texpect(html).toContain(\"min-block-size: var(--ui-button-icon-size-md, 2.5rem);\");\n\t});\n\n\ttest(\"drops the padding a fixed-size glyph box has no room for\", async () => {\n\t\tlet html = await renderDismissibleTag();\n\n\t\texpect(html).toMatch(\n\t\t\t/&\\[data-icon-only\\] \\{\\s*padding: calc\\(var\\(--ui-spacing, 0\\.25rem\\) \\* 0\\);/,\n\t\t);\n\t});\n\n\ttest(\"keeps a pointer target of --ui-target-size around the shrunken glyph\", async () => {\n\t\tlet html = await renderDismissibleTag();\n\n\t\texpect(html).toMatch(\n\t\t\t/&::after \\{[^}]*position: absolute;[^}]*inline-size: var\\(--ui-target-size, 1\\.5rem\\);/,\n\t\t);\n\t});\n});\n"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "text-field",
|
|
3
|
+
"changedIn": "2026.10.2",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"description",
|
|
6
|
+
"field-error",
|
|
7
|
+
"form",
|
|
8
|
+
"input",
|
|
9
|
+
"label"
|
|
10
|
+
],
|
|
11
|
+
"exports": [
|
|
12
|
+
"TextField"
|
|
13
|
+
],
|
|
14
|
+
"source": {
|
|
15
|
+
"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 type PartsProps = FieldPartsProps;\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\"> {\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 `<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\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\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\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"text-field\" mix={[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={resolvedType as never}\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\tplaceholder={placeholder}\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\tpattern={pattern}\n\t\t\t\t\tminLength={minLength}\n\t\t\t\t\tmaxLength={maxLength}\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={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
|
+
},
|
|
18
|
+
"test": null
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "text",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Text"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
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]} />;\n\t};\n}\n"
|
|
11
|
+
},
|
|
12
|
+
"test": null
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "textarea",
|
|
3
|
+
"changedIn": "2026.10.2",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"TextArea"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
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]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
|
+
},
|
|
12
|
+
"test": null
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "time-field",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"description",
|
|
6
|
+
"field-error",
|
|
7
|
+
"form",
|
|
8
|
+
"input",
|
|
9
|
+
"label"
|
|
10
|
+
],
|
|
11
|
+
"exports": [
|
|
12
|
+
"TimeField"
|
|
13
|
+
],
|
|
14
|
+
"source": {
|
|
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={[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
|
+
},
|
|
18
|
+
"test": null
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toast",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Toast"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "toast.tsx",
|
|
10
|
+
"content": "/**\n * A transient notification panel that floats above page content to report\n * the outcome of an action, colored by one of five semantic tones and\n * structured like an inline status panel: an optional leading icon or\n * loading graphic, a title/description block, and trailing actions.\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 { XIcon } from \"@sdxc/icons\";\nimport { bg, border, colorMix, fg } from \"@sdxc/u/color\";\nimport { backdropBlur, backdropSaturate, rounded, shadow, transition } from \"@sdxc/u/effects\";\nimport { pointerEvents, raw } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tbasis,\n\tfixed,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\tinlineFlex,\n\tinsBe,\n\tinsBs,\n\tinsIe,\n\tinsIs,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { media, supports } from \"@sdxc/u/responsive\";\nimport { is, bs, maxIs, minIs, pb, pi, pie } from \"@sdxc/u/size\";\nimport { active, data, hover, when } from \"@sdxc/u/state\";\nimport { translateX } from \"@sdxc/u/transform\";\nimport { balance, fontSize, leading, pretty, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { graphicHostStyle } from \"@sdxc/ui/styles\";\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\n/**\n * `role` applied to {@link Toast} through {@link attrs} unless a consumer\n * supplies its own, announcing the panel as a status update that assistive\n * technology reads after finishing whatever it is currently reading.\n */\nconst DEFAULT_ROLE = \"status\";\n\n/**\n * Default {@link Toast.Props.color}, rendering a toast with the neutral tone\n * when a consumer names no semantic color.\n */\nconst DEFAULT_COLOR: Toast.Color = \"neutral\";\n\n/**\n * Default {@link Toast.Props.live}, announcing a toast's content politely so\n * each toast waits its turn behind whatever assistive technology is\n * currently reading.\n */\nconst DEFAULT_LIVE: Toast.Live = \"polite\";\n\n/**\n * `aria-atomic=\"true\"` applied through {@link attrs} unless a consumer\n * overrides it, so assistive technology re-reads the whole toast whenever\n * any part of it updates.\n */\nconst DEFAULT_ARIA_ATOMIC = \"true\";\n\n/**\n * `aria-hidden=\"true\"` applied to {@link Toast.Icon} and {@link Toast.Loader}\n * through {@link attrs} unless a consumer overrides it, keeping a purely\n * decorative graphic out of the accessibility tree.\n */\nconst DEFAULT_GRAPHIC_ARIA_HIDDEN = \"true\";\n\n/**\n * `type=\"button\"` default applied to {@link Toast.Action} and\n * {@link Toast.Cancel}, matching the script-driven command most toast\n * actions run; pass `type=\"submit\"` for a form control.\n */\nconst DEFAULT_BUTTON_TYPE: NonNullable<Toast.ActionProps[\"type\"]> = \"button\";\n\n/**\n * Corner {@link Toast.Region} renders in when `placement` is left unset.\n */\nconst DEFAULT_PLACEMENT: Toast.Placement = \"bottom-end\";\n\n/**\n * `role` applied to {@link Toast.Region} through {@link attrs} unless a\n * consumer supplies its own, exposing the stack of toasts as a landmark\n * region.\n */\nconst DEFAULT_REGION_ROLE = \"region\";\n\n/**\n * Prop types for {@link Toast} and its compound parts, including\n * {@link Toast.Region}.\n */\nexport namespace Toast {\n\t/**\n\t * Semantic tone driving the host element's border, tint, and foreground\n\t * color through the `--ui-*` variables for that color.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * `aria-live` politeness applied to the host element. `\"off\"` omits the\n\t * `aria-live` attribute entirely, leaving the element's implicit\n\t * live-region behavior in place.\n\t */\n\texport type Live = \"polite\" | \"assertive\" | \"off\";\n\n\t/**\n\t * Corner of the viewport {@link Toast.Region} renders in. The block side\n\t * (`top`/`bottom`) names a physical edge, while the inline edge\n\t * (`start`/`end`) flips under `dir` to stay in the reading-trailing corner.\n\t */\n\texport type Placement =\n\t\t| \"top-start\"\n\t\t| \"top-center\"\n\t\t| \"top-end\"\n\t\t| \"bottom-start\"\n\t\t| \"bottom-center\"\n\t\t| \"bottom-end\";\n\n\t/**\n\t * Props accepted by {@link Toast}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic tone of the toast. Default: `\"neutral\"`. */\n\t\tcolor?: Color;\n\t\t/** `aria-live` politeness for the toast's content. Default: `\"polite\"`. */\n\t\tlive?: Live;\n\t\t/** The toast's compound parts: {@link Toast.Icon}, {@link Toast.Content}, {@link Toast.Action}, or any other content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Icon}.\n\t */\n\texport interface IconProps extends TagProps<\"div\"> {\n\t\t/** The icon graphic, typically a single SVG icon. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Loader}.\n\t */\n\texport interface LoaderProps extends TagProps<\"div\"> {\n\t\t/** The loading graphic shown in place of {@link Toast.Icon} while the toast represents pending work. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** The toast's title, description, or other body content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"h3\"> {\n\t\t/** The toast's heading text. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** The toast's supporting message text. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Action}.\n\t */\n\texport interface ActionProps extends TagProps<\"button\"> {\n\t\t/** The action's label. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Cancel}.\n\t */\n\texport interface CancelProps extends TagProps<\"button\"> {\n\t\t/** The cancel control's label. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Toast.Close}.\n\t */\n\texport interface CloseProps extends TagProps<\"button\"> {\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\t/**\n\t * Props accepted by {@link Toast.Region}.\n\t */\n\texport interface RegionProps extends TagProps<\"div\"> {\n\t\t/** Corner of the viewport the stack renders in. Default: `\"bottom-end\"`. */\n\t\tplacement?: Placement;\n\t\t/** Every currently queued {@link Toast}. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Renders a single toast panel, tinted, bordered, and shadowed by\n * {@link Toast.Props.color}, with `role` and `aria-atomic` defaulted\n * (overridable); pair a `mix`-driven `enterExit()`, since it holds still.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the toast's markup.\n * @example\n * <Toast color=\"success\">\n * <Toast.Icon><CircleCheckIcon /></Toast.Icon>\n * <Toast.Content>\n * <Toast.Title>{t(\"toasts.saved.title\")}</Toast.Title>\n * <Toast.Description>{t(\"toasts.saved.description\")}</Toast.Description>\n * </Toast.Content>\n * <Toast.Close aria-label={t(\"actions.dismiss\")} />\n * </Toast>\n * @example\n * <Toast color=\"danger\" live=\"assertive\">\n * <Toast.Content>\n * <Toast.Title>{t(\"toasts.uploadFailed.title\")}</Toast.Title>\n * </Toast.Content>\n * <Toast.Action>{t(\"actions.retry\")}</Toast.Action>\n * <Toast.Cancel>{t(\"actions.dismiss\")}</Toast.Cancel>\n * </Toast>\n */\nexport function Toast(handle: Handle<Toast.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor = DEFAULT_COLOR,\n\t\t\tlive = DEFAULT_LIVE,\n\t\t\t\"aria-live\": ariaLiveProp,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet ariaLive = ariaLiveProp ?? (live === \"off\" ? undefined : live);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\taria-live={ariaLive}\n\t\t\t\tdata-color={color}\n\t\t\t\tdata-slot=\"toast\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_ROLE, \"aria-atomic\": DEFAULT_ARIA_ATOMIC }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tflex(),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\tgap(\"0.75rem\"),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tfg(\"neutral.fg-emphasis\"),\n\t\t\t\t\tpb(\"1rem\"),\n\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\twhen('&:has(> [data-slot=\"close\"])', pie(\"2.5rem\")),\n\t\t\t\t\twhen('&[data-color=\"brand\"]', [border(\"brand\"), fg(\"brand.fg-emphasis\")]),\n\t\t\t\t\twhen('&[data-color=\"neutral\"]', [border(\"neutral\"), fg(\"neutral.fg-emphasis\")]),\n\t\t\t\t\twhen('&[data-color=\"success\"]', [border(\"success\"), fg(\"success.fg-emphasis\")]),\n\t\t\t\t\twhen('&[data-color=\"warning\"]', [border(\"warning\"), fg(\"warning.fg-emphasis\")]),\n\t\t\t\t\twhen('&[data-color=\"danger\"]', [border(\"danger\"), fg(\"danger.fg-emphasis\")]),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tshadow(\"lg\"),\n\t\t\t\t\titems(\"start\"),\n\t\t\t\t\tpointerEvents(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\t\"--ui-toast-bg\": \"var(--ui-neutral-bg-tint)\",\n\t\t\t\t\t\tbackgroundColor: \"var(--ui-toast-bg)\",\n\t\t\t\t\t}),\n\t\t\t\t\tdata(\n\t\t\t\t\t\t\"color\",\n\t\t\t\t\t\t\"brand\",\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-toast-bg\": \"var(--ui-brand-bg-tint)\",\n\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-toast-bg)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\tdata(\n\t\t\t\t\t\t\"color\",\n\t\t\t\t\t\t\"neutral\",\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-toast-bg\": \"var(--ui-neutral-bg-tint)\",\n\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-toast-bg)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\tdata(\n\t\t\t\t\t\t\"color\",\n\t\t\t\t\t\t\"success\",\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-toast-bg\": \"var(--ui-success-bg-tint)\",\n\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-toast-bg)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\tdata(\n\t\t\t\t\t\t\"color\",\n\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-toast-bg\": \"var(--ui-warning-bg-tint)\",\n\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-toast-bg)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\tdata(\n\t\t\t\t\t\t\"color\",\n\t\t\t\t\t\t\"danger\",\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-toast-bg\": \"var(--ui-danger-bg-tint)\",\n\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-toast-bg)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\tsupports(\n\t\t\t\t\t\t\"(backdrop-filter: blur(0))\",\n\t\t\t\t\t\tmedia(\"(prefers-reduced-transparency: no-preference)\", [\n\t\t\t\t\t\t\tbg(colorMix(\"oklab\", { color: \"var(--ui-toast-bg)\", weight: 85 }, \"transparent\")),\n\t\t\t\t\t\t\tbackdropBlur(\"md\"),\n\t\t\t\t\t\t\tbackdropSaturate(1.4),\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Toast.IconProps.children} as the toast's leading icon,\n * hidden from assistive technology since the toast's color and text already\n * carry its meaning; swap in {@link Toast.Loader} while pending.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the icon's markup.\n */\nToast.Icon = function ToastIcon(handle: Handle<Toast.IconProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"icon\"\n\t\t\t\tmix={[attrs({ \"aria-hidden\": DEFAULT_GRAPHIC_ARIA_HIDDEN }), graphicHostStyle(), mix]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Toast.LoaderProps.children} as the toast's loading graphic,\n * laid out identically to {@link Toast.Icon} so swapping between them keeps\n * the layout stable; pair a `spin()` `mix` factory for its rotating loop.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the loading graphic's markup.\n */\nToast.Loader = function ToastLoader(handle: Handle<Toast.LoaderProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"loader\"\n\t\t\t\tmix={[attrs({ \"aria-hidden\": DEFAULT_GRAPHIC_ARIA_HIDDEN }), graphicHostStyle(), mix]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Toast.ContentProps.children} as the toast's body block: a\n * column flex container that shrinks to fit alongside a leading icon or\n * trailing action, holding {@link Toast.Title} and {@link Toast.Description}.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the content block's markup.\n */\nToast.Content = function ToastContent(handle: Handle<Toast.ContentProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"content\"\n\t\t\t\tmix={[flex(), flexCol(), gap(\"0.25rem\"), minIs(0), grow(), shrink(1), basis(\"0%\"), mix]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Toast.TitleProps.children} as the toast's heading, in a\n * native `<h3>` sized and weighted as a small, single-line label above the\n * toast's description.\n *\n * @param handle Runtime handle carrying the host `<h3>`'s props.\n * @returns The render function producing the title's markup.\n */\nToast.Title = function ToastTitle(handle: Handle<Toast.TitleProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<h3\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[weight(500), leading(1), fontSize(\"sm\"), balance(), mix]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Toast.DescriptionProps.children} as the toast's supporting\n * message, in a native `<p>` set slightly translucent against the toast's\n * foreground color so it reads as secondary to {@link Toast.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n */\nToast.Description = function ToastDescription(handle: Handle<Toast.DescriptionProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"description\"\n\t\t\t\tmix={[\n\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\tpretty(),\n\t\t\t\t\tfg(colorMix(\"oklab\", { color: \"currentcolor\", weight: 70 }, \"transparent\")),\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</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Toast.ActionProps.children} as the toast's primary trailing\n * control; `type` defaults to `\"button\"`, ordered before the consumer's\n * attributes so `command`/`commandfor` still run; use `type=\"submit\"` for a form.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the action control's markup.\n * @example\n * <Toast.Action>{t(\"actions.undo\")}</Toast.Action>\n */\nToast.Action = function ToastAction(handle: Handle<Toast.ActionProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_BUTTON_TYPE;\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[\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\trounded(\"md\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\tpb(\"0.25rem\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tshrink(),\n\t\t\t\t\ttransition(\n\t\t\t\t\t\t\"color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter\",\n\t\t\t\t\t),\n\t\t\t\t\tfg(\"currentcolor\"),\n\t\t\t\t\tborder(colorMix(\"oklab\", { color: \"currentcolor\", weight: 30 }, \"transparent\")),\n\t\t\t\t\tfontSize(\"xs\"),\n\t\t\t\t\thover(bg(colorMix(\"oklab\", { color: \"currentcolor\", weight: 10 }, \"transparent\"))),\n\t\t\t\t\tactive(bg(colorMix(\"oklab\", { color: \"currentcolor\", weight: 20 }, \"transparent\"))),\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 * Renders {@link Toast.CancelProps.children} as a neutral-tinted, secondary\n * trailing control; `type` defaults to `\"button\"`, ordered before the\n * consumer's attributes so `command`/`commandfor` still run.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the cancel control's markup.\n * @example\n * <Toast.Cancel>{t(\"actions.dismiss\")}</Toast.Cancel>\n */\nToast.Cancel = function ToastCancel(handle: Handle<Toast.CancelProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_BUTTON_TYPE;\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"cancel\"\n\t\t\t\tmix={[\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\trounded(\"md\"),\n\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\tpb(\"0.25rem\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tfg(\"neutral.fg\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.fg-emphasis\")]),\n\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\tshrink(),\n\t\t\t\t\ttransition(\n\t\t\t\t\t\t\"color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter\",\n\t\t\t\t\t),\n\t\t\t\t\tfontSize(\"xs\"),\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 * Renders a dismiss control for the ancestor {@link Toast}: an icon-only\n * `<button>` removable via a consumer's mixin or the `commandfor`/`command`\n * pair; `type=\"button\"` precedes those attributes so the pairing still runs.\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 * <Toast.Close aria-label={t(\"actions.dismiss\")} />\n */\nToast.Close = function ToastClose(handle: Handle<Toast.CloseProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"close\"\n\t\t\t\tmix={[\n\t\t\t\t\tabsolute(),\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(\"1.5rem\"),\n\t\t\t\t\tbs(\"1.5rem\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tfg(\"neutral.fg-muted\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.fg-emphasis\")]),\n\t\t\t\t\ttransition(\n\t\t\t\t\t\t\"color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter\",\n\t\t\t\t\t),\n\t\t\t\t\tinsBs(\"0.5rem\"),\n\t\t\t\t\tinsIe(\"0.5rem\"),\n\t\t\t\t\thitArea(),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<XIcon size={16} />\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders the fixed viewport stacking every queued {@link Toast} at a corner\n * via {@link Toast.RegionProps.placement}; `pointer-events` stays `none` so\n * clicks pass through to content behind, restored per toast.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the viewport's markup.\n * @example\n * <Toast.Region aria-label={t(\"toasts.region\")}>\n * {toasts.map((toast) => (\n * <Toast key={toast.id} color={toast.data.color}>\n * <Toast.Content>\n * <Toast.Title>{toast.data.title}</Toast.Title>\n * </Toast.Content>\n * </Toast>\n * ))}\n * </Toast.Region>\n * @example\n * <Toast.Region aria-label={t(\"toasts.region\")} placement=\"top-center\">\n * <Toast color=\"warning\">\n * <Toast.Content>\n * <Toast.Title>{t(\"toasts.offline.title\")}</Toast.Title>\n * </Toast.Content>\n * </Toast>\n * </Toast.Region>\n */\nToast.Region = function ToastRegion(handle: Handle<Toast.RegionProps>) {\n\treturn () => {\n\t\tlet { placement, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_PLACEMENT;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Toast.Region: needs an \"aria-label\" or \"aria-labelledby\" identifying this landmark for assistive technology.',\n\t\t);\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-placement={resolvedPlacement}\n\t\t\t\tdata-slot=\"region\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_REGION_ROLE }),\n\t\t\t\t\tfixed(),\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tgap(\"0.75rem\"),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\tmaxIs(\"24rem\"),\n\t\t\t\t\tpb(\"1rem\"),\n\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\tpointerEvents(),\n\t\t\t\t\traw({ zIndex: \"var(--ui-toast-z, 50)\" }),\n\t\t\t\t\twhen('&[data-placement^=\"top\"]', insBs(\"0\")),\n\t\t\t\t\twhen('&[data-placement^=\"bottom\"]', insBe(\"0\")),\n\t\t\t\t\twhen('&[data-placement$=\"start\"]', insIs(\"0\")),\n\t\t\t\t\twhen('&[data-placement$=\"end\"]', insIe(\"0\")),\n\t\t\t\t\twhen('&[data-placement$=\"center\"]', [insIs(\"50%\"), translateX(\"-50%\")]),\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</div>\n\t\t);\n\t};\n};\n"
|
|
11
|
+
},
|
|
12
|
+
"test": {
|
|
13
|
+
"path": "toast.test.tsx",
|
|
14
|
+
"content": "/**\n * Tests for the `type` {@link Toast}'s three controls write: an explicit\n * `type=\"button\"`, positioned before the consumer's own attributes, without\n * which the platform refuses to run an Invoker Command the control carries\n * inside a `<form>` — it decides whether the pairing is ambiguous while it\n * parses `command`/`commandfor` and never sees a `type` serialized after them.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Toast } from \"@sdxc/ui/toast\";\n\ndescribe(\"Toast.Action\", () => {\n\ttest('types itself \"button\", so its command survives inside a form', async () => {\n\t\tlet html = await renderToString(<Toast.Action>Undo</Toast.Action>);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest(\"writes type before the command attributes, which is where the platform reads it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Toast.Action commandfor=\"upload-toast\" command=\"hide\">\n\t\t\t\tUndo\n\t\t\t</Toast.Action>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"command=\"));\n\t});\n\n\ttest(\"leaves an explicitly typed submit action alone\", async () => {\n\t\tlet html = await renderToString(<Toast.Action type=\"submit\">Retry</Toast.Action>);\n\n\t\texpect(html).toContain('type=\"submit\"');\n\t});\n});\n\ndescribe(\"Toast.Cancel\", () => {\n\ttest('types itself \"button\", so its command survives inside a form', async () => {\n\t\tlet html = await renderToString(<Toast.Cancel>Dismiss</Toast.Cancel>);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest(\"writes type before the command attributes, which is where the platform reads it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Toast.Cancel commandfor=\"upload-toast\" command=\"hide\">\n\t\t\t\tDismiss\n\t\t\t</Toast.Cancel>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"command=\"));\n\t});\n});\n\ndescribe(\"Toast.Close\", () => {\n\ttest('types itself \"button\", so its command survives inside a form', async () => {\n\t\tlet html = await renderToString(<Toast.Close aria-label=\"Dismiss\" />);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest(\"writes type before the command attributes, which is where the platform reads it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Toast.Close aria-label=\"Dismiss\" commandfor=\"upload-toast\" command=\"hide\" />,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"command=\"));\n\t});\n});\n"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toggle-button",
|
|
3
|
+
"changedIn": "2026.10.13",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"ToggleButton",
|
|
7
|
+
"ToggleButtonGroup"
|
|
8
|
+
],
|
|
9
|
+
"source": {
|
|
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"
|
|
12
|
+
},
|
|
13
|
+
"test": {
|
|
14
|
+
"path": "toggle-button.test.tsx",
|
|
15
|
+
"content": "/**\n * Tests for {@link ToggleButton}: a glyph at either edge of a label is marked so that\n * side's padding drops a step, an icon-only toggle marks neither edge, and the host\n * carries an inset-free pointer target box.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { ToggleButton } from \"@sdxc/ui/toggle-button\";\n\ndescribe(ToggleButton.name, () => {\n\ttest(\"marks a leading glyph beside a label\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<ToggleButton aria-pressed={false}>\n\t\t\t\t<svg />\n\t\t\t\tBold\n\t\t\t</ToggleButton>,\n\t\t);\n\n\t\texpect(html).toMatch(/<button [^>]*data-glyph-start/);\n\t\texpect(html).not.toMatch(/<button [^>]*data-glyph-end/);\n\t});\n\n\ttest(\"marks neither edge on an icon-only toggle\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<ToggleButton aria-pressed={false} aria-label=\"Bold\">\n\t\t\t\t<svg />\n\t\t\t</ToggleButton>,\n\t\t);\n\n\t\texpect(html).not.toMatch(/<button [^>]*data-glyph-/);\n\t});\n\n\ttest(\"draws a target-size box that holds however the toggle is positioned\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<ToggleButton aria-pressed={false} size=\"sm\" aria-label=\"Bold\">\n\t\t\t\t<svg />\n\t\t\t</ToggleButton>,\n\t\t);\n\n\t\texpect(html).toMatch(\n\t\t\t/&::after \\{[^}]*position: absolute;[^}]*inline-size: var\\(--ui-target-size, 1\\.5rem\\);/,\n\t\t);\n\t});\n});\n"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "toolbar",
|
|
3
|
+
"changedIn": "2026.10.2",
|
|
4
|
+
"dependencies": [],
|
|
5
|
+
"exports": [
|
|
6
|
+
"Toolbar"
|
|
7
|
+
],
|
|
8
|
+
"source": {
|
|
9
|
+
"path": "toolbar.tsx",
|
|
10
|
+
"content": "/**\n * A bordered, tinted panel that groups a set of interactive controls —\n * buttons, toggles, menus — along a single axis. The host renders as a\n * `toolbar` landmark and lays its children out as a row by default,\n * switching to a column when its orientation flips to vertical.\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 } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { flexCol, hstack, items } from \"@sdxc/u/layout\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\n/**\n * `role=\"toolbar\"` applied through {@link attrs} unless a consumer supplies\n * its own `role`, announcing the host as a toolbar landmark for the controls\n * grouped inside it.\n */\nconst DEFAULT_ROLE = \"toolbar\";\n\n/**\n * Default {@link Toolbar.Props} orientation, applied through {@link attrs}\n * unless a consumer sets `aria-orientation` directly, so one attribute flips\n * both the accessibility contract and the CSS layout variant.\n */\nconst DEFAULT_ORIENTATION: Toolbar.Orientation = \"horizontal\";\n\n/**\n * Prop types for {@link Toolbar}.\n */\nexport namespace Toolbar {\n\t/**\n\t * Axis the toolbar's controls 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 the `mix` passthrough.\n\t * Setting `aria-orientation=\"vertical\"` switches both the accessibility\n\t * contract and rendered layout to a column; leaving it unset keeps the row.\n\t */\n\texport interface Props extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders a bordered, tinted panel grouping a set of interactive controls\n * along one axis. The host carries the `toolbar` role and lays its children\n * out as a row by default, flipping to a column when `aria-orientation=\"vertical\"`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the toolbar's markup.\n * @example\n * <Toolbar aria-label={t(\"editor.toolbar\")}>\n * \t<Button variant=\"ghost\"><ScissorsIcon /></Button>\n * \t<Button variant=\"ghost\"><CopyIcon /></Button>\n * \t<Button variant=\"ghost\"><ClipboardIcon /></Button>\n * </Toolbar>\n * @example\n * <Toolbar aria-label={t(\"editor.toolbar\")} aria-orientation=\"vertical\">\n * \t<Button variant=\"ghost\"><BoldIcon /></Button>\n * \t<Button variant=\"ghost\"><ItalicIcon /></Button>\n * </Toolbar>\n */\nexport function Toolbar(handle: Handle<Toolbar.Props>) {\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_ROLE, \"aria-orientation\": DEFAULT_ORIENTATION }),\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ color: \"neutral.border\", width: 1 }),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tpi(2),\n\t\t\t\t\twhen('&[aria-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
|
+
},
|
|
12
|
+
"test": null
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tooltip",
|
|
3
|
+
"changedIn": "2026.10.2",
|
|
4
|
+
"dependencies": [
|
|
5
|
+
"overlay-arrow",
|
|
6
|
+
"popover"
|
|
7
|
+
],
|
|
8
|
+
"exports": [
|
|
9
|
+
"Tooltip"
|
|
10
|
+
],
|
|
11
|
+
"source": {
|
|
12
|
+
"path": "tooltip.tsx",
|
|
13
|
+
"content": "/**\n * A small floating label identifying an otherwise unlabeled control or\n * adding a supplementary hint, riding the same `popover`-attributed host and\n * CSS anchor positioning contract as {@link Popover}. Its reveal is plain\n * `:hover`/`:focus-visible` state read off the sibling immediately before it\n * in the DOM — the trigger — so pointing at or tabbing to that trigger\n * surfaces the hint with no script anywhere in the path.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle } from \"remix/component\";\n\nimport { bg, fg, fill } from \"@sdxc/u/color\";\nimport { opacity, rounded, shadow, transition, transitionBehavior } from \"@sdxc/u/effects\";\nimport { block } from \"@sdxc/u/layout\";\nimport { media, startingStyle } from \"@sdxc/u/responsive\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { scaleProperty } from \"@sdxc/u/transform\";\nimport { text } from \"@sdxc/u/typography\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\n\nimport { OverlayArrow } from \"@sdxc/ui/overlay-arrow\";\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Side of the trigger {@link Tooltip} renders against when `placement` is\n * left unset — above the trigger, the most common resting spot for a hint\n * that shouldn't cover the control it describes.\n */\nconst DEFAULT_PLACEMENT: Popover.Placement = \"top\";\n\n/**\n * Whether {@link Tooltip} renders its pointer-arrow child when a consumer\n * leaves `showArrow` unset.\n */\nconst DEFAULT_SHOW_ARROW = true;\n\n/**\n * Selector matching the pointer-hovered trigger — the sibling immediately\n * before {@link Tooltip}'s host — for use only inside `@media (hover: hover)`,\n * wrapped in `:is()` since the style serializer treats a bare selector starting with `*` as a plain declaration.\n */\nconst HOVERED_TRIGGER_SELECTOR = \":is(*:hover) ~ &\";\n\n/**\n * Selector matching {@link Tooltip}'s entered state: native `:popover-open` —\n * set by a `popovertarget` (or `commandfor`/`command=\"toggle-popover\"`)\n * invoker, or an `interestfor` attribute — or keyboard focus on the trigger sibling immediately before it.\n */\nconst ENTERED_SELECTOR = \"&:popover-open, *:focus-visible ~ &\";\n\n/**\n * Prop types for {@link Tooltip}.\n */\nexport namespace Tooltip {\n\t/**\n\t * Every prop {@link Popover.Props} accepts except `popover` and `role`,\n\t * fixed here: `popover` is always `\"hint\"` so the tooltip layers over an\n\t * open `\"auto\"` popover, and `role` is always `\"tooltip\"` per WAI-ARIA.\n\t */\n\texport interface Props extends Omit<Popover.Props, \"popover\" | \"role\"> {\n\t\t/**\n\t\t * Whether to render a pointer-arrow child pointing back at the trigger,\n\t\t * filled to match this host's own solid background so the two read as\n\t\t * one continuous shape. Defaults to {@link DEFAULT_SHOW_ARROW}.\n\t\t */\n\t\tshowArrow?: boolean;\n\t}\n}\n\n/**\n * Renders the hint through {@link Popover}, fixing `popover` to `\"hint\"` and\n * `role` to `\"tooltip\"`. The host stays present in the DOM, entering on\n * `:popover-open`, `:focus-visible`, or the trigger's hover, animated via `@starting-style`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the hint's markup.\n * @example\n * <button popovertarget=\"save-tooltip\" aria-describedby=\"save-tooltip\">\n * \t{t(\"actions.save\")}\n * </button>\n * <Tooltip id=\"save-tooltip\">{t(\"actions.saveDescription\")}</Tooltip>\n * @example\n * <a href=\"/settings\" popovertarget=\"settings-tooltip\" aria-describedby=\"settings-tooltip\">\n * \t<GearIcon aria-hidden />\n * </a>\n * <Tooltip id=\"settings-tooltip\" placement=\"right\" showArrow={false}>\n * \t{t(\"nav.settings\")}\n * </Tooltip>\n */\nexport function Tooltip(handle: Handle<Tooltip.Props>) {\n\treturn () => {\n\t\tlet { placement, showArrow, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_PLACEMENT;\n\t\tlet resolvedShowArrow = showArrow ?? DEFAULT_SHOW_ARROW;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\t{...rest}\n\t\t\t\tpopover=\"hint\"\n\t\t\t\trole=\"tooltip\"\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tmix={[\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(2),\n\t\t\t\t\tpb(1),\n\t\t\t\t\tshadow(\"md\"),\n\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\topacity(0),\n\t\t\t\t\ttransition(\"opacity, scale, display, overlay\", {\n\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t}),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tscaleProperty(\"0.95\"),\n\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\twhen(ENTERED_SELECTOR, [block(), opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\tstartingStyle(when(ENTERED_SELECTOR, [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\tmedia(\"(hover: hover)\", [\n\t\t\t\t\t\twhen(HOVERED_TRIGGER_SELECTOR, [block(), opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\t\tstartingStyle(when(HOVERED_TRIGGER_SELECTOR, [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\t]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\ttransition(\"opacity, display, overlay\", {\n\t\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\tscaleProperty(\"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\t\t{children}\n\t\t\t\t{resolvedShowArrow && (\n\t\t\t\t\t<OverlayArrow placement={resolvedPlacement} mix={fill(\"neutral.solid\")}>\n\t\t\t\t\t\t<svg width={8} height={8} viewBox=\"0 0 8 8\">\n\t\t\t\t\t\t\t<path d=\"M0 0 L4 4 L8 0\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t</OverlayArrow>\n\t\t\t\t)}\n\t\t\t</Popover>\n\t\t);\n\t};\n}\n"
|
|
14
|
+
},
|
|
15
|
+
"test": null
|
|
16
|
+
}
|