@carbon/react 1.37.0-rc.0 → 1.37.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.
Files changed (68) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +9019 -0
  2. package/es/components/Button/Button.js +12 -12
  3. package/es/components/DataTable/DataTable.d.ts +4 -0
  4. package/es/components/DataTable/DataTable.js +2 -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/TableToolbarSearch.d.ts +176 -0
  8. package/es/components/DataTable/TableToolbarSearch.js +9 -4
  9. package/es/components/FileUploader/FileUploader.Skeleton.d.ts +1 -4
  10. package/es/components/FileUploader/FileUploaderDropContainer.d.ts +9 -17
  11. package/es/components/FileUploader/FileUploaderDropContainer.js +21 -17
  12. package/es/components/FileUploader/FileUploaderItem.d.ts +3 -14
  13. package/es/components/FileUploader/FileUploaderItem.js +4 -4
  14. package/es/components/FormLabel/FormLabel.d.ts +40 -0
  15. package/es/components/FormLabel/index.d.ts +9 -0
  16. package/es/components/MultiSelect/MultiSelect.d.ts +1 -3
  17. package/es/components/SkeletonPlaceholder/SkeletonPlaceholder.d.ts +24 -0
  18. package/es/components/SkeletonPlaceholder/SkeletonPlaceholder.js +3 -5
  19. package/es/components/SkeletonPlaceholder/index.d.ts +9 -0
  20. package/es/components/StructuredList/StructuredList.js +5 -2
  21. package/es/components/Tag/Tag.Skeleton.d.ts +35 -0
  22. package/es/components/Tag/Tag.d.ts +122 -0
  23. package/es/components/Tag/Tag.js +6 -6
  24. package/es/components/Tag/index.d.ts +11 -0
  25. package/es/components/TimePicker/TimePicker.js +8 -6
  26. package/es/components/Toggle/Toggle.Skeleton.js +1 -4
  27. package/es/components/Toggle/Toggle.js +1 -1
  28. package/es/components/ToggleSmall/ToggleSmall.Skeleton.js +0 -3
  29. package/es/components/UIShell/HeaderMenuItem.js +1 -2
  30. package/es/components/UIShell/Link.js +1 -2
  31. package/es/components/UIShell/SideNav.js +1 -3
  32. package/es/components/UIShell/index.d.ts +35 -0
  33. package/es/index.js +32 -32
  34. package/es/types/common.d.ts +7 -0
  35. package/lib/components/Button/Button.js +12 -12
  36. package/lib/components/DataTable/DataTable.d.ts +4 -0
  37. package/lib/components/DataTable/DataTable.js +2 -0
  38. package/lib/components/DataTable/TableBatchActions.d.ts +51 -0
  39. package/lib/components/DataTable/TableBatchActions.js +39 -8
  40. package/lib/components/DataTable/TableToolbarSearch.d.ts +176 -0
  41. package/lib/components/DataTable/TableToolbarSearch.js +9 -4
  42. package/lib/components/FileUploader/FileUploader.Skeleton.d.ts +1 -4
  43. package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +9 -17
  44. package/lib/components/FileUploader/FileUploaderDropContainer.js +21 -17
  45. package/lib/components/FileUploader/FileUploaderItem.d.ts +3 -14
  46. package/lib/components/FileUploader/FileUploaderItem.js +4 -4
  47. package/lib/components/FormLabel/FormLabel.d.ts +40 -0
  48. package/lib/components/FormLabel/index.d.ts +9 -0
  49. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -3
  50. package/lib/components/SkeletonPlaceholder/SkeletonPlaceholder.d.ts +24 -0
  51. package/lib/components/SkeletonPlaceholder/SkeletonPlaceholder.js +3 -5
  52. package/lib/components/SkeletonPlaceholder/index.d.ts +9 -0
  53. package/lib/components/StructuredList/StructuredList.js +5 -2
  54. package/lib/components/Tag/Tag.Skeleton.d.ts +35 -0
  55. package/lib/components/Tag/Tag.d.ts +122 -0
  56. package/lib/components/Tag/Tag.js +6 -6
  57. package/lib/components/Tag/index.d.ts +11 -0
  58. package/lib/components/TimePicker/TimePicker.js +8 -6
  59. package/lib/components/Toggle/Toggle.Skeleton.js +1 -4
  60. package/lib/components/Toggle/Toggle.js +1 -1
  61. package/lib/components/ToggleSmall/ToggleSmall.Skeleton.js +0 -3
  62. package/lib/components/UIShell/HeaderMenuItem.js +1 -2
  63. package/lib/components/UIShell/Link.js +1 -2
  64. package/lib/components/UIShell/SideNav.js +1 -3
  65. package/lib/components/UIShell/index.d.ts +35 -0
  66. package/lib/index.js +65 -65
  67. package/lib/types/common.d.ts +7 -0
  68. package/package.json +6 -5
