@whity/ui 0.0.0-stage → 0.5.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 (169) hide show
  1. package/README.md +107 -3
  2. package/package.json +192 -6
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +302 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +500 -0
  16. package/src/approval-queue.tsx +108 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar.tsx +83 -0
  22. package/src/badge.stories.tsx +105 -0
  23. package/src/badge.tsx +68 -0
  24. package/src/beta-warning.stories.tsx +79 -0
  25. package/src/beta-warning.tsx +189 -0
  26. package/src/bilingual-input.stories.tsx +82 -0
  27. package/src/bilingual-input.tsx +183 -0
  28. package/src/breadcrumb.stories.tsx +51 -0
  29. package/src/breadcrumb.tsx +90 -0
  30. package/src/button.stories.tsx +87 -0
  31. package/src/button.tsx +118 -0
  32. package/src/card.stories.tsx +423 -0
  33. package/src/card.tsx +180 -0
  34. package/src/chart.stories.tsx +66 -0
  35. package/src/chart.tsx +228 -0
  36. package/src/checkbox.stories.tsx +62 -0
  37. package/src/checkbox.tsx +54 -0
  38. package/src/collapsible.stories.tsx +48 -0
  39. package/src/collapsible.tsx +34 -0
  40. package/src/color-card.stories.tsx +61 -0
  41. package/src/color-card.tsx +270 -0
  42. package/src/color-picker.stories.tsx +65 -0
  43. package/src/color-picker.tsx +425 -0
  44. package/src/command-palette.tsx +306 -0
  45. package/src/copy-block.stories.tsx +38 -0
  46. package/src/copy-block.tsx +85 -0
  47. package/src/data-table.stories.tsx +200 -0
  48. package/src/data-table.tsx +1106 -0
  49. package/src/date-picker.stories.tsx +61 -0
  50. package/src/date-picker.tsx +422 -0
  51. package/src/design-cards.stories.tsx +458 -0
  52. package/src/dialog.stories.tsx +48 -0
  53. package/src/dialog.tsx +166 -0
  54. package/src/documents/barcode-svg.stories.tsx +72 -0
  55. package/src/documents/barcode-svg.tsx +79 -0
  56. package/src/dropdown-menu.stories.tsx +77 -0
  57. package/src/dropdown-menu.tsx +271 -0
  58. package/src/editor/behaviour.ts +279 -0
  59. package/src/editor/block-ids.ts +44 -0
  60. package/src/editor/block-list.tsx +101 -0
  61. package/src/editor/block-toolbar.tsx +477 -0
  62. package/src/editor/bubble.tsx +93 -0
  63. package/src/editor/catalogue.ts +103 -0
  64. package/src/editor/collab-rail.tsx +746 -0
  65. package/src/editor/collab.stories.tsx +207 -0
  66. package/src/editor/collab.ts +87 -0
  67. package/src/editor/contract.ts +408 -0
  68. package/src/editor/convert.ts +362 -0
  69. package/src/editor/doc-editor.stories.tsx +98 -0
  70. package/src/editor/doc-editor.tsx +1287 -0
  71. package/src/editor/editor.css +536 -0
  72. package/src/editor/extensions.ts +86 -0
  73. package/src/editor/field-picker.tsx +107 -0
  74. package/src/editor/fields.ts +100 -0
  75. package/src/editor/gutter.tsx +367 -0
  76. package/src/editor/index.ts +22 -0
  77. package/src/editor/label-sheet.tsx +289 -0
  78. package/src/editor/labels.ts +310 -0
  79. package/src/editor/link-tools.tsx +141 -0
  80. package/src/editor/node-views.tsx +450 -0
  81. package/src/editor/page-view.tsx +353 -0
  82. package/src/editor/publish-check.tsx +182 -0
  83. package/src/editor/rich-blocks.stories.tsx +146 -0
  84. package/src/editor/sample.ts +40 -0
  85. package/src/editor/schema-rich.ts +150 -0
  86. package/src/editor/schema.ts +315 -0
  87. package/src/editor/services.tsx +127 -0
  88. package/src/editor/slash.ts +64 -0
  89. package/src/editor/suggesting.ts +372 -0
  90. package/src/editor/suggestions.ts +763 -0
  91. package/src/editor/table-keys.ts +66 -0
  92. package/src/editor/templates.stories.tsx +324 -0
  93. package/src/editor/toolbar.tsx +358 -0
  94. package/src/empty-state.stories.tsx +51 -0
  95. package/src/empty-state.tsx +100 -0
  96. package/src/empty-state.usage-notes.md +30 -0
  97. package/src/form.stories.tsx +112 -0
  98. package/src/form.tsx +176 -0
  99. package/src/globals.css +20 -0
  100. package/src/icon-button.tsx +85 -0
  101. package/src/icon-map.ts +244 -0
  102. package/src/icon.tsx +41 -0
  103. package/src/index.ts +67 -0
  104. package/src/input.stories.tsx +157 -0
  105. package/src/input.tsx +759 -0
  106. package/src/locked-screen.stories.tsx +29 -0
  107. package/src/locked-screen.tsx +61 -0
  108. package/src/mark.tsx +62 -0
  109. package/src/math-text.stories.tsx +33 -0
  110. package/src/math-text.tsx +43 -0
  111. package/src/menu-bar.stories.tsx +198 -0
  112. package/src/menu-bar.tsx +373 -0
  113. package/src/money/currency.ts +230 -0
  114. package/src/page-header.stories.tsx +95 -0
  115. package/src/page-header.tsx +122 -0
  116. package/src/page-shell.stories.tsx +42 -0
  117. package/src/page-shell.tsx +32 -0
  118. package/src/pagination.stories.tsx +45 -0
  119. package/src/pagination.tsx +98 -0
  120. package/src/plugin-card.stories.tsx +180 -0
  121. package/src/plugin-card.tsx +848 -0
  122. package/src/popover.stories.tsx +48 -0
  123. package/src/popover.tsx +55 -0
  124. package/src/radio-group.stories.tsx +26 -0
  125. package/src/radio-group.tsx +44 -0
  126. package/src/route-flow/editor.tsx +1014 -0
  127. package/src/route-flow/model.ts +716 -0
  128. package/src/scope-grant.tsx +139 -0
  129. package/src/screen-too-small.stories.tsx +61 -0
  130. package/src/screen-too-small.tsx +104 -0
  131. package/src/select.stories.tsx +44 -0
  132. package/src/select.tsx +197 -0
  133. package/src/separator.stories.tsx +34 -0
  134. package/src/separator.tsx +34 -0
  135. package/src/sheet.stories.tsx +49 -0
  136. package/src/sheet.tsx +168 -0
  137. package/src/skeleton.stories.tsx +28 -0
  138. package/src/skeleton.tsx +19 -0
  139. package/src/slider.stories.tsx +78 -0
  140. package/src/slider.tsx +300 -0
  141. package/src/spinner.stories.tsx +33 -0
  142. package/src/spinner.tsx +55 -0
  143. package/src/switch.stories.tsx +42 -0
  144. package/src/switch.tsx +41 -0
  145. package/src/switcher.stories.tsx +111 -0
  146. package/src/switcher.tsx +131 -0
  147. package/src/table.stories.tsx +48 -0
  148. package/src/table.tsx +121 -0
  149. package/src/tabs.stories.tsx +74 -0
  150. package/src/tabs.tsx +90 -0
  151. package/src/tag-input.stories.tsx +67 -0
  152. package/src/tag-input.tsx +117 -0
  153. package/src/tenant-logo.tsx +63 -0
  154. package/src/tenant-switcher.stories.tsx +38 -0
  155. package/src/tenant-switcher.tsx +164 -0
  156. package/src/textarea.stories.tsx +27 -0
  157. package/src/textarea.tsx +18 -0
  158. package/src/theme-mode.ts +52 -0
  159. package/src/time-picker.stories.tsx +62 -0
  160. package/src/time-picker.tsx +615 -0
  161. package/src/toggle-group.tsx +138 -0
  162. package/src/tooltip.stories.tsx +43 -0
  163. package/src/tooltip.tsx +73 -0
  164. package/src/top-nav.stories.tsx +58 -0
  165. package/src/top-nav.tsx +324 -0
  166. package/src/undo-bar.tsx +107 -0
  167. package/src/utils.ts +45 -0
  168. package/src/view-toggle.stories.tsx +84 -0
  169. package/src/view-toggle.tsx +110 -0
