@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
@@ -0,0 +1,325 @@
1
+ import { useCallback, useRef, useState } from "react";
2
+
3
+ type FileError =
4
+ "file-too-large" | "file-too-small" | "too-many-files" | "file-invalid-type";
5
+
6
+ interface FileRejection {
7
+ file: File;
8
+ errors: FileError[];
9
+ }
10
+
11
+ interface UseFileDropzoneOptions {
12
+ /**
13
+ * Accepted MIME types or extensions, keyed by MIME with extension arrays.
14
+ * @example { "image/*": [".png", ".jpg"], "application/pdf": [".pdf"] }
15
+ */
16
+ accept?: Record<string, readonly string[]>;
17
+ /** Maximum file size in bytes. */
18
+ maxSize?: number;
19
+ /** Minimum file size in bytes. */
20
+ minSize?: number;
21
+ /** Maximum number of files. `1` disables `multiple` on the input when `multiple` is not set. */
22
+ maxFiles?: number;
23
+ /** Whether the file input accepts multiple files. Defaults to `maxFiles !== 1`. */
24
+ multiple?: boolean;
25
+ /** Whether the dropzone is disabled. */
26
+ disabled?: boolean;
27
+ /** Custom validation function. Return an array of error codes or an empty array. */
28
+ validate?: (file: File) => FileError[];
29
+ /** Called with accepted and rejected files after a drop or file pick. */
30
+ onFilesChange?: (details: {
31
+ acceptedFiles: File[];
32
+ rejectedFiles: FileRejection[];
33
+ }) => void;
34
+ }
35
+
36
+ type DropzoneState = "idle" | "accept" | "reject";
37
+
38
+ interface UseFileDropzoneReturn {
39
+ /** Current visual state of the drop zone. */
40
+ state: DropzoneState;
41
+ /** Whether a drag is currently over the zone. */
42
+ dragActive: boolean;
43
+ /** Props to spread on the drop zone element. */
44
+ dropzoneProps: {
45
+ onDragEnter: (e: React.DragEvent) => void;
46
+ onDragOver: (e: React.DragEvent) => void;
47
+ onDragLeave: (e: React.DragEvent) => void;
48
+ onDrop: (e: React.DragEvent) => void;
49
+ onPaste: (e: React.ClipboardEvent) => void;
50
+ };
51
+ /** Props to spread on the hidden file input. */
52
+ inputProps: {
53
+ type: "file";
54
+ accept: string | undefined;
55
+ multiple: boolean;
56
+ disabled: boolean | undefined;
57
+ onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
58
+ tabIndex: -1;
59
+ style: React.CSSProperties;
60
+ };
61
+ /** Ref for the hidden file input. */
62
+ inputRef: React.RefObject<HTMLInputElement | null>;
63
+ /** Programmatically open the file picker. */
64
+ openFilePicker: () => void;
65
+ }
66
+
67
+ function getAcceptString(
68
+ accept?: Record<string, readonly string[]>
69
+ ): string | undefined {
70
+ if (!accept) return undefined;
71
+ const parts: string[] = [];
72
+ for (const [mime, exts] of Object.entries(accept)) {
73
+ parts.push(mime);
74
+ parts.push(...exts);
75
+ }
76
+ return parts.join(",");
77
+ }
78
+
79
+ function matchesMime(
80
+ fileType: string,
81
+ accept: Record<string, readonly string[]>
82
+ ): boolean {
83
+ for (const [mime, exts] of Object.entries(accept)) {
84
+ if (mime === fileType) return true;
85
+ if (mime.endsWith("/*") && fileType.startsWith(mime.replace("/*", "/")))
86
+ return true;
87
+ const ext = `.${fileType.split("/").pop()}`;
88
+ if (exts.some((e) => e.toLowerCase() === ext.toLowerCase())) return true;
89
+ }
90
+ return false;
91
+ }
92
+
93
+ function matchesExtension(
94
+ fileName: string,
95
+ accept: Record<string, readonly string[]>
96
+ ): boolean {
97
+ const fileExt = fileName.slice(fileName.lastIndexOf(".")).toLowerCase();
98
+ for (const exts of Object.values(accept)) {
99
+ if (exts.some((e) => e.toLowerCase() === fileExt)) return true;
100
+ }
101
+ return false;
102
+ }
103
+
104
+ export function validateFile(
105
+ file: File,
106
+ options: UseFileDropzoneOptions
107
+ ): FileError[] {
108
+ const errors: FileError[] = [];
109
+
110
+ if (options.accept) {
111
+ const typeMatch = file.type
112
+ ? matchesMime(file.type, options.accept)
113
+ : false;
114
+ const extMatch = matchesExtension(file.name, options.accept);
115
+ if (!typeMatch && !extMatch) {
116
+ errors.push("file-invalid-type");
117
+ }
118
+ }
119
+ if (options.maxSize !== undefined && file.size > options.maxSize) {
120
+ errors.push("file-too-large");
121
+ }
122
+ if (options.minSize !== undefined && file.size < options.minSize) {
123
+ errors.push("file-too-small");
124
+ }
125
+ if (options.validate) {
126
+ errors.push(...options.validate(file));
127
+ }
128
+ return errors;
129
+ }
130
+
131
+ export function dragItemsMatchAccept(
132
+ items: DataTransferItemList,
133
+ accept?: Record<string, readonly string[]>
134
+ ): boolean {
135
+ let hasFile = false;
136
+ for (let i = 0; i < items.length; i++) {
137
+ const item = items[i]!;
138
+ if (item.kind !== "file") continue;
139
+ hasFile = true;
140
+ if (accept && !matchesMime(item.type, accept)) return false;
141
+ }
142
+ return hasFile;
143
+ }
144
+
145
+ /**
146
+ * Native HTML5 drag-and-drop for file inputs: tracks the drag state
147
+ * (`idle` / `accept` / `reject`) by sniffing dragged item MIME types,
148
+ * validates dropped, picked or pasted files against `accept`, `minSize`,
149
+ * `maxSize` and a custom `validate`, and returns the props to spread on the
150
+ * drop zone and its hidden `<input type="file">`.
151
+ *
152
+ * `maxFiles` here limits one batch; a running total across drops is the
153
+ * caller's job (see `FileUpload`).
154
+ *
155
+ * @param options - Accepted types, size limits, max files, disabled flag, custom validate, and onFilesChange callback.
156
+ */
157
+ export function useFileDropzone(
158
+ options: UseFileDropzoneOptions = {}
159
+ ): UseFileDropzoneReturn {
160
+ const { disabled = false, maxFiles, multiple, onFilesChange } = options;
161
+ const [state, setState] = useState<DropzoneState>("idle");
162
+ const dragCounter = useRef(0);
163
+ const inputRef = useRef<HTMLInputElement | null>(null);
164
+
165
+ const processFiles = useCallback(
166
+ (fileList: FileList | File[]) => {
167
+ const files = Array.from(fileList);
168
+ let accepted: File[] = [];
169
+ const rejected: FileRejection[] = [];
170
+
171
+ for (const file of files) {
172
+ const errors = validateFile(file, options);
173
+ if (errors.length > 0) {
174
+ rejected.push({ file, errors });
175
+ } else {
176
+ accepted.push(file);
177
+ }
178
+ }
179
+
180
+ if (maxFiles !== undefined && accepted.length > maxFiles) {
181
+ const overflow = accepted.slice(maxFiles);
182
+ accepted = accepted.slice(0, maxFiles);
183
+ for (const file of overflow) {
184
+ rejected.push({ file, errors: ["too-many-files"] });
185
+ }
186
+ }
187
+
188
+ onFilesChange?.({ acceptedFiles: accepted, rejectedFiles: rejected });
189
+ },
190
+ [maxFiles, onFilesChange, options]
191
+ );
192
+
193
+ const onDragEnter = useCallback(
194
+ (e: React.DragEvent) => {
195
+ e.preventDefault();
196
+ e.stopPropagation();
197
+ if (disabled) return;
198
+
199
+ dragCounter.current += 1;
200
+ if (dragCounter.current === 1) {
201
+ const matches = dragItemsMatchAccept(
202
+ e.dataTransfer.items,
203
+ options.accept
204
+ );
205
+ setState(matches ? "accept" : "reject");
206
+ }
207
+ },
208
+ [disabled, options.accept]
209
+ );
210
+
211
+ const onDragOver = useCallback(
212
+ (e: React.DragEvent) => {
213
+ e.preventDefault();
214
+ e.stopPropagation();
215
+ if (disabled) return;
216
+ e.dataTransfer.dropEffect = "copy";
217
+ },
218
+ [disabled]
219
+ );
220
+
221
+ const onDragLeave = useCallback(
222
+ (e: React.DragEvent) => {
223
+ e.preventDefault();
224
+ e.stopPropagation();
225
+ if (disabled) return;
226
+
227
+ dragCounter.current -= 1;
228
+ if (dragCounter.current === 0) {
229
+ setState("idle");
230
+ }
231
+ },
232
+ [disabled]
233
+ );
234
+
235
+ const onDrop = useCallback(
236
+ (e: React.DragEvent) => {
237
+ e.preventDefault();
238
+ e.stopPropagation();
239
+ dragCounter.current = 0;
240
+ setState("idle");
241
+ if (disabled) return;
242
+
243
+ const droppedFiles: File[] = [];
244
+ if (e.dataTransfer.items) {
245
+ for (let i = 0; i < e.dataTransfer.items.length; i++) {
246
+ const item = e.dataTransfer.items[i]!;
247
+ if (item.kind !== "file") continue;
248
+ const entry = item.webkitGetAsEntry?.();
249
+ if (entry?.isDirectory) continue;
250
+ const file = item.getAsFile();
251
+ if (file) droppedFiles.push(file);
252
+ }
253
+ } else {
254
+ droppedFiles.push(...Array.from(e.dataTransfer.files));
255
+ }
256
+
257
+ processFiles(droppedFiles);
258
+ },
259
+ [disabled, processFiles]
260
+ );
261
+
262
+ const onInputChange = useCallback(
263
+ (e: React.ChangeEvent<HTMLInputElement>) => {
264
+ if (disabled) return;
265
+ if (e.target.files) {
266
+ processFiles(e.target.files);
267
+ }
268
+ e.target.value = "";
269
+ },
270
+ [disabled, processFiles]
271
+ );
272
+
273
+ const onPaste = useCallback(
274
+ (e: React.ClipboardEvent) => {
275
+ if (disabled) return;
276
+ const files = Array.from(e.clipboardData.files);
277
+ if (files.length > 0) {
278
+ e.preventDefault();
279
+ processFiles(files);
280
+ }
281
+ },
282
+ [disabled, processFiles]
283
+ );
284
+
285
+ const openFilePicker = useCallback(() => {
286
+ if (!disabled) {
287
+ inputRef.current?.click();
288
+ }
289
+ }, [disabled]);
290
+
291
+ return {
292
+ state,
293
+ dragActive: state !== "idle",
294
+ dropzoneProps: { onDragEnter, onDragOver, onDragLeave, onDrop, onPaste },
295
+ inputProps: {
296
+ type: "file",
297
+ accept: getAcceptString(options.accept),
298
+ multiple: multiple ?? maxFiles !== 1,
299
+ disabled,
300
+ onChange: onInputChange,
301
+ tabIndex: -1,
302
+ style: {
303
+ position: "absolute",
304
+ width: 1,
305
+ height: 1,
306
+ padding: 0,
307
+ margin: -1,
308
+ overflow: "hidden",
309
+ clip: "rect(0,0,0,0)",
310
+ whiteSpace: "nowrap",
311
+ borderWidth: 0,
312
+ },
313
+ },
314
+ inputRef,
315
+ openFilePicker,
316
+ };
317
+ }
318
+
319
+ export type {
320
+ FileError,
321
+ FileRejection,
322
+ UseFileDropzoneOptions,
323
+ UseFileDropzoneReturn,
324
+ DropzoneState,
325
+ };
package/src/index.ts CHANGED
@@ -29,10 +29,13 @@ export * from "./components/date-picker";
29
29
  export * from "./components/context-menu";
