@eifi1/ui-kit 0.12.0 → 0.13.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 (197) hide show
  1. package/README.md +10 -10
  2. package/dist/components/amount-input.d.ts +17 -1
  3. package/dist/components/amount-input.js +46 -11
  4. package/dist/components/amount-input.js.map +1 -1
  5. package/dist/components/bulk-action-bar.d.ts +10 -2
  6. package/dist/components/bulk-action-bar.js.map +1 -1
  7. package/dist/components/button-group.d.ts +1 -1
  8. package/dist/components/calculator.d.ts +1 -1
  9. package/dist/components/chart.js +14 -8
  10. package/dist/components/chart.js.map +1 -1
  11. package/dist/components/chip.js +20 -15
  12. package/dist/components/chip.js.map +1 -1
  13. package/dist/components/combobox-core.d.ts +3 -1
  14. package/dist/components/combobox-core.js +16 -5
  15. package/dist/components/combobox-core.js.map +1 -1
  16. package/dist/components/combobox.js.map +1 -1
  17. package/dist/components/copy-button.d.ts +1 -1
  18. package/dist/components/data-table-filter-popover.js +8 -1
  19. package/dist/components/data-table-filter-popover.js.map +1 -1
  20. package/dist/components/data-table.js +28 -20
  21. package/dist/components/data-table.js.map +1 -1
  22. package/dist/components/entity-combobox.js +22 -17
  23. package/dist/components/entity-combobox.js.map +1 -1
  24. package/dist/components/error-boundary.d.ts +202 -13
  25. package/dist/components/error-boundary.js +211 -20
  26. package/dist/components/error-boundary.js.map +1 -1
  27. package/dist/components/field-sync.js +90 -83
  28. package/dist/components/field-sync.js.map +1 -1
  29. package/dist/components/file-button.d.ts +1 -1
  30. package/dist/components/file-dropzone.d.ts +1 -1
  31. package/dist/components/form-actions.d.ts +1 -1
  32. package/dist/components/full-bleed-dialog.js +4 -0
  33. package/dist/components/full-bleed-dialog.js.map +1 -1
  34. package/dist/components/hover-menu.js +64 -56
  35. package/dist/components/hover-menu.js.map +1 -1
  36. package/dist/components/list.d.ts +14 -2
  37. package/dist/components/list.js +3 -1
  38. package/dist/components/list.js.map +1 -1
  39. package/dist/components/modal.js.map +1 -1
  40. package/dist/components/multi-entity-combobox.js +23 -17
  41. package/dist/components/multi-entity-combobox.js.map +1 -1
  42. package/dist/components/number-field.d.ts +1 -1
  43. package/dist/components/number-input.d.ts +1 -1
  44. package/dist/components/number-input.js.map +1 -1
  45. package/dist/components/numpad-sheet.d.ts +6 -2
  46. package/dist/components/numpad-sheet.js +3 -2
  47. package/dist/components/numpad-sheet.js.map +1 -1
  48. package/dist/components/page-header.d.ts +35 -6
  49. package/dist/components/page-header.js +7 -1
  50. package/dist/components/page-header.js.map +1 -1
  51. package/dist/components/picker-sheet.js +3 -0
  52. package/dist/components/picker-sheet.js.map +1 -1
  53. package/dist/components/popover.js +3 -0
  54. package/dist/components/popover.js.map +1 -1
  55. package/dist/components/settings-fields.d.ts +1 -1
  56. package/dist/components/signed-amount.d.ts +2 -1
  57. package/dist/components/signed-amount.js +1 -1
  58. package/dist/components/signed-amount.js.map +1 -1
  59. package/dist/components/stat-tile.js +1 -1
  60. package/dist/components/stat-tile.js.map +1 -1
  61. package/dist/components/swipeable-row.js +4 -3
  62. package/dist/components/swipeable-row.js.map +1 -1
  63. package/dist/components/text-link.d.ts +73 -11
  64. package/dist/components/text-link.js +45 -10
  65. package/dist/components/text-link.js.map +1 -1
  66. package/dist/components/text.d.ts +26 -2
  67. package/dist/components/text.js +16 -2
  68. package/dist/components/text.js.map +1 -1
  69. package/dist/components/time-input.d.ts +1 -1
  70. package/dist/components/toggle-group.d.ts +22 -0
  71. package/dist/components/toggle-group.js +8 -8
  72. package/dist/components/toggle-group.js.map +1 -1
  73. package/dist/components/toggle-legend.d.ts +17 -0
  74. package/dist/components/toggle-legend.js +6 -2
  75. package/dist/components/toggle-legend.js.map +1 -1
  76. package/dist/components/tooltip.d.ts +51 -1
  77. package/dist/components/tooltip.js +59 -35
  78. package/dist/components/tooltip.js.map +1 -1
  79. package/dist/components/ui.d.ts +1 -1
  80. package/dist/components/ui.js +166 -28
  81. package/dist/components/ui.js.map +1 -1
  82. package/dist/feedback/feedback-attachment.js +4 -6
  83. package/dist/feedback/feedback-attachment.js.map +1 -1
  84. package/dist/feedback/feedback-dialog.js +5 -3
  85. package/dist/feedback/feedback-dialog.js.map +1 -1
  86. package/dist/feedback/feedback-inbox.js +86 -75
  87. package/dist/feedback/feedback-inbox.js.map +1 -1
  88. package/dist/feedback/feedback-thread.d.ts +43 -3
  89. package/dist/feedback/feedback-thread.js +53 -26
  90. package/dist/feedback/feedback-thread.js.map +1 -1
  91. package/dist/feedback.d.ts +1 -1
  92. package/dist/hooks/use-file-drop.d.ts +1 -1
  93. package/dist/i18n/defaults.d.ts +1 -1
  94. package/dist/i18n/kit-labels.d.ts +1 -1
  95. package/dist/i18n/kit-labels.js.map +1 -1
  96. package/dist/i18n/locales/de-CH-informal.d.ts +1 -1
  97. package/dist/i18n/locales/de-CH.d.ts +1 -1
  98. package/dist/i18n/locales/de-informal.d.ts +1 -1
  99. package/dist/i18n/locales/de.d.ts +1 -1
  100. package/dist/i18n/locales/de.js +9 -1
  101. package/dist/i18n/locales/de.js.map +1 -1
  102. package/dist/i18n/locales/es.d.ts +1 -1
  103. package/dist/i18n/locales/es.js +9 -1
  104. package/dist/i18n/locales/es.js.map +1 -1
  105. package/dist/i18n/locales/fr.d.ts +1 -1
  106. package/dist/i18n/locales/fr.js +9 -1
  107. package/dist/i18n/locales/fr.js.map +1 -1
  108. package/dist/i18n/locales/hu.d.ts +1 -1
  109. package/dist/i18n/locales/hu.js +9 -1
  110. package/dist/i18n/locales/hu.js.map +1 -1
  111. package/dist/i18n/locales/it.d.ts +1 -1
  112. package/dist/i18n/locales/it.js +9 -1
  113. package/dist/i18n/locales/it.js.map +1 -1
  114. package/dist/i18n/locales/zh.d.ts +1 -1
  115. package/dist/i18n/locales/zh.js +9 -1
  116. package/dist/i18n/locales/zh.js.map +1 -1
  117. package/dist/index.d.ts +6 -6
  118. package/dist/{kit-labels-v3biUF1L.d.ts → kit-labels-Mz8zZHIF.d.ts} +102 -3
  119. package/dist/lib/format.d.ts +23 -5
  120. package/dist/lib/format.js +3 -1
  121. package/dist/lib/format.js.map +1 -1
  122. package/dist/rhf/fields.d.ts +57 -15
  123. package/dist/rhf/fields.js +41 -11
  124. package/dist/rhf/fields.js.map +1 -1
  125. package/dist/rhf/form.d.ts +1 -1
  126. package/dist/rhf.d.ts +2 -2
  127. package/dist/rhf.js.map +1 -1
  128. package/dist/search/command-palette.js +20 -14
  129. package/dist/search/command-palette.js.map +1 -1
  130. package/dist/shell/app-shell.d.ts +1 -1
  131. package/dist/shell/app-shell.js +62 -54
  132. package/dist/shell/app-shell.js.map +1 -1
  133. package/dist/shell/top-bar-brand.d.ts +1 -1
  134. package/dist/shell/topbar-action-menu.d.ts +9 -3
  135. package/dist/shell/topbar-action-menu.js +2 -1
  136. package/dist/shell/topbar-action-menu.js.map +1 -1
  137. package/dist/shell.d.ts +1 -1
  138. package/dist/tour/tour.js +10 -4
  139. package/dist/tour/tour.js.map +1 -1
  140. package/dist/wizard/stepper-nav.d.ts +1 -1
  141. package/dist/wizard/use-wizard.js +4 -2
  142. package/dist/wizard/use-wizard.js.map +1 -1
  143. package/dist/wizard/wizard-step.d.ts +11 -1
  144. package/dist/wizard/wizard-step.js +24 -6
  145. package/dist/wizard/wizard-step.js.map +1 -1
  146. package/dist/wizard.d.ts +1 -1
  147. package/package.json +6 -6
  148. package/src/components/amount-input.tsx +97 -10
  149. package/src/components/bulk-action-bar.tsx +16 -3
  150. package/src/components/chart.tsx +19 -8
  151. package/src/components/chip.tsx +6 -0
  152. package/src/components/combobox-core.tsx +28 -9
  153. package/src/components/combobox.tsx +2 -0
  154. package/src/components/data-table-filter-popover.tsx +13 -5
  155. package/src/components/data-table.tsx +6 -0
  156. package/src/components/entity-combobox.tsx +7 -4
  157. package/src/components/error-boundary.tsx +453 -29
  158. package/src/components/field-sync.tsx +48 -40
  159. package/src/components/full-bleed-dialog.tsx +4 -0
  160. package/src/components/hover-menu.tsx +26 -17
  161. package/src/components/list.tsx +17 -3
  162. package/src/components/modal.tsx +4 -0
  163. package/src/components/multi-entity-combobox.tsx +8 -4
  164. package/src/components/number-input.tsx +1 -0
  165. package/src/components/numpad-sheet.tsx +6 -1
  166. package/src/components/page-header.tsx +42 -5
  167. package/src/components/picker-sheet.tsx +3 -0
  168. package/src/components/popover.tsx +3 -0
  169. package/src/components/signed-amount.tsx +12 -3
  170. package/src/components/stat-tile.tsx +3 -1
  171. package/src/components/swipeable-row.tsx +7 -7
  172. package/src/components/text-link.tsx +126 -18
  173. package/src/components/text.tsx +46 -2
  174. package/src/components/toggle-group.tsx +35 -10
  175. package/src/components/toggle-legend.tsx +22 -1
  176. package/src/components/tooltip.tsx +79 -8
  177. package/src/components/ui.tsx +307 -39
  178. package/src/feedback/feedback-attachment.tsx +10 -7
  179. package/src/feedback/feedback-dialog.tsx +7 -4
  180. package/src/feedback/feedback-inbox.tsx +7 -0
  181. package/src/feedback/feedback-thread.tsx +109 -33
  182. package/src/i18n/kit-labels.tsx +16 -0
  183. package/src/i18n/locales/de.ts +8 -0
  184. package/src/i18n/locales/es.ts +8 -0
  185. package/src/i18n/locales/fr.ts +8 -0
  186. package/src/i18n/locales/hu.ts +8 -0
  187. package/src/i18n/locales/it.ts +8 -0
  188. package/src/i18n/locales/zh.ts +8 -0
  189. package/src/lib/format.ts +29 -6
  190. package/src/rhf/fields.tsx +97 -16
  191. package/src/rhf.ts +1 -1
  192. package/src/search/command-palette.tsx +29 -19
  193. package/src/shell/app-shell.tsx +6 -1
  194. package/src/shell/topbar-action-menu.tsx +11 -4
  195. package/src/tour/tour.tsx +16 -5
  196. package/src/wizard/use-wizard.ts +8 -4
  197. package/src/wizard/wizard-step.tsx +38 -6
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/stat-tile.tsx"],"sourcesContent":["import { isValidElement, useId, useLayoutEffect, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, CSSProperties, ReactElement, ReactNode } from \"react\";\nimport { ArrowDown, ArrowUp, Minus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels, useKitLink, useKitLocale } from \"../i18n/kit-labels\";\nimport { pickLinkRenderer, RenderedKitLink } from \"./text-link\";\nimport { Card, FieldHint } from \"./ui\";\nimport { Sparkline } from \"./sparkline\";\nimport { Tooltip } from \"./tooltip\";\n// The kit's one placeholder look, so a loading tile and the Skeleton list beside it\n// shimmer as one surface — and both stop under `prefers-reduced-motion`, which this\n// tile's private copy of the string did not.\nimport { SKELETON_CLASS } from \"./skeleton\";\n\n/**\n * The words a stat tile speaks. The delta's arrow is an icon, and an icon is not a\n * sentence: a screen reader gets the direction (and, under `goodDirection`, the\n * verdict) as words, and a sighted reader who cannot tell the two delta colours apart\n * still has the arrow — neither judgement rides on colour alone.\n */\nexport interface StatTileLabels {\n /** The delta, rising. `amount` is already formatted and unsigned. */\n increase: (amount: string) => string;\n decrease: (amount: string) => string;\n unchanged: string;\n /** Wraps the direction sentence when `goodDirection` says the change is good. */\n better: (change: string) => string;\n worse: (change: string) => string;\n /** Spoken in place of a missing value (the tile shows a dash). */\n noValue: string;\n /** Spoken while `loading`. */\n loading: string;\n}\n\nexport const DEFAULT_STAT_TILE_LABELS: StatTileLabels = {\n increase: (amount) => `Up ${amount}`,\n decrease: (amount) => `Down ${amount}`,\n unchanged: \"No change\",\n better: (change) => `${change} (better)`,\n worse: (change) => `${change} (worse)`,\n noValue: \"No data\",\n loading: \"Loading…\",\n};\n\n/**\n * What colours a figure. Token-backed like everything else in the kit.\n *\n * - `income` / `expense` / `net` — the money trio (teal / amber / violet, CVD-safe).\n * - `signed` — a money figure read by its own sign: above zero `income`, below zero\n * `expense`, exactly zero neutral (a zero balance is neither news). Needs a NUMBER\n * value; a pre-formatted string cannot be read and stays neutral.\n * - `success` / `warning` / `danger` / `info` — a threshold verdict (\"phase margin\n * below 30°\"). Say it in the hint or description as well; colour alone is not one.\n */\nexport type StatTileTone =\n | \"neutral\"\n | \"brand\"\n | \"income\"\n | \"expense\"\n | \"net\"\n | \"signed\"\n | \"success\"\n | \"warning\"\n | \"danger\"\n | \"info\";\n\nconst TONE_CLASS: Record<Exclude<StatTileTone, \"signed\">, string> = {\n neutral: \"text-[var(--text-primary)]\",\n brand: \"text-[var(--brand)]\",\n income: \"text-[var(--money-income)]\",\n expense: \"text-[var(--money-expense)]\",\n net: \"text-[var(--money-net)]\",\n success: \"text-[var(--success)]\",\n warning: \"text-[var(--warning)]\",\n danger: \"text-[var(--danger)]\",\n info: \"text-[var(--info)]\",\n};\n\nfunction toneClass(tone: StatTileTone, value: unknown): string {\n if (tone !== \"signed\") return TONE_CLASS[tone];\n if (typeof value !== \"number\" || value === 0) return TONE_CLASS.neutral;\n return value < 0 ? TONE_CLASS.expense : TONE_CLASS.income;\n}\n\n/** A change since the previous period. A bare number is shorthand for `{ value }`. */\nexport interface StatTileDelta {\n /** Signed: above zero is \"up\". */\n value: number;\n /** `\"value\"` (default) formats it like the headline — same currency, same\n * notation. `\"percent\"` reads it as a RATIO: `0.12` is shown as 12 %. */\n unit?: \"value\" | \"percent\";\n /** What it is measured against, shown after it: \"vs last month\". */\n label?: ReactNode;\n}\n\n/** A smaller figure under the headline — a prior period, a projection, a split. */\nexport interface StatTileSubValue {\n label: ReactNode;\n /** A number is formatted like the headline; anything else is rendered as given. */\n value: ReactNode;\n /** Defaults to the tile's own `tone`, read per figure (so a `signed` tile shows a\n * teal September above an amber August). Sub-values are always the muted weight\n * of their tone: they are history, and must not outshout the figure above them.\n *\n * `\"none\"` leaves the figure untinted — the row's own muted text, like its label —\n * even on a toned tile: keksdose's report KpiCard (reports/charts/kpi-card.tsx),\n * whose `negative` convention tints only a figure below zero and leaves the rest\n * plain. (`\"neutral\"` is not that: it is the headline's full text colour, at the\n * sub-value's 75 %.) */\n tone?: StatTileTone | \"none\";\n}\n\n/** What {@link StatTileProps.renderLink} is handed. Spread it onto your router's\n * link: the class is what stretches the link over the whole tile. */\nexport interface StatTileLinkProps {\n href: string;\n className: string;\n \"aria-describedby\": string;\n children: ReactNode;\n}\n\nexport interface StatTileProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\" | \"onClick\"> {\n /** What is measured. Also the tile's accessible name when it is a link/button. */\n label: ReactNode;\n /**\n * The headline. A number is formatted with `Intl.NumberFormat` in the kit's locale\n * (see `currency`, `compact`, `numberFormat`, `format`); a string or element is\n * rendered as given. `null`/`undefined` shows a dash and says \"No data\".\n */\n value?: ReactNode;\n /** ISO 4217 code — formats a number value (and a `\"value\"` delta, and numeric\n * sub-values) as money. */\n currency?: string;\n /** Compact notation: 12 400 → \"12K\". */\n compact?: boolean;\n /** Any further `Intl.NumberFormat` options, merged over the two above. */\n numberFormat?: Intl.NumberFormatOptions;\n /** Formats every NUMBER the tile shows, replacing the `Intl` default outright. */\n format?: (value: number) => string;\n locale?: string;\n /** A short unit after the value that `Intl` has no name for: \"ms\", \"dB\", \"Hz\". */\n unit?: ReactNode;\n /** The period the headline belongs to, shown to its left (\"SEP\"). */\n valueLabel?: ReactNode;\n tone?: StatTileTone;\n delta?: number | StatTileDelta;\n /** Which way is good news. Unset, the delta is stated and not judged (users up and\n * cost up are the same arrow); set, it is coloured and its sentence says so. */\n goodDirection?: \"up\" | \"down\";\n /** The explanation behind a \"?\" beside the label (a {@link FieldHint}) — hidden\n * until asked for, so it is for what a reader MIGHT want to know (\"excludes\n * transfers between your own accounts\"). For a line everyone should read, use\n * {@link StatTileProps.description} instead. */\n hint?: string;\n /**\n * Keep the label to ONE line, cut with an ellipsis, and show the whole of it in a\n * {@link Tooltip} on hover and focus — but only while it is actually cut, so a\n * label that fits shows no bubble repeating itself. keksdose's admin MetricTile\n * wall: twenty tiles whose German labels (\"Aktive Abonnements (30 Tage)\") wrapped\n * onto two or three lines and pushed each tile's figure to a different height.\n *\n * The label element keeps the FULL text — the ellipsis is paint — so it is still\n * the tile's accessible name (and the stretched link's, on a link tile) exactly as\n * without this. Off by default: a wrapping label is what every existing tile does,\n * and a tile standing alone has room to.\n *\n * This is the tooltip: pass the label as a plain STRING rather than wrapping it in\n * your own `<Tooltip>` for the full text (keksdose's admin metrics-panel.tsx:134\n * does, from before this prop). A wrapped label shows a bubble even when nothing is\n * cut, and nests its trigger inside this one's.\n */\n truncateLabel?: boolean;\n /**\n * The tile's name as plain text, for the places that need a string rather than a\n * node — today the {@link StatTileProps.trend} sparkline's accessible name. Only\n * needed when `label` is not a string AND its text cannot be read from it: a label\n * element's text children are found on their own (a `<Tooltip label=\"…\">Spend\n * </Tooltip>` label still names its sparkline \"Spend\"), an icon or a formatted\n * message component's are not.\n */\n name?: string;\n /** A visible line under the value: \"Last 12 months\", \"3 estates / 9 buildings\" —\n * always shown, so it is for what every reader needs. An explanation only some\n * will want belongs in {@link StatTileProps.hint}, the \"?\" beside the label. */\n description?: ReactNode;\n /**\n * One figure that belongs WITH the headline rather than under it: keksdose's\n * \"Projected €1,850\" under a to-date \"€420\" (KpiCard, feedback #51), which it\n * currently smuggles into `description` with hand-set margins so the prior-month\n * sub-values do not come between the two. It is drawn directly under the value\n * (before the delta, the description and the sparkline) as a sub-value row, with\n * only a hair of space above it.\n *\n * A slot of its own rather than a placement switch for `subValues`: the history\n * rows (last month, last year) should stay at the bottom where they are, and moving\n * the whole list up to bring one row with it would put them between the headline\n * and its delta. Same shape as a sub-value, so the `tone` rules are the same.\n * Withheld while `loading`, like the sub-values.\n */\n projection?: StatTileSubValue;\n subValues?: StatTileSubValue[];\n /** Shorthand for a fluid {@link Sparkline} named after the tile and speaking in\n * the tile's number format. The name is the label's text; see\n * {@link StatTileProps.name} for a label that has none. */\n trend?: ReadonlyArray<number | null | undefined>;\n /** A custom sparkline (or any small graphic) in the same place. Wins over `trend`. */\n sparkline?: ReactNode;\n /** A decorative icon at the top end of the tile. */\n icon?: ReactNode;\n /** Anything below the rest — a progress bar, a link row. */\n footer?: ReactNode;\n /** Tag every figure `data-private`, so the host's demo-mode rule blurs it — the\n * same attribute `Tooltip redact` and the chart tooltip's value cell carry. */\n sensitive?: boolean;\n /** Skeleton in place of the value; delta, sub-values and trend are withheld. */\n loading?: boolean;\n /** `\"sm\"` for dense grids (a metrics wall); `\"md\"` the default KPI. */\n size?: \"sm\" | \"md\";\n /** Makes the tile a link. See {@link renderLink} for a router. */\n href?: string;\n /** Renders the link for `href` — pass your router's `<Link>` here, since a plain\n * `<a>` reloads a single-page app. Default: the `<UiKitProvider linkComponent>`\n * (for an in-app `href`), then `<a>`. */\n renderLink?: (props: StatTileLinkProps) => ReactElement;\n /** Makes the tile a button (ignored when `href` is given). */\n onClick?: () => void;\n labels?: Partial<StatTileLabels>;\n}\n\n// One formatter per option set: a metrics wall is twenty of these.\nconst formatters = new Map<string, Intl.NumberFormat>();\nfunction numberFormatter(locale: string | undefined, options: Intl.NumberFormatOptions): Intl.NumberFormat {\n const key = `${locale ?? \"\"}|${JSON.stringify(options)}`;\n let f = formatters.get(key);\n if (!f) {\n f = new Intl.NumberFormat(locale, options);\n formatters.set(key, f);\n }\n return f;\n}\n\n// The headline sizes are keyed on the TILE's width (it is a @container), not the\n// viewport: a grid beside a sidebar makes tiles narrowest exactly where a viewport\n// breakpoint would hand them the larger font. `sm` is keksdose's compact headline,\n// sized so a worst-case \"CHF 123,456.78\" still fits a 320px phone's 2-up tiles.\nconst VALUE_TEXT = {\n md: \"text-xl @[13rem]:text-2xl\",\n sm: \"text-xs @[8.5rem]:text-sm @[13rem]:text-base\",\n} as const;\nconst PADDING = { md: \"p-3 sm:p-4\", sm: \"px-2.5 py-2\" } as const;\n\n/**\n * The KPI card: a label, one number, and optionally how it moved, what it is made of\n * and which way it has been going.\n *\n * Replaces keksdose's `KpiCard` and admin `Tile`, lenkbank's metrics tiles and\n * kastlan's `KpiCard` — the same card four times, with four answers to the same\n * questions (how a currency is formatted, whether a delta is judged, what happens to\n * the figures in demo mode).\n *\n * Interactive tiles use a STRETCHED link: the label is the `<a>`/`<button>`, and its\n * `::after` covers the card. Making the card itself the link would nest the hint's\n * `<button>` inside it, which is invalid HTML and an unreachable control; this way\n * the hint sits above the overlay and stays its own tab stop. The link's name is the\n * label, and it is described by the value and the delta.\n */\nexport function StatTile({\n label,\n value,\n currency,\n compact = false,\n numberFormat,\n format,\n locale,\n unit,\n valueLabel,\n tone = \"neutral\",\n delta,\n goodDirection,\n hint,\n truncateLabel = false,\n name,\n description,\n projection,\n subValues,\n trend,\n sparkline,\n icon,\n footer,\n sensitive = false,\n loading = false,\n size = \"md\",\n href,\n renderLink,\n onClick,\n labels,\n className,\n ...rest\n}: StatTileProps) {\n const text = useKitLabels(\"statTile\", DEFAULT_STAT_TILE_LABELS, labels);\n const kitLink = useKitLink();\n const [labelEl, setLabelEl] = useState<HTMLElement | null>(null);\n const labelCut = useIsTruncated(truncateLabel ? labelEl : null);\n const kitLocale = useKitLocale(locale);\n const id = useId();\n const valueId = `${id}-value`;\n const deltaId = `${id}-delta`;\n const priv = sensitive ? \"\" : undefined;\n\n const fmt =\n format ??\n ((n: number) =>\n numberFormatter(kitLocale, {\n ...(currency ? { style: \"currency\", currency } : null),\n ...(compact ? { notation: \"compact\" } : null),\n ...numberFormat,\n }).format(n));\n const show = (v: ReactNode) => (typeof v === \"number\" ? fmt(v) : v);\n\n const d = typeof delta === \"number\" ? { value: delta } : delta;\n const hasValue = value !== null && value !== undefined && value !== \"\";\n const labelText = name ?? plainText(label);\n\n // ── The label, which is also the link/button when the tile is interactive ──\n const stretched = cn(\n \"text-start uppercase tracking-wide\",\n \"after:absolute after:inset-0 after:rounded-lg after:content-['']\",\n \"focus-visible:outline-none focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-[var(--brand)]\",\n );\n const describedBy = d ? `${valueId} ${deltaId}` : valueId;\n let labelNode: ReactNode = label;\n if (href !== undefined) {\n const linkProps: StatTileLinkProps = {\n href,\n className: stretched,\n \"aria-describedby\": describedBy,\n children: label,\n };\n const kit = pickLinkRenderer<StatTileLinkProps>(undefined, kitLink, href);\n labelNode = renderLink ? (\n renderLink(linkProps)\n ) : kit ? (\n <RenderedKitLink render={kit} props={linkProps} />\n ) : (\n <a href={href} className={stretched} aria-describedby={describedBy}>\n {label}\n </a>\n );\n } else if (onClick) {\n labelNode = (\n <button type=\"button\" onClick={onClick} aria-describedby={describedBy} className={stretched}>\n {label}\n </button>\n );\n }\n const interactive = href !== undefined || onClick !== undefined;\n\n // ── Delta ──\n let deltaNode: ReactNode = null;\n if (d && !loading && Number.isFinite(d.value)) {\n const magnitude = Math.abs(d.value);\n const amount =\n d.unit === \"percent\"\n ? numberFormatter(kitLocale, { style: \"percent\", maximumFractionDigits: 1 }).format(magnitude)\n : fmt(magnitude);\n const dir = d.value > 0 ? \"up\" : d.value < 0 ? \"down\" : \"flat\";\n const Icon = dir === \"up\" ? ArrowUp : dir === \"down\" ? ArrowDown : Minus;\n let spoken = dir === \"up\" ? text.increase(amount) : dir === \"down\" ? text.decrease(amount) : text.unchanged;\n let deltaTone = \"text-[var(--text-muted)]\";\n if (goodDirection && dir !== \"flat\") {\n const good = dir === goodDirection;\n spoken = good ? text.better(spoken) : text.worse(spoken);\n deltaTone = good ? \"text-[var(--success)]\" : \"text-[var(--danger)]\";\n }\n deltaNode = (\n // `relative`: the containing block for the sr-only sentence (see the\n // sr-only-containment test for what an escaped one does to the page).\n <div className=\"relative mt-1 flex flex-wrap items-center gap-x-1.5 text-xs tabular-nums\">\n <span id={deltaId} data-private={priv} className={cn(\"inline-flex items-center gap-0.5 font-medium\", deltaTone)}>\n <Icon className=\"size-3 shrink-0\" aria-hidden />\n <span aria-hidden>{dir === \"flat\" ? null : amount}</span>\n <span className=\"sr-only\">{spoken}</span>\n </span>\n {d.label != null && <span className=\"text-[var(--text-muted)]\">{d.label}</span>}\n </div>\n );\n }\n\n // ── Headline ──\n const valueClass = cn(\n \"whitespace-nowrap font-semibold tabular-nums\",\n VALUE_TEXT[size],\n toneClass(tone, value),\n );\n const headline = loading ? (\n <span id={valueId} className=\"relative block py-0.5\">\n <span aria-hidden className={cn(SKELETON_CLASS, \"block h-6 w-24 max-w-full\")} />\n <span className=\"sr-only\">{text.loading}</span>\n </span>\n ) : hasValue ? (\n <span id={valueId} data-private={priv} className={cn(valueClass, valueLabel != null && \"ms-auto\")}>\n {show(value)}\n {unit != null && (\n <span className=\"ms-1 text-[0.7em] font-medium text-[var(--text-muted)]\">{unit}</span>\n )}\n </span>\n ) : (\n <span id={valueId} className={cn(\"relative\", valueClass, \"text-[var(--text-muted)]\")}>\n <span aria-hidden>—</span>\n <span className=\"sr-only\">{text.noValue}</span>\n </span>\n );\n\n const graphic =\n loading ? null : sparkline ??\n (trend && (\n <Sparkline\n data={trend}\n fluid\n height={size === \"sm\" ? 20 : 28}\n label={labelText}\n formatValue={fmt}\n locale={kitLocale}\n tone={tone === \"signed\" ? \"signed\" : tone === \"neutral\" ? \"chart\" : tone}\n data-private={priv}\n />\n ));\n\n return (\n <Card\n {...rest}\n aria-busy={loading || undefined}\n className={cn(\n // @container: the headline sizes read the tile's width. relative: the stretched\n // link's overlay. overflow-hidden: at pathological widths a figure clips inside\n // the border instead of painting over the neighbouring tile.\n \"@container relative flex min-w-0 flex-col overflow-hidden\",\n PADDING[size],\n interactive && \"transition-colors hover:border-[var(--border-strong)] hover:bg-[var(--bg-hover)]\",\n className,\n )}\n >\n <div className=\"flex items-start gap-2\">\n <div className=\"flex min-w-0 flex-1 items-center gap-1 break-words text-xs uppercase tracking-wide text-[var(--text-muted)]\">\n {truncateLabel && labelCut ? (\n // Portalled: the tile is `overflow-hidden`, and a bubble inside it would be\n // clipped by the very box whose edge cut the label.\n <Tooltip label={label} side=\"top\" portal className=\"flex min-w-0\">\n <span ref={setLabelEl} className=\"block min-w-0 truncate\">\n {labelNode}\n </span>\n </Tooltip>\n ) : (\n <span ref={setLabelEl} className={cn(\"min-w-0\", truncateLabel && \"block truncate\")}>\n {labelNode}\n </span>\n )}\n {/* Above the stretched link's overlay, so it stays hoverable and focusable. */}\n {hint && <FieldHint label={hint} side=\"top\" className=\"relative z-10 shrink-0\" />}\n </div>\n {icon != null && (\n <span aria-hidden className=\"shrink-0 text-[var(--text-muted)] [&_svg]:size-4\">\n {icon}\n </span>\n )}\n </div>\n\n {valueLabel != null ? (\n // Period-left / value-right, matching the sub-rows below it. flex-wrap lets a\n // too-long amount drop to its own end-aligned line instead of overflowing.\n <div className=\"mt-1 flex flex-wrap items-baseline gap-x-1.5\">\n <span className=\"shrink-0 text-xs uppercase tracking-wide text-[var(--text-muted)]\">{valueLabel}</span>\n {headline}\n </div>\n ) : (\n <div className=\"mt-1\">{headline}</div>\n )}\n\n {!loading && projection && (\n <dl className=\"mt-0.5\">\n <FigureRow figure={projection} tileTone={tone} show={show} priv={priv} />\n </dl>\n )}\n\n {deltaNode}\n {description != null && <div className=\"mt-1 text-xs text-[var(--text-muted)]\">{description}</div>}\n {graphic && <div className=\"mt-2\">{graphic}</div>}\n\n {!loading && subValues && subValues.length > 0 && (\n <dl className=\"mt-1.5 space-y-0.5\">\n {subValues.map((sv, i) => (\n <FigureRow key={i} figure={sv} tileTone={tone} show={show} priv={priv} />\n ))}\n </dl>\n )}\n\n {footer != null && <div className=\"mt-2\">{footer}</div>}\n </Card>\n );\n}\n\n/** One label/value row of a `<dl>`: a sub-value, or the projection. */\nfunction FigureRow({\n figure,\n tileTone,\n show,\n priv,\n}: {\n figure: StatTileSubValue;\n tileTone: StatTileTone;\n show: (v: ReactNode) => ReactNode;\n priv: \"\" | undefined;\n}) {\n const own = figure.tone ?? (tileTone === \"neutral\" ? undefined : tileTone);\n const svTone = own === \"none\" ? undefined : own;\n return (\n <div className=\"flex flex-wrap items-baseline gap-x-2 text-xs tabular-nums text-[var(--text-muted)]\">\n <dt className=\"uppercase tracking-wide\">{figure.label}</dt>\n <dd\n data-private={priv}\n className={cn(\"ms-auto whitespace-nowrap\", svTone && [toneClass(svTone, figure.value), \"opacity-75\"])}\n >\n {show(figure.value)}\n </dd>\n </div>\n );\n}\n\n/**\n * The text of a label node, for the sparkline's name: a string or number as is, an\n * element by its children, recursively. A `<Tooltip label=\"…\">Spend</Tooltip>` label\n * yields \"Spend\" — the text the reader sees, not the bubble's. `undefined` when there\n * is no text to find (an icon), so the sparkline falls back to its unnamed summary.\n */\nfunction plainText(node: ReactNode): string | undefined {\n const walk = (n: ReactNode): string => {\n if (typeof n === \"string\" || typeof n === \"number\") return String(n);\n if (Array.isArray(n)) return n.map(walk).join(\"\");\n if (isValidElement<{ children?: ReactNode }>(n)) return walk(n.props.children);\n return \"\";\n };\n const text = walk(node).replace(/\\s+/g, \" \").trim();\n return text === \"\" ? undefined : text;\n}\n\n/**\n * Whether `el`'s text is wider than its box — i.e. whether `truncate` is cutting it.\n * Re-measured whenever the box resizes (a grid reflowing, a translation loading), not\n * only on mount. Keyed on the ELEMENT (a callback ref), because wrapping the label in\n * its tooltip remounts it, and an observer on the old node would watch nothing.\n */\nfunction useIsTruncated(el: HTMLElement | null): boolean {\n const [cut, setCut] = useState(false);\n useLayoutEffect(() => {\n // No reset while there is no node: between the unwrapped label unmounting and the\n // wrapped one mounting there is none, and a reset there would unwrap it again.\n if (!el) return;\n const measure = () => setCut(el.scrollWidth > el.clientWidth);\n measure();\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(el);\n return () => observer.disconnect();\n }, [el]);\n return cut;\n}\n\nexport interface StatTileGridProps extends ComponentPropsWithoutRef<\"div\"> {\n /** The narrowest a tile may get before the grid drops a column. The default fits\n * two tiles on a 320px phone. */\n minTileWidth?: string;\n}\n\n/**\n * The row of tiles every dashboard in the three apps lays out by hand, each with its\n * own breakpoint ladder (`grid-cols-2 md:grid-cols-4 min-[2400px]:grid-cols-8` …).\n * Those ladders read the VIEWPORT and so ignored the sidebar: 6-up tiles at 155px in\n * the band where the sidebar was open. This fits as many columns as `minTileWidth`\n * allows in the space the grid actually has, and needs no breakpoint at all.\n */\nexport function StatTileGrid({ minTileWidth = \"9rem\", className, style, ...rest }: StatTileGridProps) {\n const columns: CSSProperties = {\n gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${minTileWidth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,GAAG,WAAW;AAC5D,YAAQ;AACR,QAAI,OAAO,mBAAmB,YAAa;AAC3C,UAAM,WAAW,IAAI,eAAe,OAAO;AAC3C,aAAS,QAAQ,EAAE;AACnB,WAAO,MAAM,SAAS,WAAW;AAAA,EACnC,GAAG,CAAC,EAAE,CAAC;AACP,SAAO;AACT;AAeO,SAAS,aAAa,EAAE,eAAe,QAAQ,WAAW,OAAO,GAAG,KAAK,GAAsB;AACpG,QAAM,UAAyB;AAAA,IAC7B,qBAAqB,qCAAqC,YAAY;AAAA,EACxE;AACA,SAAO,oBAAC,SAAK,GAAG,MAAM,WAAW,GAAG,cAAc,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,GAAG,MAAM,GAAG;AACjG;","names":[]}
1
+ {"version":3,"sources":["../../src/components/stat-tile.tsx"],"sourcesContent":["import { isValidElement, useId, useLayoutEffect, useState } from \"react\";\nimport type { ComponentPropsWithoutRef, CSSProperties, ReactElement, ReactNode } from \"react\";\nimport { ArrowDown, ArrowUp, Minus } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitLabels, useKitLink, useKitLocale } from \"../i18n/kit-labels\";\nimport { pickLinkRenderer, RenderedKitLink } from \"./text-link\";\nimport { Card, FieldHint } from \"./ui\";\nimport { Sparkline } from \"./sparkline\";\nimport { Tooltip } from \"./tooltip\";\n// The kit's one placeholder look, so a loading tile and the Skeleton list beside it\n// shimmer as one surface — and both stop under `prefers-reduced-motion`, which this\n// tile's private copy of the string did not.\nimport { SKELETON_CLASS } from \"./skeleton\";\n\n/**\n * The words a stat tile speaks. The delta's arrow is an icon, and an icon is not a\n * sentence: a screen reader gets the direction (and, under `goodDirection`, the\n * verdict) as words, and a sighted reader who cannot tell the two delta colours apart\n * still has the arrow — neither judgement rides on colour alone.\n */\nexport interface StatTileLabels {\n /** The delta, rising. `amount` is already formatted and unsigned. */\n increase: (amount: string) => string;\n decrease: (amount: string) => string;\n unchanged: string;\n /** Wraps the direction sentence when `goodDirection` says the change is good. */\n better: (change: string) => string;\n worse: (change: string) => string;\n /** Spoken in place of a missing value (the tile shows a dash). */\n noValue: string;\n /** Spoken while `loading`. */\n loading: string;\n}\n\nexport const DEFAULT_STAT_TILE_LABELS: StatTileLabels = {\n increase: (amount) => `Up ${amount}`,\n decrease: (amount) => `Down ${amount}`,\n unchanged: \"No change\",\n better: (change) => `${change} (better)`,\n worse: (change) => `${change} (worse)`,\n noValue: \"No data\",\n loading: \"Loading…\",\n};\n\n/**\n * What colours a figure. Token-backed like everything else in the kit.\n *\n * - `income` / `expense` / `net` — the money trio (teal / amber / violet, CVD-safe).\n * - `signed` — a money figure read by its own sign: above zero `income`, below zero\n * `expense`, exactly zero neutral (a zero balance is neither news). Needs a NUMBER\n * value; a pre-formatted string cannot be read and stays neutral.\n * - `success` / `warning` / `danger` / `info` — a threshold verdict (\"phase margin\n * below 30°\"). Say it in the hint or description as well; colour alone is not one.\n */\nexport type StatTileTone =\n | \"neutral\"\n | \"brand\"\n | \"income\"\n | \"expense\"\n | \"net\"\n | \"signed\"\n | \"success\"\n | \"warning\"\n | \"danger\"\n | \"info\";\n\nconst TONE_CLASS: Record<Exclude<StatTileTone, \"signed\">, string> = {\n neutral: \"text-[var(--text-primary)]\",\n brand: \"text-[var(--brand)]\",\n income: \"text-[var(--money-income)]\",\n expense: \"text-[var(--money-expense)]\",\n net: \"text-[var(--money-net)]\",\n success: \"text-[var(--success)]\",\n warning: \"text-[var(--warning)]\",\n danger: \"text-[var(--danger)]\",\n info: \"text-[var(--info)]\",\n};\n\nfunction toneClass(tone: StatTileTone, value: unknown): string {\n if (tone !== \"signed\") return TONE_CLASS[tone];\n if (typeof value !== \"number\" || value === 0) return TONE_CLASS.neutral;\n return value < 0 ? TONE_CLASS.expense : TONE_CLASS.income;\n}\n\n/** A change since the previous period. A bare number is shorthand for `{ value }`. */\nexport interface StatTileDelta {\n /** Signed: above zero is \"up\". */\n value: number;\n /** `\"value\"` (default) formats it like the headline — same currency, same\n * notation. `\"percent\"` reads it as a RATIO: `0.12` is shown as 12 %. */\n unit?: \"value\" | \"percent\";\n /** What it is measured against, shown after it: \"vs last month\". */\n label?: ReactNode;\n}\n\n/** A smaller figure under the headline — a prior period, a projection, a split. */\nexport interface StatTileSubValue {\n label: ReactNode;\n /** A number is formatted like the headline; anything else is rendered as given. */\n value: ReactNode;\n /** Defaults to the tile's own `tone`, read per figure (so a `signed` tile shows a\n * teal September above an amber August). Sub-values are always the muted weight\n * of their tone: they are history, and must not outshout the figure above them.\n *\n * `\"none\"` leaves the figure untinted — the row's own muted text, like its label —\n * even on a toned tile: keksdose's report KpiCard (reports/charts/kpi-card.tsx),\n * whose `negative` convention tints only a figure below zero and leaves the rest\n * plain. (`\"neutral\"` is not that: it is the headline's full text colour, at the\n * sub-value's 75 %.) */\n tone?: StatTileTone | \"none\";\n}\n\n/** What {@link StatTileProps.renderLink} is handed. Spread it onto your router's\n * link: the class is what stretches the link over the whole tile. */\nexport interface StatTileLinkProps {\n href: string;\n className: string;\n \"aria-describedby\": string;\n children: ReactNode;\n}\n\nexport interface StatTileProps\n extends Omit<ComponentPropsWithoutRef<\"div\">, \"children\" | \"onClick\"> {\n /** What is measured. Also the tile's accessible name when it is a link/button. */\n label: ReactNode;\n /**\n * The headline. A number is formatted with `Intl.NumberFormat` in the kit's locale\n * (see `currency`, `compact`, `numberFormat`, `format`); a string or element is\n * rendered as given. `null`/`undefined` shows a dash and says \"No data\".\n */\n value?: ReactNode;\n /** ISO 4217 code — formats a number value (and a `\"value\"` delta, and numeric\n * sub-values) as money. */\n currency?: string;\n /** Compact notation: 12 400 → \"12K\". */\n compact?: boolean;\n /** Any further `Intl.NumberFormat` options, merged over the two above. */\n numberFormat?: Intl.NumberFormatOptions;\n /** Formats every NUMBER the tile shows, replacing the `Intl` default outright. */\n format?: (value: number) => string;\n locale?: string;\n /** A short unit after the value that `Intl` has no name for: \"ms\", \"dB\", \"Hz\". */\n unit?: ReactNode;\n /** The period the headline belongs to, shown to its left (\"SEP\"). */\n valueLabel?: ReactNode;\n tone?: StatTileTone;\n delta?: number | StatTileDelta;\n /** Which way is good news. Unset, the delta is stated and not judged (users up and\n * cost up are the same arrow); set, it is coloured and its sentence says so. */\n goodDirection?: \"up\" | \"down\";\n /** The explanation behind a \"?\" beside the label (a {@link FieldHint}) — hidden\n * until asked for, so it is for what a reader MIGHT want to know (\"excludes\n * transfers between your own accounts\"). For a line everyone should read, use\n * {@link StatTileProps.description} instead. */\n hint?: string;\n /**\n * Keep the label to ONE line, cut with an ellipsis, and show the whole of it in a\n * {@link Tooltip} on hover and focus — but only while it is actually cut, so a\n * label that fits shows no bubble repeating itself. keksdose's admin MetricTile\n * wall: twenty tiles whose German labels (\"Aktive Abonnements (30 Tage)\") wrapped\n * onto two or three lines and pushed each tile's figure to a different height.\n *\n * The label element keeps the FULL text — the ellipsis is paint — so it is still\n * the tile's accessible name (and the stretched link's, on a link tile) exactly as\n * without this. Off by default: a wrapping label is what every existing tile does,\n * and a tile standing alone has room to.\n *\n * This is the tooltip: pass the label as a plain STRING rather than wrapping it in\n * your own `<Tooltip>` for the full text (keksdose's admin metrics-panel.tsx:134\n * does, from before this prop). A wrapped label shows a bubble even when nothing is\n * cut, and nests its trigger inside this one's.\n */\n truncateLabel?: boolean;\n /**\n * The tile's name as plain text, for the places that need a string rather than a\n * node — today the {@link StatTileProps.trend} sparkline's accessible name. Only\n * needed when `label` is not a string AND its text cannot be read from it: a label\n * element's text children are found on their own (a `<Tooltip label=\"…\">Spend\n * </Tooltip>` label still names its sparkline \"Spend\"), an icon or a formatted\n * message component's are not.\n */\n name?: string;\n /** A visible line under the value: \"Last 12 months\", \"3 estates / 9 buildings\" —\n * always shown, so it is for what every reader needs. An explanation only some\n * will want belongs in {@link StatTileProps.hint}, the \"?\" beside the label. */\n description?: ReactNode;\n /**\n * One figure that belongs WITH the headline rather than under it: keksdose's\n * \"Projected €1,850\" under a to-date \"€420\" (KpiCard, feedback #51), which it\n * currently smuggles into `description` with hand-set margins so the prior-month\n * sub-values do not come between the two. It is drawn directly under the value\n * (before the delta, the description and the sparkline) as a sub-value row, with\n * only a hair of space above it.\n *\n * A slot of its own rather than a placement switch for `subValues`: the history\n * rows (last month, last year) should stay at the bottom where they are, and moving\n * the whole list up to bring one row with it would put them between the headline\n * and its delta. Same shape as a sub-value, so the `tone` rules are the same.\n * Withheld while `loading`, like the sub-values.\n */\n projection?: StatTileSubValue;\n subValues?: StatTileSubValue[];\n /** Shorthand for a fluid {@link Sparkline} named after the tile and speaking in\n * the tile's number format. The name is the label's text; see\n * {@link StatTileProps.name} for a label that has none. */\n trend?: ReadonlyArray<number | null | undefined>;\n /** A custom sparkline (or any small graphic) in the same place. Wins over `trend`. */\n sparkline?: ReactNode;\n /** A decorative icon at the top end of the tile. */\n icon?: ReactNode;\n /** Anything below the rest — a progress bar, a link row. */\n footer?: ReactNode;\n /** Tag every figure `data-private`, so the host's demo-mode rule blurs it — the\n * same attribute `Tooltip redact` and the chart tooltip's value cell carry. */\n sensitive?: boolean;\n /** Skeleton in place of the value; delta, sub-values and trend are withheld. */\n loading?: boolean;\n /** `\"sm\"` for dense grids (a metrics wall); `\"md\"` the default KPI. */\n size?: \"sm\" | \"md\";\n /** Makes the tile a link. See {@link renderLink} for a router. */\n href?: string;\n /** Renders the link for `href` — pass your router's `<Link>` here, since a plain\n * `<a>` reloads a single-page app. Default: the `<UiKitProvider linkComponent>`\n * (for an in-app `href`), then `<a>`. */\n renderLink?: (props: StatTileLinkProps) => ReactElement;\n /** Makes the tile a button (ignored when `href` is given). */\n onClick?: () => void;\n labels?: Partial<StatTileLabels>;\n}\n\n// One formatter per option set: a metrics wall is twenty of these.\nconst formatters = new Map<string, Intl.NumberFormat>();\nfunction numberFormatter(locale: string | undefined, options: Intl.NumberFormatOptions): Intl.NumberFormat {\n const key = `${locale ?? \"\"}|${JSON.stringify(options)}`;\n let f = formatters.get(key);\n if (!f) {\n f = new Intl.NumberFormat(locale, options);\n formatters.set(key, f);\n }\n return f;\n}\n\n// The headline sizes are keyed on the TILE's width (it is a @container), not the\n// viewport: a grid beside a sidebar makes tiles narrowest exactly where a viewport\n// breakpoint would hand them the larger font. `sm` is keksdose's compact headline,\n// sized so a worst-case \"CHF 123,456.78\" still fits a 320px phone's 2-up tiles.\nconst VALUE_TEXT = {\n md: \"text-xl @[13rem]:text-2xl\",\n sm: \"text-xs @[8.5rem]:text-sm @[13rem]:text-base\",\n} as const;\nconst PADDING = { md: \"p-3 sm:p-4\", sm: \"px-2.5 py-2\" } as const;\n\n/**\n * The KPI card: a label, one number, and optionally how it moved, what it is made of\n * and which way it has been going.\n *\n * Replaces keksdose's `KpiCard` and admin `Tile`, lenkbank's metrics tiles and\n * kastlan's `KpiCard` — the same card four times, with four answers to the same\n * questions (how a currency is formatted, whether a delta is judged, what happens to\n * the figures in demo mode).\n *\n * Interactive tiles use a STRETCHED link: the label is the `<a>`/`<button>`, and its\n * `::after` covers the card. Making the card itself the link would nest the hint's\n * `<button>` inside it, which is invalid HTML and an unreachable control; this way\n * the hint sits above the overlay and stays its own tab stop. The link's name is the\n * label, and it is described by the value and the delta.\n */\nexport function StatTile({\n label,\n value,\n currency,\n compact = false,\n numberFormat,\n format,\n locale,\n unit,\n valueLabel,\n tone = \"neutral\",\n delta,\n goodDirection,\n hint,\n truncateLabel = false,\n name,\n description,\n projection,\n subValues,\n trend,\n sparkline,\n icon,\n footer,\n sensitive = false,\n loading = false,\n size = \"md\",\n href,\n renderLink,\n onClick,\n labels,\n className,\n ...rest\n}: StatTileProps) {\n const text = useKitLabels(\"statTile\", DEFAULT_STAT_TILE_LABELS, labels);\n const kitLink = useKitLink();\n const [labelEl, setLabelEl] = useState<HTMLElement | null>(null);\n const labelCut = useIsTruncated(truncateLabel ? labelEl : null);\n const kitLocale = useKitLocale(locale);\n const id = useId();\n const valueId = `${id}-value`;\n const deltaId = `${id}-delta`;\n const priv = sensitive ? \"\" : undefined;\n\n const fmt =\n format ??\n ((n: number) =>\n numberFormatter(kitLocale, {\n ...(currency ? { style: \"currency\", currency } : null),\n ...(compact ? { notation: \"compact\" } : null),\n ...numberFormat,\n }).format(n));\n const show = (v: ReactNode) => (typeof v === \"number\" ? fmt(v) : v);\n\n const d = typeof delta === \"number\" ? { value: delta } : delta;\n const hasValue = value !== null && value !== undefined && value !== \"\";\n const labelText = name ?? plainText(label);\n\n // ── The label, which is also the link/button when the tile is interactive ──\n const stretched = cn(\n \"text-start uppercase tracking-wide\",\n \"after:absolute after:inset-0 after:rounded-lg after:content-['']\",\n \"focus-visible:outline-none focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-[var(--brand)]\",\n );\n const describedBy = d ? `${valueId} ${deltaId}` : valueId;\n let labelNode: ReactNode = label;\n if (href !== undefined) {\n const linkProps: StatTileLinkProps = {\n href,\n className: stretched,\n \"aria-describedby\": describedBy,\n children: label,\n };\n const kit = pickLinkRenderer<StatTileLinkProps>(undefined, kitLink, href);\n labelNode = renderLink ? (\n renderLink(linkProps)\n ) : kit ? (\n <RenderedKitLink render={kit} props={linkProps} />\n ) : (\n <a href={href} className={stretched} aria-describedby={describedBy}>\n {label}\n </a>\n );\n } else if (onClick) {\n labelNode = (\n <button type=\"button\" onClick={onClick} aria-describedby={describedBy} className={stretched}>\n {label}\n </button>\n );\n }\n const interactive = href !== undefined || onClick !== undefined;\n\n // ── Delta ──\n let deltaNode: ReactNode = null;\n if (d && !loading && Number.isFinite(d.value)) {\n const magnitude = Math.abs(d.value);\n const amount =\n d.unit === \"percent\"\n ? numberFormatter(kitLocale, { style: \"percent\", maximumFractionDigits: 1 }).format(magnitude)\n : fmt(magnitude);\n const dir = d.value > 0 ? \"up\" : d.value < 0 ? \"down\" : \"flat\";\n const Icon = dir === \"up\" ? ArrowUp : dir === \"down\" ? ArrowDown : Minus;\n let spoken = dir === \"up\" ? text.increase(amount) : dir === \"down\" ? text.decrease(amount) : text.unchanged;\n let deltaTone = \"text-[var(--text-muted)]\";\n if (goodDirection && dir !== \"flat\") {\n const good = dir === goodDirection;\n spoken = good ? text.better(spoken) : text.worse(spoken);\n deltaTone = good ? \"text-[var(--success)]\" : \"text-[var(--danger)]\";\n }\n deltaNode = (\n // `relative`: the containing block for the sr-only sentence (see the\n // sr-only-containment test for what an escaped one does to the page).\n <div className=\"relative mt-1 flex flex-wrap items-center gap-x-1.5 text-xs tabular-nums\">\n <span id={deltaId} data-private={priv} className={cn(\"inline-flex items-center gap-0.5 font-medium\", deltaTone)}>\n <Icon className=\"size-3 shrink-0\" aria-hidden />\n {/* The figure at zero too, like Delta (kastlan 48): \"0 %\" says the change was\n measured; a bare dash reads like a missing value. */}\n <span aria-hidden>{amount}</span>\n <span className=\"sr-only\">{spoken}</span>\n </span>\n {d.label != null && <span className=\"text-[var(--text-muted)]\">{d.label}</span>}\n </div>\n );\n }\n\n // ── Headline ──\n const valueClass = cn(\n \"whitespace-nowrap font-semibold tabular-nums\",\n VALUE_TEXT[size],\n toneClass(tone, value),\n );\n const headline = loading ? (\n <span id={valueId} className=\"relative block py-0.5\">\n <span aria-hidden className={cn(SKELETON_CLASS, \"block h-6 w-24 max-w-full\")} />\n <span className=\"sr-only\">{text.loading}</span>\n </span>\n ) : hasValue ? (\n <span id={valueId} data-private={priv} className={cn(valueClass, valueLabel != null && \"ms-auto\")}>\n {show(value)}\n {unit != null && (\n <span className=\"ms-1 text-[0.7em] font-medium text-[var(--text-muted)]\">{unit}</span>\n )}\n </span>\n ) : (\n <span id={valueId} className={cn(\"relative\", valueClass, \"text-[var(--text-muted)]\")}>\n <span aria-hidden>—</span>\n <span className=\"sr-only\">{text.noValue}</span>\n </span>\n );\n\n const graphic =\n loading ? null : sparkline ??\n (trend && (\n <Sparkline\n data={trend}\n fluid\n height={size === \"sm\" ? 20 : 28}\n label={labelText}\n formatValue={fmt}\n locale={kitLocale}\n tone={tone === \"signed\" ? \"signed\" : tone === \"neutral\" ? \"chart\" : tone}\n data-private={priv}\n />\n ));\n\n return (\n <Card\n {...rest}\n aria-busy={loading || undefined}\n className={cn(\n // @container: the headline sizes read the tile's width. relative: the stretched\n // link's overlay. overflow-hidden: at pathological widths a figure clips inside\n // the border instead of painting over the neighbouring tile.\n \"@container relative flex min-w-0 flex-col overflow-hidden\",\n PADDING[size],\n interactive && \"transition-colors hover:border-[var(--border-strong)] hover:bg-[var(--bg-hover)]\",\n className,\n )}\n >\n <div className=\"flex items-start gap-2\">\n <div className=\"flex min-w-0 flex-1 items-center gap-1 break-words text-xs uppercase tracking-wide text-[var(--text-muted)]\">\n {truncateLabel && labelCut ? (\n // Portalled: the tile is `overflow-hidden`, and a bubble inside it would be\n // clipped by the very box whose edge cut the label.\n <Tooltip label={label} side=\"top\" portal className=\"flex min-w-0\">\n <span ref={setLabelEl} className=\"block min-w-0 truncate\">\n {labelNode}\n </span>\n </Tooltip>\n ) : (\n <span ref={setLabelEl} className={cn(\"min-w-0\", truncateLabel && \"block truncate\")}>\n {labelNode}\n </span>\n )}\n {/* Above the stretched link's overlay, so it stays hoverable and focusable. */}\n {hint && <FieldHint label={hint} side=\"top\" className=\"relative z-10 shrink-0\" />}\n </div>\n {icon != null && (\n <span aria-hidden className=\"shrink-0 text-[var(--text-muted)] [&_svg]:size-4\">\n {icon}\n </span>\n )}\n </div>\n\n {valueLabel != null ? (\n // Period-left / value-right, matching the sub-rows below it. flex-wrap lets a\n // too-long amount drop to its own end-aligned line instead of overflowing.\n <div className=\"mt-1 flex flex-wrap items-baseline gap-x-1.5\">\n <span className=\"shrink-0 text-xs uppercase tracking-wide text-[var(--text-muted)]\">{valueLabel}</span>\n {headline}\n </div>\n ) : (\n <div className=\"mt-1\">{headline}</div>\n )}\n\n {!loading && projection && (\n <dl className=\"mt-0.5\">\n <FigureRow figure={projection} tileTone={tone} show={show} priv={priv} />\n </dl>\n )}\n\n {deltaNode}\n {description != null && <div className=\"mt-1 text-xs text-[var(--text-muted)]\">{description}</div>}\n {graphic && <div className=\"mt-2\">{graphic}</div>}\n\n {!loading && subValues && subValues.length > 0 && (\n <dl className=\"mt-1.5 space-y-0.5\">\n {subValues.map((sv, i) => (\n <FigureRow key={i} figure={sv} tileTone={tone} show={show} priv={priv} />\n ))}\n </dl>\n )}\n\n {footer != null && <div className=\"mt-2\">{footer}</div>}\n </Card>\n );\n}\n\n/** One label/value row of a `<dl>`: a sub-value, or the projection. */\nfunction FigureRow({\n figure,\n tileTone,\n show,\n priv,\n}: {\n figure: StatTileSubValue;\n tileTone: StatTileTone;\n show: (v: ReactNode) => ReactNode;\n priv: \"\" | undefined;\n}) {\n const own = figure.tone ?? (tileTone === \"neutral\" ? undefined : tileTone);\n const svTone = own === \"none\" ? undefined : own;\n return (\n <div className=\"flex flex-wrap items-baseline gap-x-2 text-xs tabular-nums text-[var(--text-muted)]\">\n <dt className=\"uppercase tracking-wide\">{figure.label}</dt>\n <dd\n data-private={priv}\n className={cn(\"ms-auto whitespace-nowrap\", svTone && [toneClass(svTone, figure.value), \"opacity-75\"])}\n >\n {show(figure.value)}\n </dd>\n </div>\n );\n}\n\n/**\n * The text of a label node, for the sparkline's name: a string or number as is, an\n * element by its children, recursively. A `<Tooltip label=\"…\">Spend</Tooltip>` label\n * yields \"Spend\" — the text the reader sees, not the bubble's. `undefined` when there\n * is no text to find (an icon), so the sparkline falls back to its unnamed summary.\n */\nfunction plainText(node: ReactNode): string | undefined {\n const walk = (n: ReactNode): string => {\n if (typeof n === \"string\" || typeof n === \"number\") return String(n);\n if (Array.isArray(n)) return n.map(walk).join(\"\");\n if (isValidElement<{ children?: ReactNode }>(n)) return walk(n.props.children);\n return \"\";\n };\n const text = walk(node).replace(/\\s+/g, \" \").trim();\n return text === \"\" ? undefined : text;\n}\n\n/**\n * Whether `el`'s text is wider than its box — i.e. whether `truncate` is cutting it.\n * Re-measured whenever the box resizes (a grid reflowing, a translation loading), not\n * only on mount. Keyed on the ELEMENT (a callback ref), because wrapping the label in\n * its tooltip remounts it, and an observer on the old node would watch nothing.\n */\nfunction useIsTruncated(el: HTMLElement | null): boolean {\n const [cut, setCut] = useState(false);\n useLayoutEffect(() => {\n // No reset while there is no node: between the unwrapped label unmounting and the\n // wrapped one mounting there is none, and a reset there would unwrap it again.\n if (!el) return;\n const measure = () => setCut(el.scrollWidth > el.clientWidth);\n measure();\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(measure);\n observer.observe(el);\n return () => observer.disconnect();\n }, [el]);\n return cut;\n}\n\nexport interface StatTileGridProps extends ComponentPropsWithoutRef<\"div\"> {\n /** The narrowest a tile may get before the grid drops a column. The default fits\n * two tiles on a 320px phone. */\n minTileWidth?: string;\n}\n\n/**\n * The row of tiles every dashboard in the three apps lays out by hand, each with its\n * own breakpoint ladder (`grid-cols-2 md:grid-cols-4 min-[2400px]:grid-cols-8` …).\n * Those ladders read the VIEWPORT and so ignored the sidebar: 6-up tiles at 155px in\n * the band where the sidebar was open. This fits as many columns as `minTileWidth`\n * allows in the space the grid actually has, and needs no breakpoint at all.\n */\nexport function StatTileGrid({ minTileWidth = \"9rem\", className, style, ...rest }: StatTileGridProps) {\n const columns: CSSProperties = {\n gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${minTileWidth}), 1fr))`,\n };\n return <div {...rest} className={cn(\"grid gap-3\", className)} style={{ ...columns, ...style }} />;\n}\n"],"mappings":";AAuVM,cAoCE,YApCF;AAvVN,SAAS,gBAAgB,OAAO,iBAAiB,gBAAgB;AAEjE,SAAS,WAAW,SAAS,aAAa;AAC1C,SAAS,UAAU;AACnB,SAAS,cAAc,YAAY,oBAAoB;AACvD,SAAS,kBAAkB,uBAAuB;AAClD,SAAS,MAAM,iBAAiB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAIxB,SAAS,sBAAsB;AAsBxB,MAAM,2BAA2C;AAAA,EACtD,UAAU,CAAC,WAAW,MAAM,MAAM;AAAA,EAClC,UAAU,CAAC,WAAW,QAAQ,MAAM;AAAA,EACpC,WAAW;AAAA,EACX,QAAQ,CAAC,WAAW,GAAG,MAAM;AAAA,EAC7B,OAAO,CAAC,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const lastSide = useRef("right");
54
- if (dx !== 0) lastSide.current = dx < 0 ? "left" : "right";
55
- const draggingLeft = dx !== 0 ? dx < 0 : lastSide.current === "left";
53
+ const [lastSide, setLastSide] = useState("right");
54
+ const side = dx === 0 ? null : dx < 0 ? "left" : "right";
55
+ if (side && side !== lastSide) setLastSide(side);
56
+ const draggingLeft = side ? side === "left" : lastSide === "left";
56
57
  const shown = draggingLeft ? leftActions[Math.max(0, swipe.armedLeftIndex)] : rightActions[Math.max(0, swipe.armedRightIndex)];
57
58
  const armed = draggingLeft ? swipe.armedLeftIndex >= 0 : swipe.armedRightIndex >= 0;
58
59
  return /* @__PURE__ */ jsxs("div", { ref: rowRef, className: cn("relative overflow-hidden", className), children: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/swipeable-row.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useRowSwipe, type SwipeStage } from \"../hooks/use-row-swipe\";\nimport { DEFAULT_SWIPEABLE_ROW_LABELS, useKitLabels } from \"../i18n/kit-labels\";\n\n/**\n * One armed swipe action: what it does, and how the reveal panel presents it.\n *\n * The two background classes are the idle and armed states. Before the first\n * threshold is crossed the panel previews the nearest action in its IDLE colour, so\n * the user can see what a little more drag will do; crossing the threshold flips it to\n * `armedClassName`. Passing the same value for both simply removes that feedback.\n */\nexport interface SwipeAction {\n onCommit: () => void;\n label: string;\n /** Rendered inside the panel. Icons stay the consumer's choice — this package\n * ships no opinion about which icon set an app uses. */\n icon?: ReactNode;\n /** Background utility class while the action is previewed but not yet armed. */\n className: string;\n /** Background utility class once the drag has passed this action's threshold. */\n armedClassName: string;\n}\n\n/**\n * `right`/`left` are PHYSICAL drag directions in every writing direction, and stay so on\n * purpose: a swipe is a movement of the finger across the glass, the gesture hook\n * measures it in screen pixels, and \"which way is destructive\" is an app decision that\n * RTL guidelines do not agree on. An app that wants mirrored actions in RTL swaps the\n * two arrays itself. What the component does mirror is everything it lays out: the\n * reveal panel's contents hug the physical edge being uncovered, and the keyboard\n * buttons sit at the row's logical END.\n */\nexport interface SwipeableRowProps {\n /** Actions committed by dragging (physically) RIGHT, nearest threshold first. */\n right?: SwipeAction[];\n /** Actions committed by dragging (physically) LEFT, nearest threshold first. */\n left?: SwipeAction[];\n /** Turn the gesture off — an open editor, a pending mutation, a locked row. This\n * also withdraws the keyboard buttons below: a row that must not be acted on must\n * not be actionable by ANY input. */\n enabled?: boolean;\n /** Names the revealed action buttons as a set (\"Row actions\"), for a reader that\n * reaches the group before it reaches any one button. Default:\n * `swipeableRow.actions` from the {@link UiKitProvider}, else English. */\n actionsLabel?: string;\n className?: string;\n children: ReactNode;\n}\n\n/** How much of the row stays on screen at full drag. A row that can be pulled\n * entirely off its own track reads as already deleted, and there is nothing left to\n * drag back; a sliver keeps the gesture reversible and the row identifiable. */\nconst PEEK_PX = 40;\n\n/**\n * A row whose horizontal drag reveals actions underneath it.\n *\n * The reveal panel spans the FULL row width (Keksdose feedback #174). It used to be\n * two half-width blocks side by side, which capped the drag at half the row so the\n * opposite panel could never be exposed — and on a row bound to three actions that\n * left ~55px between stages on a phone, close enough that the wrong one committed.\n * Only the side being dragged toward is painted now, so full width costs nothing:\n * at rest the content covers both anyway, and a drag only ever reveals one side.\n *\n * Thresholds are still not fixed pixel values — they are spread evenly across the\n * available drag, which is now the row width less a {@link PEEK_PX} sliver. A fixed\n * 72/150/228px ladder overshoots a narrow phone; a proportional one keeps every\n * action reachable and roughly doubles the room between them.\n *\n * **Whether the action will fire is stated three ways, not one** (feedback #174): the\n * panel goes from dimmed to solid, the icon grows and gains a filled disc, and the\n * label turns bold — plus the existing haptic tick per newly armed stage. A colour\n * shift alone is easy to miss mid-gesture, and it is invisible to anyone who cannot\n * distinguish the two tones.\n *\n * Clicks that follow a drag are swallowed in the capture phase: without that, a swipe\n * would also fire whatever click handler the row content carries (expanding it, opening\n * a dialog) on top of the action it just committed.\n *\n * ## The keyboard path is buttons, and deliberately not a typed gesture\n *\n * Every action here used to live exclusively inside a pointer drag — `onCommit` had no\n * other caller — so with a keyboard, with a screen reader, or on any input that cannot\n * express 120px of horizontal travel, the row's actions did not exist at all. That is\n * not a rough edge on a phone control: {@link DataTable} mounts this for every row of\n * its mobile layout, and the actions an app puts here are its destructive ones.\n *\n * The rejected fix was to map the gesture onto keys — arrows nudging `dx`, a chord that\n * \"swipes\". That invents a private idiom with nothing to discover it by, and it makes\n * the keyboard imitate a touchscreen instead of doing the job the touchscreen is doing.\n * So each action is ALSO a real button, `sr-only` until it takes focus and then shown at\n * the row's trailing edge, firing the identical `onCommit`: one definition of what an\n * action is, two ways to reach it, and nothing to drift apart. `sr-only` hides from\n * the eye and not from the accessibility tree, so the row also ANNOUNCES what can be\n * done to it rather than keeping it behind a gesture nobody can hear.\n */\nexport function SwipeableRow({\n right,\n left,\n enabled = true,\n actionsLabel,\n className,\n children,\n}: SwipeableRowProps) {\n const labels = useKitLabels(\"swipeableRow\", DEFAULT_SWIPEABLE_ROW_LABELS, {\n actions: actionsLabel,\n });\n const rowRef = useRef<HTMLDivElement>(null);\n const [rowWidth, setRowWidth] = useState(0);\n useEffect(() => {\n const el = rowRef.current;\n if (!el) return;\n setRowWidth(el.clientWidth);\n if (typeof ResizeObserver === \"undefined\") return;\n const ro = new ResizeObserver((entries) => {\n for (const e of entries) setRowWidth(e.contentRect.width);\n });\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n const rightActions = right ?? [];\n const leftActions = left ?? [];\n const active = enabled && (rightActions.length > 0 || leftActions.length > 0);\n // The whole row less a sliver, not half of it (feedback #174). `Math.max` keeps a\n // very narrow row (or one measured before layout) from producing a zero or\n // negative drag, which would arm every stage at once.\n const maxDrag = rowWidth > 0 ? Math.max(96, Math.round(rowWidth - PEEK_PX)) : 200;\n const spread = (actions: SwipeAction[]): SwipeStage[] =>\n actions.map((a, i) => ({\n threshold: Math.round((maxDrag * (i + 1)) / (actions.length + 1)),\n onCommit: a.onCommit,\n }));\n\n const swipe = useRowSwipe({\n enabled: active,\n rightStages: spread(rightActions),\n leftStages: spread(leftActions),\n maxDrag,\n });\n\n // A haptic tick per newly armed threshold, so each stage is felt and not only seen.\n const armedNow = swipe.dx >= 0 ? swipe.armedRightIndex : swipe.armedLeftIndex;\n const prevArmed = useRef(-1);\n useEffect(() => {\n if (armedNow > prevArmed.current && armedNow >= 0) navigator.vibrate?.(12);\n prevArmed.current = armedNow;\n }, [armedNow]);\n\n // Index -1 (nothing armed yet) still previews the nearest action, idle-coloured.\n const dx = swipe.dx;\n // Only the side being dragged toward is painted, which is what makes a full-width\n // panel safe.\n //\n // The side has to SURVIVE the release, though, and that is what this ref is for\n // (Keksdose feedback dev#467): *\"Swiping a category to the left with no option — if\n // letting it go it gets, for the way back, the background color of the opposite\n // swipe direction where there should be no color change at all.\"* On release dx\n // snaps to 0 while the row itself slides back over 150ms, so a plain `dx < 0` read\n // \"right\" for exactly the frames where the left side was still uncovered — and\n // painted the RIGHT action's colour into the gap. With no left action at all that\n // colour was the only thing the gesture ever showed.\n //\n // Written during render rather than in an effect: an effect would repaint a frame\n // later (visibly, at 150ms) and `setState` in an effect body is an eslint error in\n // the consuming app. The value is derived from this render's own dx, so a\n // concurrent re-render recomputes it identically.\n const lastSide = useRef<\"left\" | \"right\">(\"right\");\n if (dx !== 0) lastSide.current = dx < 0 ? \"left\" : \"right\";\n const draggingLeft = dx !== 0 ? dx < 0 : lastSide.current === \"left\";\n const shown = draggingLeft\n ? leftActions[Math.max(0, swipe.armedLeftIndex)]\n : rightActions[Math.max(0, swipe.armedRightIndex)];\n const armed = draggingLeft ? swipe.armedLeftIndex >= 0 : swipe.armedRightIndex >= 0;\n\n return (\n <div ref={rowRef} className={cn(\"relative overflow-hidden\", className)}>\n {active && shown && (\n <div\n className={cn(\n \"pointer-events-none absolute inset-0 flex items-center gap-2 px-4\",\n \"text-xs font-medium text-white transition-all\",\n // Dimmed until the drag has actually passed a threshold: \"nothing will\n // happen yet\" has to look different from \"let go and this fires\", and on\n // a moving row a one-step colour change was too quiet to notice.\n armed ? \"opacity-100\" : \"opacity-60\",\n armed ? shown.armedClassName : shown.className,\n // The panel is anchored to the edge the row is uncovering, so the label\n // sits where the eye already is rather than across the screen. That edge is\n // physical, while a flex row starts at the INLINE start — so in RTL the two\n // directions swap, or the label sat under the row on the covered side.\n draggingLeft ? \"flex-row-reverse rtl:flex-row\" : \"rtl:flex-row-reverse\",\n )}\n >\n {shown.icon && (\n <span\n className={cn(\n \"flex shrink-0 items-center justify-center rounded-full transition-all\",\n // Armed, the icon gets a disc of its own and grows — a second,\n // non-colour signal, and the one that stays readable at a glance.\n armed ? \"size-8 scale-110 bg-white/25\" : \"size-7 bg-white/10\",\n )}\n >\n {shown.icon}\n </span>\n )}\n <span className={cn(\"truncate transition-all\", armed && \"text-sm font-semibold\")}>\n {shown.label}\n </span>\n </div>\n )}\n <div\n // Capture phase: the row's own click handler lives on a DESCENDANT, so a\n // bubble-phase listener here would run after it — too late to suppress.\n onClickCapture={(e) => {\n if (!swipe.consumeClick()) return;\n e.preventDefault();\n e.stopPropagation();\n }}\n className={cn(\n \"relative bg-[var(--bg-surface)]\",\n // A mouse drag is a supported way to swipe (use-row-swipe gates only on\n // the button, not the pointer type), and a horizontal mouse drag over\n // text also SELECTS that text — so committing an action left the row\n // highlighted blue. Suppressed only while dragging, so text in a row at\n // rest stays selectable.\n swipe.dragging ? \"select-none\" : \"transition-transform duration-150\",\n )}\n style={{\n transform: dx !== 0 ? `translate3d(${dx}px,0,0)` : undefined,\n touchAction: active ? \"pan-y\" : undefined,\n }}\n {...(active ? swipe.handlers : {})}\n >\n {children}\n </div>\n {active && (\n <div\n role=\"group\"\n aria-label={labels.actions}\n // OUTSIDE the sliding div on purpose: an action that travels with the row it\n // acts on is a moving target, and the drag transform would carry it off the\n // screen mid-gesture.\n //\n // `pointer-events-none` here, restored on a button only once it HAS focus: a\n // sr-only button is clipped to nothing but is still a hit target, and this\n // strip sits at the row's trailing edge — exactly where a drag toward the\n // start begins.\n //\n // `end-0`/`pe-2`, not `right-0`/`pr-2`: in RTL the right edge is where the\n // row's title starts, and a focused button there covered it.\n // A gesture that silently failed to start because it landed on an invisible\n // button is not a bug anyone would find by looking at the screen.\n className=\"pointer-events-none absolute inset-y-0 end-0 z-10 flex items-center gap-1 pe-2\"\n >\n {/* Both sides, each still nearest-threshold first, so the tab order reads in\n the order the gesture arms them. */}\n {[...rightActions, ...leftActions].map((action, i) => (\n <button\n key={`${action.label}-${i}`}\n type=\"button\"\n onClick={action.onCommit}\n className={cn(\n \"sr-only whitespace-nowrap rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-2 py-1 text-xs font-medium text-[var(--text-primary)] shadow-sm\",\n \"focus:not-sr-only focus:pointer-events-auto focus:inline-flex focus:items-center focus:gap-1.5\",\n \"focus-visible:ring-2 focus-visible:ring-[var(--brand)]\",\n )}\n >\n {/* The label is the button's accessible name, so the caller's icon is\n decoration on top of it rather than a second reading of it. */}\n {action.icon && (\n <span aria-hidden=\"true\" className=\"[&_svg]:size-4\">\n {action.icon}\n </span>\n )}\n {action.label}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";AAqLQ,SAiBI,KAjBJ;AArLR,SAAS,WAAW,QAAQ,gBAAgB;AAE5C,SAAS,UAAU;AACnB,SAAS,mBAAoC;AAC7C,SAAS,8BAA8B,oBAAoB;AAmD3D,MAAM,UAAU;AA4CT,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,QAAM,SAAS,aAAa,gBAAgB,8BAA8B;AAAA,IACxE,SAAS;AAAA,EACX,CAAC;AACD,QAAM,SAAS,OAAuB,IAAI;AAC1C,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,CAAC;AAC1C,YAAU,MAAM;AACd,UAAM,KAAK,OAAO;AAClB,QAAI,CAAC,GAAI;AACT,gBAAY,GAAG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C;AAAA,UAAC;AAAA;AAAA,YAEC,MAAK;AAAA,YACL,SAAS,OAAO;AAAA,YAChB,WAAW;AAAA,cACT;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YAIC;AAAA,qBAAO,QACN,oBAAC,UAAK,eAAY,QAAO,WAAU,kBAChC,iBAAO,MACV;AAAA,cAED,OAAO;AAAA;AAAA;AAAA,UAhBH,GAAG,OAAO,KAAK,IAAI,CAAC;AAAA,QAiB3B,CACD;AAAA;AAAA,IACH;AAAA,KAEJ;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/swipeable-row.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useRowSwipe, type SwipeStage } from \"../hooks/use-row-swipe\";\nimport { DEFAULT_SWIPEABLE_ROW_LABELS, useKitLabels } from \"../i18n/kit-labels\";\n\n/**\n * One armed swipe action: what it does, and how the reveal panel presents it.\n *\n * The two background classes are the idle and armed states. Before the first\n * threshold is crossed the panel previews the nearest action in its IDLE colour, so\n * the user can see what a little more drag will do; crossing the threshold flips it to\n * `armedClassName`. Passing the same value for both simply removes that feedback.\n */\nexport interface SwipeAction {\n onCommit: () => void;\n label: string;\n /** Rendered inside the panel. Icons stay the consumer's choice — this package\n * ships no opinion about which icon set an app uses. */\n icon?: ReactNode;\n /** Background utility class while the action is previewed but not yet armed. */\n className: string;\n /** Background utility class once the drag has passed this action's threshold. */\n armedClassName: string;\n}\n\n/**\n * `right`/`left` are PHYSICAL drag directions in every writing direction, and stay so on\n * purpose: a swipe is a movement of the finger across the glass, the gesture hook\n * measures it in screen pixels, and \"which way is destructive\" is an app decision that\n * RTL guidelines do not agree on. An app that wants mirrored actions in RTL swaps the\n * two arrays itself. What the component does mirror is everything it lays out: the\n * reveal panel's contents hug the physical edge being uncovered, and the keyboard\n * buttons sit at the row's logical END.\n */\nexport interface SwipeableRowProps {\n /** Actions committed by dragging (physically) RIGHT, nearest threshold first. */\n right?: SwipeAction[];\n /** Actions committed by dragging (physically) LEFT, nearest threshold first. */\n left?: SwipeAction[];\n /** Turn the gesture off — an open editor, a pending mutation, a locked row. This\n * also withdraws the keyboard buttons below: a row that must not be acted on must\n * not be actionable by ANY input. */\n enabled?: boolean;\n /** Names the revealed action buttons as a set (\"Row actions\"), for a reader that\n * reaches the group before it reaches any one button. Default:\n * `swipeableRow.actions` from the {@link UiKitProvider}, else English. */\n actionsLabel?: string;\n className?: string;\n children: ReactNode;\n}\n\n/** How much of the row stays on screen at full drag. A row that can be pulled\n * entirely off its own track reads as already deleted, and there is nothing left to\n * drag back; a sliver keeps the gesture reversible and the row identifiable. */\nconst PEEK_PX = 40;\n\n/**\n * A row whose horizontal drag reveals actions underneath it.\n *\n * The reveal panel spans the FULL row width (Keksdose feedback #174). It used to be\n * two half-width blocks side by side, which capped the drag at half the row so the\n * opposite panel could never be exposed — and on a row bound to three actions that\n * left ~55px between stages on a phone, close enough that the wrong one committed.\n * Only the side being dragged toward is painted now, so full width costs nothing:\n * at rest the content covers both anyway, and a drag only ever reveals one side.\n *\n * Thresholds are still not fixed pixel values — they are spread evenly across the\n * available drag, which is now the row width less a {@link PEEK_PX} sliver. A fixed\n * 72/150/228px ladder overshoots a narrow phone; a proportional one keeps every\n * action reachable and roughly doubles the room between them.\n *\n * **Whether the action will fire is stated three ways, not one** (feedback #174): the\n * panel goes from dimmed to solid, the icon grows and gains a filled disc, and the\n * label turns bold — plus the existing haptic tick per newly armed stage. A colour\n * shift alone is easy to miss mid-gesture, and it is invisible to anyone who cannot\n * distinguish the two tones.\n *\n * Clicks that follow a drag are swallowed in the capture phase: without that, a swipe\n * would also fire whatever click handler the row content carries (expanding it, opening\n * a dialog) on top of the action it just committed.\n *\n * ## The keyboard path is buttons, and deliberately not a typed gesture\n *\n * Every action here used to live exclusively inside a pointer drag — `onCommit` had no\n * other caller — so with a keyboard, with a screen reader, or on any input that cannot\n * express 120px of horizontal travel, the row's actions did not exist at all. That is\n * not a rough edge on a phone control: {@link DataTable} mounts this for every row of\n * its mobile layout, and the actions an app puts here are its destructive ones.\n *\n * The rejected fix was to map the gesture onto keys — arrows nudging `dx`, a chord that\n * \"swipes\". That invents a private idiom with nothing to discover it by, and it makes\n * the keyboard imitate a touchscreen instead of doing the job the touchscreen is doing.\n * So each action is ALSO a real button, `sr-only` until it takes focus and then shown at\n * the row's trailing edge, firing the identical `onCommit`: one definition of what an\n * action is, two ways to reach it, and nothing to drift apart. `sr-only` hides from\n * the eye and not from the accessibility tree, so the row also ANNOUNCES what can be\n * done to it rather than keeping it behind a gesture nobody can hear.\n */\nexport function SwipeableRow({\n right,\n left,\n enabled = true,\n actionsLabel,\n className,\n children,\n}: SwipeableRowProps) {\n const labels = useKitLabels(\"swipeableRow\", DEFAULT_SWIPEABLE_ROW_LABELS, {\n actions: actionsLabel,\n });\n const rowRef = useRef<HTMLDivElement>(null);\n const [rowWidth, setRowWidth] = useState(0);\n useEffect(() => {\n const el = rowRef.current;\n if (!el) return;\n setRowWidth(el.clientWidth);\n if (typeof ResizeObserver === \"undefined\") return;\n const ro = new ResizeObserver((entries) => {\n for (const e of entries) setRowWidth(e.contentRect.width);\n });\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n const rightActions = right ?? [];\n const leftActions = left ?? [];\n const active = enabled && (rightActions.length > 0 || leftActions.length > 0);\n // The whole row less a sliver, not half of it (feedback #174). `Math.max` keeps a\n // very narrow row (or one measured before layout) from producing a zero or\n // negative drag, which would arm every stage at once.\n const maxDrag = rowWidth > 0 ? Math.max(96, Math.round(rowWidth - PEEK_PX)) : 200;\n const spread = (actions: SwipeAction[]): SwipeStage[] =>\n actions.map((a, i) => ({\n threshold: Math.round((maxDrag * (i + 1)) / (actions.length + 1)),\n onCommit: a.onCommit,\n }));\n\n const swipe = useRowSwipe({\n enabled: active,\n rightStages: spread(rightActions),\n leftStages: spread(leftActions),\n maxDrag,\n });\n\n // A haptic tick per newly armed threshold, so each stage is felt and not only seen.\n const armedNow = swipe.dx >= 0 ? swipe.armedRightIndex : swipe.armedLeftIndex;\n const prevArmed = useRef(-1);\n useEffect(() => {\n if (armedNow > prevArmed.current && armedNow >= 0) navigator.vibrate?.(12);\n prevArmed.current = armedNow;\n }, [armedNow]);\n\n // Index -1 (nothing armed yet) still previews the nearest action, idle-coloured.\n const dx = swipe.dx;\n // Only the side being dragged toward is painted, which is what makes a full-width\n // panel safe.\n //\n // The side has to SURVIVE the release, though, and that is what this ref is for\n // (Keksdose feedback dev#467): *\"Swiping a category to the left with no option — if\n // letting it go it gets, for the way back, the background color of the opposite\n // swipe direction where there should be no color change at all.\"* On release dx\n // snaps to 0 while the row itself slides back over 150ms, so a plain `dx < 0` read\n // \"right\" for exactly the frames where the left side was still uncovered — and\n // painted the RIGHT action's colour into the gap. With no left action at all that\n // colour was the only thing the gesture ever showed.\n //\n // Adjusted during render rather than in an effect: an effect would repaint a frame\n // later (visibly, at 150ms). State set while rendering re-renders this component\n // before anything is committed, so the released frame already has the right side.\n const [lastSide, setLastSide] = useState<\"left\" | \"right\">(\"right\");\n const side = dx === 0 ? null : dx < 0 ? \"left\" : \"right\";\n if (side && side !== lastSide) setLastSide(side);\n const draggingLeft = side ? side === \"left\" : lastSide === \"left\";\n const shown = draggingLeft\n ? leftActions[Math.max(0, swipe.armedLeftIndex)]\n : rightActions[Math.max(0, swipe.armedRightIndex)];\n const armed = draggingLeft ? swipe.armedLeftIndex >= 0 : swipe.armedRightIndex >= 0;\n\n return (\n <div ref={rowRef} className={cn(\"relative overflow-hidden\", className)}>\n {active && shown && (\n <div\n className={cn(\n \"pointer-events-none absolute inset-0 flex items-center gap-2 px-4\",\n \"text-xs font-medium text-white transition-all\",\n // Dimmed until the drag has actually passed a threshold: \"nothing will\n // happen yet\" has to look different from \"let go and this fires\", and on\n // a moving row a one-step colour change was too quiet to notice.\n armed ? \"opacity-100\" : \"opacity-60\",\n armed ? shown.armedClassName : shown.className,\n // The panel is anchored to the edge the row is uncovering, so the label\n // sits where the eye already is rather than across the screen. That edge is\n // physical, while a flex row starts at the INLINE start — so in RTL the two\n // directions swap, or the label sat under the row on the covered side.\n draggingLeft ? \"flex-row-reverse rtl:flex-row\" : \"rtl:flex-row-reverse\",\n )}\n >\n {shown.icon && (\n <span\n className={cn(\n \"flex shrink-0 items-center justify-center rounded-full transition-all\",\n // Armed, the icon gets a disc of its own and grows — a second,\n // non-colour signal, and the one that stays readable at a glance.\n armed ? \"size-8 scale-110 bg-white/25\" : \"size-7 bg-white/10\",\n )}\n >\n {shown.icon}\n </span>\n )}\n <span className={cn(\"truncate transition-all\", armed && \"text-sm font-semibold\")}>\n {shown.label}\n </span>\n </div>\n )}\n <div\n // Capture phase: the row's own click handler lives on a DESCENDANT, so a\n // bubble-phase listener here would run after it — too late to suppress.\n onClickCapture={(e) => {\n if (!swipe.consumeClick()) return;\n e.preventDefault();\n e.stopPropagation();\n }}\n className={cn(\n \"relative bg-[var(--bg-surface)]\",\n // A mouse drag is a supported way to swipe (use-row-swipe gates only on\n // the button, not the pointer type), and a horizontal mouse drag over\n // text also SELECTS that text — so committing an action left the row\n // highlighted blue. Suppressed only while dragging, so text in a row at\n // rest stays selectable.\n swipe.dragging ? \"select-none\" : \"transition-transform duration-150\",\n )}\n style={{\n transform: dx !== 0 ? `translate3d(${dx}px,0,0)` : undefined,\n touchAction: active ? \"pan-y\" : undefined,\n }}\n {...(active ? swipe.handlers : {})}\n >\n {children}\n </div>\n {active && (\n <div\n role=\"group\"\n aria-label={labels.actions}\n // OUTSIDE the sliding div on purpose: an action that travels with the row it\n // acts on is a moving target, and the drag transform would carry it off the\n // screen mid-gesture.\n //\n // `pointer-events-none` here, restored on a button only once it HAS focus: a\n // sr-only button is clipped to nothing but is still a hit target, and this\n // strip sits at the row's trailing edge — exactly where a drag toward the\n // start begins.\n //\n // `end-0`/`pe-2`, not `right-0`/`pr-2`: in RTL the right edge is where the\n // row's title starts, and a focused button there covered it.\n // A gesture that silently failed to start because it landed on an invisible\n // button is not a bug anyone would find by looking at the screen.\n className=\"pointer-events-none absolute inset-y-0 end-0 z-10 flex items-center gap-1 pe-2\"\n >\n {/* Both sides, each still nearest-threshold first, so the tab order reads in\n the order the gesture arms them. */}\n {[...rightActions, ...leftActions].map((action, i) => (\n <button\n key={`${action.label}-${i}`}\n type=\"button\"\n onClick={action.onCommit}\n className={cn(\n \"sr-only whitespace-nowrap rounded-md border border-[var(--border)] bg-[var(--bg-surface)] px-2 py-1 text-xs font-medium text-[var(--text-primary)] shadow-sm\",\n \"focus:not-sr-only focus:pointer-events-auto focus:inline-flex focus:items-center focus:gap-1.5\",\n \"focus-visible:ring-2 focus-visible:ring-[var(--brand)]\",\n )}\n >\n {/* The label is the button's accessible name, so the caller's icon is\n decoration on top of it rather than a second reading of it. */}\n {action.icon && (\n <span aria-hidden=\"true\" className=\"[&_svg]:size-4\">\n {action.icon}\n </span>\n )}\n {action.label}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";AAqLQ,SAiBI,KAjBJ;AArLR,SAAS,WAAW,QAAQ,gBAAgB;AAE5C,SAAS,UAAU;AACnB,SAAS,mBAAoC;AAC7C,SAAS,8BAA8B,oBAAoB;AAmD3D,MAAM,UAAU;AA4CT,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,QAAM,SAAS,aAAa,gBAAgB,8BAA8B;AAAA,IACxE,SAAS;AAAA,EACX,CAAC;AACD,QAAM,SAAS,OAAuB,IAAI;AAC1C,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,CAAC;AAC1C,YAAU,MAAM;AACd,UAAM,KAAK,OAAO;AAClB,QAAI,CAAC,GAAI;AACT,gBAAY,GAAG,WAAW;AAC1B,QAAI,OAAO,mBAAmB,YAAa;AAC3C,UAAM,KAAK,IAAI,eAAe,CAAC,YAAY;AACzC,iBAAW,KAAK,QAAS,aAAY,EAAE,YAAY,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W;AAAA,cACT;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YAIC;AAAA,qBAAO,QACN,oBAAC,UAAK,eAAY,QAAO,WAAU,kBAChC,iBAAO,MACV;AAAA,cAED,OAAO;AAAA;AAAA;AAAA,UAhBH,GAAG,OAAO,KAAK,IAAI,CAAC;AAAA,QAiB3B,CACD;AAAA;AAAA,IACH;AAAA,KAEJ;AAEJ;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactElement, ComponentPropsWithoutRef, ReactNode, Ref, MouseEvent, KeyboardEvent } from 'react';
