@carbon/react 1.32.0-rc.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/Tabs/Tabs.d.ts +9 -1
- package/es/components/Tabs/Tabs.js +16 -3
- 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 +61 -5
- package/es/components/UIShell/Link.js +2 -1
- package/es/components/UIShell/SideNav.d.ts +1 -1
- package/es/components/UIShell/Switcher.js +45 -5
- package/es/components/UIShell/SwitcherItem.js +45 -6
- 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/es/internal/useMatchMedia.js +44 -0
- 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/Tabs/Tabs.d.ts +9 -1
- package/lib/components/Tabs/Tabs.js +16 -3
- 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 +60 -4
- package/lib/components/UIShell/Link.js +2 -1
- package/lib/components/UIShell/SideNav.d.ts +1 -1
- package/lib/components/UIShell/Switcher.js +44 -4
- package/lib/components/UIShell/SwitcherItem.js +45 -6
- 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/lib/internal/useMatchMedia.js +48 -0
- package/package.json +22 -19
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React__default, { useContext, useRef
|
|
9
|
+
import React__default, { useState, useContext, useRef } from 'react';
|
|
10
10
|
import { useSelect } from 'downshift';
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import PropTypes from 'prop-types';
|
|
@@ -21,6 +21,13 @@ import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
|
|
|
21
21
|
import { ListBoxSize, ListBoxType } from '../ListBox/ListBoxPropTypes.js';
|
|
22
22
|
|
|
23
23
|
const getInstanceId = setupGetInstanceId();
|
|
24
|
+
const {
|
|
25
|
+
MenuBlur,
|
|
26
|
+
MenuKeyDownArrowDown,
|
|
27
|
+
MenuKeyDownArrowUp,
|
|
28
|
+
MenuKeyDownEscape,
|
|
29
|
+
ToggleButtonClick
|
|
30
|
+
} = useSelect.stateChangeTypes;
|
|
24
31
|
const defaultItemToString = item => {
|
|
25
32
|
if (typeof item === 'string') {
|
|
26
33
|
return item;
|
|
@@ -65,6 +72,7 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
65
72
|
...other
|
|
66
73
|
} = _ref;
|
|
67
74
|
const prefix = usePrefix();
|
|
75
|
+
const [highlightedIndex, setHighlightedIndex] = useState();
|
|
68
76
|
const {
|
|
69
77
|
isFluid
|
|
70
78
|
} = useContext(FormContext);
|
|
@@ -72,12 +80,32 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
72
80
|
...downshiftProps,
|
|
73
81
|
items,
|
|
74
82
|
itemToString,
|
|
83
|
+
highlightedIndex,
|
|
75
84
|
initialSelectedItem,
|
|
76
|
-
onSelectedItemChange
|
|
85
|
+
onSelectedItemChange,
|
|
86
|
+
onStateChange
|
|
77
87
|
};
|
|
78
88
|
const {
|
|
79
89
|
current: dropdownInstanceId
|
|
80
90
|
} = useRef(getInstanceId());
|
|
91
|
+
function onStateChange(changes) {
|
|
92
|
+
const {
|
|
93
|
+
type
|
|
94
|
+
} = changes;
|
|
95
|
+
switch (type) {
|
|
96
|
+
case MenuKeyDownArrowDown:
|
|
97
|
+
case MenuKeyDownArrowUp:
|
|
98
|
+
setHighlightedIndex(changes.highlightedIndex);
|
|
99
|
+
break;
|
|
100
|
+
case MenuBlur:
|
|
101
|
+
case MenuKeyDownEscape:
|
|
102
|
+
setHighlightedIndex(changes.highlightedIndex);
|
|
103
|
+
break;
|
|
104
|
+
case ToggleButtonClick:
|
|
105
|
+
setHighlightedIndex(changes.highlightedIndex);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
81
109
|
|
|
82
110
|
// only set selectedItem if the prop is defined. Setting if it is undefined
|
|
83
111
|
// will overwrite default selected items from useSelect
|
|
@@ -90,7 +118,6 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
90
118
|
getLabelProps,
|
|
91
119
|
getMenuProps,
|
|
92
120
|
getItemProps,
|
|
93
|
-
highlightedIndex,
|
|
94
121
|
selectedItem
|
|
95
122
|
} = useSelect(selectProps);
|
|
96
123
|
const inline = type === 'inline';
|
|
@@ -169,12 +196,10 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
169
196
|
}
|
|
170
197
|
} : {
|
|
171
198
|
onKeyDown: evt => {
|
|
172
|
-
console.log('typing should be false', isTyping);
|
|
173
199
|
if (evt.code !== 'Space' || !['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)) {
|
|
174
200
|
setIsTyping(true);
|
|
175
201
|
}
|
|
176
202
|
if (isTyping && evt.code === 'Space' || !['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)) {
|
|
177
|
-
console.log(evt.key);
|
|
178
203
|
if (evt.code === 'Space') {
|
|
179
204
|
evt.preventDefault();
|
|
180
205
|
return;
|
|
@@ -244,7 +269,7 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
244
269
|
return /*#__PURE__*/React__default.createElement(ListBox.MenuItem, _extends({
|
|
245
270
|
key: itemProps.id,
|
|
246
271
|
isActive: selectedItem === item,
|
|
247
|
-
isHighlighted: highlightedIndex === index
|
|
272
|
+
isHighlighted: highlightedIndex === index,
|
|
248
273
|
title: title,
|
|
249
274
|
ref: {
|
|
250
275
|
menuItemOptionRef: menuItemOptionRefs.current[index]
|
|
@@ -0,0 +1,29 @@
|
|
|
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 FileUploaderSkeletonProps extends ReactAttr<HTMLDivElement> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify an optional className to add.
|
|
13
|
+
*/
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
declare function FileUploaderSkeleton({ className, ...rest }: {
|
|
17
|
+
[x: string]: any;
|
|
18
|
+
className: any;
|
|
19
|
+
}): JSX.Element;
|
|
20
|
+
declare namespace FileUploaderSkeleton {
|
|
21
|
+
var propTypes: {
|
|
22
|
+
/**
|
|
23
|
+
* Specify an optional className to add.
|
|
24
|
+
*/
|
|
25
|
+
className: PropTypes.Requireable<string>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export default FileUploaderSkeleton;
|
|
29
|
+
export { FileUploaderSkeleton };
|
|
@@ -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
|
+
}
|
|
@@ -47,9 +47,9 @@ class FileUploader extends React__default.Component {
|
|
|
47
47
|
});
|
|
48
48
|
if (this.props.onDelete) {
|
|
49
49
|
this.props.onDelete(evt);
|
|
50
|
-
this.uploaderButton.current
|
|
50
|
+
this.uploaderButton.current?.focus?.();
|
|
51
51
|
}
|
|
52
|
-
this.props.onClick(evt);
|
|
52
|
+
this.props.onClick?.(evt);
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
_defineProperty(this, "clearFiles", () => {
|
|
@@ -86,7 +86,7 @@ class FileUploader extends React__default.Component {
|
|
|
86
86
|
name,
|
|
87
87
|
size = 'md',
|
|
88
88
|
onDelete,
|
|
89
|
-
// eslint-disable-line
|
|
89
|
+
// eslint-disable-line
|
|
90
90
|
...other
|
|
91
91
|
} = this.props;
|
|
92
92
|
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;
|
|
@@ -57,18 +57,20 @@ function FileUploaderButton(_ref) {
|
|
|
57
57
|
}
|
|
58
58
|
function onClick(event) {
|
|
59
59
|
event.target.value = null;
|
|
60
|
-
inputNode.current
|
|
61
|
-
|
|
60
|
+
if (inputNode.current) {
|
|
61
|
+
inputNode.current.value = '';
|
|
62
|
+
inputNode.current.click();
|
|
63
|
+
}
|
|
62
64
|
}
|
|
63
65
|
function onKeyDown(event) {
|
|
64
|
-
if (matches(event, [Enter, Space])) {
|
|
66
|
+
if (matches(event, [Enter, Space]) && inputNode.current) {
|
|
65
67
|
inputNode.current.value = '';
|
|
66
68
|
inputNode.current.click();
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
function handleOnChange(event) {
|
|
70
72
|
const files = event.target.files;
|
|
71
|
-
const length = event.target.files
|
|
73
|
+
const length = event.target.files?.length || 0;
|
|
72
74
|
if (files && !disableLabelChanges) {
|
|
73
75
|
if (length > 1) {
|
|
74
76
|
setLabelText(`${length} files`);
|
|
@@ -84,7 +86,9 @@ function FileUploaderButton(_ref) {
|
|
|
84
86
|
className: classes,
|
|
85
87
|
onClick: onClick,
|
|
86
88
|
onKeyDown: onKeyDown
|
|
87
|
-
}, other
|
|
89
|
+
}, other, {
|
|
90
|
+
tabIndex: other.tabIndex !== undefined ? parseInt(other.tabIndex) : undefined
|
|
91
|
+
}), labelText), /*#__PURE__*/React__default.createElement("label", {
|
|
88
92
|
className: `${prefix}--visually-hidden`,
|
|
89
93
|
ref: innerRef,
|
|
90
94
|
htmlFor: inputId
|
|
@@ -94,9 +98,9 @@ function FileUploaderButton(_ref) {
|
|
|
94
98
|
id: inputId,
|
|
95
99
|
disabled: disabled,
|
|
96
100
|
type: "file",
|
|
97
|
-
tabIndex:
|
|
101
|
+
tabIndex: -1,
|
|
98
102
|
multiple: multiple,
|
|
99
|
-
accept: accept,
|
|
103
|
+
accept: accept?.toString(),
|
|
100
104
|
name: name,
|
|
101
105
|
onChange: handleOnChange
|
|
102
106
|
}));
|
|
@@ -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;
|
|
@@ -80,7 +80,7 @@ function FileUploaderDropContainer(_ref) {
|
|
|
80
80
|
}
|
|
81
81
|
const handleClick = () => {
|
|
82
82
|
if (!disabled) {
|
|
83
|
-
inputRef.current
|
|
83
|
+
inputRef.current?.click();
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -119,7 +119,7 @@ function FileUploaderDropContainer(_ref) {
|
|
|
119
119
|
onKeyDown: evt => {
|
|
120
120
|
if (matches(evt, [Enter, Space])) {
|
|
121
121
|
evt.preventDefault();
|
|
122
|
-
inputRef.current
|
|
122
|
+
inputRef.current?.click();
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
125
|
onClick: composeEventHandlers([onClick, handleClick])
|
|
@@ -131,7 +131,7 @@ function FileUploaderDropContainer(_ref) {
|
|
|
131
131
|
id: uid,
|
|
132
132
|
className: `${prefix}--file-input`,
|
|
133
133
|
ref: inputRef,
|
|
134
|
-
tabIndex:
|
|
134
|
+
tabIndex: -1,
|
|
135
135
|
disabled: disabled,
|
|
136
136
|
accept: accept,
|
|
137
137
|
name: name,
|