30
30
  export * from "./components/delta";
31
31
  export * from "./components/description";
32
+ export * from "./components/description-list";
32
33
  export * from "./components/dialog";
33
34
  export * from "./components/drawer";
34
35
  export * from "./components/dropdown-menu";
36
+ export * from "./components/count-indicator";
35
37
  export * from "./components/field";
38
+ export * from "./components/file-upload";
36
39
  export * from "./components/global-layout";
37
40
  export * from "./components/grid";
38
41
  export * from "./components/header";
@@ -97,6 +100,7 @@ export * from "./blocks/sidebar";
97
100
 
98
101
  // Hooks
99
102
  export * from "./hooks/use-debounce";
103
+ export * from "./hooks/use-file-dropzone";
100
104
  export * from "./hooks/use-delayed-pending";
101
105
  export * from "./hooks/use-filter-search-params";
102
106
  export * from "./hooks/use-breakpoint";
@@ -23,15 +23,22 @@ import { TypographyText } from "../components/typography-text";
23
23
  * -----------------------------------------------------------------------------------------------*/
24
24
 
25
25
  /**
26
- * The glyph is one size, everywhere: 32.
26
+ * The glyph is 32 in every real content box.
27
27
  *
28
- * It does not scale with the box, and there is no size step either. A canvas
29
- * empty is one treatment, so it reads the same on a metric card's plot, a map
30
- * well and a photo slot — and every box these land in is a real content box,
31
- * where 32 is right. A step existed briefly for a 1200px mockup-filler frame
32
- * that no longer exists; three variants of one treatment were noise.
28
+ * It does not scale with the box. A canvas empty is one treatment, so it reads
29
+ * the same on a metric card's plot, a map well and a photo slot. A larger step
30
+ * existed briefly for a 1200px mockup-filler frame that no longer exists.
31
+ *
32
+ * The one smaller step is for a slot under 48px — a table thumbnail, a list
33
+ * avatar (DS-1257). A 32px glyph plus a line cannot centre in a 40px tile, so
34
+ * the compact canvas drops the line and draws the glyph at 20 (`size-5`, the
35
+ * bare LogoMark `sm` glyph). Only `MediaEmpty` exposes it: a chart plot or a
36
+ * map well is never that small.
33
37
  */
