@carbon/react 1.32.0 → 1.33.0-rc.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/README.md +22 -7
- package/es/components/ComboBox/ComboBox.js +43 -10
- package/es/components/ContentSwitcher/ContentSwitcher.js +5 -5
- package/es/components/DataTable/DataTable.js +110 -130
- package/es/components/DataTable/Table.js +1 -1
- package/es/components/DatePicker/DatePicker.d.ts +14 -13
- package/es/components/DatePicker/DatePicker.js +3 -0
- package/es/components/DatePickerInput/DatePickerInput.d.ts +2 -2
- package/es/components/Dropdown/Dropdown.js +31 -6
- package/es/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
- package/es/components/FileUploader/FileUploader.d.ts +175 -0
- package/es/components/FileUploader/FileUploader.js +3 -3
- package/es/components/FileUploader/FileUploaderButton.d.ts +140 -0
- package/es/components/FileUploader/FileUploaderButton.js +11 -7
- package/es/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
- package/es/components/FileUploader/FileUploaderDropContainer.js +3 -3
- package/es/components/FileUploader/FileUploaderItem.d.ts +110 -0
- package/es/components/FileUploader/Filename.d.ts +71 -0
- package/es/components/FileUploader/Filename.js +6 -4
- package/es/components/InlineCheckbox/InlineCheckbox.js +3 -1
- package/es/components/Loading/Loading.d.ts +65 -0
- package/es/components/Notification/Notification.d.ts +4 -4
- package/es/components/Notification/Notification.js +3 -3
- package/es/components/OverflowMenu/OverflowMenu.js +36 -41
- package/es/components/Slider/Slider.js +59 -68
- package/es/components/Toggle/Toggle.d.ts +129 -0
- package/es/components/Toggle/Toggle.js +2 -2
- package/es/components/Toggle/index.d.ts +11 -0
- package/es/components/UIShell/HeaderMenu.js +29 -36
- package/es/components/UIShell/HeaderName.d.ts +39 -0
- package/es/components/UIShell/HeaderName.js +2 -7
- package/es/components/UIShell/HeaderPanel.js +1 -1
- package/es/components/UIShell/Link.js +2 -1
- package/es/index.js +1 -1
- package/es/internal/FloatingMenu.js +47 -51
- package/es/internal/useControllableState.js +1 -1
- package/es/internal/useId.js +10 -1
- package/lib/components/ComboBox/ComboBox.js +43 -10
- package/lib/components/ContentSwitcher/ContentSwitcher.js +5 -5
- package/lib/components/DataTable/DataTable.js +110 -130
- package/lib/components/DataTable/Table.js +1 -1
- package/lib/components/DatePicker/DatePicker.d.ts +14 -13
- package/lib/components/DatePicker/DatePicker.js +3 -0
- package/lib/components/DatePickerInput/DatePickerInput.d.ts +2 -2
- package/lib/components/Dropdown/Dropdown.js +30 -5
- package/lib/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
- package/lib/components/FileUploader/FileUploader.d.ts +175 -0
- package/lib/components/FileUploader/FileUploader.js +3 -3
- package/lib/components/FileUploader/FileUploaderButton.d.ts +140 -0
- package/lib/components/FileUploader/FileUploaderButton.js +11 -7
- package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
- package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -3
- package/lib/components/FileUploader/FileUploaderItem.d.ts +110 -0
- package/lib/components/FileUploader/Filename.d.ts +71 -0
- package/lib/components/FileUploader/Filename.js +6 -4
- package/lib/components/InlineCheckbox/InlineCheckbox.js +3 -1
- package/lib/components/Loading/Loading.d.ts +65 -0
- package/lib/components/Notification/Notification.d.ts +4 -4
- package/lib/components/Notification/Notification.js +3 -3
- package/lib/components/OverflowMenu/OverflowMenu.js +36 -41
- package/lib/components/Slider/Slider.js +59 -68
- package/lib/components/Toggle/Toggle.d.ts +129 -0
- package/lib/components/Toggle/Toggle.js +2 -2
- package/lib/components/Toggle/index.d.ts +11 -0
- package/lib/components/UIShell/HeaderMenu.js +29 -36
- package/lib/components/UIShell/HeaderName.d.ts +39 -0
- package/lib/components/UIShell/HeaderName.js +2 -7
- package/lib/components/UIShell/HeaderPanel.js +1 -1
- package/lib/components/UIShell/Link.js +2 -1
- package/lib/index.js +2 -2
- package/lib/internal/FloatingMenu.js +47 -51
- package/lib/internal/useControllableState.js +1 -1
- package/lib/internal/useId.js +9 -0
- package/package.json +22 -19
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { ReactAttr } from '../../types/common';
|
|
10
|
+
export interface FileUploaderProps extends ReactAttr<HTMLSpanElement> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify the types of files that this input should be able to receive
|
|
13
|
+
*/
|
|
14
|
+
accept?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Specify the type of the `<FileUploaderButton>`
|
|
17
|
+
*/
|
|
18
|
+
buttonKind?: 'primary' | 'secondary' | 'danger' | 'ghost' | 'danger--primary' | 'danger--ghost' | 'danger--tertiary' | 'tertiary';
|
|
19
|
+
/**
|
|
20
|
+
* Provide the label text to be read by screen readers when interacting with
|
|
21
|
+
* the `<FileUploaderButton>`
|
|
22
|
+
*/
|
|
23
|
+
buttonLabel?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Provide a custom className to be applied to the container node
|
|
26
|
+
*/
|
|
27
|
+
className?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Specify whether file input is disabled
|
|
30
|
+
*/
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Specify the status of the File Upload
|
|
34
|
+
*/
|
|
35
|
+
filenameStatus: 'edit' | 'complete' | 'uploading';
|
|
36
|
+
/**
|
|
37
|
+
* Provide a description for the complete/close icon that can be read by screen readers
|
|
38
|
+
*/
|
|
39
|
+
iconDescription: string;
|
|
40
|
+
/**
|
|
41
|
+
* Specify the description text of this `<FileUploader>`
|
|
42
|
+
*/
|
|
43
|
+
labelDescription?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Specify the title text of this `<FileUploader>`
|
|
46
|
+
*/
|
|
47
|
+
labelTitle?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Specify if the component should accept multiple files to upload
|
|
50
|
+
*/
|
|
51
|
+
multiple?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Provide a name for the underlying `<input>` node
|
|
54
|
+
*/
|
|
55
|
+
name?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Provide an optional `onChange` hook that is called each time the input is
|
|
58
|
+
* changed
|
|
59
|
+
*/
|
|
60
|
+
onChange?: (event: any) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Provide an optional `onClick` hook that is called each time the
|
|
63
|
+
* FileUploader is clicked
|
|
64
|
+
*/
|
|
65
|
+
onClick?: (event: any) => void;
|
|
66
|
+
/**
|
|
67
|
+
* Provide an optional `onDelete` hook that is called when an uploaded item
|
|
68
|
+
* is removed
|
|
69
|
+
*/
|
|
70
|
+
onDelete?: (event: any) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Specify the size of the FileUploaderButton, from a list of available
|
|
73
|
+
* sizes.
|
|
74
|
+
*/
|
|
75
|
+
size?: 'sm' | 'small' | 'md' | 'field' | 'lg';
|
|
76
|
+
}
|
|
77
|
+
export default class FileUploader extends React.Component<FileUploaderProps, {
|
|
78
|
+
filenames: string[];
|
|
79
|
+
}> {
|
|
80
|
+
static propTypes: {
|
|
81
|
+
/**
|
|
82
|
+
* Specify the types of files that this input should be able to receive
|
|
83
|
+
*/
|
|
84
|
+
accept: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Specify the type of the `<FileUploaderButton>`
|
|
87
|
+
*/
|
|
88
|
+
buttonKind: PropTypes.Requireable<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Provide the label text to be read by screen readers when interacting with
|
|
91
|
+
* the `<FileUploaderButton>`
|
|
92
|
+
*/
|
|
93
|
+
buttonLabel: PropTypes.Requireable<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Provide a custom className to be applied to the container node
|
|
96
|
+
*/
|
|
97
|
+
className: PropTypes.Requireable<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Specify whether file input is disabled
|
|
100
|
+
*/
|
|
101
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Specify the status of the File Upload
|
|
104
|
+
*/
|
|
105
|
+
filenameStatus: PropTypes.Validator<string>;
|
|
106
|
+
/**
|
|
107
|
+
* Provide a description for the complete/close icon that can be read by screen readers
|
|
108
|
+
*/
|
|
109
|
+
iconDescription: PropTypes.Validator<string>;
|
|
110
|
+
/**
|
|
111
|
+
* Specify the description text of this `<FileUploader>`
|
|
112
|
+
*/
|
|
113
|
+
labelDescription: PropTypes.Requireable<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Specify the title text of this `<FileUploader>`
|
|
116
|
+
*/
|
|
117
|
+
labelTitle: PropTypes.Requireable<string>;
|
|
118
|
+
/**
|
|
119
|
+
* Specify if the component should accept multiple files to upload
|
|
120
|
+
*/
|
|
121
|
+
multiple: PropTypes.Requireable<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* Provide a name for the underlying `<input>` node
|
|
124
|
+
*/
|
|
125
|
+
name: PropTypes.Requireable<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Provide an optional `onChange` hook that is called each time the input is
|
|
128
|
+
* changed
|
|
129
|
+
*/
|
|
130
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
131
|
+
/**
|
|
132
|
+
* Provide an optional `onClick` hook that is called each time the
|
|
133
|
+
* FileUploader is clicked
|
|
134
|
+
*/
|
|
135
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
136
|
+
/**
|
|
137
|
+
* Provide an optional `onDelete` hook that is called when an uploaded item
|
|
138
|
+
* is removed
|
|
139
|
+
*/
|
|
140
|
+
onDelete: PropTypes.Requireable<(...args: any[]) => any>;
|
|
141
|
+
/**
|
|
142
|
+
* Specify the size of the FileUploaderButton, from a list of available
|
|
143
|
+
* sizes.
|
|
144
|
+
*/
|
|
145
|
+
size: PropTypes.Requireable<string>;
|
|
146
|
+
};
|
|
147
|
+
static contextType: React.Context<string>;
|
|
148
|
+
static defaultProps: {
|
|
149
|
+
disabled: boolean;
|
|
150
|
+
filenameStatus: string;
|
|
151
|
+
buttonLabel: string;
|
|
152
|
+
buttonKind: string;
|
|
153
|
+
multiple: boolean;
|
|
154
|
+
onClick: () => void;
|
|
155
|
+
accept: never[];
|
|
156
|
+
};
|
|
157
|
+
state: {
|
|
158
|
+
filenames: string[];
|
|
159
|
+
};
|
|
160
|
+
nodes: HTMLElement[];
|
|
161
|
+
uploaderButton: React.RefObject<HTMLLabelElement>;
|
|
162
|
+
static getDerivedStateFromProps({ filenameStatus }: {
|
|
163
|
+
filenameStatus: any;
|
|
164
|
+
}, state: any): {
|
|
165
|
+
filenameStatus: any;
|
|
166
|
+
prevFilenameStatus: any;
|
|
167
|
+
} | null;
|
|
168
|
+
handleChange: (evt: any) => void;
|
|
169
|
+
handleClick: (evt: any, { index, filenameStatus }: {
|
|
170
|
+
index: any;
|
|
171
|
+
filenameStatus: any;
|
|
172
|
+
}) => void;
|
|
173
|
+
clearFiles: () => void;
|
|
174
|
+
render(): JSX.Element;
|
|
175
|
+
}
|
|
@@ -57,9 +57,9 @@ class FileUploader extends React__default["default"].Component {
|
|
|
57
57
|
});
|
|
58
58
|
if (this.props.onDelete) {
|
|
59
59
|
this.props.onDelete(evt);
|
|
60
|
-
this.uploaderButton.current
|
|
60
|
+
this.uploaderButton.current?.focus?.();
|
|
61
61
|
}
|
|
62
|
-
this.props.onClick(evt);
|
|
62
|
+
this.props.onClick?.(evt);
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
_rollupPluginBabelHelpers.defineProperty(this, "clearFiles", () => {
|
|
@@ -96,7 +96,7 @@ class FileUploader extends React__default["default"].Component {
|
|
|
96
96
|
name,
|
|
97
97
|
size = 'md',
|
|
98
98
|
onDelete,
|
|
99
|
-
// eslint-disable-line
|
|
99
|
+
// eslint-disable-line
|
|
100
100
|
...other
|
|
101
101
|
} = this.props;
|
|
102
102
|
const prefix = this.context;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { ReactAttr } from '../../types/common';
|
|
10
|
+
export interface FileUploaderButtonProps extends Omit<ReactAttr<HTMLButtonElement>, 'onChange' | 'tabIndex'> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify the types of files that this input should be able to receive
|
|
13
|
+
*/
|
|
14
|
+
accept?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Specify the type of underlying button
|
|
17
|
+
*/
|
|
18
|
+
buttonKind?: 'primary' | 'secondary' | 'danger' | 'ghost' | 'danger--primary' | 'danger--ghost' | 'danger--tertiary' | 'tertiary';
|
|
19
|
+
/**
|
|
20
|
+
* Provide a custom className to be applied to the container node
|
|
21
|
+
*/
|
|
22
|
+
className?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Specify whether you want to disable any updates to the FileUploaderButton
|
|
25
|
+
* label
|
|
26
|
+
*/
|
|
27
|
+
disableLabelChanges?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Specify whether file input is disabled
|
|
30
|
+
*/
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Provide a unique id for the underlying `<input>` node
|
|
34
|
+
*/
|
|
35
|
+
id?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Provide the label text to be read by screen readers when interacting with
|
|
38
|
+
* this control
|
|
39
|
+
*/
|
|
40
|
+
labelText?: React.ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Specify if the component should accept multiple files to upload
|
|
43
|
+
*/
|
|
44
|
+
multiple?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Provide a name for the underlying `<input>` node
|
|
47
|
+
*/
|
|
48
|
+
name?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Provide an optional `onChange` hook that is called each time the `<input>`
|
|
51
|
+
* value changes
|
|
52
|
+
*/
|
|
53
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Provide an optional `onClick` hook that is called each time the button is
|
|
56
|
+
* clicked
|
|
57
|
+
*/
|
|
58
|
+
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Provide an accessibility role for the `<FileUploaderButton>`
|
|
61
|
+
*/
|
|
62
|
+
role?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Specify the size of the FileUploaderButton, from a list of available
|
|
65
|
+
* sizes.
|
|
66
|
+
*/
|
|
67
|
+
size?: 'sm' | 'small' | 'field' | 'md' | 'lg';
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated The `tabIndex` prop for `FileUploaderButton` has been deprecated since it now renders a button element by default.
|
|
70
|
+
*/
|
|
71
|
+
tabIndex?: number | string;
|
|
72
|
+
innerRef?: React.RefObject<HTMLLabelElement>;
|
|
73
|
+
}
|
|
74
|
+
declare function FileUploaderButton({ accept, buttonKind, className, disabled, disableLabelChanges, id, labelText: ownerLabelText, multiple, onChange, name, size, innerRef, ...other }: FileUploaderButtonProps): JSX.Element;
|
|
75
|
+
declare namespace FileUploaderButton {
|
|
76
|
+
var propTypes: {
|
|
77
|
+
/**
|
|
78
|
+
* Specify the types of files that this input should be able to receive
|
|
79
|
+
*/
|
|
80
|
+
accept: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Specify the type of underlying button
|
|
83
|
+
*/
|
|
84
|
+
buttonKind: PropTypes.Requireable<string>;
|
|
85
|
+
/**
|
|
86
|
+
* Provide a custom className to be applied to the container node
|
|
87
|
+
*/
|
|
88
|
+
className: PropTypes.Requireable<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Specify whether you want to disable any updates to the FileUploaderButton
|
|
91
|
+
* label
|
|
92
|
+
*/
|
|
93
|
+
disableLabelChanges: PropTypes.Requireable<boolean>;
|
|
94
|
+
/**
|
|
95
|
+
* Specify whether file input is disabled
|
|
96
|
+
*/
|
|
97
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* Provide a unique id for the underlying `<input>` node
|
|
100
|
+
*/
|
|
101
|
+
id: PropTypes.Requireable<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Provide the label text to be read by screen readers when interacting with
|
|
104
|
+
* this control
|
|
105
|
+
*/
|
|
106
|
+
labelText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
107
|
+
/**
|
|
108
|
+
* Specify if the component should accept multiple files to upload
|
|
109
|
+
*/
|
|
110
|
+
multiple: PropTypes.Requireable<boolean>;
|
|
111
|
+
/**
|
|
112
|
+
* Provide a name for the underlying `<input>` node
|
|
113
|
+
*/
|
|
114
|
+
name: PropTypes.Requireable<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Provide an optional `onChange` hook that is called each time the `<input>`
|
|
117
|
+
* value changes
|
|
118
|
+
*/
|
|
119
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
120
|
+
/**
|
|
121
|
+
* Provide an optional `onClick` hook that is called each time the button is
|
|
122
|
+
* clicked
|
|
123
|
+
*/
|
|
124
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
125
|
+
/**
|
|
126
|
+
* Provide an accessibility role for the `<FileUploaderButton>`
|
|
127
|
+
*/
|
|
128
|
+
role: PropTypes.Requireable<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Specify the size of the FileUploaderButton, from a list of available
|
|
131
|
+
* sizes.
|
|
132
|
+
*/
|
|
133
|
+
size: PropTypes.Requireable<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Provide a custom tabIndex value for the `<FileUploaderButton>`
|
|
136
|
+
*/
|
|
137
|
+
tabIndex: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export default FileUploaderButton;
|
|
@@ -67,18 +67,20 @@ function FileUploaderButton(_ref) {
|
|
|
67
67
|
}
|
|
68
68
|
function onClick(event) {
|
|
69
69
|
event.target.value = null;
|
|
70
|
-
inputNode.current
|
|
71
|
-
|
|
70
|
+
if (inputNode.current) {
|
|
71
|
+
inputNode.current.value = '';
|
|
72
|
+
inputNode.current.click();
|
|
73
|
+
}
|
|
72
74
|
}
|
|
73
75
|
function onKeyDown(event) {
|
|
74
|
-
if (match.matches(event, [keys.Enter, keys.Space])) {
|
|
76
|
+
if (match.matches(event, [keys.Enter, keys.Space]) && inputNode.current) {
|
|
75
77
|
inputNode.current.value = '';
|
|
76
78
|
inputNode.current.click();
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
function handleOnChange(event) {
|
|
80
82
|
const files = event.target.files;
|
|
81
|
-
const length = event.target.files
|
|
83
|
+
const length = event.target.files?.length || 0;
|
|
82
84
|
if (files && !disableLabelChanges) {
|
|
83
85
|
if (length > 1) {
|
|
84
86
|
setLabelText(`${length} files`);
|
|
@@ -94,7 +96,9 @@ function FileUploaderButton(_ref) {
|
|
|
94
96
|
className: classes,
|
|
95
97
|
onClick: onClick,
|
|
96
98
|
onKeyDown: onKeyDown
|
|
97
|
-
}, other
|
|
99
|
+
}, other, {
|
|
100
|
+
tabIndex: other.tabIndex !== undefined ? parseInt(other.tabIndex) : undefined
|
|
101
|
+
}), labelText), /*#__PURE__*/React__default["default"].createElement("label", {
|
|
98
102
|
className: `${prefix}--visually-hidden`,
|
|
99
103
|
ref: innerRef,
|
|
100
104
|
htmlFor: inputId
|
|
@@ -104,9 +108,9 @@ function FileUploaderButton(_ref) {
|
|
|
104
108
|
id: inputId,
|
|
105
109
|
disabled: disabled,
|
|
106
110
|
type: "file",
|
|
107
|
-
tabIndex:
|
|
111
|
+
tabIndex: -1,
|
|
108
112
|
multiple: multiple,
|
|
109
|
-
accept: accept,
|
|
113
|
+
accept: accept?.toString(),
|
|
110
114
|
name: name,
|
|
111
115
|
onChange: handleOnChange
|
|
112
116
|
}));
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { ReactAttr } from '../../types/common';
|
|
10
|
+
export interface FileUploaderDropContainerProps extends Omit<ReactAttr<HTMLButtonElement>, 'tabIndex'> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify the types of files that this input should be able to receive
|
|
13
|
+
*/
|
|
14
|
+
accept?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* Provide a custom className to be applied to the container node
|
|
17
|
+
*/
|
|
18
|
+
className?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Specify whether file input is disabled
|
|
21
|
+
*/
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Provide a unique id for the underlying `<input>` node
|
|
25
|
+
*/
|
|
26
|
+
id?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Provide the label text to be read by screen readers when interacting with
|
|
29
|
+
* this control
|
|
30
|
+
*/
|
|
31
|
+
labelText: string;
|
|
32
|
+
/**
|
|
33
|
+
* Specify if the component should accept multiple files to upload
|
|
34
|
+
*/
|
|
35
|
+
multiple?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Provide a name for the underlying `<input>` node
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Event handler that is called after files are added to the uploader
|
|
42
|
+
* The event handler signature looks like `onAddFiles(evt, { addedFiles })`
|
|
43
|
+
*/
|
|
44
|
+
onAddFiles?: () => void;
|
|
45
|
+
/**
|
|
46
|
+
* Provide an optional function to be called when the button element
|
|
47
|
+
* is clicked
|
|
48
|
+
*/
|
|
49
|
+
onClick?: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Provide a custom regex pattern for the acceptedTypes
|
|
52
|
+
*/
|
|
53
|
+
pattern?: string;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated The `role` prop for `FileUploaderButton` has been deprecated since it now renders a button element by default, and has an implicit role of button.
|
|
56
|
+
*/
|
|
57
|
+
role?: string;
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated The `tabIndex` prop for `FileUploaderButton` has been deprecated since it now renders a button element by default.
|
|
60
|
+
*/
|
|
61
|
+
tabIndex?: number | string;
|
|
62
|
+
}
|
|
63
|
+
declare function FileUploaderDropContainer({ accept, className, id, disabled, labelText, multiple, name, onAddFiles, onClick, pattern, innerRef, ...rest }: {
|
|
64
|
+
[x: string]: any;
|
|
65
|
+
accept: any;
|
|
66
|
+
className: any;
|
|
67
|
+
id: any;
|
|
68
|
+
disabled: any;
|
|
69
|
+
labelText: any;
|
|
70
|
+
multiple: any;
|
|
71
|
+
name: any;
|
|
72
|
+
onAddFiles: any;
|
|
73
|
+
onClick: any;
|
|
74
|
+
pattern: any;
|
|
75
|
+
innerRef: any;
|
|
76
|
+
}): JSX.Element;
|
|
77
|
+
declare namespace FileUploaderDropContainer {
|
|
78
|
+
var propTypes: {
|
|
79
|
+
/**
|
|
80
|
+
* Specify the types of files that this input should be able to receive
|
|
81
|
+
*/
|
|
82
|
+
accept: PropTypes.Requireable<(string | null | undefined)[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Provide a custom className to be applied to the container node
|
|
85
|
+
*/
|
|
86
|
+
className: PropTypes.Requireable<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Specify whether file input is disabled
|
|
89
|
+
*/
|
|
90
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
91
|
+
/**
|
|
92
|
+
* Provide a unique id for the underlying `<input>` node
|
|
93
|
+
*/
|
|
94
|
+
id: PropTypes.Requireable<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Provide the label text to be read by screen readers when interacting with
|
|
97
|
+
* this control
|
|
98
|
+
*/
|
|
99
|
+
labelText: PropTypes.Validator<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Specify if the component should accept multiple files to upload
|
|
102
|
+
*/
|
|
103
|
+
multiple: PropTypes.Requireable<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* Provide a name for the underlying `<input>` node
|
|
106
|
+
*/
|
|
107
|
+
name: PropTypes.Requireable<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Event handler that is called after files are added to the uploader
|
|
110
|
+
* The event handler signature looks like `onAddFiles(evt, { addedFiles })`
|
|
111
|
+
*/
|
|
112
|
+
onAddFiles: PropTypes.Requireable<(...args: any[]) => any>;
|
|
113
|
+
/**
|
|
114
|
+
* Provide an optional function to be called when the button element
|
|
115
|
+
* is clicked
|
|
116
|
+
*/
|
|
117
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
118
|
+
/**
|
|
119
|
+
* Provide a custom regex pattern for the acceptedTypes
|
|
120
|
+
*/
|
|
121
|
+
pattern: PropTypes.Requireable<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Provide an accessibility role for the `<FileUploaderButton>`
|
|
124
|
+
*/
|
|
125
|
+
role: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
126
|
+
/**
|
|
127
|
+
* Provide a custom tabIndex value for the `<FileUploaderButton>`
|
|
128
|
+
*/
|
|
129
|
+
tabIndex: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
130
|
+
};
|
|
131
|
+
var defaultProps: {
|
|
132
|
+
labelText: string;
|
|
133
|
+
multiple: boolean;
|
|
134
|
+
onAddFiles: () => void;
|
|
135
|
+
accept: never[];
|
|
136
|
+
pattern: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export default FileUploaderDropContainer;
|
|
@@ -90,7 +90,7 @@ function FileUploaderDropContainer(_ref) {
|
|
|
90
90
|
}
|
|
91
91
|
const handleClick = () => {
|
|
92
92
|
if (!disabled) {
|
|
93
|
-
inputRef.current
|
|
93
|
+
inputRef.current?.click();
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -129,7 +129,7 @@ function FileUploaderDropContainer(_ref) {
|
|
|
129
129
|
onKeyDown: evt => {
|
|
130
130
|
if (match.matches(evt, [keys.Enter, keys.Space])) {
|
|
131
131
|
evt.preventDefault();
|
|
132
|
-
inputRef.current
|
|
132
|
+
inputRef.current?.click();
|
|
133
133
|
}
|
|
134
134
|
},
|
|
135
135
|
onClick: events.composeEventHandlers([onClick, handleClick])
|
|
@@ -141,7 +141,7 @@ function FileUploaderDropContainer(_ref) {
|
|
|
141
141
|
id: uid,
|
|
142
142
|
className: `${prefix}--file-input`,
|
|
143
143
|
ref: inputRef,
|
|
144
|
-
tabIndex:
|
|
144
|
+
tabIndex: -1,
|
|
145
145
|
disabled: disabled,
|
|
146
146
|
accept: accept,
|
|
147
147
|
name: name,
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import { ReactAttr } from '../../types/common';
|
|
10
|
+
export interface FileUploaderItemProps extends ReactAttr<HTMLSpanElement> {
|
|
11
|
+
/**
|
|
12
|
+
* Error message body for an invalid file upload
|
|
13
|
+
*/
|
|
14
|
+
errorBody?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Error message subject for an invalid file upload
|
|
17
|
+
*/
|
|
18
|
+
errorSubject?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Description of status icon (displayed in native tooltip)
|
|
21
|
+
*/
|
|
22
|
+
iconDescription?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Specify if the currently uploaded file is invalid
|
|
25
|
+
*/
|
|
26
|
+
invalid?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Name of the uploaded file
|
|
29
|
+
*/
|
|
30
|
+
name?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Event handler that is called after removing a file from the file uploader
|
|
33
|
+
* The event handler signature looks like `onDelete(evt, { uuid })`
|
|
34
|
+
*/
|
|
35
|
+
onDelete?: (event: any, opts: {
|
|
36
|
+
uuid: string;
|
|
37
|
+
}) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Specify the size of the FileUploaderButton, from a list of available
|
|
40
|
+
* sizes.
|
|
41
|
+
*/
|
|
42
|
+
size?: 'sm' | 'md' | 'lg';
|
|
43
|
+
/**
|
|
44
|
+
* Status of the file upload
|
|
45
|
+
*/
|
|
46
|
+
status?: 'uploading' | 'edit' | 'complete';
|
|
47
|
+
/**
|
|
48
|
+
* Unique identifier for the file object
|
|
49
|
+
*/
|
|
50
|
+
uuid?: string;
|
|
51
|
+
}
|
|
52
|
+
declare function FileUploaderItem({ uuid, name, status, iconDescription, onDelete, invalid, errorSubject, errorBody, size, ...other }: {
|
|
53
|
+
[x: string]: any;
|
|
54
|
+
uuid: any;
|
|
55
|
+
name: any;
|
|
56
|
+
status: any;
|
|
57
|
+
iconDescription: any;
|
|
58
|
+
onDelete: any;
|
|
59
|
+
invalid: any;
|
|
60
|
+
errorSubject: any;
|
|
61
|
+
errorBody: any;
|
|
62
|
+
size: any;
|
|
63
|
+
}): JSX.Element;
|
|
64
|
+
declare namespace FileUploaderItem {
|
|
65
|
+
var propTypes: {
|
|
66
|
+
/**
|
|
67
|
+
* Error message body for an invalid file upload
|
|
68
|
+
*/
|
|
69
|
+
errorBody: PropTypes.Requireable<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Error message subject for an invalid file upload
|
|
72
|
+
*/
|
|
73
|
+
errorSubject: PropTypes.Requireable<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Description of status icon (displayed in native tooltip)
|
|
76
|
+
*/
|
|
77
|
+
iconDescription: PropTypes.Requireable<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Specify if the currently uploaded file is invalid
|
|
80
|
+
*/
|
|
81
|
+
invalid: PropTypes.Requireable<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Name of the uploaded file
|
|
84
|
+
*/
|
|
85
|
+
name: PropTypes.Requireable<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Event handler that is called after removing a file from the file uploader
|
|
88
|
+
* The event handler signature looks like `onDelete(evt, { uuid })`
|
|
89
|
+
*/
|
|
90
|
+
onDelete: PropTypes.Requireable<(...args: any[]) => any>;
|
|
91
|
+
/**
|
|
92
|
+
* Specify the size of the FileUploaderButton, from a list of available
|
|
93
|
+
* sizes.
|
|
94
|
+
*/
|
|
95
|
+
size: PropTypes.Requireable<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Status of the file upload
|
|
98
|
+
*/
|
|
99
|
+
status: PropTypes.Requireable<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Unique identifier for the file object
|
|
102
|
+
*/
|
|
103
|
+
uuid: PropTypes.Requireable<string>;
|
|
104
|
+
};
|
|
105
|
+
var defaultProps: {
|
|
106
|
+
status: string;
|
|
107
|
+
onDelete: () => void;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export default FileUploaderItem;
|