@groupeactual/ui-kit 1.7.0-beta.3 → 1.7.0-beta.4
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/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.ts +5 -5
- package/dist/es/index.js +2 -2
- package/dist/es/index.js.map +1 -1
- package/dist/es/src/components/UploadDocument/FileUploaderSingle.d.ts +5 -5
- package/package.json +2 -2
- package/src/components/Tooltip/Tooltip.tsx +1 -1
- package/src/components/UploadDocument/FileUploaderSingle.tsx +46 -19
|
@@ -17,7 +17,7 @@ export interface Props {
|
|
|
17
17
|
children?: JSX.Element | null;
|
|
18
18
|
titleAddButton?: string;
|
|
19
19
|
_isDroppingFile?: boolean;
|
|
20
|
-
validateFile?: (_size: number, _type: string) => boolean;
|
|
20
|
+
validateFile?: (_size: number, _type: string, _accept: string[], _setUploadFileError: React.Dispatch<React.SetStateAction<boolean | string>>) => boolean;
|
|
21
21
|
removeExistingFile?: () => void;
|
|
22
22
|
onTouched?: () => void;
|
|
23
23
|
onFileDataChange?: (_fileData: {
|
|
@@ -57,13 +57,13 @@ export interface Props {
|
|
|
57
57
|
*
|
|
58
58
|
* Example:
|
|
59
59
|
* ```js
|
|
60
|
-
* validateFile={(size, type) => {
|
|
60
|
+
* validateFile={(size, type, accept, setUploadFileError) => {
|
|
61
61
|
* if (size > 10 * 1024 * 1024) {
|
|
62
|
-
|
|
62
|
+
* setUploadFileError('Le fichier doit être inférieur à 10 Mo');
|
|
63
63
|
* return true;
|
|
64
64
|
* }
|
|
65
|
-
* if (!
|
|
66
|
-
*
|
|
65
|
+
* if (!accept.includes(type)) {
|
|
66
|
+
* setUploadFileError('Le fichier doit être au format PDF, PNG, JPEG ou JPG');
|
|
67
67
|
* return true;
|
|
68
68
|
* }
|
|
69
69
|
* return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@groupeactual/ui-kit",
|
|
3
|
-
"version": "1.7.0-beta.
|
|
3
|
+
"version": "1.7.0-beta.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A simple template for a custom React component library",
|
|
6
6
|
"devDependencies": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"react": "^18.3.1",
|
|
57
57
|
"react-dom": "^18.3.1",
|
|
58
58
|
"react-google-picker": "^0.1.0",
|
|
59
|
-
"@groupeactual/design-tokens": "1.7.0-beta.
|
|
59
|
+
"@groupeactual/design-tokens": "1.7.0-beta.4"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "rollup -c",
|
|
@@ -48,7 +48,12 @@ export interface Props {
|
|
|
48
48
|
children?: JSX.Element | null;
|
|
49
49
|
titleAddButton?: string;
|
|
50
50
|
_isDroppingFile?: boolean; // * Only used for storybook
|
|
51
|
-
validateFile?: (
|
|
51
|
+
validateFile?: (
|
|
52
|
+
_size: number,
|
|
53
|
+
_type: string,
|
|
54
|
+
_accept: string[],
|
|
55
|
+
_setUploadFileError: React.Dispatch<React.SetStateAction<boolean | string>>,
|
|
56
|
+
) => boolean;
|
|
52
57
|
removeExistingFile?: () => void;
|
|
53
58
|
onTouched?: () => void;
|
|
54
59
|
onFileDataChange?: (
|
|
@@ -91,13 +96,13 @@ export interface Props {
|
|
|
91
96
|
*
|
|
92
97
|
* Example:
|
|
93
98
|
* ```js
|
|
94
|
-
* validateFile={(size, type) => {
|
|
99
|
+
* validateFile={(size, type, accept, setUploadFileError) => {
|
|
95
100
|
* if (size > 10 * 1024 * 1024) {
|
|
96
|
-
|
|
101
|
+
* setUploadFileError('Le fichier doit être inférieur à 10 Mo');
|
|
97
102
|
* return true;
|
|
98
103
|
* }
|
|
99
|
-
* if (!
|
|
100
|
-
*
|
|
104
|
+
* if (!accept.includes(type)) {
|
|
105
|
+
* setUploadFileError('Le fichier doit être au format PDF, PNG, JPEG ou JPG');
|
|
101
106
|
* return true;
|
|
102
107
|
* }
|
|
103
108
|
* return false;
|
|
@@ -147,6 +152,10 @@ const FileUploaderSingle = ({
|
|
|
147
152
|
useState<boolean>(_isDroppingFile);
|
|
148
153
|
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
|
149
154
|
|
|
155
|
+
const [fileUploadError, setUploadFileError] = useState<string | boolean>(
|
|
156
|
+
false,
|
|
157
|
+
);
|
|
158
|
+
|
|
150
159
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
151
160
|
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
|
152
161
|
setAnchorEl(event.currentTarget);
|
|
@@ -167,6 +176,7 @@ const FileUploaderSingle = ({
|
|
|
167
176
|
}[];
|
|
168
177
|
} | null,
|
|
169
178
|
token: string | null = null,
|
|
179
|
+
accept: string[] = [],
|
|
170
180
|
fakeClick?: boolean,
|
|
171
181
|
) => {
|
|
172
182
|
if (fakeClick) {
|
|
@@ -175,13 +185,17 @@ const FileUploaderSingle = ({
|
|
|
175
185
|
handleClose();
|
|
176
186
|
onTouched?.();
|
|
177
187
|
|
|
188
|
+
// * Local File
|
|
178
189
|
if (
|
|
179
190
|
fileInputRef.current?.files &&
|
|
180
191
|
fileInputRef.current.files.length > 0
|
|
181
192
|
) {
|
|
182
193
|
const file = fileInputRef.current.files[0];
|
|
183
194
|
setCurrentFile(file);
|
|
184
|
-
if (
|
|
195
|
+
if (
|
|
196
|
+
validateFile &&
|
|
197
|
+
validateFile(file.size, file.type, accept, setUploadFileError)
|
|
198
|
+
) {
|
|
185
199
|
setIsDroppingFile(false);
|
|
186
200
|
return;
|
|
187
201
|
}
|
|
@@ -199,6 +213,7 @@ const FileUploaderSingle = ({
|
|
|
199
213
|
setIsDroppingFile(false);
|
|
200
214
|
}
|
|
201
215
|
|
|
216
|
+
// * Google Drive
|
|
202
217
|
if (token && data && data.docs && data.docs.length > 0) {
|
|
203
218
|
const googleFile = data.docs[0];
|
|
204
219
|
const fileData = {
|
|
@@ -210,7 +225,12 @@ const FileUploaderSingle = ({
|
|
|
210
225
|
};
|
|
211
226
|
if (
|
|
212
227
|
validateFile &&
|
|
213
|
-
validateFile(
|
|
228
|
+
validateFile(
|
|
229
|
+
googleFile.sizeBytes,
|
|
230
|
+
googleFile.mimeType,
|
|
231
|
+
accept,
|
|
232
|
+
setUploadFileError,
|
|
233
|
+
)
|
|
214
234
|
) {
|
|
215
235
|
return;
|
|
216
236
|
}
|
|
@@ -251,9 +271,9 @@ const FileUploaderSingle = ({
|
|
|
251
271
|
|
|
252
272
|
const dashedColor = useMemo(() => {
|
|
253
273
|
if (isDroppingFile) return DROPPING_COLOR;
|
|
254
|
-
if (error) return ERROR_COLOR;
|
|
274
|
+
if (error || fileUploadError !== false) return ERROR_COLOR;
|
|
255
275
|
return DEFAULT_COLOR;
|
|
256
|
-
}, [isDroppingFile, error]);
|
|
276
|
+
}, [isDroppingFile, error, fileUploadError]);
|
|
257
277
|
|
|
258
278
|
const bgColor = useMemo(() => {
|
|
259
279
|
if (fileData?.name || disabledInput) return 'greyXLight';
|
|
@@ -263,9 +283,9 @@ const FileUploaderSingle = ({
|
|
|
263
283
|
|
|
264
284
|
const titleColor = useMemo(() => {
|
|
265
285
|
if (fileData?.name) return 'greyDark';
|
|
266
|
-
if (error) return 'redError';
|
|
286
|
+
if (error || fileUploadError !== false) return 'redError';
|
|
267
287
|
return 'greyXDark';
|
|
268
|
-
}, [fileData?.name, error]);
|
|
288
|
+
}, [fileData?.name, error, fileUploadError]);
|
|
269
289
|
|
|
270
290
|
const inputCss = useMemo(
|
|
271
291
|
() => ({
|
|
@@ -320,7 +340,12 @@ const FileUploaderSingle = ({
|
|
|
320
340
|
</Text>
|
|
321
341
|
{titleTooltip && (
|
|
322
342
|
<Box sx={{ marginLeft: '4px' }}>
|
|
323
|
-
<Tooltip
|
|
343
|
+
<Tooltip
|
|
344
|
+
title={titleTooltip}
|
|
345
|
+
sx={{
|
|
346
|
+
display: 'flex',
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
324
349
|
<IconProvider icon={faInfoCircle} size="sm" color="blueInfo" />
|
|
325
350
|
</Tooltip>
|
|
326
351
|
</Box>
|
|
@@ -361,7 +386,7 @@ const FileUploaderSingle = ({
|
|
|
361
386
|
disabled={!!fileData?.name || disabledInput}
|
|
362
387
|
type="file"
|
|
363
388
|
ref={fileInputRef}
|
|
364
|
-
onChange={handleFileChange}
|
|
389
|
+
onChange={(event) => handleFileChange(event, null, null, accept)}
|
|
365
390
|
onBlur={onTouched}
|
|
366
391
|
accept={accept.join(', ')}
|
|
367
392
|
/>
|
|
@@ -446,7 +471,7 @@ const FileUploaderSingle = ({
|
|
|
446
471
|
>
|
|
447
472
|
<MenuItem
|
|
448
473
|
testId="pc-add"
|
|
449
|
-
onClick={() => handleFileChange(null, null, null, true)}
|
|
474
|
+
onClick={() => handleFileChange(null, null, null, [], true)}
|
|
450
475
|
>
|
|
451
476
|
<Box gap={1} display="flex">
|
|
452
477
|
<IconProvider size="sm" icon={faFolderOpen} />
|
|
@@ -455,7 +480,7 @@ const FileUploaderSingle = ({
|
|
|
455
480
|
</MenuItem>
|
|
456
481
|
<GooglePickerWrapper
|
|
457
482
|
callback={(data, token) =>
|
|
458
|
-
handleFileChange(null, data, token)
|
|
483
|
+
handleFileChange(null, data, token, accept)
|
|
459
484
|
}
|
|
460
485
|
multiselect={true}
|
|
461
486
|
navHidden={false}
|
|
@@ -482,7 +507,7 @@ const FileUploaderSingle = ({
|
|
|
482
507
|
backgroundColor: '#FFFFFF !important',
|
|
483
508
|
},
|
|
484
509
|
}}
|
|
485
|
-
onClick={() => handleFileChange(null, null, null, true)}
|
|
510
|
+
onClick={() => handleFileChange(null, null, null, [], true)}
|
|
486
511
|
disabled={!!fileData?.name}
|
|
487
512
|
>
|
|
488
513
|
<IconProvider icon={faUpload} size="md" mr={1} />
|
|
@@ -492,14 +517,16 @@ const FileUploaderSingle = ({
|
|
|
492
517
|
</Box>
|
|
493
518
|
</Box>
|
|
494
519
|
</Tooltip>
|
|
495
|
-
{(error || helperText) && (
|
|
520
|
+
{(error || helperText || fileUploadError !== false) && (
|
|
496
521
|
<Box pl={1} pt={1}>
|
|
497
522
|
<Text
|
|
498
523
|
variant="caption"
|
|
499
|
-
color={
|
|
524
|
+
color={
|
|
525
|
+
((error || fileUploadError !== false) && 'redError') || 'greyDark'
|
|
526
|
+
}
|
|
500
527
|
data-testid="helperText"
|
|
501
528
|
>
|
|
502
|
-
{helperText}
|
|
529
|
+
{fileUploadError !== false ? fileUploadError : helperText}
|
|
503
530
|
</Text>
|
|
504
531
|
</Box>
|
|
505
532
|
)}
|