@dinachi/cli 1.0.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 (105) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/index.js +244 -72
  3. package/package.json +5 -1
  4. package/templates/accordion/accordion.tsx +5 -1
  5. package/templates/agent/agent.tsx +35 -18
  6. package/templates/alert/alert.tsx +345 -0
  7. package/templates/alert/index.ts +16 -0
  8. package/templates/alert-dialog/alert-dialog.tsx +14 -3
  9. package/templates/animated-icon/animated-icon.tsx +1 -0
  10. package/templates/animated-list/animated-list.tsx +2 -1
  11. package/templates/animated-tabs/animated-tabs.tsx +4 -0
  12. package/templates/ask-bar/ask-bar.tsx +1061 -0
  13. package/templates/ask-bar/index.ts +1 -0
  14. package/templates/autocomplete/autocomplete.tsx +14 -4
  15. package/templates/avatar/avatar.tsx +3 -0
  16. package/templates/badge/badge.tsx +1 -0
  17. package/templates/breadcrumb/breadcrumb.tsx +606 -0
  18. package/templates/breadcrumb/index.ts +9 -0
  19. package/templates/button/button.tsx +1 -0
  20. package/templates/calendar/calendar.tsx +1155 -0
  21. package/templates/calendar/index.ts +15 -0
  22. package/templates/card/card.tsx +6 -1
  23. package/templates/carousel/carousel.tsx +7 -0
  24. package/templates/checkbox/checkbox.tsx +1 -0
  25. package/templates/checkbox-group/checkbox-group.tsx +1 -0
  26. package/templates/collapsible/collapsible.tsx +3 -1
  27. package/templates/combobox/combobox.tsx +15 -4
  28. package/templates/command-items/command-items.tsx +69 -0
  29. package/templates/command-items/index.ts +1 -0
  30. package/templates/command-palette/command-palette.tsx +954 -0
  31. package/templates/command-palette/index.ts +1 -0
  32. package/templates/compare-slider/compare-slider.tsx +1 -0
  33. package/templates/comparison-table/comparison-table.tsx +540 -0
  34. package/templates/comparison-table/index.ts +15 -0
  35. package/templates/context-menu/context-menu.tsx +61 -14
  36. package/templates/data-table/data-table.tsx +2077 -0
  37. package/templates/data-table/index.ts +14 -0
  38. package/templates/date-picker/date-picker.tsx +527 -0
  39. package/templates/date-picker/index.ts +2 -0
  40. package/templates/date-range-picker/date-range-picker.tsx +504 -0
  41. package/templates/date-range-picker/index.ts +2 -0
  42. package/templates/detail-list/detail-list.tsx +419 -0
  43. package/templates/detail-list/index.ts +12 -0
  44. package/templates/dialog/dialog.tsx +13 -3
  45. package/templates/drawer/drawer.tsx +19 -6
  46. package/templates/expandable-card/expandable-card.tsx +5 -1
  47. package/templates/field/field.tsx +5 -1
  48. package/templates/fieldset/fieldset.tsx +2 -0
  49. package/templates/form/form.tsx +1 -0
  50. package/templates/heat-table/heat-table.tsx +613 -0
  51. package/templates/heat-table/index.ts +9 -0
  52. package/templates/hold-to-confirm/hold-to-confirm.tsx +1 -0
  53. package/templates/input/input.tsx +1 -0
  54. package/templates/label/label.tsx +1 -0
  55. package/templates/link/link.tsx +1 -0
  56. package/templates/load-transition/load-transition.tsx +1 -0
  57. package/templates/marquee/marquee.tsx +1 -0
  58. package/templates/menu/menu.tsx +27 -6
  59. package/templates/menubar/menubar.tsx +15 -3
  60. package/templates/meter/meter.tsx +5 -1
  61. package/templates/month-picker/index.ts +1 -0
  62. package/templates/month-picker/month-picker.tsx +351 -0
  63. package/templates/navigation-menu/navigation-menu.tsx +13 -2
  64. package/templates/number-field/number-field.tsx +7 -1
  65. package/templates/number-ticker/number-ticker.tsx +3 -0
  66. package/templates/omnibar/index.ts +1 -0
  67. package/templates/omnibar/omnibar.tsx +1009 -0
  68. package/templates/otp-field/otp-field.tsx +4 -0
  69. package/templates/pagination/index.ts +8 -0
  70. package/templates/pagination/pagination.tsx +389 -0
  71. package/templates/popover/popover.tsx +19 -5
  72. package/templates/preview-card/preview-card.tsx +11 -3
  73. package/templates/progress/progress.tsx +5 -1
  74. package/templates/progress-ring/progress-ring.tsx +1 -0
  75. package/templates/radio/radio.tsx +3 -0
  76. package/templates/scroll-area/scroll-area.tsx +14 -4
  77. package/templates/scroll-progress/scroll-progress.tsx +1 -0
  78. package/templates/scroll-reveal/scroll-reveal.tsx +1 -0
  79. package/templates/select/select.tsx +18 -2
  80. package/templates/separator/separator.tsx +1 -0
  81. package/templates/skeleton/skeleton.tsx +1 -0
  82. package/templates/slider/slider.tsx +7 -0
  83. package/templates/sortable/sortable.tsx +3 -0
  84. package/templates/stagger-list/stagger-list.tsx +2 -0
  85. package/templates/streaming-text/streaming-text.tsx +1 -0
  86. package/templates/swipeable-row/swipeable-row.tsx +1 -0
  87. package/templates/switch/switch.tsx +2 -0
  88. package/templates/table/index.ts +13 -0
  89. package/templates/table/table.tsx +265 -0
  90. package/templates/tabs/tabs.tsx +5 -0
  91. package/templates/text/text.tsx +1 -0
  92. package/templates/text-morph/text-morph.tsx +2 -0
  93. package/templates/text-shimmer/text-shimmer.tsx +1 -0
  94. package/templates/textarea/textarea.tsx +1 -0
  95. package/templates/time-slots/index.ts +1 -0
  96. package/templates/time-slots/time-slots.tsx +589 -0
  97. package/templates/toast/toast.tsx +10 -1
  98. package/templates/toggle/toggle.tsx +1 -0
  99. package/templates/toggle-group/toggle-group.tsx +2 -0
  100. package/templates/toolbar/toolbar.tsx +6 -0
  101. package/templates/tooltip/tooltip.tsx +9 -3
  102. package/templates/week-strip/index.ts +1 -0
  103. package/templates/week-strip/week-strip.tsx +329 -0
  104. package/templates/year-view/index.ts +1 -0
  105. package/templates/year-view/year-view.tsx +362 -0
