@carbon/react 1.36.0 → 1.37.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/es/components/Button/Button.js +12 -12
  2. package/es/components/ComboBox/ComboBox.js +2 -4
  3. package/es/components/DataTable/DataTable.d.ts +30 -0
  4. package/es/components/DataTable/DataTable.js +27 -0
  5. package/es/components/DataTable/TableBatchActions.d.ts +51 -0
  6. package/es/components/DataTable/TableBatchActions.js +39 -8
  7. package/es/components/DataTable/TableExpandHeader.d.ts +27 -5
  8. package/es/components/DataTable/TableExpandHeader.js +17 -3
  9. package/es/components/DataTable/TableExpandRow.d.ts +24 -3
  10. package/es/components/DataTable/TableExpandRow.js +18 -3
  11. package/es/components/DataTable/TableRow.js +1 -1
  12. package/es/components/DataTable/TableToolbarSearch.d.ts +176 -0
  13. package/es/components/DataTable/TableToolbarSearch.js +9 -4
  14. package/es/components/Dropdown/Dropdown.d.ts +1 -1
  15. package/es/components/Dropdown/Dropdown.js +40 -40
  16. package/es/components/FileUploader/FileUploader.Skeleton.d.ts +1 -4
  17. package/es/components/FileUploader/FileUploaderDropContainer.d.ts +9 -17
  18. package/es/components/FileUploader/FileUploaderDropContainer.js +21 -17
  19. package/es/components/FileUploader/FileUploaderItem.d.ts +3 -14
  20. package/es/components/FileUploader/FileUploaderItem.js +4 -4
  21. package/es/components/FormLabel/FormLabel.d.ts +40 -0
  22. package/es/components/FormLabel/index.d.ts +9 -0
  23. package/es/components/ListBox/ListBoxMenu.d.ts +2 -2
  24. package/es/components/ListBox/ListBoxMenu.js +1 -1
  25. package/es/components/ListBox/ListBoxMenuItem.d.ts +6 -2
  26. package/es/components/ListBox/ListBoxMenuItem.js +6 -3
  27. package/es/components/MultiSelect/FilterableMultiSelect.js +24 -4
  28. package/es/components/MultiSelect/MultiSelect.d.ts +1 -3
  29. package/es/components/MultiSelect/MultiSelect.js +77 -56
  30. package/es/components/NumberInput/NumberInput.d.ts +1 -1
  31. package/es/components/NumberInput/NumberInput.js +18 -44
  32. package/es/components/SkeletonPlaceholder/SkeletonPlaceholder.d.ts +24 -0
  33. package/es/components/SkeletonPlaceholder/SkeletonPlaceholder.js +3 -5
  34. package/es/components/SkeletonPlaceholder/index.d.ts +9 -0
  35. package/es/components/Slider/Slider.d.ts +6 -0
  36. package/es/components/Slider/Slider.js +17 -2
  37. package/es/components/StructuredList/StructuredList.js +5 -2
  38. package/es/components/Tag/Tag.Skeleton.d.ts +35 -0
  39. package/es/components/Tag/Tag.d.ts +122 -0
  40. package/es/components/Tag/Tag.js +6 -6
  41. package/es/components/Tag/index.d.ts +11 -0
  42. package/es/components/TextArea/TextArea.js +1 -1
  43. package/es/components/Tile/Tile.js +5 -5
  44. package/es/components/TimePicker/TimePicker.js +8 -6
  45. package/es/components/Toggle/Toggle.Skeleton.js +1 -4
  46. package/es/components/Toggle/Toggle.js +1 -1
  47. package/es/components/ToggleSmall/ToggleSmall.Skeleton.js +0 -3
  48. package/es/components/UIShell/HeaderMenuItem.js +1 -2
  49. package/es/components/UIShell/Link.js +1 -2
  50. package/es/components/UIShell/SideNav.js +1 -3
  51. package/es/components/UIShell/index.d.ts +35 -0
  52. package/es/index.js +32 -32
  53. package/es/types/common.d.ts +7 -0
  54. package/lib/components/Button/Button.js +12 -12
  55. package/lib/components/ComboBox/ComboBox.js +2 -4
  56. package/lib/components/DataTable/DataTable.d.ts +30 -0
  57. package/lib/components/DataTable/DataTable.js +27 -0
  58. package/lib/components/DataTable/TableBatchActions.d.ts +51 -0
  59. package/lib/components/DataTable/TableBatchActions.js +39 -8
  60. package/lib/components/DataTable/TableExpandHeader.d.ts +27 -5
  61. package/lib/components/DataTable/TableExpandHeader.js +17 -3
  62. package/lib/components/DataTable/TableExpandRow.d.ts +24 -3
  63. package/lib/components/DataTable/TableExpandRow.js +18 -3
  64. package/lib/components/DataTable/TableRow.js +1 -1
  65. package/lib/components/DataTable/TableToolbarSearch.d.ts +176 -0
  66. package/lib/components/DataTable/TableToolbarSearch.js +9 -4
  67. package/lib/components/Dropdown/Dropdown.d.ts +1 -1
  68. package/lib/components/Dropdown/Dropdown.js +39 -39
  69. package/lib/components/FileUploader/FileUploader.Skeleton.d.ts +1 -4
  70. package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +9 -17
  71. package/lib/components/FileUploader/FileUploaderDropContainer.js +21 -17
  72. package/lib/components/FileUploader/FileUploaderItem.d.ts +3 -14
  73. package/lib/components/FileUploader/FileUploaderItem.js +4 -4
  74. package/lib/components/FormLabel/FormLabel.d.ts +40 -0
  75. package/lib/components/FormLabel/index.d.ts +9 -0
  76. package/lib/components/ListBox/ListBoxMenu.d.ts +2 -2
  77. package/lib/components/ListBox/ListBoxMenu.js +1 -1
  78. package/lib/components/ListBox/ListBoxMenuItem.d.ts +6 -2
  79. package/lib/components/ListBox/ListBoxMenuItem.js +6 -3
  80. package/lib/components/MultiSelect/FilterableMultiSelect.js +24 -4
  81. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -3
  82. package/lib/components/MultiSelect/MultiSelect.js +75 -55
  83. package/lib/components/NumberInput/NumberInput.d.ts +1 -1
  84. package/lib/components/NumberInput/NumberInput.js +18 -44
  85. package/lib/components/SkeletonPlaceholder/SkeletonPlaceholder.d.ts +24 -0
  86. package/lib/components/SkeletonPlaceholder/SkeletonPlaceholder.js +3 -5
  87. package/lib/components/SkeletonPlaceholder/index.d.ts +9 -0
  88. package/lib/components/Slider/Slider.d.ts +6 -0
  89. package/lib/components/Slider/Slider.js +17 -2
  90. package/lib/components/StructuredList/StructuredList.js +5 -2
  91. package/lib/components/Tag/Tag.Skeleton.d.ts +35 -0
  92. package/lib/components/Tag/Tag.d.ts +122 -0
  93. package/lib/components/Tag/Tag.js +6 -6
  94. package/lib/components/Tag/index.d.ts +11 -0
  95. package/lib/components/TextArea/TextArea.js +1 -1
  96. package/lib/components/Tile/Tile.js +5 -5
  97. package/lib/components/TimePicker/TimePicker.js +8 -6
  98. package/lib/components/Toggle/Toggle.Skeleton.js +1 -4
  99. package/lib/components/Toggle/Toggle.js +1 -1
  100. package/lib/components/ToggleSmall/ToggleSmall.Skeleton.js +0 -3
  101. package/lib/components/UIShell/HeaderMenuItem.js +1 -2
  102. package/lib/components/UIShell/Link.js +1 -2
  103. package/lib/components/UIShell/SideNav.js +1 -3
  104. package/lib/components/UIShell/index.d.ts +35 -0
  105. package/lib/index.js +65 -65
  106. package/lib/types/common.d.ts +7 -0
  107. package/package.json +5 -5
