@eifi1/ui-kit 0.7.0 → 0.8.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 (233) hide show
  1. package/README.md +32 -17
  2. package/dist/chart.d.ts +3 -2
  3. package/dist/components/alert-banner.d.ts +59 -10
  4. package/dist/components/alert-banner.js +114 -8
  5. package/dist/components/alert-banner.js.map +1 -1
  6. package/dist/components/amount-input.d.ts +5 -0
  7. package/dist/components/button-group.d.ts +26 -0
  8. package/dist/components/button-group.js +49 -0
  9. package/dist/components/button-group.js.map +1 -0
  10. package/dist/components/calculator.d.ts +5 -0
  11. package/dist/components/chart-zoom.d.ts +63 -14
  12. package/dist/components/chart-zoom.js +82 -16
  13. package/dist/components/chart-zoom.js.map +1 -1
  14. package/dist/components/chip.d.ts +67 -2
  15. package/dist/components/chip.js +73 -8
  16. package/dist/components/chip.js.map +1 -1
  17. package/dist/components/confirm-dialog.d.ts +120 -0
  18. package/dist/components/confirm-dialog.js +96 -0
  19. package/dist/components/confirm-dialog.js.map +1 -0
  20. package/dist/components/copy-button.d.ts +62 -0
  21. package/dist/components/copy-button.js +95 -0
  22. package/dist/components/copy-button.js.map +1 -0
  23. package/dist/components/data-table-filter-popover.d.ts +1 -1
  24. package/dist/components/data-table-filters.d.ts +1 -1
  25. package/dist/components/data-table-pagination.d.ts +5 -1
  26. package/dist/components/data-table-pagination.js +71 -58
  27. package/dist/components/data-table-pagination.js.map +1 -1
  28. package/dist/components/data-table-sort.d.ts +28 -5
  29. package/dist/components/data-table-sort.js +11 -7
  30. package/dist/components/data-table-sort.js.map +1 -1
  31. package/dist/components/data-table.d.ts +1 -1
  32. package/dist/components/data-table.js +544 -423
  33. package/dist/components/data-table.js.map +1 -1
  34. package/dist/components/date-picker.d.ts +51 -5
  35. package/dist/components/date-picker.js +152 -40
  36. package/dist/components/date-picker.js.map +1 -1
  37. package/dist/components/description-list.d.ts +60 -0
  38. package/dist/components/description-list.js +112 -0
  39. package/dist/components/description-list.js.map +1 -0
  40. package/dist/components/disclosure.d.ts +37 -2
  41. package/dist/components/disclosure.js +14 -5
  42. package/dist/components/disclosure.js.map +1 -1
  43. package/dist/components/facing-pair.d.ts +2 -0
  44. package/dist/components/file-button.d.ts +19 -1
  45. package/dist/components/file-button.js +8 -1
  46. package/dist/components/file-button.js.map +1 -1
  47. package/dist/components/file-dropzone.d.ts +56 -9
  48. package/dist/components/file-dropzone.js +100 -70
  49. package/dist/components/file-dropzone.js.map +1 -1
  50. package/dist/components/floating-panel.d.ts +107 -0
  51. package/dist/components/floating-panel.js +206 -0
  52. package/dist/components/floating-panel.js.map +1 -0
  53. package/dist/components/full-bleed-dialog.d.ts +12 -1
  54. package/dist/components/full-bleed-dialog.js +26 -5
  55. package/dist/components/full-bleed-dialog.js.map +1 -1
  56. package/dist/components/modal.d.ts +6 -2
  57. package/dist/components/modal.js +2 -1
  58. package/dist/components/modal.js.map +1 -1
  59. package/dist/components/number-field.d.ts +5 -0
  60. package/dist/components/number-input.d.ts +5 -0
  61. package/dist/components/numpad-sheet.d.ts +5 -0
  62. package/dist/components/progress-bar.d.ts +54 -0
  63. package/dist/components/progress-bar.js +94 -0
  64. package/dist/components/progress-bar.js.map +1 -0
  65. package/dist/components/scroll-area.d.ts +53 -0
  66. package/dist/components/scroll-area.js +86 -0
  67. package/dist/components/scroll-area.js.map +1 -0
  68. package/dist/components/separator.d.ts +23 -0
  69. package/dist/components/separator.js +24 -0
  70. package/dist/components/separator.js.map +1 -0
  71. package/dist/components/series-chart-ticks.d.ts +34 -1
  72. package/dist/components/series-chart-ticks.js +83 -1
  73. package/dist/components/series-chart-ticks.js.map +1 -1
  74. package/dist/components/series-chart.d.ts +314 -19
  75. package/dist/components/series-chart.js +510 -120
  76. package/dist/components/series-chart.js.map +1 -1
  77. package/dist/components/settings-fields.d.ts +2 -0
  78. package/dist/components/skeleton.d.ts +36 -0
  79. package/dist/components/skeleton.js +35 -0
  80. package/dist/components/skeleton.js.map +1 -0
  81. package/dist/components/stat-tile.d.ts +60 -6
  82. package/dist/components/stat-tile.js +60 -26
  83. package/dist/components/stat-tile.js.map +1 -1
  84. package/dist/components/table.d.ts +83 -0
  85. package/dist/components/table.js +166 -0
  86. package/dist/components/table.js.map +1 -0
  87. package/dist/components/time-input.d.ts +2 -0
  88. package/dist/components/toggle-legend.d.ts +3 -2
  89. package/dist/components/toggle-legend.js +1 -1
  90. package/dist/components/toggle-legend.js.map +1 -1
  91. package/dist/components/tooltip.d.ts +10 -4
  92. package/dist/components/tooltip.js +23 -6
  93. package/dist/components/tooltip.js.map +1 -1
  94. package/dist/components/tree-view.d.ts +129 -0
  95. package/dist/components/tree-view.js +376 -0
  96. package/dist/components/tree-view.js.map +1 -0
  97. package/dist/components/treemap.d.ts +9 -2
  98. package/dist/components/treemap.js +2 -1
  99. package/dist/components/treemap.js.map +1 -1
  100. package/dist/components/ui.d.ts +92 -14
  101. package/dist/components/ui.js +112 -30
  102. package/dist/components/ui.js.map +1 -1
  103. package/dist/components/use-table-state.d.ts +1 -1
  104. package/dist/{data-table-filters-noy0Abvi.d.ts → data-table-filters-CF1PXqjQ.d.ts} +73 -3
  105. package/dist/data-table.d.ts +2 -2
  106. package/dist/data-table.js.map +1 -1
  107. package/dist/hooks/use-copy-to-clipboard.d.ts +28 -0
  108. package/dist/hooks/use-copy-to-clipboard.js +81 -0
  109. package/dist/hooks/use-copy-to-clipboard.js.map +1 -0
  110. package/dist/hooks/use-debounce.d.ts +43 -0
  111. package/dist/hooks/use-debounce.js +56 -0
  112. package/dist/hooks/use-debounce.js.map +1 -0
  113. package/dist/hooks/use-file-drop.d.ts +72 -0
  114. package/dist/hooks/use-file-drop.js +57 -0
  115. package/dist/hooks/use-file-drop.js.map +1 -0
  116. package/dist/i18n/defaults.d.ts +5 -0
  117. package/dist/i18n/defaults.js +7 -1
  118. package/dist/i18n/defaults.js.map +1 -1
  119. package/dist/i18n/kit-labels.d.ts +17 -0
  120. package/dist/i18n/kit-labels.js +6 -2
  121. package/dist/i18n/kit-labels.js.map +1 -1
  122. package/dist/i18n/locales/de-CH-informal.d.ts +43 -0
  123. package/dist/i18n/locales/de-CH-informal.js +8 -0
  124. package/dist/i18n/locales/de-CH-informal.js.map +1 -0
  125. package/dist/i18n/locales/de-CH.d.ts +5 -0
  126. package/dist/i18n/locales/de-CH.js +1 -14
  127. package/dist/i18n/locales/de-CH.js.map +1 -1
  128. package/dist/i18n/locales/de-informal.d.ts +64 -0
  129. package/dist/i18n/locales/de-informal.js +37 -0
  130. package/dist/i18n/locales/de-informal.js.map +1 -0
  131. package/dist/i18n/locales/de.d.ts +5 -0
  132. package/dist/i18n/locales/de.js +25 -0
  133. package/dist/i18n/locales/de.js.map +1 -1
  134. package/dist/i18n/locales/es.d.ts +5 -0
  135. package/dist/i18n/locales/es.js +25 -0
  136. package/dist/i18n/locales/es.js.map +1 -1
  137. package/dist/i18n/locales/fr.d.ts +5 -0
  138. package/dist/i18n/locales/fr.js +25 -0
  139. package/dist/i18n/locales/fr.js.map +1 -1
  140. package/dist/i18n/locales/hu.d.ts +5 -0
  141. package/dist/i18n/locales/hu.js +25 -0
  142. package/dist/i18n/locales/hu.js.map +1 -1
  143. package/dist/i18n/locales/it.d.ts +5 -0
  144. package/dist/i18n/locales/it.js +25 -0
  145. package/dist/i18n/locales/it.js.map +1 -1
  146. package/dist/i18n/locales/zh.d.ts +5 -0
  147. package/dist/i18n/locales/zh.js +25 -0
  148. package/dist/i18n/locales/zh.js.map +1 -1
  149. package/dist/i18n/swiss.d.ts +13 -0
  150. package/dist/i18n/swiss.js +19 -0
  151. package/dist/i18n/swiss.js.map +1 -0
  152. package/dist/index.d.ts +26 -11
  153. package/dist/index.js +22 -0
  154. package/dist/index.js.map +1 -1
  155. package/dist/lib/dates.d.ts +37 -1
  156. package/dist/lib/dates.js +19 -0
  157. package/dist/lib/dates.js.map +1 -1
  158. package/dist/rhf/form.d.ts +2 -0
  159. package/dist/rhf.d.ts +2 -0
  160. package/dist/search/command-palette.d.ts +15 -1
  161. package/dist/search/command-palette.js +10 -2
  162. package/dist/search/command-palette.js.map +1 -1
  163. package/dist/shell/app-shell.js +2 -2
  164. package/dist/shell/app-shell.js.map +1 -1
  165. package/dist/wizard/stepper-nav.d.ts +35 -2
  166. package/dist/wizard/stepper-nav.js +54 -22
  167. package/dist/wizard/stepper-nav.js.map +1 -1
  168. package/dist/wizard/types.d.ts +107 -5
  169. package/dist/wizard/types.js +2 -1
  170. package/dist/wizard/types.js.map +1 -1
  171. package/dist/wizard/use-wizard.js +141 -21
  172. package/dist/wizard/use-wizard.js.map +1 -1
  173. package/dist/wizard/wizard-summary.d.ts +10 -2
  174. package/dist/wizard/wizard-summary.js +3 -1
  175. package/dist/wizard/wizard-summary.js.map +1 -1
  176. package/dist/wizard.d.ts +4 -1
  177. package/dist/wizard.js.map +1 -1
  178. package/package.json +1 -1
  179. package/src/components/alert-banner.tsx +211 -20
  180. package/src/components/button-group.tsx +75 -0
  181. package/src/components/chart-zoom.tsx +158 -20
  182. package/src/components/chip.tsx +160 -9
  183. package/src/components/confirm-dialog.tsx +242 -0
  184. package/src/components/copy-button.tsx +158 -0
  185. package/src/components/data-table-pagination.tsx +19 -6
  186. package/src/components/data-table-sort.ts +49 -10
  187. package/src/components/data-table.tsx +293 -24
  188. package/src/components/date-picker.tsx +262 -57
  189. package/src/components/description-list.tsx +174 -0
  190. package/src/components/disclosure.tsx +58 -5
  191. package/src/components/file-button.tsx +22 -2
  192. package/src/components/file-dropzone.tsx +198 -100
  193. package/src/components/floating-panel.tsx +341 -0
  194. package/src/components/full-bleed-dialog.tsx +48 -5
  195. package/src/components/modal.tsx +9 -2
  196. package/src/components/progress-bar.tsx +163 -0
  197. package/src/components/scroll-area.tsx +129 -0
  198. package/src/components/separator.tsx +37 -0
  199. package/src/components/series-chart-ticks.ts +135 -0
  200. package/src/components/series-chart.tsx +934 -67
  201. package/src/components/skeleton.tsx +65 -0
  202. package/src/components/stat-tile.tsx +160 -27
  203. package/src/components/table.tsx +263 -0
  204. package/src/components/toggle-legend.tsx +4 -3
  205. package/src/components/tooltip.tsx +40 -12
  206. package/src/components/tree-view.tsx +589 -0
  207. package/src/components/treemap.tsx +10 -2
  208. package/src/components/ui.tsx +268 -42
  209. package/src/data-table.ts +2 -0
  210. package/src/hooks/use-copy-to-clipboard.ts +122 -0
  211. package/src/hooks/use-debounce.ts +105 -0
  212. package/src/hooks/use-file-drop.ts +123 -0
  213. package/src/i18n/defaults.ts +6 -0
  214. package/src/i18n/kit-labels.tsx +19 -0
  215. package/src/i18n/locales/de-CH-informal.ts +10 -0
  216. package/src/i18n/locales/de-CH.ts +1 -16
  217. package/src/i18n/locales/de-informal.ts +61 -0
  218. package/src/i18n/locales/de.ts +25 -0
  219. package/src/i18n/locales/es.ts +25 -0
  220. package/src/i18n/locales/fr.ts +25 -0
  221. package/src/i18n/locales/hu.ts +25 -0
  222. package/src/i18n/locales/it.ts +25 -0
  223. package/src/i18n/locales/zh.ts +25 -0
  224. package/src/i18n/swiss.ts +25 -0
  225. package/src/index.ts +29 -0
  226. package/src/lib/dates.ts +48 -0
  227. package/src/search/command-palette.tsx +29 -3
  228. package/src/shell/app-shell.tsx +2 -2
  229. package/src/wizard/stepper-nav.tsx +102 -28
  230. package/src/wizard/types.ts +106 -4
  231. package/src/wizard/use-wizard.ts +211 -31
  232. package/src/wizard/wizard-summary.tsx +24 -12
  233. package/src/wizard.ts +3 -2
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/tree-view.tsx"],"sourcesContent":["import { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, KeyboardEvent, MouseEvent, ReactNode } from \"react\";\nimport { ChevronRight } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { horizontalStep } from \"../lib/direction\";\nimport { Spinner } from \"./ui\";\n\n/**\n * A hierarchy you walk with the keyboard: kastlan's chart of accounts (Assets › Current\n * assets › Bank › 1020 Operating account), and — through {@link TreeRow} alone — the\n * row labels of its gantt, which indent and fold like a tree but sit beside a timeline\n * and so cannot be one.\n *\n * Both apps had written it as nested `<div>`s with a chevron button per row: every\n * row a Tab stop (a 300-account chart was 300 presses to get past), no way to say\n * \"level 3 of 5, collapsed\" to a screen reader, and no ←/→ at all. This is the WAI-ARIA\n * tree pattern instead:\n *\n * - `role=\"tree\"` › `treeitem` (with `aria-level`, `aria-expanded` on a parent,\n * `aria-selected` when selectable) › `role=\"group\"` for its children — so the\n * reader announces the position and the state it needs.\n * - ONE Tab stop (roving tabindex). ↑/↓ walk the visible rows, → opens a closed\n * parent and then steps into it, ← closes an open one and then steps out to the\n * parent, Home/End jump to the ends, `*` opens every sibling, and typing a few\n * letters jumps to the next row that starts with them. ←/→ follow the reading\n * direction (`horizontalStep`): in an RTL tree the children hang off to the left,\n * and ← is what opens them.\n * - Enter / Space, or a click, select. The chevron alone toggles on click.\n *\n * `expanded` and `selected` each work controlled or uncontrolled.\n */\n\n/* ── Nodes ───────────────────────────────────────────────────────────────── */\n\nexport interface TreeNode<T = unknown> {\n /** Unique across the whole tree — it is what `expanded` and `selected` hold. */\n id: string;\n label: ReactNode;\n /** The text type-ahead matches. Defaults to the row's rendered text. */\n textValue?: string;\n /** Before the label: an account-type icon, a colour dot. */\n icon?: ReactNode;\n /** After the label, pushed to the end of the row: a balance, a count, an action. */\n trailing?: ReactNode;\n children?: readonly TreeNode<T>[];\n /**\n * The node has children that are not loaded yet — it gets a chevron, and opening it\n * calls `loadChildren`. Pass the children in `items` once they arrive.\n */\n hasChildren?: boolean;\n /** Focusable and announced as unavailable (`aria-disabled`), but not selectable. */\n disabled?: boolean;\n /** Anything of the host's own, handed back to `renderItem` and `onSelectedChange`. */\n data?: T;\n}\n\n/** What {@link TreeViewProps.renderItem} is told about a row. */\nexport interface TreeItemState {\n level: number;\n expanded: boolean;\n selected: boolean;\n /** It has children, loaded or not — it shows a chevron. */\n expandable: boolean;\n loading: boolean;\n disabled: boolean;\n}\n\n/* ── TreeRow ─────────────────────────────────────────────────────────────── */\n\nexport interface TreeRowProps extends ComponentPropsWithoutRef<\"div\"> {\n /** 1 for a top-level row. Sets the indent and the number of guides. */\n level: number;\n /** `true`/`false` for a row that can fold; leave it `undefined` for a leaf, which\n * gets a chevron-sized gap instead so labels at one level still line up. */\n expanded?: boolean;\n /**\n * Make the chevron a real button (with `aria-expanded`, named by the label) that\n * calls this. For a row used ON ITS OWN — kastlan's gantt labels, where each row is\n * a line of a timeline and not an item of a tree widget. Inside {@link TreeView} it\n * is omitted: the tree owns the keys, and a button per row would be a Tab stop per\n * row, which is what the tree exists to remove.\n */\n onToggle?: () => void;\n /** The toggle button's name. By default it is named by the row's label (the state\n * is `aria-expanded`'s to say); required when `children` replaces the label. */\n toggleLabel?: string;\n label: ReactNode;\n icon?: ReactNode;\n trailing?: ReactNode;\n /** Pixels per level. Default 16. */\n indent?: number;\n /** Draw a vertical hairline per ancestor level. Default `true`. */\n guides?: boolean;\n selected?: boolean;\n /** A spinner in place of the chevron, while lazy children load. */\n loading?: boolean;\n /** Replace the label + trailing part of the row (the indent and chevron stay). */\n children?: ReactNode;\n}\n\nconst DEFAULT_INDENT = 16;\n/** The chevron's box; the guide for a level runs through its centre. */\nconst CHEVRON = 16;\n/** The row's start padding, before any indent. */\nconst ROW_PAD = 4;\n\n/**\n * One row: indent, guides, chevron, icon, label, trailing — no tree semantics of its\n * own. {@link TreeView} is built from it, and a host that needs the look without the\n * widget (a gantt's label column) uses it directly.\n *\n * Laid out with logical properties throughout (`padding-inline-start`,\n * `inset-inline-start`), so the indent, the guides and the chevron all hang from the\n * reading start in an RTL layout without a second code path.\n */\nexport function TreeRow({\n level,\n expanded,\n onToggle,\n toggleLabel,\n label,\n icon,\n trailing,\n indent = DEFAULT_INDENT,\n guides = true,\n selected,\n loading,\n children,\n className,\n style,\n ...rest\n}: TreeRowProps) {\n const labelId = useId();\n const depth = Math.max(0, level - 1);\n const expandable = expanded !== undefined;\n // A right-pointing chevron that turns DOWN when open. In RTL it is mirrored to point\n // left, and turning that one clockwise would point it UP — so it turns the other way.\n const chevron = (\n <ChevronRight\n aria-hidden\n className={cn(\n \"size-4 transition-transform motion-reduce:transition-none rtl:-scale-x-100\",\n expanded && \"rotate-90 rtl:-rotate-90\",\n )}\n />\n );\n return (\n <div\n {...rest}\n data-tree-row=\"\"\n data-selected={selected || undefined}\n style={{ paddingInlineStart: ROW_PAD + depth * indent, ...style }}\n className={cn(\n \"relative flex min-h-8 items-center gap-1.5 rounded pe-2 text-sm\",\n selected\n ? \"bg-[var(--bg-active)] font-medium text-[var(--text-primary)]\"\n : \"text-[var(--text-secondary)]\",\n className,\n )}\n >\n {guides &&\n Array.from({ length: depth }, (_, i) => (\n <span\n key={i}\n aria-hidden\n data-tree-guide=\"\"\n className=\"pointer-events-none absolute inset-y-0 w-px bg-[var(--border)]\"\n style={{ insetInlineStart: ROW_PAD + i * indent + CHEVRON / 2 }}\n />\n ))}\n {loading ? (\n <span className=\"flex size-4 shrink-0 items-center justify-center\">\n <Spinner label={null} className=\"size-3 border\" />\n </span>\n ) : expandable && onToggle ? (\n <button\n type=\"button\"\n aria-expanded={expanded}\n aria-label={toggleLabel}\n aria-labelledby={toggleLabel ? undefined : labelId}\n onClick={(e) => {\n e.stopPropagation();\n onToggle();\n }}\n className=\"flex size-4 shrink-0 items-center justify-center rounded text-[var(--text-muted)] outline-none hover:text-[var(--text-primary)] focus-visible:ring-2 focus-visible:ring-[var(--brand)]\"\n >\n {chevron}\n </button>\n ) : expandable ? (\n <span data-tree-toggle=\"\" className=\"flex size-4 shrink-0 cursor-pointer items-center justify-center text-[var(--text-muted)]\">\n {chevron}\n </span>\n ) : (\n <span aria-hidden className=\"size-4 shrink-0\" />\n )}\n {children ?? (\n <>\n {icon && <span className=\"flex shrink-0 items-center\">{icon}</span>}\n <span id={labelId} data-tree-label=\"\" className=\"min-w-0 flex-1 truncate\">\n {label}\n </span>\n {trailing !== undefined && trailing !== null && (\n <span className=\"ms-auto flex shrink-0 items-center gap-1 text-xs tabular-nums text-[var(--text-muted)]\">\n {trailing}\n </span>\n )}\n </>\n )}\n </div>\n );\n}\n\n/* ── TreeView ────────────────────────────────────────────────────────────── */\n\nexport interface TreeViewProps<T = unknown>\n extends Omit<ComponentPropsWithoutRef<\"ul\">, \"onSelect\" | \"children\" | \"defaultValue\"> {\n items: readonly TreeNode<T>[];\n /** Open nodes, controlled. */\n expanded?: readonly string[];\n /** Open nodes on first render, uncontrolled. */\n defaultExpanded?: readonly string[];\n onExpandedChange?: (expanded: string[]) => void;\n /** The selected node's id, controlled; `null` for none. */\n selected?: string | null;\n defaultSelected?: string | null;\n onSelectedChange?: (id: string, node: TreeNode<T>) => void;\n /** `\"none\"` makes it a navigation-only tree: no `aria-selected`, Enter toggles. */\n selectionMode?: \"single\" | \"none\";\n /** The whole row content after the chevron, per node. Wins over `label`/`trailing`. */\n renderItem?: (node: TreeNode<T>, state: TreeItemState) => ReactNode;\n /**\n * Called when a node with `hasChildren` and no `children` is opened. While the\n * promise is pending the row shows a spinner and is `aria-busy`; put the children\n * into `items` before it resolves (or after — the row opens either way).\n */\n loadChildren?: (node: TreeNode<T>) => Promise<void> | void;\n /** Pixels per level. Default 16. */\n indent?: number;\n /** Vertical hairlines per level. Default `true`. */\n indentGuides?: boolean;\n /** Extra classes for each row (the `TreeRow`), e.g. a denser height. */\n rowClassName?: string;\n}\n\ninterface FlatNode<T> {\n node: TreeNode<T>;\n level: number;\n parentId: string | null;\n}\n\nconst isExpandable = (n: TreeNode<unknown>) => Boolean(n.children?.length || n.hasChildren);\n\n/** Controlled when `value` is given, otherwise state seeded from `initial`. */\nfunction useControllable<V>(value: V | undefined, initial: V): [V, (next: V) => void] {\n const [own, setOwn] = useState<V>(initial);\n const controlled = value !== undefined;\n const set = (next: V) => {\n if (!controlled) setOwn(next);\n };\n return [controlled ? value : own, set];\n}\n\n/** How long a type-ahead run stays open between keys — the APG's suggested half second. */\nconst TYPEAHEAD_MS = 500;\n\nexport function TreeView<T = unknown>({\n items,\n expanded: expandedProp,\n defaultExpanded,\n onExpandedChange,\n selected: selectedProp,\n defaultSelected,\n onSelectedChange,\n selectionMode = \"single\",\n renderItem,\n loadChildren,\n indent = DEFAULT_INDENT,\n indentGuides = true,\n rowClassName,\n className,\n onKeyDown,\n onClick,\n ...rest\n}: TreeViewProps<T>) {\n const [expandedList, setExpandedOwn] = useControllable<readonly string[]>(\n expandedProp,\n defaultExpanded ?? [],\n );\n const [selected, setSelectedOwn] = useControllable<string | null>(\n selectedProp,\n defaultSelected ?? null,\n );\n const expandedSet = useMemo(() => new Set(expandedList), [expandedList]);\n const [loading, setLoading] = useState<ReadonlySet<string>>(() => new Set());\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const itemRefs = useRef(new Map<string, HTMLLIElement>());\n const pendingFocus = useRef<string | null>(null);\n const typeahead = useRef({ text: \"\", at: 0 });\n const baseId = useId();\n\n // Every node by id (for parents and lookups), and the rows currently on screen in\n // order — the list the arrow keys walk.\n const { byId, visible } = useMemo(() => {\n const map = new Map<string, FlatNode<T>>();\n const rows: FlatNode<T>[] = [];\n const walk = (nodes: readonly TreeNode<T>[], level: number, parentId: string | null, shown: boolean) => {\n for (const node of nodes) {\n const flat = { node, level, parentId };\n map.set(node.id, flat);\n if (shown) rows.push(flat);\n if (node.children) walk(node.children, level + 1, node.id, shown && expandedSet.has(node.id));\n }\n };\n walk(items, 1, null, true);\n return { byId: map, visible: rows };\n }, [items, expandedSet]);\n\n // The one tabbable row. Focus that was inside a branch that has since closed (a\n // click on its parent's chevron) moves up to the nearest ancestor still on screen,\n // so the tab stop never points at a row that is not rendered.\n const visibleIds = useMemo(() => new Set(visible.map((f) => f.node.id)), [visible]);\n const nearestVisible = (id: string | null): string | null => {\n let cur = id;\n while (cur && !visibleIds.has(cur)) cur = byId.get(cur)?.parentId ?? null;\n return cur;\n };\n const tabbable =\n nearestVisible(focusedId) ?? nearestVisible(selected) ?? visible[0]?.node.id ?? null;\n\n useEffect(() => {\n const id = pendingFocus.current;\n if (!id) return;\n pendingFocus.current = null;\n itemRefs.current.get(id)?.focus();\n });\n\n const focusRow = (id: string) => {\n setFocusedId(id);\n // After the commit: moving into a branch that just opened targets a row that is\n // not in the DOM yet.\n pendingFocus.current = id;\n itemRefs.current.get(id)?.focus();\n };\n\n const setExpanded = (next: Set<string>) => {\n const list = [...next];\n setExpandedOwn(list);\n onExpandedChange?.(list);\n };\n\n const open = (node: TreeNode<T>) => {\n if (expandedSet.has(node.id) || !isExpandable(node)) return;\n const next = new Set(expandedSet);\n next.add(node.id);\n setExpanded(next);\n if (loadChildren && node.hasChildren && !node.children?.length) {\n const pending = loadChildren(node);\n if (pending && typeof pending.then === \"function\") {\n setLoading((s) => new Set(s).add(node.id));\n const done = () =>\n setLoading((s) => {\n const n = new Set(s);\n n.delete(node.id);\n return n;\n });\n pending.then(done, done);\n }\n }\n };\n\n const close = (node: TreeNode<T>) => {\n if (!expandedSet.has(node.id)) return;\n const next = new Set(expandedSet);\n next.delete(node.id);\n setExpanded(next);\n };\n\n const toggle = (node: TreeNode<T>) => (expandedSet.has(node.id) ? close(node) : open(node));\n\n const select = (node: TreeNode<T>) => {\n if (node.disabled) return;\n if (selectionMode === \"none\") {\n toggle(node);\n return;\n }\n setSelectedOwn(node.id);\n onSelectedChange?.(node.id, node);\n };\n\n const idOf = (target: EventTarget | null): string | null =>\n (target as Element | null)?.closest?.<HTMLElement>('[role=\"treeitem\"]')?.dataset.treeId ?? null;\n\n const textOf = (flat: FlatNode<T>): string => {\n if (flat.node.textValue !== undefined) return flat.node.textValue;\n if (typeof flat.node.label === \"string\") return flat.node.label;\n const row = itemRefs.current.get(flat.node.id)?.querySelector(\"[data-tree-row]\");\n return row?.textContent ?? \"\";\n };\n\n const findByText = (fromIndex: number, text: string): string | null => {\n const needle = text.toLocaleLowerCase();\n for (let i = 1; i <= visible.length; i++) {\n const flat = visible[(fromIndex + i) % visible.length];\n if (textOf(flat).trim().toLocaleLowerCase().startsWith(needle)) return flat.node.id;\n }\n return null;\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLUListElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented) return;\n const id = idOf(e.target);\n const flat = id ? byId.get(id) : undefined;\n if (!flat) return;\n const { node } = flat;\n const index = visible.findIndex((f) => f.node.id === node.id);\n const expandedNow = expandedSet.has(node.id);\n // Forward / backward along the reading direction, from the row itself.\n const step = horizontalStep(e.key, e.target as Element);\n // A space inside a type-ahead run is part of the name being typed (\"current a…\"),\n // not a request to select.\n const inRun = Date.now() - typeahead.current.at < TYPEAHEAD_MS && typeahead.current.text !== \"\";\n const key = e.key === \" \" && inRun ? \"typeahead\" : e.key;\n\n let handled = true;\n if (step === 1) {\n if (!isExpandable(node)) handled = false;\n else if (!expandedNow) open(node);\n else if (node.children?.length) focusRow(node.children[0].id);\n } else if (step === -1) {\n if (expandedNow) close(node);\n else if (flat.parentId) focusRow(flat.parentId);\n else handled = false;\n } else {\n switch (key) {\n case \"ArrowDown\":\n if (index < visible.length - 1) focusRow(visible[index + 1].node.id);\n break;\n case \"ArrowUp\":\n if (index > 0) focusRow(visible[index - 1].node.id);\n break;\n case \"Home\":\n if (visible.length) focusRow(visible[0].node.id);\n break;\n case \"End\":\n if (visible.length) focusRow(visible[visible.length - 1].node.id);\n break;\n case \"Enter\":\n case \" \":\n select(node);\n break;\n case \"*\": {\n // Every sibling at this level, as the pattern suggests.\n const siblings = flat.parentId ? (byId.get(flat.parentId)?.node.children ?? []) : items;\n const next = new Set(expandedSet);\n for (const s of siblings) if (isExpandable(s)) next.add(s.id);\n setExpanded(next);\n break;\n }\n default: {\n const printable = e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;\n if (!printable) {\n handled = false;\n break;\n }\n const now = Date.now();\n const run = now - typeahead.current.at < TYPEAHEAD_MS ? typeahead.current.text : \"\";\n typeahead.current = { text: run + e.key, at: now };\n const typed = typeahead.current.text;\n // \"aaa\" cycles through the rows starting with \"a\", as a file list does;\n // anything else extends the prefix, searched from the row after this one\n // (or from this one, when it still matches the longer prefix).\n const repeated = typed.length > 1 && [...typed].every((c) => c === typed[0]);\n const target = repeated\n ? findByText(index, typed[0])\n : typed.length > 1 && textOf(flat).trim().toLocaleLowerCase().startsWith(typed.toLocaleLowerCase())\n ? node.id\n : findByText(index, typed);\n if (target) focusRow(target);\n }\n }\n }\n if (handled) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleClick = (e: MouseEvent<HTMLUListElement>) => {\n onClick?.(e);\n const id = idOf(e.target);\n const flat = id ? byId.get(id) : undefined;\n if (!flat) return;\n // Controls a host rendered into a row (an action in `trailing`) are their own.\n const control = (e.target as Element).closest(\"button, a[href], input, select, textarea\");\n if (control && itemRefs.current.get(flat.node.id)?.contains(control)) return;\n setFocusedId(flat.node.id);\n if ((e.target as Element).closest(\"[data-tree-toggle]\")) {\n toggle(flat.node);\n return;\n }\n select(flat.node);\n };\n\n const renderNodes = (nodes: readonly TreeNode<T>[], level: number, path: string): ReactNode =>\n nodes.map((node, i) => {\n // Named by its own row, not by its content: a treeitem's content is the whole\n // open branch below it, and \"Assets Current assets 1020 Bank …\" is not a name.\n // A path of indices, because a host's id may hold spaces an idref cannot.\n const rowId = `${baseId}-${path}${i}`;\n const expandable = isExpandable(node);\n const isOpen = expandable && expandedSet.has(node.id);\n const isSelected = selectionMode !== \"none\" && selected === node.id;\n const isLoading = loading.has(node.id);\n const state: TreeItemState = {\n level,\n expanded: isOpen,\n selected: isSelected,\n expandable,\n loading: isLoading,\n disabled: Boolean(node.disabled),\n };\n return (\n <li\n key={node.id}\n ref={(el) => {\n if (el) itemRefs.current.set(node.id, el);\n else itemRefs.current.delete(node.id);\n }}\n role=\"treeitem\"\n data-tree-id={node.id}\n aria-labelledby={rowId}\n aria-level={level}\n aria-expanded={expandable ? isOpen : undefined}\n aria-selected={selectionMode === \"none\" ? undefined : isSelected}\n aria-disabled={node.disabled || undefined}\n aria-busy={isLoading || undefined}\n tabIndex={node.id === tabbable ? 0 : -1}\n onFocus={(e) => {\n // Only the row itself: a focus event bubbling up from a nested row, or from\n // a control inside this one, is not this row being focused.\n if (e.target === e.currentTarget) setFocusedId(node.id);\n }}\n // The ring goes on this row's own box, not the <li>: the <li> contains the\n // whole open branch below it, and ringing that would outline a subtree.\n className=\"outline-none [&:focus-visible>[data-tree-row]]:ring-2 [&:focus-visible>[data-tree-row]]:ring-[var(--brand)]\"\n >\n <TreeRow\n id={rowId}\n level={level}\n expanded={expandable ? isOpen : undefined}\n label={node.label}\n icon={node.icon}\n trailing={node.trailing}\n indent={indent}\n guides={indentGuides}\n selected={isSelected}\n loading={isLoading}\n className={cn(\n node.disabled ? \"cursor-not-allowed opacity-50\" : \"cursor-pointer hover:bg-[var(--bg-hover)]\",\n rowClassName,\n )}\n >\n {renderItem ? renderItem(node, state) : undefined}\n </TreeRow>\n {isOpen && (\n <ul role=\"group\">\n {/* Empty while lazy children load: a \"Loading…\" line in here would be\n a child that is not a treeitem, and the parent row already says\n `aria-busy` and shows the spinner. */}\n {node.children?.length ? renderNodes(node.children, level + 1, `${path}${i}-`) : null}\n </ul>\n )}\n </li>\n );\n });\n\n return (\n <ul\n {...rest}\n role=\"tree\"\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n className={cn(\"flex flex-col text-sm\", className)}\n >\n {renderNodes(items, 1, \"\")}\n </ul>\n );\n}\n"],"mappings":";AA0II,SA0DI,UA1DJ,KA0DI,YA1DJ;AA1IJ,SAAS,WAAW,OAAO,SAAS,QAAQ,gBAAgB;AAE5D,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AA+FxB,MAAM,iBAAiB;AAEvB,MAAM,UAAU;AAEhB,MAAM,UAAU;AAWT,SAAS,QAAQ;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,SAAS;AAAA,EACT;AAAA,EAC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AC;AAEH,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,MAAK;AAAA,MACL,WAAW;AAAA,MACX,SAAS;AAAA,MACT,WAAW,GAAG,yBAAyB,SAAS;AAAA,MAE/C,sBAAY,OAAO,GAAG,EAAE;AAAA;AAAA,EAC3B;AAEJ;","names":[]}
@@ -23,8 +23,13 @@ interface TreemapNode {
23
23
  /** Overrides the by-index palette colour for this tile — e.g. to paint every child
24
24
  * in its parent group's colour, so the groups stay legible in one picture. A
25
25
  * concrete `#rrggbb` keeps the label ink measured; anything else (a CSS var) gets
26
- * `currentColor` ink, because there is nothing to measure. */
26
+ * `currentColor` ink, because there is nothing to measure — set `labelColor` then. */
27
27
  fill?: string;
28
+ /** The label's ink, for a `fill` the kit cannot measure (a `var()` or `color-mix()`):
29
+ * keksdose's recency plot fills with `color-mix(in srgb, var(--chart-1) N%,
30
+ * transparent)`, where `currentColor` put dark page text on full-strength indigo
31
+ * (~1.5:1). Wins over the measured ink when given. */
32
+ labelColor?: string;
28
33
  }
