@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": "date-range-picker",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"date-field",
|
|
6
6
|
"date-picker"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "date-range-picker.tsx",
|
|
13
|
-
"content": "/**\n * A paired-field date range control built on {@link DateField} — independent\n * start-date and end-date fields, each fully labeled, described, and validated\n * on its own — with a {@link DateRangePicker.Group} row for joining the two\n * into one control. The calendar is the platform's, since each field is a\n * native date input, so the whole range is pickable before any script loads.\n * Leaving `children` unset renders the pair 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 { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { attrs } from \"remix/component\";\n\nimport { DateField } from \"@sdxc/ui/date-field\";\nimport { DatePicker } from \"@sdxc/ui/date-picker\";\n\n/**\n * Prop types for {@link DateRangePicker} and its compound parts.\n * {@link DateRangePicker.Group} aliases {@link DatePicker.Group} directly,\n * since a row of fields reads the same for a range as for a single date.\n */\nexport namespace DateRangePicker {\n\t/**\n\t * Semantic color role for the fallback pair's keyboard focus rings. Read\n\t * only by the fallback fields — {@link DateRangePicker.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 * Per-part styling for the two {@link DateField} instances the fallback\n\t * pair composes, each forwarded to that field's own `parts`. Read only\n\t * when `children` is unset; the composed layout styles its own parts individually instead.\n\t */\n\texport interface PartsProps {\n\t\t/** Per-part styling for the fallback pair's start-date field. */\n\t\tstart?: DateField.PartsProps;\n\t\t/** Per-part styling for the fallback pair's end-date field. */\n\t\tend?: DateField.PartsProps;\n\t}\n\n\t/**\n\t * Props accepted by {@link DateRangePicker}. Leaving `children` unset\n\t * renders two independent {@link DateField} instances — one per end of\n\t * the range — using every field below; composing\n\t * {@link DateRangePicker.Group} instead renders the joined row and leaves\n\t * every field below unread.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback pair's focus rings. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The start-date field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tstartLabel?: RemixNode;\n\t\t/** The end-date field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tendLabel?: RemixNode;\n\t\t/** Supporting copy beneath the start-date field. Read only when `children` is unset. */\n\t\tstartDescription?: RemixNode;\n\t\t/** Supporting copy beneath the end-date field. Read only when `children` is unset. */\n\t\tendDescription?: RemixNode;\n\t\t/** Validation message beneath the start-date field. Read only when `children` is unset. */\n\t\tstartErrorMessage?: RemixNode;\n\t\t/** Validation message beneath the end-date field. Read only when `children` is unset. */\n\t\tendErrorMessage?: RemixNode;\n\t\t/** Native `name` submitted with an enclosing form for the start-date field. */\n\t\tstartName?: string;\n\t\t/** Native `name` submitted with an enclosing form for the end-date field. */\n\t\tendName?: string;\n\t\t/** Current start-of-range value, in `YYYY-MM-DD` form, for a fallback pair a consumer tracks itself. */\n\t\tstartValue?: string;\n\t\t/** Current end-of-range value, in `YYYY-MM-DD` form, for a fallback pair a consumer tracks itself. */\n\t\tendValue?: string;\n\t\t/** Initial start-of-range value, in `YYYY-MM-DD` form, for a fallback pair left to the platform's own uncontrolled state. */\n\t\tstartDefaultValue?: string;\n\t\t/** Initial end-of-range value, in `YYYY-MM-DD` form, for a fallback pair left to the platform's own uncontrolled state. */\n\t\tendDefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read by both of the fallback pair's fields. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read by both of the fallback pair's fields. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, both of the fallback pair's values must fall on. */\n\t\tstep?: number;\n\t\t/** Marks both of the fallback pair's fields required for their enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks both of the fallback pair's fields inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks both of the fallback pair's fields' values fixed, while keeping them focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for both of the fallback pair's fields. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback pair's internally composed {@link DateField} instances. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The joined layout — typically a `Label` and a\n\t\t * {@link DateRangePicker.Group} — rendered in place of the paired fields,\n\t\t * leaving every field above unread when set.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every prop {@link DatePicker.GroupProps} accepts, unchanged. `children`\n\t * composes the range's own start and end controls into one visual row.\n\t */\n\texport interface GroupProps extends DatePicker.GroupProps {}\n}\n\n/**\n * Renders {@link DateRangePicker}'s root. Leaving `children` unset renders\n * two independent {@link DateField} instances side by side under a native\n * `role=\"group\"`, each aligned to its own start edge so a validation message\n * under one never shifts the other's label; composing\n * {@link DateRangePicker.Group} as `children` instead joins the two fields into\n * one row and leaves every field prop above unread.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date range picker's markup.\n * @example\n * <DateRangePicker\n * \tstartLabel={t(\"form.stay.checkIn\")}\n * \tendLabel={t(\"form.stay.checkOut\")}\n * \tstartName=\"checkIn\"\n * \tendName=\"checkOut\"\n * />\n * @example\n * <DateRangePicker>\n * \t<Label htmlFor=\"tripStart\">{t(\"form.trip.label\")}</Label>\n * \t<DateRangePicker.Group>\n * \t\t<Input id=\"tripStart\" type=\"date\" name=\"tripStart\" aria-label={t(\"form.trip.start\")} />\n * \t\t<Input id=\"tripEnd\" type=\"date\" name=\"tripEnd\" aria-label={t(\"form.trip.end\")} />\n * \t</DateRangePicker.Group>\n * </DateRangePicker>\n */\nexport function DateRangePicker(handle: Handle<DateRangePicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tstartLabel,\n\t\t\tendLabel,\n\t\t\tstartDescription,\n\t\t\tendDescription,\n\t\t\tstartErrorMessage,\n\t\t\tendErrorMessage,\n\t\t\tstartName,\n\t\t\tendName,\n\t\t\tstartValue,\n\t\t\tendValue,\n\t\t\tstartDefaultValue,\n\t\t\tendDefaultValue,\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
|
|
13
|
+
"content": "/**\n * A paired-field date range control built on {@link DateField} — independent\n * start-date and end-date fields, each fully labeled, described, and validated\n * on its own — with a {@link DateRangePicker.Group} row for joining the two\n * into one control. The calendar is the platform's, since each field is a\n * native date input, so the whole range is pickable before any script loads.\n * Leaving `children` unset renders the pair 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 { flex, flexCol, gap, items } from \"@sdxc/u/layout\";\nimport { attrs } from \"remix/component\";\n\nimport { DateField } from \"@sdxc/ui/date-field\";\nimport { DatePicker } from \"@sdxc/ui/date-picker\";\n\n/**\n * Prop types for {@link DateRangePicker} and its compound parts.\n * {@link DateRangePicker.Group} aliases {@link DatePicker.Group} directly,\n * since a row of fields reads the same for a range as for a single date.\n */\nexport namespace DateRangePicker {\n\t/**\n\t * Semantic color role for the fallback pair's keyboard focus rings. Read\n\t * only by the fallback fields — {@link DateRangePicker.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 * Per-part styling for the two {@link DateField} instances the fallback\n\t * pair composes, each forwarded to that field's own `parts`. Read only\n\t * when `children` is unset; the composed layout styles its own parts individually instead.\n\t */\n\texport interface PartsProps {\n\t\t/** Per-part styling for the fallback pair's start-date field. */\n\t\tstart?: DateField.PartsProps;\n\t\t/** Per-part styling for the fallback pair's end-date field. */\n\t\tend?: DateField.PartsProps;\n\t}\n\n\t/**\n\t * Props accepted by {@link DateRangePicker}. Leaving `children` unset\n\t * renders two independent {@link DateField} instances — one per end of\n\t * the range — using every field below; composing\n\t * {@link DateRangePicker.Group} instead renders the joined row and leaves\n\t * every field below unread.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback pair's focus rings. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The start-date field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tstartLabel?: RemixNode;\n\t\t/** The end-date field's caption, rendered through {@link DateField}. Read only when `children` is unset. */\n\t\tendLabel?: RemixNode;\n\t\t/** Supporting copy beneath the start-date field. Read only when `children` is unset. */\n\t\tstartDescription?: RemixNode;\n\t\t/** Supporting copy beneath the end-date field. Read only when `children` is unset. */\n\t\tendDescription?: RemixNode;\n\t\t/** Validation message beneath the start-date field. Read only when `children` is unset. */\n\t\tstartErrorMessage?: RemixNode;\n\t\t/** Validation message beneath the end-date field. Read only when `children` is unset. */\n\t\tendErrorMessage?: RemixNode;\n\t\t/** Native `name` submitted with an enclosing form for the start-date field. */\n\t\tstartName?: string;\n\t\t/** Native `name` submitted with an enclosing form for the end-date field. */\n\t\tendName?: string;\n\t\t/** Current start-of-range value, in `YYYY-MM-DD` form, for a fallback pair a consumer tracks itself. */\n\t\tstartValue?: string;\n\t\t/** Current end-of-range value, in `YYYY-MM-DD` form, for a fallback pair a consumer tracks itself. */\n\t\tendValue?: string;\n\t\t/** Initial start-of-range value, in `YYYY-MM-DD` form, for a fallback pair left to the platform's own uncontrolled state. */\n\t\tstartDefaultValue?: string;\n\t\t/** Initial end-of-range value, in `YYYY-MM-DD` form, for a fallback pair left to the platform's own uncontrolled state. */\n\t\tendDefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read by both of the fallback pair's fields. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read by both of the fallback pair's fields. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, both of the fallback pair's values must fall on. */\n\t\tstep?: number;\n\t\t/** Marks both of the fallback pair's fields required for their enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks both of the fallback pair's fields inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks both of the fallback pair's fields' values fixed, while keeping them focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for both of the fallback pair's fields. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback pair's internally composed {@link DateField} instances. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The joined layout — typically a `Label` and a\n\t\t * {@link DateRangePicker.Group} — rendered in place of the paired fields,\n\t\t * leaving every field above unread when set.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every prop {@link DatePicker.GroupProps} accepts, unchanged. `children`\n\t * composes the range's own start and end controls into one visual row.\n\t */\n\texport interface GroupProps extends DatePicker.GroupProps {}\n}\n\n/**\n * Renders {@link DateRangePicker}'s root. Leaving `children` unset renders\n * two independent {@link DateField} instances side by side under a native\n * `role=\"group\"`, each aligned to its own start edge so a validation message\n * under one never shifts the other's label; composing\n * {@link DateRangePicker.Group} as `children` instead joins the two fields into\n * one row and leaves every field prop above unread.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the date range picker's markup.\n * @example\n * <DateRangePicker\n * \tstartLabel={t(\"form.stay.checkIn\")}\n * \tendLabel={t(\"form.stay.checkOut\")}\n * \tstartName=\"checkIn\"\n * \tendName=\"checkOut\"\n * />\n * @example\n * <DateRangePicker>\n * \t<Label htmlFor=\"tripStart\">{t(\"form.trip.label\")}</Label>\n * \t<DateRangePicker.Group>\n * \t\t<Input id=\"tripStart\" type=\"date\" name=\"tripStart\" aria-label={t(\"form.trip.start\")} />\n * \t\t<Input id=\"tripEnd\" type=\"date\" name=\"tripEnd\" aria-label={t(\"form.trip.end\")} />\n * \t</DateRangePicker.Group>\n * </DateRangePicker>\n */\nexport function DateRangePicker(handle: Handle<DateRangePicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tstartLabel,\n\t\t\tendLabel,\n\t\t\tstartDescription,\n\t\t\tendDescription,\n\t\t\tstartErrorMessage,\n\t\t\tendErrorMessage,\n\t\t\tstartName,\n\t\t\tendName,\n\t\t\tstartValue,\n\t\t\tendValue,\n\t\t\tstartDefaultValue,\n\t\t\tendDefaultValue,\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) {\n\t\t\tif (!startLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'DateRangePicker: falling back to paired \"input type=date\" fields needs a \"startLabel\" describing the range\\'s start for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!endLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'DateRangePicker: falling back to paired \"input type=date\" fields needs an \"endLabel\" describing the range\\'s end for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\t{...rest}\n\t\t\t\t\tdata-slot=\"fields\"\n\t\t\t\t\tmix={[attrs({ role: \"group\" }), flex(), gap(2), items(\"start\"), mix]}\n\t\t\t\t>\n\t\t\t\t\t<DateField\n\t\t\t\t\t\tcolor={color}\n\t\t\t\t\t\tlabel={startLabel}\n\t\t\t\t\t\tdescription={startDescription}\n\t\t\t\t\t\terrorMessage={startErrorMessage}\n\t\t\t\t\t\tname={startName}\n\t\t\t\t\t\tvalue={startValue}\n\t\t\t\t\t\tdefaultValue={startDefaultValue}\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\tparts={parts?.start}\n\t\t\t\t\t/>\n\t\t\t\t\t<DateField\n\t\t\t\t\t\tcolor={color}\n\t\t\t\t\t\tlabel={endLabel}\n\t\t\t\t\t\tdescription={endDescription}\n\t\t\t\t\t\terrorMessage={endErrorMessage}\n\t\t\t\t\t\tname={endName}\n\t\t\t\t\t\tvalue={endValue}\n\t\t\t\t\t\tdefaultValue={endDefaultValue}\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\tparts={parts?.end}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"date-range-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 DateRangePicker}'s control row: identical to\n * {@link DatePicker.Group}'s markup and focus-within outline. `children`\n * composes the range's start and end controls with {@link DateRangePicker.Button}, and the row gains a keyboard focus ring whenever focus lands anywhere inside it.\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 * <DateRangePicker.Group>\n * \t<Input id=\"tripStart\" type=\"date\" name=\"tripStart\" aria-label={t(\"form.trip.start\")} />\n * \t<Input id=\"tripEnd\" type=\"date\" name=\"tripEnd\" aria-label={t(\"form.trip.end\")} />\n * </DateRangePicker.Group>\n */\nDateRangePicker.Group = DatePicker.Group;\n"
|
|
14
14
|
},
|
|
15
15
|
"test": null
|
|
16
16
|
}
|
package/registry/ui/dialog.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dialog",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button",
|
|
6
6
|
"heading-scope"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "dialog.tsx",
|
|
13
|
-
"content": "/**\n * A modal surface built on the native `<dialog>` element, opened and closed\n * declaratively through Invoker Commands (`commandfor`/`command`) instead of\n * a JavaScript-tracked open state. Compound parts cover a header, title,\n * description, footer, and a dismiss control, so a page composes only the\n * pieces a given dialog needs.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { XIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport {\n\tbackdropBlur,\n\tbackdropSaturate,\n\topacity,\n\trounded,\n\tshadow,\n\ttransition,\n\ttransitionBehavior,\n} from \"@sdxc/u/effects\";\nimport { raw, vars } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tcontainer,\n\tfixed,\n\tflex,\n\tflexCol,\n\tflexColReverse,\n\tflexRow,\n\tgap,\n\tinset,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { at, media, startingStyle, supports } from \"@sdxc/u/responsive\";\nimport { is, maxBs, maxIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tfontSize,\n\tleading,\n\tpretty,\n\ttextAlign,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport { SHADOW_RING } from \"@sdxc/ui/styles\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Named container {@link Dialog} declares on its own host, so\n * {@link Dialog.Header} and {@link Dialog.Footer} can query the panel's own\n * width instead of the page's.\n */\nconst CONTAINER_NAME = \"ui-dialog\";\n\n/**\n * Panel width from which {@link Dialog.Header} and {@link Dialog.Footer} lay out for a\n * comfortable dialog: a leading title and a trailing row of actions. It is measured\n * against the panel's own inline size, which a dialog keeps well under a viewport's.\n */\nconst COMFORTABLE_WIDTH = \"24rem\";\n\n/**\n * Invoker Commands verb {@link Dialog.CloseProps.command} falls back to when\n * omitted, dismissing the ancestor Dialog named by `commandfor`.\n */\nconst DEFAULT_CLOSE_COMMAND = \"close\";\n\n/**\n * Prop types for {@link Dialog} and its compound parts.\n */\nexport namespace Dialog {\n\t/**\n\t * Every native `<dialog>` attribute, plus the `mix` passthrough. `role`\n\t * stays the platform's implicit `\"dialog\"` unless set to `\"alertdialog\"`,\n\t * and `open`/`closedby` stay the platform's own native state and light-dismiss controls.\n\t */\n\texport interface Props extends TagProps<\"dialog\"> {\n\t\t/** The panel's compound parts: {@link Dialog.Header}, {@link Dialog.Footer}, {@link Dialog.Close}, or any other content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Dialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Title}. Every native heading-element\n\t * attribute still applies, since the rendered tag depends on the nearest\n\t * ambient heading level, falling back to `<h1>` where none is set.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Close}: every {@link Button.Props} field\n\t * except the ones this component fixes on the consumer's behalf.\n\t */\n\texport interface CloseProps extends Omit<\n\t\tButton.Props,\n\t\t\"children\" | \"variant\" | \"color\" | \"size\" | \"aria-label\" | \"commandfor\" | \"command\"\n\t> {\n\t\t/** `id` of the ancestor {@link Dialog} this button dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target Dialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\n\t\t/**\n\t\t * Accessible label for the icon-only control — required, since the\n\t\t * button carries no visible text for assistive technology to read.\n\t\t */\n\t\t\"aria-label\": string;\n\t}\n}\n\n/**\n * Renders the dialog panel as a native `<dialog>` host, its `::backdrop`\n * tinted and, where supported, blurred to dim the page behind it. The panel\n * declares the `ui-dialog` named container so {@link Dialog.Header} and {@link Dialog.Footer} can size against the panel's own width; Invoker Commands open and close it declaratively — a trigger elsewhere points `commandfor` at this element's `id` with `command=\"show-modal\"`, and any control inside, including {@link Dialog.Close}, points `commandfor` at that same `id` with `command=\"close\"`.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Button commandfor=\"confirm-delete\" command=\"show-modal\">{t(\"project.delete\")}</Button>\n * <Dialog id=\"confirm-delete\" aria-labelledby=\"confirm-delete-title\">\n * \t<Dialog.Header>\n * \t\t<Dialog.Title id=\"confirm-delete-title\">{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t\t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * \t</Dialog.Header>\n * \t<Dialog.Footer>\n * \t\t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * \t</Dialog.Footer>\n * \t<Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n * </Dialog>\n * @example\n * <Dialog id=\"welcome\" mix={zoom({ duration: durations.normal })}>\n * \t<Dialog.Header>\n * \t\t<Dialog.Title>{t(\"welcome.title\")}</Dialog.Title>\n * \t</Dialog.Header>\n * </Dialog>\n */\nexport function Dialog(handle: Handle<Dialog.Props>) {\n\treturn () => {\n\t\tlet { id, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env.DEV && !id) {\n\t\t\tconsole.warn(\n\t\t\t\t'Dialog rendered without an \"id\" — \"commandfor\" on a trigger or close control has nothing to target.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<dialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\tdata-slot=\"dialog\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * Establishes the containing block {@link Dialog.Close} pins itself to while\n\t\t\t\t\t * the panel sits in the page's flow, which a dialog opened through its `open`\n\t\t\t\t\t * attribute alone does.\n\t\t\t\t\t */\n\t\t\t\t\trelative(),\n\t\t\t\t\t/**\n\t\t\t\t\t * Measures a modal panel against the viewport, so it stays centered on screen\n\t\t\t\t\t * however far the page behind it is scrolled: the top layer resolves any other\n\t\t\t\t\t * positioning scheme against the document's own coordinates.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:modal\", fixed()),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * Wide enough for the form a dialog usually carries, so a field, its help text and a row\n\t\t\t\t\t * of actions read as one column. A consumer with less to say narrows it through `mix`.\n\t\t\t\t\t */\n\t\t\t\t\tmaxIs(\"32rem\"),\n\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\tgap(6),\n\t\t\t\t\tp(6),\n\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t/** Gated on `[open]` so the UA's own `dialog:not([open])` hiding still applies. */\n\t\t\t\t\twhen(\"&[open]\", flex()),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tcontainer(CONTAINER_NAME, \"inline-size\"),\n\t\t\t\t\twhen(\"&::backdrop\", [\n\t\t\t\t\t\tbg(\"rgb(0 0 0 / 0.5)\"),\n\t\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\t\topacity(0),\n\t\t\t\t\t\ttransition(\"opacity, display, overlay\", {\n\t\t\t\t\t\t\tduration: durations.normal,\n\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&[open]::backdrop\", opacity(100)),\n\t\t\t\t\tsupports(\n\t\t\t\t\t\t\"(backdrop-filter: blur(0))\",\n\t\t\t\t\t\tmedia(\n\t\t\t\t\t\t\t\"(prefers-reduced-transparency: no-preference)\",\n\t\t\t\t\t\t\twhen(\"&::backdrop\", [backdropBlur(\"md\"), backdropSaturate(1.4)]),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\tstartingStyle(when(\"&[open]::backdrop\", opacity(0))),\n\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The panel's edge is a ring shadow that takes on the tone behind it, over a\n\t\t\t\t\t * transparent border that forced-colors mode still paints as a line.\n\t\t\t\t\t */\n\t\t\t\t\tborder({ color: \"transparent\", width: 1 }),\n\t\t\t\t\tshadow(\"xl\"),\n\t\t\t\t\tvars({ \"ui-box-shadow-ring\": SHADOW_RING }),\n\t\t\t\t\t/** `overscrollBehavior` has no matching utility. */\n\t\t\t\t\traw({ overscrollBehavior: \"contain\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Dialog.HeaderProps.children} as the panel's header slot: a\n * column stacking {@link Dialog.Title} and {@link Dialog.Description},\n * centered while narrow and start-aligned (flipping under `dir=\"rtl\"`) once the panel's own `ui-dialog` container grows past `40rem`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <Dialog.Header>\n * \t<Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * </Dialog.Header>\n */\nDialog.Header = function DialogHeader(handle: Handle<Dialog.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tgap(1.5),\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, textAlign(\"start\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.TitleProps.children} as the panel's heading, inside\n * the native heading element matching the nearest ambient heading level —\n * `<h1>` by default — sized and weighted as the panel's most prominent line of text at every level.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n */\nDialog.Title = function DialogTitle(handle: Handle<Dialog.TitleProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\tfontSize(\"lg\"),\n\t\t\t\t\tleading(1),\n\t\t\t\t\tbalance(),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.DescriptionProps.children} as the panel's supporting\n * copy, in a native `<p>` set to the panel's muted foreground color so it\n * reads as secondary to {@link Dialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n */\nDialog.Description = function DialogDescription(handle: Handle<Dialog.DescriptionProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"description\"\n\t\t\t\tmix={[fg(\"neutral.muted\"), fontSize(\"sm\"), pretty(), mix]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.FooterProps.children} as the panel's action row: a\n * column of stacked, full-width controls while the panel is narrow,\n * switching to a single end-aligned row past the panel's own `40rem` container mark.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Dialog.Footer>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" variant=\"outline\">{t(\"actions.cancel\")}</Button>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * </Dialog.Footer>\n */\nDialog.Footer = function DialogFooter(handle: Handle<Dialog.FooterProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"footer\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(2),\n\t\t\t\t\tflexColReverse(),\n\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, [flexRow(), justify(\"end\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a dismiss control for the ancestor {@link Dialog} named by\n * `commandfor`: a small, ghost-styled {@link Button} with a fixed \"X\" glyph,\n * pinned to the panel's corner. `command` defaults to `\"close\"`, so passing only `commandfor` and `aria-label` wires it up.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the dismiss control's markup.\n * @example\n * <Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n */\nDialog.Close = function DialogClose(handle: Handle<Dialog.CloseProps>) {\n\treturn () => {\n\t\tlet { commandfor, command, mix, ...rest } = handle.props;\n\t\tlet resolvedCommand = command ?? DEFAULT_CLOSE_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tcolor=\"neutral\"\n\t\t\t\tsize=\"sm\"\n\t\t\t\tcommandfor={commandfor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"close\"\n\t\t\t\tmix={[absolute(), inset(4, 4, \"auto\", \"auto\"), mix]}\n\t\t\t>\n\t\t\t\t<XIcon size={16} />\n\t\t\t</Button>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
"content": "/**\n * A modal surface built on the native `<dialog>` element, opened and closed\n * declaratively through Invoker Commands (`commandfor`/`command`) instead of\n * a JavaScript-tracked open state. Compound parts cover a header, title,\n * description, footer, and a dismiss control, so a page composes only the\n * pieces a given dialog needs.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { XIcon } from \"@sdxc/icons\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport {\n\tbackdropBlur,\n\tbackdropSaturate,\n\topacity,\n\trounded,\n\tshadow,\n\ttransition,\n\ttransitionBehavior,\n} from \"@sdxc/u/effects\";\nimport { raw, vars } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tcontainer,\n\tfixed,\n\tflex,\n\tflexCol,\n\tflexColReverse,\n\tflexRow,\n\tgap,\n\tinset,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { at, media, startingStyle, supports } from \"@sdxc/u/responsive\";\nimport { is, maxBs, maxIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tfontSize,\n\tleading,\n\tpretty,\n\ttextAlign,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport { SHADOW_RING } from \"@sdxc/ui/styles\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Named container {@link Dialog} declares on its own host, so\n * {@link Dialog.Header} and {@link Dialog.Footer} can query the panel's own\n * width instead of the page's.\n */\nconst CONTAINER_NAME = \"ui-dialog\";\n\n/**\n * Panel width from which {@link Dialog.Header} and {@link Dialog.Footer} lay out for a\n * comfortable dialog: a leading title and a trailing row of actions. It is measured\n * against the panel's own inline size, which a dialog keeps well under a viewport's.\n */\nconst COMFORTABLE_WIDTH = \"24rem\";\n\n/**\n * Invoker Commands verb {@link Dialog.CloseProps.command} falls back to when\n * omitted, dismissing the ancestor Dialog named by `commandfor`.\n */\nconst DEFAULT_CLOSE_COMMAND = \"close\";\n\n/**\n * Prop types for {@link Dialog} and its compound parts.\n */\nexport namespace Dialog {\n\t/**\n\t * Every native `<dialog>` attribute, plus the `mix` passthrough. `role`\n\t * stays the platform's implicit `\"dialog\"` unless set to `\"alertdialog\"`,\n\t * and `open`/`closedby` stay the platform's own native state and light-dismiss controls.\n\t */\n\texport interface Props extends TagProps<\"dialog\"> {\n\t\t/** The panel's compound parts: {@link Dialog.Header}, {@link Dialog.Footer}, {@link Dialog.Close}, or any other content. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Dialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Title}. Every native heading-element\n\t * attribute still applies, since the rendered tag depends on the nearest\n\t * ambient heading level, falling back to `<h1>` where none is set.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link Dialog.Close}: every {@link Button.Props} field\n\t * except the ones this component fixes on the consumer's behalf.\n\t */\n\texport interface CloseProps extends Omit<\n\t\tButton.Props,\n\t\t\"children\" | \"variant\" | \"color\" | \"size\" | \"aria-label\" | \"commandfor\" | \"command\"\n\t> {\n\t\t/** `id` of the ancestor {@link Dialog} this button dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target Dialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\n\t\t/**\n\t\t * Accessible label for the icon-only control — required, since the\n\t\t * button carries no visible text for assistive technology to read.\n\t\t */\n\t\t\"aria-label\": string;\n\t}\n}\n\n/**\n * Renders the dialog panel as a native `<dialog>` host, its `::backdrop`\n * tinted and, where supported, blurred to dim the page behind it. The panel\n * declares the `ui-dialog` named container so {@link Dialog.Header} and {@link Dialog.Footer} can size against the panel's own width; Invoker Commands open and close it declaratively — a trigger elsewhere points `commandfor` at this element's `id` with `command=\"show-modal\"`, and any control inside, including {@link Dialog.Close}, points `commandfor` at that same `id` with `command=\"close\"`.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Button commandfor=\"confirm-delete\" command=\"show-modal\">{t(\"project.delete\")}</Button>\n * <Dialog id=\"confirm-delete\" aria-labelledby=\"confirm-delete-title\">\n * \t<Dialog.Header>\n * \t\t<Dialog.Title id=\"confirm-delete-title\">{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t\t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * \t</Dialog.Header>\n * \t<Dialog.Footer>\n * \t\t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * \t</Dialog.Footer>\n * \t<Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n * </Dialog>\n * @example\n * <Dialog id=\"welcome\" mix={zoom({ duration: durations.normal })}>\n * \t<Dialog.Header>\n * \t\t<Dialog.Title>{t(\"welcome.title\")}</Dialog.Title>\n * \t</Dialog.Header>\n * </Dialog>\n */\nexport function Dialog(handle: Handle<Dialog.Props>) {\n\treturn () => {\n\t\tlet { id, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env?.DEV && !id) {\n\t\t\tconsole.warn(\n\t\t\t\t'Dialog rendered without an \"id\" — \"commandfor\" on a trigger or close control has nothing to target.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<dialog\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\tdata-slot=\"dialog\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * Establishes the containing block {@link Dialog.Close} pins itself to while\n\t\t\t\t\t * the panel sits in the page's flow, which a dialog opened through its `open`\n\t\t\t\t\t * attribute alone does.\n\t\t\t\t\t */\n\t\t\t\t\trelative(),\n\t\t\t\t\t/**\n\t\t\t\t\t * Measures a modal panel against the viewport, so it stays centered on screen\n\t\t\t\t\t * however far the page behind it is scrolled: the top layer resolves any other\n\t\t\t\t\t * positioning scheme against the document's own coordinates.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:modal\", fixed()),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * Wide enough for the form a dialog usually carries, so a field, its help text and a row\n\t\t\t\t\t * of actions read as one column. A consumer with less to say narrows it through `mix`.\n\t\t\t\t\t */\n\t\t\t\t\tmaxIs(\"32rem\"),\n\t\t\t\t\tmaxBs(\"90vh\"),\n\t\t\t\t\tgap(6),\n\t\t\t\t\tp(6),\n\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t/** Gated on `[open]` so the UA's own `dialog:not([open])` hiding still applies. */\n\t\t\t\t\twhen(\"&[open]\", flex()),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tcontainer(CONTAINER_NAME, \"inline-size\"),\n\t\t\t\t\twhen(\"&::backdrop\", [\n\t\t\t\t\t\tbg(\"rgb(0 0 0 / 0.5)\"),\n\t\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\t\topacity(0),\n\t\t\t\t\t\ttransition(\"opacity, display, overlay\", {\n\t\t\t\t\t\t\tduration: durations.normal,\n\t\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&[open]::backdrop\", opacity(100)),\n\t\t\t\t\tsupports(\n\t\t\t\t\t\t\"(backdrop-filter: blur(0))\",\n\t\t\t\t\t\tmedia(\n\t\t\t\t\t\t\t\"(prefers-reduced-transparency: no-preference)\",\n\t\t\t\t\t\t\twhen(\"&::backdrop\", [backdropBlur(\"md\"), backdropSaturate(1.4)]),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t\tstartingStyle(when(\"&[open]::backdrop\", opacity(0))),\n\t\t\t\t\toutline(\"none\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The panel's edge is a ring shadow that takes on the tone behind it, over a\n\t\t\t\t\t * transparent border that forced-colors mode still paints as a line.\n\t\t\t\t\t */\n\t\t\t\t\tborder({ color: \"transparent\", width: 1 }),\n\t\t\t\t\tshadow(\"xl\"),\n\t\t\t\t\tvars({ \"ui-box-shadow-ring\": SHADOW_RING }),\n\t\t\t\t\t/** `overscrollBehavior` has no matching utility. */\n\t\t\t\t\traw({ overscrollBehavior: \"contain\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Dialog.HeaderProps.children} as the panel's header slot: a\n * column stacking {@link Dialog.Title} and {@link Dialog.Description},\n * centered while narrow and start-aligned (flipping under `dir=\"rtl\"`) once the panel's own `ui-dialog` container grows past `40rem`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <Dialog.Header>\n * \t<Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n * \t<Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n * </Dialog.Header>\n */\nDialog.Header = function DialogHeader(handle: Handle<Dialog.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tgap(1.5),\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, textAlign(\"start\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.TitleProps.children} as the panel's heading, inside\n * the native heading element matching the nearest ambient heading level —\n * `<h1>` by default — sized and weighted as the panel's most prominent line of text at every level.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <Dialog.Title>{t(\"project.deleteTitle\")}</Dialog.Title>\n */\nDialog.Title = function DialogTitle(handle: Handle<Dialog.TitleProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\tfontSize(\"lg\"),\n\t\t\t\t\tleading(1),\n\t\t\t\t\tbalance(),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.DescriptionProps.children} as the panel's supporting\n * copy, in a native `<p>` set to the panel's muted foreground color so it\n * reads as secondary to {@link Dialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Dialog.Description>{t(\"project.deleteDescription\")}</Dialog.Description>\n */\nDialog.Description = function DialogDescription(handle: Handle<Dialog.DescriptionProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"description\"\n\t\t\t\tmix={[fg(\"neutral.muted\"), fontSize(\"sm\"), pretty(), mix]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link Dialog.FooterProps.children} as the panel's action row: a\n * column of stacked, full-width controls while the panel is narrow,\n * switching to a single end-aligned row past the panel's own `40rem` container mark.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Dialog.Footer>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" variant=\"outline\">{t(\"actions.cancel\")}</Button>\n * \t<Button commandfor=\"confirm-delete\" command=\"close\" color=\"danger\">{t(\"actions.delete\")}</Button>\n * </Dialog.Footer>\n */\nDialog.Footer = function DialogFooter(handle: Handle<Dialog.FooterProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"footer\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(2),\n\t\t\t\t\tflexColReverse(),\n\t\t\t\t\tat(COMFORTABLE_WIDTH, CONTAINER_NAME, [flexRow(), justify(\"end\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a dismiss control for the ancestor {@link Dialog} named by\n * `commandfor`: a small, ghost-styled {@link Button} with a fixed \"X\" glyph,\n * pinned to the panel's corner. `command` defaults to `\"close\"`, so passing only `commandfor` and `aria-label` wires it up.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the dismiss control's markup.\n * @example\n * <Dialog.Close commandfor=\"confirm-delete\" aria-label={t(\"actions.close\")} />\n */\nDialog.Close = function DialogClose(handle: Handle<Dialog.CloseProps>) {\n\treturn () => {\n\t\tlet { commandfor, command, mix, ...rest } = handle.props;\n\t\tlet resolvedCommand = command ?? DEFAULT_CLOSE_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tvariant=\"ghost\"\n\t\t\t\tcolor=\"neutral\"\n\t\t\t\tsize=\"sm\"\n\t\t\t\tcommandfor={commandfor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"close\"\n\t\t\t\tmix={[absolute(), inset(4, 4, \"auto\", \"auto\"), mix]}\n\t\t\t>\n\t\t\t\t<XIcon size={16} />\n\t\t\t</Button>\n\t\t);\n\t};\n};\n"
|
|
14
14
|
},
|
|
15
15
|
"test": {
|
|
16
16
|
"path": "dialog.test.tsx",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "file-trigger",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"FileTrigger"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "file-trigger.tsx",
|
|
10
|
-
"content": "/**\n * A pressable surface that opens the platform's file picker, backed by a\n * native `<input type=\"file\">` wrapped in a `<label>` so the platform itself\n * handles the trigger-to-picker wiring. Its visible content renders inside\n * the same label as a button-like surface, colored, weighted, and sized\n * through the same semantic contract as this library's other pressable\n * controls.\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 { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, userSelect } from \"@sdxc/u/general\";\nimport { gap, inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minBs, pb, pi } from \"@sdxc/u/size\";\nimport { active, data, hover, when } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { hasAccessibleText } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link FileTrigger} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: FileTrigger.Color = \"neutral\";\n\n/** Visual weight {@link FileTrigger} falls back to when `variant` is omitted. */\nconst DEFAULT_VARIANT: FileTrigger.Variant = \"solid\";\n\n/** Size variant {@link FileTrigger} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: FileTrigger.Size = \"md\";\n\n/**\n * Prop types for {@link FileTrigger}.\n */\nexport namespace FileTrigger {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Visual weight the trigger renders with: a solid fill with an on-solid\n\t * foreground, a transparent fill with a strong colored border, or a fully\n\t * transparent fill with just a colored label.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\";\n\n\t/**\n\t * Size variant controlling the trigger's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Per-part styling for the elements this component composes besides its\n\t * own host `<input>`.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the `<label>` rendering as the trigger's visible, pressable surface. */\n\t\ttrigger?: TagProps<\"label\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link FileTrigger}. Every native `<input type=\"file\">`\n\t * attribute applies unchanged except `type` (fixed `\"file\"`), `role` (not\n\t * overridable on a file input), and `size` (repurposed for visual size).\n\t */\n\texport interface Props extends Omit<TagProps<\"input\">, \"type\" | \"role\" | \"size\"> {\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */\n\t\tvariant?: Variant;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t\t/**\n\t\t * Switches the picker from choosing individual files to choosing whole\n\t\t * directories, carrying every file nested inside the chosen directory.\n\t\t */\n\t\tacceptDirectory?: boolean;\n\t\t/**\n\t\t * The trigger's visible content, rendered inside the same `<label>` that\n\t\t * wraps the host `<input>` — an icon, text, or both, kept decorative so\n\t\t * the platform's label-to-control association reaches the input on click.\n\t\t */\n\t\tchildren?: RemixNode;\n\t\t/** Per-part styling for this component's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Renders a native `<input type=\"file\">` wrapped in a `<label>` styled\n * through this library's shared `data-color`/`data-variant`/`data-size`\n * contract; in dev mode, content lacking an accessible name logs a warning.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <FileTrigger name=\"avatar\" accept=\"image/png, image/jpeg\">\n * \t{t(\"profile.chooseFile\")}\n * </FileTrigger>\n * @example\n * <FileTrigger name=\"attachments\" multiple color=\"brand\" variant=\"outline\">\n * \t{t(\"thread.attachFiles\")}\n * </FileTrigger>\n * @example\n * <FileTrigger name=\"folder\" acceptDirectory aria-label={t(\"importer.chooseFolder\")} />\n */\nexport function FileTrigger(handle: Handle<FileTrigger.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, acceptDirectory, children, parts, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\n\t\tif (\n\t\t\timport.meta.env.DEV &&\n\t\t\t!handle.props[\"aria-label\"] &&\n\t\t\t!handle.props[\"aria-labelledby\"] &&\n\t\t\t!hasAccessibleText(children)\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"FileTrigger: a trigger with no visible label text needs an `aria-label` describing what it opens — assistive technology has no accessible name to announce otherwise.\",\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-variant={resolvedVariant}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tgap(2),\n\t\t\t\t\t/**\n\t\t\t\t\t * A glyph is sized against the label beside it and holds that size, so the row keeps the\n\t\t\t\t\t * height its text and padding ask for; the default `flex-shrink: 1` would squash the glyph\n\t\t\t\t\t * ahead of the words.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& > svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\twhen(\"&:has(input:focus-visible)\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", outline(\"neutral.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"success\", outline(\"success.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"warning\", outline(\"warning.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"danger\", outline(\"danger.ring\")),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&:has(input:disabled)\", [opacity(50), cursor(\"not-allowed\")]),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\tuserSelect(),\n\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\ttext(\"sm\"),\n\n\t\t\t\t\t/**\n\t\t\t\t\t * The row measure is stated, so the control lines up with a field of the same size when\n\t\t\t\t\t * a Group fuses the two, and still grows when a long label wraps.\n\t\t\t\t\t */\n\t\t\t\t\tminBs(\"2.5rem\"),\n\n\t\t\t\t\tdata(\"size\", \"sm\", [\n\t\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\t\tpb(\"0.375rem\"),\n\t\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\t\tminBs(\"2rem\"),\n\t\t\t\t\t\twhen(\"& > svg\", [is(3), bs(3)]),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"size\", \"lg\", [pi(\"1.25rem\"), pb(\"0.625rem\"), text(\"base\"), minBs(\"3rem\")]),\n\n\t\t\t\t\tdata(\"variant\", \"solid\", [\n\t\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"brand.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\t\tbg(\"success.solid\"),\n\t\t\t\t\t\t\tfg(\"success.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"success.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\t\tbg(\"warning.solid\"),\n\t\t\t\t\t\t\tfg(\"warning.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"warning.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\t\tbg(\"danger.solid\"),\n\t\t\t\t\t\t\tfg(\"danger.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"danger.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"variant\", \"outline\", [\n\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\t\tborder(\"brand\"),\n\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\thover([bg(\"brand.tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\thover([bg(\"neutral.tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\t\tborder(\"success\"),\n\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\thover([bg(\"success.tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\t\tborder(\"warning\"),\n\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\thover([bg(\"warning.tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\thover([bg(\"danger.tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"variant\", \"ghost\", [\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\thover(bg(\"brand.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\thover(bg(\"success.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\thover(bg(\"warning.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\thover(bg(\"danger.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\n\t\t\t\t\tparts?.trigger,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t\t<input\n\t\t\t\t\ttype=\"file\"\n\t\t\t\t\t{...rest}\n\t\t\t\t\tmix={[acceptDirectory && attrs({ webkitdirectory: true }), visuallyHidden(), mix]}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t);\n\t};\n}\n"
|
|
10
|
+
"content": "/**\n * A pressable surface that opens the platform's file picker, backed by a\n * native `<input type=\"file\">` wrapped in a `<label>` so the platform itself\n * handles the trigger-to-picker wiring. Its visible content renders inside\n * the same label as a button-like surface, colored, weighted, and sized\n * through the same semantic contract as this library's other pressable\n * controls.\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 { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, userSelect } from \"@sdxc/u/general\";\nimport { gap, inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { bs, is, minBs, pb, pi } from \"@sdxc/u/size\";\nimport { active, data, hover, when } from \"@sdxc/u/state\";\nimport { text, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { hasAccessibleText } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link FileTrigger} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: FileTrigger.Color = \"neutral\";\n\n/** Visual weight {@link FileTrigger} falls back to when `variant` is omitted. */\nconst DEFAULT_VARIANT: FileTrigger.Variant = \"solid\";\n\n/** Size variant {@link FileTrigger} falls back to when `size` is omitted. */\nconst DEFAULT_SIZE: FileTrigger.Size = \"md\";\n\n/**\n * Prop types for {@link FileTrigger}.\n */\nexport namespace FileTrigger {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Visual weight the trigger renders with: a solid fill with an on-solid\n\t * foreground, a transparent fill with a strong colored border, or a fully\n\t * transparent fill with just a colored label.\n\t */\n\texport type Variant = \"solid\" | \"outline\" | \"ghost\";\n\n\t/**\n\t * Size variant controlling the trigger's padding and font size.\n\t */\n\texport type Size = \"sm\" | \"md\" | \"lg\";\n\n\t/**\n\t * Per-part styling for the elements this component composes besides its\n\t * own host `<input>`.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the `<label>` rendering as the trigger's visible, pressable surface. */\n\t\ttrigger?: TagProps<\"label\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link FileTrigger}. Every native `<input type=\"file\">`\n\t * attribute applies unchanged except `type` (fixed `\"file\"`), `role` (not\n\t * overridable on a file input), and `size` (repurposed for visual size).\n\t */\n\texport interface Props extends Omit<TagProps<\"input\">, \"type\" | \"role\" | \"size\"> {\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Visual weight. Defaults to {@link DEFAULT_VARIANT}. */\n\t\tvariant?: Variant;\n\t\t/** Size variant. Defaults to {@link DEFAULT_SIZE}. */\n\t\tsize?: Size;\n\t\t/**\n\t\t * Switches the picker from choosing individual files to choosing whole\n\t\t * directories, carrying every file nested inside the chosen directory.\n\t\t */\n\t\tacceptDirectory?: boolean;\n\t\t/**\n\t\t * The trigger's visible content, rendered inside the same `<label>` that\n\t\t * wraps the host `<input>` — an icon, text, or both, kept decorative so\n\t\t * the platform's label-to-control association reaches the input on click.\n\t\t */\n\t\tchildren?: RemixNode;\n\t\t/** Per-part styling for this component's internally composed elements. */\n\t\tparts?: PartsProps;\n\t}\n}\n\n/**\n * Renders a native `<input type=\"file\">` wrapped in a `<label>` styled\n * through this library's shared `data-color`/`data-variant`/`data-size`\n * contract; in dev mode, content lacking an accessible name logs a warning.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <FileTrigger name=\"avatar\" accept=\"image/png, image/jpeg\">\n * \t{t(\"profile.chooseFile\")}\n * </FileTrigger>\n * @example\n * <FileTrigger name=\"attachments\" multiple color=\"brand\" variant=\"outline\">\n * \t{t(\"thread.attachFiles\")}\n * </FileTrigger>\n * @example\n * <FileTrigger name=\"folder\" acceptDirectory aria-label={t(\"importer.chooseFolder\")} />\n */\nexport function FileTrigger(handle: Handle<FileTrigger.Props>) {\n\treturn () => {\n\t\tlet { color, variant, size, acceptDirectory, children, parts, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedVariant = variant ?? DEFAULT_VARIANT;\n\t\tlet resolvedSize = size ?? DEFAULT_SIZE;\n\n\t\tif (\n\t\t\timport.meta.env?.DEV &&\n\t\t\t!handle.props[\"aria-label\"] &&\n\t\t\t!handle.props[\"aria-labelledby\"] &&\n\t\t\t!hasAccessibleText(children)\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"FileTrigger: a trigger with no visible label text needs an `aria-label` describing what it opens — assistive technology has no accessible name to announce otherwise.\",\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-variant={resolvedVariant}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tgap(2),\n\t\t\t\t\t/**\n\t\t\t\t\t * A glyph is sized against the label beside it and holds that size, so the row keeps the\n\t\t\t\t\t * height its text and padding ask for; the default `flex-shrink: 1` would squash the glyph\n\t\t\t\t\t * ahead of the words.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& > svg\", [shrink(), is(4), bs(4)]),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\twhen(\"&:has(input:focus-visible)\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", outline(\"neutral.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"success\", outline(\"success.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"warning\", outline(\"warning.ring\")),\n\t\t\t\t\t\tdata(\"color\", \"danger\", outline(\"danger.ring\")),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&:has(input:disabled)\", [opacity(50), cursor(\"not-allowed\")]),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\tuserSelect(),\n\t\t\t\t\tpi(\"1rem\"),\n\t\t\t\t\tpb(\"0.5rem\"),\n\t\t\t\t\ttext(\"sm\"),\n\n\t\t\t\t\t/**\n\t\t\t\t\t * The row measure is stated, so the control lines up with a field of the same size when\n\t\t\t\t\t * a Group fuses the two, and still grows when a long label wraps.\n\t\t\t\t\t */\n\t\t\t\t\tminBs(\"2.5rem\"),\n\n\t\t\t\t\tdata(\"size\", \"sm\", [\n\t\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\t\tpb(\"0.375rem\"),\n\t\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\t\tminBs(\"2rem\"),\n\t\t\t\t\t\twhen(\"& > svg\", [is(3), bs(3)]),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"size\", \"lg\", [pi(\"1.25rem\"), pb(\"0.625rem\"), text(\"base\"), minBs(\"3rem\")]),\n\n\t\t\t\t\tdata(\"variant\", \"solid\", [\n\t\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"brand.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\t\tbg(\"neutral.solid\"),\n\t\t\t\t\t\t\tfg(\"neutral.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\t\tbg(\"success.solid\"),\n\t\t\t\t\t\t\tfg(\"success.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"success.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\t\tbg(\"warning.solid\"),\n\t\t\t\t\t\t\tfg(\"warning.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"warning.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\t\tbg(\"danger.solid\"),\n\t\t\t\t\t\t\tfg(\"danger.onSolid\"),\n\t\t\t\t\t\t\thover(bg(\"danger.bg-solid-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-solid-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"variant\", \"outline\", [\n\t\t\t\t\t\tborder({ width: 1, noStyleDefault: true }),\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\t\tborder(\"brand\"),\n\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\thover([bg(\"brand.tint\"), border(\"brand.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\thover([bg(\"neutral.tint\"), border(\"neutral.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\t\tborder(\"success\"),\n\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\thover([bg(\"success.tint\"), border(\"success.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\t\tborder(\"warning\"),\n\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\thover([bg(\"warning.tint\"), border(\"warning.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\thover([bg(\"danger.tint\"), border(\"danger.border-hover\")]),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\n\t\t\t\t\tdata(\"variant\", \"ghost\", [\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\thover(bg(\"brand.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"brand.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\thover(bg(\"success.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"success.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\thover(bg(\"warning.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"warning.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\thover(bg(\"danger.tint\")),\n\t\t\t\t\t\t\tactive(bg(\"danger.bg-tint-hover\")),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\n\t\t\t\t\tparts?.trigger,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t\t<input\n\t\t\t\t\ttype=\"file\"\n\t\t\t\t\t{...rest}\n\t\t\t\t\tmix={[acceptDirectory && attrs({ webkitdirectory: true }), visuallyHidden(), mix]}\n\t\t\t\t/>\n\t\t\t</label>\n\t\t);\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": null
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "heading-scope",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"HeadingLevel",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"source": {
|
|
13
13
|
"path": "heading-scope.tsx",
|
|
14
|
-
"content": "/**\n * Establishes an ambient heading level read by nested headings and scopes,\n * keeping a document outline sequential without passing a level by hand.\n * Nesting moves one level deeper unless an explicit `level` fixes it, and\n * renders a `display: contents` host so composing it adds no layout box\n * while still exposing the depth via `data-heading-level`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { contents } from \"@sdxc/u/layout\";\n\n/**\n * Semantic depth, from `1` (`<h1>`) through `6` (`<h6>`), shared by every\n * heading-related component's level resolution.\n */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Native tag rendered for each supported {@link HeadingLevel}, as a single\n * level-to-element lookup table.\n */\nexport const TAG_BY_LEVEL: Record<HeadingLevel, \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\"> = {\n\t1: \"h1\",\n\t2: \"h2\",\n\t3: \"h3\",\n\t4: \"h4\",\n\t5: \"h5\",\n\t6: \"h6\",\n};\n\nconst DEFAULT_LEVEL: HeadingLevel = 1;\n\n/** Deepest semantic depth the native heading elements support; a resolution past this clamps down to it. */\nconst MAX_LEVEL: HeadingLevel = 6;\n\n/**\n * Prop and context types for {@link HeadingScope}.\n */\nexport namespace HeadingScope {\n\t/** Value {@link HeadingScope} provides to descendants through context. */\n\texport interface Context {\n\t\t/** Semantic depth this scope establishes for the headings and nested scopes rendered inside it. */\n\t\tlevel: HeadingLevel;\n\t}\n\n\t/**\n\t * Native `<div>` attributes, plus `mix` and an optional `level` that\n\t * fixes this scope's depth outright, overriding the ambient\n\t * one-level-deeper default.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Explicit semantic depth for this scope. Defaults to one level past\n\t\t * the nearest ancestor scope's depth, or `1` where no scope wraps\n\t\t * this one at all.\n\t\t */\n\t\tlevel?: HeadingLevel;\n\t}\n}\n\n/**\n * Reads the semantic depth from the nearest ancestor {@link HeadingScope},\n * always resolving safely to `undefined` when no ancestor scope exists,\n * regardless of how that absence surfaces.\n *\n * @param handle Runtime handle of the component performing the lookup.\n * @returns The nearest ancestor scope's depth, or `undefined` where nothing wraps the caller.\n * @example\n * let ambient = readAmbientLevel(handle); // 2, nested inside a HeadingScope holding level 2\n */\nexport function readAmbientLevel(handle: Handle<unknown, any>): HeadingLevel | undefined {\n\ttry {\n\t\tlet ambient = handle.context.get(HeadingScope) as HeadingScope.Context | undefined;\n\n\t\treturn ambient?.level;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves the semantic depth a heading renders at: an explicit level wins,\n * then the nearest ancestor {@link HeadingScope}'s depth, then `1`, clamped\n * to `6` with a dev-mode warning to flatten or restart the nesting.\n *\n * @param handle Runtime handle of the component resolving its depth.\n * @param explicitLevel A `level` passed directly to the component, if any.\n * @returns The resolved, clamped {@link HeadingLevel}.\n * @example\n * let level = resolveHeadingLevel(handle, handle.props.level); // an explicit level always wins\n */\nexport function resolveHeadingLevel(\n\thandle: Handle<unknown, any>,\n\texplicitLevel?: HeadingLevel,\n): HeadingLevel {\n\tlet resolved: number = explicitLevel ?? readAmbientLevel(handle) ?? DEFAULT_LEVEL;\n\n\tif (resolved > MAX_LEVEL) {\n\t\tif (import.meta.env
|
|
14
|
+
"content": "/**\n * Establishes an ambient heading level read by nested headings and scopes,\n * keeping a document outline sequential without passing a level by hand.\n * Nesting moves one level deeper unless an explicit `level` fixes it, and\n * renders a `display: contents` host so composing it adds no layout box\n * while still exposing the depth via `data-heading-level`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { contents } from \"@sdxc/u/layout\";\n\n/**\n * Semantic depth, from `1` (`<h1>`) through `6` (`<h6>`), shared by every\n * heading-related component's level resolution.\n */\nexport type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Native tag rendered for each supported {@link HeadingLevel}, as a single\n * level-to-element lookup table.\n */\nexport const TAG_BY_LEVEL: Record<HeadingLevel, \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\"> = {\n\t1: \"h1\",\n\t2: \"h2\",\n\t3: \"h3\",\n\t4: \"h4\",\n\t5: \"h5\",\n\t6: \"h6\",\n};\n\nconst DEFAULT_LEVEL: HeadingLevel = 1;\n\n/** Deepest semantic depth the native heading elements support; a resolution past this clamps down to it. */\nconst MAX_LEVEL: HeadingLevel = 6;\n\n/**\n * Prop and context types for {@link HeadingScope}.\n */\nexport namespace HeadingScope {\n\t/** Value {@link HeadingScope} provides to descendants through context. */\n\texport interface Context {\n\t\t/** Semantic depth this scope establishes for the headings and nested scopes rendered inside it. */\n\t\tlevel: HeadingLevel;\n\t}\n\n\t/**\n\t * Native `<div>` attributes, plus `mix` and an optional `level` that\n\t * fixes this scope's depth outright, overriding the ambient\n\t * one-level-deeper default.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Explicit semantic depth for this scope. Defaults to one level past\n\t\t * the nearest ancestor scope's depth, or `1` where no scope wraps\n\t\t * this one at all.\n\t\t */\n\t\tlevel?: HeadingLevel;\n\t}\n}\n\n/**\n * Reads the semantic depth from the nearest ancestor {@link HeadingScope},\n * always resolving safely to `undefined` when no ancestor scope exists,\n * regardless of how that absence surfaces.\n *\n * @param handle Runtime handle of the component performing the lookup.\n * @returns The nearest ancestor scope's depth, or `undefined` where nothing wraps the caller.\n * @example\n * let ambient = readAmbientLevel(handle); // 2, nested inside a HeadingScope holding level 2\n */\nexport function readAmbientLevel(handle: Handle<unknown, any>): HeadingLevel | undefined {\n\ttry {\n\t\tlet ambient = handle.context.get(HeadingScope) as HeadingScope.Context | undefined;\n\n\t\treturn ambient?.level;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolves the semantic depth a heading renders at: an explicit level wins,\n * then the nearest ancestor {@link HeadingScope}'s depth, then `1`, clamped\n * to `6` with a dev-mode warning to flatten or restart the nesting.\n *\n * @param handle Runtime handle of the component resolving its depth.\n * @param explicitLevel A `level` passed directly to the component, if any.\n * @returns The resolved, clamped {@link HeadingLevel}.\n * @example\n * let level = resolveHeadingLevel(handle, handle.props.level); // an explicit level always wins\n */\nexport function resolveHeadingLevel(\n\thandle: Handle<unknown, any>,\n\texplicitLevel?: HeadingLevel,\n): HeadingLevel {\n\tlet resolved: number = explicitLevel ?? readAmbientLevel(handle) ?? DEFAULT_LEVEL;\n\n\tif (resolved > MAX_LEVEL) {\n\t\tif (import.meta.env?.DEV) {\n\t\t\tconsole.warn(\n\t\t\t\t`Heading nesting resolved to level ${resolved}, past the native \"h1\"–\"h6\" range. Flatten the nesting, or start a new top-level HeadingScope instead of nesting further.`,\n\t\t\t);\n\t\t}\n\n\t\treturn MAX_LEVEL;\n\t}\n\n\treturn resolved as HeadingLevel;\n}\n\n/**\n * Establishes an ambient heading level for descendants: an explicit `level`\n * fixes it, otherwise one level past the nearest ancestor {@link HeadingScope},\n * read before this scope publishes its own depth, or `1` with no ancestor.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link HeadingScope.Context} to descendants.\n * @returns The render function producing the scope's markup.\n * @example\n * <HeadingScope>\n * \t<Heading>Document title</Heading>\n * \t<HeadingScope>\n * \t\t<Heading>Section title</Heading>\n * \t</HeadingScope>\n * </HeadingScope>\n */\nexport function HeadingScope(handle: Handle<HeadingScope.Props, HeadingScope.Context>) {\n\treturn () => {\n\t\tlet { level, mix, ...rest } = handle.props;\n\t\tlet ambient = readAmbientLevel(handle);\n\t\tlet requested = level ?? (ambient === undefined ? undefined : ((ambient + 1) as HeadingLevel));\n\t\tlet resolved = resolveHeadingLevel(handle, requested);\n\n\t\thandle.context.set({ level: resolved });\n\n\t\treturn <div {...rest} data-heading-level={resolved} mix={[contents(), mix]} />;\n\t};\n}\n"
|
|
15
15
|
},
|
|
16
16
|
"test": {
|
|
17
17
|
"path": "heading-scope.test.ts",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "message-scroller",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button",
|
|
6
6
|
"scroll-area"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "message-scroller.tsx",
|
|
13
|
-
"content": "/**\n * A scrollable frame for a conversational message log. Its viewport reuses\n * the same scrollbar treatment every scrolling surface in this catalog\n * shares and fades its own edges to hint at history above and replies still\n * below; its content region announces newly appended rows through the ARIA\n * log role; each row carries the message id and anchor data a scroll-follow\n * behavior reads; and a static jump-to-latest control sits ready for that\n * same behavior to reveal.\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 { border } from \"@sdxc/u/color\";\nimport { rounded, shadow } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tinsIe,\n\tinsIs,\n\tinset,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\nimport { translateProperty } from \"@sdxc/u/transform\";\nimport { attrs } from \"remix/component\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { ScrollArea } from \"@sdxc/ui/scroll-area\";\n\n/**\n * Named container {@link MessageScroller} declares on its own host, so\n * {@link MessageScroller.Button} can size its own placement to the\n * frame's own width.\n */\nconst CONTAINER_NAME = \"ui-message-scroller\";\n\n/**\n * Container width under which {@link MessageScroller.Button} switches from a\n * centered floating pill to a bar stretched across the frame's own inline\n * size. It is measured against the frame's own width, which a conversation\n * column keeps well under a viewport's, so only a phone-width column reaches it.\n */\nconst BUTTON_NARROW_QUERY = `@container ${CONTAINER_NAME} (max-width: 20rem)`;\n\n/**\n * `role=\"log\"` applied to {@link MessageScroller.Content} through\n * {@link attrs} unless a consumer supplies its own `role`, whose implicit\n * `aria-live=\"polite\"` behavior announces each newly appended row.\n */\nconst DEFAULT_CONTENT_ROLE = \"log\";\n\n/**\n * `aria-relevant=\"additions\"` applied to {@link MessageScroller.Content}\n * through {@link attrs} unless overridden, scoping assistive-technology\n * announcements to newly appended rows.\n */\nconst DEFAULT_CONTENT_ARIA_RELEVANT = \"additions\";\n\n/** Semantic color role {@link MessageScroller.Button} falls back to when `color` is omitted. */\nconst DEFAULT_BUTTON_COLOR: Button.Color = \"neutral\";\n\n/**\n * Visual weight {@link MessageScroller.Button} falls back to when `variant` is omitted.\n * The control floats over a conversation it points at rather than competing with it, so\n * it reads as a surface of its own carrying an arrow.\n */\nconst DEFAULT_BUTTON_VARIANT: Button.Variant = \"outline\";\n\n/** Size variant {@link MessageScroller.Button} falls back to when `size` is omitted. */\nconst DEFAULT_BUTTON_SIZE: Button.Size = \"sm\";\n\n/**\n * `hidden` applied to {@link MessageScroller.Button} when a consumer omits\n * it: the control starts absent from rendering and the accessibility tree\n * until a paired scroll-follow behavior reveals it.\n */\nconst DEFAULT_BUTTON_HIDDEN = true;\n\n/**\n * Prop types for {@link MessageScroller} and its compound parts.\n */\nexport namespace MessageScroller {\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * Size the frame through `mix` since {@link MessageScroller.Viewport}\n\t * fills whatever block size this host resolves to.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** The frame's compound parts: {@link MessageScroller.Viewport} and, optionally, {@link MessageScroller.Button}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ViewportProps extends TagProps<\"div\"> {\n\t\t/** {@link MessageScroller.Content}, scrolling inside the viewport. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Marks the log as busy while a row inside it is still being written\n\t\t * to — a reply still streaming in, for instance — forwarded to the host's\n\t\t * native `aria-busy` attribute. Clear it once the row settles.\n\t\t */\n\t\t\"aria-busy\"?: TagProps<\"div\">[\"aria-busy\"];\n\t\t/** The {@link MessageScroller.Item} rows to render in document order. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ItemProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Stable id of the message this row renders, mirrored onto the host's\n\t\t * `data-message-id` attribute so a scroll-follow behavior can find,\n\t\t * measure, and scroll to this exact row directly.\n\t\t */\n\t\tmessageId: string;\n\t\t/**\n\t\t * Marks this row as a candidate anchor point — typically the first row\n\t\t * of a new turn — mirrored onto `data-scroll-anchor` so a scroll-follow\n\t\t * behavior can tell which rows are worth anchoring the viewport to.\n\t\t *\n\t\t * @default false\n\t\t */\n\t\tscrollAnchor?: boolean;\n\t\t/** The row's own content, typically a conversational row composed inside it. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every {@link Button.Props} field, unchanged, except `hidden`, which\n\t * defaults to `true`.\n\t */\n\texport interface ButtonProps extends Button.Props {\n\t\t/**\n\t\t * Whether the control is absent from rendering and the accessibility tree.\n\t\t * A paired scroll-follow behavior clears this attribute as the reader\n\t\t * scrolls away from the live edge and sets it again on return or press.\n\t\t *\n\t\t * @default true\n\t\t */\n\t\thidden?: boolean;\n\t}\n}\n\n/**\n * Renders the frame's root host: a bordered, rounded `<div>` that\n * declares the `ui-message-scroller` container queried by\n * {@link MessageScroller.Button} for its own placement.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the frame's markup.\n * @example\n * <MessageScroller mix={css({ blockSize: \"32rem\" })}>\n * \t<MessageScroller.Viewport>\n * \t\t<MessageScroller.Content aria-busy={isStreaming}>\n * \t\t\t<MessageScroller.Item messageId={turn.id} scrollAnchor>\n * \t\t\t\t{turn.content}\n * \t\t\t</MessageScroller.Item>\n * \t\t</MessageScroller.Content>\n * \t</MessageScroller.Viewport>\n * \t<MessageScroller.Button aria-label={t(\"chat.jumpToLatest\")} />\n * </MessageScroller>\n */\nexport function MessageScroller(handle: Handle<MessageScroller.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=\"message-scroller\"\n\t\t\t\tmix={[\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\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 frame's scrolling surface as {@link ScrollArea.Viewport},\n * fixed to the block axis. Compose `scrollFade()` through `mix` to fade\n * this viewport's edges when more content is off-screen.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the viewport's markup.\n * @example\n * <MessageScroller.Viewport mix={scrollFade({ axis: \"block\" })}>\n * \t<MessageScroller.Content>...</MessageScroller.Content>\n * </MessageScroller.Viewport>\n */\nMessageScroller.Viewport = function MessageScrollerViewport(\n\thandle: Handle<MessageScroller.ViewportProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <ScrollArea.Viewport {...rest} orientation=\"vertical\" mix={mix} />;\n\t};\n};\n\n/**\n * Renders the frame's live region: a `<div>` carrying the ARIA log role,\n * stacking its {@link MessageScroller.Item} rows in a column and\n * announcing each added row via `aria-relevant=\"additions\"`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the log region's markup.\n * @example\n * <MessageScroller.Content aria-busy={isStreaming}>\n * \t<MessageScroller.Item messageId={turn.id}>{turn.content}</MessageScroller.Item>\n * </MessageScroller.Content>\n */\nMessageScroller.Content = function MessageScrollerContent(\n\thandle: Handle<MessageScroller.ContentProps>,\n) {\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\tattrs({ role: DEFAULT_CONTENT_ROLE, \"aria-relevant\": DEFAULT_CONTENT_ARIA_RELEVANT }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tgap(4),\n\t\t\t\t\tpb(4),\n\t\t\t\t\tpi(4),\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 a single message row: a `<div>` mirroring `messageId` onto\n * `data-message-id` and, when `scrollAnchor` is set, an empty\n * `data-scroll-anchor` attribute for a scroll-follow behavior to read.\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 * <MessageScroller.Item messageId={turn.id} scrollAnchor={turn.startsNewTurn}>\n * \t{turn.content}\n * </MessageScroller.Item>\n */\nMessageScroller.Item = function MessageScrollerItem(handle: Handle<MessageScroller.ItemProps>) {\n\treturn () => {\n\t\tlet { messageId, scrollAnchor, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env.DEV && !messageId) {\n\t\t\tconsole.warn(\n\t\t\t\t'MessageScroller.Item: needs a \"messageId\" — a scroll-follow behavior matches rows 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-message-id={messageId}\n\t\t\t\tdata-scroll-anchor={scrollAnchor || undefined}\n\t\t\t\tmix={[\n\t\t\t\t\traw({\n\t\t\t\t\t\tscrollMarginBlockStart: \"var(--ui-message-scroller-anchor-offset, 0px)\",\n\t\t\t\t\t}),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders a static jump-to-latest control as {@link Button}, floating\n * over the frame's block-end edge and starting `hidden` until a paired\n * scroll-follow behavior clears the attribute.\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 * <MessageScroller.Button aria-label={t(\"chat.jumpToLatest\")}>\n * \t{t(\"chat.jumpToLatest\")}\n * </MessageScroller.Button>\n */\nMessageScroller.Button = function MessageScrollerButton(\n\thandle: Handle<MessageScroller.ButtonProps>,\n) {\n\treturn () => {\n\t\tlet { hidden, color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tcolor={color ?? DEFAULT_BUTTON_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_BUTTON_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_BUTTON_SIZE}\n\t\t\t\thidden={hidden ?? DEFAULT_BUTTON_HIDDEN}\n\t\t\t\tdata-slot=\"jump-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tz(1),\n\t\t\t\t\tabsolute(),\n\t\t\t\t\tinset(\"auto\", \"auto\", \"1rem\", \"50%\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The control floats over the log, so it carries an opaque surface of its own to stay\n\t\t\t\t\t * legible. `!important` settles it: each mix entry gets its own cascade sublayer, and\n\t\t\t\t\t * the variant's own fill may land in a later one.\n\t\t\t\t\t */\n\t\t\t\t\traw({ backgroundColor: \"var(--ui-bg, Canvas) !important\" }),\n\t\t\t\t\tshadow(\"md\"),\n\t\t\t\t\ttranslateProperty(\"-50% 0\"),\n\t\t\t\t\twhen(BUTTON_NARROW_QUERY, [\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tinsIs(\"1rem\"),\n\t\t\t\t\t\tinsIe(\"1rem\"),\n\t\t\t\t\t\ttranslateProperty(\"0 0\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
"content": "/**\n * A scrollable frame for a conversational message log. Its viewport reuses\n * the same scrollbar treatment every scrolling surface in this catalog\n * shares and fades its own edges to hint at history above and replies still\n * below; its content region announces newly appended rows through the ARIA\n * log role; each row carries the message id and anchor data a scroll-follow\n * behavior reads; and a static jump-to-latest control sits ready for that\n * same behavior to reveal.\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 { border } from \"@sdxc/u/color\";\nimport { rounded, shadow } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tabsolute,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tinsIe,\n\tinsIs,\n\tinset,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { pb, pi } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { when } from \"@sdxc/u/state\";\nimport { translateProperty } from \"@sdxc/u/transform\";\nimport { attrs } from \"remix/component\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { ScrollArea } from \"@sdxc/ui/scroll-area\";\n\n/**\n * Named container {@link MessageScroller} declares on its own host, so\n * {@link MessageScroller.Button} can size its own placement to the\n * frame's own width.\n */\nconst CONTAINER_NAME = \"ui-message-scroller\";\n\n/**\n * Container width under which {@link MessageScroller.Button} switches from a\n * centered floating pill to a bar stretched across the frame's own inline\n * size. It is measured against the frame's own width, which a conversation\n * column keeps well under a viewport's, so only a phone-width column reaches it.\n */\nconst BUTTON_NARROW_QUERY = `@container ${CONTAINER_NAME} (max-width: 20rem)`;\n\n/**\n * `role=\"log\"` applied to {@link MessageScroller.Content} through\n * {@link attrs} unless a consumer supplies its own `role`, whose implicit\n * `aria-live=\"polite\"` behavior announces each newly appended row.\n */\nconst DEFAULT_CONTENT_ROLE = \"log\";\n\n/**\n * `aria-relevant=\"additions\"` applied to {@link MessageScroller.Content}\n * through {@link attrs} unless overridden, scoping assistive-technology\n * announcements to newly appended rows.\n */\nconst DEFAULT_CONTENT_ARIA_RELEVANT = \"additions\";\n\n/** Semantic color role {@link MessageScroller.Button} falls back to when `color` is omitted. */\nconst DEFAULT_BUTTON_COLOR: Button.Color = \"neutral\";\n\n/**\n * Visual weight {@link MessageScroller.Button} falls back to when `variant` is omitted.\n * The control floats over a conversation it points at rather than competing with it, so\n * it reads as a surface of its own carrying an arrow.\n */\nconst DEFAULT_BUTTON_VARIANT: Button.Variant = \"outline\";\n\n/** Size variant {@link MessageScroller.Button} falls back to when `size` is omitted. */\nconst DEFAULT_BUTTON_SIZE: Button.Size = \"sm\";\n\n/**\n * `hidden` applied to {@link MessageScroller.Button} when a consumer omits\n * it: the control starts absent from rendering and the accessibility tree\n * until a paired scroll-follow behavior reveals it.\n */\nconst DEFAULT_BUTTON_HIDDEN = true;\n\n/**\n * Prop types for {@link MessageScroller} and its compound parts.\n */\nexport namespace MessageScroller {\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * Size the frame through `mix` since {@link MessageScroller.Viewport}\n\t * fills whatever block size this host resolves to.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** The frame's compound parts: {@link MessageScroller.Viewport} and, optionally, {@link MessageScroller.Button}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ViewportProps extends TagProps<\"div\"> {\n\t\t/** {@link MessageScroller.Content}, scrolling inside the viewport. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Marks the log as busy while a row inside it is still being written\n\t\t * to — a reply still streaming in, for instance — forwarded to the host's\n\t\t * native `aria-busy` attribute. Clear it once the row settles.\n\t\t */\n\t\t\"aria-busy\"?: TagProps<\"div\">[\"aria-busy\"];\n\t\t/** The {@link MessageScroller.Item} rows to render in document order. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ItemProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Stable id of the message this row renders, mirrored onto the host's\n\t\t * `data-message-id` attribute so a scroll-follow behavior can find,\n\t\t * measure, and scroll to this exact row directly.\n\t\t */\n\t\tmessageId: string;\n\t\t/**\n\t\t * Marks this row as a candidate anchor point — typically the first row\n\t\t * of a new turn — mirrored onto `data-scroll-anchor` so a scroll-follow\n\t\t * behavior can tell which rows are worth anchoring the viewport to.\n\t\t *\n\t\t * @default false\n\t\t */\n\t\tscrollAnchor?: boolean;\n\t\t/** The row's own content, typically a conversational row composed inside it. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every {@link Button.Props} field, unchanged, except `hidden`, which\n\t * defaults to `true`.\n\t */\n\texport interface ButtonProps extends Button.Props {\n\t\t/**\n\t\t * Whether the control is absent from rendering and the accessibility tree.\n\t\t * A paired scroll-follow behavior clears this attribute as the reader\n\t\t * scrolls away from the live edge and sets it again on return or press.\n\t\t *\n\t\t * @default true\n\t\t */\n\t\thidden?: boolean;\n\t}\n}\n\n/**\n * Renders the frame's root host: a bordered, rounded `<div>` that\n * declares the `ui-message-scroller` container queried by\n * {@link MessageScroller.Button} for its own placement.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the frame's markup.\n * @example\n * <MessageScroller mix={css({ blockSize: \"32rem\" })}>\n * \t<MessageScroller.Viewport>\n * \t\t<MessageScroller.Content aria-busy={isStreaming}>\n * \t\t\t<MessageScroller.Item messageId={turn.id} scrollAnchor>\n * \t\t\t\t{turn.content}\n * \t\t\t</MessageScroller.Item>\n * \t\t</MessageScroller.Content>\n * \t</MessageScroller.Viewport>\n * \t<MessageScroller.Button aria-label={t(\"chat.jumpToLatest\")} />\n * </MessageScroller>\n */\nexport function MessageScroller(handle: Handle<MessageScroller.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=\"message-scroller\"\n\t\t\t\tmix={[\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\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 frame's scrolling surface as {@link ScrollArea.Viewport},\n * fixed to the block axis. Compose `scrollFade()` through `mix` to fade\n * this viewport's edges when more content is off-screen.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the viewport's markup.\n * @example\n * <MessageScroller.Viewport mix={scrollFade({ axis: \"block\" })}>\n * \t<MessageScroller.Content>...</MessageScroller.Content>\n * </MessageScroller.Viewport>\n */\nMessageScroller.Viewport = function MessageScrollerViewport(\n\thandle: Handle<MessageScroller.ViewportProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <ScrollArea.Viewport {...rest} orientation=\"vertical\" mix={mix} />;\n\t};\n};\n\n/**\n * Renders the frame's live region: a `<div>` carrying the ARIA log role,\n * stacking its {@link MessageScroller.Item} rows in a column and\n * announcing each added row via `aria-relevant=\"additions\"`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the log region's markup.\n * @example\n * <MessageScroller.Content aria-busy={isStreaming}>\n * \t<MessageScroller.Item messageId={turn.id}>{turn.content}</MessageScroller.Item>\n * </MessageScroller.Content>\n */\nMessageScroller.Content = function MessageScrollerContent(\n\thandle: Handle<MessageScroller.ContentProps>,\n) {\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\tattrs({ role: DEFAULT_CONTENT_ROLE, \"aria-relevant\": DEFAULT_CONTENT_ARIA_RELEVANT }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tflexCol(),\n\t\t\t\t\tgap(4),\n\t\t\t\t\tpb(4),\n\t\t\t\t\tpi(4),\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 a single message row: a `<div>` mirroring `messageId` onto\n * `data-message-id` and, when `scrollAnchor` is set, an empty\n * `data-scroll-anchor` attribute for a scroll-follow behavior to read.\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 * <MessageScroller.Item messageId={turn.id} scrollAnchor={turn.startsNewTurn}>\n * \t{turn.content}\n * </MessageScroller.Item>\n */\nMessageScroller.Item = function MessageScrollerItem(handle: Handle<MessageScroller.ItemProps>) {\n\treturn () => {\n\t\tlet { messageId, scrollAnchor, children, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env?.DEV && !messageId) {\n\t\t\tconsole.warn(\n\t\t\t\t'MessageScroller.Item: needs a \"messageId\" — a scroll-follow behavior matches rows 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-message-id={messageId}\n\t\t\t\tdata-scroll-anchor={scrollAnchor || undefined}\n\t\t\t\tmix={[\n\t\t\t\t\traw({\n\t\t\t\t\t\tscrollMarginBlockStart: \"var(--ui-message-scroller-anchor-offset, 0px)\",\n\t\t\t\t\t}),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * Renders a static jump-to-latest control as {@link Button}, floating\n * over the frame's block-end edge and starting `hidden` until a paired\n * scroll-follow behavior clears the attribute.\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 * <MessageScroller.Button aria-label={t(\"chat.jumpToLatest\")}>\n * \t{t(\"chat.jumpToLatest\")}\n * </MessageScroller.Button>\n */\nMessageScroller.Button = function MessageScrollerButton(\n\thandle: Handle<MessageScroller.ButtonProps>,\n) {\n\treturn () => {\n\t\tlet { hidden, color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype=\"button\"\n\t\t\t\tcolor={color ?? DEFAULT_BUTTON_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_BUTTON_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_BUTTON_SIZE}\n\t\t\t\thidden={hidden ?? DEFAULT_BUTTON_HIDDEN}\n\t\t\t\tdata-slot=\"jump-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tz(1),\n\t\t\t\t\tabsolute(),\n\t\t\t\t\tinset(\"auto\", \"auto\", \"1rem\", \"50%\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The control floats over the log, so it carries an opaque surface of its own to stay\n\t\t\t\t\t * legible. `!important` settles it: each mix entry gets its own cascade sublayer, and\n\t\t\t\t\t * the variant's own fill may land in a later one.\n\t\t\t\t\t */\n\t\t\t\t\traw({ backgroundColor: \"var(--ui-bg, Canvas) !important\" }),\n\t\t\t\t\tshadow(\"md\"),\n\t\t\t\t\ttranslateProperty(\"-50% 0\"),\n\t\t\t\t\twhen(BUTTON_NARROW_QUERY, [\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tinsIs(\"1rem\"),\n\t\t\t\t\t\tinsIe(\"1rem\"),\n\t\t\t\t\t\ttranslateProperty(\"0 0\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
14
14
|
},
|
|
15
15
|
"test": null
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "number-field",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"input"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "number-field.tsx",
|
|
12
|
-
"content": "/**\n * A numeric field pairing a native `<input type=\"number\">` control with a\n * decrement and an increment button, all three sharing one bordered,\n * rounded frame. The frame draws its own box styling and keyboard focus\n * ring, so the input inside sits flush against its neighboring buttons\n * instead of carrying a competing border of 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 { MinusIcon, PlusIcon } from \"@sdxc/icons\";\nimport { bg, border, borderEdge, fg, outline, outlineWidth } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { basis, flex, grow, inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { bs, is } from \"@sdxc/u/size\";\nimport { active, focusVisible, hover, invalid, when } from \"@sdxc/u/state\";\nimport { tabularNums, textAlign } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\nimport { Input } from \"@sdxc/ui/input\";\n\n/**\n * ARIA role applied to {@link NumberField.Group} through {@link attrs}\n * unless a consumer supplies its own `role`, announcing the frame as one\n * related unit to assistive technology.\n */\nconst DEFAULT_ROLE = \"group\";\n\n/**\n * Native `<button>` `type` {@link NumberField.DecrementButton} and\n * {@link NumberField.IncrementButton} fall back to when a consumer doesn't\n * supply one, keeping a click on either from submitting a surrounding `<form>`.\n */\nconst DEFAULT_BUTTON_TYPE: NonNullable<NumberField.DecrementButtonProps[\"type\"]> = \"button\";\n\n/**\n * Shared box, color, and interaction-state styling for\n * {@link NumberField.DecrementButton} and {@link NumberField.IncrementButton},\n * differing only in which inline edge carries the divider border.\n *\n * @param dividerEdge Which inline edge carries the divider border: `\"end\"` for the control preceding the input, `\"start\"` for the one following it.\n * @returns The mixins shared by both stepper buttons.\n */\nfunction stepperButtonMix(dividerEdge: \"start\" | \"end\") {\n\treturn [\n\t\tinteractiveTransition(),\n\t\tflex(),\n\t\titems(\"center\"),\n\t\tjustify(\"center\"),\n\t\tis(\"2.5rem\"),\n\t\tfg(\"neutral\"),\n\t\tborder(\"neutral\"),\n\t\tborderEdge(dividerEdge === \"start\" ? \"inline-start\" : \"inline-end\", { width: 1 }),\n\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\trounded(\"none\"),\n\t\tbg(\"transparent\"),\n\t\twhen(\"& svg\", [is(\"1rem\"), bs(\"1rem\")]),\n\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t];\n}\n\n/**\n * Prop types for {@link NumberField} and its compound parts.\n */\nexport namespace NumberField {\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes this field's parts — typically a caption, the\n\t * {@link NumberField.Group} row, and any supporting or validation copy.\n\t */\n\texport interface Props extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes {@link NumberField.DecrementButton},\n\t * {@link NumberField.Input}, and {@link NumberField.IncrementButton}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every prop {@link Input.Props} accepts except `type` and `role`, fixed to\n\t * `\"number\"` and the platform's own `spinbutton` role, and `color`, unexposed\n\t * since the keyboard focus ring is deferred to {@link NumberField.Group}.\n\t */\n\texport interface InputProps extends Omit<Input.Props, \"type\" | \"role\" | \"color\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, which stays fixed\n\t * to this button's own decrement glyph, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_BUTTON_TYPE}.\n\t */\n\texport interface DecrementButtonProps extends Omit<TagProps<\"button\">, \"children\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, which stays fixed\n\t * to this button's own increment glyph, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_BUTTON_TYPE}.\n\t */\n\texport interface IncrementButtonProps extends Omit<TagProps<\"button\">, \"children\"> {}\n}\n\n/**\n * Renders a plain host stacking this field's compound parts in a single\n * column with a small gap between them: typically a caption, the\n * {@link NumberField.Group} row, and any supporting or validation copy.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the field's markup.\n * @example\n * <NumberField>\n * \t<Label htmlFor=\"quantity\">{t(\"form.quantity.label\")}</Label>\n * \t<NumberField.Group>\n * \t\t<NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} />\n * \t\t<NumberField.Input id=\"quantity\" name=\"quantity\" min={0} max={10} defaultValue={1} />\n * \t\t<NumberField.IncrementButton aria-label={t(\"stepper.increment\")} />\n * \t</NumberField.Group>\n * </NumberField>\n */\nexport function NumberField(handle: Handle<NumberField.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"number-field\" mix={[fieldStackLayout(), mix]} />;\n\t};\n}\n\n/**\n * Renders {@link NumberField}'s frame: a `role=\"group\"` `<div>` drawing a\n * bordered, rounded, tinted-background box that reads as one seamless\n * control, ringing the whole frame via `:focus-within` when a child gains focus.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the frame's markup.\n * @example\n * <NumberField.Group>\n * \t<NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} />\n * \t<NumberField.Input aria-label={t(\"form.quantity.label\")} />\n * \t<NumberField.IncrementButton aria-label={t(\"stepper.increment\")} />\n * </NumberField.Group>\n */\nNumberField.Group = function NumberFieldGroup(handle: Handle<NumberField.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\tattrs({ role: DEFAULT_ROLE }),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"stretch\"),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\thover(border(\"neutral.border-hover\")),\n\t\t\t\t\t/**\n\t\t\t\t\t * The wrapper wears the focus of whichever part holds it as a ring standing off the\n\t\t\t\t\t * field, as every button here does; the border steps only to its hover weight, since a\n\t\t\t\t\t * darkened border flush with the ring reads as one thick slab.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:focus-within\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\tborder(\"neutral.border-hover\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link NumberField}'s control: a native `<input type=\"number\">`\n * built on {@link Input}. The stepper buttons need a separately wired\n * `stepUp()`/`stepDown()` for press-and-hold repeat; typed entry works without it.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <NumberField.Input aria-label={t(\"form.quantity.label\")} min={0} max={10} defaultValue={1} />\n * @example\n * <NumberField.Input id=\"price\" name=\"price\" step={0.01} aria-invalid=\"true\" />\n */\nNumberField.Input = function NumberFieldInput(handle: Handle<NumberField.InputProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Input\n\t\t\t\ttype=\"number\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\trounded(\"none\"),\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\tborder({ width: \"0\", noStyleDefault: true }),\n\t\t\t\t\traw({\n\t\t\t\t\t\t\"-moz-appearance\": \"textfield\",\n\n\t\t\t\t\t\t\"&::-webkit-inner-spin-button, &::-webkit-outer-spin-button\": {\n\t\t\t\t\t\t\t\"-webkit-appearance\": \"none\",\n\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\twhen(\"&:disabled\", bg(\"transparent\")),\n\t\t\t\t\tfocusVisible(outlineWidth(\"0\")),\n\t\t\t\t\tinvalid([outlineWidth(\"0\"), fg(\"danger\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a native `<button>` decrementing {@link NumberField.Input}'s\n * value; its glyph is `aria-hidden`, so callers must supply an `aria-label`.\n * In dev mode, a missing `aria-label`/`aria-labelledby` logs a `console.warn`.\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 * <NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} />\n * @example\n * <NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} disabled={quantity <= 0} />\n */\nNumberField.DecrementButton = function NumberFieldDecrementButton(\n\thandle: Handle<NumberField.DecrementButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env.DEV && !handle.props[\"aria-label\"] && !handle.props[\"aria-labelledby\"]) {\n\t\t\tconsole.warn(\n\t\t\t\t\"NumberField.DecrementButton: needs an `aria-label` describing what it does — its content is a decorative glyph with no accessible name of its own.\",\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"decrement\"\n\t\t\t\tmix={[stepperButtonMix(\"end\"), mix]}\n\t\t\t>\n\t\t\t\t<MinusIcon />\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders a native `<button>` incrementing {@link NumberField.Input}'s\n * value; its glyph is `aria-hidden`, so callers must supply an `aria-label`.\n * In dev mode, a missing `aria-label`/`aria-labelledby` logs a `console.warn`.\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 * <NumberField.IncrementButton aria-label={t(\"stepper.increment\")} />\n * @example\n * <NumberField.IncrementButton aria-label={t(\"stepper.increment\")} disabled={quantity >= 10} />\n */\nNumberField.IncrementButton = function NumberFieldIncrementButton(\n\thandle: Handle<NumberField.IncrementButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env.DEV && !handle.props[\"aria-label\"] && !handle.props[\"aria-labelledby\"]) {\n\t\t\tconsole.warn(\n\t\t\t\t\"NumberField.IncrementButton: needs an `aria-label` describing what it does — its content is a decorative glyph with no accessible name of its own.\",\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"increment\"\n\t\t\t\tmix={[stepperButtonMix(\"start\"), mix]}\n\t\t\t>\n\t\t\t\t<PlusIcon />\n\t\t\t</button>\n\t\t);\n\t};\n};\n"
|
|
12
|
+
"content": "/**\n * A numeric field pairing a native `<input type=\"number\">` control with a\n * decrement and an increment button, all three sharing one bordered,\n * rounded frame. The frame draws its own box styling and keyboard focus\n * ring, so the input inside sits flush against its neighboring buttons\n * instead of carrying a competing border of 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 { MinusIcon, PlusIcon } from \"@sdxc/icons\";\nimport { bg, border, borderEdge, fg, outline, outlineWidth } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { basis, flex, grow, inlineFlex, items, justify, shrink } from \"@sdxc/u/layout\";\nimport { bs, is } from \"@sdxc/u/size\";\nimport { active, focusVisible, hover, invalid, when } from \"@sdxc/u/state\";\nimport { tabularNums, textAlign } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { fieldStackLayout } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\nimport { Input } from \"@sdxc/ui/input\";\n\n/**\n * ARIA role applied to {@link NumberField.Group} through {@link attrs}\n * unless a consumer supplies its own `role`, announcing the frame as one\n * related unit to assistive technology.\n */\nconst DEFAULT_ROLE = \"group\";\n\n/**\n * Native `<button>` `type` {@link NumberField.DecrementButton} and\n * {@link NumberField.IncrementButton} fall back to when a consumer doesn't\n * supply one, keeping a click on either from submitting a surrounding `<form>`.\n */\nconst DEFAULT_BUTTON_TYPE: NonNullable<NumberField.DecrementButtonProps[\"type\"]> = \"button\";\n\n/**\n * Shared box, color, and interaction-state styling for\n * {@link NumberField.DecrementButton} and {@link NumberField.IncrementButton},\n * differing only in which inline edge carries the divider border.\n *\n * @param dividerEdge Which inline edge carries the divider border: `\"end\"` for the control preceding the input, `\"start\"` for the one following it.\n * @returns The mixins shared by both stepper buttons.\n */\nfunction stepperButtonMix(dividerEdge: \"start\" | \"end\") {\n\treturn [\n\t\tinteractiveTransition(),\n\t\tflex(),\n\t\titems(\"center\"),\n\t\tjustify(\"center\"),\n\t\tis(\"2.5rem\"),\n\t\tfg(\"neutral\"),\n\t\tborder(\"neutral\"),\n\t\tborderEdge(dividerEdge === \"start\" ? \"inline-start\" : \"inline-end\", { width: 1 }),\n\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\trounded(\"none\"),\n\t\tbg(\"transparent\"),\n\t\twhen(\"& svg\", [is(\"1rem\"), bs(\"1rem\")]),\n\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t];\n}\n\n/**\n * Prop types for {@link NumberField} and its compound parts.\n */\nexport namespace NumberField {\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes this field's parts — typically a caption, the\n\t * {@link NumberField.Group} row, and any supporting or validation copy.\n\t */\n\texport interface Props extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes {@link NumberField.DecrementButton},\n\t * {@link NumberField.Input}, and {@link NumberField.IncrementButton}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every prop {@link Input.Props} accepts except `type` and `role`, fixed to\n\t * `\"number\"` and the platform's own `spinbutton` role, and `color`, unexposed\n\t * since the keyboard focus ring is deferred to {@link NumberField.Group}.\n\t */\n\texport interface InputProps extends Omit<Input.Props, \"type\" | \"role\" | \"color\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, which stays fixed\n\t * to this button's own decrement glyph, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_BUTTON_TYPE}.\n\t */\n\texport interface DecrementButtonProps extends Omit<TagProps<\"button\">, \"children\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, which stays fixed\n\t * to this button's own increment glyph, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_BUTTON_TYPE}.\n\t */\n\texport interface IncrementButtonProps extends Omit<TagProps<\"button\">, \"children\"> {}\n}\n\n/**\n * Renders a plain host stacking this field's compound parts in a single\n * column with a small gap between them: typically a caption, the\n * {@link NumberField.Group} row, and any supporting or validation copy.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the field's markup.\n * @example\n * <NumberField>\n * \t<Label htmlFor=\"quantity\">{t(\"form.quantity.label\")}</Label>\n * \t<NumberField.Group>\n * \t\t<NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} />\n * \t\t<NumberField.Input id=\"quantity\" name=\"quantity\" min={0} max={10} defaultValue={1} />\n * \t\t<NumberField.IncrementButton aria-label={t(\"stepper.increment\")} />\n * \t</NumberField.Group>\n * </NumberField>\n */\nexport function NumberField(handle: Handle<NumberField.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"number-field\" mix={[fieldStackLayout(), mix]} />;\n\t};\n}\n\n/**\n * Renders {@link NumberField}'s frame: a `role=\"group\"` `<div>` drawing a\n * bordered, rounded, tinted-background box that reads as one seamless\n * control, ringing the whole frame via `:focus-within` when a child gains focus.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the frame's markup.\n * @example\n * <NumberField.Group>\n * \t<NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} />\n * \t<NumberField.Input aria-label={t(\"form.quantity.label\")} />\n * \t<NumberField.IncrementButton aria-label={t(\"stepper.increment\")} />\n * </NumberField.Group>\n */\nNumberField.Group = function NumberFieldGroup(handle: Handle<NumberField.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\tattrs({ role: DEFAULT_ROLE }),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"stretch\"),\n\t\t\t\t\tis(\"full\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tborder({ color: \"neutral\", width: 1 }),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\thover(border(\"neutral.border-hover\")),\n\t\t\t\t\t/**\n\t\t\t\t\t * The wrapper wears the focus of whichever part holds it as a ring standing off the\n\t\t\t\t\t * field, as every button here does; the border steps only to its hover weight, since a\n\t\t\t\t\t * darkened border flush with the ring reads as one thick slab.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:focus-within\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\tborder(\"neutral.border-hover\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link NumberField}'s control: a native `<input type=\"number\">`\n * built on {@link Input}. The stepper buttons need a separately wired\n * `stepUp()`/`stepDown()` for press-and-hold repeat; typed entry works without it.\n *\n * @param handle Runtime handle carrying the host `<input>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <NumberField.Input aria-label={t(\"form.quantity.label\")} min={0} max={10} defaultValue={1} />\n * @example\n * <NumberField.Input id=\"price\" name=\"price\" step={0.01} aria-invalid=\"true\" />\n */\nNumberField.Input = function NumberFieldInput(handle: Handle<NumberField.InputProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Input\n\t\t\t\ttype=\"number\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\trounded(\"none\"),\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\tborder({ width: \"0\", noStyleDefault: true }),\n\t\t\t\t\traw({\n\t\t\t\t\t\t\"-moz-appearance\": \"textfield\",\n\n\t\t\t\t\t\t\"&::-webkit-inner-spin-button, &::-webkit-outer-spin-button\": {\n\t\t\t\t\t\t\t\"-webkit-appearance\": \"none\",\n\t\t\t\t\t\t\tmargin: \"0\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\twhen(\"&:disabled\", bg(\"transparent\")),\n\t\t\t\t\tfocusVisible(outlineWidth(\"0\")),\n\t\t\t\t\tinvalid([outlineWidth(\"0\"), fg(\"danger\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a native `<button>` decrementing {@link NumberField.Input}'s\n * value; its glyph is `aria-hidden`, so callers must supply an `aria-label`.\n * In dev mode, a missing `aria-label`/`aria-labelledby` logs a `console.warn`.\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 * <NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} />\n * @example\n * <NumberField.DecrementButton aria-label={t(\"stepper.decrement\")} disabled={quantity <= 0} />\n */\nNumberField.DecrementButton = function NumberFieldDecrementButton(\n\thandle: Handle<NumberField.DecrementButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env?.DEV && !handle.props[\"aria-label\"] && !handle.props[\"aria-labelledby\"]) {\n\t\t\tconsole.warn(\n\t\t\t\t\"NumberField.DecrementButton: needs an `aria-label` describing what it does — its content is a decorative glyph with no accessible name of its own.\",\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"decrement\"\n\t\t\t\tmix={[stepperButtonMix(\"end\"), mix]}\n\t\t\t>\n\t\t\t\t<MinusIcon />\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders a native `<button>` incrementing {@link NumberField.Input}'s\n * value; its glyph is `aria-hidden`, so callers must supply an `aria-label`.\n * In dev mode, a missing `aria-label`/`aria-labelledby` logs a `console.warn`.\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 * <NumberField.IncrementButton aria-label={t(\"stepper.increment\")} />\n * @example\n * <NumberField.IncrementButton aria-label={t(\"stepper.increment\")} disabled={quantity >= 10} />\n */\nNumberField.IncrementButton = function NumberFieldIncrementButton(\n\thandle: Handle<NumberField.IncrementButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, mix, ...rest } = handle.props;\n\n\t\tif (import.meta.env?.DEV && !handle.props[\"aria-label\"] && !handle.props[\"aria-labelledby\"]) {\n\t\t\tconsole.warn(\n\t\t\t\t\"NumberField.IncrementButton: needs an `aria-label` describing what it does — its content is a decorative glyph with no accessible name of its own.\",\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"increment\"\n\t\t\t\tmix={[stepperButtonMix(\"start\"), mix]}\n\t\t\t>\n\t\t\t\t<PlusIcon />\n\t\t\t</button>\n\t\t);\n\t};\n};\n"
|
|
13
13
|
},
|
|
14
14
|
"test": null
|
|
15
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "range-calendar",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"calendar",
|
|
6
6
|
"input"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "range-calendar.tsx",
|
|
13
|
-
"content": "/**\n * A calendar surface for choosing a start and end date as one connected\n * range, sharing every header, grid, and row part with {@link Calendar} and\n * layering range position on top of its day cell. Used bare, with no\n * composed children, it renders a pair of native `<input type=\"date\">`\n * fields instead — start and end, each independently keyboard-operable —\n * ready for the `calendarKeys()`/`rangePreview()` mixins a consumer attaches\n * to turn the composed grid into a live, drag- or arrow-key-extended range.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, fg } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { flex, gap, items } from \"@sdxc/u/layout\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { Calendar } from \"@sdxc/ui/calendar\";\nimport { Input } from \"@sdxc/ui/input\";\n\n/** Semantic color role {@link RangeCalendar}'s bare fallback pair falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: RangeCalendar.Color = \"neutral\";\n\n/**\n * Prop types for {@link RangeCalendar} and its compound parts. Every part\n * but {@link RangeCalendar.Cell} aliases {@link Calendar}'s matching part,\n * sharing its header, grid, and row markup.\n */\nexport namespace RangeCalendar {\n\t/**\n\t * Semantic color role for the bare fallback pair's keyboard focus rings,\n\t * mapped to `--ui-*` variables like {@link Calendar.Color}. The composed\n\t * grid's day cells always use fixed semantic roles, regardless of this value.\n\t */\n\texport type Color = Calendar.Color;\n\n\t/**\n\t * Per-part styling for the bare fallback pair's two internally composed\n\t * inputs, layered after each input's own built-in styling. Style the\n\t * composed grid's parts through {@link Calendar}'s own compound parts.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the bare fallback's start-date input, rendered through {@link Input}. */\n\t\tstart?: TagProps<\"input\">[\"mix\"];\n\t\t/** Styling for the bare fallback's end-date input, rendered through {@link Input}. */\n\t\tend?: TagProps<\"input\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link RangeCalendar}. Composing\n\t * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n\t * renders the visual month surface; omitting `children` renders a bare native `<input type=\"date\">` pair from the fields below.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback pair's focus rings. 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's start-date input. */\n\t\tstartName?: string;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback's end-date input. */\n\t\tendName?: string;\n\t\t/** Current start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tstartValue?: string;\n\t\t/** Current end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tendValue?: string;\n\t\t/** Initial start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tstartDefaultValue?: string;\n\t\t/** Initial end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tendDefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, both of the bare fallback pair's values must fall on. */\n\t\tstep?: number;\n\t\t/** Marks both of the bare fallback pair's inputs required for their enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs' values fixed, while keeping them focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for both of the bare fallback pair's inputs, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Accessible label for the bare fallback pair's start-date input. Read only when `children` is unset. */\n\t\tstartLabel?: string;\n\t\t/** Accessible label for the bare fallback pair's end-date input. Read only when `children` is unset. */\n\t\tendLabel?: string;\n\t\t/** Per-part styling for the bare fallback pair's internally composed inputs. */\n\t\tparts?: PartsProps;\n\t}\n\n\t/** Every prop {@link Calendar.HeaderProps} accepts, unchanged. */\n\texport interface HeaderProps extends Calendar.HeaderProps {}\n\n\t/** Every prop {@link Calendar.PreviousButtonProps} accepts, unchanged. */\n\texport interface PreviousButtonProps extends Calendar.PreviousButtonProps {}\n\n\t/** Every prop {@link Calendar.NextButtonProps} accepts, unchanged. */\n\texport interface NextButtonProps extends Calendar.NextButtonProps {}\n\n\t/** Every prop {@link Calendar.HeadingProps} accepts, unchanged. */\n\texport interface HeadingProps extends Calendar.HeadingProps {}\n\n\t/** Every prop {@link Calendar.GridProps} accepts, unchanged. */\n\texport interface GridProps extends Calendar.GridProps {}\n\n\t/** Every prop {@link Calendar.GridHeaderProps} accepts, unchanged. */\n\texport interface GridHeaderProps extends Calendar.GridHeaderProps {}\n\n\t/** Every prop {@link Calendar.RowProps} accepts, unchanged. */\n\texport interface RowProps extends Calendar.RowProps {}\n\n\t/** Every prop {@link Calendar.HeaderCellProps} accepts, unchanged. */\n\texport interface HeaderCellProps extends Calendar.HeaderCellProps {}\n\n\t/** Every prop {@link Calendar.GridBodyProps} accepts, unchanged. */\n\texport interface GridBodyProps extends Calendar.GridBodyProps {}\n\n\t/**\n\t * Every prop {@link Calendar.CellProps} accepts, unchanged. Set\n\t * `data-selection-start` on the range's first day, `data-selection-end`\n\t * on its last, and `aria-selected=\"true\"` alone on the days between — each read straight off what the consumer sets on this instance.\n\t */\n\texport interface CellProps extends Calendar.CellProps {}\n}\n\n/**\n * Renders {@link RangeCalendar}'s root through {@link Calendar}. Composing\n * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n * renders the visual month surface; omitting `children` renders a bare, script-free native `<input type=\"date\">` pair from this instance's own fields.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the range calendar's markup.\n * @example\n * <RangeCalendar startLabel={t(\"form.stay.checkIn\")} endLabel={t(\"form.stay.checkOut\")} startName=\"checkIn\" endName=\"checkOut\" />\n * @example\n * <RangeCalendar aria-label={t(\"calendar.label\")}>\n * \t<RangeCalendar.Header>\n * \t\t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t\t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</RangeCalendar.Header>\n * \t<RangeCalendar.Grid aria-label={monthLabel}>\n * \t\t<RangeCalendar.GridHeader>\n * \t\t\t<RangeCalendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<RangeCalendar.HeaderCell key={day}>{day}</RangeCalendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</RangeCalendar.Row>\n * \t\t</RangeCalendar.GridHeader>\n * \t\t<RangeCalendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<RangeCalendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<RangeCalendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.inRange ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-start={day.iso === range.start ? \"\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-end={day.iso === range.end ? \"\" : 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</RangeCalendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</RangeCalendar.Row>\n * \t\t\t))}\n * \t\t</RangeCalendar.GridBody>\n * \t</RangeCalendar.Grid>\n * </RangeCalendar>\n */\nexport function RangeCalendar(handle: Handle<RangeCalendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tstartName,\n\t\t\tendName,\n\t\t\tstartValue,\n\t\t\tendValue,\n\t\t\tstartDefaultValue,\n\t\t\tendDefaultValue,\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\tstartLabel,\n\t\t\tendLabel,\n\t\t\tparts,\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) {\n\t\t\tif (!startLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs a \"startLabel\" describing the range\\'s start for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!endLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs an \"endLabel\" describing the range\\'s end for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<Calendar {...rest} mix={mix}>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-slot=\"fields\"\n\t\t\t\t\t\tmix={[attrs({ role: \"group\" }), flex(), items(\"center\"), gap(\"0.5rem\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"start-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={startName}\n\t\t\t\t\t\t\tvalue={startValue}\n\t\t\t\t\t\t\tdefaultValue={startDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={startLabel}\n\t\t\t\t\t\t\tmix={parts?.start}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"end-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={endName}\n\t\t\t\t\t\t\tvalue={endValue}\n\t\t\t\t\t\t\tdefaultValue={endDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={endLabel}\n\t\t\t\t\t\t\tmix={parts?.end}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t</Calendar>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link RangeCalendar.HeaderProps.children} as the nav row: identical\n * to {@link Calendar.Header}, since {@link RangeCalendar} reuses\n * {@link Calendar}'s grid markup for its own header.\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 * <RangeCalendar.Header>\n * \t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * </RangeCalendar.Header>\n */\nRangeCalendar.Header = Calendar.Header;\n\n/**\n * Renders a control standing for \"show the previous month\": identical to\n * {@link Calendar.PreviousButton}.\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 * <RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nRangeCalendar.PreviousButton = Calendar.PreviousButton;\n\n/**\n * Renders a control standing for \"show the following month\": identical to\n * {@link Calendar.NextButton}.\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 * <RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nRangeCalendar.NextButton = Calendar.NextButton;\n\n/**\n * Renders the calendar's visible month/year caption: identical to\n * {@link Calendar.Heading}.\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 * <RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n */\nRangeCalendar.Heading = Calendar.Heading;\n\n/**\n * Renders the day grid's native `<table>` host: identical to\n * {@link Calendar.Grid}.\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 * <RangeCalendar.Grid aria-label={monthLabel}>\n * \t<RangeCalendar.GridHeader>...</RangeCalendar.GridHeader>\n * \t<RangeCalendar.GridBody>...</RangeCalendar.GridBody>\n * </RangeCalendar.Grid>\n */\nRangeCalendar.Grid = Calendar.Grid;\n\n/**\n * Renders the grid's `<thead>` host: identical to {@link Calendar.GridHeader}.\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 * <RangeCalendar.GridHeader>\n * \t<RangeCalendar.Row>\n * \t\t<RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n * \t</RangeCalendar.Row>\n * </RangeCalendar.GridHeader>\n */\nRangeCalendar.GridHeader = Calendar.GridHeader;\n\n/**\n * Renders a native `<tr>` host: identical to {@link Calendar.Row}. Composes\n * a row of {@link RangeCalendar.HeaderCell} inside\n * {@link RangeCalendar.GridHeader}, or a week's row of {@link RangeCalendar.Cell} inside {@link RangeCalendar.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 * <RangeCalendar.Row>\n * \t<RangeCalendar.Cell>{day.label}</RangeCalendar.Cell>\n * </RangeCalendar.Row>\n */\nRangeCalendar.Row = Calendar.Row;\n\n/**\n * Renders a weekday abbreviation: identical to {@link Calendar.HeaderCell}.\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 * <RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n */\nRangeCalendar.HeaderCell = Calendar.HeaderCell;\n\n/**\n * Renders the grid's `<tbody>` host: identical to {@link Calendar.GridBody}.\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 * <RangeCalendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<RangeCalendar.Row key={week[0].iso}>...</RangeCalendar.Row>\n * \t))}\n * </RangeCalendar.GridBody>\n */\nRangeCalendar.GridBody = Calendar.GridBody;\n\n/**\n * Renders one calendar day for {@link RangeCalendar}, building on\n * {@link Calendar.Cell}. `data-selection-start`/`data-selection-end`\n * square off each end's outer corners so the range reads as one unbroken bar, driven by whatever state the consumer sets for the `calendarKeys()`/`rangePreview()` mixins.\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 * <RangeCalendar.Cell data-selection-start=\"\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell aria-selected=\"true\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell data-selection-end=\"\">{day.label}</RangeCalendar.Cell>\n */\nRangeCalendar.Cell = function RangeCalendarCell(handle: Handle<RangeCalendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Calendar.Cell\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * A day is the range's opening, its closing, both at once, or one of the days\n\t\t\t\t\t * between. The four are written under selectors that match one apiece, so each\n\t\t\t\t\t * day keeps its own shape however the cascade orders the set.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&[data-selection-start]:not([data-selection-end])\", [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\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\twhen(\"&[data-selection-end]:not([data-selection-start])\", [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\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]),\n\t\t\t\t\t/**\n\t\t\t\t\t * A range of one day opens and closes on itself, so it reads as a single day.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&[data-selection-start][data-selection-end]\", [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]:not([data-selection-start]):not([data-selection-end])', [\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The days between carry the range across the row, so the band reads as one\n\t\t\t\t\t\t * run at a glance while the two ends stay the strongest thing in the month.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tbg(\"brand.bg-tint-hover\"),\n\t\t\t\t\t\tfg(\"brand.emphasis\"),\n\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
"content": "/**\n * A calendar surface for choosing a start and end date as one connected\n * range, sharing every header, grid, and row part with {@link Calendar} and\n * layering range position on top of its day cell. Used bare, with no\n * composed children, it renders a pair of native `<input type=\"date\">`\n * fields instead — start and end, each independently keyboard-operable —\n * ready for the `calendarKeys()`/`rangePreview()` mixins a consumer attaches\n * to turn the composed grid into a live, drag- or arrow-key-extended range.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, fg } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { flex, gap, items } from \"@sdxc/u/layout\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { Calendar } from \"@sdxc/ui/calendar\";\nimport { Input } from \"@sdxc/ui/input\";\n\n/** Semantic color role {@link RangeCalendar}'s bare fallback pair falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: RangeCalendar.Color = \"neutral\";\n\n/**\n * Prop types for {@link RangeCalendar} and its compound parts. Every part\n * but {@link RangeCalendar.Cell} aliases {@link Calendar}'s matching part,\n * sharing its header, grid, and row markup.\n */\nexport namespace RangeCalendar {\n\t/**\n\t * Semantic color role for the bare fallback pair's keyboard focus rings,\n\t * mapped to `--ui-*` variables like {@link Calendar.Color}. The composed\n\t * grid's day cells always use fixed semantic roles, regardless of this value.\n\t */\n\texport type Color = Calendar.Color;\n\n\t/**\n\t * Per-part styling for the bare fallback pair's two internally composed\n\t * inputs, layered after each input's own built-in styling. Style the\n\t * composed grid's parts through {@link Calendar}'s own compound parts.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the bare fallback's start-date input, rendered through {@link Input}. */\n\t\tstart?: TagProps<\"input\">[\"mix\"];\n\t\t/** Styling for the bare fallback's end-date input, rendered through {@link Input}. */\n\t\tend?: TagProps<\"input\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link RangeCalendar}. Composing\n\t * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n\t * renders the visual month surface; omitting `children` renders a bare native `<input type=\"date\">` pair from the fields below.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback pair's focus rings. 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's start-date input. */\n\t\tstartName?: string;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback's end-date input. */\n\t\tendName?: string;\n\t\t/** Current start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tstartValue?: string;\n\t\t/** Current end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tendValue?: string;\n\t\t/** Initial start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tstartDefaultValue?: string;\n\t\t/** Initial end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tendDefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, both of the bare fallback pair's values must fall on. */\n\t\tstep?: number;\n\t\t/** Marks both of the bare fallback pair's inputs required for their enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs' values fixed, while keeping them focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for both of the bare fallback pair's inputs, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Accessible label for the bare fallback pair's start-date input. Read only when `children` is unset. */\n\t\tstartLabel?: string;\n\t\t/** Accessible label for the bare fallback pair's end-date input. Read only when `children` is unset. */\n\t\tendLabel?: string;\n\t\t/** Per-part styling for the bare fallback pair's internally composed inputs. */\n\t\tparts?: PartsProps;\n\t}\n\n\t/** Every prop {@link Calendar.HeaderProps} accepts, unchanged. */\n\texport interface HeaderProps extends Calendar.HeaderProps {}\n\n\t/** Every prop {@link Calendar.PreviousButtonProps} accepts, unchanged. */\n\texport interface PreviousButtonProps extends Calendar.PreviousButtonProps {}\n\n\t/** Every prop {@link Calendar.NextButtonProps} accepts, unchanged. */\n\texport interface NextButtonProps extends Calendar.NextButtonProps {}\n\n\t/** Every prop {@link Calendar.HeadingProps} accepts, unchanged. */\n\texport interface HeadingProps extends Calendar.HeadingProps {}\n\n\t/** Every prop {@link Calendar.GridProps} accepts, unchanged. */\n\texport interface GridProps extends Calendar.GridProps {}\n\n\t/** Every prop {@link Calendar.GridHeaderProps} accepts, unchanged. */\n\texport interface GridHeaderProps extends Calendar.GridHeaderProps {}\n\n\t/** Every prop {@link Calendar.RowProps} accepts, unchanged. */\n\texport interface RowProps extends Calendar.RowProps {}\n\n\t/** Every prop {@link Calendar.HeaderCellProps} accepts, unchanged. */\n\texport interface HeaderCellProps extends Calendar.HeaderCellProps {}\n\n\t/** Every prop {@link Calendar.GridBodyProps} accepts, unchanged. */\n\texport interface GridBodyProps extends Calendar.GridBodyProps {}\n\n\t/**\n\t * Every prop {@link Calendar.CellProps} accepts, unchanged. Set\n\t * `data-selection-start` on the range's first day, `data-selection-end`\n\t * on its last, and `aria-selected=\"true\"` alone on the days between — each read straight off what the consumer sets on this instance.\n\t */\n\texport interface CellProps extends Calendar.CellProps {}\n}\n\n/**\n * Renders {@link RangeCalendar}'s root through {@link Calendar}. Composing\n * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n * renders the visual month surface; omitting `children` renders a bare, script-free native `<input type=\"date\">` pair from this instance's own fields.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the range calendar's markup.\n * @example\n * <RangeCalendar startLabel={t(\"form.stay.checkIn\")} endLabel={t(\"form.stay.checkOut\")} startName=\"checkIn\" endName=\"checkOut\" />\n * @example\n * <RangeCalendar aria-label={t(\"calendar.label\")}>\n * \t<RangeCalendar.Header>\n * \t\t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t\t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</RangeCalendar.Header>\n * \t<RangeCalendar.Grid aria-label={monthLabel}>\n * \t\t<RangeCalendar.GridHeader>\n * \t\t\t<RangeCalendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<RangeCalendar.HeaderCell key={day}>{day}</RangeCalendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</RangeCalendar.Row>\n * \t\t</RangeCalendar.GridHeader>\n * \t\t<RangeCalendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<RangeCalendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<RangeCalendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.inRange ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-start={day.iso === range.start ? \"\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-end={day.iso === range.end ? \"\" : 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</RangeCalendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</RangeCalendar.Row>\n * \t\t\t))}\n * \t\t</RangeCalendar.GridBody>\n * \t</RangeCalendar.Grid>\n * </RangeCalendar>\n */\nexport function RangeCalendar(handle: Handle<RangeCalendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tstartName,\n\t\t\tendName,\n\t\t\tstartValue,\n\t\t\tendValue,\n\t\t\tstartDefaultValue,\n\t\t\tendDefaultValue,\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\tstartLabel,\n\t\t\tendLabel,\n\t\t\tparts,\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) {\n\t\t\tif (!startLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs a \"startLabel\" describing the range\\'s start for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!endLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs an \"endLabel\" describing the range\\'s end for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<Calendar {...rest} mix={mix}>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-slot=\"fields\"\n\t\t\t\t\t\tmix={[attrs({ role: \"group\" }), flex(), items(\"center\"), gap(\"0.5rem\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"start-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={startName}\n\t\t\t\t\t\t\tvalue={startValue}\n\t\t\t\t\t\t\tdefaultValue={startDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={startLabel}\n\t\t\t\t\t\t\tmix={parts?.start}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"end-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={endName}\n\t\t\t\t\t\t\tvalue={endValue}\n\t\t\t\t\t\t\tdefaultValue={endDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={endLabel}\n\t\t\t\t\t\t\tmix={parts?.end}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t</Calendar>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link RangeCalendar.HeaderProps.children} as the nav row: identical\n * to {@link Calendar.Header}, since {@link RangeCalendar} reuses\n * {@link Calendar}'s grid markup for its own header.\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 * <RangeCalendar.Header>\n * \t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * </RangeCalendar.Header>\n */\nRangeCalendar.Header = Calendar.Header;\n\n/**\n * Renders a control standing for \"show the previous month\": identical to\n * {@link Calendar.PreviousButton}.\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 * <RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nRangeCalendar.PreviousButton = Calendar.PreviousButton;\n\n/**\n * Renders a control standing for \"show the following month\": identical to\n * {@link Calendar.NextButton}.\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 * <RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nRangeCalendar.NextButton = Calendar.NextButton;\n\n/**\n * Renders the calendar's visible month/year caption: identical to\n * {@link Calendar.Heading}.\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 * <RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n */\nRangeCalendar.Heading = Calendar.Heading;\n\n/**\n * Renders the day grid's native `<table>` host: identical to\n * {@link Calendar.Grid}.\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 * <RangeCalendar.Grid aria-label={monthLabel}>\n * \t<RangeCalendar.GridHeader>...</RangeCalendar.GridHeader>\n * \t<RangeCalendar.GridBody>...</RangeCalendar.GridBody>\n * </RangeCalendar.Grid>\n */\nRangeCalendar.Grid = Calendar.Grid;\n\n/**\n * Renders the grid's `<thead>` host: identical to {@link Calendar.GridHeader}.\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 * <RangeCalendar.GridHeader>\n * \t<RangeCalendar.Row>\n * \t\t<RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n * \t</RangeCalendar.Row>\n * </RangeCalendar.GridHeader>\n */\nRangeCalendar.GridHeader = Calendar.GridHeader;\n\n/**\n * Renders a native `<tr>` host: identical to {@link Calendar.Row}. Composes\n * a row of {@link RangeCalendar.HeaderCell} inside\n * {@link RangeCalendar.GridHeader}, or a week's row of {@link RangeCalendar.Cell} inside {@link RangeCalendar.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 * <RangeCalendar.Row>\n * \t<RangeCalendar.Cell>{day.label}</RangeCalendar.Cell>\n * </RangeCalendar.Row>\n */\nRangeCalendar.Row = Calendar.Row;\n\n/**\n * Renders a weekday abbreviation: identical to {@link Calendar.HeaderCell}.\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 * <RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n */\nRangeCalendar.HeaderCell = Calendar.HeaderCell;\n\n/**\n * Renders the grid's `<tbody>` host: identical to {@link Calendar.GridBody}.\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 * <RangeCalendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<RangeCalendar.Row key={week[0].iso}>...</RangeCalendar.Row>\n * \t))}\n * </RangeCalendar.GridBody>\n */\nRangeCalendar.GridBody = Calendar.GridBody;\n\n/**\n * Renders one calendar day for {@link RangeCalendar}, building on\n * {@link Calendar.Cell}. `data-selection-start`/`data-selection-end`\n * square off each end's outer corners so the range reads as one unbroken bar, driven by whatever state the consumer sets for the `calendarKeys()`/`rangePreview()` mixins.\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 * <RangeCalendar.Cell data-selection-start=\"\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell aria-selected=\"true\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell data-selection-end=\"\">{day.label}</RangeCalendar.Cell>\n */\nRangeCalendar.Cell = function RangeCalendarCell(handle: Handle<RangeCalendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Calendar.Cell\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * A day is the range's opening, its closing, both at once, or one of the days\n\t\t\t\t\t * between. The four are written under selectors that match one apiece, so each\n\t\t\t\t\t * day keeps its own shape however the cascade orders the set.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&[data-selection-start]:not([data-selection-end])\", [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\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\twhen(\"&[data-selection-end]:not([data-selection-start])\", [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\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]),\n\t\t\t\t\t/**\n\t\t\t\t\t * A range of one day opens and closes on itself, so it reads as a single day.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&[data-selection-start][data-selection-end]\", [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]:not([data-selection-start]):not([data-selection-end])', [\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * The days between carry the range across the row, so the band reads as one\n\t\t\t\t\t\t * run at a glance while the two ends stay the strongest thing in the month.\n\t\t\t\t\t\t */\n\t\t\t\t\t\tbg(\"brand.bg-tint-hover\"),\n\t\t\t\t\t\tfg(\"brand.emphasis\"),\n\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
14
14
|
},
|
|
15
15
|
"test": null
|
|
16
16
|
}
|