@alulore/kumiko 0.18.2 → 0.19.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.
Files changed (147) hide show
  1. package/dist/dialog/ask.d.ts +7 -0
  2. package/dist/dialog/ask.js +8 -0
  3. package/dist/dialog/dialog-content.d.ts +23 -0
  4. package/dist/dialog/dialog-content.js +15 -0
  5. package/dist/dialog/dialog-entry.d.ts +14 -0
  6. package/dist/dialog/dialog-entry.js +111 -0
  7. package/dist/dialog/dialog-labels.d.ts +23 -0
  8. package/dist/dialog/dialog-labels.js +16 -0
  9. package/dist/dialog/dialog-store.d.ts +139 -0
  10. package/dist/dialog/dialog-store.js +296 -0
  11. package/dist/dialog/dialog.css +39 -1
  12. package/dist/dialog/dialog.d.ts +0 -3
  13. package/dist/dialog/dialog.js +0 -6
  14. package/dist/dialog/index.d.ts +8 -2
  15. package/dist/dialog/index.js +7 -2
  16. package/dist/dialog/leave-guard.d.ts +24 -0
  17. package/dist/dialog/leave-guard.js +98 -0
  18. package/dist/dialog/nest.d.ts +14 -0
  19. package/dist/dialog/nest.js +26 -0
  20. package/dist/dialog/open-dialog.d.ts +16 -0
  21. package/dist/dialog/open-dialog.js +13 -0
  22. package/dist/dialog/overlay-host.d.ts +27 -0
  23. package/dist/dialog/overlay-host.js +47 -0
  24. package/dist/dialog/question-dialog.d.ts +21 -0
  25. package/dist/dialog/question-dialog.js +78 -0
  26. package/dist/drawer/drawer.css +18 -16
  27. package/dist/menu/menu.css +21 -17
  28. package/dist/otp-input/otp-input.css +38 -37
  29. package/dist/page/index.d.ts +8 -0
  30. package/dist/page/index.js +8 -0
  31. package/dist/page/page-action.d.ts +26 -0
  32. package/dist/page/page-action.js +23 -0
  33. package/dist/page/page-actions.d.ts +10 -0
  34. package/dist/page/page-actions.js +66 -0
  35. package/dist/page/page-back.d.ts +11 -0
  36. package/dist/page/page-back.js +17 -0
  37. package/dist/page/page-breadcrumbs.d.ts +21 -0
  38. package/dist/page/page-breadcrumbs.js +60 -0
  39. package/dist/page/page-context.d.ts +5 -0
  40. package/dist/page/page-context.js +13 -0
  41. package/dist/page/page-fit.d.ts +26 -0
  42. package/dist/page/page-fit.js +36 -0
  43. package/dist/page/page-header.d.ts +26 -0
  44. package/dist/page/page-header.js +16 -0
  45. package/dist/page/page-icons.d.ts +4 -0
  46. package/dist/page/page-icons.js +13 -0
  47. package/dist/page/page-labels.d.ts +12 -0
  48. package/dist/page/page-labels.js +6 -0
  49. package/dist/page/page-section.d.ts +14 -0
  50. package/dist/page/page-section.js +9 -0
  51. package/dist/page/page.css +422 -0
  52. package/dist/page/page.d.ts +16 -0
  53. package/dist/page/page.js +12 -0
  54. package/dist/page/use-measured-fit.d.ts +22 -0
  55. package/dist/page/use-measured-fit.js +75 -0
  56. package/dist/page/use-stuck.d.ts +7 -0
  57. package/dist/page/use-stuck.js +31 -0
  58. package/dist/pagination/index.d.ts +3 -0
  59. package/dist/pagination/index.js +3 -0
  60. package/dist/pagination/pagination-extras.d.ts +28 -0
  61. package/dist/pagination/pagination-extras.js +42 -0
  62. package/dist/pagination/pagination-fit.d.ts +15 -0
  63. package/dist/pagination/pagination-fit.js +52 -0
  64. package/dist/pagination/pagination-icons.d.ts +4 -0
  65. package/dist/pagination/pagination-icons.js +16 -0
  66. package/dist/pagination/pagination-labels.d.ts +23 -0
  67. package/dist/pagination/pagination-labels.js +14 -0
  68. package/dist/pagination/pagination-math.d.ts +7 -0
  69. package/dist/pagination/pagination-math.js +24 -0
  70. package/dist/pagination/pagination-motion.d.ts +6 -0
  71. package/dist/pagination/pagination-motion.js +71 -0
  72. package/dist/pagination/pagination.css +455 -0
  73. package/dist/pagination/pagination.d.ts +59 -0
  74. package/dist/pagination/pagination.js +77 -0
  75. package/dist/select/select.css +6 -10
  76. package/dist/server-render.test.js +49 -0
  77. package/dist/sidebar/app-shell.d.ts +54 -0
  78. package/dist/sidebar/app-shell.js +28 -0
  79. package/dist/sidebar/index.d.ts +9 -0
  80. package/dist/sidebar/index.js +8 -0
  81. package/dist/sidebar/shell-context.d.ts +30 -0
  82. package/dist/sidebar/shell-context.js +20 -0
  83. package/dist/sidebar/shell-sheet.d.ts +7 -0
  84. package/dist/sidebar/shell-sheet.js +12 -0
  85. package/dist/sidebar/shell-top-bar.d.ts +8 -0
  86. package/dist/sidebar/shell-top-bar.js +25 -0
  87. package/dist/sidebar/sidebar-body.d.ts +5 -0
  88. package/dist/sidebar/sidebar-body.js +37 -0
  89. package/dist/sidebar/sidebar-icons.d.ts +4 -0
  90. package/dist/sidebar/sidebar-icons.js +13 -0
  91. package/dist/sidebar/sidebar-item.d.ts +26 -0
  92. package/dist/sidebar/sidebar-item.js +68 -0
  93. package/dist/sidebar/sidebar-labels.d.ts +14 -0
  94. package/dist/sidebar/sidebar-labels.js +7 -0
  95. package/dist/sidebar/sidebar-marker.d.ts +12 -0
  96. package/dist/sidebar/sidebar-marker.js +77 -0
  97. package/dist/sidebar/sidebar-storage.d.ts +18 -0
  98. package/dist/sidebar/sidebar-storage.js +27 -0
  99. package/dist/sidebar/sidebar-toggle.d.ts +7 -0
  100. package/dist/sidebar/sidebar-toggle.js +18 -0
  101. package/dist/sidebar/sidebar.css +587 -0
  102. package/dist/sidebar/sidebar.d.ts +19 -0
  103. package/dist/sidebar/sidebar.js +31 -0
  104. package/dist/sidebar/use-collapsed.d.ts +13 -0
  105. package/dist/sidebar/use-collapsed.js +20 -0
  106. package/dist/sidebar/use-narrow.d.ts +4 -0
  107. package/dist/sidebar/use-narrow.js +18 -0
  108. package/dist/sidebar/use-shell-focus.d.ts +8 -0
  109. package/dist/sidebar/use-shell-focus.js +30 -0
  110. package/dist/sidebar/use-shell-shortcut.d.ts +4 -0
  111. package/dist/sidebar/use-shell-shortcut.js +32 -0
  112. package/dist/sidebar/use-shell-state.d.ts +18 -0
  113. package/dist/sidebar/use-shell-state.js +47 -0
  114. package/dist/slider/slider.css +9 -6
  115. package/dist/smooth-caret/caret-geometry.js +10 -4
  116. package/dist/table/data-table-props.d.ts +96 -0
  117. package/dist/table/data-table-props.js +1 -0
  118. package/dist/table/data-table.d.ts +7 -0
  119. package/dist/table/data-table.js +59 -0
  120. package/dist/table/index.d.ts +7 -0
  121. package/dist/table/index.js +5 -0
  122. package/dist/table/table-actions.d.ts +9 -0
  123. package/dist/table/table-actions.js +24 -0
  124. package/dist/table/table-builder.d.ts +60 -0
  125. package/dist/table/table-builder.js +99 -0
  126. package/dist/table/table-cells.d.ts +19 -0
  127. package/dist/table/table-cells.js +67 -0
  128. package/dist/table/table-columns.d.ts +38 -0
  129. package/dist/table/table-columns.js +119 -0
  130. package/dist/table/table-icons.d.ts +3 -0
  131. package/dist/table/table-icons.js +8 -0
  132. package/dist/table/table-labels.d.ts +24 -0
  133. package/dist/table/table-labels.js +17 -0
  134. package/dist/table/table-model.d.ts +28 -0
  135. package/dist/table/table-model.js +69 -0
  136. package/dist/table/table-sections.d.ts +25 -0
  137. package/dist/table/table-sections.js +79 -0
  138. package/dist/table/table-state.d.ts +42 -0
  139. package/dist/table/table-state.js +81 -0
  140. package/dist/table/table-types.d.ts +86 -0
  141. package/dist/table/table-types.js +1 -0
  142. package/dist/table/table.css +919 -0
  143. package/dist/table/use-table-view.d.ts +30 -0
  144. package/dist/table/use-table-view.js +147 -0
  145. package/dist/toast/index.d.ts +1 -2
  146. package/dist/toast/index.js +1 -2
  147. package/package.json +44 -1