3
3
  import { LucideIcon } from 'lucide-react';
4
- import { ax as KitLinkComponent } from '../kit-labels-v3biUF1L.js';
4
+ import { az as KitLinkComponent } from '../kit-labels-Mz8zZHIF.js';
5
5
  import './data-table-labels.js';
6
6
  import './mini-calendar.js';
7
7
  import './calendar-heatmap.js';
@@ -88,6 +88,30 @@ declare function isRoutableHref(href: string): boolean;
88
88
  * @internal Shared by the kit's link-bearing components; not part of the barrel.
89
89
  */
90
90
  declare function pickLinkRenderer<P>(own: ((props: P) => ReactElement) | undefined, kitLink: KitLinkComponent | undefined, href: string | undefined): ((props: P) => ReactElement) | undefined;
91
+ /**
92
+ * The `onClick` of a PLAIN `<a>` whose kit link was asked to `replace` (keksdose F1).
93
+ *
94
+ * A router link replaces the history entry itself (it is handed `replace`, see
95
+ * {@link routerLinkNavigation}); a plain `<a>` has no attribute that says so, and the
96
+ * browser's own navigation always pushes. So a plain click is taken over — the caller's
97
+ * `onClick` runs first and may still `preventDefault` — and becomes
98
+ * `location.replace(href)`: the same document load, with Back skipping the one-shot URL.
99
+ * That is the case of `replace` together with `reloadDocument`, or an app with no
100
+ * `linkComponent`. A modified click (new tab) and a `target` other than `_self` are left
101
+ * to the browser: they do not navigate THIS history. Without `replace`, `onClick` comes
102
+ * back untouched.
103
+ * @internal
104
+ */
105
+ declare function replacingClick(onClick: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined, href: string, replace: boolean | undefined, target?: string): ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;
106
+ /**
107
+ * What a ROUTER link is handed for `replace`: `{ replace: true }` when asked, else
108
+ * nothing at all — so a provider link that spreads its props onto a DOM `<a>` never
109
+ * receives an unknown attribute from a link that did not ask (see `KitLinkProps.replace`).
110
+ * @internal
111
+ */
112
+ declare function routerLinkNavigation(replace: boolean | undefined): {
113
+ replace?: true;
114
+ };
91
115
  /**
92
116
  * Draws `props` through `render` as a component of its own, so a router link's hooks
93
117
  * belong to it and not to the kit component calling it — for the kit components that
@@ -98,13 +122,32 @@ declare function RenderedKitLink<P>({ render, props }: {
98
122
  render: (props: P) => ReactElement;
99
123
  props: P;
100
124
  }): ReactElement<unknown, string | react.JSXElementConstructor<any>>;
101
- /** `brand` (default) for a link in running text, `muted` for footer and meta links
102
- * that should not compete with the content, `danger` for a destructive one ("Leave
103
- * group"), `inherit` for a link that takes its surroundings' colour. */
104
- type TextLinkTone = "brand" | "muted" | "danger" | "inherit";
105
- /** `hover` (default): underlined under the pointer — the idiom all three apps draw.
106
- * `always` for a link inside prose, where colour alone must not be the only mark
107
- * (WCAG 1.4.1). `none` where the context already says "link" (a footer nav). */
125
+ /**
126
+ * `brand` (default) for a link in running text, `muted` for footer and meta links
127
+ * that should not compete with the content, `danger` for a destructive one ("Leave
128
+ * group"), `inherit` for a link that takes its surroundings' colour.
129
+ *
130
+ * `primary` and `secondary` are the body and the secondary text colour, UNDERLINED
131
+ * (keksdose F3): a link that must read as part of the text around it — a name in a
132
+ * list row, a reference in a card's meta line — where `brand` repaints it in the accent
133
+ * and `muted` is a step too light to read as content. `secondary` darkens to the body
134
+ * colour under the pointer, as `muted` does; `primary` has nowhere darker to go, so its
135
+ * underline thickens instead.
136
+ *
137
+ * `warning` is the kit's `--warning` text colour, underlined (kastlan 46): a link inside
138
+ * a `<Tone tone="warning">` sentence or a warning banner, which `brand` would paint in a
139
+ * second hue and `inherit` would leave indistinguishable from the sentence. Like
140
+ * `primary`, it keeps its colour on hover and thickens the underline.
141
+ *
142
+ * The three colours that sit IN the text default to `underline="always"`: with the
143
+ * colour of their surroundings, the underline is the only thing that says "link"
144
+ * (WCAG 1.4.1). An explicit `underline` still wins.
145
+ */
146
+ type TextLinkTone = "brand" | "muted" | "danger" | "inherit" | "primary" | "secondary" | "warning";
147
+ /** `hover` (the default for `brand`, `muted`, `danger`, `inherit`): underlined under
148
+ * the pointer — the idiom all three apps draw. `always` (the default for `primary`,
149
+ * `secondary`, `warning`) for a link inside prose, where colour alone must not be the
150
+ * only mark (WCAG 1.4.1). `none` where the context already says "link" (a footer nav). */
108
151
  type TextLinkUnderline = "hover" | "always" | "none";
