@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
@@ -0,0 +1 @@
1
+ export * from "./command-palette"
@@ -369,6 +369,7 @@ const CompareSlider = React.forwardRef<HTMLDivElement, CompareSliderProps>(
369
369
  "data-[disabled]:opacity-50",
370
370
  className
371
371
  )}
372
+ data-slot="compare-slider"
372
373
  {...lock.panel}
373
374
  {...props}
374
375
  {...panelHandlers}
@@ -0,0 +1,540 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group"
5
+ import { Toggle as TogglePrimitive } from "@base-ui/react/toggle"
6
+ import { Check } from "lucide-react"
7
+ import { cn } from "@/lib/utils"
8
+ import { Button } from "@/components/ui/button"
9
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
10
+ import { Switch, SwitchThumb } from "@/components/ui/switch"
11
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
12
+ import { changeAsAgent, matchAgentChoice, useAgentControl, useAgentState, useHasAgent, useMergedRef } from "@/components/ui/agent"
13
+
14
+ /** A billing period's value, such as "monthly". */
15
+ export type ComparisonBilling = string
16
+
17
+ /** One choice on the billing toggle. Plans key their `price` and `per` by `value`. */
18
+ export interface ComparisonPeriod {
19
+ value: ComparisonBilling
20
+ label: string
21
+ }
22
+
23
+ /** One node for every period, or one node for each period by its value. */
24
+ export type ComparisonByPeriod = React.ReactNode | Partial<Record<ComparisonBilling, React.ReactNode>>
25
+
26
+ /** `true` is included, `false` or nothing is not, and text is shown as it is. */
27
+ export type ComparisonCellValue = boolean | string | number | null | undefined
28
+
29
+ export interface ComparisonPlan {
30
+ id: string
31
+ name: string
32
+ /** The price, the same for every period, or keyed by period value. */
33
+ price: ComparisonByPeriod
34
+ /** The line under the price, such as "a month". Leave a plan's out to keep it blank. */
35
+ per?: ComparisonByPeriod
36
+ /**
37
+ * The plan's button. The label defaults to "Choose {name}"; a label without the plan's
38
+ * name is read with it. `href` renders a link, and `false` leaves the plan without one.
39
+ */
40
+ cta?: { label?: React.ReactNode; href?: string; onClick?: (event: React.MouseEvent) => void } | false
41
+ /** Tints the plan's column, fills its button and badges it "Recommended". One plan at most. */
42
+ highlighted?: boolean
43
+ /** A label over the plan's name, read with its header and button. Defaults to "Recommended" when highlighted. */
44
+ badge?: string
45
+ }
46
+
47
+ export interface ComparisonFeature {
48
+ label: string
49
+ /** Each plan's value, by plan id. */
50
+ values: Record<string, ComparisonCellValue>
51
+ }
52
+
53
+ export interface ComparisonGroup {
54
+ label: string
55
+ features: ComparisonFeature[]
56
+ }
57
+
58
+ /** Base UI's change details, which the agent's changes also carry. */
59
+ export interface ComparisonChangeDetails {
60
+ reason: string
61
+ event?: Event
62
+ isCanceled: boolean
63
+ cancel(): void
64
+ }
65
+
66
+ const BILLING: ComparisonPeriod[] = [
67
+ { value: "monthly", label: "Monthly" },
68
+ { value: "yearly", label: "Yearly" },
69
+ ]
70
+
71
+ const WIDE = "(min-width: 768px)"
72
+
73
+ const byPeriod = (v: ComparisonByPeriod): v is Partial<Record<ComparisonBilling, React.ReactNode>> =>
74
+ v != null &&
75
+ typeof v === "object" &&
76
+ !React.isValidElement(v) &&
77
+ !(Symbol.iterator in v) &&
78
+ typeof (v as { then?: unknown }).then !== "function"
79
+
80
+ const forPeriod = (v: ComparisonByPeriod, period: ComparisonBilling | undefined): React.ReactNode =>
81
+ byPeriod(v) ? (period == null ? undefined : v[period]) : v
82
+
83
+ const badgeOf = (plan: ComparisonPlan) => plan.badge ?? (plan.highlighted ? "Recommended" : undefined)
84
+
85
+ // A missing value and `false` both mean not included, so they count as the same.
86
+ const norm = (v: ComparisonCellValue) => (v == null || v === false ? false : v === true ? true : String(v))
87
+
88
+ /** Whether the plans disagree on a feature. */
89
+ export function featureDiffers(feature: ComparisonFeature, planIds: string[]): boolean {
90
+ return planIds.some((id) => norm(feature.values[id]) !== norm(feature.values[planIds[0]]))
91
+ }
92
+
93
+ const badgeClass =
94
+ "inline-block rounded-full bg-primary px-2 py-0.5 text-[11px] font-medium leading-4 text-primary-foreground"
95
+
96
+ const tint = "bg-[color:color-mix(in_oklab,var(--secondary)_55%,var(--card))]"
97
+
98
+ export interface ComparisonValueProps extends React.HTMLAttributes<HTMLSpanElement> {
99
+ value: ComparisonCellValue
100
+ }
101
+
102
+ /** One plan's value for a feature: a tick read as Included, a dash read as Not included, or text. */
103
+ const ComparisonValue = React.forwardRef<HTMLSpanElement, ComparisonValueProps>(({ value, className, ...props }, ref) => {
104
+ const v = norm(value)
105
+ return (
106
+ <span
107
+ ref={ref}
108
+ data-slot="comparison-value"
109
+ role={typeof v === "boolean" ? "img" : undefined}
110
+ aria-label={v === true ? "Included" : v === false ? "Not included" : undefined}
111
+ className={cn("inline-flex items-center", v === false && "text-muted-foreground", className)}
112
+ {...props}
113
+ >
114
+ {v === true ? <Check aria-hidden className="h-4 w-4" strokeWidth={2.25} /> : v === false ? <span aria-hidden>–</span> : v}
115
+ </span>
116
+ )
117
+ })
118
+ ComparisonValue.displayName = "ComparisonValue"
119
+
120
+ export interface ComparisonTableProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue"> {
121
+ plans: ComparisonPlan[]
122
+ groups: ComparisonGroup[]
123
+ /** The toggle's periods. Defaults to Monthly and Yearly; `false` or fewer than two drops the toggle. */
124
+ billingPeriods?: ComparisonPeriod[] | false
125
+ /** Names the toggle, for people and agents. */
126
+ billingLabel?: string
127
+ billing?: ComparisonBilling
128
+ /** Defaults to the first period. */
129
+ defaultBilling?: ComparisonBilling
130
+ /** Runs on every change, for people and agents. `details.cancel()` refuses it. */
131
+ onBillingChange?: (billing: ComparisonBilling, details: ComparisonChangeDetails) => void
132
+ /** Hides every feature the plans agree on. */
133
+ onlyDifferences?: boolean
134
+ defaultOnlyDifferences?: boolean
135
+ onOnlyDifferencesChange?: (onlyDifferences: boolean, details: ComparisonChangeDetails) => void
136
+ /** Small text over the feature names, such as "Prices per seat, ex. VAT". */
137
+ note?: React.ReactNode
138
+ /** The two plans a phone compares, by id. Defaults to the highlighted plan and the one after it. */
139
+ defaultPhonePlans?: [string, string]
140
+ /** Caps the height, so the features scroll under the plan row. Without it the plan row sticks to the page. */
141
+ maxHeight?: number | string
142
+ disabled?: boolean
143
+ }
144
+
145
+ /**
146
+ * Plans as columns and features as rows, grouped. The plan row sticks with each price and
147
+ * button. Below 768px it becomes two plan pickers with each feature's values under its name.
148
+ */
149
+ const ComparisonTable = React.forwardRef<HTMLDivElement, ComparisonTableProps>((props, ref) => {
150
+ const {
151
+ plans,
152
+ groups,
153
+ billingPeriods = BILLING,
154
+ billingLabel = "Billing",
155
+ billing: billingProp,
156
+ defaultBilling,
157
+ onBillingChange,
158
+ onlyDifferences: diffProp,
159
+ defaultOnlyDifferences = false,
160
+ onOnlyDifferencesChange,
161
+ note,
162
+ defaultPhonePlans,
163
+ maxHeight,
164
+ disabled,
165
+ className,
166
+ ...rest
167
+ } = props
168
+ const hasAgent = useHasAgent()
169
+ const periods = billingPeriods || []
170
+ const toggle = periods.length > 1
171
+ const [billing, changeBilling] = useAgentState<ComparisonBilling, ComparisonChangeDetails>(
172
+ billingProp,
173
+ defaultBilling ?? periods[0]?.value ?? "",
174
+ onBillingChange
175
+ )
176
+ const period = periods.length ? billing : undefined
177
+ const [only, changeOnly] = useAgentState<boolean, ComparisonChangeDetails>(diffProp, defaultOnlyDifferences, onOnlyDifferencesChange)
178
+ const [picked, setPhone] = React.useState<[string, string]>(() => {
179
+ if (defaultPhonePlans) return defaultPhonePlans
180
+ const at = Math.max(0, plans.findIndex((p) => p.highlighted))
181
+ const first = Math.min(at, Math.max(0, plans.length - 2))
182
+ return [plans[first]?.id ?? "", plans[first + 1]?.id ?? plans[first]?.id ?? ""]
183
+ })
184
+
185
+ const root = React.useRef<HTMLDivElement | null>(null)
186
+ const rootRef = useMergedRef(ref, root)
187
+ const seg = React.useRef<HTMLDivElement | null>(null)
188
+ const id = React.useId()
189
+
190
+ const allIds = plans.map((p) => p.id)
191
+ // A picked plan that is no longer in `plans` falls back to the plan in its place.
192
+ const phone = picked.map((planId, i) => (allIds.includes(planId) ? planId : (allIds[i] ?? allIds[0] ?? ""))) as [
193
+ string,
194
+ string,
195
+ ]
196
+ const features = groups.flatMap((g) => g.features)
197
+ const hiddenWide = only ? features.filter((f) => !featureDiffers(f, allIds)).length : 0
198
+ const hiddenPhone = only ? features.filter((f) => !featureDiffers(f, phone)).length : 0
199
+
200
+ // CSS hides the layout that does not fit, which the agent cannot see, so the hidden one is
201
+ // marked for it directly. Outside AgentProvider nothing is marked and nothing re-renders.
202
+ React.useEffect(() => {
203
+ if (!hasAgent || !root.current) return
204
+ const query = window.matchMedia?.(WIDE)
205
+ const mark = () => {
206
+ const wide = query?.matches ?? true
207
+ const el = root.current
208
+ el?.querySelector('[data-slot="comparison-table-plans"]')?.toggleAttribute("data-agent-hidden", !wide)
209
+ el?.querySelector('[data-slot="comparison-table-phone"]')?.toggleAttribute("data-agent-hidden", wide)
210
+ }
211
+ mark()
212
+ query?.addEventListener("change", mark)
213
+ return () => query?.removeEventListener("change", mark)
214
+ }, [hasAgent])
215
+
216
+ /* ---- agent ---- */
217
+ useAgentControl(() =>
218
+ toggle
219
+ ? {
220
+ kind: "toggle-group",
221
+ element: seg.current,
222
+ label: billingLabel,
223
+ value: periods.find((b) => b.value === billing)?.label ?? billing,
224
+ items: periods.map((b) => b.label),
225
+ disabled,
226
+ actions: {
227
+ setValue: (wanted: unknown) => {
228
+ const match = matchAgentChoice(periods, wanted)
229
+ if (typeof match === "string") return match
230
+ return match.value === billing ? undefined : changeAsAgent(changeBilling, match.value)
231
+ },
232
+ },
233
+ }
234
+ : null
235
+ )
236
+
237
+ const nameId = (i: number) => `${id}-n${i}`
238
+ const badgeId = (i: number) => `${id}-b${i}`
239
+
240
+ const cta = (plan: ComparisonPlan, at: number, badge: string | undefined, className?: string) => {
241
+ if (plan.cta === false) return null
242
+ const custom = plan.cta?.label
243
+ const label = custom ?? `Choose ${plan.name}`
244
+ const named = typeof label === "string" && label.includes(plan.name)
245
+ const describedBy = [typeof label !== "string" && nameId(at), badge && badgeId(at)].filter(Boolean).join(" ")
246
+ return (
247
+ <Button
248
+ data-slot="comparison-table-cta"
249
+ variant={plan.highlighted ? "default" : "outline"}
250
+ disabled={disabled}
251
+ onClick={plan.cta?.onClick}
252
+ render={plan.cta?.href ? <a href={plan.cta.href} /> : undefined}
253
+ // Base UI names a non-button element a button; a link keeps its own role.
254
+ {...(plan.cta?.href ? { role: undefined } : {})}
255
+ aria-label={typeof label === "string" && !named ? `${label}, ${plan.name}` : undefined}
256
+ aria-describedby={describedBy || undefined}
257
+ className={cn("w-full px-3 text-[13px]", className)}
258
+ >
259
+ {label}
260
+ </Button>
261
+ )
262
+ }
263
+
264
+ const hasCta = plans.some((p) => p.cta !== false)
265
+ const phoneBadges = phone.some((planId) => {
266
+ const plan = plans.find((p) => p.id === planId)
267
+ return plan ? badgeOf(plan) : false
268
+ })
269
+
270
+ const scroll = maxHeight != null
271
+
272
+ return (
273
+ <div
274
+ ref={rootRef}
275
+ data-slot="comparison-table"
276
+ className={cn("w-full overflow-clip rounded-xl border bg-card text-card-foreground", className)}
277
+ {...rest}
278
+ >
279
+ <div
280
+ data-slot="comparison-table-toolbar"
281
+ className="flex flex-wrap items-center gap-x-2.5 gap-y-2 border-b px-4 py-3 text-[13px] md:px-[18px] md:py-3.5"
282
+ >
283
+ <Switch
284
+ aria-labelledby={`${id}-only`}
285
+ checked={only}
286
+ disabled={disabled}
287
+ onCheckedChange={(next, details) => changeOnly(next, details as ComparisonChangeDetails)}
288
+ >
289
+ <SwitchThumb />
290
+ </Switch>
291
+ <span id={`${id}-only`}>
292
+ Only differences
293
+ </span>
294
+ <span aria-live="polite" className="text-muted-foreground max-md:hidden">
295
+ {hiddenWide > 0 ? `${hiddenWide} hidden` : ""}
296
+ </span>
297
+ <span aria-live="polite" className="text-muted-foreground md:hidden">
298
+ {hiddenPhone > 0 ? `${hiddenPhone} hidden` : ""}
299
+ </span>
300
+ {toggle && (
301
+ <ToggleGroupPrimitive
302
+ ref={seg}
303
+ data-slot="comparison-table-billing"
304
+ aria-label={billingLabel}
305
+ value={[billing]}
306
+ disabled={disabled}
307
+ onValueChange={(value, details) => {
308
+ const next = value[0] as ComparisonBilling | undefined
309
+ // Pressing the chosen period again would leave none chosen.
310
+ if (next && next !== billing) changeBilling(next, details as ComparisonChangeDetails)
311
+ }}
312
+ className="ms-auto inline-flex rounded-full border p-0.5 max-md:order-first max-md:ms-0 max-md:grid max-md:w-full max-md:auto-cols-fr max-md:grid-flow-col"
313
+ >
314
+ {periods.map((b) => (
315
+ <TogglePrimitive
316
+ key={b.value}
317
+ value={b.value}
318
+ data-agent-part={hasAgent ? "" : undefined}
319
+ className={cn(
320
+ "h-7 cursor-pointer rounded-full px-3 text-[13px] text-muted-foreground transition-colors duration-100 motion-reduce:transition-none max-md:h-8",
321
+ "hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
322
+ "data-[pressed]:bg-primary data-[pressed]:text-primary-foreground",
323
+ "data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50"
324
+ )}
325
+ >
326
+ {b.label}
327
+ </TogglePrimitive>
328
+ ))}
329
+ </ToggleGroupPrimitive>
330
+ )}
331
+ </div>
332
+
333
+ <div
334
+ data-slot="comparison-table-scroll"
335
+ className={cn(scroll && "overflow-auto")}
336
+ style={scroll ? { maxHeight } : undefined}
337
+ >
338
+ <div data-slot="comparison-table-plans" className="max-md:hidden">
339
+ <Table containerClassName="overflow-visible" className="table-fixed">
340
+ <colgroup>
341
+ <col className="w-[34%]" />
342
+ {plans.map((p) => (
343
+ <col key={p.id} />
344
+ ))}
345
+ </colgroup>
346
+ {/* Names, prices and buttons are a row each, so each lines up however the names wrap. */}
347
+ <TableHeader className="sticky top-[var(--comparison-table-top,0px)] z-10">
348
+ <TableRow>
349
+ <TableHead
350
+ rowSpan={hasCta ? 3 : 2}
351
+ className="h-auto whitespace-normal bg-card px-4 pb-3.5 pt-4 align-top text-xs font-normal"
352
+ >
353
+ {note ?? <span className="sr-only">Feature</span>}
354
+ </TableHead>
355
+ {plans.map((plan, i) => {
356
+ const badge = badgeOf(plan)
357
+ return (
358
+ <TableHead
359
+ key={plan.id}
360
+ data-highlighted={plan.highlighted || undefined}
361
+ className={cn(
362
+ "h-auto whitespace-normal border-b-0 bg-card px-4 pt-4 align-bottom font-normal text-foreground",
363
+ plan.highlighted && tint
364
+ )}
365
+ >
366
+ {badge && (
367
+ <span id={badgeId(i)} data-slot="comparison-table-badge" className={cn(badgeClass, "mb-1.5")}>
368
+ {badge}
369
+ </span>
370
+ )}{" "}
371
+ <div id={nameId(i)} className="text-sm font-semibold">
372
+ {plan.name}
373
+ </div>
374
+ </TableHead>
375
+ )
376
+ })}
377
+ </TableRow>
378
+ <TableRow>
379
+ {plans.map((plan) => (
380
+ <TableCell
381
+ key={plan.id}
382
+ className={cn(
383
+ "h-auto whitespace-normal bg-card px-4 pt-1.5 align-top",
384
+ hasCta ? "pb-0" : "border-b pb-3.5",
385
+ plan.highlighted && tint
386
+ )}
387
+ >
388
+ <div data-slot="comparison-table-price">
389
+ <div className="mb-0.5 text-[26px] font-semibold leading-tight tracking-[-0.02em] tabular-nums">
390
+ {forPeriod(plan.price, period)}
391
+ </div>
392
+ <div className="min-h-[18px] text-xs leading-[18px] text-muted-foreground">
393
+ {forPeriod(plan.per, period)}
394
+ </div>
395
+ </div>
396
+ </TableCell>
397
+ ))}
398
+ </TableRow>
399
+ {hasCta && (
400
+ <TableRow>
401
+ {plans.map((plan, i) => (
402
+ <TableCell
403
+ key={plan.id}
404
+ className={cn("h-auto border-b bg-card px-4 pb-3.5 pt-3 align-bottom", plan.highlighted && tint)}
405
+ >
406
+ {cta(plan, i, badgeOf(plan), "h-9")}
407
+ </TableCell>
408
+ ))}
409
+ </TableRow>
410
+ )}
411
+ </TableHeader>
412
+ {groups.map((group, gi) => {
413
+ const shown = group.features.map((f, fi) => [f, fi] as const).filter(([f]) => !only || featureDiffers(f, allIds))
414
+ if (!shown.length) return null
415
+ return (
416
+ <TableBody key={gi} data-slot="comparison-table-group">
417
+ <TableRow className="hover:bg-transparent">
418
+ <TableHead
419
+ scope="colgroup"
420
+ colSpan={plans.length + 1}
421
+ className="h-auto px-4 pb-2.5 pt-[22px] text-xs font-semibold text-muted-foreground"
422
+ >
423
+ {group.label}
424
+ </TableHead>
425
+ </TableRow>
426
+ {shown.map(([feature, fi]) => (
427
+ <TableRow key={fi} data-slot="comparison-table-feature">
428
+ <TableHead className="h-auto whitespace-normal px-4 py-[11px] font-normal">{feature.label}</TableHead>
429
+ {plans.map((plan) => (
430
+ <TableCell
431
+ key={plan.id}
432
+ className={cn("h-auto whitespace-normal px-4 py-[11px]", plan.highlighted && tint)}
433
+ >
434
+ <ComparisonValue value={feature.values[plan.id]} />
435
+ </TableCell>
436
+ ))}
437
+ </TableRow>
438
+ ))}
439
+ </TableBody>
440
+ )
441
+ })}
442
+ </Table>
443
+ </div>
444
+
445
+ <div data-slot="comparison-table-phone" className="px-4 md:hidden">
446
+ <div className="sticky top-[var(--comparison-table-top,0px)] z-10 grid grid-cols-2 gap-2.5 border-b bg-card py-2.5">
447
+ {phone.map((planId, i) => {
448
+ const at = plans.findIndex((p) => p.id === planId)
449
+ const plan = plans[at]
450
+ if (!plan) return null
451
+ const badge = badgeOf(plan)
452
+ return (
453
+ <div key={i} className="min-w-0">
454
+ <Select
455
+ items={plans.map((p) => ({ value: p.id, label: p.name }))}
456
+ value={plan.id}
457
+ disabled={disabled}
458
+ onValueChange={(next) => {
459
+ if (typeof next !== "string") return
460
+ setPhone(i === 0 ? [next, phone[1]] : [phone[0], next])
461
+ }}
462
+ >
463
+ <SelectTrigger
464
+ aria-label={i === 0 ? "First plan" : "Second plan"}
465
+ aria-describedby={badge ? badgeId(at) : undefined}
466
+ // Names wrap to two lines rather than cut to a letter in a narrow column.
467
+ className="h-auto min-h-9 gap-1.5 rounded-lg px-2.5 py-1.5 text-left text-[15px] font-semibold leading-tight [&>span]:line-clamp-2"
468
+ >
469
+ <SelectValue />
470
+ </SelectTrigger>
471
+ <SelectContent>
472
+ {plans.map((p) => (
473
+ <SelectItem key={p.id} value={p.id}>
474
+ {p.name}
475
+ </SelectItem>
476
+ ))}
477
+ </SelectContent>
478
+ </Select>
479
+ {phoneBadges && (
480
+ <div className="mx-0.5 mt-1.5 min-h-5">
481
+ {badge && (
482
+ <span aria-hidden data-slot="comparison-table-badge" className={badgeClass}>
483
+ {badge}
484
+ </span>
485
+ )}
486
+ </div>
487
+ )}
488
+ <div data-slot="comparison-table-price" className="mx-0.5 mt-1.5 flex flex-wrap items-baseline gap-x-1.5">
489
+ <span className="text-lg font-semibold tabular-nums">{forPeriod(plan.price, period)}</span>
490
+ <span className="text-[13px] text-muted-foreground">{forPeriod(plan.per, period)}</span>
491
+ </div>
492
+ </div>
493
+ )
494
+ })}
495
+ </div>
496
+ {/* The buttons scroll away; the plan and its price stay. */}
497
+ {phone.some((planId) => plans.find((p) => p.id === planId)?.cta !== false) && (
498
+ <div className="grid grid-cols-2 gap-2.5 pt-3">
499
+ {phone.map((planId, i) => {
500
+ const at = plans.findIndex((p) => p.id === planId)
501
+ const plan = plans[at]
502
+ return plan ? <div key={i}>{cta(plan, at, badgeOf(plan), "h-10 w-full rounded-xl")}</div> : null
503
+ })}
504
+ </div>
505
+ )}
506
+ {groups.map((group, gi) => {
507
+ const shown = group.features.map((f, fi) => [f, fi] as const).filter(([f]) => !only || featureDiffers(f, phone))
508
+ if (!shown.length) return null
509
+ return (
510
+ <div key={gi} data-slot="comparison-table-group">
511
+ <h3 className="pb-1.5 pt-5 text-[13px] font-semibold text-muted-foreground">{group.label}</h3>
512
+ <dl>
513
+ {shown.map(([feature, fi]) => (
514
+ <div
515
+ key={fi}
516
+ data-slot="comparison-table-feature"
517
+ className="grid grid-cols-2 gap-x-2.5 border-b py-2.5 text-[15px] last:border-b-0"
518
+ >
519
+ <dt className="col-span-2 mb-1 text-[13px] text-muted-foreground">{feature.label}</dt>
520
+ {phone.map((planId, i) => (
521
+ <dd key={i}>
522
+ <span className="sr-only">{plans.find((p) => p.id === planId)?.name}: </span>
523
+ <ComparisonValue value={feature.values[planId]} />
524
+ </dd>
525
+ ))}
526
+ </div>
527
+ ))}
528
+ </dl>
529
+ </div>
530
+ )
531
+ })}
532
+ <div className="h-5" />
533
+ </div>
534
+ </div>
535
+ </div>
536
+ )
537
+ })
538
+ ComparisonTable.displayName = "ComparisonTable"
539
+
540
+ export { ComparisonTable, ComparisonValue }
@@ -0,0 +1,15 @@
1
+ export {
2
+ ComparisonTable,
3
+ ComparisonValue,
4
+ featureDiffers,
5
+ type ComparisonTableProps,
6
+ type ComparisonValueProps,
7
+ type ComparisonPlan,
8
+ type ComparisonGroup,
9
+ type ComparisonFeature,
10
+ type ComparisonCellValue,
11
+ type ComparisonBilling,
12
+ type ComparisonPeriod,
13
+ type ComparisonByPeriod,
14
+ type ComparisonChangeDetails,
15
+ } from "./comparison-table"