baseui 14.0.0 → 15.0.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 (162) hide show
  1. package/accordion/accordion.js +4 -4
  2. package/accordion/panel.d.ts +1 -1
  3. package/accordion/stateless-accordion.js +8 -8
  4. package/accordion/styled-components.js +1 -1
  5. package/accordion/types.d.ts +1 -1
  6. package/app-nav-bar/mobile-menu.js +3 -1
  7. package/banner/banner.js +3 -1
  8. package/banner/types.d.ts +2 -1
  9. package/bottom-navigation/bottom-navigation.js +4 -6
  10. package/bottom-navigation/selector.js +1 -1
  11. package/bottom-navigation/styled-components.js +1 -1
  12. package/button/button.d.ts +1 -3
  13. package/button/button.js +6 -2
  14. package/button/styled-components.d.ts +1 -0
  15. package/button/styled-components.js +61 -4
  16. package/button/types.d.ts +15 -3
  17. package/button-timed/button-timed.js +4 -5
  18. package/button-timed/styled-components.js +5 -3
  19. package/button-timed/types.d.ts +1 -1
  20. package/data-table/column-categorical.js +2 -2
  21. package/data-table/column-numerical.js +3 -18
  22. package/data-table/locale.d.ts +2 -0
  23. package/data-table/locale.js +2 -1
  24. package/data-table/stateful-container.js +1 -1
  25. package/data-table/stateful-data-table.js +7 -3
  26. package/data-table/types.d.ts +2 -0
  27. package/datepicker/day.js +2 -4
  28. package/datepicker/utils/date-helpers.d.ts +1 -0
  29. package/datepicker/utils/date-helpers.js +3 -0
  30. package/dialog/dialog.d.ts +1 -1
  31. package/dialog/dialog.js +38 -56
  32. package/dialog/styled-components.d.ts +2 -2
  33. package/dialog/styled-components.js +56 -24
  34. package/dialog/types.d.ts +5 -2
  35. package/dnd-list/list.js +1 -1
  36. package/dnd-list/stateful-list-container.js +1 -1
  37. package/file-uploader/constants.d.ts +18 -0
  38. package/file-uploader/constants.js +32 -0
  39. package/file-uploader/file-uploader.d.ts +2 -2
  40. package/file-uploader/file-uploader.js +406 -117
  41. package/file-uploader/index.d.ts +1 -1
  42. package/file-uploader/index.js +67 -18
  43. package/file-uploader/locale.d.ts +10 -10
  44. package/file-uploader/locale.js +5 -5
  45. package/file-uploader/styled-components.d.ts +13 -6
  46. package/file-uploader/styled-components.js +261 -64
  47. package/file-uploader/types.d.ts +49 -32
  48. package/file-uploader/utils.d.ts +5 -0
  49. package/file-uploader/utils.js +45 -0
  50. package/file-uploader-basic/file-uploader-basic.d.ts +10 -0
  51. package/file-uploader-basic/file-uploader-basic.js +173 -0
  52. package/file-uploader-basic/index.d.ts +4 -0
  53. package/file-uploader-basic/index.js +71 -0
  54. package/file-uploader-basic/locale.d.ts +15 -0
  55. package/file-uploader-basic/locale.js +21 -0
  56. package/file-uploader-basic/styled-components.d.ts +7 -0
  57. package/file-uploader-basic/styled-components.js +83 -0
  58. package/file-uploader-basic/types.d.ts +41 -0
  59. package/form-control/form-control.js +38 -3
  60. package/form-control/styled-components.d.ts +2 -0
  61. package/form-control/styled-components.js +22 -2
  62. package/form-control/types.d.ts +4 -0
  63. package/helpers/react-helpers.js +1 -1
  64. package/icon/circle-check-filled.d.ts +9 -0
  65. package/icon/circle-check-filled.js +50 -0
  66. package/icon/circle-exclamation-point-filled.d.ts +9 -0
  67. package/icon/circle-exclamation-point-filled.js +50 -0
  68. package/icon/hide.js +1 -1
  69. package/icon/icon-exports.d.ts +4 -0
  70. package/icon/icon-exports.js +28 -0
  71. package/icon/paperclip-filled.d.ts +9 -0
  72. package/icon/paperclip-filled.js +50 -0
  73. package/icon/show.js +1 -1
  74. package/icon/trash-can-filled.d.ts +9 -0
  75. package/{button-docked/button-docked.js → icon/trash-can-filled.js} +35 -16
  76. package/list/list-item.js +0 -2
  77. package/locale/en_US.js +14 -12
  78. package/locale/es_AR.js +9 -1
  79. package/locale/index.d.ts +3 -0
  80. package/locale/index.js +1 -0
  81. package/locale/tr_TR.js +9 -1
  82. package/locale/types.d.ts +2 -0
  83. package/message-card/message-card.js +2 -2
  84. package/message-card/utils.js +8 -3
  85. package/mobile-header/mobile-header.js +0 -1
  86. package/modal/modal-button.d.ts +1 -3
  87. package/package.json +5 -2
  88. package/page-control/page-control.js +1 -3
  89. package/payment-card/custom-cards.config.d.ts +1 -11
  90. package/payment-card/payment-card.js +1 -3
  91. package/phone-input/base-country-picker.js +2 -2
  92. package/phone-input/country-picker.js +0 -10
  93. package/progress-bar/progressbar-rounded.js +1 -1
  94. package/progress-bar/styled-components.js +8 -6
  95. package/rating/styled-components.js +3 -2
  96. package/rating/svg-icons.d.ts +5 -5
  97. package/rating/svg-icons.js +20 -20
  98. package/segmented-control/segmented-control.js +1 -2
  99. package/segmented-control/stateful-segmented-control.js +1 -2
  100. package/select/multi-value.js +1 -1
  101. package/sheet/sheet.js +1 -3
  102. package/snackbar/index.d.ts +1 -0
  103. package/snackbar/snackbar-context.d.ts +1 -2
  104. package/snackbar/snackbar-context.js +27 -21
  105. package/spinner/index.d.ts +4 -2
  106. package/stepper/stepper.js +29 -30
  107. package/styles/__mocks__/styled.js +0 -2
  108. package/styles/as-primary-export-hoc.js +0 -2
  109. package/styles/styled.js +0 -2
  110. package/styles/types.d.ts +7 -3
  111. package/system-banner/system-banner.js +1 -3
  112. package/tabs-motion/tabs.js +2 -2
  113. package/tag/constants.d.ts +5 -4
  114. package/tag/constants.js +7 -6
  115. package/tag/index.d.ts +1 -1
  116. package/tag/index.js +7 -7
  117. package/tag/styled-components.d.ts +1 -1
  118. package/tag/styled-components.js +137 -124
  119. package/tag/tag.js +2 -2
  120. package/tag/types.d.ts +9 -8
  121. package/tag/types.js +2 -2
  122. package/themes/dark-theme/color-component-tokens.d.ts +2 -2
  123. package/themes/dark-theme/color-component-tokens.js +279 -275
  124. package/themes/dark-theme/color-foundation-tokens.d.ts +3 -0
  125. package/themes/dark-theme/{color-tokens.js → color-foundation-tokens.js} +11 -14
  126. package/themes/dark-theme/color-semantic-tokens.d.ts +2 -2
  127. package/themes/dark-theme/color-semantic-tokens.js +52 -58
  128. package/themes/dark-theme/create-dark-theme.d.ts +1 -1
  129. package/themes/dark-theme/create-dark-theme.js +12 -32
  130. package/themes/dark-theme/dark-theme.js +4 -4
  131. package/themes/dark-theme/primitives.js +2 -2
  132. package/themes/light-theme/color-component-tokens.d.ts +2 -2
  133. package/themes/light-theme/color-component-tokens.js +287 -282
  134. package/themes/light-theme/color-foundation-tokens.d.ts +3 -0
  135. package/themes/light-theme/{color-tokens.js → color-foundation-tokens.js} +10 -13
  136. package/themes/light-theme/color-semantic-tokens.d.ts +2 -2
  137. package/themes/light-theme/color-semantic-tokens.js +50 -53
  138. package/themes/light-theme/create-light-theme.d.ts +1 -1
  139. package/themes/light-theme/create-light-theme.js +12 -32
  140. package/themes/light-theme/light-theme.js +4 -4
  141. package/themes/light-theme/primitives.js +2 -2
  142. package/themes/types.d.ts +74 -13
  143. package/themes/utils.d.ts +1 -1
  144. package/themes/utils.js +4 -4
  145. package/tile/tile-group.js +2 -2
  146. package/timezonepicker/update-tzdata.js +0 -1
  147. package/tokens/color-primitive-tokens.d.ts +5 -0
  148. package/tokens/color-primitive-tokens.js +301 -0
  149. package/tokens/index.d.ts +5 -4
  150. package/tokens/index.js +25 -3
  151. package/tokens/types.d.ts +170 -1
  152. package/button-docked/button-docked.d.ts +0 -4
  153. package/button-docked/index.d.ts +0 -3
  154. package/button-docked/index.js +0 -40
  155. package/button-docked/styled-components.d.ts +0 -5
  156. package/button-docked/styled-components.js +0 -55
  157. package/button-docked/types.d.ts +0 -14
  158. package/themes/dark-theme/color-tokens.d.ts +0 -3
  159. package/themes/light-theme/color-tokens.d.ts +0 -3
  160. package/tokens/colors.d.ts +0 -3
  161. package/tokens/colors.js +0 -125
  162. /package/{button-docked → file-uploader-basic}/types.js +0 -0