109
152
  /** The `aria-current` token. `true` on {@link TextLinkProps.current} means `page`. */
110
153
  type TextLinkCurrent = "page" | "step" | "location" | "date" | "time" | "true";
@@ -121,6 +164,9 @@ interface TextLinkRenderProps {
121
164
  "aria-current"?: TextLinkCurrent;
122
165
  id?: string;
123
166
  title?: string;
167
+ /** Present, as `true`, only when the link was given `replace` — see
168
+ * `KitLinkProps.replace`. Map it to your router's replace; never onto a DOM `<a>`. */
169
+ replace?: boolean;
124
170
  [key: `aria-${string}`]: string | boolean | number | undefined;
125
171
  [key: `data-${string}`]: unknown;
126
172
  }
@@ -129,8 +175,24 @@ interface TextLinkProps extends Omit<ComponentPropsWithoutRef<"a">, "href" | "ch
129
175
  children: ReactNode;
130
176
  /** Default `brand`. */
131
177
  tone?: TextLinkTone;
132
- /** Default `hover`. */
178
+ /** Default `always` for `primary`, `secondary` and `warning`, else `hover`. */
133
179
  underline?: TextLinkUnderline;
180
+ /**
181
+ * Navigate by replacing the current history entry, so Back does not return to this
182
+ * URL — keksdose F1, a one-shot URL (a confirmation landing, a `?done=1` hop). Handed
183
+ * to the router link as `replace` (see `KitLinkProps.replace` for mapping it); on a
184
+ * plain `<a>` (no `linkComponent`, or `reloadDocument`) a plain click becomes
185
+ * `location.replace(href)`. Ignored on an `external` link, which opens a new tab.
186
+ */
187
+ replace?: boolean;
188
+ /**
189
+ * A plain `<a>` for an in-app `href`: the browser loads the whole document instead of
190
+ * the router swapping the view — keksdose F1, a route served outside the SPA (a file
191
+ * download, a server-rendered page, a logout that must drop every in-memory cache).
192
+ * Wins over `renderLink` and the provider's `linkComponent`: it is the caller saying
193
+ * "not the router" for this one link.
194
+ */
195
+ reloadDocument?: boolean;
134
196
  /**
135
197
  * The link leaves the app: a plain `<a target="_blank" rel="noopener noreferrer">`
136
198
  * (never the router's), an external-link mark after the text (mirrored in RTL), and
@@ -171,6 +233,6 @@ interface TextLinkProps extends Omit<ComponentPropsWithoutRef<"a">, "href" | "ch
171
233
  * on the text's baseline at the text's size, so they scale with whatever type the link
172
234
  * is set in. The focus ring is an outline, which follows every line of a wrapped link.
173
235
  */
