@42-central/ui-react 0.20.1 → 0.22.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 (129) hide show
  1. package/dist/{chunk-45QRQKRC.js → chunk-3L5GLI67.js} +12 -8
  2. package/dist/chunk-3L5GLI67.js.map +1 -0
  3. package/dist/{chunk-BNWQ7IAZ.js → chunk-4FEOMQYR.js} +5 -5
  4. package/dist/{chunk-BNWQ7IAZ.js.map → chunk-4FEOMQYR.js.map} +1 -1
  5. package/dist/{chunk-POKLPMSB.js → chunk-D3JYDAUZ.js} +3 -3
  6. package/dist/{chunk-POKLPMSB.js.map → chunk-D3JYDAUZ.js.map} +1 -1
  7. package/dist/{chunk-KMZENCEP.js → chunk-DHJB4UJD.js} +4 -4
  8. package/dist/{chunk-KMZENCEP.js.map → chunk-DHJB4UJD.js.map} +1 -1
  9. package/dist/{chunk-IOYZC7SA.js → chunk-DJAXXLN6.js} +3 -3
  10. package/dist/{chunk-IOYZC7SA.js.map → chunk-DJAXXLN6.js.map} +1 -1
  11. package/dist/{chunk-3BXKTWWD.js → chunk-FB2G4LNH.js} +5 -5
  12. package/dist/{chunk-3BXKTWWD.js.map → chunk-FB2G4LNH.js.map} +1 -1
  13. package/dist/{chunk-E63VD25L.js → chunk-HQPU73WV.js} +4 -4
  14. package/dist/{chunk-E63VD25L.js.map → chunk-HQPU73WV.js.map} +1 -1
  15. package/dist/{chunk-RCF7HTG5.js → chunk-IRNF274I.js} +5 -5
  16. package/dist/chunk-IRNF274I.js.map +1 -0
  17. package/dist/{chunk-O5W3QWJ6.js → chunk-J44FJ7PH.js} +3 -3
  18. package/dist/{chunk-O5W3QWJ6.js.map → chunk-J44FJ7PH.js.map} +1 -1
  19. package/dist/{chunk-TWLJQE75.js → chunk-MRAJ45IM.js} +4 -4
  20. package/dist/{chunk-TWLJQE75.js.map → chunk-MRAJ45IM.js.map} +1 -1
  21. package/dist/{chunk-5HUEBSIS.js → chunk-N66NC6QK.js} +120 -24
  22. package/dist/chunk-N66NC6QK.js.map +1 -0
  23. package/dist/{chunk-SXNAUSEB.js → chunk-OZMSXYBX.js} +4 -4
  24. package/dist/{chunk-SXNAUSEB.js.map → chunk-OZMSXYBX.js.map} +1 -1
  25. package/dist/{chunk-LBAE6FP6.js → chunk-SZEOTXRZ.js} +4 -4
  26. package/dist/{chunk-LBAE6FP6.js.map → chunk-SZEOTXRZ.js.map} +1 -1
  27. package/dist/chunk-V6PY7C6S.js +18 -0
  28. package/dist/chunk-V6PY7C6S.js.map +1 -0
  29. package/dist/{chunk-MKKQE3TM.js → chunk-YPFSRZ3T.js} +4 -4
  30. package/dist/{chunk-MKKQE3TM.js.map → chunk-YPFSRZ3T.js.map} +1 -1
  31. package/dist/{chunk-NJPHZBLI.js → chunk-YWTOW7PZ.js} +5 -5
  32. package/dist/{chunk-NJPHZBLI.js.map → chunk-YWTOW7PZ.js.map} +1 -1
  33. package/dist/{chunk-VTDBWU6H.js → chunk-YZJUPYPO.js} +3 -3
  34. package/dist/{chunk-VTDBWU6H.js.map → chunk-YZJUPYPO.js.map} +1 -1
  35. package/dist/components/autocomplete/index.js +4 -3
  36. package/dist/components/autocomplete/index.js.map +1 -1
  37. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts +94 -0
  38. package/dist/components/calendar-heatmap/calendar-heatmap-grid.d.ts.map +1 -0
  39. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts +76 -0
  40. package/dist/components/calendar-heatmap/calendar-heatmap.d.ts.map +1 -0
  41. package/dist/components/calendar-heatmap/index.d.ts +2 -0
  42. package/dist/components/calendar-heatmap/index.d.ts.map +1 -0
  43. package/dist/components/calendar-heatmap/index.js +311 -0
  44. package/dist/components/calendar-heatmap/index.js.map +1 -0
  45. package/dist/components/camera/index.js +6 -5
  46. package/dist/components/clipboard/index.js +1 -1
  47. package/dist/components/code-block/chrome.js +4 -4
  48. package/dist/components/code-block/index.js +5 -5
  49. package/dist/components/combobox/index.js +4 -3
  50. package/dist/components/combobox-list/index.js +6 -5
  51. package/dist/components/data-table/index.js +16 -16
  52. package/dist/components/date-picker/index.js +7 -6
  53. package/dist/components/date-picker/index.js.map +1 -1
  54. package/dist/components/hover-card/hover-card.d.ts +44 -26
  55. package/dist/components/hover-card/hover-card.d.ts.map +1 -1
  56. package/dist/components/hover-card/index.js +35 -53
  57. package/dist/components/hover-card/index.js.map +1 -1
  58. package/dist/components/input/index.js +1 -1
  59. package/dist/components/input/input.d.ts.map +1 -1
  60. package/dist/components/menu/index.js +3 -3
  61. package/dist/components/menu/menu.d.ts +7 -5
  62. package/dist/components/menu/menu.d.ts.map +1 -1
  63. package/dist/components/multi-combobox-list/index.js +6 -5
  64. package/dist/components/multi-select/index.js +5 -4
  65. package/dist/components/multi-select/index.js.map +1 -1
  66. package/dist/components/navigation-progress/index.d.ts +2 -0
  67. package/dist/components/navigation-progress/index.d.ts.map +1 -0
  68. package/dist/components/navigation-progress/index.js +133 -0
  69. package/dist/components/navigation-progress/index.js.map +1 -0
  70. package/dist/components/navigation-progress/navigation-progress.d.ts +46 -0
  71. package/dist/components/navigation-progress/navigation-progress.d.ts.map +1 -0
  72. package/dist/components/number-input/index.js +4 -3
  73. package/dist/components/number-input/number-input.d.ts.map +1 -1
  74. package/dist/components/password-input/index.js +1 -1
  75. package/dist/components/photo-capture/index.js +6 -5
  76. package/dist/components/photo-capture/index.js.map +1 -1
  77. package/dist/components/pills-input/index.js +2 -2
  78. package/dist/components/pin-input/index.js +1 -1
  79. package/dist/components/popover/index.d.ts +1 -1
  80. package/dist/components/popover/index.d.ts.map +1 -1
  81. package/dist/components/popover/index.js +2 -1
  82. package/dist/components/popover/popover.d.ts +44 -29
  83. package/dist/components/popover/popover.d.ts.map +1 -1
  84. package/dist/components/schedule/index.js +2 -2
  85. package/dist/components/select/index.js +5 -4
  86. package/dist/components/spotlight/index.js +5 -4
  87. package/dist/components/spotlight/index.js.map +1 -1
  88. package/dist/components/tags-input/index.js +4 -3
  89. package/dist/components/tags-input/index.js.map +1 -1
  90. package/dist/components/text-input/index.js +1 -1
  91. package/dist/components/textarea/index.js +1 -1
  92. package/dist/components/time-input/index.js +5 -4
  93. package/dist/components/time-input/index.js.map +1 -1
  94. package/dist/components/tooltip/index.js +2 -2
  95. package/dist/components/tree-multi-select/index.js +5 -4
  96. package/dist/components/tree-multi-select/index.js.map +1 -1
  97. package/dist/components/tree-select/index.js +4 -3
  98. package/dist/components/tree-select/index.js.map +1 -1
  99. package/dist/index.js +2 -2
  100. package/dist/lib/placement.d.ts +42 -1
  101. package/dist/lib/placement.d.ts.map +1 -1
  102. package/dist/lib/slide-on-switch.d.ts +69 -0
  103. package/dist/lib/slide-on-switch.d.ts.map +1 -0
  104. package/package.json +1 -1
  105. package/src/as-child.contract.test.tsx +4 -0
  106. package/src/components/calendar-heatmap/calendar-heatmap-grid.test.ts +186 -0
  107. package/src/components/calendar-heatmap/calendar-heatmap-grid.ts +192 -0
  108. package/src/components/calendar-heatmap/calendar-heatmap.test.tsx +180 -0
  109. package/src/components/calendar-heatmap/calendar-heatmap.tsx +385 -0
  110. package/src/components/calendar-heatmap/index.ts +11 -0
  111. package/src/components/hover-card/hover-card.tsx +89 -167
  112. package/src/components/input/input.test.tsx +23 -0
  113. package/src/components/input/input.tsx +10 -6
  114. package/src/components/menu/menu.tsx +16 -9
  115. package/src/components/navigation-progress/index.ts +14 -0
  116. package/src/components/navigation-progress/navigation-progress.test.tsx +184 -0
  117. package/src/components/navigation-progress/navigation-progress.tsx +228 -0
  118. package/src/components/number-input/number-input.tsx +3 -4
  119. package/src/components/popover/index.ts +2 -0
  120. package/src/components/popover/popover.test.tsx +131 -0
  121. package/src/components/popover/popover.tsx +191 -53
  122. package/src/lib/placement.test.ts +37 -0
  123. package/src/lib/placement.ts +60 -1
  124. package/src/lib/slide-on-switch.ts +99 -0
  125. package/dist/chunk-45QRQKRC.js.map +0 -1
  126. package/dist/chunk-5HUEBSIS.js.map +0 -1
  127. package/dist/chunk-G52U24GR.js +0 -10
  128. package/dist/chunk-G52U24GR.js.map +0 -1
  129. package/dist/chunk-RCF7HTG5.js.map +0 -1