@@ -96,9 +96,13 @@
96
96
  box-sizing: border-box;
97
97
  inline-size: var(--_otp-w);
98
98
  block-size: var(--_otp-h);
99
- border: var(--kumiko-otp-border-width) solid var(--kumiko-otp-border);
99
+ border: var(--kumiko-otp-border-width) solid
100
+ var(
101
+ --_otp-edge-locked,
102
+ var(--_otp-edge-invalid, var(--_otp-edge-hover, var(--kumiko-otp-border)))
103
+ );
100
104
  border-radius: var(--kumiko-otp-radius);
101
- background: var(--kumiko-otp-bg);
105
+ background: var(--_otp-fill, var(--kumiko-otp-bg));
102
106
  font-family: var(--kumiko-otp-font-family);
103
107
  font-size: var(--_otp-fs);
104
108
  font-weight: var(--kumiko-otp-font-weight);
@@ -110,24 +114,29 @@
110
114
  box-shadow var(--kumiko-fade-duration) var(--kumiko-fade-ease);
111
115
  }
112
116
 
117
+ /*
118
+ * A slot's edge, strongest first: read-only, invalid, hover, then filled or plain; the active slot puts
119
+ * invalid first and takes the accent. The code passes its state down as properties, because a :has() before
120
+ * a combinator would restyle the whole page on every change.
121
+ */
113
122
  :where([data-slot="otp-input-slot"][data-filled]) {
114
- border-color: var(--kumiko-otp-filled-border);
123
+ border-color: var(
124
+ --_otp-edge-locked,
125
+ var(--_otp-edge-invalid, var(--_otp-edge-hover, var(--kumiko-otp-filled-border)))
126
+ );
115
127
  }