@@ -3,16 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = FileUploader;
7
7
  var React = _interopRequireWildcard(require("react"));
8
- var _reactDropzone = _interopRequireDefault(require("react-dropzone"));
9
- var _locale = require("../locale");
10
- var _styles = require("../styles");
8
+ var _fileUploaderBasic = require("../file-uploader-basic");
11
9
  var _button = require("../button");
12
- var _overrides = require("../helpers/overrides");
13
10
  var _progressBar = require("../progress-bar");
14
- var _spinner = require("../spinner");
11
+ var _overrides = require("../helpers/overrides");
15
12
  var _styledComponents = require("./styled-components");
13
+ var _constants = require("./constants");
14
+ var _utils = require("./utils");
15
+ var _circleCheckFilled = _interopRequireDefault(require("../icon/circle-check-filled"));
16
+ var _circleExclamationPointFilled = _interopRequireDefault(require("../icon/circle-exclamation-point-filled"));
17
+ var _paperclipFilled = _interopRequireDefault(require("../icon/paperclip-filled"));
18
+ var _trashCanFilled = _interopRequireDefault(require("../icon/trash-can-filled"));
19
+ var _upload = _interopRequireDefault(require("../icon/upload"));
20
+ var _styles = require("../styles");
21
+ var _locale = require("../locale");
22
+ var _reactUid = require("react-uid");
16
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
24
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
18
25
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -22,127 +29,409 @@ Copyright (c) Uber Technologies, Inc.
22
29
  This source code is licensed under the MIT license found in the
