@brightlocal/ui-components 3.3.0 → 3.5.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 (207) hide show
  1. package/AI_USAGE.md +22 -3
  2. package/README.md +177 -109
  3. package/component-meta.json +1307 -113
  4. package/dist/alert-dialog.cjs +1 -1
  5. package/dist/alert-dialog.d.ts +13 -2
  6. package/dist/alert-dialog.d.ts.map +1 -1
  7. package/dist/alert-dialog.js +4 -3
  8. package/dist/banner.cjs +1 -1
  9. package/dist/banner.d.ts +47 -11
  10. package/dist/banner.d.ts.map +1 -1
  11. package/dist/banner.js +156 -79
  12. package/dist/blocks/empty-state.cjs +1 -1
  13. package/dist/blocks/empty-state.d.ts +40 -5
  14. package/dist/blocks/empty-state.d.ts.map +1 -1
  15. package/dist/blocks/empty-state.js +59 -52
  16. package/dist/blocks/input-list.cjs +1 -1
  17. package/dist/blocks/input-list.d.ts +1 -0
  18. package/dist/blocks/input-list.d.ts.map +1 -1
  19. package/dist/blocks/input-list.js +39 -39
  20. package/dist/blocks/sidebar.cjs +1 -1
  21. package/dist/blocks/sidebar.d.ts +12 -6
  22. package/dist/blocks/sidebar.d.ts.map +1 -1
  23. package/dist/blocks/sidebar.js +64 -63
  24. package/dist/button.cjs +1 -1
  25. package/dist/button.d.ts.map +1 -1
  26. package/dist/button.js +47 -43
  27. package/dist/card.cjs +1 -1
  28. package/dist/card.d.ts +12 -0
  29. package/dist/card.d.ts.map +1 -1
  30. package/dist/card.js +115 -97
  31. package/dist/chart.cjs +6 -6
  32. package/dist/chart.d.ts +6 -10
  33. package/dist/chart.d.ts.map +1 -1
  34. package/dist/chart.js +281 -296
  35. package/dist/combobox.cjs +3 -3
  36. package/dist/combobox.d.ts.map +1 -1
  37. package/dist/combobox.js +430 -343
  38. package/dist/command.cjs +1 -1
  39. package/dist/command.d.ts +23 -2
  40. package/dist/command.d.ts.map +1 -1
  41. package/dist/command.js +212 -207
  42. package/dist/count-indicator.cjs +1 -0
  43. package/dist/count-indicator.d.ts +85 -0
  44. package/dist/count-indicator.d.ts.map +1 -0
  45. package/dist/count-indicator.js +72 -0
  46. package/dist/data-table.cjs +1 -1
  47. package/dist/data-table.d.ts +101 -11
  48. package/dist/data-table.d.ts.map +1 -1
  49. package/dist/data-table.js +593 -523
  50. package/dist/description-list.cjs +1 -0
  51. package/dist/description-list.d.ts +142 -0
  52. package/dist/description-list.d.ts.map +1 -0
  53. package/dist/description-list.js +173 -0
  54. package/dist/dialog.cjs +1 -1
  55. package/dist/dialog.d.ts +26 -3
  56. package/dist/dialog.d.ts.map +1 -1
  57. package/dist/dialog.js +62 -47
  58. package/dist/drawer.cjs +1 -1
  59. package/dist/drawer.d.ts +8 -4
  60. package/dist/drawer.d.ts.map +1 -1
  61. package/dist/drawer.js +37 -38
  62. package/dist/file-upload.cjs +1 -0
  63. package/dist/file-upload.d.ts +546 -0
  64. package/dist/file-upload.d.ts.map +1 -0
  65. package/dist/file-upload.js +1103 -0
  66. package/dist/global-layout.cjs +1 -1
  67. package/dist/global-layout.d.ts +7 -2
  68. package/dist/global-layout.d.ts.map +1 -1
  69. package/dist/global-layout.js +52 -52
  70. package/dist/hooks/use-file-dropzone.cjs +1 -0
  71. package/dist/hooks/use-file-dropzone.d.ts +75 -0
  72. package/dist/hooks/use-file-dropzone.d.ts.map +1 -0
  73. package/dist/hooks/use-file-dropzone.js +133 -0
  74. package/dist/hover-card.cjs +1 -1
  75. package/dist/hover-card.d.ts +29 -16
  76. package/dist/hover-card.d.ts.map +1 -1
  77. package/dist/hover-card.js +153 -36
  78. package/dist/index.cjs +1 -1
  79. package/dist/index.d.ts +4 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +681 -623
  82. package/dist/input-chip.cjs +1 -1
  83. package/dist/input-chip.d.ts +30 -1
  84. package/dist/input-chip.d.ts.map +1 -1
  85. package/dist/input-chip.js +131 -115
  86. package/dist/input-group.cjs +1 -1
  87. package/dist/input-group.d.ts +37 -2
  88. package/dist/input-group.d.ts.map +1 -1
  89. package/dist/input-group.js +131 -114
  90. package/dist/input-password.cjs +1 -1
  91. package/dist/input-password.js +6 -6
  92. package/dist/lib/empty-canvas.cjs +1 -1
  93. package/dist/lib/empty-canvas.d.ts +27 -1
  94. package/dist/lib/empty-canvas.d.ts.map +1 -1
  95. package/dist/lib/empty-canvas.js +27 -23
  96. package/dist/lib/empty-chip.cjs +1 -1
  97. package/dist/lib/empty-chip.d.ts +19 -2
  98. package/dist/lib/empty-chip.d.ts.map +1 -1
  99. package/dist/lib/empty-chip.js +14 -9
  100. package/dist/lib/field-aria.cjs +1 -1
  101. package/dist/lib/field-aria.d.ts +4 -4
  102. package/dist/lib/field-aria.d.ts.map +1 -1
  103. package/dist/lib/field-aria.js +7 -5
  104. package/dist/lib/media-viewer-content.cjs +1 -1
  105. package/dist/lib/media-viewer-content.js +1 -1
  106. package/dist/lib/motion.cjs +1 -1
  107. package/dist/lib/motion.js +15 -10
  108. package/dist/lib/table-internal.cjs +1 -1
  109. package/dist/lib/table-internal.d.ts +19 -0
  110. package/dist/lib/table-internal.d.ts.map +1 -1
  111. package/dist/lib/table-internal.js +22 -7
  112. package/dist/list.cjs +1 -1
  113. package/dist/list.d.ts +230 -40
  114. package/dist/list.d.ts.map +1 -1
  115. package/dist/list.js +301 -66
  116. package/dist/logo-mark.cjs +1 -1
  117. package/dist/logo-mark.d.ts +18 -2
  118. package/dist/logo-mark.d.ts.map +1 -1
  119. package/dist/logo-mark.js +159 -79
  120. package/dist/media-empty.cjs +1 -1
  121. package/dist/media-empty.d.ts +50 -7
  122. package/dist/media-empty.d.ts.map +1 -1
  123. package/dist/media-empty.js +14 -13
  124. package/dist/media-viewer.cjs +1 -1
  125. package/dist/media-viewer.js +6 -6
  126. package/dist/multi-select-filter.cjs +1 -1
  127. package/dist/multi-select-filter.d.ts.map +1 -1
  128. package/dist/multi-select-filter.js +92 -101
  129. package/dist/pagination.cjs +1 -1
  130. package/dist/pagination.d.ts +11 -0
  131. package/dist/pagination.d.ts.map +1 -1
  132. package/dist/pagination.js +17 -17
  133. package/dist/relative-date.d.ts +6 -0
  134. package/dist/relative-date.d.ts.map +1 -1
  135. package/dist/resizable.d.ts +1 -1
  136. package/dist/result-count.cjs +1 -1
  137. package/dist/result-count.d.ts +13 -16
  138. package/dist/result-count.d.ts.map +1 -1
  139. package/dist/result-count.js +24 -33
  140. package/dist/route-progress.cjs +1 -1
  141. package/dist/route-progress.js +24 -23
  142. package/dist/sheet.cjs +1 -1
  143. package/dist/sheet.d.ts +22 -3
  144. package/dist/sheet.d.ts.map +1 -1
  145. package/dist/sheet.js +152 -125
  146. package/dist/single-select-filter.cjs +1 -1
  147. package/dist/single-select-filter.d.ts.map +1 -1
  148. package/dist/single-select-filter.js +67 -76
  149. package/dist/table.cjs +1 -1
  150. package/dist/table.d.ts.map +1 -1
  151. package/dist/table.js +77 -76
  152. package/dist/tabs.cjs +1 -1
  153. package/dist/tabs.d.ts +39 -3
  154. package/dist/tabs.d.ts.map +1 -1
  155. package/dist/tabs.js +127 -76
  156. package/dist/textarea.cjs +1 -1
  157. package/dist/textarea.d.ts +34 -0
  158. package/dist/textarea.d.ts.map +1 -1
  159. package/dist/textarea.js +115 -19
  160. package/dist/tooltip.cjs +1 -1
  161. package/dist/tooltip.d.ts.map +1 -1
  162. package/dist/tooltip.js +137 -131
  163. package/dist/typography-text.cjs +1 -1
  164. package/dist/typography-text.d.ts +6 -2
  165. package/dist/typography-text.d.ts.map +1 -1
  166. package/dist/typography-text.js +14 -13
  167. package/package.json +2 -3
  168. package/src/blocks/empty-state.tsx +108 -48
  169. package/src/blocks/input-list.tsx +15 -9
  170. package/src/blocks/sidebar.tsx +39 -16
  171. package/src/components/alert-dialog.tsx +18 -2
  172. package/src/components/banner.tsx +247 -68
  173. package/src/components/button.tsx +27 -10
  174. package/src/components/card.tsx +89 -7
  175. package/src/components/chart.tsx +47 -67
  176. package/src/components/combobox.tsx +221 -12
  177. package/src/components/command.tsx +83 -37
  178. package/src/components/count-indicator.tsx +188 -0
  179. package/src/components/data-table.tsx +506 -159
  180. package/src/components/description-list.tsx +445 -0
  181. package/src/components/dialog.tsx +74 -5
  182. package/src/components/drawer.tsx +52 -32
  183. package/src/components/file-upload.tsx +2574 -0
  184. package/src/components/global-layout.tsx +18 -5
  185. package/src/components/hover-card.tsx +395 -65
  186. package/src/components/input-chip.tsx +67 -2
  187. package/src/components/input-group.tsx +89 -6
  188. package/src/components/list.tsx +720 -72
  189. package/src/components/logo-mark.tsx +109 -25
  190. package/src/components/media-empty.tsx +62 -7
  191. package/src/components/multi-select-filter.tsx +9 -16
  192. package/src/components/pagination.tsx +15 -2
  193. package/src/components/relative-date.tsx +6 -0
  194. package/src/components/result-count.tsx +27 -54
  195. package/src/components/sheet.tsx +86 -8
  196. package/src/components/single-select-filter.tsx +9 -16
  197. package/src/components/table.tsx +16 -1
  198. package/src/components/tabs.tsx +223 -41
  199. package/src/components/textarea.tsx +271 -4
  200. package/src/components/tooltip.tsx +29 -2
  201. package/src/components/typography-text.tsx +7 -2
  202. package/src/hooks/use-file-dropzone.ts +325 -0
  203. package/src/index.ts +4 -0
  204. package/src/lib/empty-canvas.tsx +47 -20
  205. package/src/lib/empty-chip.tsx +38 -3
  206. package/src/lib/field-aria.tsx +11 -6
  207. package/src/lib/table-internal.ts +38 -0
