@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
@@ -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.
@@ -313,6 +313,8 @@ class DataTable extends React__default["default"].Component {
313
313
  } = _this.state;
314
314
  const totalSelected = _this.getSelectedRows().length;
315
315
  return {
316
+ onSelectAll: undefined,
317
+ totalCount: _this.state.rowIds.length || 0,
316
318
  ...props,
317
319
  shouldShowBatchActions: shouldShowBatchActions && totalSelected > 0,
318
320
  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;
@@ -26,16 +26,28 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
26
26
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
27
27
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
28
28
 
29
+ const TableBatchActionsTranslationKeys = ['carbon.table.batch.cancel', 'carbon.table.batch.items.selected', 'carbon.table.batch.item.selected', 'carbon.table.batch.selectAll'];
29
30
  const translationKeys = {
30
31
  'carbon.table.batch.cancel': 'Cancel',
31
32
  'carbon.table.batch.items.selected': 'items selected',
32
- 'carbon.table.batch.item.selected': 'item selected'
33
+ 'carbon.table.batch.item.selected': 'item selected',
34
+ 'carbon.table.batch.selectAll': 'Select all'
33
35
  };
34
- const translateWithId = (id, state) => {
36
+ const translateWithId = function (id) {
37
+ let {
38
+ totalSelected,
39
+ totalCount
40
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
41
+ totalSelected: 0,
42
+ totalCount: 0
43
+ };
35
44
  if (id === 'carbon.table.batch.cancel') {
36
45
  return translationKeys[id];
37
46
  }
38
- return `${state.totalSelected} ${translationKeys[id]}`;
47
+ if (id === 'carbon.table.batch.selectAll') {
48
+ return `${translationKeys[id]} (${totalCount})`;
49
+ }
50
+ return `${totalSelected} ${translationKeys[id]}`;
39
51
  };
40
52
  const TableBatchActions = _ref => {
41
53
  let {
@@ -43,11 +55,13 @@ const TableBatchActions = _ref => {
43
55
  children,
44
56
  shouldShowBatchActions,
45
57
  totalSelected,
58
+ totalCount,
46
59
  onCancel,
47
- translateWithId: t,
60
+ onSelectAll,
61
+ translateWithId: t = translateWithId,
48
62
  ...rest
49
63
  } = _ref;
50
- const [isScrolling, setIsScrolling] = React__default["default"].useState();
64
+ const [isScrolling, setIsScrolling] = React__default["default"].useState(false);
51
65
  const prefix = usePrefix.usePrefix();
52
66
  const batchActionsClasses = cx__default["default"]({
53
67
  [`${prefix}--batch-actions`]: true,
@@ -72,13 +86,20 @@ const TableBatchActions = _ref => {
72
86
  totalSelected
73
87
  }) : t('carbon.table.batch.item.selected', {
74
88
  totalSelected
89
+ }))), onSelectAll && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("span", {
90
+ className: `${prefix}--batch-summary__divider`
91
+ }, "|"), /*#__PURE__*/React__default["default"].createElement(Button["default"], {
92
+ onClick: onSelectAll,
93
+ tabIndex: shouldShowBatchActions ? 0 : -1
94
+ }, t('carbon.table.batch.selectAll', {
95
+ totalCount
75
96
  })))), /*#__PURE__*/React__default["default"].createElement(TableActionList["default"], null, children, /*#__PURE__*/React__default["default"].createElement(Button["default"], {
76
97
  className: `${prefix}--batch-summary__cancel`,
77
98
  tabIndex: shouldShowBatchActions ? 0 : -1,
78
99
  onClick: onCancel
79
100
  }, t('carbon.table.batch.cancel'))));
80
101
  };