@@ -113,17 +113,18 @@ const Button = /*#__PURE__*/React__default.forwardRef(function Button(_ref, ref)
113
113
  component = 'a';
114
114
  otherProps = anchorProps;
115
115
  }
116
- const Button = /*#__PURE__*/React__default.createElement(component, {
117
- onMouseEnter,
118
- onMouseLeave,
119
- onFocus,
120
- onBlur,
121
- onClick,
122
- ...rest,
123
- ...commonProps,
124
- ...otherProps
125
- }, assistiveText, children, buttonImage);
126
- if (hasIconOnly) {
116
+ if (!hasIconOnly) {
117
+ return /*#__PURE__*/React__default.createElement(component, {
118
+ onMouseEnter,
119
+ onMouseLeave,
120
+ onFocus,
121
+ onBlur,
122
+ onClick,
123
+ ...rest,
124
+ ...commonProps,
125
+ ...otherProps
126
+ }, assistiveText, children, buttonImage);
127
+ } else {
127
128
  let align = undefined;
128
129
  if (tooltipPosition === 'top' || tooltipPosition === 'bottom') {
129
130
  if (tooltipAlignment === 'center') {
@@ -152,7 +153,6 @@ const Button = /*#__PURE__*/React__default.forwardRef(function Button(_ref, ref)
152
153
  onClick: composeEventHandlers([onClick, handleClick])
153
154
  }, rest, commonProps, otherProps), iconOnlyImage ? iconOnlyImage : children);
154
155
  }
155
- return Button;
156
156
  });
157
157
  Button.displayName = 'Button';
158
158
  Button.propTypes = {
@@ -150,7 +150,9 @@ export interface DataTableRenderProps<RowType, ColTypes extends any[]> {
150
150
  [key: string]: unknown;
151
151
  }) => {
152
152
  onCancel: () => void;
153
+ onSelectAll?: () => void | undefined;
153
154
  shouldShowBatchActions: boolean;
155
+ totalCount: number;
154
156
  totalSelected: number;
155
157
  [key: string]: unknown;
156
158
  };
@@ -478,6 +480,8 @@ declare class DataTable<RowType, ColTypes extends any[]> extends React.Component
478
480
  shouldShowBatchActions: boolean;
479
481
  totalSelected: number;
480
482
  onCancel: () => void;
483
+ onSelectAll: undefined;
484
+ totalCount: number;
481
485
  };
482
486
  /**
483
487
  * Helper utility to get the Table Props.
@@ -303,6 +303,8 @@ class DataTable extends React__default.Component {
303
303
  } = _this.state;
304
304
  const totalSelected = _this.getSelectedRows().length;
305
305
  return {
306
+ onSelectAll: undefined,
307
+ totalCount: _this.state.rowIds.length || 0,
306
308
  ...props,
307
309
  shouldShowBatchActions: shouldShowBatchActions && totalSelected > 0,
308
310
  totalSelected,
@@ -0,0 +1,51 @@
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 React, { type MouseEventHandler } from 'react';
8
+ import type { InternationalProps } from '../../types/common';
9
+ declare const TableBatchActionsTranslationKeys: readonly ["carbon.table.batch.cancel", "carbon.table.batch.items.selected", "carbon.table.batch.item.selected", "carbon.table.batch.selectAll"];
10
+ export type TableBatchActionsTranslationKey = (typeof TableBatchActionsTranslationKeys)[number];
11
+ export interface TableBatchActionsTranslationArgs {
12
+ totalSelected?: number;
13
+ totalCount?: number;
14
+ }
15
+ export interface TableBatchActionsProps extends React.HTMLAttributes<HTMLDivElement>, InternationalProps<TableBatchActionsTranslationKey, TableBatchActionsTranslationArgs> {
16
+ /**
17
+ * Provide elements to be rendered inside of the component.
18
+ */
19
+ children?: React.ReactNode;
20
+ /**
21
+ * Hook required to listen for when the user initiates a cancel request
22
+ * through this component.
23
+ */
24
+ onCancel: MouseEventHandler<HTMLButtonElement>;
25
+ /**
26
+ * Hook to listen for when the user initiates a select all
27
+ * request through this component. This _only_ controls the rendering
28
+ * of the `Select All` button and does not include built in functionality
29
+ */
30
+ onSelectAll?: MouseEventHandler<HTMLButtonElement>;
31
+ /**
32
+ * Boolean specifier for whether or not the batch action bar should be
33
+ * displayed.
34
+ */
35
+ shouldShowBatchActions?: boolean;
36
+ /**
37
+ * Numeric representation of the total number of items selected in a table.
38
+ * This number is used to derive the selection message.
39
+ */
40
+ totalSelected: number;
41
+ /**
42
+ * Numeric representation of the total number of items in a table.
43
+ * This number is used in the select all button text
44
+ */
45
+ totalCount?: number;
46
+ }
47
+ export interface TableBatchActionsComponent extends React.FC<TableBatchActionsProps> {
48
+ translationKeys: ReadonlyArray<TableBatchActionsTranslationKey>;
49
+ }
50
+ declare const TableBatchActions: TableBatchActionsComponent;
51
+ export default TableBatchActions;
@@ -16,16 +16,28 @@ import '../Text/index.js';
16
16
  import { usePrefix } from '../../internal/usePrefix.js';
