@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.
Files changed (67) hide show
  1. package/README.md +3 -1
  2. package/component-meta.json +41 -9
  3. package/dist/badge.cjs +1 -1
  4. package/dist/badge.d.ts.map +1 -1
  5. package/dist/badge.js +42 -25
  6. package/dist/blocks/sidebar.cjs +1 -1
  7. package/dist/blocks/sidebar.d.ts +1 -3
  8. package/dist/blocks/sidebar.d.ts.map +1 -1
  9. package/dist/blocks/sidebar.js +46 -49
  10. package/dist/browser-entry.d.ts +17 -0
  11. package/dist/browser-entry.d.ts.map +1 -0
  12. package/dist/button.cjs +1 -1
  13. package/dist/button.js +25 -25
  14. package/dist/card.cjs +1 -1
  15. package/dist/card.d.ts +10 -1
  16. package/dist/card.d.ts.map +1 -1
  17. package/dist/card.js +85 -82
  18. package/dist/carousel.cjs +1 -1
  19. package/dist/carousel.d.ts +13 -1
  20. package/dist/carousel.d.ts.map +1 -1
  21. package/dist/carousel.js +196 -150
  22. package/dist/combobox.cjs +3 -3
  23. package/dist/combobox.d.ts +3 -3
  24. package/dist/combobox.d.ts.map +1 -1
  25. package/dist/combobox.js +480 -440
  26. package/dist/command.cjs +1 -1
  27. package/dist/command.d.ts +101 -1
  28. package/dist/command.d.ts.map +1 -1
  29. package/dist/command.js +383 -119
  30. package/dist/hooks/use-breakpoint.cjs +1 -1
  31. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  32. package/dist/hooks/use-breakpoint.js +10 -10
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +402 -391
  37. package/dist/input-chip.cjs +1 -1
  38. package/dist/input-chip.d.ts +1 -4
  39. package/dist/input-chip.d.ts.map +1 -1
  40. package/dist/input-chip.js +163 -170
  41. package/dist/map.cjs +1 -0
  42. package/dist/map.d.ts +192 -0
  43. package/dist/map.d.ts.map +1 -0
  44. package/dist/map.js +250 -0
  45. package/dist/sonner.cjs +1 -1
  46. package/dist/sonner.d.ts.map +1 -1
  47. package/dist/sonner.js +32 -30
  48. package/dist/tabs.cjs +1 -1
  49. package/dist/tabs.d.ts +4 -0
  50. package/dist/tabs.d.ts.map +1 -1
  51. package/dist/tabs.js +101 -52
  52. package/package.json +4 -1
  53. package/src/blocks/sidebar.tsx +21 -26
  54. package/src/browser-entry.ts +89 -0
  55. package/src/browser-tokens.css +1 -0
  56. package/src/components/badge.tsx +22 -5
  57. package/src/components/button.tsx +13 -13
  58. package/src/components/card.tsx +35 -19
  59. package/src/components/carousel.tsx +101 -9
  60. package/src/components/combobox.tsx +106 -28
  61. package/src/components/command.tsx +637 -16
  62. package/src/components/input-chip.tsx +102 -65
  63. package/src/components/map.tsx +574 -0
  64. package/src/components/sonner.tsx +9 -3
  65. package/src/components/tabs.tsx +118 -22
  66. package/src/hooks/use-breakpoint.ts +2 -3
  67. package/src/index.ts +1 -0
@@ -28,18 +28,70 @@ interface InputChipContextValue {
28
28
  chipRefs: React.RefObject<(HTMLDivElement | null)[]>;
29
29
  }
30
30
 
31
- const InputChipContext = React.createContext<InputChipContextValue | null>(
32
- null
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 useInputChipContext() {
36
- const context = React.useContext(InputChipContext);
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
- controlledOnValueChange?.(newValue);
177
+ controlledOnValueChangeRef.current?.(newValue);
118
178
  },
119
- [isControlled, controlledOnValueChange]
179
+ [isControlled]
120
180
  );
121
181
 
122
182
  const addItem = React.useCallback(
123
183
  (item: string) => {
124
- if (disabled) return;
184
+ if (disabledRef.current) return;
125
185
  const trimmed = item.trim();
126
- if (trimmed && (allowDuplicates || !value.includes(trimmed))) {
127
- onValueChange([...value, trimmed]);
186
+ if (trimmed && (allowDuplicates || !valueRef.current.includes(trimmed))) {
187
+ onValueChange([...valueRef.current, trimmed]);
128
188
  setInputValue("");
129
189
  }
130
190
  },
131
- [value, onValueChange, allowDuplicates, disabled]
191
+ [allowDuplicates, onValueChange]
132
192
  );
133
193
 
134
194
  const removeItem = React.useCallback(
135
195
  (index: number) => {
136
- if (disabled) return;
137
- onValueChange(value.filter((_, i) => i !== index));
196
+ if (disabledRef.current) return;
197
+ onValueChange(valueRef.current.filter((_, i) => i !== index));
138
198
  },
139
- [value, onValueChange, disabled]
199
+ [onValueChange]
140
200
  );
141
201
 
142
- const contextValue = React.useMemo<InputChipContextValue>(
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
- value,
158
- onValueChange,
159
- inputValue,
160
- setInputValue,
161
- disabled,
162
- addItem,
163
- removeItem,
164
- inputRef,
165
- focusedChipIndex,
166
- setFocusedChipIndex,
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
- <InputChipContext.Provider value={contextValue}>
173
- {children}
174
- </InputChipContext.Provider>
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
- value,
295
- inputValue,
296
- setInputValue,
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
- value,
383
- disabled,
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
- // Keep for backwards compatibility
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 };