@sdxc/kit 2026.10.29 → 2026.11.1
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/changelog.jsonl +93 -0
- package/dist/make/declare.js +32 -11
- package/package.json +2 -2
- package/registry/ui/accordion.json +2 -2
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/alert.json +2 -2
- package/registry/ui/aspect-ratio.json +2 -2
- package/registry/ui/avatar.json +6 -3
- package/registry/ui/badge.json +2 -2
- package/registry/ui/breadcrumbs.json +2 -2
- package/registry/ui/button.json +5 -3
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/card.json +2 -2
- package/registry/ui/carousel.json +2 -2
- package/registry/ui/checkbox-group.json +2 -2
- package/registry/ui/checkbox.json +2 -2
- package/registry/ui/combobox.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/cta-group.json +2 -2
- package/registry/ui/date-field.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/description.json +2 -2
- package/registry/ui/dialog-dismiss.json +13 -0
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/disclosure.json +2 -2
- package/registry/ui/drawer.json +2 -2
- package/registry/ui/field-error.json +2 -2
- package/registry/ui/form.json +2 -2
- package/registry/ui/group.json +2 -2
- package/registry/ui/header.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/heading.json +3 -3
- package/registry/ui/highlight.json +3 -3
- package/registry/ui/hover-card.json +2 -2
- package/registry/ui/image-placeholder.json +2 -2
- package/registry/ui/input.json +2 -2
- package/registry/ui/item.json +2 -2
- package/registry/ui/keyboard.json +2 -2
- package/registry/ui/label.json +2 -2
- package/registry/ui/link-button.json +5 -3
- package/registry/ui/link.json +2 -2
- package/registry/ui/listbox.json +2 -2
- package/registry/ui/menu.json +2 -2
- package/registry/ui/meter.json +2 -2
- package/registry/ui/modal.json +2 -2
- package/registry/ui/nav-link.json +2 -2
- package/registry/ui/navigation-menu.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/otp-field.json +2 -2
- package/registry/ui/overlay-arrow.json +2 -2
- package/registry/ui/pagination.json +2 -2
- package/registry/ui/popover.json +2 -2
- package/registry/ui/progress-bar.json +2 -2
- package/registry/ui/radio-group.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/scroll-area.json +2 -2
- package/registry/ui/search-field.json +2 -2
- package/registry/ui/section.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/selection-indicator.json +2 -2
- package/registry/ui/sentinel-row.json +2 -2
- package/registry/ui/separator.json +2 -2
- package/registry/ui/shared-element.json +2 -2
- package/registry/ui/sheet.json +2 -2
- package/registry/ui/sidebar.json +2 -2
- package/registry/ui/slider.json +2 -2
- package/registry/ui/spinner.json +2 -2
- package/registry/ui/switch.json +2 -2
- package/registry/ui/tabs.json +2 -2
- package/registry/ui/tag-group.json +2 -2
- package/registry/ui/text-field.json +2 -2
- package/registry/ui/text.json +2 -2
- package/registry/ui/textarea.json +2 -2
- package/registry/ui/time-field.json +2 -2
- package/registry/ui/toggle-button.json +2 -2
- package/registry/ui/tooltip.json +2 -2
- package/registry/ui/typeset.json +2 -2
- package/registry/ui/youtube-embed.json +2 -2
- package/stubs/scaffold.controller.index.stub +1 -1
- package/registry/ui/attachment.json +0 -15
- package/registry/ui/bubble.json +0 -13
- package/registry/ui/chart.json +0 -13
- package/registry/ui/color-area.json +0 -13
- package/registry/ui/color-field.json +0 -20
- package/registry/ui/color-picker.json +0 -17
- package/registry/ui/color-slider.json +0 -13
- package/registry/ui/color-swatch-picker.json +0 -15
- package/registry/ui/color-swatch.json +0 -13
- package/registry/ui/color-wheel.json +0 -13
- package/registry/ui/context-menu.json +0 -16
- package/registry/ui/drop-indicator.json +0 -13
- package/registry/ui/drop-zone.json +0 -13
- package/registry/ui/empty.json +0 -15
- package/registry/ui/feature.json +0 -18
- package/registry/ui/file-trigger.json +0 -13
- package/registry/ui/grid-list.json +0 -18
- package/registry/ui/logo-cloud.json +0 -16
- package/registry/ui/marker.json +0 -13
- package/registry/ui/marketing-header.json +0 -18
- package/registry/ui/marketing-section.json +0 -16
- package/registry/ui/menubar.json +0 -13
- package/registry/ui/message-scroller.json +0 -16
- package/registry/ui/message.json +0 -13
- package/registry/ui/resizable.json +0 -13
- package/registry/ui/shortcut-list.json +0 -18
- package/registry/ui/skeleton.json +0 -13
- package/registry/ui/split.json +0 -16
- package/registry/ui/stat-strip.json +0 -16
- package/registry/ui/table.json +0 -16
- package/registry/ui/toast.json +0 -16
- package/registry/ui/toolbar.json +0 -13
- package/registry/ui/tree.json +0 -18
package/registry/ui/dialog.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dialog",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button",
|
|
6
6
|
"heading-scope"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "dialog.tsx",
|
|
13
|
-
"content": "/**\n * A modal surface built on the native `<dialog>` element, opened and closed\n * declaratively through Invoker Commands (`commandfor`/`command`) instead of\n * a JavaScript-tracked open state. Compound parts cover a header, title,\n * description, footer, and a dismiss control, so a page composes only the\n * pieces a given dialog needs.\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, fg, outline } from \"@sdxc/u/color\";\nimport {\n\tbackdropBlur,\n\tbackdropSaturate,\n\topacity,\n\trounded,\n\tshadow,\n\ttransition,\n\ttransitionBehavior,\n} from \"@sdxc/u/effects\";\nimport { raw, vars } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tcontainer,\n\tfixed,\n\tflex,\n\tflexCol,\n\tflexColReverse,\n\tflexRow,\n\tgap,\n\tinset,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { at, media, startingStyle, supports } from \"@sdxc/u/responsive\";\nimport { is, maxBs, maxIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tfontSize,\n\tleading,\n\tpretty,\n\ttextAlign,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport { SHADOW_RING } from \"@sdxc/ui/styles\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Named container {@link Dialog} declares on its own host, so\n * {@link Dialog.Header} and {@link Dialog.Footer} can query the panel's own\n * width instead of the page's.\n */\nconst CONTAINER_NAME = \"ui-dialog\";\n\n/**\n * Panel width from which {@link Dialog.Header} and {@link Dialog.Footer} lay out for a\n * comfortable dialog: a leading title and a trailing row of actions. It is measured\n * against the panel's own inline size, which a dialog keeps well under a viewport's.\n */\nconst COMFORTABLE_WIDTH = \"24rem\";\n\n/**\n * Invoker Commands verb {@link Dialog.CloseProps.command} falls back to when\n * omitted, dismissing the ancestor Dialog named by `commandfor`.\n */\nconst DEFAULT_CLOSE_COMMAND = \"close\";\n\n/**\n * Prop types for {@link Dialog} and its compound parts.\n */\nexport namespace Dialog {\n\t/**\n\t * Every native `<dialog>` attribute, plus the `mix` passthrough. `role`\n\t * stays the platform's implicit `\"dialog\"` unless set to `\"alertdialog\"`,\n\t * and `open`/`closedby` stay the platform's own native state and light-dismiss controls.\n\t */\n\texport interface Props extends TagProps<\"dialog\"> {\n\t\t/** The panel's compound parts: {@link Dialog.Header}, {@link Dialog.Footer}, {@link Dialog.Close}, or any other content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Dialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Title}. Every native heading-element\n\t * attribute still applies, since the rendered tag depends on the nearest\n\t * ambient heading level, falling back to `<h1>` where none is set.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Close}: every {@link Button.Props} field\n\t * except the ones this component fixes on the consumer's behalf.\n\t */\n\texport interface CloseProps extends Omit<\n\t\tButton.Props,\n\t\t\"children\" | \"variant\" | \"color\" | \"size\" | \"aria-label\" | \"commandfor\" | \"command\"\n\t> {\n\t\t/** `id` of the ancestor {@link Dialog} this button dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target Dialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\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 dialog panel as a native `<dialog>` host, its `::backdrop`\n * tinted and, where supported, blurred to dim the page behind it. The panel\n * declares the `ui-dialog` named container so {@link Dialog.Header} and {@link Dialog.Footer} can size against the panel's own width; Invoker Commands open and close it declaratively — a trigger elsewhere points `commandfor` at this element's `id` with `command=\"show-modal\"`, and any control inside, including {@link Dialog.Close}, points `commandfor` at that same `id` with `command=\"close\"`.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Button commandfor=\"confirm-delete\" command=\"show-modal\">{t(\"project.delete\")}</Button>\n * <Dialog id=\"confirm-delete\" aria-labelledby=\"confirm-delete-title\">\n * \t<Dialog.Header>\n * \t\t<Dialog.Title id=\"confirm-delete-title\">{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t\t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * \t</Dialog.Header>\n * \t<Dialog.Footer>\n * \t\t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * \t</Dialog.Footer>\n * \t<Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n * </Dialog>\n * @example\n * <Dialog id=\"welcome\" mix={zoom({ duration: durations.normal })}>\n * \t<Dialog.Header>\n * \t\t<Dialog.Title>{t(\"welcome.title\")}</Dialog.Title>\n * \t</Dialog.Header>\n * </Dialog>\n */\nexport function Dialog(handle: Handle<Dialog.Props>) {\n\treturn () => {\n\t\tlet { id, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env?.DEV && !id) {\n\t\t\tconsole.warn(\n\t\t\t\t'Dialog rendered without an \"id\" — \"commandfor\" on a trigger or close control has nothing to target.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<dialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\tdata-slot=\"dialog\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * Establishes the containing block {@link Dialog.Close} pins itself to while\n\t\t\t\t\t * the panel sits in the page's flow, which a dialog opened through its `open`\n\t\t\t\t\t * attribute alone does.\n\t\t\t\t\t */\n\t\t\t\t\trelative(),\n\t\t\t\t\t/**\n\t\t\t\t\t * Measures a modal panel against the viewport, so it stays centered on screen\n\t\t\t\t\t * however far the page behind it is scrolled: the top layer resolves any other\n\t\t\t\t\t * positioning scheme against the document's own coordinates.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:modal\", fixed()),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * Wide enough for the form a dialog usually carries, so a field, its help text and a row\n\t\t\t\t\t * of actions read as one column. A consumer with less to say narrows it through `mix`.\n\t\t\t\t\t */\n\t\t\t\t\tmaxIs(\"32rem\"),\n\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\tgap(6),\n\t\t\t\t\tp(6),\n\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t/** Gated on `[open]` so the UA's own `dialog:not([open])` hiding still applies. */\n\t\t\t\t\twhen(\"&[open]\", flex()),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tcontainer(CONTAINER_NAME, \"inline-size\"),\n\t\t\t\t\twhen(\"&::backdrop\", [\n\t\t\t\t\t\tbg(\"rgb(0 0 0 / 0.5)\"),\n\t\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\t\topacity(0),\n\t\t\t\t\t\ttransition(\"opacity, display, overlay\", {\n\t\t\t\t\t\t\tduration: durations.normal,\n\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&[open]::backdrop\", opacity(100)),\n\t\t\t\t\tsupports(\n\t\t\t\t\t\t\"(backdrop-filter: blur(0))\",\n\t\t\t\t\t\tmedia(\n\t\t\t\t\t\t\t\"(prefers-reduced-transparency: no-preference)\",\n\t\t\t\t\t\t\twhen(\"&::backdrop\", [backdropBlur(\"md\"), backdropSaturate(1.4)]),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\tstartingStyle(when(\"&[open]::backdrop\", opacity(0))),\n\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The panel's edge is a ring shadow that takes on the tone behind it, over a\n\t\t\t\t\t * transparent border that forced-colors mode still paints as a line.\n\t\t\t\t\t */\n\t\t\t\t\tborder({ color: \"transparent\", width: 1 }),\n\t\t\t\t\tshadow(\"xl\"),\n\t\t\t\t\tvars({ \"ui-box-shadow-ring\": SHADOW_RING }),\n\t\t\t\t\t/** `overscrollBehavior` has no matching utility. */\n\t\t\t\t\traw({ overscrollBehavior: \"contain\" }),\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</dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Dialog.HeaderProps.children} as the panel's header slot: a\n * column stacking {@link Dialog.Title} and {@link Dialog.Description},\n * centered while narrow and start-aligned (flipping under `dir=\"rtl\"`) once the panel's own `ui-dialog` container grows past `40rem`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <Dialog.Header>\n * \t<Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * </Dialog.Header>\n */\nDialog.Header = function DialogHeader(handle: Handle<Dialog.HeaderProps>) {\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=\"header\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tgap(1.5),\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, textAlign(\"start\")),\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 {@link Dialog.TitleProps.children} as the panel's heading, inside\n * the native heading element matching the nearest ambient heading level —\n * `<h1>` by default — sized and weighted as the panel's most prominent line of text at every level.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n */\nDialog.Title = function DialogTitle(handle: Handle<Dialog.TitleProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\tfontSize(\"lg\"),\n\t\t\t\t\tleading(1),\n\t\t\t\t\tbalance(),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.DescriptionProps.children} as the panel's supporting\n * copy, in a native `<p>` set to the panel's muted foreground color so it\n * reads as secondary to {@link Dialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n */\nDialog.Description = function DialogDescription(handle: Handle<Dialog.DescriptionProps>) {\n\treturn () => {\n\t\tlet { 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={[fg(\"neutral.muted\"), fontSize(\"sm\"), pretty(), mix]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.FooterProps.children} as the panel's action row: a\n * column of stacked, full-width controls while the panel is narrow,\n * switching to a single end-aligned row past the panel's own `40rem` container mark.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Dialog.Footer>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" variant=\"outline\">{t(\"actions.cancel\")}</Button>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * </Dialog.Footer>\n */\nDialog.Footer = function DialogFooter(handle: Handle<Dialog.FooterProps>) {\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=\"footer\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(2),\n\t\t\t\t\tflexColReverse(),\n\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, [flexRow(), justify(\"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 dismiss control for the ancestor {@link Dialog} named by\n * `commandfor`: a small, ghost-styled {@link Button} with a fixed \"X\" glyph,\n * pinned to the panel's corner. `command` defaults to `\"close\"`, so passing only `commandfor` and `aria-label` wires it up.\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 * <Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n */\nDialog.Close = function DialogClose(handle: Handle<Dialog.CloseProps>) {\n\treturn () => {\n\t\tlet { commandfor, command, mix, ...rest } = handle.props;\n\t\tlet resolvedCommand = command ?? DEFAULT_CLOSE_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tcolor=\"neutral\"\n\t\t\t\tsize=\"sm\"\n\t\t\t\tcommandfor={commandfor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"close\"\n\t\t\t\tmix={[absolute(), inset(4, 4, \"auto\", \"auto\"), mix]}\n\t\t\t>\n\t\t\t\t<XIcon size={16} />\n\t\t\t</Button>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
"content": "/**\n * A modal surface built on the native `<dialog>` element, opened and closed\n * declaratively through Invoker Commands (`commandfor`/`command`) instead of\n * a JavaScript-tracked open state. Compound parts cover a header, title,\n * description, footer, and a dismiss control, so a page composes only the\n * pieces a given dialog needs.\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, fg, outline } from \"@sdxc/u/color\";\nimport {\n\tbackdropBlur,\n\tbackdropSaturate,\n\topacity,\n\trounded,\n\tshadow,\n\ttransition,\n\ttransitionBehavior,\n} from \"@sdxc/u/effects\";\nimport { raw, vars, mergeMix } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tcontainer,\n\tfixed,\n\tflex,\n\tflexCol,\n\tflexColReverse,\n\tflexRow,\n\tgap,\n\tinset,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { at, media, startingStyle, supports } from \"@sdxc/u/responsive\";\nimport { is, maxBs, maxIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tfontSize,\n\tleading,\n\tpretty,\n\ttextAlign,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport { SHADOW_RING } from \"@sdxc/ui/styles\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Named container {@link Dialog} declares on its own host, so\n * {@link Dialog.Header} and {@link Dialog.Footer} can query the panel's own\n * width instead of the page's.\n */\nconst CONTAINER_NAME = \"ui-dialog\";\n\n/**\n * Panel width from which {@link Dialog.Header} and {@link Dialog.Footer} lay out for a\n * comfortable dialog: a leading title and a trailing row of actions. It is measured\n * against the panel's own inline size, which a dialog keeps well under a viewport's.\n */\nconst COMFORTABLE_WIDTH = \"24rem\";\n\n/**\n * Invoker Commands verb {@link Dialog.CloseProps.command} falls back to when\n * omitted, dismissing the ancestor Dialog named by `commandfor`.\n */\nconst DEFAULT_CLOSE_COMMAND = \"close\";\n\n/**\n * Prop types for {@link Dialog} and its compound parts.\n */\nexport namespace Dialog {\n\t/**\n\t * Every native `<dialog>` attribute, plus the `mix` passthrough. `role`\n\t * stays the platform's implicit `\"dialog\"` unless set to `\"alertdialog\"`,\n\t * and `open`/`closedby` stay the platform's own native state and light-dismiss controls.\n\t */\n\texport interface Props extends TagProps<\"dialog\"> {\n\t\t/** The panel's compound parts: {@link Dialog.Header}, {@link Dialog.Footer}, {@link Dialog.Close}, or any other content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Dialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Title}. Every native heading-element\n\t * attribute still applies, since the rendered tag depends on the nearest\n\t * ambient heading level, falling back to `<h1>` where none is set.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Close}: every {@link Button.Props} field\n\t * except the ones this component fixes on the consumer's behalf.\n\t */\n\texport interface CloseProps extends Omit<\n\t\tButton.Props,\n\t\t\"children\" | \"variant\" | \"color\" | \"size\" | \"aria-label\" | \"commandfor\" | \"command\"\n\t> {\n\t\t/** `id` of the ancestor {@link Dialog} this button dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target Dialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\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 dialog panel as a native `<dialog>` host, its `::backdrop`\n * tinted and, where supported, blurred to dim the page behind it. The panel\n * declares the `ui-dialog` named container so {@link Dialog.Header} and {@link Dialog.Footer} can size against the panel's own width; Invoker Commands open and close it declaratively — a trigger elsewhere points `commandfor` at this element's `id` with `command=\"show-modal\"`, and any control inside, including {@link Dialog.Close}, points `commandfor` at that same `id` with `command=\"close\"`.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Button commandfor=\"confirm-delete\" command=\"show-modal\">{t(\"project.delete\")}</Button>\n * <Dialog id=\"confirm-delete\" aria-labelledby=\"confirm-delete-title\">\n * \t<Dialog.Header>\n * \t\t<Dialog.Title id=\"confirm-delete-title\">{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t\t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * \t</Dialog.Header>\n * \t<Dialog.Footer>\n * \t\t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * \t</Dialog.Footer>\n * \t<Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n * </Dialog>\n * @example\n * <Dialog id=\"welcome\" mix={zoom({ duration: durations.normal })}>\n * \t<Dialog.Header>\n * \t\t<Dialog.Title>{t(\"welcome.title\")}</Dialog.Title>\n * \t</Dialog.Header>\n * </Dialog>\n */\nexport function Dialog(handle: Handle<Dialog.Props>) {\n\treturn () => {\n\t\tlet { id, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env?.DEV && !id) {\n\t\t\tconsole.warn(\n\t\t\t\t'Dialog rendered without an \"id\" — \"commandfor\" on a trigger or close control has nothing to target.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<dialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\tdata-slot=\"dialog\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Establishes the containing block {@link Dialog.Close} pins itself to while\n\t\t\t\t\t\t * the panel sits in the page's flow, which a dialog opened through its `open`\n\t\t\t\t\t\t * attribute alone does.\n\t\t\t\t\t\t */\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Measures a modal panel against the viewport, so it stays centered on screen\n\t\t\t\t\t\t * however far the page behind it is scrolled: the top layer resolves any other\n\t\t\t\t\t\t * positioning scheme against the document's own coordinates.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&:modal\", fixed()),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Wide enough for the form a dialog usually carries, so a field, its help text and a row\n\t\t\t\t\t\t * of actions read as one column. A consumer with less to say narrows it through `mix`.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tmaxIs(\"32rem\"),\n\t\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\t\tgap(6),\n\t\t\t\t\t\tp(6),\n\t\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t\t/** Gated on `[open]` so the UA's own `dialog:not([open])` hiding still applies. */\n\t\t\t\t\t\twhen(\"&[open]\", flex()),\n\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\tcontainer(CONTAINER_NAME, \"inline-size\"),\n\t\t\t\t\t\twhen(\"&::backdrop\", [\n\t\t\t\t\t\t\tbg(\"rgb(0 0 0 / 0.5)\"),\n\t\t\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\t\t\topacity(0),\n\t\t\t\t\t\t\ttransition(\"opacity, display, overlay\", {\n\t\t\t\t\t\t\t\tduration: durations.normal,\n\t\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&[open]::backdrop\", opacity(100)),\n\t\t\t\t\t\tsupports(\n\t\t\t\t\t\t\t\"(backdrop-filter: blur(0))\",\n\t\t\t\t\t\t\tmedia(\n\t\t\t\t\t\t\t\t\"(prefers-reduced-transparency: no-preference)\",\n\t\t\t\t\t\t\t\twhen(\"&::backdrop\", [backdropBlur(\"md\"), backdropSaturate(1.4)]),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tstartingStyle(when(\"&[open]::backdrop\", opacity(0))),\n\t\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The panel's edge is a ring shadow that takes on the tone behind it, over a\n\t\t\t\t\t\t * transparent border that forced-colors mode still paints as a line.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tborder({ color: \"transparent\", width: 1 }),\n\t\t\t\t\t\tshadow(\"xl\"),\n\t\t\t\t\t\tvars({ \"ui-box-shadow-ring\": SHADOW_RING }),\n\t\t\t\t\t\t/** `overscrollBehavior` has no matching utility. */\n\t\t\t\t\t\traw({ overscrollBehavior: \"contain\" }),\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</dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Dialog.HeaderProps.children} as the panel's header slot: a\n * column stacking {@link Dialog.Title} and {@link Dialog.Description},\n * centered while narrow and start-aligned (flipping under `dir=\"rtl\"`) once the panel's own `ui-dialog` container grows past `40rem`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <Dialog.Header>\n * \t<Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * </Dialog.Header>\n */\nDialog.Header = function DialogHeader(handle: Handle<Dialog.HeaderProps>) {\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=\"header\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\tgap(1.5),\n\t\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, textAlign(\"start\")),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.TitleProps.children} as the panel's heading, inside\n * the native heading element matching the nearest ambient heading level —\n * `<h1>` by default — sized and weighted as the panel's most prominent line of text at every level.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n */\nDialog.Title = function DialogTitle(handle: Handle<Dialog.TitleProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\t\tfontSize(\"lg\"),\n\t\t\t\t\t\tleading(1),\n\t\t\t\t\t\tbalance(),\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{rest.children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.DescriptionProps.children} as the panel's supporting\n * copy, in a native `<p>` set to the panel's muted foreground color so it\n * reads as secondary to {@link Dialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n */\nDialog.Description = function DialogDescription(handle: Handle<Dialog.DescriptionProps>) {\n\treturn () => {\n\t\tlet { 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={mergeMix([fg(\"neutral.muted\"), fontSize(\"sm\"), pretty()], mix)}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.FooterProps.children} as the panel's action row: a\n * column of stacked, full-width controls while the panel is narrow,\n * switching to a single end-aligned row past the panel's own `40rem` container mark.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Dialog.Footer>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" variant=\"outline\">{t(\"actions.cancel\")}</Button>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * </Dialog.Footer>\n */\nDialog.Footer = function DialogFooter(handle: Handle<Dialog.FooterProps>) {\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=\"footer\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tgap(2),\n\t\t\t\t\t\tflexColReverse(),\n\t\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, [flexRow(), justify(\"end\")]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a dismiss control for the ancestor {@link Dialog} named by\n * `commandfor`: a small, ghost-styled {@link Button} with a fixed \"X\" glyph,\n * pinned to the panel's corner. `command` defaults to `\"close\"`, so passing only `commandfor` and `aria-label` wires it up.\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 * <Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n */\nDialog.Close = function DialogClose(handle: Handle<Dialog.CloseProps>) {\n\treturn () => {\n\t\tlet { commandfor, command, mix, ...rest } = handle.props;\n\t\tlet resolvedCommand = command ?? DEFAULT_CLOSE_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tcolor=\"neutral\"\n\t\t\t\tsize=\"sm\"\n\t\t\t\tcommandfor={commandfor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"close\"\n\t\t\t\tmix={mergeMix([absolute(), inset(4, 4, \"auto\", \"auto\")], mix)}\n\t\t\t>\n\t\t\t\t<XIcon size={16} />\n\t\t\t</Button>\n\t\t);\n\t};\n};\n"
|
|
14
14
|
},
|
|
15
15
|
"test": {
|
|
16
16
|
"path": "dialog.test.tsx",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "disclosure",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"heading-scope"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "disclosure.tsx",
|
|
12
|
-
"content": "/**\n * A single expand/collapse section built on the native `<details>` and\n * `<summary>` elements, so the show/hide state, keyboard handling, and\n * find-in-page behavior all come from the platform itself.\n * `Disclosure.Trigger` is the always-visible `<summary>` label and\n * `Disclosure.Panel` is the content it reveals; `Disclosure.Group` stacks\n * several disclosures into one bordered list.\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 { bg, borderEdge, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, roundedCorner, rounded, transition, transitionDuration } from \"@sdxc/u/effects\";\nimport { cursor, listStyle, pointerEvents, raw } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, hidden, interpolateSize, items, shrink } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, m, pb, pbe, pi } from \"@sdxc/u/size\";\nimport { detailsContent, hover, open, when } from \"@sdxc/u/state\";\nimport { rotate } from \"@sdxc/u/transform\";\nimport { balance, textAlign, weight } from \"@sdxc/u/typography\";\n\nimport { panelChrome } from \"@sdxc/ui/styles\";\n\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Prop types for {@link Disclosure} and its compound parts.\n */\nexport namespace Disclosure {\n\t/**\n\t * Every native `<details>` attribute, plus the `mix` passthrough. The\n\t * `open` attribute alone drives expanded state, and sibling disclosures\n\t * sharing a `name` let the browser keep only one open at a time.\n\t */\n\texport interface Props extends TagProps<\"details\"> {\n\t\t/** The section's compound parts: {@link Disclosure.Trigger} followed by {@link Disclosure.Panel}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Header}. The rendered tag matches\n\t * the nearest ambient heading level, falling back to `<h1>` where nothing\n\t * supplies one.\n\t */\n\texport interface HeaderProps extends TagProps<\"h1\"> {\n\t\t/** The trigger's label text, exposed as a heading for assistive technology. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"summary\"> {\n\t\t/** The always-visible label, typically plain text or {@link Disclosure.Header}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Panel}.\n\t */\n\texport interface PanelProps extends TagProps<\"div\"> {\n\t\t/** The content revealed while the section is open. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** One or more {@link Disclosure} sections to stack into a single bordered list. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Renders the section's `<details>` host, revealing\n * {@link Disclosure.Panel}'s content while `open`. The `::details-content`\n * block-size transition is a progressive enhancement over the native toggle.\n *\n * @param handle Runtime handle carrying the host `<details>`'s props.\n * @returns The render function producing the section's markup.\n * @example\n * <Disclosure>\n * \t<Disclosure.Trigger>\n * \t\t{t(\"faq.refunds.question\")}\n * \t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden=\"true\" />\n * \t</Disclosure.Trigger>\n * \t<Disclosure.Panel>\n * \t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t</Disclosure.Panel>\n * </Disclosure>\n * @example\n * <Disclosure open>\n * \t<Disclosure.Trigger>{t(\"faq.shipping.question\")}</Disclosure.Trigger>\n * \t<Disclosure.Panel>\n * \t\t<p>{t(\"faq.shipping.answer\")}</p>\n * \t</Disclosure.Panel>\n * </Disclosure>\n */\nexport function Disclosure(handle: Handle<Disclosure.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<details\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tpanelChrome(),\n\t\t\t\t\tinterpolateSize(),\n\t\t\t\t\tdetailsContent([\n\t\t\t\t\t\toverflow(\"clip\"),\n\t\t\t\t\t\tbs(0),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\ttransitionProperty: \"block-size, content-visibility\",\n\t\t\t\t\t\t\ttransitionBehavior: \"allow-discrete\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\ttransitionDuration(\"200ms\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&[open]::details-content\", bs(\"auto\")),\n\t\t\t\t\t/**\n\t\t\t\t\t * The glyph a trigger carries as `data-slot=\"icon\"` turns over while the section\n\t\t\t\t\t * is open, the same rule `Accordion` states: the section owns the turn because\n\t\t\t\t\t * only it knows it is open, and the trigger owns which glyph turns.\n\t\t\t\t\t */\n\t\t\t\t\topen(when('& summary [data-slot=\"icon\"]', rotate(180))),\n\t\t\t\t\twhen('& summary [data-slot=\"icon\"]', transition(\"transform\", { duration: 200 })),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\tdetailsContent(transitionDuration(\"0s\")),\n\t\t\t\t\t\twhen('& summary [data-slot=\"icon\"]', transitionDuration(\"0s\")),\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</details>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Disclosure.HeaderProps.children} as an accessible heading\n * at the ambient level, nested directly inside\n * {@link Disclosure.Trigger}, since `<summary>` must stay `<details>`'s direct child.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Disclosure.Trigger>\n * \t<Disclosure.Header>{t(\"faq.refunds.question\")}</Disclosure.Header>\n * </Disclosure.Trigger>\n */\nDisclosure.Header = function DisclosureHeader(handle: Handle<Disclosure.HeaderProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag {...rest} data-heading-level={resolved} mix={[m(0), balance(), mix]}>\n\t\t\t\t{children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Disclosure.TriggerProps.children} inside a native `<summary>`\n * with its marker suppressed, so the indicator is a glyph the consumer passes as a\n * child carrying `data-slot=\"icon\"` — which the section turns over while it is open.\n * `aria-disabled=\"true\"` also stops the section toggling: the row leaves the tab order and\n * stops taking pointer events, which is what a `<summary>` has in place of the `disabled`\n * a button would carry.\n *\n * @param handle Runtime handle carrying the host `<summary>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <Disclosure.Trigger>{t(\"faq.refunds.question\")}</Disclosure.Trigger>\n * @example\n * <Disclosure.Trigger aria-disabled=\"true\">{t(\"faq.archived.question\")}</Disclosure.Trigger>\n */\nDisclosure.Trigger = function DisclosureTrigger(handle: Handle<Disclosure.TriggerProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\t/**\n\t\t * A `<summary>` has no `disabled`, so a disabled row leaves the tab order to keep Enter\n\t\t * and Space off it. With the pointer-events rule below, that covers all `disabled` does,\n\t\t * and it holds before any script runs.\n\t\t */\n\t\tlet disabled = rest[\"aria-disabled\"] === \"true\";\n\n\t\treturn (\n\t\t\t<summary\n\t\t\t\t{...rest}\n\t\t\t\ttabIndex={disabled ? -1 : rest.tabIndex}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tflex(),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(2),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tpb(3),\n\t\t\t\t\tpi(3),\n\t\t\t\t\ttextAlign(\"start\"),\n\t\t\t\t\tbalance(),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\thover(bg(\"neutral.tint\")),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [opacity(50), pointerEvents(\"none\")]),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\tlistStyle(),\n\t\t\t\t\twhen(\"&::-webkit-details-marker\", hidden()),\n\t\t\t\t\twhen(\"&::marker\", raw({ content: '\"\"' })),\n\t\t\t\t\t/**\n\t\t\t\t\t * The indicator is sized against the label beside it, whatever an icon set draws at,\n\t\t\t\t\t * and holds that size when a long label squeezes the row.\n\t\t\t\t\t */\n\t\t\t\t\twhen('& [data-slot=\"icon\"]', [is(4), bs(4), shrink()]),\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\",\n\t\t\t\t\t),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', 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</summary>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Disclosure.PanelProps.children} in a `<div>` positioned\n * after {@link Disclosure.Trigger}, all `<details>` needs to treat it as\n * the collapsible body. Its padding is left for the consumer to size.\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 * <Disclosure.Panel>\n * \t<p>{t(\"faq.refunds.answer\")}</p>\n * </Disclosure.Panel>\n */\nDisclosure.Panel = function DisclosurePanel(handle: Handle<Disclosure.PanelProps>) {\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\tmix={[\n\t\t\t\t\toverflow(),\n\t\t\t\t\t/**\n\t\t\t\t\t * The panel is inset to the line the trigger's label sits on, so the section reads as\n\t\t\t\t\t * one block; the block-start stays open because the trigger's own padding already\n\t\t\t\t\t * separates the two.\n\t\t\t\t\t */\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpbe(3),\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 Disclosure.GroupProps.children} as a bordered, rounded list\n * of {@link Disclosure} sections sharing one divider between them. Sections\n * keep toggling independently unless they share a `name`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <Disclosure.Group>\n * \t<Disclosure>\n * \t\t<Disclosure.Trigger>{t(\"faq.refunds.question\")}</Disclosure.Trigger>\n * \t\t<Disclosure.Panel>\n * \t\t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t\t</Disclosure.Panel>\n * \t</Disclosure>\n * \t<Disclosure>\n * \t\t<Disclosure.Trigger>{t(\"faq.shipping.question\")}</Disclosure.Trigger>\n * \t\t<Disclosure.Panel>\n * \t\t\t<p>{t(\"faq.shipping.answer\")}</p>\n * \t\t</Disclosure.Panel>\n * \t</Disclosure>\n * </Disclosure.Group>\n */\nDisclosure.Group = function DisclosureGroup(handle: Handle<Disclosure.GroupProps>) {\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\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\twhen(\"& > details\", [\n\t\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\t\tborderEdge(\"inline-start\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\t\tborderEdge(\"inline-end\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\t\tborderEdge(\"block-start\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\t\twhen(\"&:first-child\", [\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"lg\"),\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"lg\"),\n\t\t\t\t\t\t\tborderEdge(\"block-start\", { width: 1, noStyleDefault: true }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&:last-child\", [\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"lg\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"lg\"),\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"
|
|
12
|
+
"content": "/**\n * A single expand/collapse section built on the native `<details>` and\n * `<summary>` elements, so the show/hide state, keyboard handling, and\n * find-in-page behavior all come from the platform itself.\n * `Disclosure.Trigger` is the always-visible `<summary>` label and\n * `Disclosure.Panel` is the content it reveals; `Disclosure.Group` stacks\n * several disclosures into one bordered list.\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 { bg, borderEdge, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, roundedCorner, rounded, transition, transitionDuration } from \"@sdxc/u/effects\";\nimport { cursor, listStyle, pointerEvents, raw, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, hidden, interpolateSize, items, shrink } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, m, pb, pbe, pi } from \"@sdxc/u/size\";\nimport { detailsContent, hover, open, when } from \"@sdxc/u/state\";\nimport { rotate } from \"@sdxc/u/transform\";\nimport { balance, textAlign, weight } from \"@sdxc/u/typography\";\n\nimport { panelChrome } from \"@sdxc/ui/styles\";\n\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Prop types for {@link Disclosure} and its compound parts.\n */\nexport namespace Disclosure {\n\t/**\n\t * Every native `<details>` attribute, plus the `mix` passthrough. The\n\t * `open` attribute alone drives expanded state, and sibling disclosures\n\t * sharing a `name` let the browser keep only one open at a time.\n\t */\n\texport interface Props extends TagProps<\"details\"> {\n\t\t/** The section's compound parts: {@link Disclosure.Trigger} followed by {@link Disclosure.Panel}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Header}. The rendered tag matches\n\t * the nearest ambient heading level, falling back to `<h1>` where nothing\n\t * supplies one.\n\t */\n\texport interface HeaderProps extends TagProps<\"h1\"> {\n\t\t/** The trigger's label text, exposed as a heading for assistive technology. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"summary\"> {\n\t\t/** The always-visible label, typically plain text or {@link Disclosure.Header}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Panel}.\n\t */\n\texport interface PanelProps extends TagProps<\"div\"> {\n\t\t/** The content revealed while the section is open. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Disclosure.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** One or more {@link Disclosure} sections to stack into a single bordered list. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * Renders the section's `<details>` host, revealing\n * {@link Disclosure.Panel}'s content while `open`. The `::details-content`\n * block-size transition is a progressive enhancement over the native toggle.\n *\n * @param handle Runtime handle carrying the host `<details>`'s props.\n * @returns The render function producing the section's markup.\n * @example\n * <Disclosure>\n * \t<Disclosure.Trigger>\n * \t\t{t(\"faq.refunds.question\")}\n * \t\t<ChevronDownIcon data-slot=\"icon\" aria-hidden=\"true\" />\n * \t</Disclosure.Trigger>\n * \t<Disclosure.Panel>\n * \t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t</Disclosure.Panel>\n * </Disclosure>\n * @example\n * <Disclosure open>\n * \t<Disclosure.Trigger>{t(\"faq.shipping.question\")}</Disclosure.Trigger>\n * \t<Disclosure.Panel>\n * \t\t<p>{t(\"faq.shipping.answer\")}</p>\n * \t</Disclosure.Panel>\n * </Disclosure>\n */\nexport function Disclosure(handle: Handle<Disclosure.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<details\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tpanelChrome(),\n\t\t\t\t\t\tinterpolateSize(),\n\t\t\t\t\t\tdetailsContent([\n\t\t\t\t\t\t\toverflow(\"clip\"),\n\t\t\t\t\t\t\tbs(0),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\ttransitionProperty: \"block-size, content-visibility\",\n\t\t\t\t\t\t\t\ttransitionBehavior: \"allow-discrete\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\ttransitionDuration(\"200ms\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&[open]::details-content\", bs(\"auto\")),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The glyph a trigger carries as `data-slot=\"icon\"` turns over while the section\n\t\t\t\t\t\t * is open, the same rule `Accordion` states: the section owns the turn because\n\t\t\t\t\t\t * only it knows it is open, and the trigger owns which glyph turns.\n\t\t\t\t\t\t */\n\t\t\t\t\t\topen(when('& summary [data-slot=\"icon\"]', rotate(180))),\n\t\t\t\t\t\twhen('& summary [data-slot=\"icon\"]', transition(\"transform\", { duration: 200 })),\n\t\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\t\tdetailsContent(transitionDuration(\"0s\")),\n\t\t\t\t\t\t\twhen('& summary [data-slot=\"icon\"]', transitionDuration(\"0s\")),\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</details>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Disclosure.HeaderProps.children} as an accessible heading\n * at the ambient level, nested directly inside\n * {@link Disclosure.Trigger}, since `<summary>` must stay `<details>`'s direct child.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Disclosure.Trigger>\n * \t<Disclosure.Header>{t(\"faq.refunds.question\")}</Disclosure.Header>\n * </Disclosure.Trigger>\n */\nDisclosure.Header = function DisclosureHeader(handle: Handle<Disclosure.HeaderProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag {...rest} data-heading-level={resolved} mix={mergeMix([m(0), balance()], mix)}>\n\t\t\t\t{children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Disclosure.TriggerProps.children} inside a native `<summary>`\n * with its marker suppressed, so the indicator is a glyph the consumer passes as a\n * child carrying `data-slot=\"icon\"` — which the section turns over while it is open.\n * `aria-disabled=\"true\"` also stops the section toggling: the row leaves the tab order and\n * stops taking pointer events, which is what a `<summary>` has in place of the `disabled`\n * a button would carry.\n *\n * @param handle Runtime handle carrying the host `<summary>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <Disclosure.Trigger>{t(\"faq.refunds.question\")}</Disclosure.Trigger>\n * @example\n * <Disclosure.Trigger aria-disabled=\"true\">{t(\"faq.archived.question\")}</Disclosure.Trigger>\n */\nDisclosure.Trigger = function DisclosureTrigger(handle: Handle<Disclosure.TriggerProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\t\t/**\n\t\t * A `<summary>` has no `disabled`, so a disabled row leaves the tab order to keep Enter\n\t\t * and Space off it. With the pointer-events rule below, that covers all `disabled` does,\n\t\t * and it holds before any script runs.\n\t\t */\n\t\tlet disabled = rest[\"aria-disabled\"] === \"true\";\n\n\t\treturn (\n\t\t\t<summary\n\t\t\t\t{...rest}\n\t\t\t\ttabIndex={disabled ? -1 : rest.tabIndex}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tgap(2),\n\t\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\t\tpb(3),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\ttextAlign(\"start\"),\n\t\t\t\t\t\tbalance(),\n\t\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\thover(bg(\"neutral.tint\")),\n\t\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [opacity(50), pointerEvents(\"none\")]),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\tlistStyle(),\n\t\t\t\t\t\twhen(\"&::-webkit-details-marker\", hidden()),\n\t\t\t\t\t\twhen(\"&::marker\", raw({ content: '\"\"' })),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The indicator is sized against the label beside it, whatever an icon set draws at,\n\t\t\t\t\t\t * and holds that size when a long label squeezes the row.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen('& [data-slot=\"icon\"]', [is(4), bs(4), shrink()]),\n\t\t\t\t\t\ttransition(\n\t\t\t\t\t\t\t\"color, background-color, border-color, outline-color, text-decoration-color, fill, stroke\",\n\t\t\t\t\t\t),\n\t\t\t\t\t\twhen('&[aria-disabled=\"true\"]', cursor(\"not-allowed\")),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</summary>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Disclosure.PanelProps.children} in a `<div>` positioned\n * after {@link Disclosure.Trigger}, all `<details>` needs to treat it as\n * the collapsible body. Its padding is left for the consumer to size.\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 * <Disclosure.Panel>\n * \t<p>{t(\"faq.refunds.answer\")}</p>\n * </Disclosure.Panel>\n */\nDisclosure.Panel = function DisclosurePanel(handle: Handle<Disclosure.PanelProps>) {\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\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\toverflow(),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The panel is inset to the line the trigger's label sits on, so the section reads as\n\t\t\t\t\t\t * one block; the block-start stays open because the trigger's own padding already\n\t\t\t\t\t\t * separates the two.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tpbe(3),\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 Disclosure.GroupProps.children} as a bordered, rounded list\n * of {@link Disclosure} sections sharing one divider between them. Sections\n * keep toggling independently unless they share a `name`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <Disclosure.Group>\n * \t<Disclosure>\n * \t\t<Disclosure.Trigger>{t(\"faq.refunds.question\")}</Disclosure.Trigger>\n * \t\t<Disclosure.Panel>\n * \t\t\t<p>{t(\"faq.refunds.answer\")}</p>\n * \t\t</Disclosure.Panel>\n * \t</Disclosure>\n * \t<Disclosure>\n * \t\t<Disclosure.Trigger>{t(\"faq.shipping.question\")}</Disclosure.Trigger>\n * \t\t<Disclosure.Panel>\n * \t\t\t<p>{t(\"faq.shipping.answer\")}</p>\n * \t\t</Disclosure.Panel>\n * \t</Disclosure>\n * </Disclosure.Group>\n */\nDisclosure.Group = function DisclosureGroup(handle: Handle<Disclosure.GroupProps>) {\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\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\twhen(\"& > details\", [\n\t\t\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\t\t\tborderEdge(\"inline-start\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\t\t\tborderEdge(\"inline-end\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\t\t\tborderEdge(\"block-start\", { width: \"0\", noStyleDefault: true }),\n\t\t\t\t\t\t\twhen(\"&:first-child\", [\n\t\t\t\t\t\t\t\troundedCorner(\"start-start\", \"lg\"),\n\t\t\t\t\t\t\t\troundedCorner(\"start-end\", \"lg\"),\n\t\t\t\t\t\t\t\tborderEdge(\"block-start\", { width: 1, noStyleDefault: true }),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\twhen(\"&:last-child\", [\n\t\t\t\t\t\t\t\troundedCorner(\"end-start\", \"lg\"),\n\t\t\t\t\t\t\t\troundedCorner(\"end-end\", \"lg\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n"
|
|
13
13
|
},
|
|
14
14
|
"test": {
|
|
15
15
|
"path": "disclosure.test.tsx",
|
package/registry/ui/drawer.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drawer",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"dialog"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "drawer.tsx",
|
|
12
|
-
"content": "/**\n * A preset of {@link Dialog} docked flush against one physical edge of the\n * viewport, sized to fill that edge, sliding into place from it on open and\n * fading out with a short drift toward it on close. Every other detail — the\n * dimming, blurrable `::backdrop`, the `ui-dialog` named container its\n * compound parts query, and the missing-`id` dev-mode contract check — carries\n * over from {@link Dialog}, since this component composes it directly.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle } from \"remix/component\";\n\nimport { rounded } from \"@sdxc/u/effects\";\nimport { vars, willChange } from \"@sdxc/u/general\";\nimport { fixed, insBe, insBs, insIe, insIs, insLeft, insRight } from \"@sdxc/u/layout\";\nimport { bs, is, m, maxBs, maxIs } from \"@sdxc/u/size\";\nimport { data } from \"@sdxc/u/state\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport { enterExit } from \"@sdxc/ui/animations\";\n\nimport { Dialog } from \"@sdxc/ui/dialog\";\n\n/**\n * Physical edge of the viewport {@link Drawer} docks against when\n * `placement` is left unset.\n */\nconst DEFAULT_PLACEMENT: Drawer.Placement = \"bottom\";\n\n/**\n * How far toward its edge the panel drifts while it fades out on close: a\n * hint of the direction it came from, short of the full slide it entered with.\n */\nconst EXIT_DISTANCE = \"1rem\";\n\n/** Blur radius in pixels the panel softens to as it fades out. */\nconst EXIT_BLUR_PX = 4;\n\n/**\n * Prop types for {@link Drawer} and its compound parts. Each compound part\n * aliases {@link Dialog}'s matching part, since {@link Drawer} renders\n * straight through to {@link Dialog}'s markup.\n */\nexport namespace Drawer {\n\t/**\n\t * Physical edge of the viewport the panel docks against and slides in from.\n\t * `\"left\"`/`\"right\"` name that fixed edge regardless of `dir`;\n\t * `\"top\"`/`\"bottom\"` name the block axis, which already tracks `dir` on its own.\n\t */\n\texport type Placement = \"top\" | \"right\" | \"bottom\" | \"left\";\n\n\t/** Every prop {@link Dialog.Props} accepts, plus `placement`. */\n\texport interface Props extends Dialog.Props {\n\t\t/**\n\t\t * Physical edge of the viewport to dock against and slide in from.\n\t\t * Defaults to {@link DEFAULT_PLACEMENT}.\n\t\t */\n\t\tplacement?: Placement;\n\t}\n\n\t/** Every prop {@link Dialog.HeaderProps} accepts, unchanged. */\n\texport interface HeaderProps extends Dialog.HeaderProps {}\n\n\t/** Every prop {@link Dialog.TitleProps} accepts, unchanged. */\n\texport interface TitleProps extends Dialog.TitleProps {}\n\n\t/** Every prop {@link Dialog.DescriptionProps} accepts, unchanged. */\n\texport interface DescriptionProps extends Dialog.DescriptionProps {}\n\n\t/** Every prop {@link Dialog.FooterProps} accepts, unchanged. */\n\texport interface FooterProps extends Dialog.FooterProps {}\n\n\t/** Every prop {@link Dialog.CloseProps} accepts, unchanged. */\n\texport interface CloseProps extends Dialog.CloseProps {}\n}\n\n/**\n * Renders {@link Dialog} pinned to one edge of the viewport, animating a\n * `transform` off the native `open` attribute so `@starting-style` can\n * animate the close; a `mix` prop composes alongside this placement styling.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props, plus `placement`.\n * @returns The render function producing the docked panel's markup.\n * @example\n * <Button commandfor=\"cart\" command=\"show-modal\">{t(\"cart.open\")}</Button>\n * <Drawer id=\"cart\" placement=\"right\" aria-labelledby=\"cart-title\">\n * \t<Drawer.Header>\n * \t\t<Drawer.Title id=\"cart-title\">{t(\"cart.title\")}</Drawer.Title>\n * \t</Drawer.Header>\n * \t<Drawer.Close commandfor=\"cart\" aria-label={t(\"actions.close\")} />\n * </Drawer>\n * @example\n * <Drawer id=\"filters\" placement=\"bottom\" aria-labelledby=\"filters-title\">\n * \t<Drawer.Header>\n * \t\t<Drawer.Title id=\"filters-title\">{t(\"filters.title\")}</Drawer.Title>\n * \t</Drawer.Header>\n * \t<Drawer.Footer>\n * \t\t<Button commandfor=\"filters\" command=\"close\">{t(\"actions.apply\")}</Button>\n * \t</Drawer.Footer>\n * </Drawer>\n */\nexport function Drawer(handle: Handle<Drawer.Props>) {\n\treturn () => {\n\t\tlet { placement, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_PLACEMENT;\n\n\t\treturn (\n\t\t\t<Dialog\n\t\t\t\t{...rest}\n\t\t\t\tdata-placement={resolvedPlacement}\n\t\t\t\tmix={[\n\t\t\t\t\tfixed(),\n\t\t\t\t\tm(0),\n\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\tenterExit({\n\t\t\t\t\t\ttranslate: \"var(--ui-drawer-enter-offset)\",\n\t\t\t\t\t\tduration: durations.slow,\n\t\t\t\t\t\teasing: easings.decelerate,\n\t\t\t\t\t\texit: { translate: \"var(--ui-drawer-exit-offset)\", opacity: 0, blur: EXIT_BLUR_PX },\n\t\t\t\t\t\texitDuration: durations.fast,\n\t\t\t\t\t\texitEasing: easings.accelerate,\n\t\t\t\t\t}),\n\t\t\t\t\twillChange(\"translate\"),\n\n\t\t\t\t\t/**\n\t\t\t\t\t * Each placement frees the far edge so the dialog's centring lets go, gives its docked\n\t\t\t\t\t * edge a depth, and fills the other axis, since a `<dialog>` sizes to its content on both\n\t\t\t\t\t * axes even with opposite insets pinned.\n\t\t\t\t\t */\n\t\t\t\t\tdata(\"placement\", \"top\", [\n\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\tinsBe(\"auto\"),\n\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\tinsIe(\"0\"),\n\t\t\t\t\t\tbs(\"24rem\"),\n\t\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tmaxIs(\"none\"),\n\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"0 -100%\",\n\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `0 -${EXIT_DISTANCE}`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"placement\", \"bottom\", [\n\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\tinsBs(\"auto\"),\n\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\tinsIe(\"0\"),\n\t\t\t\t\t\tbs(\"24rem\"),\n\t\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tmaxIs(\"none\"),\n\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"0 100%\",\n\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `0 ${EXIT_DISTANCE}`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"placement\", \"left\", [\n\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\tinsLeft(\"0\"),\n\t\t\t\t\t\tinsRight(\"auto\"),\n\t\t\t\t\t\tis(\"22rem\"),\n\t\t\t\t\t\tmaxIs(\"90vw\"),\n\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\tmaxBs(\"none\"),\n\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"-100% 0\",\n\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `-${EXIT_DISTANCE} 0`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"placement\", \"right\", [\n\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\tinsRight(\"0\"),\n\t\t\t\t\t\tinsLeft(\"auto\"),\n\t\t\t\t\t\tis(\"22rem\"),\n\t\t\t\t\t\tmaxIs(\"90vw\"),\n\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\tmaxBs(\"none\"),\n\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"100% 0\",\n\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `${EXIT_DISTANCE} 0`,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\n\t\t\t\t\tmix,\n\t\t\t\t
|
|
12
|
+
"content": "/**\n * A preset of {@link Dialog} docked flush against one physical edge of the\n * viewport, sized to fill that edge, sliding into place from it on open and\n * fading out with a short drift toward it on close. Every other detail — the\n * dimming, blurrable `::backdrop`, the `ui-dialog` named container its\n * compound parts query, and the missing-`id` dev-mode contract check — carries\n * over from {@link Dialog}, since this component composes it directly.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle } from \"remix/component\";\n\nimport { rounded } from \"@sdxc/u/effects\";\nimport { vars, willChange, mergeMix } from \"@sdxc/u/general\";\nimport { fixed, insBe, insBs, insIe, insIs, insLeft, insRight } from \"@sdxc/u/layout\";\nimport { bs, is, m, maxBs, maxIs } from \"@sdxc/u/size\";\nimport { data } from \"@sdxc/u/state\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport { enterExit } from \"@sdxc/ui/animations\";\n\nimport { Dialog } from \"@sdxc/ui/dialog\";\n\n/**\n * Physical edge of the viewport {@link Drawer} docks against when\n * `placement` is left unset.\n */\nconst DEFAULT_PLACEMENT: Drawer.Placement = \"bottom\";\n\n/**\n * How far toward its edge the panel drifts while it fades out on close: a\n * hint of the direction it came from, short of the full slide it entered with.\n */\nconst EXIT_DISTANCE = \"1rem\";\n\n/** Blur radius in pixels the panel softens to as it fades out. */\nconst EXIT_BLUR_PX = 4;\n\n/**\n * Prop types for {@link Drawer} and its compound parts. Each compound part\n * aliases {@link Dialog}'s matching part, since {@link Drawer} renders\n * straight through to {@link Dialog}'s markup.\n */\nexport namespace Drawer {\n\t/**\n\t * Physical edge of the viewport the panel docks against and slides in from.\n\t * `\"left\"`/`\"right\"` name that fixed edge regardless of `dir`;\n\t * `\"top\"`/`\"bottom\"` name the block axis, which already tracks `dir` on its own.\n\t */\n\texport type Placement = \"top\" | \"right\" | \"bottom\" | \"left\";\n\n\t/** Every prop {@link Dialog.Props} accepts, plus `placement`. */\n\texport interface Props extends Dialog.Props {\n\t\t/**\n\t\t * Physical edge of the viewport to dock against and slide in from.\n\t\t * Defaults to {@link DEFAULT_PLACEMENT}.\n\t\t */\n\t\tplacement?: Placement;\n\t}\n\n\t/** Every prop {@link Dialog.HeaderProps} accepts, unchanged. */\n\texport interface HeaderProps extends Dialog.HeaderProps {}\n\n\t/** Every prop {@link Dialog.TitleProps} accepts, unchanged. */\n\texport interface TitleProps extends Dialog.TitleProps {}\n\n\t/** Every prop {@link Dialog.DescriptionProps} accepts, unchanged. */\n\texport interface DescriptionProps extends Dialog.DescriptionProps {}\n\n\t/** Every prop {@link Dialog.FooterProps} accepts, unchanged. */\n\texport interface FooterProps extends Dialog.FooterProps {}\n\n\t/** Every prop {@link Dialog.CloseProps} accepts, unchanged. */\n\texport interface CloseProps extends Dialog.CloseProps {}\n}\n\n/**\n * Renders {@link Dialog} pinned to one edge of the viewport, animating a\n * `transform` off the native `open` attribute so `@starting-style` can\n * animate the close; a `mix` prop composes alongside this placement styling.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props, plus `placement`.\n * @returns The render function producing the docked panel's markup.\n * @example\n * <Button commandfor=\"cart\" command=\"show-modal\">{t(\"cart.open\")}</Button>\n * <Drawer id=\"cart\" placement=\"right\" aria-labelledby=\"cart-title\">\n * \t<Drawer.Header>\n * \t\t<Drawer.Title id=\"cart-title\">{t(\"cart.title\")}</Drawer.Title>\n * \t</Drawer.Header>\n * \t<Drawer.Close commandfor=\"cart\" aria-label={t(\"actions.close\")} />\n * </Drawer>\n * @example\n * <Drawer id=\"filters\" placement=\"bottom\" aria-labelledby=\"filters-title\">\n * \t<Drawer.Header>\n * \t\t<Drawer.Title id=\"filters-title\">{t(\"filters.title\")}</Drawer.Title>\n * \t</Drawer.Header>\n * \t<Drawer.Footer>\n * \t\t<Button commandfor=\"filters\" command=\"close\">{t(\"actions.apply\")}</Button>\n * \t</Drawer.Footer>\n * </Drawer>\n */\nexport function Drawer(handle: Handle<Drawer.Props>) {\n\treturn () => {\n\t\tlet { placement, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_PLACEMENT;\n\n\t\treturn (\n\t\t\t<Dialog\n\t\t\t\t{...rest}\n\t\t\t\tdata-placement={resolvedPlacement}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tfixed(),\n\t\t\t\t\t\tm(0),\n\t\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\t\tenterExit({\n\t\t\t\t\t\t\ttranslate: \"var(--ui-drawer-enter-offset)\",\n\t\t\t\t\t\t\tduration: durations.slow,\n\t\t\t\t\t\t\teasing: easings.decelerate,\n\t\t\t\t\t\t\texit: { translate: \"var(--ui-drawer-exit-offset)\", opacity: 0, blur: EXIT_BLUR_PX },\n\t\t\t\t\t\t\texitDuration: durations.fast,\n\t\t\t\t\t\t\texitEasing: easings.accelerate,\n\t\t\t\t\t\t}),\n\t\t\t\t\t\twillChange(\"translate\"),\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Each placement frees the far edge so the dialog's centring lets go, gives its docked\n\t\t\t\t\t\t * edge a depth, and fills the other axis, since a `<dialog>` sizes to its content on both\n\t\t\t\t\t\t * axes even with opposite insets pinned.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tdata(\"placement\", \"top\", [\n\t\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\t\tinsBe(\"auto\"),\n\t\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\t\tinsIe(\"0\"),\n\t\t\t\t\t\t\tbs(\"24rem\"),\n\t\t\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\t\tmaxIs(\"none\"),\n\t\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"0 -100%\",\n\t\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `0 -${EXIT_DISTANCE}`,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\tdata(\"placement\", \"bottom\", [\n\t\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\t\tinsBs(\"auto\"),\n\t\t\t\t\t\t\tinsIs(\"0\"),\n\t\t\t\t\t\t\tinsIe(\"0\"),\n\t\t\t\t\t\t\tbs(\"24rem\"),\n\t\t\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\t\tmaxIs(\"none\"),\n\t\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"0 100%\",\n\t\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `0 ${EXIT_DISTANCE}`,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\tdata(\"placement\", \"left\", [\n\t\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\t\tinsLeft(\"0\"),\n\t\t\t\t\t\t\tinsRight(\"auto\"),\n\t\t\t\t\t\t\tis(\"22rem\"),\n\t\t\t\t\t\t\tmaxIs(\"90vw\"),\n\t\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\t\tmaxBs(\"none\"),\n\t\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"-100% 0\",\n\t\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `-${EXIT_DISTANCE} 0`,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\n\t\t\t\t\t\tdata(\"placement\", \"right\", [\n\t\t\t\t\t\t\tinsBs(\"0\"),\n\t\t\t\t\t\t\tinsBe(\"0\"),\n\t\t\t\t\t\t\tinsRight(\"0\"),\n\t\t\t\t\t\t\tinsLeft(\"auto\"),\n\t\t\t\t\t\t\tis(\"22rem\"),\n\t\t\t\t\t\t\tmaxIs(\"90vw\"),\n\t\t\t\t\t\t\tbs(\"full\"),\n\t\t\t\t\t\t\tmaxBs(\"none\"),\n\t\t\t\t\t\t\tvars({\n\t\t\t\t\t\t\t\t\"ui-drawer-enter-offset\": \"100% 0\",\n\t\t\t\t\t\t\t\t\"ui-drawer-exit-offset\": `${EXIT_DISTANCE} 0`,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Drawer.HeaderProps.children} as the panel's header slot,\n * routed straight through to {@link Dialog.Header}'s markup.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <Drawer.Header>\n * \t<Drawer.Title>{t(\"cart.title\")}</Drawer.Title>\n * </Drawer.Header>\n */\nDrawer.Header = Dialog.Header;\n\n/**\n * Renders {@link Drawer.TitleProps.children} as the panel's heading:\n * identical to {@link Dialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<h2>`'s props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Drawer.Title>{t(\"cart.title\")}</Drawer.Title>\n */\nDrawer.Title = Dialog.Title;\n\n/**\n * Renders {@link Drawer.DescriptionProps.children} as the panel's supporting\n * copy: identical to {@link Dialog.Description}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Drawer.Description>{t(\"cart.description\")}</Drawer.Description>\n */\nDrawer.Description = Dialog.Description;\n\n/**\n * Renders {@link Drawer.FooterProps.children} as the panel's action row:\n * identical to {@link Dialog.Footer}.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Drawer.Footer>\n * \t<Button commandfor=\"cart\" command=\"close\" variant=\"outline\">{t(\"actions.cancel\")}</Button>\n * \t<Button commandfor=\"cart\" command=\"close\">{t(\"actions.checkout\")}</Button>\n * </Drawer.Footer>\n */\nDrawer.Footer = Dialog.Footer;\n\n/**\n * Renders a dismiss control for the ancestor {@link Drawer} named by\n * `commandfor`: identical to {@link Dialog.Close}.\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 * <Drawer.Close commandfor=\"cart\" aria-label={t(\"actions.close\")} />\n */\nDrawer.Close = Dialog.Close;\n"
|
|
13
13
|
},
|
|
14
14
|
"test": {
|
|
15
15
|
"path": "drawer.test.tsx",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "field-error",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"FieldError"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "field-error.tsx",
|
|
10
|
-
"content": "/**\n * A native form field's validation message, styled at a small size in the\n * danger foreground color. Its host carries a stable id — its own\n * `handle.id` unless a consumer supplies one — ready for a field's control\n * to reference through `aria-describedby`, and a `data-field-error` marker\n * that lets a validation script locate this slot through that same\n * `aria-describedby` list regardless of where it sits in the DOM. It\n * is the foundational error slot every field wrapper composes alongside a\n * label and a control.\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, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\n/**\n * `data-field-error` applied through {@link attrs} unless a consumer\n * overrides it, marking the host as a field's error slot so a validation\n * script can locate it via the field's `aria-describedby` list.\n */\nconst DEFAULT_FIELD_ERROR_ATTRIBUTE = true;\n\n/**\n * Prop types for {@link FieldError}.\n */\nexport namespace FieldError {\n\t/**\n\t * Every native `<span>` attribute plus the `mix` passthrough. `children`\n\t * holds the validation message the consumer supplies, and `id` defaults\n\t * to this component's own `handle.id` when omitted.\n\t */\n\texport interface Props extends TagProps<\"span\"> {}\n}\n\n/**\n * Renders a field's validation message. `id` falls back to `handle.id` so\n * a sibling `aria-describedby` can target it via `data-field-error`; pass\n * `hidden` to keep it out of layout until the field is invalid.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the error message's markup.\n * @example\n * <input id=\"email\" type=\"email\" required aria-describedby=\"email-error\" />\n * <FieldError id=\"email-error\">{t(\"fields.email.required\")}</FieldError>\n * @example\n * <input type=\"email\" required aria-describedby={handle.id} />\n * <FieldError hidden={!errors.email}>{errors.email}</FieldError>\n */\nexport function FieldError(handle: Handle<FieldError.Props>) {\n\treturn () => {\n\t\tlet { id, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<span\n\t\t\t\tid={id ?? handle.id}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ \"data-field-error\": DEFAULT_FIELD_ERROR_ATTRIBUTE }),\n\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tpretty(),\n\t\t\t\t\tmix,\n\t\t\t\t
|
|
10
|
+
"content": "/**\n * A native form field's validation message, styled at a small size in the\n * danger foreground color. Its host carries a stable id — its own\n * `handle.id` unless a consumer supplies one — ready for a field's control\n * to reference through `aria-describedby`, and a `data-field-error` marker\n * that lets a validation script locate this slot through that same\n * `aria-describedby` list regardless of where it sits in the DOM. It\n * is the foundational error slot every field wrapper composes alongside a\n * label and a control.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { fg } from \"@sdxc/u/color\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { pretty, text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\n/**\n * `data-field-error` applied through {@link attrs} unless a consumer\n * overrides it, marking the host as a field's error slot so a validation\n * script can locate it via the field's `aria-describedby` list.\n */\nconst DEFAULT_FIELD_ERROR_ATTRIBUTE = true;\n\n/**\n * Prop types for {@link FieldError}.\n */\nexport namespace FieldError {\n\t/**\n\t * Every native `<span>` attribute plus the `mix` passthrough. `children`\n\t * holds the validation message the consumer supplies, and `id` defaults\n\t * to this component's own `handle.id` when omitted.\n\t */\n\texport interface Props extends TagProps<\"span\"> {}\n}\n\n/**\n * Renders a field's validation message. `id` falls back to `handle.id` so\n * a sibling `aria-describedby` can target it via `data-field-error`; pass\n * `hidden` to keep it out of layout until the field is invalid.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the error message's markup.\n * @example\n * <input id=\"email\" type=\"email\" required aria-describedby=\"email-error\" />\n * <FieldError id=\"email-error\">{t(\"fields.email.required\")}</FieldError>\n * @example\n * <input type=\"email\" required aria-describedby={handle.id} />\n * <FieldError hidden={!errors.email}>{errors.email}</FieldError>\n */\nexport function FieldError(handle: Handle<FieldError.Props>) {\n\treturn () => {\n\t\tlet { id, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<span\n\t\t\t\tid={id ?? handle.id}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ \"data-field-error\": DEFAULT_FIELD_ERROR_ATTRIBUTE }),\n\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\tpretty(),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": null
|
|
13
13
|
}
|
package/registry/ui/form.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "form",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"alert"
|
|
6
6
|
],
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"source": {
|
|
14
14
|
"path": "form.tsx",
|
|
15
|
-
"content": "/**\n * The wrapper every multi-field layout starts from: a native `<form>` laying\n * its children out in a single spaced column, and the point where a parsed\n * validation result enters the tree. Set `issues` from a `parseSafe` (or any\n * other Standard Schema compliant) result and every field beneath it can\n * pick out its own errors by name through component context, with no\n * `issues` prop threaded down by hand.\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 { flex, flexCol, gap } from \"@sdxc/u/layout\";\n\nimport { Alert } from \"@sdxc/ui/alert\";\n\n/** {@link Form.Props.issues} fallback for a first, not-yet-submitted render. */\nconst DEFAULT_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/** Shared empty result {@link Form.Context.getIssues} returns for a field with no matching issue. */\nconst NO_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/**\n * Prop types for {@link Form} and the context value it provides to\n * descendant fields.\n */\nexport namespace Form {\n\t/**\n\t * A single validation failure as reported by a Standard Schema compliant\n\t * validator. `path` locates the field the issue belongs to — a plain key,\n\t * an index, or a `{ key }` segment — or is omitted for a form-level issue.\n\t */\n\texport interface Issue {\n\t\t/** Human-readable failure message, rendered verbatim by a field's `FieldError`. */\n\t\treadonly message: string;\n\t\t/** Field location of the issue, e.g. `[\"email\"]` or `[\"address\", \"zip\"]`. Omitted for a form-level issue. */\n\t\treadonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>;\n\t}\n\n\t/**\n\t * Value {@link Form} stores in component context. A field reads it with\n\t * `handle.context.get(Form)` to find its own issues by name and learn\n\t * whether it's the field that should carry `autofocus` on this render.\n\t */\n\texport interface Context {\n\t\t/**\n\t\t * Every issue whose `path` resolves to `name` (segments joined with\n\t\t * `\".\"`, e.g. `\"address.zip\"`), or an empty array when the field has\n\t\t * none.\n\t\t *\n\t\t * @param name Field name to look up, matching its `name` attribute.\n\t\t * @returns The issues addressed to that field, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetIssues(name: string): ReadonlyArray<Issue>;\n\t\t/**\n\t\t * `true` for the single field name that comes first among\n\t\t * {@link Form.Props.issues}, so exactly one invalid field renders\n\t\t * `autofocus`, landing keyboard focus on it after a server re-render.\n\t\t *\n\t\t * @param name Field name to check, matching its `name` attribute.\n\t\t * @returns Whether `name` is the first invalid field this render.\n\t\t */\n\t\tisFirstInvalid(name: string): boolean;\n\t\t/**\n\t\t * Every issue with no `path` at all — a failure that names no single\n\t\t * field, such as a server-side refusal decided before any field was\n\t\t * reached. {@link Form} already renders these through its own leading\n\t\t * `Alert`; a caller reaches for this only to render them somewhere\n\t\t * else instead.\n\t\t *\n\t\t * @returns The form-level issues, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetFormIssues(): ReadonlyArray<Issue>;\n\t}\n\n\t/**\n\t * Props accepted by {@link Form}.\n\t */\n\texport interface Props extends TagProps<\"form\"> {\n\t\t/**\n\t\t * Validation issues from a `parseSafe` (or equivalent Standard Schema)\n\t\t * result, provided to every descendant field through component\n\t\t * context. Defaults to no issues, matching a first render.\n\t\t *\n\t\t * @example\n\t\t * let result = parseSafe(ContactSchema, await request.formData());\n\t\t * if (!result.success) return ctx.render(<ContactPage issues={result.issues} />, { status: 400 });\n\t\t */\n\t\tissues?: ReadonlyArray<Issue>;\n\t}\n}\n\n/**\n * Resolves the flat field name an issue's `path` addresses, joining every\n * segment with `\".\"` (`[\"address\", \"zip\"]` becomes `\"address.zip\"`).\n *\n * @param path Issue path to resolve, or `undefined` for a form-level issue.\n * @returns The joined field name, or `undefined` when `path` is missing or empty.\n */\nfunction resolveFieldName(path: Form.Issue[\"path\"]): string | undefined {\n\tif (!path || path.length === 0) return undefined;\n\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\n/**\n * Groups `issues` by the field name each one's `path` resolves to. An issue\n * with no path names no field to group under, so {@link Form} reads those\n * separately, through {@link Form.Context.getFormIssues}.\n *\n * @param issues Issues to group, typically {@link Form.Props.issues} as-is.\n * @returns A map from field name to every issue addressed to it, in `issues` order.\n */\nfunction groupIssuesByField(issues: ReadonlyArray<Form.Issue>): Map<string, Form.Issue[]> {\n\tlet byField = new Map<string, Form.Issue[]>();\n\n\tfor (let issue of issues) {\n\t\tlet name = resolveFieldName(issue.path);\n\t\tif (name === undefined) continue;\n\n\t\tlet bucket = byField.get(name);\n\t\tif (bucket) bucket.push(issue);\n\t\telse byField.set(name, [issue]);\n\t}\n\n\treturn byField;\n}\n\n/**\n * Renders a native `<form>` laying children out in a single column, and\n * provides {@link Form.Context} so descendant fields resolve their own\n * issues by name and focus the first invalid field with no client JS. An\n * issue with no `path` names no field to attach to, so it renders as its\n * own leading `Alert` instead of being silently unreachable — a refusal\n * decided before any field was reached still reaches the person filling\n * the form in.\n *\n * @param handle Runtime handle carrying the host `<form>`'s props and providing {@link Form.Context}.\n * @returns The render function producing the form's markup.\n * @example\n * let result = parseSafe(ContactSchema, formData);\n * <Form method=\"post\" issues={result.success ? undefined : result.issues}>\n * <TextField name=\"email\" label={t(\"contact.email\")} />\n * <Button type=\"submit\">{t(\"contact.submit\")}</Button>\n * </Form>\n */\nexport function Form(handle: Handle<Form.Props, Form.Context>) {\n\treturn () => {\n\t\tlet { issues = DEFAULT_ISSUES, mix, children, ...rest } = handle.props;\n\t\tlet byField = groupIssuesByField(issues);\n\t\tlet formIssues = issues.filter((issue) => resolveFieldName(issue.path) === undefined);\n\t\tlet firstInvalidField = issues\n\t\t\t.map((issue) => resolveFieldName(issue.path))\n\t\t\t.find((name) => name !== undefined);\n\n\t\thandle.context.set({\n\t\t\tgetIssues(name) {\n\t\t\t\treturn byField.get(name) ?? NO_ISSUES;\n\t\t\t},\n\t\t\tisFirstInvalid(name) {\n\t\t\t\treturn name === firstInvalidField;\n\t\t\t},\n\t\t\tgetFormIssues() {\n\t\t\t\treturn formIssues;\n\t\t\t},\n\t\t});\n\n\t\treturn (\n\t\t\t<form {...rest} mix={[flex(), flexCol(), gap(4), mix
|
|
15
|
+
"content": "/**\n * The wrapper every multi-field layout starts from: a native `<form>` laying\n * its children out in a single spaced column, and the point where a parsed\n * validation result enters the tree. Set `issues` from a `parseSafe` (or any\n * other Standard Schema compliant) result and every field beneath it can\n * pick out its own errors by name through component context, with no\n * `issues` prop threaded down by hand.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap } from \"@sdxc/u/layout\";\n\nimport { Alert } from \"@sdxc/ui/alert\";\n\n/** {@link Form.Props.issues} fallback for a first, not-yet-submitted render. */\nconst DEFAULT_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/** Shared empty result {@link Form.Context.getIssues} returns for a field with no matching issue. */\nconst NO_ISSUES: ReadonlyArray<Form.Issue> = [];\n\n/**\n * Prop types for {@link Form} and the context value it provides to\n * descendant fields.\n */\nexport namespace Form {\n\t/**\n\t * A single validation failure as reported by a Standard Schema compliant\n\t * validator. `path` locates the field the issue belongs to — a plain key,\n\t * an index, or a `{ key }` segment — or is omitted for a form-level issue.\n\t */\n\texport interface Issue {\n\t\t/** Human-readable failure message, rendered verbatim by a field's `FieldError`. */\n\t\treadonly message: string;\n\t\t/** Field location of the issue, e.g. `[\"email\"]` or `[\"address\", \"zip\"]`. Omitted for a form-level issue. */\n\t\treadonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>;\n\t}\n\n\t/**\n\t * Value {@link Form} stores in component context. A field reads it with\n\t * `handle.context.get(Form)` to find its own issues by name and learn\n\t * whether it's the field that should carry `autofocus` on this render.\n\t */\n\texport interface Context {\n\t\t/**\n\t\t * Every issue whose `path` resolves to `name` (segments joined with\n\t\t * `\".\"`, e.g. `\"address.zip\"`), or an empty array when the field has\n\t\t * none.\n\t\t *\n\t\t * @param name Field name to look up, matching its `name` attribute.\n\t\t * @returns The issues addressed to that field, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetIssues(name: string): ReadonlyArray<Issue>;\n\t\t/**\n\t\t * `true` for the single field name that comes first among\n\t\t * {@link Form.Props.issues}, so exactly one invalid field renders\n\t\t * `autofocus`, landing keyboard focus on it after a server re-render.\n\t\t *\n\t\t * @param name Field name to check, matching its `name` attribute.\n\t\t * @returns Whether `name` is the first invalid field this render.\n\t\t */\n\t\tisFirstInvalid(name: string): boolean;\n\t\t/**\n\t\t * Every issue with no `path` at all — a failure that names no single\n\t\t * field, such as a server-side refusal decided before any field was\n\t\t * reached. {@link Form} already renders these through its own leading\n\t\t * `Alert`; a caller reaches for this only to render them somewhere\n\t\t * else instead.\n\t\t *\n\t\t * @returns The form-level issues, in {@link Form.Props.issues} order.\n\t\t */\n\t\tgetFormIssues(): ReadonlyArray<Issue>;\n\t}\n\n\t/**\n\t * Props accepted by {@link Form}.\n\t */\n\texport interface Props extends TagProps<\"form\"> {\n\t\t/**\n\t\t * Validation issues from a `parseSafe` (or equivalent Standard Schema)\n\t\t * result, provided to every descendant field through component\n\t\t * context. Defaults to no issues, matching a first render.\n\t\t *\n\t\t * @example\n\t\t * let result = parseSafe(ContactSchema, await request.formData());\n\t\t * if (!result.success) return ctx.render(<ContactPage issues={result.issues} />, { status: 400 });\n\t\t */\n\t\tissues?: ReadonlyArray<Issue>;\n\t}\n}\n\n/**\n * Resolves the flat field name an issue's `path` addresses, joining every\n * segment with `\".\"` (`[\"address\", \"zip\"]` becomes `\"address.zip\"`).\n *\n * @param path Issue path to resolve, or `undefined` for a form-level issue.\n * @returns The joined field name, or `undefined` when `path` is missing or empty.\n */\nfunction resolveFieldName(path: Form.Issue[\"path\"]): string | undefined {\n\tif (!path || path.length === 0) return undefined;\n\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\n/**\n * Groups `issues` by the field name each one's `path` resolves to. An issue\n * with no path names no field to group under, so {@link Form} reads those\n * separately, through {@link Form.Context.getFormIssues}.\n *\n * @param issues Issues to group, typically {@link Form.Props.issues} as-is.\n * @returns A map from field name to every issue addressed to it, in `issues` order.\n */\nfunction groupIssuesByField(issues: ReadonlyArray<Form.Issue>): Map<string, Form.Issue[]> {\n\tlet byField = new Map<string, Form.Issue[]>();\n\n\tfor (let issue of issues) {\n\t\tlet name = resolveFieldName(issue.path);\n\t\tif (name === undefined) continue;\n\n\t\tlet bucket = byField.get(name);\n\t\tif (bucket) bucket.push(issue);\n\t\telse byField.set(name, [issue]);\n\t}\n\n\treturn byField;\n}\n\n/**\n * Renders a native `<form>` laying children out in a single column, and\n * provides {@link Form.Context} so descendant fields resolve their own\n * issues by name and focus the first invalid field with no client JS. An\n * issue with no `path` names no field to attach to, so it renders as its\n * own leading `Alert` instead of being silently unreachable — a refusal\n * decided before any field was reached still reaches the person filling\n * the form in.\n *\n * @param handle Runtime handle carrying the host `<form>`'s props and providing {@link Form.Context}.\n * @returns The render function producing the form's markup.\n * @example\n * let result = parseSafe(ContactSchema, formData);\n * <Form method=\"post\" issues={result.success ? undefined : result.issues}>\n * <TextField name=\"email\" label={t(\"contact.email\")} />\n * <Button type=\"submit\">{t(\"contact.submit\")}</Button>\n * </Form>\n */\nexport function Form(handle: Handle<Form.Props, Form.Context>) {\n\treturn () => {\n\t\tlet { issues = DEFAULT_ISSUES, mix, children, ...rest } = handle.props;\n\t\tlet byField = groupIssuesByField(issues);\n\t\tlet formIssues = issues.filter((issue) => resolveFieldName(issue.path) === undefined);\n\t\tlet firstInvalidField = issues\n\t\t\t.map((issue) => resolveFieldName(issue.path))\n\t\t\t.find((name) => name !== undefined);\n\n\t\thandle.context.set({\n\t\t\tgetIssues(name) {\n\t\t\t\treturn byField.get(name) ?? NO_ISSUES;\n\t\t\t},\n\t\t\tisFirstInvalid(name) {\n\t\t\t\treturn name === firstInvalidField;\n\t\t\t},\n\t\t\tgetFormIssues() {\n\t\t\t\treturn formIssues;\n\t\t\t},\n\t\t});\n\n\t\treturn (\n\t\t\t<form {...rest} mix={mergeMix([flex(), flexCol(), gap(4)], mix)}>\n\t\t\t\t{formIssues.length > 0 && (\n\t\t\t\t\t<Alert color=\"danger\" data-slot=\"form-issues\">\n\t\t\t\t\t\t<Alert.Description>\n\t\t\t\t\t\t\t{formIssues.map((issue) => issue.message).join(\" \")}\n\t\t\t\t\t\t</Alert.Description>\n\t\t\t\t\t</Alert>\n\t\t\t\t)}\n\t\t\t\t{children}\n\t\t\t</form>\n\t\t);\n\t};\n}\n\n/**\n * What a field resolved for its own validation state this render, from its\n * own props and from whatever the enclosing {@link Form} knows about it.\n */\nexport interface FieldIssueState {\n\t/** Message the field renders through its `FieldError`, or `undefined` for a field with nothing to report. */\n\terrorMessage: RemixNode | undefined;\n\t/** Whether this is the field that should carry `autofocus`, so focus lands on the first problem after a server round-trip. */\n\tisFirstInvalid: boolean;\n}\n\n/**\n * Reads the {@link Form.Context} provided by the nearest ancestor\n * {@link Form}, resolving to `undefined` when no Form wraps the caller so\n * every field renders safely inside or outside a Form.\n *\n * @param handle Runtime handle of the field performing the lookup.\n * @returns The enclosing form's context, or `undefined` where no Form wraps the caller.\n */\nexport function readFormContext(handle: Handle<unknown, any>): Form.Context | undefined {\n\ttry {\n\t\treturn handle.context.get(Form) as Form.Context | undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves the validation state a field renders: an explicit `errorMessage`\n * always wins over a matching {@link Form} issue for `name`, which is how\n * `Form`'s `issues` reach a field with no per-field prop threaded by hand.\n *\n * @param handle Runtime handle of the field resolving its state.\n * @param name The field's `name` attribute, used to look its issues up.\n * @param errorMessage An `errorMessage` passed directly to the field, if any.\n * @returns The message to render and whether this field carries `autofocus`.\n * @example\n * let { errorMessage, isFirstInvalid } = resolveFieldIssue(handle, \"email\", handle.props.errorMessage);\n */\nexport function resolveFieldIssue(\n\thandle: Handle<unknown, any>,\n\tname: string | undefined,\n\terrorMessage?: RemixNode,\n): FieldIssueState {\n\tif (name === undefined) return { errorMessage, isFirstInvalid: false };\n\n\tlet context = readFormContext(handle);\n\tif (!context) return { errorMessage, isFirstInvalid: false };\n\n\tlet resolved = errorMessage ?? context.getIssues(name)[0]?.message;\n\n\treturn {\n\t\terrorMessage: resolved,\n\t\tisFirstInvalid: Boolean(resolved) && context.isFirstInvalid(name),\n\t};\n}\n"
|
|
16
16
|
},
|
|
17
17
|
"test": {
|
|
18
18
|
"path": "form.test.tsx",
|
package/registry/ui/group.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "group",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Group"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "group.tsx",
|
|
10
|
-
"content": "/**\n * A visual and semantic wrapper binding a cluster of related controls into\n * one unit — a text input paired with its clear button, a row of segmented\n * buttons, a search field with a trailing submit action. The host lays its\n * children out in a single row, joining their edges so the cluster reads as one\n * control, with the seam between two of them drawn structurally rather than\n * through any tracked state.\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 { outlineColor } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { flex, items } from \"@sdxc/u/layout\";\nimport { mis } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\n/**\n * Default ARIA role applied through {@link attrs} unless a consumer\n * overrides `role`; pass `\"region\"` for landmark-worthy content or\n * `\"presentation\"` for purely visual grouping.\n */\nconst DEFAULT_ROLE = \"group\";\n\n/**\n * Prop types for {@link Group}.\n */\nexport namespace Group {\n\t/**\n\t * Native `<div>` attributes plus `mix`. `role` defaults to\n\t * {@link DEFAULT_ROLE} (or `\"region\"`/`\"presentation\"`); `aria-invalid`\n\t * gives the focus ring the danger tone, `aria-disabled` marks it disabled.\n\t */\n\texport interface Props extends TagProps<\"div\"> {}\n}\n\n/**\n * Lays children out in a centered flex row with no border, background, or gap, joining\n * their edges into one shape: only the cluster's outer corners stay round, and the seam\n * two controls share is drawn once. Focus is shown by whichever control holds it.\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 * <Group>\n * \t<Button>{t(\"stepper.decrement\")}</Button>\n * \t<Button>{t(\"stepper.increment\")}</Button>\n * </Group>\n * @example\n * <Group aria-invalid=\"true\">\n * \t<input aria-label={t(\"form.email\")} />\n * \t<Button aria-label={t(\"form.clear\")}>\n * \t\t<XIcon />\n * \t</Button>\n * </Group>\n */\nexport function Group(handle: Handle<Group.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 }),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The controls compose into one shape, so the cluster keeps the rounding on\n\t\t\t\t\t * its own outer corners and the seam where two of them meet is drawn once; the\n\t\t\t\t\t * last control before a trailing `<link rel=\"prefetch\">` hint keeps its corners.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& > *:not(:first-child)\", [\n\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\tmis(\"-1px\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& > *:has(~ :not(link))\", [\n\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t]),\n\t\t\t\t\t/**\n\t\t\t\t\t * Focus shows on the control holding it, naming which control has it where a ring\n\t\t\t\t\t * around the cluster names only the group. That control is raised so its ring\n\t\t\t\t\t * crosses the seam it shares with a neighbour.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& > *:focus-visible\", z(1)),\n\t\t\t\t\twhen('&[aria-invalid=\"true\"] > *:focus-visible', outlineColor(\"danger\")),\n\t\t\t\t\tmix,\n\t\t\t\t
|
|
10
|
+
"content": "/**\n * A visual and semantic wrapper binding a cluster of related controls into\n * one unit — a text input paired with its clear button, a row of segmented\n * buttons, a search field with a trailing submit action. The host lays its\n * children out in a single row, joining their edges so the cluster reads as one\n * control, with the seam between two of them drawn structurally rather than\n * through any tracked state.\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 { outlineColor } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { flex, items } from \"@sdxc/u/layout\";\nimport { mis } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\n/**\n * Default ARIA role applied through {@link attrs} unless a consumer\n * overrides `role`; pass `\"region\"` for landmark-worthy content or\n * `\"presentation\"` for purely visual grouping.\n */\nconst DEFAULT_ROLE = \"group\";\n\n/**\n * Prop types for {@link Group}.\n */\nexport namespace Group {\n\t/**\n\t * Native `<div>` attributes plus `mix`. `role` defaults to\n\t * {@link DEFAULT_ROLE} (or `\"region\"`/`\"presentation\"`); `aria-invalid`\n\t * gives the focus ring the danger tone, `aria-disabled` marks it disabled.\n\t */\n\texport interface Props extends TagProps<\"div\"> {}\n}\n\n/**\n * Lays children out in a centered flex row with no border, background, or gap, joining\n * their edges into one shape: only the cluster's outer corners stay round, and the seam\n * two controls share is drawn once. Focus is shown by whichever control holds it.\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 * <Group>\n * \t<Button>{t(\"stepper.decrement\")}</Button>\n * \t<Button>{t(\"stepper.increment\")}</Button>\n * </Group>\n * @example\n * <Group aria-invalid=\"true\">\n * \t<input aria-label={t(\"form.email\")} />\n * \t<Button aria-label={t(\"form.clear\")}>\n * \t\t<XIcon />\n * \t</Button>\n * </Group>\n */\nexport function Group(handle: Handle<Group.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={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_ROLE }),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The controls compose into one shape, so the cluster keeps the rounding on\n\t\t\t\t\t\t * its own outer corners and the seam where two of them meet is drawn once; the\n\t\t\t\t\t\t * last control before a trailing `<link rel=\"prefetch\">` hint keeps its corners.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:not(:first-child)\", [\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\t\tmis(\"-1px\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"& > *:has(~ :not(link))\", [\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Focus shows on the control holding it, naming which control has it where a ring\n\t\t\t\t\t\t * around the cluster names only the group. That control is raised so its ring\n\t\t\t\t\t\t * crosses the seam it shares with a neighbour.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"& > *:focus-visible\", z(1)),\n\t\t\t\t\t\twhen('&[aria-invalid=\"true\"] > *:focus-visible', outlineColor(\"danger\")),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "group.test.tsx",
|
package/registry/ui/header.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "header",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Header"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "header.tsx",
|
|
10
|
-
"content": "/**\n * A small, muted section label rendered inside a native `<header>` element —\n * the heading that introduces a group of related items inside a listbox,\n * menu, or combobox section. It carries no interactive behavior of its own,\n * only the compact uppercase typography that sets it apart from the items\n * beneath it.\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 { pb, pi } from \"@sdxc/u/size\";\nimport { text, textTransform, tracking, weight } from \"@sdxc/u/typography\";\n\n/**\n * Props accepted by {@link Header}.\n */\nexport namespace Header {\n\t/**\n\t * Native `<header>` attributes plus `mix`. Renders whatever `children`\n\t * the consumer supplies — a section's name, most often plain text.\n\t */\n\texport interface Props extends TagProps<\"header\"> {}\n}\n\n/**\n * Renders its children inside a `<header>` element styled as a small,\n * muted, uppercase section label — the heading introducing a group of\n * related items inside a listbox, menu, or combobox section.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the section label's markup.\n * @example\n * <Header>Fruits</Header>\n */\nexport function Header(handle: Handle<Header.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<header\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpb(1.5),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttracking(\"wider\"),\n\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\ttextTransform(\"uppercase\"),\n\t\t\t\t\tmix,\n\t\t\t\t
|
|
10
|
+
"content": "/**\n * A small, muted section label rendered inside a native `<header>` element —\n * the heading that introduces a group of related items inside a listbox,\n * menu, or combobox section. It carries no interactive behavior of its own,\n * only the compact uppercase typography that sets it apart from the items\n * beneath it.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { fg } from \"@sdxc/u/color\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { text, textTransform, tracking, weight } from \"@sdxc/u/typography\";\n\n/**\n * Props accepted by {@link Header}.\n */\nexport namespace Header {\n\t/**\n\t * Native `<header>` attributes plus `mix`. Renders whatever `children`\n\t * the consumer supplies — a section's name, most often plain text.\n\t */\n\texport interface Props extends TagProps<\"header\"> {}\n}\n\n/**\n * Renders its children inside a `<header>` element styled as a small,\n * muted, uppercase section label — the heading introducing a group of\n * related items inside a listbox, menu, or combobox section.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the section label's markup.\n * @example\n * <Header>Fruits</Header>\n */\nexport function Header(handle: Handle<Header.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<header\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tpb(1.5),\n\t\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\t\ttracking(\"wider\"),\n\t\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\t\ttextTransform(\"uppercase\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": null
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "heading-scope",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"HeadingLevel",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"source": {
|
|
13
13
|
"path": "heading-scope.tsx",
|
|
14
|
-
"content": "/**\n * Establishes an ambient heading level read by nested headings and scopes,\n * keeping a document outline sequential without passing a level by hand.\n * Nesting moves one level deeper unless an explicit `level` fixes it, and\n * renders a `display: contents` host so composing it adds no layout box\n * while still exposing the depth via `data-heading-level`.\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 { contents } from \"@sdxc/u/layout\";\n\n/**\n * Semantic depth, from `1` (`<h1>`) through `6` (`<h6>`), shared by every\n * heading-related component's level resolution.\n */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Native tag rendered for each supported {@link HeadingLevel}, as a single\n * level-to-element lookup table.\n */\nexport const TAG_BY_LEVEL: Record<HeadingLevel, \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\"> = {\n\t1: \"h1\",\n\t2: \"h2\",\n\t3: \"h3\",\n\t4: \"h4\",\n\t5: \"h5\",\n\t6: \"h6\",\n};\n\nconst DEFAULT_LEVEL: HeadingLevel = 1;\n\n/** Deepest semantic depth the native heading elements support; a resolution past this clamps down to it. */\nconst MAX_LEVEL: HeadingLevel = 6;\n\n/**\n * Prop and context types for {@link HeadingScope}.\n */\nexport namespace HeadingScope {\n\t/** Value {@link HeadingScope} provides to descendants through context. */\n\texport interface Context {\n\t\t/** Semantic depth this scope establishes for the headings and nested scopes rendered inside it. */\n\t\tlevel: HeadingLevel;\n\t}\n\n\t/**\n\t * Native `<div>` attributes, plus `mix` and an optional `level` that\n\t * fixes this scope's depth outright, overriding the ambient\n\t * one-level-deeper default.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Explicit semantic depth for this scope. Defaults to one level past\n\t\t * the nearest ancestor scope's depth, or `1` where no scope wraps\n\t\t * this one at all.\n\t\t */\n\t\tlevel?: HeadingLevel;\n\t}\n}\n\n/**\n * Reads the semantic depth from the nearest ancestor {@link HeadingScope},\n * always resolving safely to `undefined` when no ancestor scope exists,\n * regardless of how that absence surfaces.\n *\n * @param handle Runtime handle of the component performing the lookup.\n * @returns The nearest ancestor scope's depth, or `undefined` where nothing wraps the caller.\n * @example\n * let ambient = readAmbientLevel(handle); // 2, nested inside a HeadingScope holding level 2\n */\nexport function readAmbientLevel(handle: Handle<unknown, any>): HeadingLevel | undefined {\n\ttry {\n\t\tlet ambient = handle.context.get(HeadingScope) as HeadingScope.Context | undefined;\n\n\t\treturn ambient?.level;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves the semantic depth a heading renders at: an explicit level wins,\n * then the nearest ancestor {@link HeadingScope}'s depth, then `1`, clamped\n * to `6` with a dev-mode warning to flatten or restart the nesting.\n *\n * @param handle Runtime handle of the component resolving its depth.\n * @param explicitLevel A `level` passed directly to the component, if any.\n * @returns The resolved, clamped {@link HeadingLevel}.\n * @example\n * let level = resolveHeadingLevel(handle, handle.props.level); // an explicit level always wins\n */\nexport function resolveHeadingLevel(\n\thandle: Handle<unknown, any>,\n\texplicitLevel?: HeadingLevel,\n): HeadingLevel {\n\tlet resolved: number = explicitLevel ?? readAmbientLevel(handle) ?? DEFAULT_LEVEL;\n\n\tif (resolved > MAX_LEVEL) {\n\t\tif (import.meta.env?.DEV) {\n\t\t\tconsole.warn(\n\t\t\t\t`Heading nesting resolved to level ${resolved}, past the native \"h1\"–\"h6\" range. Flatten the nesting, or start a new top-level HeadingScope instead of nesting further.`,\n\t\t\t);\n\t\t}\n\n\t\treturn MAX_LEVEL;\n\t}\n\n\treturn resolved as HeadingLevel;\n}\n\n/**\n * Establishes an ambient heading level for descendants: an explicit `level`\n * fixes it, otherwise one level past the nearest ancestor {@link HeadingScope},\n * read before this scope publishes its own depth, or `1` with no ancestor.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link HeadingScope.Context} to descendants.\n * @returns The render function producing the scope's markup.\n * @example\n * <HeadingScope>\n * \t<Heading>Document title</Heading>\n * \t<HeadingScope>\n * \t\t<Heading>Section title</Heading>\n * \t</HeadingScope>\n * </HeadingScope>\n */\nexport function HeadingScope(handle: Handle<HeadingScope.Props, HeadingScope.Context>) {\n\treturn () => {\n\t\tlet { level, mix, ...rest } = handle.props;\n\t\tlet ambient = readAmbientLevel(handle);\n\t\tlet requested = level ?? (ambient === undefined ? undefined : ((ambient + 1) as HeadingLevel));\n\t\tlet resolved = resolveHeadingLevel(handle, requested);\n\n\t\thandle.context.set({ level: resolved });\n\n\t\treturn <div {...rest} data-heading-level={resolved} mix={
|
|
14
|
+
"content": "/**\n * Establishes an ambient heading level read by nested headings and scopes,\n * keeping a document outline sequential without passing a level by hand.\n * Nesting moves one level deeper unless an explicit `level` fixes it, and\n * renders a `display: contents` host so composing it adds no layout box\n * while still exposing the depth via `data-heading-level`.\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 { mergeMix } from \"@sdxc/u/general\";\nimport { contents } from \"@sdxc/u/layout\";\n\n/**\n * Semantic depth, from `1` (`<h1>`) through `6` (`<h6>`), shared by every\n * heading-related component's level resolution.\n */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Native tag rendered for each supported {@link HeadingLevel}, as a single\n * level-to-element lookup table.\n */\nexport const TAG_BY_LEVEL: Record<HeadingLevel, \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\"> = {\n\t1: \"h1\",\n\t2: \"h2\",\n\t3: \"h3\",\n\t4: \"h4\",\n\t5: \"h5\",\n\t6: \"h6\",\n};\n\nconst DEFAULT_LEVEL: HeadingLevel = 1;\n\n/** Deepest semantic depth the native heading elements support; a resolution past this clamps down to it. */\nconst MAX_LEVEL: HeadingLevel = 6;\n\n/**\n * Prop and context types for {@link HeadingScope}.\n */\nexport namespace HeadingScope {\n\t/** Value {@link HeadingScope} provides to descendants through context. */\n\texport interface Context {\n\t\t/** Semantic depth this scope establishes for the headings and nested scopes rendered inside it. */\n\t\tlevel: HeadingLevel;\n\t}\n\n\t/**\n\t * Native `<div>` attributes, plus `mix` and an optional `level` that\n\t * fixes this scope's depth outright, overriding the ambient\n\t * one-level-deeper default.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Explicit semantic depth for this scope. Defaults to one level past\n\t\t * the nearest ancestor scope's depth, or `1` where no scope wraps\n\t\t * this one at all.\n\t\t */\n\t\tlevel?: HeadingLevel;\n\t}\n}\n\n/**\n * Reads the semantic depth from the nearest ancestor {@link HeadingScope},\n * always resolving safely to `undefined` when no ancestor scope exists,\n * regardless of how that absence surfaces.\n *\n * @param handle Runtime handle of the component performing the lookup.\n * @returns The nearest ancestor scope's depth, or `undefined` where nothing wraps the caller.\n * @example\n * let ambient = readAmbientLevel(handle); // 2, nested inside a HeadingScope holding level 2\n */\nexport function readAmbientLevel(handle: Handle<unknown, any>): HeadingLevel | undefined {\n\ttry {\n\t\tlet ambient = handle.context.get(HeadingScope) as HeadingScope.Context | undefined;\n\n\t\treturn ambient?.level;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves the semantic depth a heading renders at: an explicit level wins,\n * then the nearest ancestor {@link HeadingScope}'s depth, then `1`, clamped\n * to `6` with a dev-mode warning to flatten or restart the nesting.\n *\n * @param handle Runtime handle of the component resolving its depth.\n * @param explicitLevel A `level` passed directly to the component, if any.\n * @returns The resolved, clamped {@link HeadingLevel}.\n * @example\n * let level = resolveHeadingLevel(handle, handle.props.level); // an explicit level always wins\n */\nexport function resolveHeadingLevel(\n\thandle: Handle<unknown, any>,\n\texplicitLevel?: HeadingLevel,\n): HeadingLevel {\n\tlet resolved: number = explicitLevel ?? readAmbientLevel(handle) ?? DEFAULT_LEVEL;\n\n\tif (resolved > MAX_LEVEL) {\n\t\tif (import.meta.env?.DEV) {\n\t\t\tconsole.warn(\n\t\t\t\t`Heading nesting resolved to level ${resolved}, past the native \"h1\"–\"h6\" range. Flatten the nesting, or start a new top-level HeadingScope instead of nesting further.`,\n\t\t\t);\n\t\t}\n\n\t\treturn MAX_LEVEL;\n\t}\n\n\treturn resolved as HeadingLevel;\n}\n\n/**\n * Establishes an ambient heading level for descendants: an explicit `level`\n * fixes it, otherwise one level past the nearest ancestor {@link HeadingScope},\n * read before this scope publishes its own depth, or `1` with no ancestor.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link HeadingScope.Context} to descendants.\n * @returns The render function producing the scope's markup.\n * @example\n * <HeadingScope>\n * \t<Heading>Document title</Heading>\n * \t<HeadingScope>\n * \t\t<Heading>Section title</Heading>\n * \t</HeadingScope>\n * </HeadingScope>\n */\nexport function HeadingScope(handle: Handle<HeadingScope.Props, HeadingScope.Context>) {\n\treturn () => {\n\t\tlet { level, mix, ...rest } = handle.props;\n\t\tlet ambient = readAmbientLevel(handle);\n\t\tlet requested = level ?? (ambient === undefined ? undefined : ((ambient + 1) as HeadingLevel));\n\t\tlet resolved = resolveHeadingLevel(handle, requested);\n\n\t\thandle.context.set({ level: resolved });\n\n\t\treturn <div {...rest} data-heading-level={resolved} mix={mergeMix(contents(), mix)} />;\n\t};\n}\n"
|
|
15
15
|
},
|
|
16
16
|
"test": {
|
|
17
17
|
"path": "heading-scope.test.ts",
|
package/registry/ui/heading.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "heading",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"heading-scope"
|
|
6
6
|
],
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "heading.tsx",
|
|
12
|
-
"content": "/**\n * A section title rendered inside the native heading element matching its\n * semantic depth — `<h1>` through `<h6>` — styled at one fixed emphasis size\n * regardless of which level it renders. An explicit `level` prop fixes the\n * depth outright; otherwise, the nearest ancestor `HeadingScope` supplies\n * it, and a heading with no scope wrapping it at all renders as `<h1>`.\n * Choosing a level changes only the document outline the element contributes to\n * assistive technology; its rendered size stays fixed, so nesting sections\n * correctly never requires a visual trade-off. Pass `size=\"display\"` or\n * `size=\"chapter\"` for
|
|
12
|
+
"content": "/**\n * A section title rendered inside the native heading element matching its\n * semantic depth — `<h1>` through `<h6>` — styled at one fixed emphasis size\n * regardless of which level it renders. An explicit `level` prop fixes the\n * depth outright; otherwise, the nearest ancestor `HeadingScope` supplies\n * it, and a heading with no scope wrapping it at all renders as `<h1>`.\n * Choosing a level changes only the document outline the element contributes to\n * assistive technology; its rendered size stays fixed, so nesting sections\n * correctly never requires a visual trade-off. Pass `size=\"display\"` or\n * `size=\"chapter\"` for landing headlines that read the `--ui-landing-*`\n * display tokens (light weight, tight tracking, near-1.0 leading).\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { fg } from \"@sdxc/u/color\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { balance, fontSize, leading, tracking, weight } from \"@sdxc/u/typography\";\n\nimport { displayHeading } from \"@sdxc/ui/styles\";\n\nimport type { HeadingLevel } from \"@sdxc/ui/heading-scope\";\n\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/** Visual size {@link Heading} applies when `size` is omitted. */\nconst DEFAULT_SIZE: Heading.Size = \"default\";\n\n/**\n * Prop types for {@link Heading}.\n */\nexport namespace Heading {\n\t/**\n\t * Semantic depth, from `1` (`<h1>`) through `6` (`<h6>`), mapped to the\n\t * matching native heading element.\n\t */\n\texport type Level = HeadingLevel;\n\n\t/**\n\t * Visual size recipe: the catalog default, a page H1 display scale, or a\n\t * section chapter (~40–48px) from the landing tokens.\n\t */\n\texport type Size = \"default\" | \"display\" | \"chapter\";\n\n\t/**\n\t * Every native heading-element attribute, unchanged, plus the `mix`\n\t * passthrough and a `level` prop choosing which native element the\n\t * heading renders as.\n\t */\n\texport interface Props extends TagProps<\"h1\"> {\n\t\t/**\n\t\t * Semantic depth. Defaults to the nearest ancestor `HeadingScope`'s\n\t\t * depth, or `1` where no scope wraps this heading at all.\n\t\t */\n\t\tlevel?: Level;\n\t\t/**\n\t\t * Visual size recipe. Defaults to {@link DEFAULT_SIZE}. Landing\n\t\t * pages reach for `\"display\"` (H1) or `\"chapter\"` (section H2); app\n\t\t * chrome keeps `\"default\"`.\n\t\t */\n\t\tsize?: Size;\n\t}\n}\n\n/**\n * Renders its children inside the native heading element matching `level`.\n * The default size is semibold, tight-tracked emphasis at `lg`; `\"display\"`\n * and `\"chapter\"` swap in {@link displayHeading} so large landing titles\n * stay light-weighted.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Heading level={1}>Page title</Heading>\n * @example\n * <Heading>Section title</Heading>\n * @example\n * <Heading size=\"chapter\">{t(\"section.title\")}</Heading>\n */\nexport function Heading(handle: Handle<Heading.Props>) {\n\treturn () => {\n\t\tlet { level, mix, size, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle, level);\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\t\tlet isLanding = resolvedSize === \"display\" || resolvedSize === \"chapter\";\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-heading-level={resolved}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tresolvedSize === \"display\" ? displayHeading(1) : [],\n\t\t\t\t\t\tresolvedSize === \"chapter\" ? displayHeading(2) : [],\n\t\t\t\t\t\tisLanding\n\t\t\t\t\t\t\t? []\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\t\t\tfontSize(\"lg\"),\n\t\t\t\t\t\t\t\t\tleading(\"none\"),\n\t\t\t\t\t\t\t\t\tbalance(),\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
13
13
|
},
|
|
14
14
|
"test": {
|
|
15
15
|
"path": "heading.test.tsx",
|
|
16
|
-
"content": "/**\n * Covers {@link Heading} default and
|
|
16
|
+
"content": "/**\n * Covers {@link Heading} default and landing display size recipes.\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 { Heading } from \"@sdxc/ui/heading\";\n\ndescribe(\"Heading\", () => {\n\ttest(\"keeps the default catalog size\", async () => {\n\t\tlet html = await renderToString(<Heading level={2}>Section</Heading>);\n\n\t\texpect(html).toContain(\"<h2\");\n\t\texpect(html).toContain('data-size=\"default\"');\n\t\texpect(html).toContain(\"font-weight: 600\");\n\t});\n\n\ttest(\"applies display and chapter landing recipes\", async () => {\n\t\tlet display = await renderToString(<Heading size=\"display\">Hero</Heading>);\n\t\tlet chapter = await renderToString(\n\t\t\t<Heading size=\"chapter\" level={2}>\n\t\t\t\tChapter\n\t\t\t</Heading>,\n\t\t);\n\n\t\texpect(display).toContain('data-size=\"display\"');\n\t\texpect(display).toContain(\"var(--ui-landing-display-weight\");\n\t\texpect(chapter).toContain('data-size=\"chapter\"');\n\t\texpect(chapter).toContain(\"var(--ui-landing-chapter-size\");\n\t});\n});\n"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "highlight",
|
|
3
|
-
"changedIn": "2026.
|
|
3
|
+
"changedIn": "2026.11.1",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Highlight"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "highlight.tsx",
|
|
10
|
-
"content": "/**\n * Text with the stretches a search matched marked: a run of `{ text, match }` segments\n * rendered as one inline `<span>`, each matched stretch a native `<mark>` tinted through a\n * semantic color role. Segments stay text nodes, so the content is escaped by construction.\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 {
|
|
10
|
+
"content": "/**\n * Text with the stretches a search matched marked: a run of `{ text, match }` segments\n * rendered as one inline `<span>`, each matched stretch a native `<mark>` tinted through a\n * semantic color role. Segments stay text nodes, so the content is escaped by construction.\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 { rounded } from \"@sdxc/u/effects\";\nimport { raw, mergeMix } from \"@sdxc/u/general\";\nimport { data, when } from \"@sdxc/u/state\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link Highlight} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: Highlight.Color = \"brand\";\n\n/**\n * Prop types for {@link Highlight}.\n */\nexport namespace Highlight {\n\t/** Semantic color role the marks are tinted with. */\n\texport type Color = SemanticColor;\n\n\t/** One stretch of the text, and whether the query matched it. */\n\texport interface Segment {\n\t\t/** The stretch exactly as written. */\n\t\ttext: string;\n\t\t/** Whether this stretch is drawn as a `<mark>`. */\n\t\tmatch: boolean;\n\t}\n\n\t/**\n\t * Every native `<span>` attribute except `children`, which the segments replace, plus\n\t * the `mix` passthrough.\n\t */\n\texport interface Props extends Omit<TagProps<\"span\">, \"children\"> {\n\t\t/** The text in order, split where the matches start and end. */\n\t\tsegments: ReadonlyArray<Segment>;\n\t\t/** Semantic color role of the marks. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t}\n}\n\n/**\n * Renders the segments inline, each match as a `<mark>` with a quiet tint behind text\n * that keeps the surrounding color and weight, so a match inside a link still reads as\n * the link. A mark broken across lines keeps its rounded tint on every fragment.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the highlighted text.\n * @example\n * <Highlight segments={[{ text: \"Remix\", match: true }, { text: \" routing\", match: false }]} />\n * @example\n * <Link href={post.href}><Highlight segments={post.title} color=\"warning\" /></Link>\n */\nexport function Highlight(handle: Handle<Highlight.Props>) {\n\treturn () => {\n\t\tlet { color, segments, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-color={color ?? DEFAULT_COLOR}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\twhen(\"& > mark\", [\n\t\t\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tfontWeight: \"inherit\",\n\t\t\t\t\t\t\t\tpaddingInline: \"0.08em\",\n\t\t\t\t\t\t\t\tboxDecorationBreak: \"clone\",\n\t\t\t\t\t\t\t\tWebkitBoxDecorationBreak: \"clone\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"brand\", when(\"& > mark\", markTint(\"brand\"))),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", when(\"& > mark\", markTint(\"neutral\"))),\n\t\t\t\t\t\tdata(\"color\", \"success\", when(\"& > mark\", markTint(\"success\"))),\n\t\t\t\t\t\tdata(\"color\", \"warning\", when(\"& > mark\", markTint(\"warning\"))),\n\t\t\t\t\t\tdata(\"color\", \"danger\", when(\"& > mark\", markTint(\"danger\"))),\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{segments.map((segment) => (segment.match ? <mark>{segment.text}</mark> : segment.text))}\n\t\t\t</span>\n\t\t);\n\t};\n}\n\n/**\n * The tint behind a match: the role's ink at 20%, which reads in light and dark alike\n * where the palette's own tint step fades into the page.\n */\nfunction markTint(role: Highlight.Color) {\n\treturn raw({ backgroundColor: `color-mix(in oklab, var(--ui-${role}-fg) 20%, transparent)` });\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "highlight.test.tsx",
|
|
14
|
-
"content": "/**\n * Tests for the markup and tint {@link Highlight} renders: matches become `<mark>`, every\n * stretch stays escaped text, and the tint follows the color role.\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 { Highlight } from \"@sdxc/ui/highlight\";\n\ndescribe(Highlight.name, () => {\n\ttest(\"marks exactly the matched stretches, in order\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Highlight\n\t\t\t\tsegments={[\n\t\t\t\t\t{ text: \"Learn \", match: false },\n\t\t\t\t\t{ text: \"Remix\", match: true },\n\t\t\t\t\t{ text: \" today\", match: false },\n\t\t\t\t]}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toMatch(/<span data-color=\"brand\"[^>]*>Learn <mark>Remix<\\/mark> today<\\/span>/);\n\t});\n\n\ttest(\"escapes the text of every stretch\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Highlight\n\t\t\t\tsegments={[\n\t\t\t\t\t{ text: \"<b>\", match: true },\n\t\t\t\t\t{ text: \" & co\", match: false },\n\t\t\t\t]}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toContain(\"<mark><b></mark> & co\");\n\t});\n\n\ttest(\"tints the marks with the color role asked for\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Highlight color=\"warning\" segments={[{ text: \"hit\", match: true }]} />,\n\t\t);\n\n\t\texpect(html).toContain('data-color=\"warning\"');\n\t\texpect(html).toContain(\"--ui-warning-
|
|
14
|
+
"content": "/**\n * Tests for the markup and tint {@link Highlight} renders: matches become `<mark>`, every\n * stretch stays escaped text, and the tint follows the color role.\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 { Highlight } from \"@sdxc/ui/highlight\";\n\ndescribe(Highlight.name, () => {\n\ttest(\"marks exactly the matched stretches, in order\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Highlight\n\t\t\t\tsegments={[\n\t\t\t\t\t{ text: \"Learn \", match: false },\n\t\t\t\t\t{ text: \"Remix\", match: true },\n\t\t\t\t\t{ text: \" today\", match: false },\n\t\t\t\t]}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toMatch(/<span data-color=\"brand\"[^>]*>Learn <mark>Remix<\\/mark> today<\\/span>/);\n\t});\n\n\ttest(\"escapes the text of every stretch\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Highlight\n\t\t\t\tsegments={[\n\t\t\t\t\t{ text: \"<b>\", match: true },\n\t\t\t\t\t{ text: \" & co\", match: false },\n\t\t\t\t]}\n\t\t\t/>,\n\t\t);\n\n\t\texpect(html).toContain(\"<mark><b></mark> & co\");\n\t});\n\n\ttest(\"tints the marks with the color role asked for\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Highlight color=\"warning\" segments={[{ text: \"hit\", match: true }]} />,\n\t\t);\n\n\t\texpect(html).toContain('data-color=\"warning\"');\n\t\texpect(html).toContain(\"var(--ui-warning-fg) 20%\");\n\t});\n});\n"
|
|
15
15
|
}
|
|
16
16
|
}
|