@@ -28,20 +28,23 @@ const ScrollArea = React.forwardRef<
28
28
  ref
29
29
  ) => (
30
30
  <ScrollAreaPrimitive.Root
31
+ data-slot="scroll-area"
31
32
  ref={ref}
32
33
  className={cn("relative overflow-hidden", className)}
33
34
  {...props}
34
35
  >
35
36
  <ScrollAreaPrimitive.Viewport
37
+ data-slot="scroll-area-viewport"
36
38
  className={cn("size-full rounded-[inherit]", viewportClassName)}
37
39
  >
38
- <ScrollAreaPrimitive.Content className="min-w-full">
40
+ <ScrollAreaPrimitive.Content data-slot="scroll-area-content" className="min-w-full">
39
41
  {children}
40
42
  </ScrollAreaPrimitive.Content>
41
43
  </ScrollAreaPrimitive.Viewport>
42
44
 
43
45
  {(orientation === "vertical" || orientation === "both") && (
44
46
  <ScrollAreaPrimitive.Scrollbar
47
+ data-slot="scroll-area-scrollbar"
45
48
  orientation="vertical"
46
49
  className={cn(
47
50
  "flex touch-none select-none p-0.5 transition-colors",
@@ -49,12 +52,13 @@ const ScrollArea = React.forwardRef<
49
52
  scrollbarClassName
50
53
  )}
51
54
  >
52
- <ScrollAreaPrimitive.Thumb className="relative flex-1 rounded-full bg-border" />
55
+ <ScrollAreaPrimitive.Thumb data-slot="scroll-area-thumb" className="relative flex-1 rounded-full bg-border" />
53
56
  </ScrollAreaPrimitive.Scrollbar>
54
57
  )}
55
58
 
56
59
  {(orientation === "horizontal" || orientation === "both") && (
57
60
  <ScrollAreaPrimitive.Scrollbar
61
+ data-slot="scroll-area-scrollbar"
58
62
  orientation="horizontal"
59
63
  className={cn(
60
64
  "flex touch-none select-none p-0.5 transition-colors",
@@ -62,11 +66,11 @@ const ScrollArea = React.forwardRef<
62
66
  scrollbarClassName
63
67
  )}
64
68
  >
65
- <ScrollAreaPrimitive.Thumb className="relative flex-1 rounded-full bg-border" />
69
+ <ScrollAreaPrimitive.Thumb data-slot="scroll-area-thumb" className="relative flex-1 rounded-full bg-border" />
66
70
  </ScrollAreaPrimitive.Scrollbar>
67
71
  )}
68
72
 
69
- {orientation === "both" && <ScrollAreaPrimitive.Corner className="bg-background" />}
73
+ {orientation === "both" && <ScrollAreaPrimitive.Corner data-slot="scroll-area-corner" className="bg-background" />}
70
74
  </ScrollAreaPrimitive.Root>
71
75
  )