174
- declare function TextLink({ href, children, tone, underline, external, stopPropagation, current, icon: Icon, renderLink, className, onClick, onKeyDown, ref, ...rest }: TextLinkProps): react.JSX.Element;
236
+ declare function TextLink({ href, children, tone, underline: underlineProp, external, replace, reloadDocument, stopPropagation, current, icon: Icon, renderLink, className, onClick, onKeyDown, ref, ...rest }: TextLinkProps): react.JSX.Element;
175
237
 
176
- export { RenderedKitLink, TextLink, type TextLinkCurrent, type TextLinkProps, type TextLinkRenderProps, type TextLinkTone, type TextLinkUnderline, isExternalHref, isInPageAnchor, isRoutableHref, pickLinkRenderer };
238
+ export { RenderedKitLink, TextLink, type TextLinkCurrent, type TextLinkProps, type TextLinkRenderProps, type TextLinkTone, type TextLinkUnderline, isExternalHref, isInPageAnchor, isRoutableHref, pickLinkRenderer, replacingClick, routerLinkNavigation };
@@ -17,6 +17,21 @@ function pickLinkRenderer(own, kitLink, href) {
17
17
  if (!kitLink || href === void 0 || !isRoutableHref(href)) return void 0;
18
18
  return kitLink;
19
19
  }