@@ -0,0 +1,385 @@
1
+ "use client"
2
+
3
+ import { ark, type HTMLArkProps } from "@ark-ui/react"
4
+ import { useLocaleContext } from "@ark-ui/react/locale"
5
+ import { useTooltipContext } from "@ark-ui/react/tooltip"
6
+ import { parseDate } from "@internationalized/date"
7
+ import { type CSSProperties, type KeyboardEvent, useMemo, useRef, useState } from "react"
8
+ import type { NoAsChild } from "../../lib/as-child"
9
+ import { cn } from "../../lib/cn"
10
+ import type { Color } from "../../lib/colors"
11
+ import { focusStyles } from "../../lib/focus-styles"
12
+ import { useLocale, useTimeZone } from "../../lib/intl"
13
+ import { props } from "../../lib/props"
14
+ import type { WithTestId } from "../../lib/test-id"
15
+ import { TEXT_COLOR_CLASSES } from "../../lib/typography-size"
16
+ import { useIsomorphicLayoutEffect } from "../../lib/use-isomorphic-layout-effect"
17
+ import { isNowPending, useNow } from "../../lib/use-now"
18
+ import type { FirstDayOfWeek } from "../schedule/schedule-types"
19
+ import { Tooltip } from "../tooltip"
20
+ import {
21
+ buildHeatmap,
22
+ type CalendarHeatmapDatum,
23
+ type CalendarHeatmapThresholds,
24
+ defaultRange,
25
+ type HeatmapDay,
26
+ intensity,
27
+ legendLevels,
28
+ nextHeatmapDay,
29
+ } from "./calendar-heatmap-grid"
30
+
31
+ export type { CalendarHeatmapDatum, CalendarHeatmapThresholds }
32
+
33
+ /**
34
+ * Everything the heatmap says that `Intl` can't: the grid's name, the legend's
35
+ * ends, and the sentence that names a day. Dates, weekdays, months and numbers
36
+ * are never here, they come from the resolved locale.
37
+ */
38
+ export type CalendarHeatmapTranslations = {
39
+ /** The grid's accessible name. */
40
+ label: string
41
+ /** A day's tooltip and accessible name. One sentence, so word order is the
42
+ * translation's own: "3 activités le lundi 26 octobre 2026". */
43
+ day: (details: { value: number; formattedValue: string; formattedDate: string }) => string
44
+ less: string
45
+ more: string
46
+ }
47
+
48
+ export const CALENDAR_HEATMAP_DEFAULT_TRANSLATIONS: CalendarHeatmapTranslations = {
49
+ label: "Activity",
50
+ day: ({ value, formattedValue, formattedDate }) =>
51
+ value === 0
52
+ ? `No activity on ${formattedDate}`
53
+ : `${formattedValue} ${value === 1 ? "activity" : "activities"} on ${formattedDate}`,
54
+ less: "Less",
55
+ more: "More",
56
+ }
57
+
58
+ export type CalendarHeatmapClassNames = {
59
+ grid?: string
60
+ cell?: string
61
+ legend?: string
62
+ tooltip?: string
63
+ }
64
+
65
+ export type CalendarHeatmapProps = Omit<NoAsChild<HTMLArkProps<"div">>, "color" | "children"> &
66
+ WithTestId & {
67
+ /** One entry per day, or per event: entries on the same day add up. */
68
+ data: readonly CalendarHeatmapDatum[]
69
+ /** The first and last day shown, both included. Defaults to the year ending today. */
70
+ range?: { start: Date; end: Date }
71
+ /** The ramp's palette. Inherits the nearest `data-color` when omitted. */
72
+ color?: Color
73
+ /**
74
+ * Lower bounds of levels 1 to 4, ascending: `[1, 5, 10, 20]` paints 1–4
75
+ * at level 1 and 20 or more at level 4. One to four of them, never more:
76
+ * past four steps a reader can't rank the shades. Defaults to the busiest
77
+ * day split into quarters.
78
+ */
79
+ thresholds?: CalendarHeatmapThresholds
80
+ /** The day each column starts on. Defaults to the locale's. */
81
+ startOfWeek?: FirstDayOfWeek
82
+ /** BCP-47 tag, or `"auto"`. Inherits `IntlProvider`'s when omitted. */
83
+ locale?: "auto" | (string & {})
84
+ /** IANA zone the data's instants are bucketed in, or `"auto"`. Inherits `IntlProvider`'s. */
85
+ timeZone?: "auto" | (string & {})
86
+ /** Makes days activatable, by click, Enter or Space. */
87
+ onDayClick?: (date: Date, value: number) => void
88
+ translations?: Partial<CalendarHeatmapTranslations>
89
+ classNames?: CalendarHeatmapClassNames
90
+ }
91
+
92
+ /**
93
+ * The four-step ramp, as whole class literals so Tailwind sees every one.
94
+ * Each step is the palette's solid at a growing strength, so any `color`,
95
+ * custom palettes included, makes its own ramp; step 0 is the kit's neutral
96
+ * no-data ground.
97
+ *
98
+ * Forced colors drop every background, so there intensity becomes size: a
99
+ * `Highlight` square that grows with the step inside a `CanvasText` frame.
100
+ */
101
+ const RAMP = [
102
+ "bg-brand-900/6 dark:bg-white/8",
103
+ "bg-(--c-solid)/30 before:inset-[35%]",
104
+ "bg-(--c-solid)/55 before:inset-[24%]",
105
+ "bg-(--c-solid)/80 before:inset-[12%]",
106
+ "bg-(--c-solid) before:inset-0",
107
+ ]
108
+
109
+ const swatch = cn(
110
+ "relative block aspect-square rounded-xxs",
111
+ "forced-colors:border forced-colors:border-[CanvasText] forced-colors:bg-[Canvas]",
112
+ "before:absolute before:hidden before:bg-[Highlight] forced-colors:before:block",
113
+ "forced-colors:forced-color-adjust-none",
114
+ )
115
+
116
+ /** `NumberFormat#formatRange` is ES2023, and the kit's `lib` stops at ES2022. */
117
+ type RangeNumberFormat = Intl.NumberFormat & { formatRange(start: number, end: number): string }
118
+
119
+ const caption = cn("text-xs leading-none", TEXT_COLOR_CLASSES.muted)
120
+
121
+ /**
122
+ * Figma's cell and gap, as custom properties so a consumer can resize the
123
+ * whole heatmap from `className`: `className="[--cell:10px] [--gap:3px]"`.
124
+ * The squares never stretch or shrink with the container; a range longer
125
+ * than it has room for scrolls instead, whatever its length.
126
+ */
127
+ const SIZE = "[--cell:0.75rem] [--gap:0.25rem]"
128
+
129
+ /** The month row, then seven day rows: shared by the grid and the weekday labels beside it, which is what lines them up. */
130
+ const TRACKS = "grid grid-rows-[auto_repeat(7,var(--cell))] gap-(--gap)"
131
+
132
+ /**
133
+ * A GitHub-style activity grid: one square per day, a column per week, the
134
+ * shade saying how much happened.
135
+ *
136
+ * <CalendarHeatmap data={commits} color="green" />
137
+ *
138
+ * It is a real ARIA grid: one tab stop, arrows move a day (↑↓) or a week
139
+ * (←→, mirrored in RTL), Home/End go along the row, Ctrl+Home/End to the
140
+ * ends, PageUp/PageDown a month. Every day is named in full ("3 activities on
141
+ * Monday, October 26, 2026"), and one shared tooltip follows hover and focus.
142
+ *
143
+ * The squares keep their size: a range wider than the container scrolls, the
144
+ * latest week in view and the weekday labels pinned beside it.
145
+ */
146
+ export const CalendarHeatmap = ({
147
+ data,
148
+ range,
149
+ color,
150
+ thresholds,
151
+ startOfWeek,
152
+ locale: localeProp,
153
+ timeZone: timeZoneProp,
154
+ onDayClick,
155
+ translations,
156
+ className,
157
+ classNames,
158
+ style,
159
+ testId,
160
+ ...rest
161
+ }: CalendarHeatmapProps) => {
162
+ const locale = useLocale(localeProp)
163
+ const timeZone = useTimeZone(timeZoneProp)
164
+ const { dir } = useLocaleContext()
165
+ const t = { ...CALENDAR_HEATMAP_DEFAULT_TRANSLATIONS, ...translations }
166
+
167
+ // The default range ends today, which the server can't know: until the
168
+ // client clock arrives the grid renders empty, so the markup still matches.
169
+ const now = useNow()
170
+ const pending = !range && isNowPending(now)
171
+ const { start, end } = range ?? defaultRange(now, timeZone)
172
+ // Compared by instant, so an inline `range={{ start, end }}` or the default
173
+ // range's minute tick doesn't rebuild an unchanged grid.
174
+ const startTime = start.getTime()
175
+ const endTime = end.getTime()
176
+
177
+ const layout = useMemo(
178
+ () =>
179
+ buildHeatmap({
180
+ data,
181
+ start: new Date(startTime),
182
+ end: new Date(endTime),
183
+ timeZone,
184
+ locale,
185
+ startOfWeek,
186
+ thresholds,
187
+ }),
188
+ [data, startTime, endTime, timeZone, locale, startOfWeek, thresholds],
189
+ )
190
+ const { weeks, months, weekdays, first, last } = layout
191
+ const levels = layout.thresholds.length
192
+
193
+ const format = useMemo(
194
+ () => ({
195
+ number: new Intl.NumberFormat(locale) as RangeNumberFormat,
196
+ date: new Intl.DateTimeFormat(locale, { dateStyle: "full", timeZone }),
197
+ month: new Intl.DateTimeFormat(locale, { month: "short", timeZone }),
198
+ weekday: new Intl.DateTimeFormat(locale, { weekday: "short", timeZone }),
199
+ weekdayLong: new Intl.DateTimeFormat(locale, { weekday: "long", timeZone }),
200
+ }),
201
+ [locale, timeZone],
202
+ )
203
+ const describe = (day: HeatmapDay) =>
204
+ t.day({
205
+ value: day.value,
206
+ formattedValue: format.number.format(day.value),
207
+ formattedDate: format.date.format(day.date),
208
+ })
209
+
210
+ // Roving tab stop: the last focused day, else the latest one.
211
+ const [focused, setFocused] = useState<string | null>(null)
212
+ const stop =
213
+ focused && focused >= first.toString() && focused <= last.toString() ? focused : last.toString()
214
+
215
+ const gridRef = useRef<HTMLDivElement>(null)
216
+ const scrollerRef = useRef<HTMLDivElement>(null)
217
+
218
+ // Open on the latest week when the grid is wider than its container. By
219
+ // delta, not to an absolute position, so RTL's negative scroll works too.
220
+ useIsomorphicLayoutEffect(() => {
221
+ const scroller = scrollerRef.current
222
+ if (!scroller) return
223
+ scroller.scrollLeft += dir === "rtl" ? -scroller.scrollWidth : scroller.scrollWidth
224
+ }, [dir, weeks.length, pending])
225
+
226
+ const onKeyDown = (event: KeyboardEvent<HTMLElement>, day: HeatmapDay, column: number) => {
227
+ if (onDayClick && (event.key === "Enter" || event.key === " ")) {
228
+ event.preventDefault()
229
+ onDayClick(day.date, day.value)
230
+ return
231
+ }
232
+ const target = nextHeatmapDay(event.key, parseDate(day.key), {
233
+ dir,
234
+ ctrlKey: event.ctrlKey || event.metaKey,
235
+ column,
236
+ columns: weeks.length,
237
+ first,
238
+ last,
239
+ })
240
+ if (!target) return
241
+ // The scroller would scroll on an unhandled arrow.
242
+ event.preventDefault()
243
+ const key = target.toString()
244
+ setFocused(key)
245
+ gridRef.current?.querySelector<HTMLElement>(`[data-date="${key}"]`)?.focus()
246
+ }
247
+
248
+ return (
249
+ <ark.div
250
+ data-color={color}
251
+ // As wide as the weeks need and no wider, so the legend ends where they
252
+ // do; capped at the container, past which the weeks scroll.
253
+ className={cn("flex w-fit max-w-full min-w-0 flex-col gap-3", SIZE, className)}
254
+ style={{ "--weeks": weeks.length, ...style } as CSSProperties}
255
+ {...props({ "data-testid": testId })}
256
+ {...rest}
257
+ >
258
+ <div className="flex">
259
+ {/* The weekday labels sit outside the scroller, so they stay in view
260
+ however far back the weeks are scrolled. Fixed tracks line them up
261
+ with the rows; the screen-reader row headers live in the grid. */}
262
+ <div aria-hidden className={cn(caption, TRACKS, "shrink-0 grid-cols-[auto] py-1 pe-2")}>
263
+ <span>&nbsp;</span>
264
+ {weekdays.map((weekday, row) => (
265
+ <span key={weekday.getTime()} className="flex items-center">
266
+ {/* Every other row, like a paper calendar: seven labels crowd. */}
267
+ {row % 2 === 1 && format.weekday.format(weekday)}
268
+ </span>
269
+ ))}
270
+ </div>
271
+
272
+ <Tooltip.Root openDelay={150} closeDelay={0}>
273
+ {/* Padded so the focus ring isn't clipped by the scroll edge. */}
274
+ <div ref={scrollerRef} className="min-w-0 overflow-x-auto p-1">
275
+ {/* biome-ignore lint/a11y/useSemanticElements: ARIA grid on divs, not a <table>: the cells are laid out on CSS grid tracks (rows are subgrids), and table elements lose their implicit semantics in some engines once their display changes. */}
276
+ <div
277
+ ref={gridRef}
278
+ role="grid"
279
+ aria-label={t.label}
280
+ aria-busy={pending || undefined}
281
+ className={cn(
282
+ TRACKS,
283
+ "w-max grid-cols-[repeat(var(--weeks),var(--cell))]",
284
+ classNames?.grid,
285
+ )}
286
+ >
287
+ {/* Each day's own name carries its date, so the month row is visual only. */}
288
+ <div aria-hidden className={cn(caption, "col-span-full grid grid-cols-subgrid")}>
289
+ <span>&nbsp;</span>
290
+ {!pending &&
291
+ months.map(({ column, date }) => (
292
+ <span
293
+ key={column}
294
+ className="row-start-1 whitespace-nowrap"
295
+ style={{ gridColumnStart: column + 1 }}
296
+ >
297
+ {format.month.format(date)}
298
+ </span>
299
+ ))}
300
+ </div>
301
+ {weekdays.map((weekday, row) => (
302
+ // biome-ignore lint/a11y/useSemanticElements lint/a11y/useFocusableInteractive: ARIA grid on divs, not a <table>: the cells are laid out on CSS grid tracks (rows are subgrids), and table elements lose their implicit semantics in some engines once their display changes; only cells take focus in the grid pattern.
303
+ <div
304
+ key={weekday.getTime()}
305
+ role="row"
306
+ className="col-span-full grid grid-cols-subgrid"
307
+ >
308
+ {/* biome-ignore lint/a11y/useSemanticElements lint/a11y/useFocusableInteractive: ARIA grid on divs, not a <table>: the cells are laid out on CSS grid tracks (rows are subgrids), and table elements lose their implicit semantics in some engines once their display changes; a header is read, not focused. */}
309
+ <div role="rowheader" className="sr-only">
310
+ {format.weekdayLong.format(weekday)}
311
+ </div>
312
+ {weeks.map((week, column) => {
313
+ const day = week[row]
314
+ // biome-ignore lint/suspicious/noArrayIndexKey lint/a11y/useSemanticElements lint/a11y/useFocusableInteractive: a padding slot has no date, so its column is its identity, and nothing to focus; ARIA grid on divs, not a <table>: the cells are laid out on CSS grid tracks (rows are subgrids), and table elements lose their implicit semantics in some engines once their display changes.
315
+ if (!day || pending) return <div key={column} role="gridcell" />
316
+ return (
317
+ <Tooltip.Trigger key={day.key} asChild value={day.key}>
318
+ {/* biome-ignore lint/a11y/useSemanticElements: ARIA grid on divs, not a <table>: the cells are laid out on CSS grid tracks (rows are subgrids), and table elements lose their implicit semantics in some engines once their display changes. */}
319
+ <div
320
+ role="gridcell"
321
+ tabIndex={day.key === stop ? 0 : -1}
322
+ // The tooltip repeats the day's own name, so it mustn't describe it too.
323
+ aria-describedby={undefined}
324
+ data-date={day.key}
325
+ data-level={day.level}
326
+ className={cn(
327
+ swatch,
328
+ RAMP[intensity(day.level, levels)],
329
+ focusStyles(),
330
+ // Focus scrolls a cell into view: leave room for its ring.
331
+ "scroll-m-1",
332
+ onDayClick && "cursor-pointer",
333
+ classNames?.cell,
334
+ )}
335
+ onFocus={() => setFocused(day.key)}
336
+ onKeyDown={(event) => onKeyDown(event, day, column)}
337
+ onClick={onDayClick && (() => onDayClick(day.date, day.value))}
338
+ >
339
+ <span className="sr-only">{describe(day)}</span>
340
+ </div>
341
+ </Tooltip.Trigger>
342
+ )
343
+ })}
344
+ </div>
345
+ ))}
346
+ </div>
347
+ </div>
348
+ <Tooltip.Content aria-hidden className={classNames?.tooltip}>
349
+ <DayTooltip weeks={weeks} describe={describe} />
350
+ </Tooltip.Content>
351
+ </Tooltip.Root>
352
+ </div>
353
+
354
+ <div className={cn(caption, "flex items-center justify-end gap-1", classNames?.legend)}>
355
+ <span className="me-1">{t.less}</span>
356
+ {legendLevels(layout.thresholds).map(({ level, min, max }) => (
357
+ <span key={level} className={cn(swatch, "size-(--cell)", RAMP[intensity(level, levels)])}>
358
+ <span className="sr-only">
359
+ {max === null
360
+ ? `${format.number.format(min)}+`
361
+ : max - min <= 1
362
+ ? format.number.format(min)
363
+ : // NFKC: server and browser ICU disagree on the dash's spacing.
364
+ format.number.formatRange(min, max - 1).normalize("NFKC")}
365
+ </span>
366
+ </span>
367
+ ))}
368
+ <span className="ms-1">{t.more}</span>
369
+ </div>
370
+ </ark.div>
371
+ )
372
+ }
373
+
374
+ /** The shared tooltip's text: whichever day's trigger it is showing for. */
375
+ const DayTooltip = ({
376
+ weeks,
377
+ describe,
378
+ }: {
379
+ weeks: (HeatmapDay | null)[][]
380
+ describe: (day: HeatmapDay) => string
381
+ }) => {
382
+ const { triggerValue } = useTooltipContext()
383
+ const day = weeks.flat().find((candidate) => candidate?.key === triggerValue)
384
+ return day ? describe(day) : null
385
+ }
@@ -0,0 +1,11 @@
1
+ "use client"
2
+
3
+ export {
4
+ CALENDAR_HEATMAP_DEFAULT_TRANSLATIONS,
5
+ CalendarHeatmap,
6
+ type CalendarHeatmapClassNames,
7
+ type CalendarHeatmapDatum,
8
+ type CalendarHeatmapProps,
9
+ type CalendarHeatmapThresholds,
10
+ type CalendarHeatmapTranslations,
11
+ } from "./calendar-heatmap"