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