@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
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
5
|
+
import { X, LoaderCircle } from "@brightlocal/icons";
|
|
6
|
+
|
|
7
|
+
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
|
+
import {
|
|
9
|
+
Tooltip,
|
|
10
|
+
TooltipContent,
|
|
11
|
+
TooltipProvider,
|
|
12
|
+
TooltipTrigger,
|
|
13
|
+
} from "@brightlocal/ui-components/tooltip";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Chip size options
|
|
17
|
+
*/
|
|
18
|
+
type ChipSize = "md" | "lg";
|
|
19
|
+
|
|
20
|
+
const chipVariants = cva(
|
|
21
|
+
[
|
|
22
|
+
// Base styles
|
|
23
|
+
"inline-flex",
|
|
24
|
+
"items-center",
|
|
25
|
+
"justify-center",
|
|
26
|
+
"gap-0.5",
|
|
27
|
+
"rounded-full",
|
|
28
|
+
"font-medium",
|
|
29
|
+
"whitespace-nowrap",
|
|
30
|
+
"shrink-0",
|
|
31
|
+
"select-none",
|
|
32
|
+
// Background and text colors
|
|
33
|
+
"bg-secondary",
|
|
34
|
+
"text-foreground",
|
|
35
|
+
// Transitions
|
|
36
|
+
"transition-[color,background-color,box-shadow]",
|
|
37
|
+
"duration-150",
|
|
38
|
+
"ease-in-out",
|
|
39
|
+
// Hover state
|
|
40
|
+
"hover:bg-secondary/80",
|
|
41
|
+
// Focus state - direct focus on chip (for keyboard navigation)
|
|
42
|
+
"focus:outline-none",
|
|
43
|
+
"focus-visible:shadow-default",
|
|
44
|
+
// Disabled state
|
|
45
|
+
"disabled:pointer-events-none",
|
|
46
|
+
"disabled:opacity-50",
|
|
47
|
+
"aria-disabled:pointer-events-none",
|
|
48
|
+
"aria-disabled:opacity-50",
|
|
49
|
+
],
|
|
50
|
+
{
|
|
51
|
+
variants: {
|
|
52
|
+
size: {
|
|
53
|
+
md: ["h-7", "pl-2.5", "pr-1", "text-xs"],
|
|
54
|
+
lg: ["h-8", "pl-4", "pr-2", "text-base"],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
defaultVariants: {
|
|
58
|
+
size: "md",
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const chipDeleteButtonVariants = cva(
|
|
64
|
+
[
|
|
65
|
+
// Base styles
|
|
66
|
+
"inline-flex",
|
|
67
|
+
"items-center",
|
|
68
|
+
"justify-center",
|
|
69
|
+
"rounded-full",
|
|
70
|
+
"cursor-pointer",
|
|
71
|
+
// Colors
|
|
72
|
+
"text-muted-foreground",
|
|
73
|
+
// Hover
|
|
74
|
+
"hover:text-foreground",
|
|
75
|
+
// Focus
|
|
76
|
+
"outline-none",
|
|
77
|
+
"focus-visible:text-foreground",
|
|
78
|
+
// Disabled
|
|
79
|
+
"disabled:pointer-events-none",
|
|
80
|
+
"disabled:opacity-50",
|
|
81
|
+
],
|
|
82
|
+
{
|
|
83
|
+
variants: {
|
|
84
|
+
size: {
|
|
85
|
+
md: ["size-6"],
|
|
86
|
+
lg: ["size-6"],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
defaultVariants: {
|
|
90
|
+
size: "md",
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Props for the Chip component
|
|
97
|
+
*/
|
|
98
|
+
interface ChipProps extends Omit<React.ComponentProps<"div">, "children"> {
|
|
99
|
+
/**
|
|
100
|
+
* Chip content (text label)
|
|
101
|
+
*/
|
|
102
|
+
children: React.ReactNode;
|
|
103
|
+
/**
|
|
104
|
+
* Size variant of the chip
|
|
105
|
+
* @default "md"
|
|
106
|
+
*/
|
|
107
|
+
size?: ChipSize;
|
|
108
|
+
/**
|
|
109
|
+
* Show loading spinner instead of delete button
|
|
110
|
+
* @default false
|
|
111
|
+
*/
|
|
112
|
+
loading?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Disable the chip and its delete button
|
|
115
|
+
* @default false
|
|
116
|
+
*/
|
|
117
|
+
disabled?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Callback when delete button is clicked
|
|
120
|
+
*/
|
|
121
|
+
onRemove?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
122
|
+
/**
|
|
123
|
+
* Data hook for automated testing (required)
|
|
124
|
+
*/
|
|
125
|
+
dataHook: string;
|
|
126
|
+
/**
|
|
127
|
+
* Tracking element identifier for analytics
|
|
128
|
+
*/
|
|
129
|
+
trackingEl?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Tracking label for analytics context
|
|
132
|
+
*/
|
|
133
|
+
trackingLabel?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Maximum width of the chip label before truncation
|
|
136
|
+
* @default 200
|
|
137
|
+
*/
|
|
138
|
+
maxWidth?: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Chip component for displaying removable tags or selections.
|
|
143
|
+
* Used for filter selections, tag lists, and multi-select values.
|
|
144
|
+
*/
|
|
145
|
+
const Chip = React.forwardRef<HTMLDivElement, ChipProps>(
|
|
146
|
+
(
|
|
147
|
+
{
|
|
148
|
+
className,
|
|
149
|
+
children,
|
|
150
|
+
size = "md",
|
|
151
|
+
loading = false,
|
|
152
|
+
disabled = false,
|
|
153
|
+
onRemove,
|
|
154
|
+
dataHook,
|
|
155
|
+
trackingEl,
|
|
156
|
+
trackingLabel,
|
|
157
|
+
maxWidth = 200,
|
|
158
|
+
...props
|
|
159
|
+
},
|
|
160
|
+
ref
|
|
161
|
+
) => {
|
|
162
|
+
const isDisabled = disabled || loading;
|
|
163
|
+
const iconSize = size === "lg" ? 16 : 16;
|
|
164
|
+
const labelRef = React.useRef<HTMLSpanElement>(null);
|
|
165
|
+
const [isTruncated, setIsTruncated] = React.useState(false);
|
|
166
|
+
|
|
167
|
+
React.useEffect(() => {
|
|
168
|
+
const checkTruncation = () => {
|
|
169
|
+
if (labelRef.current) {
|
|
170
|
+
setIsTruncated(
|
|
171
|
+
labelRef.current.scrollWidth > labelRef.current.clientWidth
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
checkTruncation();
|
|
177
|
+
window.addEventListener("resize", checkTruncation);
|
|
178
|
+
return () => window.removeEventListener("resize", checkTruncation);
|
|
179
|
+
}, [children]);
|
|
180
|
+
|
|
181
|
+
const labelContent = (
|
|
182
|
+
<span
|
|
183
|
+
ref={labelRef}
|
|
184
|
+
className="truncate"
|
|
185
|
+
data-slot="chip-label"
|
|
186
|
+
style={{ maxWidth }}
|
|
187
|
+
>
|
|
188
|
+
{children}
|
|
189
|
+
</span>
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<div
|
|
194
|
+
ref={ref}
|
|
195
|
+
aria-disabled={isDisabled ? "true" : undefined}
|
|
196
|
+
className={cn(chipVariants({ size }), className)}
|
|
197
|
+
data-hook={dataHook}
|
|
198
|
+
data-slot="chip"
|
|
199
|
+
data-tracking-el={trackingEl}
|
|
200
|
+
data-tracking-label={trackingLabel}
|
|
201
|
+
{...props}
|
|
202
|
+
>
|
|
203
|
+
{isTruncated ? (
|
|
204
|
+
<TooltipProvider>
|
|
205
|
+
<Tooltip>
|
|
206
|
+
<TooltipTrigger asChild>{labelContent}</TooltipTrigger>
|
|
207
|
+
<TooltipContent dataHook={`${dataHook}-tooltip`} sideOffset={8}>
|
|
208
|
+
{children}
|
|
209
|
+
</TooltipContent>
|
|
210
|
+
</Tooltip>
|
|
211
|
+
</TooltipProvider>
|
|
212
|
+
) : (
|
|
213
|
+
labelContent
|
|
214
|
+
)}
|
|
215
|
+
{loading ? (
|
|
216
|
+
<span
|
|
217
|
+
aria-label="Loading"
|
|
218
|
+
className={cn(chipDeleteButtonVariants({ size }))}
|
|
219
|
+
data-slot="chip-loading"
|
|
220
|
+
role="status"
|
|
221
|
+
>
|
|
222
|
+
<LoaderCircle
|
|
223
|
+
className="animate-spin motion-reduce:animate-none"
|
|
224
|
+
size={iconSize}
|
|
225
|
+
/>
|
|
226
|
+
</span>
|
|
227
|
+
) : (
|
|
228
|
+
<button
|
|
229
|
+
aria-label={`Remove ${typeof children === "string" ? children : "chip"}`}
|
|
230
|
+
className={cn(chipDeleteButtonVariants({ size }))}
|
|
231
|
+
data-slot="chip-delete"
|
|
232
|
+
data-tracking-el={trackingEl ? `${trackingEl}-delete` : undefined}
|
|
233
|
+
disabled={isDisabled}
|
|
234
|
+
tabIndex={-1}
|
|
235
|
+
type="button"
|
|
236
|
+
onClick={onRemove}
|
|
237
|
+
>
|
|
238
|
+
<X size={iconSize} />
|
|
239
|
+
</button>
|
|
240
|
+
)}
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
Chip.displayName = "Chip";
|
|
247
|
+
|
|
248
|
+
export { Chip, chipVariants };
|
|
249
|
+
export type { ChipProps, ChipSize };
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import {
|
|
5
|
-
ChevronsUpDownIcon,
|
|
6
|
-
CheckIcon,
|
|
7
|
-
LoaderIcon,
|
|
8
|
-
} from "@brightlocal/icons";
|
|
4
|
+
import { ChevronsUpDownIcon, CheckIcon, LoaderIcon } from "@brightlocal/icons";
|
|
9
5
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
10
6
|
|
|
11
7
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
@@ -208,7 +204,8 @@ const comboboxTriggerVariants = cva(
|
|
|
208
204
|
);
|
|
209
205
|
|
|
210
206
|
export interface ComboboxTriggerProps
|
|
211
|
-
extends
|
|
207
|
+
extends
|
|
208
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
212
209
|
VariantProps<typeof comboboxTriggerVariants> {
|
|
213
210
|
/** Data hook for automated testing (REQUIRED) */
|
|
214
211
|
dataHook: string;
|
|
@@ -346,8 +343,9 @@ function ComboboxContent({
|
|
|
346
343
|
* Combobox Input
|
|
347
344
|
* -----------------------------------------------------------------------------------------------*/
|
|
348
345
|
|
|
349
|
-
export interface ComboboxInputProps
|
|
350
|
-
|
|
346
|
+
export interface ComboboxInputProps extends React.ComponentProps<
|
|
347
|
+
typeof CommandInput
|
|
348
|
+
> {
|
|
351
349
|
/** Current input value. Use for controlled/async search. */
|
|
352
350
|
value?: string;
|
|
353
351
|
/** Called when input value changes. Use to trigger async search requests. */
|
|
@@ -420,7 +418,10 @@ function highlightText(
|
|
|
420
418
|
return text;
|
|
421
419
|
}
|
|
422
420
|
|
|
423
|
-
const regex = new RegExp(
|
|
421
|
+
const regex = new RegExp(
|
|
422
|
+
`(${highlight.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`,
|
|
423
|
+
"gi"
|
|
424
|
+
);
|
|
424
425
|
const parts = text.split(regex);
|
|
425
426
|
|
|
426
427
|
return (
|
|
@@ -438,8 +439,10 @@ function highlightText(
|
|
|
438
439
|
);
|
|
439
440
|
}
|
|
440
441
|
|
|
441
|
-
export interface ComboboxItemProps
|
|
442
|
-
|
|
442
|
+
export interface ComboboxItemProps extends Omit<
|
|
443
|
+
React.ComponentProps<typeof CommandItem>,
|
|
444
|
+
"onSelect"
|
|
445
|
+
> {
|
|
443
446
|
/** The value of the item (required) */
|
|
444
447
|
value: string;
|
|
445
448
|
/** Display label - if not provided, uses children text content */
|
|
@@ -469,7 +472,8 @@ const ComboboxItem = React.forwardRef<
|
|
|
469
472
|
},
|
|
470
473
|
ref
|
|
471
474
|
) => {
|
|
472
|
-
const { value, onValueChange, setOpen, registerItem } =
|
|
475
|
+
const { value, onValueChange, setOpen, registerItem } =
|
|
476
|
+
useComboboxContext();
|
|
473
477
|
const isSelected = value === itemValue;
|
|
474
478
|
|
|
475
479
|
// Extract text content from children for label registration
|
|
@@ -565,7 +569,7 @@ function ComboboxLoading({ className, children }: ComboboxLoadingProps) {
|
|
|
565
569
|
return (
|
|
566
570
|
<div
|
|
567
571
|
className={cn(
|
|
568
|
-
"flex items-center justify-center gap-2 py-6 text-sm
|
|
572
|
+
"text-muted-foreground flex items-center justify-center gap-2 py-6 text-sm",
|
|
569
573
|
className
|
|
570
574
|
)}
|
|
571
575
|
data-slot="combobox-loading"
|