@underpin/ui 0.0.0-stage → 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 (258) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  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 +116 -4
  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
@@ -0,0 +1,158 @@
1
+ "use client";
2
+ import { ComputerIcon, MoonIcon, SunIcon } from "../lib/icons.js";
3
+ import { SegmentedControl, SegmentedControlItem } from "./segmented-control.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ import { useSyncExternalStore } from "react";
6
+ // src/components/theme.tsx
7
+ const STORAGE_KEY = "theme";
8
+ const OS_DARK_QUERY = "(prefers-color-scheme: dark)";
9
+ const THEMES = [
10
+ "system",
11
+ "light",
12
+ "dark"
13
+ ];
14
+ /**
15
+ * Tiny module store behind `useTheme`. One value shared by every subscriber, kept in step with
16
+ * `localStorage` (and with other tabs through the `storage` event) and mirrored onto
17
+ * `<html data-theme>`, which is what the stylesheet's `color-scheme` rules key on.
18
+ */
19
+ const listeners = /* @__PURE__ */ new Set();
20
+ let current;
21
+ let osScheme;
22
+ function isTheme(value) {
23
+ return typeof value === "string" && THEMES.includes(value);
24
+ }
25
+ function readStored() {
26
+ try {
27
+ const stored = localStorage.getItem(STORAGE_KEY);
28
+ return isTheme(stored) ? stored : "system";
29
+ } catch {
30
+ return "system";
31
+ }
32
+ }
33
+ function writeStored(theme) {
34
+ try {
35
+ if (theme === "system") localStorage.removeItem(STORAGE_KEY);
36
+ else localStorage.setItem(STORAGE_KEY, theme);
37
+ } catch {}
38
+ }
39
+ /**
40
+ * `system` clears the attribute so `color-scheme: light dark` follows the OS; anything else
41
+ * pins it.
42
+ */
43
+ function applyTheme(theme) {
44
+ const root = document.documentElement;
45
+ if (theme === "system") delete root.dataset.theme;
46
+ else root.dataset.theme = theme;
47
+ }
48
+ /**
49
+ * Narrows every transition to geometry until the next style pass is done. A theme change swaps
50
+ * every token at once, and anything that transitions a colour (a card's edge, a button's fill)
51
+ * would otherwise tween into the new scheme while the rest of the page flips. Movement keeps
52
+ * its transition: the theme picker's pill slides to the chosen option in the same frames.
53
+ * Called before the change, or from the OS scheme's change event, which fires before the
54
+ * browser restyles.
55
+ */
56
+ function suspendColorTransitions() {
57
+ const style = document.createElement("style");
58
+ style.textContent = "*,*::before,*::after{transition-property:translate,transform,width,height!important}";
59
+ document.head.append(style);
60
+ requestAnimationFrame(() => requestAnimationFrame(() => style.remove()));
61
+ }
62
+ function emit() {
63
+ for (const listener of listeners) listener();
64
+ }
65
+ function onStorage(event) {
66
+ if (event.key !== null && event.key !== STORAGE_KEY) return;
67
+ current = readStored();
68
+ suspendColorTransitions();
69
+ applyTheme(current);
70
+ emit();
71
+ }
72
+ function onSchemeChange() {
73
+ if (current === "system") suspendColorTransitions();
74
+ }
75
+ function getSnapshot() {
76
+ current ??= readStored();
77
+ return current;
78
+ }
79
+ function getServerSnapshot() {
80
+ return "system";
81
+ }
82
+ function subscribe(listener) {
83
+ if (listeners.size === 0) {
84
+ window.addEventListener("storage", onStorage);
85
+ osScheme = window.matchMedia(OS_DARK_QUERY);
86
+ osScheme.addEventListener("change", onSchemeChange);
87
+ applyTheme(getSnapshot());
88
+ }
89
+ listeners.add(listener);
90
+ return () => {
91
+ listeners.delete(listener);
92
+ if (listeners.size > 0) return;
93
+ window.removeEventListener("storage", onStorage);
94
+ osScheme?.removeEventListener("change", onSchemeChange);
95
+ };
96
+ }
97
+ function setTheme(theme) {
98
+ if (theme === current) return;
99
+ current = theme;
100
+ writeStored(theme);
101
+ suspendColorTransitions();
102
+ applyTheme(theme);
103
+ emit();
104
+ }
105
+ /**
106
+ * The current theme and its setter. Persists to `localStorage["theme"]`, stays in sync across
107
+ * tabs, and drives the stylesheet's `light-dark()` tokens by setting `data-theme` on `<html>`
108
+ * (`system` removes it so the OS decides). SSR-safe: the server renders `system`.
109
+ *
110
+ * The hook only applies the stored theme once the first subscriber mounts. To avoid a flash of
111
+ * the wrong scheme, apply it before first paint with this inline script in `<head>`:
112
+ *
113
+ * ```html
114
+ * <script>try{var t=localStorage.theme;if(t==="light"||t==="dark")document.documentElement.dataset.theme=t}catch(e){}<\/script>
115
+ * ```
116
+ */
117
+ function useTheme() {
118
+ return [useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot), setTheme];
119
+ }
120
+ const THEME_OPTIONS = [
121
+ {
122
+ value: "system",
123
+ label: "System",
124
+ icon: ComputerIcon
125
+ },
126
+ {
127
+ value: "light",
128
+ label: "Light",
129
+ icon: SunIcon
130
+ },
131
+ {
132
+ value: "dark",
133
+ label: "Dark",
134
+ icon: MoonIcon
135
+ }
136
+ ];
137
+ /**
138
+ * Segmented System / Light / Dark control bound to `useTheme`, for a settings page or an
139
+ * account menu.
140
+ */
141
+ function ThemeSelect({ compact, ...props }) {
142
+ const [theme, setTheme] = useTheme();
143
+ return /* @__PURE__ */ jsx(SegmentedControl, {
144
+ value: theme,
145
+ size: compact ? "xs" : "md",
146
+ "aria-label": "Theme",
147
+ onValueChange: setTheme,
148
+ ...props,
149
+ children: THEME_OPTIONS.map(({ value, label, icon: Icon }) => /* @__PURE__ */ jsx(SegmentedControlItem, {
150
+ value,
151
+ "aria-label": compact ? label : void 0,
152
+ children: compact ? /* @__PURE__ */ jsx(Icon, {}) : label
153
+ }, value))
154
+ });
155
+ }
156
+ export { ThemeSelect, useTheme };
157
+
158
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","names":[],"sources":["../../src/components/theme.tsx"],"sourcesContent":["\"use client\"\n\nimport { useSyncExternalStore } from \"react\"\nimport { ComputerIcon, MoonIcon, SunIcon } from \"../lib/icons\"\nimport {\n SegmentedControl,\n SegmentedControlItem,\n type SegmentedControlProps,\n} from \"./segmented-control\"\n\nexport type Theme = \"system\" | \"light\" | \"dark\"\n\nconst STORAGE_KEY = \"theme\"\nconst OS_DARK_QUERY = \"(prefers-color-scheme: dark)\"\nconst THEMES: readonly Theme[] = [\"system\", \"light\", \"dark\"]\n\n/**\n * Tiny module store behind `useTheme`. One value shared by every subscriber, kept in step with\n * `localStorage` (and with other tabs through the `storage` event) and mirrored onto\n * `<html data-theme>`, which is what the stylesheet's `color-scheme` rules key on.\n */\nconst listeners = new Set<() => void>()\nlet current: Theme | undefined\n// Kept, not re-queried: `matchMedia` returns a new list per call, and a listener only comes off\n// the list it was added to.\nlet osScheme: MediaQueryList | undefined\n\nfunction isTheme(value: unknown): value is Theme {\n return typeof value === \"string\" && THEMES.includes(value as Theme)\n}\n\nfunction readStored(): Theme {\n try {\n const stored = localStorage.getItem(STORAGE_KEY)\n return isTheme(stored) ? stored : \"system\"\n } catch {\n // Storage can be unavailable (privacy mode, sandboxed iframe) — fall back to the OS.\n return \"system\"\n }\n}\n\nfunction writeStored(theme: Theme) {\n try {\n if (theme === \"system\") localStorage.removeItem(STORAGE_KEY)\n else localStorage.setItem(STORAGE_KEY, theme)\n } catch {\n // Storage being unavailable only costs persistence; the in-memory value still applies.\n }\n}\n\n/**\n * `system` clears the attribute so `color-scheme: light dark` follows the OS; anything else\n * pins it.\n */\nfunction applyTheme(theme: Theme) {\n const root = document.documentElement\n\n if (theme === \"system\") delete root.dataset.theme\n else root.dataset.theme = theme\n}\n\n/**\n * Narrows every transition to geometry until the next style pass is done. A theme change swaps\n * every token at once, and anything that transitions a colour (a card's edge, a button's fill)\n * would otherwise tween into the new scheme while the rest of the page flips. Movement keeps\n * its transition: the theme picker's pill slides to the chosen option in the same frames.\n * Called before the change, or from the OS scheme's change event, which fires before the\n * browser restyles.\n */\nfunction suspendColorTransitions() {\n const style = document.createElement(\"style\")\n style.textContent =\n \"*,*::before,*::after{transition-property:translate,transform,width,height!important}\"\n document.head.append(style)\n\n // Two frames: a callback queued from the media query event can still run before that\n // frame's style pass, and the override has to outlive it.\n requestAnimationFrame(() => requestAnimationFrame(() => style.remove()))\n}\n\nfunction emit() {\n for (const listener of listeners) listener()\n}\n\nfunction onStorage(event: StorageEvent) {\n // `key === null` is a `clear()` from another tab; treat it as a reset.\n if (event.key !== null && event.key !== STORAGE_KEY) return\n\n current = readStored()\n suspendColorTransitions()\n applyTheme(current)\n emit()\n}\n\nfunction onSchemeChange() {\n // A pinned theme ignores the OS; only `system` repaints when it flips.\n if (current === \"system\") suspendColorTransitions()\n}\n\nfunction getSnapshot(): Theme {\n current ??= readStored()\n return current\n}\n\nfunction getServerSnapshot(): Theme {\n return \"system\"\n}\n\nfunction subscribe(listener: () => void) {\n if (listeners.size === 0) {\n window.addEventListener(\"storage\", onStorage)\n osScheme = window.matchMedia(OS_DARK_QUERY)\n osScheme.addEventListener(\"change\", onSchemeChange)\n // Apps that skip the inline script still land on the stored theme, one paint late.\n applyTheme(getSnapshot())\n }\n\n listeners.add(listener)\n\n return () => {\n listeners.delete(listener)\n if (listeners.size > 0) return\n\n window.removeEventListener(\"storage\", onStorage)\n osScheme?.removeEventListener(\"change\", onSchemeChange)\n }\n}\n\nfunction setTheme(theme: Theme) {\n if (theme === current) return\n\n current = theme\n writeStored(theme)\n suspendColorTransitions()\n applyTheme(theme)\n emit()\n}\n\n/**\n * The current theme and its setter. Persists to `localStorage[\"theme\"]`, stays in sync across\n * tabs, and drives the stylesheet's `light-dark()` tokens by setting `data-theme` on `<html>`\n * (`system` removes it so the OS decides). SSR-safe: the server renders `system`.\n *\n * The hook only applies the stored theme once the first subscriber mounts. To avoid a flash of\n * the wrong scheme, apply it before first paint with this inline script in `<head>`:\n *\n * ```html\n * <script>try{var t=localStorage.theme;if(t===\"light\"||t===\"dark\")document.documentElement.dataset.theme=t}catch(e){}</script>\n * ```\n */\nexport function useTheme(): [Theme, (theme: Theme) => void] {\n const theme = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n\n return [theme, setTheme]\n}\n\nconst THEME_OPTIONS = [\n { value: \"system\", label: \"System\", icon: ComputerIcon },\n { value: \"light\", label: \"Light\", icon: SunIcon },\n { value: \"dark\", label: \"Dark\", icon: MoonIcon },\n] as const\n\ninterface ThemeSelectProps extends Omit<\n SegmentedControlProps<Theme>,\n \"value\" | \"defaultValue\" | \"onValueChange\" | \"variant\" | \"size\"\n> {\n /**\n * The smallest track with one icon per theme, for a menu row where the labelled control\n * would not fit.\n */\n compact?: boolean\n}\n\n/**\n * Segmented System / Light / Dark control bound to `useTheme`, for a settings page or an\n * account menu.\n */\nexport function ThemeSelect({ compact, ...props }: ThemeSelectProps) {\n const [theme, setTheme] = useTheme()\n\n return (\n <SegmentedControl\n value={theme}\n size={compact ? \"xs\" : \"md\"}\n aria-label=\"Theme\"\n onValueChange={setTheme}\n {...props}\n >\n {THEME_OPTIONS.map(({ value, label, icon: Icon }) => (\n <SegmentedControlItem key={value} value={value} aria-label={compact ? label : undefined}>\n {compact ? <Icon /> : label}\n </SegmentedControlItem>\n ))}\n </SegmentedControl>\n )\n}\n"],"mappings":";;;;;;AAYA,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,SAA2B;CAAC;CAAU;CAAS;AAAM;;;;;;AAO3D,MAAM,4BAAY,IAAI,IAAgB;AACtC,IAAI;AAGJ,IAAI;AAEJ,SAAS,QAAQ,OAAgC;CAC/C,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAc;AACpE;AAEA,SAAS,aAAoB;CAC3B,IAAI;EACF,MAAM,SAAS,aAAa,QAAQ,WAAW;EAC/C,OAAO,QAAQ,MAAM,IAAI,SAAS;CACpC,QAAQ;EAEN,OAAO;CACT;AACF;AAEA,SAAS,YAAY,OAAc;CACjC,IAAI;EACF,IAAI,UAAU,UAAU,aAAa,WAAW,WAAW;OACtD,aAAa,QAAQ,aAAa,KAAK;CAC9C,QAAQ,CAER;AACF;;;;;AAMA,SAAS,WAAW,OAAc;CAChC,MAAM,OAAO,SAAS;CAEtB,IAAI,UAAU,UAAU,OAAO,KAAK,QAAQ;MACvC,KAAK,QAAQ,QAAQ;AAC5B;;;;;;;;;AAUA,SAAS,0BAA0B;CACjC,MAAM,QAAQ,SAAS,cAAc,OAAO;CAC5C,MAAM,cACJ;CACF,SAAS,KAAK,OAAO,KAAK;CAI1B,4BAA4B,4BAA4B,MAAM,OAAO,CAAC,CAAC;AACzE;AAEA,SAAS,OAAO;CACd,KAAK,MAAM,YAAY,WAAW,SAAS;AAC7C;AAEA,SAAS,UAAU,OAAqB;CAEtC,IAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,aAAa;CAErD,UAAU,WAAW;CACrB,wBAAwB;CACxB,WAAW,OAAO;CAClB,KAAK;AACP;AAEA,SAAS,iBAAiB;CAExB,IAAI,YAAY,UAAU,wBAAwB;AACpD;AAEA,SAAS,cAAqB;CAC5B,YAAY,WAAW;CACvB,OAAO;AACT;AAEA,SAAS,oBAA2B;CAClC,OAAO;AACT;AAEA,SAAS,UAAU,UAAsB;CACvC,IAAI,UAAU,SAAS,GAAG;EACxB,OAAO,iBAAiB,WAAW,SAAS;EAC5C,WAAW,OAAO,WAAW,aAAa;EAC1C,SAAS,iBAAiB,UAAU,cAAc;EAElD,WAAW,YAAY,CAAC;CAC1B;CAEA,UAAU,IAAI,QAAQ;CAEtB,aAAa;EACX,UAAU,OAAO,QAAQ;EACzB,IAAI,UAAU,OAAO,GAAG;EAExB,OAAO,oBAAoB,WAAW,SAAS;EAC/C,UAAU,oBAAoB,UAAU,cAAc;CACxD;AACF;AAEA,SAAS,SAAS,OAAc;CAC9B,IAAI,UAAU,SAAS;CAEvB,UAAU;CACV,YAAY,KAAK;CACjB,wBAAwB;CACxB,WAAW,KAAK;CAChB,KAAK;AACP;;;;;;;;;;;;;AAcA,SAAgB,WAA4C;CAG1D,OAAO,CAFO,qBAAqB,WAAW,aAAa,iBAE/C,GAAG,QAAQ;AACzB;AAEA,MAAM,gBAAgB;CACpB;EAAE,OAAO;EAAU,OAAO;EAAU,MAAM;CAAa;CACvD;EAAE,OAAO;EAAS,OAAO;EAAS,MAAM;CAAQ;CAChD;EAAE,OAAO;EAAQ,OAAO;EAAQ,MAAM;CAAS;AACjD;;;;;AAiBA,SAAgB,YAAY,EAAE,SAAS,GAAG,SAA2B;CACnE,MAAM,CAAC,OAAO,YAAY,SAAS;CAEnC,OACE,oBAAC,kBAAD;EACE,OAAO;EACP,MAAM,UAAU,OAAO;EACvB,cAAW;EACX,eAAe;EACf,GAAI;EAEH,UAAA,cAAc,KAAK,EAAE,OAAO,OAAO,MAAM,WACxC,oBAAC,sBAAD;GAAyC;GAAO,cAAY,UAAU,QAAQ,KAAA;GAC3E,UAAA,UAAU,oBAAC,MAAD,CAAO,CAAA,IAAI;EACF,GAFK,KAEL,CACvB;CACe,CAAA;AAEtB"}
@@ -0,0 +1,122 @@
1
+ import { TimeSeriesNote, TimeSeriesPoint, TimeSeriesSeries } from "../lib/time-series.js";
2
+ import { ComponentProps } from "react";
3
+ export interface TimeSeriesChartProps extends Omit<ComponentProps<"div">, "children"> {
4
+ data: TimeSeriesPoint[];
5
+ /**
6
+ * The series name, shown in the tooltip. Under `series` it is the chart's accessible name
7
+ * instead; each line carries its own label.
8
+ */
9
+ label: string;
10
+ /**
11
+ * Series colour; one of the `--color-chart-*` tokens.
12
+ */
13
+ color?: string;
14
+ /**
15
+ * Multi-series mode: one line per entry, read from `point.values[key]`, all on the value
16
+ * axis. Draws no gradient and no `previous` line; lists every line in the tooltip, largest
17
+ * first, and a legend of totals above the plot. Meant for up to three lines.
18
+ */
19
+ series?: TimeSeriesSeries[];
20
+ /**
21
+ * Whether the legend sums each line over the range. Off for a metric that does not add up
22
+ * across buckets (a rate, an average duration), where the legend names the lines alone.
23
+ */
24
+ seriesTotals?: boolean;
25
+ /**
26
+ * Value-axis tick, usually compact ("5.9K"). The chart builds no formatter of its own: the
27
+ * app supplies every reading, so the axis follows the same locale and time zone as the
28
+ * figures around it.
29
+ */
30
+ formatTick: (value: number) => string;
31
+ /**
32
+ * Tooltip value, usually grouped ("5,912").
33
+ */
34
+ formatValue: (value: number) => string;
35
+ /**
36
+ * Date-axis tick, usually short ("Sep 6").
37
+ */
38
+ formatDate: (date: Date) => string;
39
+ /**
40
+ * A note's day in the tooltip; `formatDate` by default. Set it where `formatDate` follows
41
+ * the bucket size and drops the day on a monthly axis.
42
+ */
43
+ formatNoteDate?: (date: Date) => string;
44
+ /**
45
+ * Tooltip heading, usually long ("September 6, 2026").
46
+ */
47
+ formatTooltipDate: (date: Date) => string;
48
+ /**
49
+ * A fixed scale (a rate pinned to `[0, 100]`) instead of a rounded top over the data.
50
+ */
51
+ domain?: [number, number];
52
+ /**
53
+ * Line shape: a smooth curve through the points by default, or straight segments between
54
+ * them (`"linear"`) so each bucket reads as a corner.
55
+ */
56
+ curve?: "smooth" | "linear";
57
+ /**
58
+ * The line through `value` (default), or the `bar` series alone (`"bar"`) at full scale on
59
+ * the left axis: a sum per bucket, such as money, rather than a level. As the chart, a
60
+ * compared period (`previous`, in the bar's unit) is a hatched bar beside each one. The bar
61
+ * element is the same either way, so switching morphs the bars instead of redrawing them.
62
+ */
63
+ shape?: "line" | "bar";
64
+ /**
65
+ * The bar series' name (tooltip and legend); shown when any point carries a `bar`.
66
+ */
67
+ barLabel?: string;
68
+ /** The outline series' name (tooltip); shown when any point carries an `outline`. */
69
+ outlineLabel?: string;
70
+ /**
71
+ * Bar colour; one of the `--color-chart-*` tokens.
72
+ */
73
+ barColor?: string;
74
+ /**
75
+ * Bar-axis tick, on the left; `formatTick` by default.
76
+ */
77
+ formatBarTick?: (value: number) => string;
78
+ /**
79
+ * Bar tooltip value; `formatValue` by default.
80
+ */
81
+ formatBarValue?: (value: number) => string;
82
+ /**
83
+ * Notes pinned to dates; drawn as markers on the baseline of the bucket that holds them and
84
+ * listed in that bucket's tooltip.
85
+ */
86
+ notes?: TimeSeriesNote[];
87
+ /**
88
+ * Marker and tooltip colour for notes; one of the `--color-chart-*` tokens.
89
+ */
90
+ noteColor?: string;
91
+ /**
92
+ * The exclusive end of the bucket starting at `date`. Only the trailing bucket needs it,
93
+ * since every other bucket ends where the next begins, and only because a month bucket's
94
+ * width can't be read off the series; without it the last bucket is as wide as the one
95
+ * before.
96
+ */
97
+ bucketEnd?: (date: Date) => Date;
98
+ /**
99
+ * Called with the clicked bucket's date and exclusive end. The cursor turns into a pointer
100
+ * when set.
101
+ */
102
+ onPointClick?: (date: Date, end: Date) => void;
103
+ /**
104
+ * What a click on the plot does, said at the foot of the tooltip; shown only with
105
+ * `onPointClick`.
106
+ */
107
+ pointClickHint?: string;
108
+ /**
109
+ * Draw no value labels, on either side, and let the data run to the plot's edges. The grid
110
+ * stays. For a plot too narrow to give the labels their room.
111
+ */
112
+ hideValueAxis?: boolean;
113
+ }
114
+ /**
115
+ * The single time series: a smooth gradient area with a right-hand value axis on round grid
116
+ * lines and evenly spaced date ticks along the bottom. A compared period draws as a dashed
117
+ * line in the same hue. Notes pinned to dates mark their bucket on the baseline and list
118
+ * themselves in its tooltip. With `series` set it is several plain lines on that same axis,
119
+ * under a legend of totals.
120
+ */
121
+ export declare function TimeSeriesChart({ data, label, color, series, seriesTotals, formatTick, formatValue, formatDate, formatNoteDate, formatTooltipDate, domain, curve, shape, barLabel, outlineLabel, barColor, formatBarTick, formatBarValue, notes, noteColor, bucketEnd, onPointClick, pointClickHint, hideValueAxis, className, ...props }: TimeSeriesChartProps): import("react").JSX.Element;
122
+ export type { TimeSeriesNote, TimeSeriesPoint, TimeSeriesSeries };