@brightlocal/ui-components 3.4.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.
- package/AI_USAGE.md +22 -3
- package/README.md +177 -109
- package/component-meta.json +1061 -102
- package/dist/alert-dialog.cjs +1 -1
- package/dist/alert-dialog.d.ts +13 -2
- package/dist/alert-dialog.d.ts.map +1 -1
- package/dist/alert-dialog.js +4 -3
- package/dist/banner.cjs +1 -1
- package/dist/banner.d.ts +47 -11
- package/dist/banner.d.ts.map +1 -1
- package/dist/banner.js +156 -79
- package/dist/blocks/empty-state.cjs +1 -1
- package/dist/blocks/empty-state.d.ts +40 -5
- package/dist/blocks/empty-state.d.ts.map +1 -1
- package/dist/blocks/empty-state.js +59 -52
- package/dist/blocks/input-list.d.ts +1 -0
- package/dist/blocks/input-list.d.ts.map +1 -1
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +12 -6
- package/dist/blocks/sidebar.d.ts.map +1 -1
- package/dist/blocks/sidebar.js +64 -63
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +47 -43
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +12 -0
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +115 -97
- package/dist/chart.cjs +6 -6
- package/dist/chart.d.ts +6 -10
- package/dist/chart.d.ts.map +1 -1
- package/dist/chart.js +281 -296
- package/dist/combobox.cjs +3 -3
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +430 -343
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +23 -2
- package/dist/command.d.ts.map +1 -1
- package/dist/command.js +212 -207
- package/dist/count-indicator.cjs +1 -0
- package/dist/count-indicator.d.ts +85 -0
- package/dist/count-indicator.d.ts.map +1 -0
- package/dist/count-indicator.js +72 -0
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.d.ts +101 -11
- package/dist/data-table.d.ts.map +1 -1
- package/dist/data-table.js +593 -523
- package/dist/dialog.cjs +1 -1
- package/dist/dialog.d.ts +26 -3
- package/dist/dialog.d.ts.map +1 -1
- package/dist/dialog.js +62 -47
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.d.ts +8 -4
- package/dist/drawer.d.ts.map +1 -1
- package/dist/drawer.js +37 -38
- package/dist/file-upload.cjs +1 -0
- package/dist/file-upload.d.ts +546 -0
- package/dist/file-upload.d.ts.map +1 -0
- package/dist/file-upload.js +1103 -0
- package/dist/global-layout.cjs +1 -1
- package/dist/global-layout.d.ts +7 -2
- package/dist/global-layout.d.ts.map +1 -1
- package/dist/global-layout.js +52 -52
- package/dist/hooks/use-file-dropzone.cjs +1 -0
- package/dist/hooks/use-file-dropzone.d.ts +75 -0
- package/dist/hooks/use-file-dropzone.d.ts.map +1 -0
- package/dist/hooks/use-file-dropzone.js +133 -0
- package/dist/hover-card.cjs +1 -1
- package/dist/hover-card.d.ts +29 -16
- package/dist/hover-card.d.ts.map +1 -1
- package/dist/hover-card.js +153 -36
- 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 +676 -640
- package/dist/input-chip.cjs +1 -1
- package/dist/input-chip.d.ts +30 -1
- package/dist/input-chip.d.ts.map +1 -1
- package/dist/input-chip.js +131 -115
- package/dist/input-group.cjs +1 -1
- package/dist/input-group.d.ts +37 -2
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +131 -114
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.js +6 -6
- package/dist/lib/empty-canvas.cjs +1 -1
- package/dist/lib/empty-canvas.d.ts +27 -1
- package/dist/lib/empty-canvas.d.ts.map +1 -1
- package/dist/lib/empty-canvas.js +27 -23
- package/dist/lib/empty-chip.cjs +1 -1
- package/dist/lib/empty-chip.d.ts +19 -2
- package/dist/lib/empty-chip.d.ts.map +1 -1
- package/dist/lib/empty-chip.js +14 -9
- package/dist/lib/field-aria.cjs +1 -1
- package/dist/lib/field-aria.d.ts +4 -4
- package/dist/lib/field-aria.d.ts.map +1 -1
- package/dist/lib/field-aria.js +7 -5
- package/dist/lib/media-viewer-content.cjs +1 -1
- package/dist/lib/media-viewer-content.js +1 -1
- package/dist/lib/table-internal.cjs +1 -1
- package/dist/lib/table-internal.d.ts +19 -0
- package/dist/lib/table-internal.d.ts.map +1 -1
- package/dist/lib/table-internal.js +22 -7
- package/dist/list.cjs +1 -1
- package/dist/list.d.ts +13 -0
- package/dist/list.d.ts.map +1 -1
- package/dist/list.js +103 -82
- package/dist/logo-mark.cjs +1 -1
- package/dist/logo-mark.d.ts +18 -2
- package/dist/logo-mark.d.ts.map +1 -1
- package/dist/logo-mark.js +159 -79
- package/dist/media-empty.cjs +1 -1
- package/dist/media-empty.d.ts +50 -7
- package/dist/media-empty.d.ts.map +1 -1
- package/dist/media-empty.js +14 -13
- package/dist/media-viewer.cjs +1 -1
- package/dist/media-viewer.js +6 -6
- package/dist/multi-select-filter.cjs +1 -1
- package/dist/multi-select-filter.d.ts.map +1 -1
- package/dist/multi-select-filter.js +92 -101
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +11 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +17 -17
- package/dist/relative-date.d.ts +6 -0
- package/dist/relative-date.d.ts.map +1 -1
- package/dist/resizable.d.ts +1 -1
- package/dist/result-count.cjs +1 -1
- package/dist/result-count.d.ts +13 -16
- package/dist/result-count.d.ts.map +1 -1
- package/dist/result-count.js +24 -33
- package/dist/sheet.cjs +1 -1
- package/dist/sheet.d.ts +22 -3
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +152 -125
- package/dist/single-select-filter.cjs +1 -1
- package/dist/single-select-filter.d.ts.map +1 -1
- package/dist/single-select-filter.js +67 -76
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +77 -76
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.d.ts +39 -3
- package/dist/tabs.d.ts.map +1 -1
- package/dist/tabs.js +127 -76
- package/dist/textarea.cjs +1 -1
- package/dist/textarea.d.ts +34 -0
- package/dist/textarea.d.ts.map +1 -1
- package/dist/textarea.js +115 -19
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.d.ts.map +1 -1
- package/dist/tooltip.js +137 -131
- package/dist/typography-text.cjs +1 -1
- package/dist/typography-text.d.ts +6 -2
- package/dist/typography-text.d.ts.map +1 -1
- package/dist/typography-text.js +14 -13
- package/package.json +3 -4
- package/src/blocks/empty-state.tsx +108 -48
- package/src/blocks/input-list.tsx +1 -0
- package/src/blocks/sidebar.tsx +39 -16
- package/src/components/alert-dialog.tsx +18 -2
- package/src/components/banner.tsx +247 -68
- package/src/components/button.tsx +27 -10
- package/src/components/card.tsx +89 -7
- package/src/components/chart.tsx +47 -67
- package/src/components/combobox.tsx +221 -12
- package/src/components/command.tsx +83 -37
- package/src/components/count-indicator.tsx +188 -0
- package/src/components/data-table.tsx +506 -159
- package/src/components/dialog.tsx +74 -5
- package/src/components/drawer.tsx +52 -32
- package/src/components/file-upload.tsx +2574 -0
- package/src/components/global-layout.tsx +18 -5
- package/src/components/hover-card.tsx +395 -65
- package/src/components/input-chip.tsx +67 -2
- package/src/components/input-group.tsx +89 -6
- package/src/components/list.tsx +40 -3
- package/src/components/logo-mark.tsx +109 -25
- package/src/components/media-empty.tsx +62 -7
- package/src/components/multi-select-filter.tsx +9 -16
- package/src/components/pagination.tsx +15 -2
- package/src/components/relative-date.tsx +6 -0
- package/src/components/result-count.tsx +27 -54
- package/src/components/sheet.tsx +86 -8
- package/src/components/single-select-filter.tsx +9 -16
- package/src/components/table.tsx +16 -1
- package/src/components/tabs.tsx +223 -41
- package/src/components/textarea.tsx +271 -4
- package/src/components/tooltip.tsx +29 -2
- package/src/components/typography-text.tsx +7 -2
- package/src/hooks/use-file-dropzone.ts +325 -0
- package/src/index.ts +3 -0
- package/src/lib/empty-canvas.tsx +47 -20
- package/src/lib/empty-chip.tsx +38 -3
- package/src/lib/field-aria.tsx +11 -6
- 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
|
@@ -33,7 +33,9 @@ export * from "./components/description-list";
|
|
|
33
33
|
export * from "./components/dialog";
|
|
34
34
|
export * from "./components/drawer";
|
|
35
35
|
export * from "./components/dropdown-menu";
|
|
36
|
+
export * from "./components/count-indicator";
|
|
36
37
|
export * from "./components/field";
|
|
38
|
+
export * from "./components/file-upload";
|
|
37
39
|
export * from "./components/global-layout";
|
|
38
40
|
export * from "./components/grid";
|
|
39
41
|
export * from "./components/header";
|
|
@@ -98,6 +100,7 @@ export * from "./blocks/sidebar";
|
|
|
98
100
|
|
|
99
101
|
// Hooks
|
|
100
102
|
export * from "./hooks/use-debounce";
|
|
103
|
+
export * from "./hooks/use-file-dropzone";
|
|
101
104
|
export * from "./hooks/use-delayed-pending";
|
|
102
105
|
export * from "./hooks/use-filter-search-params";
|
|
103
106
|
export * from "./hooks/use-breakpoint";
|
package/src/lib/empty-canvas.tsx
CHANGED
|
@@ -23,15 +23,22 @@ import { TypographyText } from "../components/typography-text";
|
|
|
23
23
|
* -----------------------------------------------------------------------------------------------*/
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* The glyph is
|
|
26
|
+
* The glyph is 32 in every real content box.
|
|
27
27
|
*
|
|
28
|
-
* It does not scale with the box
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
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
|
|
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=
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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 };
|
package/src/lib/empty-chip.tsx
CHANGED
|
@@ -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 {
|
|
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
|
|
10
|
-
*
|
|
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
|
/>
|
package/src/lib/field-aria.tsx
CHANGED
|
@@ -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
|
|
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([
|
|
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
|
+
}
|