@am92/react-design-system 2.9.10 → 2.10.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/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,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const DsFileUploader: FC<DsFileUploaderProps>;
|
|
1
|
+
import type { IDsFileUploaderProps, TContentType, TMultiple } from './DsFileUploader.Types';
|
|
2
|
+
export declare const DsFileUploader: <Multiple extends TMultiple, ContentType extends TContentType>(inProps: IDsFileUploaderProps<Multiple, ContentType>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,182 +1,133 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
2
|
-
import {
|
|
3
|
-
import { DsBox } from '../DsBox';
|
|
4
|
-
import { DsButton } from '../DsButton';
|
|
5
|
-
import { DsIconButton } from '../DsIconButton';
|
|
6
|
-
import { DsInput } from '../DsInput';
|
|
7
|
-
import { DsRemixIcon } from '../DsRemixIcon';
|
|
8
|
-
import { DsStack } from '../DsStack';
|
|
9
|
-
import { DsTypography } from '../DsTypography';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
10
3
|
import { DsFileUploaderDefaultProps } from './DsFileUploader.Types';
|
|
4
|
+
import FileUploaderFiles from './FileUploaderFiles';
|
|
5
|
+
import { getDefaultValue, getValidProcessedFile, mergeProps } from './helpers';
|
|
6
|
+
import { DsFileUploaderDropZone } from './Slots/DsFileUploaderDropZone';
|
|
7
|
+
import { DsStack } from '../DsStack';
|
|
8
|
+
import { DsInputLabel } from '../DsInputLabel';
|
|
11
9
|
export const DsFileUploader = (inProps) => {
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
|
|
23
|
-
};
|
|
24
|
-
const getFileIconClass = (mimeType) => {
|
|
25
|
-
if (mimeType.includes('image/')) {
|
|
26
|
-
return 'ri-image-2-line';
|
|
10
|
+
// Merge user props with default props, handling nested slots and slotProps gracefully
|
|
11
|
+
const props = mergeProps(inProps, DsFileUploaderDefaultProps);
|
|
12
|
+
const defaultValue = getDefaultValue(props);
|
|
13
|
+
const [files, setFiles] = useState(defaultValue);
|
|
14
|
+
const { InputLabelProps, name, value, uploadedValue, accept = '*', minSize, maxSize, onChange, onError, onDelete, onPreview, onDownload, multiple, slotProps = {}, variant, contentType, canDeleteFile, slots = {} } = props;
|
|
15
|
+
// Effective file type accept string — pulled from DropZone slotProps or `accept`
|
|
16
|
+
const allowedFiles = (slotProps?.DropZone && slotProps?.DropZone.InputProps?.accept) || accept;
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (value !== undefined) {
|
|
19
|
+
setFiles(value);
|
|
27
20
|
}
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
}, [value]);
|
|
22
|
+
// Handles selected or dropped files after validation
|
|
23
|
+
const handleFiles = (processedFiles) => {
|
|
24
|
+
const { valid, invalid } = processedFiles;
|
|
25
|
+
// If not controlled, update internal state
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
setFiles(valid);
|
|
30
28
|
}
|
|
31
|
-
return 'ri-file-list-2-line';
|
|
32
|
-
};
|
|
33
|
-
const handleOnClick = (event) => {
|
|
34
|
-
inputRef?.current?.click();
|
|
35
|
-
};
|
|
36
|
-
const handleRemoveFile = (index) => () => {
|
|
37
|
-
const { onChange, name } = props;
|
|
38
|
-
const tempFiles = [...files];
|
|
39
|
-
tempFiles.splice(index, 1);
|
|
40
|
-
setFiles(tempFiles);
|
|
41
29
|
if (onChange && typeof onChange === 'function') {
|
|
42
|
-
onChange(name,
|
|
30
|
+
onChange(name, valid);
|
|
31
|
+
}
|
|
32
|
+
if (invalid !== null) {
|
|
33
|
+
if (invalid && onError && typeof onError === 'function') {
|
|
34
|
+
onError(name, invalid);
|
|
35
|
+
}
|
|
43
36
|
}
|
|
44
37
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const stateFiles = files;
|
|
38
|
+
// Triggered when a user selects files via the input element
|
|
39
|
+
const handleFileSelect = async (event) => {
|
|
48
40
|
const { target } = event;
|
|
49
41
|
const { files: selectedFiles } = target;
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (onChange && typeof onChange === 'function') {
|
|
54
|
-
onChange(name, newFiles);
|
|
42
|
+
if (!multiple && uploadedValue) {
|
|
43
|
+
if (onDelete && typeof onDelete === 'function') {
|
|
44
|
+
onDelete(name, uploadedValue);
|
|
55
45
|
}
|
|
56
46
|
}
|
|
47
|
+
if (selectedFiles) {
|
|
48
|
+
const processedFiles = await getValidProcessedFile(selectedFiles, files ?? null, accept, minSize, maxSize, contentType);
|
|
49
|
+
handleFiles(processedFiles);
|
|
50
|
+
}
|
|
57
51
|
};
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
// Triggered when a user drops files into the drop zone
|
|
53
|
+
const handleDropFile = async (event) => {
|
|
60
54
|
event.preventDefault();
|
|
61
|
-
const {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const items = event.dataTransfer.items
|
|
68
|
-
? [...event.dataTransfer.items]
|
|
69
|
-
: [...event.dataTransfer.files];
|
|
70
|
-
items.forEach(item => {
|
|
71
|
-
let file;
|
|
72
|
-
if (!multiple && files.length) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (item instanceof DataTransferItem) {
|
|
76
|
-
if (item.kind === 'file') {
|
|
77
|
-
file = item.getAsFile();
|
|
55
|
+
const { dataTransfer } = event;
|
|
56
|
+
if (dataTransfer) {
|
|
57
|
+
const { files: selectedFiles } = dataTransfer;
|
|
58
|
+
if (!multiple && uploadedValue) {
|
|
59
|
+
if (onDelete && typeof onDelete === 'function') {
|
|
60
|
+
onDelete(name, uploadedValue);
|
|
78
61
|
}
|
|
79
62
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!file) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const { type } = file;
|
|
87
|
-
const astrerikType = `${type.split('/')[0]}/*`;
|
|
88
|
-
if (accept.includes(type) || accept.includes(astrerikType)) {
|
|
89
|
-
files.push(file);
|
|
63
|
+
if (files) {
|
|
64
|
+
const processedFiles = await getValidProcessedFile(selectedFiles, files ?? null, accept, minSize, maxSize);
|
|
65
|
+
handleFiles(processedFiles);
|
|
90
66
|
}
|
|
91
|
-
});
|
|
92
|
-
const stateFiles = files;
|
|
93
|
-
const newFiles = multiple
|
|
94
|
-
? [...stateFiles, ...files]
|
|
95
|
-
: (files[0] && [files[0]]) || (stateFiles[0] && [stateFiles[0]]) || [];
|
|
96
|
-
setFiles(newFiles);
|
|
97
|
-
if (onChange && typeof onChange === 'function') {
|
|
98
|
-
onChange(name, newFiles);
|
|
99
67
|
}
|
|
100
68
|
};
|
|
101
|
-
|
|
102
|
-
|
|
69
|
+
// Prevent default behavior to allow dropping
|
|
70
|
+
const handleDragOverHandler = event => {
|
|
103
71
|
event.preventDefault();
|
|
104
72
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
73
|
+
// Triggered when a user removes a file
|
|
74
|
+
const handleRemoveFile = async (name, file) => {
|
|
75
|
+
// Async handler for delete operations
|
|
76
|
+
if (canDeleteFile && typeof canDeleteFile === 'function') {
|
|
77
|
+
const canDelete = await canDeleteFile(name, file);
|
|
78
|
+
if (!canDelete)
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (onDelete && typeof onDelete === 'function') {
|
|
82
|
+
onDelete(name, file);
|
|
83
|
+
}
|
|
84
|
+
// Update internal state after deletion
|
|
85
|
+
if (Array.isArray(files)) {
|
|
86
|
+
const newFiles = files.filter(f => f !== file);
|
|
87
|
+
const valid = newFiles;
|
|
88
|
+
const invalid = [];
|
|
89
|
+
handleFiles({
|
|
90
|
+
valid: valid,
|
|
91
|
+
invalid: invalid
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
handleFiles({
|
|
96
|
+
valid: null,
|
|
97
|
+
invalid: null
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// Preview handler
|
|
102
|
+
const handlePreviewFileAction = (name, file) => {
|
|
103
|
+
if (onPreview && typeof onPreview === 'function') {
|
|
104
|
+
onPreview(name, file);
|
|
108
105
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
borderRadius: 'var(--ds-radius-glacial)',
|
|
115
|
-
borderWidth: '1px',
|
|
116
|
-
borderStyle: 'solid',
|
|
117
|
-
borderColor: 'var(--ds-colour-strokeDefault)',
|
|
118
|
-
backgroundColor: 'var(--ds-colour-surfacePrimary)',
|
|
119
|
-
cursor: 'pointer',
|
|
120
|
-
'&:hover': {
|
|
121
|
-
borderColor: 'var(--ds-colour-strokeSecondarySelected)',
|
|
122
|
-
backgroundColor: 'var(--ds-colour-stateSelectedSecondaryHover)'
|
|
123
|
-
}
|
|
124
|
-
}, children: [_jsx(DsRemixIcon, { sx: {
|
|
125
|
-
p: 'var(--ds-spacing-quickFreeze)',
|
|
126
|
-
borderRadius: 'var(--ds-radius-quickFreeze)',
|
|
127
|
-
backgroundColor: 'var(--ds-colour-neutral2)',
|
|
128
|
-
color: 'var(--ds-colour-actionTertiary)'
|
|
129
|
-
}, className: getFileIconClass(file.type) }), _jsxs(DsBox, { sx: {
|
|
130
|
-
display: 'flex',
|
|
131
|
-
flexGrow: 1,
|
|
132
|
-
minWidth: 0,
|
|
133
|
-
flexDirection: 'column'
|
|
134
|
-
}, children: [_jsx(DsTypography, { component: "div", variant: "subheadingSemiboldDefault", noWrap: true, children: file.name }), _jsx(DsTypography, { component: "div", variant: "bodyRegularSmall", noWrap: true, sx: {
|
|
135
|
-
color: 'var(--ds-colour-typoTertiary)'
|
|
136
|
-
}, children: humaniseSize(file.size) })] }), _jsx(DsIconButton, { onClick: handleRemoveFile(index), children: _jsx(DsRemixIcon, { className: "ri-close-line" }) })] }, `${file.name}-${index}`));
|
|
106
|
+
};
|
|
107
|
+
// Download handler
|
|
108
|
+
const handleDownloadFileAction = (name, file) => {
|
|
109
|
+
if (onDownload && typeof onDownload === 'function') {
|
|
110
|
+
onDownload(name, file);
|
|
137
111
|
}
|
|
138
|
-
return (_jsx(DsStack, { sx: {
|
|
139
|
-
mt: 'var(--ds-spacing-warm)',
|
|
140
|
-
width: '100%'
|
|
141
|
-
}, spacing: "var(--ds-spacing-glacial)", direction: "column", children: Files }));
|
|
142
112
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
top: 0,
|
|
164
|
-
left: 0,
|
|
165
|
-
height: '100%',
|
|
166
|
-
width: '100%',
|
|
167
|
-
opacity: 0,
|
|
168
|
-
cursor: 'pointer',
|
|
169
|
-
margin: 'var(--ds-spacing-zero) !important'
|
|
170
|
-
}, onChange: handleChange, onDrop: handleDrop, onDragOver: handleDragOverHandler, disableUnderline: true, inputProps: {
|
|
171
|
-
title: titleButtonText,
|
|
172
|
-
ref: inputRef,
|
|
173
|
-
value: '',
|
|
174
|
-
...InputProps,
|
|
175
|
-
style: {
|
|
176
|
-
height: '100%',
|
|
177
|
-
width: '100%',
|
|
178
|
-
cursor: 'pointer',
|
|
179
|
-
...InputProps?.style
|
|
180
|
-
}
|
|
181
|
-
} })] }), renderFiles()] }));
|
|
113
|
+
// Visibility conditions for selected and uploaded sections
|
|
114
|
+
const isSelectedSegmentVisible = multiple
|
|
115
|
+
? Array.isArray(files) && files.length > 0
|
|
116
|
+
: files;
|
|
117
|
+
const isUploadedSegmentVisible = multiple
|
|
118
|
+
? Array.isArray(uploadedValue) && uploadedValue.length > 0
|
|
119
|
+
: uploadedValue;
|
|
120
|
+
const { SelectedItemSegment, UploadedItemSegment } = slots;
|
|
121
|
+
return (_jsxs(DsStack, { direction: "column", sx: {
|
|
122
|
+
gap: 'var(--ds-spacing-bitterCold)',
|
|
123
|
+
width: '100%',
|
|
124
|
+
p: 'var(--ds-spacing-bitterCold)'
|
|
125
|
+
}, children: [_jsx(DsInputLabel, { sx: { mb: 'var(--ds-spacing-zero)', ...InputLabelProps?.sx }, ...InputLabelProps }), _jsx(DsFileUploaderDropZone, { variant: variant, ...slotProps?.DropZone, InputProps: {
|
|
126
|
+
accept: allowedFiles || accept,
|
|
127
|
+
multiple: multiple,
|
|
128
|
+
onChange: handleFileSelect,
|
|
129
|
+
onDrop: handleDropFile,
|
|
130
|
+
onDragOver: handleDragOverHandler,
|
|
131
|
+
...slotProps?.DropZone?.InputProps
|
|
132
|
+
} }), isSelectedSegmentVisible && SelectedItemSegment && (_jsx(SelectedItemSegment, { onPreview: handlePreviewFileAction, onDownload: handleDownloadFileAction, onDelete: handleRemoveFile, ...slotProps?.SelectedItemSegment, children: _jsx(FileUploaderFiles, { slots: slots, slotProps: slotProps, files: files || undefined }) })), isUploadedSegmentVisible && UploadedItemSegment && (_jsx(UploadedItemSegment, { onPreview: handlePreviewFileAction, onDownload: handleDownloadFileAction, onDelete: handleRemoveFile, ...slotProps?.UploadedItemSegment, children: _jsx(FileUploaderFiles, { slots: slots, slotProps: slotProps, files: uploadedValue || undefined }) }))] }));
|
|
182
133
|
};
|
|
@@ -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;
|