@brightlocal/ui-components 0.3.1 → 0.4.1
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.js +1 -1
- package/dist/alert.d.ts +2 -2
- package/dist/alert.js +3 -3
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.js +30 -30
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +2 -2
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +4 -4
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.js +12 -12
- package/dist/button.d.ts +1 -1
- package/dist/calendar.cjs +1 -1
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +6 -3
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +5 -0
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +49 -36
- package/dist/carousel.js +3 -3
- package/dist/centred-layout.cjs +1 -1
- package/dist/centred-layout.d.ts +4 -9
- package/dist/centred-layout.d.ts.map +1 -1
- package/dist/centred-layout.js +33 -48
- package/dist/checkbox.cjs +1 -1
- package/dist/checkbox.js +8 -8
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts +12 -7
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +117 -104
- package/dist/command.cjs +1 -1
- package/dist/command.js +3 -3
- package/dist/context-menu.cjs +1 -1
- package/dist/context-menu.js +3 -3
- package/dist/date-picker.js +4 -4
- package/dist/dropdown-menu.cjs +1 -1
- package/dist/dropdown-menu.js +10 -10
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +103 -10
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +113 -60
- package/dist/header.d.ts.map +1 -1
- package/dist/header.js +4 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +351 -349
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.js +1 -1
- package/dist/input-group.d.ts +1 -1
- package/dist/input-otp.js +3 -3
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.js +63 -63
- package/dist/label.cjs +1 -1
- package/dist/label.js +1 -1
- package/dist/link.cjs +1 -1
- package/dist/link.d.ts +5 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +26 -25
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts.map +1 -1
- package/dist/logo.js +17 -16
- package/dist/menubar.cjs +1 -1
- package/dist/menubar.js +3 -3
- package/dist/navigation-menu.cjs +1 -1
- package/dist/navigation-menu.d.ts.map +1 -1
- package/dist/navigation-menu.js +2 -1
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +1 -1
- package/dist/pagination.js +17 -17
- package/dist/radio-group.d.ts +2 -2
- package/dist/rating.cjs +1 -1
- package/dist/rating.js +8 -8
- package/dist/resizable.cjs +1 -1
- package/dist/resizable.d.ts +1 -1
- package/dist/resizable.js +1 -1
- package/dist/select.cjs +1 -1
- package/dist/select.d.ts +19 -14
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +108 -139
- package/dist/sheet.d.ts +1 -1
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +10 -9
- package/dist/switch.d.ts +1 -1
- package/package.json +9 -9
- package/src/blocks/data-table.tsx +5 -5
- package/src/blocks/sidebar.tsx +3 -2
- package/src/components/accordion.tsx +1 -1
- package/src/components/breadcrumb.tsx +1 -1
- package/src/components/calendar.tsx +6 -3
- package/src/components/card.tsx +24 -1
- package/src/components/centred-layout.tsx +8 -31
- package/src/components/checkbox.tsx +2 -2
- package/src/components/combobox.tsx +21 -5
- package/src/components/command.tsx +3 -3
- package/src/components/context-menu.tsx +3 -3
- package/src/components/dropdown-menu.tsx +4 -4
- package/src/components/field.tsx +187 -20
- package/src/components/header.tsx +4 -1
- package/src/components/input-password.tsx +4 -4
- package/src/components/label.tsx +1 -1
- package/src/components/link.tsx +8 -2
- package/src/components/logo.tsx +10 -9
- package/src/components/menubar.tsx +3 -3
- package/src/components/navigation-menu.tsx +2 -1
- package/src/components/pagination.tsx +3 -3
- package/src/components/rating.tsx +2 -2
- package/src/components/resizable.tsx +1 -1
- package/src/components/select.tsx +26 -90
- package/src/components/sonner.tsx +6 -5
|
@@ -205,7 +205,8 @@ function Calendar({
|
|
|
205
205
|
if (orientation === "left") {
|
|
206
206
|
return (
|
|
207
207
|
<ChevronLeft
|
|
208
|
-
className={
|
|
208
|
+
className={chevronClassName}
|
|
209
|
+
size={16}
|
|
209
210
|
{...iconProps}
|
|
210
211
|
/>
|
|
211
212
|
);
|
|
@@ -213,14 +214,16 @@ function Calendar({
|
|
|
213
214
|
if (orientation === "right") {
|
|
214
215
|
return (
|
|
215
216
|
<ChevronRight
|
|
216
|
-
className={
|
|
217
|
+
className={chevronClassName}
|
|
218
|
+
size={16}
|
|
217
219
|
{...iconProps}
|
|
218
220
|
/>
|
|
219
221
|
);
|
|
220
222
|
}
|
|
221
223
|
return (
|
|
222
224
|
<ChevronDown
|
|
223
|
-
className={
|
|
225
|
+
className={chevronClassName}
|
|
226
|
+
size={16}
|
|
224
227
|
{...iconProps}
|
|
225
228
|
/>
|
|
226
229
|
);
|
package/src/components/card.tsx
CHANGED
|
@@ -14,7 +14,15 @@ type CardVariant = "default" | "transparent" | "border" | "transparent-flush";
|
|
|
14
14
|
const CardContext = React.createContext<{ flush: boolean }>({ flush: false });
|
|
15
15
|
|
|
16
16
|
const cardVariants = cva(
|
|
17
|
-
[
|
|
17
|
+
[
|
|
18
|
+
"flex",
|
|
19
|
+
"flex-col",
|
|
20
|
+
"gap-8",
|
|
21
|
+
"rounded-xl",
|
|
22
|
+
"py-8",
|
|
23
|
+
"transition-colors",
|
|
24
|
+
"w-full",
|
|
25
|
+
],
|
|
18
26
|
{
|
|
19
27
|
variants: {
|
|
20
28
|
variant: {
|
|
@@ -61,6 +69,11 @@ type CardProps = React.ComponentProps<"div"> & {
|
|
|
61
69
|
* Tracking label for analytics context
|
|
62
70
|
*/
|
|
63
71
|
trackingLabel?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Maximum width of the card (e.g., "420px", "600px", "100%")
|
|
74
|
+
* @default "400px"
|
|
75
|
+
*/
|
|
76
|
+
maxWidth?: string | number;
|
|
64
77
|
};
|
|
65
78
|
|
|
66
79
|
/**
|
|
@@ -75,13 +88,22 @@ const Card = React.forwardRef<HTMLDivElement, CardProps>(
|
|
|
75
88
|
dataHook,
|
|
76
89
|
trackingEl,
|
|
77
90
|
trackingLabel,
|
|
91
|
+
maxWidth = "400px",
|
|
78
92
|
children,
|
|
93
|
+
style,
|
|
79
94
|
...props
|
|
80
95
|
},
|
|
81
96
|
ref
|
|
82
97
|
) => {
|
|
83
98
|
const flush = variant === "transparent-flush";
|
|
84
99
|
|
|
100
|
+
const maxWidthStyle =
|
|
101
|
+
maxWidth !== undefined
|
|
102
|
+
? {
|
|
103
|
+
maxWidth: typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth,
|
|
104
|
+
}
|
|
105
|
+
: undefined;
|
|
106
|
+
|
|
85
107
|
return (
|
|
86
108
|
<CardContext.Provider value={{ flush }}>
|
|
87
109
|
<div
|
|
@@ -91,6 +113,7 @@ const Card = React.forwardRef<HTMLDivElement, CardProps>(
|
|
|
91
113
|
data-slot="card"
|
|
92
114
|
data-tracking-el={trackingEl || `card-${variant}`}
|
|
93
115
|
data-tracking-label={trackingLabel}
|
|
116
|
+
style={{ ...maxWidthStyle, ...style }}
|
|
94
117
|
{...props}
|
|
95
118
|
>
|
|
96
119
|
{children}
|
|
@@ -7,14 +7,13 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
|
7
7
|
* -----------------------------------------------------------------------------------------------*/
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* CentredLayout provides a
|
|
10
|
+
* CentredLayout provides a full-page centered container.
|
|
11
11
|
*
|
|
12
12
|
* Spacing tokens used:
|
|
13
|
-
* - Padding:
|
|
13
|
+
* - Padding: section-padding-x/y tokens (responsive: 16px mobile, 24px desktop)
|
|
14
14
|
* - Header to content gap: gap-4 (spacing.4 = 16px)
|
|
15
|
-
* - Max width: max-w-7xl (1280px) by default
|
|
16
15
|
*
|
|
17
|
-
* The component centers content horizontally and vertically.
|
|
16
|
+
* The component takes full page width/height and centers content horizontally and vertically.
|
|
18
17
|
*
|
|
19
18
|
* @example
|
|
20
19
|
* // Basic usage
|
|
@@ -49,50 +48,28 @@ interface CentredLayoutProps extends React.ComponentProps<"div"> {
|
|
|
49
48
|
* Tracking label for analytics context
|
|
50
49
|
*/
|
|
51
50
|
trackingLabel?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Custom max-width value (overrides default 1280px)
|
|
54
|
-
*/
|
|
55
|
-
maxWidth?: string | number;
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
/**
|
|
59
|
-
* CentredLayout component for centering content with
|
|
54
|
+
* CentredLayout component for centering content with full page width/height.
|
|
60
55
|
*/
|
|
61
56
|
const CentredLayout = React.forwardRef<HTMLDivElement, CentredLayoutProps>(
|
|
62
57
|
(
|
|
63
|
-
{
|
|
64
|
-
className,
|
|
65
|
-
maxWidth,
|
|
66
|
-
children,
|
|
67
|
-
dataHook,
|
|
68
|
-
trackingEl,
|
|
69
|
-
trackingLabel,
|
|
70
|
-
...props
|
|
71
|
-
},
|
|
58
|
+
{ className, children, dataHook, trackingEl, trackingLabel, ...props },
|
|
72
59
|
ref
|
|
73
60
|
) => {
|
|
74
|
-
// If custom maxWidth is provided, use inline style; otherwise use default max-w-7xl
|
|
75
|
-
const maxWidthStyle =
|
|
76
|
-
maxWidth !== undefined
|
|
77
|
-
? {
|
|
78
|
-
maxWidth: typeof maxWidth === "number" ? `${maxWidth}px` : maxWidth,
|
|
79
|
-
}
|
|
80
|
-
: undefined;
|
|
81
|
-
|
|
82
61
|
return (
|
|
83
62
|
<div
|
|
84
63
|
ref={ref}
|
|
85
64
|
className={cn(
|
|
86
|
-
// Base styles with
|
|
87
|
-
"bg-background flex min-h-screen flex-col items-center justify-center gap-4 p-
|
|
88
|
-
!maxWidth && "max-w-7xl",
|
|
65
|
+
// Base styles with section-padding tokens (responsive: 16px mobile, 24px desktop) and gap-4 for header/content spacing
|
|
66
|
+
"bg-background flex min-h-screen w-full flex-col items-center justify-center gap-4 p-section",
|
|
89
67
|
className
|
|
90
68
|
)}
|
|
91
69
|
data-hook={dataHook}
|
|
92
70
|
data-slot="centred-layout"
|
|
93
71
|
data-tracking-el={trackingEl}
|
|
94
72
|
data-tracking-label={trackingLabel}
|
|
95
|
-
style={maxWidthStyle}
|
|
96
73
|
{...props}
|
|
97
74
|
>
|
|
98
75
|
{children}
|
|
@@ -161,7 +138,7 @@ const CentredLayoutContent = React.forwardRef<
|
|
|
161
138
|
<div
|
|
162
139
|
ref={ref}
|
|
163
140
|
className={cn(
|
|
164
|
-
"flex flex-1 flex-col items-center justify-center",
|
|
141
|
+
"flex w-full flex-1 flex-col items-center justify-center",
|
|
165
142
|
className
|
|
166
143
|
)}
|
|
167
144
|
data-slot="centred-layout-content"
|
|
@@ -8,7 +8,7 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
|
8
8
|
const checkboxVariants = cva(
|
|
9
9
|
[
|
|
10
10
|
// Layout & Size
|
|
11
|
-
"size-4 shrink-0 self-start",
|
|
11
|
+
"size-4 shrink-0 self-start mt-0.5",
|
|
12
12
|
// Appearance
|
|
13
13
|
"bg-background peer border border-ring dark:bg-input/30 rounded-xs transition-colors outline-none",
|
|
14
14
|
// Checked State
|
|
@@ -83,7 +83,7 @@ const Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(
|
|
|
83
83
|
className="flex items-center justify-center text-current transition-none"
|
|
84
84
|
data-slot="checkbox-indicator"
|
|
85
85
|
>
|
|
86
|
-
<CheckIcon
|
|
86
|
+
<CheckIcon size={14} />
|
|
87
87
|
</CheckboxPrimitive.Indicator>
|
|
88
88
|
</CheckboxPrimitive.Root>
|
|
89
89
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import { ChevronsUpDownIcon, CheckIcon
|
|
4
|
+
import { ChevronsUpDownIcon, CheckIcon } from "@brightlocal/icons";
|
|
5
5
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
6
6
|
|
|
7
7
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
@@ -261,7 +261,8 @@ const ComboboxTrigger = React.forwardRef<
|
|
|
261
261
|
{children}
|
|
262
262
|
<ChevronsUpDownIcon
|
|
263
263
|
aria-hidden="true"
|
|
264
|
-
className="text-muted-foreground ml-auto
|
|
264
|
+
className="text-muted-foreground ml-auto shrink-0"
|
|
265
|
+
size={16}
|
|
265
266
|
/>
|
|
266
267
|
</button>
|
|
267
268
|
</PopoverTrigger>
|
|
@@ -311,6 +312,11 @@ export interface ComboboxContentProps {
|
|
|
311
312
|
children: React.ReactNode;
|
|
312
313
|
/** Alignment of the popover relative to trigger */
|
|
313
314
|
align?: "start" | "center" | "end";
|
|
315
|
+
/**
|
|
316
|
+
* Hide the list area (and the input border). Useful for async search
|
|
317
|
+
* where you want to hide results until a minimum character count.
|
|
318
|
+
*/
|
|
319
|
+
hideList?: boolean;
|
|
314
320
|
}
|
|
315
321
|
|
|
316
322
|
function ComboboxContent({
|
|
@@ -318,6 +324,7 @@ function ComboboxContent({
|
|
|
318
324
|
className,
|
|
319
325
|
children,
|
|
320
326
|
align = "start",
|
|
327
|
+
hideList = false,
|
|
321
328
|
}: ComboboxContentProps) {
|
|
322
329
|
const { shouldFilter } = useComboboxContext();
|
|
323
330
|
|
|
@@ -326,9 +333,14 @@ function ComboboxContent({
|
|
|
326
333
|
align={align}
|
|
327
334
|
className={cn("w-[var(--radix-popover-trigger-width)] p-0", className)}
|
|
328
335
|
data-slot="combobox-popover"
|
|
336
|
+
side="bottom"
|
|
329
337
|
>
|
|
330
338
|
<Command
|
|
331
|
-
className=
|
|
339
|
+
className={cn(
|
|
340
|
+
"border-0 shadow-none",
|
|
341
|
+
hideList &&
|
|
342
|
+
"[&_[data-slot='command-input-wrapper']]:border-b-0"
|
|
343
|
+
)}
|
|
332
344
|
data-slot="combobox-command"
|
|
333
345
|
dataHook={dataHook || "combobox-command"}
|
|
334
346
|
shouldFilter={shouldFilter}
|
|
@@ -527,7 +539,8 @@ const ComboboxItem = React.forwardRef<
|
|
|
527
539
|
{isSelected && (
|
|
528
540
|
<CheckIcon
|
|
529
541
|
aria-hidden="true"
|
|
530
|
-
className="text-muted-foreground
|
|
542
|
+
className="text-muted-foreground shrink-0"
|
|
543
|
+
size={16}
|
|
531
544
|
/>
|
|
532
545
|
)}
|
|
533
546
|
</CommandItem>
|
|
@@ -576,7 +589,10 @@ function ComboboxLoading({ className, children }: ComboboxLoadingProps) {
|
|
|
576
589
|
>
|
|
577
590
|
{children || (
|
|
578
591
|
<>
|
|
579
|
-
<
|
|
592
|
+
<div
|
|
593
|
+
aria-hidden="true"
|
|
594
|
+
className="size-4 animate-spin rounded-full border-2 border-current border-t-transparent [animation-duration:0.6s]"
|
|
595
|
+
/>
|
|
580
596
|
Loading...
|
|
581
597
|
</>
|
|
582
598
|
)}
|
|
@@ -127,7 +127,7 @@ const CommandInput = React.forwardRef<
|
|
|
127
127
|
data-hook={dataHook}
|
|
128
128
|
data-slot="command-input-wrapper"
|
|
129
129
|
>
|
|
130
|
-
<SearchIcon className="
|
|
130
|
+
<SearchIcon className="shrink-0 opacity-50" size={16} />
|
|
131
131
|
<CommandPrimitive.Input
|
|
132
132
|
ref={inputRef}
|
|
133
133
|
className={cn(
|
|
@@ -149,7 +149,7 @@ const CommandInput = React.forwardRef<
|
|
|
149
149
|
variant="ghost"
|
|
150
150
|
onClick={handleClear}
|
|
151
151
|
>
|
|
152
|
-
<XIcon
|
|
152
|
+
<XIcon size={16} />
|
|
153
153
|
</Button>
|
|
154
154
|
)}
|
|
155
155
|
</div>
|
|
@@ -337,7 +337,7 @@ const CommandItem = React.forwardRef<
|
|
|
337
337
|
{...props}
|
|
338
338
|
>
|
|
339
339
|
{children}
|
|
340
|
-
{selected && <CheckIcon className="text-foreground ml-auto size
|
|
340
|
+
{selected && <CheckIcon className="text-foreground ml-auto" size={16} />}
|
|
341
341
|
</CommandPrimitive.Item>
|
|
342
342
|
)
|
|
343
343
|
);
|
|
@@ -175,7 +175,7 @@ const ContextMenuSubTrigger = React.forwardRef<
|
|
|
175
175
|
{...props}
|
|
176
176
|
>
|
|
177
177
|
{children}
|
|
178
|
-
<ChevronRight className="ml-auto size
|
|
178
|
+
<ChevronRight className="ml-auto" size={16} />
|
|
179
179
|
</ContextMenuPrimitive.SubTrigger>
|
|
180
180
|
)
|
|
181
181
|
);
|
|
@@ -341,7 +341,7 @@ const ContextMenuCheckboxItem = React.forwardRef<
|
|
|
341
341
|
>
|
|
342
342
|
<span className="absolute left-2 flex size-3.5 items-center justify-center">
|
|
343
343
|
<ContextMenuPrimitive.ItemIndicator>
|
|
344
|
-
<Check
|
|
344
|
+
<Check size={16} />
|
|
345
345
|
</ContextMenuPrimitive.ItemIndicator>
|
|
346
346
|
</span>
|
|
347
347
|
{children}
|
|
@@ -395,7 +395,7 @@ const ContextMenuRadioItem = React.forwardRef<
|
|
|
395
395
|
>
|
|
396
396
|
<span className="absolute left-2 flex size-3.5 items-center justify-center">
|
|
397
397
|
<ContextMenuPrimitive.ItemIndicator>
|
|
398
|
-
<Circle className="
|
|
398
|
+
<Circle className="fill-current" size={8} />
|
|
399
399
|
</ContextMenuPrimitive.ItemIndicator>
|
|
400
400
|
</span>
|
|
401
401
|
{children}
|
|
@@ -281,7 +281,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
|
|
|
281
281
|
>
|
|
282
282
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
283
283
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
284
|
-
<Check
|
|
284
|
+
<Check size={16} />
|
|
285
285
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
286
286
|
</span>
|
|
287
287
|
{children}
|
|
@@ -354,7 +354,7 @@ const DropdownMenuRadioItem = React.forwardRef<
|
|
|
354
354
|
>
|
|
355
355
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
356
356
|
<DropdownMenuPrimitive.ItemIndicator>
|
|
357
|
-
<Circle className="
|
|
357
|
+
<Circle className="fill-current" size={8} />
|
|
358
358
|
</DropdownMenuPrimitive.ItemIndicator>
|
|
359
359
|
</span>
|
|
360
360
|
{children}
|
|
@@ -515,7 +515,7 @@ const DropdownMenuSubTrigger = React.forwardRef<
|
|
|
515
515
|
{...props}
|
|
516
516
|
>
|
|
517
517
|
{children}
|
|
518
|
-
<ChevronRight className="ml-auto size
|
|
518
|
+
<ChevronRight className="ml-auto" size={16} />
|
|
519
519
|
</DropdownMenuPrimitive.SubTrigger>
|
|
520
520
|
);
|
|
521
521
|
}
|
|
@@ -647,7 +647,7 @@ const DropdownMenuTriggerAvatar = React.forwardRef<
|
|
|
647
647
|
</span>
|
|
648
648
|
)}
|
|
649
649
|
</div>
|
|
650
|
-
<ChevronsUpDown className="text-muted-foreground
|
|
650
|
+
<ChevronsUpDown className="text-muted-foreground opacity-50" size={16} />
|
|
651
651
|
</DropdownMenuPrimitive.Trigger>
|
|
652
652
|
);
|
|
653
653
|
}
|
package/src/components/field.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
2
|
|
|
3
|
+
import { AlertCircle, type LucideProps } from "@brightlocal/icons";
|
|
3
4
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
4
5
|
import { Description } from "./description";
|
|
5
6
|
import { Label } from "@brightlocal/ui-components/label";
|
|
@@ -68,13 +69,13 @@ const fieldVariants = cva("group/field flex w-full gap-2", {
|
|
|
68
69
|
orientation: {
|
|
69
70
|
vertical: ["flex-col [&>*]:w-full [&>.sr-only]:w-auto"],
|
|
70
71
|
horizontal: [
|
|
71
|
-
"
|
|
72
|
-
"[&>[data-slot=field-
|
|
72
|
+
"grid grid-cols-[auto_1fr] items-center",
|
|
73
|
+
"[&>[data-slot=field-description]]:col-start-2 [&>[data-slot=field-error]]:col-start-2",
|
|
73
74
|
"has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
|
74
75
|
],
|
|
75
76
|
responsive: [
|
|
76
|
-
"flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:
|
|
77
|
-
"@md/field-group:[&>[data-slot=field-
|
|
77
|
+
"flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:grid @md/field-group:grid-cols-[auto_1fr] @md/field-group:items-center @md/field-group:[&>*]:w-auto",
|
|
78
|
+
"@md/field-group:[&>[data-slot=field-description]]:col-start-2 @md/field-group:[&>[data-slot=field-error]]:col-start-2",
|
|
78
79
|
"@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
|
79
80
|
],
|
|
80
81
|
},
|
|
@@ -88,23 +89,12 @@ const fieldVariants = cva("group/field flex w-full gap-2", {
|
|
|
88
89
|
* Props for the Field component
|
|
89
90
|
*/
|
|
90
91
|
interface FieldProps
|
|
91
|
-
extends React.ComponentProps<"div">, VariantProps<typeof fieldVariants> {
|
|
92
|
-
/**
|
|
93
|
-
* Data hook for automated testing
|
|
94
|
-
*/
|
|
95
|
-
dataHook?: string;
|
|
96
|
-
}
|
|
92
|
+
extends React.ComponentProps<"div">, VariantProps<typeof fieldVariants> {}
|
|
97
93
|
|
|
98
|
-
function Field({
|
|
99
|
-
className,
|
|
100
|
-
orientation = "vertical",
|
|
101
|
-
dataHook,
|
|
102
|
-
...props
|
|
103
|
-
}: FieldProps) {
|
|
94
|
+
function Field({ className, orientation = "vertical", ...props }: FieldProps) {
|
|
104
95
|
return (
|
|
105
96
|
<div
|
|
106
97
|
className={cn(fieldVariants({ orientation }), className)}
|
|
107
|
-
data-hook={dataHook}
|
|
108
98
|
data-orientation={orientation}
|
|
109
99
|
data-slot="field"
|
|
110
100
|
role="group"
|
|
@@ -131,9 +121,18 @@ interface FieldLabelProps extends React.ComponentProps<typeof Label> {
|
|
|
131
121
|
* Required htmlFor attribute for linking label with input
|
|
132
122
|
*/
|
|
133
123
|
htmlFor: string;
|
|
124
|
+
/**
|
|
125
|
+
* Data hook for automated testing (REQUIRED)
|
|
126
|
+
*/
|
|
127
|
+
dataHook: string;
|
|
134
128
|
}
|
|
135
129
|
|
|
136
|
-
function FieldLabel({
|
|
130
|
+
function FieldLabel({
|
|
131
|
+
className,
|
|
132
|
+
htmlFor,
|
|
133
|
+
dataHook,
|
|
134
|
+
...props
|
|
135
|
+
}: FieldLabelProps) {
|
|
137
136
|
return (
|
|
138
137
|
<Label
|
|
139
138
|
className={cn(
|
|
@@ -145,6 +144,7 @@ function FieldLabel({ className, htmlFor, ...props }: FieldLabelProps) {
|
|
|
145
144
|
"has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
|
|
146
145
|
className
|
|
147
146
|
)}
|
|
147
|
+
data-hook={dataHook}
|
|
148
148
|
data-slot="field-label"
|
|
149
149
|
htmlFor={htmlFor}
|
|
150
150
|
{...props}
|
|
@@ -152,7 +152,18 @@ function FieldLabel({ className, htmlFor, ...props }: FieldLabelProps) {
|
|
|
152
152
|
);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
interface FieldDescriptionProps extends React.ComponentProps<"p"> {
|
|
156
|
+
/**
|
|
157
|
+
* Data hook for automated testing (REQUIRED)
|
|
158
|
+
*/
|
|
159
|
+
dataHook: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function FieldDescription({
|
|
163
|
+
className,
|
|
164
|
+
dataHook,
|
|
165
|
+
...props
|
|
166
|
+
}: FieldDescriptionProps) {
|
|
156
167
|
return (
|
|
157
168
|
<Description
|
|
158
169
|
className={cn(
|
|
@@ -162,16 +173,172 @@ function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|
|
162
173
|
"last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
|
|
163
174
|
className
|
|
164
175
|
)}
|
|
176
|
+
data-hook={dataHook}
|
|
165
177
|
data-slot="field-description"
|
|
166
178
|
{...props}
|
|
167
179
|
/>
|
|
168
180
|
);
|
|
169
181
|
}
|
|
170
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Error object type for form library integration
|
|
185
|
+
*/
|
|
186
|
+
interface FieldErrorItem {
|
|
187
|
+
message?: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Props for the FieldError component
|
|
192
|
+
*/
|
|
193
|
+
interface FieldErrorProps extends Omit<
|
|
194
|
+
React.ComponentProps<"div">,
|
|
195
|
+
"children"
|
|
196
|
+
> {
|
|
197
|
+
/**
|
|
198
|
+
* Data hook for automated testing (REQUIRED)
|
|
199
|
+
*/
|
|
200
|
+
dataHook: string;
|
|
201
|
+
/**
|
|
202
|
+
* Error message to display as children
|
|
203
|
+
*/
|
|
204
|
+
children?: React.ReactNode;
|
|
205
|
+
/**
|
|
206
|
+
* Array of error objects from form libraries (e.g., react-hook-form)
|
|
207
|
+
* Each error object should have a message property
|
|
208
|
+
*/
|
|
209
|
+
errors?: Array<FieldErrorItem | undefined>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
interface FieldErrorIconProps extends Omit<LucideProps, "ref"> {
|
|
213
|
+
/**
|
|
214
|
+
* Custom icon component to render instead of the default AlertCircle.
|
|
215
|
+
* Pass a BrightLocal icon component (not an element).
|
|
216
|
+
* @default AlertCircle
|
|
217
|
+
*/
|
|
218
|
+
icon?: React.ComponentType<LucideProps>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* FieldErrorIcon displays an error icon with proper styling.
|
|
223
|
+
* Use this component inside FieldError for composition - place it before or after
|
|
224
|
+
* the error text to control icon position.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```tsx
|
|
228
|
+
* // Default AlertCircle icon
|
|
229
|
+
* <FieldError>
|
|
230
|
+
* <FieldErrorIcon /> Enter a valid email address.
|
|
231
|
+
* </FieldError>
|
|
232
|
+
*
|
|
233
|
+
* // Custom icon
|
|
234
|
+
* <FieldError>
|
|
235
|
+
* <FieldErrorIcon icon={XCircle} /> Enter a valid email address.
|
|
236
|
+
* </FieldError>
|
|
237
|
+
*
|
|
238
|
+
* // Icon after text
|
|
239
|
+
* <FieldError>
|
|
240
|
+
* Enter a valid email address. <FieldErrorIcon />
|
|
241
|
+
* </FieldError>
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
function FieldErrorIcon({
|
|
245
|
+
icon: Icon = AlertCircle,
|
|
246
|
+
className,
|
|
247
|
+
...props
|
|
248
|
+
}: FieldErrorIconProps) {
|
|
249
|
+
return (
|
|
250
|
+
<Icon
|
|
251
|
+
aria-hidden="true"
|
|
252
|
+
className={cn("inline-block shrink-0 align-text-bottom", className)}
|
|
253
|
+
{...props}
|
|
254
|
+
/>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* FieldError displays validation error messages within a Field.
|
|
260
|
+
*
|
|
261
|
+
* Supports both direct children content and an errors array for form library integration.
|
|
262
|
+
* Uses role="alert" for accessibility, ensuring screen readers announce error messages.
|
|
263
|
+
* No icon is displayed by default - use FieldErrorIcon for composition.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```tsx
|
|
267
|
+
* // Simple usage without icon
|
|
268
|
+
* <FieldError>Enter a valid email address.</FieldError>
|
|
269
|
+
*
|
|
270
|
+
* // With icon (composition pattern)
|
|
271
|
+
* <FieldError>
|
|
272
|
+
* <FieldErrorIcon /> Enter a valid email address.
|
|
273
|
+
* </FieldError>
|
|
274
|
+
*
|
|
275
|
+
* // With custom icon
|
|
276
|
+
* <FieldError>
|
|
277
|
+
* <FieldErrorIcon icon={XCircle} /> Error message
|
|
278
|
+
* </FieldError>
|
|
279
|
+
*
|
|
280
|
+
* // With react-hook-form errors array
|
|
281
|
+
* <FieldError errors={[fieldState.error]} />
|
|
282
|
+
*
|
|
283
|
+
* // Multiple errors rendered as list
|
|
284
|
+
* <FieldError errors={[{ message: "Too short" }, { message: "Invalid format" }]} />
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
function FieldError({
|
|
288
|
+
className,
|
|
289
|
+
dataHook,
|
|
290
|
+
children,
|
|
291
|
+
errors,
|
|
292
|
+
...props
|
|
293
|
+
}: FieldErrorProps) {
|
|
294
|
+
// Filter out undefined errors and those without messages
|
|
295
|
+
const errorMessages = errors?.filter((e): e is FieldErrorItem =>
|
|
296
|
+
Boolean(e?.message)
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// If no children and no valid errors, don't render anything
|
|
300
|
+
if (!children && (!errorMessages || errorMessages.length === 0)) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const baseStyles = cn(
|
|
305
|
+
"text-destructive-foreground text-sm font-normal leading-5",
|
|
306
|
+
"mt-2",
|
|
307
|
+
"group-has-[[data-orientation=horizontal]]/field:text-balance",
|
|
308
|
+
"last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
|
|
309
|
+
className
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
// If multiple errors, render as a list
|
|
313
|
+
const isMultiple = errorMessages && errorMessages.length > 1;
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<div
|
|
317
|
+
className={baseStyles}
|
|
318
|
+
data-hook={dataHook}
|
|
319
|
+
data-slot="field-error"
|
|
320
|
+
role="alert"
|
|
321
|
+
{...props}
|
|
322
|
+
>
|
|
323
|
+
{isMultiple ? (
|
|
324
|
+
<ul className="list-disc space-y-1 pl-4">
|
|
325
|
+
{errorMessages.map((error, index) => (
|
|
326
|
+
<li key={index}>{error.message}</li>
|
|
327
|
+
))}
|
|
328
|
+
</ul>
|
|
329
|
+
) : (
|
|
330
|
+
<p className="m-0">{children || errorMessages?.[0]?.message}</p>
|
|
331
|
+
)}
|
|
332
|
+
</div>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
171
336
|
export {
|
|
172
337
|
Field,
|
|
173
338
|
FieldLabel,
|
|
174
339
|
FieldDescription,
|
|
340
|
+
FieldError,
|
|
341
|
+
FieldErrorIcon,
|
|
175
342
|
FieldGroup,
|
|
176
343
|
FieldLegend,
|
|
177
344
|
fieldLegendVariants,
|
|
@@ -179,4 +346,4 @@ export {
|
|
|
179
346
|
FieldContent,
|
|
180
347
|
};
|
|
181
348
|
|
|
182
|
-
export type { FieldProps };
|
|
349
|
+
export type { FieldProps, FieldErrorProps };
|
|
@@ -49,7 +49,10 @@ const Header = React.forwardRef<HTMLElement, HeaderProps>(
|
|
|
49
49
|
return (
|
|
50
50
|
<header
|
|
51
51
|
ref={ref}
|
|
52
|
-
className={cn(
|
|
52
|
+
className={cn(
|
|
53
|
+
"flex items-center",
|
|
54
|
+
className
|
|
55
|
+
)}
|
|
53
56
|
data-hook={dataHook}
|
|
54
57
|
data-slot="header"
|
|
55
58
|
data-tracking-el={trackingEl}
|
|
@@ -382,9 +382,9 @@ const InputPasswordField = React.forwardRef<
|
|
|
382
382
|
onClick={toggleVisibility}
|
|
383
383
|
>
|
|
384
384
|
{showPassword ? (
|
|
385
|
-
<EyeOff
|
|
385
|
+
<EyeOff size={16} />
|
|
386
386
|
) : (
|
|
387
|
-
<Eye
|
|
387
|
+
<Eye size={16} />
|
|
388
388
|
)}
|
|
389
389
|
</InputGroupButton>
|
|
390
390
|
</InputGroupAddon>
|
|
@@ -449,9 +449,9 @@ const InputPasswordToggle = React.forwardRef<
|
|
|
449
449
|
{...props}
|
|
450
450
|
>
|
|
451
451
|
{showPassword ? (
|
|
452
|
-
<EyeOff
|
|
452
|
+
<EyeOff size={16} />
|
|
453
453
|
) : (
|
|
454
|
-
<Eye
|
|
454
|
+
<Eye size={16} />
|
|
455
455
|
)}
|
|
456
456
|
</InputGroupButton>
|
|
457
457
|
);
|
package/src/components/label.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { cva } from "class-variance-authority";
|
|
|
6
6
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
7
7
|
|
|
8
8
|
const labelVariants = cva(
|
|
9
|
-
["text-sm font-medium leading-
|
|
9
|
+
["text-sm font-medium leading-normal", "text-foreground"],
|
|
10
10
|
{
|
|
11
11
|
variants: {
|
|
12
12
|
optional: {
|