29
34
  /**
30
35
  * Everything a `<div>` takes reaches the chart's root (`ChartContainer`), so a test id
@@ -100,6 +105,8 @@ interface TreemapCellProps {
100
105
  height?: number;
101
106
  name?: string;
102
107
  fill?: string;
108
+ /** See {@link TreemapNode.labelColor}; recharts hands each node's fields to its cell. */
109
+ labelColor?: string;
103
110
  id?: string;
104
111
  onNodeClick?: (id: string, name: string) => void;
105
112
  redactNames?: boolean;
@@ -120,7 +127,7 @@ interface TreemapCellProps {
120
127
  * (`paint-order: stroke`), which defeats any inherited stroke and keeps the text solid
121
128
  * where it overlaps a lighter or darker part of its own tile.
122
129
  */
123
- declare function TreemapCell({ depth, x, y, width, height, name, fill, id, onNodeClick, redactNames, nodeNote, dir, }: TreemapCellProps): react.JSX.Element | null;
130
+ declare function TreemapCell({ depth, x, y, width, height, name, fill, labelColor, id, onNodeClick, redactNames, nodeNote, dir, }: TreemapCellProps): react.JSX.Element | null;
124
131
  /**
125
132
  * Tile chart: one rectangle per {@link TreemapNode}, sized by `value`, coloured by
126
133
  * index from the chart ramp (or by the node's own `fill`), labelled in whichever of the
@@ -44,6 +44,7 @@ function TreemapCell({
44
44
  height = 0,
45
45
  name,
46
46
  fill,
47
+ labelColor,
47
48
  id,
48
49
  onNodeClick,
49
50
  redactNames,
@@ -56,7 +57,7 @@ function TreemapCell({
56
57
  const pw = Math.round(width);
57
58
  const ph = Math.round(height);
58
59
  const tileFill = fill ?? "var(--chart-1)";
59
- const ink = textOn(tileFill);
60
+ const ink = labelColor ?? textOn(tileFill);
60
61
  const label = pw >= 44 && ph >= 20 ? fitLabel(name ?? "", pw, LABEL_FONT_SIZE) : null;
61
62
  const rawNote = id != null && nodeNote ? nodeNote(id) : void 0;
62
63
  const note = label != null && rawNote != null && ph >= 36 ? fitLabel(rawNote, pw, NOTE_FONT_SIZE) : null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/treemap.tsx"],"sourcesContent":["// A tile chart (\"treemap\"): one rectangle per node, its AREA the node's share of what\n// is drawn. Lifted out of keksdose's reports, where five cards drew it (spending by\n// group and by category, net worth by account and by type, allocation, payees, food\n// groups) — every domain word is gone and every string it could print is a prop.\n//\n// It uses the kit's own chart shell (`ChartContainer`, `ChartTooltipContent`) and the\n// kit's own ink rule (`textOn`), so it re-skins with the palette like every other\n// chart. The one thing it cannot take from a CSS var is the tile colour: the label ink\n// is MEASURED against the fill, and a `var(--chart-3)` string measures as nothing — see\n// `useChartTokenHex` below for how the concrete hex is found instead.\nimport { useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { ComponentProps, ComponentPropsWithoutRef, KeyboardEvent, ReactNode } from \"react\";\nimport { Treemap as RechartsTreemap } from \"recharts\";\nimport { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from \"./chart\";\nimport { PALETTE_HEX, textOn } from \"../theme/chart-palette\";\nimport { parseHex } from \"../theme/color\";\nimport { dirOf, type Direction } from \"../lib/direction\";\n\n/**\n * One tile.\n *\n * `value`, not keksdose's `total`: a treemap's areas are not always money (keksdose\n * already sizes one by transaction COUNT), and `value` is the word every other chart\n * in recharts uses for the number a mark is sized by. Migrating is a rename at the\n * mapping step — `{ id, name, value: row.total }`.\n */\nexport interface TreemapNode {\n /** Stable key, handed back by {@link TreemapProps.onNodeClick} and\n * {@link TreemapProps.nodeNote}. Names can collide; ids must not. */\n id: string;\n name: string;\n /** The tile's area. A node whose value is not a positive finite number is NOT\n * drawn — an area cannot be negative, and recharts lays a negative size out as\n * nonsense rather than refusing it. Saying so is the caller's job: a group that\n * vanishes silently between two views of the same data is a bug report. */\n value: number;\n /** Overrides the by-index palette colour for this tile — e.g. to paint every child\n * in its parent group's colour, so the groups stay legible in one picture. A\n * concrete `#rrggbb` keeps the label ink measured; anything else (a CSS var) gets\n * `currentColor` ink, because there is nothing to measure. */\n fill?: string;\n}\n\n/**\n * Everything a `<div>` takes reaches the chart's root (`ChartContainer`), so a test id\n * or a `data-tour` anchor can find it. `children` is the chart's own.\n */\nexport interface TreemapProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\"> {\n data: TreemapNode[];\n /**\n * Formats a node's value in the tooltip. Handed the node's SHARE of what is drawn\n * (0–1) as a second argument, because a tile is read for how big it is relative to\n * the rest, and \"€412.30\" alone makes the reader estimate that ratio off the areas.\n * The share is `undefined` when the drawn total is not positive.\n *\n * Default: the bare number through `Intl.NumberFormat` in the runtime's locale. A\n * host that has a currency or a locale passes this — the kit knows neither.\n */\n valueFormatter?: (value: number, share: number | undefined) => ReactNode;\n /** Chart height in px. Default 320. */\n height?: number;\n /** A tile was activated — by click, or by Enter/Space on a focused tile. Setting\n * this makes every tile a focusable `role=\"button\"` named by its node name. */\n onNodeClick?: (id: string, name: string) => void;\n /**\n * The node names are the user's own data (payees, not categories): the tile labels\n * and the whole tooltip bubble get `data-private`, the same attribute the kit's\n * `Tooltip redact` and `ChartTooltipContent`'s value cell carry, so the host's one\n * privacy rule reaches them. Off by default — a category name is a label of the app.\n */\n redactNames?: boolean;\n /**\n * A second, smaller line under a tile's label — one extra figure per node that the\n * name cannot carry (a year-on-year `+12%`, `new`). Return `undefined` for a node\n * with nothing to add. Never tagged `data-private`: a ratio reveals no amount.\n *\n * ON THE TILE rather than in the tooltip, for two reasons. The tooltip identifies a\n * node by name or by raw value, so a per-node note would be keyed on an amount (two\n * nodes of equal size would swap notes). And a tooltip is a pointer affordance: a\n * phone never hovers, so a figure that only exists on hover does not exist there.\n */\n nodeNote?: (id: string) => string | undefined;\n /**\n * Draw at most this many tiles (the first N drawable nodes, in the order given —\n * sort first). Unbounded by default. A tile under ~44x20px has no room for a label,\n * and a map made of unlabelled rectangles answers nothing; around 24 is where the\n * smallest tile of a skewed series reaches that floor on a phone-width card. The\n * caller owns the \"N more not shown\" line, since it knows how many it passed.\n */\n maxTiles?: number;\n /**\n * The categorical ramp tiles take by index, as concrete hex. Default: the page's\n * live `--chart-1…9` tokens (see `useChartTokenHex`). Pass one when the host\n * already holds the active palette — e.g. `createPaletteStore`'s `useChartHex()` —\n * so a caller colouring a legend beside the map is guaranteed the same list.\n */\n colors?: readonly string[];\n}\n\n// ── The categorical ramp, as concrete hex ──────────────────────────────────\n//\n// The label ink is measured against the tile's fill, so the fill has to be a colour\n// and not a reference to one. keksdose read it from its palette STORE, which is an\n// app object the kit cannot import. What the kit does own is the token layer: whether\n// a palette arrives through `applyTokenSet` (inline properties on <html>) or through\n// tokens.css (`:root` / `.dark`), the resolved `--chart-N` on <html> is the colour\n// every other chart on the page is being painted with. So that is what is read, and\n// re-read whenever <html>'s class or style changes — which is exactly when a theme\n// toggle or a palette switch lands.\n\nconst CHART_TOKENS = 9;\n\n/** The resolved ramp, joined into ONE string so `useSyncExternalStore` compares a\n * primitive: a fresh array per read would never be `Object.is`-equal to the last and\n * would re-render forever. */\nfunction readChartTokens(): string {\n const root = document.documentElement;\n const fallback = root.classList.contains(\"dark\") ? PALETTE_HEX.dark : PALETTE_HEX.light;\n const style = getComputedStyle(root);\n return Array.from({ length: CHART_TOKENS }, (_, i) => {\n const v = style.getPropertyValue(`--chart-${i + 1}`).trim();\n // An unresolved token (a host that never loaded tokens.css, a test DOM) falls\n // back to the built-in ramp for the current theme rather than to no colour.\n return parseHex(v) ? v : fallback[i];\n }).join(\",\");\n}\n\nfunction subscribeChartTokens(onChange: () => void): () => void {\n const observer = new MutationObserver(onChange);\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\"],\n });\n return () => observer.disconnect();\n}\n\nconst SERVER_TOKENS = PALETTE_HEX.light.join(\",\");\n\nfunction useChartTokenHex(): string[] {\n const joined = useSyncExternalStore(subscribeChartTokens, readChartTokens, () => SERVER_TOKENS);\n return joined.split(\",\");\n}\n\n// ── Tile ──────────────────────────────────────────────────────────────────\n\nconst LABEL_FONT_SIZE = 12;\n/** The optional second line, a step down from the name so the tile reads name-first. */\nconst NOTE_FONT_SIZE = 11;\n\n/**\n * Fit a label to its tile: the text itself when it fits, an ellipsised head when it\n * does not, `null` when not even three characters would. Without this a long name ran\n * on across its neighbours and collided with THEIR labels. 0.58em is the average\n * advance of a UI sans at this weight; it only needs to be close, since the tile keeps\n * 6px of padding either side. The full name stays in the tooltip.\n */\nexport function fitLabel(name: string, boxWidth: number, fontSize: number): string | null {\n const max = Math.floor((boxWidth - 12) / (fontSize * 0.58));\n if (max < 3) return null;\n return name.length <= max ? name : `${name.slice(0, max - 1).trimEnd()}…`;\n}\n\n/** What recharts hands a `content` element for each node, plus the three options the\n * chart forwards. Everything optional because recharts clones the element it was\n * given and fills the geometry in — the element as written carries only the options. */\nexport interface TreemapCellProps {\n depth?: number;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n name?: string;\n fill?: string;\n id?: string;\n onNodeClick?: (id: string, name: string) => void;\n redactNames?: boolean;\n nodeNote?: (id: string) => string | undefined;\n /** The page's reading direction, which `Treemap` reads off its own root. In `rtl`\n * the label stands in the tile's top RIGHT corner and is shaped right-to-left, so a\n * clipped name ends in its ellipsis on the reading end. Default `ltr`. */\n dir?: Direction;\n}\n\n/**\n * One tile. Exported so a caller drawing its own recharts `<Treemap>` gets the same\n * label rules.\n *\n * recharts' default cell inherits the chart-level `stroke`, an SVG presentation\n * attribute that lands on the `<svg>` root and cascades into the label — so the glyphs\n * were painted with a 1px outline ON TOP of themselves, which reads as blur. This cell\n * draws its own label with a halo in the TILE colour painted BEHIND the fill\n * (`paint-order: stroke`), which defeats any inherited stroke and keeps the text solid\n * where it overlaps a lighter or darker part of its own tile.\n */\nexport function TreemapCell({\n depth,\n x = 0,\n y = 0,\n width = 0,\n height = 0,\n name,\n fill,\n id,\n onNodeClick,\n redactNames,\n nodeNote,\n dir = \"ltr\",\n}: TreemapCellProps) {\n // Depth 0 is recharts' synthetic root, which spans the whole chart.\n if (!depth) return null;\n // Whole pixels: a rect on a half pixel renders its edge across two half-lit\n // columns, and the text baseline inherits that blur.\n const px = Math.round(x);\n const py = Math.round(y);\n const pw = Math.round(width);\n const ph = Math.round(height);\n const tileFill = fill ?? \"var(--chart-1)\";\n const ink = textOn(tileFill);\n // Below ~44x20 there is no room for a readable word, so no label at all rather than\n // a one-letter stub bleeding over the tile edge.\n const label = pw >= 44 && ph >= 20 ? fitLabel(name ?? \"\", pw, LABEL_FONT_SIZE) : null;\n // Only under a label that is itself drawn — a stray \"+12%\" on an unnamed rectangle\n // names nothing — and only where a second baseline fits: the note's baseline sits\n // 29px down and an 11px glyph hangs ~2px below it, so 36 leaves the same ~5px under\n // the note that the label keeps under itself at the 20px floor.\n const rawNote = id != null && nodeNote ? nodeNote(id) : undefined;\n const note =\n label != null && rawNote != null && ph >= 36 ? fitLabel(rawNote, pw, NOTE_FONT_SIZE) : null;\n // The label's START edge, 6px in from the tile's. The tiles themselves are laid out\n // physically (the plot is not mirrored, see `ChartContainer`) and the chart's SVG is\n // pinned `ltr`, so the direction is set on each <text> explicitly: `start` is then\n // the right end in RTL, and the label grows leftwards from the tile's right edge.\n const textX = dir === \"rtl\" ? px + pw - 6 : px + 6;\n const activate = id != null && onNodeClick ? () => onNodeClick(id, name ?? \"\") : undefined;\n const onKeyDown = activate\n ? (e: KeyboardEvent<SVGGElement>) => {\n if (e.key !== \"Enter\" && e.key !== \" \") return;\n e.preventDefault();\n activate();\n }\n : undefined;\n return (\n <g\n onClick={activate}\n onKeyDown={onKeyDown}\n // A clickable tile is a button to a keyboard and a screen reader too; the\n // drilldown it opens was mouse-only in the app this came from. Named by the node\n // name, which is also why the group carries `data-private` under `redactNames`.\n role={activate ? \"button\" : undefined}\n tabIndex={activate ? 0 : undefined}\n aria-label={activate ? name : undefined}\n data-private={activate && redactNames ? \"\" : undefined}\n cursor={activate ? \"pointer\" : undefined}\n // CSS beats a presentation attribute, so this recolours the rect's own stroke\n // for as long as the tile has keyboard focus.\n className={activate ? \"outline-none [&:focus-visible>rect]:stroke-[var(--brand)]\" : undefined}\n >\n {/* The 2px gutter is the card showing through, not a white grid — on a dark\n surface white lines glare harder than the tiles. */}\n <rect\n x={px}\n y={py}\n width={pw}\n height={ph}\n fill={tileFill}\n stroke=\"var(--bg-surface)\"\n strokeWidth={2}\n rx={3}\n />\n {label != null && (\n <text\n // A plain attribute, so the host's `[data-private]` rule reaches an SVG\n // <text> exactly as it reaches a table cell.\n data-private={redactNames ? \"\" : undefined}\n x={textX}\n y={py + 15}\n direction={dir}\n fill={ink}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={LABEL_FONT_SIZE}\n fontWeight={600}\n style={{ pointerEvents: \"none\" }}\n >\n {label}\n </text>\n )}\n {note != null && (\n <text\n x={textX}\n y={py + 29}\n direction={dir}\n fill={ink}\n fillOpacity={0.85}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={NOTE_FONT_SIZE}\n fontWeight={500}\n style={{ pointerEvents: \"none\" }}\n >\n {note}\n </text>\n )}\n </g>\n );\n}\n\n// ── Chart ─────────────────────────────────────────────────────────────────\n\n// Nodes carry their own `fill`, and `ChartTooltipContent` falls back to it for the\n// swatch, so no series config is needed.\nconst TREEMAP_CONFIG: ChartConfig = {};\n\n/**\n * The shared tooltip with the whole bubble tagged `data-private`, for names that are\n * the user's own data.\n *\n * The bubble, not just the name: `ChartTooltipContent` prints the name either from\n * `item.name` or from a config `label`, and only the config route could be tagged — but\n * a config entry keyed by a payee name is not a CSS identifier, and `ChartStyle` would\n * (rightly) refuse it. The bubble holds the name and the value, and the value cell is\n * already `data-private`, so tagging the wrapper hides nothing extra.\n *\n * recharts CLONES the `content` element to inject `active`/`payload`, so this has to BE\n * that element — a `<div>` wrapped around `<ChartTooltipContent />` in the JSX would\n * take those props itself and hand the tooltip nothing.\n */\nfunction RedactedTooltipContent(props: ComponentProps<typeof ChartTooltipContent>) {\n return (\n <div data-private>\n <ChartTooltipContent {...props} />\n </div>\n );\n}\n\nconst DEFAULT_NUMBER = new Intl.NumberFormat();\n\n/**\n * Tile chart: one rectangle per {@link TreemapNode}, sized by `value`, coloured by\n * index from the chart ramp (or by the node's own `fill`), labelled in whichever of the\n * kit's two inks measures better against it. Hover shows the name and the formatted\n * value; `onNodeClick` turns the tiles into buttons.\n *\n * Renders nothing when no node has a positive value — an empty box is a hole in the\n * card, and the caller's own sentence is the better answer there.\n *\n * Needs `recharts`, like everything behind `@eifi1/ui-kit/chart`.\n */\nexport function Treemap({\n data,\n valueFormatter,\n height = 320,\n onNodeClick,\n redactNames = false,\n nodeNote,\n maxTiles,\n colors,\n style,\n ...rest\n}: TreemapProps) {\n const tokenHex = useChartTokenHex();\n // Read off the DOM after mount: the `dir` a treemap sits under is an ancestor's\n // attribute, and SVG text anchoring cannot follow it by CSS (see TreemapCell). Again\n // on new data, because a map that had nothing to draw rendered no root to read.\n const rootRef = useRef<HTMLDivElement>(null);\n const [dir, setDir] = useState<Direction>(\"ltr\");\n useLayoutEffect(() => {\n setDir(dirOf(rootRef.current));\n }, [data]);\n const ramp = colors && colors.length > 0 ? colors : tokenHex;\n // Coloured by index into `data` AS GIVEN, before anything is dropped: a caller\n // painting a legend or a second map from the same list must land on the same hue\n // for the same row, and filtering first would shift every colour after a gap.\n const nodes = data\n .map((d, idx) => ({\n id: d.id,\n name: d.name,\n size: d.value,\n fill: d.fill ?? ramp[idx % ramp.length],\n }))\n .filter((n) => Number.isFinite(n.size) && n.size > 0)\n .slice(0, maxTiles ?? undefined);\n if (nodes.length === 0) return null;\n\n // The share is of what is DRAWN, so it always reads as \"of this picture\".\n const total = nodes.reduce((acc, n) => acc + n.size, 0);\n const format = (v: number): ReactNode => {\n const share = total > 0 ? v / total : undefined;\n return valueFormatter ? valueFormatter(v, share) : DEFAULT_NUMBER.format(v);\n };\n const Content = redactNames ? RedactedTooltipContent : ChartTooltipContent;\n return (\n <ChartContainer {...rest} ref={rootRef} config={TREEMAP_CONFIG} style={{ ...style, height }}>\n {/* No chart-level `stroke`: recharts spreads it onto the <svg> root, from where\n it inherits into every label (see TreemapCell). Each cell strokes its own rect. */}\n <RechartsTreemap\n data={nodes}\n dataKey=\"size\"\n fill=\"var(--chart-1)\"\n isAnimationActive={false}\n content={\n <TreemapCell onNodeClick={onNodeClick} redactNames={redactNames} nodeNote={nodeNote} dir={dir} />\n }\n >\n <ChartTooltip content={<Content hideLabel valueFormatter={format} />} />\n </RechartsTreemap>\n </ChartContainer>\n );\n}\n"],"mappings":";AAkPI,SAiBE,KAjBF;AAxOJ,SAAS,iBAAiB,QAAQ,UAAU,4BAA4B;AAExE,SAAS,WAAW,uBAAuB;AAC3C,SAAS,gBAAgB,cAAc,2BAA6C;AACpF,SAAS,aAAa,cAAc;AACpC,SAAS,gBAAgB;AACzB,SAAS,aAA6B;AA8FtC,MAAM,eAAe;AAKrB,SAAS,kBAA0B;AACjC,QAAM,OAAO,SAAS;AACtB,QAAM,WAAW,KAAK,UAAU,SAAS,MAAM,IAAI,YAAY,OAAO,YAAY;AAClF,QAAM,QAAQ,iBAAi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S,EAAE,IAAI,KAAK,EAAE,OAAO,CAAC,EACnD,MAAM,GAAG,YAAY,MAAS;AACjC,MAAI,MAAM,WAAW,EAAG,QAAO;AAG/B,QAAM,QAAQ,MAAM,OAAO,CAAC,KAAK,MAAM,MAAM,EAAE,MAAM,CAAC;AACtD,QAAM,SAAS,CAAC,MAAyB;AACvC,UAAM,QAAQ,QAAQ,IAAI,IAAI,QAAQ;AACtC,WAAO,iBAAiB,eAAe,GAAG,KAAK,IAAI,eAAe,OAAO,CAAC;AAAA,EAC5E;AACA,QAAM,UAAU,cAAc,yBAAyB;AACvD,SACE,oBAAC,kBAAgB,GAAG,MAAM,KAAK,SAAS,QAAQ,gBAAgB,OAAO,EAAE,GAAG,OAAO,OAAO,GAGxF;AAAA,IAAC;AAAA;AAAA,MACC,MAAM;AAAA,MACN,SAAQ;AAAA,MACR,MAAK;AAAA,MACL,mBAAmB;AAAA,MACnB,SACE,oBAAC,eAAY,aAA0B,aAA0B,UAAoB,KAAU;AAAA,MAGjG,8BAAC,gBAAa,SAAS,oBAAC,WAAQ,WAAS,MAAC,gBAAgB,QAAQ,GAAI;AAAA;AAAA,EACxE,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/treemap.tsx"],"sourcesContent":["// A tile chart (\"treemap\"): one rectangle per node, its AREA the node's share of what\n// is drawn. Lifted out of keksdose's reports, where five cards drew it (spending by\n// group and by category, net worth by account and by type, allocation, payees, food\n// groups) — every domain word is gone and every string it could print is a prop.\n//\n// It uses the kit's own chart shell (`ChartContainer`, `ChartTooltipContent`) and the\n// kit's own ink rule (`textOn`), so it re-skins with the palette like every other\n// chart. The one thing it cannot take from a CSS var is the tile colour: the label ink\n// is MEASURED against the fill, and a `var(--chart-3)` string measures as nothing — see\n// `useChartTokenHex` below for how the concrete hex is found instead.\nimport { useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { ComponentProps, ComponentPropsWithoutRef, KeyboardEvent, ReactNode } from \"react\";\nimport { Treemap as RechartsTreemap } from \"recharts\";\nimport { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from \"./chart\";\nimport { PALETTE_HEX, textOn } from \"../theme/chart-palette\";\nimport { parseHex } from \"../theme/color\";\nimport { dirOf, type Direction } from \"../lib/direction\";\n\n/**\n * One tile.\n *\n * `value`, not keksdose's `total`: a treemap's areas are not always money (keksdose\n * already sizes one by transaction COUNT), and `value` is the word every other chart\n * in recharts uses for the number a mark is sized by. Migrating is a rename at the\n * mapping step — `{ id, name, value: row.total }`.\n */\nexport interface TreemapNode {\n /** Stable key, handed back by {@link TreemapProps.onNodeClick} and\n * {@link TreemapProps.nodeNote}. Names can collide; ids must not. */\n id: string;\n name: string;\n /** The tile's area. A node whose value is not a positive finite number is NOT\n * drawn — an area cannot be negative, and recharts lays a negative size out as\n * nonsense rather than refusing it. Saying so is the caller's job: a group that\n * vanishes silently between two views of the same data is a bug report. */\n value: number;\n /** Overrides the by-index palette colour for this tile — e.g. to paint every child\n * in its parent group's colour, so the groups stay legible in one picture. A\n * concrete `#rrggbb` keeps the label ink measured; anything else (a CSS var) gets\n * `currentColor` ink, because there is nothing to measure — set `labelColor` then. */\n fill?: string;\n /** The label's ink, for a `fill` the kit cannot measure (a `var()` or `color-mix()`):\n * keksdose's recency plot fills with `color-mix(in srgb, var(--chart-1) N%,\n * transparent)`, where `currentColor` put dark page text on full-strength indigo\n * (~1.5:1). Wins over the measured ink when given. */\n labelColor?: string;\n}\n\n/**\n * Everything a `<div>` takes reaches the chart's root (`ChartContainer`), so a test id\n * or a `data-tour` anchor can find it. `children` is the chart's own.\n */\nexport interface TreemapProps extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\"> {\n data: TreemapNode[];\n /**\n * Formats a node's value in the tooltip. Handed the node's SHARE of what is drawn\n * (0–1) as a second argument, because a tile is read for how big it is relative to\n * the rest, and \"€412.30\" alone makes the reader estimate that ratio off the areas.\n * The share is `undefined` when the drawn total is not positive.\n *\n * Default: the bare number through `Intl.NumberFormat` in the runtime's locale. A\n * host that has a currency or a locale passes this — the kit knows neither.\n */\n valueFormatter?: (value: number, share: number | undefined) => ReactNode;\n /** Chart height in px. Default 320. */\n height?: number;\n /** A tile was activated — by click, or by Enter/Space on a focused tile. Setting\n * this makes every tile a focusable `role=\"button\"` named by its node name. */\n onNodeClick?: (id: string, name: string) => void;\n /**\n * The node names are the user's own data (payees, not categories): the tile labels\n * and the whole tooltip bubble get `data-private`, the same attribute the kit's\n * `Tooltip redact` and `ChartTooltipContent`'s value cell carry, so the host's one\n * privacy rule reaches them. Off by default — a category name is a label of the app.\n */\n redactNames?: boolean;\n /**\n * A second, smaller line under a tile's label — one extra figure per node that the\n * name cannot carry (a year-on-year `+12%`, `new`). Return `undefined` for a node\n * with nothing to add. Never tagged `data-private`: a ratio reveals no amount.\n *\n * ON THE TILE rather than in the tooltip, for two reasons. The tooltip identifies a\n * node by name or by raw value, so a per-node note would be keyed on an amount (two\n * nodes of equal size would swap notes). And a tooltip is a pointer affordance: a\n * phone never hovers, so a figure that only exists on hover does not exist there.\n */\n nodeNote?: (id: string) => string | undefined;\n /**\n * Draw at most this many tiles (the first N drawable nodes, in the order given —\n * sort first). Unbounded by default. A tile under ~44x20px has no room for a label,\n * and a map made of unlabelled rectangles answers nothing; around 24 is where the\n * smallest tile of a skewed series reaches that floor on a phone-width card. The\n * caller owns the \"N more not shown\" line, since it knows how many it passed.\n */\n maxTiles?: number;\n /**\n * The categorical ramp tiles take by index, as concrete hex. Default: the page's\n * live `--chart-1…9` tokens (see `useChartTokenHex`). Pass one when the host\n * already holds the active palette — e.g. `createPaletteStore`'s `useChartHex()` —\n * so a caller colouring a legend beside the map is guaranteed the same list.\n */\n colors?: readonly string[];\n}\n\n// ── The categorical ramp, as concrete hex ──────────────────────────────────\n//\n// The label ink is measured against the tile's fill, so the fill has to be a colour\n// and not a reference to one. keksdose read it from its palette STORE, which is an\n// app object the kit cannot import. What the kit does own is the token layer: whether\n// a palette arrives through `applyTokenSet` (inline properties on <html>) or through\n// tokens.css (`:root` / `.dark`), the resolved `--chart-N` on <html> is the colour\n// every other chart on the page is being painted with. So that is what is read, and\n// re-read whenever <html>'s class or style changes — which is exactly when a theme\n// toggle or a palette switch lands.\n\nconst CHART_TOKENS = 9;\n\n/** The resolved ramp, joined into ONE string so `useSyncExternalStore` compares a\n * primitive: a fresh array per read would never be `Object.is`-equal to the last and\n * would re-render forever. */\nfunction readChartTokens(): string {\n const root = document.documentElement;\n const fallback = root.classList.contains(\"dark\") ? PALETTE_HEX.dark : PALETTE_HEX.light;\n const style = getComputedStyle(root);\n return Array.from({ length: CHART_TOKENS }, (_, i) => {\n const v = style.getPropertyValue(`--chart-${i + 1}`).trim();\n // An unresolved token (a host that never loaded tokens.css, a test DOM) falls\n // back to the built-in ramp for the current theme rather than to no colour.\n return parseHex(v) ? v : fallback[i];\n }).join(\",\");\n}\n\nfunction subscribeChartTokens(onChange: () => void): () => void {\n const observer = new MutationObserver(onChange);\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: [\"class\", \"style\", \"data-theme\"],\n });\n return () => observer.disconnect();\n}\n\nconst SERVER_TOKENS = PALETTE_HEX.light.join(\",\");\n\nfunction useChartTokenHex(): string[] {\n const joined = useSyncExternalStore(subscribeChartTokens, readChartTokens, () => SERVER_TOKENS);\n return joined.split(\",\");\n}\n\n// ── Tile ──────────────────────────────────────────────────────────────────\n\nconst LABEL_FONT_SIZE = 12;\n/** The optional second line, a step down from the name so the tile reads name-first. */\nconst NOTE_FONT_SIZE = 11;\n\n/**\n * Fit a label to its tile: the text itself when it fits, an ellipsised head when it\n * does not, `null` when not even three characters would. Without this a long name ran\n * on across its neighbours and collided with THEIR labels. 0.58em is the average\n * advance of a UI sans at this weight; it only needs to be close, since the tile keeps\n * 6px of padding either side. The full name stays in the tooltip.\n */\nexport function fitLabel(name: string, boxWidth: number, fontSize: number): string | null {\n const max = Math.floor((boxWidth - 12) / (fontSize * 0.58));\n if (max < 3) return null;\n return name.length <= max ? name : `${name.slice(0, max - 1).trimEnd()}…`;\n}\n\n/** What recharts hands a `content` element for each node, plus the three options the\n * chart forwards. Everything optional because recharts clones the element it was\n * given and fills the geometry in — the element as written carries only the options. */\nexport interface TreemapCellProps {\n depth?: number;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n name?: string;\n fill?: string;\n /** See {@link TreemapNode.labelColor}; recharts hands each node's fields to its cell. */\n labelColor?: string;\n id?: string;\n onNodeClick?: (id: string, name: string) => void;\n redactNames?: boolean;\n nodeNote?: (id: string) => string | undefined;\n /** The page's reading direction, which `Treemap` reads off its own root. In `rtl`\n * the label stands in the tile's top RIGHT corner and is shaped right-to-left, so a\n * clipped name ends in its ellipsis on the reading end. Default `ltr`. */\n dir?: Direction;\n}\n\n/**\n * One tile. Exported so a caller drawing its own recharts `<Treemap>` gets the same\n * label rules.\n *\n * recharts' default cell inherits the chart-level `stroke`, an SVG presentation\n * attribute that lands on the `<svg>` root and cascades into the label — so the glyphs\n * were painted with a 1px outline ON TOP of themselves, which reads as blur. This cell\n * draws its own label with a halo in the TILE colour painted BEHIND the fill\n * (`paint-order: stroke`), which defeats any inherited stroke and keeps the text solid\n * where it overlaps a lighter or darker part of its own tile.\n */\nexport function TreemapCell({\n depth,\n x = 0,\n y = 0,\n width = 0,\n height = 0,\n name,\n fill,\n labelColor,\n id,\n onNodeClick,\n redactNames,\n nodeNote,\n dir = \"ltr\",\n}: TreemapCellProps) {\n // Depth 0 is recharts' synthetic root, which spans the whole chart.\n if (!depth) return null;\n // Whole pixels: a rect on a half pixel renders its edge across two half-lit\n // columns, and the text baseline inherits that blur.\n const px = Math.round(x);\n const py = Math.round(y);\n const pw = Math.round(width);\n const ph = Math.round(height);\n const tileFill = fill ?? \"var(--chart-1)\";\n const ink = labelColor ?? textOn(tileFill);\n // Below ~44x20 there is no room for a readable word, so no label at all rather than\n // a one-letter stub bleeding over the tile edge.\n const label = pw >= 44 && ph >= 20 ? fitLabel(name ?? \"\", pw, LABEL_FONT_SIZE) : null;\n // Only under a label that is itself drawn — a stray \"+12%\" on an unnamed rectangle\n // names nothing — and only where a second baseline fits: the note's baseline sits\n // 29px down and an 11px glyph hangs ~2px below it, so 36 leaves the same ~5px under\n // the note that the label keeps under itself at the 20px floor.\n const rawNote = id != null && nodeNote ? nodeNote(id) : undefined;\n const note =\n label != null && rawNote != null && ph >= 36 ? fitLabel(rawNote, pw, NOTE_FONT_SIZE) : null;\n // The label's START edge, 6px in from the tile's. The tiles themselves are laid out\n // physically (the plot is not mirrored, see `ChartContainer`) and the chart's SVG is\n // pinned `ltr`, so the direction is set on each <text> explicitly: `start` is then\n // the right end in RTL, and the label grows leftwards from the tile's right edge.\n const textX = dir === \"rtl\" ? px + pw - 6 : px + 6;\n const activate = id != null && onNodeClick ? () => onNodeClick(id, name ?? \"\") : undefined;\n const onKeyDown = activate\n ? (e: KeyboardEvent<SVGGElement>) => {\n if (e.key !== \"Enter\" && e.key !== \" \") return;\n e.preventDefault();\n activate();\n }\n : undefined;\n return (\n <g\n onClick={activate}\n onKeyDown={onKeyDown}\n // A clickable tile is a button to a keyboard and a screen reader too; the\n // drilldown it opens was mouse-only in the app this came from. Named by the node\n // name, which is also why the group carries `data-private` under `redactNames`.\n role={activate ? \"button\" : undefined}\n tabIndex={activate ? 0 : undefined}\n aria-label={activate ? name : undefined}\n data-private={activate && redactNames ? \"\" : undefined}\n cursor={activate ? \"pointer\" : undefined}\n // CSS beats a presentation attribute, so this recolours the rect's own stroke\n // for as long as the tile has keyboard focus.\n className={activate ? \"outline-none [&:focus-visible>rect]:stroke-[var(--brand)]\" : undefined}\n >\n {/* The 2px gutter is the card showing through, not a white grid — on a dark\n surface white lines glare harder than the tiles. */}\n <rect\n x={px}\n y={py}\n width={pw}\n height={ph}\n fill={tileFill}\n stroke=\"var(--bg-surface)\"\n strokeWidth={2}\n rx={3}\n />\n {label != null && (\n <text\n // A plain attribute, so the host's `[data-private]` rule reaches an SVG\n // <text> exactly as it reaches a table cell.\n data-private={redactNames ? \"\" : undefined}\n x={textX}\n y={py + 15}\n direction={dir}\n fill={ink}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={LABEL_FONT_SIZE}\n fontWeight={600}\n style={{ pointerEvents: \"none\" }}\n >\n {label}\n </text>\n )}\n {note != null && (\n <text\n x={textX}\n y={py + 29}\n direction={dir}\n fill={ink}\n fillOpacity={0.85}\n stroke={tileFill}\n strokeWidth={2.5}\n strokeLinejoin=\"round\"\n paintOrder=\"stroke\"\n fontSize={NOTE_FONT_SIZE}\n fontWeight={500}\n style={{ pointerEvents: \"none\" }}\n >\n {note}\n </text>\n )}\n </g>\n );\n}\n\n// ── Chart ─────────────────────────────────────────────────────────────────\n\n// Nodes carry their own `fill`, and `ChartTooltipContent` falls back to it for the\n// swatch, so no series config is needed.\nconst TREEMAP_CONFIG: ChartConfig = {};\n\n/**\n * The shared tooltip with the whole bubble tagged `data-private`, for names that are\n * the user's own data.\n *\n * The bubble, not just the name: `ChartTooltipContent` prints the name either from\n * `item.name` or from a config `label`, and only the config route could be tagged — but\n * a config entry keyed by a payee name is not a CSS identifier, and `ChartStyle` would\n * (rightly) refuse it. The bubble holds the name and the value, and the value cell is\n * already `data-private`, so tagging the wrapper hides nothing extra.\n *\n * recharts CLONES the `content` element to inject `active`/`payload`, so this has to BE\n * that element — a `<div>` wrapped around `<ChartTooltipContent />` in the JSX would\n * take those props itself and hand the tooltip nothing.\n */\nfunction RedactedTooltipContent(props: ComponentProps<typeof ChartTooltipContent>) {\n return (\n <div data-private>\n <ChartTooltipContent {...props} />\n </div>\n );\n}\n\nconst DEFAULT_NUMBER = new Intl.NumberFormat();\n\n/**\n * Tile chart: one rectangle per {@link TreemapNode}, sized by `value`, coloured by\n * index from the chart ramp (or by the node's own `fill`), labelled in whichever of the\n * kit's two inks measures better against it. Hover shows the name and the formatted\n * value; `onNodeClick` turns the tiles into buttons.\n *\n * Renders nothing when no node has a positive value — an empty box is a hole in the\n * card, and the caller's own sentence is the better answer there.\n *\n * Needs `recharts`, like everything behind `@eifi1/ui-kit/chart`.\n */\nexport function Treemap({\n data,\n valueFormatter,\n height = 320,\n onNodeClick,\n redactNames = false,\n nodeNote,\n maxTiles,\n colors,\n style,\n ...rest\n}: TreemapProps) {\n const tokenHex = useChartTokenHex();\n // Read off the DOM after mount: the `dir` a treemap sits under is an ancestor's\n // attribute, and SVG text anchoring cannot follow it by CSS (see TreemapCell). Again\n // on new data, because a map that had nothing to draw rendered no root to read.\n const rootRef = useRef<HTMLDivElement>(null);\n const [dir, setDir] = useState<Direction>(\"ltr\");\n useLayoutEffect(() => {\n setDir(dirOf(rootRef.current));\n }, [data]);\n const ramp = colors && colors.length > 0 ? colors : tokenHex;\n // Coloured by index into `data` AS GIVEN, before anything is dropped: a caller\n // painting a legend or a second map from the same list must land on the same hue\n // for the same row, and filtering first would shift every colour after a gap.\n const nodes = data\n .map((d, idx) => ({\n id: d.id,\n name: d.name,\n size: d.value,\n fill: d.fill ?? ramp[idx % ramp.length],\n }))\n .filter((n) => Number.isFinite(n.size) && n.size > 0)\n .slice(0, maxTiles ?? undefined);\n if (nodes.length === 0) return null;\n\n // The share is of what is DRAWN, so it always reads as \"of this picture\".\n const total = nodes.reduce((acc, n) => acc + n.size, 0);\n const format = (v: number): ReactNode => {\n const share = total > 0 ? v / total : undefined;\n return valueFormatter ? valueFormatter(v, share) : DEFAULT_NUMBER.format(v);\n };\n const Content = redactNames ? RedactedTooltipContent : ChartTooltipContent;\n return (\n <ChartContainer {...rest} ref={rootRef} config={TREEMAP_CONFIG} style={{ ...style, height }}>\n {/* No chart-level `stroke`: recharts spreads it onto the <svg> root, from where\n it inherits into every label (see TreemapCell). Each cell strokes its own rect. */}\n <RechartsTreemap\n data={nodes}\n dataKey=\"size\"\n fill=\"var(--chart-1)\"\n isAnimationActive={false}\n content={\n <TreemapCell onNodeClick={onNodeClick} redactNames={redactNames} nodeNote={nodeNote} dir={dir} />\n }\n >\n <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TMLAttributes, Ref, SelectHTMLAttributes, ReactNode, InputHTMLAttributes, ComponentPropsWithoutRef, TextareaHTMLAttributes } from 'react';
3
+ import { TooltipSide } from './tooltip.js';
4
+ import '../hooks/use-anchored-rect.js';
3
5
 
4
- type ButtonVariant = "primary" | "secondary" | "ghost" | "danger" | "brand";
6
+ type ButtonVariant = "primary" | "secondary" | "ghost" | "danger" | "brand" | "link";
7
+ type ButtonSize = "sm" | "md";
8
+ /** The second argument of {@link buttonClasses} in its options form. */
9
+ interface ButtonClassesOptions {
10
+ /** See {@link ButtonProps.size}. */
11
+ size?: ButtonSize;
12
+ className?: string;
13
+ }
5
14
  /**
6
15
  * Button classes for the rare case where the styling must land on a non-`<button>`
7
16
  * element that {@link Button} can't render — e.g. a router `<Link>` or a Radix
8
17
  * AlertDialog Action/Cancel (which must stay the Radix element). Everywhere a real
9
- * button works, prefer `<Button>`. Draws from the same base + variant maps as
18
+ * button works, prefer `<Button>`. Draws from the same base, size and variant maps as
10
19
  * `<Button>`, so the two stay in lockstep.
20
+ *
21
+ * The second argument is either the extra classes (the pre-0.8.0 form) or
22
+ * `{ size, className }` — `buttonClasses("secondary", { size: "sm" })` for keksdose's
23
+ * compact toolbar links.
11
24
  */
12
- declare function buttonClasses(variant?: ButtonVariant, className?: string): string;
25
+ declare function buttonClasses(variant?: ButtonVariant, classNameOrOptions?: string | ButtonClassesOptions): string;
13
26
  interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
14
27
  variant?: ButtonVariant;
28
+ /** `md` (default) is the page's action button. `sm` is the compact one — 12px text
29
+ * and `px-2 py-1` — for the secondary actions in a toolbar, a card header or a
30
+ * table's header row (keksdose writes `px-2 py-1 text-xs` over `secondary` by hand
31
+ * there). Every variant takes either size. */
32
+ size?: ButtonSize;
15
33
  /** In a flex row next to a taller labelled field, fill the field's height so the
16
34
  * two line up. No effect outside a flex row. */
17
35
  stretch?: boolean;
@@ -20,23 +38,40 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
20
38
  * declared here only because `ButtonHTMLAttributes` does not carry it. */
21
39
  ref?: Ref<HTMLButtonElement>;
22
40
  }
