@underpin/ui 0.0.0 → 2.0.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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -1
  3. package/components/autocomplete.d.ts +25 -0
  4. package/components/autocomplete.js +71 -0
  5. package/components/autocomplete.js.map +1 -0
  6. package/components/avatar.d.ts +5 -0
  7. package/components/avatar.js +26 -0
  8. package/components/avatar.js.map +1 -0
  9. package/components/badge.d.ts +36 -0
  10. package/components/badge.js +140 -0
  11. package/components/badge.js.map +1 -0
  12. package/components/bar-list.d.ts +133 -0
  13. package/components/bar-list.js +204 -0
  14. package/components/bar-list.js.map +1 -0
  15. package/components/breakdown-card.d.ts +30 -0
  16. package/components/breakdown-card.js +43 -0
  17. package/components/breakdown-card.js.map +1 -0
  18. package/components/button-group.d.ts +17 -0
  19. package/components/button-group.js +27 -0
  20. package/components/button-group.js.map +1 -0
  21. package/components/button.d.ts +39 -0
  22. package/components/button.js +128 -0
  23. package/components/button.js.map +1 -0
  24. package/components/calendar.d.ts +27 -0
  25. package/components/calendar.js +95 -0
  26. package/components/calendar.js.map +1 -0
  27. package/components/callout.d.ts +26 -0
  28. package/components/callout.js +71 -0
  29. package/components/callout.js.map +1 -0
  30. package/components/card.d.ts +55 -0
  31. package/components/card.js +96 -0
  32. package/components/card.js.map +1 -0
  33. package/components/chart.d.ts +32 -0
  34. package/components/chart.js +43 -0
  35. package/components/chart.js.map +1 -0
  36. package/components/checkbox.d.ts +15 -0
  37. package/components/checkbox.js +42 -0
  38. package/components/checkbox.js.map +1 -0
  39. package/components/code-block.d.ts +21 -0
  40. package/components/code-block.js +35 -0
  41. package/components/code-block.js.map +1 -0
  42. package/components/collapse.d.ts +14 -0
  43. package/components/collapse.js +25 -0
  44. package/components/collapse.js.map +1 -0
  45. package/components/combobox.d.ts +71 -0
  46. package/components/combobox.js +155 -0
  47. package/components/combobox.js.map +1 -0
  48. package/components/copy-button.d.ts +29 -0
  49. package/components/copy-button.js +100 -0
  50. package/components/copy-button.js.map +1 -0
  51. package/components/copy-input.d.ts +15 -0
  52. package/components/copy-input.js +51 -0
  53. package/components/copy-input.js.map +1 -0
  54. package/components/date-picker-trigger.d.ts +12 -0
  55. package/components/date-picker-trigger.js +30 -0
  56. package/components/date-picker-trigger.js.map +1 -0
  57. package/components/date-picker.d.ts +36 -0
  58. package/components/date-picker.js +70 -0
  59. package/components/date-picker.js.map +1 -0
  60. package/components/detail-row.d.ts +51 -0
  61. package/components/detail-row.js +77 -0
  62. package/components/detail-row.js.map +1 -0
  63. package/components/dialog.d.ts +121 -0
  64. package/components/dialog.js +327 -0
  65. package/components/dialog.js.map +1 -0
  66. package/components/disabled-reason.d.ts +31 -0
  67. package/components/disabled-reason.js +67 -0
  68. package/components/disabled-reason.js.map +1 -0
  69. package/components/empty-state.d.ts +41 -0
  70. package/components/empty-state.js +84 -0
  71. package/components/empty-state.js.map +1 -0
  72. package/components/entity-avatar.d.ts +54 -0
  73. package/components/entity-avatar.js +68 -0
  74. package/components/entity-avatar.js.map +1 -0
  75. package/components/form-section.d.ts +22 -0
  76. package/components/form-section.js +38 -0
  77. package/components/form-section.js.map +1 -0
  78. package/components/form.d.ts +199 -0
  79. package/components/form.js +456 -0
  80. package/components/form.js.map +1 -0
  81. package/components/formatted-number.d.ts +21 -0
  82. package/components/formatted-number.js +13 -0
  83. package/components/formatted-number.js.map +1 -0
  84. package/components/heading.d.ts +23 -0
  85. package/components/heading.js +44 -0
  86. package/components/heading.js.map +1 -0
  87. package/components/icon-swap.d.ts +15 -0
  88. package/components/icon-swap.js +29 -0
  89. package/components/icon-swap.js.map +1 -0
  90. package/components/inline-action.d.ts +21 -0
  91. package/components/inline-action.js +36 -0
  92. package/components/inline-action.js.map +1 -0
  93. package/components/input.d.ts +51 -0
  94. package/components/input.js +52 -0
  95. package/components/input.js.map +1 -0
  96. package/components/kbd.d.ts +17 -0
  97. package/components/kbd.js +34 -0
  98. package/components/kbd.js.map +1 -0
  99. package/components/label.d.ts +10 -0
  100. package/components/label.js +20 -0
  101. package/components/label.js.map +1 -0
  102. package/components/menu.d.ts +77 -0
  103. package/components/menu.js +189 -0
  104. package/components/menu.js.map +1 -0
  105. package/components/nav-button.d.ts +34 -0
  106. package/components/nav-button.js +71 -0
  107. package/components/nav-button.js.map +1 -0
  108. package/components/nav.d.ts +39 -0
  109. package/components/nav.js +68 -0
  110. package/components/nav.js.map +1 -0
  111. package/components/number-input.d.ts +16 -0
  112. package/components/number-input.js +25 -0
  113. package/components/number-input.js.map +1 -0
  114. package/components/page.d.ts +14 -0
  115. package/components/page.js +23 -0
  116. package/components/page.js.map +1 -0
  117. package/components/pagination.d.ts +15 -0
  118. package/components/pagination.js +63 -0
  119. package/components/pagination.js.map +1 -0
  120. package/components/ping.d.ts +38 -0
  121. package/components/ping.js +50 -0
  122. package/components/ping.js.map +1 -0
  123. package/components/popover.d.ts +5 -0
  124. package/components/popover.js +25 -0
  125. package/components/popover.js.map +1 -0
  126. package/components/radio-group.d.ts +35 -0
  127. package/components/radio-group.js +81 -0
  128. package/components/radio-group.js.map +1 -0
  129. package/components/relative-time.d.ts +25 -0
  130. package/components/relative-time.js +51 -0
  131. package/components/relative-time.js.map +1 -0
  132. package/components/saved-mark.d.ts +15 -0
  133. package/components/saved-mark.js +45 -0
  134. package/components/saved-mark.js.map +1 -0
  135. package/components/search-input.d.ts +13 -0
  136. package/components/search-input.js +44 -0
  137. package/components/search-input.js.map +1 -0
  138. package/components/section-header.d.ts +83 -0
  139. package/components/section-header.js +170 -0
  140. package/components/section-header.js.map +1 -0
  141. package/components/segmented-control.d.ts +24 -0
  142. package/components/segmented-control.js +70 -0
  143. package/components/segmented-control.js.map +1 -0
  144. package/components/select.d.ts +28 -0
  145. package/components/select.js +129 -0
  146. package/components/select.js.map +1 -0
  147. package/components/shortcut-keys.d.ts +14 -0
  148. package/components/shortcut-keys.js +32 -0
  149. package/components/shortcut-keys.js.map +1 -0
  150. package/components/shortcuts-dialog.d.ts +10 -0
  151. package/components/shortcuts-dialog.js +92 -0
  152. package/components/shortcuts-dialog.js.map +1 -0
  153. package/components/skeleton.d.ts +8 -0
  154. package/components/skeleton.js +23 -0
  155. package/components/skeleton.js.map +1 -0
  156. package/components/sparkline.d.ts +25 -0
  157. package/components/sparkline.js +70 -0
  158. package/components/sparkline.js.map +1 -0
  159. package/components/stack.d.ts +21 -0
  160. package/components/stack.js +45 -0
  161. package/components/stack.js.map +1 -0
  162. package/components/stat-strip.d.ts +43 -0
  163. package/components/stat-strip.js +151 -0
  164. package/components/stat-strip.js.map +1 -0
  165. package/components/steps.d.ts +19 -0
  166. package/components/steps.js +25 -0
  167. package/components/steps.js.map +1 -0
  168. package/components/switch.d.ts +16 -0
  169. package/components/switch.js +29 -0
  170. package/components/switch.js.map +1 -0
  171. package/components/tabs.d.ts +18 -0
  172. package/components/tabs.js +65 -0
  173. package/components/tabs.js.map +1 -0
  174. package/components/text-link.d.ts +16 -0
  175. package/components/text-link.js +32 -0
  176. package/components/text-link.js.map +1 -0
  177. package/components/textarea.d.ts +10 -0
  178. package/components/textarea.js +23 -0
  179. package/components/textarea.js.map +1 -0
  180. package/components/theme.d.ts +28 -0
  181. package/components/theme.js +158 -0
  182. package/components/theme.js.map +1 -0
  183. package/components/time-series-chart.d.ts +122 -0
  184. package/components/time-series-chart.js +722 -0
  185. package/components/time-series-chart.js.map +1 -0
  186. package/components/toaster.d.ts +3 -0
  187. package/components/toaster.js +44 -0
  188. package/components/toaster.js.map +1 -0
  189. package/components/tooltip.d.ts +64 -0
  190. package/components/tooltip.js +126 -0
  191. package/components/tooltip.js.map +1 -0
  192. package/components/view-picker.d.ts +20 -0
  193. package/components/view-picker.js +24 -0
  194. package/components/view-picker.js.map +1 -0
  195. package/fonts/inter-OFL.txt +93 -0
  196. package/fonts/inter-cyrillic-ext.woff2 +0 -0
  197. package/fonts/inter-cyrillic.woff2 +0 -0
  198. package/fonts/inter-greek-ext.woff2 +0 -0
  199. package/fonts/inter-greek.woff2 +0 -0
  200. package/fonts/inter-latin-ext.woff2 +0 -0
  201. package/fonts/inter-latin.woff2 +0 -0
  202. package/fonts/inter-vietnamese.woff2 +0 -0
  203. package/fonts.css +83 -0
  204. package/lib/animation.d.ts +14 -0
  205. package/lib/animation.js +20 -0
  206. package/lib/animation.js.map +1 -0
  207. package/lib/aria.d.ts +5 -0
  208. package/lib/aria.js +12 -0
  209. package/lib/aria.js.map +1 -0
  210. package/lib/chart-curve.d.ts +13 -0
  211. package/lib/chart-curve.js +79 -0
  212. package/lib/chart-curve.js.map +1 -0
  213. package/lib/classes.d.ts +134 -0
  214. package/lib/classes.js +152 -0
  215. package/lib/classes.js.map +1 -0
  216. package/lib/color.d.ts +25 -0
  217. package/lib/color.js +149 -0
  218. package/lib/color.js.map +1 -0
  219. package/lib/day.d.ts +9 -0
  220. package/lib/day.js +20 -0
  221. package/lib/day.js.map +1 -0
  222. package/lib/design-tokens.d.ts +56 -0
  223. package/lib/design-tokens.js +196 -0
  224. package/lib/design-tokens.js.map +1 -0
  225. package/lib/icon.d.ts +17 -0
  226. package/lib/icon.js +34 -0
  227. package/lib/icon.js.map +1 -0
  228. package/lib/icons.d.ts +23 -0
  229. package/lib/icons.js +28 -0
  230. package/lib/icons.js.map +1 -0
  231. package/lib/interactive.d.ts +21 -0
  232. package/lib/interactive.js +31 -0
  233. package/lib/interactive.js.map +1 -0
  234. package/lib/media.d.ts +58 -0
  235. package/lib/media.js +116 -0
  236. package/lib/media.js.map +1 -0
  237. package/lib/segmented.d.ts +57 -0
  238. package/lib/segmented.js +83 -0
  239. package/lib/segmented.js.map +1 -0
  240. package/lib/shortcuts.d.ts +94 -0
  241. package/lib/shortcuts.js +271 -0
  242. package/lib/shortcuts.js.map +1 -0
  243. package/lib/slot.d.ts +9 -0
  244. package/lib/slot.js +18 -0
  245. package/lib/slot.js.map +1 -0
  246. package/lib/time-series.d.ts +100 -0
  247. package/lib/time-series.js +144 -0
  248. package/lib/time-series.js.map +1 -0
  249. package/lib/tone.d.ts +6 -0
  250. package/lib/tone.js +0 -0
  251. package/lib/variants.d.ts +12 -0
  252. package/lib/variants.js +14 -0
  253. package/lib/variants.js.map +1 -0
  254. package/package.json +110 -3
  255. package/styles.css +619 -0
  256. package/tokens.d.ts +104 -0
  257. package/tokens.js +108 -0
  258. package/tokens.js.map +1 -0
  259. package/publish.log +0 -1
