@sdxc/kit 2026.10.17 → 2026.10.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -20
- package/changelog.jsonl +1160 -1092
- package/config.schema.json +47 -1
- package/dist/cli.js +12 -0
- package/dist/commands/deploy.d.ts +23 -0
- package/dist/commands/deploy.js +167 -0
- package/dist/commands/destroy.d.ts +22 -0
- package/dist/commands/destroy.js +92 -0
- package/dist/commands/doctor.d.ts +26 -0
- package/dist/commands/doctor.js +65 -0
- package/dist/commands/initializers.d.ts +16 -0
- package/dist/commands/initializers.js +23 -0
- package/dist/commands/make.d.ts +72 -6
- package/dist/commands/make.js +127 -19
- package/dist/commands/middleware.d.ts +16 -0
- package/dist/commands/middleware.js +21 -0
- package/dist/commands/models.d.ts +18 -0
- package/dist/commands/models.js +29 -0
- package/dist/commands/notes.d.ts +17 -0
- package/dist/commands/notes.js +27 -0
- package/dist/commands/routes.d.ts +25 -0
- package/dist/commands/routes.js +50 -0
- package/dist/commands/run.d.ts +16 -0
- package/dist/commands/run.js +32 -11
- package/dist/commands/scaffold.d.ts +29 -0
- package/dist/commands/scaffold.js +33 -0
- package/dist/commands/schedule.d.ts +16 -0
- package/dist/commands/schedule.js +21 -0
- package/dist/commands/stats.d.ts +16 -0
- package/dist/commands/stats.js +21 -0
- package/dist/commands/ui/update.d.ts +6 -3
- package/dist/commands/ui/update.js +24 -7
- package/dist/commands/upgrade.d.ts +3 -1
- package/dist/commands/upgrade.js +88 -23
- package/dist/config.d.ts +18 -0
- package/dist/config.js +28 -1
- package/dist/contract.d.ts +97 -3
- package/dist/contract.js +360 -26
- package/dist/create/templates.js +3 -2
- package/dist/dependencies.d.ts +4 -1
- package/dist/dependencies.js +13 -1
- package/dist/deploy/plan.d.ts +49 -0
- package/dist/deploy/plan.js +68 -0
- package/dist/destroy.d.ts +40 -0
- package/dist/destroy.js +311 -0
- package/dist/doctor/check.d.ts +71 -0
- package/dist/doctor/check.js +53 -0
- package/dist/doctor/checks.d.ts +23 -0
- package/dist/doctor/checks.js +68 -0
- package/dist/doctor/define.d.ts +59 -0
- package/dist/doctor/define.js +16 -0
- package/dist/doctor/emails.d.ts +18 -0
- package/dist/doctor/emails.js +243 -0
- package/dist/doctor/env.d.ts +26 -0
- package/dist/doctor/env.js +88 -0
- package/dist/doctor/files.d.ts +14 -0
- package/dist/doctor/files.js +34 -0
- package/dist/doctor/fixture.d.ts +23 -0
- package/dist/doctor/fixture.js +46 -0
- package/dist/doctor/install.d.ts +17 -0
- package/dist/doctor/install.js +37 -0
- package/dist/doctor/installed.d.ts +11 -0
- package/dist/doctor/installed.js +79 -0
- package/dist/doctor/layout.d.ts +23 -0
- package/dist/doctor/layout.js +83 -0
- package/dist/doctor/migrations.d.ts +16 -0
- package/dist/doctor/migrations.js +96 -0
- package/dist/doctor/models.d.ts +13 -0
- package/dist/doctor/models.js +69 -0
- package/dist/doctor/pins.d.ts +15 -0
- package/dist/doctor/pins.js +79 -0
- package/dist/doctor/project.d.ts +58 -0
- package/dist/doctor/project.js +261 -0
- package/dist/doctor/remix.d.ts +14 -0
- package/dist/doctor/remix.js +44 -0
- package/dist/doctor/routes.d.ts +11 -0
- package/dist/doctor/routes.js +49 -0
- package/dist/doctor/typegen.d.ts +13 -0
- package/dist/doctor/typegen.js +57 -0
- package/dist/doctor/ui.d.ts +14 -0
- package/dist/doctor/ui.js +51 -0
- package/dist/initializers.d.ts +25 -0
- package/dist/initializers.js +89 -0
- package/dist/lock.d.ts +2 -2
- package/dist/make/actions.d.ts +23 -0
- package/dist/make/actions.js +82 -0
- package/dist/make/declare.d.ts +31 -3
- package/dist/make/declare.js +284 -9
- package/dist/make/email.d.ts +23 -0
- package/dist/make/email.js +111 -0
- package/dist/make/from-fields.d.ts +30 -0
- package/dist/make/from-fields.js +162 -0
- package/dist/make/from-model.d.ts +39 -0
- package/dist/make/from-model.js +161 -0
- package/dist/make/generate.d.ts +16 -5
- package/dist/make/generate.js +38 -15
- package/dist/make/guard.d.ts +35 -0
- package/dist/make/guard.js +73 -0
- package/dist/make/imports.d.ts +6 -0
- package/dist/make/imports.js +19 -0
- package/dist/make/index.d.ts +47 -4
- package/dist/make/index.js +287 -29
- package/dist/make/kinds.d.ts +29 -2
- package/dist/make/kinds.js +79 -7
- package/dist/make/mount.d.ts +25 -0
- package/dist/make/mount.js +135 -0
- package/dist/make/schema-diff.d.ts +58 -0
- package/dist/make/schema-diff.js +609 -0
- package/dist/make/schema.d.ts +76 -0
- package/dist/make/schema.js +206 -0
- package/dist/make/stubs.d.ts +7 -5
- package/dist/make/stubs.js +16 -5
- package/dist/make/test.d.ts +43 -0
- package/dist/make/test.js +149 -0
- package/dist/make/trigger.d.ts +31 -0
- package/dist/make/trigger.js +163 -0
- package/dist/models.d.ts +42 -0
- package/dist/models.js +149 -0
- package/dist/notes.d.ts +28 -0
- package/dist/notes.js +66 -0
- package/dist/reference.d.ts +27 -0
- package/dist/reference.js +103 -0
- package/dist/releases.d.ts +9 -0
- package/dist/releases.js +29 -8
- package/dist/routes/chains.d.ts +34 -0
- package/dist/routes/chains.js +95 -0
- package/dist/routes/filter.d.ts +53 -0
- package/dist/routes/filter.js +147 -0
- package/dist/routes/format.d.ts +23 -0
- package/dist/routes/format.js +123 -0
- package/dist/routes/helpers.d.ts +21 -0
- package/dist/routes/helpers.js +165 -0
- package/dist/routes/index.d.ts +56 -0
- package/dist/routes/index.js +167 -0
- package/dist/routes/modules.d.ts +116 -0
- package/dist/routes/modules.js +235 -0
- package/dist/routes/parse.d.ts +161 -0
- package/dist/routes/parse.js +621 -0
- package/dist/routes/routers.d.ts +69 -0
- package/dist/routes/routers.js +327 -0
- package/dist/scaffold/fields.d.ts +129 -0
- package/dist/scaffold/fields.js +421 -0
- package/dist/scaffold/index.d.ts +37 -0
- package/dist/scaffold/index.js +613 -0
- package/dist/scaffold/render.d.ts +51 -0
- package/dist/scaffold/render.js +332 -0
- package/dist/schedule.d.ts +45 -0
- package/dist/schedule.js +124 -0
- package/dist/stats.d.ts +37 -0
- package/dist/stats.js +126 -0
- package/dist/ui/commands.d.ts +10 -3
- package/dist/ui/commands.js +85 -15
- package/dist/ui/registry.d.ts +8 -8
- package/dist/upgrade/agents.d.ts +49 -0
- package/dist/upgrade/agents.js +110 -0
- package/dist/upgrade/changelog.d.ts +2 -2
- package/dist/upgrade/project.d.ts +4 -0
- package/dist/upgrade/project.js +11 -1
- package/dist/upgrade/prompt.d.ts +11 -0
- package/dist/upgrade/prompt.js +50 -7
- package/package.json +6 -4
- package/registry/ui/alert-dialog.json +2 -2
- package/registry/ui/attachment.json +2 -2
- package/registry/ui/calendar.json +2 -2
- package/registry/ui/color-picker.json +2 -2
- package/registry/ui/command.json +2 -2
- package/registry/ui/date-picker.json +2 -2
- package/registry/ui/date-range-picker.json +2 -2
- package/registry/ui/dialog.json +2 -2
- package/registry/ui/file-trigger.json +2 -2
- package/registry/ui/heading-scope.json +2 -2
- package/registry/ui/message-scroller.json +2 -2
- package/registry/ui/number-field.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/resizable.json +2 -2
- package/registry/ui/select.json +2 -2
- package/registry/ui/shared-element.json +2 -2
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.form.stub +2 -2
- package/stubs/controller.form.test.stub +2 -2
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/email.stub +9 -14
- package/stubs/email.test.stub +9 -9
- package/stubs/factory.stub +1 -1
- package/stubs/model.stub +3 -3
- package/stubs/policy.test.stub +34 -8
- package/stubs/scaffold.api.create.stub +34 -0
- package/stubs/scaffold.api.create.test.stub +37 -0
- package/stubs/scaffold.api.destroy.stub +34 -0
- package/stubs/scaffold.api.destroy.test.stub +44 -0
- package/stubs/scaffold.api.index.stub +23 -0
- package/stubs/scaffold.api.index.test.stub +31 -0
- package/stubs/scaffold.api.show.stub +27 -0
- package/stubs/scaffold.api.show.test.stub +41 -0
- package/stubs/scaffold.api.update.stub +44 -0
- package/stubs/scaffold.api.update.test.stub +46 -0
- package/stubs/scaffold.command.create.stub +22 -0
- package/stubs/scaffold.command.create.test.stub +30 -0
- package/stubs/scaffold.command.delete.stub +20 -0
- package/stubs/scaffold.command.delete.test.stub +39 -0
- package/stubs/scaffold.command.list.stub +18 -0
- package/stubs/scaffold.command.list.test.stub +31 -0
- package/stubs/scaffold.command.show.stub +19 -0
- package/stubs/scaffold.command.show.test.stub +37 -0
- package/stubs/scaffold.controller.destroy.stub +35 -0
- package/stubs/scaffold.controller.destroy.test.stub +65 -0
- package/stubs/scaffold.controller.edit.stub +97 -0
- package/stubs/scaffold.controller.edit.test.stub +91 -0
- package/stubs/scaffold.controller.index.stub +55 -0
- package/stubs/scaffold.controller.index.test.stub +32 -0
- package/stubs/scaffold.controller.new.stub +70 -0
- package/stubs/scaffold.controller.new.test.stub +81 -0
- package/stubs/scaffold.controller.show.stub +59 -0
- package/stubs/scaffold.controller.show.test.stub +43 -0
- package/stubs/scaffold.factory.stub +16 -0
- package/stubs/scaffold.form.stub +75 -0
- package/stubs/scaffold.mcp.create.stub +24 -0
- package/stubs/scaffold.mcp.create.test.stub +36 -0
- package/stubs/scaffold.mcp.delete.stub +31 -0
- package/stubs/scaffold.mcp.delete.test.stub +43 -0
- package/stubs/scaffold.mcp.get.stub +21 -0
- package/stubs/scaffold.mcp.get.test.stub +31 -0
- package/stubs/scaffold.mcp.list.stub +23 -0
- package/stubs/scaffold.mcp.list.test.stub +25 -0
- package/stubs/scaffold.mcp.update.stub +37 -0
- package/stubs/scaffold.mcp.update.test.stub +40 -0
- package/stubs/scaffold.migration.stub +2 -0
- package/stubs/scaffold.model.stub +35 -0
- package/stubs/scaffold.model.test.stub +25 -0
- package/stubs/scaffold.test-database.stub +33 -0
- package/stubs/scaffold.test-mcp.stub +92 -0
- package/stubs/scaffold.validator.stub +18 -0
- package/stubs/scaffold.validator.test.stub +26 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +28 -13
- package/templates/app/app/commands/console.test.ts +26 -0
- package/templates/app/app/commands/console.ts +19 -0
- package/templates/app/app/commands/db/fresh.test.ts +57 -0
- package/templates/app/app/commands/db/fresh.ts +37 -0
- package/templates/app/app/commands/db/migrate.test.ts +17 -1
- package/templates/app/app/commands/db/migrate.ts +51 -18
- package/templates/app/app/commands/db/prepare.test.ts +39 -0
- package/templates/app/app/commands/db/prepare.ts +35 -0
- package/templates/app/app/commands/db/seed.test.ts +38 -0
- package/templates/app/app/commands/db/seed.ts +26 -0
- package/templates/app/app/commands/deploy.test.ts +34 -0
- package/templates/app/app/commands/deploy.ts +18 -0
- package/templates/app/app/commands/emails/preview.test.tsx +63 -0
- package/templates/app/app/commands/emails/preview.ts +24 -0
- package/templates/app/app/commands/index.ts +57 -2
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/middleware/access.test.ts +43 -0
- package/templates/app/app/http/middleware/access.ts +41 -0
- package/templates/app/app/http/middleware/api.ts +12 -3
- package/templates/app/app/http/middleware/page.test.ts +4 -1
- package/templates/app/app/http/middleware/page.ts +7 -5
- package/templates/app/app/initializers/cli.ts +28 -2
- package/templates/app/app/initializers/dispatcher.ts +9 -1
- package/templates/app/app/initializers/mail-transport.test.ts +27 -0
- package/templates/app/app/initializers/mail-transport.ts +26 -0
- package/templates/app/app/initializers/mail.test.ts +17 -17
- package/templates/app/app/initializers/mail.ts +15 -7
- package/templates/app/app/initializers/router.test.ts +7 -0
- package/templates/app/app/initializers/router.tsx +13 -3
- package/templates/app/app/jobs/email.test.tsx +70 -0
- package/templates/app/app/jobs/email.ts +16 -0
- package/templates/app/app/jobs/index.ts +6 -2
- package/templates/app/app/policies/abilities.ts +13 -0
- package/templates/app/app/policies/policy.test.ts +15 -0
- package/templates/app/app/policies/policy.ts +30 -0
- package/templates/app/app/services/commands.ts +30 -0
- package/templates/app/app/services/migrations.test.ts +48 -1
- package/templates/app/app/services/migrations.ts +66 -9
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/cloudflare.config.ts +3 -3
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +2 -1
- package/stubs/policy.stub +0 -16
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alert-dialog",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button",
|
|
6
6
|
"dialog",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"source": {
|
|
13
13
|
"path": "alert-dialog.tsx",
|
|
14
|
-
"content": "/**\n * An interruptive modal surface that demands an explicit response before a\n * page continues — confirming a destructive action, surfacing a blocking\n * error — built on the native `<dialog>` host of {@link Dialog}, widened for\n * its two-button layout and sealed against light dismiss. Its compound parts\n * cover a header, title, description, and a two-control footer.\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 { flex, gap, justify, vstack } from \"@sdxc/u/layout\";\nimport { mbs } from \"@sdxc/u/size\";\nimport { balance, pretty, text, weight } from \"@sdxc/u/typography\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { Dialog } from \"@sdxc/ui/dialog\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Invoker Commands verb {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} fall back to when `command` is omitted,\n * dismissing the ancestor AlertDialog named by `commandfor`.\n */\nconst DEFAULT_COMMAND = \"close\";\n\n/**\n * Native `button` `type` {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} always spell out, since the platform runs an\n * Invoker Command only from a button typed `\"button\"`, `<form>` or not.\n */\nconst DEFAULT_TYPE: NonNullable<Button.Props[\"type\"]> = \"button\";\n\n/** Semantic color role {@link AlertDialog.Action} falls back to when `color` is omitted. */\nconst DEFAULT_ACTION_COLOR: Button.Color = \"danger\";\n\n/** Visual weight {@link AlertDialog.Cancel} falls back to when `variant` is omitted. */\nconst DEFAULT_CANCEL_VARIANT: Button.Variant = \"outline\";\n\n/** Semantic color role {@link AlertDialog.Cancel} falls back to when `color` is omitted. */\nconst DEFAULT_CANCEL_COLOR: Button.Color = \"neutral\";\n\n/**\n * Prop types for {@link AlertDialog} and its compound parts.\n */\nexport namespace AlertDialog {\n\t/**\n\t * Every prop {@link Dialog} accepts, minus the ones this component fixes:\n\t * `role` is always `\"alertdialog\"` and `closedby`/`closedBy` always\n\t * `\"closerequest\"`, so the panel closes only on an explicit close request.\n\t */\n\texport interface Props extends Omit<Dialog.Props, \"role\" | \"closedby\" | \"closedBy\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Title}. Every native heading-element\n\t * attribute applies, since the rendered tag follows the nearest ambient\n\t * heading level, falling back to `<h1>`.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Action}: every {@link Button.Props}\n\t * field except `commandfor`/`command`, which this type narrows.\n\t */\n\texport interface ActionProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/**\n\t\t * `id` of the ancestor {@link AlertDialog} this action dismisses.\n\t\t * Required for the default `type=\"button\"` action; a `type=\"submit\"`\n\t\t * action ends the interruption by submitting its enclosing form.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/**\n\t\t * Invoker Commands verb dispatched to the target AlertDialog. Defaults\n\t\t * to `\"close\"`, and is dropped for a `\"submit\"` or `\"reset\"` action,\n\t\t * which the platform drives as a form control instead of an invoker.\n\t\t */\n\t\tcommand?: \"close\";\n\t}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Cancel}: every {@link Button.Props}\n\t * field except `commandfor`/`command`/`type`, which this type narrows.\n\t */\n\texport interface CancelProps extends Omit<Button.Props, \"commandfor\" | \"command\" | \"type\"> {\n\t\t/** `id` of the ancestor {@link AlertDialog} this cancel control dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target AlertDialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\n\t\t/**\n\t\t * Narrowed to the only value a cancel control carries, and always\n\t\t * rendered, since the platform runs its close command only from a\n\t\t * button typed `\"button\"`, including inside a `<form>`.\n\t\t */\n\t\ttype?: \"button\";\n\t}\n}\n\n/**\n * Renders the alert panel through {@link Dialog}, widened to fit a two-button\n * footer, with `role` fixed to `\"alertdialog\"` and `closedby` to\n * `\"closerequest\"` so the interruption clears through an explicit response.\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=\"delete-project\" command=\"show-modal\" color=\"danger\">{t(\"project.delete\")}</Button>\n * <AlertDialog id=\"delete-project\" aria-labelledby=\"delete-project-title\">\n * \t<AlertDialog.Header>\n * \t\t<AlertDialog.Title id=\"delete-project-title\">{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t\t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * \t</AlertDialog.Header>\n * \t<AlertDialog.Footer>\n * \t\t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t\t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * \t</AlertDialog.Footer>\n * </AlertDialog>\n */\nexport function AlertDialog(handle: Handle<AlertDialog.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Dialog {...rest} role=\"alertdialog\" closedby=\"closerequest\" mix={mix}>\n\t\t\t\t{children}\n\t\t\t</Dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link AlertDialog.HeaderProps.children} as the panel's header\n * slot: a column stacking {@link AlertDialog.Title} and\n * {@link AlertDialog.Description} with a small gap between them.\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 * <AlertDialog.Header>\n * \t<AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * </AlertDialog.Header>\n */\nAlertDialog.Header = function AlertDialogHeader(handle: Handle<AlertDialog.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"header\" mix={[vstack({ gap: 2 }), mix]} />;\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.TitleProps.children} as the panel's heading,\n * inside the native heading element matching the nearest ancestor\n * `HeadingScope`'s depth, or `<h1>` where no scope wraps it.\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 * <AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n */\nAlertDialog.Title = function AlertDialogTitle(handle: Handle<AlertDialog.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={[fg(\"neutral.emphasis\"), weight(\"semibold\"), text(\"lg\"), balance(), mix]}\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 AlertDialog.DescriptionProps.children} as the panel's\n * supporting copy, in a native `<p>` set to the panel's muted foreground\n * color so it reads as secondary to {@link AlertDialog.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 * <AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n */\nAlertDialog.Description = function AlertDialogDescription(\n\thandle: Handle<AlertDialog.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[fg(\"neutral.muted\"), text(\"sm\"), pretty(), mix]}>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.FooterProps.children} as an end-aligned action\n * row. Compose {@link AlertDialog.Cancel} before {@link AlertDialog.Action}\n * so the emphasized, potentially destructive control renders last.\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 * <AlertDialog.Footer>\n * \t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * </AlertDialog.Footer>\n */\nAlertDialog.Footer = function AlertDialogFooter(handle: Handle<AlertDialog.FooterProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"footer\" mix={[gap(2), mbs(6), flex(), justify(\"end\"), mix]} />;\n\t};\n};\n\n/**\n * Renders the panel's emphasized action as a danger-toned {@link Button},\n * typed `\"button\"` so its `command=\"close\"` reaches the {@link AlertDialog}\n * named by `commandfor`; `type=\"submit\"` submits the enclosing form instead.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action commandfor=\"publish-post\" color=\"brand\">{t(\"actions.publish\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action type=\"submit\" name=\"intent\" value=\"delete\">{t(\"actions.delete\")}</AlertDialog.Action>\n */\nAlertDialog.Action = function AlertDialogAction(handle: Handle<AlertDialog.ActionProps>) {\n\treturn () => {\n\t\tlet { type, color, command, commandfor, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_TYPE;\n\t\tlet isInvoker = resolvedType === \"button\";\n\t\tlet resolvedColor = color ?? DEFAULT_ACTION_COLOR;\n\n\t\tif (import.meta.env.DEV && isInvoker && !commandfor) {\n\t\t\tconsole.warn(\n\t\t\t\t'AlertDialog.Action: needs \"commandfor\" naming the panel it dismisses, or type=\"submit\" to submit its enclosing form instead — as rendered, pressing it does nothing.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={resolvedType}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommandfor={isInvoker ? commandfor : undefined}\n\t\t\t\tcommand={isInvoker ? (command ?? DEFAULT_COMMAND) : undefined}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's dismiss control as an outline, neutral {@link Button}\n * with `type` fixed to `\"button\"`, so its `command=\"close\"` reaches the\n * {@link AlertDialog} named by `commandfor` from inside a `<form>` too.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the cancel control's markup.\n * @example\n * <AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n */\nAlertDialog.Cancel = function AlertDialogCancel(handle: Handle<AlertDialog.CancelProps>) {\n\treturn () => {\n\t\tlet { variant, color, command, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CANCEL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CANCEL_COLOR;\n\t\tlet resolvedCommand = command ?? DEFAULT_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={DEFAULT_TYPE}\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"cancel\"\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
14
|
+
"content": "/**\n * An interruptive modal surface that demands an explicit response before a\n * page continues — confirming a destructive action, surfacing a blocking\n * error — built on the native `<dialog>` host of {@link Dialog}, widened for\n * its two-button layout and sealed against light dismiss. Its compound parts\n * cover a header, title, description, and a two-control footer.\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 { flex, gap, justify, vstack } from \"@sdxc/u/layout\";\nimport { mbs } from \"@sdxc/u/size\";\nimport { balance, pretty, text, weight } from \"@sdxc/u/typography\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { Dialog } from \"@sdxc/ui/dialog\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Invoker Commands verb {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} fall back to when `command` is omitted,\n * dismissing the ancestor AlertDialog named by `commandfor`.\n */\nconst DEFAULT_COMMAND = \"close\";\n\n/**\n * Native `button` `type` {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} always spell out, since the platform runs an\n * Invoker Command only from a button typed `\"button\"`, `<form>` or not.\n */\nconst DEFAULT_TYPE: NonNullable<Button.Props[\"type\"]> = \"button\";\n\n/** Semantic color role {@link AlertDialog.Action} falls back to when `color` is omitted. */\nconst DEFAULT_ACTION_COLOR: Button.Color = \"danger\";\n\n/** Visual weight {@link AlertDialog.Cancel} falls back to when `variant` is omitted. */\nconst DEFAULT_CANCEL_VARIANT: Button.Variant = \"outline\";\n\n/** Semantic color role {@link AlertDialog.Cancel} falls back to when `color` is omitted. */\nconst DEFAULT_CANCEL_COLOR: Button.Color = \"neutral\";\n\n/**\n * Prop types for {@link AlertDialog} and its compound parts.\n */\nexport namespace AlertDialog {\n\t/**\n\t * Every prop {@link Dialog} accepts, minus the ones this component fixes:\n\t * `role` is always `\"alertdialog\"` and `closedby`/`closedBy` always\n\t * `\"closerequest\"`, so the panel closes only on an explicit close request.\n\t */\n\texport interface Props extends Omit<Dialog.Props, \"role\" | \"closedby\" | \"closedBy\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Title}. Every native heading-element\n\t * attribute applies, since the rendered tag follows the nearest ambient\n\t * heading level, falling back to `<h1>`.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Action}: every {@link Button.Props}\n\t * field except `commandfor`/`command`, which this type narrows.\n\t */\n\texport interface ActionProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/**\n\t\t * `id` of the ancestor {@link AlertDialog} this action dismisses.\n\t\t * Required for the default `type=\"button\"` action; a `type=\"submit\"`\n\t\t * action ends the interruption by submitting its enclosing form.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/**\n\t\t * Invoker Commands verb dispatched to the target AlertDialog. Defaults\n\t\t * to `\"close\"`, and is dropped for a `\"submit\"` or `\"reset\"` action,\n\t\t * which the platform drives as a form control instead of an invoker.\n\t\t */\n\t\tcommand?: \"close\";\n\t}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Cancel}: every {@link Button.Props}\n\t * field except `commandfor`/`command`/`type`, which this type narrows.\n\t */\n\texport interface CancelProps extends Omit<Button.Props, \"commandfor\" | \"command\" | \"type\"> {\n\t\t/** `id` of the ancestor {@link AlertDialog} this cancel control dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target AlertDialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\n\t\t/**\n\t\t * Narrowed to the only value a cancel control carries, and always\n\t\t * rendered, since the platform runs its close command only from a\n\t\t * button typed `\"button\"`, including inside a `<form>`.\n\t\t */\n\t\ttype?: \"button\";\n\t}\n}\n\n/**\n * Renders the alert panel through {@link Dialog}, widened to fit a two-button\n * footer, with `role` fixed to `\"alertdialog\"` and `closedby` to\n * `\"closerequest\"` so the interruption clears through an explicit response.\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=\"delete-project\" command=\"show-modal\" color=\"danger\">{t(\"project.delete\")}</Button>\n * <AlertDialog id=\"delete-project\" aria-labelledby=\"delete-project-title\">\n * \t<AlertDialog.Header>\n * \t\t<AlertDialog.Title id=\"delete-project-title\">{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t\t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * \t</AlertDialog.Header>\n * \t<AlertDialog.Footer>\n * \t\t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t\t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * \t</AlertDialog.Footer>\n * </AlertDialog>\n */\nexport function AlertDialog(handle: Handle<AlertDialog.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Dialog {...rest} role=\"alertdialog\" closedby=\"closerequest\" mix={mix}>\n\t\t\t\t{children}\n\t\t\t</Dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link AlertDialog.HeaderProps.children} as the panel's header\n * slot: a column stacking {@link AlertDialog.Title} and\n * {@link AlertDialog.Description} with a small gap between them.\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 * <AlertDialog.Header>\n * \t<AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * </AlertDialog.Header>\n */\nAlertDialog.Header = function AlertDialogHeader(handle: Handle<AlertDialog.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"header\" mix={[vstack({ gap: 2 }), mix]} />;\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.TitleProps.children} as the panel's heading,\n * inside the native heading element matching the nearest ancestor\n * `HeadingScope`'s depth, or `<h1>` where no scope wraps it.\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 * <AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n */\nAlertDialog.Title = function AlertDialogTitle(handle: Handle<AlertDialog.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={[fg(\"neutral.emphasis\"), weight(\"semibold\"), text(\"lg\"), balance(), mix]}\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 AlertDialog.DescriptionProps.children} as the panel's\n * supporting copy, in a native `<p>` set to the panel's muted foreground\n * color so it reads as secondary to {@link AlertDialog.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 * <AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n */\nAlertDialog.Description = function AlertDialogDescription(\n\thandle: Handle<AlertDialog.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[fg(\"neutral.muted\"), text(\"sm\"), pretty(), mix]}>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.FooterProps.children} as an end-aligned action\n * row. Compose {@link AlertDialog.Cancel} before {@link AlertDialog.Action}\n * so the emphasized, potentially destructive control renders last.\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 * <AlertDialog.Footer>\n * \t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * </AlertDialog.Footer>\n */\nAlertDialog.Footer = function AlertDialogFooter(handle: Handle<AlertDialog.FooterProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"footer\" mix={[gap(2), mbs(6), flex(), justify(\"end\"), mix]} />;\n\t};\n};\n\n/**\n * Renders the panel's emphasized action as a danger-toned {@link Button},\n * typed `\"button\"` so its `command=\"close\"` reaches the {@link AlertDialog}\n * named by `commandfor`; `type=\"submit\"` submits the enclosing form instead.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action commandfor=\"publish-post\" color=\"brand\">{t(\"actions.publish\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action type=\"submit\" name=\"intent\" value=\"delete\">{t(\"actions.delete\")}</AlertDialog.Action>\n */\nAlertDialog.Action = function AlertDialogAction(handle: Handle<AlertDialog.ActionProps>) {\n\treturn () => {\n\t\tlet { type, color, command, commandfor, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_TYPE;\n\t\tlet isInvoker = resolvedType === \"button\";\n\t\tlet resolvedColor = color ?? DEFAULT_ACTION_COLOR;\n\n\t\tif (import.meta.env?.DEV && isInvoker && !commandfor) {\n\t\t\tconsole.warn(\n\t\t\t\t'AlertDialog.Action: needs \"commandfor\" naming the panel it dismisses, or type=\"submit\" to submit its enclosing form instead — as rendered, pressing it does nothing.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={resolvedType}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommandfor={isInvoker ? commandfor : undefined}\n\t\t\t\tcommand={isInvoker ? (command ?? DEFAULT_COMMAND) : undefined}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's dismiss control as an outline, neutral {@link Button}\n * with `type` fixed to `\"button\"`, so its `command=\"close\"` reaches the\n * {@link AlertDialog} named by `commandfor` from inside a `<form>` too.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the cancel control's markup.\n * @example\n * <AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n */\nAlertDialog.Cancel = function AlertDialogCancel(handle: Handle<AlertDialog.CancelProps>) {\n\treturn () => {\n\t\tlet { variant, color, command, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CANCEL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CANCEL_COLOR;\n\t\tlet resolvedCommand = command ?? DEFAULT_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={DEFAULT_TYPE}\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"cancel\"\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
15
15
|
},
|
|
16
16
|
"test": {
|
|
17
17
|
"path": "alert-dialog.test.tsx",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "attachment",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "attachment.tsx",
|
|
12
|
-
"content": "/**\n * A compound card presenting one attached file or image — media preview, name,\n * supporting details, actions — plus a horizontally scrolling row for several\n * cards side by side. Every part styles itself off the card's own `state`, and\n * whole-card click-through stays an opt-in wrapper a consumer mixes in.\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, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tblock,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\thstack,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { overflow, overflowX } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { aspect, bs, fit, is, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign, truncate, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { shimmer } from \"@sdxc/ui/animations\";\nimport { scrollFade } from \"@sdxc/ui/animations\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\nconst DEFAULT_STATE: Attachment.State = \"idle\";\n\n/**\n * Named container {@link Attachment} declares on its own host, so\n * {@link Attachment.Media}, {@link Attachment.Content}, and the inner layout\n * wrapper resolve their width queries against the card itself.\n */\nconst CONTAINER_NAME = \"ui-attachment\";\n\n/**\n * `@container` query every width-adapting part below the root shares: at or\n * under this width the card reflows into a taller tile, the shape\n * {@link Attachment.Group}'s narrow, fixed-width cards need.\n */\nconst NARROW_CONTAINER_QUERY = `@container ${CONTAINER_NAME} (max-width: 12rem)`;\n\n/**\n * Selector fragment gating {@link Attachment.Title}'s shimmer: it matches the\n * title's own `data-state` attribute while that reads `\"uploading\"` or\n * `\"processing\"`, so a title in any other state renders as plain text.\n */\nconst TITLE_SHIMMER_WHEN = ':is([data-state=\"uploading\"], [data-state=\"processing\"])';\n\nconst DEFAULT_ACTION_VARIANT: Button.Variant = \"ghost\";\n\nconst DEFAULT_ACTION_SIZE: Button.Size = \"sm\";\n\nconst DEFAULT_ACTION_COLOR: Button.Color = \"neutral\";\n\n/**\n * Tab-stop order {@link attrs} applies to {@link Attachment.Group} when a\n * consumer supplies no `tabIndex`, so the row itself stays keyboard-reachable\n * and scrollable whatever its cards contain.\n */\nconst DEFAULT_GROUP_TAB_INDEX = 0;\n\nconst GROUP_SCROLL_FADE_SIZE = \"2rem\";\n\n/**\n * Prop types for {@link Attachment} and its compound parts.\n */\nexport namespace Attachment {\n\t/**\n\t * Lifecycle state of a card's file or image. `\"idle\"` and `\"done\"` both\n\t * render as a settled card — `\"idle\"` for a file already on the server,\n\t * `\"done\"` for one whose transfer finished. A consumer owns every transition.\n\t */\n\texport type State = \"idle\" | \"uploading\" | \"processing\" | \"error\" | \"done\";\n\n\t/**\n\t * Props accepted by {@link Attachment}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Lifecycle state of the file or image the card represents. Defaults to `\"idle\"`. */\n\t\tstate?: State;\n\t\t/** The card's compound parts: {@link Attachment.Media}, {@link Attachment.Content}, and {@link Attachment.Actions}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Media}.\n\t */\n\texport interface MediaProps extends TagProps<\"div\"> {\n\t\t/** The preview itself: an `<img>`, or a decorative icon standing in for the file's type. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** {@link Attachment.Title} and, optionally, {@link Attachment.Description}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"p\"> {\n\t\t/**\n\t\t * The ancestor {@link Attachment}'s own `state`, repeated here because a\n\t\t * component reads only its own props; passing the same value to both is\n\t\t * what keeps them in sync. Left unset, the title renders plain.\n\t\t */\n\t\tstate?: Attachment.State;\n\t\t/** The file or image name. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** Supporting detail — a file size, a page count, an error message. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Actions}.\n\t */\n\texport interface ActionsProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment.Action} controls. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Action}: every {@link Button.Props}\n\t * field, unchanged, so an action keeps the same color, weight, and size\n\t * contract as every other button in the catalog.\n\t */\n\texport interface ActionProps extends Button.Props {}\n\n\t/**\n\t * Props accepted by {@link Attachment.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Destination the whole card follows once `attachmentTrigger()` is mixed\n\t\t * in, opened in place unless the activation asks for a new tab. It rides on\n\t\t * a `<div>` so a nested {@link Attachment.Action} stays valid markup.\n\t\t */\n\t\thref?: string;\n\t\t/**\n\t\t * `id` of a `<dialog>` element the whole card opens once\n\t\t * `attachmentTrigger()` is mixed in, instead of following `href`.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/** Invoker Commands verb dispatched to `commandfor`'s dialog. Defaults to `\"show-modal\"`. */\n\t\tcommand?: \"show-modal\";\n\t\t/** Where `href` opens: a window/frame name, or `\"_blank\"` for a new tab. Meaningful only alongside `href`. */\n\t\ttarget?: string;\n\t\t/** The card's own markup — typically an {@link Attachment}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment} or {@link Attachment.Trigger} cards. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The card's outer host, recolored to the danger tint at `state=\"error\"` and\n * declaring the `ui-attachment` named container so nested parts reflow at the\n * card's width. A busy state sets `aria-busy` to the token ARIA recognizes.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the card's markup.\n * @example\n * <Attachment state=\"uploading\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title state=\"uploading\">quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploading\")}</Attachment.Description>\n * \t</Attachment.Content>\n * </Attachment>\n * @example\n * <Attachment state=\"error\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n * \t</Attachment.Content>\n * \t<Attachment.Actions>\n * \t\t<Attachment.Action aria-label={t(\"attachment.retry\")}><RotateCwIcon /></Attachment.Action>\n * \t</Attachment.Actions>\n * </Attachment>\n */\nexport function Attachment(handle: Handle<Attachment.Props>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\t\tlet resolvedState = state ?? DEFAULT_STATE;\n\t\tlet isBusy = resolvedState === \"uploading\" || resolvedState === \"processing\";\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"attachment\"\n\t\t\t\tdata-state={resolvedState}\n\t\t\t\taria-busy={isBusy ? \"true\" : undefined}\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tp(3),\n\t\t\t\t\ttransition(\"border-color, background-color\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\twhen('&[data-state=\"error\"]', [\n\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\tbg(\"danger.tint\"),\n\t\t\t\t\t\tfg(\"danger.emphasis\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\thstack({ gap: 3, align: \"center\" }),\n\t\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [flexCol(), items(\"stretch\")]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The card's media well: a fixed-size, rounded box clipping the preview a\n * consumer nests inside. Inside a narrow container it grows to the card's own\n * inline size at a wider aspect ratio, reading as a thumbnail tile.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the media well's markup.\n * @example\n * <Attachment.Media><img src={file.thumbnailUrl} alt=\"\" /></Attachment.Media>\n * @example\n * <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n */\nAttachment.Media = function AttachmentMedia(handle: Handle<Attachment.MediaProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"media\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(10),\n\t\t\t\t\tbs(10),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\twhen(\"& > img\", [is(\"full\"), bs(\"full\"), fit(\"cover\")]),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [is(\"full\"), bs(\"auto\"), aspect(4, 3), rounded(\"lg\")]),\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 * The card's text column, growing into whatever inline space\n * {@link Attachment.Media} and {@link Attachment.Actions} leave it. Its minimum\n * inline size collapses to `0`, which is what lets its children truncate.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text column's markup.\n * @example\n * <Attachment.Content>\n * \t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t<Attachment.Description>2.4 MB</Attachment.Description>\n * </Attachment.Content>\n */\nAttachment.Content = function AttachmentContent(handle: Handle<Attachment.ContentProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"content\"\n\t\t\t\tmix={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\tminIs(0),\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, textAlign(\"center\")),\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 * The file or image name in a native `<p>`, truncated to a single line with an\n * ellipsis. Given the same `state` as the ancestor {@link Attachment}, it\n * shimmers while that reads `\"uploading\"` or `\"processing\"`, then settles.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the title's markup.\n * @example\n * <Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * @example\n * <Attachment.Title state={attachment.state}>{attachment.name}</Attachment.Title>\n */\nAttachment.Title = function AttachmentTitle(handle: Handle<Attachment.TitleProps>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tdata-state={state}\n\t\t\t\tmix={[\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttruncate(),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The loop settles visible, because this host carries the file's name: a gated\n\t\t\t\t\t * loop rests hidden outside its gate, which suits an element that exists only\n\t\t\t\t\t * as a loading cue and would leave every finished upload unnamed.\n\t\t\t\t\t */\n\t\t\t\t\tshimmer({ when: TITLE_SHIMMER_WHEN, outsideGate: \"visible\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's supporting detail line: a muted, single-line `<p>` carrying a file\n * size, a page count, or the explanation of what went wrong once the ancestor\n * {@link Attachment}'s `state` reads `\"error\"`.\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 * <Attachment.Description>2.4 MB</Attachment.Description>\n * @example\n * <Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n */\nAttachment.Description = function AttachmentDescription(\n\thandle: Handle<Attachment.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[truncate(), fg(\"neutral.muted\"), text(\"xs\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's action row, shrink-proof so a narrow card's width is absorbed by\n * {@link Attachment.Content}'s own truncation while the actions keep their\n * size.\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 * <Attachment.Actions>\n * \t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t<Attachment.Action aria-label={t(\"attachment.remove\")}><XIcon /></Attachment.Action>\n * </Attachment.Actions>\n */\nAttachment.Actions = function AttachmentActions(handle: Handle<Attachment.ActionsProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"actions\" mix={[flex(), shrink(0), items(\"center\"), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A single card action as a {@link Button}, defaulting to a compact, `\"ghost\"`,\n * neutral control so a row of actions reads as secondary to the card's title.\n * Every {@link Button} prop stays available, `type` included.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <Attachment.Action aria-label={t(\"attachment.download\")}>\n * \t<DownloadIcon />\n * </Attachment.Action>\n * @example\n * <Attachment.Action type=\"submit\" name=\"intent\" value=\"retry\" aria-label={t(\"attachment.retry\")}>\n * \t<RotateCwIcon />\n * </Attachment.Action>\n */\nAttachment.Action = function AttachmentAction(handle: Handle<Attachment.ActionProps>) {\n\treturn () => {\n\t\tlet { color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tcolor={color ?? DEFAULT_ACTION_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_ACTION_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_ACTION_SIZE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[shrink(0), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A wrapper `<div>` whose `href` or `commandfor` stays an inert attribute until\n * a consumer mixes in `attachmentTrigger()`. Either one also derives a `role`\n * and `tabIndex`, so whole-card activation is announced and keyboard-reachable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Attachment.Trigger href=\"/files/quarterly-report.pdf\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">\n * \t\t<Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n * \t\t<Attachment.Content>\n * \t\t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t</Attachment.Content>\n * \t\t<Attachment.Actions>\n * \t\t\t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t\t</Attachment.Actions>\n * \t</Attachment>\n * </Attachment.Trigger>\n * @example\n * <Attachment.Trigger commandfor=\"quarterly-report-preview\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">…</Attachment>\n * </Attachment.Trigger>\n * <Dialog id=\"quarterly-report-preview\">…</Dialog>\n */\nAttachment.Trigger = function AttachmentTrigger(handle: Handle<Attachment.TriggerProps>) {\n\treturn () => {\n\t\tlet { href, commandfor, command, target, role, tabIndex, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isConfigured = href !== undefined || commandfor !== undefined;\n\t\tlet resolvedRole = role ?? (href !== undefined ? \"link\" : isConfigured ? \"button\" : undefined);\n\t\tlet resolvedTabIndex = tabIndex ?? (isConfigured ? 0 : undefined);\n\n\t\tif (import.meta.env.DEV && !isConfigured) {\n\t\t\tconsole.warn(\n\t\t\t\t'Attachment.Trigger: rendered with neither \"href\" nor \"commandfor\" — nothing will happen once `attachmentTrigger()` handles an activation.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\trole={resolvedRole}\n\t\t\t\ttabIndex={resolvedTabIndex}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ href, commandfor, command, target }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"inherit\"),\n\t\t\t\t\twhen(\"&[role]:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&[role]:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\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 * A horizontally scroll-snapping row of cards, faded at both inline edges to\n * hint at cards beyond the current view. The row itself carries the tab stop,\n * since the row is what scrolls.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Attachment.Group aria-label={t(\"thread.attachments\")}>\n * \t{attachments.map((attachment) => (\n * \t\t<Attachment key={attachment.id} state={attachment.state}>…</Attachment>\n * \t))}\n * </Attachment.Group>\n */\nAttachment.Group = function AttachmentGroup(handle: Handle<Attachment.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\tdata-slot=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ tabIndex: DEFAULT_GROUP_TAB_INDEX }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(3),\n\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\tscrollPaddingInline: \"0.75rem\",\n\t\t\t\t\t\tscrollBehavior: \"auto\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"& > *\", [shrink(0), raw({ scrollSnapAlign: \"start\" })]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: no-preference)\", raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\tscrollFade({ axis: \"inline\", size: GROUP_SCROLL_FADE_SIZE }),\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 compound card presenting one attached file or image — media preview, name,\n * supporting details, actions — plus a horizontally scrolling row for several\n * cards side by side. Every part styles itself off the card's own `state`, and\n * whole-card click-through stays an opt-in wrapper a consumer mixes in.\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, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tblock,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\thstack,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { overflow, overflowX } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { aspect, bs, fit, is, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign, truncate, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { shimmer } from \"@sdxc/ui/animations\";\nimport { scrollFade } from \"@sdxc/ui/animations\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\nconst DEFAULT_STATE: Attachment.State = \"idle\";\n\n/**\n * Named container {@link Attachment} declares on its own host, so\n * {@link Attachment.Media}, {@link Attachment.Content}, and the inner layout\n * wrapper resolve their width queries against the card itself.\n */\nconst CONTAINER_NAME = \"ui-attachment\";\n\n/**\n * `@container` query every width-adapting part below the root shares: at or\n * under this width the card reflows into a taller tile, the shape\n * {@link Attachment.Group}'s narrow, fixed-width cards need.\n */\nconst NARROW_CONTAINER_QUERY = `@container ${CONTAINER_NAME} (max-width: 12rem)`;\n\n/**\n * Selector fragment gating {@link Attachment.Title}'s shimmer: it matches the\n * title's own `data-state` attribute while that reads `\"uploading\"` or\n * `\"processing\"`, so a title in any other state renders as plain text.\n */\nconst TITLE_SHIMMER_WHEN = ':is([data-state=\"uploading\"], [data-state=\"processing\"])';\n\nconst DEFAULT_ACTION_VARIANT: Button.Variant = \"ghost\";\n\nconst DEFAULT_ACTION_SIZE: Button.Size = \"sm\";\n\nconst DEFAULT_ACTION_COLOR: Button.Color = \"neutral\";\n\n/**\n * Tab-stop order {@link attrs} applies to {@link Attachment.Group} when a\n * consumer supplies no `tabIndex`, so the row itself stays keyboard-reachable\n * and scrollable whatever its cards contain.\n */\nconst DEFAULT_GROUP_TAB_INDEX = 0;\n\nconst GROUP_SCROLL_FADE_SIZE = \"2rem\";\n\n/**\n * Prop types for {@link Attachment} and its compound parts.\n */\nexport namespace Attachment {\n\t/**\n\t * Lifecycle state of a card's file or image. `\"idle\"` and `\"done\"` both\n\t * render as a settled card — `\"idle\"` for a file already on the server,\n\t * `\"done\"` for one whose transfer finished. A consumer owns every transition.\n\t */\n\texport type State = \"idle\" | \"uploading\" | \"processing\" | \"error\" | \"done\";\n\n\t/**\n\t * Props accepted by {@link Attachment}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Lifecycle state of the file or image the card represents. Defaults to `\"idle\"`. */\n\t\tstate?: State;\n\t\t/** The card's compound parts: {@link Attachment.Media}, {@link Attachment.Content}, and {@link Attachment.Actions}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Media}.\n\t */\n\texport interface MediaProps extends TagProps<\"div\"> {\n\t\t/** The preview itself: an `<img>`, or a decorative icon standing in for the file's type. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** {@link Attachment.Title} and, optionally, {@link Attachment.Description}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"p\"> {\n\t\t/**\n\t\t * The ancestor {@link Attachment}'s own `state`, repeated here because a\n\t\t * component reads only its own props; passing the same value to both is\n\t\t * what keeps them in sync. Left unset, the title renders plain.\n\t\t */\n\t\tstate?: Attachment.State;\n\t\t/** The file or image name. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** Supporting detail — a file size, a page count, an error message. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Actions}.\n\t */\n\texport interface ActionsProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment.Action} controls. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Action}: every {@link Button.Props}\n\t * field, unchanged, so an action keeps the same color, weight, and size\n\t * contract as every other button in the catalog.\n\t */\n\texport interface ActionProps extends Button.Props {}\n\n\t/**\n\t * Props accepted by {@link Attachment.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Destination the whole card follows once `attachmentTrigger()` is mixed\n\t\t * in, opened in place unless the activation asks for a new tab. It rides on\n\t\t * a `<div>` so a nested {@link Attachment.Action} stays valid markup.\n\t\t */\n\t\thref?: string;\n\t\t/**\n\t\t * `id` of a `<dialog>` element the whole card opens once\n\t\t * `attachmentTrigger()` is mixed in, instead of following `href`.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/** Invoker Commands verb dispatched to `commandfor`'s dialog. Defaults to `\"show-modal\"`. */\n\t\tcommand?: \"show-modal\";\n\t\t/** Where `href` opens: a window/frame name, or `\"_blank\"` for a new tab. Meaningful only alongside `href`. */\n\t\ttarget?: string;\n\t\t/** The card's own markup — typically an {@link Attachment}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment} or {@link Attachment.Trigger} cards. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The card's outer host, recolored to the danger tint at `state=\"error\"` and\n * declaring the `ui-attachment` named container so nested parts reflow at the\n * card's width. A busy state sets `aria-busy` to the token ARIA recognizes.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the card's markup.\n * @example\n * <Attachment state=\"uploading\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title state=\"uploading\">quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploading\")}</Attachment.Description>\n * \t</Attachment.Content>\n * </Attachment>\n * @example\n * <Attachment state=\"error\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n * \t</Attachment.Content>\n * \t<Attachment.Actions>\n * \t\t<Attachment.Action aria-label={t(\"attachment.retry\")}><RotateCwIcon /></Attachment.Action>\n * \t</Attachment.Actions>\n * </Attachment>\n */\nexport function Attachment(handle: Handle<Attachment.Props>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\t\tlet resolvedState = state ?? DEFAULT_STATE;\n\t\tlet isBusy = resolvedState === \"uploading\" || resolvedState === \"processing\";\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"attachment\"\n\t\t\t\tdata-state={resolvedState}\n\t\t\t\taria-busy={isBusy ? \"true\" : undefined}\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tp(3),\n\t\t\t\t\ttransition(\"border-color, background-color\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\twhen('&[data-state=\"error\"]', [\n\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\tbg(\"danger.tint\"),\n\t\t\t\t\t\tfg(\"danger.emphasis\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\thstack({ gap: 3, align: \"center\" }),\n\t\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [flexCol(), items(\"stretch\")]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The card's media well: a fixed-size, rounded box clipping the preview a\n * consumer nests inside. Inside a narrow container it grows to the card's own\n * inline size at a wider aspect ratio, reading as a thumbnail tile.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the media well's markup.\n * @example\n * <Attachment.Media><img src={file.thumbnailUrl} alt=\"\" /></Attachment.Media>\n * @example\n * <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n */\nAttachment.Media = function AttachmentMedia(handle: Handle<Attachment.MediaProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"media\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(10),\n\t\t\t\t\tbs(10),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\twhen(\"& > img\", [is(\"full\"), bs(\"full\"), fit(\"cover\")]),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [is(\"full\"), bs(\"auto\"), aspect(4, 3), rounded(\"lg\")]),\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 * The card's text column, growing into whatever inline space\n * {@link Attachment.Media} and {@link Attachment.Actions} leave it. Its minimum\n * inline size collapses to `0`, which is what lets its children truncate.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text column's markup.\n * @example\n * <Attachment.Content>\n * \t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t<Attachment.Description>2.4 MB</Attachment.Description>\n * </Attachment.Content>\n */\nAttachment.Content = function AttachmentContent(handle: Handle<Attachment.ContentProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"content\"\n\t\t\t\tmix={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\tminIs(0),\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, textAlign(\"center\")),\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 * The file or image name in a native `<p>`, truncated to a single line with an\n * ellipsis. Given the same `state` as the ancestor {@link Attachment}, it\n * shimmers while that reads `\"uploading\"` or `\"processing\"`, then settles.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the title's markup.\n * @example\n * <Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * @example\n * <Attachment.Title state={attachment.state}>{attachment.name}</Attachment.Title>\n */\nAttachment.Title = function AttachmentTitle(handle: Handle<Attachment.TitleProps>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tdata-state={state}\n\t\t\t\tmix={[\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttruncate(),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The loop settles visible, because this host carries the file's name: a gated\n\t\t\t\t\t * loop rests hidden outside its gate, which suits an element that exists only\n\t\t\t\t\t * as a loading cue and would leave every finished upload unnamed.\n\t\t\t\t\t */\n\t\t\t\t\tshimmer({ when: TITLE_SHIMMER_WHEN, outsideGate: \"visible\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's supporting detail line: a muted, single-line `<p>` carrying a file\n * size, a page count, or the explanation of what went wrong once the ancestor\n * {@link Attachment}'s `state` reads `\"error\"`.\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 * <Attachment.Description>2.4 MB</Attachment.Description>\n * @example\n * <Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n */\nAttachment.Description = function AttachmentDescription(\n\thandle: Handle<Attachment.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[truncate(), fg(\"neutral.muted\"), text(\"xs\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's action row, shrink-proof so a narrow card's width is absorbed by\n * {@link Attachment.Content}'s own truncation while the actions keep their\n * size.\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 * <Attachment.Actions>\n * \t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t<Attachment.Action aria-label={t(\"attachment.remove\")}><XIcon /></Attachment.Action>\n * </Attachment.Actions>\n */\nAttachment.Actions = function AttachmentActions(handle: Handle<Attachment.ActionsProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"actions\" mix={[flex(), shrink(0), items(\"center\"), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A single card action as a {@link Button}, defaulting to a compact, `\"ghost\"`,\n * neutral control so a row of actions reads as secondary to the card's title.\n * Every {@link Button} prop stays available, `type` included.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <Attachment.Action aria-label={t(\"attachment.download\")}>\n * \t<DownloadIcon />\n * </Attachment.Action>\n * @example\n * <Attachment.Action type=\"submit\" name=\"intent\" value=\"retry\" aria-label={t(\"attachment.retry\")}>\n * \t<RotateCwIcon />\n * </Attachment.Action>\n */\nAttachment.Action = function AttachmentAction(handle: Handle<Attachment.ActionProps>) {\n\treturn () => {\n\t\tlet { color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tcolor={color ?? DEFAULT_ACTION_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_ACTION_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_ACTION_SIZE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[shrink(0), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A wrapper `<div>` whose `href` or `commandfor` stays an inert attribute until\n * a consumer mixes in `attachmentTrigger()`. Either one also derives a `role`\n * and `tabIndex`, so whole-card activation is announced and keyboard-reachable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Attachment.Trigger href=\"/files/quarterly-report.pdf\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">\n * \t\t<Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n * \t\t<Attachment.Content>\n * \t\t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t</Attachment.Content>\n * \t\t<Attachment.Actions>\n * \t\t\t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t\t</Attachment.Actions>\n * \t</Attachment>\n * </Attachment.Trigger>\n * @example\n * <Attachment.Trigger commandfor=\"quarterly-report-preview\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">…</Attachment>\n * </Attachment.Trigger>\n * <Dialog id=\"quarterly-report-preview\">…</Dialog>\n */\nAttachment.Trigger = function AttachmentTrigger(handle: Handle<Attachment.TriggerProps>) {\n\treturn () => {\n\t\tlet { href, commandfor, command, target, role, tabIndex, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isConfigured = href !== undefined || commandfor !== undefined;\n\t\tlet resolvedRole = role ?? (href !== undefined ? \"link\" : isConfigured ? \"button\" : undefined);\n\t\tlet resolvedTabIndex = tabIndex ?? (isConfigured ? 0 : undefined);\n\n\t\tif (import.meta.env?.DEV && !isConfigured) {\n\t\t\tconsole.warn(\n\t\t\t\t'Attachment.Trigger: rendered with neither \"href\" nor \"commandfor\" — nothing will happen once `attachmentTrigger()` handles an activation.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\trole={resolvedRole}\n\t\t\t\ttabIndex={resolvedTabIndex}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ href, commandfor, command, target }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"inherit\"),\n\t\t\t\t\twhen(\"&[role]:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&[role]:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\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 * A horizontally scroll-snapping row of cards, faded at both inline edges to\n * hint at cards beyond the current view. The row itself carries the tab stop,\n * since the row is what scrolls.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Attachment.Group aria-label={t(\"thread.attachments\")}>\n * \t{attachments.map((attachment) => (\n * \t\t<Attachment key={attachment.id} state={attachment.state}>…</Attachment>\n * \t))}\n * </Attachment.Group>\n */\nAttachment.Group = function AttachmentGroup(handle: Handle<Attachment.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\tdata-slot=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ tabIndex: DEFAULT_GROUP_TAB_INDEX }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(3),\n\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\tscrollPaddingInline: \"0.75rem\",\n\t\t\t\t\t\tscrollBehavior: \"auto\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"& > *\", [shrink(0), raw({ scrollSnapAlign: \"start\" })]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: no-preference)\", raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\tscrollFade({ axis: \"inline\", size: GROUP_SCROLL_FADE_SIZE }),\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": null
|
|
15
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "calendar",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"heading",
|
|
6
6
|
"input"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "calendar.tsx",
|
|
13
|
-
"content": "/**\n * A month-grid calendar surface composed from a navigable header and a native\n * `<table>` of day cells, styled through the platform's own semantics. Used\n * bare, it renders a native `<input type=\"date\">` — a complete,\n * keyboard-operable date control on its own.\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 { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tborderCollapse,\n\tborderSpacing,\n\tflex,\n\tgrow,\n\tinlineBlock,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { bs, is, mbe, p, pbe } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { scaleX } from \"@sdxc/u/transform\";\nimport {\n\ttabularNums,\n\ttext,\n\ttextAlign,\n\ttextDecoration,\n\tverticalAlign,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport {\n\twarnIfNoAccessibleLabel,\n\twarnIfNoAccessibleName,\n} from \"@sdxc/ui/utils\";\n\nimport { Heading } from \"@sdxc/ui/heading\";\nimport { Input } from \"@sdxc/ui/input\";\n\nconst DEFAULT_COLOR: Calendar.Color = \"neutral\";\n\n/**\n * `type` for {@link Calendar.PreviousButton} and {@link Calendar.NextButton}\n * when a consumer supplies none, keeping a click on either control a plain\n * month change inside a surrounding `<form>`.\n */\nconst DEFAULT_NAV_BUTTON_TYPE: NonNullable<Calendar.PreviousButtonProps[\"type\"]> = \"button\";\n\n/**\n * Prop types for {@link Calendar} and its compound parts.\n */\nexport namespace Calendar {\n\t/**\n\t * Semantic color role for the bare `<input type=\"date\">` fallback's keyboard\n\t * focus ring, each mapped to its matching `--ui-*` variables. The composed\n\t * grid reads fixed semantic roles, identical across every rendered month.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Props accepted by {@link Calendar}. Composing {@link Calendar.Header} and\n\t * {@link Calendar.Grid} as `children` renders the visual month surface;\n\t * `children` left unset renders the native `<input type=\"date\">` fallback.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback control's focus ring. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback control. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a bare fallback control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a bare fallback control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the bare fallback control's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the bare fallback control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the bare fallback control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the bare fallback control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the bare fallback control, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t}\n\n\t/**\n\t * Every native `<header>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderProps extends TagProps<\"header\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_NAV_BUTTON_TYPE}. Needs an `aria-label`\n\t * (e.g. `\"Previous month\"`) as the control's only accessible name.\n\t */\n\texport interface PreviousButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix`\n\t * passthrough, mirroring {@link Calendar.PreviousButton} for the following\n\t * month instead.\n\t */\n\texport interface NextButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every prop {@link Heading} accepts, unchanged. `level` still chooses\n\t * which native heading element renders, defaulting the same way\n\t * {@link Heading} does.\n\t */\n\texport interface HeadingProps extends Heading.Props {}\n\n\t/**\n\t * Every native `<table>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridProps extends TagProps<\"table\"> {}\n\n\t/**\n\t * Every native `<thead>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridHeaderProps extends TagProps<\"thead\"> {}\n\n\t/**\n\t * Every native `<tr>` attribute, unchanged, plus the `mix` passthrough. Holds\n\t * one row of {@link Calendar.HeaderCell} in {@link Calendar.GridHeader}, or\n\t * one week of {@link Calendar.Cell} in {@link Calendar.GridBody}.\n\t */\n\texport interface RowProps extends TagProps<\"tr\"> {}\n\n\t/**\n\t * Every native `<th>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderCellProps extends TagProps<\"th\"> {}\n\n\t/**\n\t * Every native `<tbody>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridBodyProps extends TagProps<\"tbody\"> {}\n\n\t/**\n\t * Every native `<td>` attribute, unchanged, plus the `mix` passthrough. Day\n\t * state is read straight off the rendered element: the consumer sets\n\t * `aria-selected`, `aria-disabled`, `data-unavailable`, `data-outside-month`.\n\t */\n\texport interface CellProps extends TagProps<\"td\"> {}\n}\n\n/**\n * Renders a rounded, padded surface around whichever children a consumer\n * composes; `children` left unset renders a native `<input type=\"date\">`\n * through {@link Input}, the one part the platform itself operates.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the calendar's markup.\n * @example\n * <Calendar aria-label={t(\"form.startDate.label\")} name=\"startDate\" />\n * @example\n * <Calendar aria-label={t(\"calendar.label\")}>\n * \t<Calendar.Header>\n * \t\t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t\t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</Calendar.Header>\n * \t<Calendar.Grid aria-label={monthLabel}>\n * \t\t<Calendar.GridHeader>\n * \t\t\t<Calendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<Calendar.HeaderCell key={day}>{day}</Calendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</Calendar.Row>\n * \t\t</Calendar.GridHeader>\n * \t\t<Calendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<Calendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<Calendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.iso === selected ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-outside-month={day.outsideMonth ? \"\" : undefined}\n * \t\t\t\t\t\t>\n * \t\t\t\t\t\t\t{day.label}\n * \t\t\t\t\t\t</Calendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</Calendar.Row>\n * \t\t\t))}\n * \t\t</Calendar.GridBody>\n * \t</Calendar.Grid>\n * </Calendar>\n */\nexport function Calendar(handle: Handle<Calendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-label\": ariaLabel,\n\t\t\t\"aria-labelledby\": ariaLabelledBy,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\tif (import.meta.env.DEV && !children && !ariaLabel && !ariaLabelledBy) {\n\t\t\tconsole.warn(\n\t\t\t\t'Calendar: falling back to a plain \"input type=date\" needs an \"aria-label\" or \"aria-labelledby\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"calendar\"\n\t\t\t\tmix={[inlineBlock(), rounded(\"lg\"), p(3), bg(\"neutral.tint\"), mix]}\n\t\t\t>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<Input\n\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\t\taria-labelledby={ariaLabelledBy}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Calendar}'s nav row: a flex row spacing\n * {@link Calendar.PreviousButton}, {@link Calendar.Heading}, and\n * {@link Calendar.NextButton} apart, the heading centered between the controls.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the nav row's markup.\n * @example\n * <Calendar.Header>\n * \t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * </Calendar.Header>\n */\nCalendar.Header = function CalendarHeader(handle: Handle<Calendar.HeaderProps>) {\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\tdata-slot=\"header\"\n\t\t\t\tmix={[flex(), items(\"center\"), justify(\"between\"), mbe(4), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the previous month\", sized\n * to match {@link Calendar.NextButton}. Its default chevron flips under\n * `dir=\"rtl\"` through CSS. A `calendarKeys()` mixin drives the behavior.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nCalendar.PreviousButton = function CalendarPreviousButton(\n\thandle: Handle<Calendar.PreviousButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.PreviousButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"previous-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\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\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronLeftIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the following month\", with\n * the rendering, focus, and disabled-state contract of\n * {@link Calendar.PreviousButton} and a trailing chevron by default.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nCalendar.NextButton = function CalendarNextButton(handle: Handle<Calendar.NextButtonProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.NextButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"next-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\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\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronRightIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders the consumer-formatted month/year caption through {@link Heading},\n * centered between the nav controls at a small semibold size layered after\n * {@link Heading}'s own defaults, so this size and alignment win over them.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the caption's markup.\n * @example\n * <Calendar.Heading>{new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\" }).format(visibleMonth)}</Calendar.Heading>\n */\nCalendar.Heading = function CalendarHeading(handle: Handle<Calendar.HeadingProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Heading\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"heading\"\n\t\t\t\tmix={[\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the day grid's native `<table>` host, rows and cells set apart by a\n * small gap on every side. Its `aria-label`/`aria-labelledby` — typically the\n * visible month label — names the whole grid; dev mode warns when it is absent.\n *\n * @param handle Runtime handle carrying the host `<table>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <Calendar.Grid aria-label={monthLabel}>\n * \t<Calendar.GridHeader>...</Calendar.GridHeader>\n * \t<Calendar.GridBody>...</Calendar.GridBody>\n * </Calendar.Grid>\n */\nCalendar.Grid = function CalendarGrid(handle: Handle<Calendar.GridProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Calendar.Grid: needs an \"aria-label\" or \"aria-labelledby\" identifying which month it shows for assistive technology.',\n\t\t);\n\n\t\treturn (\n\t\t\t<table\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"grid\"\n\t\t\t\tmix={[borderCollapse(\"separate\"), borderSpacing(\"0.25rem\"), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<thead>` host: a plain wrapper for the weekday\n * {@link Calendar.Row}.\n *\n * @param handle Runtime handle carrying the host `<thead>`'s props.\n * @returns The render function producing the header section's markup.\n * @example\n * <Calendar.GridHeader>\n * \t<Calendar.Row>\n * \t\t<Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n * \t</Calendar.Row>\n * </Calendar.GridHeader>\n */\nCalendar.GridHeader = function CalendarGridHeader(handle: Handle<Calendar.GridHeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <thead {...rest} data-slot=\"grid-header\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a native `<tr>` host: one row of {@link Calendar.HeaderCell} inside\n * {@link Calendar.GridHeader}, or one week of {@link Calendar.Cell} inside\n * {@link Calendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Calendar.Row>\n * \t<Calendar.Cell>{day.label}</Calendar.Cell>\n * </Calendar.Row>\n */\nCalendar.Row = function CalendarRow(handle: Handle<Calendar.RowProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tr {...rest} data-slot=\"row\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a weekday abbreviation inside a native `<th scope=\"col\">`, sized\n * small and muted beneath {@link Calendar.Cell}'s own larger day numbers.\n *\n * @param handle Runtime handle carrying the host `<th>`'s props.\n * @returns The render function producing the weekday header's markup.\n * @example\n * <Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n */\nCalendar.HeaderCell = function CalendarHeaderCell(handle: Handle<Calendar.HeaderCellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<th\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header-cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ scope: \"col\" }),\n\t\t\t\t\tpbe(2),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<tbody>` host: a plain wrapper for one\n * {@link Calendar.Row} per week.\n *\n * @param handle Runtime handle carrying the host `<tbody>`'s props.\n * @returns The render function producing the body section's markup.\n * @example\n * <Calendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<Calendar.Row key={week[0].iso}>...</Calendar.Row>\n * \t))}\n * </Calendar.GridBody>\n */\nCalendar.GridBody = function CalendarGridBody(handle: Handle<Calendar.GridBodyProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tbody {...rest} data-slot=\"grid-body\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders one calendar day inside a native `<td>`, a fixed round pill around\n * its number. `aria-selected`, `aria-disabled`, `data-unavailable`,\n * `data-outside-month`, and `aria-invalid` each drive their own visual state.\n *\n * @param handle Runtime handle carrying the host `<td>`'s props.\n * @returns The render function producing the day's markup.\n * @example\n * <Calendar.Cell aria-selected={day.iso === selected ? \"true\" : undefined}>\n * \t{day.label}\n * </Calendar.Cell>\n * @example\n * <Calendar.Cell data-outside-month=\"\">{day.label}</Calendar.Cell>\n */\nCalendar.Cell = function CalendarCell(handle: Handle<Calendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<td\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t/**\n\t\t\t\t\t * Table alignment centres the day while the cell stays a table cell in its row; a row\n\t\t\t\t\t * laid out as a flex box turns its cells into blocks, where `align-content` centres the\n\t\t\t\t\t * day. Each declaration answers one of the two cases.\n\t\t\t\t\t */\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tverticalAlign(\"middle\"),\n\t\t\t\t\traw({ alignContent: \"center\" }),\n\t\t\t\t\tis(9),\n\t\t\t\t\tbs(9),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.solid\"), fg(\"brand.onSolid\")]),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [cursor(\"not-allowed\"), opacity(30)]),\n\t\t\t\t\twhen(\"&[data-unavailable]\", [fg(\"neutral.muted\"), textDecoration(\"line-through\")]),\n\t\t\t\t\twhen(\"&[data-outside-month]\", fg(\"neutral.muted\")),\n\t\t\t\t\twhen('&[aria-invalid=\"true\"]', [bg(\"danger.solid\"), fg(\"danger.onSolid\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
"content": "/**\n * A month-grid calendar surface composed from a navigable header and a native\n * `<table>` of day cells, styled through the platform's own semantics. Used\n * bare, it renders a native `<input type=\"date\">` — a complete,\n * keyboard-operable date control on its own.\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 { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tborderCollapse,\n\tborderSpacing,\n\tflex,\n\tgrow,\n\tinlineBlock,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { bs, is, mbe, p, pbe } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { scaleX } from \"@sdxc/u/transform\";\nimport {\n\ttabularNums,\n\ttext,\n\ttextAlign,\n\ttextDecoration,\n\tverticalAlign,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport {\n\twarnIfNoAccessibleLabel,\n\twarnIfNoAccessibleName,\n} from \"@sdxc/ui/utils\";\n\nimport { Heading } from \"@sdxc/ui/heading\";\nimport { Input } from \"@sdxc/ui/input\";\n\nconst DEFAULT_COLOR: Calendar.Color = \"neutral\";\n\n/**\n * `type` for {@link Calendar.PreviousButton} and {@link Calendar.NextButton}\n * when a consumer supplies none, keeping a click on either control a plain\n * month change inside a surrounding `<form>`.\n */\nconst DEFAULT_NAV_BUTTON_TYPE: NonNullable<Calendar.PreviousButtonProps[\"type\"]> = \"button\";\n\n/**\n * Prop types for {@link Calendar} and its compound parts.\n */\nexport namespace Calendar {\n\t/**\n\t * Semantic color role for the bare `<input type=\"date\">` fallback's keyboard\n\t * focus ring, each mapped to its matching `--ui-*` variables. The composed\n\t * grid reads fixed semantic roles, identical across every rendered month.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Props accepted by {@link Calendar}. Composing {@link Calendar.Header} and\n\t * {@link Calendar.Grid} as `children` renders the visual month surface;\n\t * `children` left unset renders the native `<input type=\"date\">` fallback.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback control's focus ring. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback control. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a bare fallback control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a bare fallback control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the bare fallback control's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the bare fallback control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the bare fallback control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the bare fallback control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the bare fallback control, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t}\n\n\t/**\n\t * Every native `<header>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderProps extends TagProps<\"header\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_NAV_BUTTON_TYPE}. Needs an `aria-label`\n\t * (e.g. `\"Previous month\"`) as the control's only accessible name.\n\t */\n\texport interface PreviousButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix`\n\t * passthrough, mirroring {@link Calendar.PreviousButton} for the following\n\t * month instead.\n\t */\n\texport interface NextButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every prop {@link Heading} accepts, unchanged. `level` still chooses\n\t * which native heading element renders, defaulting the same way\n\t * {@link Heading} does.\n\t */\n\texport interface HeadingProps extends Heading.Props {}\n\n\t/**\n\t * Every native `<table>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridProps extends TagProps<\"table\"> {}\n\n\t/**\n\t * Every native `<thead>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridHeaderProps extends TagProps<\"thead\"> {}\n\n\t/**\n\t * Every native `<tr>` attribute, unchanged, plus the `mix` passthrough. Holds\n\t * one row of {@link Calendar.HeaderCell} in {@link Calendar.GridHeader}, or\n\t * one week of {@link Calendar.Cell} in {@link Calendar.GridBody}.\n\t */\n\texport interface RowProps extends TagProps<\"tr\"> {}\n\n\t/**\n\t * Every native `<th>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderCellProps extends TagProps<\"th\"> {}\n\n\t/**\n\t * Every native `<tbody>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridBodyProps extends TagProps<\"tbody\"> {}\n\n\t/**\n\t * Every native `<td>` attribute, unchanged, plus the `mix` passthrough. Day\n\t * state is read straight off the rendered element: the consumer sets\n\t * `aria-selected`, `aria-disabled`, `data-unavailable`, `data-outside-month`.\n\t */\n\texport interface CellProps extends TagProps<\"td\"> {}\n}\n\n/**\n * Renders a rounded, padded surface around whichever children a consumer\n * composes; `children` left unset renders a native `<input type=\"date\">`\n * through {@link Input}, the one part the platform itself operates.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the calendar's markup.\n * @example\n * <Calendar aria-label={t(\"form.startDate.label\")} name=\"startDate\" />\n * @example\n * <Calendar aria-label={t(\"calendar.label\")}>\n * \t<Calendar.Header>\n * \t\t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t\t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</Calendar.Header>\n * \t<Calendar.Grid aria-label={monthLabel}>\n * \t\t<Calendar.GridHeader>\n * \t\t\t<Calendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<Calendar.HeaderCell key={day}>{day}</Calendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</Calendar.Row>\n * \t\t</Calendar.GridHeader>\n * \t\t<Calendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<Calendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<Calendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.iso === selected ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-outside-month={day.outsideMonth ? \"\" : undefined}\n * \t\t\t\t\t\t>\n * \t\t\t\t\t\t\t{day.label}\n * \t\t\t\t\t\t</Calendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</Calendar.Row>\n * \t\t\t))}\n * \t\t</Calendar.GridBody>\n * \t</Calendar.Grid>\n * </Calendar>\n */\nexport function Calendar(handle: Handle<Calendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-label\": ariaLabel,\n\t\t\t\"aria-labelledby\": ariaLabelledBy,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\tif (import.meta.env?.DEV && !children && !ariaLabel && !ariaLabelledBy) {\n\t\t\tconsole.warn(\n\t\t\t\t'Calendar: falling back to a plain \"input type=date\" needs an \"aria-label\" or \"aria-labelledby\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"calendar\"\n\t\t\t\tmix={[inlineBlock(), rounded(\"lg\"), p(3), bg(\"neutral.tint\"), mix]}\n\t\t\t>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<Input\n\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\t\taria-labelledby={ariaLabelledBy}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Calendar}'s nav row: a flex row spacing\n * {@link Calendar.PreviousButton}, {@link Calendar.Heading}, and\n * {@link Calendar.NextButton} apart, the heading centered between the controls.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the nav row's markup.\n * @example\n * <Calendar.Header>\n * \t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * </Calendar.Header>\n */\nCalendar.Header = function CalendarHeader(handle: Handle<Calendar.HeaderProps>) {\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\tdata-slot=\"header\"\n\t\t\t\tmix={[flex(), items(\"center\"), justify(\"between\"), mbe(4), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the previous month\", sized\n * to match {@link Calendar.NextButton}. Its default chevron flips under\n * `dir=\"rtl\"` through CSS. A `calendarKeys()` mixin drives the behavior.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nCalendar.PreviousButton = function CalendarPreviousButton(\n\thandle: Handle<Calendar.PreviousButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.PreviousButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"previous-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\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\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronLeftIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the following month\", with\n * the rendering, focus, and disabled-state contract of\n * {@link Calendar.PreviousButton} and a trailing chevron by default.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nCalendar.NextButton = function CalendarNextButton(handle: Handle<Calendar.NextButtonProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.NextButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"next-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\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\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronRightIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders the consumer-formatted month/year caption through {@link Heading},\n * centered between the nav controls at a small semibold size layered after\n * {@link Heading}'s own defaults, so this size and alignment win over them.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the caption's markup.\n * @example\n * <Calendar.Heading>{new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\" }).format(visibleMonth)}</Calendar.Heading>\n */\nCalendar.Heading = function CalendarHeading(handle: Handle<Calendar.HeadingProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Heading\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"heading\"\n\t\t\t\tmix={[\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the day grid's native `<table>` host, rows and cells set apart by a\n * small gap on every side. Its `aria-label`/`aria-labelledby` — typically the\n * visible month label — names the whole grid; dev mode warns when it is absent.\n *\n * @param handle Runtime handle carrying the host `<table>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <Calendar.Grid aria-label={monthLabel}>\n * \t<Calendar.GridHeader>...</Calendar.GridHeader>\n * \t<Calendar.GridBody>...</Calendar.GridBody>\n * </Calendar.Grid>\n */\nCalendar.Grid = function CalendarGrid(handle: Handle<Calendar.GridProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Calendar.Grid: needs an \"aria-label\" or \"aria-labelledby\" identifying which month it shows for assistive technology.',\n\t\t);\n\n\t\treturn (\n\t\t\t<table\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"grid\"\n\t\t\t\tmix={[borderCollapse(\"separate\"), borderSpacing(\"0.25rem\"), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<thead>` host: a plain wrapper for the weekday\n * {@link Calendar.Row}.\n *\n * @param handle Runtime handle carrying the host `<thead>`'s props.\n * @returns The render function producing the header section's markup.\n * @example\n * <Calendar.GridHeader>\n * \t<Calendar.Row>\n * \t\t<Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n * \t</Calendar.Row>\n * </Calendar.GridHeader>\n */\nCalendar.GridHeader = function CalendarGridHeader(handle: Handle<Calendar.GridHeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <thead {...rest} data-slot=\"grid-header\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a native `<tr>` host: one row of {@link Calendar.HeaderCell} inside\n * {@link Calendar.GridHeader}, or one week of {@link Calendar.Cell} inside\n * {@link Calendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Calendar.Row>\n * \t<Calendar.Cell>{day.label}</Calendar.Cell>\n * </Calendar.Row>\n */\nCalendar.Row = function CalendarRow(handle: Handle<Calendar.RowProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tr {...rest} data-slot=\"row\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a weekday abbreviation inside a native `<th scope=\"col\">`, sized\n * small and muted beneath {@link Calendar.Cell}'s own larger day numbers.\n *\n * @param handle Runtime handle carrying the host `<th>`'s props.\n * @returns The render function producing the weekday header's markup.\n * @example\n * <Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n */\nCalendar.HeaderCell = function CalendarHeaderCell(handle: Handle<Calendar.HeaderCellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<th\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header-cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ scope: \"col\" }),\n\t\t\t\t\tpbe(2),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<tbody>` host: a plain wrapper for one\n * {@link Calendar.Row} per week.\n *\n * @param handle Runtime handle carrying the host `<tbody>`'s props.\n * @returns The render function producing the body section's markup.\n * @example\n * <Calendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<Calendar.Row key={week[0].iso}>...</Calendar.Row>\n * \t))}\n * </Calendar.GridBody>\n */\nCalendar.GridBody = function CalendarGridBody(handle: Handle<Calendar.GridBodyProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tbody {...rest} data-slot=\"grid-body\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders one calendar day inside a native `<td>`, a fixed round pill around\n * its number. `aria-selected`, `aria-disabled`, `data-unavailable`,\n * `data-outside-month`, and `aria-invalid` each drive their own visual state.\n *\n * @param handle Runtime handle carrying the host `<td>`'s props.\n * @returns The render function producing the day's markup.\n * @example\n * <Calendar.Cell aria-selected={day.iso === selected ? \"true\" : undefined}>\n * \t{day.label}\n * </Calendar.Cell>\n * @example\n * <Calendar.Cell data-outside-month=\"\">{day.label}</Calendar.Cell>\n */\nCalendar.Cell = function CalendarCell(handle: Handle<Calendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<td\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t/**\n\t\t\t\t\t * Table alignment centres the day while the cell stays a table cell in its row; a row\n\t\t\t\t\t * laid out as a flex box turns its cells into blocks, where `align-content` centres the\n\t\t\t\t\t * day. Each declaration answers one of the two cases.\n\t\t\t\t\t */\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tverticalAlign(\"middle\"),\n\t\t\t\t\traw({ alignContent: \"center\" }),\n\t\t\t\t\tis(9),\n\t\t\t\t\tbs(9),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.solid\"), fg(\"brand.onSolid\")]),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [cursor(\"not-allowed\"), opacity(30)]),\n\t\t\t\t\twhen(\"&[data-unavailable]\", [fg(\"neutral.muted\"), textDecoration(\"line-through\")]),\n\t\t\t\t\twhen(\"&[data-outside-month]\", fg(\"neutral.muted\")),\n\t\t\t\t\twhen('&[aria-invalid=\"true\"]', [bg(\"danger.solid\"), fg(\"danger.onSolid\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
14
14
|
},
|
|
15
15
|
"test": null
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "color-picker",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"color-field",
|
|
6
6
|
"color-swatch",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"source": {
|
|
13
13
|
"path": "color-picker.tsx",
|
|
14
|
-
"content": "/**\n * A labeled color field composing {@link ColorField}'s plain fallback with\n * an optional {@link ColorPicker.Group} trigger row and\n * {@link ColorPicker.Dialog} picking surface swapped in via `children`.\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 { outline } from \"@sdxc/u/color\";\nimport { opacity, rounded, transition } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { hstack, inlineFlex, items, justify, relative, shrink, vstack } from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { ColorField } from \"@sdxc/ui/color-field\";\nimport { ColorSwatch } from \"@sdxc/ui/color-swatch\";\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Native `<button>` `type` {@link ColorPicker.Trigger} falls back to,\n * keeping an omitted `type` from implicitly submitting an enclosing\n * `<form>` the way a bare `<button>` would.\n */\nconst DEFAULT_BUTTON_TYPE: NonNullable<ColorPicker.TriggerProps[\"type\"]> = \"button\";\n\n/**\n * Shape variant {@link ColorPicker.Trigger} falls back to when `shape` is\n * omitted, mirroring {@link ColorSwatch}'s own default so a trigger left\n * unstyled reads the same as a bare swatch.\n */\nconst DEFAULT_TRIGGER_SHAPE: ColorSwatch.Shape = \"rounded\";\n\n/**\n * `role` applied to {@link ColorPicker.Dialog}'s host through {@link attrs}\n * unless a consumer supplies its own `role`, identifying the surface as a\n * non-modal dialog layered above the page rather than a full-screen modal.\n */\nconst DEFAULT_DIALOG_ROLE = \"dialog\";\n\n/**\n * Side of the trigger {@link ColorPicker.Dialog} renders against when\n * `placement` is left unset, reading down and start-ward the way a dropdown\n * conventionally does.\n */\nconst DEFAULT_DIALOG_PLACEMENT: Popover.Placement = \"bottom-start\";\n\n/**\n * Prop types for {@link ColorPicker} and its compound parts.\n */\nexport namespace ColorPicker {\n\t/**\n\t * Semantic color role for the fallback field's keyboard focus ring,\n\t * mirroring {@link ColorField.Color}. The composed layout carries no\n\t * `color` prop of its own, since a consumer renders it directly.\n\t */\n\texport type Color = ColorField.Color;\n\n\t/**\n\t * Every prop {@link ColorField.PartsProps} accepts, unchanged, applied\n\t * only to the fallback field's internally composed parts — the composed\n\t * layout styles its own parts individually instead.\n\t */\n\texport interface PartsProps extends ColorField.PartsProps {}\n\n\t/**\n\t * Props accepted by {@link ColorPicker}. Leaving `children` unset renders\n\t * {@link ColorField}'s plain fallback using every field below; composing\n\t * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} instead skips them.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback field's focus ring. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The fallback field's caption, rendered through {@link ColorField}. Read only when `children` is unset. */\n\t\tlabel?: RemixNode;\n\t\t/** Supporting copy beneath the fallback field. Read only when `children` is unset. */\n\t\tdescription?: RemixNode;\n\t\t/** Validation message beneath the fallback field. Read only when `children` is unset. */\n\t\terrorMessage?: RemixNode;\n\t\t/** Notation the fallback field's typed entry is constrained to. Read only when `children` is unset. */\n\t\tformat?: ColorField.Format;\n\t\t/** Native `name` submitted with an enclosing form, read only by the fallback field. */\n\t\tname?: string;\n\t\t/** Current value, as a literal color string, for a fallback field a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, as a literal color string, for a fallback field left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Placeholder copy shown while the fallback field is empty. */\n\t\tplaceholder?: string;\n\t\t/** Marks the fallback field required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the fallback field inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the fallback field's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the fallback field. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback field's internally composed parts. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The trigger-and-panel layout — typically a `Label`,\n\t\t * {@link ColorPicker.Group}, and {@link ColorPicker.Dialog} — rendered in\n\t\t * place of {@link ColorField}'s plain fallback. Unset renders that fallback.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control and\n\t * {@link ColorPicker.Trigger} into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, fixed to this\n\t * button's own {@link ColorSwatch}. Point `commandfor` at\n\t * {@link ColorPicker.Dialog}'s `id` with `command=\"toggle-popover\"` to wire it up.\n\t */\n\texport interface TriggerProps extends Omit<TagProps<\"button\">, \"children\"> {\n\t\t/**\n\t\t * The color this trigger previews, already resolved to a literal CSS\n\t\t * color value — the same value its inner {@link ColorSwatch} paints.\n\t\t * Required, since a trigger with nothing to preview has no reason to render.\n\t\t */\n\t\tvalue: string;\n\t\t/** Shape variant for the inner {@link ColorSwatch}, mirrored onto the button host so its own corners match. Defaults to {@link DEFAULT_TRIGGER_SHAPE}. */\n\t\tshape?: ColorSwatch.Shape;\n\t}\n\n\t/**\n\t * Every prop {@link Popover.Props} accepts, since {@link ColorPicker.Dialog}\n\t * renders one directly as its host. `placement` defaults to\n\t * {@link DEFAULT_DIALOG_PLACEMENT}.\n\t */\n\texport interface DialogProps extends Popover.Props {}\n}\n\n/**\n * Renders {@link ColorPicker}'s root: {@link ColorField}'s plain fallback\n * when `children` is unset, or the trigger-and-panel layout composed from\n * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} otherwise.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the color picker's markup.\n * @example\n * <ColorPicker label={t(\"form.accentColor.label\")} name=\"accentColor\" defaultValue=\"#3b82f6\" />\n * @example\n * <ColorPicker>\n * \t<Label htmlFor=\"brandColor\">{t(\"form.brandColor.label\")}</Label>\n * \t<ColorPicker.Group>\n * \t\t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t\t<ColorPicker.Trigger\n * \t\t\tcommandfor=\"brandColor-panel\"\n * \t\t\tcommand=\"toggle-popover\"\n * \t\t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\t\tvalue=\"#3b82f6\"\n * \t\t/>\n * \t</ColorPicker.Group>\n * \t<ColorPicker.Dialog id=\"brandColor-panel\">\n * \t\t{...the picking surface — see ColorPicker.Dialog's own doc comment}\n * \t</ColorPicker.Dialog>\n * </ColorPicker>\n */\nexport function ColorPicker(handle: Handle<ColorPicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage,\n\t\t\tformat,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tplaceholder,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env.DEV && !children && !label) {\n\t\t\tconsole.warn(\n\t\t\t\t'ColorPicker: falling back to ColorField\\'s plain color-notation field needs a \"label\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<ColorField\n\t\t\t\t\t{...rest}\n\t\t\t\t\tcolor={color}\n\t\t\t\t\tlabel={label}\n\t\t\t\t\tdescription={description}\n\t\t\t\t\terrorMessage={errorMessage}\n\t\t\t\t\tformat={format}\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tparts={parts}\n\t\t\t\t\tmix={mix}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"color-picker\" mix={[vstack({ gap: 1 }), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link ColorPicker}'s control row: a plain flex host laying the\n * field's own control and {@link ColorPicker.Trigger} side by side, with a\n * keyboard focus ring on the whole row the moment focus lands anywhere inside.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <ColorPicker.Group>\n * \t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t<ColorPicker.Trigger\n * \t\tcommandfor=\"brandColor-panel\"\n * \t\tcommand=\"toggle-popover\"\n * \t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\tvalue=\"#3b82f6\"\n * \t/>\n * </ColorPicker.Group>\n */\nColorPicker.Group = function ColorPickerGroup(handle: Handle<ColorPicker.GroupProps>) {\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=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * Focus is shown by the control that holds it, the way `Group` shows it: a ring\n\t\t\t\t\t * around the row says the group is focused without saying whether the field or\n\t\t\t\t\t * the preview has it, and it stacks with the ring that control draws for itself.\n\t\t\t\t\t */\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\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 ColorPicker}'s trailing trigger: a `<button>` housing a\n * {@link ColorSwatch} that fills it as a live preview, wired via\n * `commandfor`/`command=\"toggle-popover\"` to {@link ColorPicker.Dialog}'s `id`.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <ColorPicker.Trigger\n * \tcommandfor=\"brandColor-panel\"\n * \tcommand=\"toggle-popover\"\n * \taria-label={t(\"form.brandColor.toggle\")}\n * \tvalue=\"#3b82f6\"\n * />\n */\nColorPicker.Trigger = function ColorPickerTrigger(handle: Handle<ColorPicker.TriggerProps>) {\n\treturn () => {\n\t\tlet { type, value, shape, mix, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_BUTTON_TYPE;\n\t\tlet resolvedShape = shape ?? DEFAULT_TRIGGER_SHAPE;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t\"ColorPicker.Trigger: this button needs an `aria-label` describing what it does — its content is a color preview with no accessible name of its own.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tdata-shape={resolvedShape}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tis(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\tbs(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\ttransition(\"box-shadow\"),\n\t\t\t\t\twhen('&[data-shape=\"circle\"]', rounded(\"full\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\tp(0),\n\t\t\t\t\tshrink(),\n\t\t\t\t\twhen('&[data-shape=\"square\"]', rounded(\"none\")),\n\t\t\t\t\t/**\n\t\t\t\t\t * The swatch grows through the size variable it reads itself: a size passed down as\n\t\t\t\t\t * `mix` compiles into its own cascade layer, which can land before the swatch's own\n\t\t\t\t\t * and leave the preview at its default size in a corner of the button.\n\t\t\t\t\t */\n\t\t\t\t\traw({ \"--ui-color-swatch-size-md\": \"100%\" }),\n\t\t\t\t\t/**\n\t\t\t\t\t * Hover steps the preview's edge one shade darker, so the edge the swatch already\n\t\t\t\t\t * draws stays the only one and the border reads once.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:hover\", raw({ boxShadow: \"0 0 0 1px var(--ui-neutral-border-hover)\" })),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", raw({ transitionDuration: \"0s\" })),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<ColorSwatch value={value} shape={resolvedShape} />\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link ColorPicker}'s picking surface: a Popover, defaulting\n * `placement` to bottom-start and `role` to `\"dialog\"`, padding whatever\n * picking controls a consumer composes as `children` in a single column.\n *\n * @param handle Runtime handle carrying the host's `Popover` props.\n * @returns The render function producing the surface's markup.\n * @example\n * <ColorPicker.Dialog id=\"brandColor-panel\">\n * \t<ColorArea aria-label={t(\"colorPicker.area\")} hue={hue} defaultSaturation={saturation} defaultValue={brightness} mix={colorAreaDrag()}>\n * \t\t<ColorArea.SaturationThumb data-color-area-axis=\"x\" aria-label={t(\"colorPicker.saturation\")} />\n * \t\t<ColorArea.ValueThumb data-color-area-axis=\"y\" aria-label={t(\"colorPicker.brightness\")} />\n * \t</ColorArea>\n * \t<ColorWheel aria-label={t(\"colorPicker.hue\")} defaultValue={hue} mix={colorWheelDrag()} />\n * \t<ColorSlider channel=\"alpha\" defaultValue={alpha}>\n * \t\t<ColorSlider.Track hue={hue}>\n * \t\t\t<ColorSlider.Thumb aria-label={t(\"colorPicker.alpha\")} />\n * \t\t</ColorSlider.Track>\n * \t</ColorSlider>\n * \t<ColorField label={t(\"colorPicker.hex\")} format=\"hex\" defaultValue=\"#3b82f6\" mix={colorPreview()} />\n * \t<ColorSwatchPicker aria-label={t(\"colorPicker.presets\")}>\n * \t\t<ColorSwatchPicker.Swatch value=\"#ef4444\" aria-label={t(\"color.red\")} />\n * \t\t<ColorSwatchPicker.Swatch value=\"#3b82f6\" aria-label={t(\"color.blue\")} defaultChecked />\n * \t</ColorSwatchPicker>\n * </ColorPicker.Dialog>\n */\nColorPicker.Dialog = function ColorPickerDialog(handle: Handle<ColorPicker.DialogProps>) {\n\treturn () => {\n\t\tlet { placement, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_DIALOG_PLACEMENT;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\t{...rest}\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_DIALOG_ROLE }),\n\t\t\t\t\tvstack({ gap: 4 }),\n\t\t\t\t\tp(4),\n\t\t\t\t\traw({ outline: \"none\" }),\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</Popover>\n\t\t);\n\t};\n};\n"
|
|
14
|
+
"content": "/**\n * A labeled color field composing {@link ColorField}'s plain fallback with\n * an optional {@link ColorPicker.Group} trigger row and\n * {@link ColorPicker.Dialog} picking surface swapped in via `children`.\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 { outline } from \"@sdxc/u/color\";\nimport { opacity, rounded, transition } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { hstack, inlineFlex, items, justify, relative, shrink, vstack } from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { ColorField } from \"@sdxc/ui/color-field\";\nimport { ColorSwatch } from \"@sdxc/ui/color-swatch\";\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Native `<button>` `type` {@link ColorPicker.Trigger} falls back to,\n * keeping an omitted `type` from implicitly submitting an enclosing\n * `<form>` the way a bare `<button>` would.\n */\nconst DEFAULT_BUTTON_TYPE: NonNullable<ColorPicker.TriggerProps[\"type\"]> = \"button\";\n\n/**\n * Shape variant {@link ColorPicker.Trigger} falls back to when `shape` is\n * omitted, mirroring {@link ColorSwatch}'s own default so a trigger left\n * unstyled reads the same as a bare swatch.\n */\nconst DEFAULT_TRIGGER_SHAPE: ColorSwatch.Shape = \"rounded\";\n\n/**\n * `role` applied to {@link ColorPicker.Dialog}'s host through {@link attrs}\n * unless a consumer supplies its own `role`, identifying the surface as a\n * non-modal dialog layered above the page rather than a full-screen modal.\n */\nconst DEFAULT_DIALOG_ROLE = \"dialog\";\n\n/**\n * Side of the trigger {@link ColorPicker.Dialog} renders against when\n * `placement` is left unset, reading down and start-ward the way a dropdown\n * conventionally does.\n */\nconst DEFAULT_DIALOG_PLACEMENT: Popover.Placement = \"bottom-start\";\n\n/**\n * Prop types for {@link ColorPicker} and its compound parts.\n */\nexport namespace ColorPicker {\n\t/**\n\t * Semantic color role for the fallback field's keyboard focus ring,\n\t * mirroring {@link ColorField.Color}. The composed layout carries no\n\t * `color` prop of its own, since a consumer renders it directly.\n\t */\n\texport type Color = ColorField.Color;\n\n\t/**\n\t * Every prop {@link ColorField.PartsProps} accepts, unchanged, applied\n\t * only to the fallback field's internally composed parts — the composed\n\t * layout styles its own parts individually instead.\n\t */\n\texport interface PartsProps extends ColorField.PartsProps {}\n\n\t/**\n\t * Props accepted by {@link ColorPicker}. Leaving `children` unset renders\n\t * {@link ColorField}'s plain fallback using every field below; composing\n\t * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} instead skips them.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback field's focus ring. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The fallback field's caption, rendered through {@link ColorField}. Read only when `children` is unset. */\n\t\tlabel?: RemixNode;\n\t\t/** Supporting copy beneath the fallback field. Read only when `children` is unset. */\n\t\tdescription?: RemixNode;\n\t\t/** Validation message beneath the fallback field. Read only when `children` is unset. */\n\t\terrorMessage?: RemixNode;\n\t\t/** Notation the fallback field's typed entry is constrained to. Read only when `children` is unset. */\n\t\tformat?: ColorField.Format;\n\t\t/** Native `name` submitted with an enclosing form, read only by the fallback field. */\n\t\tname?: string;\n\t\t/** Current value, as a literal color string, for a fallback field a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, as a literal color string, for a fallback field left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Placeholder copy shown while the fallback field is empty. */\n\t\tplaceholder?: string;\n\t\t/** Marks the fallback field required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the fallback field inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the fallback field's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the fallback field. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback field's internally composed parts. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The trigger-and-panel layout — typically a `Label`,\n\t\t * {@link ColorPicker.Group}, and {@link ColorPicker.Dialog} — rendered in\n\t\t * place of {@link ColorField}'s plain fallback. Unset renders that fallback.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control and\n\t * {@link ColorPicker.Trigger} into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, fixed to this\n\t * button's own {@link ColorSwatch}. Point `commandfor` at\n\t * {@link ColorPicker.Dialog}'s `id` with `command=\"toggle-popover\"` to wire it up.\n\t */\n\texport interface TriggerProps extends Omit<TagProps<\"button\">, \"children\"> {\n\t\t/**\n\t\t * The color this trigger previews, already resolved to a literal CSS\n\t\t * color value — the same value its inner {@link ColorSwatch} paints.\n\t\t * Required, since a trigger with nothing to preview has no reason to render.\n\t\t */\n\t\tvalue: string;\n\t\t/** Shape variant for the inner {@link ColorSwatch}, mirrored onto the button host so its own corners match. Defaults to {@link DEFAULT_TRIGGER_SHAPE}. */\n\t\tshape?: ColorSwatch.Shape;\n\t}\n\n\t/**\n\t * Every prop {@link Popover.Props} accepts, since {@link ColorPicker.Dialog}\n\t * renders one directly as its host. `placement` defaults to\n\t * {@link DEFAULT_DIALOG_PLACEMENT}.\n\t */\n\texport interface DialogProps extends Popover.Props {}\n}\n\n/**\n * Renders {@link ColorPicker}'s root: {@link ColorField}'s plain fallback\n * when `children` is unset, or the trigger-and-panel layout composed from\n * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} otherwise.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the color picker's markup.\n * @example\n * <ColorPicker label={t(\"form.accentColor.label\")} name=\"accentColor\" defaultValue=\"#3b82f6\" />\n * @example\n * <ColorPicker>\n * \t<Label htmlFor=\"brandColor\">{t(\"form.brandColor.label\")}</Label>\n * \t<ColorPicker.Group>\n * \t\t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t\t<ColorPicker.Trigger\n * \t\t\tcommandfor=\"brandColor-panel\"\n * \t\t\tcommand=\"toggle-popover\"\n * \t\t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\t\tvalue=\"#3b82f6\"\n * \t\t/>\n * \t</ColorPicker.Group>\n * \t<ColorPicker.Dialog id=\"brandColor-panel\">\n * \t\t{...the picking surface — see ColorPicker.Dialog's own doc comment}\n * \t</ColorPicker.Dialog>\n * </ColorPicker>\n */\nexport function ColorPicker(handle: Handle<ColorPicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage,\n\t\t\tformat,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tplaceholder,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env?.DEV && !children && !label) {\n\t\t\tconsole.warn(\n\t\t\t\t'ColorPicker: falling back to ColorField\\'s plain color-notation field needs a \"label\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<ColorField\n\t\t\t\t\t{...rest}\n\t\t\t\t\tcolor={color}\n\t\t\t\t\tlabel={label}\n\t\t\t\t\tdescription={description}\n\t\t\t\t\terrorMessage={errorMessage}\n\t\t\t\t\tformat={format}\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tparts={parts}\n\t\t\t\t\tmix={mix}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"color-picker\" mix={[vstack({ gap: 1 }), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link ColorPicker}'s control row: a plain flex host laying the\n * field's own control and {@link ColorPicker.Trigger} side by side, with a\n * keyboard focus ring on the whole row the moment focus lands anywhere inside.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <ColorPicker.Group>\n * \t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t<ColorPicker.Trigger\n * \t\tcommandfor=\"brandColor-panel\"\n * \t\tcommand=\"toggle-popover\"\n * \t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\tvalue=\"#3b82f6\"\n * \t/>\n * </ColorPicker.Group>\n */\nColorPicker.Group = function ColorPickerGroup(handle: Handle<ColorPicker.GroupProps>) {\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=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * Focus is shown by the control that holds it, the way `Group` shows it: a ring\n\t\t\t\t\t * around the row says the group is focused without saying whether the field or\n\t\t\t\t\t * the preview has it, and it stacks with the ring that control draws for itself.\n\t\t\t\t\t */\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\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 ColorPicker}'s trailing trigger: a `<button>` housing a\n * {@link ColorSwatch} that fills it as a live preview, wired via\n * `commandfor`/`command=\"toggle-popover\"` to {@link ColorPicker.Dialog}'s `id`.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <ColorPicker.Trigger\n * \tcommandfor=\"brandColor-panel\"\n * \tcommand=\"toggle-popover\"\n * \taria-label={t(\"form.brandColor.toggle\")}\n * \tvalue=\"#3b82f6\"\n * />\n */\nColorPicker.Trigger = function ColorPickerTrigger(handle: Handle<ColorPicker.TriggerProps>) {\n\treturn () => {\n\t\tlet { type, value, shape, mix, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_BUTTON_TYPE;\n\t\tlet resolvedShape = shape ?? DEFAULT_TRIGGER_SHAPE;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t\"ColorPicker.Trigger: this button needs an `aria-label` describing what it does — its content is a color preview with no accessible name of its own.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tdata-shape={resolvedShape}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tis(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\tbs(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\ttransition(\"box-shadow\"),\n\t\t\t\t\twhen('&[data-shape=\"circle\"]', rounded(\"full\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\tp(0),\n\t\t\t\t\tshrink(),\n\t\t\t\t\twhen('&[data-shape=\"square\"]', rounded(\"none\")),\n\t\t\t\t\t/**\n\t\t\t\t\t * The swatch grows through the size variable it reads itself: a size passed down as\n\t\t\t\t\t * `mix` compiles into its own cascade layer, which can land before the swatch's own\n\t\t\t\t\t * and leave the preview at its default size in a corner of the button.\n\t\t\t\t\t */\n\t\t\t\t\traw({ \"--ui-color-swatch-size-md\": \"100%\" }),\n\t\t\t\t\t/**\n\t\t\t\t\t * Hover steps the preview's edge one shade darker, so the edge the swatch already\n\t\t\t\t\t * draws stays the only one and the border reads once.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:hover\", raw({ boxShadow: \"0 0 0 1px var(--ui-neutral-border-hover)\" })),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", raw({ transitionDuration: \"0s\" })),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<ColorSwatch value={value} shape={resolvedShape} />\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link ColorPicker}'s picking surface: a Popover, defaulting\n * `placement` to bottom-start and `role` to `\"dialog\"`, padding whatever\n * picking controls a consumer composes as `children` in a single column.\n *\n * @param handle Runtime handle carrying the host's `Popover` props.\n * @returns The render function producing the surface's markup.\n * @example\n * <ColorPicker.Dialog id=\"brandColor-panel\">\n * \t<ColorArea aria-label={t(\"colorPicker.area\")} hue={hue} defaultSaturation={saturation} defaultValue={brightness} mix={colorAreaDrag()}>\n * \t\t<ColorArea.SaturationThumb data-color-area-axis=\"x\" aria-label={t(\"colorPicker.saturation\")} />\n * \t\t<ColorArea.ValueThumb data-color-area-axis=\"y\" aria-label={t(\"colorPicker.brightness\")} />\n * \t</ColorArea>\n * \t<ColorWheel aria-label={t(\"colorPicker.hue\")} defaultValue={hue} mix={colorWheelDrag()} />\n * \t<ColorSlider channel=\"alpha\" defaultValue={alpha}>\n * \t\t<ColorSlider.Track hue={hue}>\n * \t\t\t<ColorSlider.Thumb aria-label={t(\"colorPicker.alpha\")} />\n * \t\t</ColorSlider.Track>\n * \t</ColorSlider>\n * \t<ColorField label={t(\"colorPicker.hex\")} format=\"hex\" defaultValue=\"#3b82f6\" mix={colorPreview()} />\n * \t<ColorSwatchPicker aria-label={t(\"colorPicker.presets\")}>\n * \t\t<ColorSwatchPicker.Swatch value=\"#ef4444\" aria-label={t(\"color.red\")} />\n * \t\t<ColorSwatchPicker.Swatch value=\"#3b82f6\" aria-label={t(\"color.blue\")} defaultChecked />\n * \t</ColorSwatchPicker>\n * </ColorPicker.Dialog>\n */\nColorPicker.Dialog = function ColorPickerDialog(handle: Handle<ColorPicker.DialogProps>) {\n\treturn () => {\n\t\tlet { placement, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_DIALOG_PLACEMENT;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\t{...rest}\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_DIALOG_ROLE }),\n\t\t\t\t\tvstack({ gap: 4 }),\n\t\t\t\t\tp(4),\n\t\t\t\t\traw({ outline: \"none\" }),\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</Popover>\n\t\t);\n\t};\n};\n"
|
|
15
15
|
},
|
|
16
16
|
"test": null
|
|
17
17
|
}
|
package/registry/ui/command.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "command",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Command"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "command.tsx",
|
|
10
|
-
"content": "/**\n * A bordered panel for searching and choosing among a list of actions:\n * {@link Command.Input} holds the query row, {@link Command.List} scrolls\n * through {@link Command.Item} rows, and {@link Command.Empty} holds a\n * message for when nothing matches. Its baseline rendering is a plain, fully\n * visible list of options, styled and ready to compose; the as-you-type\n * filtering and match highlighting a search experience needs arrive through\n * a separate opt-in behavior a consumer attaches.\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, outlineStyle } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { hstack, shrink, vstack } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { bs, is, maxBs, pb, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { concentricRadius, floatingSurface, surfacePadding } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** `role=\"listbox\"` applied to {@link Command.List} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_LIST_ROLE = \"listbox\";\n\n/** `role=\"option\"` applied to {@link Command.Item} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_ITEM_ROLE = \"option\";\n\n/**\n * Prop types for {@link Command} and its compound parts.\n */\nexport namespace Command {\n\t/**\n\t * Props accepted by {@link Command}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** The panel's compound parts: {@link Command.Input}, {@link Command.List}, {@link Command.Empty}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<input>` attribute, unchanged, plus the `mix` passthrough,\n\t * styling the control itself — a type alias, since the native input prop\n\t * type resolves through a conditional type only a type alias can express.\n\t */\n\texport type InputProps = TagProps<\"input\">;\n\n\t/**\n\t * Props accepted by {@link Command.List}.\n\t */\n\texport interface ListProps extends TagProps<\"div\"> {\n\t\t/** The {@link Command.Item} rows (and, once nothing matches, {@link Command.Empty}) to scroll through. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Command.Item}.\n\t */\n\texport interface ItemProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Plain-text value identifying this row's content. A paired filter\n\t\t * behavior matches typed text against this value directly, so it stays\n\t\t * required even when the visible content is already plain text.\n\t\t */\n\t\tvalue: string;\n\t\t/** The row's visible content: a label, and optionally a leading icon or trailing hint. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Command.Empty}.\n\t */\n\texport interface EmptyProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders the panel's root host: an elevated `<div>` rounded concentric\n * with {@link Command.Item}'s corners, stacking its compound parts in a\n * column and clipping {@link Command.List}'s scrolled content to that radius.\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 * <Command aria-label={t(\"command.label\")}>\n * \t<Command.Input aria-label={t(\"command.label\")} placeholder={t(\"command.placeholder\")} />\n * \t<Command.List>\n * \t\t<Command.Item value=\"new-file\">{t(\"command.newFile\")}</Command.Item>\n * \t\t<Command.Item value=\"new-folder\">{t(\"command.newFolder\")}</Command.Item>\n * \t</Command.List>\n * \t<Command.Empty>{t(\"command.empty\")}</Command.Empty>\n * </Command>\n */\nexport function Command(handle: Handle<Command.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"command\"\n\t\t\t\tmix={[\n\t\t\t\t\tfloatingSurface(),\n\t\t\t\t\traw({ borderRadius: concentricRadius(surfacePadding(1)) }),\n\t\t\t\t\tvstack(),\n\t\t\t\t\toverflow(\"hidden\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\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 the panel's query row: a `<div>` bordered along its block-end\n * edge wrapping a native `<input>` sized to the row's full padding and\n * height, marked `data-command-input` for a paired filter mixin to read.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the query row's markup.\n * @example\n * <Command.Input aria-label={t(\"command.label\")} placeholder={t(\"command.placeholder\")} />\n * @example\n * <Command.Input aria-label={t(\"command.label\")} value={query} disabled />\n */\nCommand.Input = function CommandInput(handle: Handle<Command.InputProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div data-slot=\"input-wrapper\" mix={borderEdge(\"block-end\", { color: \"neutral\", width: 1 })}>\n\t\t\t\t<input\n\t\t\t\t\t{...rest}\n\t\t\t\t\tdata-slot=\"input\"\n\t\t\t\t\tdata-command-input\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tbs(\"3.5rem\"),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\twhen(\"&::placeholder\", fg(\"neutral.muted\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\t\tmix,\n\t\t\t\t\t]}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's scrollable option region: a `<div>` carrying the\n * `listbox` role, capped at a fixed block size, its small inline padding\n * leaving room for a selected {@link Command.Item}'s own rounded corners.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the option region's markup.\n * @example\n * <Command.List>\n * \t<Command.Item value=\"new-file\">{t(\"command.newFile\")}</Command.Item>\n * \t<Command.Item value=\"new-folder\">{t(\"command.newFolder\")}</Command.Item>\n * </Command.List>\n */\nCommand.List = function CommandList(handle: Handle<Command.ListProps>) {\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=\"list\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_LIST_ROLE }),\n\t\t\t\t\tmaxBs(\"18rem\"),\n\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\tpi(surfacePadding(1)),\n\t\t\t\t\t/**\n\t\t\t\t\t * The list spends its block padding only while a row is visible, so a filter hiding every\n\t\t\t\t\t * row leaves the empty-state message centered.\n\t\t\t\t\t */\n\t\t\t\t\twhen('&:has([data-slot=\"item\"]:not([hidden]))', pb(2)),\n\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single row: a `<div>` carrying the `option` role, its `value`\n * mirrored onto `data-value` for a paired filter behavior to read. Nest a\n * `<button>` or `<a>` in `children` for native activation.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Command.Item value=\"new-file\">{t(\"command.newFile\")}</Command.Item>\n * @example\n * <Command.Item value=\"archived-project\" aria-disabled=\"true\">\n * \t{t(\"command.archivedProject\")}\n * </Command.Item>\n */\nCommand.Item = function CommandItem(handle: Handle<Command.ItemProps>) {\n\treturn () => {\n\t\tlet { value, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env.DEV && !value) {\n\t\t\tconsole.warn(\n\t\t\t\t'Command.Item: needs a \"value\" — a filter behavior matches typed text against this instead of parsing rendered children.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"item\"\n\t\t\t\tdata-value={value}\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tattrs({ role: DEFAULT_ITEM_ROLE }),\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\n\t\t\t\t\t/**\n\t\t\t\t\t * A glyph anywhere in the row is sized against the row's text and holds that size when the\n\t\t\t\t\t * row runs short; the default `flex-shrink: 1` would squeeze each glyph by its own row's\n\t\t\t\t\t * overrun and leave the column of glyphs ragged.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(2),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The active row is a cursor tinted far enough off the surface to find at a glance, while\n\t\t\t\t\t * its text keeps reading as text. Pointer and cursor states use mutually exclusive selectors,\n\t\t\t\t\t * so the row under the pointer stays marked active whichever order the layers land in.\n\t\t\t\t\t */\n\t\t\t\t\twhen('&:hover:not([aria-selected=\"true\"])', bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('&:active:not([aria-selected=\"true\"])', bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\twhen('&:focus:not([aria-selected=\"true\"])', bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]:hover', bg(\"brand.bg-tint-pressed\")),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's no-match message: a centered, muted passage of small\n * text filling {@link Command.List}'s content area, carrying a\n * `data-command-empty` marker a paired filter behavior reads to toggle it.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the message's markup.\n * @example\n * <Command.Empty>{t(\"command.empty\")}</Command.Empty>\n */\nCommand.Empty = function CommandEmpty(handle: Handle<Command.EmptyProps>) {\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=\"empty\"\n\t\t\t\tdata-command-empty\n\t\t\t\tmix={[pi(3), pb(6), textAlign(\"center\"), fg(\"neutral.muted\"), text(\"sm\"), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
10
|
+
"content": "/**\n * A bordered panel for searching and choosing among a list of actions:\n * {@link Command.Input} holds the query row, {@link Command.List} scrolls\n * through {@link Command.Item} rows, and {@link Command.Empty} holds a\n * message for when nothing matches. Its baseline rendering is a plain, fully\n * visible list of options, styled and ready to compose; the as-you-type\n * filtering and match highlighting a search experience needs arrive through\n * a separate opt-in behavior a consumer attaches.\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, outlineStyle } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { hstack, shrink, vstack } from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { bs, is, maxBs, pb, pi } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { concentricRadius, floatingSurface, surfacePadding } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** `role=\"listbox\"` applied to {@link Command.List} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_LIST_ROLE = \"listbox\";\n\n/** `role=\"option\"` applied to {@link Command.Item} through {@link attrs} unless a consumer supplies its own `role`. */\nconst DEFAULT_ITEM_ROLE = \"option\";\n\n/**\n * Prop types for {@link Command} and its compound parts.\n */\nexport namespace Command {\n\t/**\n\t * Props accepted by {@link Command}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** The panel's compound parts: {@link Command.Input}, {@link Command.List}, {@link Command.Empty}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<input>` attribute, unchanged, plus the `mix` passthrough,\n\t * styling the control itself — a type alias, since the native input prop\n\t * type resolves through a conditional type only a type alias can express.\n\t */\n\texport type InputProps = TagProps<\"input\">;\n\n\t/**\n\t * Props accepted by {@link Command.List}.\n\t */\n\texport interface ListProps extends TagProps<\"div\"> {\n\t\t/** The {@link Command.Item} rows (and, once nothing matches, {@link Command.Empty}) to scroll through. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Command.Item}.\n\t */\n\texport interface ItemProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Plain-text value identifying this row's content. A paired filter\n\t\t * behavior matches typed text against this value directly, so it stays\n\t\t * required even when the visible content is already plain text.\n\t\t */\n\t\tvalue: string;\n\t\t/** The row's visible content: a label, and optionally a leading icon or trailing hint. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Command.Empty}.\n\t */\n\texport interface EmptyProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders the panel's root host: an elevated `<div>` rounded concentric\n * with {@link Command.Item}'s corners, stacking its compound parts in a\n * column and clipping {@link Command.List}'s scrolled content to that radius.\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 * <Command aria-label={t(\"command.label\")}>\n * \t<Command.Input aria-label={t(\"command.label\")} placeholder={t(\"command.placeholder\")} />\n * \t<Command.List>\n * \t\t<Command.Item value=\"new-file\">{t(\"command.newFile\")}</Command.Item>\n * \t\t<Command.Item value=\"new-folder\">{t(\"command.newFolder\")}</Command.Item>\n * \t</Command.List>\n * \t<Command.Empty>{t(\"command.empty\")}</Command.Empty>\n * </Command>\n */\nexport function Command(handle: Handle<Command.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"command\"\n\t\t\t\tmix={[\n\t\t\t\t\tfloatingSurface(),\n\t\t\t\t\traw({ borderRadius: concentricRadius(surfacePadding(1)) }),\n\t\t\t\t\tvstack(),\n\t\t\t\t\toverflow(\"hidden\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\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 the panel's query row: a `<div>` bordered along its block-end\n * edge wrapping a native `<input>` sized to the row's full padding and\n * height, marked `data-command-input` for a paired filter mixin to read.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the query row's markup.\n * @example\n * <Command.Input aria-label={t(\"command.label\")} placeholder={t(\"command.placeholder\")} />\n * @example\n * <Command.Input aria-label={t(\"command.label\")} value={query} disabled />\n */\nCommand.Input = function CommandInput(handle: Handle<Command.InputProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div data-slot=\"input-wrapper\" mix={borderEdge(\"block-end\", { color: \"neutral\", width: 1 })}>\n\t\t\t\t<input\n\t\t\t\t\t{...rest}\n\t\t\t\t\tdata-slot=\"input\"\n\t\t\t\t\tdata-command-input\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t\tbs(\"3.5rem\"),\n\t\t\t\t\t\tpi(3),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\twhen(\"&::placeholder\", fg(\"neutral.muted\")),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\t\tmix,\n\t\t\t\t\t]}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's scrollable option region: a `<div>` carrying the\n * `listbox` role, capped at a fixed block size, its small inline padding\n * leaving room for a selected {@link Command.Item}'s own rounded corners.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the option region's markup.\n * @example\n * <Command.List>\n * \t<Command.Item value=\"new-file\">{t(\"command.newFile\")}</Command.Item>\n * \t<Command.Item value=\"new-folder\">{t(\"command.newFolder\")}</Command.Item>\n * </Command.List>\n */\nCommand.List = function CommandList(handle: Handle<Command.ListProps>) {\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=\"list\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_LIST_ROLE }),\n\t\t\t\t\tmaxBs(\"18rem\"),\n\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\tpi(surfacePadding(1)),\n\t\t\t\t\t/**\n\t\t\t\t\t * The list spends its block padding only while a row is visible, so a filter hiding every\n\t\t\t\t\t * row leaves the empty-state message centered.\n\t\t\t\t\t */\n\t\t\t\t\twhen('&:has([data-slot=\"item\"]:not([hidden]))', pb(2)),\n\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single row: a `<div>` carrying the `option` role, its `value`\n * mirrored onto `data-value` for a paired filter behavior to read. Nest a\n * `<button>` or `<a>` in `children` for native activation.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Command.Item value=\"new-file\">{t(\"command.newFile\")}</Command.Item>\n * @example\n * <Command.Item value=\"archived-project\" aria-disabled=\"true\">\n * \t{t(\"command.archivedProject\")}\n * </Command.Item>\n */\nCommand.Item = function CommandItem(handle: Handle<Command.ItemProps>) {\n\treturn () => {\n\t\tlet { value, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env?.DEV && !value) {\n\t\t\tconsole.warn(\n\t\t\t\t'Command.Item: needs a \"value\" — a filter behavior matches typed text against this instead of parsing rendered children.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"item\"\n\t\t\t\tdata-value={value}\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tattrs({ role: DEFAULT_ITEM_ROLE }),\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\n\t\t\t\t\t/**\n\t\t\t\t\t * A glyph anywhere in the row is sized against the row's text and holds that size when the\n\t\t\t\t\t * row runs short; the default `flex-shrink: 1` would squeeze each glyph by its own row's\n\t\t\t\t\t * overrun and leave the column of glyphs ragged.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(2),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The active row is a cursor tinted far enough off the surface to find at a glance, while\n\t\t\t\t\t * its text keeps reading as text. Pointer and cursor states use mutually exclusive selectors,\n\t\t\t\t\t * so the row under the pointer stays marked active whichever order the layers land in.\n\t\t\t\t\t */\n\t\t\t\t\twhen('&:hover:not([aria-selected=\"true\"])', bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('&:active:not([aria-selected=\"true\"])', bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\twhen('&:focus:not([aria-selected=\"true\"])', bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]:hover', bg(\"brand.bg-tint-pressed\")),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's no-match message: a centered, muted passage of small\n * text filling {@link Command.List}'s content area, carrying a\n * `data-command-empty` marker a paired filter behavior reads to toggle it.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the message's markup.\n * @example\n * <Command.Empty>{t(\"command.empty\")}</Command.Empty>\n */\nCommand.Empty = function CommandEmpty(handle: Handle<Command.EmptyProps>) {\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=\"empty\"\n\t\t\t\tdata-command-empty\n\t\t\t\tmix={[pi(3), pb(6), textAlign(\"center\"), fg(\"neutral.muted\"), text(\"sm\"), mix]}\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": "date-picker",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"date-field"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "date-picker.tsx",
|
|
12
|
-
"content": "/**\n * A labeled date field built on {@link DateField}, with a\n * {@link DatePicker.Group} row for composing more than one field into a single\n * control. The calendar is the platform's: the field is a native date input, so\n * the picker, its keyboard handling and its locale all come from the browser and\n * all of it works before any script loads. Leaving `children` unset renders the\n * field on its own.\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 { outline } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { mis } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\n\nimport { DateField } from \"@sdxc/ui/date-field\";\n\n/**\n * Prop types for {@link DatePicker} and its compound parts.\n */\nexport namespace DatePicker {\n\t/**\n\t * Semantic color role for the fallback field's keyboard focus ring. Read\n\t * only by the fallback field — {@link DatePicker.Group}'s composed\n\t * control carries no `color` prop of its own.\n\t */\n\texport type Color = DateField.Color;\n\n\t/**\n\t * Every prop {@link DateField.PartsProps} accepts, applied only to the\n\t * field's internally composed parts; a composed layout styles the controls\n\t * inside {@link DatePicker.Group} individually.\n\t */\n\texport interface PartsProps extends DateField.PartsProps {}\n\n\t/**\n\t * Props accepted by {@link DatePicker}. Leaving `children` unset renders the\n\t * field using every prop below; composing {@link DatePicker.Group} instead\n\t * renders the joined row and leaves every prop below unread.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback field's focus ring. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The fallback field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tlabel?: RemixNode;\n\t\t/** Supporting copy beneath the fallback field. Read only when `children` is unset. */\n\t\tdescription?: RemixNode;\n\t\t/** Validation message beneath the fallback field. Read only when `children` is unset. */\n\t\terrorMessage?: RemixNode;\n\t\t/** Native `name` submitted with an enclosing form, read only by the fallback field. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a fallback field a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a fallback field left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read only by the fallback field. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read only by the fallback field. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the fallback field's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the fallback field required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the fallback field inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the fallback field's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the fallback field, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback field's internally composed parts. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The composed layout — typically a `Label` and a\n\t\t * {@link DatePicker.Group} — rendered in place of the field, leaving every\n\t\t * field above unread.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control, and a second one for a\n\t * range, into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders {@link DatePicker}'s root. Leaving `children` unset renders the field,\n * passing every prop above through unchanged; composing\n * {@link DatePicker.Group} as `children` instead renders the joined row and\n * leaves those props unread.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date picker's markup.\n * @example\n * <DatePicker label={t(\"form.birthday.label\")} name=\"birthday\" autoComplete=\"bday\" />\n * @example\n * <DatePicker>\n * \t<Label htmlFor=\"startDate\">{t(\"form.startDate.label\")}</Label>\n * \t<DatePicker.Group>\n * \t\t<Input id=\"startDate\" type=\"date\" name=\"startDate\" />\n * \t</DatePicker.Group>\n * </DatePicker>\n */\nexport function DatePicker(handle: Handle<DatePicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env
|
|
12
|
+
"content": "/**\n * A labeled date field built on {@link DateField}, with a\n * {@link DatePicker.Group} row for composing more than one field into a single\n * control. The calendar is the platform's: the field is a native date input, so\n * the picker, its keyboard handling and its locale all come from the browser and\n * all of it works before any script loads. Leaving `children` unset renders the\n * field on its own.\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 { outline } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { mis } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\n\nimport { DateField } from \"@sdxc/ui/date-field\";\n\n/**\n * Prop types for {@link DatePicker} and its compound parts.\n */\nexport namespace DatePicker {\n\t/**\n\t * Semantic color role for the fallback field's keyboard focus ring. Read\n\t * only by the fallback field — {@link DatePicker.Group}'s composed\n\t * control carries no `color` prop of its own.\n\t */\n\texport type Color = DateField.Color;\n\n\t/**\n\t * Every prop {@link DateField.PartsProps} accepts, applied only to the\n\t * field's internally composed parts; a composed layout styles the controls\n\t * inside {@link DatePicker.Group} individually.\n\t */\n\texport interface PartsProps extends DateField.PartsProps {}\n\n\t/**\n\t * Props accepted by {@link DatePicker}. Leaving `children` unset renders the\n\t * field using every prop below; composing {@link DatePicker.Group} instead\n\t * renders the joined row and leaves every prop below unread.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback field's focus ring. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The fallback field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tlabel?: RemixNode;\n\t\t/** Supporting copy beneath the fallback field. Read only when `children` is unset. */\n\t\tdescription?: RemixNode;\n\t\t/** Validation message beneath the fallback field. Read only when `children` is unset. */\n\t\terrorMessage?: RemixNode;\n\t\t/** Native `name` submitted with an enclosing form, read only by the fallback field. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a fallback field a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a fallback field left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read only by the fallback field. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read only by the fallback field. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the fallback field's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the fallback field required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the fallback field inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the fallback field's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the fallback field, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback field's internally composed parts. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The composed layout — typically a `Label` and a\n\t\t * {@link DatePicker.Group} — rendered in place of the field, leaving every\n\t\t * field above unread.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control, and a second one for a\n\t * range, into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n}\n\n/**\n * Renders {@link DatePicker}'s root. Leaving `children` unset renders the field,\n * passing every prop above through unchanged; composing\n * {@link DatePicker.Group} as `children` instead renders the joined row and\n * leaves those props unread.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date picker's markup.\n * @example\n * <DatePicker label={t(\"form.birthday.label\")} name=\"birthday\" autoComplete=\"bday\" />\n * @example\n * <DatePicker>\n * \t<Label htmlFor=\"startDate\">{t(\"form.startDate.label\")}</Label>\n * \t<DatePicker.Group>\n * \t\t<Input id=\"startDate\" type=\"date\" name=\"startDate\" />\n * \t</DatePicker.Group>\n * </DatePicker>\n */\nexport function DatePicker(handle: Handle<DatePicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env?.DEV && !children && !label) {\n\t\t\tconsole.warn(\n\t\t\t\t'DatePicker: falling back to DateField\\'s plain \"input type=date\" needs a \"label\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<DateField\n\t\t\t\t\t{...rest}\n\t\t\t\t\tcolor={color}\n\t\t\t\t\tlabel={label}\n\t\t\t\t\tdescription={description}\n\t\t\t\t\terrorMessage={errorMessage}\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tmin={min}\n\t\t\t\t\tmax={max}\n\t\t\t\t\tstep={step}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tparts={parts}\n\t\t\t\t\tmix={mix}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"date-picker\" mix={[flex(), flexCol(), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link DatePicker}'s control row: a flex host laying one or more date\n * controls side by side and joining their edges, so a pair reads as one field.\n * Focus and validity are drawn the way `Group` draws them — focus by the control\n * that holds it, validity once around the row.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <DatePicker.Group>\n * \t<Input id=\"startDate\" type=\"date\" name=\"startDate\" />\n * </DatePicker.Group>\n */\nDatePicker.Group = function DatePickerGroup(handle: Handle<DatePicker.GroupProps>) {\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=\"group\"\n\t\t\t\tmix={[\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 fields compose into one control, so the pair keeps the rounding on its own\n\t\t\t\t\t * outer corners and the seam the two share is drawn once.\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(\"& > *:not(:last-child)\", [\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 field holding it, naming which date has it where a ring around\n\t\t\t\t\t * the pair names only the group. That field is raised so its ring crosses the seam.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& > *:focus-visible\", z(1)),\n\t\t\t\t\t/**\n\t\t\t\t\t * Validity belongs to the pair, since a range is one value and half of one makes it\n\t\t\t\t\t * invalid: one ring is drawn around the group and each field's own ring is released,\n\t\t\t\t\t * so the seam shows one field needing attention.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\n\t\t\t\t\t\t'&:has(> :user-invalid), &:has(> [aria-invalid=\"true\"])',\n\t\t\t\t\t\toutline({ color: \"danger.ring\", offset: 2 }),\n\t\t\t\t\t),\n\t\t\t\t\twhen(\n\t\t\t\t\t\t'& > :user-invalid:not(:focus-visible), & > [aria-invalid=\"true\"]:not(:focus-visible)',\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Important so it reaches across to the cascade layer where `Input` states the field's\n\t\t\t\t\t\t * invalid ring. The selector excludes `:focus-visible`, so a field being filled in still\n\t\t\t\t\t\t * shows its own focus ring.\n\t\t\t\t\t\t */\n\t\t\t\t\t\traw({ outline: \"none !important\" }),\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": null
|
|
15
15
|
}
|