20
+ function isPlainNavigationClick(event) {
21
+ return !event.defaultPrevented && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
22
+ }
23
+ function replacingClick(onClick, href, replace, target) {
24
+ if (!replace || target !== void 0 && target !== "" && target !== "_self") return onClick;
25
+ return (event) => {
26
+ onClick?.(event);
27
+ if (!isPlainNavigationClick(event)) return;
28
+ event.preventDefault();
29
+ window.location.replace(href);
30
+ };
31
+ }
32
+ function routerLinkNavigation(replace) {
33
+ return replace ? { replace: true } : {};
34
+ }
20
35
  function RenderedKitLink({ render, props }) {
21
36
  return render(props);
22
37
  }
@@ -24,8 +39,12 @@ const TONE = {
24
39
  brand: "text-[var(--brand)] hover:text-[var(--brand-hover)]",
25
40
  muted: "text-[var(--text-muted)] hover:text-[var(--text-primary)]",
26
41
  danger: "text-[var(--danger)] hover:text-[var(--danger-hover)]",
27
- inherit: ""
42
+ inherit: "",
43
+ primary: "text-[var(--text-primary)] hover:decoration-2",
44
+ secondary: "text-[var(--text-secondary)] hover:text-[var(--text-primary)]",
45
+ warning: "text-[var(--warning)] hover:decoration-2"
28
46
  };