116
128
 
117
129
  @media (hover: hover) and (pointer: fine) {
118
- :where(
119
- [data-slot="otp-input"]:not([data-disabled]):not(:has(input[readonly])):hover
120
- [data-slot="otp-input-slot"]:not([data-active])
121
- ) {
122
- border-color: var(--kumiko-otp-border-hover);
130
+ :where([data-slot="otp-input"]:not([data-disabled]):not(:has(input[readonly])):hover) {
131
+ --_otp-edge-hover: var(--kumiko-otp-border-hover);
123
132
  }
124
133
  }
125
134
 
126
135
  /* The slot typing goes to: the accent edge and a soft ring, as a focused text field has. */
127
136
  :where([data-slot="otp-input-slot"][data-active]) {
128
137
  z-index: 1;
129
- border-color: var(--_otp-accent);
130
- box-shadow: 0 0 0 var(--kumiko-otp-ring-width) var(--_otp-ring);
138
+ border-color: var(--_otp-edge-invalid, var(--_otp-edge-locked, var(--_otp-accent)));
139
+ box-shadow: var(--_otp-active-ring, 0 0 0 var(--kumiko-otp-ring-width) var(--_otp-ring));
131
140
  }
132
141
 
133
142
  /* The caret: the input's own is hidden, so an empty active slot draws one, blinking. */
@@ -135,8 +144,8 @@
135
144
  inline-size: var(--kumiko-otp-caret-width);
136
145
  block-size: 1.1em;
137
146
  border-radius: var(--kumiko-otp-caret-width);
138
- background: var(--_otp-accent);
139
- content: "";
147
+ background: var(--_otp-caret-fill, var(--_otp-accent));
148
+ content: var(--_otp-caret, "");
140
149
  animation: kumiko-otp-caret var(--_otp-caret-blink-duration) ease-in-out infinite;
141
150
  }
142
151
 
@@ -236,22 +245,18 @@
236
245
  }
237
246
 
238
247
  & [data-slot="otp-input-slot"][data-active] {
239
- box-shadow: 0 var(--kumiko-otp-ring-width) 0 -1px var(--_otp-ring);
248
+ box-shadow: var(
249
+ --_otp-active-ring,
250
+ 0 var(--kumiko-otp-ring-width) 0 -1px var(--_otp-ring)
251
+ );
240
252
  }
241
253
  }
242
254
 
243
255
  /* An invalid code: the error colour, and one shake as it turns invalid. */
244
256
  :where([data-slot="otp-input"]:has(input[aria-invalid="true"])) {
245
257
  --_otp-ring: color-mix(in oklab, var(--_otp-invalid) 28%, transparent);
246
-
247
- & [data-slot="otp-input-slot"],
248
- & [data-slot="otp-input-slot"][data-active] {
249
- border-color: var(--_otp-invalid);
250
- }
251
-
252
- & [data-slot="otp-input-slot"][data-fake-caret]::after {
253
- background: var(--_otp-invalid);
254
- }
258
+ --_otp-edge-invalid: var(--_otp-invalid);
259
+ --_otp-caret-fill: var(--_otp-invalid);
255
260
  }
256
261
 
257
262
  /*
@@ -262,9 +267,13 @@
262
267
  [data-slot="otp-input"]:not([data-shake="false"]):not(
263
268
  :not([data-shake]):is([data-kumiko-otp~="no-shake"] *)
264
269
  ):has(input[aria-invalid="true"])
265
- [data-slot="otp-input-group"]
266
270
  ) {
267
- animation: kumiko-otp-shake calc(var(--kumiko-move-duration) * 1.5) var(--kumiko-move-ease);
271
+ --_otp-shake: kumiko-otp-shake;
272
+ }
273
+
274
+ :where([data-slot="otp-input-group"]) {
275
+ animation: var(--_otp-shake, none) calc(var(--kumiko-move-duration) * 1.5)
276
+ var(--kumiko-move-ease);
268
277
  }
269
278
 
270
279
  @keyframes kumiko-otp-shake {
@@ -287,20 +296,12 @@
287
296
 
288
297
  /* Read-only shows the code without inviting typing: no fill, a quiet edge and no caret. */
289
298
  :where([data-slot="otp-input"]:has(input[readonly])) {
290
- cursor: default;
291
-
292
- & [data-slot="otp-input-slot"] {
293
- border-color: var(--_otp-readonly-border);
294
- background: transparent;
295
- }
299
+ --_otp-edge-locked: var(--_otp-readonly-border);
300
+ --_otp-fill: transparent;
301
+ --_otp-active-ring: none;
302
+ --_otp-caret: none;
296
303
 
297
- & [data-slot="otp-input-slot"][data-active] {
298
- box-shadow: none;
299
- }
300
-
301
- & [data-slot="otp-input-slot"][data-fake-caret]::after {
302
- content: none;
303
- }
304
+ cursor: default;
304
305
  }