@@ -5,6 +5,8 @@ import { cva, type VariantProps } from "class-variance-authority";
5
5
 
6
6
  import { cn } from "@brightlocal/ui-components/lib/utils";
7
7
  import { Chip } from "@brightlocal/ui-components/chip";
8
+ import { useFieldDescribedBy } from "../lib/field-aria";
9
+ import { CountIndicator, type CountIndicatorProps } from "./count-indicator";
8
10
 
9
11
  /* -------------------------------------------------------------------------------------------------
10
12
  * InputChip Context
@@ -79,6 +81,7 @@ function useInputChipInput() {
79
81
  return context;
80
82
  }
81
83
 
84
+ /** Returns the combined InputChip context (value, dispatch, and input state). */
82
85
  function useInputChipContext(): InputChipContextValue {
83
86
  const dispatch = useInputChipDispatch();
84
87
  const { value, disabled } = useInputChipValue();
@@ -259,6 +262,10 @@ const inputChipInputVariants = cva(
259
262
  // Focus-within state (when input inside is focused)
260
263
  "has-[:focus-visible]:border-ring has-[:focus-visible]:bg-background",
261
264
  "has-[:focus-visible]:shadow-default",
265
+ // Over the count limit: error border (the message stays with the consumer)
266
+ "has-[[data-slot=count-indicator][data-state=over]]:border-destructive-40",
267
+ "has-[[data-slot=count-indicator][data-state=over]]:has-[:focus-visible]:border-destructive-40",
268
+ "has-[[data-slot=count-indicator][data-state=over]]:has-[:focus-visible]:shadow-destructive",
262
269
  // Disabled state
263
270
  "has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50",
264
271
  // Transition
@@ -389,6 +396,9 @@ const InputChipInput = React.forwardRef<HTMLInputElement, InputChipInputProps>(
389
396
  useInputChipDispatch();
390
397
  const { value, disabled } = useInputChipValue();
391
398
  const { inputValue } = useInputChipInput();
399
+ // Inside a Field the textbox also reads the FieldError, the hint and the
400
+ // count (InputChipCount); explicit ids from the consumer are kept.
401
+ const describedBy = useFieldDescribedBy(ariaDescribedby);
392
402
 
393
403
  // Expose the inner text input through the consumer's ref
394
404
  React.useImperativeHandle(ref, () => inputRef.current!, [inputRef]);
@@ -435,7 +445,7 @@ const InputChipInput = React.forwardRef<HTMLInputElement, InputChipInputProps>(
435
445
  {children}
436
446
  <input
437
447
  ref={inputRef as React.RefObject<HTMLInputElement>}
438
- aria-describedby={ariaDescribedby || undefined}
448
+ aria-describedby={describedBy || undefined}
439
449
  aria-invalid={hasError ? "true" : undefined}
440
450
  aria-label={ariaLabel}
441
451
  aria-labelledby={ariaLabelledby}
@@ -634,4 +644,59 @@ function InputChipItems({
634
644
  * Exports
635
645
  * -----------------------------------------------------------------------------------------------*/
636
646
 
637
- export { InputChip, InputChipInput, InputChipItems, useInputChipContext };
647
+ /* -------------------------------------------------------------------------------------------------
648
+ * InputChip Count (Items against a limit)
649
+ * -----------------------------------------------------------------------------------------------*/
650
+
651
+ /**
652
+ * Props for InputChipCount. `count` is optional: by default the chip field
653
+ * counts its items.
654
+ */
655
+ export interface InputChipCountProps extends Omit<
656
+ CountIndicatorProps,
657
+ "count"
658
+ > {
659
+ /**
660
+ * Count to show. Omit it to count the items in the chip field.
661
+ */
662
+ count?: number;
663
+ }
664
+
665
+ /**
666
+ * Count of items against a limit at the end of the last row of the chip field,
667
+ * such as `3 / 5`. Place it inside `InputChipInput`, next to `InputChipItems`.
668
+ *
669
+ * It never blocks adding. Over the limit the count turns red and the field
670
+ * takes the error border; show the error message and reject the save yourself
671
+ * (`onBeforeAdd` on `InputChip` can stop the add itself).
672
+ *
673
+ * @example
674
+ * ```tsx
675
+ * <InputChipInput dataHook="emails-input">
676
+ * <InputChipItems />
677
+ * <InputChipCount dataHook="emails-count" limit={5} />
678
+ * </InputChipInput>
679
+ * ```
680
+ */
681
+ const InputChipCount = React.forwardRef<HTMLSpanElement, InputChipCountProps>(
682
+ ({ className, count, ...props }, ref) => {
683
+ const { value } = useInputChipValue();
684
+ return (
685
+ <CountIndicator
686
+ ref={ref}
687
+ className={cn("order-last ml-auto pl-3", className)}
688
+ count={count ?? value.length}
689
+ {...props}
690
+ />
691
+ );
692
+ }
693
+ );
694
+ InputChipCount.displayName = "InputChipCount";
695
+
696
+ export {
697
+ InputChip,
698
+ InputChipCount,
699
+ InputChipInput,
700
+ InputChipItems,
701
+ useInputChipContext,
702
+ };
@@ -6,11 +6,18 @@ import { cva, type VariantProps } from "class-variance-authority";
6
6
  import { X } from "@brightlocal/icons";
7
7
 
8
8
  import { cn } from "@brightlocal/ui-components/lib/utils";
9
+ import { CountIndicator, type CountIndicatorProps } from "./count-indicator";
9
10
  import { Input, type InputProps } from "./input";
10
11
 
11
12
  interface InputGroupContextValue {
12
13
  /** Snapshot of the composed input's DOM state, kept fresh by InputGroupInput. */
13
- inputState: { hasValue: boolean; disabled: boolean };
14
+ inputState: {
15
+ hasValue: boolean;
16
+ length: number;
17
+ disabled: boolean;
18
+ /** False until the composed input has been read once. */
19
+ ready: boolean;
20
+ };
14
21
  /** Re-reads the composed input into `inputState`; cheap and safe to call often. */
15
22
  syncInputState: () => void;
16
23
  /**
@@ -36,7 +43,7 @@ const InputGroupContext = React.createContext<InputGroupContextValue | null>(
36
43
  );
37
44
 
38
45
  const inputGroupVariants = cva(
39
- "relative flex w-full items-center rounded-sm border border-input bg-background transition-[color,background-color,border-color,box-shadow] duration-fast ease-out has-[input:focus-visible]:border-ring has-[input:focus-visible]:shadow-default has-[:disabled]:opacity-50",
46
+ "relative flex w-full items-center rounded-sm border border-input bg-background transition-[color,background-color,border-color,box-shadow] duration-fast ease-out has-[input:focus-visible]:border-ring has-[input:focus-visible]:shadow-default has-[:disabled]:opacity-50 has-[[data-slot=count-indicator][data-state=over]]:border-destructive-40 has-[[data-slot=count-indicator][data-state=over]]:has-[input:focus-visible]:border-destructive-40 has-[[data-slot=count-indicator][data-state=over]]:has-[input:focus-visible]:shadow-destructive",
40
47
  {
41
48
  variants: {
42
49
  size: {
@@ -88,7 +95,9 @@ const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
88
95
  ) => {
89
96
  const [inputState, setInputState] = React.useState({
90
97
  hasValue: false,
98
+ length: 0,
91
99
  disabled: false,
100
+ ready: false,
92
101
  });
93
102
  const inputRef = React.useRef<HTMLInputElement | null>(null);
94
103
  const syncInputState = React.useCallback(() => {
@@ -97,10 +106,15 @@ const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
97
106
  // not offer a clear affordance either.
98
107
  const next = {
99
108
  hasValue: !!input && input.value.length > 0,
109
+ length: input ? input.value.length : 0,
100
110
  disabled: !!input && (input.disabled || input.readOnly),
111
+ ready: true,
101
112
  };
102
113
  setInputState((prev) =>
103
- prev.hasValue === next.hasValue && prev.disabled === next.disabled
114
+ prev.hasValue === next.hasValue &&
115
+ prev.length === next.length &&
116
+ prev.disabled === next.disabled &&
117
+ prev.ready === next.ready
104
118
  ? prev
105
119
  : next
106
120
  );
@@ -248,9 +262,23 @@ const inputGroupAddonVariants = cva(
248
262
  "flex shrink-0 items-center text-muted-foreground",
249
263
  {
250
264
  variants: {
265
+ // The inner side (next to the group's border) is inset 12px so an icon
266
+ // or prefix never sits on the border. An addon holding a button keeps
267
+ // 4px: the button's own box centres its icon, which lands it on the
268
+ // same 12px line as a bare icon (icon-sm: 4px + 8px). The button case
269
+ // matches InputGroupButton by data-slot too, so an `asChild` link
270
+ // counts. The inset is a variable read by a plain padding utility, so
271
+ // a consumer's pl-*/pr-* replaces it through twMerge instead of losing
272
+ // to the more specific :has() selector.
251
273
  align: {
252
- "inline-start": "",
253
- "inline-end": "ml-auto",
274
+ "inline-start": [
275
+ "pl-(--input-group-addon-inset) [--input-group-addon-inset:--spacing(3)]",
276
+ "has-[>button,>[data-slot=input-group-button]]:[--input-group-addon-inset:--spacing(1)]",
277
+ ],
278
+ "inline-end": [
279
+ "ml-auto pr-(--input-group-addon-inset) [--input-group-addon-inset:--spacing(3)]",
280
+ "has-[>button,>[data-slot=input-group-button]]:[--input-group-addon-inset:--spacing(1)]",
281
+ ],
254
282
  "block-start": "self-start",
255
283
  "block-end": "self-end",
256
284
  },
@@ -264,7 +292,15 @@ const inputGroupAddonVariants = cva(
264
292
  interface InputGroupAddonProps
265
293
  extends
266
294
  React.HTMLAttributes<HTMLDivElement>,
267
- VariantProps<typeof inputGroupAddonVariants> {}
295
+ VariantProps<typeof inputGroupAddonVariants> {
296
+ /**
297
+ * Which side of the input the addon sits on. Inline addons are inset 12px
298
+ * on their inner side (4px when the addon holds an `InputGroupButton`, so
299
+ * the button's icon lands on the same line), so no padding is needed.
300
+ * @default "inline-start"
301
+ */
302
+ align?: "inline-start" | "inline-end" | "block-start" | "block-end" | null;
303
+ }
268
304
 
269
305
  const InputGroupAddon = React.forwardRef<HTMLDivElement, InputGroupAddonProps>(
270
306
  ({ className, align, ...props }, ref) => {
@@ -280,6 +316,51 @@ const InputGroupAddon = React.forwardRef<HTMLDivElement, InputGroupAddonProps>(
280
316
  );
281
317
  InputGroupAddon.displayName = "InputGroupAddon";
282
318
 
319
+ /**
320
+ * Props for InputGroupCount. `count` is optional: by default the group counts
321
+ * the characters in its input.
322
+ */
323
+ interface InputGroupCountProps extends Omit<CountIndicatorProps, "count"> {
324
+ /**
325
+ * Count to show. Omit it to count the characters in the group's input; pass
326
+ * it when the group counts something else.
327
+ */
328
+ count?: number;
329
+ }
330
+
331
+ /**
332
+ * Count against a limit at the end of the group, such as `12 / 125`. Place it
333
+ * last, after the input (and before a clear button, if there is one).
334
+ *
335
+ * It never blocks typing. Over the limit the count turns red and the group
336
+ * takes the error border; show the error message and stop the save yourself.
337
+ *
338
+ * @example
339
+ * ```tsx
340
+ * <InputGroup dataHook="alt-group">
341
+ * <InputGroupInput value={alt} onChange={...} />
342
+ * <InputGroupCount dataHook="alt-count" limit={125} />
343
+ * </InputGroup>
344
+ * ```
345
+ */
346
+ const InputGroupCount = React.forwardRef<HTMLSpanElement, InputGroupCountProps>(
347
+ ({ className, count, ...props }, ref) => {
348
+ const context = React.useContext(InputGroupContext);
349
+ return (
350
+ <CountIndicator
351
+ ref={ref}
352
+ className={cn("pr-3", className)}
353
+ count={count ?? context?.inputState.length ?? 0}
354
+ // A saved value already over the limit is read on mount; that first
355
+ // read is not a crossing, so it stays silent.
356
+ ready={count !== undefined || (context?.inputState.ready ?? true)}
357
+ {...props}
358
+ />
359
+ );
360
+ }
361
+ );
362
+ InputGroupCount.displayName = "InputGroupCount";
363
+
283
364
  const inputGroupButtonVariants = cva(
284
365
  [
285
366
  "inline-flex items-center justify-center gap-2",
@@ -434,6 +515,7 @@ export {
434
515
  InputGroupAddon,
435
516
  InputGroupButton,
436
517
  InputGroupClear,
518
+ InputGroupCount,
437
519
  inputGroupVariants,
438
520
  inputGroupButtonVariants,
439
521
  };
@@ -443,4 +525,5 @@ export type {
443
525
  InputGroupAddonProps,
444
526
  InputGroupButtonProps,
445
527
  InputGroupClearProps,
528
+ InputGroupCountProps,
446
529
  };