34
- const CANVAS_ICON_SIZE = 32;
38
+ const CANVAS_ICON_SIZE = { md: 32, sm: 20 } as const;
39
+
40
+ /** The canvas sizes: `md` for a content box, `sm` for a slot under 48px. */
41
+ type EmptyCanvasSize = keyof typeof CANVAS_ICON_SIZE;
35
42
 
36
43
  /**
37
44
  * Props for the internal EmptyCanvas body.
@@ -47,8 +54,14 @@ interface EmptyCanvasProps extends Omit<
47
54
  * carries is overridden — so no call site has a number to get wrong.
48
55
  */
49
56
  icon: React.ReactNode;
50
- /** The one line under the glyph. */
57
+ /** The one line under the glyph. Ignored at size `sm`, which has no line. */
51
58
  message: string;
59
+ /**
60
+ * `md` draws the 32px glyph and the line; `sm` draws a 20px glyph alone,
61
+ * centred, for slots under 48px.
62
+ * @default "md"
63
+ */
64
+ size?: EmptyCanvasSize;
52
65
  /** The calling component's slot name, e.g. `"chart-empty"`. */
53
66
  slot: string;
54
67
  /** Tracking element identifier for analytics. */
@@ -67,6 +80,7 @@ const EmptyCanvas = React.forwardRef<HTMLDivElement, EmptyCanvasProps>(
67
80
  dataHook,
68
81
  icon,
69
82
  message,
83
+ size = "md",
70
84
  slot,
71
85
  trackingEl,
72
86
  trackingLabel,
@@ -84,7 +98,7 @@ const EmptyCanvas = React.forwardRef<HTMLDivElement, EmptyCanvasProps>(
84
98
  typeof icon.type !== "string" &&
85
99
  icon.type !== React.Fragment
86
100
  ? React.cloneElement(icon as React.ReactElement<{ size?: number }>, {
87
- size: CANVAS_ICON_SIZE,
101
+ size: CANVAS_ICON_SIZE[size],
88
102
  })
89
103
  : icon;
90
104
 
@@ -92,10 +106,14 @@ const EmptyCanvas = React.forwardRef<HTMLDivElement, EmptyCanvasProps>(
92
106
  <div
93
107
  ref={ref}
94
108
  className={cn(
95
- "bg-muted flex flex-col items-center justify-center gap-2 text-center",
109
+ "bg-muted flex flex-col items-center justify-center text-center",
110
+ /* The gap only separates the glyph from the line; with no line it
111
+ would push the glyph off-centre. */
112
+ size === "md" && "gap-2",
96
113
  className
97
114
  )}
98
115
  data-hook={dataHook}
116
+ data-size={size}
99
117
  data-slot={slot}
100
118
  data-tracking-el={trackingEl ?? slot}
101
119
  data-tracking-label={trackingLabel}
@@ -103,21 +121,28 @@ const EmptyCanvas = React.forwardRef<HTMLDivElement, EmptyCanvasProps>(
103
121
  >
104
122
  <span
105
123
  aria-hidden="true"
106
- className="text-muted-foreground flex items-center justify-center [&_svg:not([class*='size-'])]:size-8"
124
+ className={cn(
125
+ "text-muted-foreground flex items-center justify-center",
126
+ size === "md"
127
+ ? "[&_svg:not([class*='size-'])]:size-8"
128
+ : "[&_svg:not([class*='size-'])]:size-5"
129
+ )}
107
130
  data-hook={`${dataHook}-icon`}
108
131
  data-slot={`${slot}-icon`}
109
132
  >
110
133
  {sized}
111
134
  </span>
112
- <TypographyText
113
- align="center"
114
- color="muted"
115
- data-slot={`${slot}-message`}
116
- dataHook={`${dataHook}-message`}
117
- variant="body-sm"
118
- >
119
- {message}
120
- </TypographyText>
135
+ {size === "md" ? (
136
+ <TypographyText
137
+ align="center"
138
+ color="muted"
139
+ data-slot={`${slot}-message`}
140
+ dataHook={`${dataHook}-message`}
141
+ variant="body-sm"
142
+ >
143
+ {message}
144
+ </TypographyText>
145
+ ) : null}
121
146
  </div>
122
147
  );
123
148
  }
@@ -126,3 +151,5 @@ const EmptyCanvas = React.forwardRef<HTMLDivElement, EmptyCanvasProps>(
126
151
  EmptyCanvas.displayName = "EmptyCanvas";
127
152
 
128
153
  export { EmptyCanvas };
154
+
155
+ export type { EmptyCanvasSize };
@@ -1,13 +1,18 @@
1
1
  import * as React from "react";
2
2
 
3
3
  import { cn } from "@brightlocal/ui-components/lib/utils";
4
- import { LogoMark, type LogoMarkVariant } from "../components/logo-mark";
4
+ import {
5
+ LogoMark,
6
+ type LogoMarkShape,
7
+ type LogoMarkVariant,
8
+ } from "../components/logo-mark";
5
9
 
6
10
  /* -------------------------------------------------------------------------------------------------
7
11
  * Empty chip (internal)
8
12
  *
9
- * The icon chip every "nothing here" moment shares — EmptyState at card
10
- * scope, and CommandEmpty / ComboboxEmpty at popover scope. It is the DS
13
+ * The icon chip every "nothing here" moment shares — EmptyState at every
14
+ * size, which CommandEmpty / ComboboxEmpty and the filter drawers render at
15
+ * size sm for popover scope. It is the DS
11
16
  * LogoMark at lg (a 40px rounded square) with the glyph in muted ink, so the
12
17
  * empty chip and every other icon mark in the product share one shape
13
18
  * (DS-1208). It lives once so the two scopes cannot drift: the popover form
@@ -21,12 +26,40 @@ import { LogoMark, type LogoMarkVariant } from "../components/logo-mark";
21
26
  * is no variant for that here.
22
27
  * -----------------------------------------------------------------------------------------------*/
23
28
 
29
+ /**
30
+ * Whether an empty state's actions (`children`) render anything, so the
31
+ * actions row is never drawn around nothing. Used by EmptyState, and by
32
+ * CommandEmpty / ComboboxEmpty to decide whether `children` are actions.
33
+ *
34
+ * `children ? …` is not enough. Call sites write `{canAdd && <Button/>}`, and
35
+ * two conditionals make `children` the array `[false, false]`, which is truthy.
36
+ * `Children.toArray` drops null, undefined and booleans. It does NOT look inside
37
+ * a fragment, so a call site that wraps its conditionals in one (`<>{a}{b}</>`)
38
+ * would count as one child however empty it is. Unwrap one level first.
39
+ */
40
+ export function hasEmptyActions(children: React.ReactNode): boolean {
41
+ return (
42
+ React.Children.toArray(children).flatMap((child) =>
43
+ React.isValidElement(child) && child.type === React.Fragment
44
+ ? React.Children.toArray(
45
+ (child.props as { children?: React.ReactNode }).children
46
+ )
47
+ : [child]
48
+ ).length > 0
49
+ );
50
+ }
51
+
24
52
  interface EmptyChipProps {
25
53
  dataHook: string;
26
54
  /** The glyph. Decorative — the chip is aria-hidden. */
27
55
  icon: React.ReactNode;
28
56
  /** @default "filled" */
29
57
  variant?: LogoMarkVariant;
58
+ /**
59
+ * Container shape passed to LogoMark.
60
+ * @default "circle"
61
+ */
62
+ shape?: LogoMarkShape;
30
63
  /** Overrides LogoMark's own `logo-mark` slot, so each host keeps its name. */
31
64
  slot: string;
32
65
  className?: string;
@@ -36,6 +69,7 @@ export function EmptyChip({
36
69
  dataHook,
37
70
  icon,
38
71
  variant = "filled",
72
+ shape = "circle",
39
73
  slot,
40
74
  className,
41
75
  }: EmptyChipProps) {
@@ -45,6 +79,7 @@ export function EmptyChip({
45
79
  data-slot={slot}
46
80
  dataHook={dataHook}
47
81
  name={icon}
82
+ shape={shape}
48
83
  size="lg"
49
84
  variant={variant}
50
85
  />
@@ -5,8 +5,8 @@ import * as React from "react";
5
5
  /**
6
6
  * Wires a Field's hint and error message to the control inside it.
7
7
  *
8
- * `Field` provides the context. `FieldDescription` and `FieldError` register
9
- * the id they render while they are on screen. Text controls (`Input`,
8
+ * `Field` provides the context. `FieldDescription`, `FieldError` and
9
+ * `CountIndicator` register the id they render while they are on screen. Text controls (`Input`,
10
10
  * `Textarea`) read the registered ids and point `aria-describedby` at them, so
11
11
  * a screen reader hears the message together with the field. Outside a Field
12
12
  * the hooks do nothing and a control behaves exactly as before.
@@ -18,7 +18,7 @@ import * as React from "react";
18
18
  * passes `id` on the message and `aria-describedby` on the control by hand.
19
19
  */
20
20
 
21
- type FieldAriaKind = "description" | "error";
21
+ type FieldAriaKind = "description" | "error" | "count";
22
22
 
23
23
  type FieldAriaIds = Record<FieldAriaKind, string[]>;
24
24
 
@@ -29,7 +29,7 @@ interface FieldAriaContextValue {
29
29
  register: (kind: FieldAriaKind, id: string) => () => void;
30
30
  }
31
31
 
32
- const EMPTY_IDS: FieldAriaIds = { description: [], error: [] };
32
+ const EMPTY_IDS: FieldAriaIds = { description: [], error: [], count: [] };
33
33
 
34
34
  const FieldAriaContext = React.createContext<FieldAriaContextValue | null>(
35
35
  null
@@ -79,7 +79,7 @@ function useFieldAriaRegistration(
79
79
 
80
80
  /**
81
81
  * Returns the `aria-describedby` value for a control: the Field's error, then
82
- * its hint, then whatever the consumer passed. Ids are de-duplicated, so a
82
+ * its hint, then its count indicator, then whatever the consumer passed. Ids are de-duplicated, so a
83
83
  * consumer that already wires the same id by hand is unaffected. Outside a
84
84
  * Field it returns `describedBy` unchanged.
85
85
  */
@@ -89,7 +89,12 @@ function useFieldDescribedBy(describedBy?: string): string | undefined {
89
89
 
90
90
  const own = describedBy?.split(/\s+/).filter(Boolean) ?? [];
91
91
  const merged = [
92
- ...new Set([...context.ids.error, ...context.ids.description, ...own]),
92
+ ...new Set([
93
+ ...context.ids.error,
94
+ ...context.ids.description,
95
+ ...context.ids.count,
96
+ ...own,
97
+ ]),
93
98
  ];
94
99
  return merged.length > 0 ? merged.join(" ") : undefined;
95
100
  }
@@ -72,3 +72,41 @@ export function scrollRegionProps(scrollRegionLabel: string | undefined) {
72
72
  tabIndex: 0,
73
73
  } as const;
74
74
  }
75
+
76
+ /**
77
+ * CSS custom property a table's scroll container publishes with its visible
78
+ * inline size (`clientWidth`, px) — DS-1105. `TableEmpty` caps its message
79
+ * at it and pins the message `sticky left-0`, so the empty state stays in
80
+ * the visible part of a table that scrolls sideways. Measured rather than
81
+ * `container-type: inline-size` + `cqi`: inline-size containment zeroes the
82
+ * element's intrinsic width, which collapses a table to 0px in any
83
+ * shrink-to-fit parent (a row flex item without `flex-1`, `w-fit`, a grid
84
+ * `auto` track).
85
+ */
86
+ export const TABLE_VIEW_INLINE_SIZE_VAR = "--table-view-inline-size";
87
+
88
+ /**
89
+ * Publish the scroll container's visible inline size as
90
+ * `--table-view-inline-size` on the element itself (inherited by every cell),
91
+ * kept current by a ResizeObserver. Written straight to the element's style —
92
+ * no React state, so a resize never re-renders the table. Removed when
93
+ * `enabled` turns false or on unmount.
94
+ */
95
+ export function useTableViewInlineSize(
96
+ ref: React.RefObject<HTMLElement | null>,
97
+ enabled: boolean
98
+ ): void {
99
+ React.useLayoutEffect(() => {
100
+ const el = ref.current;
101
+ if (!enabled || !el) return;
102
+ const measure = () =>
103
+ el.style.setProperty(TABLE_VIEW_INLINE_SIZE_VAR, `${el.clientWidth}px`);
104
+ measure();
105
+ const observer = new ResizeObserver(measure);
106
+ observer.observe(el);
107
+ return () => {
108
+ observer.disconnect();
109
+ el.style.removeProperty(TABLE_VIEW_INLINE_SIZE_VAR);
110
+ };
111
+ }, [ref, enabled]);
112
+ }