47
+ const UNDERLINED_BY_DEFAULT = /* @__PURE__ */ new Set(["primary", "secondary", "warning"]);
29
48
  const UNDERLINE = {
30
49
  hover: "no-underline hover:underline",
31
50
  always: "underline",
@@ -35,8 +54,10 @@ function TextLink({
35
54
  href,
36
55
  children,
37
56
  tone = "brand",
38
- underline = "hover",
57
+ underline: underlineProp,
39
58
  external = false,
59
+ replace,
60
+ reloadDocument = false,
40
61
  stopPropagation = false,
41
62
  current,
42
63
  icon: Icon,
@@ -49,6 +70,7 @@ function TextLink({
49
70
  }) {
50
71
  const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
51
72
  const kitLink = useKitLink();
73
+ const underline = underlineProp ?? (UNDERLINED_BY_DEFAULT.has(tone) ? "always" : "hover");
52
74
  const ariaCurrent = current === true ? "page" : current === false ? void 0 : current;
53
75
  const look = cn(
54
76
  "rounded-sm underline-offset-2 transition-colors",
@@ -71,26 +93,37 @@ function TextLink({
71
93
  ] })
72
94
  ] })
73
95
  ] });
96
+ const handleClick = stopPropagation ? (event) => {
97
+ event.stopPropagation();
98
+ onClick?.(event);
99
+ } : onClick;
74
100
  const props = {
75
101
  ...rest,
76
102
  ref,
77
103
  href,
78
104
  className: look,
79
105
  "aria-current": ariaCurrent,
80
- onClick: stopPropagation ? (event) => {
81
- event.stopPropagation();
82
- onClick?.(event);
83
- } : onClick,
106
+ onClick: handleClick,
84
107
  onKeyDown: stopPropagation ? (event) => {
85
108
  if (event.key === "Enter") event.stopPropagation();
86
109
  onKeyDown?.(event);
87
110
  } : onKeyDown,
88
111
  children: body
89
112
  };