305
306
 
306
307
  :where([data-slot="otp-input"][data-disabled]) {
@@ -0,0 +1,8 @@
1
+ export { Page, type PageProps, type PageWidth } from "./page";
2
+ export { PageAction, type PageActionProps } from "./page-action";
3
+ export { PageActions } from "./page-actions";
4
+ export { PageBack, type PageBackProps } from "./page-back";
5
+ export { PageBreadcrumbs, PageCrumb, type PageCrumbProps } from "./page-breadcrumbs";
6
+ export { PageHeader, type PageHeaderProps } from "./page-header";
7
+ export { pageLabels, type PageLabels } from "./page-labels";
8
+ export { PageSection, type PageSectionProps } from "./page-section";
@@ -0,0 +1,8 @@
1
+ export { Page } from "./page";
2
+ export { PageAction } from "./page-action";
3
+ export { PageActions } from "./page-actions";
4
+ export { PageBack } from "./page-back";
5
+ export { PageBreadcrumbs, PageCrumb } from "./page-breadcrumbs";
6
+ export { PageHeader } from "./page-header";
7
+ export { pageLabels } from "./page-labels";
8
+ export { PageSection } from "./page-section";
@@ -0,0 +1,26 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ export interface PageActionProps {
3
+ /** What the action says. */
4
+ children: ReactNode;
5
+ /** An icon before the label. It follows the folded action into the menu. */
6
+ icon?: ReactNode;
7
+ /** The main action of the page. It looks solid and never folds into the menu. @defaultValue false */
8
+ primary?: boolean;
9
+ /** `"danger"` warns that the action destroys something, inline and in the menu. */
10
+ tone?: "danger";
11
+ /** Stops the action, inline and in the menu. @defaultValue false */
12
+ disabled?: boolean;
13
+ /** Makes the action a link to `href`. Without `href` or `render`, it is a button. */
14
+ href?: string;
15
+ /** The app's own link, such as `<Link to="/billing" />`. The action's props and content go into it. */
16
+ render?: ReactElement;
17
+ /** Runs when the action is chosen, inline or from the menu. A Promise it returns shows the button as loading. */
18
+ onClick?: () => unknown;
19
+ }
20
+ /** The element a link action is drawn with, or nothing for a button. */
21
+ export declare function linkElement(props: Pick<PageActionProps, "href" | "render">): ReactElement | undefined;
22
+ /**
23
+ * One action in a `PageActions`: a button, a link, or the app's own link. When there is no room it folds into the
24
+ * "More actions" menu with the same label, icon, tone and disabled state.
25
+ */
26
+ export declare function PageAction({ children, icon, primary, tone, disabled, href, render, onClick }: PageActionProps): React.JSX.Element;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from "../button";
3
+ /** The element a link action is drawn with, or nothing for a button. */
4
+ export function linkElement(props) {
5
+ if (props.render) {
6
+ return props.render;
7
+ }
8
+ return props.href === undefined ? undefined : _jsx("a", { href: props.href });
9
+ }
10
+ /**
11
+ * One action in a `PageActions`: a button, a link, or the app's own link. When there is no room it folds into the
12
+ * "More actions" menu with the same label, icon, tone and disabled state.
13
+ */
14
+ export function PageAction({ children, icon, primary, tone, disabled, href, render, onClick }) {
15
+ let variant = "outline";
16
+ if (primary) {
17
+ variant = "solid";
18
+ }
19
+ else if (tone === "danger") {
20
+ variant = "destructive-ghost";
21
+ }
22
+ return (_jsxs(Button, { "data-page-action": "", "data-tone": tone, variant: variant, disabled: disabled, render: linkElement({ href, render }), onClick: () => onClick?.(), children: [icon ? (_jsx("span", { "data-slot": "page-action-icon", "aria-hidden": "true", children: icon })) : null, children] }));
23
+ }
@@ -0,0 +1,10 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * The actions of a page or a section: `PageAction`s, and anything else the app wants beside them. It watches the
4
+ * room it has, and the actions that don't fit fold, from the end, into a "More actions" menu. The primary action and
5
+ * anything that is not a `PageAction` stay where they are. A server draws every action, and the client folds them
6
+ * before its first paint. In the sticky bar every action but the primary one is folded.
7
+ */
8
+ export declare function PageActions({ children }: {
9
+ children: ReactNode;
10
+ }): React.JSX.Element;
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, isValidElement } from "react";
3
+ import { Button } from "../button";
4
+ import { Menu, MenuContent, MenuItem, MenuItemIcon, MenuTrigger } from "../menu";
5
+ import { PageAction, linkElement } from "./page-action";
6
+ import { useInStickyBar, usePageLabels } from "./page-context";
7
+ import { foldedActions } from "./page-fit";
8
+ import { MoreIcon } from "./page-icons";
9
+ import { useMeasuredFit } from "./use-measured-fit";
10
+ /** A guess at the menu button's width, until it has been on screen once. */
11
+ const moreGuess = 40;
12
+ function actionProps(item) {
13
+ return isValidElement(item) && item.type === PageAction
14
+ ? item.props
15
+ : undefined;
16
+ }
17
+ function FoldedItem({ index, action }) {
18
+ return (_jsxs(MenuItem, { value: String(index), disabled: action.disabled, destructive: action.tone === "danger", render: linkElement(action), onSelect: () => action.onClick?.(), children: [action.icon ? _jsx(MenuItemIcon, { children: action.icon }) : null, action.children] }));
19
+ }
20
+ function FoldedMenu({ items, folded }) {
21
+ const labels = usePageLabels();
22
+ return (_jsx("span", { "data-slot": "page-actions-item", "data-fit-extra": "", children: _jsxs(Menu, { children: [_jsx(MenuTrigger, { render: _jsx(Button, { variant: "outline", icon: true, "aria-label": labels.moreActions }), children: _jsx(MoreIcon, {}) }), _jsx(MenuContent, { align: "end", children: items.map((item, index) => {
23
+ const action = actionProps(item);
24
+ return folded.has(index) && action ? (_jsx(FoldedItem, { index: index, action: action }, isValidElement(item) ? item.key : index)) : null;
25
+ }) })] }) }));
26
+ }
27
+ function toSet(value) {
28
+ return new Set(value
29
+ .split(",")
30
+ .filter((part) => part !== "")
31
+ .map(Number));
32
+ }
33
+ /**
34
+ * The actions of a page or a section: `PageAction`s, and anything else the app wants beside them. It watches the
35
+ * room it has, and the actions that don't fit fold, from the end, into a "More actions" menu. The primary action and
36
+ * anything that is not a `PageAction` stay where they are. A server draws every action, and the client folds them
37
+ * before its first paint. In the sticky bar every action but the primary one is folded.
38
+ */
39
+ export function PageActions({ children }) {
40
+ const sticky = useInStickyBar();
41
+ const items = Children.toArray(children);
42
+ const foldable = items.map((item) => {
43
+ const action = actionProps(item);
44
+ return action !== undefined && !action.primary;
45
+ });
46
+ const { value, rootRef } = useMeasuredFit({
47
+ enabled: !sticky,
48
+ initial: "",
49
+ decide: (sizes) => foldedActions({
50
+ widths: items.map((_, index) => sizes.widths[index]),
51
+ foldable,
52
+ room: sizes.room,
53
+ gap: sizes.gap,
54
+ more: sizes.extra ?? moreGuess
55
+ }).join(",")
56
+ });
57
+ const folded = sticky
58
+ ? new Set(foldable.flatMap((can, index) => (can ? [index] : [])))
59
+ : toSet(value);
60
+ for (const index of folded) {
61
+ if (!foldable[index]) {
62
+ folded.delete(index);
63
+ }
64
+ }
65
+ return (_jsxs("div", { ref: rootRef, "data-slot": "page-actions", "data-sticky": sticky || undefined, children: [items.map((item, index) => folded.has(index) ? null : (_jsx("span", { "data-slot": "page-actions-item", "data-fit-index": index, children: item }, isValidElement(item) ? item.key : index))), folded.size > 0 ? _jsx(FoldedMenu, { items: items, folded: folded }) : null] }));
66
+ }
@@ -0,0 +1,11 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ export interface PageBackProps extends Omit<React.HTMLAttributes<HTMLElement>, "children"> {
3
+ /** Where it goes, such as "Customers". Without it, the page's "Back" word. */
4
+ children?: ReactNode;
5
+ /** Makes it a link to `href`. Without `href` or `render`, it is a button. */
6
+ href?: string;
7
+ /** The app's own link, such as `<Link to="/customers" />`. The props and content go into it. */
8
+ render?: ReactElement;
9
+ }
10
+ /** The way back, above the title: an arrow that points to the start, in a link, the app's own link, or a button. */
11
+ export declare function PageBack({ children, href, render, ...props }: PageBackProps): React.JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cloneElement } from "react";
3
+ import { usePageLabels } from "./page-context";
4
+ import { BackIcon } from "./page-icons";
5
+ /** The way back, above the title: an arrow that points to the start, in a link, the app's own link, or a button. */
6
+ export function PageBack({ children, href, render, ...props }) {
7
+ const labels = usePageLabels();
8
+ const own = { ...props, "data-slot": "page-back" };
9
+ const content = (_jsxs(_Fragment, { children: [_jsx(BackIcon, {}), _jsx("span", { "data-slot": "page-back-label", children: children ?? labels.back })] }));
10
+ if (render) {
11
+ return cloneElement(render, own, content);
12
+ }
13
+ if (href === undefined) {
14
+ return (_jsx("button", { type: "button", ...own, children: content }));
15
+ }
16
+ return (_jsx("a", { href: href, ...own, children: content }));
17
+ }
@@ -0,0 +1,21 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ export interface PageCrumbProps {
3
+ /** The page's name. */
4
+ children: ReactNode;
5
+ /** Makes the crumb a link to `href`. */
6
+ href?: string;
7
+ /** The app's own link, such as `<Link to="/customers" />`. The crumb's content goes into it. */
8
+ render?: ReactElement;
9
+ /** Marks the page the app is on: it carries `aria-current="page"` and is not a link. @defaultValue false */
10
+ current?: boolean;
11
+ }
12
+ /** One page on the way to this one. It lives in a `PageBreadcrumbs`. */
13
+ export declare function PageCrumb({ children, href, render, current }: PageCrumbProps): React.JSX.Element;
14
+ /**
15
+ * The pages on the way to this one, in a `nav` with an ordered list. When there is no room the middle crumbs, the
16
+ * ones after the first, collapse into a "…" button that opens a menu of them. The separators are drawn by CSS, so
17
+ * a screen reader never reads them. A server draws every crumb.
18
+ */
19
+ export declare function PageBreadcrumbs({ children }: {
20
+ children: ReactNode;
21
+ }): React.JSX.Element;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, cloneElement, isValidElement } from "react";
3
+ import { Menu, MenuContent, MenuItem, MenuTrigger } from "../menu";
4
+ import { usePageLabels } from "./page-context";
5
+ import { hiddenCrumbs } from "./page-fit";
6
+ import { MoreIcon } from "./page-icons";
7
+ import { useMeasuredFit } from "./use-measured-fit";
8
+ /** A guess at the "…" button's width, until it has been on screen once. */
9
+ const moreGuess = 48;
10
+ /** One page on the way to this one. It lives in a `PageBreadcrumbs`. */
11
+ export function PageCrumb({ children, href, render, current }) {
12
+ const label = _jsx("span", { "data-slot": "page-crumb-label", children: children });
13
+ if (current) {
14
+ return (_jsx("span", { "data-slot": "page-crumb", "aria-current": "page", children: label }));
15
+ }
16
+ if (render) {
17
+ return cloneElement(render, { "data-slot": "page-crumb" }, label);
18
+ }
19
+ if (href === undefined) {
20
+ return _jsx("span", { "data-slot": "page-crumb", children: label });
21
+ }
22
+ return (_jsx("a", { "data-slot": "page-crumb", href: href, children: label }));
23
+ }
24
+ function crumbProps(item) {
25
+ return isValidElement(item) && item.type === PageCrumb ? item.props : undefined;
26
+ }
27
+ function HiddenMenu({ crumbs, hidden }) {
28
+ const labels = usePageLabels();
29
+ return (_jsx("li", { "data-slot": "page-crumb-item", "data-fit-extra": "", children: _jsxs(Menu, { children: [_jsx(MenuTrigger, { render: _jsx("button", { type: "button", "data-slot": "page-crumb-more", "aria-label": labels.showHidden }), children: _jsx(MoreIcon, {}) }), _jsx(MenuContent, { align: "start", children: crumbs.slice(1, hidden + 1).map((item, offset) => {
30
+ const crumb = crumbProps(item);
31
+ const link = crumb?.render ??
32
+ (crumb?.href === undefined ? undefined : _jsx("a", { href: crumb.href }));
33
+ return crumb ? (_jsx(MenuItem, { value: String(offset + 1), render: link, children: crumb.children }, isValidElement(item) ? item.key : offset)) : null;
34
+ }) })] }) }));
35
+ }
36
+ /**
37
+ * The pages on the way to this one, in a `nav` with an ordered list. When there is no room the middle crumbs, the
38
+ * ones after the first, collapse into a "…" button that opens a menu of them. The separators are drawn by CSS, so
39
+ * a screen reader never reads them. A server draws every crumb.
40
+ */
41
+ export function PageBreadcrumbs({ children }) {
42
+ const labels = usePageLabels();
43
+ const crumbs = Children.toArray(children);
44
+ const { value, rootRef } = useMeasuredFit({
45
+ enabled: true,
46
+ initial: "0",
47
+ decide: (sizes) => String(hiddenCrumbs({
48
+ widths: crumbs.map((_, index) => sizes.widths[index]),
49
+ room: sizes.room,
50
+ more: sizes.extra ?? moreGuess
51
+ }))
52
+ });
53
+ const hidden = Math.min(Number(value), Math.max(0, crumbs.length - 2));
54
+ return (_jsx("nav", { ref: rootRef, "data-slot": "page-breadcrumbs", "aria-label": labels.breadcrumbs, children: _jsx("ol", { "data-slot": "page-crumbs", children: crumbs.map((item, index) => {
55
+ if (index > 0 && index <= hidden) {
56
+ return index === 1 ? (_jsx(HiddenMenu, { crumbs: crumbs, hidden: hidden }, "hidden")) : null;
57
+ }
58
+ return (_jsx("li", { "data-slot": "page-crumb-item", "data-fit-index": index, children: item }, isValidElement(item) ? item.key : index));
59
+ }) }) }));
60
+ }
@@ -0,0 +1,5 @@
1
+ import { type PageLabels } from "./page-labels";
2
+ export declare const LabelsProvider: import("react").Context<PageLabels>;
3
+ export declare const StickyProvider: import("react").Context<boolean>;
4
+ export declare function usePageLabels(): PageLabels;
5
+ export declare function useInStickyBar(): boolean;
@@ -0,0 +1,13 @@
1
+ import { createContext, use } from "react";
2
+ import { pageLabels } from "./page-labels";
3
+ const LabelsContext = createContext(pageLabels);
4
+ /** The sticky bar's actions fold harder, so they need to know they are in it. */
5
+ const StickyContext = createContext(false);
6
+ export const LabelsProvider = LabelsContext;
7
+ export const StickyProvider = StickyContext;
8
+ export function usePageLabels() {
9
+ return use(LabelsContext);
10
+ }
11
+ export function useInStickyBar() {
12
+ return use(StickyContext);
13
+ }
@@ -0,0 +1,26 @@
1
+ /** What fits, worked out from sizes alone so it can run anywhere. */
2
+ interface ActionsFit {
3
+ /** The width each action took when it was last on screen, by position. */
4
+ widths: readonly (number | undefined)[];
5
+ /** Whether each action may fold. The primary action and anything the app put there itself may not. */
6
+ foldable: readonly boolean[];
7
+ room: number;
8
+ gap: number;
9
+ /** The width of the "More actions" button. */
10
+ more: number;
11
+ }
12
+ /** The positions that fold into the menu: from the end, one by one, until the rest fit beside the menu button. */
13
+ export declare function foldedActions(input: ActionsFit): number[];
14
+ interface CrumbsFit {
15
+ /** The width each crumb took when it was last on screen, with its separator, by position. */
16
+ widths: readonly (number | undefined)[];
17
+ room: number;
18
+ /** The width of the "…" button, with its separator. */
19
+ more: number;
20
+ }
21
+ /**
22
+ * How many crumbs collapse into the "…" menu. The first and the last stay, and the ones right after the first go
23
+ * first, so the crumbs nearest the current page are the last to go.
24
+ */
25
+ export declare function hiddenCrumbs(input: CrumbsFit): number;
26
+ export {};
@@ -0,0 +1,36 @@
1
+ /** What fits, worked out from sizes alone so it can run anywhere. */
2
+ /** The positions that fold into the menu: from the end, one by one, until the rest fit beside the menu button. */
3
+ export function foldedActions(input) {
4
+ const { widths, foldable, room, gap, more } = input;
5
+ const folded = [];
6
+ const needs = () => {
7
+ const shown = widths.map((_, index) => index).filter((index) => !folded.includes(index));
8
+ const sizes = shown.map((index) => widths[index] ?? 0);
9
+ if (folded.length > 0) {
10
+ sizes.push(more);
11
+ }
12
+ return sizes.reduce((sum, size) => sum + size, 0) + gap * Math.max(0, sizes.length - 1);
13
+ };
14
+ for (let index = widths.length - 1; index >= 0 && needs() > room; index -= 1) {
15
+ if (foldable[index]) {
16
+ folded.push(index);
17
+ }
18
+ }
19
+ return folded.sort((a, b) => a - b);
20
+ }
21
+ /**
22
+ * How many crumbs collapse into the "…" menu. The first and the last stay, and the ones right after the first go
23
+ * first, so the crumbs nearest the current page are the last to go.
24
+ */
25
+ export function hiddenCrumbs(input) {
26
+ const { widths, room, more } = input;
27
+ const middle = Math.max(0, widths.length - 2);
28
+ for (let hidden = 0; hidden <= middle; hidden += 1) {
29
+ const shown = widths.filter((_, index) => index === 0 || index > hidden);
30
+ const need = shown.reduce((sum, width) => sum + (width ?? 0), 0);
31
+ if (need + (hidden > 0 ? more : 0) <= room) {
32
+ return hidden;
33
+ }
34
+ }
35
+ return middle;
36
+ }
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from "react";
2
+ export interface PageHeaderProps extends Omit<React.ComponentProps<"header">, "title"> {
3
+ /** A small line above the title, such as the section of the app. A paragraph, not a heading. */
4
+ eyebrow?: ReactNode;
5
+ /** The page's title, in an `h1`. */
6
+ title: ReactNode;
7
+ /** A line or two under the title. */
8
+ description?: ReactNode;
9
+ /** The way back, above everything: a `PageBack` or a `PageBreadcrumbs`. */
10
+ back?: ReactNode;
11
+ /** The page's actions: a `PageActions`. */
12
+ actions?: ReactNode;
13
+ /**
14
+ * Once the header scrolls out of sight, a slim bar slides in at the top with the title and the actions, folded
15
+ * harder. It sits below the app shell's top bar while that shows.
16
+ * @defaultValue false
17
+ */
18
+ sticky?: boolean;
19
+ /** The heading level of the title. @defaultValue 1 */
20
+ level?: 1 | 2 | 3 | 4 | 5 | 6;
21
+ }
22
+ /**
23
+ * The top of a page: the way back, an eyebrow, the title, a description and the actions. The title wraps in
24
+ * balanced lines. The actions fold into a "More actions" menu by the room the header itself has, not the window's.
25
+ */
26
+ export declare function PageHeader({ eyebrow, title, description, back, actions, sticky, level, ...props }: PageHeaderProps): React.JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from "react";
3
+ import { StickyProvider } from "./page-context";
4
+ import { useStuck } from "./use-stuck";
5
+ const headings = { 1: "h1", 2: "h2", 3: "h3", 4: "h4", 5: "h5", 6: "h6" };
6
+ /**
7
+ * The top of a page: the way back, an eyebrow, the title, a description and the actions. The title wraps in
8
+ * balanced lines. The actions fold into a "More actions" menu by the room the header itself has, not the window's.
9
+ */
10
+ export function PageHeader({ eyebrow, title, description, back, actions, sticky, level = 1, ...props }) {
11
+ const header = useRef(null);
12
+ const holder = useRef(null);
13
+ const stuck = useStuck(sticky === true, header, holder);
14
+ const Heading = headings[level];
15
+ return (_jsxs(_Fragment, { children: [sticky ? (_jsx("div", { ref: holder, "data-slot": "page-sticky", "data-shown": stuck || undefined, children: _jsxs("div", { "data-slot": "page-sticky-bar", inert: !stuck, children: [_jsx("p", { "data-slot": "page-sticky-title", "aria-hidden": "true", children: title }), actions ? (_jsx(StickyProvider, { value: true, children: _jsx("div", { "data-slot": "page-sticky-actions", children: actions }) })) : null] }) })) : null, _jsxs("header", { ref: header, "data-slot": "page-header", ...props, children: [back ? _jsx("div", { "data-slot": "page-header-back", children: back }) : null, _jsxs("div", { "data-slot": "page-head", children: [_jsxs("div", { "data-slot": "page-titles", children: [eyebrow ? _jsx("p", { "data-slot": "page-eyebrow", children: eyebrow }) : null, _jsx(Heading, { "data-slot": "page-title", children: title })] }), actions ? _jsx("div", { "data-slot": "page-header-actions", children: actions }) : null] }), description ? _jsx("p", { "data-slot": "page-description", children: description }) : null] })] }));
16
+ }
@@ -0,0 +1,4 @@
1
+ /** An arrow that points back to the start, mirrored in right to left. */
2
+ export declare function BackIcon(): React.JSX.Element;
3
+ /** Three dots, for the actions and the pages that were folded away. */
4
+ export declare function MoreIcon(): React.JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** Icons the page draws itself, so it needs no icon library. They follow the text colour. */
3
+ function Icon({ mirror, children }) {
4
+ return (_jsx("svg", { "data-slot": "page-icon", "data-mirror": mirror || undefined, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: children }));
5
+ }
6
+ /** An arrow that points back to the start, mirrored in right to left. */
7
+ export function BackIcon() {
8
+ return (_jsx(Icon, { mirror: true, children: _jsx("path", { d: "M13 8H3.5M7.5 3.5 3 8l4.5 4.5" }) }));
9
+ }
10
+ /** Three dots, for the actions and the pages that were folded away. */
11
+ export function MoreIcon() {
12
+ return (_jsxs(Icon, { children: [_jsx("circle", { cx: "3.5", cy: "8", r: "0.6" }), _jsx("circle", { cx: "8", cy: "8", r: "0.6" }), _jsx("circle", { cx: "12.5", cy: "8", r: "0.6" })] }));
13
+ }
@@ -0,0 +1,12 @@
1
+ /** Every word the page parts show or read out. */
2
+ export interface PageLabels {
3
+ /** The name of the folded actions' menu button. */
4
+ moreActions: string;
5
+ /** The name of the breadcrumbs' `nav`. */
6
+ breadcrumbs: string;
7
+ /** What a `PageBack` says when it has no label of its own. */
8
+ back: string;
9
+ /** The name of the "…" button that opens the breadcrumbs that no longer fit. */
10
+ showHidden: string;
11
+ }
12
+ export declare const pageLabels: PageLabels;
@@ -0,0 +1,6 @@
1
+ export const pageLabels = {
2
+ moreActions: "More actions",
3
+ breadcrumbs: "Breadcrumbs",
4
+ back: "Back",
5
+ showHidden: "Show the hidden pages"
6
+ };
@@ -0,0 +1,14 @@
1
+ import { type ReactNode } from "react";
2
+ export interface PageSectionProps extends Omit<React.ComponentProps<"section">, "title"> {
3
+ /** The section's title. It names the section for a screen reader. */
4
+ title?: ReactNode;
5
+ /** A line or two under the title. */
6
+ description?: ReactNode;
7
+ /** The section's own actions: a `PageActions`. They fold by the section's own room. */
8
+ actions?: ReactNode;
9
+ /** The heading level of the title. @defaultValue 2 */
10
+ level?: 2 | 3 | 4 | 5 | 6;
11
+ children?: ReactNode;
12
+ }
13
+ /** A titled part of a page, with a description and actions of its own. */
14
+ export declare function PageSection({ title, description, actions, level, children, ...props }: PageSectionProps): React.JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ const headings = { 2: "h2", 3: "h3", 4: "h4", 5: "h5", 6: "h6" };
4
+ /** A titled part of a page, with a description and actions of its own. */
5
+ export function PageSection({ title, description, actions, level = 2, children, ...props }) {
6
+ const titleId = useId();
7
+ const Heading = headings[level];
8
+ return (_jsxs("section", { "data-slot": "page-section", "aria-labelledby": title ? titleId : undefined, ...props, children: [title || description || actions ? (_jsxs("div", { "data-slot": "page-head", "data-section": "", children: [_jsx("div", { "data-slot": "page-titles", children: title ? (_jsx(Heading, { id: titleId, "data-slot": "page-section-title", children: title })) : null }), actions ? _jsx("div", { "data-slot": "page-header-actions", children: actions }) : null] })) : null, description ? _jsx("p", { "data-slot": "page-description", children: description }) : null, children] }));
9
+ }