23
- declare function Button({ variant, stretch, className, ...rest }: ButtonProps): react.JSX.Element;
24
- type IconButtonSize = "md" | "sm" | "xs" | "2xs";
41
+ declare function Button({ variant, size, stretch, className, ...rest }: ButtonProps): react.JSX.Element;
42
+ type IconButtonSize = "lg" | "md" | "sm" | "xs" | "2xs";
25
43
  declare const ICON_BUTTON_TONES: {
26
44
  readonly default: "";
27
45
  readonly muted: "text-[var(--text-placeholder)] hover:bg-[var(--bg-surface-2)] hover:text-[var(--text-primary)]";
28
46
  readonly danger: "text-[var(--text-placeholder)] hover:bg-[var(--danger-bg)] hover:text-[var(--danger)] focus:ring-[var(--danger-border)]";
47
+ readonly warning: "text-[var(--warning)] hover:bg-[var(--warning-bg)] focus:ring-[var(--warning-border)]";
48
+ readonly info: "text-[var(--info)] hover:bg-[var(--info-bg)] focus:ring-[var(--info-border)]";
29
49
  };
30
50
  interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
31
- variant?: ButtonVariant;
32
- /** Box size: md = 36px (matches the top bar), sm = 32px — both with a 20px icon;
51
+ /** Any {@link ButtonVariant}, or `overlay` — a round translucent disc for use over
52
+ * an image (see `ICON_BUTTON_OVERLAY`). */
53
+ variant?: ButtonVariant | "overlay";
54
+ /** Box size: lg = 44px (a phone's touch target), md = 36px (matches the top bar),
55
+ * sm = 32px — all three with a 20px icon;
33
56
  * xs = 28px with a 16px icon (an action in a list row), 2xs = 24px with a 14px
34
57
  * icon (an action on a chip or a tab). */