@@ -0,0 +1,176 @@
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, { FocusEvent, ReactNode } from 'react';
9
+ export interface TableToolbarSearchProps {
10
+ children?: ReactNode;
11
+ /**
12
+ * Provide an optional class name for the search container
13
+ */
14
+ className?: string;
15
+ /**
16
+ * Specifies if the search should initially render in an expanded state
17
+ */
18
+ defaultExpanded?: boolean;
19
+ /**
20
+ * Provide an optional default value for the Search component
21
+ */
22
+ defaultValue?: string;
23
+ /**
24
+ * Specifies if the search should be disabled
25
+ */
26
+ disabled?: boolean;
27
+ /**
28
+ * Specifies if the search should expand
29
+ */
30
+ expanded?: boolean;
31
+ /**
32
+ * Provide an optional id for the search container
33
+ */
34
+ id?: string;
35
+ /**
36
+ * Provide an optional label text for the Search component icon
37
+ */
38
+ labelText?: string;
39
+ /**
40
+ * Provide an optional function to be called when the search input loses focus, this will be
41
+ * passed the event as the first parameter and a function to handle the expanding of the search
42
+ * input as the second
43
+ */
44
+ onBlur?: (event: FocusEvent<HTMLInputElement>, handleExpand: (event: FocusEvent<HTMLInputElement>, value: boolean) => void) => void;
45
+ /**
46
+ * Provide an optional hook that is called each time the input is updated
47
+ */
48
+ onChange?: (event: '' | Partial<React.ChangeEventHandler<HTMLInputElement>>, value?: string) => void;
49
+ /**
50
+ * Optional callback called when the search value is cleared.
51
+ */
52
+ onClear?: () => void;
53
+ /**
54
+ * Provide an optional hook that is called each time the input is expanded
55
+ */
56
+ onExpand?: (event: FocusEvent<HTMLInputElement>, value: boolean) => void;
57
+ /**
58
+ * Provide an optional function to be called when the search input gains focus, this will be
59
+ * passed the event as the first parameter and a function to handle the expanding of the search
60
+ * input as the second.
61
+ */
62
+ onFocus?: (event: FocusEvent<HTMLInputElement>, handleExpand: (event: FocusEvent<HTMLInputElement>, value: boolean) => void) => void;
63
+ /**
64
+ * Whether the search should be allowed to expand
65
+ */
66
+ persistent?: boolean;
67
+ /**
68
+ * Provide an optional placeholder text for the Search component
69
+ */
70
+ placeholder?: string;
71
+ /**
72
+ * Provide an optional className for the overall container of the Search
73
+ */
74
+ searchContainerClass?: string;
75
+ /**
76
+ * Specify the size of the Search
77
+ */
78
+ size?: 'sm' | 'md' | 'lg';
79
+ /**
80
+ * Optional prop to specify the tabIndex of the <Search> (in expanded state) or the container (in collapsed state)
81
+ */
82
+ tabIndex?: number | string;
83
+ /**
84
+ * Provide custom text for the component for each translation id
85
+ */
86
+ translateWithId: (id: string) => string;
87
+ }
88
+ declare const TableToolbarSearch: {
89
+ ({ className, searchContainerClass, onChange: onChangeProp, onClear, translateWithId: t, placeholder, labelText, expanded: expandedProp, defaultExpanded, defaultValue, disabled, onExpand, persistent, id, onBlur, onFocus, size, tabIndex, ...rest }: TableToolbarSearchProps): JSX.Element;
90
+ propTypes: {
91
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
92
+ /**
93
+ * Provide an optional class name for the search container
94
+ */
95
+ className: PropTypes.Requireable<string>;
96
+ /**
97
+ * Specifies if the search should initially render in an expanded state
98
+ */
99
+ defaultExpanded: PropTypes.Requireable<boolean>;
100
+ /**
101
+ * Provide an optional default value for the Search component
102
+ */
103
+ defaultValue: PropTypes.Requireable<string>;
104
+ /**
105
+ * Specifies if the search should be disabled
106
+ */
107
+ disabled: PropTypes.Requireable<boolean>;
108
+ /**
109
+ * Specifies if the search should expand
110
+ */
111
+ expanded: PropTypes.Requireable<boolean>;
112
+ /**
113
+ * Provide an optional id for the search container
114
+ */
115
+ id: PropTypes.Requireable<string>;
116
+ /**
117
+ * Provide an optional label text for the Search component icon
118
+ */
119
+ labelText: PropTypes.Requireable<string>;
120
+ /**
121
+ * Provide an optional function to be called when the search input loses focus, this will be
122
+ * passed the event as the first parameter and a function to handle the expanding of the search
123
+ * input as the second
124
+ */
125
+ onBlur: PropTypes.Requireable<(...args: any[]) => any>;
126
+ /**
127
+ * Provide an optional hook that is called each time the input is updated
128
+ */
129
+ onChange: PropTypes.Requireable<(...args: any[]) => any>;
130
+ /**
131
+ * Optional callback called when the search value is cleared.
132
+ */
133
+ onClear: PropTypes.Requireable<(...args: any[]) => any>;
134
+ /**
135
+ * Provide an optional hook that is called each time the input is expanded
136
+ */
137
+ onExpand: PropTypes.Requireable<(...args: any[]) => any>;
138
+ /**
139
+ * Provide an optional function to be called when the search input gains focus, this will be
140
+ * passed the event as the first parameter and a function to handle the expanding of the search
141
+ * input as the second.
142
+ */
143
+ onFocus: PropTypes.Requireable<(...args: any[]) => any>;
144
+ /**
145
+ * Whether the search should be allowed to expand
146
+ */
147
+ persistent: PropTypes.Requireable<boolean>;
148
+ /**
149
+ * Provide an optional placeholder text for the Search component
150
+ */
151
+ placeholder: PropTypes.Requireable<string>;
152
+ /**
153
+ * Provide an optional className for the overall container of the Search
154
+ */
155
+ searchContainerClass: PropTypes.Requireable<string>;
156
+ /**
157
+ * Specify the size of the Search
158
+ */
159
+ size: PropTypes.Requireable<string>;
160
+ /**
161
+ * Optional prop to specify the tabIndex of the <Search> (in expanded state) or the container (in collapsed state)
162
+ */
163
+ tabIndex: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
164
+ /**
165
+ * Provide custom text for the component for each translation id
166
+ */
167
+ translateWithId: PropTypes.Validator<(...args: any[]) => any>;
168
+ };
169
+ defaultProps: {
170
+ tabIndex: string;
171
+ translateWithId: (id: string) => string;
172
+ persistent: boolean;
173
+ onClear: () => void;
174
+ };
175
+ };
176
+ export default TableToolbarSearch;
@@ -41,6 +41,7 @@ const TableToolbarSearch = _ref => {
41
41
  onBlur,
42
42
  onFocus,
43
43
  size = 'lg',
44
+ tabIndex,
44
45
  ...rest
45
46
  } = _ref;
