@sdxc/kit 2026.10.16 → 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 +391 -20
- package/changelog.jsonl +1160 -1035
- package/config.schema.json +47 -1
- package/dist/author.d.ts +36 -0
- package/dist/author.js +107 -0
- package/dist/cli.js +12 -0
- package/dist/commands/create.js +9 -4
- 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 +18 -2
- package/dist/commands/run.js +35 -12
- 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.d.ts +8 -1
- package/dist/create/templates.js +26 -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/init.d.ts +5 -3
- package/dist/init.js +15 -7
- 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 +32 -4
- package/dist/make/declare.js +405 -27
- 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 +43 -14
- 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 -25
- package/dist/make/kinds.d.ts +31 -3
- package/dist/make/kinds.js +82 -9
- 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/testing.d.ts +12 -2
- package/dist/testing.js +22 -3
- 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/command.stub +4 -0
- package/stubs/command.test.stub +3 -0
- package/stubs/controller.api.resource.stub +23 -0
- package/stubs/controller.api.stub +21 -0
- package/stubs/controller.api.test.stub +18 -0
- package/stubs/controller.form.stub +40 -10
- package/stubs/controller.form.test.stub +61 -0
- package/stubs/controller.resource.form.stub +67 -0
- package/stubs/controller.resource.stub +28 -0
- package/stubs/controller.stub +15 -8
- package/stubs/controller.test.stub +3 -0
- package/stubs/email.stub +15 -38
- package/stubs/email.test.stub +12 -7
- package/stubs/factory.stub +4 -1
- package/stubs/initializer.stub +2 -0
- package/stubs/initializer.test.stub +3 -0
- package/stubs/job.cron.stub +4 -0
- package/stubs/job.stub +4 -0
- package/stubs/job.test.stub +3 -0
- package/stubs/mcp.resource.stub +3 -0
- package/stubs/mcp.stub +3 -0
- package/stubs/mcp.test.stub +3 -0
- package/stubs/middleware.stub +6 -1
- package/stubs/middleware.test.stub +3 -0
- package/stubs/model.stub +12 -3
- package/stubs/model.test.stub +3 -0
- package/stubs/policy.test.stub +36 -7
- 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/stubs/service.stub +4 -0
- package/stubs/service.test.stub +3 -0
- package/stubs/validator.stub +3 -0
- package/stubs/validator.test.stub +3 -0
- package/templates/app/.env.example +16 -0
- package/templates/app/AGENTS.md +163 -0
- package/templates/app/CLAUDE.md +1 -0
- package/templates/app/README.md +79 -37
- package/templates/app/app/commands/about.test.ts +1 -1
- 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/console.ts +6 -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 +46 -0
- package/templates/app/app/commands/db/migrate.ts +88 -0
- 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 +72 -1
- package/templates/app/app/commands/typegen.test.ts +17 -0
- package/templates/app/app/commands/typegen.ts +16 -0
- package/templates/app/app/emails/index.ts +10 -0
- package/templates/app/app/http/controllers/api/health.tsx +15 -0
- package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
- package/templates/app/app/http/controllers/home.tsx +21 -13
- package/templates/app/app/http/controllers/mcp.tsx +16 -0
- package/templates/app/app/http/controllers/not-found.tsx +23 -18
- package/templates/app/app/http/controllers/robots.test.ts +18 -0
- package/templates/app/app/http/controllers/robots.ts +24 -0
- package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
- package/templates/app/app/http/controllers/sitemap.ts +25 -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 +19 -0
- package/templates/app/app/http/middleware/page.test.ts +43 -0
- package/templates/app/app/http/middleware/page.ts +51 -0
- package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
- package/templates/app/app/http/middleware/server-timing.ts +42 -0
- package/templates/app/app/initializers/assets.ts +1 -1
- package/templates/app/app/initializers/captcha.ts +11 -0
- package/templates/app/app/initializers/cli.ts +68 -2
- package/templates/app/app/initializers/database.test.ts +18 -0
- package/templates/app/app/initializers/database.ts +18 -0
- package/templates/app/app/initializers/dispatcher.ts +26 -0
- package/templates/app/app/initializers/honeypot.ts +11 -0
- package/templates/app/app/initializers/i18n.test.ts +16 -0
- package/templates/app/app/initializers/i18n.ts +28 -0
- package/templates/app/app/initializers/local-database.test.ts +33 -0
- package/templates/app/app/initializers/local-database.ts +53 -0
- 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 +27 -0
- package/templates/app/app/initializers/mail.ts +19 -0
- package/templates/app/app/initializers/mcp.ts +1 -1
- package/templates/app/app/initializers/openapi.ts +21 -0
- package/templates/app/app/initializers/router.test.ts +68 -0
- package/templates/app/app/initializers/router.tsx +81 -25
- package/templates/app/app/initializers/seo.ts +15 -0
- package/templates/app/app/initializers/session.test.ts +34 -0
- package/templates/app/app/initializers/session.ts +29 -0
- package/templates/app/app/initializers/spam.ts +10 -0
- 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/models/index.ts +10 -0
- 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 +92 -0
- package/templates/app/app/services/migrations.ts +117 -0
- package/templates/app/app/test/cloudflare-workers.ts +25 -0
- package/templates/app/app/test/local-database.ts +67 -0
- package/templates/app/app/test/session.ts +28 -0
- package/templates/app/bootstrap/cli.ts +1 -1
- package/templates/app/bootstrap/console.ts +13 -0
- package/templates/app/bootstrap/worker.ts +4 -4
- package/templates/app/cloudflare.config.ts +30 -2
- package/templates/app/config/constants.ts +19 -0
- package/templates/app/config/problems.ts +24 -0
- package/templates/app/config/security-policy.ts +34 -0
- package/templates/app/config/security-txt.ts +28 -0
- package/templates/app/database/migrations/.gitkeep +0 -0
- package/templates/app/database/seed.ts +12 -0
- package/templates/app/package.json +37 -6
- package/templates/app/resources/layouts/document.tsx +28 -7
- package/templates/app/resources/locales/en.json +10 -0
- package/templates/app/routes/api.ts +29 -0
- package/templates/app/routes/web.ts +6 -4
- package/templates/app/vite.config.ts +4 -0
- package/stubs/policy.stub +0 -13
- package/templates/app/config/router-context.d.ts +0 -20
package/dist/upgrade/prompt.js
CHANGED
|
@@ -14,8 +14,10 @@ import { loadConfig } from "../config.js";
|
|
|
14
14
|
import { readLock, uiEntries } from "../lock.js";
|
|
15
15
|
import { lockFileAtOrAbove, packageManager } from "../package-manager.js";
|
|
16
16
|
import { scopedPackageOf } from "../releases.js";
|
|
17
|
+
import { AGENTS_FILE, AGENTS_TEMPLATE } from "./agents.js";
|
|
17
18
|
import { entriesBetween, fullHistoryStart, readChangelog } from "./changelog.js";
|
|
18
19
|
import { projectImports, readManifest } from "./project.js";
|
|
20
|
+
import { PACKAGE_FILES, RELEASE_PACKAGE } from "./registry.js";
|
|
19
21
|
/** Where each release's GitHub Release lives, `<RELEASES>/tag/v<version>`. */
|
|
20
22
|
const RELEASES = "https://github.com/sergiodxa/monorepo/releases";
|
|
21
23
|
/** Each package's reference page, as Markdown an agent reads directly. */
|
|
@@ -33,16 +35,21 @@ const FIX_TYPES = new Set(["fix", "perf", "revert"]);
|
|
|
33
35
|
*/
|
|
34
36
|
export function renderPrompt(input) {
|
|
35
37
|
let imported = new Set(input.packages);
|
|
36
|
-
let
|
|
37
|
-
|
|
38
|
+
let since = input.since ?? new Map();
|
|
39
|
+
let from = earliestStart(input);
|
|
40
|
+
let relevant = entriesBetween(input.entries, from, input.to)
|
|
41
|
+
.filter((entry) => imported.has(entry.package) &&
|
|
42
|
+
compare(entry.release, since.get(entry.package) ?? input.from) > 0)
|
|
38
43
|
.sort((a, b) => compare(a.release, b.release) || compareText(a.package, b.package));
|
|
39
44
|
let breaking = relevant.filter((entry) => entry.breaking);
|
|
40
45
|
let features = relevant.filter((entry) => !entry.breaking && entry.type === "feat");
|
|
41
46
|
let fixes = relevant.filter((entry) => !entry.breaking && FIX_TYPES.has(entry.type));
|
|
42
47
|
let sections = [
|
|
43
48
|
[
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
from === input.to
|
|
50
|
+
? `# Align the project with @sdxc release ${input.to}`
|
|
51
|
+
: `# Upgrade the @sdxc packages from ${from} to ${input.to}`,
|
|
52
|
+
`This project now depends on the @sdxc packages of release ${input.to}, installed. Update its code for the changes below, which are the release notes of the packages it imports for every release after ${from}. Apply each breaking change's migration wherever the code uses what it changed, adopt the features and fixes where they apply, then run the verification commands and fix what they report.`,
|
|
46
53
|
`Packages this project imports: ${[...input.packages].sort(compareText).map(code).join(", ")}.`,
|
|
47
54
|
].join("\n\n"),
|
|
48
55
|
];
|
|
@@ -73,6 +80,9 @@ export function renderPrompt(input) {
|
|
|
73
80
|
.join("\n"),
|
|
74
81
|
].join("\n\n"));
|
|
75
82
|
}
|
|
83
|
+
let agents = agentsNote(input);
|
|
84
|
+
if (agents !== null)
|
|
85
|
+
sections.push(agents);
|
|
76
86
|
if (input.verify.length > 0) {
|
|
77
87
|
sections.push([
|
|
78
88
|
"## Verify",
|
|
@@ -129,11 +139,13 @@ export async function buildPrompt(options) {
|
|
|
129
139
|
: null;
|
|
130
140
|
return success(renderPrompt({
|
|
131
141
|
from: options.from,
|
|
142
|
+
...(options.since === undefined ? {} : { since: options.since }),
|
|
132
143
|
to,
|
|
133
144
|
entries: entries.data,
|
|
134
145
|
packages: [...packages],
|
|
135
146
|
remix,
|
|
136
147
|
components: components.data,
|
|
148
|
+
...(options.agents === undefined ? {} : { agents: options.agents }),
|
|
137
149
|
verify: VERIFY_SCRIPTS.filter((name) => scripts[name] !== undefined).map((name) => [...manager.run, name].join(" ")),
|
|
138
150
|
}));
|
|
139
151
|
}
|
|
@@ -186,21 +198,52 @@ async function registryChangedIn(packageRoot, name) {
|
|
|
186
198
|
*/
|
|
187
199
|
function olderReleases(input) {
|
|
188
200
|
let start = fullHistoryStart(input.to);
|
|
189
|
-
|
|
201
|
+
let from = earliestStart(input);
|
|
202
|
+
if (compare(from, start) >= 0)
|
|
190
203
|
return null;
|
|
191
204
|
let releases = [
|
|
192
|
-
...new Set(entriesBetween(input.entries,
|
|
205
|
+
...new Set(entriesBetween(input.entries, from, input.to)
|
|
193
206
|
.map((entry) => entry.release)
|
|
194
207
|
.filter((release) => compare(release, start) < 0)),
|
|
195
208
|
].sort(compare);
|
|
196
209
|
return [
|
|
197
210
|
"## Older releases",
|
|
198
|
-
`Releases after ${
|
|
211
|
+
`Releases after ${from} and before ${start} are summarized by their breaking changes only. Their full notes are on GitHub: ${RELEASES}`,
|
|
199
212
|
...(releases.length > 0
|
|
200
213
|
? [releases.map((release) => `- ${release}: ${RELEASES}/tag/v${release}`).join("\n")]
|
|
201
214
|
: []),
|
|
202
215
|
].join("\n\n");
|
|
203
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* The note on an `AGENTS.md` the upgrade left as it is, pointing at the release's sdxc section;
|
|
219
|
+
* `null` when the file holds the section or the status is unknown. The agent decides whether
|
|
220
|
+
* the project follows the app layout the section describes.
|
|
221
|
+
*/
|
|
222
|
+
function agentsNote(input) {
|
|
223
|
+
if (input.agents === undefined || input.agents === "refreshed" || input.agents === "current") {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
let url = `${PACKAGE_FILES}/${RELEASE_PACKAGE}@${input.to}/${AGENTS_TEMPLATE}`;
|
|
227
|
+
let markers = "`<!-- sdxc:start …-->` and `<!-- sdxc:end -->`";
|
|
228
|
+
let state = input.agents === "missing"
|
|
229
|
+
? `This project has no \`${AGENTS_FILE}\`.`
|
|
230
|
+
: input.agents === "unmarked"
|
|
231
|
+
? `\`${AGENTS_FILE}\` has no sdxc section, so the upgrade left it as it is.`
|
|
232
|
+
: `\`${AGENTS_FILE}\` needs exactly one ${markers} line pair, so the upgrade left it as it is.`;
|
|
233
|
+
let action = input.agents === "unbalanced"
|
|
234
|
+
? `Restore one pair around the sdxc section, which for release ${input.to} is in ${url}.`
|
|
235
|
+
: `When this project is an app in the sdxc layout (it has \`bootstrap/worker.ts\`), add the section from ${url}, ${markers} lines included, to \`${AGENTS_FILE}\`, creating the file if needed; \`sdxc upgrade\` then keeps it current.`;
|
|
236
|
+
return ["## Agent instructions", `${state} ${action}`].join("\n\n");
|
|
237
|
+
}
|
|
238
|
+
/** The oldest release the prompt covers: `from`, or an older pin of a lagging package. */
|
|
239
|
+
function earliestStart(input) {
|
|
240
|
+
let earliest = input.from;
|
|
241
|
+
for (let pinned of input.since?.values() ?? []) {
|
|
242
|
+
if (compare(pinned, earliest) < 0)
|
|
243
|
+
earliest = pinned;
|
|
244
|
+
}
|
|
245
|
+
return earliest;
|
|
246
|
+
}
|
|
204
247
|
/** A heading and each entry under its own sub-heading with its full body. */
|
|
205
248
|
function entrySection(heading, entries) {
|
|
206
249
|
let blocks = entries.map((entry) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/kit",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.20",
|
|
4
4
|
"description": "The sdxc command line: start a Remix v3 app, generate its files, copy UI components into it and upgrade it",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": "./dist/cli.js",
|
|
12
|
+
"./doctor": "./dist/doctor/define.js",
|
|
12
13
|
"./config.schema.json": "./config.schema.json",
|
|
13
14
|
"./lock.schema.json": "./lock.schema.json"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"@sdxc/cli": "2026.10.
|
|
17
|
-
"@sdxc/codemod": "2026.10.
|
|
17
|
+
"@sdxc/cli": "2026.10.20",
|
|
18
|
+
"@sdxc/codemod": "2026.10.20",
|
|
19
|
+
"@sdxc/cron": "2026.10.13",
|
|
18
20
|
"@sdxc/json-schema": "2026.10.16",
|
|
19
21
|
"@sdxc/jsonc": "2026.10.16",
|
|
20
22
|
"@sdxc/jsonl": "2026.10.16",
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
"peerDependencies": {
|
|
25
27
|
"remix": "3.0.0"
|
|
26
28
|
},
|
|
27
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "bd4473246f405c43055d2fc5e08c62ba35197258",
|
|
28
30
|
"publishConfig": {
|
|
29
31
|
"access": "public"
|
|
30
32
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alert-dialog",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button",
|
|
6
6
|
"dialog",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"source": {
|
|
13
13
|
"path": "alert-dialog.tsx",
|
|
14
|
-
"content": "/**\n * An interruptive modal surface that demands an explicit response before a\n * page continues — confirming a destructive action, surfacing a blocking\n * error — built on the native `<dialog>` host of {@link Dialog}, widened for\n * its two-button layout and sealed against light dismiss. Its compound parts\n * cover a header, title, description, and a two-control footer.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { fg } from \"@sdxc/u/color\";\nimport { flex, gap, justify, vstack } from \"@sdxc/u/layout\";\nimport { mbs } from \"@sdxc/u/size\";\nimport { balance, pretty, text, weight } from \"@sdxc/u/typography\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { Dialog } from \"@sdxc/ui/dialog\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Invoker Commands verb {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} fall back to when `command` is omitted,\n * dismissing the ancestor AlertDialog named by `commandfor`.\n */\nconst DEFAULT_COMMAND = \"close\";\n\n/**\n * Native `button` `type` {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} always spell out, since the platform runs an\n * Invoker Command only from a button typed `\"button\"`, `<form>` or not.\n */\nconst DEFAULT_TYPE: NonNullable<Button.Props[\"type\"]> = \"button\";\n\n/** Semantic color role {@link AlertDialog.Action} falls back to when `color` is omitted. */\nconst DEFAULT_ACTION_COLOR: Button.Color = \"danger\";\n\n/** Visual weight {@link AlertDialog.Cancel} falls back to when `variant` is omitted. */\nconst DEFAULT_CANCEL_VARIANT: Button.Variant = \"outline\";\n\n/** Semantic color role {@link AlertDialog.Cancel} falls back to when `color` is omitted. */\nconst DEFAULT_CANCEL_COLOR: Button.Color = \"neutral\";\n\n/**\n * Prop types for {@link AlertDialog} and its compound parts.\n */\nexport namespace AlertDialog {\n\t/**\n\t * Every prop {@link Dialog} accepts, minus the ones this component fixes:\n\t * `role` is always `\"alertdialog\"` and `closedby`/`closedBy` always\n\t * `\"closerequest\"`, so the panel closes only on an explicit close request.\n\t */\n\texport interface Props extends Omit<Dialog.Props, \"role\" | \"closedby\" | \"closedBy\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Title}. Every native heading-element\n\t * attribute applies, since the rendered tag follows the nearest ambient\n\t * heading level, falling back to `<h1>`.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Action}: every {@link Button.Props}\n\t * field except `commandfor`/`command`, which this type narrows.\n\t */\n\texport interface ActionProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/**\n\t\t * `id` of the ancestor {@link AlertDialog} this action dismisses.\n\t\t * Required for the default `type=\"button\"` action; a `type=\"submit\"`\n\t\t * action ends the interruption by submitting its enclosing form.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/**\n\t\t * Invoker Commands verb dispatched to the target AlertDialog. Defaults\n\t\t * to `\"close\"`, and is dropped for a `\"submit\"` or `\"reset\"` action,\n\t\t * which the platform drives as a form control instead of an invoker.\n\t\t */\n\t\tcommand?: \"close\";\n\t}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Cancel}: every {@link Button.Props}\n\t * field except `commandfor`/`command`/`type`, which this type narrows.\n\t */\n\texport interface CancelProps extends Omit<Button.Props, \"commandfor\" | \"command\" | \"type\"> {\n\t\t/** `id` of the ancestor {@link AlertDialog} this cancel control dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target AlertDialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\n\t\t/**\n\t\t * Narrowed to the only value a cancel control carries, and always\n\t\t * rendered, since the platform runs its close command only from a\n\t\t * button typed `\"button\"`, including inside a `<form>`.\n\t\t */\n\t\ttype?: \"button\";\n\t}\n}\n\n/**\n * Renders the alert panel through {@link Dialog}, widened to fit a two-button\n * footer, with `role` fixed to `\"alertdialog\"` and `closedby` to\n * `\"closerequest\"` so the interruption clears through an explicit response.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Button commandfor=\"delete-project\" command=\"show-modal\" color=\"danger\">{t(\"project.delete\")}</Button>\n * <AlertDialog id=\"delete-project\" aria-labelledby=\"delete-project-title\">\n * \t<AlertDialog.Header>\n * \t\t<AlertDialog.Title id=\"delete-project-title\">{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t\t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * \t</AlertDialog.Header>\n * \t<AlertDialog.Footer>\n * \t\t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t\t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * \t</AlertDialog.Footer>\n * </AlertDialog>\n */\nexport function AlertDialog(handle: Handle<AlertDialog.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Dialog {...rest} role=\"alertdialog\" closedby=\"closerequest\" mix={mix}>\n\t\t\t\t{children}\n\t\t\t</Dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link AlertDialog.HeaderProps.children} as the panel's header\n * slot: a column stacking {@link AlertDialog.Title} and\n * {@link AlertDialog.Description} with a small gap between them.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <AlertDialog.Header>\n * \t<AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * </AlertDialog.Header>\n */\nAlertDialog.Header = function AlertDialogHeader(handle: Handle<AlertDialog.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"header\" mix={[vstack({ gap: 2 }), mix]} />;\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.TitleProps.children} as the panel's heading,\n * inside the native heading element matching the nearest ancestor\n * `HeadingScope`'s depth, or `<h1>` where no scope wraps it.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n */\nAlertDialog.Title = function AlertDialogTitle(handle: Handle<AlertDialog.TitleProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[fg(\"neutral.emphasis\"), weight(\"semibold\"), text(\"lg\"), balance(), mix]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.DescriptionProps.children} as the panel's\n * supporting copy, in a native `<p>` set to the panel's muted foreground\n * color so it reads as secondary to {@link AlertDialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n */\nAlertDialog.Description = function AlertDialogDescription(\n\thandle: Handle<AlertDialog.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[fg(\"neutral.muted\"), text(\"sm\"), pretty(), mix]}>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.FooterProps.children} as an end-aligned action\n * row. Compose {@link AlertDialog.Cancel} before {@link AlertDialog.Action}\n * so the emphasized, potentially destructive control renders last.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <AlertDialog.Footer>\n * \t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * </AlertDialog.Footer>\n */\nAlertDialog.Footer = function AlertDialogFooter(handle: Handle<AlertDialog.FooterProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"footer\" mix={[gap(2), mbs(6), flex(), justify(\"end\"), mix]} />;\n\t};\n};\n\n/**\n * Renders the panel's emphasized action as a danger-toned {@link Button},\n * typed `\"button\"` so its `command=\"close\"` reaches the {@link AlertDialog}\n * named by `commandfor`; `type=\"submit\"` submits the enclosing form instead.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action commandfor=\"publish-post\" color=\"brand\">{t(\"actions.publish\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action type=\"submit\" name=\"intent\" value=\"delete\">{t(\"actions.delete\")}</AlertDialog.Action>\n */\nAlertDialog.Action = function AlertDialogAction(handle: Handle<AlertDialog.ActionProps>) {\n\treturn () => {\n\t\tlet { type, color, command, commandfor, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_TYPE;\n\t\tlet isInvoker = resolvedType === \"button\";\n\t\tlet resolvedColor = color ?? DEFAULT_ACTION_COLOR;\n\n\t\tif (import.meta.env.DEV && isInvoker && !commandfor) {\n\t\t\tconsole.warn(\n\t\t\t\t'AlertDialog.Action: needs \"commandfor\" naming the panel it dismisses, or type=\"submit\" to submit its enclosing form instead — as rendered, pressing it does nothing.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={resolvedType}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommandfor={isInvoker ? commandfor : undefined}\n\t\t\t\tcommand={isInvoker ? (command ?? DEFAULT_COMMAND) : undefined}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's dismiss control as an outline, neutral {@link Button}\n * with `type` fixed to `\"button\"`, so its `command=\"close\"` reaches the\n * {@link AlertDialog} named by `commandfor` from inside a `<form>` too.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the cancel control's markup.\n * @example\n * <AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n */\nAlertDialog.Cancel = function AlertDialogCancel(handle: Handle<AlertDialog.CancelProps>) {\n\treturn () => {\n\t\tlet { variant, color, command, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CANCEL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CANCEL_COLOR;\n\t\tlet resolvedCommand = command ?? DEFAULT_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={DEFAULT_TYPE}\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"cancel\"\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
14
|
+
"content": "/**\n * An interruptive modal surface that demands an explicit response before a\n * page continues — confirming a destructive action, surfacing a blocking\n * error — built on the native `<dialog>` host of {@link Dialog}, widened for\n * its two-button layout and sealed against light dismiss. Its compound parts\n * cover a header, title, description, and a two-control footer.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { fg } from \"@sdxc/u/color\";\nimport { flex, gap, justify, vstack } from \"@sdxc/u/layout\";\nimport { mbs } from \"@sdxc/u/size\";\nimport { balance, pretty, text, weight } from \"@sdxc/u/typography\";\n\nimport { Button } from \"@sdxc/ui/button\";\nimport { Dialog } from \"@sdxc/ui/dialog\";\nimport { resolveHeadingLevel, TAG_BY_LEVEL } from \"@sdxc/ui/heading-scope\";\n\n/**\n * Invoker Commands verb {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} fall back to when `command` is omitted,\n * dismissing the ancestor AlertDialog named by `commandfor`.\n */\nconst DEFAULT_COMMAND = \"close\";\n\n/**\n * Native `button` `type` {@link AlertDialog.Action} and\n * {@link AlertDialog.Cancel} always spell out, since the platform runs an\n * Invoker Command only from a button typed `\"button\"`, `<form>` or not.\n */\nconst DEFAULT_TYPE: NonNullable<Button.Props[\"type\"]> = \"button\";\n\n/** Semantic color role {@link AlertDialog.Action} falls back to when `color` is omitted. */\nconst DEFAULT_ACTION_COLOR: Button.Color = \"danger\";\n\n/** Visual weight {@link AlertDialog.Cancel} falls back to when `variant` is omitted. */\nconst DEFAULT_CANCEL_VARIANT: Button.Variant = \"outline\";\n\n/** Semantic color role {@link AlertDialog.Cancel} falls back to when `color` is omitted. */\nconst DEFAULT_CANCEL_COLOR: Button.Color = \"neutral\";\n\n/**\n * Prop types for {@link AlertDialog} and its compound parts.\n */\nexport namespace AlertDialog {\n\t/**\n\t * Every prop {@link Dialog} accepts, minus the ones this component fixes:\n\t * `role` is always `\"alertdialog\"` and `closedby`/`closedBy` always\n\t * `\"closerequest\"`, so the panel closes only on an explicit close request.\n\t */\n\texport interface Props extends Omit<Dialog.Props, \"role\" | \"closedby\" | \"closedBy\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Header}.\n\t */\n\texport interface HeaderProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Title}. Every native heading-element\n\t * attribute applies, since the rendered tag follows the nearest ambient\n\t * heading level, falling back to `<h1>`.\n\t */\n\texport interface TitleProps extends TagProps<\"h1\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Footer}.\n\t */\n\texport interface FooterProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Action}: every {@link Button.Props}\n\t * field except `commandfor`/`command`, which this type narrows.\n\t */\n\texport interface ActionProps extends Omit<Button.Props, \"commandfor\" | \"command\"> {\n\t\t/**\n\t\t * `id` of the ancestor {@link AlertDialog} this action dismisses.\n\t\t * Required for the default `type=\"button\"` action; a `type=\"submit\"`\n\t\t * action ends the interruption by submitting its enclosing form.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/**\n\t\t * Invoker Commands verb dispatched to the target AlertDialog. Defaults\n\t\t * to `\"close\"`, and is dropped for a `\"submit\"` or `\"reset\"` action,\n\t\t * which the platform drives as a form control instead of an invoker.\n\t\t */\n\t\tcommand?: \"close\";\n\t}\n\n\t/**\n\t * Props accepted by {@link AlertDialog.Cancel}: every {@link Button.Props}\n\t * field except `commandfor`/`command`/`type`, which this type narrows.\n\t */\n\texport interface CancelProps extends Omit<Button.Props, \"commandfor\" | \"command\" | \"type\"> {\n\t\t/** `id` of the ancestor {@link AlertDialog} this cancel control dismisses. */\n\t\tcommandfor: string;\n\t\t/** Invoker Commands verb dispatched to the target AlertDialog. Defaults to `\"close\"`. */\n\t\tcommand?: \"close\";\n\t\t/**\n\t\t * Narrowed to the only value a cancel control carries, and always\n\t\t * rendered, since the platform runs its close command only from a\n\t\t * button typed `\"button\"`, including inside a `<form>`.\n\t\t */\n\t\ttype?: \"button\";\n\t}\n}\n\n/**\n * Renders the alert panel through {@link Dialog}, widened to fit a two-button\n * footer, with `role` fixed to `\"alertdialog\"` and `closedby` to\n * `\"closerequest\"` so the interruption clears through an explicit response.\n *\n * @param handle Runtime handle carrying the host `<dialog>`'s props.\n * @returns The render function producing the panel's markup.\n * @example\n * <Button commandfor=\"delete-project\" command=\"show-modal\" color=\"danger\">{t(\"project.delete\")}</Button>\n * <AlertDialog id=\"delete-project\" aria-labelledby=\"delete-project-title\">\n * \t<AlertDialog.Header>\n * \t\t<AlertDialog.Title id=\"delete-project-title\">{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t\t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * \t</AlertDialog.Header>\n * \t<AlertDialog.Footer>\n * \t\t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t\t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * \t</AlertDialog.Footer>\n * </AlertDialog>\n */\nexport function AlertDialog(handle: Handle<AlertDialog.Props>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Dialog {...rest} role=\"alertdialog\" closedby=\"closerequest\" mix={mix}>\n\t\t\t\t{children}\n\t\t\t</Dialog>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link AlertDialog.HeaderProps.children} as the panel's header\n * slot: a column stacking {@link AlertDialog.Title} and\n * {@link AlertDialog.Description} with a small gap between them.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the header slot's markup.\n * @example\n * <AlertDialog.Header>\n * \t<AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n * \t<AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n * </AlertDialog.Header>\n */\nAlertDialog.Header = function AlertDialogHeader(handle: Handle<AlertDialog.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"header\" mix={[vstack({ gap: 2 }), mix]} />;\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.TitleProps.children} as the panel's heading,\n * inside the native heading element matching the nearest ancestor\n * `HeadingScope`'s depth, or `<h1>` where no scope wraps it.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the heading's markup.\n * @example\n * <AlertDialog.Title>{t(\"project.deleteTitle\")}</AlertDialog.Title>\n */\nAlertDialog.Title = function AlertDialogTitle(handle: Handle<AlertDialog.TitleProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\tlet resolved = resolveHeadingLevel(handle);\n\t\tlet Tag = TAG_BY_LEVEL[resolved];\n\n\t\treturn (\n\t\t\t<Tag\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tmix={[fg(\"neutral.emphasis\"), weight(\"semibold\"), text(\"lg\"), balance(), mix]}\n\t\t\t>\n\t\t\t\t{rest.children}\n\t\t\t</Tag>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.DescriptionProps.children} as the panel's\n * supporting copy, in a native `<p>` set to the panel's muted foreground\n * color so it reads as secondary to {@link AlertDialog.Title}.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <AlertDialog.Description>{t(\"project.deleteDescription\")}</AlertDialog.Description>\n */\nAlertDialog.Description = function AlertDialogDescription(\n\thandle: Handle<AlertDialog.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[fg(\"neutral.muted\"), text(\"sm\"), pretty(), mix]}>\n\t\t\t\t{rest.children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link AlertDialog.FooterProps.children} as an end-aligned action\n * row. Compose {@link AlertDialog.Cancel} before {@link AlertDialog.Action}\n * so the emphasized, potentially destructive control renders last.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <AlertDialog.Footer>\n * \t<AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n * \t<AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * </AlertDialog.Footer>\n */\nAlertDialog.Footer = function AlertDialogFooter(handle: Handle<AlertDialog.FooterProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} data-slot=\"footer\" mix={[gap(2), mbs(6), flex(), justify(\"end\"), mix]} />;\n\t};\n};\n\n/**\n * Renders the panel's emphasized action as a danger-toned {@link Button},\n * typed `\"button\"` so its `command=\"close\"` reaches the {@link AlertDialog}\n * named by `commandfor`; `type=\"submit\"` submits the enclosing form instead.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <AlertDialog.Action commandfor=\"delete-project\">{t(\"actions.delete\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action commandfor=\"publish-post\" color=\"brand\">{t(\"actions.publish\")}</AlertDialog.Action>\n * @example\n * <AlertDialog.Action type=\"submit\" name=\"intent\" value=\"delete\">{t(\"actions.delete\")}</AlertDialog.Action>\n */\nAlertDialog.Action = function AlertDialogAction(handle: Handle<AlertDialog.ActionProps>) {\n\treturn () => {\n\t\tlet { type, color, command, commandfor, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_TYPE;\n\t\tlet isInvoker = resolvedType === \"button\";\n\t\tlet resolvedColor = color ?? DEFAULT_ACTION_COLOR;\n\n\t\tif (import.meta.env?.DEV && isInvoker && !commandfor) {\n\t\t\tconsole.warn(\n\t\t\t\t'AlertDialog.Action: needs \"commandfor\" naming the panel it dismisses, or type=\"submit\" to submit its enclosing form instead — as rendered, pressing it does nothing.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={resolvedType}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommandfor={isInvoker ? commandfor : undefined}\n\t\t\t\tcommand={isInvoker ? (command ?? DEFAULT_COMMAND) : undefined}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the panel's dismiss control as an outline, neutral {@link Button}\n * with `type` fixed to `\"button\"`, so its `command=\"close\"` reaches the\n * {@link AlertDialog} named by `commandfor` from inside a `<form>` too.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the cancel control's markup.\n * @example\n * <AlertDialog.Cancel commandfor=\"delete-project\">{t(\"actions.cancel\")}</AlertDialog.Cancel>\n */\nAlertDialog.Cancel = function AlertDialogCancel(handle: Handle<AlertDialog.CancelProps>) {\n\treturn () => {\n\t\tlet { variant, color, command, ...rest } = handle.props;\n\t\tlet resolvedVariant = variant ?? DEFAULT_CANCEL_VARIANT;\n\t\tlet resolvedColor = color ?? DEFAULT_CANCEL_COLOR;\n\t\tlet resolvedCommand = command ?? DEFAULT_COMMAND;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\t{...rest}\n\t\t\t\ttype={DEFAULT_TYPE}\n\t\t\t\tvariant={resolvedVariant}\n\t\t\t\tcolor={resolvedColor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\tdata-slot=\"cancel\"\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
15
15
|
},
|
|
16
16
|
"test": {
|
|
17
17
|
"path": "alert-dialog.test.tsx",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "attachment",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"button"
|
|
6
6
|
],
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "attachment.tsx",
|
|
12
|
-
"content": "/**\n * A compound card presenting one attached file or image — media preview, name,\n * supporting details, actions — plus a horizontally scrolling row for several\n * cards side by side. Every part styles itself off the card's own `state`, and\n * whole-card click-through stays an opt-in wrapper a consumer mixes in.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tblock,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\thstack,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { overflow, overflowX } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { aspect, bs, fit, is, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign, truncate, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { shimmer } from \"@sdxc/ui/animations\";\nimport { scrollFade } from \"@sdxc/ui/animations\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\nconst DEFAULT_STATE: Attachment.State = \"idle\";\n\n/**\n * Named container {@link Attachment} declares on its own host, so\n * {@link Attachment.Media}, {@link Attachment.Content}, and the inner layout\n * wrapper resolve their width queries against the card itself.\n */\nconst CONTAINER_NAME = \"ui-attachment\";\n\n/**\n * `@container` query every width-adapting part below the root shares: at or\n * under this width the card reflows into a taller tile, the shape\n * {@link Attachment.Group}'s narrow, fixed-width cards need.\n */\nconst NARROW_CONTAINER_QUERY = `@container ${CONTAINER_NAME} (max-width: 12rem)`;\n\n/**\n * Selector fragment gating {@link Attachment.Title}'s shimmer: it matches the\n * title's own `data-state` attribute while that reads `\"uploading\"` or\n * `\"processing\"`, so a title in any other state renders as plain text.\n */\nconst TITLE_SHIMMER_WHEN = ':is([data-state=\"uploading\"], [data-state=\"processing\"])';\n\nconst DEFAULT_ACTION_VARIANT: Button.Variant = \"ghost\";\n\nconst DEFAULT_ACTION_SIZE: Button.Size = \"sm\";\n\nconst DEFAULT_ACTION_COLOR: Button.Color = \"neutral\";\n\n/**\n * Tab-stop order {@link attrs} applies to {@link Attachment.Group} when a\n * consumer supplies no `tabIndex`, so the row itself stays keyboard-reachable\n * and scrollable whatever its cards contain.\n */\nconst DEFAULT_GROUP_TAB_INDEX = 0;\n\nconst GROUP_SCROLL_FADE_SIZE = \"2rem\";\n\n/**\n * Prop types for {@link Attachment} and its compound parts.\n */\nexport namespace Attachment {\n\t/**\n\t * Lifecycle state of a card's file or image. `\"idle\"` and `\"done\"` both\n\t * render as a settled card — `\"idle\"` for a file already on the server,\n\t * `\"done\"` for one whose transfer finished. A consumer owns every transition.\n\t */\n\texport type State = \"idle\" | \"uploading\" | \"processing\" | \"error\" | \"done\";\n\n\t/**\n\t * Props accepted by {@link Attachment}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Lifecycle state of the file or image the card represents. Defaults to `\"idle\"`. */\n\t\tstate?: State;\n\t\t/** The card's compound parts: {@link Attachment.Media}, {@link Attachment.Content}, and {@link Attachment.Actions}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Media}.\n\t */\n\texport interface MediaProps extends TagProps<\"div\"> {\n\t\t/** The preview itself: an `<img>`, or a decorative icon standing in for the file's type. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** {@link Attachment.Title} and, optionally, {@link Attachment.Description}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"p\"> {\n\t\t/**\n\t\t * The ancestor {@link Attachment}'s own `state`, repeated here because a\n\t\t * component reads only its own props; passing the same value to both is\n\t\t * what keeps them in sync. Left unset, the title renders plain.\n\t\t */\n\t\tstate?: Attachment.State;\n\t\t/** The file or image name. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** Supporting detail — a file size, a page count, an error message. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Actions}.\n\t */\n\texport interface ActionsProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment.Action} controls. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Action}: every {@link Button.Props}\n\t * field, unchanged, so an action keeps the same color, weight, and size\n\t * contract as every other button in the catalog.\n\t */\n\texport interface ActionProps extends Button.Props {}\n\n\t/**\n\t * Props accepted by {@link Attachment.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Destination the whole card follows once `attachmentTrigger()` is mixed\n\t\t * in, opened in place unless the activation asks for a new tab. It rides on\n\t\t * a `<div>` so a nested {@link Attachment.Action} stays valid markup.\n\t\t */\n\t\thref?: string;\n\t\t/**\n\t\t * `id` of a `<dialog>` element the whole card opens once\n\t\t * `attachmentTrigger()` is mixed in, instead of following `href`.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/** Invoker Commands verb dispatched to `commandfor`'s dialog. Defaults to `\"show-modal\"`. */\n\t\tcommand?: \"show-modal\";\n\t\t/** Where `href` opens: a window/frame name, or `\"_blank\"` for a new tab. Meaningful only alongside `href`. */\n\t\ttarget?: string;\n\t\t/** The card's own markup — typically an {@link Attachment}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment} or {@link Attachment.Trigger} cards. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The card's outer host, recolored to the danger tint at `state=\"error\"` and\n * declaring the `ui-attachment` named container so nested parts reflow at the\n * card's width. A busy state sets `aria-busy` to the token ARIA recognizes.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the card's markup.\n * @example\n * <Attachment state=\"uploading\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title state=\"uploading\">quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploading\")}</Attachment.Description>\n * \t</Attachment.Content>\n * </Attachment>\n * @example\n * <Attachment state=\"error\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n * \t</Attachment.Content>\n * \t<Attachment.Actions>\n * \t\t<Attachment.Action aria-label={t(\"attachment.retry\")}><RotateCwIcon /></Attachment.Action>\n * \t</Attachment.Actions>\n * </Attachment>\n */\nexport function Attachment(handle: Handle<Attachment.Props>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\t\tlet resolvedState = state ?? DEFAULT_STATE;\n\t\tlet isBusy = resolvedState === \"uploading\" || resolvedState === \"processing\";\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"attachment\"\n\t\t\t\tdata-state={resolvedState}\n\t\t\t\taria-busy={isBusy ? \"true\" : undefined}\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tp(3),\n\t\t\t\t\ttransition(\"border-color, background-color\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\twhen('&[data-state=\"error\"]', [\n\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\tbg(\"danger.tint\"),\n\t\t\t\t\t\tfg(\"danger.emphasis\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\thstack({ gap: 3, align: \"center\" }),\n\t\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [flexCol(), items(\"stretch\")]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The card's media well: a fixed-size, rounded box clipping the preview a\n * consumer nests inside. Inside a narrow container it grows to the card's own\n * inline size at a wider aspect ratio, reading as a thumbnail tile.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the media well's markup.\n * @example\n * <Attachment.Media><img src={file.thumbnailUrl} alt=\"\" /></Attachment.Media>\n * @example\n * <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n */\nAttachment.Media = function AttachmentMedia(handle: Handle<Attachment.MediaProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"media\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(10),\n\t\t\t\t\tbs(10),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\twhen(\"& > img\", [is(\"full\"), bs(\"full\"), fit(\"cover\")]),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [is(\"full\"), bs(\"auto\"), aspect(4, 3), rounded(\"lg\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * The card's text column, growing into whatever inline space\n * {@link Attachment.Media} and {@link Attachment.Actions} leave it. Its minimum\n * inline size collapses to `0`, which is what lets its children truncate.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text column's markup.\n * @example\n * <Attachment.Content>\n * \t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t<Attachment.Description>2.4 MB</Attachment.Description>\n * </Attachment.Content>\n */\nAttachment.Content = function AttachmentContent(handle: Handle<Attachment.ContentProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"content\"\n\t\t\t\tmix={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\tminIs(0),\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, textAlign(\"center\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * The file or image name in a native `<p>`, truncated to a single line with an\n * ellipsis. Given the same `state` as the ancestor {@link Attachment}, it\n * shimmers while that reads `\"uploading\"` or `\"processing\"`, then settles.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the title's markup.\n * @example\n * <Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * @example\n * <Attachment.Title state={attachment.state}>{attachment.name}</Attachment.Title>\n */\nAttachment.Title = function AttachmentTitle(handle: Handle<Attachment.TitleProps>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tdata-state={state}\n\t\t\t\tmix={[\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttruncate(),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The loop settles visible, because this host carries the file's name: a gated\n\t\t\t\t\t * loop rests hidden outside its gate, which suits an element that exists only\n\t\t\t\t\t * as a loading cue and would leave every finished upload unnamed.\n\t\t\t\t\t */\n\t\t\t\t\tshimmer({ when: TITLE_SHIMMER_WHEN, outsideGate: \"visible\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's supporting detail line: a muted, single-line `<p>` carrying a file\n * size, a page count, or the explanation of what went wrong once the ancestor\n * {@link Attachment}'s `state` reads `\"error\"`.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Attachment.Description>2.4 MB</Attachment.Description>\n * @example\n * <Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n */\nAttachment.Description = function AttachmentDescription(\n\thandle: Handle<Attachment.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[truncate(), fg(\"neutral.muted\"), text(\"xs\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's action row, shrink-proof so a narrow card's width is absorbed by\n * {@link Attachment.Content}'s own truncation while the actions keep their\n * size.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Attachment.Actions>\n * \t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t<Attachment.Action aria-label={t(\"attachment.remove\")}><XIcon /></Attachment.Action>\n * </Attachment.Actions>\n */\nAttachment.Actions = function AttachmentActions(handle: Handle<Attachment.ActionsProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"actions\" mix={[flex(), shrink(0), items(\"center\"), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A single card action as a {@link Button}, defaulting to a compact, `\"ghost\"`,\n * neutral control so a row of actions reads as secondary to the card's title.\n * Every {@link Button} prop stays available, `type` included.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <Attachment.Action aria-label={t(\"attachment.download\")}>\n * \t<DownloadIcon />\n * </Attachment.Action>\n * @example\n * <Attachment.Action type=\"submit\" name=\"intent\" value=\"retry\" aria-label={t(\"attachment.retry\")}>\n * \t<RotateCwIcon />\n * </Attachment.Action>\n */\nAttachment.Action = function AttachmentAction(handle: Handle<Attachment.ActionProps>) {\n\treturn () => {\n\t\tlet { color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tcolor={color ?? DEFAULT_ACTION_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_ACTION_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_ACTION_SIZE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[shrink(0), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A wrapper `<div>` whose `href` or `commandfor` stays an inert attribute until\n * a consumer mixes in `attachmentTrigger()`. Either one also derives a `role`\n * and `tabIndex`, so whole-card activation is announced and keyboard-reachable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Attachment.Trigger href=\"/files/quarterly-report.pdf\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">\n * \t\t<Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n * \t\t<Attachment.Content>\n * \t\t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t</Attachment.Content>\n * \t\t<Attachment.Actions>\n * \t\t\t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t\t</Attachment.Actions>\n * \t</Attachment>\n * </Attachment.Trigger>\n * @example\n * <Attachment.Trigger commandfor=\"quarterly-report-preview\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">…</Attachment>\n * </Attachment.Trigger>\n * <Dialog id=\"quarterly-report-preview\">…</Dialog>\n */\nAttachment.Trigger = function AttachmentTrigger(handle: Handle<Attachment.TriggerProps>) {\n\treturn () => {\n\t\tlet { href, commandfor, command, target, role, tabIndex, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isConfigured = href !== undefined || commandfor !== undefined;\n\t\tlet resolvedRole = role ?? (href !== undefined ? \"link\" : isConfigured ? \"button\" : undefined);\n\t\tlet resolvedTabIndex = tabIndex ?? (isConfigured ? 0 : undefined);\n\n\t\tif (import.meta.env.DEV && !isConfigured) {\n\t\t\tconsole.warn(\n\t\t\t\t'Attachment.Trigger: rendered with neither \"href\" nor \"commandfor\" — nothing will happen once `attachmentTrigger()` handles an activation.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\trole={resolvedRole}\n\t\t\t\ttabIndex={resolvedTabIndex}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ href, commandfor, command, target }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"inherit\"),\n\t\t\t\t\twhen(\"&[role]:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&[role]:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A horizontally scroll-snapping row of cards, faded at both inline edges to\n * hint at cards beyond the current view. The row itself carries the tab stop,\n * since the row is what scrolls.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Attachment.Group aria-label={t(\"thread.attachments\")}>\n * \t{attachments.map((attachment) => (\n * \t\t<Attachment key={attachment.id} state={attachment.state}>…</Attachment>\n * \t))}\n * </Attachment.Group>\n */\nAttachment.Group = function AttachmentGroup(handle: Handle<Attachment.GroupProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ tabIndex: DEFAULT_GROUP_TAB_INDEX }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(3),\n\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\tscrollPaddingInline: \"0.75rem\",\n\t\t\t\t\t\tscrollBehavior: \"auto\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"& > *\", [shrink(0), raw({ scrollSnapAlign: \"start\" })]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: no-preference)\", raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\tscrollFade({ axis: \"inline\", size: GROUP_SCROLL_FADE_SIZE }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n"
|
|
12
|
+
"content": "/**\n * A compound card presenting one attached file or image — media preview, name,\n * supporting details, actions — plus a horizontally scrolling row for several\n * cards side by side. Every part styles itself off the card's own `state`, and\n * whole-card click-through stays an opt-in wrapper a consumer mixes in.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { rounded, transition } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tblock,\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrow,\n\thstack,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n\tvstack,\n} from \"@sdxc/u/layout\";\nimport { overflow, overflowX } from \"@sdxc/u/overflow\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { aspect, bs, fit, is, minIs, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { text, textAlign, truncate, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { shimmer } from \"@sdxc/ui/animations\";\nimport { scrollFade } from \"@sdxc/ui/animations\";\n\nimport { Button } from \"@sdxc/ui/button\";\n\nconst DEFAULT_STATE: Attachment.State = \"idle\";\n\n/**\n * Named container {@link Attachment} declares on its own host, so\n * {@link Attachment.Media}, {@link Attachment.Content}, and the inner layout\n * wrapper resolve their width queries against the card itself.\n */\nconst CONTAINER_NAME = \"ui-attachment\";\n\n/**\n * `@container` query every width-adapting part below the root shares: at or\n * under this width the card reflows into a taller tile, the shape\n * {@link Attachment.Group}'s narrow, fixed-width cards need.\n */\nconst NARROW_CONTAINER_QUERY = `@container ${CONTAINER_NAME} (max-width: 12rem)`;\n\n/**\n * Selector fragment gating {@link Attachment.Title}'s shimmer: it matches the\n * title's own `data-state` attribute while that reads `\"uploading\"` or\n * `\"processing\"`, so a title in any other state renders as plain text.\n */\nconst TITLE_SHIMMER_WHEN = ':is([data-state=\"uploading\"], [data-state=\"processing\"])';\n\nconst DEFAULT_ACTION_VARIANT: Button.Variant = \"ghost\";\n\nconst DEFAULT_ACTION_SIZE: Button.Size = \"sm\";\n\nconst DEFAULT_ACTION_COLOR: Button.Color = \"neutral\";\n\n/**\n * Tab-stop order {@link attrs} applies to {@link Attachment.Group} when a\n * consumer supplies no `tabIndex`, so the row itself stays keyboard-reachable\n * and scrollable whatever its cards contain.\n */\nconst DEFAULT_GROUP_TAB_INDEX = 0;\n\nconst GROUP_SCROLL_FADE_SIZE = \"2rem\";\n\n/**\n * Prop types for {@link Attachment} and its compound parts.\n */\nexport namespace Attachment {\n\t/**\n\t * Lifecycle state of a card's file or image. `\"idle\"` and `\"done\"` both\n\t * render as a settled card — `\"idle\"` for a file already on the server,\n\t * `\"done\"` for one whose transfer finished. A consumer owns every transition.\n\t */\n\texport type State = \"idle\" | \"uploading\" | \"processing\" | \"error\" | \"done\";\n\n\t/**\n\t * Props accepted by {@link Attachment}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Lifecycle state of the file or image the card represents. Defaults to `\"idle\"`. */\n\t\tstate?: State;\n\t\t/** The card's compound parts: {@link Attachment.Media}, {@link Attachment.Content}, and {@link Attachment.Actions}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Media}.\n\t */\n\texport interface MediaProps extends TagProps<\"div\"> {\n\t\t/** The preview itself: an `<img>`, or a decorative icon standing in for the file's type. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Content}.\n\t */\n\texport interface ContentProps extends TagProps<\"div\"> {\n\t\t/** {@link Attachment.Title} and, optionally, {@link Attachment.Description}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Title}.\n\t */\n\texport interface TitleProps extends TagProps<\"p\"> {\n\t\t/**\n\t\t * The ancestor {@link Attachment}'s own `state`, repeated here because a\n\t\t * component reads only its own props; passing the same value to both is\n\t\t * what keeps them in sync. Left unset, the title renders plain.\n\t\t */\n\t\tstate?: Attachment.State;\n\t\t/** The file or image name. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Description}.\n\t */\n\texport interface DescriptionProps extends TagProps<\"p\"> {\n\t\t/** Supporting detail — a file size, a page count, an error message. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Actions}.\n\t */\n\texport interface ActionsProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment.Action} controls. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Action}: every {@link Button.Props}\n\t * field, unchanged, so an action keeps the same color, weight, and size\n\t * contract as every other button in the catalog.\n\t */\n\texport interface ActionProps extends Button.Props {}\n\n\t/**\n\t * Props accepted by {@link Attachment.Trigger}.\n\t */\n\texport interface TriggerProps extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Destination the whole card follows once `attachmentTrigger()` is mixed\n\t\t * in, opened in place unless the activation asks for a new tab. It rides on\n\t\t * a `<div>` so a nested {@link Attachment.Action} stays valid markup.\n\t\t */\n\t\thref?: string;\n\t\t/**\n\t\t * `id` of a `<dialog>` element the whole card opens once\n\t\t * `attachmentTrigger()` is mixed in, instead of following `href`.\n\t\t */\n\t\tcommandfor?: string;\n\t\t/** Invoker Commands verb dispatched to `commandfor`'s dialog. Defaults to `\"show-modal\"`. */\n\t\tcommand?: \"show-modal\";\n\t\t/** Where `href` opens: a window/frame name, or `\"_blank\"` for a new tab. Meaningful only alongside `href`. */\n\t\ttarget?: string;\n\t\t/** The card's own markup — typically an {@link Attachment}. */\n\t\tchildren: RemixNode;\n\t}\n\n\t/**\n\t * Props accepted by {@link Attachment.Group}.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {\n\t\t/** A run of {@link Attachment} or {@link Attachment.Trigger} cards. */\n\t\tchildren: RemixNode;\n\t}\n}\n\n/**\n * The card's outer host, recolored to the danger tint at `state=\"error\"` and\n * declaring the `ui-attachment` named container so nested parts reflow at the\n * card's width. A busy state sets `aria-busy` to the token ARIA recognizes.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the card's markup.\n * @example\n * <Attachment state=\"uploading\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title state=\"uploading\">quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploading\")}</Attachment.Description>\n * \t</Attachment.Content>\n * </Attachment>\n * @example\n * <Attachment state=\"error\">\n * \t<Attachment.Media><FileIcon aria-hidden /></Attachment.Media>\n * \t<Attachment.Content>\n * \t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t<Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n * \t</Attachment.Content>\n * \t<Attachment.Actions>\n * \t\t<Attachment.Action aria-label={t(\"attachment.retry\")}><RotateCwIcon /></Attachment.Action>\n * \t</Attachment.Actions>\n * </Attachment>\n */\nexport function Attachment(handle: Handle<Attachment.Props>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\t\tlet resolvedState = state ?? DEFAULT_STATE;\n\t\tlet isBusy = resolvedState === \"uploading\" || resolvedState === \"processing\";\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"attachment\"\n\t\t\t\tdata-state={resolvedState}\n\t\t\t\taria-busy={isBusy ? \"true\" : undefined}\n\t\t\t\tmix={[\n\t\t\t\t\trelative(),\n\t\t\t\t\trounded(\"lg\"),\n\t\t\t\t\tborder({ width: 1 }),\n\t\t\t\t\tborder(\"neutral\"),\n\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tp(3),\n\t\t\t\t\ttransition(\"border-color, background-color\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\twhen('&[data-state=\"error\"]', [\n\t\t\t\t\t\tborder(\"danger\"),\n\t\t\t\t\t\tbg(\"danger.tint\"),\n\t\t\t\t\t\tfg(\"danger.emphasis\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"body\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\thstack({ gap: 3, align: \"center\" }),\n\t\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [flexCol(), items(\"stretch\")]),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * The card's media well: a fixed-size, rounded box clipping the preview a\n * consumer nests inside. Inside a narrow container it grows to the card's own\n * inline size at a wider aspect ratio, reading as a thumbnail tile.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the media well's markup.\n * @example\n * <Attachment.Media><img src={file.thumbnailUrl} alt=\"\" /></Attachment.Media>\n * @example\n * <Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n */\nAttachment.Media = function AttachmentMedia(handle: Handle<Attachment.MediaProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"media\"\n\t\t\t\tmix={[\n\t\t\t\t\tflex(),\n\t\t\t\t\tshrink(0),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(10),\n\t\t\t\t\tbs(10),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\twhen(\"& > svg\", [is(5), bs(5)]),\n\t\t\t\t\twhen(\"& > img\", [is(\"full\"), bs(\"full\"), fit(\"cover\")]),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, [is(\"full\"), bs(\"auto\"), aspect(4, 3), rounded(\"lg\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * The card's text column, growing into whatever inline space\n * {@link Attachment.Media} and {@link Attachment.Actions} leave it. Its minimum\n * inline size collapses to `0`, which is what lets its children truncate.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the text column's markup.\n * @example\n * <Attachment.Content>\n * \t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t<Attachment.Description>2.4 MB</Attachment.Description>\n * </Attachment.Content>\n */\nAttachment.Content = function AttachmentContent(handle: Handle<Attachment.ContentProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"content\"\n\t\t\t\tmix={[\n\t\t\t\t\tvstack({ gap: 0.5 }),\n\t\t\t\t\tminIs(0),\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\twhen(NARROW_CONTAINER_QUERY, textAlign(\"center\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * The file or image name in a native `<p>`, truncated to a single line with an\n * ellipsis. Given the same `state` as the ancestor {@link Attachment}, it\n * shimmers while that reads `\"uploading\"` or `\"processing\"`, then settles.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the title's markup.\n * @example\n * <Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * @example\n * <Attachment.Title state={attachment.state}>{attachment.name}</Attachment.Title>\n */\nAttachment.Title = function AttachmentTitle(handle: Handle<Attachment.TitleProps>) {\n\treturn () => {\n\t\tlet { state, children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"title\"\n\t\t\t\tdata-state={state}\n\t\t\t\tmix={[\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\ttruncate(),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t/**\n\t\t\t\t\t * The loop settles visible, because this host carries the file's name: a gated\n\t\t\t\t\t * loop rests hidden outside its gate, which suits an element that exists only\n\t\t\t\t\t * as a loading cue and would leave every finished upload unnamed.\n\t\t\t\t\t */\n\t\t\t\t\tshimmer({ when: TITLE_SHIMMER_WHEN, outsideGate: \"visible\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's supporting detail line: a muted, single-line `<p>` carrying a file\n * size, a page count, or the explanation of what went wrong once the ancestor\n * {@link Attachment}'s `state` reads `\"error\"`.\n *\n * @param handle Runtime handle carrying the host `<p>`'s props.\n * @returns The render function producing the description's markup.\n * @example\n * <Attachment.Description>2.4 MB</Attachment.Description>\n * @example\n * <Attachment.Description>{t(\"attachment.uploadFailed\")}</Attachment.Description>\n */\nAttachment.Description = function AttachmentDescription(\n\thandle: Handle<Attachment.DescriptionProps>,\n) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<p {...rest} data-slot=\"description\" mix={[truncate(), fg(\"neutral.muted\"), text(\"xs\"), mix]}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t);\n\t};\n};\n\n/**\n * The card's action row, shrink-proof so a narrow card's width is absorbed by\n * {@link Attachment.Content}'s own truncation while the actions keep their\n * size.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the action row's markup.\n * @example\n * <Attachment.Actions>\n * \t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t<Attachment.Action aria-label={t(\"attachment.remove\")}><XIcon /></Attachment.Action>\n * </Attachment.Actions>\n */\nAttachment.Actions = function AttachmentActions(handle: Handle<Attachment.ActionsProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"actions\" mix={[flex(), shrink(0), items(\"center\"), gap(1), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A single card action as a {@link Button}, defaulting to a compact, `\"ghost\"`,\n * neutral control so a row of actions reads as secondary to the card's title.\n * Every {@link Button} prop stays available, `type` included.\n *\n * @param handle Runtime handle carrying the host button's props.\n * @returns The render function producing the action's markup.\n * @example\n * <Attachment.Action aria-label={t(\"attachment.download\")}>\n * \t<DownloadIcon />\n * </Attachment.Action>\n * @example\n * <Attachment.Action type=\"submit\" name=\"intent\" value=\"retry\" aria-label={t(\"attachment.retry\")}>\n * \t<RotateCwIcon />\n * </Attachment.Action>\n */\nAttachment.Action = function AttachmentAction(handle: Handle<Attachment.ActionProps>) {\n\treturn () => {\n\t\tlet { color, variant, size, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Button\n\t\t\t\tcolor={color ?? DEFAULT_ACTION_COLOR}\n\t\t\t\tvariant={variant ?? DEFAULT_ACTION_VARIANT}\n\t\t\t\tsize={size ?? DEFAULT_ACTION_SIZE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"action\"\n\t\t\t\tmix={[shrink(0), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * A wrapper `<div>` whose `href` or `commandfor` stays an inert attribute until\n * a consumer mixes in `attachmentTrigger()`. Either one also derives a `role`\n * and `tabIndex`, so whole-card activation is announced and keyboard-reachable.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the wrapper's markup.\n * @example\n * <Attachment.Trigger href=\"/files/quarterly-report.pdf\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">\n * \t\t<Attachment.Media><FileTextIcon aria-hidden /></Attachment.Media>\n * \t\t<Attachment.Content>\n * \t\t\t<Attachment.Title>quarterly-report.pdf</Attachment.Title>\n * \t\t</Attachment.Content>\n * \t\t<Attachment.Actions>\n * \t\t\t<Attachment.Action aria-label={t(\"attachment.download\")}><DownloadIcon /></Attachment.Action>\n * \t\t</Attachment.Actions>\n * \t</Attachment>\n * </Attachment.Trigger>\n * @example\n * <Attachment.Trigger commandfor=\"quarterly-report-preview\" mix={attachmentTrigger()}>\n * \t<Attachment state=\"done\">…</Attachment>\n * </Attachment.Trigger>\n * <Dialog id=\"quarterly-report-preview\">…</Dialog>\n */\nAttachment.Trigger = function AttachmentTrigger(handle: Handle<Attachment.TriggerProps>) {\n\treturn () => {\n\t\tlet { href, commandfor, command, target, role, tabIndex, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet isConfigured = href !== undefined || commandfor !== undefined;\n\t\tlet resolvedRole = role ?? (href !== undefined ? \"link\" : isConfigured ? \"button\" : undefined);\n\t\tlet resolvedTabIndex = tabIndex ?? (isConfigured ? 0 : undefined);\n\n\t\tif (import.meta.env?.DEV && !isConfigured) {\n\t\t\tconsole.warn(\n\t\t\t\t'Attachment.Trigger: rendered with neither \"href\" nor \"commandfor\" — nothing will happen once `attachmentTrigger()` handles an activation.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\trole={resolvedRole}\n\t\t\t\ttabIndex={resolvedTabIndex}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ href, commandfor, command, target }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tblock(),\n\t\t\t\t\trounded(\"inherit\"),\n\t\t\t\t\twhen(\"&[role]:hover\", bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&[role]:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n\n/**\n * A horizontally scroll-snapping row of cards, faded at both inline edges to\n * hint at cards beyond the current view. The row itself carries the tab stop,\n * since the row is what scrolls.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Attachment.Group aria-label={t(\"thread.attachments\")}>\n * \t{attachments.map((attachment) => (\n * \t\t<Attachment key={attachment.id} state={attachment.state}>…</Attachment>\n * \t))}\n * </Attachment.Group>\n */\nAttachment.Group = function AttachmentGroup(handle: Handle<Attachment.GroupProps>) {\n\treturn () => {\n\t\tlet { children, mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ tabIndex: DEFAULT_GROUP_TAB_INDEX }),\n\t\t\t\t\tflex(),\n\t\t\t\t\tgap(3),\n\t\t\t\t\toverflowX(\"auto\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\tscrollSnapType: \"inline mandatory\",\n\t\t\t\t\t\tscrollPaddingInline: \"0.75rem\",\n\t\t\t\t\t\tscrollBehavior: \"auto\",\n\t\t\t\t\t}),\n\t\t\t\t\twhen(\"& > *\", [shrink(0), raw({ scrollSnapAlign: \"start\" })]),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: no-preference)\", raw({ scrollBehavior: \"smooth\" })),\n\t\t\t\t\tscrollFade({ axis: \"inline\", size: GROUP_SCROLL_FADE_SIZE }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n};\n"
|
|
13
13
|
},
|
|
14
14
|
"test": null
|
|
15
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "calendar",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"heading",
|
|
6
6
|
"input"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "calendar.tsx",
|
|
13
|
-
"content": "/**\n * A month-grid calendar surface composed from a navigable header and a native\n * `<table>` of day cells, styled through the platform's own semantics. Used\n * bare, it renders a native `<input type=\"date\">` — a complete,\n * keyboard-operable date control on its own.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tborderCollapse,\n\tborderSpacing,\n\tflex,\n\tgrow,\n\tinlineBlock,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { bs, is, mbe, p, pbe } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { scaleX } from \"@sdxc/u/transform\";\nimport {\n\ttabularNums,\n\ttext,\n\ttextAlign,\n\ttextDecoration,\n\tverticalAlign,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport {\n\twarnIfNoAccessibleLabel,\n\twarnIfNoAccessibleName,\n} from \"@sdxc/ui/utils\";\n\nimport { Heading } from \"@sdxc/ui/heading\";\nimport { Input } from \"@sdxc/ui/input\";\n\nconst DEFAULT_COLOR: Calendar.Color = \"neutral\";\n\n/**\n * `type` for {@link Calendar.PreviousButton} and {@link Calendar.NextButton}\n * when a consumer supplies none, keeping a click on either control a plain\n * month change inside a surrounding `<form>`.\n */\nconst DEFAULT_NAV_BUTTON_TYPE: NonNullable<Calendar.PreviousButtonProps[\"type\"]> = \"button\";\n\n/**\n * Prop types for {@link Calendar} and its compound parts.\n */\nexport namespace Calendar {\n\t/**\n\t * Semantic color role for the bare `<input type=\"date\">` fallback's keyboard\n\t * focus ring, each mapped to its matching `--ui-*` variables. The composed\n\t * grid reads fixed semantic roles, identical across every rendered month.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Props accepted by {@link Calendar}. Composing {@link Calendar.Header} and\n\t * {@link Calendar.Grid} as `children` renders the visual month surface;\n\t * `children` left unset renders the native `<input type=\"date\">` fallback.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback control's focus ring. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback control. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a bare fallback control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a bare fallback control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the bare fallback control's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the bare fallback control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the bare fallback control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the bare fallback control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the bare fallback control, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t}\n\n\t/**\n\t * Every native `<header>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderProps extends TagProps<\"header\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_NAV_BUTTON_TYPE}. Needs an `aria-label`\n\t * (e.g. `\"Previous month\"`) as the control's only accessible name.\n\t */\n\texport interface PreviousButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix`\n\t * passthrough, mirroring {@link Calendar.PreviousButton} for the following\n\t * month instead.\n\t */\n\texport interface NextButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every prop {@link Heading} accepts, unchanged. `level` still chooses\n\t * which native heading element renders, defaulting the same way\n\t * {@link Heading} does.\n\t */\n\texport interface HeadingProps extends Heading.Props {}\n\n\t/**\n\t * Every native `<table>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridProps extends TagProps<\"table\"> {}\n\n\t/**\n\t * Every native `<thead>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridHeaderProps extends TagProps<\"thead\"> {}\n\n\t/**\n\t * Every native `<tr>` attribute, unchanged, plus the `mix` passthrough. Holds\n\t * one row of {@link Calendar.HeaderCell} in {@link Calendar.GridHeader}, or\n\t * one week of {@link Calendar.Cell} in {@link Calendar.GridBody}.\n\t */\n\texport interface RowProps extends TagProps<\"tr\"> {}\n\n\t/**\n\t * Every native `<th>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderCellProps extends TagProps<\"th\"> {}\n\n\t/**\n\t * Every native `<tbody>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridBodyProps extends TagProps<\"tbody\"> {}\n\n\t/**\n\t * Every native `<td>` attribute, unchanged, plus the `mix` passthrough. Day\n\t * state is read straight off the rendered element: the consumer sets\n\t * `aria-selected`, `aria-disabled`, `data-unavailable`, `data-outside-month`.\n\t */\n\texport interface CellProps extends TagProps<\"td\"> {}\n}\n\n/**\n * Renders a rounded, padded surface around whichever children a consumer\n * composes; `children` left unset renders a native `<input type=\"date\">`\n * through {@link Input}, the one part the platform itself operates.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the calendar's markup.\n * @example\n * <Calendar aria-label={t(\"form.startDate.label\")} name=\"startDate\" />\n * @example\n * <Calendar aria-label={t(\"calendar.label\")}>\n * \t<Calendar.Header>\n * \t\t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t\t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</Calendar.Header>\n * \t<Calendar.Grid aria-label={monthLabel}>\n * \t\t<Calendar.GridHeader>\n * \t\t\t<Calendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<Calendar.HeaderCell key={day}>{day}</Calendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</Calendar.Row>\n * \t\t</Calendar.GridHeader>\n * \t\t<Calendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<Calendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<Calendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.iso === selected ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-outside-month={day.outsideMonth ? \"\" : undefined}\n * \t\t\t\t\t\t>\n * \t\t\t\t\t\t\t{day.label}\n * \t\t\t\t\t\t</Calendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</Calendar.Row>\n * \t\t\t))}\n * \t\t</Calendar.GridBody>\n * \t</Calendar.Grid>\n * </Calendar>\n */\nexport function Calendar(handle: Handle<Calendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-label\": ariaLabel,\n\t\t\t\"aria-labelledby\": ariaLabelledBy,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\tif (import.meta.env.DEV && !children && !ariaLabel && !ariaLabelledBy) {\n\t\t\tconsole.warn(\n\t\t\t\t'Calendar: falling back to a plain \"input type=date\" needs an \"aria-label\" or \"aria-labelledby\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"calendar\"\n\t\t\t\tmix={[inlineBlock(), rounded(\"lg\"), p(3), bg(\"neutral.tint\"), mix]}\n\t\t\t>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<Input\n\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\t\taria-labelledby={ariaLabelledBy}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Calendar}'s nav row: a flex row spacing\n * {@link Calendar.PreviousButton}, {@link Calendar.Heading}, and\n * {@link Calendar.NextButton} apart, the heading centered between the controls.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the nav row's markup.\n * @example\n * <Calendar.Header>\n * \t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * </Calendar.Header>\n */\nCalendar.Header = function CalendarHeader(handle: Handle<Calendar.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<header\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header\"\n\t\t\t\tmix={[flex(), items(\"center\"), justify(\"between\"), mbe(4), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the previous month\", sized\n * to match {@link Calendar.NextButton}. Its default chevron flips under\n * `dir=\"rtl\"` through CSS. A `calendarKeys()` mixin drives the behavior.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nCalendar.PreviousButton = function CalendarPreviousButton(\n\thandle: Handle<Calendar.PreviousButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.PreviousButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"previous-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronLeftIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the following month\", with\n * the rendering, focus, and disabled-state contract of\n * {@link Calendar.PreviousButton} and a trailing chevron by default.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nCalendar.NextButton = function CalendarNextButton(handle: Handle<Calendar.NextButtonProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.NextButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"next-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronRightIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders the consumer-formatted month/year caption through {@link Heading},\n * centered between the nav controls at a small semibold size layered after\n * {@link Heading}'s own defaults, so this size and alignment win over them.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the caption's markup.\n * @example\n * <Calendar.Heading>{new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\" }).format(visibleMonth)}</Calendar.Heading>\n */\nCalendar.Heading = function CalendarHeading(handle: Handle<Calendar.HeadingProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Heading\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"heading\"\n\t\t\t\tmix={[\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the day grid's native `<table>` host, rows and cells set apart by a\n * small gap on every side. Its `aria-label`/`aria-labelledby` — typically the\n * visible month label — names the whole grid; dev mode warns when it is absent.\n *\n * @param handle Runtime handle carrying the host `<table>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <Calendar.Grid aria-label={monthLabel}>\n * \t<Calendar.GridHeader>...</Calendar.GridHeader>\n * \t<Calendar.GridBody>...</Calendar.GridBody>\n * </Calendar.Grid>\n */\nCalendar.Grid = function CalendarGrid(handle: Handle<Calendar.GridProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Calendar.Grid: needs an \"aria-label\" or \"aria-labelledby\" identifying which month it shows for assistive technology.',\n\t\t);\n\n\t\treturn (\n\t\t\t<table\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"grid\"\n\t\t\t\tmix={[borderCollapse(\"separate\"), borderSpacing(\"0.25rem\"), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<thead>` host: a plain wrapper for the weekday\n * {@link Calendar.Row}.\n *\n * @param handle Runtime handle carrying the host `<thead>`'s props.\n * @returns The render function producing the header section's markup.\n * @example\n * <Calendar.GridHeader>\n * \t<Calendar.Row>\n * \t\t<Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n * \t</Calendar.Row>\n * </Calendar.GridHeader>\n */\nCalendar.GridHeader = function CalendarGridHeader(handle: Handle<Calendar.GridHeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <thead {...rest} data-slot=\"grid-header\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a native `<tr>` host: one row of {@link Calendar.HeaderCell} inside\n * {@link Calendar.GridHeader}, or one week of {@link Calendar.Cell} inside\n * {@link Calendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Calendar.Row>\n * \t<Calendar.Cell>{day.label}</Calendar.Cell>\n * </Calendar.Row>\n */\nCalendar.Row = function CalendarRow(handle: Handle<Calendar.RowProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tr {...rest} data-slot=\"row\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a weekday abbreviation inside a native `<th scope=\"col\">`, sized\n * small and muted beneath {@link Calendar.Cell}'s own larger day numbers.\n *\n * @param handle Runtime handle carrying the host `<th>`'s props.\n * @returns The render function producing the weekday header's markup.\n * @example\n * <Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n */\nCalendar.HeaderCell = function CalendarHeaderCell(handle: Handle<Calendar.HeaderCellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<th\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header-cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ scope: \"col\" }),\n\t\t\t\t\tpbe(2),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<tbody>` host: a plain wrapper for one\n * {@link Calendar.Row} per week.\n *\n * @param handle Runtime handle carrying the host `<tbody>`'s props.\n * @returns The render function producing the body section's markup.\n * @example\n * <Calendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<Calendar.Row key={week[0].iso}>...</Calendar.Row>\n * \t))}\n * </Calendar.GridBody>\n */\nCalendar.GridBody = function CalendarGridBody(handle: Handle<Calendar.GridBodyProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tbody {...rest} data-slot=\"grid-body\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders one calendar day inside a native `<td>`, a fixed round pill around\n * its number. `aria-selected`, `aria-disabled`, `data-unavailable`,\n * `data-outside-month`, and `aria-invalid` each drive their own visual state.\n *\n * @param handle Runtime handle carrying the host `<td>`'s props.\n * @returns The render function producing the day's markup.\n * @example\n * <Calendar.Cell aria-selected={day.iso === selected ? \"true\" : undefined}>\n * \t{day.label}\n * </Calendar.Cell>\n * @example\n * <Calendar.Cell data-outside-month=\"\">{day.label}</Calendar.Cell>\n */\nCalendar.Cell = function CalendarCell(handle: Handle<Calendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<td\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t/**\n\t\t\t\t\t * Table alignment centres the day while the cell stays a table cell in its row; a row\n\t\t\t\t\t * laid out as a flex box turns its cells into blocks, where `align-content` centres the\n\t\t\t\t\t * day. Each declaration answers one of the two cases.\n\t\t\t\t\t */\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tverticalAlign(\"middle\"),\n\t\t\t\t\traw({ alignContent: \"center\" }),\n\t\t\t\t\tis(9),\n\t\t\t\t\tbs(9),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.solid\"), fg(\"brand.onSolid\")]),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [cursor(\"not-allowed\"), opacity(30)]),\n\t\t\t\t\twhen(\"&[data-unavailable]\", [fg(\"neutral.muted\"), textDecoration(\"line-through\")]),\n\t\t\t\t\twhen(\"&[data-outside-month]\", fg(\"neutral.muted\")),\n\t\t\t\t\twhen('&[aria-invalid=\"true\"]', [bg(\"danger.solid\"), fg(\"danger.onSolid\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
"content": "/**\n * A month-grid calendar surface composed from a navigable header and a native\n * `<table>` of day cells, styled through the platform's own semantics. Used\n * bare, it renders a native `<input type=\"date\">` — a complete,\n * keyboard-operable date control on its own.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport {\n\tbasis,\n\tborderCollapse,\n\tborderSpacing,\n\tflex,\n\tgrow,\n\tinlineBlock,\n\titems,\n\tjustify,\n\trelative,\n\tshrink,\n} from \"@sdxc/u/layout\";\nimport { bs, is, mbe, p, pbe } from \"@sdxc/u/size\";\nimport { hover, when } from \"@sdxc/u/state\";\nimport { scaleX } from \"@sdxc/u/transform\";\nimport {\n\ttabularNums,\n\ttext,\n\ttextAlign,\n\ttextDecoration,\n\tverticalAlign,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { hitArea } from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport {\n\twarnIfNoAccessibleLabel,\n\twarnIfNoAccessibleName,\n} from \"@sdxc/ui/utils\";\n\nimport { Heading } from \"@sdxc/ui/heading\";\nimport { Input } from \"@sdxc/ui/input\";\n\nconst DEFAULT_COLOR: Calendar.Color = \"neutral\";\n\n/**\n * `type` for {@link Calendar.PreviousButton} and {@link Calendar.NextButton}\n * when a consumer supplies none, keeping a click on either control a plain\n * month change inside a surrounding `<form>`.\n */\nconst DEFAULT_NAV_BUTTON_TYPE: NonNullable<Calendar.PreviousButtonProps[\"type\"]> = \"button\";\n\n/**\n * Prop types for {@link Calendar} and its compound parts.\n */\nexport namespace Calendar {\n\t/**\n\t * Semantic color role for the bare `<input type=\"date\">` fallback's keyboard\n\t * focus ring, each mapped to its matching `--ui-*` variables. The composed\n\t * grid reads fixed semantic roles, identical across every rendered month.\n\t */\n\texport type Color = \"brand\" | \"neutral\" | \"success\" | \"warning\" | \"danger\";\n\n\t/**\n\t * Props accepted by {@link Calendar}. Composing {@link Calendar.Header} and\n\t * {@link Calendar.Grid} as `children` renders the visual month surface;\n\t * `children` left unset renders the native `<input type=\"date\">` fallback.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback control's focus ring. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback control. */\n\t\tname?: string;\n\t\t/** Current value, in `YYYY-MM-DD` form, for a bare fallback control a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, in `YYYY-MM-DD` form, for a bare fallback control left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read only by the bare fallback control. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, the bare fallback control's value must fall on. */\n\t\tstep?: number;\n\t\t/** Marks the bare fallback control required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the bare fallback control inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the bare fallback control's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the bare fallback control, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t}\n\n\t/**\n\t * Every native `<header>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderProps extends TagProps<\"header\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix` passthrough.\n\t * `type` defaults to {@link DEFAULT_NAV_BUTTON_TYPE}. Needs an `aria-label`\n\t * (e.g. `\"Previous month\"`) as the control's only accessible name.\n\t */\n\texport interface PreviousButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix`\n\t * passthrough, mirroring {@link Calendar.PreviousButton} for the following\n\t * month instead.\n\t */\n\texport interface NextButtonProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every prop {@link Heading} accepts, unchanged. `level` still chooses\n\t * which native heading element renders, defaulting the same way\n\t * {@link Heading} does.\n\t */\n\texport interface HeadingProps extends Heading.Props {}\n\n\t/**\n\t * Every native `<table>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridProps extends TagProps<\"table\"> {}\n\n\t/**\n\t * Every native `<thead>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridHeaderProps extends TagProps<\"thead\"> {}\n\n\t/**\n\t * Every native `<tr>` attribute, unchanged, plus the `mix` passthrough. Holds\n\t * one row of {@link Calendar.HeaderCell} in {@link Calendar.GridHeader}, or\n\t * one week of {@link Calendar.Cell} in {@link Calendar.GridBody}.\n\t */\n\texport interface RowProps extends TagProps<\"tr\"> {}\n\n\t/**\n\t * Every native `<th>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface HeaderCellProps extends TagProps<\"th\"> {}\n\n\t/**\n\t * Every native `<tbody>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface GridBodyProps extends TagProps<\"tbody\"> {}\n\n\t/**\n\t * Every native `<td>` attribute, unchanged, plus the `mix` passthrough. Day\n\t * state is read straight off the rendered element: the consumer sets\n\t * `aria-selected`, `aria-disabled`, `data-unavailable`, `data-outside-month`.\n\t */\n\texport interface CellProps extends TagProps<\"td\"> {}\n}\n\n/**\n * Renders a rounded, padded surface around whichever children a consumer\n * composes; `children` left unset renders a native `<input type=\"date\">`\n * through {@link Input}, the one part the platform itself operates.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the calendar's markup.\n * @example\n * <Calendar aria-label={t(\"form.startDate.label\")} name=\"startDate\" />\n * @example\n * <Calendar aria-label={t(\"calendar.label\")}>\n * \t<Calendar.Header>\n * \t\t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t\t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</Calendar.Header>\n * \t<Calendar.Grid aria-label={monthLabel}>\n * \t\t<Calendar.GridHeader>\n * \t\t\t<Calendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<Calendar.HeaderCell key={day}>{day}</Calendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</Calendar.Row>\n * \t\t</Calendar.GridHeader>\n * \t\t<Calendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<Calendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<Calendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.iso === selected ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-outside-month={day.outsideMonth ? \"\" : undefined}\n * \t\t\t\t\t\t>\n * \t\t\t\t\t\t\t{day.label}\n * \t\t\t\t\t\t</Calendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</Calendar.Row>\n * \t\t\t))}\n * \t\t</Calendar.GridBody>\n * \t</Calendar.Grid>\n * </Calendar>\n */\nexport function Calendar(handle: Handle<Calendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\t\"aria-label\": ariaLabel,\n\t\t\t\"aria-labelledby\": ariaLabelledBy,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\tif (import.meta.env?.DEV && !children && !ariaLabel && !ariaLabelledBy) {\n\t\t\tconsole.warn(\n\t\t\t\t'Calendar: falling back to a plain \"input type=date\" needs an \"aria-label\" or \"aria-labelledby\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"calendar\"\n\t\t\t\tmix={[inlineBlock(), rounded(\"lg\"), p(3), bg(\"neutral.tint\"), mix]}\n\t\t\t>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<Input\n\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\tname={name}\n\t\t\t\t\t\tvalue={value}\n\t\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\taria-label={ariaLabel}\n\t\t\t\t\t\taria-labelledby={ariaLabelledBy}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link Calendar}'s nav row: a flex row spacing\n * {@link Calendar.PreviousButton}, {@link Calendar.Heading}, and\n * {@link Calendar.NextButton} apart, the heading centered between the controls.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the nav row's markup.\n * @example\n * <Calendar.Header>\n * \t<Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<Calendar.Heading>{monthLabel}</Calendar.Heading>\n * \t<Calendar.NextButton aria-label={t(\"calendar.next\")} />\n * </Calendar.Header>\n */\nCalendar.Header = function CalendarHeader(handle: Handle<Calendar.HeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<header\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header\"\n\t\t\t\tmix={[flex(), items(\"center\"), justify(\"between\"), mbe(4), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the previous month\", sized\n * to match {@link Calendar.NextButton}. Its default chevron flips under\n * `dir=\"rtl\"` through CSS. A `calendarKeys()` mixin drives the behavior.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nCalendar.PreviousButton = function CalendarPreviousButton(\n\thandle: Handle<Calendar.PreviousButtonProps>,\n) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.PreviousButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"previous-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronLeftIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders a round icon control standing for \"show the following month\", with\n * the rendering, focus, and disabled-state contract of\n * {@link Calendar.PreviousButton} and a trailing chevron by default.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <Calendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nCalendar.NextButton = function CalendarNextButton(handle: Handle<Calendar.NextButtonProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Calendar.NextButton: an icon-only control needs an \"aria-label\" describing what it does — assistive technology has no accessible text to announce otherwise.',\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={type ?? DEFAULT_NAV_BUTTON_TYPE}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"next-button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\trelative(),\n\t\t\t\t\tis(8),\n\t\t\t\t\tbs(8),\n\t\t\t\t\thitArea(),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\twhen(\"& svg\", [is(4), bs(4)]),\n\t\t\t\t\twhen(\"&:dir(rtl) svg\", scaleX(-1)),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children ?? <ChevronRightIcon />}\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders the consumer-formatted month/year caption through {@link Heading},\n * centered between the nav controls at a small semibold size layered after\n * {@link Heading}'s own defaults, so this size and alignment win over them.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the caption's markup.\n * @example\n * <Calendar.Heading>{new Intl.DateTimeFormat(locale, { month: \"long\", year: \"numeric\" }).format(visibleMonth)}</Calendar.Heading>\n */\nCalendar.Heading = function CalendarHeading(handle: Handle<Calendar.HeadingProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Heading\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"heading\"\n\t\t\t\tmix={[\n\t\t\t\t\tgrow(),\n\t\t\t\t\tshrink(1),\n\t\t\t\t\tbasis(\"0%\"),\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the day grid's native `<table>` host, rows and cells set apart by a\n * small gap on every side. Its `aria-label`/`aria-labelledby` — typically the\n * visible month label — names the whole grid; dev mode warns when it is absent.\n *\n * @param handle Runtime handle carrying the host `<table>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <Calendar.Grid aria-label={monthLabel}>\n * \t<Calendar.GridHeader>...</Calendar.GridHeader>\n * \t<Calendar.GridBody>...</Calendar.GridBody>\n * </Calendar.Grid>\n */\nCalendar.Grid = function CalendarGrid(handle: Handle<Calendar.GridProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Calendar.Grid: needs an \"aria-label\" or \"aria-labelledby\" identifying which month it shows for assistive technology.',\n\t\t);\n\n\t\treturn (\n\t\t\t<table\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"grid\"\n\t\t\t\tmix={[borderCollapse(\"separate\"), borderSpacing(\"0.25rem\"), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<thead>` host: a plain wrapper for the weekday\n * {@link Calendar.Row}.\n *\n * @param handle Runtime handle carrying the host `<thead>`'s props.\n * @returns The render function producing the header section's markup.\n * @example\n * <Calendar.GridHeader>\n * \t<Calendar.Row>\n * \t\t<Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n * \t</Calendar.Row>\n * </Calendar.GridHeader>\n */\nCalendar.GridHeader = function CalendarGridHeader(handle: Handle<Calendar.GridHeaderProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <thead {...rest} data-slot=\"grid-header\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a native `<tr>` host: one row of {@link Calendar.HeaderCell} inside\n * {@link Calendar.GridHeader}, or one week of {@link Calendar.Cell} inside\n * {@link Calendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <Calendar.Row>\n * \t<Calendar.Cell>{day.label}</Calendar.Cell>\n * </Calendar.Row>\n */\nCalendar.Row = function CalendarRow(handle: Handle<Calendar.RowProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tr {...rest} data-slot=\"row\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders a weekday abbreviation inside a native `<th scope=\"col\">`, sized\n * small and muted beneath {@link Calendar.Cell}'s own larger day numbers.\n *\n * @param handle Runtime handle carrying the host `<th>`'s props.\n * @returns The render function producing the weekday header's markup.\n * @example\n * <Calendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</Calendar.HeaderCell>\n */\nCalendar.HeaderCell = function CalendarHeaderCell(handle: Handle<Calendar.HeaderCellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<th\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"header-cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ scope: \"col\" }),\n\t\t\t\t\tpbe(2),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral.muted\"),\n\t\t\t\t\ttext(\"xs\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders the grid's `<tbody>` host: a plain wrapper for one\n * {@link Calendar.Row} per week.\n *\n * @param handle Runtime handle carrying the host `<tbody>`'s props.\n * @returns The render function producing the body section's markup.\n * @example\n * <Calendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<Calendar.Row key={week[0].iso}>...</Calendar.Row>\n * \t))}\n * </Calendar.GridBody>\n */\nCalendar.GridBody = function CalendarGridBody(handle: Handle<Calendar.GridBodyProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <tbody {...rest} data-slot=\"grid-body\" mix={[mix]} />;\n\t};\n};\n\n/**\n * Renders one calendar day inside a native `<td>`, a fixed round pill around\n * its number. `aria-selected`, `aria-disabled`, `data-unavailable`,\n * `data-outside-month`, and `aria-invalid` each drive their own visual state.\n *\n * @param handle Runtime handle carrying the host `<td>`'s props.\n * @returns The render function producing the day's markup.\n * @example\n * <Calendar.Cell aria-selected={day.iso === selected ? \"true\" : undefined}>\n * \t{day.label}\n * </Calendar.Cell>\n * @example\n * <Calendar.Cell data-outside-month=\"\">{day.label}</Calendar.Cell>\n */\nCalendar.Cell = function CalendarCell(handle: Handle<Calendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<td\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"cell\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t/**\n\t\t\t\t\t * Table alignment centres the day while the cell stays a table cell in its row; a row\n\t\t\t\t\t * laid out as a flex box turns its cells into blocks, where `align-content` centres the\n\t\t\t\t\t * day. Each declaration answers one of the two cases.\n\t\t\t\t\t */\n\t\t\t\t\ttextAlign(\"center\"),\n\t\t\t\t\tverticalAlign(\"middle\"),\n\t\t\t\t\traw({ alignContent: \"center\" }),\n\t\t\t\t\tis(9),\n\t\t\t\t\tbs(9),\n\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\thover(bg(\"neutral.bg-tint-hover\")),\n\t\t\t\t\twhen('&[aria-selected=\"true\"]', [bg(\"brand.solid\"), fg(\"brand.onSolid\")]),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [cursor(\"not-allowed\"), opacity(30)]),\n\t\t\t\t\twhen(\"&[data-unavailable]\", [fg(\"neutral.muted\"), textDecoration(\"line-through\")]),\n\t\t\t\t\twhen(\"&[data-outside-month]\", fg(\"neutral.muted\")),\n\t\t\t\t\twhen('&[aria-invalid=\"true\"]', [bg(\"danger.solid\"), fg(\"danger.onSolid\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
14
14
|
},
|
|
15
15
|
"test": null
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "color-picker",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.20",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"color-field",
|
|
6
6
|
"color-swatch",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"source": {
|
|
13
13
|
"path": "color-picker.tsx",
|
|
14
|
-
"content": "/**\n * A labeled color field composing {@link ColorField}'s plain fallback with\n * an optional {@link ColorPicker.Group} trigger row and\n * {@link ColorPicker.Dialog} picking surface swapped in via `children`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { outline } from \"@sdxc/u/color\";\nimport { opacity, rounded, transition } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { hstack, inlineFlex, items, justify, relative, shrink, vstack } from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { ColorField } from \"@sdxc/ui/color-field\";\nimport { ColorSwatch } from \"@sdxc/ui/color-swatch\";\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Native `<button>` `type` {@link ColorPicker.Trigger} falls back to,\n * keeping an omitted `type` from implicitly submitting an enclosing\n * `<form>` the way a bare `<button>` would.\n */\nconst DEFAULT_BUTTON_TYPE: NonNullable<ColorPicker.TriggerProps[\"type\"]> = \"button\";\n\n/**\n * Shape variant {@link ColorPicker.Trigger} falls back to when `shape` is\n * omitted, mirroring {@link ColorSwatch}'s own default so a trigger left\n * unstyled reads the same as a bare swatch.\n */\nconst DEFAULT_TRIGGER_SHAPE: ColorSwatch.Shape = \"rounded\";\n\n/**\n * `role` applied to {@link ColorPicker.Dialog}'s host through {@link attrs}\n * unless a consumer supplies its own `role`, identifying the surface as a\n * non-modal dialog layered above the page rather than a full-screen modal.\n */\nconst DEFAULT_DIALOG_ROLE = \"dialog\";\n\n/**\n * Side of the trigger {@link ColorPicker.Dialog} renders against when\n * `placement` is left unset, reading down and start-ward the way a dropdown\n * conventionally does.\n */\nconst DEFAULT_DIALOG_PLACEMENT: Popover.Placement = \"bottom-start\";\n\n/**\n * Prop types for {@link ColorPicker} and its compound parts.\n */\nexport namespace ColorPicker {\n\t/**\n\t * Semantic color role for the fallback field's keyboard focus ring,\n\t * mirroring {@link ColorField.Color}. The composed layout carries no\n\t * `color` prop of its own, since a consumer renders it directly.\n\t */\n\texport type Color = ColorField.Color;\n\n\t/**\n\t * Every prop {@link ColorField.PartsProps} accepts, unchanged, applied\n\t * only to the fallback field's internally composed parts — the composed\n\t * layout styles its own parts individually instead.\n\t */\n\texport interface PartsProps extends ColorField.PartsProps {}\n\n\t/**\n\t * Props accepted by {@link ColorPicker}. Leaving `children` unset renders\n\t * {@link ColorField}'s plain fallback using every field below; composing\n\t * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} instead skips them.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback field's focus ring. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The fallback field's caption, rendered through {@link ColorField}. Read only when `children` is unset. */\n\t\tlabel?: RemixNode;\n\t\t/** Supporting copy beneath the fallback field. Read only when `children` is unset. */\n\t\tdescription?: RemixNode;\n\t\t/** Validation message beneath the fallback field. Read only when `children` is unset. */\n\t\terrorMessage?: RemixNode;\n\t\t/** Notation the fallback field's typed entry is constrained to. Read only when `children` is unset. */\n\t\tformat?: ColorField.Format;\n\t\t/** Native `name` submitted with an enclosing form, read only by the fallback field. */\n\t\tname?: string;\n\t\t/** Current value, as a literal color string, for a fallback field a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, as a literal color string, for a fallback field left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Placeholder copy shown while the fallback field is empty. */\n\t\tplaceholder?: string;\n\t\t/** Marks the fallback field required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the fallback field inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the fallback field's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the fallback field. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback field's internally composed parts. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The trigger-and-panel layout — typically a `Label`,\n\t\t * {@link ColorPicker.Group}, and {@link ColorPicker.Dialog} — rendered in\n\t\t * place of {@link ColorField}'s plain fallback. Unset renders that fallback.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control and\n\t * {@link ColorPicker.Trigger} into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, fixed to this\n\t * button's own {@link ColorSwatch}. Point `commandfor` at\n\t * {@link ColorPicker.Dialog}'s `id` with `command=\"toggle-popover\"` to wire it up.\n\t */\n\texport interface TriggerProps extends Omit<TagProps<\"button\">, \"children\"> {\n\t\t/**\n\t\t * The color this trigger previews, already resolved to a literal CSS\n\t\t * color value — the same value its inner {@link ColorSwatch} paints.\n\t\t * Required, since a trigger with nothing to preview has no reason to render.\n\t\t */\n\t\tvalue: string;\n\t\t/** Shape variant for the inner {@link ColorSwatch}, mirrored onto the button host so its own corners match. Defaults to {@link DEFAULT_TRIGGER_SHAPE}. */\n\t\tshape?: ColorSwatch.Shape;\n\t}\n\n\t/**\n\t * Every prop {@link Popover.Props} accepts, since {@link ColorPicker.Dialog}\n\t * renders one directly as its host. `placement` defaults to\n\t * {@link DEFAULT_DIALOG_PLACEMENT}.\n\t */\n\texport interface DialogProps extends Popover.Props {}\n}\n\n/**\n * Renders {@link ColorPicker}'s root: {@link ColorField}'s plain fallback\n * when `children` is unset, or the trigger-and-panel layout composed from\n * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} otherwise.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the color picker's markup.\n * @example\n * <ColorPicker label={t(\"form.accentColor.label\")} name=\"accentColor\" defaultValue=\"#3b82f6\" />\n * @example\n * <ColorPicker>\n * \t<Label htmlFor=\"brandColor\">{t(\"form.brandColor.label\")}</Label>\n * \t<ColorPicker.Group>\n * \t\t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t\t<ColorPicker.Trigger\n * \t\t\tcommandfor=\"brandColor-panel\"\n * \t\t\tcommand=\"toggle-popover\"\n * \t\t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\t\tvalue=\"#3b82f6\"\n * \t\t/>\n * \t</ColorPicker.Group>\n * \t<ColorPicker.Dialog id=\"brandColor-panel\">\n * \t\t{...the picking surface — see ColorPicker.Dialog's own doc comment}\n * \t</ColorPicker.Dialog>\n * </ColorPicker>\n */\nexport function ColorPicker(handle: Handle<ColorPicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage,\n\t\t\tformat,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tplaceholder,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env.DEV && !children && !label) {\n\t\t\tconsole.warn(\n\t\t\t\t'ColorPicker: falling back to ColorField\\'s plain color-notation field needs a \"label\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<ColorField\n\t\t\t\t\t{...rest}\n\t\t\t\t\tcolor={color}\n\t\t\t\t\tlabel={label}\n\t\t\t\t\tdescription={description}\n\t\t\t\t\terrorMessage={errorMessage}\n\t\t\t\t\tformat={format}\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tparts={parts}\n\t\t\t\t\tmix={mix}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"color-picker\" mix={[vstack({ gap: 1 }), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link ColorPicker}'s control row: a plain flex host laying the\n * field's own control and {@link ColorPicker.Trigger} side by side, with a\n * keyboard focus ring on the whole row the moment focus lands anywhere inside.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <ColorPicker.Group>\n * \t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t<ColorPicker.Trigger\n * \t\tcommandfor=\"brandColor-panel\"\n * \t\tcommand=\"toggle-popover\"\n * \t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\tvalue=\"#3b82f6\"\n * \t/>\n * </ColorPicker.Group>\n */\nColorPicker.Group = function ColorPickerGroup(handle: Handle<ColorPicker.GroupProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * Focus is shown by the control that holds it, the way `Group` shows it: a ring\n\t\t\t\t\t * around the row says the group is focused without saying whether the field or\n\t\t\t\t\t * the preview has it, and it stacks with the ring that control draws for itself.\n\t\t\t\t\t */\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link ColorPicker}'s trailing trigger: a `<button>` housing a\n * {@link ColorSwatch} that fills it as a live preview, wired via\n * `commandfor`/`command=\"toggle-popover\"` to {@link ColorPicker.Dialog}'s `id`.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <ColorPicker.Trigger\n * \tcommandfor=\"brandColor-panel\"\n * \tcommand=\"toggle-popover\"\n * \taria-label={t(\"form.brandColor.toggle\")}\n * \tvalue=\"#3b82f6\"\n * />\n */\nColorPicker.Trigger = function ColorPickerTrigger(handle: Handle<ColorPicker.TriggerProps>) {\n\treturn () => {\n\t\tlet { type, value, shape, mix, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_BUTTON_TYPE;\n\t\tlet resolvedShape = shape ?? DEFAULT_TRIGGER_SHAPE;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t\"ColorPicker.Trigger: this button needs an `aria-label` describing what it does — its content is a color preview with no accessible name of its own.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tdata-shape={resolvedShape}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tis(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\tbs(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\ttransition(\"box-shadow\"),\n\t\t\t\t\twhen('&[data-shape=\"circle\"]', rounded(\"full\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\tp(0),\n\t\t\t\t\tshrink(),\n\t\t\t\t\twhen('&[data-shape=\"square\"]', rounded(\"none\")),\n\t\t\t\t\t/**\n\t\t\t\t\t * The swatch grows through the size variable it reads itself: a size passed down as\n\t\t\t\t\t * `mix` compiles into its own cascade layer, which can land before the swatch's own\n\t\t\t\t\t * and leave the preview at its default size in a corner of the button.\n\t\t\t\t\t */\n\t\t\t\t\traw({ \"--ui-color-swatch-size-md\": \"100%\" }),\n\t\t\t\t\t/**\n\t\t\t\t\t * Hover steps the preview's edge one shade darker, so the edge the swatch already\n\t\t\t\t\t * draws stays the only one and the border reads once.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:hover\", raw({ boxShadow: \"0 0 0 1px var(--ui-neutral-border-hover)\" })),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", raw({ transitionDuration: \"0s\" })),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<ColorSwatch value={value} shape={resolvedShape} />\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link ColorPicker}'s picking surface: a Popover, defaulting\n * `placement` to bottom-start and `role` to `\"dialog\"`, padding whatever\n * picking controls a consumer composes as `children` in a single column.\n *\n * @param handle Runtime handle carrying the host's `Popover` props.\n * @returns The render function producing the surface's markup.\n * @example\n * <ColorPicker.Dialog id=\"brandColor-panel\">\n * \t<ColorArea aria-label={t(\"colorPicker.area\")} hue={hue} defaultSaturation={saturation} defaultValue={brightness} mix={colorAreaDrag()}>\n * \t\t<ColorArea.SaturationThumb data-color-area-axis=\"x\" aria-label={t(\"colorPicker.saturation\")} />\n * \t\t<ColorArea.ValueThumb data-color-area-axis=\"y\" aria-label={t(\"colorPicker.brightness\")} />\n * \t</ColorArea>\n * \t<ColorWheel aria-label={t(\"colorPicker.hue\")} defaultValue={hue} mix={colorWheelDrag()} />\n * \t<ColorSlider channel=\"alpha\" defaultValue={alpha}>\n * \t\t<ColorSlider.Track hue={hue}>\n * \t\t\t<ColorSlider.Thumb aria-label={t(\"colorPicker.alpha\")} />\n * \t\t</ColorSlider.Track>\n * \t</ColorSlider>\n * \t<ColorField label={t(\"colorPicker.hex\")} format=\"hex\" defaultValue=\"#3b82f6\" mix={colorPreview()} />\n * \t<ColorSwatchPicker aria-label={t(\"colorPicker.presets\")}>\n * \t\t<ColorSwatchPicker.Swatch value=\"#ef4444\" aria-label={t(\"color.red\")} />\n * \t\t<ColorSwatchPicker.Swatch value=\"#3b82f6\" aria-label={t(\"color.blue\")} defaultChecked />\n * \t</ColorSwatchPicker>\n * </ColorPicker.Dialog>\n */\nColorPicker.Dialog = function ColorPickerDialog(handle: Handle<ColorPicker.DialogProps>) {\n\treturn () => {\n\t\tlet { placement, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_DIALOG_PLACEMENT;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\t{...rest}\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_DIALOG_ROLE }),\n\t\t\t\t\tvstack({ gap: 4 }),\n\t\t\t\t\tp(4),\n\t\t\t\t\traw({ outline: \"none\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</Popover>\n\t\t);\n\t};\n};\n"
|
|
14
|
+
"content": "/**\n * A labeled color field composing {@link ColorField}'s plain fallback with\n * an optional {@link ColorPicker.Group} trigger row and\n * {@link ColorPicker.Dialog} picking surface swapped in via `children`.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { outline } from \"@sdxc/u/color\";\nimport { opacity, rounded, transition } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { hstack, inlineFlex, items, justify, relative, shrink, vstack } from \"@sdxc/u/layout\";\nimport { media } from \"@sdxc/u/responsive\";\nimport { bs, is, p } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { warnIfNoAccessibleLabel } from \"@sdxc/ui/utils\";\n\nimport { ColorField } from \"@sdxc/ui/color-field\";\nimport { ColorSwatch } from \"@sdxc/ui/color-swatch\";\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Native `<button>` `type` {@link ColorPicker.Trigger} falls back to,\n * keeping an omitted `type` from implicitly submitting an enclosing\n * `<form>` the way a bare `<button>` would.\n */\nconst DEFAULT_BUTTON_TYPE: NonNullable<ColorPicker.TriggerProps[\"type\"]> = \"button\";\n\n/**\n * Shape variant {@link ColorPicker.Trigger} falls back to when `shape` is\n * omitted, mirroring {@link ColorSwatch}'s own default so a trigger left\n * unstyled reads the same as a bare swatch.\n */\nconst DEFAULT_TRIGGER_SHAPE: ColorSwatch.Shape = \"rounded\";\n\n/**\n * `role` applied to {@link ColorPicker.Dialog}'s host through {@link attrs}\n * unless a consumer supplies its own `role`, identifying the surface as a\n * non-modal dialog layered above the page rather than a full-screen modal.\n */\nconst DEFAULT_DIALOG_ROLE = \"dialog\";\n\n/**\n * Side of the trigger {@link ColorPicker.Dialog} renders against when\n * `placement` is left unset, reading down and start-ward the way a dropdown\n * conventionally does.\n */\nconst DEFAULT_DIALOG_PLACEMENT: Popover.Placement = \"bottom-start\";\n\n/**\n * Prop types for {@link ColorPicker} and its compound parts.\n */\nexport namespace ColorPicker {\n\t/**\n\t * Semantic color role for the fallback field's keyboard focus ring,\n\t * mirroring {@link ColorField.Color}. The composed layout carries no\n\t * `color` prop of its own, since a consumer renders it directly.\n\t */\n\texport type Color = ColorField.Color;\n\n\t/**\n\t * Every prop {@link ColorField.PartsProps} accepts, unchanged, applied\n\t * only to the fallback field's internally composed parts — the composed\n\t * layout styles its own parts individually instead.\n\t */\n\texport interface PartsProps extends ColorField.PartsProps {}\n\n\t/**\n\t * Props accepted by {@link ColorPicker}. Leaving `children` unset renders\n\t * {@link ColorField}'s plain fallback using every field below; composing\n\t * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} instead skips them.\n\t */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** Semantic color role for the fallback field's focus ring. Read only when `children` is unset. */\n\t\tcolor?: Color;\n\t\t/** The fallback field's caption, rendered through {@link ColorField}. Read only when `children` is unset. */\n\t\tlabel?: RemixNode;\n\t\t/** Supporting copy beneath the fallback field. Read only when `children` is unset. */\n\t\tdescription?: RemixNode;\n\t\t/** Validation message beneath the fallback field. Read only when `children` is unset. */\n\t\terrorMessage?: RemixNode;\n\t\t/** Notation the fallback field's typed entry is constrained to. Read only when `children` is unset. */\n\t\tformat?: ColorField.Format;\n\t\t/** Native `name` submitted with an enclosing form, read only by the fallback field. */\n\t\tname?: string;\n\t\t/** Current value, as a literal color string, for a fallback field a consumer tracks itself. */\n\t\tvalue?: string;\n\t\t/** Initial value, as a literal color string, for a fallback field left to the platform's own uncontrolled state. */\n\t\tdefaultValue?: string;\n\t\t/** Placeholder copy shown while the fallback field is empty. */\n\t\tplaceholder?: string;\n\t\t/** Marks the fallback field required for its enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks the fallback field inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the fallback field's value fixed, while keeping it focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for the fallback field. */\n\t\tautoComplete?: string;\n\t\t/** Per-part styling for the fallback field's internally composed parts. Read only when `children` is unset. */\n\t\tparts?: PartsProps;\n\t\t/**\n\t\t * The trigger-and-panel layout — typically a `Label`,\n\t\t * {@link ColorPicker.Group}, and {@link ColorPicker.Dialog} — rendered in\n\t\t * place of {@link ColorField}'s plain fallback. Unset renders that fallback.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, unchanged, plus the `mix` passthrough.\n\t * `children` composes the field's own control and\n\t * {@link ColorPicker.Trigger} into one visual row.\n\t */\n\texport interface GroupProps extends TagProps<\"div\"> {}\n\n\t/**\n\t * Every native `<button>` attribute except `children`, fixed to this\n\t * button's own {@link ColorSwatch}. Point `commandfor` at\n\t * {@link ColorPicker.Dialog}'s `id` with `command=\"toggle-popover\"` to wire it up.\n\t */\n\texport interface TriggerProps extends Omit<TagProps<\"button\">, \"children\"> {\n\t\t/**\n\t\t * The color this trigger previews, already resolved to a literal CSS\n\t\t * color value — the same value its inner {@link ColorSwatch} paints.\n\t\t * Required, since a trigger with nothing to preview has no reason to render.\n\t\t */\n\t\tvalue: string;\n\t\t/** Shape variant for the inner {@link ColorSwatch}, mirrored onto the button host so its own corners match. Defaults to {@link DEFAULT_TRIGGER_SHAPE}. */\n\t\tshape?: ColorSwatch.Shape;\n\t}\n\n\t/**\n\t * Every prop {@link Popover.Props} accepts, since {@link ColorPicker.Dialog}\n\t * renders one directly as its host. `placement` defaults to\n\t * {@link DEFAULT_DIALOG_PLACEMENT}.\n\t */\n\texport interface DialogProps extends Popover.Props {}\n}\n\n/**\n * Renders {@link ColorPicker}'s root: {@link ColorField}'s plain fallback\n * when `children` is unset, or the trigger-and-panel layout composed from\n * {@link ColorPicker.Group} and {@link ColorPicker.Dialog} otherwise.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the color picker's markup.\n * @example\n * <ColorPicker label={t(\"form.accentColor.label\")} name=\"accentColor\" defaultValue=\"#3b82f6\" />\n * @example\n * <ColorPicker>\n * \t<Label htmlFor=\"brandColor\">{t(\"form.brandColor.label\")}</Label>\n * \t<ColorPicker.Group>\n * \t\t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t\t<ColorPicker.Trigger\n * \t\t\tcommandfor=\"brandColor-panel\"\n * \t\t\tcommand=\"toggle-popover\"\n * \t\t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\t\tvalue=\"#3b82f6\"\n * \t\t/>\n * \t</ColorPicker.Group>\n * \t<ColorPicker.Dialog id=\"brandColor-panel\">\n * \t\t{...the picking surface — see ColorPicker.Dialog's own doc comment}\n * \t</ColorPicker.Dialog>\n * </ColorPicker>\n */\nexport function ColorPicker(handle: Handle<ColorPicker.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tlabel,\n\t\t\tdescription,\n\t\t\terrorMessage,\n\t\t\tformat,\n\t\t\tname,\n\t\t\tvalue,\n\t\t\tdefaultValue,\n\t\t\tplaceholder,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\n\t\tif (import.meta.env?.DEV && !children && !label) {\n\t\t\tconsole.warn(\n\t\t\t\t'ColorPicker: falling back to ColorField\\'s plain color-notation field needs a \"label\" describing what it collects for assistive technology.',\n\t\t\t);\n\t\t}\n\n\t\tif (!children) {\n\t\t\treturn (\n\t\t\t\t<ColorField\n\t\t\t\t\t{...rest}\n\t\t\t\t\tcolor={color}\n\t\t\t\t\tlabel={label}\n\t\t\t\t\tdescription={description}\n\t\t\t\t\terrorMessage={errorMessage}\n\t\t\t\t\tformat={format}\n\t\t\t\t\tname={name}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tdefaultValue={defaultValue}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\tparts={parts}\n\t\t\t\t\tmix={mix}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<div {...rest} data-slot=\"color-picker\" mix={[vstack({ gap: 1 }), mix]}>\n\t\t\t\t{children}\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link ColorPicker}'s control row: a plain flex host laying the\n * field's own control and {@link ColorPicker.Trigger} side by side, with a\n * keyboard focus ring on the whole row the moment focus lands anywhere inside.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <ColorPicker.Group>\n * \t<Input id=\"brandColor\" type=\"text\" name=\"brandColor\" defaultValue=\"#3b82f6\" />\n * \t<ColorPicker.Trigger\n * \t\tcommandfor=\"brandColor-panel\"\n * \t\tcommand=\"toggle-popover\"\n * \t\taria-label={t(\"form.brandColor.toggle\")}\n * \t\tvalue=\"#3b82f6\"\n * \t/>\n * </ColorPicker.Group>\n */\nColorPicker.Group = function ColorPickerGroup(handle: Handle<ColorPicker.GroupProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"group\"\n\t\t\t\tmix={[\n\t\t\t\t\t/**\n\t\t\t\t\t * Focus is shown by the control that holds it, the way `Group` shows it: a ring\n\t\t\t\t\t * around the row says the group is focused without saying whether the field or\n\t\t\t\t\t * the preview has it, and it stacks with the ring that control draws for itself.\n\t\t\t\t\t */\n\t\t\t\t\thstack({ gap: 2, align: \"center\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link ColorPicker}'s trailing trigger: a `<button>` housing a\n * {@link ColorSwatch} that fills it as a live preview, wired via\n * `commandfor`/`command=\"toggle-popover\"` to {@link ColorPicker.Dialog}'s `id`.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the trigger's markup.\n * @example\n * <ColorPicker.Trigger\n * \tcommandfor=\"brandColor-panel\"\n * \tcommand=\"toggle-popover\"\n * \taria-label={t(\"form.brandColor.toggle\")}\n * \tvalue=\"#3b82f6\"\n * />\n */\nColorPicker.Trigger = function ColorPickerTrigger(handle: Handle<ColorPicker.TriggerProps>) {\n\treturn () => {\n\t\tlet { type, value, shape, mix, ...rest } = handle.props;\n\t\tlet resolvedType = type ?? DEFAULT_BUTTON_TYPE;\n\t\tlet resolvedShape = shape ?? DEFAULT_TRIGGER_SHAPE;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t\"ColorPicker.Trigger: this button needs an `aria-label` describing what it does — its content is a color preview with no accessible name of its own.\",\n\t\t);\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"trigger\"\n\t\t\t\tdata-shape={resolvedShape}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\trelative(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tis(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\tbs(\"var(--ui-color-picker-trigger-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\ttransition(\"box-shadow\"),\n\t\t\t\t\twhen('&[data-shape=\"circle\"]', rounded(\"full\")),\n\t\t\t\t\twhen(\"&:disabled\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\tp(0),\n\t\t\t\t\tshrink(),\n\t\t\t\t\twhen('&[data-shape=\"square\"]', rounded(\"none\")),\n\t\t\t\t\t/**\n\t\t\t\t\t * The swatch grows through the size variable it reads itself: a size passed down as\n\t\t\t\t\t * `mix` compiles into its own cascade layer, which can land before the swatch's own\n\t\t\t\t\t * and leave the preview at its default size in a corner of the button.\n\t\t\t\t\t */\n\t\t\t\t\traw({ \"--ui-color-swatch-size-md\": \"100%\" }),\n\t\t\t\t\t/**\n\t\t\t\t\t * Hover steps the preview's edge one shade darker, so the edge the swatch already\n\t\t\t\t\t * draws stays the only one and the border reads once.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"&:hover\", raw({ boxShadow: \"0 0 0 1px var(--ui-neutral-border-hover)\" })),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", raw({ transitionDuration: \"0s\" })),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t<ColorSwatch value={value} shape={resolvedShape} />\n\t\t\t</button>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link ColorPicker}'s picking surface: a Popover, defaulting\n * `placement` to bottom-start and `role` to `\"dialog\"`, padding whatever\n * picking controls a consumer composes as `children` in a single column.\n *\n * @param handle Runtime handle carrying the host's `Popover` props.\n * @returns The render function producing the surface's markup.\n * @example\n * <ColorPicker.Dialog id=\"brandColor-panel\">\n * \t<ColorArea aria-label={t(\"colorPicker.area\")} hue={hue} defaultSaturation={saturation} defaultValue={brightness} mix={colorAreaDrag()}>\n * \t\t<ColorArea.SaturationThumb data-color-area-axis=\"x\" aria-label={t(\"colorPicker.saturation\")} />\n * \t\t<ColorArea.ValueThumb data-color-area-axis=\"y\" aria-label={t(\"colorPicker.brightness\")} />\n * \t</ColorArea>\n * \t<ColorWheel aria-label={t(\"colorPicker.hue\")} defaultValue={hue} mix={colorWheelDrag()} />\n * \t<ColorSlider channel=\"alpha\" defaultValue={alpha}>\n * \t\t<ColorSlider.Track hue={hue}>\n * \t\t\t<ColorSlider.Thumb aria-label={t(\"colorPicker.alpha\")} />\n * \t\t</ColorSlider.Track>\n * \t</ColorSlider>\n * \t<ColorField label={t(\"colorPicker.hex\")} format=\"hex\" defaultValue=\"#3b82f6\" mix={colorPreview()} />\n * \t<ColorSwatchPicker aria-label={t(\"colorPicker.presets\")}>\n * \t\t<ColorSwatchPicker.Swatch value=\"#ef4444\" aria-label={t(\"color.red\")} />\n * \t\t<ColorSwatchPicker.Swatch value=\"#3b82f6\" aria-label={t(\"color.blue\")} defaultChecked />\n * \t</ColorSwatchPicker>\n * </ColorPicker.Dialog>\n */\nColorPicker.Dialog = function ColorPickerDialog(handle: Handle<ColorPicker.DialogProps>) {\n\treturn () => {\n\t\tlet { placement, children, mix, ...rest } = handle.props;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_DIALOG_PLACEMENT;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\t{...rest}\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_DIALOG_ROLE }),\n\t\t\t\t\tvstack({ gap: 4 }),\n\t\t\t\t\tp(4),\n\t\t\t\t\traw({ outline: \"none\" }),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</Popover>\n\t\t);\n\t};\n};\n"
|
|
15
15
|
},
|
|
16
16
|
"test": null
|
|
17
17
|
}
|