35
58
  size?: IconButtonSize;
36
59
  /** Glyph colour over the variant. `muted`: placeholder grey, full text colour on
37
60
  * hover. `danger`: the same grey at rest, `--danger` on hover and focus — for a
38
- * remove/delete that repeats down a list. Default: the variant's own colours. */
61
+ * remove/delete that repeats down a list. `warning`: amber at rest — a flag that
62
+ * wants attention. `info`: sky at rest — a notice-worthy but harmless action
63
+ * (keksdose's reconcile). Default: the variant's own colours. */
39
64
  tone?: keyof typeof ICON_BUTTON_TONES;
65
+ /**
66
+ * Make it a toggle button. `true` sets `aria-pressed="true"` and draws the "on" look
67
+ * (brand glyph on the quiet brand fill); `false` sets `aria-pressed="false"` with the
68
+ * normal look, so a screen reader still hears a toggle that is off. Left out, it is
69
+ * an ordinary button with no `aria-pressed` — or whatever `aria-pressed` the caller
70
+ * passes. For keksdose's budget share toggle (budgets-page:291), which paints its own
71
+ * brand colour over a ghost button today. Keep the `aria-label` the same in both
72
+ * states ("Share budget"): the pressed state already says whether it is on.
73
+ */
74
+ pressed?: boolean;
40
75
  /** Keep the click (and the Enter/Space that produces it) from reaching an
41
76
  * ancestor's handler — for an action inside a clickable table row or card.
42
77
  *
@@ -170,7 +205,9 @@ interface FieldHintProps extends Omit<ComponentPropsWithoutRef<"button">, "child
170
205
  /** The explanation. It is both the tooltip's text and, by default, the button's
171
206
  * accessible name, so a screen reader gets it without the bubble ever opening. */
172
207
  label: string;
173
- side?: "left" | "right" | "top" | "bottom";
208
+ /** Default `"start"`: before the hint in the reading direction (the left in LTR, the
209
+ * right in RTL). `left` / `right` stay physical. */
210
+ side?: TooltipSide;
174
211
  }
