@dinachi/cli 1.1.0 → 1.3.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 (45) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/index.js +244 -72
  3. package/package.json +5 -1
  4. package/templates/agent/agent.tsx +35 -18
  5. package/templates/alert/alert.tsx +345 -0
  6. package/templates/alert/index.ts +16 -0
  7. package/templates/ask-bar/ask-bar.tsx +1061 -0
  8. package/templates/ask-bar/index.ts +1 -0
  9. package/templates/autocomplete/autocomplete.tsx +0 -1
  10. package/templates/breadcrumb/breadcrumb.tsx +606 -0
  11. package/templates/breadcrumb/index.ts +9 -0
  12. package/templates/calendar/calendar.tsx +1155 -0
  13. package/templates/calendar/index.ts +15 -0
  14. package/templates/combobox/combobox.tsx +0 -1
  15. package/templates/command-items/command-items.tsx +69 -0
  16. package/templates/command-items/index.ts +1 -0
  17. package/templates/command-palette/command-palette.tsx +954 -0
  18. package/templates/command-palette/index.ts +1 -0
  19. package/templates/comparison-table/comparison-table.tsx +540 -0
  20. package/templates/comparison-table/index.ts +15 -0
  21. package/templates/data-table/data-table.tsx +2077 -0
  22. package/templates/data-table/index.ts +14 -0
  23. package/templates/date-picker/date-picker.tsx +527 -0
  24. package/templates/date-picker/index.ts +2 -0
  25. package/templates/date-range-picker/date-range-picker.tsx +504 -0
  26. package/templates/date-range-picker/index.ts +2 -0
  27. package/templates/detail-list/detail-list.tsx +419 -0
  28. package/templates/detail-list/index.ts +12 -0
  29. package/templates/heat-table/heat-table.tsx +613 -0
  30. package/templates/heat-table/index.ts +9 -0
  31. package/templates/menu/menu.tsx +8 -3
  32. package/templates/month-picker/index.ts +1 -0
  33. package/templates/month-picker/month-picker.tsx +351 -0
  34. package/templates/omnibar/index.ts +1 -0
  35. package/templates/omnibar/omnibar.tsx +1009 -0
  36. package/templates/pagination/index.ts +8 -0
  37. package/templates/pagination/pagination.tsx +389 -0
  38. package/templates/table/index.ts +13 -0
  39. package/templates/table/table.tsx +265 -0
  40. package/templates/time-slots/index.ts +1 -0
  41. package/templates/time-slots/time-slots.tsx +589 -0
  42. package/templates/week-strip/index.ts +1 -0
  43. package/templates/week-strip/week-strip.tsx +329 -0
  44. package/templates/year-view/index.ts +1 -0
  45. package/templates/year-view/year-view.tsx +362 -0
