@sdxc/kit 2026.10.21 → 2026.10.24
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 +84 -4
- package/changelog.jsonl +168 -0
- package/config.schema.json +154 -0
- package/dist/architecture/complexity.d.ts +73 -0
- package/dist/architecture/complexity.js +185 -0
- package/dist/architecture/crap.d.ts +62 -0
- package/dist/architecture/crap.js +121 -0
- package/dist/architecture/graph.d.ts +55 -0
- package/dist/architecture/graph.js +194 -0
- package/dist/architecture/layers.d.ts +29 -0
- package/dist/architecture/layers.js +81 -0
- package/dist/architecture/mermaid.d.ts +20 -0
- package/dist/architecture/mermaid.js +51 -0
- package/dist/cli.js +9 -0
- package/dist/commands/create.js +4 -3
- package/dist/commands/deploy.js +10 -9
- package/dist/commands/destroy.d.ts +1 -1
- package/dist/commands/diagram.d.ts +17 -0
- package/dist/commands/diagram.js +45 -0
- package/dist/commands/fix.d.ts +69 -0
- package/dist/commands/fix.js +102 -0
- package/dist/commands/make.d.ts +71 -2
- package/dist/commands/make.js +46 -0
- package/dist/commands/run.d.ts +15 -11
- package/dist/commands/run.js +21 -16
- package/dist/commands/scaffold.d.ts +1 -1
- package/dist/commands/setup.d.ts +26 -0
- package/dist/commands/setup.js +33 -0
- package/dist/config.d.ts +52 -0
- package/dist/config.js +88 -1
- package/dist/contract.d.ts +52 -3
- package/dist/contract.js +124 -2
- package/dist/dependencies.js +7 -1
- package/dist/deploy/plan.d.ts +5 -0
- package/dist/deploy/plan.js +10 -0
- package/dist/destroy.js +13 -6
- package/dist/diagram.d.ts +32 -0
- package/dist/diagram.js +47 -0
- package/dist/doctor/checks.d.ts +2 -1
- package/dist/doctor/checks.js +24 -1
- package/dist/doctor/complexity.d.ts +13 -0
- package/dist/doctor/complexity.js +52 -0
- package/dist/doctor/crap.d.ts +14 -0
- package/dist/doctor/crap.js +67 -0
- package/dist/doctor/dependencies.d.ts +13 -0
- package/dist/doctor/dependencies.js +42 -0
- package/dist/doctor/duplication.d.ts +19 -0
- package/dist/doctor/duplication.js +106 -0
- package/dist/doctor/fan-out.d.ts +12 -0
- package/dist/doctor/fan-out.js +42 -0
- package/dist/doctor/feature-scatter.d.ts +15 -0
- package/dist/doctor/feature-scatter.js +84 -0
- package/dist/doctor/module-size.d.ts +13 -0
- package/dist/doctor/module-size.js +50 -0
- package/dist/doctor/mutation.d.ts +20 -0
- package/dist/doctor/mutation.js +97 -0
- package/dist/doctor/orphans.d.ts +13 -0
- package/dist/doctor/orphans.js +50 -0
- package/dist/doctor/project.js +8 -5
- package/dist/doctor/result-throws.d.ts +17 -0
- package/dist/doctor/result-throws.js +72 -0
- package/dist/doctor/test-ratio.d.ts +12 -0
- package/dist/doctor/test-ratio.js +31 -0
- package/dist/fix/commands.d.ts +37 -0
- package/dist/fix/commands.js +63 -0
- package/dist/fix/emails.d.ts +21 -0
- package/dist/fix/emails.js +159 -0
- package/dist/fix/env.d.ts +29 -0
- package/dist/fix/env.js +58 -0
- package/dist/fix/index.d.ts +11 -0
- package/dist/fix/index.js +11 -0
- package/dist/fix/models.d.ts +20 -0
- package/dist/fix/models.js +95 -0
- package/dist/lock.js +12 -2
- package/dist/make/binding.d.ts +42 -0
- package/dist/make/binding.js +237 -0
- package/dist/make/imports.js +7 -5
- package/dist/make/schema-diff.js +8 -1
- package/dist/models.js +7 -7
- package/dist/routes/modules.js +8 -5
- package/dist/routes/parse.js +8 -7
- package/dist/routes/routers.js +9 -5
- package/dist/setup/auth.d.ts +12 -0
- package/dist/setup/auth.js +209 -0
- package/dist/setup/billing.d.ts +11 -0
- package/dist/setup/billing.js +116 -0
- package/dist/setup/catalog.d.ts +25 -0
- package/dist/setup/catalog.js +34 -0
- package/dist/setup/credit.d.ts +13 -0
- package/dist/setup/credit.js +21 -0
- package/dist/setup/flags.d.ts +11 -0
- package/dist/setup/flags.js +62 -0
- package/dist/setup/index.d.ts +25 -0
- package/dist/setup/index.js +53 -0
- package/dist/setup/plan.d.ts +38 -0
- package/dist/setup/plan.js +62 -0
- package/dist/testing.js +3 -3
- package/dist/ui/layout.js +1 -1
- package/dist/ui/registry.d.ts +2 -2
- package/dist/upgrade/project.d.ts +2 -2
- package/dist/upgrade/prompt.js +7 -5
- package/package.json +11 -8
- package/registry/ui/attachment.json +2 -2
- package/registry/ui/breadcrumbs.json +6 -3
- package/registry/ui/group.json +6 -3
- package/registry/ui/link-button.json +3 -3
- package/registry/ui/link.json +6 -3
- package/registry/ui/nav-link.json +6 -3
- package/registry/ui/navigation-menu.json +6 -3
- package/registry/ui/pagination.json +3 -3
- package/registry/ui/sidebar.json +3 -3
- package/templates/app/AGENTS.md +14 -1
- package/templates/app/package.json +1 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nav-link",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.24",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"NavLink"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "nav-link.tsx",
|
|
10
|
-
"content": "/**\n * An inline text link for site navigation, colored through a semantic color\n * role and underlined to read as a link among surrounding prose. Its\n * current-page state comes straight from `aria-current` set on the host\n * server-side, rendering the emphasized, non-underlined treatment directly\n * from that attribute.\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 { colorMix, fg, outline } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { data, hover, when } from \"@sdxc/u/state\";\nimport { textDecoration, weight } from \"@sdxc/u/typography\";\n\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\n/** Semantic color role {@link NavLink} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: NavLink.Color = \"neutral\";\n\n/**\n * Prop types for {@link NavLink}.\n */\nexport namespace NavLink {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * Props accepted by {@link NavLink}, built as an intersection: the\n\t * underlying anchor prop type is a union keyed on `href`, since the\n\t * accessible-anchor contract restricts `role` once `href` is present.\n\t */\n\texport type Props = TagProps<\"a\"> & {\n\t\t/** Destination the link navigates to. */\n\t\thref: string;\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * Marks the link as sitting over its own colored background: drops the\n\t\t * underline entirely, since the background fill already sets it apart\n\t\t * from surrounding text.\n\t\t */\n\t\thasBackground?: boolean;\n\t};\n}\n\n/**\n * Renders a native `<a>`, colored via `data-color` and underlined with a\n * translucent decoration that solidifies on hover. Setting `aria-current`\n * server-side renders the current-page treatment; the focus-visible ring always reads in the primary color.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the link's markup.\n * @example\n * <NavLink href=\"/dashboard\" color=\"brand\">{t(\"nav.dashboard\")}</NavLink>\n * @example\n * <NavLink href=\"/settings\" aria-current={pathname === \"/settings\" ? \"page\" : undefined}>{t(\"nav.settings\")}</NavLink>\n * @example\n * <NavLink href=\"/settings\" hasBackground mix={css({ paddingInline: \"0.75rem\", paddingBlock: \"0.5rem\" })}>{t(\"nav.settings\")}</NavLink>\n */\nexport function NavLink(handle: Handle<NavLink.Props>) {\n\treturn () => {\n\t\tlet { color, hasBackground, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\t{...rest}\n\t\t\t\tdata-color={resolvedColor}\n\t\t\t\tdata-has-background={hasBackground || undefined}\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\ttextDecoration(\"underline\"),\n\t\t\t\t\traw({\n\t\t\t\t\t\ttextDecorationColor: colorMix(\n\t\t\t\t\t\t\t\"oklab\",\n\t\t\t\t\t\t\t{ color: \"currentcolor\", weight: 60 },\n\t\t\t\t\t\t\t\"transparent\",\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttextUnderlineOffset: \"4px\",\n\t\t\t\t\t}),\n\t\t\t\t\thover(raw({ textDecorationColor: \"currentcolor\" })),\n\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\tfg(\"brand.emphasis\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\tfg(\"success.emphasis\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\tfg(\"warning.emphasis\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\tfg(\"danger.emphasis\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\traw({ textDecorationThickness: \"2px\", textDecorationColor: \"currentcolor\" }),\n\t\t\t\t\t]),\n\t\t\t\t\tdata(\"has-background\", textDecoration(\"none\")),\n\t\t\t\t\twhen(\n\t\t\t\t\t\t'&[data-has-background]:hover, &[data-has-background][aria-current]:not([aria-current=\"false\"])',\n\t\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\t),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
10
|
+
"content": "/**\n * An inline text link for site navigation, colored through a semantic color\n * role and underlined to read as a link among surrounding prose. Its\n * current-page state comes straight from `aria-current` set on the host\n * server-side, rendering the emphasized, non-underlined treatment directly\n * from that attribute.\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 { colorMix, fg, outline } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { cursor, raw } from \"@sdxc/u/general\";\nimport { data, hover, when } from \"@sdxc/u/state\";\nimport { textDecoration, weight } from \"@sdxc/u/typography\";\n\nimport type { LinkPrefetch } from \"@sdxc/ui/utils\";\nimport type { SemanticColor } from \"@sdxc/ui/utils\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { prefetchAttribute, rendersPrefetchHint } from \"@sdxc/ui/utils\";\n\n/** Semantic color role {@link NavLink} falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: NavLink.Color = \"neutral\";\n\n/** Prefetch mode {@link NavLink} falls back to when `prefetch` is omitted. */\nconst DEFAULT_PREFETCH: NavLink.Prefetch = \"none\";\n\n/**\n * Prop types for {@link NavLink}.\n */\nexport namespace NavLink {\n\t/**\n\t * Semantic color role, each mapped to its matching `--ui-*` variables.\n\t */\n\texport type Color = SemanticColor;\n\n\t/**\n\t * When the destination starts loading: on intent, once in the viewport, on\n\t * render through a `<link rel=\"prefetch\">` that also serves full-document\n\t * navigations, or only on navigation (`\"none\"`).\n\t */\n\texport type Prefetch = LinkPrefetch;\n\n\t/**\n\t * Props accepted by {@link NavLink}, built as an intersection: the\n\t * underlying anchor prop type is a union keyed on `href`, since the\n\t * accessible-anchor contract restricts `role` once `href` is present.\n\t */\n\texport type Props = TagProps<\"a\"> & {\n\t\t/** Destination the link navigates to. */\n\t\thref: string;\n\t\t/** Semantic color role. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/**\n\t\t * Marks the link as sitting over its own colored background: drops the\n\t\t * underline entirely, since the background fill already sets it apart\n\t\t * from surrounding text.\n\t\t */\n\t\thasBackground?: boolean;\n\t\t/**\n\t\t * Prefetch mode, for links whose GET is safe to repeat. `\"render\"` suits\n\t\t * multi-page navigations; a menu keeps it to its first few items, since each\n\t\t * hint is a request on page load. Defaults to {@link DEFAULT_PREFETCH}.\n\t\t */\n\t\tprefetch?: Prefetch;\n\t};\n}\n\n/**\n * Renders a native `<a>`, colored via `data-color` and underlined with a\n * translucent decoration that solidifies on hover. Setting `aria-current`\n * server-side renders the current-page treatment; the focus-visible ring always reads in the primary color.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the link's markup.\n * @example\n * <NavLink href=\"/dashboard\" color=\"brand\" prefetch=\"render\">{t(\"nav.dashboard\")}</NavLink>\n * @example\n * <NavLink href=\"/settings\" aria-current={pathname === \"/settings\" ? \"page\" : undefined}>{t(\"nav.settings\")}</NavLink>\n * @example\n * <NavLink href=\"/settings\" hasBackground mix={css({ paddingInline: \"0.75rem\", paddingBlock: \"0.5rem\" })}>{t(\"nav.settings\")}</NavLink>\n */\nexport function NavLink(handle: Handle<NavLink.Props>) {\n\treturn () => {\n\t\tlet { color, hasBackground, prefetch, mix, ...rest } = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\t\tlet resolvedPrefetch = prefetch ?? DEFAULT_PREFETCH;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<a\n\t\t\t\t\t{...rest}\n\t\t\t\t\tdata-color={resolvedColor}\n\t\t\t\t\tdata-has-background={hasBackground || undefined}\n\t\t\t\t\tdata-rmx-prefetch={prefetchAttribute(resolvedPrefetch)}\n\t\t\t\t\tmix={[\n\t\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t\tcursor(\"pointer\"),\n\t\t\t\t\t\ttextDecoration(\"underline\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\ttextDecorationColor: colorMix(\n\t\t\t\t\t\t\t\t\"oklab\",\n\t\t\t\t\t\t\t\t{ color: \"currentcolor\", weight: 60 },\n\t\t\t\t\t\t\t\t\"transparent\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttextUnderlineOffset: \"4px\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t\thover(raw({ textDecorationColor: \"currentcolor\" })),\n\t\t\t\t\t\tdata(\"color\", \"brand\", [\n\t\t\t\t\t\t\tfg(\"brand\"),\n\t\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\t\tfg(\"brand.emphasis\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"neutral\", [\n\t\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"success\", [\n\t\t\t\t\t\t\tfg(\"success\"),\n\t\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\t\tfg(\"success.emphasis\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"warning\", [\n\t\t\t\t\t\t\tfg(\"warning\"),\n\t\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\t\tfg(\"warning.emphasis\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"color\", \"danger\", [\n\t\t\t\t\t\t\tfg(\"danger\"),\n\t\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\t\tfg(\"danger.emphasis\"),\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\t\tweight(500),\n\t\t\t\t\t\t\traw({ textDecorationThickness: \"2px\", textDecorationColor: \"currentcolor\" }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\tdata(\"has-background\", textDecoration(\"none\")),\n\t\t\t\t\t\twhen(\n\t\t\t\t\t\t\t'&[data-has-background]:hover, &[data-has-background][aria-current]:not([aria-current=\"false\"])',\n\t\t\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tmix,\n\t\t\t\t\t]}\n\t\t\t\t/>\n\t\t\t\t{rendersPrefetchHint(resolvedPrefetch, rest.href) && (\n\t\t\t\t\t<link rel=\"prefetch\" href={rest.href} />\n\t\t\t\t)}\n\t\t\t</>\n\t\t);\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
|
-
"test":
|
|
12
|
+
"test": {
|
|
13
|
+
"path": "nav-link.test.tsx",
|
|
14
|
+
"content": "/**\n * Tests for {@link NavLink}: the anchor carries `data-rmx-prefetch` only for the\n * runtime's modes, and `\"render\"` adds a `<link rel=\"prefetch\">` after it instead.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { NavLink } from \"@sdxc/ui/nav-link\";\n\ndescribe(NavLink.name, () => {\n\ttest(\"leaves prefetching off unless a mode is chosen\", async () => {\n\t\tlet html = await renderToString(<NavLink href=\"/settings\">Settings</NavLink>);\n\t\tlet none = await renderToString(\n\t\t\t<NavLink href=\"/settings\" prefetch=\"none\">\n\t\t\t\tSettings\n\t\t\t</NavLink>,\n\t\t);\n\n\t\texpect(html).toMatch(/<a [^>]*href=\"\\/settings\"[^>]*>Settings<\\/a>/);\n\t\texpect(html).not.toContain(\"data-rmx-prefetch\");\n\t\texpect(none).not.toContain(\"data-rmx-prefetch\");\n\t\texpect(html).not.toContain(\"<link\");\n\t\texpect(none).not.toContain(\"<link\");\n\t});\n\n\ttest.each([\"intent\", \"viewport\"] as const)(\"prefetches on %s\", async (prefetch) => {\n\t\tlet html = await renderToString(\n\t\t\t<NavLink href=\"/settings\" prefetch={prefetch}>\n\t\t\t\tSettings\n\t\t\t</NavLink>,\n\t\t);\n\n\t\texpect(html).toMatch(new RegExp(`<a [^>]*data-rmx-prefetch=\"${prefetch}\"`));\n\t\texpect(html).not.toContain(\"<link\");\n\t});\n\n\ttest(\"renders a prefetch hint after the anchor on render\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<NavLink href=\"/settings\" prefetch=\"render\">\n\t\t\t\tSettings\n\t\t\t</NavLink>,\n\t\t);\n\n\t\texpect(html).toMatch(/Settings<\\/a><link rel=\"prefetch\" href=\"\\/settings\"/);\n\t\texpect(html).not.toContain(\"data-rmx-prefetch\");\n\t});\n\n\ttest(\"renders no prefetch hint without a destination\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<NavLink href=\"\" prefetch=\"render\">\n\t\t\t\tSettings\n\t\t\t</NavLink>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"<link\");\n\t});\n});\n"
|
|
15
|
+
}
|
|
13
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "navigation-menu",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.24",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"popover"
|
|
6
6
|
],
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "navigation-menu.tsx",
|
|
12
|
-
"content": "/**\n * A row of top-level navigation triggers, each either a plain link or a\n * button that opens a floating panel of related links. `NavigationMenu.Item`\n * hands its own stable id to whichever `NavigationMenu.Trigger` and\n * `NavigationMenu.Content` nest inside it through component context, so the\n * two pair up automatically — a consumer never wires a `commandfor`/`id`\n * pair by hand for the common case.\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, fg, outline, outlineStyle } from \"@sdxc/u/color\";\nimport {\n\topacity,\n\trounded,\n\ttransition,\n\ttransitionBehavior,\n\ttransitionProperty,\n} from \"@sdxc/u/effects\";\nimport { cursor, raw, userSelect } from \"@sdxc/u/general\";\nimport {\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrid,\n\tgridTemplate,\n\tinlineFlex,\n\titems,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { at, media, startingStyle } from \"@sdxc/u/responsive\";\nimport { bs, is, maxIs, mbs, minIs, pb, pi } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { data, disabled, hover, when } from \"@sdxc/u/state\";\nimport { scaleProperty } from \"@sdxc/u/transform\";\nimport { fontSize, leading, text, textDecoration, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport {\n\tconcentricRadius,\n\tfloatingSurface,\n\tsurfaceInset,\n\tsurfacePadding,\n} from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\n\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Named container {@link NavigationMenu.Content} declares on its own host, so\n * {@link NavigationMenu.ContentGrid} can adapt to the panel's own width\n * instead of the page's.\n */\nconst CONTAINER_NAME = \"ui-navigation-menu-content\";\n\n/**\n * `role=\"list\"` applied to {@link NavigationMenu.List} through {@link attrs}\n * unless a consumer supplies its own `role`, restoring list semantics that a\n * stylesheet clearing `list-style` otherwise drops for assistive technology.\n */\nconst DEFAULT_LIST_ROLE = \"list\";\n\n/**\n * Default {@link NavigationMenu.ListProps} orientation, applied when\n * `orientation` is omitted, laying triggers out in a single row.\n */\nconst DEFAULT_ORIENTATION: NavigationMenu.Orientation = \"horizontal\";\n\n/**\n * `type` {@link NavigationMenu.TriggerProps.type} falls back to when a\n * consumer doesn't supply one, keeping a click on the trigger from\n * submitting a surrounding `<form>`.\n */\nconst DEFAULT_TRIGGER_TYPE: NonNullable<NavigationMenu.TriggerProps[\"type\"]> = \"button\";\n\n/**\n * Invoker Commands verb {@link NavigationMenu.TriggerProps.command} falls\n * back to when omitted, showing the paired {@link NavigationMenu.Content} if\n * it's hidden and hiding it again if it's already showing.\n */\nconst DEFAULT_TRIGGER_COMMAND = \"toggle-popover\";\n\n/**\n * Side of the trigger {@link NavigationMenu.Content} renders against when\n * `placement` is left unset, matching a dropdown reading down and start-ward\n * from its trigger.\n */\nconst DEFAULT_CONTENT_PLACEMENT: NavigationMenu.ContentProps[\"placement\"] = \"bottom-start\";\n\n/**\n * {@link NavigationMenu.ContentProps.size} falls back to when omitted,\n * sizing the panel to its own content instead of a fixed wide measure.\n */\nconst DEFAULT_CONTENT_SIZE: NavigationMenu.ContentSize = \"default\";\n\n/**\n * Prop types for {@link NavigationMenu} and its compound parts.\n */\nexport namespace NavigationMenu {\n\t/**\n\t * Axis {@link NavigationMenu.List} lays its triggers out along: a single\n\t * row, or a single column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Panel width {@link NavigationMenu.Content} renders at: sized to its own\n\t * content (`\"default\"`), or a fixed, generously wide measure that still\n\t * clamps to the viewport on narrow screens (`\"wide\"`).\n\t */\n\texport type ContentSize = \"default\" | \"wide\";\n\n\t/**\n\t * Value {@link NavigationMenu.Item} stores in component context so the\n\t * {@link NavigationMenu.Trigger} and {@link NavigationMenu.Content} nested\n\t * inside it pair up automatically.\n\t */\n\texport interface Context {\n\t\t/** Stable id the enclosing {@link NavigationMenu.Item} generated for its {@link NavigationMenu.Content}. */\n\t\tcontentId: string;\n\t}\n\n\t/**\n\t * Every native `<nav>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface Props extends TagProps<\"nav\"> {\n\t\t/** The menu's own {@link NavigationMenu.List}, and anything else rendered alongside it (a {@link NavigationMenu.Viewport}, for instance). */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<ul>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ListProps extends TagProps<\"ul\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t\t/** One or more {@link NavigationMenu.Item}s. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<li>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ItemProps extends TagProps<\"li\"> {\n\t\t/**\n\t\t * Either a standalone {@link NavigationMenu.Link}, or a\n\t\t * {@link NavigationMenu.Trigger} followed by the\n\t\t * {@link NavigationMenu.Content} it opens.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<button>` attribute, plus the `mix` passthrough.\n\t * `commandfor` and `command` both default from the enclosing\n\t * {@link NavigationMenu.Item}'s context.\n\t */\n\texport interface TriggerProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every prop {@link Popover.Props} accepts except `id`, which becomes\n\t * optional here since it defaults from the enclosing\n\t * {@link NavigationMenu.Item}'s context, plus `size`.\n\t */\n\texport interface ContentProps extends Omit<Popover.Props, \"id\" | \"placement\"> {\n\t\t/** Stable id matched against a {@link NavigationMenu.Trigger}'s `commandfor`. Defaults to the enclosing {@link NavigationMenu.Item}'s generated id. */\n\t\tid?: string;\n\t\t/** Side of the trigger to render against. Defaults to {@link DEFAULT_CONTENT_PLACEMENT}. */\n\t\tplacement?: Popover.Placement;\n\t\t/** Panel width. Defaults to {@link DEFAULT_CONTENT_SIZE}. */\n\t\tsize?: ContentSize;\n\t}\n\n\t/**\n\t * Every native `<a>` attribute, plus the `mix` passthrough. Uses an\n\t * intersection because the underlying anchor prop type is a union keyed on\n\t * `href`, narrowed here to required since a link needs a destination.\n\t */\n\texport type LinkProps = TagProps<\"a\"> & {\n\t\t/** Destination the link navigates to. */\n\t\thref: string;\n\t};\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ViewportProps extends TagProps<\"div\"> {\n\t\t/** The currently active item's content, mirrored in from wherever it actually renders. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ContentListProps extends TagProps<\"div\"> {\n\t\t/** One or more {@link NavigationMenu.Link}s. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ContentGridProps extends TagProps<\"div\"> {\n\t\t/** Two or more {@link NavigationMenu.ContentColumn}s. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ContentColumnProps extends TagProps<\"div\"> {\n\t\t/** One or more {@link NavigationMenu.Link}s. */\n\t\tchildren?: RemixNode;\n\t}\n}\n\n/**\n * Renders the menu's root host: a native `<nav>` landmark establishing a\n * positioning context for whatever floating panels its\n * {@link NavigationMenu.Content} instances anchor against.\n *\n * @param handle Runtime handle carrying the host `<nav>`'s props.\n * @returns The render function producing the menu's markup.\n * @example\n * <NavigationMenu aria-label={t(\"nav.primary\")}>\n * \t<NavigationMenu.List>\n * \t\t<NavigationMenu.Item>\n * \t\t\t<NavigationMenu.Link href=\"/\">{t(\"nav.home\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.Item>\n * \t</NavigationMenu.List>\n * </NavigationMenu>\n */\nexport function NavigationMenu(handle: Handle<NavigationMenu.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <nav {...rest} mix={[relative(), mix]} />;\n\t};\n}\n\n/**\n * Renders the row of top-level triggers: a native `<ul>` laying its\n * {@link NavigationMenu.Item}s out horizontally by default, switching to a\n * single start-aligned column when `orientation` is `\"vertical\"`.\n *\n * @param handle Runtime handle carrying the host `<ul>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <NavigationMenu.List>\n * \t<NavigationMenu.Item>\n * \t\t<NavigationMenu.Link href=\"/pricing\">{t(\"nav.pricing\")}</NavigationMenu.Link>\n * \t</NavigationMenu.Item>\n * </NavigationMenu.List>\n * @example\n * <NavigationMenu.List orientation=\"vertical\">\n * \t<NavigationMenu.Item>\n * \t\t<NavigationMenu.Link href=\"/settings/profile\">{t(\"nav.profile\")}</NavigationMenu.Link>\n * \t</NavigationMenu.Item>\n * </NavigationMenu.List>\n */\nNavigationMenu.List = function NavigationMenuList(handle: Handle<NavigationMenu.ListProps>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;\n\n\t\treturn (\n\t\t\t<ul\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_LIST_ROLE }),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(1),\n\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [flexCol(), items(\"start\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single top-level entry: a native `<li>` holding either a\n * standalone {@link NavigationMenu.Link} or a {@link NavigationMenu.Trigger}\n * paired with the {@link NavigationMenu.Content} it opens.\n *\n * @param handle Runtime handle carrying the host `<li>`'s props and providing {@link NavigationMenu.Context}.\n * @returns The render function producing the item's markup.\n * @example\n * <NavigationMenu.Item>\n * \t<NavigationMenu.Trigger>{t(\"nav.products\")}</NavigationMenu.Trigger>\n * \t<NavigationMenu.Content>\n * \t\t<NavigationMenu.ContentList>\n * \t\t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t\t\t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentList>\n * \t</NavigationMenu.Content>\n * </NavigationMenu.Item>\n */\nNavigationMenu.Item = function NavigationMenuItem(\n\thandle: Handle<NavigationMenu.ItemProps, NavigationMenu.Context>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\thandle.context.set({ contentId: handle.id });\n\n\t\treturn <li {...rest} mix={[relative(), flex(), items(\"center\"), mix]} />;\n\t};\n};\n\n/**\n * Renders a native `<button>` that opens the enclosing\n * {@link NavigationMenu.Item}'s {@link NavigationMenu.Content} through the\n * Invoker Commands API, so `aria-expanded` reflects the panel automatically.\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 * <NavigationMenu.Trigger>{t(\"nav.products\")}</NavigationMenu.Trigger>\n * @example\n * <NavigationMenu.Trigger aria-disabled=\"true\">{t(\"nav.archived\")}</NavigationMenu.Trigger>\n */\nNavigationMenu.Trigger = function NavigationMenuTrigger(\n\thandle: Handle<NavigationMenu.TriggerProps>,\n) {\n\treturn () => {\n\t\tlet { type, commandfor, command, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(NavigationMenu.Item);\n\t\tlet resolvedType = type ?? DEFAULT_TRIGGER_TYPE;\n\t\tlet resolvedCommandfor = commandfor ?? context.contentId;\n\t\tlet resolvedCommand = command ?? DEFAULT_TRIGGER_COMMAND;\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\tcommandfor={resolvedCommandfor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\t{...rest}\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\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(2),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\tdisabled(opacity(50)),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-expanded=\"true\"]', [bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\tdisabled(cursor(\"not-allowed\")),\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 {@link NavigationMenu.Content}, the floating panel a\n * {@link NavigationMenu.Trigger} opens: a {@link Popover} that fades and\n * scales itself using the platform's own `:popover-open` state.\n *\n * @param handle Runtime handle carrying the host's {@link Popover} props.\n * @returns The render function producing the panel's markup.\n * @example\n * <NavigationMenu.Content>\n * \t<NavigationMenu.ContentList>\n * \t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t</NavigationMenu.ContentList>\n * </NavigationMenu.Content>\n * @example\n * <NavigationMenu.Content size=\"wide\">\n * \t<NavigationMenu.ContentGrid>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t</NavigationMenu.ContentGrid>\n * </NavigationMenu.Content>\n */\nNavigationMenu.Content = function NavigationMenuContent(\n\thandle: Handle<NavigationMenu.ContentProps>,\n) {\n\treturn () => {\n\t\tlet { id, placement, size, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(NavigationMenu.Item);\n\t\tlet resolvedId = id ?? context.contentId;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_CONTENT_PLACEMENT;\n\t\tlet resolvedSize = size ?? DEFAULT_CONTENT_SIZE;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\tid={resolvedId}\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tis(\"max-content\"),\n\t\t\t\t\tminIs(\"11rem\"),\n\t\t\t\t\tsurfaceInset({ scale: 2 }),\n\t\t\t\t\tz(50),\n\t\t\t\t\topacity(0),\n\t\t\t\t\twhen('& [data-slot=\"link\"]', [is(\"full\"), justify(\"start\")]),\n\t\t\t\t\twhen('&[data-size=\"wide\"]', [is(\"28rem\"), maxIs(\"calc(100vw - 2rem)\")]),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\ttransition(\"opacity, scale, display, overlay\", {\n\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t}),\n\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\tscaleProperty(\"0.95\"),\n\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\twhen(\"&:popover-open\", [opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\tstartingStyle(when(\"&:popover-open\", [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\tscaleProperty(\"none\"),\n\t\t\t\t\t\ttransitionProperty(\"opacity, display, overlay\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link NavigationMenu.LinkProps.children} as a native `<a>`.\n * `aria-current` marks the active page; `aria-disabled=\"true\"` only mutes it\n * visually, since a plain `<a>` has no native disabled state to block clicks.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the link's markup.\n * @example\n * <NavigationMenu.Link href=\"/pricing\">{t(\"nav.pricing\")}</NavigationMenu.Link>\n * @example\n * <NavigationMenu.Link href=\"/dashboard\" aria-current={pathname === \"/dashboard\" ? \"page\" : undefined}>\n * \t{t(\"nav.dashboard\")}\n * </NavigationMenu.Link>\n */\nNavigationMenu.Link = function NavigationMenuLink(handle: Handle<NavigationMenu.LinkProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\tdata-slot=\"link\"\n\t\t\t\t{...rest}\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\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(2),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tleading(1),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [opacity(50), cursor(\"not-allowed\")]),\n\t\t\t\t\tuserSelect(),\n\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\tfontSize(\"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 a shared, animated surface that swaps in the active\n * {@link NavigationMenu.Item}'s content, sized by the custom properties a\n * pairing mixin writes as it measures the active panel and toggles visibility.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the shared frame's markup.\n * @example\n * <NavigationMenu.Viewport data-visible={isMenuOpen || undefined} />\n */\nNavigationMenu.Viewport = function NavigationMenuViewport(\n\thandle: Handle<NavigationMenu.ViewportProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tfloatingSurface(),\n\t\t\t\t\traw({ borderRadius: concentricRadius(surfacePadding(2)) }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tmbs(2),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(\"var(--ui-navigation-menu-viewport-inline-size, auto)\"),\n\t\t\t\t\tbs(\"var(--ui-navigation-menu-viewport-block-size, auto)\"),\n\t\t\t\t\topacity(0),\n\t\t\t\t\ttransition(\"inline-size, block-size, opacity, scale\", {\n\t\t\t\t\t\tduration: durations.normal,\n\t\t\t\t\t\teasing: easings.decelerate,\n\t\t\t\t\t}),\n\t\t\t\t\tscaleProperty(\"0.95\"),\n\t\t\t\t\tdata(\"visible\", [opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\tstartingStyle(data(\"visible\", [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\tscaleProperty(\"none\"),\n\t\t\t\t\t\ttransitionProperty(\"inline-size, block-size, opacity\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link NavigationMenu.ContentListProps.children} as a plain\n * vertical run of {@link NavigationMenu.Link}s inside\n * {@link NavigationMenu.Content}, for a dropdown that's just a short list.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <NavigationMenu.ContentList>\n * \t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * </NavigationMenu.ContentList>\n */\nNavigationMenu.ContentList = function NavigationMenuContentList(\n\thandle: Handle<NavigationMenu.ContentListProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} mix={[grid(), gap(1), mix]} />;\n\t};\n};\n\n/**\n * Renders {@link NavigationMenu.ContentGridProps.children} as a\n * multi-column layout inside {@link NavigationMenu.Content}: a single column\n * while the panel's own container is narrower than `40rem`, else two columns.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <NavigationMenu.Content size=\"wide\">\n * \t<NavigationMenu.ContentGrid>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t</NavigationMenu.ContentGrid>\n * </NavigationMenu.Content>\n */\nNavigationMenu.ContentGrid = function NavigationMenuContentGrid(\n\thandle: Handle<NavigationMenu.ContentGridProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tgrid(),\n\t\t\t\t\tgap(4),\n\t\t\t\t\tat(\"40rem\", CONTAINER_NAME, gridTemplate({ columns: \"repeat(2, minmax(0, 1fr))\" })),\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 NavigationMenu.ContentColumnProps.children} as one column of\n * stacked {@link NavigationMenu.Link}s inside a\n * {@link NavigationMenu.ContentGrid}.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the column's markup.\n * @example\n * <NavigationMenu.ContentColumn>\n * \t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * </NavigationMenu.ContentColumn>\n */\nNavigationMenu.ContentColumn = function NavigationMenuContentColumn(\n\thandle: Handle<NavigationMenu.ContentColumnProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} mix={[grid(), gap(1), mix]} />;\n\t};\n};\n"
|
|
12
|
+
"content": "/**\n * A row of top-level navigation triggers, each either a plain link or a\n * button that opens a floating panel of related links. `NavigationMenu.Item`\n * hands its own stable id to whichever `NavigationMenu.Trigger` and\n * `NavigationMenu.Content` nest inside it through component context, so the\n * two pair up automatically — a consumer never wires a `commandfor`/`id`\n * pair by hand for the common case.\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, fg, outline, outlineStyle } from \"@sdxc/u/color\";\nimport {\n\topacity,\n\trounded,\n\ttransition,\n\ttransitionBehavior,\n\ttransitionProperty,\n} from \"@sdxc/u/effects\";\nimport { cursor, raw, userSelect } from \"@sdxc/u/general\";\nimport {\n\tcontainer,\n\tflex,\n\tflexCol,\n\tgap,\n\tgrid,\n\tgridTemplate,\n\tinlineFlex,\n\titems,\n\tjustify,\n\trelative,\n} from \"@sdxc/u/layout\";\nimport { overflow } from \"@sdxc/u/overflow\";\nimport { at, media, startingStyle } from \"@sdxc/u/responsive\";\nimport { bs, is, maxIs, mbs, minIs, pb, pi } from \"@sdxc/u/size\";\nimport { z } from \"@sdxc/u/stacking\";\nimport { data, disabled, hover, when } from \"@sdxc/u/state\";\nimport { scaleProperty } from \"@sdxc/u/transform\";\nimport { fontSize, leading, text, textDecoration, weight } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\nimport type { LinkPrefetch } from \"@sdxc/ui/utils\";\n\nimport { durations, easings } from \"@sdxc/ui/animations\";\nimport {\n\tconcentricRadius,\n\tfloatingSurface,\n\tsurfaceInset,\n\tsurfacePadding,\n} from \"@sdxc/ui/styles\";\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { prefetchAttribute, rendersPrefetchHint } from \"@sdxc/ui/utils\";\n\nimport { Popover } from \"@sdxc/ui/popover\";\n\n/**\n * Named container {@link NavigationMenu.Content} declares on its own host, so\n * {@link NavigationMenu.ContentGrid} can adapt to the panel's own width\n * instead of the page's.\n */\nconst CONTAINER_NAME = \"ui-navigation-menu-content\";\n\n/**\n * `role=\"list\"` applied to {@link NavigationMenu.List} through {@link attrs}\n * unless a consumer supplies its own `role`, restoring list semantics that a\n * stylesheet clearing `list-style` otherwise drops for assistive technology.\n */\nconst DEFAULT_LIST_ROLE = \"list\";\n\n/**\n * Default {@link NavigationMenu.ListProps} orientation, applied when\n * `orientation` is omitted, laying triggers out in a single row.\n */\nconst DEFAULT_ORIENTATION: NavigationMenu.Orientation = \"horizontal\";\n\n/**\n * `type` {@link NavigationMenu.TriggerProps.type} falls back to when a\n * consumer doesn't supply one, keeping a click on the trigger from\n * submitting a surrounding `<form>`.\n */\nconst DEFAULT_TRIGGER_TYPE: NonNullable<NavigationMenu.TriggerProps[\"type\"]> = \"button\";\n\n/**\n * Invoker Commands verb {@link NavigationMenu.TriggerProps.command} falls\n * back to when omitted, showing the paired {@link NavigationMenu.Content} if\n * it's hidden and hiding it again if it's already showing.\n */\nconst DEFAULT_TRIGGER_COMMAND = \"toggle-popover\";\n\n/**\n * Side of the trigger {@link NavigationMenu.Content} renders against when\n * `placement` is left unset, matching a dropdown reading down and start-ward\n * from its trigger.\n */\nconst DEFAULT_CONTENT_PLACEMENT: NavigationMenu.ContentProps[\"placement\"] = \"bottom-start\";\n\n/**\n * {@link NavigationMenu.ContentProps.size} falls back to when omitted,\n * sizing the panel to its own content instead of a fixed wide measure.\n */\nconst DEFAULT_CONTENT_SIZE: NavigationMenu.ContentSize = \"default\";\n\n/** Prefetch mode {@link NavigationMenu.Link} falls back to when `prefetch` is omitted. */\nconst DEFAULT_PREFETCH: NavigationMenu.Prefetch = \"none\";\n\n/**\n * Prop types for {@link NavigationMenu} and its compound parts.\n */\nexport namespace NavigationMenu {\n\t/**\n\t * Axis {@link NavigationMenu.List} lays its triggers out along: a single\n\t * row, or a single column.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Panel width {@link NavigationMenu.Content} renders at: sized to its own\n\t * content (`\"default\"`), or a fixed, generously wide measure that still\n\t * clamps to the viewport on narrow screens (`\"wide\"`).\n\t */\n\texport type ContentSize = \"default\" | \"wide\";\n\n\t/**\n\t * Value {@link NavigationMenu.Item} stores in component context so the\n\t * {@link NavigationMenu.Trigger} and {@link NavigationMenu.Content} nested\n\t * inside it pair up automatically.\n\t */\n\texport interface Context {\n\t\t/** Stable id the enclosing {@link NavigationMenu.Item} generated for its {@link NavigationMenu.Content}. */\n\t\tcontentId: string;\n\t}\n\n\t/**\n\t * Every native `<nav>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface Props extends TagProps<\"nav\"> {\n\t\t/** The menu's own {@link NavigationMenu.List}, and anything else rendered alongside it (a {@link NavigationMenu.Viewport}, for instance). */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<ul>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ListProps extends TagProps<\"ul\"> {\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t\t/** One or more {@link NavigationMenu.Item}s. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<li>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ItemProps extends TagProps<\"li\"> {\n\t\t/**\n\t\t * Either a standalone {@link NavigationMenu.Link}, or a\n\t\t * {@link NavigationMenu.Trigger} followed by the\n\t\t * {@link NavigationMenu.Content} it opens.\n\t\t */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<button>` attribute, plus the `mix` passthrough.\n\t * `commandfor` and `command` both default from the enclosing\n\t * {@link NavigationMenu.Item}'s context.\n\t */\n\texport interface TriggerProps extends TagProps<\"button\"> {}\n\n\t/**\n\t * Every prop {@link Popover.Props} accepts except `id`, which becomes\n\t * optional here since it defaults from the enclosing\n\t * {@link NavigationMenu.Item}'s context, plus `size`.\n\t */\n\texport interface ContentProps extends Omit<Popover.Props, \"id\" | \"placement\"> {\n\t\t/** Stable id matched against a {@link NavigationMenu.Trigger}'s `commandfor`. Defaults to the enclosing {@link NavigationMenu.Item}'s generated id. */\n\t\tid?: string;\n\t\t/** Side of the trigger to render against. Defaults to {@link DEFAULT_CONTENT_PLACEMENT}. */\n\t\tplacement?: Popover.Placement;\n\t\t/** Panel width. Defaults to {@link DEFAULT_CONTENT_SIZE}. */\n\t\tsize?: ContentSize;\n\t}\n\n\t/**\n\t * Every native `<a>` attribute, plus the `mix` passthrough. Uses an\n\t * intersection because the underlying anchor prop type is a union keyed on\n\t * `href`, narrowed here to required since a link needs a destination.\n\t */\n\texport type LinkProps = TagProps<\"a\"> & {\n\t\t/** Destination the link navigates to. */\n\t\thref: string;\n\t\t/**\n\t\t * `\"intent\"`/`\"viewport\"` write `data-rmx-prefetch`; `\"render\"` adds a `<link rel=\"prefetch\">`\n\t\t * that also serves full-document navigations, so keep it to the first few links, since each\n\t\t * hint is a request on page load. Defaults to {@link DEFAULT_PREFETCH}.\n\t\t */\n\t\tprefetch?: Prefetch;\n\t};\n\n\t/**\n\t * When a {@link NavigationMenu.Link}'s destination starts loading, the same\n\t * modes every link component in this library accepts.\n\t */\n\texport type Prefetch = LinkPrefetch;\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ViewportProps extends TagProps<\"div\"> {\n\t\t/** The currently active item's content, mirrored in from wherever it actually renders. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ContentListProps extends TagProps<\"div\"> {\n\t\t/** One or more {@link NavigationMenu.Link}s. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ContentGridProps extends TagProps<\"div\"> {\n\t\t/** Two or more {@link NavigationMenu.ContentColumn}s. */\n\t\tchildren?: RemixNode;\n\t}\n\n\t/**\n\t * Every native `<div>` attribute, plus the `mix` passthrough.\n\t */\n\texport interface ContentColumnProps extends TagProps<\"div\"> {\n\t\t/** One or more {@link NavigationMenu.Link}s. */\n\t\tchildren?: RemixNode;\n\t}\n}\n\n/**\n * Renders the menu's root host: a native `<nav>` landmark establishing a\n * positioning context for whatever floating panels its\n * {@link NavigationMenu.Content} instances anchor against.\n *\n * @param handle Runtime handle carrying the host `<nav>`'s props.\n * @returns The render function producing the menu's markup.\n * @example\n * <NavigationMenu aria-label={t(\"nav.primary\")}>\n * \t<NavigationMenu.List>\n * \t\t<NavigationMenu.Item>\n * \t\t\t<NavigationMenu.Link href=\"/\">{t(\"nav.home\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.Item>\n * \t</NavigationMenu.List>\n * </NavigationMenu>\n */\nexport function NavigationMenu(handle: Handle<NavigationMenu.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <nav {...rest} mix={[relative(), mix]} />;\n\t};\n}\n\n/**\n * Renders the row of top-level triggers: a native `<ul>` laying its\n * {@link NavigationMenu.Item}s out horizontally by default, switching to a\n * single start-aligned column when `orientation` is `\"vertical\"`.\n *\n * @param handle Runtime handle carrying the host `<ul>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <NavigationMenu.List>\n * \t<NavigationMenu.Item>\n * \t\t<NavigationMenu.Link href=\"/pricing\">{t(\"nav.pricing\")}</NavigationMenu.Link>\n * \t</NavigationMenu.Item>\n * </NavigationMenu.List>\n * @example\n * <NavigationMenu.List orientation=\"vertical\">\n * \t<NavigationMenu.Item>\n * \t\t<NavigationMenu.Link href=\"/settings/profile\">{t(\"nav.profile\")}</NavigationMenu.Link>\n * \t</NavigationMenu.Item>\n * </NavigationMenu.List>\n */\nNavigationMenu.List = function NavigationMenuList(handle: Handle<NavigationMenu.ListProps>) {\n\treturn () => {\n\t\tlet { orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;\n\n\t\treturn (\n\t\t\t<ul\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tattrs({ role: DEFAULT_LIST_ROLE }),\n\t\t\t\t\tflex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(1),\n\t\t\t\t\twhen('&[data-orientation=\"vertical\"]', [flexCol(), items(\"start\")]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single top-level entry: a native `<li>` holding either a\n * standalone {@link NavigationMenu.Link} or a {@link NavigationMenu.Trigger}\n * paired with the {@link NavigationMenu.Content} it opens.\n *\n * @param handle Runtime handle carrying the host `<li>`'s props and providing {@link NavigationMenu.Context}.\n * @returns The render function producing the item's markup.\n * @example\n * <NavigationMenu.Item>\n * \t<NavigationMenu.Trigger>{t(\"nav.products\")}</NavigationMenu.Trigger>\n * \t<NavigationMenu.Content>\n * \t\t<NavigationMenu.ContentList>\n * \t\t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t\t\t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentList>\n * \t</NavigationMenu.Content>\n * </NavigationMenu.Item>\n */\nNavigationMenu.Item = function NavigationMenuItem(\n\thandle: Handle<NavigationMenu.ItemProps, NavigationMenu.Context>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\thandle.context.set({ contentId: handle.id });\n\n\t\treturn <li {...rest} mix={[relative(), flex(), items(\"center\"), mix]} />;\n\t};\n};\n\n/**\n * Renders a native `<button>` that opens the enclosing\n * {@link NavigationMenu.Item}'s {@link NavigationMenu.Content} through the\n * Invoker Commands API, so `aria-expanded` reflects the panel automatically.\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 * <NavigationMenu.Trigger>{t(\"nav.products\")}</NavigationMenu.Trigger>\n * @example\n * <NavigationMenu.Trigger aria-disabled=\"true\">{t(\"nav.archived\")}</NavigationMenu.Trigger>\n */\nNavigationMenu.Trigger = function NavigationMenuTrigger(\n\thandle: Handle<NavigationMenu.TriggerProps>,\n) {\n\treturn () => {\n\t\tlet { type, commandfor, command, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(NavigationMenu.Item);\n\t\tlet resolvedType = type ?? DEFAULT_TRIGGER_TYPE;\n\t\tlet resolvedCommandfor = commandfor ?? context.contentId;\n\t\tlet resolvedCommand = command ?? DEFAULT_TRIGGER_COMMAND;\n\n\t\treturn (\n\t\t\t<button\n\t\t\t\ttype={resolvedType}\n\t\t\t\tcommandfor={resolvedCommandfor}\n\t\t\t\tcommand={resolvedCommand}\n\t\t\t\t{...rest}\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\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(2),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\tdisabled(opacity(50)),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-expanded=\"true\"]', [bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\tdisabled(cursor(\"not-allowed\")),\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 {@link NavigationMenu.Content}, the floating panel a\n * {@link NavigationMenu.Trigger} opens: a {@link Popover} that fades and\n * scales itself using the platform's own `:popover-open` state.\n *\n * @param handle Runtime handle carrying the host's {@link Popover} props.\n * @returns The render function producing the panel's markup.\n * @example\n * <NavigationMenu.Content>\n * \t<NavigationMenu.ContentList>\n * \t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t</NavigationMenu.ContentList>\n * </NavigationMenu.Content>\n * @example\n * <NavigationMenu.Content size=\"wide\">\n * \t<NavigationMenu.ContentGrid>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t</NavigationMenu.ContentGrid>\n * </NavigationMenu.Content>\n */\nNavigationMenu.Content = function NavigationMenuContent(\n\thandle: Handle<NavigationMenu.ContentProps>,\n) {\n\treturn () => {\n\t\tlet { id, placement, size, mix, ...rest } = handle.props;\n\t\tlet context = handle.context.get(NavigationMenu.Item);\n\t\tlet resolvedId = id ?? context.contentId;\n\t\tlet resolvedPlacement = placement ?? DEFAULT_CONTENT_PLACEMENT;\n\t\tlet resolvedSize = size ?? DEFAULT_CONTENT_SIZE;\n\n\t\treturn (\n\t\t\t<Popover\n\t\t\t\tid={resolvedId}\n\t\t\t\tplacement={resolvedPlacement}\n\t\t\t\tdata-size={resolvedSize}\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\tis(\"max-content\"),\n\t\t\t\t\tminIs(\"11rem\"),\n\t\t\t\t\tsurfaceInset({ scale: 2 }),\n\t\t\t\t\tz(50),\n\t\t\t\t\topacity(0),\n\t\t\t\t\twhen('& [data-slot=\"link\"]', [is(\"full\"), justify(\"start\")]),\n\t\t\t\t\twhen('&[data-size=\"wide\"]', [is(\"28rem\"), maxIs(\"calc(100vw - 2rem)\")]),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\ttransition(\"opacity, scale, display, overlay\", {\n\t\t\t\t\t\tduration: durations.fast,\n\t\t\t\t\t\teasing: easings.standard,\n\t\t\t\t\t}),\n\t\t\t\t\toutlineStyle(\"none\"),\n\t\t\t\t\tscaleProperty(\"0.95\"),\n\t\t\t\t\ttransitionBehavior(\"allow-discrete\"),\n\t\t\t\t\twhen(\"&:popover-open\", [opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\tstartingStyle(when(\"&:popover-open\", [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\tscaleProperty(\"none\"),\n\t\t\t\t\t\ttransitionProperty(\"opacity, display, overlay\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link NavigationMenu.LinkProps.children} as a native `<a>`, followed\n * by its `<link rel=\"prefetch\">` when `prefetch=\"render\"`. `aria-current` marks\n * the active page; `aria-disabled=\"true\"` only mutes it visually.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the link's markup.\n * @example\n * <NavigationMenu.Link href=\"/pricing\">{t(\"nav.pricing\")}</NavigationMenu.Link>\n * @example\n * <NavigationMenu.Link href=\"/docs\" prefetch=\"intent\">{t(\"nav.docs\")}</NavigationMenu.Link>\n * @example\n * <NavigationMenu.Link href=\"/dashboard\" aria-current={pathname === \"/dashboard\" ? \"page\" : undefined}>\n * \t{t(\"nav.dashboard\")}\n * </NavigationMenu.Link>\n */\nNavigationMenu.Link = function NavigationMenuLink(handle: Handle<NavigationMenu.LinkProps>) {\n\treturn () => {\n\t\tlet { prefetch, mix, ...rest } = handle.props;\n\t\tlet resolvedPrefetch = prefetch ?? DEFAULT_PREFETCH;\n\n\t\tlet anchor = (\n\t\t\t<a\n\t\t\t\tdata-slot=\"link\"\n\t\t\t\tdata-rmx-prefetch={prefetchAttribute(resolvedPrefetch)}\n\t\t\t\t{...rest}\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\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tgap(2),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(3),\n\t\t\t\t\tpb(2),\n\t\t\t\t\tleading(1),\n\t\t\t\t\tweight(\"medium\"),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\tbg(\"neutral.bg-tint-hover\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [opacity(50), cursor(\"not-allowed\")]),\n\t\t\t\t\tuserSelect(),\n\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\tfontSize(\"sm\"),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\n\t\tif (!rendersPrefetchHint(resolvedPrefetch, rest.href)) return anchor;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{anchor}\n\t\t\t\t<link rel=\"prefetch\" href={rest.href} />\n\t\t\t</>\n\t\t);\n\t};\n};\n\n/**\n * Renders a shared, animated surface that swaps in the active\n * {@link NavigationMenu.Item}'s content, sized by the custom properties a\n * pairing mixin writes as it measures the active panel and toggles visibility.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the shared frame's markup.\n * @example\n * <NavigationMenu.Viewport data-visible={isMenuOpen || undefined} />\n */\nNavigationMenu.Viewport = function NavigationMenuViewport(\n\thandle: Handle<NavigationMenu.ViewportProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tfloatingSurface(),\n\t\t\t\t\traw({ borderRadius: concentricRadius(surfacePadding(2)) }),\n\t\t\t\t\trelative(),\n\t\t\t\t\tmbs(2),\n\t\t\t\t\toverflow(),\n\t\t\t\t\tis(\"var(--ui-navigation-menu-viewport-inline-size, auto)\"),\n\t\t\t\t\tbs(\"var(--ui-navigation-menu-viewport-block-size, auto)\"),\n\t\t\t\t\topacity(0),\n\t\t\t\t\ttransition(\"inline-size, block-size, opacity, scale\", {\n\t\t\t\t\t\tduration: durations.normal,\n\t\t\t\t\t\teasing: easings.decelerate,\n\t\t\t\t\t}),\n\t\t\t\t\tscaleProperty(\"0.95\"),\n\t\t\t\t\tdata(\"visible\", [opacity(100), scaleProperty(\"none\")]),\n\t\t\t\t\tstartingStyle(data(\"visible\", [opacity(0), scaleProperty(\"0.95\")])),\n\t\t\t\t\tmedia(\"(prefers-reduced-motion: reduce)\", [\n\t\t\t\t\t\tscaleProperty(\"none\"),\n\t\t\t\t\t\ttransitionProperty(\"inline-size, block-size, opacity\"),\n\t\t\t\t\t]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders {@link NavigationMenu.ContentListProps.children} as a plain\n * vertical run of {@link NavigationMenu.Link}s inside\n * {@link NavigationMenu.Content}, for a dropdown that's just a short list.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <NavigationMenu.ContentList>\n * \t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * </NavigationMenu.ContentList>\n */\nNavigationMenu.ContentList = function NavigationMenuContentList(\n\thandle: Handle<NavigationMenu.ContentListProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} mix={[grid(), gap(1), mix]} />;\n\t};\n};\n\n/**\n * Renders {@link NavigationMenu.ContentGridProps.children} as a\n * multi-column layout inside {@link NavigationMenu.Content}: a single column\n * while the panel's own container is narrower than `40rem`, else two columns.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <NavigationMenu.Content size=\"wide\">\n * \t<NavigationMenu.ContentGrid>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t\t<NavigationMenu.ContentColumn>\n * \t\t\t<NavigationMenu.Link href=\"/products/two\">{t(\"products.two\")}</NavigationMenu.Link>\n * \t\t</NavigationMenu.ContentColumn>\n * \t</NavigationMenu.ContentGrid>\n * </NavigationMenu.Content>\n */\nNavigationMenu.ContentGrid = function NavigationMenuContentGrid(\n\thandle: Handle<NavigationMenu.ContentGridProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tmix={[\n\t\t\t\t\tgrid(),\n\t\t\t\t\tgap(4),\n\t\t\t\t\tat(\"40rem\", CONTAINER_NAME, gridTemplate({ columns: \"repeat(2, minmax(0, 1fr))\" })),\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 NavigationMenu.ContentColumnProps.children} as one column of\n * stacked {@link NavigationMenu.Link}s inside a\n * {@link NavigationMenu.ContentGrid}.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the column's markup.\n * @example\n * <NavigationMenu.ContentColumn>\n * \t<NavigationMenu.Link href=\"/products/one\">{t(\"products.one\")}</NavigationMenu.Link>\n * </NavigationMenu.ContentColumn>\n */\nNavigationMenu.ContentColumn = function NavigationMenuContentColumn(\n\thandle: Handle<NavigationMenu.ContentColumnProps>,\n) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <div {...rest} mix={[grid(), gap(1), mix]} />;\n\t};\n};\n"
|
|
13
13
|
},
|
|
14
|
-
"test":
|
|
14
|
+
"test": {
|
|
15
|
+
"path": "navigation-menu.test.tsx",
|
|
16
|
+
"content": "/**\n * Tests for the markup each {@link NavigationMenu.Link} prefetch mode writes:\n * runtime-read modes land on the anchor as `data-rmx-prefetch`, and `\"render\"`\n * places a `<link rel=\"prefetch\">` right after it.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { NavigationMenu } from \"@sdxc/ui/navigation-menu\";\n\ndescribe(\"NavigationMenu.Link prefetch\", () => {\n\ttest(\"writes neither the attribute nor a hint by default\", async () => {\n\t\tlet html = await renderToString(<NavigationMenu.Link href=\"/next\">Docs</NavigationMenu.Link>);\n\n\t\texpect(html).not.toContain(\"data-rmx-prefetch\");\n\t\texpect(html).not.toContain('rel=\"prefetch\"');\n\t});\n\n\ttest.each([\"intent\", \"viewport\"] as const)(\n\t\t'writes data-rmx-prefetch=\"%s\" on the anchor and renders no hint',\n\t\tasync (mode) => {\n\t\t\tlet html = await renderToString(\n\t\t\t\t<NavigationMenu.Link href=\"/next\" prefetch={mode}>\n\t\t\t\t\tDocs\n\t\t\t\t</NavigationMenu.Link>,\n\t\t\t);\n\n\t\t\texpect(html).toMatch(new RegExp(`<a[^>]*data-rmx-prefetch=\"${mode}\"`));\n\t\t\texpect(html).not.toContain('rel=\"prefetch\"');\n\t\t},\n\t);\n\n\ttest('renders a prefetch hint after the anchor, without the attribute, for \"render\"', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<NavigationMenu.Link href=\"/next\" prefetch=\"render\">\n\t\t\t\tDocs\n\t\t\t</NavigationMenu.Link>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"data-rmx-prefetch\");\n\t\texpect(html).toMatch(/<\\/a><link rel=\"prefetch\" href=\"\\/next\"\\s*\\/?>/);\n\t});\n\n\ttest('renders no hint for \"render\" when the anchor has no destination', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<NavigationMenu.Link href=\"\" prefetch=\"render\">\n\t\t\t\tDocs\n\t\t\t</NavigationMenu.Link>,\n\t\t);\n\n\t\texpect(html).not.toContain('rel=\"prefetch\"');\n\t});\n});\n"
|
|
17
|
+
}
|
|
15
18
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pagination",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.24",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Pagination"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "pagination.tsx",
|
|
10
|
-
"content": "/**\n * A navigation landmark for moving between pages of results, composing a\n * `<nav>` root, an `<ul>` list, and `<li>` items around two interactive\n * parts: {@link Pagination.Link} for page-number destinations and\n * {@link Pagination.Button} for previous/next controls. The active page reads\n * straight from the native `aria-current` attribute a consumer sets while\n * rendering the current page's link server-side, with no client-tracked\n * route state anywhere in this module.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, listStyle, pointerEvents } from \"@sdxc/u/general\";\nimport { flex, gap, inlineFlex, items, justify } from \"@sdxc/u/layout\";\nimport { bs, m, minIs, p, pi } from \"@sdxc/u/size\";\nimport { active, hover, when } from \"@sdxc/u/state\";\nimport { tabularNums, text, textDecoration, weight } from \"@sdxc/u/typography\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport {\n\twarnIfNoAccessibleLabel,\n\twarnIfNoAccessibleName,\n} from \"@sdxc/ui/utils\";\n\n/**\n * `type` given to a {@link Pagination.Button} carrying an Invoker Command, for\n * which the platform accepts no other value.\n */\nconst INVOKER_TYPE = \"button\";\n\n/**\n * Prop types for {@link Pagination} and its compound parts.\n */\nexport namespace Pagination {\n\t/**\n\t * Every native `<nav>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface Props extends TagProps<\"nav\"> {}\n\n\t/**\n\t * Every native `<ul>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ListProps extends TagProps<\"ul\"> {}\n\n\t/**\n\t * Every native `<li>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ItemProps extends TagProps<\"li\"> {}\n\n\t/**\n\t * Every native `<a>` attribute, plus the `mix` passthrough. A type alias\n\t * rather than an interface, since native anchor props resolve through a\n\t * conditional type an `interface extends` clause can't statically extend.\n\t */\n\texport type LinkProps = TagProps<\"a\">;\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ButtonProps extends TagProps<\"button\"> {}\n}\n\n/**\n * Renders the pagination's `<nav>` root, laying its single {@link\n * Pagination.List} child out as a centered row. In dev mode, a root missing\n * `aria-label`/`aria-labelledby` logs a `console.warn` for assistive tech.\n *\n * @param handle Runtime handle carrying the host `<nav>`'s props.\n * @returns The render function producing the navigation landmark's markup.\n * @example\n * <Pagination aria-label={t(\"pagination.label\")}>\n * \t<Pagination.List>\n * \t\t<Pagination.Item>\n * \t\t\t<Pagination.Link href=\"?page=1\" aria-current=\"page\">1</Pagination.Link>\n * \t\t</Pagination.Item>\n * \t</Pagination.List>\n * </Pagination>\n */\nexport function Pagination(handle: Handle<Pagination.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Pagination: needs an \"aria-label\" or \"aria-labelledby\" identifying which set of results it paginates for assistive technology.',\n\t\t);\n\n\t\treturn <nav {...rest} data-slot=\"pagination\" mix={[flex(), items(\"center\"), mix]} />;\n\t};\n}\n\n/**\n * Renders the pagination's `<ul>` list, resetting native list markers and\n * spacing and laying {@link Pagination.Item} children out as a centered row\n * with a small gap between them.\n *\n * @param handle Runtime handle carrying the host `<ul>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <Pagination.List>\n * \t<Pagination.Item>\n * \t\t<Pagination.Link href=\"?page=1\" aria-current=\"page\">1</Pagination.Link>\n * \t</Pagination.Item>\n * \t<Pagination.Item>\n * \t\t<Pagination.Link href=\"?page=2\">2</Pagination.Link>\n * \t</Pagination.Item>\n * </Pagination.List>\n */\nPagination.List = function PaginationList(handle: Handle<Pagination.ListProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<ul\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"list\"\n\t\t\t\tmix={[flex(), items(\"center\"), gap(\"0.25rem\"), m(\"0\"), p(\"0\"), listStyle(), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single `<li>` wrapping one {@link Pagination.Link} or\n * {@link Pagination.Button}, centering its content — this element carries no\n * visual styling of its own beyond the layout needed to hold its child.\n *\n * @param handle Runtime handle carrying the host `<li>`'s props.\n * @returns The render function producing the item's markup.\n * @example\n * <Pagination.Item>\n * \t<Pagination.Link href=\"?page=3\">3</Pagination.Link>\n * </Pagination.Item>\n */\nPagination.Item = function PaginationItem(handle: Handle<Pagination.ItemProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <li {...rest} data-slot=\"item\" mix={[flex(), items(\"center\"), mix]} />;\n\t};\n};\n\n/**\n * Renders a page-number destination as a native `<a>`. Setting\n * `aria-current=\"page\"` fills it with the active-page treatment, and\n * `aria-disabled=\"true\"` mutes it and blocks pointer interaction.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the link's markup.\n * @example\n * <Pagination.Link href=\"?page=4\">4</Pagination.Link>\n * @example\n * <Pagination.Link href=\"?page=5\" aria-current=\"page\">5</Pagination.Link>\n * @example\n * <Pagination.Link aria-disabled=\"true\">…</Pagination.Link>\n */\nPagination.Link = function PaginationLink(handle: Handle<Pagination.LinkProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"link\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tbs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\tminIs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [cursor(\"not-allowed\"), pointerEvents()]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a previous/next control as a native `<button>`. A control with\n * `command`/`commandfor` renders `type=\"button\"` first, since the platform's\n * ambiguity check can't see a `type` written after those attributes.\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 * <Pagination.Button aria-label={t(\"pagination.previous\")} disabled={!hasPreviousPage}>\n * \t<ChevronLeftIcon aria-hidden />\n * </Pagination.Button>\n * @example\n * <Pagination.Button aria-label={t(\"pagination.next\")} disabled={!hasNextPage}>\n * \t<ChevronRightIcon aria-hidden />\n * </Pagination.Button>\n */\nPagination.Button = function PaginationButton(handle: Handle<Pagination.ButtonProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\t\tlet isInvoker = rest.command !== undefined || rest.commandfor !== undefined;\n\t\tlet resolvedType = type ?? (isInvoker ? INVOKER_TYPE : undefined);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Pagination.Button: 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={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tbs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\tminIs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\twhen(\"&:disabled\", opacity(50)),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</button>\n\t\t);\n\t};\n};\n"
|
|
10
|
+
"content": "/**\n * A navigation landmark for moving between pages of results, composing a\n * `<nav>` root, an `<ul>` list, and `<li>` items around two interactive\n * parts: {@link Pagination.Link} for page-number destinations and\n * {@link Pagination.Button} for previous/next controls. The active page reads\n * straight from the native `aria-current` attribute a consumer sets while\n * rendering the current page's link server-side, with no client-tracked\n * route state anywhere in this module.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded } from \"@sdxc/u/effects\";\nimport { cursor, listStyle, pointerEvents } from \"@sdxc/u/general\";\nimport { flex, gap, inlineFlex, items, justify } from \"@sdxc/u/layout\";\nimport { bs, m, minIs, p, pi } from \"@sdxc/u/size\";\nimport { active, hover, when } from \"@sdxc/u/state\";\nimport { tabularNums, text, textDecoration, weight } from \"@sdxc/u/typography\";\n\nimport type { LinkPrefetch } from \"@sdxc/ui/utils\";\n\nimport { interactiveTransition } from \"@sdxc/ui/styles\";\nimport { prefetchAttribute, rendersPrefetchHint } from \"@sdxc/ui/utils\";\nimport {\n\twarnIfNoAccessibleLabel,\n\twarnIfNoAccessibleName,\n} from \"@sdxc/ui/utils\";\n\n/**\n * `type` given to a {@link Pagination.Button} carrying an Invoker Command, for\n * which the platform accepts no other value.\n */\nconst INVOKER_TYPE = \"button\";\n\n/** Prefetch mode {@link Pagination.Link} falls back to when `prefetch` is omitted. */\nconst DEFAULT_PREFETCH: Pagination.Prefetch = \"none\";\n\n/**\n * Prop types for {@link Pagination} and its compound parts.\n */\nexport namespace Pagination {\n\t/**\n\t * Every native `<nav>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface Props extends TagProps<\"nav\"> {}\n\n\t/**\n\t * Every native `<ul>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ListProps extends TagProps<\"ul\"> {}\n\n\t/**\n\t * Every native `<li>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ItemProps extends TagProps<\"li\"> {}\n\n\t/**\n\t * When a {@link Pagination.Link}'s destination starts loading, the same\n\t * modes every link component in this library accepts.\n\t */\n\texport type Prefetch = LinkPrefetch;\n\n\t/**\n\t * Every native `<a>` attribute, plus `prefetch` and the `mix` passthrough. A\n\t * type alias rather than an interface, since native anchor props resolve\n\t * through a conditional type an `interface extends` clause can't extend.\n\t */\n\texport type LinkProps = TagProps<\"a\"> & {\n\t\t/**\n\t\t * `\"intent\"`/`\"viewport\"` write `data-rmx-prefetch`; `\"render\"` adds a `<link rel=\"prefetch\">`\n\t\t * that also serves full-document navigations. The next-page link suits `\"render\"` or\n\t\t * `\"intent\"`. Defaults to {@link DEFAULT_PREFETCH}.\n\t\t */\n\t\tprefetch?: Prefetch;\n\t};\n\n\t/**\n\t * Every native `<button>` attribute, unchanged, plus the `mix` passthrough.\n\t */\n\texport interface ButtonProps extends TagProps<\"button\"> {}\n}\n\n/**\n * Renders the pagination's `<nav>` root, laying its single {@link\n * Pagination.List} child out as a centered row. In dev mode, a root missing\n * `aria-label`/`aria-labelledby` logs a `console.warn` for assistive tech.\n *\n * @param handle Runtime handle carrying the host `<nav>`'s props.\n * @returns The render function producing the navigation landmark's markup.\n * @example\n * <Pagination aria-label={t(\"pagination.label\")}>\n * \t<Pagination.List>\n * \t\t<Pagination.Item>\n * \t\t\t<Pagination.Link href=\"?page=1\" aria-current=\"page\">1</Pagination.Link>\n * \t\t</Pagination.Item>\n * \t</Pagination.List>\n * </Pagination>\n */\nexport function Pagination(handle: Handle<Pagination.Props>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\twarnIfNoAccessibleLabel(\n\t\t\thandle.props,\n\t\t\t'Pagination: needs an \"aria-label\" or \"aria-labelledby\" identifying which set of results it paginates for assistive technology.',\n\t\t);\n\n\t\treturn <nav {...rest} data-slot=\"pagination\" mix={[flex(), items(\"center\"), mix]} />;\n\t};\n}\n\n/**\n * Renders the pagination's `<ul>` list, resetting native list markers and\n * spacing and laying {@link Pagination.Item} children out as a centered row\n * with a small gap between them.\n *\n * @param handle Runtime handle carrying the host `<ul>`'s props.\n * @returns The render function producing the list's markup.\n * @example\n * <Pagination.List>\n * \t<Pagination.Item>\n * \t\t<Pagination.Link href=\"?page=1\" aria-current=\"page\">1</Pagination.Link>\n * \t</Pagination.Item>\n * \t<Pagination.Item>\n * \t\t<Pagination.Link href=\"?page=2\">2</Pagination.Link>\n * \t</Pagination.Item>\n * </Pagination.List>\n */\nPagination.List = function PaginationList(handle: Handle<Pagination.ListProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<ul\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"list\"\n\t\t\t\tmix={[flex(), items(\"center\"), gap(\"0.25rem\"), m(\"0\"), p(\"0\"), listStyle(), mix]}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/**\n * Renders a single `<li>` wrapping one {@link Pagination.Link} or\n * {@link Pagination.Button}, centering its content — this element carries no\n * visual styling of its own beyond the layout needed to hold its child.\n *\n * @param handle Runtime handle carrying the host `<li>`'s props.\n * @returns The render function producing the item's markup.\n * @example\n * <Pagination.Item>\n * \t<Pagination.Link href=\"?page=3\">3</Pagination.Link>\n * </Pagination.Item>\n */\nPagination.Item = function PaginationItem(handle: Handle<Pagination.ItemProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn <li {...rest} data-slot=\"item\" mix={[flex(), items(\"center\"), mix]} />;\n\t};\n};\n\n/**\n * Renders a page-number destination as a native `<a>`, followed by its\n * `<link rel=\"prefetch\">` when `prefetch=\"render\"`. `aria-current=\"page\"` fills\n * it with the active-page treatment; `aria-disabled=\"true\"` mutes it.\n *\n * @param handle Runtime handle carrying the host `<a>`'s props.\n * @returns The render function producing the link's markup.\n * @example\n * <Pagination.Link href=\"?page=6\" prefetch=\"render\">6</Pagination.Link>\n * @example\n * <Pagination.Link href=\"?page=5\" aria-current=\"page\">5</Pagination.Link>\n * @example\n * <Pagination.Link aria-disabled=\"true\">…</Pagination.Link>\n */\nPagination.Link = function PaginationLink(handle: Handle<Pagination.LinkProps>) {\n\treturn () => {\n\t\tlet { prefetch, mix, ...rest } = handle.props;\n\t\tlet resolvedPrefetch = prefetch ?? DEFAULT_PREFETCH;\n\n\t\tlet anchor = (\n\t\t\t<a\n\t\t\t\tdata-rmx-prefetch={prefetchAttribute(resolvedPrefetch)}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"link\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tbs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\tminIs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen('&[aria-current]:not([aria-current=\"false\"])', [\n\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', opacity(50)),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\ttextDecoration(\"none\"),\n\t\t\t\t\twhen('&[aria-disabled=\"true\"]', [cursor(\"not-allowed\"), pointerEvents()]),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\n\t\tif (!rendersPrefetchHint(resolvedPrefetch, rest.href)) return anchor;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{anchor}\n\t\t\t\t<link rel=\"prefetch\" href={rest.href} />\n\t\t\t</>\n\t\t);\n\t};\n};\n\n/**\n * Renders a previous/next control as a native `<button>`. A control with\n * `command`/`commandfor` renders `type=\"button\"` first, since the platform's\n * ambiguity check can't see a `type` written after those attributes.\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 * <Pagination.Button aria-label={t(\"pagination.previous\")} disabled={!hasPreviousPage}>\n * \t<ChevronLeftIcon aria-hidden />\n * </Pagination.Button>\n * @example\n * <Pagination.Button aria-label={t(\"pagination.next\")} disabled={!hasNextPage}>\n * \t<ChevronRightIcon aria-hidden />\n * </Pagination.Button>\n */\nPagination.Button = function PaginationButton(handle: Handle<Pagination.ButtonProps>) {\n\treturn () => {\n\t\tlet { type, children, mix, ...rest } = handle.props;\n\t\tlet isInvoker = rest.command !== undefined || rest.commandfor !== undefined;\n\t\tlet resolvedType = type ?? (isInvoker ? INVOKER_TYPE : undefined);\n\n\t\twarnIfNoAccessibleName(\n\t\t\thandle.props,\n\t\t\tchildren,\n\t\t\t'Pagination.Button: 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={resolvedType}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"button\"\n\t\t\t\tmix={[\n\t\t\t\t\tinteractiveTransition(),\n\t\t\t\t\tinlineFlex(),\n\t\t\t\t\titems(\"center\"),\n\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\tbs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\tminIs(\"var(--ui-pagination-control-size, 2.25rem)\"),\n\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\tpi(\"0.75rem\"),\n\t\t\t\t\tweight(500),\n\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\thover([bg(\"neutral.bg-tint-hover\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\tactive(bg(\"neutral.bg-tint-pressed\")),\n\t\t\t\t\twhen(\"&:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\twhen(\"&:disabled\", opacity(50)),\n\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\ttabularNums(),\n\t\t\t\t\twhen(\"&:disabled\", cursor(\"not-allowed\")),\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</button>\n\t\t);\n\t};\n};\n"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "pagination.test.tsx",
|
|
14
|
-
"content": "/**\n * Tests for the `type` {@link Pagination.Button} resolves: a control carrying an\n * Invoker Command renders `type=\"button\"` on its own, before the command\n * attributes, because inside a `<form>` an untyped button is a submit button and\n * the platform then refuses to run its command at all — judging that while it\n * parses `command`/`commandfor`, so a `type` written after them is refused the\n * same way.
|
|
14
|
+
"content": "/**\n * Tests for the `type` {@link Pagination.Button} resolves: a control carrying an\n * Invoker Command renders `type=\"button\"` on its own, before the command\n * attributes, because inside a `<form>` an untyped button is a submit button and\n * the platform then refuses to run its command at all — judging that while it\n * parses `command`/`commandfor`, so a `type` written after them is refused the\n * same way. Also covers the markup each {@link Pagination.Link} prefetch mode writes.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Pagination } from \"@sdxc/ui/pagination\";\n\ndescribe(\"Pagination.Button\", () => {\n\ttest('types itself \"button\" when it carries a command, so its command survives inside a form', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Pagination.Button aria-label=\"Next\" commandfor=\"results\" command=\"next\">\n\t\t\t\tNext\n\t\t\t</Pagination.Button>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest('types itself \"button\" when it carries only a commandfor', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Pagination.Button aria-label=\"Next\" commandfor=\"results\">\n\t\t\t\tNext\n\t\t\t</Pagination.Button>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"button\"');\n\t});\n\n\ttest(\"renders no type of its own for a control carrying no command\", async () => {\n\t\tlet html = await renderToString(<Pagination.Button aria-label=\"Next\">Next</Pagination.Button>);\n\n\t\texpect(html).not.toContain(\"type=\");\n\t});\n\n\ttest(\"leaves an explicitly typed submit control alone\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Pagination.Button aria-label=\"Next\" type=\"submit\">\n\t\t\t\tNext\n\t\t\t</Pagination.Button>,\n\t\t);\n\n\t\texpect(html).toContain('type=\"submit\"');\n\t});\n\n\ttest(\"writes type before the command attributes, which is where the platform reads it\", async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Pagination.Button aria-label=\"Next\" commandfor=\"results\" command=\"next\">\n\t\t\t\tNext\n\t\t\t</Pagination.Button>,\n\t\t);\n\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"commandfor=\"));\n\t\texpect(html.indexOf('type=\"button\"')).toBeLessThan(html.indexOf(\"command=\"));\n\t});\n});\n\ndescribe(\"Pagination.Link prefetch\", () => {\n\ttest(\"writes neither the attribute nor a hint by default\", async () => {\n\t\tlet html = await renderToString(<Pagination.Link href=\"/next\">2</Pagination.Link>);\n\n\t\texpect(html).not.toContain(\"data-rmx-prefetch\");\n\t\texpect(html).not.toContain('rel=\"prefetch\"');\n\t});\n\n\ttest.each([\"intent\", \"viewport\"] as const)(\n\t\t'writes data-rmx-prefetch=\"%s\" on the anchor and renders no hint',\n\t\tasync (mode) => {\n\t\t\tlet html = await renderToString(\n\t\t\t\t<Pagination.Link href=\"/next\" prefetch={mode}>\n\t\t\t\t\t2\n\t\t\t\t</Pagination.Link>,\n\t\t\t);\n\n\t\t\texpect(html).toMatch(new RegExp(`<a[^>]*data-rmx-prefetch=\"${mode}\"`));\n\t\t\texpect(html).not.toContain('rel=\"prefetch\"');\n\t\t},\n\t);\n\n\ttest('renders a prefetch hint after the anchor, without the attribute, for \"render\"', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Pagination.Link href=\"/next\" prefetch=\"render\">\n\t\t\t\t2\n\t\t\t</Pagination.Link>,\n\t\t);\n\n\t\texpect(html).not.toContain(\"data-rmx-prefetch\");\n\t\texpect(html).toMatch(/<\\/a><link rel=\"prefetch\" href=\"\\/next\"\\s*\\/?>/);\n\t});\n\n\ttest('renders no hint for \"render\" when the anchor has no destination', async () => {\n\t\tlet html = await renderToString(\n\t\t\t<Pagination.Link href=\"\" prefetch=\"render\">\n\t\t\t\t2\n\t\t\t</Pagination.Link>,\n\t\t);\n\n\t\texpect(html).not.toContain('rel=\"prefetch\"');\n\t});\n});\n"
|
|
15
15
|
}
|
|
16
16
|
}
|