23
30
  LICENSE file in the root directory of this source tree.
24
31
  */
25
- // @ts-ignore
26
- function prependStyleProps(styleProps) {
27
- return Object.keys(styleProps).reduce((nextStyleProps, currentKey) => {
28
- // @ts-ignore
29
- nextStyleProps[`$${currentKey}`] = styleProps[currentKey];
30
- return nextStyleProps;
31
- }, {});
32
- }
33
32
  function FileUploader(props) {
33
+ if (props['onDrop']) {
34
+ console.error('onDrop is not a prop for FileUploader.');
35
+ }
36
+ if (props['onDropAccepted']) {
37
+ console.error('onDropAccepted is not a prop for FileUploader.');
38
+ }
39
+ if (props['onDropRejected']) {
40
+ console.error('onDropRejected is not a prop for FileUploader.');
41
+ }
42
+ if (props['progressAmount']) {
43
+ console.error('progressAmount is not a prop for FileUploader.');
44
+ }
45
+
46
+ // Isolate props that are not meant to be passed to FileUploaderBasic
34
47
  const {
35
- overrides = {}
48
+ fileRows,
49
+ hint,
50
+ itemPreview,
51
+ label,
52
+ maxFiles,
53
+ overrides = {},
54
+ processFileOnDrop,
55
+ progressAmountStartValue,
56
+ setFileRows,
57
+ ...fileUploaderBasicProps
36
58
  } = props;
37
- const [, theme] = (0, _styles.useStyletron)();
38
- const [Root, rootProps] = (0, _overrides.getOverrides)(overrides.Root, _styledComponents.StyledRoot);
39
- const [FileDragAndDrop, fileDragAndDropProps] = (0, _overrides.getOverrides)(overrides.FileDragAndDrop, _styledComponents.StyledFileDragAndDrop);
40
- const [ContentMessage, contentMessageProps] = (0, _overrides.getOverrides)(overrides.ContentMessage, _styledComponents.StyledContentMessage);
41
- const [ContentSeparator, contentSeparatorProps] = (0, _overrides.getOverrides)(overrides.ContentSeparator, _styledComponents.StyledContentSeparator);
42
- const [ErrorMessage, errorMessageProps] = (0, _overrides.getOverrides)(overrides.ErrorMessage, _styledComponents.StyledErrorMessage);
43
- const [HiddenInput, hiddenInputProps] = (0, _overrides.getOverrides)(overrides.HiddenInput, _styledComponents.StyledHiddenInput);
44
- const [ButtonComponent, buttonProps] = (0, _overrides.getOverrides)(overrides.ButtonComponent, _button.Button);
45
- const [RetryButtonComponent, retryButtonProps] = (0, _overrides.getOverrides)(overrides.RetryButtonComponent, _button.Button);
46
- const [CancelButtonComponent, cancelButtonProps] = (0, _overrides.getOverrides)(overrides.CancelButtonComponent, _button.Button);
47
- const [SpinnerComponent, spinnerProps] = (0, _overrides.getOverrides)(overrides.Spinner, _spinner.Spinner);
59
+ // Isolate styles that are not meant to be passed to FileUploaderBasic
60
+ const {
61
+ // Overrides for FileUploader
62
+ CircleCheckFilledIcon: OverridesCircleCheckFilledIcon,
63
+ CircleExclamationPointFilledIcon: OverridesCircleExclamationPointFilledIcon,
64
+ DeleteButtonComponent: OverridesDeleteButtonComponent,
65
+ FileRow: OverridesFileRow,
66
+ FileRowColumn: OverridesFileRowColumn,
67
+ FileRowContent: OverridesFileRowContent,
68
+ FileRowFileName: OverridesFileRowFileName,
69
+ FileRowText: OverridesFileRowText,
70
+ FileRowUploadMessage: OverridesFileRowUploadMessage,
71
+ FileRowUploadText: OverridesFileRowUploadText,
72
+ FileRows: OverridesFileRows,
73
+ Hint: OverridesHint,
74
+ ImagePreviewThumbnail: OverridesImagePreviewThumbnail,
75
+ ItemPreviewContainer: OverridesItemPreviewContainer,
76
+ Label: OverridesLabel,
77
+ PaperclipFilledIcon: OverridesPaperclipFilledIcon,
78
+ ParentRoot: OverridesParentRoot,
79
+ TrashCanFilledIcon: OverridesTrashCanFilledIcon,
80
+ // Overrides for FileUploaderBasic that are modified in this file
81
+ ButtonComponent,
82
+ ContentMessage,
83
+ FileDragAndDrop,
84
+ ...fileUploaderBasicOverrides
85
+ } = overrides;
86
+ const [css, theme] = (0, _styles.useStyletron)();
87
+
88
+ // Prepare icon overrides
89
+ const [CircleCheckFilledIcon, circleCheckFilledIconProps] = (0, _overrides.getOverrides)(overrides.CircleCheckFilledIcon, _circleCheckFilled.default);
90
+ const [CircleExclamationPointFilledIcon, circleExclamationPointFilledIconProps] = (0, _overrides.getOverrides)(OverridesCircleExclamationPointFilledIcon, _circleExclamationPointFilled.default);
91
+ const [PaperclipFilledIcon, paperclipFilledIconProps] = (0, _overrides.getOverrides)(OverridesPaperclipFilledIcon, _paperclipFilled.default);
92
+ const [TrashCanFilledIcon, trashCanFilledIconProps] = (0, _overrides.getOverrides)(OverridesTrashCanFilledIcon, _trashCanFilled.default);
93
+
94
+ // Prepare baseui component overrides
95
+ const [DeleteButtonComponent, deleteButtonProps] = (0, _overrides.getOverrides)(OverridesDeleteButtonComponent, _button.Button);
48
96
  const [ProgressBarComponent, progressBarProps] = (0, _overrides.getOverrides)(overrides.ProgressBar, _progressBar.ProgressBar);
49
- const afterFileDrop = !!(props.progressAmount || props.progressMessage || props.errorMessage);
50
- let accept;
51
- if (Array.isArray(props.accept)) {
52
- accept = props.accept.join(',');
53
- } else if (typeof props.accept === 'string') {
54
- accept = props.accept;
55
- }
56
- return /*#__PURE__*/React.createElement(_reactDropzone.default, _extends({}, props, {
57
- accept: accept,
58
- disabled: props.disabled || afterFileDrop
59
- }), renderProps => {
60
- const {
61
- getRootProps,
62
- getInputProps,
63
- open,
64
- ...styleProps
65
- } = renderProps;
66
- const prefixedStyledProps = prependStyleProps({
67
- ...styleProps,
68
- isDisabled: props.disabled,
69
- afterFileDrop
97
+
98
+ // Prepare styled component overrides
99
+ const [FileRow, fileRowProps] = (0, _overrides.getOverrides)(OverridesFileRow, _styledComponents.StyledFileRow);
100
+ const [FileRowColumn, fileRowColumnProps] = (0, _overrides.getOverrides)(OverridesFileRowColumn, _styledComponents.StyledFileRowColumn);
101
+ const [FileRowContent, fileRowContentProps] = (0, _overrides.getOverrides)(OverridesFileRowContent, _styledComponents.StyledFileRowContent);
102
+ const [FileRowFileName, fileRowFileNameProps] = (0, _overrides.getOverrides)(OverridesFileRowFileName, _styledComponents.StyledFileRowFileName);
103
+ const [FileRowText, fileRowTextProps] = (0, _overrides.getOverrides)(OverridesFileRowText, _styledComponents.StyledFileRowText);
104
+ const [FileRowUploadMessage, fileRowUploadMessageProps] = (0, _overrides.getOverrides)(OverridesFileRowUploadMessage, _styledComponents.StyledFileRowUploadMessage);
105
+ const [FileRowUploadText, fileRowUploadTextProps] = (0, _overrides.getOverrides)(OverridesFileRowUploadText, _styledComponents.StyledFileRowUploadText);
106
+ const [FileRows, fileRowsProps] = (0, _overrides.getOverrides)(OverridesFileRows, _styledComponents.StyledFileRows);
107
+ const [Hint, hintProps] = (0, _overrides.getOverrides)(OverridesHint, _styledComponents.StyledHint);
108
+ const [ImagePreviewThumbnail, imagePreviewThumbnailProps] = (0, _overrides.getOverrides)(OverridesImagePreviewThumbnail, _styledComponents.StyledImagePreviewThumbnail);
109
+ const [ItemPreviewContainer, itemPreviewContainerProps] = (0, _overrides.getOverrides)(OverridesItemPreviewContainer, _styledComponents.StyledItemPreviewContainer);
110
+ const [Label, labelProps] = (0, _overrides.getOverrides)(OverridesLabel, _styledComponents.StyledLabel);
111
+ const [ParentRoot, parentRootProps] = (0, _overrides.getOverrides)(OverridesParentRoot, _styledComponents.StyledParentRoot);
112
+ const onDrop = React.useCallback((acceptedFiles, rejectedFiles) => {
113
+ const newFiles = acceptedFiles.concat(rejectedFiles);
114
+ let newFileRows = [...props.fileRows];
115
+ newFiles.forEach(file => {
116
+ newFileRows.push({
117
+ errorMessage: null,
118
+ file,
119
+ id: (0, _reactUid.uid)(file),
120
+ imagePreviewThumbnail: '',
121
+ progressAmount: progressAmountStartValue ?? _constants.PROGRESS_AMOUNT_LOADING,
122
+ status: _constants.FILE_STATUS.added
123
+ });
124
+ props.setFileRows([...newFileRows]);
70
125
  });
71
- const getRootPropsArgs = {
72
- ...(props.disableClick ? {
73
- onClick: evt => evt.preventDefault()
74
- } : {}),
75
- tabIndex: -1
76
- };
77
- return /*#__PURE__*/React.createElement(_locale.LocaleContext.Consumer, null, locale => /*#__PURE__*/React.createElement(Root, _extends({
78
- "data-baseweb": "file-uploader"
79
- }, prefixedStyledProps, rootProps), /*#__PURE__*/React.createElement(FileDragAndDrop, _extends({}, getRootProps(getRootPropsArgs), prefixedStyledProps, fileDragAndDropProps), !afterFileDrop && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentMessage, _extends({}, prefixedStyledProps, contentMessageProps), locale.fileuploader.dropFilesToUpload), /*#__PURE__*/React.createElement(ContentSeparator, _extends({}, prefixedStyledProps, contentSeparatorProps), locale.fileuploader.or), /*#__PURE__*/React.createElement(ButtonComponent, _extends({
80
- disabled: props.disabled,
81
- kind: _button.KIND.secondary,
82
- shape: _button.SHAPE.pill,
83
- size: _button.SIZE.compact,
84
- onClick: open,
85
- role: "button",
86
- overrides: {
87
- BaseButton: {
88
- // @ts-ignore
89
- style: ({
90
- $theme
91
- }) => ({
92
- marginTop: $theme.sizing.scale500
93
- })
94
- }
126
+ newFileRows.forEach((fileRow, index) => {
127
+ if (fileRow.status === _constants.FILE_STATUS.added) {
128
+ let reader = new FileReader();
129
+ reader.onerror = () => {
130
+ newFileRows[index].errorMessage = 'cannot read file';
131
+ newFileRows[index].status = _constants.FILE_STATUS.error;
132
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
133
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.ADDITION, `${newFileRows[index].file.name} added, upload failed: ${newFileRows[index].errorMessage}`);
134
+ props.setFileRows([...newFileRows]);
135
+ };
136
+ reader.onload = event => {
137
+ if (newFileRows[index].file.type.startsWith('image/')) {
138
+ newFileRows[index].imagePreviewThumbnail = event.target?.result;
139
+ props.setFileRows([...newFileRows]);
140
+ }
141
+ if (props.maxFiles !== undefined && Number.isInteger(props.maxFiles) && index >= props.maxFiles) {
142
+ // If too many files
143
+ newFileRows[index].errorMessage = `cannot process more than ${props.maxFiles} file(s)`;
144
+ newFileRows[index].status = _constants.FILE_STATUS.error;
145
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
146
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.ADDITION, `${newFileRows[index].file.name} added, upload failed: ${newFileRows[index].errorMessage}`);
147
+ props.setFileRows([...newFileRows]);
148
+ } else if (props.minSize !== undefined && Number.isInteger(props.minSize) && props.minSize > fileRow.file.size) {
149
+ // If file size is too small
150
+ newFileRows[index].errorMessage = `file size must be greater than ${(0, _utils.formatBytes)(props.minSize)}`;
151
+ newFileRows[index].status = _constants.FILE_STATUS.error;
152
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
153
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.ADDITION, `${newFileRows[index].file.name} added, upload failed: ${newFileRows[index].errorMessage}`);
154
+ props.setFileRows([...newFileRows]);
155
+ } else if (props.maxSize !== undefined && Number.isInteger(props.maxSize) && props.maxSize < fileRow.file.size) {
156
+ // If file size is too big
157
+ newFileRows[index].errorMessage = `file size must be less than ${(0, _utils.formatBytes)(props.maxSize)}`;
158
+ newFileRows[index].status = _constants.FILE_STATUS.error;
159
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
160
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.ADDITION, `${newFileRows[index].file.name} added, upload failed: ${newFileRows[index].errorMessage}`);
161
+ props.setFileRows([...newFileRows]);
162
+ } else if (index >= newFileRows.length - rejectedFiles.length) {
163
+ // If file was rejected by dropzone (e.g. wrong file type)
164
+ newFileRows[index].errorMessage = fileRow.file.type ? `file type of ${fileRow.file.type} is not accepted` : 'file type is not accepted';
165
+ newFileRows[index].status = _constants.FILE_STATUS.error;
166
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
167
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.ADDITION, `${newFileRows[index].file.name} added, upload failed: ${newFileRows[index].errorMessage}`);
168
+ props.setFileRows([...newFileRows]);
169
+ } else if (props.processFileOnDrop) {
170
+ // If caller passed in file process function
171
+ props.processFileOnDrop(fileRow.file, fileRow.id, newFileRows).then(({
172
+ errorMessage,
173
+ fileInfo
174
+ }) => {
175
+ if (fileInfo) {
176
+ newFileRows[index].fileInfo = fileInfo;
177
+ }
178
+ if (errorMessage) {
179
+ newFileRows[index].errorMessage = errorMessage;
180
+ newFileRows[index].status = _constants.FILE_STATUS.error;
181
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
182
+ } else {
183
+ newFileRows[index].status = _constants.FILE_STATUS.processed;
184
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
185
+ }
186
+ }).catch(error => {
187
+ console.error('error with processFileOnDrop', error);
188
+ newFileRows[index].errorMessage = 'unknown processing error';
189
+ newFileRows[index].status = _constants.FILE_STATUS.error;
190
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
191
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.ADDITION, `${newFileRows[index].file.name} added, upload failed: ${newFileRows[index].errorMessage}`);
192
+ }).finally(() => {
193
+ props.setFileRows([...newFileRows]);
194
+ });
195
+ } else {
196
+ // If no errors and no file process function
197
+ newFileRows[index].status = _constants.FILE_STATUS.processed;
198
+ newFileRows[index].progressAmount = _constants.PROGRESS_AMOUNT_LOADING_COMPLETE;
199
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.ADDITION, `${newFileRows[index].file.name} added, upload successful`);
200
+ props.setFileRows([...newFileRows]);
201
+ }
202
+ };
203
+ reader.readAsDataURL(fileRow.file);
95
204
  }
96
- }, prefixedStyledProps, buttonProps), locale.fileuploader.browseFiles)), afterFileDrop && /*#__PURE__*/React.createElement(React.Fragment, null, typeof props.progressAmount === 'number' ? /*#__PURE__*/React.createElement(ProgressBarComponent, _extends({
97
- value: props.progressAmount,
98
- overrides: {
99
- BarProgress: {
100
- // @ts-ignore
101
- style: ({
102
- $theme
103
- }) => ({
104
- backgroundColor: props.errorMessage ? $theme.colors.negative : $theme.colors.accent
105
- })
205
+ });
206
+ }, [props]);
207
+ const removeFileRow = event => {
208
+ event.preventDefault();
209
+ const indexOfFileRowToRemove = Number(event?.currentTarget?.getAttribute('index'));
210
+ (0, _utils.handleAriaLiveUpdates)(_constants.ARIA_LIVE_ELEMENT_ID.REMOVAL, `${props.fileRows[indexOfFileRowToRemove].file.name} removed`);
211
+ props.setFileRows([...props.fileRows.toSpliced(indexOfFileRowToRemove, 1)]);
212
+ const label = document.querySelector('[data-baseweb="file-uploader-label"]');
213
+ if (label) {
214
+ label.focus();
215
+ }
216
+ };
217
+ const noFilesAreLoading = React.useMemo(() => !props.fileRows.find(fileRow => fileRow.status === _constants.FILE_STATUS.added), [props.fileRows]);
218
+ return /*#__PURE__*/React.createElement(_locale.LocaleContext.Consumer, null, locale => /*#__PURE__*/React.createElement(ParentRoot, _extends({
219
+ "data-baseweb": "file-uploader-parent-root"
220
+ }, parentRootProps), /*#__PURE__*/React.createElement("span", {
221
+ "aria-live": "assertive",
222
+ "aria-relevant": "additions",
223
+ className: css({
224
+ top: 0,
225
+ left: '-4px',
226
+ width: '1px',
227
+ height: '1px',
228
+ position: 'absolute',
229
+ overflow: 'hidden'
230
+ }),
231
+ id: _constants.ARIA_LIVE_ELEMENT_ID.ADDITION
232
+ }), /*#__PURE__*/React.createElement("span", {
233
+ "aria-live": "polite",
234
+ "aria-relevant": "additions",
235
+ className: css({
236
+ top: 0,
237
+ left: '-2px',
238
+ width: '1px',
239
+ height: '1px',
240
+ position: 'absolute',
241
+ overflow: 'hidden'
242
+ }),
243
+ id: _constants.ARIA_LIVE_ELEMENT_ID.REMOVAL
244
+ }), props.label && /*#__PURE__*/React.createElement(Label, _extends({
245
+ "data-baseweb": "file-uploader-label",
246
+ tabIndex: -1
247
+ }, labelProps, {
248
+ $disabled: !!props.disabled
249
+ }), props.label), /*#__PURE__*/React.createElement(_fileUploaderBasic.FileUploaderBasic, _extends({
250
+ buttonIcon: () => /*#__PURE__*/React.createElement(_upload.default, {
251
+ "aria-hidden": 'true'
252
+ }),
253
+ buttonText: locale.fileuploader.buttonText,
254
+ contentMessage: locale.fileuploader.contentMessage,
255
+ overrides: {
256
+ ButtonComponent: {
257
+ props: {
258
+ 'aria-describedby': 'file-uploader-hint',
259
+ shape: _button.SHAPE.default,
260
+ size: _button.SIZE.default,
261
+ ...props.overrides?.ButtonComponent?.props,
262
+ style: {
263
+ marginTop: 0,
264
+ ...(0, _utils.destructureStyleOverride)(
265
+ // @ts-expect-error
266
+ props.overrides?.ButtonComponent?.props?.style, theme)
267
+ },
268
+ overrides: {
269
+ // @ts-expect-error
270
+ ...props.overrides?.ButtonComponent?.props?.overrides,
271
+ BaseButton: {
272
+ // @ts-expect-error
273
+ ...props.overrides?.ButtonComponent?.props?.overrides?.BaseButton,
274
+ style: {
275
+ backgroundColor: theme.colors.backgroundPrimary,
276
+ height: theme.sizing.scale950,
277
+ display: 'flex',
278
+ flexDirection: 'row',
279
+ gap: '8px',
280
+ ...theme.typography.LabelSmall,
281
+ ...(0, _utils.destructureStyleOverride)(
282
+ // @ts-expect-error
283
+ props.overrides?.ButtonComponent?.props?.overrides?.BaseButton?.style, theme)
284
+ }
285
+ }
286
+ }
287
+ }
288
+ },
289
+ ContentMessage: {
290
+ style: {
291
+ ...theme.typography.ParagraphSmall,
292
+ color: theme.colors.contentTertiary,
293
+ ...(0, _utils.destructureStyleOverride)(props.overrides?.ContentMessage?.style, theme)
106
294
  }
107
- }
108
- }, progressBarProps)) : props.errorMessage ? null : /*#__PURE__*/React.createElement(SpinnerComponent, _extends({
109
- $size: _spinner.SIZE.medium,
110
- $style: {
111
- marginBottom: theme.sizing.scale300
112
- }
113
- }, spinnerProps)), (props.errorMessage || props.progressMessage) && props.errorMessage ? /*#__PURE__*/React.createElement(ErrorMessage, _extends({}, prefixedStyledProps, errorMessageProps), props.errorMessage) : /*#__PURE__*/React.createElement(ContentMessage, _extends({}, prefixedStyledProps, contentMessageProps), props.progressMessage), props.errorMessage ? /*#__PURE__*/React.createElement(RetryButtonComponent, _extends({
114
- kind: _button.KIND.tertiary,
115
- onClick: () => {
116
- props.onRetry && props.onRetry();
117
295
  },
118
- "aria-invalid": Boolean(props.errorMessage),
119
- "aria-describedby": props['aria-describedby'],
120
- "aria-errormessage": props.errorMessage
121
- }, retryButtonProps), locale.fileuploader.retry) : /*#__PURE__*/React.createElement(CancelButtonComponent, _extends({
122
- kind: _button.KIND.tertiary,
123
- onClick: () => {
124
- props.onCancel && props.onCancel();
296
+ FileDragAndDrop: {
297
+ style: fileDragAndDropProps => ({
298
+ backgroundColor: fileDragAndDropProps.$theme.colors.fileUploaderBackgroundColor,
299
+ borderColor: fileDragAndDropProps.$isDragActive ? fileDragAndDropProps.$theme.colors.borderSelected : fileDragAndDropProps.$theme.colors.fileUploaderBorderColorDefault,
300
+ borderStyle: 'solid',
301
+ borderWidth: '3px',
302
+ flexDirection: 'row',
303
+ flexWrap: 'wrap',
304
+ gap: theme.sizing.scale300,
305
+ paddingBottom: theme.sizing.scale600,
306
+ paddingLeft: theme.sizing.scale600,
307
+ paddingRight: theme.sizing.scale600,
308
+ paddingTop: theme.sizing.scale600,
309
+ ...(0, _utils.destructureStyleOverride)(props.overrides?.FileDragAndDrop?.style, theme)
310
+ })
125
311
  },
126
- "aria-describedby": props['aria-describedby'],
127
- overrides: {
128
- BaseButton: {
129
- // @ts-ignore
130
- style: ({
131
- $theme
132
- }) => ({
133
- color: $theme.colors.contentNegative
134
- })
312
+ Root: {
313
+ style: {
314
+ marginBottom: theme.sizing.scale300,
315
+ ...(0, _utils.destructureStyleOverride)(props.overrides?.Root?.style, theme)
135
316
  }
317
+ },
318
+ ...fileUploaderBasicOverrides
319
+ },
320
+ swapButtonAndMessage: true
321
+ }, fileUploaderBasicProps, {
322
+ // Disable uploads while files are loading, even if application passes disabled as false
323
+ disabled: !!props.disabled ? props.disabled : !!props.fileRows.find(fileRow => fileRow.status === _constants.FILE_STATUS.added)
324
+ // Implement or use no-op callbacks to prevent consumers from passing them in
325
+ ,
326
+ onDrop: onDrop,
327
+ onDropAccepted: _ => {},
328
+ onDropRejected: _ => {},
329
+ progressAmount: undefined
330
+ })), props.fileRows.length > 0 && /*#__PURE__*/React.createElement(FileRows, _extends({
331
+ "data-baseweb": "file-uploader-file-rows"
332
+ }, fileRowsProps), props.fileRows.map((fileRow, index) => /*#__PURE__*/React.createElement(FileRow, _extends({
333
+ id: `file-uploader-file-row-${index}`,
334
+ "data-baseweb": "file-uploader-file-row",
335
+ key: fileRow.id
336
+ }, fileRowProps), props.itemPreview && /*#__PURE__*/React.createElement(ItemPreviewContainer, _extends({
337
+ "aria-hidden": 'true',
338
+ "data-baseweb": "file-uploader-item-preview-container"
339
+ }, itemPreviewContainerProps), fileRow.imagePreviewThumbnail ? /*#__PURE__*/React.createElement(ImagePreviewThumbnail, _extends({
340
+ alt: fileRow.file.name,
341
+ "data-baseweb": "file-uploader-image-preview-thumbnail",
342
+ src: fileRow.imagePreviewThumbnail
343
+ }, imagePreviewThumbnailProps)) : /*#__PURE__*/React.createElement(PaperclipFilledIcon, _extends({
344
+ "data-baseweb": "file-uploader-paperclip-filled-icon",
345
+ color: theme.colors.contentSecondary
346
+ }, paperclipFilledIconProps))), /*#__PURE__*/React.createElement(FileRowColumn, _extends({
347
+ "data-baseweb": "file-uploader-file-row-column"
348
+ }, fileRowColumnProps), /*#__PURE__*/React.createElement(FileRowContent, _extends({
349
+ "data-baseweb": "file-uploader-file-row-content"
350
+ }, fileRowContentProps), /*#__PURE__*/React.createElement(FileRowText, _extends({
351
+ "data-baseweb": "file-uploader-file-row-text"
352
+ }, fileRowTextProps), /*#__PURE__*/React.createElement(FileRowFileName, _extends({
353
+ "data-baseweb": "file-uploader-file-row-file-name"
354
+ }, fileRowFileNameProps), fileRow.file.name), /*#__PURE__*/React.createElement(FileRowUploadMessage, _extends({
355
+ "data-baseweb": "file-uploader-file-row-upload-message",
356
+ $color: (0, _constants.FILE_STATUS_TO_COLOR_MAP)(theme)[fileRow.status]
357
+ }, fileRowUploadMessageProps), fileRow.status === _constants.FILE_STATUS.error && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CircleExclamationPointFilledIcon, _extends({
358
+ "aria-hidden": 'true',
359
+ color: (0, _constants.FILE_STATUS_TO_COLOR_MAP)(theme)[fileRow.status],
360
+ "data-baseweb": "file-uploader-circle-exclamation-point-filled-icon",
361
+ title: fileRow.status
362
+ }, circleExclamationPointFilledIconProps)), /*#__PURE__*/React.createElement(FileRowUploadText, _extends({
363
+ "aria-errormessage": fileRow.errorMessage,
364
+ "aria-invalid": true,
365
+ "data-baseweb": "file-uploader-file-row-upload-message-text",
366
+ id: `file-uploader-file-row-upload-message-text-${index}`
367
+ }, fileRowUploadTextProps), locale.fileuploader.error, fileRow.errorMessage)), fileRow.status === _constants.FILE_STATUS.processed && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CircleCheckFilledIcon, _extends({
368
+ "aria-hidden": 'true',
369
+ color: (0, _constants.FILE_STATUS_TO_COLOR_MAP)(theme)[fileRow.status],
370
+ "data-baseweb": "file-uploader-circle-check-filled-icon",
371
+ title: fileRow.status
372
+ }, circleCheckFilledIconProps)), /*#__PURE__*/React.createElement(FileRowUploadText, _extends({
373
+ "data-baseweb": "file-uploader-file-row-upload-message-text"
374
+ }, fileRowUploadTextProps), locale.fileuploader.processed)), fileRow.status === _constants.FILE_STATUS.added && /*#__PURE__*/React.createElement(FileRowUploadText, _extends({
375
+ $color: theme.colors.contentTertiary,
376
+ "data-baseweb": "file-uploader-file-row-upload-message-text"
377
+ }, fileRowUploadTextProps), locale.fileuploader.added))), noFilesAreLoading && /*#__PURE__*/React.createElement(DeleteButtonComponent, _extends({
378
+ "aria-label": `Remove ${fileRow.file.name}`,
379
+ "data-baseweb": "file-uploader-delete-button-component",
380
+ index: index,
381
+ onClick: removeFileRow,
382
+ kind: _button.KIND.tertiary,
383
+ shape: _button.SHAPE.circle,
384
+ size: _button.SIZE.compact
385
+ }, deleteButtonProps), /*#__PURE__*/React.createElement(TrashCanFilledIcon, _extends({
386
+ "aria-hidden": 'true',
387
+ "data-baseweb": "file-uploader-trash-can-filled-icon",
388
+ overrides: {
389
+ Svg: {
390
+ style: {
391
+ verticalAlign: 'middle'
392
+ }
393
+ }
394
+ },
395
+ size: theme.sizing.scale600,
396
+ title: 'remove'
397
+ }, trashCanFilledIconProps)))), /*#__PURE__*/React.createElement(ProgressBarComponent, _extends({
398
+ "aria-hidden": 'true',
399
+ "data-baseweb": "file-uploader-progress-bar",
400
+ overrides: {
401
+ Bar: {
402
+ style: {
403
+ marginTop: theme.sizing.scale0,
404
+ marginBottom: theme.sizing.scale0,
405
+ marginLeft: 0,
406
+ marginRight: 0
407
+ }
408
+ },
409
+ BarContainer: {
410
+ style: {
411
+ marginTop: 0,
412
+ marginBottom: 0,
413
+ marginLeft: 0,
414
+ marginRight: 0
415
+ }
416
+ },
417
+ BarProgress: {
418
+ // @ts-ignore
419
+ style: ({
420
+ $theme
421
+ }) => ({
422
+ backgroundColor: (0, _constants.FILE_STATUS_TO_COLOR_MAP)($theme)[fileRow.status]
423
+ })
136
424
  }
137
- }, cancelButtonProps), locale.fileuploader.cancel))), /*#__PURE__*/React.createElement(HiddenInput, _extends({
138
- "aria-invalid": Boolean(props.errorMessage) || null,
139
- "aria-describedby": props['aria-describedby'],
140
- "aria-errormessage": props.errorMessage || null
141
- }, getInputProps(), prefixedStyledProps, hiddenInputProps))));
142
- });
425
+ },
426
+ size: _progressBar.SIZE.small,
427
+ value: fileRow.progressAmount ?? _constants.PROGRESS_AMOUNT_LOADING_COMPLETE
428
+ }, progressBarProps)))))), props.hint && /*#__PURE__*/React.createElement(Hint, _extends({
429
+ "data-baseweb": "file-uploader-hint",
430
+ id: "file-uploader-hint",
431
+ $fileCount: props.fileRows.length
432
+ }, hintProps), props.hint)));
143
433
  }
144
434
  FileUploader.defaultProps = {
145
- disableClick: true,
146
- overrides: {}
147
- };
148
- var _default = exports.default = FileUploader;
435
+ fileRows: [],
436
+ setFileRows: () => {}
437
+ };
@@ -1,4 +1,4 @@
1
1
  export { default as FileUploader } from './file-uploader';
2
- export { StyledRoot, StyledFileDragAndDrop, StyledContentMessage, StyledContentSeparator, StyledErrorMessage, StyledHiddenInput, } from './styled-components';
2
+ export { StyledFileRow, StyledFileRowColumn, StyledFileRowContent, StyledFileRowFileName, StyledFileRowText, StyledFileRowUploadMessage, StyledFileRowUploadText, StyledFileRows, StyledHint, StyledImagePreviewThumbnail, StyledItemPreviewContainer, StyledLabel, StyledParentRoot, } from './styled-components';
3
3
  export * from './types';
4
4
  export type { FileUploaderLocale } from './locale';