@brightlocal/ui-components 0.1.1 → 0.1.3
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.
- package/dist/accordion.cjs +1 -1
- package/dist/accordion.d.ts +74 -4
- package/dist/accordion.d.ts.map +1 -1
- package/dist/accordion.js +100 -105
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +30 -10
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +129 -132
- package/dist/alert.d.ts +22 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/aspect-ratio.cjs +1 -1
- package/dist/aspect-ratio.d.ts +11 -1
- package/dist/aspect-ratio.d.ts.map +1 -1
- package/dist/aspect-ratio.js +16 -20
- package/dist/avatar.cjs +1 -1
- package/dist/avatar.d.ts +43 -3
- package/dist/avatar.d.ts.map +1 -1
- package/dist/avatar.js +18 -16
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts +24 -9
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +34 -32
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.d.ts.map +1 -1
- package/dist/blocks/data-table.js +209 -202
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +1 -1
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +154 -154
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts +63 -8
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +97 -93
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts +17 -45
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +49 -50
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.d.ts +12 -0
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +10 -8
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +58 -18
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +60 -51
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +99 -9
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +142 -128
- package/dist/centred-layout.cjs +1 -1
- package/dist/centred-layout.d.ts +18 -2
- package/dist/centred-layout.d.ts.map +1 -1
- package/dist/centred-layout.js +46 -33
- package/dist/chart.cjs +4 -4
- package/dist/chart.d.ts +70 -7
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +71 -66
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.d.ts +9 -5
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +61 -82
- package/dist/collapsible.cjs +1 -1
- package/dist/collapsible.d.ts +65 -8
- package/dist/collapsible.d.ts.map +1 -1
- package/dist/collapsible.js +41 -55
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts +29 -11
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +193 -159
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +115 -9
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +176 -152
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.d.ts +188 -20
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js +119 -121
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +75 -9
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +220 -81
- package/dist/description.cjs +1 -0
- package/dist/description.d.ts +37 -0
- package/dist/description.d.ts.map +1 -0
- package/dist/description.js +25 -0
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +73 -9
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +103 -112
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +92 -0
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +67 -52
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.d.ts +95 -11
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/dropdown-menu.js +146 -106
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +23 -6
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +54 -53
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +27 -17
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +86 -79
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +36 -6
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +44 -42
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +383 -387
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +21 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +51 -41
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +24 -25
- package/dist/input.cjs +1 -1
- package/dist/input.d.ts +38 -24
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +68 -136
- package/dist/label.cjs +1 -1
- package/dist/label.d.ts +20 -1
- package/dist/label.d.ts.map +1 -1
- package/dist/label.js +31 -18
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +3 -0
- package/dist/logo.d.ts.map +1 -1
- package/dist/logo.js +12 -10
- package/dist/menubar.cjs +1 -1
- package/dist/menubar.d.ts +40 -6
- package/dist/menubar.d.ts.map +1 -1
- package/dist/menubar.js +97 -76
- package/dist/popover.cjs +1 -1
- package/dist/popover.d.ts +59 -4
- package/dist/popover.d.ts.map +1 -1
- package/dist/popover.js +42 -34
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +9 -2
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +71 -59
- package/dist/radio-group.d.ts +40 -0
- package/dist/radio-group.d.ts.map +1 -1
- package/dist/rating.d.ts +4 -0
- package/dist/rating.d.ts.map +1 -1
- package/dist/resizable.cjs +1 -1
- package/dist/resizable.d.ts +65 -4
- package/dist/resizable.d.ts.map +1 -1
- package/dist/resizable.js +53 -36
- package/dist/scroll-area.cjs +1 -1
- package/dist/scroll-area.d.ts +46 -5
- package/dist/scroll-area.d.ts.map +1 -1
- package/dist/scroll-area.js +42 -38
- package/dist/select.cjs +1 -1
- package/dist/select.d.ts +30 -0
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +64 -54
- package/dist/separator.cjs +1 -1
- package/dist/separator.d.ts +49 -2
- package/dist/separator.d.ts.map +1 -1
- package/dist/separator.js +48 -36
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +80 -9
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +117 -113
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.d.ts +24 -2
- package/dist/skeleton.d.ts.map +1 -1
- package/dist/skeleton.js +15 -9
- package/dist/slider.cjs +1 -1
- package/dist/slider.d.ts +18 -4
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +72 -66
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts +4 -2
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +29 -28
- package/dist/split-layout.d.ts +4 -1
- package/dist/split-layout.d.ts.map +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.js +1 -1
- package/dist/toggle-group.cjs +1 -1
- package/dist/toggle-group.d.ts +3 -1
- package/dist/toggle-group.d.ts.map +1 -1
- package/dist/toggle-group.js +38 -36
- package/package.json +8 -2
- package/src/blocks/data-table.tsx +42 -32
- package/src/blocks/sidebar.tsx +4 -12
- package/src/components/accordion.tsx +163 -77
- package/src/components/alert-dialog.tsx +156 -111
- package/src/components/alert.tsx +26 -13
- package/src/components/aspect-ratio.tsx +25 -16
- package/src/components/avatar.tsx +56 -8
- package/src/components/badge.tsx +65 -42
- package/src/components/breadcrumb.tsx +158 -82
- package/src/components/button.tsx +41 -62
- package/src/components/calendar.tsx +16 -2
- package/src/components/card.tsx +92 -40
- package/src/components/carousel.tsx +240 -115
- package/src/components/centred-layout.tsx +67 -35
- package/src/components/chart.tsx +118 -47
- package/src/components/checkbox.tsx +42 -78
- package/src/components/collapsible.tsx +95 -26
- package/src/components/combobox.tsx +242 -144
- package/src/components/command.tsx +295 -121
- package/src/components/context-menu.tsx +278 -81
- package/src/components/date-picker.tsx +281 -30
- package/src/components/description.tsx +60 -0
- package/src/components/dialog.tsx +162 -86
- package/src/components/drawer.tsx +76 -2
- package/src/components/dropdown-menu.tsx +143 -37
- package/src/components/field.tsx +36 -11
- package/src/components/global-layout.tsx +116 -77
- package/src/components/hover-card.tsx +54 -14
- package/src/components/input-group.tsx +56 -18
- package/src/components/input-password.tsx +3 -4
- package/src/components/input.tsx +93 -186
- package/src/components/label.tsx +56 -15
- package/src/components/logo.tsx +3 -0
- package/src/components/menubar.tsx +58 -4
- package/src/components/popover.tsx +103 -20
- package/src/components/progress.tsx +82 -60
- package/src/components/radio-group.tsx +40 -0
- package/src/components/rating.tsx +4 -1
- package/src/components/resizable.tsx +119 -31
- package/src/components/scroll-area.tsx +123 -56
- package/src/components/select.tsx +21 -1
- package/src/components/separator.tsx +97 -20
- package/src/components/sheet.tsx +180 -79
- package/src/components/skeleton.tsx +40 -10
- package/src/components/slider.tsx +83 -57
- package/src/components/sonner.tsx +10 -7
- package/src/components/split-layout.tsx +4 -1
- package/src/components/table.tsx +1 -1
- package/src/components/toggle-group.tsx +4 -0
- package/src/index.ts +1 -1
- package/dist/input-base.cjs +0 -1
- package/dist/input-base.d.ts +0 -28
- package/dist/input-base.d.ts.map +0 -1
- package/dist/input-base.js +0 -56
- package/src/components/input-base.tsx +0 -86
package/src/components/chart.tsx
CHANGED
|
@@ -38,53 +38,80 @@ function useChart() {
|
|
|
38
38
|
// Chart Container
|
|
39
39
|
// ============================================================================
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Props for the ChartContainer component.
|
|
43
|
+
*/
|
|
41
44
|
interface ChartContainerProps
|
|
42
|
-
extends React.ComponentProps<"div">,
|
|
43
|
-
|
|
45
|
+
extends React.ComponentProps<"div">, ChartContextProps {
|
|
46
|
+
/**
|
|
47
|
+
* Chart content (typically a Recharts chart component)
|
|
48
|
+
*/
|
|
44
49
|
children: React.ComponentProps<
|
|
45
50
|
typeof RechartsPrimitive.ResponsiveContainer
|
|
46
51
|
>["children"];
|
|
52
|
+
/**
|
|
53
|
+
* Configuration object for chart colors and labels
|
|
54
|
+
*/
|
|
47
55
|
config: ChartConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Data hook for automated testing (required)
|
|
58
|
+
*/
|
|
48
59
|
dataHook: string;
|
|
60
|
+
/**
|
|
61
|
+
* Tracking element identifier for analytics
|
|
62
|
+
*/
|
|
49
63
|
trackingEl?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Tracking label for analytics context
|
|
66
|
+
*/
|
|
50
67
|
trackingLabel?: string;
|
|
51
68
|
}
|
|
52
69
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
70
|
+
/**
|
|
71
|
+
* ChartContainer wraps Recharts charts with theme-aware styling,
|
|
72
|
+
* responsive container, and configuration context.
|
|
73
|
+
*/
|
|
74
|
+
const ChartContainer = React.forwardRef<HTMLDivElement, ChartContainerProps>(
|
|
75
|
+
(
|
|
76
|
+
{
|
|
77
|
+
id,
|
|
78
|
+
className,
|
|
79
|
+
children,
|
|
80
|
+
config,
|
|
81
|
+
dataHook,
|
|
82
|
+
trackingEl,
|
|
83
|
+
trackingLabel,
|
|
84
|
+
...props
|
|
85
|
+
},
|
|
86
|
+
ref
|
|
87
|
+
) => {
|
|
88
|
+
const uniqueId = React.useId();
|
|
89
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<ChartContext.Provider value={{ config }}>
|
|
93
|
+
<div
|
|
94
|
+
ref={ref}
|
|
95
|
+
className={cn(
|
|
96
|
+
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-pie-sector]:stroke-background flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-pie-sector]:stroke-2 [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none [&_svg_g]:outline-none [&_svg_g]:focus:outline-none",
|
|
97
|
+
className
|
|
98
|
+
)}
|
|
99
|
+
data-chart={chartId}
|
|
100
|
+
data-hook={dataHook}
|
|
101
|
+
data-slot="chart-container"
|
|
102
|
+
data-tracking-el={trackingEl}
|
|
103
|
+
data-tracking-label={trackingLabel}
|
|
104
|
+
{...props}
|
|
105
|
+
>
|
|
106
|
+
<ChartStyle config={config} id={chartId} />
|
|
107
|
+
<RechartsPrimitive.ResponsiveContainer>
|
|
108
|
+
{children}
|
|
109
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
110
|
+
</div>
|
|
111
|
+
</ChartContext.Provider>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
);
|
|
88
115
|
|
|
89
116
|
ChartContainer.displayName = "ChartContainer";
|
|
90
117
|
|
|
@@ -135,27 +162,48 @@ function ChartStyle({ id, config }: { id: string; config: ChartConfig }) {
|
|
|
135
162
|
// Chart Tooltip
|
|
136
163
|
// ============================================================================
|
|
137
164
|
|
|
138
|
-
|
|
139
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Props for the ChartTooltip component.
|
|
167
|
+
*/
|
|
168
|
+
interface ChartTooltipProps extends React.ComponentProps<
|
|
169
|
+
typeof RechartsPrimitive.Tooltip
|
|
170
|
+
> {
|
|
171
|
+
/** Hide the tooltip label */
|
|
140
172
|
hideLabel?: boolean;
|
|
173
|
+
/** Hide the color indicator */
|
|
141
174
|
hideIndicator?: boolean;
|
|
175
|
+
/** Style of the color indicator */
|
|
142
176
|
indicator?: "line" | "dot" | "dashed";
|
|
177
|
+
/** Key to use for the series name */
|
|
143
178
|
nameKey?: string;
|
|
179
|
+
/** Key to use for the label */
|
|
144
180
|
labelKey?: string;
|
|
145
181
|
}
|
|
146
182
|
|
|
183
|
+
/**
|
|
184
|
+
* ChartTooltip displays data values on hover.
|
|
185
|
+
*/
|
|
147
186
|
function ChartTooltip({ ...props }: ChartTooltipProps) {
|
|
148
187
|
return <RechartsPrimitive.Tooltip {...props} />;
|
|
149
188
|
}
|
|
150
189
|
|
|
190
|
+
ChartTooltip.displayName = "ChartTooltip";
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Props for the ChartTooltipContent component.
|
|
194
|
+
*/
|
|
151
195
|
interface ChartTooltipContentProps
|
|
152
|
-
extends
|
|
196
|
+
extends
|
|
197
|
+
React.ComponentProps<"div">,
|
|
153
198
|
Pick<
|
|
154
199
|
ChartTooltipProps,
|
|
155
200
|
"hideLabel" | "hideIndicator" | "indicator" | "nameKey" | "labelKey"
|
|
156
201
|
> {
|
|
202
|
+
/** Custom label formatter function */
|
|
157
203
|
labelFormatter?: (value: unknown, payload: unknown[]) => React.ReactNode;
|
|
204
|
+
/** Additional CSS class for the label */
|
|
158
205
|
labelClassName?: string;
|
|
206
|
+
/** Custom value formatter function */
|
|
159
207
|
formatter?: (
|
|
160
208
|
value: unknown,
|
|
161
209
|
name: string,
|
|
@@ -165,6 +213,9 @@ interface ChartTooltipContentProps
|
|
|
165
213
|
) => React.ReactNode;
|
|
166
214
|
}
|
|
167
215
|
|
|
216
|
+
/**
|
|
217
|
+
* ChartTooltipContent renders the content inside the tooltip.
|
|
218
|
+
*/
|
|
168
219
|
function ChartTooltipContent({
|
|
169
220
|
active,
|
|
170
221
|
payload,
|
|
@@ -326,36 +377,56 @@ ChartTooltipContent.displayName = "ChartTooltipContent";
|
|
|
326
377
|
// Chart Legend
|
|
327
378
|
// ============================================================================
|
|
328
379
|
|
|
329
|
-
|
|
330
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Props for the ChartLegend component.
|
|
382
|
+
*/
|
|
383
|
+
interface ChartLegendProps extends React.ComponentProps<
|
|
384
|
+
typeof RechartsPrimitive.Legend
|
|
385
|
+
> {
|
|
386
|
+
/** Key to use for the series name */
|
|
331
387
|
nameKey?: string;
|
|
332
388
|
}
|
|
333
389
|
|
|
390
|
+
/**
|
|
391
|
+
* ChartLegend displays a legend for the chart series.
|
|
392
|
+
*/
|
|
334
393
|
function ChartLegend({ ...props }: ChartLegendProps) {
|
|
335
394
|
return <RechartsPrimitive.Legend {...props} />;
|
|
336
395
|
}
|
|
337
396
|
|
|
397
|
+
ChartLegend.displayName = "ChartLegend";
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Props for the ChartLegendContent component.
|
|
401
|
+
*/
|
|
338
402
|
interface ChartLegendContentProps
|
|
339
|
-
extends React.ComponentProps<"div">,
|
|
340
|
-
|
|
403
|
+
extends React.ComponentProps<"div">, Pick<ChartLegendProps, "nameKey"> {
|
|
404
|
+
/** Hide the series icon in the legend */
|
|
341
405
|
hideIcon?: boolean;
|
|
406
|
+
/** Legend payload from Recharts (automatically provided) */
|
|
342
407
|
payload?: Array<{
|
|
343
408
|
value: string;
|
|
344
409
|
dataKey: string;
|
|
345
410
|
color?: string;
|
|
346
411
|
payload: Record<string, unknown>;
|
|
347
412
|
}>;
|
|
413
|
+
/**
|
|
414
|
+
* Vertical alignment of the legend relative to the chart
|
|
415
|
+
* @default "bottom"
|
|
416
|
+
*/
|
|
417
|
+
verticalAlign?: "top" | "bottom";
|
|
348
418
|
}
|
|
349
419
|
|
|
420
|
+
/**
|
|
421
|
+
* ChartLegendContent renders the content inside the legend.
|
|
422
|
+
*/
|
|
350
423
|
function ChartLegendContent({
|
|
351
424
|
className,
|
|
352
425
|
hideIcon = false,
|
|
353
426
|
payload,
|
|
354
427
|
verticalAlign = "bottom",
|
|
355
428
|
nameKey,
|
|
356
|
-
}: ChartLegendContentProps
|
|
357
|
-
verticalAlign?: "top" | "bottom";
|
|
358
|
-
}) {
|
|
429
|
+
}: ChartLegendContentProps) {
|
|
359
430
|
const { config } = useChart();
|
|
360
431
|
|
|
361
432
|
if (!payload?.length) {
|
|
@@ -2,36 +2,52 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
4
4
|
import { CheckIcon } from "lucide-react";
|
|
5
|
-
import { cva } from "class-variance-authority";
|
|
5
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
6
6
|
|
|
7
7
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
|
-
import { Label } from "@brightlocal/ui-components/label";
|
|
9
8
|
|
|
10
|
-
const checkboxVariants = cva(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const checkboxVariants = cva(
|
|
10
|
+
[
|
|
11
|
+
// Layout & Size
|
|
12
|
+
"size-4 shrink-0 self-start",
|
|
13
|
+
// Appearance
|
|
14
|
+
"bg-background peer border border-ring dark:bg-input/30 rounded-xs transition-colors outline-none",
|
|
15
|
+
// Checked State
|
|
16
|
+
"data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary",
|
|
17
|
+
// Focus States
|
|
18
|
+
"focus-visible:border-ring focus-visible:shadow-default",
|
|
19
|
+
// Disabled States
|
|
20
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
21
|
+
],
|
|
22
|
+
{
|
|
23
|
+
variants: {
|
|
24
|
+
error: {
|
|
25
|
+
true: [
|
|
26
|
+
// Error state - red border with 40% opacity
|
|
27
|
+
"border-destructive/40 dark:border-destructive/60",
|
|
28
|
+
// Error focus state - solid red border with destructive shadow
|
|
29
|
+
"focus-visible:border-destructive focus-visible:shadow-destructive",
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: {
|
|
34
|
+
error: false,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
);
|
|
22
38
|
|
|
23
|
-
export interface CheckboxProps
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
> {
|
|
27
|
-
|
|
39
|
+
export interface CheckboxProps
|
|
40
|
+
extends
|
|
41
|
+
Omit<React.ComponentProps<typeof CheckboxPrimitive.Root>, "disabled">,
|
|
42
|
+
VariantProps<typeof checkboxVariants> {
|
|
43
|
+
/** Whether the checkbox is disabled */
|
|
28
44
|
disabled?: boolean;
|
|
29
|
-
|
|
30
|
-
description?: string;
|
|
45
|
+
/** Data hook for automated testing (REQUIRED) */
|
|
31
46
|
dataHook: string;
|
|
47
|
+
/** Tracking element identifier for analytics */
|
|
32
48
|
trackingEl?: string;
|
|
49
|
+
/** Tracking label for analytics context */
|
|
33
50
|
trackingLabel?: string;
|
|
34
|
-
required?: boolean;
|
|
35
51
|
}
|
|
36
52
|
|
|
37
53
|
const Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(
|
|
@@ -39,31 +55,23 @@ const Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(
|
|
|
39
55
|
{
|
|
40
56
|
className,
|
|
41
57
|
disabled = false,
|
|
42
|
-
|
|
43
|
-
description,
|
|
58
|
+
error,
|
|
44
59
|
dataHook,
|
|
45
60
|
trackingEl,
|
|
46
61
|
trackingLabel,
|
|
47
|
-
required,
|
|
48
62
|
id,
|
|
49
|
-
ariaLabel,
|
|
50
63
|
...props
|
|
51
64
|
},
|
|
52
65
|
ref
|
|
53
66
|
) => {
|
|
54
67
|
const generatedId = React.useId();
|
|
55
68
|
const checkboxId = id || generatedId;
|
|
56
|
-
const descriptionId = `${checkboxId}-description`;
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const checkboxElement = (
|
|
70
|
+
return (
|
|
61
71
|
<CheckboxPrimitive.Root
|
|
62
72
|
ref={ref}
|
|
63
|
-
aria-
|
|
64
|
-
|
|
65
|
-
aria-required={required ? "true" : undefined}
|
|
66
|
-
className={cn(checkboxVariants(), className)}
|
|
73
|
+
aria-invalid={error ? "true" : undefined}
|
|
74
|
+
className={cn(checkboxVariants({ error }), className)}
|
|
67
75
|
data-hook={dataHook}
|
|
68
76
|
data-slot="checkbox"
|
|
69
77
|
data-tracking-el={trackingEl}
|
|
@@ -80,50 +88,6 @@ const Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(
|
|
|
80
88
|
</CheckboxPrimitive.Indicator>
|
|
81
89
|
</CheckboxPrimitive.Root>
|
|
82
90
|
);
|
|
83
|
-
|
|
84
|
-
const labelElement = label && (
|
|
85
|
-
<Label
|
|
86
|
-
className={cn(
|
|
87
|
-
"cursor-pointer self-start",
|
|
88
|
-
disabled && "cursor-not-allowed opacity-70 peer-disabled:opacity-70",
|
|
89
|
-
"mt-[1px]"
|
|
90
|
-
)}
|
|
91
|
-
data-hook={dataHook ? `${dataHook}-label` : undefined}
|
|
92
|
-
htmlFor={checkboxId}
|
|
93
|
-
>
|
|
94
|
-
{label}
|
|
95
|
-
{required && <span className="sr-only"> (required)</span>}
|
|
96
|
-
</Label>
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const descriptionElement = description && (
|
|
100
|
-
<div
|
|
101
|
-
className={cn(
|
|
102
|
-
"text-muted-foreground text-sm",
|
|
103
|
-
disabled && "cursor-not-allowed"
|
|
104
|
-
)}
|
|
105
|
-
data-hook={dataHook ? `${dataHook}-description` : undefined}
|
|
106
|
-
id={descriptionId}
|
|
107
|
-
>
|
|
108
|
-
{description}
|
|
109
|
-
</div>
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
// If text is not shown, return just the checkbox
|
|
113
|
-
if (!description && !label) {
|
|
114
|
-
return checkboxElement;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// If text is shown, wrap in a container with label and description
|
|
118
|
-
return (
|
|
119
|
-
<div className="flex items-start gap-2">
|
|
120
|
-
{checkboxElement}
|
|
121
|
-
<div className="flex flex-col gap-1.5">
|
|
122
|
-
{labelElement}
|
|
123
|
-
{descriptionElement}
|
|
124
|
-
</div>
|
|
125
|
-
</div>
|
|
126
|
-
);
|
|
127
91
|
}
|
|
128
92
|
);
|
|
129
93
|
|
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import * as React from "react";
|
|
3
4
|
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Props for the Collapsible component
|
|
8
|
+
*/
|
|
9
|
+
export interface CollapsibleProps extends React.ComponentProps<
|
|
10
|
+
typeof CollapsiblePrimitive.Root
|
|
11
|
+
> {
|
|
12
|
+
/**
|
|
13
|
+
* Data hook for automated testing (required)
|
|
14
|
+
*/
|
|
11
15
|
dataHook: string;
|
|
16
|
+
/**
|
|
17
|
+
* Tracking element identifier for analytics
|
|
18
|
+
*/
|
|
12
19
|
trackingEl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Tracking label for analytics context
|
|
22
|
+
*/
|
|
13
23
|
trackingLabel?: string;
|
|
14
|
-
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Collapsible component that shows/hides content with animation
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* <Collapsible dataHook="my-collapsible">
|
|
32
|
+
* <CollapsibleTrigger>Toggle</CollapsibleTrigger>
|
|
33
|
+
* <CollapsibleContent>Content</CollapsibleContent>
|
|
34
|
+
* </Collapsible>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const Collapsible = React.forwardRef<
|
|
38
|
+
React.ComponentRef<typeof CollapsiblePrimitive.Root>,
|
|
39
|
+
CollapsibleProps
|
|
40
|
+
>(({ dataHook, trackingEl, trackingLabel, ...props }, ref) => {
|
|
15
41
|
return (
|
|
16
42
|
<CollapsiblePrimitive.Root
|
|
43
|
+
ref={ref}
|
|
17
44
|
data-hook={dataHook}
|
|
18
45
|
data-slot="collapsible"
|
|
19
46
|
data-tracking-el={trackingEl}
|
|
@@ -21,20 +48,40 @@ function Collapsible({
|
|
|
21
48
|
{...props}
|
|
22
49
|
/>
|
|
23
50
|
);
|
|
24
|
-
}
|
|
51
|
+
});
|
|
25
52
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
Collapsible.displayName = "Collapsible";
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Props for the CollapsibleTrigger component
|
|
57
|
+
*/
|
|
58
|
+
export interface CollapsibleTriggerProps extends React.ComponentProps<
|
|
59
|
+
typeof CollapsiblePrimitive.CollapsibleTrigger
|
|
60
|
+
> {
|
|
61
|
+
/**
|
|
62
|
+
* Data hook for automated testing
|
|
63
|
+
*/
|
|
64
|
+
dataHook?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Tracking element identifier for analytics
|
|
67
|
+
*/
|
|
33
68
|
trackingEl?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Tracking label for analytics context
|
|
71
|
+
*/
|
|
34
72
|
trackingLabel?: string;
|
|
35
|
-
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Trigger button that toggles the collapsible content
|
|
77
|
+
*/
|
|
78
|
+
const CollapsibleTrigger = React.forwardRef<
|
|
79
|
+
React.ComponentRef<typeof CollapsiblePrimitive.CollapsibleTrigger>,
|
|
80
|
+
CollapsibleTriggerProps
|
|
81
|
+
>(({ dataHook, trackingEl, trackingLabel, ...props }, ref) => {
|
|
36
82
|
return (
|
|
37
83
|
<CollapsiblePrimitive.CollapsibleTrigger
|
|
84
|
+
ref={ref}
|
|
38
85
|
data-hook={dataHook}
|
|
39
86
|
data-slot="collapsible-trigger"
|
|
40
87
|
data-tracking-el={trackingEl}
|
|
@@ -42,20 +89,40 @@ function CollapsibleTrigger({
|
|
|
42
89
|
{...props}
|
|
43
90
|
/>
|
|
44
91
|
);
|
|
45
|
-
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
CollapsibleTrigger.displayName = "CollapsibleTrigger";
|
|
46
95
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Props for the CollapsibleContent component
|
|
98
|
+
*/
|
|
99
|
+
export interface CollapsibleContentProps extends React.ComponentProps<
|
|
100
|
+
typeof CollapsiblePrimitive.CollapsibleContent
|
|
101
|
+
> {
|
|
102
|
+
/**
|
|
103
|
+
* Data hook for automated testing
|
|
104
|
+
*/
|
|
105
|
+
dataHook?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Tracking element identifier for analytics
|
|
108
|
+
*/
|
|
54
109
|
trackingEl?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Tracking label for analytics context
|
|
112
|
+
*/
|
|
55
113
|
trackingLabel?: string;
|
|
56
|
-
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Content container that is shown/hidden based on collapsible state
|
|
118
|
+
*/
|
|
119
|
+
const CollapsibleContent = React.forwardRef<
|
|
120
|
+
React.ComponentRef<typeof CollapsiblePrimitive.CollapsibleContent>,
|
|
121
|
+
CollapsibleContentProps
|
|
122
|
+
>(({ dataHook, trackingEl, trackingLabel, ...props }, ref) => {
|
|
57
123
|
return (
|
|
58
124
|
<CollapsiblePrimitive.CollapsibleContent
|
|
125
|
+
ref={ref}
|
|
59
126
|
data-hook={dataHook}
|
|
60
127
|
data-slot="collapsible-content"
|
|
61
128
|
data-tracking-el={trackingEl}
|
|
@@ -63,6 +130,8 @@ function CollapsibleContent({
|
|
|
63
130
|
{...props}
|
|
64
131
|
/>
|
|
65
132
|
);
|
|
66
|
-
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
CollapsibleContent.displayName = "CollapsibleContent";
|
|
67
136
|
|
|
68
137
|
export { Collapsible, CollapsibleTrigger, CollapsibleContent };
|