46
47
  const {
@@ -54,18 +55,19 @@ const TableToolbarSearch = _ref => {
54
55
  const prefix = usePrefix();
55
56
  useEffect(() => {
56
57
  if (focusTarget) {
57
- focusTarget.current.querySelector('input').focus();
58
+ focusTarget.current?.querySelector?.('input')?.focus();
58
59
  setFocusTarget(null);
59
60
  }
60
61
  }, [focusTarget]);
61
62
  useEffect(() => {
62
63
  if (defaultValue) {
63
- onChangeProp('', defaultValue);
64
+ onChangeProp?.('', defaultValue);
64
65
  }
65
66
  },
66
67
  //eslint-disable-next-line react-hooks/exhaustive-deps
67
68
  []);
68
69
  const searchClasses = cx(className, {
70
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
71
  [searchContainerClass]: searchContainerClass,
70
72
  [`${prefix}--toolbar-search-container-active`]: expanded,
71
73
  [`${prefix}--toolbar-search-container-disabled`]: disabled,
@@ -103,6 +105,10 @@ const TableToolbarSearch = _ref => {
103
105
  onFocus: onFocus ? event => onFocus(event, handleExpand) : handleOnFocus,
104
106
  onBlur: onBlur ? event => onBlur(event, handleExpand) : handleOnBlur,
105
107
  size: size
108
+ // HTMLAttributes defines tabIndex as number | undefined but in reality it
109
+ // also accepts a string, so we cast here to convince Typescript this is okay.
110
+ ,
111
+ tabIndex: tabIndex
106
112
  }, rest));
107
113
  };
108
114
  TableToolbarSearch.propTypes = {
@@ -190,6 +196,5 @@ TableToolbarSearch.defaultProps = {
190
196
  persistent: false,
191
197
  onClear: () => {}
192
198
  };
193
- var TableToolbarSearch$1 = TableToolbarSearch;
194
199
 
195
- export { TableToolbarSearch$1 as default };
200
+ export { TableToolbarSearch as default };
@@ -71,7 +71,7 @@ export interface DropdownProps<ItemType> extends Omit<ReactAttr<HTMLDivElement>,
71
71
  * given item to a string label. By default, it extracts the `label` field
72
72
  * from a given item to serve as the item label in the list.
73
73
  */
74
- itemToString?(item: ItemType): string;
74
+ itemToString?(item: ItemType | null): string;
75
75
  /**
76
76
  * We try to stay as generic as possible here to allow individuals to pass
77
77
  * in a collection of whatever kind of data structure they prefer
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useState, useContext, useRef } from 'react';
9
+ import React__default, { useContext, useRef, useState } from 'react';
10
10
  import { useSelect } from 'downshift';
11
11
  import cx from 'classnames';
12
12
  import PropTypes from 'prop-types';
@@ -22,11 +22,11 @@ import { ListBoxSize, ListBoxType } from '../ListBox/ListBoxPropTypes.js';
22
22
 
23
23
  const getInstanceId = setupGetInstanceId();
24
24
  const {
25
- MenuBlur,
26
- MenuKeyDownArrowDown,
27
- MenuKeyDownArrowUp,
28
- MenuKeyDownEscape,
29
- ToggleButtonClick
25
+ ToggleButtonKeyDownArrowDown,
26
+ ToggleButtonKeyDownArrowUp,
27
+ ToggleButtonKeyDownHome,
28
+ ToggleButtonKeyDownEnd,
29
+ ItemMouseMove
30
30
  } = useSelect.stateChangeTypes;
31
31
  const defaultItemToString = item => {
32
32
  if (typeof item === 'string') {
@@ -72,7 +72,6 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
72
72
  ...other
73
73
  } = _ref;
74
74
  const prefix = usePrefix();
75
- const [highlightedIndex, setHighlightedIndex] = useState();
76
75
  const {
77
76
  isFluid
78
77
  } = useContext(FormContext);
@@ -80,31 +79,43 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
80
79
  ...downshiftProps,
81
80
  items,
82
81
  itemToString,
83
- highlightedIndex,
84
82
  initialSelectedItem,
85
83
  onSelectedItemChange,
86
- onStateChange
84
+ stateReducer,
85
+ isItemDisabled(item, _index) {
86
+ const isObject = item !== null && typeof item === 'object';
87
+ return isObject && 'disabled' in item && item.disabled === true;
88
+ }
87
89
  };
88
90
  const {
89
91
  current: dropdownInstanceId
90
92
  } = useRef(getInstanceId());
91
- function onStateChange(changes) {
93
+ function stateReducer(state, actionAndChanges) {
92
94
  const {
95
+ changes,
96
+ props,
93
97
  type
98
+ } = actionAndChanges;
99
+ const {
100
+ highlightedIndex
94
101
  } = changes;
95
102
  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;
103
+ case ToggleButtonKeyDownArrowDown:
104
+ case ToggleButtonKeyDownArrowUp:
105
+ case ToggleButtonKeyDownHome:
106
+ case ToggleButtonKeyDownEnd:
107
+ if (highlightedIndex > -1) {
108
+ const itemArray = document.querySelectorAll(`li.${prefix}--list-box__menu-item[role="option"]`);
109
+ props.scrollIntoView(itemArray[highlightedIndex]);
110
+ }
111
+ return changes;
112
+ case ItemMouseMove:
113
+ return {
114
+ ...changes,
115
+ highlightedIndex: state.highlightedIndex
116
+ };
107
117
  }
118
+ return changes;
108
119
  }
109
120
 
110
121
  // only set selectedItem if the prop is defined. Setting if it is undefined
@@ -118,7 +129,8 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
118
129
  getLabelProps,
119
130
  getMenuProps,
120
131
  getItemProps,
121
- selectedItem
132
+ selectedItem,
133
+ highlightedIndex
122
134
  } = useSelect(selectProps);
123
135
  const inline = type === 'inline';
124
136
  const showWarning = !invalid && warn;
@@ -162,14 +174,12 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
162
174
  let {
163
175
  selectedItem
164
176
  } = _ref2;
165
- setIsFocused(false);
166
177
  if (onChange) {
167
178
  onChange({
168
179
  selectedItem: selectedItem ?? null
169
180
  });
170
181
  }
171
182
  }
172
- const menuItemOptionRefs = useRef(items.map(_ => /*#__PURE__*/React__default.createRef()));
173
183
  const handleFocus = evt => {
174
184
  setIsFocused(evt.type === 'focus' ? true : false);
175
185
  };