81
- TableBatchActions.translationKeys = Object.keys(translationKeys);
102
+ TableBatchActions.translationKeys = TableBatchActionsTranslationKeys;
82
103
  TableBatchActions.propTypes = {
83
104
  children: PropTypes__default["default"].node,
84
105
  className: PropTypes__default["default"].string,
@@ -87,11 +108,22 @@ TableBatchActions.propTypes = {
87
108
  * through this component
88
109
  */
89
110
  onCancel: PropTypes__default["default"].func.isRequired,
111
+ /**
112
+ * Hook to listen for when the user initiates a select all
113
+ * request through this component. This _only_ controls the rendering
114
+ * of the `Select All` button and does not include built in functionality
115
+ */
116
+ onSelectAll: PropTypes__default["default"].func,
90
117
  /**
91
118
  * Boolean specifier for whether or not the batch action bar should be
92
119
  * displayed
93
120
  */
94
121
  shouldShowBatchActions: PropTypes__default["default"].bool,
122
+ /**
123
+ * Numeric representation of the total number of items in a table.
124
+ * This number is used in the select all button text
125
+ */
126
+ totalCount: PropTypes__default["default"].number,
95
127
  /**
96
128
  * Numeric representation of the total number of items selected in a table.
97
129
  * This number is used to derive the selection message
@@ -107,6 +139,5 @@ TableBatchActions.propTypes = {
107
139
  TableBatchActions.defaultProps = {
108
140
  translateWithId
109
141
  };
110
- var TableBatchActions$1 = TableBatchActions;
111
142
 
112
- exports["default"] = TableBatchActions$1;
143
+ exports["default"] = TableBatchActions;
@@ -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;
@@ -51,6 +51,7 @@ const TableToolbarSearch = _ref => {
51
51
  onBlur,
52
52
  onFocus,
53
53
  size = 'lg',
54
+ tabIndex,
54
55
  ...rest
55
56
  } = _ref;
56
57
  const {
@@ -64,18 +65,19 @@ const TableToolbarSearch = _ref => {
64
65
  const prefix = usePrefix.usePrefix();
65
66
  React.useEffect(() => {
66
67
  if (focusTarget) {
67
- focusTarget.current.querySelector('input').focus();
68
+ focusTarget.current?.querySelector?.('input')?.focus();
68
69
  setFocusTarget(null);
69
70
  }
70
71
  }, [focusTarget]);
71
72
  React.useEffect(() => {
72
73
  if (defaultValue) {
73
- onChangeProp('', defaultValue);
74
+ onChangeProp?.('', defaultValue);
74
75
  }
75
76
  },
76
77
  //eslint-disable-next-line react-hooks/exhaustive-deps
77
78
  []);
78
79
  const searchClasses = cx__default["default"](className, {
80
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79
81
  [searchContainerClass]: searchContainerClass,
80
82
  [`${prefix}--toolbar-search-container-active`]: expanded,
81
83
  [`${prefix}--toolbar-search-container-disabled`]: disabled,
@@ -113,6 +115,10 @@ const TableToolbarSearch = _ref => {
113
115
  onFocus: onFocus ? event => onFocus(event, handleExpand) : handleOnFocus,
114
116
  onBlur: onBlur ? event => onBlur(event, handleExpand) : handleOnBlur,
115
117
  size: size
118
+ // HTMLAttributes defines tabIndex as number | undefined but in reality it
119
+ // also accepts a string, so we cast here to convince Typescript this is okay.
120
+ ,
121
+ tabIndex: tabIndex
116
122
  }, rest));
117
123
  };
118
124
  TableToolbarSearch.propTypes = {
@@ -200,6 +206,5 @@ TableToolbarSearch.defaultProps = {
200
206
  persistent: false,
201
207
  onClear: () => {}
202
208
  };
203
- var TableToolbarSearch$1 = TableToolbarSearch;
204
209
 
205
- exports["default"] = TableToolbarSearch$1;
210
+ exports["default"] = TableToolbarSearch;
@@ -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
  /**
@@ -28,16 +28,16 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
28
28
 
29
29
  function FileUploaderDropContainer(_ref) {
30
30
  let {
31
- accept,
31
+ accept = [],
32
32
  className,
33
33
  id,
34
34
  disabled,
35
- labelText,
36
- multiple,
35
+ labelText = 'Add file',
36
+ multiple = false,
37
37
  name,
38
- onAddFiles,
38
+ onAddFiles = () => {},
39
39
  onClick,
40
- pattern,
40
+ pattern = '.[0-9a-z]+$',
41
41
  // eslint-disable-next-line react/prop-types
42
42
  innerRef,
43
43
  ...rest
@@ -50,16 +50,13 @@ function FileUploaderDropContainer(_ref) {
50
50
  const [isActive, setActive] = React.useState(false);
51
51
  const dropareaClasses = cx__default["default"](`${prefix}--file__drop-container`, `${prefix}--file-browse-btn`, {
52
52
  [`${prefix}--file__drop-container--drag-over`]: isActive,
53
- [`${prefix}--file-browse-btn--disabled`]: disabled,
54
- [className]: className
55
- });
53
+ [`${prefix}--file-browse-btn--disabled`]: disabled
54
+ }, className);
56
55
 
57
56
  /**
58
57
  * Filters the array of added files based on file type restrictions
59
- * @param {Event} event - Event object, used to get the list of files added
60
58
  */
61
- function validateFiles(event) {
62
- const transferredFiles = event.type === 'drop' ? [...event.dataTransfer.files] : [...event.target.files];
59
+ function validateFiles(transferredFiles) {
63
60
  if (!accept.length) {
64
61
  return transferredFiles;
65
62
  }
@@ -70,11 +67,10 @@ function FileUploaderDropContainer(_ref) {
70
67
  type: mimeType = ''
71
68
  } = curr;
72
69
  const fileExtensionRegExp = new RegExp(pattern, 'i');
73
- const hasFileExtension = fileExtensionRegExp.test(name);
74
- if (!hasFileExtension) {
70
+ const [fileExtension] = name.match(fileExtensionRegExp) ?? [];
71
+ if (fileExtension === undefined) {
75
72
  return acc;
76
73
  }
77
- const [fileExtension] = name.match(fileExtensionRegExp);
78
74
  if (acceptedTypes.has(mimeType) || acceptedTypes.has(fileExtension.toLowerCase())) {
79
75
  return acc.concat([curr]);
80
76
  }
@@ -83,7 +79,15 @@ function FileUploaderDropContainer(_ref) {
83
79
  }, []);
84
80
  }
85
81
  function handleChange(event) {
86
- const addedFiles = validateFiles(event);
82
+ const files = [...(event.target.files ?? [])];
83
+ const addedFiles = validateFiles(files);
84
+ return onAddFiles(event, {
85
+ addedFiles
86
+ });
87
+ }
88
+ function handleDrop(event) {
89
+ const files = [...event.dataTransfer.files];
90
+ const addedFiles = validateFiles(files);
87
91
  return onAddFiles(event, {
88
92
  addedFiles
89
93
  });
@@ -120,7 +124,7 @@ function FileUploaderDropContainer(_ref) {
120
124
  return;
121
125
  }
122
126
  setActive(false);
123
- handleChange(evt);
127
+ handleDrop(evt);
124
128
  }
125
129
  }, /*#__PURE__*/React__default["default"].createElement("button", _rollupPluginBabelHelpers["extends"]({
126
130
  type: "button",
@@ -143,7 +147,7 @@ function FileUploaderDropContainer(_ref) {
143
147
  ref: inputRef,
144
148
  tabIndex: -1,
145
149
  disabled: disabled,
146
- accept: accept,
150
+ accept: accept.join(','),
147
151
  name: name,
148
152
  multiple: multiple,
149
153
  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
  /**
@@ -29,9 +29,9 @@ function FileUploaderItem(_ref) {
29
29
  let {
30
30
  uuid,
31
31
  name,
32
- status,
32
+ status = 'uploading',
33
33
  iconDescription,
34
- onDelete,
34
+ onDelete = () => {},
35
35
  invalid,
36
36
  errorSubject,
37
37
  errorBody,
@@ -44,8 +44,8 @@ function FileUploaderItem(_ref) {
44
44
  } = React.useRef(uuid || uniqueId["default"]());
45
45
  const classes = cx__default["default"](`${prefix}--file__selected-file`, {
46
46
  [`${prefix}--file__selected-file--invalid`]: invalid,
47
- [`${prefix}--file__selected-file--md`]: size === 'field' || size === 'md',
48
- [`${prefix}--file__selected-file--sm`]: size === 'small' || size === 'sm'
47
+ [`${prefix}--file__selected-file--md`]: size === 'md',
48
+ [`${prefix}--file__selected-file--sm`]: size === 'sm'
49
49
  });
50
50
  return /*#__PURE__*/React__default["default"].createElement("span", _rollupPluginBabelHelpers["extends"]({
51
51
  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 };