@underpin/ui 2.1.0 → 2.3.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/components/data-table.d.ts +16 -14
- package/components/data-table.js +19 -9
- package/components/data-table.js.map +1 -1
- package/components/menu.d.ts +16 -1
- package/components/menu.js +23 -2
- package/components/menu.js.map +1 -1
- package/components/nav.d.ts +33 -2
- package/components/nav.js +37 -2
- package/components/nav.js.map +1 -1
- package/components/range-picker.d.ts +59 -0
- package/components/range-picker.js +107 -0
- package/components/range-picker.js.map +1 -0
- package/components/router.d.ts +20 -0
- package/components/router.js +48 -0
- package/components/router.js.map +1 -0
- package/components/section-header.d.ts +13 -2
- package/components/section-header.js +15 -1
- package/components/section-header.js.map +1 -1
- package/components/shell.d.ts +54 -0
- package/components/shell.js +152 -0
- package/components/shell.js.map +1 -0
- package/components/table.d.ts +18 -1
- package/components/table.js +23 -4
- package/components/table.js.map +1 -1
- package/lib/data-table-search.d.ts +91 -0
- package/lib/data-table-search.js +115 -0
- package/lib/data-table-search.js.map +1 -0
- package/lib/data-table-state.d.ts +3 -18
- package/lib/data-table-state.js.map +1 -1
- package/lib/data-table-types.d.ts +29 -0
- package/lib/data-table-types.js +0 -0
- package/lib/href.d.ts +11 -0
- package/lib/href.js +15 -0
- package/lib/href.js.map +1 -0
- package/lib/icons.d.ts +15 -1
- package/lib/icons.js +40 -2
- package/lib/icons.js.map +1 -1
- package/package.json +14 -2
- package/styles.css +11 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { chevronTurnClasses } from "../lib/classes.js";
|
|
3
|
+
import { CalendarIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon } from "../lib/icons.js";
|
|
4
|
+
import { useShortcuts } from "../lib/shortcuts.js";
|
|
5
|
+
import { Button } from "./button.js";
|
|
6
|
+
import { ButtonGroup } from "./button-group.js";
|
|
7
|
+
import { DisabledReason } from "./disabled-reason.js";
|
|
8
|
+
import { Menu, MenuContent, MenuRadioGroup, MenuRadioItem, MenuSeparator, MenuTrigger } from "./menu.js";
|
|
9
|
+
import { ShortcutKeys } from "./shortcut-keys.js";
|
|
10
|
+
import { Tooltip } from "./tooltip.js";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { Fragment as Fragment$1 } from "react";
|
|
13
|
+
// src/components/range-picker.tsx
|
|
14
|
+
/**
|
|
15
|
+
* A stats page's date range: a menu of preset ranges with optional steps to the previous and
|
|
16
|
+
* next range. It sits in the toolbar under the page header, and the range it picks lives in the
|
|
17
|
+
* URL. Both arrows sit after the label, on the control's fixed right edge: the label changes
|
|
18
|
+
* width on every step, and an arrow before it would drift out from under a cursor clicking
|
|
19
|
+
* repeatedly. An arrow at a bound is greyed out rather than hidden.
|
|
20
|
+
*/
|
|
21
|
+
function RangePicker({ value, label, presets, onChange, previous, next, menuLabel = "Date range", shortcuts = [], children, onOpenChange, ref, className }) {
|
|
22
|
+
function stepBy(step) {
|
|
23
|
+
if (!step.disabledReason) step.onStep();
|
|
24
|
+
}
|
|
25
|
+
useShortcuts([
|
|
26
|
+
...presets.flat().flatMap((preset) => preset.shortcut ? [{
|
|
27
|
+
keys: preset.shortcut.toLowerCase(),
|
|
28
|
+
label: preset.label,
|
|
29
|
+
handler: () => onChange(preset.value)
|
|
30
|
+
}] : []),
|
|
31
|
+
...previous ? [{
|
|
32
|
+
keys: "left",
|
|
33
|
+
label: previous.label,
|
|
34
|
+
handler: () => stepBy(previous)
|
|
35
|
+
}] : [],
|
|
36
|
+
...next ? [{
|
|
37
|
+
keys: "right",
|
|
38
|
+
label: next.label,
|
|
39
|
+
handler: () => stepBy(next)
|
|
40
|
+
}] : [],
|
|
41
|
+
...shortcuts
|
|
42
|
+
].map((shortcut) => ({
|
|
43
|
+
...shortcut,
|
|
44
|
+
group: menuLabel
|
|
45
|
+
})));
|
|
46
|
+
function arrow(step, direction) {
|
|
47
|
+
const button = /* @__PURE__ */ jsx(Button, {
|
|
48
|
+
variant: "secondary",
|
|
49
|
+
prefix: /* @__PURE__ */ jsx(direction === "previous" ? ChevronLeftIcon : ChevronRightIcon, {}),
|
|
50
|
+
"aria-label": step.label,
|
|
51
|
+
disabled: !!step.disabledReason,
|
|
52
|
+
onClick: () => stepBy(step)
|
|
53
|
+
});
|
|
54
|
+
if (step.disabledReason) return /* @__PURE__ */ jsx(DisabledReason, {
|
|
55
|
+
reason: step.disabledReason,
|
|
56
|
+
children: button
|
|
57
|
+
});
|
|
58
|
+
if (!step.target) return button;
|
|
59
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
60
|
+
tooltip: /* @__PURE__ */ jsxs(Fragment, { children: [step.target, /* @__PURE__ */ jsx("span", {
|
|
61
|
+
className: "opacity-60",
|
|
62
|
+
children: direction === "previous" ? "←" : "→"
|
|
63
|
+
})] }),
|
|
64
|
+
children: button
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return /* @__PURE__ */ jsxs(ButtonGroup, {
|
|
68
|
+
ref,
|
|
69
|
+
className,
|
|
70
|
+
children: [
|
|
71
|
+
/* @__PURE__ */ jsxs(Menu, {
|
|
72
|
+
onOpenChange,
|
|
73
|
+
children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
74
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
75
|
+
variant: "secondary",
|
|
76
|
+
prefix: /* @__PURE__ */ jsx(CalendarIcon, {}),
|
|
77
|
+
suffix: /* @__PURE__ */ jsx(ChevronDownIcon, { className: chevronTurnClasses }),
|
|
78
|
+
className: "flex-1 tabular-nums"
|
|
79
|
+
}),
|
|
80
|
+
children: label ?? presets.flat().find((preset) => preset.value === value)?.label
|
|
81
|
+
}), /* @__PURE__ */ jsxs(MenuContent, {
|
|
82
|
+
label: menuLabel,
|
|
83
|
+
align: "end",
|
|
84
|
+
children: [presets.map((group, index) => /* @__PURE__ */ jsxs(Fragment$1, { children: [index > 0 && /* @__PURE__ */ jsx(MenuSeparator, {}), /* @__PURE__ */ jsx(MenuRadioGroup, {
|
|
85
|
+
value: group.some((preset) => preset.value === value) ? value : null,
|
|
86
|
+
children: group.map((preset) => /* @__PURE__ */ jsx(MenuRadioItem, {
|
|
87
|
+
value: preset.value,
|
|
88
|
+
closeOnClick: true,
|
|
89
|
+
shortcut: preset.shortcut && /* @__PURE__ */ jsx(ShortcutKeys, {
|
|
90
|
+
keys: preset.shortcut,
|
|
91
|
+
variant: "plain",
|
|
92
|
+
className: "pointer-coarse:hidden"
|
|
93
|
+
}),
|
|
94
|
+
onClick: () => onChange(preset.value),
|
|
95
|
+
children: preset.label
|
|
96
|
+
}, preset.value))
|
|
97
|
+
})] }, index)), children]
|
|
98
|
+
})]
|
|
99
|
+
}),
|
|
100
|
+
previous && arrow(previous, "previous"),
|
|
101
|
+
next && arrow(next, "next")
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export { RangePicker };
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=range-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range-picker.js","names":["Fragment"],"sources":["../../src/components/range-picker.tsx"],"sourcesContent":["\"use client\"\n\nimport { Fragment, type ReactNode, type Ref } from \"react\"\nimport { chevronTurnClasses } from \"../lib/classes\"\nimport { CalendarIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon } from \"../lib/icons\"\nimport { type Shortcut, useShortcuts } from \"../lib/shortcuts\"\nimport { Button } from \"./button\"\nimport { ButtonGroup } from \"./button-group\"\nimport { DisabledReason } from \"./disabled-reason\"\nimport {\n Menu,\n MenuContent,\n MenuRadioGroup,\n MenuRadioItem,\n MenuSeparator,\n MenuTrigger,\n} from \"./menu\"\nimport { ShortcutKeys } from \"./shortcut-keys\"\nimport { Tooltip } from \"./tooltip\"\n\nexport interface RangePickerPreset<T extends string | number> {\n /** What the row stands for, handed to `onChange`. Unique across every group. */\n value: T\n label: string\n /**\n * A single key that picks the row from anywhere on the page, printed beside it: `\"D\"` or\n * `\"d\"`, matched on the character the key produces.\n */\n shortcut?: string\n}\n\nexport interface RangePickerStep {\n /** The button's accessible name, and its row in the shortcuts dialog: \"Earlier period\". */\n label: string\n /** The tooltip: the name of the range a click moves to. */\n target?: ReactNode\n /** Greys the button out and says why, at a bound: \"No data before this period.\" */\n disabledReason?: string\n onStep: () => void\n}\n\nexport interface RangePickerProps<T extends string | number> {\n /** The picked row, or `undefined` while the range is one no row names. */\n value: T | undefined\n /**\n * The trigger's text: the range's name. Defaults to the picked row's label, so only a range no\n * row names needs one.\n */\n label?: ReactNode\n /** The menu's rows, in the groups a separator divides. */\n presets: RangePickerPreset<T>[][]\n /** Runs on every click of a row, the picked one included, so a row can reopen its own panel. */\n onChange: (value: T) => void\n /** The step back, on `←`. Without it, the control has no arrow buttons. */\n previous?: RangePickerStep\n /** The step forward, on `→`. */\n next?: RangePickerStep\n /** The menu's accessible name, and the section its shortcuts list under. */\n menuLabel?: string\n /** Further shortcuts listed in the same section, after the control's own. */\n shortcuts?: Omit<Shortcut, \"group\">[]\n /**\n * Rows after the presets: a comparison, a bucket-size switch. Start each group with a\n * `MenuSeparator`.\n */\n children?: ReactNode\n onOpenChange?: (open: boolean) => void\n /** The whole control, arrows included: a panel that opens from a row lines up with it. */\n ref?: Ref<HTMLDivElement>\n className?: string\n}\n\n/**\n * A stats page's date range: a menu of preset ranges with optional steps to the previous and\n * next range. It sits in the toolbar under the page header, and the range it picks lives in the\n * URL. Both arrows sit after the label, on the control's fixed right edge: the label changes\n * width on every step, and an arrow before it would drift out from under a cursor clicking\n * repeatedly. An arrow at a bound is greyed out rather than hidden.\n */\nexport function RangePicker<T extends string | number>({\n value,\n label,\n presets,\n onChange,\n previous,\n next,\n menuLabel = \"Date range\",\n shortcuts = [],\n children,\n onOpenChange,\n ref,\n className,\n}: RangePickerProps<T>) {\n function stepBy(step: RangePickerStep) {\n if (!step.disabledReason) step.onStep()\n }\n\n useShortcuts(\n [\n ...presets.flat().flatMap(preset =>\n preset.shortcut\n ? [\n {\n keys: preset.shortcut.toLowerCase(),\n label: preset.label,\n handler: () => onChange(preset.value),\n },\n ]\n : [],\n ),\n ...(previous\n ? [{ keys: \"left\", label: previous.label, handler: () => stepBy(previous) }]\n : []),\n ...(next ? [{ keys: \"right\", label: next.label, handler: () => stepBy(next) }] : []),\n ...shortcuts,\n ].map(shortcut => ({ ...shortcut, group: menuLabel })),\n )\n\n function arrow(step: RangePickerStep, direction: \"previous\" | \"next\") {\n const Icon = direction === \"previous\" ? ChevronLeftIcon : ChevronRightIcon\n const button = (\n <Button\n variant=\"secondary\"\n prefix={<Icon />}\n aria-label={step.label}\n disabled={!!step.disabledReason}\n onClick={() => stepBy(step)}\n />\n )\n\n if (step.disabledReason) {\n return <DisabledReason reason={step.disabledReason}>{button}</DisabledReason>\n }\n\n if (!step.target) return button\n\n return (\n <Tooltip\n tooltip={\n <>\n {step.target}\n <span className=\"opacity-60\">{direction === \"previous\" ? \"←\" : \"→\"}</span>\n </>\n }\n >\n {button}\n </Tooltip>\n )\n }\n\n return (\n <ButtonGroup ref={ref} className={className}>\n <Menu onOpenChange={onOpenChange}>\n <MenuTrigger\n render={\n <Button\n variant=\"secondary\"\n prefix={<CalendarIcon />}\n suffix={<ChevronDownIcon className={chevronTurnClasses} />}\n className=\"flex-1 tabular-nums\"\n />\n }\n >\n {label ?? presets.flat().find(preset => preset.value === value)?.label}\n </MenuTrigger>\n\n <MenuContent label={menuLabel} align=\"end\">\n {presets.map((group, index) => (\n <Fragment key={index}>\n {index > 0 && <MenuSeparator />}\n\n {/* Each group checks its own row; one with nothing picked holds a value no row\n has, which keeps it controlled. */}\n <MenuRadioGroup value={group.some(preset => preset.value === value) ? value : null}>\n {group.map(preset => (\n <MenuRadioItem\n key={preset.value}\n value={preset.value}\n closeOnClick\n shortcut={\n preset.shortcut && (\n <ShortcutKeys\n keys={preset.shortcut}\n variant=\"plain\"\n className=\"pointer-coarse:hidden\"\n />\n )\n }\n onClick={() => onChange(preset.value)}\n >\n {preset.label}\n </MenuRadioItem>\n ))}\n </MenuRadioGroup>\n </Fragment>\n ))}\n\n {children}\n </MenuContent>\n </Menu>\n\n {previous && arrow(previous, \"previous\")}\n {next && arrow(next, \"next\")}\n </ButtonGroup>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+EA,SAAgB,YAAuC,EACrD,OACA,OACA,SACA,UACA,UACA,MACA,YAAY,cACZ,YAAY,CAAC,GACb,UACA,cACA,KACA,aACsB;CACtB,SAAS,OAAO,MAAuB;EACrC,IAAI,CAAC,KAAK,gBAAgB,KAAK,OAAO;CACxC;CAEA,aACE;EACE,GAAG,QAAQ,KAAK,CAAC,CAAC,SAAQ,WACxB,OAAO,WACH,CACE;GACE,MAAM,OAAO,SAAS,YAAY;GAClC,OAAO,OAAO;GACd,eAAe,SAAS,OAAO,KAAK;EACtC,CACF,IACA,CAAC,CACP;EACA,GAAI,WACA,CAAC;GAAE,MAAM;GAAQ,OAAO,SAAS;GAAO,eAAe,OAAO,QAAQ;EAAE,CAAC,IACzE,CAAC;EACL,GAAI,OAAO,CAAC;GAAE,MAAM;GAAS,OAAO,KAAK;GAAO,eAAe,OAAO,IAAI;EAAE,CAAC,IAAI,CAAC;EAClF,GAAG;CACL,CAAC,CAAC,KAAI,cAAa;EAAE,GAAG;EAAU,OAAO;CAAU,EAAE,CACvD;CAEA,SAAS,MAAM,MAAuB,WAAgC;EAEpE,MAAM,SACJ,oBAAC,QAAD;GACE,SAAQ;GACR,QAAQ,oBAJC,cAAc,aAAa,kBAAkB,kBAI9C,CAAO,CAAA;GACf,cAAY,KAAK;GACjB,UAAU,CAAC,CAAC,KAAK;GACjB,eAAe,OAAO,IAAI;EAC3B,CAAA;EAGH,IAAI,KAAK,gBACP,OAAO,oBAAC,gBAAD;GAAgB,QAAQ,KAAK;GAAiB,UAAA;EAAuB,CAAA;EAG9E,IAAI,CAAC,KAAK,QAAQ,OAAO;EAEzB,O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ps } from "../lib/data-table-search.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* The TanStack Router parts of the table system, kept apart so an app on another router never
|
|
5
|
+
* installs this one. `@tanstack/react-router` is an optional peer.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A `DataTable` row link through the router, for its `renderRowLink`: the row opens its `href`
|
|
9
|
+
* in place and preloads it on intent, as every other link in the app does. The href goes in
|
|
10
|
+
* split into path, search and hash, since `to` takes a path alone and a whole href with a
|
|
11
|
+
* query string matches no route to preload.
|
|
12
|
+
*/
|
|
13
|
+
export declare function RouterRowLink({ href, ...props }: ComponentProps<"a">): import("react").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* The `state` and `onStateChange` that keep a `DataTable` in the current route's search
|
|
16
|
+
* params, for a table described by `createDataTableSearch`. Each change merges into the params
|
|
17
|
+
* the route already holds, so a view or filter of the page's own stays put. A new page or sort
|
|
18
|
+
* adds a history entry; a corrected page and a search typed a key at a time replace it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useDataTableRoute<Keys extends DataTableSearchKeys>(table: DataTableSearch<Keys>, search: Record<string, unknown>): DataTableSearchProps;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { parseHref } from "../lib/href.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Link, useNavigate, useRouter } from "@tanstack/react-router";
|
|
5
|
+
// src/components/router.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The TanStack Router parts of the table system, kept apart so an app on another router never
|
|
8
|
+
* installs this one. `@tanstack/react-router` is an optional peer.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* A `DataTable` row link through the router, for its `renderRowLink`: the row opens its `href`
|
|
12
|
+
* in place and preloads it on intent, as every other link in the app does. The href goes in
|
|
13
|
+
* split into path, search and hash, since `to` takes a path alone and a whole href with a
|
|
14
|
+
* query string matches no route to preload.
|
|
15
|
+
*/
|
|
16
|
+
function RouterRowLink({ href = "", ...props }) {
|
|
17
|
+
const router = useRouter();
|
|
18
|
+
const { pathname, search, hash } = parseHref(href);
|
|
19
|
+
return /* @__PURE__ */ jsx(Link, {
|
|
20
|
+
...props,
|
|
21
|
+
to: pathname,
|
|
22
|
+
search: router.options.parseSearch(search),
|
|
23
|
+
hash
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The `state` and `onStateChange` that keep a `DataTable` in the current route's search
|
|
28
|
+
* params, for a table described by `createDataTableSearch`. Each change merges into the params
|
|
29
|
+
* the route already holds, so a view or filter of the page's own stays put. A new page or sort
|
|
30
|
+
* adds a history entry; a corrected page and a search typed a key at a time replace it.
|
|
31
|
+
*/
|
|
32
|
+
function useDataTableRoute(table, search) {
|
|
33
|
+
const navigate = useNavigate();
|
|
34
|
+
return table.getProps({
|
|
35
|
+
search,
|
|
36
|
+
onSearchChange: (next, { replace }) => void navigate({
|
|
37
|
+
to: ".",
|
|
38
|
+
search: (previous) => ({
|
|
39
|
+
...previous,
|
|
40
|
+
...next
|
|
41
|
+
}),
|
|
42
|
+
replace
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export { RouterRowLink, useDataTableRoute };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","names":[],"sources":["../../src/components/router.tsx"],"sourcesContent":["\"use client\"\n\nimport { Link, useNavigate, useRouter } from \"@tanstack/react-router\"\nimport type { ComponentProps } from \"react\"\nimport type {\n DataTableSearch,\n DataTableSearchKeys,\n DataTableSearchProps,\n} from \"../lib/data-table-search\"\nimport { parseHref } from \"../lib/href\"\n\n/**\n * The TanStack Router parts of the table system, kept apart so an app on another router never\n * installs this one. `@tanstack/react-router` is an optional peer.\n */\n\n/**\n * A `DataTable` row link through the router, for its `renderRowLink`: the row opens its `href`\n * in place and preloads it on intent, as every other link in the app does. The href goes in\n * split into path, search and hash, since `to` takes a path alone and a whole href with a\n * query string matches no route to preload.\n */\nexport function RouterRowLink({ href = \"\", ...props }: ComponentProps<\"a\">) {\n const router = useRouter()\n const { pathname, search, hash } = parseHref(href)\n\n return <Link {...props} to={pathname} search={router.options.parseSearch(search)} hash={hash} />\n}\n\n/**\n * The `state` and `onStateChange` that keep a `DataTable` in the current route's search\n * params, for a table described by `createDataTableSearch`. Each change merges into the params\n * the route already holds, so a view or filter of the page's own stays put. A new page or sort\n * adds a history entry; a corrected page and a search typed a key at a time replace it.\n */\nexport function useDataTableRoute<Keys extends DataTableSearchKeys>(\n table: DataTableSearch<Keys>,\n search: Record<string, unknown>,\n): DataTableSearchProps {\n const navigate = useNavigate()\n\n return table.getProps({\n search,\n onSearchChange: (next, { replace }) =>\n void navigate({\n to: \".\",\n search: (previous: Record<string, unknown>) => ({ ...previous, ...next }),\n replace,\n }),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAAgB,cAAc,EAAE,OAAO,IAAI,GAAG,SAA8B;CAC1E,MAAM,SAAS,UAAU;CACzB,MAAM,EAAE,UAAU,QAAQ,SAAS,UAAU,IAAI;CAEjD,OAAO,oBAAC,MAAD;EAAM,GAAI;EAAO,IAAI;EAAU,QAAQ,OAAO,QAAQ,YAAY,MAAM;EAAS;CAAO,CAAA;AACjG;;;;;;;AAQA,SAAgB,kBACd,OACA,QACsB;CACtB,MAAM,WAAW,YAAY;CAE7B,OAAO,MAAM,SAAS;EACpB;EACA,iBAAiB,MAAM,EAAE,cACvB,KAAK,SAAS;GACZ,IAAI;GACJ,SAAS,cAAuC;IAAE,GAAG;IAAU,GAAG;GAAK;GACvE;EACF,CAAC;CACL,CAAC;AACH"}
|
|
@@ -2,7 +2,7 @@ import { VariantProps } from "../lib/variants.js";
|
|
|
2
2
|
import { HeadingProps } from "./heading.js";
|
|
3
3
|
import { Stack } from "./stack.js";
|
|
4
4
|
import { useRender } from "@base-ui/react/use-render";
|
|
5
|
-
import { ComponentProps, ReactNode } from "react";
|
|
5
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
6
6
|
declare const sectionHeaderVariants: import("tailwind-variants").TVReturnType<{
|
|
7
7
|
alignment: {
|
|
8
8
|
left: string;
|
|
@@ -59,6 +59,17 @@ declare function SectionHeaderTitle({ size, as, className, ...props }: HeadingPr
|
|
|
59
59
|
* page. The caller passes the link with its chevron.
|
|
60
60
|
*/
|
|
61
61
|
declare function SectionHeaderBack({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
|
|
62
|
+
interface BackLinkProps {
|
|
63
|
+
/** The link to the list, rendered as the control: a router's `<Link to="/users" />`. */
|
|
64
|
+
render: ReactElement;
|
|
65
|
+
/** The list's name: "Users". */
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The link back to the list a record belongs to, for the header's `back` slot: a chevron and
|
|
70
|
+
* the list's name, muted, the same on every detail page.
|
|
71
|
+
*/
|
|
72
|
+
declare function BackLink({ render, children }: BackLinkProps): import("react").JSX.Element;
|
|
62
73
|
type SectionHeaderBodyProps = ComponentProps<"div"> & {
|
|
63
74
|
/**
|
|
64
75
|
* Leading visual, e.g. an entity avatar.
|
|
@@ -80,4 +91,4 @@ declare function SectionHeaderDescription({ className, ...props }: ComponentProp
|
|
|
80
91
|
* truncates instead of squeezing the buttons.
|
|
81
92
|
*/
|
|
82
93
|
declare function SectionHeaderActions({ className, ...props }: ComponentProps<typeof Stack>): import("react").JSX.Element;
|
|
83
|
-
export { SectionHeader, SectionHeaderActions, SectionHeaderBack, SectionHeaderBody, SectionHeaderDescription, SectionHeaderTitle };
|
|
94
|
+
export { BackLink, SectionHeader, SectionHeaderActions, SectionHeaderBack, SectionHeaderBody, SectionHeaderDescription, SectionHeaderTitle };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { descriptionClasses } from "../lib/classes.js";
|
|
3
|
+
import { ChevronLeftIcon } from "../lib/icons.js";
|
|
3
4
|
import { cn, variants } from "../lib/variants.js";
|
|
4
5
|
import { Heading } from "./heading.js";
|
|
6
|
+
import { InlineAction } from "./inline-action.js";
|
|
5
7
|
import { Stack } from "./stack.js";
|
|
6
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
9
|
import { useRender } from "@base-ui/react/use-render";
|
|
@@ -129,6 +131,18 @@ function SectionHeaderBack({ className, ...props }) {
|
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
133
|
/**
|
|
134
|
+
* The link back to the list a record belongs to, for the header's `back` slot: a chevron and
|
|
135
|
+
* the list's name, muted, the same on every detail page.
|
|
136
|
+
*/
|
|
137
|
+
function BackLink({ render, children }) {
|
|
138
|
+
return /* @__PURE__ */ jsxs(InlineAction, {
|
|
139
|
+
touchTarget: true,
|
|
140
|
+
className: "gap-1",
|
|
141
|
+
render,
|
|
142
|
+
children: [/* @__PURE__ */ jsx(ChevronLeftIcon, {}), children]
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
132
146
|
* The one title block for every header in the app (pages, cards, dialogs, settings sections):
|
|
133
147
|
* an optional leading visual beside a column of `SectionHeaderTitle` + `SectionHeaderDescription`. Change the
|
|
134
148
|
* spacing here and it changes everywhere.
|
|
@@ -165,6 +179,6 @@ function SectionHeaderActions({ className, ...props }) {
|
|
|
165
179
|
...props
|
|
166
180
|
});
|
|
167
181
|
}
|
|
168
|
-
export { SectionHeader, SectionHeaderActions, SectionHeaderBack, SectionHeaderBody, SectionHeaderDescription, SectionHeaderTitle };
|
|
182
|
+
export { BackLink, SectionHeader, SectionHeaderActions, SectionHeaderBack, SectionHeaderBody, SectionHeaderDescription, SectionHeaderTitle };
|
|
169
183
|
|
|
170
184
|
//# sourceMappingURL=section-header.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"section-header.js","names":[],"sources":["../../src/components/section-header.tsx"],"sourcesContent":["\"use client\"\n\nimport { useRender } from \"@base-ui/react/use-render\"\nimport { type ComponentProps, createContext, type ReactNode, use } from \"react\"\nimport { descriptionClasses } from \"../lib/classes\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\nimport { Heading, type HeadingProps } from \"./heading\"\nimport { Stack } from \"./stack\"\n\nconst sectionHeaderVariants = variants({\n base: \"flex items-center w-full min-w-0\",\n\n variants: {\n alignment: {\n left: \"justify-between text-start\",\n center: \"justify-center text-center\",\n },\n size: {\n // On a phone the actions stay on the title's line and the description runs the full\n // width under both, so a page never spends a row on its actions alone. The body and its\n // column dissolve into this grid there (see `SectionHeaderBody`), and each part names\n // its own area.\n page: [\n \"gap-x-6 lg:gap-x-12\",\n \"max-sm:grid max-sm:grid-cols-[minmax(0,1fr)_auto] max-sm:gap-x-3\",\n \"max-sm:[grid-template-areas:'back_back'_'title_actions'_'description_description']\",\n ],\n card: \"gap-y-2 gap-x-6 max-sm:flex-col max-sm:items-stretch\",\n // The title block keeps its content width in the wrap calculation, so the actions (a\n // card's tab row) drop under it only when the two really cannot share the line.\n panel: \"gap-y-2 gap-x-6 [&>*:first-child]:flex-auto\",\n hero: \"gap-y-3 gap-x-6 lg:gap-x-12\",\n },\n wrap: {\n true: \"flex-wrap\",\n false: \"flex-nowrap\",\n },\n },\n\n defaultVariants: {\n alignment: \"left\",\n wrap: true,\n },\n})\n\ntype SectionHeaderSize = NonNullable<VariantProps<typeof sectionHeaderVariants>[\"size\"]>\n\n/**\n * The title each header scale gets, alongside the spacing the variant above gives it: `page`\n * for a route heading, `card` for a standalone card, `panel` for a dashboard or list panel,\n * `hero` for the centered auth and callback screens. The `as` entry keeps the heading outline\n * intact: one `<h1>` per route, `<h2>` for everything nested inside it.\n */\nconst sectionHeaderTitles = {\n page: { size: \"h3\", as: \"h1\" },\n card: { size: \"h4\", as: \"h2\" },\n panel: { size: \"h5\", as: \"h2\" },\n hero: { size: \"h2\", as: \"h1\" },\n} as const satisfies Record<SectionHeaderSize, { size: HeadingProps[\"size\"]; as: string }>\n\nconst SectionHeaderContext = createContext<{ size: SectionHeaderSize; wrap: boolean }>({\n size: \"page\",\n wrap: true,\n})\n\ntype SectionHeaderProps = Omit<useRender.ComponentProps<\"div\">, \"title\"> &\n Omit<VariantProps<typeof sectionHeaderVariants>, \"wrap\"> & {\n /**\n * Keep the title block and the actions on one line instead of wrapping them.\n */\n wrap?: boolean\n /**\n * Title block. Given any of `title`/`description`/`leading`/`actions`, the header renders\n * its own `SectionHeaderBody` (empty if there is nothing but actions, so they still sit right);\n * leave them all out to compose the body by hand, e.g. an entity header with dot-joined\n * meta or the dashboard greeting.\n */\n title?: ReactNode\n description?: ReactNode\n actions?: ReactNode\n /**\n * The link back to the list a record belongs to, above its title.\n */\n back?: ReactNode\n /**\n * Leading visual beside the title, e.g. an entity avatar.\n */\n leading?: ReactNode\n }\n\n/**\n * The one header for every surface in the app: pages, cards, list panels, dialogs and settings\n * sections. Pass `title`/`description`/`actions` for the standard block, or compose\n * `SectionHeaderBody` + `SectionHeaderActions` as children when the content is bespoke.\n */\nfunction SectionHeader({\n className,\n alignment = \"left\",\n size = \"page\",\n wrap = true,\n title,\n description,\n actions,\n back,\n leading,\n children,\n render,\n ...props\n}: SectionHeaderProps) {\n const element = useRender({\n render,\n defaultTagName: \"div\",\n props: {\n className: sectionHeaderVariants({ alignment, size, wrap, className }),\n children: (\n <>\n {/* `||`: a `false` or `\"\"` slot counts as missing. */}\n {/* oxlint-disable-next-line typescript/prefer-nullish-coalescing */}\n {(title || description || back || leading || actions) && (\n <SectionHeaderBody\n leading={leading}\n className={cn(alignment === \"center\" && \"justify-center\")}\n >\n {back && <SectionHeaderBack>{back}</SectionHeaderBack>}\n {title && <SectionHeaderTitle>{title}</SectionHeaderTitle>}\n {description && <SectionHeaderDescription>{description}</SectionHeaderDescription>}\n </SectionHeaderBody>\n )}\n\n {actions && <SectionHeaderActions>{actions}</SectionHeaderActions>}\n\n {children}\n </>\n ),\n ...props,\n },\n })\n\n return <SectionHeaderContext value={{ size, wrap }}>{element}</SectionHeaderContext>\n}\n\n/**\n * The page title. Its visual size and semantic level both follow the header's `size`, so a\n * page heading stays the route's single `<h1>` while cards and panels render `<h2>`s. Pass\n * `size`/`as` to override either one on its own.\n */\nfunction SectionHeaderTitle({ size, as, className, ...props }: HeadingProps) {\n const context = use(SectionHeaderContext)\n const preset = sectionHeaderTitles[context.size]\n\n return (\n <Heading\n size={size ?? preset.size}\n as={as ?? preset.as}\n // A page title steps down to 20px on a phone, where it shares its line with the actions.\n className={cn(\n context.size === \"page\" && \"max-sm:text-xl max-sm:[grid-area:title]\",\n className,\n )}\n {...props}\n />\n )\n}\n\n/**\n * The link back to the list a record belongs to, over the title: muted, one size on every\n * page. The caller passes the link with its chevron.\n */\nfunction SectionHeaderBack({ className, ...props }: ComponentProps<\"div\">) {\n const { size } = use(SectionHeaderContext)\n\n return (\n <div\n className={cn(\n \"flex text-copy [&_svg]:size-3.5\",\n size === \"page\" && \"max-sm:mb-2 max-sm:[grid-area:back]\",\n className,\n )}\n {...props}\n />\n )\n}\n\ntype SectionHeaderBodyProps = ComponentProps<\"div\"> & {\n /**\n * Leading visual, e.g. an entity avatar.\n */\n leading?: ReactNode\n}\n\n/**\n * The one title block for every header in the app (pages, cards, dialogs, settings sections):\n * an optional leading visual beside a column of `SectionHeaderTitle` + `SectionHeaderDescription`. Change the\n * spacing here and it changes everywhere.\n */\nfunction SectionHeaderBody({ leading, children, className, ...props }: SectionHeaderBodyProps) {\n // A page header without a leading visual hands its parts to the header's phone grid.\n const dissolve = use(SectionHeaderContext).size === \"page\" && !leading\n\n return (\n <div\n className={cn(\n \"flex min-w-0 flex-1 items-center gap-3\",\n dissolve && \"max-sm:contents\",\n className,\n )}\n {...props}\n >\n {leading}\n <div className={cn(\"flex min-w-0 flex-col gap-1.5\", dissolve && \"max-sm:contents\")}>\n {children}\n </div>\n </div>\n )\n}\n\n/**\n * The muted line under a title. Wraps by default; pass `truncate` for one-line entity meta.\n */\nfunction SectionHeaderDescription({ className, ...props }: ComponentProps<\"p\">) {\n const { size } = use(SectionHeaderContext)\n\n return (\n <p\n className={cn(\n descriptionClasses,\n // Two lines at most on a phone, so a long one never pushes the page down.\n size === \"page\" && \"max-sm:mt-2 max-sm:line-clamp-2 max-sm:[grid-area:description]\",\n className,\n )}\n {...props}\n />\n )\n}\n\n/**\n * Right-aligned actions. Stops shrinking when the header is `wrap={false}`, so a long title\n * truncates instead of squeezing the buttons.\n */\nfunction SectionHeaderActions({ className, ...props }: ComponentProps<typeof Stack>) {\n const { size, wrap } = use(SectionHeaderContext)\n\n return (\n <Stack\n className={cn(\n \"-my-0.5\",\n !wrap && \"shrink-0\",\n // A page's actions sit as close as the toolbar's controls, and on a phone they hold the\n // end of the title's line.\n size === \"page\" && \"flex-nowrap gap-1.5 max-sm:[grid-area:actions]\",\n className,\n )}\n {...props}\n />\n )\n}\n\nexport {\n SectionHeader,\n SectionHeaderTitle,\n SectionHeaderBack,\n SectionHeaderBody,\n SectionHeaderDescription,\n SectionHeaderActions,\n}\n"],"mappings":";;;;;;;;;AASA,MAAM,wBAAwB,SAAS;CACrC,MAAM;CAEN,UAAU;EACR,WAAW;GACT,MAAM;GACN,QAAQ;EACV;EACA,MAAM;GAKJ,MAAM;IACJ;IACA;IACA;GACF;GACA,MAAM;GAGN,OAAO;GACP,MAAM;EACR;EACA,MAAM;GACJ,MAAM;GACN,OAAO;EACT;CACF;CAEA,iBAAiB;EACf,WAAW;EACX,MAAM;CACR;AACF,CAAC;;;;;;;AAUD,MAAM,sBAAsB;CAC1B,MAAM;EAAE,MAAM;EAAM,IAAI;CAAK;CAC7B,MAAM;EAAE,MAAM;EAAM,IAAI;CAAK;CAC7B,OAAO;EAAE,MAAM;EAAM,IAAI;CAAK;CAC9B,MAAM;EAAE,MAAM;EAAM,IAAI;CAAK;AAC/B;AAEA,MAAM,uBAAuB,cAA0D;CACrF,MAAM;CACN,MAAM;AACR,CAAC;;;;;;AAgCD,SAAS,cAAc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AG,SAAiC;CAE7F,MAAM,WAAW,IAAI,oBAAoB,CAAC,CAAC,SAAS,UAAU,CAAC;CAE/D,OACE,qBAAC,OAAD;EACE,WAAW,GACT,0CACA,YAAY,mBACZ,SACF;EACA,GAAI;EANN,UAAA,CAQG,SACD,oBAAC,OAAD;GAAK,WAAW,GAAG,iCAAiC,YAAY,iBAAiB;GAC9E;EACE,CAAA,CACF;;AAET;;;;AAKA,SAAS,yBAAyB,EAAE,WAAW,GAAG,SAA8B;CAC9E,MAAM,EAAE,SAAS,IAAI,oBAAoB;CAEzC,OACE,oBAAC,KAAD;EACE,WAAW,GACT,oBAEA,SAAS,UAAU,kEACnB,SACF;EACA,GAAI;CACL,CAAA;AAEL;;;;;AAMA,SAAS,qBAAqB,EAAE,WAAW,GAAG,SAAuC;CACnF,MAAM,EAAE,MAAM,SAAS,IAAI,oBAAoB;CAE/C,OACE,oBAAC,OAAD;EACE,WAAW,GACT,WACA,CAAC,QAAQ,YAGT,SAAS,UAAU,kDACnB,SACF;EACA,GAAI;CACL,CAAA;AAEL"}
|
|
1
|
+
{"version":3,"file":"section-header.js","names":[],"sources":["../../src/components/section-header.tsx"],"sourcesContent":["\"use client\"\n\nimport { useRender } from \"@base-ui/react/use-render\"\nimport { type ComponentProps, createContext, type ReactElement, type ReactNode, use } from \"react\"\nimport { descriptionClasses } from \"../lib/classes\"\nimport { ChevronLeftIcon } from \"../lib/icons\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\nimport { Heading, type HeadingProps } from \"./heading\"\nimport { InlineAction } from \"./inline-action\"\nimport { Stack } from \"./stack\"\n\nconst sectionHeaderVariants = variants({\n base: \"flex items-center w-full min-w-0\",\n\n variants: {\n alignment: {\n left: \"justify-between text-start\",\n center: \"justify-center text-center\",\n },\n size: {\n // On a phone the actions stay on the title's line and the description runs the full\n // width under both, so a page never spends a row on its actions alone. The body and its\n // column dissolve into this grid there (see `SectionHeaderBody`), and each part names\n // its own area.\n page: [\n \"gap-x-6 lg:gap-x-12\",\n \"max-sm:grid max-sm:grid-cols-[minmax(0,1fr)_auto] max-sm:gap-x-3\",\n \"max-sm:[grid-template-areas:'back_back'_'title_actions'_'description_description']\",\n ],\n card: \"gap-y-2 gap-x-6 max-sm:flex-col max-sm:items-stretch\",\n // The title block keeps its content width in the wrap calculation, so the actions (a\n // card's tab row) drop under it only when the two really cannot share the line.\n panel: \"gap-y-2 gap-x-6 [&>*:first-child]:flex-auto\",\n hero: \"gap-y-3 gap-x-6 lg:gap-x-12\",\n },\n wrap: {\n true: \"flex-wrap\",\n false: \"flex-nowrap\",\n },\n },\n\n defaultVariants: {\n alignment: \"left\",\n wrap: true,\n },\n})\n\ntype SectionHeaderSize = NonNullable<VariantProps<typeof sectionHeaderVariants>[\"size\"]>\n\n/**\n * The title each header scale gets, alongside the spacing the variant above gives it: `page`\n * for a route heading, `card` for a standalone card, `panel` for a dashboard or list panel,\n * `hero` for the centered auth and callback screens. The `as` entry keeps the heading outline\n * intact: one `<h1>` per route, `<h2>` for everything nested inside it.\n */\nconst sectionHeaderTitles = {\n page: { size: \"h3\", as: \"h1\" },\n card: { size: \"h4\", as: \"h2\" },\n panel: { size: \"h5\", as: \"h2\" },\n hero: { size: \"h2\", as: \"h1\" },\n} as const satisfies Record<SectionHeaderSize, { size: HeadingProps[\"size\"]; as: string }>\n\nconst SectionHeaderContext = createContext<{ size: SectionHeaderSize; wrap: boolean }>({\n size: \"page\",\n wrap: true,\n})\n\ntype SectionHeaderProps = Omit<useRender.ComponentProps<\"div\">, \"title\"> &\n Omit<VariantProps<typeof sectionHeaderVariants>, \"wrap\"> & {\n /**\n * Keep the title block and the actions on one line instead of wrapping them.\n */\n wrap?: boolean\n /**\n * Title block. Given any of `title`/`description`/`leading`/`actions`, the header renders\n * its own `SectionHeaderBody` (empty if there is nothing but actions, so they still sit right);\n * leave them all out to compose the body by hand, e.g. an entity header with dot-joined\n * meta or the dashboard greeting.\n */\n title?: ReactNode\n description?: ReactNode\n actions?: ReactNode\n /**\n * The link back to the list a record belongs to, above its title.\n */\n back?: ReactNode\n /**\n * Leading visual beside the title, e.g. an entity avatar.\n */\n leading?: ReactNode\n }\n\n/**\n * The one header for every surface in the app: pages, cards, list panels, dialogs and settings\n * sections. Pass `title`/`description`/`actions` for the standard block, or compose\n * `SectionHeaderBody` + `SectionHeaderActions` as children when the content is bespoke.\n */\nfunction SectionHeader({\n className,\n alignment = \"left\",\n size = \"page\",\n wrap = true,\n title,\n description,\n actions,\n back,\n leading,\n children,\n render,\n ...props\n}: SectionHeaderProps) {\n const element = useRender({\n render,\n defaultTagName: \"div\",\n props: {\n className: sectionHeaderVariants({ alignment, size, wrap, className }),\n children: (\n <>\n {/* `||`: a `false` or `\"\"` slot counts as missing. */}\n {/* oxlint-disable-next-line typescript/prefer-nullish-coalescing */}\n {(title || description || back || leading || actions) && (\n <SectionHeaderBody\n leading={leading}\n className={cn(alignment === \"center\" && \"justify-center\")}\n >\n {back && <SectionHeaderBack>{back}</SectionHeaderBack>}\n {title && <SectionHeaderTitle>{title}</SectionHeaderTitle>}\n {description && <SectionHeaderDescription>{description}</SectionHeaderDescription>}\n </SectionHeaderBody>\n )}\n\n {actions && <SectionHeaderActions>{actions}</SectionHeaderActions>}\n\n {children}\n </>\n ),\n ...props,\n },\n })\n\n return <SectionHeaderContext value={{ size, wrap }}>{element}</SectionHeaderContext>\n}\n\n/**\n * The page title. Its visual size and semantic level both follow the header's `size`, so a\n * page heading stays the route's single `<h1>` while cards and panels render `<h2>`s. Pass\n * `size`/`as` to override either one on its own.\n */\nfunction SectionHeaderTitle({ size, as, className, ...props }: HeadingProps) {\n const context = use(SectionHeaderContext)\n const preset = sectionHeaderTitles[context.size]\n\n return (\n <Heading\n size={size ?? preset.size}\n as={as ?? preset.as}\n // A page title steps down to 20px on a phone, where it shares its line with the actions.\n className={cn(\n context.size === \"page\" && \"max-sm:text-xl max-sm:[grid-area:title]\",\n className,\n )}\n {...props}\n />\n )\n}\n\n/**\n * The link back to the list a record belongs to, over the title: muted, one size on every\n * page. The caller passes the link with its chevron.\n */\nfunction SectionHeaderBack({ className, ...props }: ComponentProps<\"div\">) {\n const { size } = use(SectionHeaderContext)\n\n return (\n <div\n className={cn(\n \"flex text-copy [&_svg]:size-3.5\",\n size === \"page\" && \"max-sm:mb-2 max-sm:[grid-area:back]\",\n className,\n )}\n {...props}\n />\n )\n}\n\ninterface BackLinkProps {\n /** The link to the list, rendered as the control: a router's `<Link to=\"/users\" />`. */\n render: ReactElement\n /** The list's name: \"Users\". */\n children: ReactNode\n}\n\n/**\n * The link back to the list a record belongs to, for the header's `back` slot: a chevron and\n * the list's name, muted, the same on every detail page.\n */\nfunction BackLink({ render, children }: BackLinkProps) {\n return (\n <InlineAction touchTarget className=\"gap-1\" render={render}>\n <ChevronLeftIcon />\n {children}\n </InlineAction>\n )\n}\n\ntype SectionHeaderBodyProps = ComponentProps<\"div\"> & {\n /**\n * Leading visual, e.g. an entity avatar.\n */\n leading?: ReactNode\n}\n\n/**\n * The one title block for every header in the app (pages, cards, dialogs, settings sections):\n * an optional leading visual beside a column of `SectionHeaderTitle` + `SectionHeaderDescription`. Change the\n * spacing here and it changes everywhere.\n */\nfunction SectionHeaderBody({ leading, children, className, ...props }: SectionHeaderBodyProps) {\n // A page header without a leading visual hands its parts to the header's phone grid.\n const dissolve = use(SectionHeaderContext).size === \"page\" && !leading\n\n return (\n <div\n className={cn(\n \"flex min-w-0 flex-1 items-center gap-3\",\n dissolve && \"max-sm:contents\",\n className,\n )}\n {...props}\n >\n {leading}\n <div className={cn(\"flex min-w-0 flex-col gap-1.5\", dissolve && \"max-sm:contents\")}>\n {children}\n </div>\n </div>\n )\n}\n\n/**\n * The muted line under a title. Wraps by default; pass `truncate` for one-line entity meta.\n */\nfunction SectionHeaderDescription({ className, ...props }: ComponentProps<\"p\">) {\n const { size } = use(SectionHeaderContext)\n\n return (\n <p\n className={cn(\n descriptionClasses,\n // Two lines at most on a phone, so a long one never pushes the page down.\n size === \"page\" && \"max-sm:mt-2 max-sm:line-clamp-2 max-sm:[grid-area:description]\",\n className,\n )}\n {...props}\n />\n )\n}\n\n/**\n * Right-aligned actions. Stops shrinking when the header is `wrap={false}`, so a long title\n * truncates instead of squeezing the buttons.\n */\nfunction SectionHeaderActions({ className, ...props }: ComponentProps<typeof Stack>) {\n const { size, wrap } = use(SectionHeaderContext)\n\n return (\n <Stack\n className={cn(\n \"-my-0.5\",\n !wrap && \"shrink-0\",\n // A page's actions sit as close as the toolbar's controls, and on a phone they hold the\n // end of the title's line.\n size === \"page\" && \"flex-nowrap gap-1.5 max-sm:[grid-area:actions]\",\n className,\n )}\n {...props}\n />\n )\n}\n\nexport {\n BackLink,\n SectionHeader,\n SectionHeaderTitle,\n SectionHeaderBack,\n SectionHeaderBody,\n SectionHeaderDescription,\n SectionHeaderActions,\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,wBAAwB,SAAS;CACrC,MAAM;CAEN,UAAU;EACR,WAAW;GACT,MAAM;GACN,QAAQ;EACV;EACA,MAAM;GAKJ,MAAM;IACJ;IACA;IACA;GACF;GACA,MAAM;GAGN,OAAO;GACP,MAAM;EACR;EACA,MAAM;GACJ,MAAM;GACN,OAAO;EACT;CACF;CAEA,iBAAiB;EACf,WAAW;EACX,MAAM;CACR;AACF,CAAC;;;;;;;AAUD,MAAM,sBAAsB;CAC1B,MAAM;EAAE,MAAM;EAAM,IAAI;CAAK;CAC7B,MAAM;EAAE,MAAM;EAAM,IAAI;CAAK;CAC7B,OAAO;EAAE,MAAM;EAAM,IAAI;CAAK;CAC9B,MAAM;EAAE,MAAM;EAAM,IAAI;CAAK;AAC/B;AAEA,MAAM,uBAAuB,cAA0D;CACrF,MAAM;CACN,MAAM;AACR,CAAC;;;;;;AAgCD,SAAS,cAAc,EACrB,WACA,YAAY,QACZ,OAAO,QACP,OAAO,MACP,OACA,aACA,SACA,MACA,SACA,UACA,QACA,GAAG,SACkB;CACrB,MAAM,UAAU,UAAU;EACxB;EACA,gBAAgB;EAChB,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SAAS,UAAU,WAAW,GAAG,SAAiC;CAE7F,MAAM,WAAW,IAAI,oBAAoB,CAAC,CAAC,SAAS,UAAU,CAAC;CAE/D,OACE,qBAAC,OAAD;EACE,WAAW,GACT,0CACA,YAAY,mBACZ,SACF;EACA,GAAI;EANN,UAAA,CAQG,SACD,oBAAC,OAAD;GAAK,WAAW,GAAG,iCAAiC,YAAY,iBAAiB;GAC9E;EACE,CAAA,CACF;;AAET;;;;AAKA,SAAS,yBAAyB,EAAE,WAAW,GAAG,SAA8B;CAC9E,MAAM,EAAE,SAAS,IAAI,oBAAoB;CAEzC,OACE,oBAAC,KAAD;EACE,WAAW,GACT,oBAEA,SAAS,UAAU,kEACnB,SACF;EACA,GAAI;CACL,CAAA;AAEL;;;;;AAMA,SAAS,qBAAqB,EAAE,WAAW,GAAG,SAAuC;CACnF,MAAM,EAAE,MAAM,SAAS,IAAI,oBAAoB;CAE/C,OACE,oBAAC,OAAD;EACE,WAAW,GACT,WACA,CAAC,QAAQ,YAGT,SAAS,UAAU,kDACnB,SACF;EACA,GAAI;CACL,CAAA;AAEL"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Nav } from "./nav.js";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* The rail's top row, which holds the product's switcher (a site, a workspace). Give it the
|
|
5
|
+
* name a screen reader announces, such as `aria-label="Current workspace"`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function RailTop({ className, ...props }: ComponentProps<typeof Nav>): import("react").JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* The rail's bottom row, which holds the user menu's trigger. Its bottom inset grows by what a
|
|
10
|
+
* phone's home indicator needs, so the row clears it in the drawer.
|
|
11
|
+
*/
|
|
12
|
+
export declare function RailBottom({ className, ...props }: ComponentProps<typeof Nav>): import("react").JSX.Element;
|
|
13
|
+
export interface ShellProps {
|
|
14
|
+
/**
|
|
15
|
+
* The rail's top on a wide screen, usually a `RailTop` holding the switcher. The drawer leaves
|
|
16
|
+
* it out, because the phone bar holds the switcher.
|
|
17
|
+
*/
|
|
18
|
+
top?: ReactNode;
|
|
19
|
+
/** The rail's groups of `NavLink` rows. The rail and the phone drawer both show them. */
|
|
20
|
+
nav: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* What stays pinned under the rows while they scroll, usually a `RailBottom` holding the user
|
|
23
|
+
* menu's trigger, with any notice above it. The rail and the drawer both show it.
|
|
24
|
+
*/
|
|
25
|
+
footer?: ReactNode;
|
|
26
|
+
/** The phone bar after the drawer toggle, usually the switcher. It fills the bar's width. */
|
|
27
|
+
header?: ReactNode;
|
|
28
|
+
/** The phone bar's end, after `header`, such as a live count. */
|
|
29
|
+
headerEnd?: ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* A value that changes on every navigation, such as the router's current URL (TanStack
|
|
32
|
+
* Router's `location.href`, Next.js's `usePathname()`). A change closes the drawer, which
|
|
33
|
+
* covers a navigation that did not start from a link inside it.
|
|
34
|
+
*/
|
|
35
|
+
navigationKey?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the phone drawer is open, for a product that closes it from an action that is not
|
|
38
|
+
* a link, such as a menu item that opens a dialog. The shell keeps its own state without it.
|
|
39
|
+
*/
|
|
40
|
+
open?: boolean;
|
|
41
|
+
/** Runs when the drawer opens or closes, from the toggle, a link or `navigationKey`. */
|
|
42
|
+
onOpenChange?: (open: boolean) => void;
|
|
43
|
+
/** Classes for the part of the wide rail that scrolls: `top` and `nav`. */
|
|
44
|
+
railBodyClassName?: string;
|
|
45
|
+
/** The page, inside `<main>` on the shared content container. */
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The signed-in frame of a dashboard. On a wide screen (`lg`) a 224px rail sits beside the
|
|
50
|
+
* content. Under `lg` the rail gives way to one sticky bar holding the drawer toggle and the
|
|
51
|
+
* `header`. The drawer and its scrim start below the bar and show the rail's rows and footer.
|
|
52
|
+
* A plain click on any link in the drawer closes it, so a row needs no handler of its own.
|
|
53
|
+
*/
|
|
54
|
+
export declare function Shell({ top, nav, footer, header, headerEnd, navigationKey, open: openProp, onOpenChange, railBodyClassName, children }: ShellProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { SidebarIcon } from "../lib/icons.js";
|
|
3
|
+
import { FROM_LG, useMediaQuery } from "../lib/media.js";
|
|
4
|
+
import { cn } from "../lib/variants.js";
|
|
5
|
+
import { Button, buttonVariants } from "./button.js";
|
|
6
|
+
import { SideDrawer } from "./dialog.js";
|
|
7
|
+
import { Nav } from "./nav.js";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { useEffect, useState } from "react";
|
|
10
|
+
// src/components/shell.tsx
|
|
11
|
+
/**
|
|
12
|
+
* The phone bar's own height, which the drawer under it starts from. The bar's
|
|
13
|
+
* `h-[calc(3rem+env(safe-area-inset-top))]` class spells the same value out for Tailwind, which
|
|
14
|
+
* reads class names from the source; change the two together.
|
|
15
|
+
*/
|
|
16
|
+
const HEADER_HEIGHT = "calc(3rem + env(safe-area-inset-top))";
|
|
17
|
+
/**
|
|
18
|
+
* The one 40px drawer toggle, in the bar in both states: its glyph grows the panel's bar into
|
|
19
|
+
* a filled pane as the drawer opens, and it takes the fill while the drawer is open. The -11px
|
|
20
|
+
* is the space between the square's edge and the glyph's ink: 9px of centring the 22px icon in
|
|
21
|
+
* 40px, plus the 2px the panel sits inside its box. It lines the ink up with the content's inset.
|
|
22
|
+
*/
|
|
23
|
+
function DrawerToggle({ open, ...props }) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
25
|
+
variant: "ghost",
|
|
26
|
+
"aria-label": open ? "Close the menu" : "Open the menu",
|
|
27
|
+
"aria-expanded": open,
|
|
28
|
+
className: cn("-ml-[11px] size-10 shrink-0 p-0", open && "bg-fill text-ink"),
|
|
29
|
+
...props,
|
|
30
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
31
|
+
className: "flex justify-center",
|
|
32
|
+
children: /* @__PURE__ */ jsx(SidebarIcon, {
|
|
33
|
+
open,
|
|
34
|
+
className: "size-5.5"
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The rail's top row, which holds the product's switcher (a site, a workspace). Give it the
|
|
41
|
+
* name a screen reader announces, such as `aria-label="Current workspace"`.
|
|
42
|
+
*/
|
|
43
|
+
function RailTop({ className, ...props }) {
|
|
44
|
+
return /* @__PURE__ */ jsx(Nav, {
|
|
45
|
+
className: cn("pt-3 pb-1", className),
|
|
46
|
+
...props
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The rail's bottom row, which holds the user menu's trigger. Its bottom inset grows by what a
|
|
51
|
+
* phone's home indicator needs, so the row clears it in the drawer.
|
|
52
|
+
*/
|
|
53
|
+
function RailBottom({ className, ...props }) {
|
|
54
|
+
return /* @__PURE__ */ jsx(Nav, {
|
|
55
|
+
className: cn("pb-[calc(0.75rem+env(safe-area-inset-bottom))]", className),
|
|
56
|
+
...props
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The signed-in frame of a dashboard. On a wide screen (`lg`) a 224px rail sits beside the
|
|
61
|
+
* content. Under `lg` the rail gives way to one sticky bar holding the drawer toggle and the
|
|
62
|
+
* `header`. The drawer and its scrim start below the bar and show the rail's rows and footer.
|
|
63
|
+
* A plain click on any link in the drawer closes it, so a row needs no handler of its own.
|
|
64
|
+
*/
|
|
65
|
+
function Shell({ top, nav, footer, header, headerEnd, navigationKey, open: openProp, onOpenChange, railBodyClassName, children }) {
|
|
66
|
+
const [ownOpen, setOwnOpen] = useState(false);
|
|
67
|
+
const open = openProp ?? ownOpen;
|
|
68
|
+
const wide = useMediaQuery(FROM_LG);
|
|
69
|
+
function setOpen(next) {
|
|
70
|
+
if (openProp === void 0) setOwnOpen(next);
|
|
71
|
+
onOpenChange?.(next);
|
|
72
|
+
}
|
|
73
|
+
const [seen, setSeen] = useState({
|
|
74
|
+
navigationKey,
|
|
75
|
+
wide,
|
|
76
|
+
closes: 0
|
|
77
|
+
});
|
|
78
|
+
if (seen.navigationKey !== navigationKey || seen.wide !== wide) {
|
|
79
|
+
const closes = open && (seen.navigationKey !== navigationKey || wide);
|
|
80
|
+
setSeen({
|
|
81
|
+
navigationKey,
|
|
82
|
+
wide,
|
|
83
|
+
closes: seen.closes + (closes ? 1 : 0)
|
|
84
|
+
});
|
|
85
|
+
if (closes) setOwnOpen(false);
|
|
86
|
+
}
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (seen.closes > 0) onOpenChange?.(false);
|
|
89
|
+
}, [seen.closes]);
|
|
90
|
+
function closeOnLink(event) {
|
|
91
|
+
const link = event.target.closest("a[href]");
|
|
92
|
+
if (!link || !event.currentTarget.contains(link)) return;
|
|
93
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
94
|
+
if (link.hasAttribute("download")) return;
|
|
95
|
+
const linkTarget = link.getAttribute("target");
|
|
96
|
+
if (linkTarget && linkTarget !== "_self") return;
|
|
97
|
+
setOpen(false);
|
|
98
|
+
}
|
|
99
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
100
|
+
className: "flex min-h-dvh max-lg:flex-col",
|
|
101
|
+
children: [
|
|
102
|
+
/* @__PURE__ */ jsx("a", {
|
|
103
|
+
href: "#main",
|
|
104
|
+
className: buttonVariants({
|
|
105
|
+
variant: "secondary",
|
|
106
|
+
className: "sr-only absolute focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-50"
|
|
107
|
+
}),
|
|
108
|
+
children: "Skip to content"
|
|
109
|
+
}),
|
|
110
|
+
/* @__PURE__ */ jsxs("header", {
|
|
111
|
+
className: "page-container sticky top-0 z-50 flex h-[calc(3rem+env(safe-area-inset-top))] items-center gap-2 border-b bg-canvas pt-[env(safe-area-inset-top)] lg:hidden",
|
|
112
|
+
children: [
|
|
113
|
+
/* @__PURE__ */ jsx(SideDrawer, {
|
|
114
|
+
open: open && !wide,
|
|
115
|
+
offset: HEADER_HEIGHT,
|
|
116
|
+
trigger: /* @__PURE__ */ jsx(DrawerToggle, { open }),
|
|
117
|
+
className: "w-70",
|
|
118
|
+
onOpenChange: setOpen,
|
|
119
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
120
|
+
className: "contents",
|
|
121
|
+
onClick: closeOnLink,
|
|
122
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
123
|
+
className: "flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain",
|
|
124
|
+
children: nav
|
|
125
|
+
}), footer]
|
|
126
|
+
})
|
|
127
|
+
}),
|
|
128
|
+
/* @__PURE__ */ jsx("div", {
|
|
129
|
+
className: "min-w-0 flex-1",
|
|
130
|
+
children: header
|
|
131
|
+
}),
|
|
132
|
+
headerEnd
|
|
133
|
+
]
|
|
134
|
+
}),
|
|
135
|
+
/* @__PURE__ */ jsxs("aside", {
|
|
136
|
+
className: "sticky top-0 hidden h-dvh w-56 shrink-0 flex-col border-r bg-canvas lg:flex",
|
|
137
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
138
|
+
className: cn("flex min-h-0 flex-1 flex-col overflow-y-auto", railBodyClassName),
|
|
139
|
+
children: [top, nav]
|
|
140
|
+
}), footer]
|
|
141
|
+
}),
|
|
142
|
+
/* @__PURE__ */ jsx("main", {
|
|
143
|
+
id: "main",
|
|
144
|
+
className: "page-container min-w-0 flex-1 py-5",
|
|
145
|
+
children
|
|
146
|
+
})
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
export { RailBottom, RailTop, Shell };
|
|
151
|
+
|
|
152
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","names":[],"sources":["../../src/components/shell.tsx"],"sourcesContent":["\"use client\"\n\nimport { type ComponentProps, type MouseEvent, type ReactNode, useEffect, useState } from \"react\"\nimport { SidebarIcon } from \"../lib/icons\"\nimport { FROM_LG, useMediaQuery } from \"../lib/media\"\nimport { cn } from \"../lib/variants\"\nimport { Button, buttonVariants } from \"./button\"\nimport { SideDrawer } from \"./dialog\"\nimport { Nav } from \"./nav\"\n\n/**\n * The phone bar's own height, which the drawer under it starts from. The bar's\n * `h-[calc(3rem+env(safe-area-inset-top))]` class spells the same value out for Tailwind, which\n * reads class names from the source; change the two together.\n */\nconst HEADER_HEIGHT = \"calc(3rem + env(safe-area-inset-top))\"\n\ninterface DrawerToggleProps extends ComponentProps<typeof Button> {\n open: boolean\n}\n\n/**\n * The one 40px drawer toggle, in the bar in both states: its glyph grows the panel's bar into\n * a filled pane as the drawer opens, and it takes the fill while the drawer is open. The -11px\n * is the space between the square's edge and the glyph's ink: 9px of centring the 22px icon in\n * 40px, plus the 2px the panel sits inside its box. It lines the ink up with the content's inset.\n */\nfunction DrawerToggle({ open, ...props }: DrawerToggleProps) {\n return (\n <Button\n variant=\"ghost\"\n aria-label={open ? \"Close the menu\" : \"Open the menu\"}\n aria-expanded={open}\n className={cn(\"-ml-[11px] size-10 shrink-0 p-0\", open && \"bg-fill text-ink\")}\n {...props}\n >\n <span className=\"flex justify-center\">\n <SidebarIcon open={open} className=\"size-5.5\" />\n </span>\n </Button>\n )\n}\n\n/**\n * The rail's top row, which holds the product's switcher (a site, a workspace). Give it the\n * name a screen reader announces, such as `aria-label=\"Current workspace\"`.\n */\nexport function RailTop({ className, ...props }: ComponentProps<typeof Nav>) {\n return <Nav className={cn(\"pt-3 pb-1\", className)} {...props} />\n}\n\n/**\n * The rail's bottom row, which holds the user menu's trigger. Its bottom inset grows by what a\n * phone's home indicator needs, so the row clears it in the drawer.\n */\nexport function RailBottom({ className, ...props }: ComponentProps<typeof Nav>) {\n return (\n <Nav className={cn(\"pb-[calc(0.75rem+env(safe-area-inset-bottom))]\", className)} {...props} />\n )\n}\n\nexport interface ShellProps {\n /**\n * The rail's top on a wide screen, usually a `RailTop` holding the switcher. The drawer leaves\n * it out, because the phone bar holds the switcher.\n */\n top?: ReactNode\n\n /** The rail's groups of `NavLink` rows. The rail and the phone drawer both show them. */\n nav: ReactNode\n\n /**\n * What stays pinned under the rows while they scroll, usually a `RailBottom` holding the user\n * menu's trigger, with any notice above it. The rail and the drawer both show it.\n */\n footer?: ReactNode\n\n /** The phone bar after the drawer toggle, usually the switcher. It fills the bar's width. */\n header?: ReactNode\n\n /** The phone bar's end, after `header`, such as a live count. */\n headerEnd?: ReactNode\n\n /**\n * A value that changes on every navigation, such as the router's current URL (TanStack\n * Router's `location.href`, Next.js's `usePathname()`). A change closes the drawer, which\n * covers a navigation that did not start from a link inside it.\n */\n navigationKey?: string\n\n /**\n * Whether the phone drawer is open, for a product that closes it from an action that is not\n * a link, such as a menu item that opens a dialog. The shell keeps its own state without it.\n */\n open?: boolean\n\n /** Runs when the drawer opens or closes, from the toggle, a link or `navigationKey`. */\n onOpenChange?: (open: boolean) => void\n\n /** Classes for the part of the wide rail that scrolls: `top` and `nav`. */\n railBodyClassName?: string\n\n /** The page, inside `<main>` on the shared content container. */\n children: ReactNode\n}\n\n/**\n * The signed-in frame of a dashboard. On a wide screen (`lg`) a 224px rail sits beside the\n * content. Under `lg` the rail gives way to one sticky bar holding the drawer toggle and the\n * `header`. The drawer and its scrim start below the bar and show the rail's rows and footer.\n * A plain click on any link in the drawer closes it, so a row needs no handler of its own.\n */\nexport function Shell({\n top,\n nav,\n footer,\n header,\n headerEnd,\n navigationKey,\n open: openProp,\n onOpenChange,\n railBodyClassName,\n children,\n}: ShellProps) {\n const [ownOpen, setOwnOpen] = useState(false)\n const open = openProp ?? ownOpen\n const wide = useMediaQuery(FROM_LG)\n\n function setOpen(next: boolean) {\n if (openProp === undefined) setOwnOpen(next)\n onOpenChange?.(next)\n }\n\n // A navigation that did not start in the drawer closes it, and so does a screen that grows\n // past `lg` (a tablet turned to landscape), where the rail takes the drawer's place. The own\n // state closes during this render; a caller holding `open` hears it from the effect below,\n // since a parent's state cannot change while this component renders.\n const [seen, setSeen] = useState({ navigationKey, wide, closes: 0 })\n if (seen.navigationKey !== navigationKey || seen.wide !== wide) {\n const closes = open && (seen.navigationKey !== navigationKey || wide)\n setSeen({ navigationKey, wide, closes: seen.closes + (closes ? 1 : 0) })\n if (closes) setOwnOpen(false)\n }\n\n useEffect(() => {\n if (seen.closes > 0) onOpenChange?.(false)\n }, [seen.closes])\n\n // Only a link the drawer's own DOM holds closes it. A menu opened from the drawer renders in a\n // portal, whose clicks still bubble here through React, and it closes itself. A link that\n // opens elsewhere (a modifier held, a `target` other than `_self`, a download) leaves the\n // reader here.\n function closeOnLink(event: MouseEvent<HTMLDivElement>) {\n const target = event.target as Element\n const link = target.closest(\"a[href]\")\n if (!link || !event.currentTarget.contains(link)) return\n if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return\n if (link.hasAttribute(\"download\")) return\n const linkTarget = link.getAttribute(\"target\")\n if (linkTarget && linkTarget !== \"_self\") return\n setOpen(false)\n }\n\n return (\n <div className=\"flex min-h-dvh max-lg:flex-col\">\n {/* The rail comes before the content in the source, so the first Tab of a fresh page\n offers the way past it. `absolute` restates what `sr-only` sets, since the button's\n own `relative` would otherwise win and leave a 1px flex item in the row. */}\n <a\n href=\"#main\"\n className={buttonVariants({\n variant: \"secondary\",\n className:\n \"sr-only absolute focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-50\",\n })}\n >\n Skip to content\n </a>\n\n {/* The content's inset (`page-container`), so the bar's contents line up with the page. The\n height is `HEADER_HEIGHT`, written out as a class. */}\n <header className=\"page-container sticky top-0 z-50 flex h-[calc(3rem+env(safe-area-inset-top))] items-center gap-2 border-b bg-canvas pt-[env(safe-area-inset-top)] lg:hidden\">\n <SideDrawer\n // Never shown beside the rail, even for the frame before the effect above closes it.\n open={open && !wide}\n offset={HEADER_HEIGHT}\n trigger={<DrawerToggle open={open} />}\n className=\"w-70\"\n onOpenChange={setOpen}\n >\n {/* `contents` keeps the rows and the footer laid out by the drawer, while one listener\n hears a click on a link in either. */}\n {/* oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions -- the links inside take the keyboard, and Enter on a link fires this click too */}\n <div className=\"contents\" onClick={closeOnLink}>\n {/* Only the rows scroll, so the footer stays in reach on a short screen, as it does\n in the rail. */}\n <div className=\"flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain\">\n {nav}\n </div>\n\n {footer}\n </div>\n </SideDrawer>\n\n <div className=\"min-w-0 flex-1\">{header}</div>\n\n {headerEnd}\n </header>\n\n <aside className=\"sticky top-0 hidden h-dvh w-56 shrink-0 flex-col border-r bg-canvas lg:flex\">\n <div className={cn(\"flex min-h-0 flex-1 flex-col overflow-y-auto\", railBodyClassName)}>\n {top}\n {nav}\n </div>\n\n {footer}\n </aside>\n\n {/* Top and bottom stay on the grid's 20px gap at every width, so the first and last\n card sit as far from the viewport edge as they do from each other. */}\n <main id=\"main\" className=\"page-container min-w-0 flex-1 py-5\">\n {children}\n </main>\n </div>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,gBAAgB;;;;;;;AAYtB,SAAS,aAAa,EAAE,MAAM,GAAG,SAA4B;CAC3D,OACE,oBAAC,QAAD;EACE,SAAQ;EACR,cAAY,OAAO,mBAAmB;EACtC,iBAAe;EACf,WAAW,GAAG,mCAAmC,QAAQ,kBAAkB;EAC3E,GAAI;EAEJ,UAAA,oBAAC,QAAD;GAAM,WAAU;GACd,UAAA,oBAAC,aAAD;IAAmB;IAAM,WAAU;GAAY,CAAA;EAC3C,CAAA;CACA,CAAA;AAEZ;;;;;AAMA,SAAgB,QAAQ,EAAE,WAAW,GAAG,SAAqC;CAC3E,OAAO,oBAAC,KAAD;EAAK,WAAW,GAAG,aAAa,SAAS;EAAG,GAAI;CAAQ,CAAA;AACjE;;;;;AAMA,SAAgB,WAAW,EAAE,WAAW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AAA;GAIH,qBAAC,UAAD;IAAQ,WAAU;IAAlB,UAAA;KACE,oBAAC,YAAD;MAEE,MAAM,QAAQ,CAAC;MACf,QAAQ;MACR,SAAS,oBAAC,cAAD,EAAoB,KAAO,CAAA;MACpC,WAAU;MACV,cAAc;MAKd,UAAA,qBAAC,OAAD;OAAK,WAAU;OAAW,SAAS;OAAnC,UAAA,CAGE,oBAAC,OAAD;QAAK,WAAU;QACZ,UAAA;OACE,CAAA,GAEJ,MACE;;KACK,CAAA;KAEZ,oBAAC,OAAD;MAAK,WAAU;MAAkB,UAAA;KAAY,CAAA;KAE5C;IACK;;GAER,qBAAC,SAAD;IAAO,WAAU;IAAjB,UAAA,CACE,qBAAC,OAAD;KAAK,WAAW,GAAG,gDAAgD,iBAAiB;KAApF,UAAA,CACG,KACA,GACE;IAEJ,CAAA,GAAA,MACI;;GAIP,oBAAC,QAAD;IAAM,IAAG;IAAO,WAAU;IACvB;GACG,CAAA;EACH;;AAET"}
|
package/components/table.d.ts
CHANGED
|
@@ -232,6 +232,18 @@ export declare function TablePersonCell({ avatar, name, ...props }: TablePersonC
|
|
|
232
232
|
* open, and always on a touch screen, which has no hover to give.
|
|
233
233
|
*/
|
|
234
234
|
export declare function TableActionsCell({ align, className, children, ...props }: TableCellProps): import("react").JSX.Element;
|
|
235
|
+
interface TableActionsMenuProps {
|
|
236
|
+
/** Names the menu and its trigger for a screen reader: "Actions for figma.com". */
|
|
237
|
+
label: string;
|
|
238
|
+
/** Classes for the trigger, e.g. its place on a card. */
|
|
239
|
+
className?: string;
|
|
240
|
+
children: ReactNode;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The row's "…" menu, for a `TableActionsCell`: `ActionsMenu` at its `row` placement, a quiet
|
|
244
|
+
* ghost trigger that grows to finger size on a touch screen, and a menu aligned to the row's end.
|
|
245
|
+
*/
|
|
246
|
+
export declare function TableActionsMenu(props: TableActionsMenuProps): import("react").JSX.Element;
|
|
235
247
|
interface TableCheckboxCellProps extends Omit<TableCellProps, "children" | "onChange">, Pick<ComponentProps<typeof Checkbox>, "checked" | "indeterminate" | "disabled" | "onCheckedChange"> {
|
|
236
248
|
/** Names the checkbox: "Select openalternative.com", "Select all". */
|
|
237
249
|
label: string;
|
|
@@ -266,11 +278,16 @@ interface TableMessageProps {
|
|
|
266
278
|
icon?: ReactNode;
|
|
267
279
|
title: ReactNode;
|
|
268
280
|
description?: ReactNode;
|
|
281
|
+
/** The message's button. Left out, an `error` with `onRetry` draws the retry button. */
|
|
269
282
|
action?: ReactNode;
|
|
283
|
+
/** Loads the rows again, from the "Try again" button of an `error`. */
|
|
284
|
+
onRetry?: () => void;
|
|
285
|
+
/** The retry button's label. */
|
|
286
|
+
retryLabel?: ReactNode;
|
|
270
287
|
}
|
|
271
288
|
/**
|
|
272
289
|
* Stands in for the rows: the small empty state across every column, under the header, which
|
|
273
290
|
* keeps its line. Put it inside `TableBody`.
|
|
274
291
|
*/
|
|
275
|
-
export declare function TableMessage({ kind, icon, title, description, action }: TableMessageProps): import("react").JSX.Element;
|
|
292
|
+
export declare function TableMessage({ kind, icon, title, description, action, onRetry, retryLabel }: TableMessageProps): import("react").JSX.Element;
|
|
276
293
|
export {};
|