@@ -200,10 +210,6 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
200
210
  setIsTyping(true);
201
211
  }
202
212
  if (isTyping && evt.code === 'Space' || !['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)) {
203
- if (evt.code === 'Space') {
204
- evt.preventDefault();
205
- return;
206
- }
207
213
  if (currTimer) {
208
214
  clearTimeout(currTimer);
209
215
  }
@@ -211,7 +217,9 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
211
217
  setIsTyping(false);
212
218
  }, 3000));
213
219
  }
214
- toggleButtonProps.onKeyDown(evt);
220
+ if (toggleButtonProps.onKeyDown) {
221
+ toggleButtonProps.onKeyDown(evt);
222
+ }
215
223
  }
216
224
  };
217
225
  const menuProps = getMenuProps();
@@ -240,16 +248,12 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
240
248
  type: "button"
241
249
  // aria-expanded is already being passed through {...toggleButtonProps}
242
250
  ,
243
- role: "combobox" // eslint-disable-line jsx-a11y/role-has-required-aria-props
244
- ,
245
- "aria-owns": getMenuProps().id,
246
- "aria-controls": getMenuProps().id,
247
251
  className: `${prefix}--list-box__field`,
248
252
  disabled: disabled,
249
253
  "aria-disabled": readOnly ? true : undefined // aria-disabled to remain focusable
