@brightlocal/ui-components 2.9.2 → 2.11.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/README.md +3 -1
- package/component-meta.json +41 -9
- package/dist/badge.cjs +1 -1
- package/dist/badge.d.ts.map +1 -1
- package/dist/badge.js +42 -25
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +1 -3
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +46 -49
- package/dist/browser-entry.d.ts +17 -0
- package/dist/browser-entry.d.ts.map +1 -0
- package/dist/button.cjs +1 -1
- package/dist/button.js +25 -25
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +10 -1
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +85 -82
- package/dist/carousel.cjs +1 -1
- package/dist/carousel.d.ts +13 -1
- package/dist/carousel.d.ts.map +1 -1
- package/dist/carousel.js +196 -150
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts +3 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +480 -440
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +101 -1
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +383 -119
- package/dist/hooks/use-breakpoint.cjs +1 -1
- package/dist/hooks/use-breakpoint.d.ts.map +1 -1
- package/dist/hooks/use-breakpoint.js +10 -10
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +402 -391
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +1 -4
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +163 -170
- package/dist/map.cjs +1 -0
- package/dist/map.d.ts +192 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +250 -0
- package/dist/sonner.cjs +1 -1
- package/dist/sonner.d.ts.map +1 -1
- package/dist/sonner.js +32 -30
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +4 -0
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +101 -52
- package/package.json +4 -1
- package/src/blocks/sidebar.tsx +21 -26
- package/src/browser-entry.ts +89 -0
- package/src/browser-tokens.css +1 -0
- package/src/components/badge.tsx +22 -5
- package/src/components/button.tsx +13 -13
- package/src/components/card.tsx +35 -19
- package/src/components/carousel.tsx +101 -9
- package/src/components/combobox.tsx +106 -28
- package/src/components/command.tsx +637 -16
- package/src/components/input-chip.tsx +102 -65
- package/src/components/map.tsx +574 -0
- package/src/components/sonner.tsx +9 -3
- package/src/components/tabs.tsx +118 -22
- package/src/hooks/use-breakpoint.ts +2 -3
- package/src/index.ts +1 -0
|
@@ -28,18 +28,70 @@ interface InputChipContextValue {
|
|
|
28
28
|
chipRefs: React.RefObject<(HTMLDivElement | null)[]>;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
31
|
+
interface InputChipDispatchContextValue {
|
|
32
|
+
onValueChange: (value: string[]) => void;
|
|
33
|
+
setInputValue: (value: string) => void;
|
|
34
|
+
addItem: (item: string) => void;
|
|
35
|
+
removeItem: (index: number) => void;
|
|
36
|
+
inputRef: React.RefObject<HTMLInputElement | null>;
|
|
37
|
+
setFocusedChipIndex: (index: number) => void;
|
|
38
|
+
chipRefs: React.RefObject<(HTMLDivElement | null)[]>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface InputChipValueContextValue {
|
|
42
|
+
value: string[];
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface InputChipInputContextValue {
|
|
47
|
+
inputValue: string;
|
|
48
|
+
focusedChipIndex: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const InputChipDispatchContext =
|
|
52
|
+
React.createContext<InputChipDispatchContextValue | null>(null);
|
|
53
|
+
const InputChipValueContext =
|
|
54
|
+
React.createContext<InputChipValueContextValue | null>(null);
|
|
55
|
+
const InputChipInputContext =
|
|
56
|
+
React.createContext<InputChipInputContextValue | null>(null);
|
|
57
|
+
|
|
58
|
+
function useInputChipDispatch() {
|
|
59
|
+
const context = React.useContext(InputChipDispatchContext);
|
|
60
|
+
if (!context) {
|
|
61
|
+
throw new Error("InputChip components must be used within an <InputChip>");
|
|
62
|
+
}
|
|
63
|
+
return context;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function useInputChipValue() {
|
|
67
|
+
const context = React.useContext(InputChipValueContext);
|
|
68
|
+
if (!context) {
|
|
69
|
+
throw new Error("InputChip components must be used within an <InputChip>");
|
|
70
|
+
}
|
|
71
|
+
return context;
|
|
72
|
+
}
|
|
34
73
|
|
|
35
|
-
function
|
|
36
|
-
const context = React.useContext(
|
|
74
|
+
function useInputChipInput() {
|
|
75
|
+
const context = React.useContext(InputChipInputContext);
|
|
37
76
|
if (!context) {
|
|
38
77
|
throw new Error("InputChip components must be used within an <InputChip>");
|
|
39
78
|
}
|
|
40
79
|
return context;
|
|
41
80
|
}
|
|
42
81
|
|
|
82
|
+
function useInputChipContext(): InputChipContextValue {
|
|
83
|
+
const dispatch = useInputChipDispatch();
|
|
84
|
+
const { value, disabled } = useInputChipValue();
|
|
85
|
+
const { inputValue, focusedChipIndex } = useInputChipInput();
|
|
86
|
+
return {
|
|
87
|
+
...dispatch,
|
|
88
|
+
value,
|
|
89
|
+
disabled,
|
|
90
|
+
inputValue,
|
|
91
|
+
focusedChipIndex,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
43
95
|
/* -------------------------------------------------------------------------------------------------
|
|
44
96
|
* InputChip (Context provider)
|
|
45
97
|
* -----------------------------------------------------------------------------------------------*/
|
|
@@ -98,12 +150,20 @@ function InputChip({
|
|
|
98
150
|
const isControlled = controlledValue !== undefined;
|
|
99
151
|
const value = isControlled ? controlledValue : uncontrolledValue;
|
|
100
152
|
|
|
153
|
+
const valueRef = React.useRef(value);
|
|
154
|
+
const controlledOnValueChangeRef = React.useRef(controlledOnValueChange);
|
|
155
|
+
const disabledRef = React.useRef(disabled);
|
|
156
|
+
React.useLayoutEffect(() => {
|
|
157
|
+
valueRef.current = value;
|
|
158
|
+
controlledOnValueChangeRef.current = controlledOnValueChange;
|
|
159
|
+
disabledRef.current = disabled;
|
|
160
|
+
});
|
|
161
|
+
|
|
101
162
|
// Cleanup when chips are removed: trim refs and reset stale focus index
|
|
102
163
|
React.useEffect(() => {
|
|
103
164
|
if (chipRefs.current.length > value.length) {
|
|
104
165
|
chipRefs.current.length = value.length;
|
|
105
166
|
}
|
|
106
|
-
// Reset focus index if it's out of bounds (e.g., chip was removed externally)
|
|
107
167
|
if (focusedChipIndex >= value.length) {
|
|
108
168
|
setFocusedChipIndex(-1);
|
|
109
169
|
}
|
|
@@ -114,64 +174,62 @@ function InputChip({
|
|
|
114
174
|
if (!isControlled) {
|
|
115
175
|
setUncontrolledValue(newValue);
|
|
116
176
|
}
|
|
117
|
-
|
|
177
|
+
controlledOnValueChangeRef.current?.(newValue);
|
|
118
178
|
},
|
|
119
|
-
[isControlled
|
|
179
|
+
[isControlled]
|
|
120
180
|
);
|
|
121
181
|
|
|
122
182
|
const addItem = React.useCallback(
|
|
123
183
|
(item: string) => {
|
|
124
|
-
if (
|
|
184
|
+
if (disabledRef.current) return;
|
|
125
185
|
const trimmed = item.trim();
|
|
126
|
-
if (trimmed && (allowDuplicates || !
|
|
127
|
-
onValueChange([...
|
|
186
|
+
if (trimmed && (allowDuplicates || !valueRef.current.includes(trimmed))) {
|
|
187
|
+
onValueChange([...valueRef.current, trimmed]);
|
|
128
188
|
setInputValue("");
|
|
129
189
|
}
|
|
130
190
|
},
|
|
131
|
-
[
|
|
191
|
+
[allowDuplicates, onValueChange]
|
|
132
192
|
);
|
|
133
193
|
|
|
134
194
|
const removeItem = React.useCallback(
|
|
135
195
|
(index: number) => {
|
|
136
|
-
if (
|
|
137
|
-
onValueChange(
|
|
196
|
+
if (disabledRef.current) return;
|
|
197
|
+
onValueChange(valueRef.current.filter((_, i) => i !== index));
|
|
138
198
|
},
|
|
139
|
-
[
|
|
199
|
+
[onValueChange]
|
|
140
200
|
);
|
|
141
201
|
|
|
142
|
-
const
|
|
202
|
+
const dispatchValue = React.useMemo<InputChipDispatchContextValue>(
|
|
143
203
|
() => ({
|
|
144
|
-
value,
|
|
145
204
|
onValueChange,
|
|
146
|
-
inputValue,
|
|
147
205
|
setInputValue,
|
|
148
|
-
disabled,
|
|
149
206
|
addItem,
|
|
150
207
|
removeItem,
|
|
151
208
|
inputRef,
|
|
152
|
-
focusedChipIndex,
|
|
153
209
|
setFocusedChipIndex,
|
|
154
210
|
chipRefs,
|
|
155
211
|
}),
|
|
156
|
-
[
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
chipRefs,
|
|
168
|
-
]
|
|
212
|
+
[onValueChange, addItem, removeItem]
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const valueContextValue = React.useMemo<InputChipValueContextValue>(
|
|
216
|
+
() => ({ value, disabled }),
|
|
217
|
+
[value, disabled]
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const inputContextValue = React.useMemo<InputChipInputContextValue>(
|
|
221
|
+
() => ({ inputValue, focusedChipIndex }),
|
|
222
|
+
[inputValue, focusedChipIndex]
|
|
169
223
|
);
|
|
170
224
|
|
|
171
225
|
return (
|
|
172
|
-
<
|
|
173
|
-
{
|
|
174
|
-
|
|
226
|
+
<InputChipDispatchContext.Provider value={dispatchValue}>
|
|
227
|
+
<InputChipValueContext.Provider value={valueContextValue}>
|
|
228
|
+
<InputChipInputContext.Provider value={inputContextValue}>
|
|
229
|
+
{children}
|
|
230
|
+
</InputChipInputContext.Provider>
|
|
231
|
+
</InputChipValueContext.Provider>
|
|
232
|
+
</InputChipDispatchContext.Provider>
|
|
175
233
|
);
|
|
176
234
|
}
|
|
177
235
|
|
|
@@ -290,16 +348,10 @@ const InputChipInput = React.forwardRef<HTMLDivElement, InputChipInputProps>(
|
|
|
290
348
|
},
|
|
291
349
|
ref
|
|
292
350
|
) => {
|
|
293
|
-
const {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
disabled,
|
|
298
|
-
addItem,
|
|
299
|
-
inputRef,
|
|
300
|
-
setFocusedChipIndex,
|
|
301
|
-
chipRefs,
|
|
302
|
-
} = useInputChipContext();
|
|
351
|
+
const { setInputValue, addItem, inputRef, setFocusedChipIndex, chipRefs } =
|
|
352
|
+
useInputChipDispatch();
|
|
353
|
+
const { value, disabled } = useInputChipValue();
|
|
354
|
+
const { inputValue } = useInputChipInput();
|
|
303
355
|
|
|
304
356
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
305
357
|
setInputValue(e.target.value);
|
|
@@ -378,14 +430,9 @@ function InputChipItems({
|
|
|
378
430
|
className,
|
|
379
431
|
dataHookPrefix = "chip",
|
|
380
432
|
}: InputChipItemsProps) {
|
|
381
|
-
const {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
removeItem,
|
|
385
|
-
inputRef,
|
|
386
|
-
setFocusedChipIndex,
|
|
387
|
-
chipRefs,
|
|
388
|
-
} = useInputChipContext();
|
|
433
|
+
const { removeItem, inputRef, setFocusedChipIndex, chipRefs } =
|
|
434
|
+
useInputChipDispatch();
|
|
435
|
+
const { value, disabled } = useInputChipValue();
|
|
389
436
|
|
|
390
437
|
// Track pending focus to apply after DOM updates (avoids race conditions with rapid deletions)
|
|
391
438
|
const pendingFocusRef = React.useRef<number | "input" | null>(null);
|
|
@@ -532,14 +579,4 @@ function InputChipItems({
|
|
|
532
579
|
* Exports
|
|
533
580
|
* -----------------------------------------------------------------------------------------------*/
|
|
534
581
|
|
|
535
|
-
|
|
536
|
-
const inputChipVariants = inputChipInputVariants;
|
|
537
|
-
|
|
538
|
-
export {
|
|
539
|
-
InputChip,
|
|
540
|
-
InputChipInput,
|
|
541
|
-
InputChipItems,
|
|
542
|
-
inputChipVariants,
|
|
543
|
-
inputChipInputVariants,
|
|
544
|
-
useInputChipContext,
|
|
545
|
-
};
|
|
582
|
+
export { InputChip, InputChipInput, InputChipItems, useInputChipContext };
|