package/src/card.tsx ADDED
@@ -0,0 +1,180 @@
1
+ import * as React from "react"
2
+
3
+ import { cn } from "./utils"
4
+
5
+ export type CardVariant =
6
+ | "default"
7
+ | "flat"
8
+ | "outline"
9
+ | "elevated"
10
+ | "purple"
11
+ | "info"
12
+ | "success"
13
+ | "warning"
14
+ | "destructive"
15
+
16
+ export type CardBorderStyle = "solid" | "dashed" | "dotted" | "none"
17
+
18
+ export type CardState = "default" | "disabled" | "selected" | "active"
19
+
20
+ export interface CardProps extends React.ComponentProps<"div"> {
21
+ size?: "default" | "sm" | "lg"
22
+ variant?: CardVariant
23
+ borderStyle?: CardBorderStyle
24
+ state?: CardState
25
+ disabled?: boolean
26
+ /**
27
+ * Opt into hover/elevated treatment for interactive cards.
28
+ */
29
+ interactive?: boolean
30
+ }
31
+
32
+ function Card({
33
+ className,
34
+ size = "default",
35
+ variant = "default",
36
+ borderStyle = "solid",
37
+ state = "default",
38
+ disabled = false,
39
+ interactive = false,
40
+ ...props
41
+ }: CardProps) {
42
+ const isDisabled = disabled || state === "disabled"
43
+ const isSelected = state === "selected"
44
+ const isActive = state === "active"
45
+
46
+ // Elevated solid background & shadow styling according to variant
47
+ const variantClasses = {
48
+ default: "bg-card text-card-foreground shadow-2xs border border-border/60 ring-0",
49
+ flat: "bg-card text-card-foreground shadow-2xs border border-border/40 ring-0",
50
+ outline: "bg-card/60 text-card-foreground border border-border ring-0",
51
+ elevated: "bg-card text-card-foreground shadow-md border border-border/60 ring-0",
52
+ purple: "bg-card text-card-foreground shadow-2xs border border-purple-500/25 dark:bg-purple-950/20 dark:border-purple-500/35 ring-0",
53
+ info: "bg-card text-card-foreground shadow-2xs border border-blue-500/25 dark:bg-blue-950/20 dark:border-blue-500/35 ring-0",
54
+ success: "bg-card text-card-foreground shadow-2xs border border-emerald-500/25 dark:bg-emerald-950/20 dark:border-emerald-500/35 ring-0",
55
+ warning: "bg-card text-card-foreground shadow-2xs border border-amber-500/25 dark:bg-amber-950/25 dark:border-amber-500/30 ring-0",
56
+ destructive: "bg-card text-card-foreground shadow-2xs border border-red-500/25 dark:bg-red-950/20 dark:border-red-500/35 ring-0",
57
+ }[variant]
58
+
59
+ // Border style modifier
60
+ const borderStyleClasses = {
61
+ solid: "border-solid",
62
+ dashed: "border-dashed border",
63
+ dotted: "border-dotted border-2",
64
+ none: "border-none ring-0",
65
+ }[borderStyle]
66
+
67
+ // Card size spacing
68
+ const sizeClasses = {
69
+ sm: "gap-3 py-3 data-[size=sm]:gap-3 data-[size=sm]:py-3",
70
+ default: "gap-4 py-4",
71
+ lg: "gap-6 py-6",
72
+ }[size]
73
+
74
+ return (
75
+ <div
76
+ data-slot="card"
77
+ data-size={size}
78
+ data-variant={variant}
79
+ data-border-style={borderStyle}
80
+ data-state={isDisabled ? "disabled" : isSelected ? "selected" : isActive ? "active" : "default"}
81
+ data-interactive={interactive && !isDisabled ? true : undefined}
82
+ aria-disabled={isDisabled || undefined}
83
+ className={cn(
84
+ "group/card flex flex-col overflow-hidden rounded-xl text-xs/relaxed transition-all duration-200",
85
+ variantClasses,
86
+ borderStyleClasses,
87
+ sizeClasses,
88
+ // State modifiers
89
+ isSelected && "ring-2 ring-primary border-primary bg-primary/[0.04] shadow-xs",
90
+ isActive && "ring-2 ring-primary/80 border-primary",
91
+ isDisabled && "opacity-55 pointer-events-none bg-muted/20 grayscale-[20%] select-none cursor-not-allowed shadow-none",
92
+ // Interactive state
93
+ interactive && !isDisabled && "cursor-pointer hover:-translate-y-0.5 hover:shadow-md hover:border-border/80 focus-within:ring-2 focus-within:ring-ring/50 active:translate-y-0 active:shadow-xs",
94
+ // Media first/last child rounded corners & banner top padding removal
95
+ "has-[>img:first-child]:pt-0 has-[>[data-slot=card-banner]:first-child]:pt-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
96
+ className
97
+ )}
98
+ {...props}
99
+ />
100
+ )
101
+ }
102
+
103
+ function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
104
+ return (
105
+ <div
106
+ data-slot="card-header"
107
+ className={cn(
108
+ "group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-4 group-data-[size=sm]/card:px-3 group-data-[size=lg]/card:px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3 group-data-[size=lg]/card:[.border-b]:pb-6",
109
+ className
110
+ )}
111
+ {...props}
112
+ />
113
+ )
114
+ }
115
+
116
+ function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
117
+ return (
118
+ <div
119
+ data-slot="card-title"
120
+ className={cn("font-heading text-sm font-medium tracking-tight text-foreground", className)}
121
+ {...props}
122
+ />
123
+ )
124
+ }
125
+
126
+ function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
127
+ return (
128
+ <div
129
+ data-slot="card-description"
130
+ className={cn("text-xs/relaxed text-muted-foreground", className)}
131
+ {...props}
132
+ />
133
+ )
134
+ }
135
+
136
+ function CardAction({ className, ...props }: React.ComponentProps<"div">) {
137
+ return (
138
+ <div
139
+ data-slot="card-action"
140
+ className={cn(
141
+ "col-start-2 row-span-2 row-start-1 self-start justify-self-end",
142
+ className
143
+ )}
144
+ {...props}
145
+ />
146
+ )
147
+ }
148
+
149
+ function CardContent({ className, ...props }: React.ComponentProps<"div">) {
150
+ return (
151
+ <div
152
+ data-slot="card-content"
153
+ className={cn("px-4 group-data-[size=sm]/card:px-3 group-data-[size=lg]/card:px-6", className)}
154
+ {...props}
155
+ />
156
+ )
157
+ }
158
+
159
+ function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
160
+ return (
161
+ <div
162
+ data-slot="card-footer"
163
+ className={cn(
164
+ "flex items-center rounded-b-xl px-4 group-data-[size=sm]/card:px-3 group-data-[size=lg]/card:px-6 [.border-t]:pt-4 group-data-[size=sm]/card:[.border-t]:pt-3 group-data-[size=lg]/card:[.border-t]:pt-6",
165
+ className
166
+ )}
167
+ {...props}
168
+ />
169
+ )
170
+ }
171
+
172
+ export {
173
+ Card,
174
+ CardHeader,
175
+ CardFooter,
176
+ CardTitle,
177
+ CardAction,
178
+ CardDescription,
179
+ CardContent,
180
+ }
@@ -0,0 +1,66 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import { Chart } from "./chart"
4
+
5
+ const meta = {
6
+ title: "Primitives/Chart",
7
+ component: Chart,
8
+ tags: ["autodocs"],
9
+ } satisfies Meta<typeof Chart>
10
+
11
+ export default meta
12
+ type Story = StoryObj<typeof meta>
13
+
14
+ const monthly = [
15
+ { month: "Jan", revenue: 186, cost: 120 },
16
+ { month: "Feb", revenue: 205, cost: 130 },
17
+ { month: "Mar", revenue: 237, cost: 145 },
18
+ { month: "Apr", revenue: 173, cost: 110 },
19
+ { month: "May", revenue: 209, cost: 128 },
20
+ ]
21
+
22
+ const shareData = [
23
+ { channel: "Direct", value: 42 },
24
+ { channel: "Referral", value: 28 },
25
+ { channel: "Search", value: 18 },
26
+ { channel: "Social", value: 12 },
27
+ ]
28
+
29
+ export const Bar: Story = {
30
+ args: {
31
+ type: "bar",
32
+ data: monthly,
33
+ xKey: "month",
34
+ series: [
35
+ { key: "revenue", label: "Revenue", color: 1 },
36
+ { key: "cost", label: "Cost", color: 2 },
37
+ ],
38
+ },
39
+ }
40
+
41
+ export const Line: Story = {
42
+ args: {
43
+ type: "line",
44
+ data: monthly,
45
+ xKey: "month",
46
+ series: [{ key: "revenue", label: "Revenue", color: 1 }],
47
+ },
48
+ }
49
+
50
+ export const Area: Story = {
51
+ args: {
52
+ type: "area",
53
+ data: monthly,
54
+ xKey: "month",
55
+ series: [{ key: "revenue", label: "Revenue", color: 1 }],
56
+ },
57
+ }
58
+
59
+ export const Pie: Story = {
60
+ args: {
61
+ type: "pie",
62
+ data: shareData,
63
+ xKey: "channel",
64
+ series: [{ key: "value", label: "Share", color: 1 }],
65
+ },
66
+ }
package/src/chart.tsx ADDED
@@ -0,0 +1,228 @@
1
+ import * as React from "react"
2
+ import {
3
+ Area,
4
+ AreaChart,
5
+ Bar,
6
+ BarChart,
7
+ CartesianGrid,
8
+ Cell,
9
+ LabelList,
10
+ Legend,
11
+ Line,
12
+ LineChart,
13
+ Pie,
14
+ PieChart,
15
+ ResponsiveContainer,
16
+ Tooltip,
17
+ XAxis,
18
+ YAxis,
19
+ } from "recharts"
20
+
21
+ import { cn } from "./utils"
22
+
23
+ /**
24
+ * Minimal `--chart-1..5`-token-wired chart primitive built on recharts.
25
+ *
26
+ * Colors are NEVER passed as hex/rgb: each series picks one of the five
27
+ * semantic chart tokens (`--chart-1` .. `--chart-5`, defined in
28
+ * `globals.css`) via `var(--chart-N)`, so the same series set re-themes with
29
+ * the rest of the design system (including dark mode) with zero recharts
30
+ * config changes.
31
+ *
32
+ * This is intentionally small — one shared primitive for both the plugin
33
+ * Blocks DSL `chart` block type and (future) first-party chart call sites
34
+ * (e.g. `StatsChart`) to build on, so a second, divergent recharts wrapper
35
+ * never needs to exist.
36
+ */
37
+
38
+ export type ChartColor = 1 | 2 | 3 | 4 | 5
39
+
40
+ export interface ChartSeries {
41
+ /** Key into each row of `data`. */
42
+ key: string
43
+ /** Legend / tooltip label. */
44
+ label: string
45
+ /** One of the five semantic chart tokens. */
46
+ color: ChartColor
47
+ }
48
+
49
+ export type ChartType = "bar" | "line" | "area" | "pie"
50
+
51
+ export interface ChartProps extends React.ComponentProps<"div"> {
52
+ type: ChartType
53
+ data: Record<string, string | number>[]
54
+ series: ChartSeries[]
55
+ /** Category key for the x-axis; ignored for `type="pie"`. */
56
+ xKey?: string
57
+ /** Fixed render height in pixels (the width always fills the container). */
58
+ height?: number
59
+ /** Show the legend. Defaults to on; a single series rarely needs one. */
60
+ legend?: boolean
61
+ /** For `bar`: the index of the one bar whose value is printed above it (BarChart card). */
62
+ highlight?: number
63
+ /** Formats the highlighted value. */
64
+ formatValue?: (value: number) => string
65
+ /** For `pie`: draw a ring instead of a full disc. */
66
+ donut?: boolean
67
+ }
68
+
69
+ /** The next round axis end at or above `value` (38.5 → 40, 5346 → 6000). */
70
+ function niceCeil(value: number): number {
71
+ if (value <= 0) return 1
72
+ const step = 10 ** Math.floor(Math.log10(value))
73
+ const m = value / step
74
+ return ([1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10].find((n) => m <= n) ?? 10) * step
75
+ }
76
+
77
+ function chartColorVar(color: ChartColor): string {
78
+ return `var(--chart-${color})`
79
+ }
80
+
81
+ function ChartTooltipContent({
82
+ active,
83
+ payload,
84
+ label,
85
+ }: {
86
+ active?: boolean
87
+ payload?: { name?: string; value?: string | number; color?: string }[]
88
+ label?: string | number
89
+ }) {
90
+ if (active !== true || !payload || payload.length === 0) return null
91
+ return (
92
+ <div className="rounded-lg border bg-popover px-3 py-2 text-xs text-popover-foreground shadow-sm">
93
+ {label !== undefined && <div className="font-medium">{label}</div>}
94
+ <div className="mt-1 space-y-0.5">
95
+ {payload.map((entry, index) => (
96
+ <div key={index} className="flex items-center gap-1.5">
97
+ <span
98
+ className="size-2 rounded-full"
99
+ style={{ backgroundColor: entry.color }}
100
+ aria-hidden
101
+ />
102
+ <span className="text-muted-foreground">{entry.name}</span>
103
+ <span className="font-medium">{entry.value}</span>
104
+ </div>
105
+ ))}
106
+ </div>
107
+ </div>
108
+ )
109
+ }
110
+
111
+ function Chart({
112
+ type,
113
+ data,
114
+ series,
115
+ xKey,
116
+ height = 240,
117
+ legend = true,
118
+ highlight,
119
+ formatValue = String,
120
+ donut = false,
121
+ className,
122
+ ...props
123
+ }: ChartProps) {
124
+ const content = React.useMemo(() => {
125
+ switch (type) {
126
+ case "bar":
127
+ return (
128
+ <BarChart data={data}>
129
+ <CartesianGrid vertical={false} stroke="var(--border)" />
130
+ {xKey !== undefined && <XAxis dataKey={xKey} tickLine={false} axisLine={false} />}
131
+ {/* Headroom above the tallest bar, so its printed value is not clipped. */}
132
+ <YAxis tickLine={false} axisLine={false} domain={highlight !== undefined ? [0, (max: number) => niceCeil(max * 1.1)] : undefined} />
133
+ <Tooltip content={<ChartTooltipContent />} />
134
+ {legend && <Legend />}
135
+ {series.map((s, i) => (
136
+ // At most 24px thick, rounded at the end and square on the baseline (BarChart card).
137
+ <Bar key={s.key} dataKey={s.key} name={s.label} fill={chartColorVar(s.color)} radius={[4, 4, 0, 0]} maxBarSize={24}>
138
+ {i === 0 && highlight !== undefined && (
139
+ <LabelList
140
+ dataKey={s.key}
141
+ content={(p) => (p.index === highlight ? <text x={Number(p.x) + Number(p.width) / 2} y={Number(p.y) - 6} textAnchor="middle" className="fill-foreground text-xs font-semibold">{formatValue(Number(p.value))}</text> : null)}
142
+ />
143
+ )}
144
+ </Bar>
145
+ ))}
146
+ </BarChart>
147
+ )
148
+ case "line":
149
+ return (
150
+ <LineChart data={data}>
151
+ <CartesianGrid vertical={false} stroke="var(--border)" />
152
+ {xKey !== undefined && <XAxis dataKey={xKey} tickLine={false} axisLine={false} />}
153
+ <YAxis tickLine={false} axisLine={false} />
154
+ <Tooltip content={<ChartTooltipContent />} />
155
+ {legend && <Legend />}
156
+ {series.map((s) => (
157
+ <Line
158
+ key={s.key}
159
+ type="monotone"
160
+ dataKey={s.key}
161
+ name={s.label}
162
+ stroke={chartColorVar(s.color)}
163
+ strokeWidth={2}
164
+ dot={false}
165
+ />
166
+ ))}
167
+ </LineChart>
168
+ )
169
+ case "area":
170
+ return (
171
+ <AreaChart data={data}>
172
+ <CartesianGrid vertical={false} stroke="var(--border)" />
173
+ {xKey !== undefined && <XAxis dataKey={xKey} tickLine={false} axisLine={false} />}
174
+ <YAxis tickLine={false} axisLine={false} />
175
+ <Tooltip content={<ChartTooltipContent />} />
176
+ {legend && <Legend />}
177
+ {series.map((s) => (
178
+ <Area
179
+ key={s.key}
180
+ type="monotone"
181
+ dataKey={s.key}
182
+ name={s.label}
183
+ stroke={chartColorVar(s.color)}
184
+ fill={chartColorVar(s.color)}
185
+ fillOpacity={0.2}
186
+ />
187
+ ))}
188
+ </AreaChart>
189
+ )
190
+ case "pie": {
191
+ const first = series[0]
192
+ if (first === undefined || xKey === undefined) return null
193
+ return (
194
+ <PieChart>
195
+ <Tooltip content={<ChartTooltipContent />} />
196
+ {legend && <Legend />}
197
+ <Pie data={data} dataKey={first.key} nameKey={xKey} label={!donut} innerRadius={donut ? "60%" : 0}>
198
+ {data.map((_, index) => (
199
+ <Cell
200
+ key={index}
201
+ // A ring of one series takes the palette in its fixed order, one colour per slice.
202
+ fill={chartColorVar(donut ? (((index % 5) + 1) as ChartColor) : (series[index % series.length]?.color ?? 1))}
203
+ />
204
+ ))}
205
+ </Pie>
206
+ </PieChart>
207
+ )
208
+ }
209
+ }
210
+ }, [type, data, series, xKey, legend, highlight, formatValue, donut])
211
+
212
+ return (
213
+ <div
214
+ data-slot="chart"
215
+ role="img"
216
+ aria-label={series.map((s) => s.label).join(", ")}
217
+ className={cn("w-full", className)}
218
+ style={{ height }}
219
+ {...props}
220
+ >
221
+ <ResponsiveContainer width="100%" height="100%">
222
+ {content ?? <svg />}
223
+ </ResponsiveContainer>
224
+ </div>
225
+ )
226
+ }
227
+
228
+ export { Chart }
@@ -0,0 +1,62 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+ import * as React from "react"
3
+
4
+ import { Checkbox } from "./checkbox"
5
+
6
+ const meta = {
7
+ title: "Primitives/Checkbox",
8
+ component: Checkbox,
9
+ tags: ["autodocs"],
10
+ } satisfies Meta<typeof Checkbox>
11
+
12
+ export default meta
13
+ type Story = StoryObj<typeof meta>
14
+
15
+ export const Default: Story = {
16
+ args: { "aria-label": "Accept terms" },
17
+ }
18
+
19
+ export const Checked: Story = {
20
+ args: { "aria-label": "Accept terms", defaultChecked: true },
21
+ }
22
+
23
+ export const Indeterminate: Story = {
24
+ args: { "aria-label": "Select all", checked: "indeterminate" },
25
+ }
26
+
27
+ export const Disabled: Story = {
28
+ args: { "aria-label": "Accept terms", disabled: true },
29
+ }
30
+
31
+ export const SelectAllPattern: Story = {
32
+ render: () => {
33
+ const [items, setItems] = React.useState([false, true, false])
34
+ const allChecked = items.every(Boolean)
35
+ const someChecked = items.some(Boolean) && !allChecked
36
+
37
+ return (
38
+ <div className="flex flex-col gap-2">
39
+ <label className="flex items-center gap-2">
40
+ <Checkbox
41
+ aria-label="Select all rows"
42
+ checked={someChecked ? "indeterminate" : allChecked}
43
+ onCheckedChange={(v) => setItems(items.map(() => v === true))}
44
+ />
45
+ Select all
46
+ </label>
47
+ {items.map((checked, i) => (
48
+ <label key={i} className="flex items-center gap-2 ps-4">
49
+ <Checkbox
50
+ aria-label={`Row ${i + 1}`}
51
+ checked={checked}
52
+ onCheckedChange={(v) =>
53
+ setItems(items.map((c, idx) => (idx === i ? v === true : c)))
54
+ }
55
+ />
56
+ Row {i + 1}
57
+ </label>
58
+ ))}
59
+ </div>
60
+ )
61
+ },
62
+ }
@@ -0,0 +1,54 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Checkbox as CheckboxPrimitive } from "radix-ui"
5
+ import { IconCheck, IconMinus } from "@tabler/icons-react"
6
+
7
+ import { cn } from "./utils"
8
+
9
+ /**
10
+ * Tri-state checkbox (checked / unchecked / indeterminate) built on Radix
11
+ * Checkbox — required by the DataTable selection primitive's select-all
12
+ * (indeterminate when some-but-not-all rows are selected) and per-row
13
+ * checkboxes.
14
+ *
15
+ * PLATFORM NOTE: `checked`/`disabled`/`onCheckedChange` map directly onto a
16
+ * Flutter Checkbox's `value`(tristate)/`onChanged` — this prop shape is
17
+ * plain enough to mirror there. `checked` accepts `boolean | "indeterminate"`
18
+ * (Radix's own type), same tri-state concept a Flutter `tristate: true`
19
+ * Checkbox exposes.
20
+ *
21
+ * NOTE (found while building this): the plugin Blocks DSL's `checkbox` block
22
+ * type (sdk/src/Frontend/Blocks/BlockContract.php + block-renderer.tsx)
23
+ * currently renders its OWN inline `<input type="checkbox">` markup — a
24
+ * second, visually-divergent implementation. Not addressed here (out of
25
+ * scope for this task); flagged for the "richer data-bound blocks" task in
26
+ * this same flow, which touches block-renderer.tsx anyway and could migrate
27
+ * that block onto this shared primitive at the same time.
28
+ */
29
+ function Checkbox({
30
+ className,
31
+ checked,
32
+ ...props
33
+ }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
34
+ return (
35
+ <CheckboxPrimitive.Root
36
+ data-slot="checkbox"
37
+ checked={checked}
38
+ className={cn(
39
+ "peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs outline-none transition-shadow focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground",
40
+ className
41
+ )}
42
+ {...props}
43
+ >
44
+ <CheckboxPrimitive.Indicator
45
+ data-slot="checkbox-indicator"
46
+ className="flex items-center justify-center text-current [&_svg]:size-3"
47
+ >
48
+ {checked === "indeterminate" ? <IconMinus /> : <IconCheck />}
49
+ </CheckboxPrimitive.Indicator>
50
+ </CheckboxPrimitive.Root>
51
+ )
52
+ }
53
+
54
+ export { Checkbox }
@@ -0,0 +1,48 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import { Collapsible, CollapsibleTrigger, CollapsibleContent } from "./collapsible"
4
+ import { Button } from "./button"
5
+
6
+ const meta = {
7
+ title: "Primitives/Collapsible",
8
+ component: Collapsible,
9
+ tags: ["autodocs"],
10
+ } satisfies Meta<typeof Collapsible>
11
+
12
+ export default meta
13
+ type Story = StoryObj<typeof meta>
14
+
15
+ export const Default: Story = {
16
+ render: () => (
17
+ <Collapsible className="w-72 space-y-2">
18
+ <div className="flex items-center justify-between">
19
+ <span className="text-sm font-medium text-foreground">3 items starred</span>
20
+ <CollapsibleTrigger asChild>
21
+ <Button variant="ghost" size="sm">
22
+ Toggle
23
+ </Button>
24
+ </CollapsibleTrigger>
25
+ </div>
26
+ <div className="rounded-md border border-border px-3 py-2 text-xs text-muted-foreground">whity-core</div>
27
+ <CollapsibleContent className="space-y-2">
28
+ <div className="rounded-md border border-border px-3 py-2 text-xs text-muted-foreground">whity-plugins</div>
29
+ <div className="rounded-md border border-border px-3 py-2 text-xs text-muted-foreground">whity-desktop</div>
30
+ </CollapsibleContent>
31
+ </Collapsible>
32
+ ),
33
+ }
34
+
35
+ export const DefaultOpen: Story = {
36
+ render: () => (
37
+ <Collapsible defaultOpen className="w-72 space-y-2">
38
+ <CollapsibleTrigger asChild>
39
+ <Button variant="outline" size="sm">
40
+ Toggle (starts open)
41
+ </Button>
42
+ </CollapsibleTrigger>
43
+ <CollapsibleContent className="rounded-md border border-border px-3 py-2 text-xs text-muted-foreground">
44
+ Visible by default — click the trigger to collapse.
45
+ </CollapsibleContent>
46
+ </Collapsible>
47
+ ),
48
+ }
@@ -0,0 +1,34 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+ import { Collapsible as CollapsiblePrimitive } from "radix-ui"
5
+
6
+ /**
7
+ * Thin expand/collapse primitive (Root/Trigger/Content) — a keyboard- and
8
+ * screen-reader-accessible replacement for hand-rolled expand/collapse state
9
+ * (e.g. web/app/(protected)/admin/ous/ou-tree.tsx's manual `Set<number>`
10
+ * toggle state, or web/app/onboarding/page.tsx's native `<details>` used
11
+ * specifically "so it needs no extra dependency" — this primitive removes
12
+ * that constraint since the dependency is already bundled via `radix-ui`).
13
+ * No default styling is applied to Content — animate/size it per use site
14
+ * via `data-[state=open]`/`data-[state=closed]` (matches this kit's other
15
+ * Radix wrappers, which leave animation to the consumer's className).
16
+ */
17
+
18
+ function Collapsible({ ...props }: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
19
+ return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
20
+ }
21
+
22
+ function CollapsibleTrigger({
23
+ ...props
24
+ }: React.ComponentProps<typeof CollapsiblePrimitive.Trigger>) {
25
+ return <CollapsiblePrimitive.Trigger data-slot="collapsible-trigger" {...props} />
26
+ }
27
+
28
+ function CollapsibleContent({
29
+ ...props
30
+ }: React.ComponentProps<typeof CollapsiblePrimitive.Content>) {
31
+ return <CollapsiblePrimitive.Content data-slot="collapsible-content" {...props} />
32
+ }
33
+
34
+ export { Collapsible, CollapsibleTrigger, CollapsibleContent }