175
212
  declare function FieldHint({ label, side, className, "aria-label": ariaLabel, ...rest }: FieldHintProps): react.JSX.Element;
176
213
  /**
@@ -298,8 +335,18 @@ interface CardProps extends ComponentPropsWithoutRef<"div"> {
298
335
  * content cards on data pages; leave off for centered dialog/panel cards.
299
336
  */
300
337
  flush?: boolean;
338
+ /**
339
+ * `inset`: a panel INSIDE a card rather than a card on the page — the raised
340
+ * `--bg-surface-2`, a small radius, `p-3` of its own and no border or shadow, since
341
+ * it is already sitting on the card that has them. Lenkbank's results blocks and
342
+ * corner panels write this by hand (`rounded-md bg-surface-2 p-3`) under a Card of
343
+ * their own. Unlike the default card it carries its padding, because every one of
344
+ * those copies wanted the same one; a caller's `p-*` still wins. `flush` is ignored:
345
+ * an inset panel never runs edge to edge.
346
+ */
347
+ variant?: "default" | "inset";
301
348
  }
302
- declare function Card({ className, children, flush, ...rest }: CardProps): react.JSX.Element;
349
+ declare function Card({ className, children, flush, variant, ...rest }: CardProps): react.JSX.Element;
303
350
  /** The sub-parts add nothing to a `<div>`'s props — they are the SAME element with a
304
351
  * `data-slot` and a padding rhythm — so each name is an alias rather than an empty
305
352
  * interface pretending to be more. They exist so a consumer's own wrapper can say
@@ -350,11 +397,22 @@ declare function Spinner({ className, label, ...rest }: SpinnerProps): react.JSX
350
397
  interface EmptyStateProps extends Omit<ComponentPropsWithoutRef<"div">, "children"> {
351
398
  /** The box renders `title` and `hint` in its own two-line rhythm, which is what makes
352
399
  * every empty state in three apps look like the same thing — so there is no
353
- * `children` slot to put arbitrary content in. */
400
+ * `children` slot to put arbitrary content in. The two slots below are the only
401
+ * other things an empty state has turned out to need, and each has a fixed place. */
354
402
  title: string;
