@brightlocal/ui-components 0.2.0 → 0.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.
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts +10 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +6 -2
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +6 -2
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +89 -73
- package/dist/centred-layout.cjs +1 -1
- package/dist/centred-layout.d.ts +49 -25
- package/dist/centred-layout.d.ts.map +1 -1
- package/dist/centred-layout.js +57 -32
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/chip.cjs +1 -0
- package/dist/chip.d.ts +61 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +165 -0
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +5 -2
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +89 -52
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +228 -210
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/header.cjs +1 -0
- package/dist/header.d.ts +42 -0
- package/dist/header.d.ts.map +1 -0
- package/dist/header.js +22 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +426 -396
- package/dist/input-chip.cjs +1 -0
- package/dist/input-chip.d.ts +117 -0
- package/dist/input-chip.d.ts.map +1 -0
- package/dist/input-chip.js +284 -0
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.d.ts +43 -36
- package/dist/input-otp.d.ts.map +1 -1
- package/dist/input-otp.js +140 -119
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +147 -19
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +197 -92
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +10 -0
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +45 -36
- package/dist/select.d.ts.map +1 -1
- package/dist/slider.cjs +1 -1
- package/dist/slider.d.ts +31 -3
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +53 -43
- package/dist/textarea.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/alert.tsx +10 -1
- package/src/components/card.tsx +66 -38
- package/src/components/centred-layout.tsx +115 -38
- package/src/components/checkbox.tsx +2 -2
- package/src/components/chip.tsx +249 -0
- package/src/components/combobox.tsx +17 -13
- package/src/components/date-picker.tsx +410 -266
- package/src/components/dropdown-menu.tsx +6 -1
- package/src/components/header.tsx +69 -0
- package/src/components/input-chip.tsx +548 -0
- package/src/components/input-group.tsx +4 -1
- package/src/components/input-otp.tsx +159 -91
- package/src/components/input-password.tsx +469 -129
- package/src/components/input.tsx +1 -1
- package/src/components/progress.tsx +21 -2
- package/src/components/select.tsx +1 -3
- package/src/components/slider.tsx +85 -15
- package/src/components/textarea.tsx +4 -1
- package/src/index.ts +3 -0
|
@@ -33,6 +33,16 @@ interface ProgressProps extends React.ComponentProps<
|
|
|
33
33
|
* Optional visible label text displayed above the progress bar
|
|
34
34
|
*/
|
|
35
35
|
label?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Custom class name for the indicator (progress fill)
|
|
38
|
+
* Use this to customize the color, e.g., "bg-red-500"
|
|
39
|
+
*/
|
|
40
|
+
indicatorClassName?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the progress is in a disabled state
|
|
43
|
+
* When disabled, the component renders with 50% opacity
|
|
44
|
+
*/
|
|
45
|
+
disabled?: boolean;
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
/**
|
|
@@ -52,6 +62,8 @@ const Progress = React.forwardRef<
|
|
|
52
62
|
trackingLabel,
|
|
53
63
|
ariaLabel = "Progress",
|
|
54
64
|
label,
|
|
65
|
+
indicatorClassName,
|
|
66
|
+
disabled,
|
|
55
67
|
...props
|
|
56
68
|
},
|
|
57
69
|
ref
|
|
@@ -67,6 +79,7 @@ const Progress = React.forwardRef<
|
|
|
67
79
|
className={cn(
|
|
68
80
|
"relative h-2 w-full overflow-hidden rounded-full",
|
|
69
81
|
"bg-primary/20",
|
|
82
|
+
!hasVisibleLabel && disabled && "opacity-50",
|
|
70
83
|
className
|
|
71
84
|
)}
|
|
72
85
|
data-hook={dataHook}
|
|
@@ -80,7 +93,10 @@ const Progress = React.forwardRef<
|
|
|
80
93
|
animate={{
|
|
81
94
|
transform: `translateX(-${100 - (value || 0)}%)`,
|
|
82
95
|
}}
|
|
83
|
-
className=
|
|
96
|
+
className={cn(
|
|
97
|
+
"h-full w-full flex-1 bg-green-400",
|
|
98
|
+
indicatorClassName
|
|
99
|
+
)}
|
|
84
100
|
data-slot="progress-indicator"
|
|
85
101
|
initial={false}
|
|
86
102
|
transition={{
|
|
@@ -100,7 +116,10 @@ const Progress = React.forwardRef<
|
|
|
100
116
|
|
|
101
117
|
return (
|
|
102
118
|
<div
|
|
103
|
-
className=
|
|
119
|
+
className={cn(
|
|
120
|
+
"flex w-full items-center gap-2",
|
|
121
|
+
disabled && "opacity-50"
|
|
122
|
+
)}
|
|
104
123
|
data-slot="progress-wrapper"
|
|
105
124
|
>
|
|
106
125
|
<span
|
|
@@ -205,9 +205,7 @@ function SelectTrigger({
|
|
|
205
205
|
}: SelectTriggerProps) {
|
|
206
206
|
// Support both error prop and aria-invalid for backwards compatibility
|
|
207
207
|
const isError =
|
|
208
|
-
error ||
|
|
209
|
-
props["aria-invalid"] === true ||
|
|
210
|
-
props["aria-invalid"] === "true";
|
|
208
|
+
error || props["aria-invalid"] === true || props["aria-invalid"] === "true";
|
|
211
209
|
const isRequired =
|
|
212
210
|
props["aria-required"] === true || props["aria-required"] === "true";
|
|
213
211
|
|
|
@@ -15,10 +15,18 @@ export interface SliderProps extends React.ComponentProps<
|
|
|
15
15
|
* Data hook for automated testing (required)
|
|
16
16
|
*/
|
|
17
17
|
dataHook: string;
|
|
18
|
+
/**
|
|
19
|
+
* Slider mode - single value or range (two thumbs).
|
|
20
|
+
* - "single": One thumb, selects a single value (default)
|
|
21
|
+
* - "range": Two thumbs, selects a min/max range
|
|
22
|
+
* @default "single"
|
|
23
|
+
*/
|
|
24
|
+
mode?: "single" | "range";
|
|
18
25
|
/**
|
|
19
26
|
* Accessible labels for the slider thumb(s).
|
|
20
|
-
* For
|
|
21
|
-
*
|
|
27
|
+
* - For single mode: provide one label (e.g., ["Volume"])
|
|
28
|
+
* - For range mode: provide two labels (e.g., ["Minimum price", "Maximum price"])
|
|
29
|
+
* @default ["Slider"] for single, ["Minimum value", "Maximum value"] for range
|
|
22
30
|
*/
|
|
23
31
|
thumbLabels?: string[];
|
|
24
32
|
/**
|
|
@@ -31,10 +39,33 @@ export interface SliderProps extends React.ComponentProps<
|
|
|
31
39
|
trackingLabel?: string;
|
|
32
40
|
}
|
|
33
41
|
|
|
42
|
+
const DEFAULT_SINGLE_LABELS = ["Slider"];
|
|
43
|
+
const DEFAULT_RANGE_LABELS = ["Minimum value", "Maximum value"];
|
|
44
|
+
|
|
34
45
|
/**
|
|
35
46
|
* Slider component for selecting numeric values within a range.
|
|
36
|
-
* Supports single value selection and range selection (two thumbs).
|
|
47
|
+
* Supports single value selection (default) and range selection (two thumbs).
|
|
37
48
|
* Built on Radix UI Slider primitive with full keyboard accessibility.
|
|
49
|
+
*
|
|
50
|
+
* @example Single value slider (controlled)
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <Slider
|
|
53
|
+
* dataHook="volume-slider"
|
|
54
|
+
* value={[50]}
|
|
55
|
+
* onValueChange={(value) => setValue(value)}
|
|
56
|
+
* thumbLabels={["Volume"]}
|
|
57
|
+
* />
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Range slider (uncontrolled)
|
|
61
|
+
* ```tsx
|
|
62
|
+
* <Slider
|
|
63
|
+
* dataHook="price-range"
|
|
64
|
+
* mode="range"
|
|
65
|
+
* defaultValue={[20, 80]}
|
|
66
|
+
* thumbLabels={["Minimum price", "Maximum price"]}
|
|
67
|
+
* />
|
|
68
|
+
* ```
|
|
38
69
|
*/
|
|
39
70
|
const Slider = React.forwardRef<
|
|
40
71
|
React.ComponentRef<typeof SliderPrimitive.Root>,
|
|
@@ -47,6 +78,7 @@ const Slider = React.forwardRef<
|
|
|
47
78
|
defaultValue,
|
|
48
79
|
max = 100,
|
|
49
80
|
min = 0,
|
|
81
|
+
mode = "single",
|
|
50
82
|
thumbLabels,
|
|
51
83
|
trackingEl,
|
|
52
84
|
trackingLabel,
|
|
@@ -55,15 +87,52 @@ const Slider = React.forwardRef<
|
|
|
55
87
|
},
|
|
56
88
|
ref
|
|
57
89
|
) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
90
|
+
// Determine thumb count based on mode and provided values
|
|
91
|
+
const thumbCount = React.useMemo(() => {
|
|
92
|
+
// If value or defaultValue is explicitly provided as array, use its length
|
|
93
|
+
if (Array.isArray(value)) return value.length;
|
|
94
|
+
if (Array.isArray(defaultValue)) return defaultValue.length;
|
|
95
|
+
// Otherwise, use mode to determine thumb count
|
|
96
|
+
return mode === "range" ? 2 : 1;
|
|
97
|
+
}, [value, defaultValue, mode]);
|
|
98
|
+
|
|
99
|
+
// Compute effective default value for Radix
|
|
100
|
+
const effectiveDefaultValue = React.useMemo(() => {
|
|
101
|
+
if (defaultValue !== undefined) return defaultValue;
|
|
102
|
+
if (value !== undefined) return undefined; // Controlled, no default needed
|
|
103
|
+
// Provide sensible defaults based on mode
|
|
104
|
+
return mode === "range" ? [min, max] : [min];
|
|
105
|
+
}, [defaultValue, value, mode, min, max]);
|
|
106
|
+
|
|
107
|
+
// Get appropriate labels with fallbacks
|
|
108
|
+
const getThumbLabel = (index: number): string => {
|
|
109
|
+
const customLabel = thumbLabels?.[index];
|
|
110
|
+
if (customLabel) return customLabel;
|
|
111
|
+
const defaultLabels =
|
|
112
|
+
thumbCount > 1 ? DEFAULT_RANGE_LABELS : DEFAULT_SINGLE_LABELS;
|
|
113
|
+
return defaultLabels[index] ?? `Slider thumb ${index + 1}`;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Dev-only warnings
|
|
117
|
+
if (process.env.NODE_ENV === "development") {
|
|
118
|
+
// Warn if both controlled and uncontrolled props are provided
|
|
119
|
+
if (value !== undefined && defaultValue !== undefined) {
|
|
120
|
+
console.warn(
|
|
121
|
+
`[Slider] Component is being used with both "value" and "defaultValue" props. ` +
|
|
122
|
+
`This is likely a mistake. Use "value" with "onValueChange" for controlled mode, ` +
|
|
123
|
+
`or "defaultValue" for uncontrolled mode, but not both.`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Warn if thumbLabels length doesn't match thumb count
|
|
128
|
+
if (thumbLabels && thumbLabels.length !== thumbCount) {
|
|
129
|
+
console.warn(
|
|
130
|
+
`[Slider] "thumbLabels" array length (${thumbLabels.length}) doesn't match ` +
|
|
131
|
+
`the number of thumbs (${thumbCount}). ` +
|
|
132
|
+
`For ${mode === "range" ? "range" : "single"} mode, provide ${thumbCount} label(s).`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
67
136
|
|
|
68
137
|
return (
|
|
69
138
|
<SliderPrimitive.Root
|
|
@@ -73,10 +142,11 @@ const Slider = React.forwardRef<
|
|
|
73
142
|
className
|
|
74
143
|
)}
|
|
75
144
|
data-hook={dataHook}
|
|
145
|
+
data-mode={mode}
|
|
76
146
|
data-slot="slider"
|
|
77
147
|
data-tracking-el={trackingEl}
|
|
78
148
|
data-tracking-label={trackingLabel}
|
|
79
|
-
defaultValue={
|
|
149
|
+
defaultValue={effectiveDefaultValue}
|
|
80
150
|
max={max}
|
|
81
151
|
min={min}
|
|
82
152
|
value={value}
|
|
@@ -95,10 +165,10 @@ const Slider = React.forwardRef<
|
|
|
95
165
|
data-slot="slider-range"
|
|
96
166
|
/>
|
|
97
167
|
</SliderPrimitive.Track>
|
|
98
|
-
{Array.from({ length:
|
|
168
|
+
{Array.from({ length: thumbCount }, (_, index) => (
|
|
99
169
|
<SliderPrimitive.Thumb
|
|
100
170
|
key={index}
|
|
101
|
-
aria-label={
|
|
171
|
+
aria-label={getThumbLabel(index)}
|
|
102
172
|
className="border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
|
103
173
|
data-slot="slider-thumb"
|
|
104
174
|
/>
|
|
@@ -50,7 +50,10 @@ interface TextareaProps extends Omit<
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
53
|
-
(
|
|
53
|
+
(
|
|
54
|
+
{ className, dataHook, error, trackingEl, trackingLabel, ...props },
|
|
55
|
+
ref
|
|
56
|
+
) => {
|
|
54
57
|
// Support both error prop and aria-invalid for backwards compatibility
|
|
55
58
|
const hasError =
|
|
56
59
|
error ||
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./components/carousel";
|
|
|
13
13
|
export * from "./components/chart";
|
|
14
14
|
export * from "./components/centred-layout";
|
|
15
15
|
export * from "./components/checkbox";
|
|
16
|
+
export * from "./components/chip";
|
|
16
17
|
export * from "./components/collapsible";
|
|
17
18
|
export * from "./components/combobox";
|
|
18
19
|
export * from "./components/command";
|
|
@@ -24,8 +25,10 @@ export * from "./components/drawer";
|
|
|
24
25
|
export * from "./components/dropdown-menu";
|
|
25
26
|
export * from "./components/field";
|
|
26
27
|
export * from "./components/global-layout";
|
|
28
|
+
export * from "./components/header";
|
|
27
29
|
export * from "./components/hover-card";
|
|
28
30
|
export * from "./components/input";
|
|
31
|
+
export * from "./components/input-chip";
|
|
29
32
|
export * from "./components/input-group";
|
|
30
33
|
export * from "./components/input-otp";
|
|
31
34
|
export * from "./components/label";
|