@charcuterie/ui 3.23.0 → 3.24.0
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/dist/Board/Board.d.ts +6 -3
- package/dist/Board/Board.d.ts.map +1 -1
- package/dist/Board/Board.js +19 -1
- package/dist/Board/Board.js.map +1 -1
- package/dist/Board/BoardCard.d.ts +42 -7
- package/dist/Board/BoardCard.d.ts.map +1 -1
- package/dist/Board/BoardCard.js +54 -8
- package/dist/Board/BoardCard.js.map +1 -1
- package/dist/Nav/Nav.d.ts +167 -0
- package/dist/Nav/Nav.d.ts.map +1 -0
- package/dist/Nav/Nav.js +165 -0
- package/dist/Nav/Nav.js.map +1 -0
- package/dist/Nav/NavLink.d.ts +43 -0
- package/dist/Nav/NavLink.d.ts.map +1 -0
- package/dist/Nav/NavLink.js +111 -0
- package/dist/Nav/NavLink.js.map +1 -0
- package/dist/Nav/navItems.d.ts +67 -0
- package/dist/Nav/navItems.d.ts.map +1 -0
- package/dist/Nav/navItems.js +104 -0
- package/dist/Nav/navItems.js.map +1 -0
- package/dist/Nav/useNavLayout.d.ts +86 -0
- package/dist/Nav/useNavLayout.d.ts.map +1 -0
- package/dist/Nav/useNavLayout.js +114 -0
- package/dist/Nav/useNavLayout.js.map +1 -0
- package/dist/NavBar/NavBar.d.ts +37 -111
- package/dist/NavBar/NavBar.d.ts.map +1 -1
- package/dist/NavBar/NavBar.js +30 -110
- package/dist/NavBar/NavBar.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Board/Board.mdx +25 -2
- package/src/Board/Board.stories.tsx +52 -1
- package/src/Board/Board.test.tsx +82 -0
- package/src/Board/Board.tsx +24 -4
- package/src/Board/BoardCard.tsx +103 -21
- package/src/Board/boardMoveHandleContainer.test.ts +54 -0
- package/src/Nav/Nav.mdx +169 -0
- package/src/Nav/Nav.stories.tsx +402 -0
- package/src/Nav/Nav.test.tsx +338 -0
- package/src/Nav/Nav.tsx +406 -0
- package/src/Nav/NavLink.tsx +220 -0
- package/src/Nav/navItems.test.ts +163 -0
- package/src/Nav/navItems.ts +175 -0
- package/src/Nav/useNavLayout.ts +197 -0
- package/src/NavBar/NavBar.mdx +26 -0
- package/src/NavBar/NavBar.tsx +54 -240
- package/src/index.ts +20 -1
- package/src/sourceRules.test.ts +13 -1
- package/dist/NavBar/NavBarLink.d.ts +0 -43
- package/dist/NavBar/NavBarLink.d.ts.map +0 -1
- package/dist/NavBar/NavBarLink.js +0 -67
- package/dist/NavBar/NavBarLink.js.map +0 -1
- package/dist/NavBar/navBarCurrent.d.ts +0 -37
- package/dist/NavBar/navBarCurrent.d.ts.map +0 -1
- package/dist/NavBar/navBarCurrent.js +0 -48
- package/dist/NavBar/navBarCurrent.js.map +0 -1
- package/src/NavBar/NavBarLink.tsx +0 -139
- package/src/NavBar/navBarCurrent.test.ts +0 -81
- package/src/NavBar/navBarCurrent.ts +0 -64
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ControlSize } from "@charcuterie/tokens";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { NavItem } from "./navItems.ts";
|
|
4
|
+
/** Where the row is drawn. Each paints differently; all are links. */
|
|
5
|
+
export type NavLinkPlacement = "bar" | "bottom" | "panel" | "rail" | "railIcons";
|
|
6
|
+
export type NavLinkProps = {
|
|
7
|
+
isCurrent: boolean;
|
|
8
|
+
item: NavItem;
|
|
9
|
+
/**
|
|
10
|
+
* Fires when the reader activates this link **in a way that keeps
|
|
11
|
+
* them on the page** — a plain left click, Enter, Space. It is
|
|
12
|
+
* what closes the panel behind them.
|
|
13
|
+
*
|
|
14
|
+
* A modified click (ctrl, meta, shift, alt) opens a new tab and
|
|
15
|
+
* leaves this document exactly where it was, so it deliberately
|
|
16
|
+
* does not fire: shutting the menu the reader is still working
|
|
17
|
+
* through is the behaviour that makes people stop ctrl-clicking.
|
|
18
|
+
*/
|
|
19
|
+
onNavigate?: () => void;
|
|
20
|
+
placement: NavLinkPlacement;
|
|
21
|
+
size: ControlSize;
|
|
22
|
+
/** Hands the bar row's box to the measuring hook. Bar only. */
|
|
23
|
+
trackElement?: (element: HTMLElement | null) => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* One destination — and it is a real `<a href>` in every placement.
|
|
27
|
+
*
|
|
28
|
+
* That is the whole reason this exists rather than the `Menu` a
|
|
29
|
+
* collapsed `Toolbar` opens: `MenuItem` is `{ label, onSelect }`, so
|
|
30
|
+
* a nav folded into one becomes a row of `<button>`s. It looks
|
|
31
|
+
* identical in a screenshot and it loses middle-click, ctrl-click,
|
|
32
|
+
* "open in a new tab", "copy link address", the status bar, and the
|
|
33
|
+
* browser's own visited styling. `BuildingAnApp.mdx` names
|
|
34
|
+
* `<button onClick={navigate}>` as the fleet's most common
|
|
35
|
+
* navigation defect; a collapse mechanism that introduced it at
|
|
36
|
+
* narrow widths would be that defect on a timer.
|
|
37
|
+
*
|
|
38
|
+
* The router seam is `ButtonLink`'s, unchanged: an external
|
|
39
|
+
* destination or a fragment falls back to a plain anchor rather than
|
|
40
|
+
* being pushed onto a history stack that has no route for it.
|
|
41
|
+
*/
|
|
42
|
+
export declare const NavLink: ({ isCurrent, item, onNavigate, placement, size, trackElement, }: NavLinkProps) => ReactNode;
|
|
43
|
+
//# sourceMappingURL=NavLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavLink.d.ts","sourceRoot":"","sources":["../../src/Nav/NavLink.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,KAAK,EAAc,SAAS,EAAE,MAAM,OAAO,CAAA;AAWlD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GACxB,KAAK,GACL,QAAQ,GACR,OAAO,GACP,MAAM,GACN,WAAW,CAAA;AAEf,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,OAAO,CAAA;IAClB,IAAI,EAAE,OAAO,CAAA;IACb;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,CAAA;IACvB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,IAAI,EAAE,WAAW,CAAA;IACjB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAA;CACrD,CAAA;AAiDD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,OAAO,GAAI,iEAOrB,YAAY,KAAG,SA0GjB,CAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CONTROL_SIZE_CLASS, PANEL_ITEM_SIZE_CLASS, } from "../controlStyles.js";
|
|
3
|
+
import { FOCUS_RING_CLASS } from "../intentStyles.js";
|
|
4
|
+
import { useRouterLink } from "../RouterLink/RouterLinkProvider.js";
|
|
5
|
+
import { getIsRoutedHref } from "../RouterLink/routerLink.js";
|
|
6
|
+
import { toClassName } from "../toClassName.js";
|
|
7
|
+
import { VisuallyHidden } from "../VisuallyHidden/VisuallyHidden.js";
|
|
8
|
+
const PLACEMENT_CLASS = {
|
|
9
|
+
bar: "inline-flex shrink-0 items-center rounded-md border border-transparent whitespace-nowrap",
|
|
10
|
+
// A foot-of-the-screen target is a thumb target, so it takes the
|
|
11
|
+
// 44px WCAG 2.5.5 floor rather than a control height. It is a
|
|
12
|
+
// genuinely standalone tap target and shares a row with nothing,
|
|
13
|
+
// which is the case
|
|
14
|
+
// `2026-08-05-controls-share-one-height-no-per-component-touch-floor`
|
|
15
|
+
// reserves `MIN_TOUCH_TARGET_CLASS` for.
|
|
16
|
+
bottom: "flex min-h-(--control-min-touch-target) flex-col items-center justify-center gap-1 rounded-none px-1 py-2 text-xs",
|
|
17
|
+
panel: "flex w-full items-center rounded-sm text-start",
|
|
18
|
+
rail: "flex w-full items-center rounded-md",
|
|
19
|
+
// Square, and sized on both axes from the height token — the same
|
|
20
|
+
// rule `ICON_CONTROL_SIZE_CLASS` states, so a collapsed rail item
|
|
21
|
+
// and an `IconButton` beside it measure the same.
|
|
22
|
+
railIcons: "flex size-(--control-height-lg) items-center justify-center rounded-md",
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* `-hover` in the panel, not the plain surface: the panel is drawn
|
|
26
|
+
* on `surface-overlay`, which every dark scheme paints *lighter*
|
|
27
|
+
* than the base tint, so the plain one reads as no change at all.
|
|
28
|
+
* Same correction `MenuAction` carries.
|
|
29
|
+
*/
|
|
30
|
+
const CURRENT_CLASS = {
|
|
31
|
+
bar: "bg-intent-neutral-surface font-medium text-content-primary",
|
|
32
|
+
bottom: "bg-intent-neutral-surface font-medium text-content-primary",
|
|
33
|
+
panel: "bg-intent-neutral-surface-hover font-medium text-content-primary",
|
|
34
|
+
rail: "bg-intent-neutral-surface font-medium text-content-primary",
|
|
35
|
+
railIcons: "bg-intent-neutral-surface font-medium text-content-primary",
|
|
36
|
+
};
|
|
37
|
+
const RESTING_CLASS = {
|
|
38
|
+
bar: "text-content-secondary hover:bg-intent-neutral-surface hover:text-content-primary",
|
|
39
|
+
bottom: "text-content-secondary hover:bg-intent-neutral-surface hover:text-content-primary",
|
|
40
|
+
panel: "text-content-primary hover:bg-intent-neutral-surface-hover",
|
|
41
|
+
rail: "text-content-secondary hover:bg-intent-neutral-surface hover:text-content-primary",
|
|
42
|
+
railIcons: "text-content-secondary hover:bg-intent-neutral-surface hover:text-content-primary",
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* One destination — and it is a real `<a href>` in every placement.
|
|
46
|
+
*
|
|
47
|
+
* That is the whole reason this exists rather than the `Menu` a
|
|
48
|
+
* collapsed `Toolbar` opens: `MenuItem` is `{ label, onSelect }`, so
|
|
49
|
+
* a nav folded into one becomes a row of `<button>`s. It looks
|
|
50
|
+
* identical in a screenshot and it loses middle-click, ctrl-click,
|
|
51
|
+
* "open in a new tab", "copy link address", the status bar, and the
|
|
52
|
+
* browser's own visited styling. `BuildingAnApp.mdx` names
|
|
53
|
+
* `<button onClick={navigate}>` as the fleet's most common
|
|
54
|
+
* navigation defect; a collapse mechanism that introduced it at
|
|
55
|
+
* narrow widths would be that defect on a timer.
|
|
56
|
+
*
|
|
57
|
+
* The router seam is `ButtonLink`'s, unchanged: an external
|
|
58
|
+
* destination or a fragment falls back to a plain anchor rather than
|
|
59
|
+
* being pushed onto a history stack that has no route for it.
|
|
60
|
+
*/
|
|
61
|
+
export const NavLink = ({ isCurrent, item, onNavigate, placement, size, trackElement, }) => {
|
|
62
|
+
const RouterLink = useRouterLink();
|
|
63
|
+
const isExternal = item.isExternal === true;
|
|
64
|
+
const LinkElement = isExternal || !getIsRoutedHref(item.href)
|
|
65
|
+
? "a"
|
|
66
|
+
: RouterLink;
|
|
67
|
+
const isIconOnly = placement === "railIcons";
|
|
68
|
+
const sizeClass = placement === "panel"
|
|
69
|
+
? PANEL_ITEM_SIZE_CLASS[size]
|
|
70
|
+
: placement === "bar"
|
|
71
|
+
? CONTROL_SIZE_CLASS[size]
|
|
72
|
+
: placement === "rail"
|
|
73
|
+
? "min-h-(--control-height-md) gap-(--control-gap-md) px-(--control-padding-inline-md) py-1.5 text-md"
|
|
74
|
+
: "";
|
|
75
|
+
return (_jsxs(LinkElement
|
|
76
|
+
// The platform's own "you are here", and the reason the paint
|
|
77
|
+
// is never the only signal: a highlight is invisible to a
|
|
78
|
+
// screen reader and to anyone who cannot tell the two surfaces
|
|
79
|
+
// apart. A `font-weight` swap alone is the same WCAG 1.4.1
|
|
80
|
+
// failure.
|
|
81
|
+
, { "aria-current": isCurrent ? "page" : undefined, className: toClassName("no-underline transition-colors duration-(--duration-fast) ease-standard", PLACEMENT_CLASS[placement], sizeClass,
|
|
82
|
+
// Two written-out entries rather than one interpolated
|
|
83
|
+
// string, the same rule `SegmentedOption` follows:
|
|
84
|
+
// Tailwind's scanner cannot see a class that exists only at
|
|
85
|
+
// runtime, and `tailwindCandidates.test.ts` rejects a
|
|
86
|
+
// template literal in a className outright.
|
|
87
|
+
isCurrent
|
|
88
|
+
? CURRENT_CLASS[placement]
|
|
89
|
+
: RESTING_CLASS[placement], FOCUS_RING_CLASS), href: item.href, onClick: (event) => {
|
|
90
|
+
if (event.defaultPrevented ||
|
|
91
|
+
event.button !== 0 ||
|
|
92
|
+
event.altKey ||
|
|
93
|
+
event.ctrlKey ||
|
|
94
|
+
event.metaKey ||
|
|
95
|
+
event.shiftKey) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
onNavigate?.();
|
|
99
|
+
}, ref: (element) => {
|
|
100
|
+
trackElement?.(element);
|
|
101
|
+
},
|
|
102
|
+
// `noreferrer` beside `noopener` on purpose: one closes the
|
|
103
|
+
// `window.opener` hole, the other stops this app's address
|
|
104
|
+
// leaking as the referrer to a product it does not own.
|
|
105
|
+
rel: isExternal ? "noopener noreferrer" : undefined, target: isExternal ? "_blank" : undefined,
|
|
106
|
+
// A pointer can recover the name a collapsed rail has hidden.
|
|
107
|
+
// It is not the accessible name — see the `VisuallyHidden`
|
|
108
|
+
// below — because `title` alone is not reliably announced.
|
|
109
|
+
title: isIconOnly ? item.label : undefined, children: [item.icon === undefined ? null : (_jsx("span", { "aria-hidden": "true", className: "flex shrink-0 text-content-secondary", children: item.icon })), isIconOnly ? (_jsx(VisuallyHidden, { children: item.label })) : (_jsx("span", { className: placement === "bar" ? undefined : "truncate", children: item.label })), isExternal ? (_jsx(VisuallyHidden, { children: "(opens in a new tab)" })) : null] }));
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=NavLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavLink.js","sourceRoot":"","sources":["../../src/Nav/NavLink.tsx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,GAAG,EAAE,CAAC,OAAiC,EAAE,EAAE;YACzC,YAAY,EAAE,CAAC,OAAO,CAAC,CAAA;QACzB,CAAC;QACD,4DAA4D;QAC5D,2DAA2D;QAC3D,wDAAwD;QACxD,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,EACnD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;QACzC,8DAA8D;QAC9D,2DAA2D;QAC3D,2DAA2D;QAC3D,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,aAEzC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAGhC,8BACc,MAAM,EAClB,SAAS,EAAC,sCAAsC,YAE/C,IAAI,CAAC,IAAI,GACL,CACR,EAEA,UAAU,CAAC,CAAC,CAAC,CACZ,KAAC,cAAc,cAAE,IAAI,CAAC,KAAK,GAAkB,CAC9C,CAAC,CAAC,CAAC,CAMF,eACE,SAAS,EACP,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,YAG7C,IAAI,CAAC,KAAK,GACN,CACR,EAEA,UAAU,CAAC,CAAC,CAAC,CACZ,KAAC,cAAc,uCAEE,CAClB,CAAC,CAAC,CAAC,IAAI,IACI,CACf,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type NavItem = {
|
|
3
|
+
/**
|
|
4
|
+
* Where it goes. Routed through the injected `RouterLink` when it
|
|
5
|
+
* is this app's own path, and left to the platform when it is not.
|
|
6
|
+
*/
|
|
7
|
+
href: string;
|
|
8
|
+
/** Decoration beside the label. Never the accessible name. */
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* A destination outside this app. It renders a plain anchor with
|
|
12
|
+
* `target="_blank"` and `rel="noopener noreferrer"`, and it is
|
|
13
|
+
* never current — pushing `https://…` onto a router's history
|
|
14
|
+
* navigates the app to a route it does not have.
|
|
15
|
+
*/
|
|
16
|
+
isExternal?: boolean;
|
|
17
|
+
/** Defaults to `href`, which is already unique in a nav. */
|
|
18
|
+
key?: string;
|
|
19
|
+
/** The visible text, and the accessible name. */
|
|
20
|
+
label: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* What the rail layouts take. `icon` stops being optional, because
|
|
24
|
+
* `railIcons` takes the **label** away: an item with no glyph is a
|
|
25
|
+
* blank square that still navigates, and there is no visual defect
|
|
26
|
+
* to notice because the row reads as padding.
|
|
27
|
+
*
|
|
28
|
+
* Optional would move that failure out of the type checker and into
|
|
29
|
+
* the first time somebody drags a window narrow. The library still
|
|
30
|
+
* ships no icons — a glyph in a default renders as nothing where the
|
|
31
|
+
* font lacks it, so the app brings its own.
|
|
32
|
+
*/
|
|
33
|
+
export type NavRailItem = NavItem & {
|
|
34
|
+
icon: ReactNode;
|
|
35
|
+
};
|
|
36
|
+
export declare const getNavItemKey: (item: NavItem) => string;
|
|
37
|
+
export declare const getIsCurrentHref: ({ currentHref, href, }: {
|
|
38
|
+
/** Where the reader is. `undefined` means "nothing is current". */
|
|
39
|
+
currentHref: string | undefined;
|
|
40
|
+
/** Where this destination goes. */
|
|
41
|
+
href: string;
|
|
42
|
+
}) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The current destination's key, or `null` — the whole-list answer,
|
|
45
|
+
* and the one `Nav` marks with `aria-current="page"`.
|
|
46
|
+
*
|
|
47
|
+
* ## Exactly one, because the deepest match wins
|
|
48
|
+
*
|
|
49
|
+
* `getIsCurrentHref` is asked per item, so a nav holding both
|
|
50
|
+
* `/settings` and `/settings/labels` gets `true` twice while the
|
|
51
|
+
* reader is on the deeper one. Two current items is a nav that has
|
|
52
|
+
* stopped saying anything — the same thing react-router's `<NavLink
|
|
53
|
+
* to="/">` footgun produces — so the longest matching path wins and
|
|
54
|
+
* the shallower section stands down.
|
|
55
|
+
*
|
|
56
|
+
* Longest by **path**, not by array position: an app must be able to
|
|
57
|
+
* list its destinations in the order the product reads (Docket's is
|
|
58
|
+
* the pipeline) without that order deciding which one lights up.
|
|
59
|
+
*
|
|
60
|
+
* ## An external item is never current
|
|
61
|
+
*
|
|
62
|
+
* It is not a place inside this app, so no address the app is at can
|
|
63
|
+
* be it. Without this, an item pointing at `https://example.com/board`
|
|
64
|
+
* matches the app's own `/board` on a plain string compare.
|
|
65
|
+
*/
|
|
66
|
+
export declare const resolveActiveKey: (items: readonly NavItem[], activeHref?: string) => string | null;
|
|
67
|
+
//# sourceMappingURL=navItems.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navItems.d.ts","sourceRoot":"","sources":["../../src/Nav/navItems.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,MAAM,MAAM,OAAO,GAAG;IACpB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,8DAA8D;IAC9D,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,4DAA4D;IAC5D,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG;IAClC,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,MAAM,OAAO,KAAG,MACvB,CAAA;AA8CvB,eAAO,MAAM,gBAAgB,GAAI,wBAG9B;IACD,mEAAmE;IACnE,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAA;CACb,KAAG,OAgBH,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,gBAAgB,GAC3B,OAAO,SAAS,OAAO,EAAE,EACzB,aAAa,MAAM,KAClB,MAAM,GAAG,IAqCX,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export const getNavItemKey = (item) => item.key ?? item.href;
|
|
2
|
+
/**
|
|
3
|
+
* Which destination the reader is on — the rule behind
|
|
4
|
+
* `aria-current="page"`, kept pure so it can be checked in Node.
|
|
5
|
+
*
|
|
6
|
+
* The library is router-agnostic (see `RouterLinkProvider`), so it
|
|
7
|
+
* cannot ask a router which link is active. The app hands it one
|
|
8
|
+
* string — `useLocation().pathname`, `window.location.pathname`,
|
|
9
|
+
* whatever it has — and this decides the rest.
|
|
10
|
+
*
|
|
11
|
+
* ## A parent path is current for its children
|
|
12
|
+
*
|
|
13
|
+
* `/tasks` is current while the reader is on `/tasks/41`, because a
|
|
14
|
+
* nav item names a **section** and a section does not stop being the
|
|
15
|
+
* one you are in when you open something inside it. The match is on
|
|
16
|
+
* whole segments: `/task` is *not* current for `/tasks`, which a bare
|
|
17
|
+
* `startsWith` would get wrong.
|
|
18
|
+
*
|
|
19
|
+
* ## `/` is exact, and that is deliberately not react-router
|
|
20
|
+
*
|
|
21
|
+
* react-router's `<NavLink to="/">` is active on **every** route
|
|
22
|
+
* unless the caller remembers `end`, which is the footgun behind
|
|
23
|
+
* every "why is Home always highlighted" bug in the fleet. The root
|
|
24
|
+
* matches only itself here, and there is no prop to change it: a nav
|
|
25
|
+
* with two current items is a nav that has stopped saying anything.
|
|
26
|
+
*
|
|
27
|
+
* ## The query string and the fragment are not part of the answer
|
|
28
|
+
*
|
|
29
|
+
* `/backlog?focus=search` is still the Backlog. Sorting a list does
|
|
30
|
+
* not move the reader to a different destination.
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ **This answers for ONE item, so it cannot keep the promise in
|
|
33
|
+
* the paragraph above by itself.** Given `/settings` and
|
|
34
|
+
* `/settings/labels`, it says `true` for both on the deeper path.
|
|
35
|
+
* `resolveActiveKey` is the whole-list answer, and it is what `Nav`
|
|
36
|
+
* uses; reach for this one only when there is a single link to test.
|
|
37
|
+
*/
|
|
38
|
+
const toComparablePath = (href) => {
|
|
39
|
+
const path = href.split(/[#?]/u)[0] ?? "";
|
|
40
|
+
// A trailing slash is the same place, so it must not change the
|
|
41
|
+
// answer — but `/` itself has to survive being trimmed.
|
|
42
|
+
return path.length > 1 ? path.replace(/\/+$/u, "") : path;
|
|
43
|
+
};
|
|
44
|
+
export const getIsCurrentHref = ({ currentHref, href, }) => {
|
|
45
|
+
if (currentHref === undefined) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const current = toComparablePath(currentHref);
|
|
49
|
+
const target = toComparablePath(href);
|
|
50
|
+
if (target === "" || target === "/") {
|
|
51
|
+
return current === target;
|
|
52
|
+
}
|
|
53
|
+
return (current === target || current.startsWith(`${target}/`));
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The current destination's key, or `null` — the whole-list answer,
|
|
57
|
+
* and the one `Nav` marks with `aria-current="page"`.
|
|
58
|
+
*
|
|
59
|
+
* ## Exactly one, because the deepest match wins
|
|
60
|
+
*
|
|
61
|
+
* `getIsCurrentHref` is asked per item, so a nav holding both
|
|
62
|
+
* `/settings` and `/settings/labels` gets `true` twice while the
|
|
63
|
+
* reader is on the deeper one. Two current items is a nav that has
|
|
64
|
+
* stopped saying anything — the same thing react-router's `<NavLink
|
|
65
|
+
* to="/">` footgun produces — so the longest matching path wins and
|
|
66
|
+
* the shallower section stands down.
|
|
67
|
+
*
|
|
68
|
+
* Longest by **path**, not by array position: an app must be able to
|
|
69
|
+
* list its destinations in the order the product reads (Docket's is
|
|
70
|
+
* the pipeline) without that order deciding which one lights up.
|
|
71
|
+
*
|
|
72
|
+
* ## An external item is never current
|
|
73
|
+
*
|
|
74
|
+
* It is not a place inside this app, so no address the app is at can
|
|
75
|
+
* be it. Without this, an item pointing at `https://example.com/board`
|
|
76
|
+
* matches the app's own `/board` on a plain string compare.
|
|
77
|
+
*/
|
|
78
|
+
export const resolveActiveKey = (items, activeHref) => {
|
|
79
|
+
if (activeHref === undefined) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
let matchedItem = null;
|
|
83
|
+
let matchedLength = -1;
|
|
84
|
+
for (const item of items) {
|
|
85
|
+
if (item.isExternal === true) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (!getIsCurrentHref({
|
|
89
|
+
currentHref: activeHref,
|
|
90
|
+
href: item.href,
|
|
91
|
+
})) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const candidateLength = toComparablePath(item.href).length;
|
|
95
|
+
if (candidateLength > matchedLength) {
|
|
96
|
+
matchedItem = item;
|
|
97
|
+
matchedLength = candidateLength;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return matchedItem === null
|
|
101
|
+
? null
|
|
102
|
+
: getNavItemKey(matchedItem);
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=navItems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navItems.js","sourceRoot":"","sources":["../../src/Nav/navItems.ts"],"names":[],"mappings":"AAsCA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAa,EAAU,EAAE,CACrD,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,CAAA;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAU,EAAE;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAEzC,gEAAgE;IAChE,wDAAwD;IACxD,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAA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;YACpC,WAAW,GAAG,IAAI,CAAA;YAElB,aAAa,GAAG,eAAe,CAAA;QACjC,CAAC;IACH,CAAC;IAED,OAAO,WAAW,KAAK,IAAI;QACzB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;AAChC,CAAC,CAAA"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the reader asked for, which is not the same as what they get.
|
|
3
|
+
*
|
|
4
|
+
* `auto` lets the width decide. The other two are a deliberate
|
|
5
|
+
* override and outrank the width — but only where a rail fits at
|
|
6
|
+
* all; see `useNavLayout`.
|
|
7
|
+
*/
|
|
8
|
+
export type NavLayoutMode = "auto" | "collapsed" | "expanded";
|
|
9
|
+
/** The three forms a rail-shaped nav actually takes on screen. */
|
|
10
|
+
export type ResolvedNavLayout = "menu" | "rail" | "railIcons";
|
|
11
|
+
export type UseNavLayoutOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* Below this width the rail drops its labels. Default `64rem`,
|
|
14
|
+
* which is `screen.lg`.
|
|
15
|
+
*/
|
|
16
|
+
iconsBelow?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Below this width there is no rail at all. Default `48rem`, which
|
|
19
|
+
* is `screen.md` — and the same step `Rail` itself collapses at,
|
|
20
|
+
* so the two cannot disagree.
|
|
21
|
+
*/
|
|
22
|
+
menuBelow?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Where the manual choice is remembered. Omit and the override
|
|
25
|
+
* lasts until the tab is closed.
|
|
26
|
+
*
|
|
27
|
+
* Name it for the app (`"queuepilot-nav"`), not for this library:
|
|
28
|
+
* two apps on the same origin share `localStorage`, and this
|
|
29
|
+
* fleet's dev servers all sit on `localhost`.
|
|
30
|
+
*/
|
|
31
|
+
storageKey?: string;
|
|
32
|
+
};
|
|
33
|
+
export type NavLayoutState = {
|
|
34
|
+
/** `true` in `railIcons`. The rail's own collapse control reads it. */
|
|
35
|
+
isCollapsed: boolean;
|
|
36
|
+
/** What to pass to `Nav`'s `layout`. */
|
|
37
|
+
layout: ResolvedNavLayout;
|
|
38
|
+
mode: NavLayoutMode;
|
|
39
|
+
setMode: (mode: NavLayoutMode) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Expanded ⇄ collapsed. From `auto` it goes to whichever of the two
|
|
42
|
+
* is **not** on screen now, so the first press always visibly does
|
|
43
|
+
* something — which "toggle" has to mean or the control reads as
|
|
44
|
+
* broken.
|
|
45
|
+
*/
|
|
46
|
+
toggle: () => void;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The width rule for a rail-shaped navigation, written once.
|
|
50
|
+
*
|
|
51
|
+
* Three states, and the app chooses none of them:
|
|
52
|
+
*
|
|
53
|
+
* | Width | Layout | What the app renders |
|
|
54
|
+
* | --- | --- | --- |
|
|
55
|
+
* | `>= iconsBelow` | `rail` | a `Rail` holding a `Nav` |
|
|
56
|
+
* | `>= menuBelow` | `railIcons` | the same `Rail`, narrower |
|
|
57
|
+
* | below that | `menu` | a trigger in the `Header` |
|
|
58
|
+
*
|
|
59
|
+
* ### Why the app still places it
|
|
60
|
+
*
|
|
61
|
+
* Because the placement genuinely differs and the rule does not. The
|
|
62
|
+
* `menu` state puts a control in the header — a different corner of
|
|
63
|
+
* the page from a side rail — and no amount of restyling moves an
|
|
64
|
+
* element across `Shell`'s grid. So the library owns *which* state
|
|
65
|
+
* is right, at what width, with what override and where the override
|
|
66
|
+
* is remembered; the app owns two `if`s. That is the half that was
|
|
67
|
+
* being rewritten per app, and rewritten differently: Docket's nav
|
|
68
|
+
* wraps to three lines on a phone, mail-sifter collapses at `40rem`,
|
|
69
|
+
* and QueuePilot at `760px`, all of them arrived at alone.
|
|
70
|
+
*
|
|
71
|
+
* ### The override does not reach the narrow state
|
|
72
|
+
*
|
|
73
|
+
* `expanded` on a 390px screen would be a 212px rail beside 178px of
|
|
74
|
+
* content. The width wins there, and the remembered choice is *kept*
|
|
75
|
+
* rather than cleared — rotating a tablet back to landscape restores
|
|
76
|
+
* the rail the reader asked for, instead of silently forgetting it.
|
|
77
|
+
*
|
|
78
|
+
* ### It is a hook, not CSS
|
|
79
|
+
*
|
|
80
|
+
* The same reason `usePanelItemSize` is: a media query can restyle a
|
|
81
|
+
* rail, but it cannot move a control into the header, and it cannot
|
|
82
|
+
* tell the trigger whether to render at all. A resize re-renders;
|
|
83
|
+
* a scheme or density change still does not.
|
|
84
|
+
*/
|
|
85
|
+
export declare const useNavLayout: ({ iconsBelow, menuBelow, storageKey, }?: UseNavLayoutOptions) => NavLayoutState;
|
|
86
|
+
//# sourceMappingURL=useNavLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavLayout.d.ts","sourceRoot":"","sources":["../../src/Nav/useNavLayout.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,WAAW,GACX,UAAU,CAAA;AAEd,kEAAkE;AAClE,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,MAAM,GACN,WAAW,CAAA;AAEf,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,uEAAuE;IACvE,WAAW,EAAE,OAAO,CAAA;IACpB,wCAAwC;IACxC,MAAM,EAAE,iBAAiB,CAAA;IACzB,IAAI,EAAE,aAAa,CAAA;IACnB,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAA;IACtC;;;;;OAKG;IACH,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB,CAAA;AAgDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,YAAY,GAAI,yCAI1B,mBAAwB,KAAG,cAgD7B,CAAA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useMediaQuery } from "@charcuterie/logic";
|
|
2
|
+
import { matchMediaMatcher } from "@charcuterie/logic/browser";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
const DEFAULT_ICONS_BELOW = "64rem";
|
|
5
|
+
const DEFAULT_MENU_BELOW = "48rem";
|
|
6
|
+
const isNavLayoutMode = (value) => value === "auto" ||
|
|
7
|
+
value === "collapsed" ||
|
|
8
|
+
value === "expanded";
|
|
9
|
+
/**
|
|
10
|
+
* `localStorage`, wrapped both ways.
|
|
11
|
+
*
|
|
12
|
+
* It throws in a sandboxed iframe and in some privacy modes, and it
|
|
13
|
+
* does not exist at all while a page renders on a server — a rail
|
|
14
|
+
* that cannot remember its width should still have one.
|
|
15
|
+
*
|
|
16
|
+
* `@charcuterie/logic/browser`'s `localStoragePersistence` is the
|
|
17
|
+
* same shape and is deliberately **not** reused: it validates what
|
|
18
|
+
* it reads with `isColorSchemeMode`, so it answers `null` for every
|
|
19
|
+
* value this hook stores.
|
|
20
|
+
*/
|
|
21
|
+
const readStoredMode = (key) => {
|
|
22
|
+
try {
|
|
23
|
+
const stored = window.localStorage.getItem(key);
|
|
24
|
+
return isNavLayoutMode(stored) ? stored : null;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const writeStoredMode = (key, mode) => {
|
|
31
|
+
try {
|
|
32
|
+
window.localStorage.setItem(key, mode);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// A page that cannot persist still switches for this session.
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The width rule for a rail-shaped navigation, written once.
|
|
40
|
+
*
|
|
41
|
+
* Three states, and the app chooses none of them:
|
|
42
|
+
*
|
|
43
|
+
* | Width | Layout | What the app renders |
|
|
44
|
+
* | --- | --- | --- |
|
|
45
|
+
* | `>= iconsBelow` | `rail` | a `Rail` holding a `Nav` |
|
|
46
|
+
* | `>= menuBelow` | `railIcons` | the same `Rail`, narrower |
|
|
47
|
+
* | below that | `menu` | a trigger in the `Header` |
|
|
48
|
+
*
|
|
49
|
+
* ### Why the app still places it
|
|
50
|
+
*
|
|
51
|
+
* Because the placement genuinely differs and the rule does not. The
|
|
52
|
+
* `menu` state puts a control in the header — a different corner of
|
|
53
|
+
* the page from a side rail — and no amount of restyling moves an
|
|
54
|
+
* element across `Shell`'s grid. So the library owns *which* state
|
|
55
|
+
* is right, at what width, with what override and where the override
|
|
56
|
+
* is remembered; the app owns two `if`s. That is the half that was
|
|
57
|
+
* being rewritten per app, and rewritten differently: Docket's nav
|
|
58
|
+
* wraps to three lines on a phone, mail-sifter collapses at `40rem`,
|
|
59
|
+
* and QueuePilot at `760px`, all of them arrived at alone.
|
|
60
|
+
*
|
|
61
|
+
* ### The override does not reach the narrow state
|
|
62
|
+
*
|
|
63
|
+
* `expanded` on a 390px screen would be a 212px rail beside 178px of
|
|
64
|
+
* content. The width wins there, and the remembered choice is *kept*
|
|
65
|
+
* rather than cleared — rotating a tablet back to landscape restores
|
|
66
|
+
* the rail the reader asked for, instead of silently forgetting it.
|
|
67
|
+
*
|
|
68
|
+
* ### It is a hook, not CSS
|
|
69
|
+
*
|
|
70
|
+
* The same reason `usePanelItemSize` is: a media query can restyle a
|
|
71
|
+
* rail, but it cannot move a control into the header, and it cannot
|
|
72
|
+
* tell the trigger whether to render at all. A resize re-renders;
|
|
73
|
+
* a scheme or density change still does not.
|
|
74
|
+
*/
|
|
75
|
+
export const useNavLayout = ({ iconsBelow = DEFAULT_ICONS_BELOW, menuBelow = DEFAULT_MENU_BELOW, storageKey, } = {}) => {
|
|
76
|
+
// Read once, lazily — a `useState` initialiser, so the stored
|
|
77
|
+
// choice is in place for the first paint and the rail does not
|
|
78
|
+
// open wide and then snap shut.
|
|
79
|
+
const [mode, setStoredMode] = useState(() => (storageKey === undefined
|
|
80
|
+
? null
|
|
81
|
+
: readStoredMode(storageKey)) ?? "auto");
|
|
82
|
+
const { isMatching: isBelowMenu } = useMediaQuery({
|
|
83
|
+
matcher: matchMediaMatcher(`(width < ${menuBelow})`),
|
|
84
|
+
});
|
|
85
|
+
const { isMatching: isBelowIcons } = useMediaQuery({
|
|
86
|
+
matcher: matchMediaMatcher(`(width < ${iconsBelow})`),
|
|
87
|
+
});
|
|
88
|
+
const setMode = (nextMode) => {
|
|
89
|
+
setStoredMode(nextMode);
|
|
90
|
+
if (storageKey !== undefined) {
|
|
91
|
+
writeStoredMode(storageKey, nextMode);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const autoLayout = isBelowIcons
|
|
95
|
+
? "railIcons"
|
|
96
|
+
: "rail";
|
|
97
|
+
const layout = isBelowMenu
|
|
98
|
+
? "menu"
|
|
99
|
+
: mode === "auto"
|
|
100
|
+
? autoLayout
|
|
101
|
+
: mode === "collapsed"
|
|
102
|
+
? "railIcons"
|
|
103
|
+
: "rail";
|
|
104
|
+
return {
|
|
105
|
+
isCollapsed: layout === "railIcons",
|
|
106
|
+
layout,
|
|
107
|
+
mode,
|
|
108
|
+
setMode,
|
|
109
|
+
toggle: () => {
|
|
110
|
+
setMode(layout === "rail" ? "collapsed" : "expanded");
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=useNavLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNavLayout.js","sourceRoot":"","sources":["../../src/Nav/useNavLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AA2DhC,MAAM,mBAAmB,GAAG,OAAO,CAAA;AAEnC,MAAM,kBAAkB,GAAG,OA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