355
403
  hint?: string;
404
+ /** A glyph ABOVE the title — kastlan's InboxEmptyState (an inbox), keksdose's
405
+ * offline card (a cloud with a slash). Sized by the box (`[&_svg]:size-8`) and
406
+ * muted, so five call sites cannot pick five sizes; hidden from assistive tech,
407
+ * because the title already says what it shows. */
408
+ icon?: ReactNode;
409
+ /** What to do about it, BELOW the hint: keksdose's query-state cards (Retry), its
410
+ * error boundary (Retry / Reload / Go home — pass all three in a fragment, they
411
+ * wrap and centre as one row), kastlan's "Create a rule". Buttons or links the
412
+ * caller renders; the box only places them. */
413
+ action?: ReactNode;
356
414
  }
357
- declare function EmptyState({ title, hint, className, ...rest }: EmptyStateProps): react.JSX.Element;
415
+ declare function EmptyState({ title, hint, icon, action, className, ...rest }: EmptyStateProps): react.JSX.Element;
358
416
  /** One tab of a {@link Tabs} strip. */
359
417
  interface TabItem<T extends string> {
360
418
  id: T;
@@ -516,7 +574,27 @@ interface TabsProps<T extends string> extends Omit<ComponentPropsWithoutRef<"div
516
574
  /** An add or a remove is in flight: the × and the add button are disabled and
517
575
  * Delete is ignored, so a double click cannot remove two tabs. Nothing moves. */
518
576
  busy?: boolean;
577
+ /**
578
+ * `"vertical"`: the same strip as a SIDE NAV — one item per row, the open one
579
+ * filled, ↑/↓ walking it (Home/End as before) and `aria-orientation="vertical"` on
580
+ * the tablist. For keksdose's admin page and settings page, which each hand-built
581
+ * the identical sidebar with none of this strip's keyboard, roving tab stop or
582
+ * routed-`href` handling. Everything else — `href` tabs, `badge`, `panelId`,
583
+ * `onRemove`, `onAdd` — means exactly what it means on the horizontal strip; the
584
+ * badge moves to the row's end.
585
+ *
586
+ * **On a phone ({@link PHONE_QUERY}) it becomes the horizontal strip**, `wrap` and
587
+ * all, rather than staying a column. A side nav only works beside its content; on
588
+ * a phone it has to go ABOVE it, and eight full-width rows there push the panel
589
+ * the user picked below the fold on every visit — the two keksdose pages both
590
+ * collapsed theirs into a scrolling row by hand for exactly that reason. The
591
+ * orientation is switched in JavaScript, not with `md:` classes, so the
592
+ * `aria-orientation` a screen reader hears and the arrow keys that work always
593
+ * match the layout on screen. The caller's own two-column layout has to stack at
594
+ * the same breakpoint (`md:grid-cols-[14rem_1fr]`).
595
+ */
596
+ orientation?: "horizontal" | "vertical";
519
597
  }
