-
Notifications
You must be signed in to change notification settings - Fork 14
/
types.ts
134 lines (129 loc) · 4.33 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
type Space = "xxsmall" | "xsmall" | "small" | "medium" | "large" | "xlarge" | "xxlarge";
type Margin = {
top?: Space;
bottom?: Space;
left?: Space;
right?: Space;
};
type FileData = {
/**
* Selected file.
*/
file: File;
/**
* Error of the file. If it is defined, it will be shown and the file item will be mark as invalid.
*/
error?: string;
/**
* Preview of the file.
*/
preview?: string;
};
type CommonProps = {
/**
* @deprecated Name attribute.
*/
name?: string;
/**
* Text to be placed above the component.
*/
label?: string;
/**
* Text to be placed inside the button.
*/
buttonLabel?: string;
/**
* Helper text to be placed above the component.
*/
helperText?: string;
/**
* The file types that the component accepts. Its value must be one of all the possible values of the HTML file input's accept attribute.
*/
accept?: string;
/**
* An array of files representing the selected files.
*/
value: FileData[];
/**
* The minimum file size (in bytes) allowed. If the size of the file does not comply the minSize, the file will have an error.
*/
minSize?: number;
/**
* The maximum file size (in bytes) allowed. If the size of the file does not comply the maxSize, the file will have an error.
*/
maxSize?: number;
/**
* If true, if the file is an image, a preview of it will be shown. If not, an icon refering to the file type will be shown.
*/
showPreview?: boolean;
/**
* If true, the component allows multiple file items and will show all of them. If false, only one file will be shown, and if there is already one
* file selected and a new one is chosen, it will be replaced by the new selected one.
*/
multiple?: boolean;
/**
* If true, the component will be disabled.
*/
disabled?: boolean;
/**
* This function will be called when the user selects or drops a file. The list of files will be sent as a parameter.
* In this function, the files can be updated or returned as they come. These files must be passed to the value in order to be shown.
*/
callbackFile: (files: FileData[]) => void;
/**
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
*/
margin?: Space | Margin;
/**
* Value of the tabindex attribute.
*/
tabIndex?: number;
};
type DropModeProps = CommonProps & {
/**
* Uses one of the available file input modes:
* 'file': Files are selected by clicking the button and selecting it through the file explorer.
* 'filedrop': Files can be selected by clicking the button and selecting it through the file explorer or by dropping them inside the drag and drop area.
* 'dropzone': Files can be selected by clicking the button and selecting it through the file explorer or by dropping them inside the drag and drop area.
* The drag and drop area of this mode is bigger than the one of the filedrop mode.
*/
mode: "filedrop" | "dropzone";
/**
* Text to be placed inside the drag and drop zone alongside the button.
*/
dropAreaLabel?: string;
};
type FileModeProps = CommonProps & {
/**
* Uses one of the available file input modes:
* 'file': Files are selected by clicking the button and selecting it through the file explorer.
* 'filedrop': Files can be selected by clicking the button and selecting it through the file explorer or by dropping them inside the drag and drop area.
* 'dropzone': Files can be selected by clicking the button and selecting it through the file explorer or by dropping them inside the drag and drop area.
* The drag and drop area of this mode is bigger than the one of the filedrop mode.
*/
mode?: "file";
/**
* Text to be placed inside the drag and drop zone alongside the button.
*/
dropAreaLabel?: never;
};
/**
* Reference to the component.
*/
export type RefType = HTMLDivElement;
type Props = DropModeProps | FileModeProps;
/**
* Single file item preview.
*/
export type FileItemProps = {
fileName?: string;
error?: string;
showPreview: boolean;
singleFileMode: boolean;
preview: string;
type: string;
onDelete: (fileName: string) => void,
tabIndex: number,
};
export default Props;