72
76
  )
@@ -81,6 +85,7 @@ const ScrollAreaRoot = React.forwardRef<
81
85
  React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
82
86
  >(({ className, ...props }, ref) => (
83
87
  <ScrollAreaPrimitive.Root
88
+ data-slot="scroll-area-root"
84
89
  ref={ref}
85
90
  className={cn("relative overflow-hidden", className)}
86
91
  {...props}
@@ -93,6 +98,7 @@ const ScrollAreaViewport = React.forwardRef<
93
98
  React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Viewport>
94
99
  >(({ className, ...props }, ref) => (
95
100
  <ScrollAreaPrimitive.Viewport
101
+ data-slot="scroll-area-viewport"
96
102
  ref={ref}
97
103
  className={cn("size-full rounded-[inherit]", className)}
98
104
  {...props}
@@ -105,6 +111,7 @@ const ScrollAreaContent = React.forwardRef<
105
111
  React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Content>
106
112
  >(({ className, ...props }, ref) => (
107
113
  <ScrollAreaPrimitive.Content
114
+ data-slot="scroll-area-content"
108
115
  ref={ref}
109
116
  className={cn("min-w-full", className)}
110
117
  {...props}
@@ -117,6 +124,7 @@ const ScrollAreaScrollbar = React.forwardRef<
117
124
  React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Scrollbar>
118
125
  >(({ className, orientation = "vertical", ...props }, ref) => (
119
126
  <ScrollAreaPrimitive.Scrollbar
127
+ data-slot="scroll-area-scrollbar"
120
128
  ref={ref}
121
129
  orientation={orientation}
122
130
  className={cn(
@@ -136,6 +144,7 @@ const ScrollAreaThumb = React.forwardRef<
136
144
  React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Thumb>
137
145
  >(({ className, ...props }, ref) => (
138
146
  <ScrollAreaPrimitive.Thumb
147
+ data-slot="scroll-area-thumb"
139
148
  ref={ref}
140
149
  className={cn("relative flex-1 rounded-full bg-border", className)}
141
150
  {...props}
@@ -148,6 +157,7 @@ const ScrollAreaCorner = React.forwardRef<
148
157
  React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Corner>
149
158
  >(({ className, ...props }, ref) => (
150
159
  <ScrollAreaPrimitive.Corner
160
+ data-slot="scroll-area-corner"
151
161
  ref={ref}
152
162
  className={cn("bg-background", className)}
153
163
  {...props}
@@ -127,6 +127,7 @@ const ScrollProgress = React.forwardRef<HTMLDivElement, ScrollProgressProps>(
127
127
  <motion.div
128
128
  ref={ref}
129
129
  aria-hidden
130
+ data-slot="scroll-progress"
130
131
  style={{ scaleX, ...style }}
131
132
  // `will-change-transform` stays on permanently, against the usual advice to hint
132
133
  // only imminent motion: this element is transformed on essentially every scroll
@@ -169,6 +169,7 @@ const ScrollReveal = React.forwardRef<HTMLDivElement, ScrollRevealProps>(
169
169
  <div ref={wrapperRef}>
170
170
  <motion.div
171
171
  ref={ref}
172
+ data-slot="scroll-reveal"
172
173
  className={cn(className)}
173
174
  initial={hidden}
174
175
  animate={inView ? shown : hidden}
@@ -103,8 +103,13 @@ function Select<Value, Multiple extends boolean | undefined = false>({
103
103
  )
104
104
  }
105
105
 
106
- const SelectGroup = SelectPrimitive.Group
107
- const SelectValue = SelectPrimitive.Value
106
+ function SelectGroup(props: React.ComponentProps<typeof SelectPrimitive.Group>) {
107
+ return <SelectPrimitive.Group data-slot="select-group" {...props} />
108
+ }
109
+
110
+ function SelectValue(props: React.ComponentProps<typeof SelectPrimitive.Value>) {
111
+ return <SelectPrimitive.Value data-slot="select-value" {...props} />
112
+ }
108
113
 
109
114
  const SelectTrigger = React.forwardRef<
110
115
  React.ComponentRef<typeof SelectPrimitive.Trigger>,
@@ -186,6 +191,7 @@ const SelectTrigger = React.forwardRef<
186
191
 
187
192
  return (
188
193
  <SelectPrimitive.Trigger
194
+ data-slot="select-trigger"
189
195
  ref={mergedRef}
190
196
  className={cn(
191
197
  "flex h-10 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
@@ -229,6 +235,7 @@ const SelectContent = React.forwardRef<
229
235
  className="z-50"
230
236
  >
231
237
  <SelectPrimitive.Popup
238
+ data-slot="select-content"
232
239
  ref={ref}
233
240
  className={cn(
234
241
  "relative max-h-96 min-w-[var(--anchor-width)] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md",
@@ -280,6 +287,7 @@ const SelectBackdrop = React.forwardRef<
280
287
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.Backdrop>
281
288
  >(({ className, ...props }, ref) => (
282
289
  <SelectPrimitive.Backdrop
290
+ data-slot="select-backdrop"
283
291
  ref={ref}
284
292
  className={cn("fixed inset-0 z-40", className)}
285
293
  {...props}
@@ -292,6 +300,7 @@ const SelectScrollUpArrow = React.forwardRef<
292
300
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpArrow>
293
301
  >(({ className, ...props }, ref) => (
294
302
  <SelectPrimitive.ScrollUpArrow
303
+ data-slot="select-scroll-up-arrow"
295
304
  ref={ref}
296
305
  className={cn(
297
306
  "flex cursor-default items-center justify-center py-1",
@@ -309,6 +318,7 @@ const SelectScrollDownArrow = React.forwardRef<
309
318
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownArrow>
310
319
  >(({ className, ...props }, ref) => (
311
320
  <SelectPrimitive.ScrollDownArrow
321
+ data-slot="select-scroll-down-arrow"
312
322
  ref={ref}
313
323
  className={cn(
314
324
  "flex cursor-default items-center justify-center py-1",
@@ -326,6 +336,7 @@ const SelectFieldLabel = React.forwardRef<
326
336
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
327
337
  >(({ className, ...props }, ref) => (
328
338
  <SelectPrimitive.Label
339
+ data-slot="select-field-label"
329
340
  ref={ref}
330
341
  className={cn("block text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", className)}
331
342
  {...props}
@@ -338,6 +349,7 @@ const SelectLabel = React.forwardRef<
338
349
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.GroupLabel>
339
350
  >(({ className, ...props }, ref) => (
340
351
  <SelectPrimitive.GroupLabel
352
+ data-slot="select-label"
341
353
  ref={ref}
342
354
  className={cn("py-1.5 pl-2 pr-2 text-sm font-medium", className)}
343
355
  {...props}
@@ -377,6 +389,7 @@ const SelectItem = React.forwardRef<
377
389
 
378
390
  return (
379
391
  <SelectPrimitive.Item
392
+ data-slot="select-item"
380
393
  ref={mergedRef}
381
394
  className={cn(
382
395
  "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 text-sm outline-none",
@@ -404,6 +417,7 @@ const SelectItemIndicator = React.forwardRef<
404
417
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.ItemIndicator>
405
418
  >(({ className, children, ...props }, ref) => (
406
419
  <SelectPrimitive.ItemIndicator
420
+ data-slot="select-item-indicator"
407
421
  ref={ref}
408
422
  className={cn("flex h-3.5 w-3.5 items-center justify-center", className)}
409
423
  {...props}
@@ -418,6 +432,7 @@ const SelectArrow = React.forwardRef<
418
432
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.Arrow>
419
433
  >(({ className, ...props }, ref) => (
420
434
  <SelectPrimitive.Arrow
435
+ data-slot="select-arrow"
421
436
  ref={ref}
422
437
  className={cn("fill-popover stroke-border", className)}
423
438
  {...props}
@@ -430,6 +445,7 @@ const SelectSeparator = React.forwardRef<
430
445
  React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
431
446
  >(({ className, ...props }, ref) => (
432
447
  <SelectPrimitive.Separator
448
+ data-slot="select-separator"
433
449
  ref={ref}
434
450
  className={cn("-mx-1 my-1 h-px bg-muted", className)}
435
451
  {...props}
@@ -9,6 +9,7 @@ const Separator = React.forwardRef<
9
9
  React.ComponentPropsWithoutRef<typeof SeparatorPrimitive>
10
10
  >(({ className, orientation = "horizontal", ...props }, ref) => (
11
11
  <SeparatorPrimitive
12
+ data-slot="separator"
12
13
  ref={ref}
13
14
  orientation={orientation}
14
15
  className={cn(
@@ -3,6 +3,7 @@ import { cn } from "@/lib/utils"
3
3
  function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
4
4
  return (
5
5
  <div
6
+ data-slot="skeleton"
6
7
  className={cn("animate-pulse rounded-md bg-muted", className)}
7
8
  {...props}
8
9
  />
@@ -74,6 +74,7 @@ const Slider = React.forwardRef<
74
74
  className={cn("relative flex w-full flex-col gap-2", className)}
75
75
  value={value}
76
76
  onValueChange={changeValue}
77
+ data-slot="slider"
77
78
  {...props}
78
79
  />
79
80
  );
@@ -89,6 +90,7 @@ const SliderValue = React.forwardRef<
89
90
  >(({ className, ...props }, ref) => (
90
91
  <BaseSlider.Value
91
92
  ref={ref}
93
+ data-slot="slider-value"
92
94
  className={cn("text-sm font-medium", className)}
93
95
  {...props}
94
96
  />
@@ -101,6 +103,7 @@ const SliderControl = React.forwardRef<
101
103
  >(({ className, ...props }, ref) => (
102
104
  <BaseSlider.Control
103
105
  ref={ref}
106
+ data-slot="slider-control"
104
107
  className={cn("relative flex w-full touch-none select-none items-center", className)}
105
108
  {...props}
106
109
  />
@@ -113,6 +116,7 @@ const SliderTrack = React.forwardRef<
113
116
  >(({ className, ...props }, ref) => (
114
117
  <BaseSlider.Track
115
118
  ref={ref}
119
+ data-slot="slider-track"
116
120
  className={cn(
117
121
  "relative h-2 w-full grow rounded-full bg-secondary shadow-[inset_0_0_0_1px] shadow-secondary-foreground/5",
118
122
  className
@@ -128,6 +132,7 @@ const SliderRange = React.forwardRef<
128
132
  >(({ className, ...props }, ref) => (
129
133
  <BaseSlider.Indicator
130
134
  ref={ref}
135
+ data-slot="slider-range"
131
136
  className={cn("absolute h-full bg-primary rounded-full", className)}
132
137
  {...props}
133
138
  />
@@ -140,6 +145,7 @@ const SliderThumb = React.forwardRef<
140
145
  >(({ className, inputRef, ...props }, ref) => (
141
146
  <BaseSlider.Thumb
142
147
  ref={ref}
148
+ data-slot="slider-thumb"
143
149
  inputRef={useMergedRef(inputRef, useHasAgent() ? hideFromAgent : undefined)}
144
150
  className={cn(
145
151
  "block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background",
@@ -160,6 +166,7 @@ const SliderLabel = React.forwardRef<
160
166
  >(({ className, ...props }, ref) => (
161
167
  <BaseSlider.Label
162
168
  ref={ref}
169
+ data-slot="slider-label"
163
170
  className={cn("block text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", className)}
164
171
  {...props}
165
172
  />
@@ -208,6 +208,7 @@ const Sortable = React.forwardRef<HTMLUListElement, SortableProps>(
208
208
  values={value}
209
209
  onReorder={(next: string[]) => onValueChange(next, personChange("drag"))}
210
210
  data-disabled={disabled ? "" : undefined}
211
+ data-slot="sortable"
211
212
  className={cn("list-none space-y-2", className)}
212
213
  {...props}
213
214
  >
@@ -278,6 +279,7 @@ const SortableItem = React.forwardRef<HTMLLIElement, SortableItemProps>(
278
279
  onDragEnd={() => setDragging(false)}
279
280
  animate={{ scale: lifted && !list.reducedMotion ? 1.02 : 1 }}
280
281
  transition={{ type: "spring", bounce: 0.2, duration: 0.3 }}
282
+ data-slot="sortable-item"
281
283
  className={cn(
282
284
  "relative flex items-center gap-3 rounded-xl border bg-background px-3 py-3",
283
285
  lifted ? "z-10 border-primary/50" : "border-border",
@@ -370,6 +372,7 @@ const SortableHandle = React.forwardRef<HTMLButtonElement, SortableHandleProps>(
370
372
  aria-pressed={grabbed}
371
373
  disabled={list.disabled}
372
374
  data-agent-part={list.labels ? "" : undefined}
375
+ data-slot="sortable-handle"
373
376
  onPointerDown={(event) => {
374
377
  onPointerDown?.(event)
375
378
  if (event.defaultPrevented || list.disabled) return
@@ -155,6 +155,7 @@ const StaggerList = React.forwardRef<HTMLUListElement, StaggerListProps>(
155
155
  <StaggerContext.Provider value={contextValue}>
156
156
  <motion.ul
157
157
  ref={ref}
158
+ data-slot="stagger-list"
158
159
  className={cn("list-none", className)}
159
160
  variants={containerVariants}
160
161
  initial="hidden"
@@ -190,6 +191,7 @@ const StaggerListItem = React.forwardRef<HTMLLIElement, StaggerListItemProps>(
190
191
  return (
191
192
  <motion.li
192
193
  ref={ref}
194
+ data-slot="stagger-list-item"
193
195
  className={cn(className)}
194
196
  variants={context.itemVariants}
195
197
  {...props}
@@ -142,6 +142,7 @@ const StreamingText = React.forwardRef<HTMLDivElement, StreamingTextProps>(
142
142
  return (
143
143
  <div
144
144
  ref={ref}
145
+ data-slot="streaming-text"
145
146
  className={cn("text-sm leading-relaxed text-foreground", className)}
146
147
  {...props}
147
148
  >
@@ -237,6 +237,7 @@ const SwipeableRow = React.forwardRef<HTMLDivElement, SwipeableRowProps>(
237
237
  return (
238
238
  <div
239
239
  ref={useMergedRef(ref, rowRef)}
240
+ data-slot="swipeable-row"
240
241
  className={cn("relative overflow-hidden rounded-xl", className)}
241
242
  {...props}
242
243
  >
@@ -45,6 +45,7 @@ const Switch = React.forwardRef<
45
45
  <span className="relative inline-flex [&>input]:!absolute">
46
46
  <SwitchPrimitive.Root
47
47
  ref={mergedRef}
48
+ data-slot="switch"
48
49
  className={cn(
49
50
  "inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors duration-[var(--motion-duration-fast,150ms)]",
50
51
  "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
@@ -68,6 +69,7 @@ const SwitchThumb = React.forwardRef<
68
69
  >(({ className, ...props }, ref) => (
69
70
  <SwitchPrimitive.Thumb
70
71
  ref={ref}
72
+ data-slot="switch-thumb"
71
73
  className={cn(
72
74
  "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0",
73
75
  "transition-transform duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
@@ -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 }