90
- const render = external ? void 0 : pickLinkRenderer(renderLink, kitLink, href);
91
- if (render) return /* @__PURE__ */ jsx(RenderedTextLink, { render, ...props });
113
+ const render = external || reloadDocument ? void 0 : pickLinkRenderer(renderLink, kitLink, href);
114
+ if (render) return /* @__PURE__ */ jsx(RenderedTextLink, { render, ...props, ...routerLinkNavigation(replace) });
115
+ const plainClick = external ? handleClick : replacingClick(handleClick, href, replace, rest.target);
92
116
  const { children: content, ...anchor } = props;
93
- return /* @__PURE__ */ jsx("a", { ...anchor, ...external ? { target: "_blank", rel: "noopener noreferrer" } : null, children: content });
117
+ return /* @__PURE__ */ jsx(
118
+ "a",
119
+ {
120
+ ...anchor,
121
+ href,
122
+ onClick: plainClick,
123
+ ...external ? { target: "_blank", rel: "noopener noreferrer" } : null,
124
+ children: content
125
+ }
126
+ );
94
127
  }
95
128
  function RenderedTextLink({
96
129
  render,
@@ -104,6 +137,8 @@ export {
104
137
  isExternalHref,
105
138
  isInPageAnchor,
106
139
  isRoutableHref,
107
- pickLinkRenderer
140
+ pickLinkRenderer,
141
+ replacingClick,
142
+ routerLinkNavigation
108
143
  };
109
144
  //# sourceMappingURL=text-link.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/text-link.tsx"],"sourcesContent":["import type { ComponentPropsWithoutRef, KeyboardEvent, MouseEvent, ReactElement, ReactNode, Ref } from \"react\";\nimport { ExternalLink } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { DEFAULT_COMMON_LABELS, useKitLabels, useKitLink } from \"../i18n/kit-labels\";\nimport type { KitLinkComponent } from \"../i18n/kit-labels\";\n\n/* ── Choosing what draws a link ──────────────────────────────────────────── */\n\n/**\n * An `href` that leaves the app: a scheme (`https:`, `mailto:`, `tel:`) or a\n * protocol-relative `//host`. A router's link is for paths inside the app, so the\n * provider's `linkComponent` is never handed one of these — they stay a plain `<a>`.\n *\n * NOT external, and so handed to the router link: a path (`/x`, `x`, `?q=1`) and the\n * hash-router form `#/x` — that IS a route in a `HashRouter` app, which maps it to\n * `to=\"/x\"`. A plain in-page anchor (`#section`) is not external either, but it is not\n * a route: see {@link isInPageAnchor}.\n */\nexport function isExternalHref(href: string): boolean {\n return /^(?:[a-z][a-z\\d+.-]*:|\\/\\/)/i.test(href);\n}\n\n/**\n * An `href` that only scrolls the current page: `#section` (or a bare `#`). The\n * hash-router form `#/x` is a ROUTE, not an anchor, and is not one of these. A router\n * link must not get an anchor — under a `HashRouter` `#section` would navigate to the\n * path `/section` — so every kit link draws it as a plain `<a>`.\n */\nexport function isInPageAnchor(href: string): boolean {\n return href.startsWith(\"#\") && !href.startsWith(\"#/\");\n}\n\n/**\n * Whether the provider's `linkComponent` (or a kit component's router fallback) draws\n * `href`: an in-app path, `#/x` included — not an external `href`\n * ({@link isExternalHref}) and not an in-page `#anchor` ({@link isInPageAnchor}).\n */\nexport function isRoutableHref(href: string): boolean {\n return !isExternalHref(href) && !isInPageAnchor(href);\n}\n\n/**\n * What draws a kit link to `href`: the component's own `renderLink` when it was given\n * one (it always wins — the caller asked for it by name), else the\n * `<UiKitProvider linkComponent>` for a routable `href` ({@link isRoutableHref}), else\n * `undefined` — a plain `<a>`. The one rule every kit link follows: `https:` /\n * `mailto:` / `//host` and `#section` stay plain anchors; `/x`, `x` and a hash-router\n * `#/x` go to the router link. Every kit link props type is a subset of the anchor\n * attributes `KitLinkProps` describes, which is what makes the cast sound.\n * @internal Shared by the kit's link-bearing components; not part of the barrel.\n */\nexport function pickLinkRenderer<P>(\n own: ((props: P) => ReactElement) | undefined,\n kitLink: KitLinkComponent | undefined,\n href: string | undefined,\n): ((props: P) => ReactElement) | undefined {\n if (own) return own;\n if (!kitLink || href === undefined || !isRoutableHref(href)) return undefined;\n return kitLink as unknown as (props: P) => ReactElement;\n}\n\n/**\n * Draws `props` through `render` as a component of its own, so a router link's hooks\n * belong to it and not to the kit component calling it — for the kit components that\n * call their own `renderLink` inline and reach the provider's link through here.\n * @internal\n */\nexport function RenderedKitLink<P>({ render, props }: { render: (props: P) => ReactElement; props: P }) {\n return render(props);\n}\n\n/* ── TextLink ─────────────────────────────────────────────────────────────── */\n\n/** `brand` (default) for a link in running text, `muted` for footer and meta links\n * that should not compete with the content, `danger` for a destructive one (\"Leave\n * group\"), `inherit` for a link that takes its surroundings' colour. */\nexport type TextLinkTone = \"brand\" | \"muted\" | \"danger\" | \"inherit\";\n\n/** `hover` (default): underlined under the pointer — the idiom all three apps draw.\n * `always` for a link inside prose, where colour alone must not be the only mark\n * (WCAG 1.4.1). `none` where the context already says \"link\" (a footer nav). */\nexport type TextLinkUnderline = \"hover\" | \"always\" | \"none\";\n\n/** The `aria-current` token. `true` on {@link TextLinkProps.current} means `page`. */\nexport type TextLinkCurrent = \"page\" | \"step\" | \"location\" | \"date\" | \"time\" | \"true\";\n\n/** What {@link TextLinkProps.renderLink} (and the provider's `linkComponent`) is\n * handed. Spread it onto your router's link — `({ href, ...p }) => <Link to={href} {...p} />`. */\nexport interface TextLinkRenderProps {\n href: string;\n /** The link's look — keep it, or the tone, underline and focus ring go. */\n className: string;\n children: ReactNode;\n ref?: Ref<HTMLAnchorElement>;\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;\n onKeyDown?: (event: KeyboardEvent<HTMLAnchorElement>) => void;\n \"aria-current\"?: TextLinkCurrent;\n id?: string;\n title?: string;\n [key: `aria-${string}`]: string | boolean | number | undefined;\n [key: `data-${string}`]: unknown;\n}\n\nexport interface TextLinkProps\n extends Omit<ComponentPropsWithoutRef<\"a\">, \"href\" | \"children\" | \"aria-current\" | \"onClick\" | \"onKeyDown\"> {\n href: string;\n children: ReactNode;\n /** Default `brand`. */\n tone?: TextLinkTone;\n /** Default `hover`. */\n underline?: TextLinkUnderline;\n /**\n * The link leaves the app: a plain `<a target=\"_blank\" rel=\"noopener noreferrer\">`\n * (never the router's), an external-link mark after the text (mirrored in RTL), and\n * \"opens in a new tab\" (`common.opensInNewTab`) read after it — the mark says it\n * only to the eye. kastlan's BWO / BFS source links (rent-increase-calculator-page).\n */\n external?: boolean;\n /**\n * Keep the click (and the Enter that activates the link) from reaching an ancestor —\n * a link in a DataTable row with `onRowClick` goes to its own target instead of\n * running the row's action. kastlan's `CellLink` did this by hand.\n */\n stopPropagation?: boolean;\n /** Mark the link as the current one of a set — `true` is `aria-current=\"page\"`, the\n * legal footer's link to the page you are on. Drawn in semibold. */\n current?: boolean | TextLinkCurrent;\n /** A Lucide icon before the text, at the text's size — kastlan's \"← Back\" link. */\n icon?: LucideIcon;\n /** Your router's link for an in-app `href`. Default: the `<UiKitProvider\n * linkComponent>`, then a plain `<a>`. Ignored on an `external` link. */\n renderLink?: (props: TextLinkRenderProps) => ReactElement;\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;\n onKeyDown?: (event: KeyboardEvent<HTMLAnchorElement>) => void;\n ref?: Ref<HTMLAnchorElement>;\n}\n\nconst TONE: Record<TextLinkTone, string> = {\n brand: \"text-[var(--brand)] hover:text-[var(--brand-hover)]\",\n muted: \"text-[var(--text-muted)] hover:text-[var(--text-primary)]\",\n danger: \"text-[var(--danger)] hover:text-[var(--danger-hover)]\",\n inherit: \"\",\n};\n\nconst UNDERLINE: Record<TextLinkUnderline, string> = {\n hover: \"no-underline hover:underline\",\n always: \"underline\",\n none: \"no-underline\",\n};\n\n/**\n * The one inline link: a real `<a href>` (middle click, \"open in new tab\", link\n * semantics) through the app's router for an in-app path, in one of four tones.\n *\n * kastlan draws this link a dozen ways by hand — `EntityLink` and `CellLink` (text-primary,\n * hover underline, one stopping the row click), the legal pages' back link and footer,\n * the feedback page's URL links, the calculator's external sources with a hand-placed\n * ↗ and no word for a screen reader — and the lease wizard's unit step (lease-unit-step)\n * used a raw `<a>` to an in-app route, which reloads the whole app. Here the router\n * link comes from `<UiKitProvider linkComponent>`, set once.\n *\n * Inline, not `inline-flex`: a link inside a sentence must wrap with it. The icons sit\n * on the text's baseline at the text's size, so they scale with whatever type the link\n * is set in. The focus ring is an outline, which follows every line of a wrapped link.\n */\nexport function TextLink({\n href,\n children,\n tone = \"brand\",\n underline = \"hover\",\n external = false,\n stopPropagation = false,\n current,\n icon: Icon,\n renderLink,\n className,\n onClick,\n onKeyDown,\n ref,\n ...rest\n}: TextLinkProps) {\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const kitLink = useKitLink();\n const ariaCurrent: TextLinkCurrent | undefined =\n current === true ? \"page\" : current === false ? undefined : current;\n\n const look = cn(\n \"rounded-sm underline-offset-2 transition-colors\",\n \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--brand)]\",\n TONE[tone],\n UNDERLINE[underline],\n ariaCurrent && \"font-semibold\",\n className,\n );\n\n const body = (\n <>\n {Icon && <Icon aria-hidden className=\"me-1 inline size-[1em] shrink-0 align-[-0.125em]\" />}\n {children}\n {external && (\n <>\n <ExternalLink aria-hidden className=\"ms-1 inline size-[0.85em] align-[-0.1em] rtl:-scale-x-100\" />\n {\" \"}\n <span className=\"sr-only\">({common.opensInNewTab})</span>\n </>\n )}\n </>\n );\n\n const props: TextLinkRenderProps = {\n ...(rest as Partial<TextLinkRenderProps>),\n ref,\n href,\n className: look,\n \"aria-current\": ariaCurrent,\n onClick: stopPropagation\n ? (event) => {\n event.stopPropagation();\n onClick?.(event);\n }\n : onClick,\n onKeyDown: stopPropagation\n ? (event) => {\n if (event.key === \"Enter\") event.stopPropagation();\n onKeyDown?.(event);\n }\n : onKeyDown,\n children: body,\n };\n\n const render = external ? undefined : pickLinkRenderer(renderLink, kitLink, href);\n if (render) return <RenderedTextLink render={render} {...props} />;\n const { children: content, ...anchor } = props;\n return (\n <a {...anchor} {...(external ? { target: \"_blank\", rel: \"noopener noreferrer\" } : null)}>\n {content}\n </a>\n );\n}\n\n/** Calls the link renderer as a component, so a router link's hooks are its own. */\nfunction RenderedTextLink({\n render,\n ...props\n}: TextLinkRenderProps & { render: (props: TextLinkRenderProps) => ReactElement }) {\n return render(props);\n}\n"],"mappings":";AAsMe,SAGP,UAHO,KAML,YANK;AArMf,SAAS,oBAAoB;AAE7B,SAAS,UAAU;AACnB,SAAS,uBAAuB,cAAc,kBAAkB;AAezD,SAAS,eAAe,MAAuB;AACpD,SAAO,+BAA+B,KAAK,IAAI;AACjD;AAQO,SAAS,eAAe,MAAuB;AACpD,SAAO,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,WAAW,IAAI;AACtD;AAOO,SAAS,eAAe,MAAuB;AACpD,SAAO,CAAC,eAAe,IAAI,KAAK,CAAC,eAAe,IAAI;AACtD;AAYO,SAAS,iBACd,KACA,SACA,MAC0C;AAC1C,MAAI,IAAK,QAAO;AAChB,MAAI,CAAC,WAAW,SAAS,UAAa,CAAC,eAAe,IAAI,EAAG,QAAO;AACpE,SAAO;AACT;AAQO,SAAS,gBAAmB,EAAE,QAAQ,MAAM,GAAqD;AACtG,SAAO,OAAO,KAAK;AACrB;AAoEA,MAAM,OAAqC;AAAA,EACzC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AACX;AAEA,MAAM,YAA+C;AAAA,EACnD,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AAiBO,SAAS,SAAS;AAAA,EACvB;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB;AAAA,EACA,MAAM;AAAA,EACN;AAAA,EACA;AAAA,EACA;AAAA,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,GAAmF;AACjF,SAAO,OAAO,KAAK;AACrB;","names":[]}
1
+ {"version":3,"sources":["../../src/components/text-link.tsx"],"sourcesContent":["import type { ComponentPropsWithoutRef, KeyboardEvent, MouseEvent, ReactElement, ReactNode, Ref } from \"react\";\nimport { ExternalLink } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\nimport { cn } from \"../lib/cn\";\nimport { DEFAULT_COMMON_LABELS, useKitLabels, useKitLink } from \"../i18n/kit-labels\";\nimport type { KitLinkComponent } from \"../i18n/kit-labels\";\n\n/* ── Choosing what draws a link ──────────────────────────────────────────── */\n\n/**\n * An `href` that leaves the app: a scheme (`https:`, `mailto:`, `tel:`) or a\n * protocol-relative `//host`. A router's link is for paths inside the app, so the\n * provider's `linkComponent` is never handed one of these — they stay a plain `<a>`.\n *\n * NOT external, and so handed to the router link: a path (`/x`, `x`, `?q=1`) and the\n * hash-router form `#/x` — that IS a route in a `HashRouter` app, which maps it to\n * `to=\"/x\"`. A plain in-page anchor (`#section`) is not external either, but it is not\n * a route: see {@link isInPageAnchor}.\n */\nexport function isExternalHref(href: string): boolean {\n return /^(?:[a-z][a-z\\d+.-]*:|\\/\\/)/i.test(href);\n}\n\n/**\n * An `href` that only scrolls the current page: `#section` (or a bare `#`). The\n * hash-router form `#/x` is a ROUTE, not an anchor, and is not one of these. A router\n * link must not get an anchor — under a `HashRouter` `#section` would navigate to the\n * path `/section` — so every kit link draws it as a plain `<a>`.\n */\nexport function isInPageAnchor(href: string): boolean {\n return href.startsWith(\"#\") && !href.startsWith(\"#/\");\n}\n\n/**\n * Whether the provider's `linkComponent` (or a kit component's router fallback) draws\n * `href`: an in-app path, `#/x` included — not an external `href`\n * ({@link isExternalHref}) and not an in-page `#anchor` ({@link isInPageAnchor}).\n */\nexport function isRoutableHref(href: string): boolean {\n return !isExternalHref(href) && !isInPageAnchor(href);\n}\n\n/**\n * What draws a kit link to `href`: the component's own `renderLink` when it was given\n * one (it always wins — the caller asked for it by name), else the\n * `<UiKitProvider linkComponent>` for a routable `href` ({@link isRoutableHref}), else\n * `undefined` — a plain `<a>`. The one rule every kit link follows: `https:` /\n * `mailto:` / `//host` and `#section` stay plain anchors; `/x`, `x` and a hash-router\n * `#/x` go to the router link. Every kit link props type is a subset of the anchor\n * attributes `KitLinkProps` describes, which is what makes the cast sound.\n * @internal Shared by the kit's link-bearing components; not part of the barrel.\n */\nexport function pickLinkRenderer<P>(\n own: ((props: P) => ReactElement) | undefined,\n kitLink: KitLinkComponent | undefined,\n href: string | undefined,\n): ((props: P) => ReactElement) | undefined {\n if (own) return own;\n if (!kitLink || href === undefined || !isRoutableHref(href)) return undefined;\n return kitLink as unknown as (props: P) => ReactElement;\n}\n\n/** The plain primary click a page navigates on — not a middle click, not ⌘ / Ctrl /\n * Shift / Alt (new tab, new window, download), and not one a handler already took. */\nfunction isPlainNavigationClick(event: MouseEvent<HTMLAnchorElement>): boolean {\n return (\n !event.defaultPrevented &&\n event.button === 0 &&\n !event.metaKey &&\n !event.ctrlKey &&\n !event.shiftKey &&\n !event.altKey\n );\n}\n\n/**\n * The `onClick` of a PLAIN `<a>` whose kit link was asked to `replace` (keksdose F1).\n *\n * A router link replaces the history entry itself (it is handed `replace`, see\n * {@link routerLinkNavigation}); a plain `<a>` has no attribute that says so, and the\n * browser's own navigation always pushes. So a plain click is taken over — the caller's\n * `onClick` runs first and may still `preventDefault` — and becomes\n * `location.replace(href)`: the same document load, with Back skipping the one-shot URL.\n * That is the case of `replace` together with `reloadDocument`, or an app with no\n * `linkComponent`. A modified click (new tab) and a `target` other than `_self` are left\n * to the browser: they do not navigate THIS history. Without `replace`, `onClick` comes\n * back untouched.\n * @internal\n */\nexport function replacingClick(\n onClick: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined,\n href: string,\n replace: boolean | undefined,\n target?: string,\n): ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined {\n if (!replace || (target !== undefined && target !== \"\" && target !== \"_self\")) return onClick;\n return (event) => {\n onClick?.(event);\n if (!isPlainNavigationClick(event)) return;\n event.preventDefault();\n window.location.replace(href);\n };\n}\n\n/**\n * What a ROUTER link is handed for `replace`: `{ replace: true }` when asked, else\n * nothing at all — so a provider link that spreads its props onto a DOM `<a>` never\n * receives an unknown attribute from a link that did not ask (see `KitLinkProps.replace`).\n * @internal\n */\nexport function routerLinkNavigation(replace: boolean | undefined): { replace?: true } {\n return replace ? { replace: true } : {};\n}\n\n/**\n * Draws `props` through `render` as a component of its own, so a router link's hooks\n * belong to it and not to the kit component calling it — for the kit components that\n * call their own `renderLink` inline and reach the provider's link through here.\n * @internal\n */\nexport function RenderedKitLink<P>({ render, props }: { render: (props: P) => ReactElement; props: P }) {\n return render(props);\n}\n\n/* ── TextLink ─────────────────────────────────────────────────────────────── */\n\n/**\n * `brand` (default) for a link in running text, `muted` for footer and meta links\n * that should not compete with the content, `danger` for a destructive one (\"Leave\n * group\"), `inherit` for a link that takes its surroundings' colour.\n *\n * `primary` and `secondary` are the body and the secondary text colour, UNDERLINED\n * (keksdose F3): a link that must read as part of the text around it — a name in a\n * list row, a reference in a card's meta line — where `brand` repaints it in the accent\n * and `muted` is a step too light to read as content. `secondary` darkens to the body\n * colour under the pointer, as `muted` does; `primary` has nowhere darker to go, so its\n * underline thickens instead.\n *\n * `warning` is the kit's `--warning` text colour, underlined (kastlan 46): a link inside\n * a `<Tone tone=\"warning\">` sentence or a warning banner, which `brand` would paint in a\n * second hue and `inherit` would leave indistinguishable from the sentence. Like\n * `primary`, it keeps its colour on hover and thickens the underline.\n *\n * The three colours that sit IN the text default to `underline=\"always\"`: with the\n * colour of their surroundings, the underline is the only thing that says \"link\"\n * (WCAG 1.4.1). An explicit `underline` still wins.\n */\nexport type TextLinkTone = \"brand\" | \"muted\" | \"danger\" | \"inherit\" | \"primary\" | \"secondary\" | \"warning\";\n\n/** `hover` (the default for `brand`, `muted`, `danger`, `inherit`): underlined under\n * the pointer — the idiom all three apps draw. `always` (the default for `primary`,\n * `secondary`, `warning`) for a link inside prose, where colour alone must not be the\n * only mark (WCAG 1.4.1). `none` where the context already says \"link\" (a footer nav). */\nexport type TextLinkUnderline = \"hover\" | \"always\" | \"none\";\n\n/** The `aria-current` token. `true` on {@link TextLinkProps.current} means `page`. */\nexport type TextLinkCurrent = \"page\" | \"step\" | \"location\" | \"date\" | \"time\" | \"true\";\n\n/** What {@link TextLinkProps.renderLink} (and the provider's `linkComponent`) is\n * handed. Spread it onto your router's link — `({ href, ...p }) => <Link to={href} {...p} />`. */\nexport interface TextLinkRenderProps {\n href: string;\n /** The link's look — keep it, or the tone, underline and focus ring go. */\n className: string;\n children: ReactNode;\n ref?: Ref<HTMLAnchorElement>;\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;\n onKeyDown?: (event: KeyboardEvent<HTMLAnchorElement>) => void;\n \"aria-current\"?: TextLinkCurrent;\n id?: string;\n title?: string;\n /** Present, as `true`, only when the link was given `replace` — see\n * `KitLinkProps.replace`. Map it to your router's replace; never onto a DOM `<a>`. */\n replace?: boolean;\n [key: `aria-${string}`]: string | boolean | number | undefined;\n [key: `data-${string}`]: unknown;\n}\n\nexport interface TextLinkProps\n extends Omit<ComponentPropsWithoutRef<\"a\">, \"href\" | \"children\" | \"aria-current\" | \"onClick\" | \"onKeyDown\"> {\n href: string;\n children: ReactNode;\n /** Default `brand`. */\n tone?: TextLinkTone;\n /** Default `always` for `primary`, `secondary` and `warning`, else `hover`. */\n underline?: TextLinkUnderline;\n /**\n * Navigate by replacing the current history entry, so Back does not return to this\n * URL — keksdose F1, a one-shot URL (a confirmation landing, a `?done=1` hop). Handed\n * to the router link as `replace` (see `KitLinkProps.replace` for mapping it); on a\n * plain `<a>` (no `linkComponent`, or `reloadDocument`) a plain click becomes\n * `location.replace(href)`. Ignored on an `external` link, which opens a new tab.\n */\n replace?: boolean;\n /**\n * A plain `<a>` for an in-app `href`: the browser loads the whole document instead of\n * the router swapping the view — keksdose F1, a route served outside the SPA (a file\n * download, a server-rendered page, a logout that must drop every in-memory cache).\n * Wins over `renderLink` and the provider's `linkComponent`: it is the caller saying\n * \"not the router\" for this one link.\n */\n reloadDocument?: boolean;\n /**\n * The link leaves the app: a plain `<a target=\"_blank\" rel=\"noopener noreferrer\">`\n * (never the router's), an external-link mark after the text (mirrored in RTL), and\n * \"opens in a new tab\" (`common.opensInNewTab`) read after it — the mark says it\n * only to the eye. kastlan's BWO / BFS source links (rent-increase-calculator-page).\n */\n external?: boolean;\n /**\n * Keep the click (and the Enter that activates the link) from reaching an ancestor —\n * a link in a DataTable row with `onRowClick` goes to its own target instead of\n * running the row's action. kastlan's `CellLink` did this by hand.\n */\n stopPropagation?: boolean;\n /** Mark the link as the current one of a set — `true` is `aria-current=\"page\"`, the\n * legal footer's link to the page you are on. Drawn in semibold. */\n current?: boolean | TextLinkCurrent;\n /** A Lucide icon before the text, at the text's size — kastlan's \"← Back\" link. */\n icon?: LucideIcon;\n /** Your router's link for an in-app `href`. Default: the `<UiKitProvider\n * linkComponent>`, then a plain `<a>`. Ignored on an `external` link. */\n renderLink?: (props: TextLinkRenderProps) => ReactElement;\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;\n onKeyDown?: (event: KeyboardEvent<HTMLAnchorElement>) => void;\n ref?: Ref<HTMLAnchorElement>;\n}\n\nconst TONE: Record<TextLinkTone, string> = {\n brand: \"text-[var(--brand)] hover:text-[var(--brand-hover)]\",\n muted: \"text-[var(--text-muted)] hover:text-[var(--text-primary)]\",\n danger: \"text-[var(--danger)] hover:text-[var(--danger-hover)]\",\n inherit: \"\",\n primary: \"text-[var(--text-primary)] hover:decoration-2\",\n secondary: \"text-[var(--text-secondary)] hover:text-[var(--text-primary)]\",\n warning: \"text-[var(--warning)] hover:decoration-2\",\n};\n\n/** The tones whose colour is their surroundings' — underlined by default; see\n * {@link TextLinkTone}. */\nconst UNDERLINED_BY_DEFAULT = new Set<TextLinkTone>([\"primary\", \"secondary\", \"warning\"]);\n\nconst UNDERLINE: Record<TextLinkUnderline, string> = {\n hover: \"no-underline hover:underline\",\n always: \"underline\",\n none: \"no-underline\",\n};\n\n/**\n * The one inline link: a real `<a href>` (middle click, \"open in new tab\", link\n * semantics) through the app's router for an in-app path, in one of four tones.\n *\n * kastlan draws this link a dozen ways by hand — `EntityLink` and `CellLink` (text-primary,\n * hover underline, one stopping the row click), the legal pages' back link and footer,\n * the feedback page's URL links, the calculator's external sources with a hand-placed\n * ↗ and no word for a screen reader — and the lease wizard's unit step (lease-unit-step)\n * used a raw `<a>` to an in-app route, which reloads the whole app. Here the router\n * link comes from `<UiKitProvider linkComponent>`, set once.\n *\n * Inline, not `inline-flex`: a link inside a sentence must wrap with it. The icons sit\n * on the text's baseline at the text's size, so they scale with whatever type the link\n * is set in. The focus ring is an outline, which follows every line of a wrapped link.\n */\nexport function TextLink({\n href,\n children,\n tone = \"brand\",\n underline: underlineProp,\n external = false,\n replace,\n reloadDocument = false,\n stopPropagation = false,\n current,\n icon: Icon,\n renderLink,\n className,\n onClick,\n onKeyDown,\n ref,\n ...rest\n}: TextLinkProps) {\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const kitLink = useKitLink();\n const underline = underlineProp ?? (UNDERLINED_BY_DEFAULT.has(tone) ? \"always\" : \"hover\");\n const ariaCurrent: TextLinkCurrent | undefined =\n current === true ? \"page\" : current === false ? undefined : current;\n\n const look = cn(\n \"rounded-sm underline-offset-2 transition-colors\",\n \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--brand)]\",\n TONE[tone],\n UNDERLINE[underline],\n ariaCurrent && \"font-semibold\",\n className,\n );\n\n const body = (\n <>\n {Icon && <Icon aria-hidden className=\"me-1 inline size-[1em] shrink-0 align-[-0.125em]\" />}\n {children}\n {external && (\n <>\n <ExternalLink aria-hidden className=\"ms-1 inline size-[0.85em] align-[-0.1em] rtl:-scale-x-100\" />\n {\" \"}\n <span className=\"sr-only\">({common.opensInNewTab})</span>\n </>\n )}\n </>\n );\n\n const handleClick: TextLinkRenderProps[\"onClick\"] = stopPropagation\n ? (event) => {\n event.stopPropagation();\n onClick?.(event);\n }\n : onClick;\n const props: TextLinkRenderProps = {\n ...(rest as Partial<TextLinkRenderProps>),\n ref,\n href,\n className: look,\n \"aria-current\": ariaCurrent,\n onClick: handleClick,\n onKeyDown: stopPropagation\n ? (event) => {\n if (event.key === \"Enter\") event.stopPropagation();\n onKeyDown?.(event);\n }\n : onKeyDown,\n children: body,\n };\n\n const render = external || reloadDocument ? undefined : pickLinkRenderer(renderLink, kitLink, href);\n if (render) return <RenderedTextLink render={render} {...props} {...routerLinkNavigation(replace)} />;\n // A plain `<a>` never gets `replace` as an attribute; asked for, it takes the click.\n const plainClick = external ? handleClick : replacingClick(handleClick, href, replace, rest.target);\n const { children: content, ...anchor } = props;\n return (\n <a\n {...anchor}\n href={href}\n onClick={plainClick}\n {...(external ? { target: \"_blank\", rel: \"noopener noreferrer\" } : null)}\n >\n {content}\n </a>\n );\n}\n\n/** Calls the link renderer as a component, so a router link's hooks are its own. */\nfunction RenderedTextLink({\n render,\n ...props\n}: TextLinkRenderProps & { render: (props: TextLinkRenderProps) => ReactElement }) {\n return render(props);\n}\n"],"mappings":";AA0Se,SAGP,UAHO,KAML,YANK;AAzSf,SAAS,oBAAoB;AAE7B,SAAS,UAAU;AACnB,SAAS,uBAAuB,cAAc,kBAAkB;AAezD,SAAS,eAAe,MAAuB;AACpD,SAAO,+BAA+B,KAAK,IAAI;AACjD;AAQO,SAAS,eAAe,MAAuB;AACpD,SAAO,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,WAAW,IAAI;AACtD;AAOO,SAAS,eAAe,MAAuB;AACpD,SAAO,CAAC,eAAe,IAAI,KAAK,CAAC,eAAe,IAAI;AACtD;AAYO,SAAS,iBACd,KACA,SACA,MAC0C;AAC1C,MAAI,IAAK,QAAO;AAChB,MAAI,CAAC,WAAW,SAAS,UAAa,CAAC,eAAe,IAAI,EAAG,QAAO;AACpE,SAAO;AACT;AAIA,SAAS,uBAAuB,OAA+C;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