@@ -0,0 +1,31 @@
1
+ import { variants } from "./variants.js";
2
+ // src/lib/interactive.ts
3
+ /**
4
+ * Shared chrome for every interactive surface (buttons, inputs, select triggers, switches,
5
+ * tabs): a snappy colour transition, a pointer cursor when `interactive`, and, when `bordered`,
6
+ * the strong 1px border, which darkens under the pointer, plus the subtle fill when the control
7
+ * is clicked rather than typed into. Components layer their own fill and text colours on top
8
+ * with `cn`. An `aria-disabled` control keeps the pointer for its reason's tooltip, so it shows
9
+ * the not-allowed cursor and no hover fill or edge.
10
+ *
11
+ * Focus is not a variant: every focusable element gets the one focus ring from `styles.css`
12
+ * (`:focus-visible`), so there is nothing to opt into here. An invalid control
13
+ * (`aria-invalid`, set by a form field with an error) turns its border to the danger tone and
14
+ * keeps it while focused, so the field the message belongs to reads at a glance.
15
+ */
16
+ const interactiveVariants = variants({
17
+ base: "transition-[color,background-color,border-color,box-shadow,opacity,filter] duration-75 ease-out aria-invalid:border-danger aria-invalid:focus:border-danger",
18
+ variants: {
19
+ interactive: { true: "not-disabled:not-aria-disabled:cursor-pointer aria-disabled:cursor-not-allowed" },
20
+ bordered: { true: "border border-edge-strong hover:not-disabled:not-aria-disabled:not-aria-invalid:border-edge-solid" }
21
+ },
22
+ compoundVariants: [{
23
+ interactive: true,
24
+ bordered: true,
25
+ class: "hover:not-disabled:not-aria-disabled:bg-fill-subtle"
26
+ }],
27
+ defaultVariants: { interactive: true }
28
+ });
29
+ export { interactiveVariants };
30
+
31
+ //# sourceMappingURL=interactive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interactive.js","names":[],"sources":["../../src/lib/interactive.ts"],"sourcesContent":["import { variants } from \"./variants\"\n\n/**\n * Shared chrome for every interactive surface (buttons, inputs, select triggers, switches,\n * tabs): a snappy colour transition, a pointer cursor when `interactive`, and, when `bordered`,\n * the strong 1px border, which darkens under the pointer, plus the subtle fill when the control\n * is clicked rather than typed into. Components layer their own fill and text colours on top\n * with `cn`. An `aria-disabled` control keeps the pointer for its reason's tooltip, so it shows\n * the not-allowed cursor and no hover fill or edge.\n *\n * Focus is not a variant: every focusable element gets the one focus ring from `styles.css`\n * (`:focus-visible`), so there is nothing to opt into here. An invalid control\n * (`aria-invalid`, set by a form field with an error) turns its border to the danger tone and\n * keeps it while focused, so the field the message belongs to reads at a glance.\n */\nexport const interactiveVariants = variants({\n base: \"transition-[color,background-color,border-color,box-shadow,opacity,filter] duration-75 ease-out aria-invalid:border-danger aria-invalid:focus:border-danger\",\n\n variants: {\n interactive: {\n true: \"not-disabled:not-aria-disabled:cursor-pointer aria-disabled:cursor-not-allowed\",\n },\n bordered: {\n true: \"border border-edge-strong hover:not-disabled:not-aria-disabled:not-aria-invalid:border-edge-solid\",\n },\n },\n\n compoundVariants: [\n {\n interactive: true,\n bordered: true,\n class: \"hover:not-disabled:not-aria-disabled:bg-fill-subtle\",\n },\n ],\n\n defaultVariants: {\n interactive: true,\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,sBAAsB,SAAS;CAC1C,MAAM;CAEN,UAAU;EACR,aAAa,EACX,MAAM,iFACR;EACA,UAAU,EACR,MAAM,oGACR;CACF;CAEA,kBAAkB,CAChB;EACE,aAAa;EACb,UAAU;EACV,OAAO;CACT,CACF;CAEA,iBAAiB,EACf,aAAa,KACf;AACF,CAAC"}
package/lib/media.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ /** Tailwind's `lg` and up, where an app shell has room for a side rail. */
2
+ export declare const FROM_LG = "(min-width: 64rem)";
3
+ /** A mouse or trackpad: the device the `pointer-fine:` variant styles for. */
4
+ export declare const POINTER_FINE = "(pointer: fine)";
5
+ /**
6
+ * Whether a media query matches right now, for a callback. A render reads `useMediaQuery`
7
+ * instead, which is false on the server and re-renders when the answer changes.
8
+ */
9
+ export declare function matchesMedia(query: string): boolean;
10
+ /**
11
+ * Whether a media query matches, re-rendering when that changes. False on the server and
12
+ * through hydration, so the first client render matches the markup; React then re-renders
13
+ * with the truth. Pass a module constant: the store is keyed on the string.
14
+ */
15
+ export declare function useMediaQuery(query: string): boolean;
16
+ /**
17
+ * Whether the viewport is under `sm`. A component that swaps on it remounts when the
18
+ * breakpoint is crossed, which only ever happens on a resize.
19
+ */
20
+ export declare function useBelowSm(): boolean;
21
+ /**
22
+ * Whether a popup opening now takes the phone's bottom sheet: true under `sm`. The answer is
23
+ * read once, when the caller mounts, and held. Call it from inside the popup's portal, which
24
+ * mounts as the popup opens and unmounts once it has closed: a popup then keeps one shape for
25
+ * as long as it is open, and a resize across `sm` neither moves nor remounts it.
26
+ */
27
+ export declare function usePopupSheet(): boolean;
28
+ /**
29
+ * Whether a popup takes the phone's bottom sheet, for a caller that renders the sheet or a
30
+ * popover itself rather than through `Dialog`. It follows the viewport while `open`
31
+ * is false and holds while it is true, so a resize across `sm` neither swaps the component in
32
+ * use nor drops what is typed in it.
33
+ */
34
+ export declare function useSheetWhileOpen(open: boolean): boolean;
35
+ interface ElementWidthOptions {
36
+ /** Rounds the width down to a multiple of this many pixels. */
37
+ step?: number;
38
+ /** Applies a new width as a transition. Default true. */
39
+ deferred?: boolean;
40
+ }
41
+ /**
42
+ * The width of the element the caller holds in state, in pixels, rounded down to a multiple
43
+ * of `step`, and `undefined` until it has been measured. The rounding is what makes the
44
+ * reading usable as a key: a drag-resize would otherwise report every pixel on the way, and
45
+ * anything derived from the width (a lattice, a bucket count) would be rebuilt on each one.
46
+ *
47
+ * The element comes from a callback ref (`ref={setElement}`) rather than a `RefObject`, so
48
+ * one that mounts later than the hook is measured as soon as it arrives: a `RefObject` is the
49
+ * same object on every render, so an effect keyed on it never runs again, and an element
50
+ * mounted after an error state gave way would never be observed at all.
51
+ *
52
+ * The new width arrives as a transition by default, so a drag-resize stays responsive while the
53
+ * work behind it re-runs. A transition waits on every other pending one, so while a page loads
54
+ * its data the first width can land a second late: `deferred: false` applies it at once, for
55
+ * a layout that reads wrong until measured.
56
+ */
57
+ export declare function useElementWidth(element: HTMLElement | null, { step, deferred }?: ElementWidthOptions): number | undefined;
58
+ export {};
package/lib/media.js ADDED
@@ -0,0 +1,116 @@
1
+ "use client";
2
+ import { startTransition, useEffect, useState, useSyncExternalStore } from "react";
3
+ // src/lib/media.ts
4
+ /**
5
+ * Below Tailwind's `sm` (40rem), i.e. the phone layout. Kept as a constant so this JS-driven
6
+ * switch flips on exactly the same pixel as the `max-sm:` classes components style with.
7
+ */
8
+ const BELOW_SM = "(max-width: 39.9375rem)";
9
+ /** Tailwind's `lg` and up, where an app shell has room for a side rail. */
10
+ const FROM_LG = "(min-width: 64rem)";
11
+ /** A mouse or trackpad: the device the `pointer-fine:` variant styles for. */
12
+ const POINTER_FINE = "(pointer: fine)";
13
+ const stores = /* @__PURE__ */ new Map();
14
+ /**
15
+ * Whether a media query matches right now, for a callback. A render reads `useMediaQuery`
16
+ * instead, which is false on the server and re-renders when the answer changes.
17
+ */
18
+ function matchesMedia(query) {
19
+ return matchMedia(query).matches;
20
+ }
21
+ function storeFor(query) {
22
+ const existing = stores.get(query);
23
+ if (existing) return existing;
24
+ const store = {
25
+ subscribe(onChange) {
26
+ const list = matchMedia(query);
27
+ list.addEventListener("change", onChange);
28
+ return () => list.removeEventListener("change", onChange);
29
+ },
30
+ getSnapshot() {
31
+ return matchesMedia(query);
32
+ }
33
+ };
34
+ stores.set(query, store);
35
+ return store;
36
+ }
37
+ function serverSnapshot() {
38
+ return false;
39
+ }
40
+ /**
41
+ * Whether a media query matches, re-rendering when that changes. False on the server and
42
+ * through hydration, so the first client render matches the markup; React then re-renders
43
+ * with the truth. Pass a module constant: the store is keyed on the string.
44
+ */
45
+ function useMediaQuery(query) {
46
+ const { subscribe, getSnapshot } = storeFor(query);
47
+ return useSyncExternalStore(subscribe, getSnapshot, serverSnapshot);
48
+ }
49
+ /**
50
+ * Whether the viewport is under `sm`. A component that swaps on it remounts when the
51
+ * breakpoint is crossed, which only ever happens on a resize.
52
+ */
53
+ function useBelowSm() {
54
+ return useMediaQuery(BELOW_SM);
55
+ }
56
+ /**
57
+ * Whether a popup opening now takes the phone's bottom sheet: true under `sm`. The answer is
58
+ * read once, when the caller mounts, and held. Call it from inside the popup's portal, which
59
+ * mounts as the popup opens and unmounts once it has closed: a popup then keeps one shape for
60
+ * as long as it is open, and a resize across `sm` neither moves nor remounts it.
61
+ */
62
+ function usePopupSheet() {
63
+ const [sheet] = useState(() => matchesMedia(BELOW_SM));
64
+ return sheet;
65
+ }
66
+ /**
67
+ * Whether a popup takes the phone's bottom sheet, for a caller that renders the sheet or a
68
+ * popover itself rather than through `Dialog`. It follows the viewport while `open`
69
+ * is false and holds while it is true, so a resize across `sm` neither swaps the component in
70
+ * use nor drops what is typed in it.
71
+ */
72
+ function useSheetWhileOpen(open) {
73
+ const belowSm = useBelowSm();
74
+ const [sheet, setSheet] = useState(belowSm);
75
+ if (!open && sheet !== belowSm) setSheet(belowSm);
76
+ return sheet;
77
+ }
78
+ /**
79
+ * The width of the element the caller holds in state, in pixels, rounded down to a multiple
80
+ * of `step`, and `undefined` until it has been measured. The rounding is what makes the
81
+ * reading usable as a key: a drag-resize would otherwise report every pixel on the way, and
82
+ * anything derived from the width (a lattice, a bucket count) would be rebuilt on each one.
83
+ *
84
+ * The element comes from a callback ref (`ref={setElement}`) rather than a `RefObject`, so
85
+ * one that mounts later than the hook is measured as soon as it arrives: a `RefObject` is the
86
+ * same object on every render, so an effect keyed on it never runs again, and an element
87
+ * mounted after an error state gave way would never be observed at all.
88
+ *
89
+ * The new width arrives as a transition by default, so a drag-resize stays responsive while the
90
+ * work behind it re-runs. A transition waits on every other pending one, so while a page loads
91
+ * its data the first width can land a second late: `deferred: false` applies it at once, for
92
+ * a layout that reads wrong until measured.
93
+ */
94
+ function useElementWidth(element, { step = 1, deferred = true } = {}) {
95
+ const [width, setWidth] = useState();
96
+ useEffect(() => {
97
+ if (!element) return;
98
+ function apply(measured) {
99
+ const next = measured > 0 ? Math.floor(measured / step) * step : void 0;
100
+ if (deferred) startTransition(() => setWidth(next));
101
+ else setWidth(next);
102
+ }
103
+ if (!deferred) apply(element.clientWidth);
104
+ const observer = new ResizeObserver(([entry]) => apply(entry?.contentRect.width ?? 0));
105
+ observer.observe(element);
106
+ return () => observer.disconnect();
107
+ }, [
108
+ element,
109
+ step,
110
+ deferred
111
+ ]);
112
+ return width;
113
+ }
114
+ export { FROM_LG, POINTER_FINE, matchesMedia, useBelowSm, useElementWidth, useMediaQuery, usePopupSheet, useSheetWhileOpen };
115
+
116
+ //# sourceMappingURL=media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.js","names":[],"sources":["../../src/lib/media.ts"],"sourcesContent":["\"use client\"\n\nimport { startTransition, useEffect, useState, useSyncExternalStore } from \"react\"\n\n/**\n * Below Tailwind's `sm` (40rem), i.e. the phone layout. Kept as a constant so this JS-driven\n * switch flips on exactly the same pixel as the `max-sm:` classes components style with.\n */\nconst BELOW_SM = \"(max-width: 39.9375rem)\"\n\n/** Tailwind's `lg` and up, where an app shell has room for a side rail. */\nexport const FROM_LG = \"(min-width: 64rem)\"\n\n/** A mouse or trackpad: the device the `pointer-fine:` variant styles for. */\nexport const POINTER_FINE = \"(pointer: fine)\"\n\ninterface MediaQueryStore {\n subscribe: (onChange: () => void) => () => void\n getSnapshot: () => boolean\n}\n\n// One store per query string, so every component watching the same query shares a listener\n// and `useSyncExternalStore` gets the referentially stable callbacks it compares on.\nconst stores = new Map<string, MediaQueryStore>()\n\n/**\n * Whether a media query matches right now, for a callback. A render reads `useMediaQuery`\n * instead, which is false on the server and re-renders when the answer changes.\n */\nexport function matchesMedia(query: string): boolean {\n return matchMedia(query).matches\n}\n\n// `matchMedia` is only ever touched inside these callbacks, which is what keeps the module\n// importable on the server.\nfunction storeFor(query: string): MediaQueryStore {\n const existing = stores.get(query)\n if (existing) return existing\n\n const store: MediaQueryStore = {\n subscribe(onChange) {\n const list = matchMedia(query)\n list.addEventListener(\"change\", onChange)\n return () => list.removeEventListener(\"change\", onChange)\n },\n getSnapshot() {\n return matchesMedia(query)\n },\n }\n stores.set(query, store)\n\n return store\n}\n\nfunction serverSnapshot() {\n return false\n}\n\n/**\n * Whether a media query matches, re-rendering when that changes. False on the server and\n * through hydration, so the first client render matches the markup; React then re-renders\n * with the truth. Pass a module constant: the store is keyed on the string.\n */\nexport function useMediaQuery(query: string): boolean {\n const { subscribe, getSnapshot } = storeFor(query)\n\n return useSyncExternalStore(subscribe, getSnapshot, serverSnapshot)\n}\n\n/**\n * Whether the viewport is under `sm`. A component that swaps on it remounts when the\n * breakpoint is crossed, which only ever happens on a resize.\n */\nexport function useBelowSm() {\n return useMediaQuery(BELOW_SM)\n}\n\n/**\n * Whether a popup opening now takes the phone's bottom sheet: true under `sm`. The answer is\n * read once, when the caller mounts, and held. Call it from inside the popup's portal, which\n * mounts as the popup opens and unmounts once it has closed: a popup then keeps one shape for\n * as long as it is open, and a resize across `sm` neither moves nor remounts it.\n */\nexport function usePopupSheet() {\n const [sheet] = useState(() => matchesMedia(BELOW_SM))\n\n return sheet\n}\n\n/**\n * Whether a popup takes the phone's bottom sheet, for a caller that renders the sheet or a\n * popover itself rather than through `Dialog`. It follows the viewport while `open`\n * is false and holds while it is true, so a resize across `sm` neither swaps the component in\n * use nor drops what is typed in it.\n */\nexport function useSheetWhileOpen(open: boolean) {\n const belowSm = useBelowSm()\n const [sheet, setSheet] = useState(belowSm)\n\n // Adjusting state while rendering: only a closed popup takes up a new answer.\n if (!open && sheet !== belowSm) setSheet(belowSm)\n\n return sheet\n}\n\ninterface ElementWidthOptions {\n /** Rounds the width down to a multiple of this many pixels. */\n step?: number\n /** Applies a new width as a transition. Default true. */\n deferred?: boolean\n}\n\n/**\n * The width of the element the caller holds in state, in pixels, rounded down to a multiple\n * of `step`, and `undefined` until it has been measured. The rounding is what makes the\n * reading usable as a key: a drag-resize would otherwise report every pixel on the way, and\n * anything derived from the width (a lattice, a bucket count) would be rebuilt on each one.\n *\n * The element comes from a callback ref (`ref={setElement}`) rather than a `RefObject`, so\n * one that mounts later than the hook is measured as soon as it arrives: a `RefObject` is the\n * same object on every render, so an effect keyed on it never runs again, and an element\n * mounted after an error state gave way would never be observed at all.\n *\n * The new width arrives as a transition by default, so a drag-resize stays responsive while the\n * work behind it re-runs. A transition waits on every other pending one, so while a page loads\n * its data the first width can land a second late: `deferred: false` applies it at once, for\n * a layout that reads wrong until measured.\n */\nexport function useElementWidth(\n element: HTMLElement | null,\n { step = 1, deferred = true }: ElementWidthOptions = {},\n) {\n const [width, setWidth] = useState<number>()\n\n useEffect(() => {\n if (!element) return\n\n function apply(measured: number) {\n const next = measured > 0 ? Math.floor(measured / step) * step : undefined\n if (deferred) startTransition(() => setWidth(next))\n else setWidth(next)\n }\n\n // Urgent means now: layout already knows the width a frame before the observer reports it.\n if (!deferred) apply(element.clientWidth)\n const observer = new ResizeObserver(([entry]) => apply(entry?.contentRect.width ?? 0))\n observer.observe(element)\n return () => observer.disconnect()\n }, [element, step, deferred])\n\n return width\n}\n"],"mappings":";;;;;;;AAQA,MAAM,WAAW;;AAGjB,MAAa,UAAU;;AAGvB,MAAa,eAAe;AAS5B,MAAM,yBAAS,IAAI,IAA6B;;;;;AAMhD,SAAgB,aAAa,OAAwB;CACnD,OAAO,WAAW,KAAK,CAAC,CAAC;AAC3B;AAIA,SAAS,SAAS,OAAgC;CAChD,MAAM,WAAW,OAAO,IAAI,KAAK;CACjC,IAAI,UAAU,OAAO;CAErB,MAAM,QAAyB;EAC7B,UAAU,UAAU;GAClB,MAAM,OAAO,WAAW,KAAK;GAC7B,KAAK,iBAAiB,UAAU,QAAQ;GACxC,aAAa,KAAK,oBAAoB,UAAU,QAAQ;EAC1D;EACA,cAAc;GACZ,OAAO,aAAa,KAAK;EAC3B;CACF;CACA,OAAO,IAAI,OAAO,KAAK;CAEvB,OAAO;AACT;AAEA,SAAS,iBAAiB;CACxB,OAAO;AACT;;;;;;AAOA,SAAgB,cAAc,OAAwB;CACpD,MAAM,EAAE,WAAW,gBAAgB,SAAS,KAAK;CAEjD,OAAO,qBAAqB,WAAW,aAAa,cAAc;AACpE;;;;;AAMA,SAAgB,aAAa;CAC3B,OAAO,cAAc,QAAQ;AAC/B;;;;;;;AAQA,SAAgB,gBAAgB;CAC9B,MAAM,CAAC,SAAS,eAAe,aAAa,QAAQ,CAAC;CAErD,OAAO;AACT;;;;;;;AAQA,SAAgB,kBAAkB,MAAe;CAC/C,MAAM,UAAU,WAAW;CAC3B,MAAM,CAAC,OAAO,YAAY,SAAS,OAAO;CAG1C,IAAI,CAAC,QAAQ,UAAU,SAAS,SAAS,OAAO;CAEhD,OAAO;AACT;;;;;;;;;;;;;;;;;AAyBA,SAAgB,gBACd,SACA,EAAE,OAAO,GAAG,WAAW,SAA8B,CAAC,GACtD;CACA,MAAM,CAAC,OAAO,YAAY,SAAiB;CAE3C,gBAAgB;EACd,IAAI,CAAC,SAAS;EAEd,SAAS,MAAM,UAAkB;GAC/B,MAAM,OAAO,WAAW,IAAI,KAAK,MAAM,WAAW,IAAI,IAAI,OAAO,KAAA;GACjE,IAAI,UAAU,sBAAsB,SAAS,IAAI,CAAC;QAC7C,SAAS,IAAI;EACpB;EAGA,IAAI,CAAC,UAAU,MAAM,QAAQ,WAAW;EACxC,MAAM,WAAW,IAAI,gBAAgB,CAAC,WAAW,MAAM,OAAO,YAAY,SAAS,CAAC,CAAC;EACrF,SAAS,QAAQ,OAAO;EACxB,aAAa,SAAS,WAAW;CACnC,GAAG;EAAC;EAAS;EAAM;CAAQ,CAAC;CAE5B,OAAO;AACT"}
@@ -0,0 +1,57 @@
1
+ import { VariantProps } from "./variants.js";
2
+ import { RefObject } from "react";
3
+ /** The variant and size a row hands its options, with the defaults filled in. */
4
+ export interface SegmentedStyle {
5
+ variant: NonNullable<VariantProps<typeof segmentedVariants>["variant"]>;
6
+ size: NonNullable<VariantProps<typeof segmentedVariants>["size"]>;
7
+ }
8
+ /**
9
+ * The row of options with one sliding pill behind the chosen one, shared by `Tabs` and
10
+ * `SegmentedControl`. Each component positions the pill from its own measurements and adds the
11
+ * state classes its primitive emits (`data-active` on a tab, `data-checked` on a radio), so
12
+ * the slots here hold only the shape.
13
+ */
14
+ export declare const segmentedVariants: import("tailwind-variants").TVReturnType<{
15
+ variant: {
16
+ segmented: {
17
+ root: string;
18
+ indicator: string;
19
+ };
20
+ plain: {
21
+ root: string;
22
+ indicator: string;
23
+ };
24
+ };
25
+ size: {
26
+ md: {
27
+ item: string;
28
+ };
29
+ sm: {
30
+ item: string;
31
+ };
32
+ xs: {
33
+ root: string;
34
+ indicator: string;
35
+ item: string;
36
+ };
37
+ };
38
+ icon: {
39
+ true: {
40
+ item: string;
41
+ };
42
+ };
43
+ }, {
44
+ root: string;
45
+ indicator: string;
46
+ item: string;
47
+ }, undefined, undefined, undefined, undefined>;
48
+ /** The pill's box, read from what `useSegmentedIndicator` wrote, hidden until it is measured. */
49
+ export declare const SEGMENTED_INDICATOR_BOX = "hidden h-(--indicator-height) w-(--indicator-width) translate-x-(--indicator-left) translate-y-(--indicator-top) in-data-measured:block";
50
+ /** A segmented row's raised key on the checked option itself, until the pill has a box to take. */
51
+ export declare const SEGMENTED_UNMEASURED_KEY = "[&:not([data-measured])_[data-checked]]:bg-surface [&:not([data-measured])_[data-checked]]:shadow-control [&:not([data-measured])_[data-checked]]:outline [&:not([data-measured])_[data-checked]]:-outline-offset-1 [&:not([data-measured])_[data-checked]]:outline-edge-strong";
52
+ /**
53
+ * Keeps a row's pill on its checked option: measures again when `value` changes and when the
54
+ * row resizes, as a label that wraps, a font that loads, or an option added later moves the
55
+ * checked one. The returned ref goes on the row.
56
+ */
57
+ export declare function useSegmentedIndicator(value: unknown): RefObject<HTMLDivElement | null>;
@@ -0,0 +1,83 @@
1
+ import { interactiveVariants } from "./interactive.js";
2
+ import { cn, variants } from "./variants.js";
3
+ import { useLayoutEffect, useRef } from "react";
4
+ // src/lib/segmented.ts
5
+ /**
6
+ * The row of options with one sliding pill behind the chosen one, shared by `Tabs` and
7
+ * `SegmentedControl`. Each component positions the pill from its own measurements and adds the
8
+ * state classes its primitive emits (`data-active` on a tab, `data-checked` on a radio), so
9
+ * the slots here hold only the shape.
10
+ */
11
+ const segmentedVariants = variants({
12
+ slots: {
13
+ root: "relative inline-flex items-center text-ink-muted",
14
+ indicator: "absolute top-0 left-0 z-0 rounded-md transition-[translate,width,height] duration-200 ease-out-expo",
15
+ item: cn(interactiveVariants({ interactive: false }), "relative z-10 inline-flex items-center justify-center whitespace-nowrap font-medium", "hover:text-ink active:text-ink", "pointer-coarse:before:absolute pointer-coarse:before:inset-x-0 pointer-coarse:before:top-1/2 pointer-coarse:before:h-10 pointer-coarse:before:-translate-y-1/2")
16
+ },
17
+ variants: {
18
+ variant: {
19
+ segmented: {
20
+ root: "rounded-md bg-well shadow-well",
21
+ indicator: "rounded-md border border-edge-strong bg-surface shadow-control"
22
+ },
23
+ plain: {
24
+ root: "gap-0.5",
25
+ indicator: "rounded-md bg-fill"
26
+ }
27
+ },
28
+ size: {
29
+ md: { item: "h-control rounded-md px-2.5 text-control" },
30
+ sm: { item: "h-7 rounded-md px-2 text-control" },
31
+ xs: {
32
+ root: "rounded",
33
+ indicator: "rounded",
34
+ item: "h-6 rounded px-1.5 text-xs"
35
+ }
36
+ },
37
+ icon: { true: { item: "aspect-square px-0 [&_svg]:size-3.5" } }
38
+ },
39
+ compoundVariants: [{
40
+ size: "xs",
41
+ icon: true,
42
+ class: { item: "[&_svg]:size-3" }
43
+ }],
44
+ defaultVariants: {
45
+ variant: "segmented",
46
+ size: "md"
47
+ }
48
+ });
49
+ /** The pill's box, read from what `useSegmentedIndicator` wrote, hidden until it is measured. */
50
+ const SEGMENTED_INDICATOR_BOX = "hidden h-(--indicator-height) w-(--indicator-width) translate-x-(--indicator-left) translate-y-(--indicator-top) in-data-measured:block";
51
+ /** A segmented row's raised key on the checked option itself, until the pill has a box to take. */
52
+ const SEGMENTED_UNMEASURED_KEY = "[&:not([data-measured])_[data-checked]]:bg-surface [&:not([data-measured])_[data-checked]]:shadow-control [&:not([data-measured])_[data-checked]]:outline [&:not([data-measured])_[data-checked]]:-outline-offset-1 [&:not([data-measured])_[data-checked]]:outline-edge-strong";
53
+ /** Writes the checked option's box onto the row, where the pill reads it. */
54
+ function measure(root) {
55
+ const checked = root.querySelector("[role=\"radio\"][data-checked], [role=\"menuitemradio\"][data-checked]");
56
+ root.style.setProperty("--indicator-left", `${checked?.offsetLeft ?? 0}px`);
57
+ root.style.setProperty("--indicator-top", `${checked?.offsetTop ?? 0}px`);
58
+ root.style.setProperty("--indicator-width", `${checked?.offsetWidth ?? 0}px`);
59
+ root.style.setProperty("--indicator-height", `${checked?.offsetHeight ?? 0}px`);
60
+ root.dataset.measured = "";
61
+ }
62
+ /**
63
+ * Keeps a row's pill on its checked option: measures again when `value` changes and when the
64
+ * row resizes, as a label that wraps, a font that loads, or an option added later moves the
65
+ * checked one. The returned ref goes on the row.
66
+ */
67
+ function useSegmentedIndicator(value) {
68
+ const ref = useRef(null);
69
+ useLayoutEffect(() => {
70
+ if (ref.current) measure(ref.current);
71
+ }, [value]);
72
+ useLayoutEffect(() => {
73
+ const root = ref.current;
74
+ if (!root) return;
75
+ const observer = new ResizeObserver(() => measure(root));
76
+ observer.observe(root);
77
+ return () => observer.disconnect();
78
+ }, []);
79
+ return ref;
80
+ }
81
+ export { SEGMENTED_INDICATOR_BOX, SEGMENTED_UNMEASURED_KEY, segmentedVariants, useSegmentedIndicator };
82
+
83
+ //# sourceMappingURL=segmented.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segmented.js","names":[],"sources":["../../src/lib/segmented.ts"],"sourcesContent":["import { type RefObject, useLayoutEffect, useRef } from \"react\"\nimport { interactiveVariants } from \"./interactive\"\nimport { cn, variants, type VariantProps } from \"./variants\"\n\n/** The variant and size a row hands its options, with the defaults filled in. */\nexport interface SegmentedStyle {\n variant: NonNullable<VariantProps<typeof segmentedVariants>[\"variant\"]>\n size: NonNullable<VariantProps<typeof segmentedVariants>[\"size\"]>\n}\n\n/**\n * The row of options with one sliding pill behind the chosen one, shared by `Tabs` and\n * `SegmentedControl`. Each component positions the pill from its own measurements and adds the\n * state classes its primitive emits (`data-active` on a tab, `data-checked` on a radio), so\n * the slots here hold only the shape.\n */\nexport const segmentedVariants = variants({\n slots: {\n root: \"relative inline-flex items-center text-ink-muted\",\n // Positioned from the root's top-left corner rather than centred on it, so a row that\n // wraps onto a second line moves the pill down to the chosen option's line as well as\n // across. 200ms on the `--ease-out-expo` curve: a pill still travelling when the new\n // content lands reads as lag.\n indicator:\n \"absolute top-0 left-0 z-0 rounded-md transition-[translate,width,height] duration-200 ease-out-expo\",\n item: cn(\n interactiveVariants({ interactive: false }),\n \"relative z-10 inline-flex items-center justify-center whitespace-nowrap font-medium\",\n // Hover and press darken the label only. The pill alone marks the chosen option, so a\n // fill under the pointer would read as a second pill beside it while the first one slides.\n \"hover:text-ink active:text-ink\",\n // A finger's 40px target, centred on the option and spilling into the row above and\n // below rather than growing the option: a `min-height` here would stretch the pill, and\n // with it the card header the row sits in. Check it on a real phone: a desktop\n // browser's mobile emulation does not match `pointer: coarse`.\n \"pointer-coarse:before:absolute pointer-coarse:before:inset-x-0 pointer-coarse:before:top-1/2 pointer-coarse:before:h-10 pointer-coarse:before:-translate-y-1/2\",\n ),\n },\n\n variants: {\n variant: {\n // The chosen option is a raised key as tall as the track, which is a well with no edge of\n // its own, so the two read as one control, the way a switch's thumb meets its track. No\n // inset and no gap between options.\n segmented: {\n root: \"rounded-md bg-well shadow-well\",\n indicator: \"rounded-md border border-edge-strong bg-surface shadow-control\",\n },\n // The same box with nothing drawn around it: no track and no edge, the chosen option on\n // the fill. A plain row is as tall as a segmented one of its size, so its labels line\n // up with any control beside it. For in-card view switchers.\n plain: {\n root: \"gap-0.5\",\n indicator: \"rounded-md bg-fill\",\n },\n },\n // The control scale, on the options rather than the row, so a row that wraps grows by\n // whole lines and a row that pads itself keeps its options' height: md is 32px and sm 28px,\n // for a card header, both with 13px labels like every control of their size; xs is 24px\n // with 12px labels, for a control inside a menu row.\n size: {\n md: { item: \"h-control rounded-md px-2.5 text-control\" },\n sm: { item: \"h-7 rounded-md px-2 text-control\" },\n xs: { root: \"rounded\", indicator: \"rounded\", item: \"h-6 rounded px-1.5 text-xs\" },\n },\n // An option that is only an icon: a square of the option's height, the icon 14px, or 12px\n // in an xs row. `SegmentedControlItem` sets it for an option labelled by `aria-label` alone.\n icon: {\n true: { item: \"aspect-square px-0 [&_svg]:size-3.5\" },\n },\n },\n\n compoundVariants: [{ size: \"xs\", icon: true, class: { item: \"[&_svg]:size-3\" } }],\n\n defaultVariants: {\n variant: \"segmented\",\n size: \"md\",\n },\n})\n\n/** The pill's box, read from what `useSegmentedIndicator` wrote, hidden until it is measured. */\nexport const SEGMENTED_INDICATOR_BOX =\n \"hidden h-(--indicator-height) w-(--indicator-width) translate-x-(--indicator-left) translate-y-(--indicator-top) in-data-measured:block\"\n\n/** A segmented row's raised key on the checked option itself, until the pill has a box to take. */\nexport const SEGMENTED_UNMEASURED_KEY =\n \"[&:not([data-measured])_[data-checked]]:bg-surface [&:not([data-measured])_[data-checked]]:shadow-control [&:not([data-measured])_[data-checked]]:outline [&:not([data-measured])_[data-checked]]:-outline-offset-1 [&:not([data-measured])_[data-checked]]:outline-edge-strong\"\n\n/** Writes the checked option's box onto the row, where the pill reads it. */\nfunction measure(root: HTMLElement) {\n const checked = root.querySelector<HTMLElement>(\n '[role=\"radio\"][data-checked], [role=\"menuitemradio\"][data-checked]',\n )\n\n root.style.setProperty(\"--indicator-left\", `${checked?.offsetLeft ?? 0}px`)\n root.style.setProperty(\"--indicator-top\", `${checked?.offsetTop ?? 0}px`)\n root.style.setProperty(\"--indicator-width\", `${checked?.offsetWidth ?? 0}px`)\n root.style.setProperty(\"--indicator-height\", `${checked?.offsetHeight ?? 0}px`)\n root.dataset.measured = \"\"\n}\n\n/**\n * Keeps a row's pill on its checked option: measures again when `value` changes and when the\n * row resizes, as a label that wraps, a font that loads, or an option added later moves the\n * checked one. The returned ref goes on the row.\n */\nexport function useSegmentedIndicator(value: unknown): RefObject<HTMLDivElement | null> {\n const ref = useRef<HTMLDivElement>(null)\n\n useLayoutEffect(() => {\n if (ref.current) measure(ref.current)\n }, [value])\n\n useLayoutEffect(() => {\n const root = ref.current\n if (!root) return\n\n const observer = new ResizeObserver(() => measure(root))\n observer.observe(root)\n\n return () => observer.disconnect()\n }, [])\n\n return ref\n}\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,oBAAoB,SAAS;CACxC,OAAO;EACL,MAAM;EAKN,WACE;EACF,MAAM,GACJ,oBAAoB,EAAE,aAAa,MAAM,CAAC,GAC1C,uFAGA,kCAKA,gKACF;CACF;CAEA,UAAU;EACR,SAAS;GAIP,WAAW;IACT,MAAM;IACN,WAAW;GACb;GAIA,OAAO;IACL,MAAM;IACN,WAAW;GACb;EACF;EAKA,MAAM;GACJ,IAAI,EAAE,MAAM,2CAA2C;GACvD,IAAI,EAAE,MAAM,mCAAmC;GAC/C,IAAI;IAAE,MAAM;IAAW,WAAW;IAAW,MAAM;GAA6B;EAClF;EAGA,MAAM,EACJ,MAAM,EAAE,MAAM,sCAAsC,EACtD;CACF;CAEA,kBAAkB,CAAC;EAAE,MAAM;EAAM,MAAM;EAAM,OAAO,EAAE,MAAM,iBAAiB;CAAE,CAAC;CAEhF,iBAAiB;EACf,SAAS;EACT,MAAM;CACR;AACF,CAAC;;AAGD,MAAa,0BACX;;AAGF,MAAa,2BACX;;AAGF,SAAS,QAAQ,MAAmB;CAClC,MAAM,UAAU,KAAK,cACnB,wEACF;CAEA,KAAK,MAAM,YAAY,oBAAoB,GAAG,SAAS,cAAc,EAAE,GAAG;CAC1E,KAAK,MAAM,YAAY,mBAAmB,GAAG,SAAS,aAAa,EAAE,GAAG;CACxE,KAAK,MAAM,YAAY,qBAAqB,GAAG,SAAS,eAAe,EAAE,GAAG;CAC5E,KAAK,MAAM,YAAY,sBAAsB,GAAG,SAAS,gBAAgB,EAAE,GAAG;CAC9E,KAAK,QAAQ,WAAW;AAC1B;;;;;;AAOA,SAAgB,sBAAsB,OAAkD;CACtF,MAAM,MAAM,OAAuB,IAAI;CAEvC,sBAAsB;EACpB,IAAI,IAAI,SAAS,QAAQ,IAAI,OAAO;CACtC,GAAG,CAAC,KAAK,CAAC;CAEV,sBAAsB;EACpB,MAAM,OAAO,IAAI;EACjB,IAAI,CAAC,MAAM;EAEX,MAAM,WAAW,IAAI,qBAAqB,QAAQ,IAAI,CAAC;EACvD,SAAS,QAAQ,IAAI;EAErB,aAAa,SAAS,WAAW;CACnC,GAAG,CAAC,CAAC;CAEL,OAAO;AACT"}
@@ -0,0 +1,94 @@
1
+ export interface Shortcut {
2
+ /**
3
+ * react-hotkeys-hook key string: `d`, `mod+k`, `shift+?`, `left`. Matched on the character the
4
+ * key produces, so a letter is the key labelled with it on any layout.
5
+ */
6
+ keys: string;
7
+ /** Human label shown in the reference dialog, e.g. "Today". */
8
+ label: string;
9
+ /** Section in the reference dialog, e.g. "Date range". Sections appear in registration order. */
10
+ group: string;
11
+ handler: (event: KeyboardEvent) => void;
12
+ /** Default true. A disabled shortcut neither fires nor shows up in the reference dialog. */
13
+ enabled?: boolean;
14
+ /** Fire while typing in inputs, textareas, selects and contenteditable. Default false. */
15
+ enableOnFormTags?: boolean;
16
+ }
17
+ export interface ShortcutGroup {
18
+ group: string;
19
+ shortcuts: {
20
+ keys: string;
21
+ label: string;
22
+ }[];
23
+ }
24
+ /** What `findShortcutRow` reads off a key press: a DOM event or React's. */
25
+ export interface MenuKeyEvent {
26
+ key: string;
27
+ ctrlKey: boolean;
28
+ metaKey: boolean;
29
+ altKey: boolean;
30
+ target: EventTarget | null;
31
+ }
32
+ type Registration = Pick<Shortcut, "group" | "keys" | "label">;
33
+ /** Add rows to the registry and get back the call that removes them. `useShortcuts` is the way in. */
34
+ export declare function registerShortcuts(entries: Registration[]): () => void;
35
+ /** The current list outside React, for tests. */
36
+ export declare function getShortcutList(): ShortcutGroup[];
37
+ /** The shortcuts mounted right now, grouped, for the reference dialog. Empty on the server. */
38
+ export declare function useShortcutList(): ShortcutGroup[];
39
+ /**
40
+ * A key string as the library reports the hotkey it matched, lower-cased and trimmed, so two can
41
+ * be compared like for like. A shortcut badge names its key this way in `data-shortcut`.
42
+ */
43
+ export declare function toHotkey(keys: string): string;
44
+ /**
45
+ * Whether a key typed over `target` belongs to the widget around it rather than to the page's
46
+ * shortcuts. Anything typed inside an open modal belongs to that modal, the shortcuts the modal
47
+ * registered itself included; that is the ceiling on one flat registry, and per-modal scopes
48
+ * (react-hotkeys-hook's HotkeysProvider) are what lifts it. A menu or a listbox reads letters as
49
+ * typeahead, so it keeps every key too, except the keys a menu prints: a row's badge picks that
50
+ * row (`findShortcutRow`), and a hint outside the rows stays the page's. Tabs, a grid and a
51
+ * radio group only step with the arrow keys, Home and End: stepping through a card's tabs must
52
+ * not also step the date range, but a letter typed after clicking a tab still reaches the page.
53
+ */
54
+ export declare function isWidgetKey(target: Element | null, key: string): boolean;
55
+ /**
56
+ * The row of an open menu whose badge shows the key pressed, for the menu to pick as a click
57
+ * would. The letters printed beside the rows answer ahead of the menu's typeahead, which would
58
+ * jump to the first row starting with that letter instead. Only a single character counts, with
59
+ * no Ctrl, Cmd or Alt held (Shift may be, for a `?`). In a field in the menu, such as its search,
60
+ * a key counts only while the field is empty: the search takes focus as the menu opens, and the
61
+ * keys printed on its rows still work then, while a query once begun keeps every key it types.
62
+ */
63
+ export declare function findShortcutRow(menu: Element, event: MenuKeyEvent): HTMLElement | undefined;
64
+ /**
65
+ * Register any number of shortcuts for as long as the component is mounted. One `useHotkeys` call
66
+ * carries them all, since the list may change length between renders, and the callback routes
67
+ * back to the right handler by the hotkey string the library matched.
68
+ */
69
+ export declare function useShortcuts(shortcuts: Shortcut[]): void;
70
+ /** A single shortcut, for the common case. */
71
+ export declare function useShortcut(shortcut: Shortcut): void;
72
+ /**
73
+ * Deliberately the same rule react-hotkeys-hook applies internally to decide whether `mod`
74
+ * means Meta or Control. It does not export it, and it only ever runs on a keystroke, so it
75
+ * cannot be reused, but it is the authority on what `mod` actually matches. Detecting the
76
+ * platform some other way (navigator.platform, userAgentData) risks a badge that says ⌘ while
77
+ * the matcher is waiting for Ctrl, and the label would be lying about the shortcut.
78
+ */
79
+ export declare function isMacUserAgent(userAgent: string): boolean;
80
+ /**
81
+ * Whether to spell shortcuts the Apple way. A hook rather than a module constant because this
82
+ * package renders under SSR: read at import time, the server produced "Ctrl" and the client
83
+ * hydrated "⌘", which is a hydration mismatch on every shortcut badge. Returning false as the
84
+ * server snapshot makes the first client render agree, then React re-renders with the truth.
85
+ */
86
+ export declare function useIsMac(): boolean;
87
+ /** A key string as badge parts: the modifiers in Apple order, then the key. Platform injectable for tests. */
88
+ export declare function formatKeys(keys: string, mac?: boolean): string[];
89
+ /**
90
+ * A key string as a screen reader should say it ("Command K"): the badge's glyphs would be read
91
+ * by their Unicode names, "place of interest sign" for ⌘. Platform injectable for tests.
92
+ */
93
+ export declare function formatSpokenKeys(keys: string, mac?: boolean): string;
94
+ export {};