250
254
  ,
251
255
  "aria-describedby": !inline && !invalid && !warn && helper ? helperId : undefined,
252
- title: selectedItem && itemToString !== undefined ? itemToString(selectedItem) : label
256
+ title: selectedItem && itemToString !== undefined ? itemToString(selectedItem) : defaultItemToString(label)
253
257
  }, toggleButtonProps, readOnlyEventHandlers, {
254
258
  ref: mergedRef
255
259
  }), /*#__PURE__*/React__default.createElement("span", {
@@ -259,11 +263,9 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
259
263
  translateWithId: translateWithId
260
264
  })), /*#__PURE__*/React__default.createElement(ListBox.Menu, menuProps, isOpen && items.map((item, index) => {
261
265
  const isObject = item !== null && typeof item === 'object';
262
- const disabled = isObject && 'disabled' in item && item.disabled === true;
263
266
  const itemProps = getItemProps({
264
267
  item,
265
- index,
266
- disabled
268
+ index
267
269
  });
268
270
  const title = isObject && 'text' in item && itemToElement ? item.text : itemToString(item);
269
271
  return /*#__PURE__*/React__default.createElement(ListBox.MenuItem, _extends({
@@ -271,9 +273,7 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
271
273
  isActive: selectedItem === item,
272
274
  isHighlighted: highlightedIndex === index,
273
275
  title: title,
274
- ref: {
275
- menuItemOptionRef: menuItemOptionRefs.current[index]
276
- }
276
+ disabled: itemProps['aria-disabled']
277
277
  }, itemProps), typeof item === 'object' && ItemToElement !== undefined && ItemToElement !== null ? /*#__PURE__*/React__default.createElement(ItemToElement, _extends({
278
278
  key: itemProps.id
279
279
  }, item)) : itemToString(item), selectedItem === item && /*#__PURE__*/React__default.createElement(Checkmark, {
@@ -13,10 +13,7 @@ export interface FileUploaderSkeletonProps extends ReactAttr<HTMLDivElement> {
13
13
  */
14
14
  className?: string;
15
15
  }
16
- declare function FileUploaderSkeleton({ className, ...rest }: {
17
- [x: string]: any;
18
- className: any;
19
- }): JSX.Element;
16
+ declare function FileUploaderSkeleton({ className, ...rest }: FileUploaderSkeletonProps): JSX.Element;
20
17
  declare namespace FileUploaderSkeleton {
21
18
  var propTypes: {
22
19
  /**
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- /// <reference types="react" />
7
+ import React from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { ReactAttr } from '../../types/common';
10
10
  export interface FileUploaderDropContainerProps extends Omit<ReactAttr<HTMLButtonElement>, 'tabIndex'> {
@@ -39,9 +39,10 @@ export interface FileUploaderDropContainerProps extends Omit<ReactAttr<HTMLButto
39
39
  name?: string;
40
40
  /**
41
41
  * Event handler that is called after files are added to the uploader
42
- * The event handler signature looks like `onAddFiles(evt, { addedFiles })`
43
42
  */
44
- onAddFiles?: () => void;
43
+ onAddFiles?: (event: React.SyntheticEvent<HTMLElement>, content: {
44
+ addedFiles: File[];
45
+ }) => void;
45
46
  /**
46
47
  * Provide an optional function to be called when the button element
47
48
  * is clicked
@@ -51,6 +52,10 @@ export interface FileUploaderDropContainerProps extends Omit<ReactAttr<HTMLButto
51
52
  * Provide a custom regex pattern for the acceptedTypes
52
53
  */
53
54
  pattern?: string;
55
+ /**
56
+ * Ref to pass to the inner button element
57
+ */
58
+ innerRef?: React.LegacyRef<HTMLButtonElement>;
54
59
  /**
55
60
  * @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
61
  */
@@ -60,20 +65,7 @@ export interface FileUploaderDropContainerProps extends Omit<ReactAttr<HTMLButto
60
65
  */
61
66
  tabIndex?: number | string;
62
67
  }
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;
68
+ declare function FileUploaderDropContainer({ accept, className, id, disabled, labelText, multiple, name, onAddFiles, onClick, pattern, innerRef, ...rest }: FileUploaderDropContainerProps): JSX.Element;
77
69
  declare namespace FileUploaderDropContainer {
78
70
  var propTypes: {
79
71
  /**
@@ -18,16 +18,16 @@ import { Enter, Space } from '../../internal/keyboard/keys.js';
18
18
 
19
19
  function FileUploaderDropContainer(_ref) {
20
20
  let {
21
- accept,
21
+ accept = [],
22
22
  className,
23
23
  id,
24
24
  disabled,
25
- labelText,
26
- multiple,
25
+ labelText = 'Add file',
26
+ multiple = false,
27
27
  name,
28
- onAddFiles,
28
+ onAddFiles = () => {},
29
29
  onClick,
30
- pattern,
30
+ pattern = '.[0-9a-z]+$',
31
31
  // eslint-disable-next-line react/prop-types
32
32
  innerRef,
33
33
  ...rest
@@ -40,16 +40,13 @@ function FileUploaderDropContainer(_ref) {
40
40
  const [isActive, setActive] = useState(false);
41
41
  const dropareaClasses = cx(`${prefix}--file__drop-container`, `${prefix}--file-browse-btn`, {
42
42
  [`${prefix}--file__drop-container--drag-over`]: isActive,
43
- [`${prefix}--file-browse-btn--disabled`]: disabled,
44
- [className]: className
45
- });
43
+ [`${prefix}--file-browse-btn--disabled`]: disabled
44
+ }, className);
46
45
 
47
46
  /**
48
47
  * Filters the array of added files based on file type restrictions
49
- * @param {Event} event - Event object, used to get the list of files added
50
48
  */
51
- function validateFiles(event) {
52
- const transferredFiles = event.type === 'drop' ? [...event.dataTransfer.files] : [...event.target.files];
49
+ function validateFiles(transferredFiles) {
53
50
  if (!accept.length) {
54
51
  return transferredFiles;
55
52
  }
@@ -60,11 +57,10 @@ function FileUploaderDropContainer(_ref) {
60
57
  type: mimeType = ''
61
58
  } = curr;
62
59
  const fileExtensionRegExp = new RegExp(pattern, 'i');
63
- const hasFileExtension = fileExtensionRegExp.test(name);
64
- if (!hasFileExtension) {
60
+ const [fileExtension] = name.match(fileExtensionRegExp) ?? [];
61
+ if (fileExtension === undefined) {
65
62
  return acc;
66
63
  }
67
- const [fileExtension] = name.match(fileExtensionRegExp);
68
64
  if (acceptedTypes.has(mimeType) || acceptedTypes.has(fileExtension.toLowerCase())) {
69
65
  return acc.concat([curr]);
70
66
  }
@@ -73,7 +69,15 @@ function FileUploaderDropContainer(_ref) {
73
69
  }, []);
74
70
  }
75
71
  function handleChange(event) {
76
- const addedFiles = validateFiles(event);
72
+ const files = [...(event.target.files ?? [])];
73
+ const addedFiles = validateFiles(files);
74
+ return onAddFiles(event, {
75
+ addedFiles
76
+ });
77
+ }
78
+ function handleDrop(event) {
79
+ const files = [...event.dataTransfer.files];
80
+ const addedFiles = validateFiles(files);
77
81
  return onAddFiles(event, {
78
82
  addedFiles
79
83
  });
@@ -110,7 +114,7 @@ function FileUploaderDropContainer(_ref) {
110
114
  return;
111
115
  }
112
116
  setActive(false);
113
- handleChange(evt);
117
+ handleDrop(evt);
114
118
  }
115
119
  }, /*#__PURE__*/React__default.createElement("button", _extends({
116
120
  type: "button",
@@ -133,7 +137,7 @@ function FileUploaderDropContainer(_ref) {
133
137
  ref: inputRef,
134
138
  tabIndex: -1,
135
139
  disabled: disabled,
136
- accept: accept,
140
+ accept: accept.join(','),
137
141
  name: name,
138
142
  multiple: multiple,
139
143
  onChange: handleChange,
@@ -4,8 +4,8 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- /// <reference types="react" />
8
7
  import PropTypes from 'prop-types';
8
+ import React from 'react';
9
9
  import { ReactAttr } from '../../types/common';
10
10
  export interface FileUploaderItemProps extends ReactAttr<HTMLSpanElement> {
11
11
  /**
@@ -32,7 +32,7 @@ export interface FileUploaderItemProps extends ReactAttr<HTMLSpanElement> {
32
32
  * Event handler that is called after removing a file from the file uploader
33
33
  * The event handler signature looks like `onDelete(evt, { uuid })`
34
34
  */
35
- onDelete?: (event: any, opts: {
35
+ onDelete?: (event: React.SyntheticEvent<HTMLElement>, opts: {
36
36
  uuid: string;
37
37
  }) => void;
38
38
  /**
@@ -49,18 +49,7 @@ export interface FileUploaderItemProps extends ReactAttr<HTMLSpanElement> {
49
49
  */
50
50
  uuid?: string;
51
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;
52
+ declare function FileUploaderItem({ uuid, name, status, iconDescription, onDelete, invalid, errorSubject, errorBody, size, ...other }: FileUploaderItemProps): JSX.Element;
64
53
  declare namespace FileUploaderItem {
65
54
  var propTypes: {
66
55
  /**
@@ -19,9 +19,9 @@ function FileUploaderItem(_ref) {
19
19
  let {
20
20
  uuid,
21
21
  name,
22
- status,
22
+ status = 'uploading',
23
23
  iconDescription,
24
- onDelete,
24
+ onDelete = () => {},
25
25
  invalid,
26
26
  errorSubject,
27
27
  errorBody,
@@ -34,8 +34,8 @@ function FileUploaderItem(_ref) {
34
34
  } = useRef(uuid || uniqueId());
35
35
  const classes = cx(`${prefix}--file__selected-file`, {
36
36
  [`${prefix}--file__selected-file--invalid`]: invalid,
37
- [`${prefix}--file__selected-file--md`]: size === 'field' || size === 'md',
38
- [`${prefix}--file__selected-file--sm`]: size === 'small' || size === 'sm'
37
+ [`${prefix}--file__selected-file--md`]: size === 'md',
38
+ [`${prefix}--file__selected-file--sm`]: size === 'sm'
39
39
  });
40
40
  return /*#__PURE__*/React__default.createElement("span", _extends({
41
41
  className: classes
@@ -0,0 +1,40 @@
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
+ export interface FormLabelProps extends Omit<React.LabelHTMLAttributes<HTMLLabelElement>, 'htmlFor'> {
10
+ /**
11
+ * Specify the content of the form label
12
+ */
13
+ children?: React.ReactNode;
14
+ /**
15
+ * Provide a custom className to be applied to the containing <label> node
16
+ */
17
+ className?: string;
18
+ /**
19
+ * Provide a unique id for the given <FormLabel>
20
+ */
21
+ id?: string;
22
+ }
23
+ declare function FormLabel({ className: customClassName, children, id, ...rest }: FormLabelProps): JSX.Element;
24
+ declare namespace FormLabel {
25
+ var propTypes: {
26
+ /**
27
+ * Specify the content of the form label
28
+ */
29
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
30
+ /**
31
+ * Provide a custom className to be applied to the containing <label> node
32
+ */
33
+ className: PropTypes.Requireable<string>;
34
+ /**
35
+ * Provide a unique id for the given <FormLabel>
36
+ */
37
+ id: PropTypes.Requireable<string>;
38
+ };
39
+ }
40
+ export default FormLabel;
@@ -0,0 +1,9 @@
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 FormLabel from './FormLabel';
8
+ export default FormLabel;
9
+ export { FormLabel };