17
17
  import { Text } from '../Text/Text.js';
18
18
 
19
+ const TableBatchActionsTranslationKeys = ['carbon.table.batch.cancel', 'carbon.table.batch.items.selected', 'carbon.table.batch.item.selected', 'carbon.table.batch.selectAll'];
19
20
  const translationKeys = {
20
21
  'carbon.table.batch.cancel': 'Cancel',
21
22
  'carbon.table.batch.items.selected': 'items selected',
22
- 'carbon.table.batch.item.selected': 'item selected'
23
+ 'carbon.table.batch.item.selected': 'item selected',
24
+ 'carbon.table.batch.selectAll': 'Select all'
23
25
  };
24
- const translateWithId = (id, state) => {
26
+ const translateWithId = function (id) {
27
+ let {
28
+ totalSelected,
29
+ totalCount
30
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
31
+ totalSelected: 0,
32
+ totalCount: 0
33
+ };
25
34
  if (id === 'carbon.table.batch.cancel') {
26
35
  return translationKeys[id];
27
36
  }
28
- return `${state.totalSelected} ${translationKeys[id]}`;
37
+ if (id === 'carbon.table.batch.selectAll') {
38
+ return `${translationKeys[id]} (${totalCount})`;
39
+ }
40
+ return `${totalSelected} ${translationKeys[id]}`;
29
41
  };
30
42
  const TableBatchActions = _ref => {
31
43
  let {
@@ -33,11 +45,13 @@ const TableBatchActions = _ref => {
33
45
  children,
34
46
  shouldShowBatchActions,
35
47
  totalSelected,
48
+ totalCount,
36
49
  onCancel,
37
- translateWithId: t,
50
+ onSelectAll,
51
+ translateWithId: t = translateWithId,
38
52
  ...rest
39
53
  } = _ref;
40
- const [isScrolling, setIsScrolling] = React__default.useState();
54
+ const [isScrolling, setIsScrolling] = React__default.useState(false);
41
55
  const prefix = usePrefix();
42
56
  const batchActionsClasses = cx({
43
57
  [`${prefix}--batch-actions`]: true,
@@ -62,13 +76,20 @@ const TableBatchActions = _ref => {
62
76
  totalSelected
63
77
  }) : t('carbon.table.batch.item.selected', {
64
78
  totalSelected
79
+ }))), onSelectAll && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("span", {
80
+ className: `${prefix}--batch-summary__divider`
81
+ }, "|"), /*#__PURE__*/React__default.createElement(Button, {
82
+ onClick: onSelectAll,
83
+ tabIndex: shouldShowBatchActions ? 0 : -1
84
+ }, t('carbon.table.batch.selectAll', {
85
+ totalCount
65
86
  })))), /*#__PURE__*/React__default.createElement(TableActionList, null, children, /*#__PURE__*/React__default.createElement(Button, {
66
87
  className: `${prefix}--batch-summary__cancel`,
67
88
  tabIndex: shouldShowBatchActions ? 0 : -1,
68
89
  onClick: onCancel
69
90
  }, t('carbon.table.batch.cancel'))));
70
91
  };
71
- TableBatchActions.translationKeys = Object.keys(translationKeys);
92
+ TableBatchActions.translationKeys = TableBatchActionsTranslationKeys;
72
93
  TableBatchActions.propTypes = {
73
94
  children: PropTypes.node,
74
95
  className: PropTypes.string,
@@ -77,11 +98,22 @@ TableBatchActions.propTypes = {
77
98
  * through this component
78
99
  */
79
100
  onCancel: PropTypes.func.isRequired,
101
+ /**
102
+ * Hook to listen for when the user initiates a select all
103
+ * request through this component. This _only_ controls the rendering
104
+ * of the `Select All` button and does not include built in functionality
105
+ */
106
+ onSelectAll: PropTypes.func,
80
107
  /**
81
108
  * Boolean specifier for whether or not the batch action bar should be
82
109
  * displayed
83
110
  */
84
111
  shouldShowBatchActions: PropTypes.bool,
112
+ /**
113
+ * Numeric representation of the total number of items in a table.
114
+ * This number is used in the select all button text
115
+ */
116
+ totalCount: PropTypes.number,
85
117
  /**
86
118
  * Numeric representation of the total number of items selected in a table.
87
119
  * This number is used to derive the selection message
@@ -97,6 +129,5 @@ TableBatchActions.propTypes = {
97
129
  TableBatchActions.defaultProps = {
98
130
  translateWithId
99
131
  };
100
- var TableBatchActions$1 = TableBatchActions;
101
132
 
102
- export { TableBatchActions$1 as default };
133
+ export { TableBatchActions as default };
@@ -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 };
@@ -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