520
- declare function Tabs<T extends string>({ tabs, active, onChange, className, wrap, label, panelId, onRemove, removeOn, onAdd, addLabel, labels, busy, "aria-label": ariaLabel, ...rest }: TabsProps<T>): react.JSX.Element;
598
+ declare function Tabs<T extends string>({ tabs, active, onChange, className, wrap, label, panelId, onRemove, removeOn, onAdd, addLabel, labels, busy, orientation, "aria-label": ariaLabel, ...rest }: TabsProps<T>): react.JSX.Element;
521
599
 
522
- export { Button, type ButtonProps, type ButtonVariant, Card, CardAction, type CardActionProps, CardContent, type CardContentProps, CardDescription, type CardDescriptionProps, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, type CardTitleProps, DEFAULT_PASSWORD_REVEAL_LABELS, DEFAULT_TABS_LABELS, EmptyState, type EmptyStateProps, FIELD_BASE, FIELD_DISPLAY, FIELD_FLOATING_PAD, FIELD_INVALID, FIELD_TRIGGER, FIELD_WRITABLE_LOOK, FLOATING_INPUT_CLASS, FLOATING_LABEL_CLASS, FLOATING_LABEL_STATIC, FieldChevron, type FieldChevronProps, FieldHint, type FieldHintProps, FieldLabel, type FieldLabelProps, FloatingField, type FloatingFieldProps, IconButton, type IconButtonProps, type IconButtonSize, Input, type InputProps, Label, type LabelProps, PHONE_QUERY, type PasswordRevealLabels, Select, type SelectProps, Spinner, type SpinnerProps, type TabItem, Tabs, type TabsLabels, type TabsProps, Textarea, type TextareaProps, buttonClasses, resolvePasswordRevealLabels };
600
+ export { Button, type ButtonClassesOptions, type ButtonProps, type ButtonSize, type ButtonVariant, Card, CardAction, type CardActionProps, CardContent, type CardContentProps, CardDescription, type CardDescriptionProps, CardFooter, type CardFooterProps, CardHeader, type CardHeaderProps, type CardProps, CardTitle, type CardTitleProps, DEFAULT_PASSWORD_REVEAL_LABELS, DEFAULT_TABS_LABELS, EmptyState, type EmptyStateProps, FIELD_BASE, FIELD_DISPLAY, FIELD_FLOATING_PAD, FIELD_INVALID, FIELD_TRIGGER, FIELD_WRITABLE_LOOK, FLOATING_INPUT_CLASS, FLOATING_LABEL_CLASS, FLOATING_LABEL_STATIC, FieldChevron, type FieldChevronProps, FieldHint, type FieldHintProps, FieldLabel, type FieldLabelProps, FloatingField, type FloatingFieldProps, IconButton, type IconButtonProps, type IconButtonSize, Input, type InputProps, Label, type LabelProps, PHONE_QUERY, type PasswordRevealLabels, Select, type SelectProps, Spinner, type SpinnerProps, type TabItem, Tabs, type TabsLabels, type TabsProps, Textarea, type TextareaProps, buttonClasses, resolvePasswordRevealLabels };