@@ -0,0 +1,8 @@
1
+ export {
2
+ Pagination,
3
+ pageItems,
4
+ type PaginationProps,
5
+ type PaginationChangeDetails,
6
+ type PaginationChangeReason,
7
+ type PageItem,
8
+ } from "./pagination"
@@ -0,0 +1,389 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { ChevronLeft, ChevronRight } from "lucide-react"
5
+ import { cn } from "@/lib/utils"
6
+ import { Button } from "@/components/ui/button"
7
+ import { changeAsAgent, useAgentControl, useAgentState, useHasAgent, useMergedRef } from "@/components/ui/agent"
8
+
9
+ export type PageItem = number | "gap"
10
+
11
+ /**
12
+ * The pages a bar shows. Past seven pages it always returns seven slots, so the bar keeps
13
+ * its width and the arrows stay under the pointer as the page changes.
14
+ */
15
+ export function pageItems(page: number, count: number): PageItem[] {
16
+ const total = Math.max(0, Math.floor(count))
17
+ if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1)
18
+ const p = clampPage(page, total)
19
+ if (p <= 4) return [1, 2, 3, 4, 5, "gap", total]
20
+ if (p >= total - 3) return [1, "gap", total - 4, total - 3, total - 2, total - 1, total]
21
+ return [1, "gap", p - 1, p, p + 1, "gap", total]
22
+ }
23
+
24
+ function clampPage(page: number, count: number) {
25
+ const n = Number.isFinite(page) ? Math.round(page) : 1
26
+ return Math.min(Math.max(1, n), Math.max(1, count))
27
+ }
28
+
29
+ export type PaginationChangeReason = "page-press" | "previous" | "next" | "jump" | "none"
30
+
31
+ export interface PaginationChangeDetails {
32
+ reason: PaginationChangeReason | (string & {})
33
+ event?: Event
34
+ isCanceled: boolean
35
+ cancel(): void
36
+ }
37
+
38
+ function changeDetails(reason: PaginationChangeReason, event?: Event): PaginationChangeDetails {
39
+ const details: PaginationChangeDetails = {
40
+ reason,
41
+ event,
42
+ isCanceled: false,
43
+ cancel() {
44
+ details.isCanceled = true
45
+ },
46
+ }
47
+ return details
48
+ }
49
+
50
+ export interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, "onChange" | "defaultValue"> {
51
+ /** How many pages there are. Below one, the bar still shows page 1. */
52
+ count: number
53
+ /** The current page, from 1. */
54
+ page?: number
55
+ defaultPage?: number
56
+ /** Runs on every change, for people and agents. `details.cancel()` refuses it. */
57
+ onPageChange?: (page: number, details: PaginationChangeDetails) => void
58
+ /** Each page's URL. Pages then render as links, through Button's `render`. */
59
+ getHref?: (page: number) => string
60
+ /** `full` shows page numbers. `compact` reads Page 6 of 25, with the number as the jump field. */
61
+ variant?: "full" | "compact"
62
+ /** `lg` makes every target 44px, for touch. */
63
+ size?: "default" | "lg"
64
+ disabled?: boolean
65
+ }
66
+
67
+ const sizes = {
68
+ default: { field: "h-8 w-[3.25rem] text-[13px]", text: "text-[13px]", arrow: "h-8 w-8" },
69
+ lg: { field: "h-11 w-[5.25rem] rounded-xl text-[17px]", text: "text-[15px]", arrow: "h-11 w-11 rounded-xl border border-border text-foreground" },
70
+ }
71
+
72
+ /**
73
+ * Pages of a list: prev and next, the pages near the current one, and gaps that open a
74
+ * field to jump anywhere. The current page is the only filled shape.
75
+ */
76
+ const Pagination = React.forwardRef<HTMLElement, PaginationProps>((props, ref) => {
77
+ const {
78
+ count: countProp,
79
+ page: pageProp,
80
+ defaultPage = 1,
81
+ onPageChange,
82
+ getHref,
83
+ variant = "full",
84
+ size = "default",
85
+ disabled,
86
+ className,
87
+ "aria-label": ariaLabel = "Pagination",
88
+ ...rest
89
+ } = props
90
+ const hasAgent = useHasAgent()
91
+ const part = hasAgent ? "" : undefined
92
+ const count = Number.isFinite(countProp) ? Math.max(1, Math.floor(countProp)) : 1
93
+ const [raw, change] = useAgentState<number, PaginationChangeDetails>(pageProp, defaultPage, onPageChange)
94
+ const page = clampPage(raw, count)
95
+ const nav = React.useRef<HTMLElement | null>(null)
96
+ const navRef = useMergedRef(ref, nav)
97
+ const s = sizes[size]
98
+
99
+ // Which jump field is open: a gap's index, or the compact page number. A gap's index
100
+ // points at another slot once the page moves, so a new page closes it.
101
+ const [editing, setEditing] = React.useState<number | "current" | null>(null)
102
+ const [editingAt, setEditingAt] = React.useState(page)
103
+ if (editingAt !== page) {
104
+ setEditingAt(page)
105
+ if (editing !== null) setEditing(null)
106
+ }
107
+ // Where focus goes on the next render, once what had it is gone or disabled: the
108
+ // current page, or the gap a jump field was opened from.
109
+ const refocus = React.useRef<"current" | number | null>(null)
110
+
111
+ const go = (next: number, reason: PaginationChangeReason, event?: Event) => {
112
+ if (disabled || next === page || next < 1 || next > count) return false
113
+ const details = changeDetails(reason, event)
114
+ change(next, details)
115
+ return !details.isCanceled
116
+ }
117
+
118
+ // Pages with their own URL load it when the change comes from somewhere a link cannot.
119
+ const visit = (next: number) => {
120
+ if (getHref && typeof window !== "undefined") window.location.assign(getHref(next))
121
+ }
122
+
123
+ const pressLink = (next: number, reason: PaginationChangeReason) => (e: React.MouseEvent) => {
124
+ // A new tab or window leaves this page where it is.
125
+ if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
126
+ // A refused change keeps the browser where it is too, so the app can route it itself.
127
+ if (!go(next, reason, e.nativeEvent) && next !== page) e.preventDefault()
128
+ }
129
+
130
+ React.useLayoutEffect(() => {
131
+ const target = refocus.current
132
+ if (target === null) return
133
+ refocus.current = null
134
+ const el =
135
+ target === "current"
136
+ ? nav.current?.querySelector('[aria-current="page"], [data-slot="pagination-current"]')
137
+ : nav.current?.querySelectorAll('[data-slot="pagination-gap"]')[target]
138
+ ;(el as HTMLElement | null | undefined)?.focus()
139
+ })
140
+
141
+ /* ---- agent ---- */
142
+ const whole = (value: unknown) => Number(String(value ?? "").trim() || NaN)
143
+ const to = (next: number) => {
144
+ if (next < 1 || next > count) return `Page ${next} is out of range. Pages run from 1 to ${count}.`
145
+ if (next === page) return undefined
146
+ return changeAsAgent((n: number, details: PaginationChangeDetails) => change(n, details), next) ?? visit(next)
147
+ }
148
+ const step = (steps: unknown, dir: 1 | -1) => {
149
+ const n = whole(steps)
150
+ return Number.isInteger(n) ? to(page + dir * n) : `"${String(steps)}" is not a whole number of pages.`
151
+ }
152
+
153
+ useAgentControl(() => ({
154
+ kind: "number",
155
+ element: nav.current,
156
+ value: page,
157
+ min: 1,
158
+ max: count,
159
+ step: 1,
160
+ disabled,
161
+ actions: {
162
+ setValue: (wanted: unknown) => {
163
+ const n = whole(wanted)
164
+ return Number.isInteger(n) ? to(n) : `"${String(wanted)}" is not a page number.`
165
+ },
166
+ increment: (steps: unknown = 1) => step(steps, 1),
167
+ decrement: (steps: unknown = 1) => step(steps, -1),
168
+ },
169
+ }))
170
+
171
+ /* ---- parts ---- */
172
+ // `opener` is the gap a field came from, as its place among the gaps.
173
+ const field = (label: string, opener: number | "current") => (
174
+ <JumpField
175
+ key="jump"
176
+ label={label}
177
+ page={page}
178
+ count={count}
179
+ className={s.field}
180
+ part={part}
181
+ onDone={(n, event, returnFocus) => {
182
+ setEditing(null)
183
+ if (returnFocus) refocus.current = n === null ? opener : "current"
184
+ if (n !== null && go(n, "jump", event)) visit(n)
185
+ }}
186
+ />
187
+ )
188
+
189
+ const arrow = (dir: -1 | 1) => {
190
+ const target = page + dir
191
+ const off = disabled || target < 1 || target > count
192
+ const href = getHref && !off ? getHref(target) : undefined
193
+ const reason = dir < 0 ? "previous" : "next"
194
+ return (
195
+ <Button
196
+ variant="ghost"
197
+ aria-label={dir < 0 ? "Previous page" : "Next page"}
198
+ data-slot={dir < 0 ? "pagination-previous" : "pagination-next"}
199
+ data-agent-part={part}
200
+ disabled={off}
201
+ render={href ? <a href={href} /> : undefined}
202
+ // Base UI names a non-button element a button; a link keeps its own role.
203
+ {...(href ? { role: undefined } : {})}
204
+ onClick={
205
+ href
206
+ ? pressLink(target, reason)
207
+ : (e: React.MouseEvent) => {
208
+ // The arrow is disabled at the end it reaches, which would drop focus.
209
+ if (go(target, reason, e.nativeEvent) && (target === 1 || target === count) && e.currentTarget === document.activeElement) {
210
+ refocus.current = "current"
211
+ }
212
+ }
213
+ }
214
+ className={cn("shrink-0 p-0 text-muted-foreground hover:text-foreground disabled:opacity-40", s.arrow)}
215
+ >
216
+ {dir < 0 ? <ChevronLeft className="size-4 rtl:rotate-180" aria-hidden /> : <ChevronRight className="size-4 rtl:rotate-180" aria-hidden />}
217
+ </Button>
218
+ )
219
+ }
220
+
221
+ // Every slot is as wide as the widest page number, so the bar never changes width.
222
+ const slot = { "--pagination-digits": String(count).length } as React.CSSProperties
223
+ const slotClass = cn(
224
+ "py-0 px-1.5 font-normal tabular-nums text-muted-foreground hover:text-foreground",
225
+ size === "lg"
226
+ ? "h-11 min-w-[max(2.75rem,calc(var(--pagination-digits)*1ch+0.75rem))] text-[15px]"
227
+ : "h-8 min-w-[max(2rem,calc(var(--pagination-digits)*1ch+0.75rem))] text-[13px]"
228
+ )
229
+
230
+ let middle: React.ReactNode
231
+ if (variant === "compact") {
232
+ middle =
233
+ editing === "current" ? (
234
+ field("Go to page", "current")
235
+ ) : (
236
+ <button
237
+ type="button"
238
+ data-slot="pagination-current"
239
+ data-agent-part={part}
240
+ aria-label={`Page ${page} of ${count}, go to page`}
241
+ disabled={disabled}
242
+ onClick={() => setEditing("current")}
243
+ className={cn(
244
+ "inline-block rounded-md px-2 tabular-nums transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
245
+ size === "lg" && "rounded-[10px] px-3",
246
+ s.text,
247
+ // Last, so merging in the text size cannot drop the line height that sets the target.
248
+ size === "lg" ? "h-11 leading-[2.75rem]" : "h-8 leading-8"
249
+ )}
250
+ >
251
+ Page{" "}
252
+ <b
253
+ className="inline-block text-center font-medium underline decoration-[color:color-mix(in_oklab,var(--foreground)_40%,transparent)] decoration-dotted underline-offset-4"
254
+ style={{ minWidth: `${String(count).length}ch` }}
255
+ >
256
+ {page}
257
+ </b>{" "}
258
+ of {count}
259
+ </button>
260
+ )
261
+ } else {
262
+ const items = pageItems(page, count)
263
+ middle = items.map((item, i) =>
264
+ item === "gap" ? (
265
+ editing === i ? (
266
+ field(`Page 1 to ${count}`, items.slice(0, i).filter((x) => x === "gap").length)
267
+ ) : (
268
+ <Button
269
+ key={`gap-${i}`}
270
+ variant="ghost"
271
+ data-slot="pagination-gap"
272
+ data-agent-part={part}
273
+ aria-label="Jump to a page"
274
+ disabled={disabled}
275
+ onClick={() => setEditing(i)}
276
+ style={slot}
277
+ className={cn(slotClass, "tracking-[1px]")}
278
+ >
279
+ …
280
+ </Button>
281
+ )
282
+ ) : (
283
+ <Button
284
+ // Keyed by slot, not page, so a shifting window changes the numbers in place
285
+ // instead of sliding the current page's fill across the row.
286
+ key={`page-${i}`}
287
+ variant="ghost"
288
+ data-slot="pagination-page"
289
+ data-agent-part={part}
290
+ aria-label={`Page ${item}`}
291
+ aria-current={item === page ? "page" : undefined}
292
+ disabled={disabled}
293
+ render={getHref && !disabled ? <a href={getHref(item)} /> : undefined}
294
+ {...(getHref && !disabled ? { role: undefined } : {})}
295
+ onClick={(e: React.MouseEvent) => {
296
+ // The slot pressed may show another page next render, so focus follows the page.
297
+ if (document.activeElement === e.currentTarget) refocus.current = "current"
298
+ if (getHref && !disabled) pressLink(item, "page-press")(e)
299
+ else go(item, "page-press", e.nativeEvent)
300
+ }}
301
+ style={slot}
302
+ className={cn(
303
+ slotClass,
304
+ "aria-[current=page]:bg-primary aria-[current=page]:font-medium aria-[current=page]:text-primary-foreground",
305
+ "aria-[current=page]:hover:bg-primary aria-[current=page]:hover:text-primary-foreground"
306
+ )}
307
+ >
308
+ {item}
309
+ </Button>
310
+ )
311
+ )
312
+ }
313
+
314
+ return (
315
+ <nav
316
+ {...rest}
317
+ ref={navRef}
318
+ aria-label={ariaLabel}
319
+ data-slot="pagination"
320
+ data-variant={variant}
321
+ data-disabled={disabled || undefined}
322
+ className={cn("inline-flex items-center", variant === "compact" ? (size === "lg" ? "gap-1" : "gap-1.5") : "gap-0.5", s.text, className)}
323
+ >
324
+ {arrow(-1)}
325
+ {middle}
326
+ {arrow(1)}
327
+ </nav>
328
+ )
329
+ })
330
+ Pagination.displayName = "Pagination"
331
+
332
+ /** The go-to-page field a gap or the compact page number opens into. */
333
+ function JumpField({
334
+ label,
335
+ page,
336
+ count,
337
+ className,
338
+ part,
339
+ onDone,
340
+ }: {
341
+ label: string
342
+ page: number
343
+ count: number
344
+ className: string
345
+ part: string | undefined
346
+ /** `returnFocus` is false on blur, where focus has already gone where the person sent it. */
347
+ onDone: (page: number | null, event: Event | undefined, returnFocus: boolean) => void
348
+ }) {
349
+ const input = React.useRef<HTMLInputElement>(null)
350
+ const done = React.useRef(false)
351
+ React.useLayoutEffect(() => {
352
+ input.current?.focus()
353
+ }, [])
354
+ const finish = (commit: boolean, returnFocus: boolean, event?: Event) => {
355
+ if (done.current) return
356
+ done.current = true
357
+ const n = parseInt(input.current?.value ?? "", 10)
358
+ onDone(commit && Number.isFinite(n) ? clampPage(n, count) : null, event, returnFocus)
359
+ }
360
+ return (
361
+ // A plain input rather than Input, so the field stays part of this control for the agent.
362
+ <input
363
+ ref={input}
364
+ data-slot="pagination-jump"
365
+ data-agent-part={part}
366
+ inputMode="numeric"
367
+ autoComplete="off"
368
+ aria-label={label}
369
+ placeholder={String(page)}
370
+ onKeyDown={(e) => {
371
+ if (e.key === "Enter") {
372
+ e.preventDefault()
373
+ finish(true, true, e.nativeEvent)
374
+ } else if (e.key === "Escape") {
375
+ e.preventDefault()
376
+ finish(false, true)
377
+ }
378
+ }}
379
+ onBlur={(e) => finish(true, false, e.nativeEvent)}
380
+ className={cn(
381
+ "shrink-0 rounded-md border border-input bg-background px-1 text-center tabular-nums outline-none placeholder:text-muted-foreground",
382
+ "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-[color:color-mix(in_oklab,var(--ring)_50%,transparent)]",
383
+ className
384
+ )}
385
+ />
386
+ )
387
+ }
388
+
389
+ export { Pagination }
@@ -0,0 +1,13 @@
1
+ export {
2
+ Table,
3
+ TableHeader,
4
+ TableBody,
5
+ TableFooter,
6
+ TableRow,
7
+ TableHead,
8
+ TableCell,
9
+ TableCaption,
10
+ type TableProps,
11
+ type TableHeadProps,
12
+ type TableCellProps,
13
+ } from "./table"
@@ -0,0 +1,265 @@
1
+ import * as React from "react"
2
+ import { cn } from "@/lib/utils"
3
+
4
+ type Density = "comfortable" | "compact"
5
+ type Dividers = "rows" | "none"
6
+ type Section = "header" | "body" | "footer"
7
+ type StackRole = "title" | "value" | "meta"
8
+
9
+ interface TableContextValue {
10
+ density: Density
11
+ dividers: Dividers
12
+ stack: boolean
13
+ }
14
+
15
+ const TableContext = React.createContext<TableContextValue>({ density: "comfortable", dividers: "rows", stack: false })
16
+ const SectionContext = React.createContext<Section>("body")
17
+
18
+ // Browsers drop a table's semantics once its parts stop displaying as table parts, so a
19
+ // stacked table names them explicitly.
20
+ const role = (stack: boolean, name: string) => (stack ? name : undefined)
21
+
22
+ export interface TableProps extends React.TableHTMLAttributes<HTMLTableElement> {
23
+ /** Row height. Compact also suits nested or dense data. */
24
+ density?: Density
25
+ /** Lines between body rows. */
26
+ dividers?: Dividers
27
+ /**
28
+ * When the table's container is under 512px wide, each row becomes a block, with cells
29
+ * placed by their `stack` role, so nothing scrolls sideways.
30
+ */
31
+ stack?: boolean
32
+ /** Classes for the element that scrolls the table sideways. */
33
+ containerClassName?: string
34
+ /** The element that scrolls the table, for a virtualiser or a scroll listener. */
35
+ containerRef?: React.Ref<HTMLDivElement>
36
+ }
37
+
38
+ const Table = React.forwardRef<HTMLTableElement, TableProps>(
39
+ ({ className, containerClassName, containerRef, density = "comfortable", dividers = "rows", stack = false, ...props }, ref) => {
40
+ const context = React.useMemo(() => ({ density, dividers, stack }), [density, dividers, stack])
41
+ return (
42
+ <TableContext.Provider value={context}>
43
+ <div
44
+ ref={containerRef}
45
+ data-slot="table-container"
46
+ className={cn("relative w-full overflow-x-auto", stack && "[container-type:inline-size]", containerClassName)}
47
+ >
48
+ <table
49
+ ref={ref}
50
+ role={role(stack, "table")}
51
+ data-slot="table"
52
+ data-density={density}
53
+ data-dividers={dividers}
54
+ data-stack={stack || undefined}
55
+ className={cn(
56
+ "w-full border-separate border-spacing-0 text-[13px]",
57
+ stack && "[@container(width<32rem)]:block [@container(width<32rem)]:text-[15px]",
58
+ className
59
+ )}
60
+ {...props}
61
+ />
62
+ </div>
63
+ </TableContext.Provider>
64
+ )
65
+ }
66
+ )
67
+ Table.displayName = "Table"
68
+
69
+ const TableHeader = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(
70
+ ({ className, ...props }, ref) => {
71
+ const { stack } = React.useContext(TableContext)
72
+ return (
73
+ <SectionContext.Provider value="header">
74
+ <thead
75
+ ref={ref}
76
+ role={role(stack, "rowgroup")}
77
+ data-slot="table-header"
78
+ // The stacked rows say what each value is, so the column names are left to screen readers.
79
+ className={cn(stack && "[@container(width<32rem)]:sr-only", className)}
80
+ {...props}
81
+ />
82
+ </SectionContext.Provider>
83
+ )
84
+ }
85
+ )
86
+ TableHeader.displayName = "TableHeader"
87
+
88
+ const TableBody = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(
89
+ ({ className, ...props }, ref) => {
90
+ const { stack } = React.useContext(TableContext)
91
+ return (
92
+ <SectionContext.Provider value="body">
93
+ <tbody
94
+ ref={ref}
95
+ role={role(stack, "rowgroup")}
96
+ data-slot="table-body"
97
+ className={cn(
98
+ "[&>tr:last-child>td]:border-b-0 [&>tr:last-child>th]:border-b-0",
99
+ "[&>tr:hover]:bg-muted/70",
100
+ stack && "[@container(width<32rem)]:block",
101
+ className
102
+ )}
103
+ {...props}
104
+ />
105
+ </SectionContext.Provider>
106
+ )
107
+ }
108
+ )
109
+ TableBody.displayName = "TableBody"
110
+
111
+ const TableFooter = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(
112
+ ({ className, ...props }, ref) => {
113
+ const { stack } = React.useContext(TableContext)
114
+ return (
115
+ <SectionContext.Provider value="footer">
116
+ <tfoot
117
+ ref={ref}
118
+ role={role(stack, "rowgroup")}
119
+ data-slot="table-footer"
120
+ className={cn(
121
+ // The first row rules off the body; the last is the total. Stacked rows already
122
+ // end on a divider, so the rule is for the table layout only.
123
+ stack
124
+ ? "md:[&>tr:first-child>*]:border-t md:[&>tr:first-child>*]:pt-1.5"
125
+ : "[&>tr:first-child>*]:border-t [&>tr:first-child>*]:pt-1.5",
126
+ "[&>tr:last-child]:text-sm [&>tr:last-child]:font-semibold",
127
+ // A total with nothing above it already sits under the last row's divider.
128
+ stack &&
129
+ "[@container(width<32rem)]:grid [@container(width<32rem)]:gap-2.5 [@container(width<32rem)]:py-4 [@container(width<32rem)]:[&>tr:last-child:not(:first-child)]:border-t [@container(width<32rem)]:[&>tr:last-child]:pt-2 [@container(width<32rem)]:[&>tr:last-child]:text-lg",
130
+ className
131
+ )}
132
+ {...props}
133
+ />
134
+ </SectionContext.Provider>
135
+ )
136
+ }
137
+ )
138
+ TableFooter.displayName = "TableFooter"
139
+
140
+ const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>(
141
+ ({ className, ...props }, ref) => {
142
+ const { stack, density, dividers } = React.useContext(TableContext)
143
+ const section = React.useContext(SectionContext)
144
+ return (
145
+ <tr
146
+ ref={ref}
147
+ role={role(stack, "row")}
148
+ data-slot="table-row"
149
+ className={cn(
150
+ "transition-colors duration-100 motion-reduce:transition-none",
151
+ stack &&
152
+ section === "body" &&
153
+ cn(
154
+ // Title and value share the first line; the break after them sends the meta cells under it.
155
+ "[@container(width<32rem)]:flex [@container(width<32rem)]:flex-wrap [@container(width<32rem)]:items-baseline [@container(width<32rem)]:gap-x-1.5 [@container(width<32rem)]:gap-y-[3px]",
156
+ "[@container(width<32rem)]:after:order-3 [@container(width<32rem)]:after:basis-full [@container(width<32rem)]:after:content-['']",
157
+ density === "compact" ? "[@container(width<32rem)]:py-2" : "[@container(width<32rem)]:py-[13px]",
158
+ dividers === "rows" && "[@container(width<32rem)]:border-b"
159
+ ),
160
+ stack && section === "footer" && "[@container(width<32rem)]:flex [@container(width<32rem)]:items-baseline [@container(width<32rem)]:justify-between [@container(width<32rem)]:gap-3",
161
+ className
162
+ )}
163
+ {...props}
164
+ />
165
+ )
166
+ }
167
+ )
168
+ TableRow.displayName = "TableRow"
169
+
170
+ const stackClasses: Record<StackRole, string> = {
171
+ title: "[@container(width<32rem)]:order-1 [@container(width<32rem)]:min-w-0 [@container(width<32rem)]:flex-1 [@container(width<32rem)]:pe-3 [@container(width<32rem)]:text-base [@container(width<32rem)]:font-medium",
172
+ value: "[@container(width<32rem)]:order-2 [@container(width<32rem)]:text-right [@container(width<32rem)]:text-base [@container(width<32rem)]:tabular-nums",
173
+ meta: "[@container(width<32rem)]:order-4 [@container(width<32rem)]:text-[13px] [@container(width<32rem)]:text-muted-foreground",
174
+ }
175
+
176
+ export interface TableHeadProps extends React.ThHTMLAttributes<HTMLTableCellElement> {
177
+ /** Right-aligns the column's name over its figures. */
178
+ numeric?: boolean
179
+ /** Where a row's header goes when the table stacks, as on `TableCell`. Defaults to `title`. */
180
+ stack?: StackRole
181
+ }
182
+
183
+ const TableHead = React.forwardRef<HTMLTableCellElement, TableHeadProps>(
184
+ ({ className, numeric, scope, stack: place, ...props }, ref) => {
185
+ const { stack, density, dividers } = React.useContext(TableContext)
186
+ const section = React.useContext(SectionContext)
187
+ return (
188
+ <th
189
+ ref={ref}
190
+ scope={scope ?? (section === "header" ? "col" : "row")}
191
+ role={role(stack, section === "header" ? "columnheader" : "rowheader")}
192
+ data-slot="table-head"
193
+ data-numeric={numeric || undefined}
194
+ data-stack={stack && section === "body" ? (place ?? "title") : undefined}
195
+ className={cn(
196
+ "whitespace-nowrap px-3 text-left align-middle font-medium",
197
+ section === "header" && "border-b text-xs text-muted-foreground",
198
+ section === "body" && dividers === "rows" && "border-b",
199
+ section === "header" && (density === "compact" ? "h-[34px]" : "h-10"),
200
+ section === "body" && (density === "compact" ? "h-9" : "h-12"),
201
+ section === "footer" && "h-9",
202
+ numeric && "text-right tabular-nums",
203
+ stack && section !== "header" && "[@container(width<32rem)]:block [@container(width<32rem)]:h-auto [@container(width<32rem)]:whitespace-normal [@container(width<32rem)]:border-0 [@container(width<32rem)]:p-0",
204
+ stack && section === "body" && stackClasses[place ?? "title"],
205
+ className
206
+ )}
207
+ {...props}
208
+ />
209
+ )
210
+ }
211
+ )
212
+ TableHead.displayName = "TableHead"
213
+
214
+ export interface TableCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
215
+ /** Right-aligns the cell in tabular figures, so a column reads as one figure. */
216
+ numeric?: boolean
217
+ /**
218
+ * Where the cell goes when the table stacks: `title` and `value` share the first line,
219
+ * `meta` sits under them. Body cells without one are meta.
220
+ */
221
+ stack?: StackRole
222
+ }
223
+
224
+ const TableCell = React.forwardRef<HTMLTableCellElement, TableCellProps>(
225
+ ({ className, numeric, stack: place, ...props }, ref) => {
226
+ const { stack, density, dividers } = React.useContext(TableContext)
227
+ const section = React.useContext(SectionContext)
228
+ return (
229
+ <td
230
+ ref={ref}
231
+ role={role(stack, "cell")}
232
+ data-slot="table-cell"
233
+ data-numeric={numeric || undefined}
234
+ data-stack={stack && section === "body" ? (place ?? "meta") : undefined}
235
+ className={cn(
236
+ "whitespace-nowrap px-3 align-middle",
237
+ section === "footer" ? "h-9" : cn(density === "compact" ? "h-9" : "h-12", dividers === "rows" && "border-b"),
238
+ numeric && "text-right tabular-nums",
239
+ stack && "[@container(width<32rem)]:block [@container(width<32rem)]:h-auto [@container(width<32rem)]:whitespace-normal [@container(width<32rem)]:border-0 [@container(width<32rem)]:p-0",
240
+ stack && section === "body" && stackClasses[place ?? "meta"],
241
+ className
242
+ )}
243
+ {...props}
244
+ />
245
+ )
246
+ }
247
+ )
248
+ TableCell.displayName = "TableCell"
249
+
250
+ const TableCaption = React.forwardRef<HTMLTableCaptionElement, React.HTMLAttributes<HTMLTableCaptionElement>>(
251
+ ({ className, ...props }, ref) => {
252
+ const { stack } = React.useContext(TableContext)
253
+ return (
254
+ <caption
255
+ ref={ref}
256
+ data-slot="table-caption"
257
+ className={cn("caption-top px-3 pb-3 text-left text-sm text-muted-foreground", stack && "[@container(width<32rem)]:block [@container(width<32rem)]:px-0", className)}
258
+ {...props}
259
+ />
260
+ )
261
+ }
262
+ )
263
+ TableCaption.displayName = "TableCaption"
264
+
265
+ export { Table, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell, TableCaption }
@@ -0,0 +1 @@
1
+ export { TimeSlots, type TimeSlot, type TimeSlotsChangeDetails, type TimeSlotsProps } from "./time-slots";