@am92/react-design-system 2.9.12 → 2.10.1
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/Components/DsBottomSheet/DsBottomSheet.Component.js +6 -6
- package/dist/Components/DsDialog/DsDialog.Component.js +4 -4
- package/dist/Components/DsFileUploader/DsFileUploader.Component.d.ts +2 -3
- package/dist/Components/DsFileUploader/DsFileUploader.Component.js +109 -158
- package/dist/Components/DsFileUploader/DsFileUploader.Overrides.d.ts +5 -1
- package/dist/Components/DsFileUploader/DsFileUploader.Overrides.js +6 -1
- package/dist/Components/DsFileUploader/DsFileUploader.Types.d.ts +306 -13
- package/dist/Components/DsFileUploader/DsFileUploader.Types.js +46 -4
- package/dist/Components/DsFileUploader/DsFileUploaderPreview/DsFileUploaderImagePreview.Component.d.ts +11 -0
- package/dist/Components/DsFileUploader/DsFileUploaderPreview/DsFileUploaderImagePreview.Component.js +68 -0
- package/dist/Components/DsFileUploader/DsFileUploaderPreview/DsFileUploaderPreview.Component.d.ts +14 -0
- package/dist/Components/DsFileUploader/DsFileUploaderPreview/DsFileUploaderPreview.Component.js +28 -0
- package/dist/Components/DsFileUploader/FileUploaderFiles.d.ts +3 -0
- package/dist/Components/DsFileUploader/FileUploaderFiles.js +48 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderActionButton.Component.d.ts +10 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderActionButton.Component.js +18 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderDropZone.d.ts +10 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderDropZone.js +130 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderSelectedFilesSegment.d.ts +10 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderSelectedFilesSegment.js +21 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderUploadedFilesSegment.d.ts +10 -0
- package/dist/Components/DsFileUploader/Slots/DsFileUploaderUploadedFilesSegment.js +21 -0
- package/dist/Components/DsFileUploader/converter.d.ts +2 -0
- package/dist/Components/DsFileUploader/converter.js +25 -0
- package/dist/Components/DsFileUploader/helpers.d.ts +9 -0
- package/dist/Components/DsFileUploader/helpers.js +88 -0
- package/dist/Components/DsFileUploader/validator.d.ts +2 -0
- package/dist/Components/DsFileUploader/validator.js +37 -0
- package/dist/Theme/componentOverrides.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,19 +1,312 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ElementType } from 'react';
|
|
2
|
+
import { DsInputLabelProps } from '../DsInputLabel';
|
|
3
3
|
import { DsRemixIconProps } from '../DsRemixIcon';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { DsStackProps } from '../DsStack';
|
|
5
|
+
import { DsInputProps } from '../DsInput';
|
|
6
|
+
import { DsIconButtonProps } from '../DsIconButton';
|
|
7
|
+
export declare enum CONTENT_TYPE {
|
|
8
|
+
FILE = "FILE",
|
|
9
|
+
BASE64 = "BASE64"
|
|
10
|
+
}
|
|
11
|
+
export declare enum VARIANT {
|
|
12
|
+
FULL = "FULL",
|
|
13
|
+
COMPRESSED = "COMPRESSED"
|
|
14
|
+
}
|
|
15
|
+
export type TMultiple = boolean | undefined;
|
|
16
|
+
export type TContentType = keyof typeof CONTENT_TYPE;
|
|
17
|
+
export type TVariant = keyof typeof VARIANT;
|
|
18
|
+
export type TFileType<TContentType> = TContentType extends 'FILE' ? File : string;
|
|
19
|
+
export type TFile<TContentType> = {
|
|
20
|
+
/**
|
|
21
|
+
* Name of the file selected or dropped.
|
|
22
|
+
*/
|
|
6
23
|
name: string;
|
|
7
|
-
|
|
24
|
+
/**
|
|
25
|
+
* mime-type of the file selected or dropped.
|
|
26
|
+
*/
|
|
27
|
+
type: string;
|
|
28
|
+
/**
|
|
29
|
+
* size in bytes of the file selected or dropped.
|
|
30
|
+
*/
|
|
31
|
+
size: number;
|
|
32
|
+
/**
|
|
33
|
+
* content of the file selected or dropped.
|
|
34
|
+
*/
|
|
35
|
+
content: TFileType<TContentType>;
|
|
36
|
+
/**
|
|
37
|
+
* Unique Identifier for the file.
|
|
38
|
+
*/
|
|
39
|
+
id?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Extra content required to be displayed with the file name and size
|
|
42
|
+
*/
|
|
43
|
+
subText?: string;
|
|
44
|
+
};
|
|
45
|
+
export type TFileValue<Multiple, TContentType> = Multiple extends false ? TFile<TContentType> | null | undefined : TFile<TContentType>[] | undefined;
|
|
46
|
+
export type TProcessFile<TMultiple, TContentType> = {
|
|
47
|
+
valid: TFileValue<TMultiple, TContentType>;
|
|
48
|
+
invalid: TErrorValue<TMultiple, TContentType>;
|
|
49
|
+
};
|
|
50
|
+
export declare enum ERROR_CODES {
|
|
51
|
+
INVALID_FILE_TYPE = "INVALID_FILE_TYPE",
|
|
52
|
+
MAX_FILE_SIZE_EXCEEDED = "MAX_FILE_SIZE_EXCEEDED",
|
|
53
|
+
FILE_SIZE_BELOW_MIN = "FILE_SIZE_BELOW_MIN"
|
|
54
|
+
}
|
|
55
|
+
export type TErrorCodes = keyof typeof ERROR_CODES;
|
|
56
|
+
export type TErrorFile<CONTENT_TYPE> = {
|
|
57
|
+
file: TFile<CONTENT_TYPE>;
|
|
58
|
+
errorCode: TErrorCodes;
|
|
59
|
+
};
|
|
60
|
+
export type TErrorValue<Multiple, CONTENT_TYPE> = Multiple extends false ? TErrorFile<CONTENT_TYPE> | null : TErrorFile<CONTENT_TYPE>[];
|
|
61
|
+
export interface IDsFileUploaderProps<Multiple extends TMultiple = true, ContentType extends TContentType = 'FILE'> {
|
|
62
|
+
InputLabelProps?: Omit<DsInputLabelProps, 'ref' | 'error' | 'success' | 'htmlFor' | 'disabled'>;
|
|
63
|
+
/**
|
|
64
|
+
* Name attribute of the input element.
|
|
65
|
+
*/
|
|
66
|
+
name: string;
|
|
67
|
+
/**
|
|
68
|
+
* @param {TVariant} variant The variant of file uploader component.
|
|
69
|
+
* @default 'FULL'
|
|
70
|
+
*/
|
|
71
|
+
variant?: TVariant;
|
|
72
|
+
/**
|
|
73
|
+
* The `input` value. Value should be array of `TFile<TContentType>` type objects. If you have multiple false then value would be null
|
|
74
|
+
* @default []
|
|
75
|
+
*/
|
|
76
|
+
value?: TFileValue<Multiple, ContentType> | null;
|
|
77
|
+
/**
|
|
78
|
+
* The `input` uploadedValue. uploadedValue should be array of `TFile<TContentType>` type objects of your previously uploaded files. If you have multiple false then uploadedValue would be null
|
|
79
|
+
* @default []
|
|
80
|
+
*/
|
|
81
|
+
uploadedValue?: TFileValue<Multiple, ContentType>;
|
|
82
|
+
/**
|
|
83
|
+
* validate the minimum file size (in bytes).
|
|
84
|
+
*
|
|
85
|
+
* If file size is below the provided value then file will be passed back in `onError` callback.
|
|
86
|
+
*/
|
|
87
|
+
minSize?: number;
|
|
88
|
+
/**
|
|
89
|
+
* The `content` type in the file object returned in callbacks for newly selected files.
|
|
90
|
+
* @default 'FILE'
|
|
91
|
+
*/
|
|
92
|
+
contentType?: TContentType;
|
|
93
|
+
/**
|
|
94
|
+
* validate the maximum file size (in bytes).
|
|
95
|
+
*
|
|
96
|
+
* If file size exceeds the provided value then file will be passed back in `onError` callback.
|
|
97
|
+
*/
|
|
98
|
+
maxSize?: number;
|
|
99
|
+
/**
|
|
100
|
+
* The `accept` attribute of the input element.
|
|
101
|
+
*
|
|
102
|
+
* This will allow to restrict user to only upload specific type of files.
|
|
103
|
+
*
|
|
104
|
+
* If you want to allow only images then use `accept='image/*'` and so on.
|
|
105
|
+
*
|
|
106
|
+
* By default it will allow any file.
|
|
107
|
+
* @default '*'
|
|
108
|
+
*/
|
|
109
|
+
accept?: string;
|
|
110
|
+
/**
|
|
111
|
+
* The `multiple` attribute of the input element.
|
|
112
|
+
*
|
|
113
|
+
* If `false` then user can upload only single file.
|
|
114
|
+
* @default false
|
|
115
|
+
*/
|
|
116
|
+
multiple?: Multiple;
|
|
117
|
+
/**
|
|
118
|
+
* To override icon associated to each file type. Called in loop for all selected files
|
|
119
|
+
*
|
|
120
|
+
* @param {string} name The name provided to the component.
|
|
121
|
+
* @param {TFile<ContentType>} [file] This would be the valid `TFile<ContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
122
|
+
*/
|
|
123
|
+
FileIconMapper?: (file: TFile<ContentType>) => DsRemixIconProps['className'];
|
|
124
|
+
/**
|
|
125
|
+
* Callback fired when a invalid file is selected or dropped.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} name The name provided to the component.
|
|
128
|
+
* @param { TErrorValue<Multiple, ContentType>} [files] This would be the valid `T_ERROR_FILE` type objects selected with its content as `FILE` type or as provided in value with the error code.
|
|
129
|
+
*/
|
|
130
|
+
onError?: (name: string, files: TErrorValue<Multiple, ContentType>) => void;
|
|
131
|
+
/**
|
|
132
|
+
* Callback fired when a file is selected or dropped.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} name The name provided to the component.
|
|
135
|
+
* @param {TFileValue<Multiple, ContentType>} [files] This would be the valid `T_FILE_UPLOADER` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
136
|
+
*/
|
|
137
|
+
onChange: (name: string, files: TFileValue<Multiple, ContentType>) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Callback fired when an existing file is removed.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} name The name provided to the component.
|
|
142
|
+
* @param {TFile<ContentType>} [file] This would be the valid `TFile<ContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
143
|
+
*/
|
|
144
|
+
onDelete?: (name: string, file: TFile<ContentType>) => void;
|
|
145
|
+
/**
|
|
146
|
+
* This is a handler that user can use to pass boolean if delete operation is async/API driven.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} name The name provided to the component.
|
|
149
|
+
* @param {TFile<ContentType>} [file] This would be the valid `TFile<ContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
150
|
+
*/
|
|
151
|
+
canDeleteFile?: (name: string, file: TFile<ContentType>) => Promise<boolean>;
|
|
152
|
+
/**
|
|
153
|
+
* Callback fired when an preview button is clicked for an existing file.
|
|
154
|
+
*
|
|
155
|
+
* @param {string} name The name provided to the component.
|
|
156
|
+
* @param {TFile<ContentType>} [file] This would be the valid `TFile<ContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
157
|
+
*/
|
|
158
|
+
onPreview?: (name: string, file: TFile<ContentType>) => void;
|
|
159
|
+
/**
|
|
160
|
+
* Callback fired when an download button is clicked for an existing file.
|
|
161
|
+
*
|
|
162
|
+
* @param {string} name The name provided to the component.
|
|
163
|
+
* @param {TFile<ContentType>} [file] This would be the valid `TFile<ContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
164
|
+
*/
|
|
165
|
+
onDownload?: (name: string, file: TFile<ContentType>) => void;
|
|
166
|
+
/**
|
|
167
|
+
slots prop is used to provide custom slots components to the file uploader
|
|
168
|
+
*/
|
|
169
|
+
slots?: TDsFileUploaderSlots;
|
|
170
|
+
/**
|
|
171
|
+
slotProps prop is used to provide custom props to the individual slots of the file uploader
|
|
172
|
+
*/
|
|
173
|
+
slotProps?: TDsFileUploaderSlotProps;
|
|
174
|
+
}
|
|
175
|
+
export interface IDsFileUploaderDropZoneProps extends DsStackProps {
|
|
176
|
+
/**
|
|
177
|
+
* @param {TFileUploaderVariant} variant The variant of file uploader component.
|
|
178
|
+
* @default 'FULL'
|
|
179
|
+
*/
|
|
180
|
+
variant?: IDsFileUploaderProps['variant'];
|
|
181
|
+
/**
|
|
182
|
+
* The `iconProps` component to be used for the file uploader.
|
|
183
|
+
*/
|
|
8
184
|
IconProps?: Omit<DsRemixIconProps, 'ref'>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
185
|
+
/**
|
|
186
|
+
* To override title text in dropbox.
|
|
187
|
+
*/
|
|
188
|
+
title?: string;
|
|
189
|
+
/**
|
|
190
|
+
* To override description text in dropbox.
|
|
191
|
+
*/
|
|
192
|
+
description?: string | string[];
|
|
193
|
+
/**
|
|
194
|
+
* To override props passed to input element
|
|
195
|
+
*/
|
|
13
196
|
InputProps?: DsInputProps['inputProps'];
|
|
197
|
+
/**
|
|
198
|
+
* This prop can be used to toggle the disabled state of the file uploaded.
|
|
199
|
+
*/
|
|
200
|
+
disabled?: boolean;
|
|
14
201
|
}
|
|
15
|
-
export interface
|
|
16
|
-
|
|
202
|
+
export interface IDsFileUploaderItemSegmentProps extends DsStackProps {
|
|
203
|
+
/**
|
|
204
|
+
* This prop is used to provide custom label to the segments
|
|
205
|
+
*/
|
|
206
|
+
label?: string;
|
|
207
|
+
/**
|
|
208
|
+
* This prop is used to switch the visibility of delete button in a particular segment
|
|
209
|
+
*/
|
|
210
|
+
showDeleteIcon?: boolean;
|
|
211
|
+
/**
|
|
212
|
+
* This prop is used to switch the visibility of preview button in a particular segment
|
|
213
|
+
*/
|
|
214
|
+
showPreviewIcon?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* This prop is used to switch the visibility of download button in a particular segment
|
|
217
|
+
*/
|
|
218
|
+
showDownloadIcon?: boolean;
|
|
219
|
+
/**
|
|
220
|
+
* This prop is used to supply files to the segment
|
|
221
|
+
*/
|
|
222
|
+
files?: TFile<TContentType> | TFile<TContentType>[];
|
|
223
|
+
/**
|
|
224
|
+
* Callback fired when an preview button is clicked for an existing file.
|
|
225
|
+
*
|
|
226
|
+
* @param {string} name The name provided to the component.
|
|
227
|
+
* @param {TFile<TContentType>} [file] This would be the valid `TFile<TContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
228
|
+
*/
|
|
229
|
+
onPreview?: IDsFileUploaderProps['onPreview'];
|
|
230
|
+
/**
|
|
231
|
+
* Callback fired when an existing file is removed.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} name The name provided to the component.
|
|
234
|
+
* @param {TFile<TContentType>} [file] This would be the valid `TFile<TContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
235
|
+
*/
|
|
236
|
+
onDelete?: IDsFileUploaderProps['onDelete'];
|
|
237
|
+
/**
|
|
238
|
+
* Callback fired when an download button is clicked for an existing file.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} name The name provided to the component.
|
|
241
|
+
* @param {TFile<TContentType>} [file] This would be the valid `TFile<TContentType>` type objects selected with its content value depending on `contentType` props or as provided in value.
|
|
242
|
+
*/
|
|
243
|
+
onDownload?: IDsFileUploaderProps['onDownload'];
|
|
244
|
+
/**
|
|
245
|
+
slots prop is used to provide custom slots components to the file uploader
|
|
246
|
+
*/
|
|
247
|
+
slots?: IDsFileUploaderProps['slots'];
|
|
248
|
+
/**
|
|
249
|
+
slotPros used to provide custom props to the individual slots of the file uploader
|
|
250
|
+
*/
|
|
251
|
+
slotProps?: IDsFileUploaderProps['slotProps'];
|
|
252
|
+
}
|
|
253
|
+
export interface IDsFileUploaderActionButtonProps extends DsIconButtonProps {
|
|
254
|
+
/**
|
|
255
|
+
* To override delete icon in files
|
|
256
|
+
*/
|
|
257
|
+
IconProps?: Omit<DsRemixIconProps, 'ref'>;
|
|
17
258
|
}
|
|
18
|
-
export
|
|
19
|
-
|
|
259
|
+
export type TDsFileUploaderSlots = {
|
|
260
|
+
/**
|
|
261
|
+
This prop is used to provide custom slot component to the drop zone of the component
|
|
262
|
+
*/
|
|
263
|
+
DropZone?: ElementType<IDsFileUploaderDropZoneProps>;
|
|
264
|
+
/**
|
|
265
|
+
This prop is used to provide custom slot component to the selected segment of the component
|
|
266
|
+
*/
|
|
267
|
+
SelectedItemSegment?: ElementType<IDsFileUploaderItemSegmentProps>;
|
|
268
|
+
/**
|
|
269
|
+
This prop is used to provide custom slot component to the uploaded segment of the component
|
|
270
|
+
*/
|
|
271
|
+
UploadedItemSegment?: ElementType<IDsFileUploaderItemSegmentProps>;
|
|
272
|
+
/**
|
|
273
|
+
This prop is used to provide custom slot component to the delete button of the component
|
|
274
|
+
*/
|
|
275
|
+
DeleteButton?: ElementType<IDsFileUploaderActionButtonProps>;
|
|
276
|
+
/**
|
|
277
|
+
This prop is used to provide custom slot component to the preview button of the component
|
|
278
|
+
*/
|
|
279
|
+
PreviewButton?: ElementType<IDsFileUploaderActionButtonProps>;
|
|
280
|
+
/**
|
|
281
|
+
This prop is used to provide custom slot component to the download button of the component
|
|
282
|
+
*/
|
|
283
|
+
DownloadButton?: ElementType<IDsFileUploaderActionButtonProps>;
|
|
284
|
+
};
|
|
285
|
+
export type TDsFileUploaderSlotProps = {
|
|
286
|
+
/**
|
|
287
|
+
This prop is used to provide custom props drop zone of the component
|
|
288
|
+
*/
|
|
289
|
+
DropZone?: IDsFileUploaderDropZoneProps;
|
|
290
|
+
/**
|
|
291
|
+
This prop is used to provide custom props selected segment of the component
|
|
292
|
+
*/
|
|
293
|
+
SelectedItemSegment?: IDsFileUploaderItemSegmentProps;
|
|
294
|
+
/**
|
|
295
|
+
This prop is used to provide custom props uploaded segment of the component
|
|
296
|
+
*/
|
|
297
|
+
UploadedItemSegment?: IDsFileUploaderItemSegmentProps;
|
|
298
|
+
/**
|
|
299
|
+
This prop is used to provide custom props delete button of the component
|
|
300
|
+
*/
|
|
301
|
+
DeleteButton?: IDsFileUploaderActionButtonProps;
|
|
302
|
+
/**
|
|
303
|
+
This prop is used to provide custom props preview button of the component
|
|
304
|
+
*/
|
|
305
|
+
PreviewButton?: IDsFileUploaderActionButtonProps;
|
|
306
|
+
/**
|
|
307
|
+
This prop is used to provide custom props download button of the component
|
|
308
|
+
*/
|
|
309
|
+
DownloadButton?: IDsFileUploaderActionButtonProps;
|
|
310
|
+
};
|
|
311
|
+
export declare const DsFileUploaderDefaultProps: IDsFileUploaderProps<TMultiple, 'FILE'>;
|
|
312
|
+
export declare const DsFileUploaderDropzoneDefaultProps: IDsFileUploaderDropZoneProps;
|
|
@@ -1,9 +1,51 @@
|
|
|
1
|
+
import { DsFileUploaderActionButton } from './Slots/DsFileUploaderActionButton.Component';
|
|
2
|
+
import { DsFileUploaderDropZone } from './Slots/DsFileUploaderDropZone';
|
|
3
|
+
import { DsFileUploaderSelectedFilesSegment } from './Slots/DsFileUploaderSelectedFilesSegment';
|
|
4
|
+
import { DsFileUploaderUploadedFilesSegment } from './Slots/DsFileUploaderUploadedFilesSegment';
|
|
5
|
+
export var CONTENT_TYPE;
|
|
6
|
+
(function (CONTENT_TYPE) {
|
|
7
|
+
CONTENT_TYPE["FILE"] = "FILE";
|
|
8
|
+
CONTENT_TYPE["BASE64"] = "BASE64";
|
|
9
|
+
})(CONTENT_TYPE || (CONTENT_TYPE = {}));
|
|
10
|
+
export var VARIANT;
|
|
11
|
+
(function (VARIANT) {
|
|
12
|
+
VARIANT["FULL"] = "FULL";
|
|
13
|
+
VARIANT["COMPRESSED"] = "COMPRESSED";
|
|
14
|
+
})(VARIANT || (VARIANT = {}));
|
|
15
|
+
export var ERROR_CODES;
|
|
16
|
+
(function (ERROR_CODES) {
|
|
17
|
+
ERROR_CODES["INVALID_FILE_TYPE"] = "INVALID_FILE_TYPE";
|
|
18
|
+
ERROR_CODES["MAX_FILE_SIZE_EXCEEDED"] = "MAX_FILE_SIZE_EXCEEDED";
|
|
19
|
+
ERROR_CODES["FILE_SIZE_BELOW_MIN"] = "FILE_SIZE_BELOW_MIN";
|
|
20
|
+
})(ERROR_CODES || (ERROR_CODES = {}));
|
|
1
21
|
export const DsFileUploaderDefaultProps = {
|
|
2
22
|
name: '',
|
|
3
23
|
onChange: () => { },
|
|
4
|
-
|
|
5
|
-
|
|
24
|
+
value: undefined,
|
|
25
|
+
accept: '*',
|
|
26
|
+
variant: 'FULL',
|
|
27
|
+
multiple: true,
|
|
28
|
+
slots: {
|
|
29
|
+
DropZone: DsFileUploaderDropZone,
|
|
30
|
+
UploadedItemSegment: DsFileUploaderUploadedFilesSegment,
|
|
31
|
+
SelectedItemSegment: DsFileUploaderSelectedFilesSegment,
|
|
32
|
+
DeleteButton: DsFileUploaderActionButton,
|
|
33
|
+
PreviewButton: DsFileUploaderActionButton,
|
|
34
|
+
DownloadButton: DsFileUploaderActionButton
|
|
35
|
+
},
|
|
36
|
+
slotProps: {
|
|
37
|
+
SelectedItemSegment: {
|
|
38
|
+
label: 'Selected Documents',
|
|
39
|
+
showDeleteIcon: true
|
|
40
|
+
},
|
|
41
|
+
UploadedItemSegment: {
|
|
42
|
+
label: 'Uploaded documents',
|
|
43
|
+
showDeleteIcon: true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
6
46
|
};
|
|
7
|
-
export const
|
|
8
|
-
|
|
47
|
+
export const DsFileUploaderDropzoneDefaultProps = {
|
|
48
|
+
variant: DsFileUploaderDefaultProps.variant,
|
|
49
|
+
title: 'Upload document',
|
|
50
|
+
description: 'Click to browse or drop here to upload'
|
|
9
51
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TContentType, TFile } from '../DsFileUploader.Types';
|
|
2
|
+
interface DsFileUploaderImagePreview {
|
|
3
|
+
file: TFile<TContentType>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* This component is responsible for rendering a preview of an uploaded image file.
|
|
7
|
+
* If the file content is valid and can be loaded, it shows the image preview.
|
|
8
|
+
* Otherwise, it displays a fallback icon.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DsFileUploaderImagePreview: ({ file }: DsFileUploaderImagePreview) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
package/dist/Components/DsFileUploader/DsFileUploaderPreview/DsFileUploaderImagePreview.Component.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { DsImage } from '../../DsImage';
|
|
4
|
+
import { DsRemixIcon } from '../../DsRemixIcon';
|
|
5
|
+
/**
|
|
6
|
+
* This component is responsible for rendering a preview of an uploaded image file.
|
|
7
|
+
* If the file content is valid and can be loaded, it shows the image preview.
|
|
8
|
+
* Otherwise, it displays a fallback icon.
|
|
9
|
+
*/
|
|
10
|
+
export const DsFileUploaderImagePreview = ({ file }) => {
|
|
11
|
+
const [src, setSrc] = useState(null);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let isMounted = true;
|
|
14
|
+
const loadImage = async () => {
|
|
15
|
+
try {
|
|
16
|
+
let content = file.content;
|
|
17
|
+
if (typeof content === 'string') {
|
|
18
|
+
const img = new Image();
|
|
19
|
+
if (!content.startsWith('data:')) {
|
|
20
|
+
content = `data:${file.type};base64,${content}`;
|
|
21
|
+
}
|
|
22
|
+
img.src = content;
|
|
23
|
+
img.onload = () => isMounted && setSrc(img.src);
|
|
24
|
+
img.onerror = () => isMounted && setSrc(null);
|
|
25
|
+
}
|
|
26
|
+
else if (content instanceof File) {
|
|
27
|
+
const url = URL.createObjectURL(content);
|
|
28
|
+
const img = new Image();
|
|
29
|
+
img.src = url;
|
|
30
|
+
img.onload = () => isMounted && setSrc(url);
|
|
31
|
+
img.onerror = () => {
|
|
32
|
+
if (isMounted)
|
|
33
|
+
setSrc(null);
|
|
34
|
+
URL.revokeObjectURL(url);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
if (isMounted)
|
|
40
|
+
setSrc(null);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
loadImage();
|
|
44
|
+
return () => {
|
|
45
|
+
isMounted = false;
|
|
46
|
+
if (src && src.startsWith('blob:')) {
|
|
47
|
+
URL.revokeObjectURL(src);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}, [file]);
|
|
51
|
+
if (src) {
|
|
52
|
+
return (_jsx(DsImage, { srcSet: [{ src: src, alt: file.name }], width: '32px', height: '32px', WrapperProps: {
|
|
53
|
+
sx: {
|
|
54
|
+
width: '32px',
|
|
55
|
+
height: '32px'
|
|
56
|
+
}
|
|
57
|
+
}, style: {
|
|
58
|
+
objectFit: 'cover',
|
|
59
|
+
borderRadius: 'var(--ds-radius-quickFreeze)'
|
|
60
|
+
} }));
|
|
61
|
+
}
|
|
62
|
+
return (_jsx(DsRemixIcon, { sx: {
|
|
63
|
+
p: 'var(--ds-spacing-quickFreeze)',
|
|
64
|
+
borderRadius: 'var(--ds-radius-quickFreeze)',
|
|
65
|
+
backgroundColor: 'var(--ds-colour-neutral2)',
|
|
66
|
+
color: 'var(--ds-colour-actionTertiary)'
|
|
67
|
+
}, className: 'ri-image-2-line' }));
|
|
68
|
+
};
|
package/dist/Components/DsFileUploader/DsFileUploaderPreview/DsFileUploaderPreview.Component.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TContentType, TFile } from '../DsFileUploader.Types';
|
|
2
|
+
interface IDsFileUploaderPreviewProps {
|
|
3
|
+
file: TFile<TContentType>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* DsFileUploaderPreview is a functional component that renders an appropriate preview
|
|
7
|
+
* based on the MIME type of the uploaded file.
|
|
8
|
+
*
|
|
9
|
+
* - For image files (e.g., image/jpeg, image/png), it shows an actual image preview.
|
|
10
|
+
* - For video files, it shows a video icon.
|
|
11
|
+
* - For all other file types, it shows a generic file icon.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DsFileUploaderPreview: ({ file }: IDsFileUploaderPreviewProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
package/dist/Components/DsFileUploader/DsFileUploaderPreview/DsFileUploaderPreview.Component.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DsRemixIcon } from '../../DsRemixIcon';
|
|
3
|
+
import { DsFileUploaderImagePreview } from './DsFileUploaderImagePreview.Component';
|
|
4
|
+
/**
|
|
5
|
+
* DsFileUploaderPreview is a functional component that renders an appropriate preview
|
|
6
|
+
* based on the MIME type of the uploaded file.
|
|
7
|
+
*
|
|
8
|
+
* - For image files (e.g., image/jpeg, image/png), it shows an actual image preview.
|
|
9
|
+
* - For video files, it shows a video icon.
|
|
10
|
+
* - For all other file types, it shows a generic file icon.
|
|
11
|
+
*/
|
|
12
|
+
export const DsFileUploaderPreview = ({ file }) => {
|
|
13
|
+
const { type: mimeType } = file;
|
|
14
|
+
const IMAGE_REGEX = new RegExp('^image/.*');
|
|
15
|
+
const VIDEO_REGEX = new RegExp('^video/.*');
|
|
16
|
+
if (IMAGE_REGEX.test(mimeType)) {
|
|
17
|
+
return _jsx(DsFileUploaderImagePreview, { file: file });
|
|
18
|
+
}
|
|
19
|
+
const iconName = VIDEO_REGEX.test(mimeType)
|
|
20
|
+
? 'ri-video-line'
|
|
21
|
+
: 'ri-file-list-2-line';
|
|
22
|
+
return (_jsx(DsRemixIcon, { sx: {
|
|
23
|
+
p: 'var(--ds-spacing-quickFreeze)',
|
|
24
|
+
borderRadius: 'var(--ds-radius-quickFreeze)',
|
|
25
|
+
backgroundColor: 'var(--ds-colour-neutral2)',
|
|
26
|
+
color: 'var(--ds-colour-actionTertiary)'
|
|
27
|
+
}, className: iconName }));
|
|
28
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type IDsFileUploaderItemSegmentProps } from './DsFileUploader.Types';
|
|
2
|
+
declare const FileUploaderFiles: (inProps: IDsFileUploaderItemSegmentProps) => import("react/jsx-runtime").JSX.Element | import("react/jsx-runtime").JSX.Element[] | null;
|
|
3
|
+
export default FileUploaderFiles;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DsBox } from '../DsBox';
|
|
3
|
+
import { DsStack } from '../DsStack';
|
|
4
|
+
import { DsTypography } from '../DsTypography';
|
|
5
|
+
import { DsFileUploaderDefaultProps } from './DsFileUploader.Types';
|
|
6
|
+
import { DsFileUploaderPreview } from './DsFileUploaderPreview/DsFileUploaderPreview.Component';
|
|
7
|
+
import { humanizeFileSize } from './helpers';
|
|
8
|
+
const FileUploaderFiles = (inProps) => {
|
|
9
|
+
const mergedSlotProps = {
|
|
10
|
+
...DsFileUploaderDefaultProps.slots,
|
|
11
|
+
...inProps.slots
|
|
12
|
+
};
|
|
13
|
+
const props = { ...inProps, slots: mergedSlotProps };
|
|
14
|
+
const { files, onPreview, onDelete, onDownload, showDeleteIcon, showDownloadIcon, showPreviewIcon, slots = {}, slotProps = {} } = props;
|
|
15
|
+
const { DownloadButton, PreviewButton, DeleteButton } = slots;
|
|
16
|
+
const { DownloadButton: DownloadButtonProps, PreviewButton: PreviewButtonProps, DeleteButton: DeleteButtonProps } = slotProps;
|
|
17
|
+
if (!files) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const renderFile = (file, index) => {
|
|
21
|
+
return (_jsxs(DsStack, { direction: 'row', spacing: 'var(--ds-spacing-bitterCold)', sx: {
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
p: 'var(--ds-spacing-bitterCold)',
|
|
24
|
+
borderRadius: 'var(--ds-radius-glacial)',
|
|
25
|
+
borderWidth: '1px',
|
|
26
|
+
borderStyle: 'solid',
|
|
27
|
+
borderColor: 'var(--ds-colour-strokeDefault)',
|
|
28
|
+
backgroundColor: 'var(--ds-colour-surfacePrimary)',
|
|
29
|
+
cursor: 'pointer',
|
|
30
|
+
'&:hover:not(:has(.delete-icon:hover, .action-icon:hover))': {
|
|
31
|
+
borderColor: 'var(--ds-colour-strokeSecondarySelected)',
|
|
32
|
+
backgroundColor: 'var(--ds-colour-stateSelectedSecondaryHover)'
|
|
33
|
+
}
|
|
34
|
+
}, children: [_jsx(DsFileUploaderPreview, { file: file }), _jsxs(DsBox, { sx: {
|
|
35
|
+
display: 'flex',
|
|
36
|
+
flexGrow: 1,
|
|
37
|
+
minWidth: 0,
|
|
38
|
+
flexDirection: 'column'
|
|
39
|
+
}, children: [_jsx(DsTypography, { component: 'div', variant: 'bodyBoldSmall', noWrap: true, children: file.name }), _jsx(DsTypography, { component: 'div', variant: 'bodyRegularSmall', noWrap: true, sx: {
|
|
40
|
+
color: 'var(--ds-colour-typoTertiary)'
|
|
41
|
+
}, children: humanizeFileSize(file.size) })] }), showDownloadIcon && DownloadButton && (_jsx(DownloadButton, { IconProps: { className: 'ri-download-line' }, onClick: () => onDownload && onDownload(file.name, file), ...DownloadButtonProps })), showPreviewIcon && PreviewButton && (_jsx(PreviewButton, { IconProps: { className: 'ri-eye-line' }, onClick: () => onPreview && onPreview(file.name, file), ...PreviewButtonProps })), showDeleteIcon && DeleteButton && (_jsx(DeleteButton, { IconProps: { className: 'ri-delete-bin-line' }, onClick: () => onDelete && onDelete(file.name, file), ...DeleteButtonProps }))] }, `${file?.name}-${index}`));
|
|
42
|
+
};
|
|
43
|
+
if (!Array.isArray(files)) {
|
|
44
|
+
return renderFile(files, 0);
|
|
45
|
+
}
|
|
46
|
+
return files?.map(renderFile);
|
|
47
|
+
};
|
|
48
|
+
export default FileUploaderFiles;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IDsFileUploaderActionButtonProps } from '../DsFileUploader.Types';
|
|
3
|
+
/**
|
|
4
|
+
* DsFileUploaderActionButton
|
|
5
|
+
*
|
|
6
|
+
* A reusable icon button component used within the FileUploader for actions like
|
|
7
|
+
* delete, download, preview, etc. It wraps a `DsRemixIcon` inside a `DsIconButton`
|
|
8
|
+
* and accepts customization through props.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DsFileUploaderActionButton: React.FC<IDsFileUploaderActionButtonProps>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DsIconButton } from '../../DsIconButton';
|
|
3
|
+
import { DsRemixIcon } from '../../DsRemixIcon';
|
|
4
|
+
/**
|
|
5
|
+
* DsFileUploaderActionButton
|
|
6
|
+
*
|
|
7
|
+
* A reusable icon button component used within the FileUploader for actions like
|
|
8
|
+
* delete, download, preview, etc. It wraps a `DsRemixIcon` inside a `DsIconButton`
|
|
9
|
+
* and accepts customization through props.
|
|
10
|
+
*/
|
|
11
|
+
export const DsFileUploaderActionButton = ({ onClick, IconProps, ...iconButtonProps }) => {
|
|
12
|
+
return (_jsx(DsIconButton, { onClick: onClick, sx: {
|
|
13
|
+
p: 'var(--ds-spacing-glacial)',
|
|
14
|
+
borderRadius: 'var(--ds-radius-quickFreeze)',
|
|
15
|
+
backgroundColor: 'var(--ds-colour-surfaceSecondary)',
|
|
16
|
+
...iconButtonProps.sx
|
|
17
|
+
}, ...iconButtonProps, children: _jsx(DsRemixIcon, { fontSize: 'bitterCold', ...IconProps }) }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IDsFileUploaderDropZoneProps } from '../DsFileUploader.Types';
|
|
2
|
+
/**
|
|
3
|
+
* DsFileUploaderDropZone
|
|
4
|
+
*
|
|
5
|
+
* This component renders a drop zone area where users can drag & drop files
|
|
6
|
+
* or click to upload using a hidden input field. It supports two layout variants:
|
|
7
|
+
* - 'DEFAULT': Large button with drag and drop space area
|
|
8
|
+
* - 'COMPRESSED': Smaller area and button size to save space
|
|
9
|
+
*/
|
|
10
|
+
export declare const DsFileUploaderDropZone: (inProps: IDsFileUploaderDropZoneProps) => (false | import("react/jsx-runtime").JSX.Element | null)[];
|