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.
- package/accordion/accordion.js +4 -4
- package/accordion/panel.d.ts +1 -1
- package/accordion/styled-components.js +1 -1
- package/accordion/types.d.ts +1 -1
- package/app-nav-bar/mobile-menu.js +3 -1
- package/banner/banner.js +3 -1
- package/banner/types.d.ts +2 -1
- package/bottom-navigation/bottom-navigation.js +3 -1
- package/bottom-navigation/selector.js +1 -1
- package/bottom-navigation/styled-components.js +1 -1
- package/button/button.d.ts +1 -3
- package/button/button.js +6 -2
- package/button/styled-components.d.ts +1 -0
- package/button/styled-components.js +61 -4
- package/button/types.d.ts +15 -3
- package/button-timed/button-timed.js +4 -5
- package/button-timed/styled-components.js +5 -3
- package/button-timed/types.d.ts +1 -1
- package/data-table/column-categorical.js +2 -2
- package/data-table/locale.d.ts +2 -0
- package/data-table/locale.js +2 -1
- package/data-table/stateful-container.js +1 -1
- package/data-table/stateful-data-table.js +7 -3
- package/data-table/types.d.ts +2 -0
- package/datepicker/day.js +2 -4
- package/datepicker/utils/date-helpers.d.ts +1 -0
- package/datepicker/utils/date-helpers.js +3 -0
- package/dialog/dialog.d.ts +1 -1
- package/dialog/dialog.js +38 -56
- package/dialog/styled-components.d.ts +2 -2
- package/dialog/styled-components.js +56 -24
- package/dialog/types.d.ts +5 -2
- package/file-uploader/constants.d.ts +16 -0
- package/file-uploader/constants.js +30 -0
- package/file-uploader/file-uploader.d.ts +2 -2
- package/file-uploader/file-uploader.js +387 -117
- package/file-uploader/index.d.ts +1 -1
- package/file-uploader/index.js +67 -18
- package/file-uploader/locale.d.ts +10 -10
- package/file-uploader/locale.js +5 -5
- package/file-uploader/styled-components.d.ts +13 -6
- package/file-uploader/styled-components.js +261 -64
- package/file-uploader/types.d.ts +47 -32
- package/file-uploader/utils.d.ts +5 -0
- package/file-uploader/utils.js +45 -0
- package/file-uploader-basic/file-uploader-basic.d.ts +10 -0
- package/file-uploader-basic/file-uploader-basic.js +175 -0
- package/file-uploader-basic/index.d.ts +4 -0
- package/file-uploader-basic/index.js +71 -0
- package/file-uploader-basic/locale.d.ts +15 -0
- package/file-uploader-basic/locale.js +21 -0
- package/file-uploader-basic/styled-components.d.ts +7 -0
- package/file-uploader-basic/styled-components.js +83 -0
- package/file-uploader-basic/types.d.ts +41 -0
- package/form-control/form-control.js +38 -3
- package/form-control/styled-components.d.ts +2 -0
- package/form-control/styled-components.js +22 -2
- package/form-control/types.d.ts +4 -0
- package/icon/circle-check-filled.d.ts +9 -0
- package/icon/circle-check-filled.js +50 -0
- package/icon/circle-exclamation-point-filled.d.ts +9 -0
- package/icon/circle-exclamation-point-filled.js +50 -0
- package/icon/hide.js +1 -1
- package/icon/icon-exports.d.ts +4 -0
- package/icon/icon-exports.js +28 -0
- package/icon/paperclip-filled.d.ts +9 -0
- package/icon/paperclip-filled.js +50 -0
- package/icon/show.js +1 -1
- package/icon/trash-can-filled.d.ts +9 -0
- package/{button-docked/button-docked.js → icon/trash-can-filled.js} +35 -16
- package/locale/en_US.js +14 -12
- package/locale/es_AR.js +9 -1
- package/locale/index.d.ts +3 -0
- package/locale/index.js +2 -0
- package/locale/tr_TR.js +9 -1
- package/locale/types.d.ts +2 -0
- package/message-card/message-card.js +2 -2
- package/message-card/utils.js +8 -3
- package/modal/modal-button.d.ts +1 -3
- package/package.json +5 -3
- package/payment-card/custom-cards.config.d.ts +1 -11
- package/payment-card/payment-card.js +1 -3
- package/phone-input/base-country-picker.js +2 -2
- package/phone-input/country-picker.js +0 -10
- package/progress-bar/progressbar-rounded.js +1 -1
- package/progress-bar/styled-components.js +8 -6
- package/rating/styled-components.js +3 -2
- package/rating/svg-icons.d.ts +5 -5
- package/rating/svg-icons.js +20 -20
- package/select/multi-value.js +1 -1
- package/snackbar/index.d.ts +1 -0
- package/snackbar/snackbar-context.d.ts +1 -2
- package/snackbar/snackbar-context.js +27 -21
- package/spinner/index.d.ts +4 -2
- package/stepper/stepper.js +28 -27
- package/styles/__mocks__/styled.js +0 -2
- package/styles/as-primary-export-hoc.js +0 -2
- package/styles/styled.js +0 -2
- package/styles/types.d.ts +7 -3
- package/tabs-motion/tabs.js +2 -2
- package/tag/constants.d.ts +5 -4
- package/tag/constants.js +7 -6
- package/tag/index.d.ts +1 -1
- package/tag/index.js +7 -7
- package/tag/styled-components.d.ts +1 -1
- package/tag/styled-components.js +137 -124
- package/tag/tag.js +2 -2
- package/tag/types.d.ts +9 -8
- package/tag/types.js +2 -2
- package/themes/dark-theme/color-component-tokens.d.ts +2 -2
- package/themes/dark-theme/color-component-tokens.js +279 -275
- package/themes/dark-theme/color-foundation-tokens.d.ts +3 -0
- package/themes/dark-theme/{color-tokens.js → color-foundation-tokens.js} +11 -14
- package/themes/dark-theme/color-semantic-tokens.d.ts +2 -2
- package/themes/dark-theme/color-semantic-tokens.js +52 -58
- package/themes/dark-theme/create-dark-theme.d.ts +1 -1
- package/themes/dark-theme/create-dark-theme.js +12 -32
- package/themes/dark-theme/dark-theme.js +4 -4
- package/themes/dark-theme/primitives.js +2 -2
- package/themes/light-theme/color-component-tokens.d.ts +2 -2
- package/themes/light-theme/color-component-tokens.js +287 -282
- package/themes/light-theme/color-foundation-tokens.d.ts +3 -0
- package/themes/light-theme/{color-tokens.js → color-foundation-tokens.js} +10 -13
- package/themes/light-theme/color-semantic-tokens.d.ts +2 -2
- package/themes/light-theme/color-semantic-tokens.js +50 -53
- package/themes/light-theme/create-light-theme.d.ts +1 -1
- package/themes/light-theme/create-light-theme.js +12 -32
- package/themes/light-theme/light-theme.js +4 -4
- package/themes/light-theme/primitives.js +2 -2
- package/themes/types.d.ts +74 -13
- package/themes/utils.d.ts +1 -1
- package/themes/utils.js +4 -4
- package/tile/tile-group.js +2 -2
- package/timezonepicker/update-tzdata.js +0 -1
- package/tokens/color-primitive-tokens.d.ts +5 -0
- package/tokens/color-primitive-tokens.js +301 -0
- package/tokens/index.d.ts +5 -4
- package/tokens/index.js +25 -3
- package/tokens/types.d.ts +170 -1
- package/button-docked/button-docked.d.ts +0 -4
- package/button-docked/index.d.ts +0 -3
- package/button-docked/index.js +0 -40
- package/button-docked/styled-components.d.ts +0 -5
- package/button-docked/styled-components.js +0 -55
- package/button-docked/types.d.ts +0 -14
- package/themes/dark-theme/color-tokens.d.ts +0 -3
- package/themes/light-theme/color-tokens.d.ts +0 -3
- package/tokens/colors.d.ts +0 -3
- package/tokens/colors.js +0 -125
- /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 =
|
|
6
|
+
exports.default = FileUploader;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var
|
|
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
|
|
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
|
-
|
|
45
|
+
fileRows,
|
|
46
|
+
hint,
|
|
47
|
+
itemPreview,
|
|
48
|
+
label,
|
|
49
|
+
maxFiles,
|
|
50
|
+
overrides = {},
|
|
51
|
+
processFileOnDrop,
|
|
52
|
+
setFileRows,
|
|
53
|
+
...fileUploaderBasicProps
|
|
36
54
|
} = props;
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})
|
|
92
|
-
|
|
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
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
148
|
-
var _default = exports.default = FileUploader;
|
|
416
|
+
fileRows: [],
|
|
417
|
+
setFileRows: () => {}
|
|
418
|
+
};
|
package/file-uploader/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as FileUploader } from './file-uploader';
|
|
2
|
-
export {
|
|
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';
|