@react-magma/dropzone 16.0.0-next.1 → 16.0.0-v6-next.2
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/dist/fileuploader.js +1 -1
- package/dist/fileuploader.js.map +1 -1
- package/dist/fileuploader.modern.js +85 -0
- package/dist/fileuploader.modern.js.map +1 -0
- package/dist/fileuploader.modern.module.js +1 -1
- package/dist/fileuploader.modern.module.js.map +1 -1
- package/dist/fileuploader.umd.js +1 -1
- package/dist/fileuploader.umd.js.map +1 -1
- package/dist/src/src/components/dropzone/Dropzone.d.ts +110 -101
- package/dist/src/src/components/dropzone/Dropzone.stories.d.ts +64 -0
- package/dist/src/src/components/dropzone/Dropzone.test.d.ts +1 -1
- package/dist/src/src/components/dropzone/FileIcon.d.ts +8 -7
- package/dist/src/src/components/dropzone/FilePreview.d.ts +15 -15
- package/dist/src/src/components/dropzone/Preview.d.ts +18 -18
- package/dist/src/src/components/dropzone/index.d.ts +4 -4
- package/dist/src/src/components/dropzone/utils.d.ts +1 -1
- package/dist/src/src/index.d.ts +1 -1
- package/package.json +15 -18
- package/src/components/dropzone/Dropzone.stories.tsx +16 -5
- package/src/components/dropzone/Dropzone.test.js +25 -6
- package/src/components/dropzone/Dropzone.tsx +70 -25
- package/src/components/dropzone/Preview.tsx +41 -14
- package/src/components/dropzone/utils.ts +0 -1
- package/dist/fileuploader.modern.mjs +0 -85
- package/dist/fileuploader.modern.mjs.map +0 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { FlexProps } from 'react-magma-dom';
|
|
3
|
-
import { FilePreview } from './FilePreview';
|
|
4
|
-
export interface PreviewProps extends Omit<FlexProps, 'behavior'> {
|
|
5
|
-
accept?: string | string[];
|
|
6
|
-
file: FilePreview;
|
|
7
|
-
isInverse?: boolean;
|
|
8
|
-
maxSize?: number;
|
|
9
|
-
minSize?: number;
|
|
10
|
-
onDeleteFile?: (file: FilePreview) => void;
|
|
11
|
-
onRemoveFile?: (file: FilePreview) => void;
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
testId?: string;
|
|
16
|
-
thumbnails: boolean;
|
|
17
|
-
}
|
|
18
|
-
export declare const Preview: React.ForwardRefExoticComponent<
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlexProps } from 'react-magma-dom';
|
|
3
|
+
import { FilePreview } from './FilePreview';
|
|
4
|
+
export interface PreviewProps extends Omit<FlexProps, 'behavior'> {
|
|
5
|
+
accept?: string | string[];
|
|
6
|
+
file: FilePreview;
|
|
7
|
+
isInverse?: boolean;
|
|
8
|
+
maxSize?: number;
|
|
9
|
+
minSize?: number;
|
|
10
|
+
onDeleteFile?: (file: FilePreview) => void;
|
|
11
|
+
onRemoveFile?: (file: FilePreview) => void;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
testId?: string;
|
|
16
|
+
thumbnails: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare const Preview: React.ForwardRefExoticComponent<Pick<PreviewProps, "isInverse" | "testId" | "accept" | "id" | "maxSize" | "minSize" | "onDeleteFile" | "onRemoveFile" | "thumbnails" | "onProgress" | "file" | "slot" | "style" | "title" | "onDragEnter" | "onDragOver" | "onDragLeave" | "onDrop" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoCapitalize" | "autoFocus" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "enterKeyHint" | "hidden" | "lang" | "nonce" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "content" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeaveCapture" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "alignContent" | "alignItems" | "direction" | "justify" | "spacing" | "wrap" | "xs" | "sm" | "md" | "lg" | "xl"> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './FileIcon';
|
|
2
|
-
export * from './FilePreview';
|
|
3
|
-
export * from './Dropzone';
|
|
4
|
-
export * from './FilePreview';
|
|
1
|
+
export * from './FileIcon';
|
|
2
|
+
export * from './FilePreview';
|
|
3
|
+
export * from './Dropzone';
|
|
4
|
+
export * from './FilePreview';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const formatFileSize: (bytes: number | undefined, decimalPoint?: number, bytesLabel?: string) => string;
|
|
1
|
+
export declare const formatFileSize: (bytes: number | undefined, decimalPoint?: number, bytesLabel?: string) => string | undefined;
|
package/dist/src/src/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './components/dropzone';
|
|
1
|
+
export * from './components/dropzone';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-magma/dropzone",
|
|
3
|
-
"version": "16.0.0-next.
|
|
3
|
+
"version": "16.0.0-v6-next.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,31 +20,28 @@
|
|
|
20
20
|
"build": "microbundle build --jsx jsx --jsxImportSource react --globals react/jsx-runtime=jsx",
|
|
21
21
|
"build-watch": "microbundle watch --jsx jsx --jsxImportSource react --globals react/jsx-runtime=jsx",
|
|
22
22
|
"lint": "eslint ./src",
|
|
23
|
-
"lint:fix": "eslint ./src --fix",
|
|
24
|
-
"lint:check": "eslint ./src --max-warnings=0",
|
|
25
23
|
"test": "jest",
|
|
26
|
-
"test-watch": "jest --watch"
|
|
27
|
-
"compiler-checks": "tsc --noEmit --project ./tsconfig.json"
|
|
24
|
+
"test-watch": "jest --watch"
|
|
28
25
|
},
|
|
29
26
|
"dependencies": {
|
|
30
|
-
"polished": "3.7.2",
|
|
27
|
+
"polished": "^3.7.2",
|
|
31
28
|
"react-dropzone": "11.3.2"
|
|
32
29
|
},
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@emotion/react": "11.
|
|
35
|
-
"@emotion/styled": "11.
|
|
36
|
-
"react": "
|
|
37
|
-
"react-dom": "
|
|
38
|
-
"react-magma-dom": "^
|
|
39
|
-
"react-magma-icons": "^3.
|
|
31
|
+
"@emotion/react": "^11.13.0",
|
|
32
|
+
"@emotion/styled": "^11.13.0",
|
|
33
|
+
"react": "^17.0.2",
|
|
34
|
+
"react-dom": "^17.0.2",
|
|
35
|
+
"react-magma-dom": "^6.1.0-v6-next.2",
|
|
36
|
+
"react-magma-icons": "^3.3.0"
|
|
40
37
|
},
|
|
41
38
|
"peerDependencies": {
|
|
42
|
-
"@emotion/react": "11.
|
|
43
|
-
"@emotion/styled": "11.
|
|
44
|
-
"react": "
|
|
45
|
-
"react-dom": "
|
|
46
|
-
"react-magma-dom": "^
|
|
47
|
-
"react-magma-icons": "^3.
|
|
39
|
+
"@emotion/react": "^11.13.0",
|
|
40
|
+
"@emotion/styled": "^11.13.0",
|
|
41
|
+
"react": "^17.0.2",
|
|
42
|
+
"react-dom": "^17.0.2",
|
|
43
|
+
"react-magma-dom": "^6.1.0-v6-next.2",
|
|
44
|
+
"react-magma-icons": "^3.3.0"
|
|
48
45
|
},
|
|
49
46
|
"engines": {
|
|
50
47
|
"node": ">=22.14.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
|
|
3
|
-
import { Textarea, Datagrid, magma } from 'react-magma-dom';
|
|
3
|
+
import { ButtonColor, Textarea, Datagrid, magma } from 'react-magma-dom';
|
|
4
4
|
|
|
5
5
|
import { Dropzone, DropzoneProps, OnSendFileProps } from './Dropzone';
|
|
6
6
|
|
|
@@ -54,6 +54,17 @@ export default {
|
|
|
54
54
|
component: Dropzone,
|
|
55
55
|
title: 'Dropzone',
|
|
56
56
|
argTypes: {
|
|
57
|
+
buttonColor: {
|
|
58
|
+
control: {
|
|
59
|
+
type: 'select',
|
|
60
|
+
},
|
|
61
|
+
options: Object.values(ButtonColor),
|
|
62
|
+
},
|
|
63
|
+
buttonText: {
|
|
64
|
+
control: {
|
|
65
|
+
type: 'text',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
57
68
|
noDrag: {
|
|
58
69
|
control: {
|
|
59
70
|
type: 'boolean',
|
|
@@ -82,6 +93,10 @@ export default {
|
|
|
82
93
|
};
|
|
83
94
|
|
|
84
95
|
export const Default = {
|
|
96
|
+
args: {
|
|
97
|
+
buttonColor: ButtonColor.secondary,
|
|
98
|
+
buttonText: 'Choose Files',
|
|
99
|
+
},
|
|
85
100
|
render: (args: DropzoneProps) => {
|
|
86
101
|
return (
|
|
87
102
|
<div
|
|
@@ -138,7 +153,6 @@ export const Image = {
|
|
|
138
153
|
const onSendFile = (props: OnSendFileProps) => {
|
|
139
154
|
const { file, onFinish } = props;
|
|
140
155
|
const reader = new FileReader();
|
|
141
|
-
|
|
142
156
|
reader.onload = function (evt) {
|
|
143
157
|
setFile(
|
|
144
158
|
(evt &&
|
|
@@ -184,7 +198,6 @@ export const Text = {
|
|
|
184
198
|
const onSendFile = (props: OnSendFileProps) => {
|
|
185
199
|
const { file, onFinish } = props;
|
|
186
200
|
const reader = new FileReader();
|
|
187
|
-
|
|
188
201
|
reader.onload = function (evt) {
|
|
189
202
|
setFile(
|
|
190
203
|
(evt &&
|
|
@@ -231,7 +244,6 @@ export const Csv = {
|
|
|
231
244
|
const onSendFile = (props: OnSendFileProps) => {
|
|
232
245
|
const { file, onFinish } = props;
|
|
233
246
|
const reader = new FileReader();
|
|
234
|
-
|
|
235
247
|
reader.onload = function (evt) {
|
|
236
248
|
const [columns, rows] =
|
|
237
249
|
(evt &&
|
|
@@ -239,7 +251,6 @@ export const Csv = {
|
|
|
239
251
|
evt.target.result &&
|
|
240
252
|
csvJSON(evt.target.result.toString())) ||
|
|
241
253
|
[];
|
|
242
|
-
|
|
243
254
|
setColumns(columns);
|
|
244
255
|
setFile(rows);
|
|
245
256
|
onFinish && onFinish({ file });
|
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
} from '@testing-library/react';
|
|
10
10
|
import userEvent from '@testing-library/user-event';
|
|
11
11
|
import { transparentize } from 'polished';
|
|
12
|
-
import { I18nContext, defaultI18n, magma } from 'react-magma-dom';
|
|
12
|
+
import { ButtonColor, I18nContext, defaultI18n, magma } from 'react-magma-dom';
|
|
13
13
|
|
|
14
|
+
import { FileIcon } from './FileIcon';
|
|
15
|
+
import { Preview } from './Preview';
|
|
14
16
|
import { axe } from '../../../axe-helper.js';
|
|
15
17
|
|
|
16
18
|
import { Dropzone } from '.';
|
|
17
|
-
import { FileIcon } from './FileIcon';
|
|
18
|
-
import { Preview } from './Preview';
|
|
19
19
|
|
|
20
20
|
describe('File Uploader', () => {
|
|
21
21
|
let files;
|
|
@@ -55,6 +55,25 @@ describe('File Uploader', () => {
|
|
|
55
55
|
).not.toBeInTheDocument();
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
+
it.each([false, true])(
|
|
59
|
+
'customizes the browse button when noDrag is %s',
|
|
60
|
+
noDrag => {
|
|
61
|
+
const buttonText = 'Choose files';
|
|
62
|
+
const { getByRole } = render(
|
|
63
|
+
<Dropzone
|
|
64
|
+
buttonColor={ButtonColor.secondary}
|
|
65
|
+
buttonText={buttonText}
|
|
66
|
+
noDrag={noDrag}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const button = getByRole('button', { name: buttonText });
|
|
71
|
+
|
|
72
|
+
expect(button).toHaveStyleRule('background', magma.colors.neutral0);
|
|
73
|
+
expect(button).toHaveStyleRule('color', magma.colors.brand.navy);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
58
77
|
it('should find element by testId', () => {
|
|
59
78
|
const testId = 'test-id';
|
|
60
79
|
|
|
@@ -764,7 +783,7 @@ describe('File Uploader', () => {
|
|
|
764
783
|
});
|
|
765
784
|
|
|
766
785
|
// TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
|
|
767
|
-
|
|
786
|
+
it.skip('changes to delete file on finish', async () => {
|
|
768
787
|
const onSendFile = ({ file, onFinish }) => {
|
|
769
788
|
onFinish({ file });
|
|
770
789
|
};
|
|
@@ -788,7 +807,7 @@ describe('File Uploader', () => {
|
|
|
788
807
|
});
|
|
789
808
|
|
|
790
809
|
// TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
|
|
791
|
-
|
|
810
|
+
it.skip('deletes the file when the Delete File icon is clicked', async () => {
|
|
792
811
|
const onSendFile = ({ file, onFinish }) => {
|
|
793
812
|
onFinish({ file });
|
|
794
813
|
};
|
|
@@ -822,7 +841,7 @@ describe('File Uploader', () => {
|
|
|
822
841
|
});
|
|
823
842
|
|
|
824
843
|
// TODO: Fix test (Delete file doesn't exist in the document (Remove file exists))
|
|
825
|
-
|
|
844
|
+
it.skip('calls onDeleteFile when the Delete File icon is clicked', async () => {
|
|
826
845
|
const onDeleteFileSpy = jest.fn();
|
|
827
846
|
const onSendFile = ({ file, onFinish }) => {
|
|
828
847
|
onFinish({ file });
|
|
@@ -54,6 +54,11 @@ enum DragState {
|
|
|
54
54
|
default = 'default',
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
const getBrowseButtonText = (
|
|
58
|
+
buttonText: string | null | undefined,
|
|
59
|
+
localizedText: string
|
|
60
|
+
) => buttonText ?? localizedText;
|
|
61
|
+
|
|
57
62
|
// NOTE: These props are manually copied to dropzone.mdx
|
|
58
63
|
export interface DropzoneProps
|
|
59
64
|
extends Omit<FormFieldContainerBaseProps, 'fieldId' | 'errorMessage'> {
|
|
@@ -61,6 +66,15 @@ export interface DropzoneProps
|
|
|
61
66
|
* Set accepted file types. See https://github.com/okonet/attr-accept for more information. Keep in mind that mime type determination is not reliable across platforms. CSV files, for example, are reported as text/plain under macOS but as application/vnd.ms-excel under Windows. In some cases there might not be a mime type set at all. See: https://github.com/react-dropzone/react-dropzone/issues/276
|
|
62
67
|
*/
|
|
63
68
|
accept?: string | string[];
|
|
69
|
+
/**
|
|
70
|
+
* The color of the button used to browse for files.
|
|
71
|
+
* @default ButtonColor.primary
|
|
72
|
+
*/
|
|
73
|
+
buttonColor?: ButtonColor;
|
|
74
|
+
/**
|
|
75
|
+
* The text displayed in the button used to browse for files. Defaults to the localized browse files text.
|
|
76
|
+
*/
|
|
77
|
+
buttonText?: string;
|
|
64
78
|
/**
|
|
65
79
|
* Enable/Disable the input
|
|
66
80
|
*/
|
|
@@ -134,6 +148,54 @@ export interface DropzoneProps
|
|
|
134
148
|
thumbnails?: boolean;
|
|
135
149
|
}
|
|
136
150
|
|
|
151
|
+
const getErrorBorderColor = (
|
|
152
|
+
dragState: DragState,
|
|
153
|
+
theme: ThemeInterface,
|
|
154
|
+
isInverse?: boolean
|
|
155
|
+
) => {
|
|
156
|
+
if (!isInverse) {
|
|
157
|
+
return theme.colors.danger;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return dragState === DragState.error
|
|
161
|
+
? theme.colors.red500
|
|
162
|
+
: theme.colors.red400;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const getContainerBorder = ({
|
|
166
|
+
dragState = DragState.default,
|
|
167
|
+
noDrag,
|
|
168
|
+
theme,
|
|
169
|
+
isInverse,
|
|
170
|
+
}: {
|
|
171
|
+
dragState?: DragState;
|
|
172
|
+
noDrag?: boolean;
|
|
173
|
+
theme: ThemeInterface;
|
|
174
|
+
isInverse?: boolean;
|
|
175
|
+
}) => {
|
|
176
|
+
if (noDrag) {
|
|
177
|
+
return '0px';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (dragState === DragState.dragReject || dragState === DragState.error) {
|
|
181
|
+
const width = dragState === DragState.error ? '1px' : '2px';
|
|
182
|
+
|
|
183
|
+
return `${width} dashed ${getErrorBorderColor(dragState, theme, isInverse)}`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (dragState === DragState.dragActive) {
|
|
187
|
+
return `2px dashed ${theme.colors.blue500}`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (dragState === DragState.dragAccept) {
|
|
191
|
+
return `2px dashed ${theme.colors.green500}`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return `2px dashed ${
|
|
195
|
+
isInverse ? theme.colors.neutral800 : theme.colors.neutral300
|
|
196
|
+
}`;
|
|
197
|
+
};
|
|
198
|
+
|
|
137
199
|
const Container = styled(Flex)<
|
|
138
200
|
DropzoneRootProps &
|
|
139
201
|
FlexProps & {
|
|
@@ -149,26 +211,7 @@ const Container = styled(Flex)<
|
|
|
149
211
|
padding: ${({ noDrag }) => (noDrag ? '0px' : '24px')};
|
|
150
212
|
border-radius: ${({ noDrag, theme }) =>
|
|
151
213
|
noDrag ? theme.borderRadiusNone : theme.borderRadiusSmall};
|
|
152
|
-
border: ${
|
|
153
|
-
noDrag
|
|
154
|
-
? `0px`
|
|
155
|
-
: dragState === DragState.dragReject || dragState === DragState.error
|
|
156
|
-
? isInverse
|
|
157
|
-
? `${dragState === DragState.error ? '1px' : '2px'} dashed ${
|
|
158
|
-
dragState === DragState.error
|
|
159
|
-
? theme.colors.red500
|
|
160
|
-
: theme.colors.red400
|
|
161
|
-
}`
|
|
162
|
-
: `${dragState === DragState.error ? '1px' : '2px'} dashed ${
|
|
163
|
-
theme.colors.danger
|
|
164
|
-
}`
|
|
165
|
-
: dragState === DragState.dragActive
|
|
166
|
-
? `2px dashed ${theme.colors.blue500}`
|
|
167
|
-
: dragState === DragState.dragAccept
|
|
168
|
-
? `2px dashed ${theme.colors.green500}`
|
|
169
|
-
: `2px dashed ${
|
|
170
|
-
isInverse ? theme.colors.neutral800 : theme.colors.neutral300
|
|
171
|
-
}`};
|
|
214
|
+
border: ${getContainerBorder};
|
|
172
215
|
|
|
173
216
|
border-style: ${({ dragState = DragState.default }) =>
|
|
174
217
|
dragState === DragState.error ? 'solid' : 'dashed'};
|
|
@@ -211,9 +254,11 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
211
254
|
(props, ref) => {
|
|
212
255
|
const {
|
|
213
256
|
accept,
|
|
257
|
+
buttonColor = ButtonColor.primary,
|
|
258
|
+
buttonText,
|
|
214
259
|
containerStyle,
|
|
215
260
|
disabled,
|
|
216
|
-
|
|
261
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
217
262
|
dropzoneOptions = {
|
|
218
263
|
multiple: true,
|
|
219
264
|
},
|
|
@@ -545,7 +590,7 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
545
590
|
{noDrag ? (
|
|
546
591
|
<Flex xs behavior={FlexBehavior.item}>
|
|
547
592
|
<Button
|
|
548
|
-
color={
|
|
593
|
+
color={buttonColor}
|
|
549
594
|
disabled={disabled}
|
|
550
595
|
isInverse={isInverse}
|
|
551
596
|
onClick={open}
|
|
@@ -553,7 +598,7 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
553
598
|
ref={browseFileButtonRef}
|
|
554
599
|
aria-describedby={helperMessage ? helperMessageId : undefined}
|
|
555
600
|
>
|
|
556
|
-
{i18n.dropzone.browseFiles}
|
|
601
|
+
{getBrowseButtonText(buttonText, i18n.dropzone.browseFiles)}
|
|
557
602
|
</Button>
|
|
558
603
|
</Flex>
|
|
559
604
|
) : (
|
|
@@ -569,7 +614,7 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
569
614
|
{i18n.dropzone.dragMessage}
|
|
570
615
|
</Wrapper>
|
|
571
616
|
<Button
|
|
572
|
-
color={
|
|
617
|
+
color={buttonColor}
|
|
573
618
|
disabled={disabled}
|
|
574
619
|
isInverse={isInverse}
|
|
575
620
|
onClick={open}
|
|
@@ -578,7 +623,7 @@ export const Dropzone = React.forwardRef<HTMLInputElement, DropzoneProps>(
|
|
|
578
623
|
ref={browseFileButtonRef}
|
|
579
624
|
aria-describedby={helperMessage ? helperMessageId : undefined}
|
|
580
625
|
>
|
|
581
|
-
{i18n.dropzone.browseFiles}
|
|
626
|
+
{getBrowseButtonText(buttonText, i18n.dropzone.browseFiles)}
|
|
582
627
|
</Button>
|
|
583
628
|
</Flex>
|
|
584
629
|
)}
|
|
@@ -71,6 +71,38 @@ const StatusIcons = styled.div`
|
|
|
71
71
|
}
|
|
72
72
|
`;
|
|
73
73
|
|
|
74
|
+
const PreviewIcon = ({
|
|
75
|
+
file,
|
|
76
|
+
isInverse,
|
|
77
|
+
theme,
|
|
78
|
+
thumbnails,
|
|
79
|
+
}: {
|
|
80
|
+
file: FilePreview;
|
|
81
|
+
isInverse: boolean;
|
|
82
|
+
theme: ThemeInterface;
|
|
83
|
+
thumbnails: boolean;
|
|
84
|
+
}) => {
|
|
85
|
+
if (file.errors) {
|
|
86
|
+
return (
|
|
87
|
+
<ErrorIcon
|
|
88
|
+
color={isInverse ? theme.colors.red500 : theme.colors.danger}
|
|
89
|
+
size={24}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
file.preview &&
|
|
96
|
+
thumbnails &&
|
|
97
|
+
file.type &&
|
|
98
|
+
file.type.startsWith('image')
|
|
99
|
+
) {
|
|
100
|
+
return <Thumb role="img" file={file} />;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return <FileIcon isInverse={isInverse} file={file} />;
|
|
104
|
+
};
|
|
105
|
+
|
|
74
106
|
const IconStyles = {
|
|
75
107
|
marginRight: '12px',
|
|
76
108
|
display: 'flex',
|
|
@@ -245,7 +277,9 @@ export const Preview = forwardRef<
|
|
|
245
277
|
return (
|
|
246
278
|
<StatusIcons>
|
|
247
279
|
<Spinner
|
|
248
|
-
color={
|
|
280
|
+
color={
|
|
281
|
+
isInverse ? theme.colors.brand.skyBlue : theme.colors.primary
|
|
282
|
+
}
|
|
249
283
|
/>
|
|
250
284
|
</StatusIcons>
|
|
251
285
|
);
|
|
@@ -299,19 +333,12 @@ export const Preview = forwardRef<
|
|
|
299
333
|
alignItems={FlexAlignItems.center}
|
|
300
334
|
style={IconStyles}
|
|
301
335
|
>
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
thumbnails &&
|
|
309
|
-
file.type &&
|
|
310
|
-
file.type.startsWith('image') ? (
|
|
311
|
-
<Thumb role="img" file={file} />
|
|
312
|
-
) : (
|
|
313
|
-
<FileIcon isInverse={isInverse} file={file} />
|
|
314
|
-
)}
|
|
336
|
+
<PreviewIcon
|
|
337
|
+
file={file}
|
|
338
|
+
isInverse={isInverse}
|
|
339
|
+
theme={theme}
|
|
340
|
+
thumbnails={thumbnails}
|
|
341
|
+
/>
|
|
315
342
|
</Flex>
|
|
316
343
|
<FileName xs behavior={FlexBehavior.item} theme={theme}>
|
|
317
344
|
{file.name}
|
|
@@ -8,7 +8,6 @@ export const formatFileSize = (
|
|
|
8
8
|
const k = 1024;
|
|
9
9
|
const sizes = [bytesLabel, 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
10
10
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
11
|
-
|
|
12
11
|
return (
|
|
13
12
|
parseFloat((bytes / Math.pow(k, i)).toFixed(decimalPoint)) + ' ' + sizes[i]
|
|
14
13
|
);
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import{magma as e,styled as r,Flex as o,Card as l,ThemeContext as t,I18nContext as i,useIsInverse as n,InverseContext as s,CardBorderRadius as a,CardCornerTreatment as c,FlexBehavior as d,FlexAlignItems as p,IconButton as m,ButtonVariant as u,ButtonColor as g,Spinner as h,Transition as f,useGenerateId as v,FormFieldContainer as y,Button as b,VisuallyHidden as x,Announce as z}from"react-magma-dom";import{InsertDriveFileIcon as S,FileWordIcon as $,FileExcelIcon as I,FilePowerpointIcon as w,FilePdfIcon as F,ImageIcon as k,VideocamIcon as R,AudiotrackIcon as D,FileZipIcon as j,CloseIcon as O,ErrorIcon as A,CheckCircleIcon as C,DeleteIcon as B,CloudUploadIcon as M}from"react-magma-icons";import{jsx as H,jsxs as L}from"react/jsx-runtime";import P,{forwardRef as E,useContext as N,useState as T,useEffect as U,useImperativeHandle as V}from"react";import{transparentize as G}from"polished";import{useDropzone as K}from"react-dropzone";const W={default:{Icon:S,style:{color:e.colors.neutral700},inverseStyle:{color:e.colors.neutral300}},word:{Icon:$,style:{color:e.colors.blue500},inverseStyle:{color:e.colors.blue500}},excel:{Icon:I,style:{color:e.colors.green500},inverseStyle:{color:e.colors.green500}},powerpoint:{Icon:w,style:{color:e.colors.tangerine600},inverseStyle:{color:e.colors.tangerine500}},pdf:{Icon:F,style:{color:e.colors.red600},inverseStyle:{color:e.colors.red500}},image:{Icon:k,style:{color:e.colors.neutral700},inverseStyle:{color:e.colors.neutral300}},video:{Icon:R,style:{color:e.colors.neutral700},inverseStyle:{color:e.colors.neutral300}},audio:{Icon:D,style:{color:e.colors.neutral700},inverseStyle:{color:e.colors.neutral300}},archive:{Icon:j,style:{color:e.colors.neutral700},inverseStyle:{color:e.colors.neutral300}}},Y={default:W.default,xlsx:W.excel,xlsm:W.excel,xlsb:W.excel,xltx:W.excel,xls:W.excel,xlt:W.excel,doc:W.word,docx:W.word,docm:W.word,dotx:W.word,dotm:W.word,docb:W.word,pptx:W.powerpoint,pptm:W.powerpoint,ppt:W.powerpoint,pdf:W.pdf,png:W.image,svg:W.image,image:W.image,audio:W.audio,video:W.video,zip:W.archive},Z=({file:r,isInverse:o})=>{const{path:l="",type:t=""}=r,i=t.split("/")[0],n=l.split(".").pop()||"default",{Icon:s,style:a,inverseStyle:c}=Y[n]||Y[i]||Y.default;/*#__PURE__*/return H(s,{size:e.iconSizes.medium,style:o?c:a})};function q(){return q=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var o=arguments[r];for(var l in o)({}).hasOwnProperty.call(o,l)&&(e[l]=o[l])}return e},q.apply(null,arguments)}function J(e,r){if(null==e)return{};var o={};for(var l in e)if({}.hasOwnProperty.call(e,l)){if(-1!==r.indexOf(l))continue;o[l]=e[l]}return o}const Q=(e,r=2,o="Bytes")=>{if(void 0===e)return;if(0==e)return`0 ${o}`;const l=[o,"KB","MB","GB","TB","PB","EB","ZB","YB"],t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(r))+" "+l[t]},X=["accept","file","isInverse","maxSize","minSize","onDeleteFile","onRemoveFile","testId","thumbnails"],_=["code"];let ee,re,oe,le,te,ie,ne,se,ae=e=>e;const ce=r.div(ee||(ee=ae`
|
|
2
|
-
background-image: ${0};
|
|
3
|
-
background-repeat: no-repeat;
|
|
4
|
-
background-size: cover;
|
|
5
|
-
display: inline-block;
|
|
6
|
-
vertical-align: middle;
|
|
7
|
-
height: 40px;
|
|
8
|
-
width: 40px;
|
|
9
|
-
`),({file:e})=>`url('${"preview"in e&&e.preview}')`),de=r.div(re||(re=ae`
|
|
10
|
-
display: grid;
|
|
11
|
-
grid-template-areas: 'inner-div';
|
|
12
|
-
height: auto;
|
|
13
|
-
place-items: center;
|
|
14
|
-
width: 46px;
|
|
15
|
-
& > div {
|
|
16
|
-
display: inline-block;
|
|
17
|
-
right: 0;
|
|
18
|
-
grid-area: inner-div;
|
|
19
|
-
}
|
|
20
|
-
`)),pe={marginRight:"12px",display:"flex"},me=r.div(oe||(oe=ae`
|
|
21
|
-
border-top: 1px solid
|
|
22
|
-
${0};
|
|
23
|
-
padding: 16px;
|
|
24
|
-
font-size: ${0};
|
|
25
|
-
line-height: ${0};
|
|
26
|
-
`),({theme:e,isInverse:r})=>r?e.colors.neutral500:e.colors.neutral300,({theme:e})=>e.typeScale.size02.fontSize,({theme:e})=>e.typeScale.size02.lineHeight),ue=r(o)(le||(le=ae`
|
|
27
|
-
height: 56px;
|
|
28
|
-
padding: 0 8px 0 16px;
|
|
29
|
-
font-size: ${0};
|
|
30
|
-
line-height: ${0};
|
|
31
|
-
`),({theme:e})=>e.typeScale.size02.fontSize,({theme:e})=>e.typeScale.size02.lineHeight),ge=r(o)(te||(te=ae`
|
|
32
|
-
overflow: hidden;
|
|
33
|
-
white-space: nowrap;
|
|
34
|
-
align-items: center;
|
|
35
|
-
text-overflow: ellipsis;
|
|
36
|
-
display: block;
|
|
37
|
-
margin-right: 24px;
|
|
38
|
-
font-size: ${0};
|
|
39
|
-
line-height: ${0};
|
|
40
|
-
`),({theme:e})=>e.typeScale.size02.fontSize,({theme:e})=>e.typeScale.size02.lineHeight),he=r(l)(ie||(ie=ae`
|
|
41
|
-
background-color: none;
|
|
42
|
-
border-color: ${0};
|
|
43
|
-
border-width: 1px;
|
|
44
|
-
color: ${0};
|
|
45
|
-
margin: 10px 0;
|
|
46
|
-
`),({file:e,theme:r,isInverse:o})=>e.errors?o?r.colors.red500:r.colors.danger:o?r.colors.neutral800:r.colors.neutral200,({file:e,theme:r,isInverse:o})=>o?r.colors.neutral0:e.errors?r.colors.neutral700:r.colors.brand.navy),fe=r.span(ne||(ne=ae`
|
|
47
|
-
display: block;
|
|
48
|
-
|
|
49
|
-
> div {
|
|
50
|
-
display: flex;
|
|
51
|
-
align-self: center;
|
|
52
|
-
margin-right: 12px;
|
|
53
|
-
}
|
|
54
|
-
`)),ve=r.span(se||(se=ae`
|
|
55
|
-
display: block;
|
|
56
|
-
`)),ye=/*#__PURE__*/E((e,r)=>{var l;const{accept:v,file:y,isInverse:b,maxSize:x,minSize:z,onDeleteFile:S,onRemoveFile:$,thumbnails:I}=e,w=J(e,X),F=N(t),k=P.useContext(i),R=n(b),[D,j]=T(/*#__PURE__*/H(O,{})),M=()=>{$&&"function"==typeof $&&$(y)},E=()=>{S&&"function"==typeof S&&S(y)},V=({status:e="ready"})=>{const[r,o]=T(!1);return U(()=>{let e=!0;return setTimeout(()=>{e&&o(!0)},1e3),()=>{e=!1}},[e]),"error"===e||"ready"===e?/*#__PURE__*/H(de,{children:/*#__PURE__*/H(m,{onClick:M,variant:u.link,color:g.subtle,"aria-label":`${k.dropzone.removeFile} ${y.name}`,icon:/*#__PURE__*/H(O,{})})}):"pending"===e?/*#__PURE__*/H(de,{children:/*#__PURE__*/H(h,{color:R?F.colors.brand.skyBlue:F.colors.primary})}):/*#__PURE__*/L(de,{children:[/*#__PURE__*/H(f,{isOpen:!r,unmountOnExit:!0,fade:!0,children:/*#__PURE__*/H(C,{color:R?F.colors.green500:F.colors.success,style:{marginTop:"4px"}})}),/*#__PURE__*/H(f,{isOpen:r,unmountOnExit:!0,fade:!0,children:/*#__PURE__*/H(m,{onClick:E,variant:u.link,color:g.subtle,"aria-label":`${k.dropzone.deleteFile} ${y.name}`,icon:/*#__PURE__*/H(B,{})})})]})};return U(()=>{var e;j(/*#__PURE__*/H(V,{status:null==y||null==(e=y.processor)?void 0:e.status}))},[null==y||null==(l=y.processor)?void 0:l.status]),/*#__PURE__*/H(s.Provider,{value:{isInverse:R},children:/*#__PURE__*/L(he,{borderRadius:a.small,cornerTreatment:c.all,isInverse:R,theme:F,file:y,"data-testid":e.testId,ref:r,role:y.errors?"alert":"",children:[/*#__PURE__*/L(ue,q({theme:F,behavior:d.container,alignItems:p.center},w,{children:[/*#__PURE__*/H(o,{behavior:d.item,alignItems:p.center,style:pe,children:y.errors?/*#__PURE__*/H(A,{color:R?F.colors.red500:F.colors.danger,size:24}):y.preview&&I&&y.type&&y.type.startsWith("image")?/*#__PURE__*/H(ce,{role:"img",file:y}):/*#__PURE__*/H(Z,{isInverse:R,file:y})}),/*#__PURE__*/H(ge,{xs:!0,behavior:d.item,theme:F,children:y.name}),y.processor&&"pending"===y.processor.status&&/*#__PURE__*/H(o,{role:"progressbar",style:{marginLeft:"auto"},behavior:d.item,children:y.processor.percent}),/*#__PURE__*/H(o,{behavior:d.item,children:D})]})),y.errors&&/*#__PURE__*/H(me,{theme:F,isInverse:R,children:y.errors.slice(0,1).map(e=>{let{code:r}=e,o=J(e,_);const{header:l="",message:t}=((e,r,o)=>{const l=Array.isArray(r.accept)&&1===r.accept.length?r.accept[0]:r.accept,t=Array.isArray(l)?`one of ${l.join(", ")}`:l;switch(e.code){case"file-too-large":return q({},e,{message:`${e.message} ${Q(r.maxSize,2,o)}.`});case"file-too-small":return q({},e,{message:`${e.message} ${Q(r.minSize,2,o)}.`});case"file-invalid-type":return q({},e,{message:`${e.message}: ${t}`});default:return e}})(q({code:r},o,k.dropzone.errors[r]),{accept:v,minSize:z,maxSize:x},k.dropzone.bytes);/*#__PURE__*/return L(P.Fragment,{children:[/*#__PURE__*/H(fe,{style:{color:R?F.colors.red500:F.colors.danger},children:l}),/*#__PURE__*/H(ve,{children:t})]},r)})})]})})}),be=["accept","containerStyle","disabled","dropzoneOptions","helperMessage","id","inputSize","isInverse","isLabelVisuallyHidden","labelStyle","labelText","maxFiles","minFiles","maxSize","minSize","multiple","noDrag","onSendFile","onDeleteFile","onRemoveFile","sendFiles","testId","thumbnails"];let xe,ze,Se,$e,Ie,we=e=>e;var Fe;!function(e){e.error="error",e.dragAccept="dragAccept",e.dragReject="dragReject",e.dragActive="dragActive",e.default="default"}(Fe||(Fe={}));const ke=r(o)(xe||(xe=we`
|
|
57
|
-
flex-direction: column;
|
|
58
|
-
align-items: ${0};
|
|
59
|
-
justify-content: ${0};
|
|
60
|
-
text-align: ${0};
|
|
61
|
-
padding: ${0};
|
|
62
|
-
border-radius: ${0};
|
|
63
|
-
border: ${0};
|
|
64
|
-
|
|
65
|
-
border-style: ${0};
|
|
66
|
-
background-color: ${0};
|
|
67
|
-
outline: none;
|
|
68
|
-
transition: ${0};
|
|
69
|
-
`),({noDrag:e})=>e?"left":"center",({noDrag:e})=>e?"left":"center",({noDrag:e})=>e?"left":"center",({noDrag:e})=>e?"0px":"24px",({noDrag:e,theme:r})=>e?r.borderRadiusNone:r.borderRadiusSmall,({dragState:e=Fe.default,noDrag:r,theme:o,isInverse:l})=>r?"0px":e===Fe.dragReject||e===Fe.error?l?`${e===Fe.error?"1px":"2px"} dashed ${e===Fe.error?o.colors.red500:o.colors.red400}`:`${e===Fe.error?"1px":"2px"} dashed ${o.colors.danger}`:e===Fe.dragActive?`2px dashed ${o.colors.blue500}`:e===Fe.dragAccept?`2px dashed ${o.colors.green500}`:`2px dashed ${l?o.colors.neutral800:o.colors.neutral300}`,({dragState:e=Fe.default})=>e===Fe.error?"solid":"dashed",({theme:e,noDrag:r,isInverse:o})=>r?"transparent":o?G(.6,e.colors.neutral1200):e.colors.neutral100,({noDrag:e})=>`border ${e?0:".24s"} ease-in-out`),Re=r.span(ze||(ze=we`
|
|
70
|
-
color: ${0};
|
|
71
|
-
display: block;
|
|
72
|
-
font-size: 14px;
|
|
73
|
-
margin: -8px 0 16px 0;
|
|
74
|
-
`),({theme:e,isInverse:r})=>r?e.colors.neutral500:e.colors.neutral700),De=r.div(Se||(Se=we`
|
|
75
|
-
color: ${0};
|
|
76
|
-
margin: 0 0 24px 0;
|
|
77
|
-
font-size: ${0};
|
|
78
|
-
line-height: ${0};
|
|
79
|
-
font-weight: 500;
|
|
80
|
-
padding: ${0};
|
|
81
|
-
`),({theme:e,isInverse:r})=>r?e.colors.neutral0:e.colors.brand.navy,({theme:e})=>e.typeScale.size02.fontSize,({theme:e})=>e.typeScale.size02.lineHeight,({theme:e})=>e.spaceScale.spacing01),je=r.ul($e||($e=we`
|
|
82
|
-
list-style: none;
|
|
83
|
-
padding: 0;
|
|
84
|
-
`)),Oe=r.li(Ie||(Ie=we``)),Ae=/*#__PURE__*/P.forwardRef((e,r)=>{const{accept:l,containerStyle:a,disabled:c,dropzoneOptions:p={multiple:!0},helperMessage:m,id:h,inputSize:f,isInverse:S,isLabelVisuallyHidden:$,labelStyle:I,labelText:w,maxFiles:F,minFiles:k,maxSize:R,minSize:D,multiple:j=!0,noDrag:O=!1,onSendFile:A,onDeleteFile:C,onRemoveFile:B,sendFiles:E=!1,testId:N,thumbnails:T=!0}=e,U=J(e,be),[G,W]=P.useState([]),[Y,Z]=P.useState(null),[Q,X]=P.useState(""),_=n(S),ee=P.useContext(t),re=P.useContext(i),oe=v(h),le=v(`${oe}-helper`),te=P.useRef(null),ie=P.useCallback((e,r)=>{const o=[...e.map(e=>Object.assign(e,{preview:URL.createObjectURL(e)})),...r.map(({file:e,errors:r})=>Object.assign(e,{errors:r}))];if(W(e=>[...e,...o]),e.length>0){const r=e.map(e=>e.name).join(", "),o=1===e.length?re.dropzone.fileAdded.replace(/\{fileName\}/g,r):re.dropzone.filesAdded.replace(/\{count\}/g,e.length.toString()).replace(/\{fileNames\}/g,r);X(o)}te.current&&te.current.focus()},[re]),{getInputProps:ne,getRootProps:se,isDragAccept:ae,isDragActive:ce,isDragReject:de,open:pe,inputRef:me}=K(q({noClick:!0,disabled:c,multiple:j,maxSize:R,minSize:D,accept:l,onDrop:ie,noDrag:O},p));V(r,()=>me.current);const ue=ne({id:oe});let ge=Fe.default;Y?ge=Fe.error:ae?ge=Fe.dragAccept:de?ge=Fe.dragReject:ce&&(ge=Fe.dragActive);const he=e=>{W(r=>r.filter(r=>r!==e)),B&&"function"==typeof B&&B(e);const r=re.dropzone.fileRemoved.replace(/\{fileName\}/g,e.name);X(r),te.current&&te.current.focus()},fe=e=>{W(r=>r.filter(r=>r!==e)),C&&"function"==typeof C&&C(e);const r=re.dropzone.fileDeleted.replace(/\{fileName\}/g,e.name);X(r),te.current&&te.current.focus()},ve=e=>{if(W(r=>r.map(r=>r===e.file?Object.assign(r,{processor:q({},r.processor,{percent:`${e.percent}%`,status:"pending"})}):r)),e.percent>0&&e.percent%25==0){const r=re.dropzone.fileUploading.replace(/\{fileName\}/g,e.file.name).replace(/\{percent\}/g,e.percent.toString());X(r)}},xe=e=>{W(r=>r.map(r=>r===e.file?Object.assign(r,{processor:q({},r.processor,{percent:"",status:"finished"})}):r));const r=re.dropzone.fileUploaded.replace(/\{fileName\}/g,e.file.name);X(r)},ze=e=>{W(r=>r.map(r=>r===e.file?Object.assign(r,{errors:e.errors,processor:q({},r.processor,{status:"error"})}):r))};return P.useEffect(()=>()=>{G.forEach(e=>e.preview&&URL.revokeObjectURL(e.preview))},[G]),P.useEffect(()=>{const e=k&&G.length<k,r=F&&G.length>F;let o=null;r?o="too-many-files":e&&(o="too-few-files"),Z(((e,r)=>{if(null===e)return null;const o=re.dropzone.errors[e];switch(e){case"too-many-files":return`${o.message} ${r.maxFiles} ${re.dropzone.files}.`;case"too-few-files":return`${o.message} ${r.minFiles} ${re.dropzone.files}.`;default:return o.message}})(o,{minFiles:k,maxFiles:F})),E&&G.length>0&&!r&&!e&&W(e=>e.map(e=>(e.errors||e.processor||!A||A({file:e,onError:ze,onFinish:xe,onProgress:ve}),e)))},[E,G.length,A,F,k,re.dropzone.errors,re.dropzone.files]),/*#__PURE__*/L(s.Provider,{value:{isInverse:_},children:[/*#__PURE__*/L(y,{actionable:!1,containerStyle:a,errorMessage:Y,fieldId:oe,inputSize:f,isInverse:_,isLabelVisuallyHidden:$,labelStyle:q({color:_?ee.colors.neutral0:ee.colors.brand.navy},I),labelText:w,messageStyle:{minHeight:0},"data-testid":N,children:[/*#__PURE__*/H(Re,{id:le,theme:ee,isInverse:_,children:m}),/*#__PURE__*/L(ke,q({behavior:d.container,dragState:ge,isInverse:_,noDrag:O,theme:ee},se(),U,{testId:N,tabIndex:-1,children:[/*#__PURE__*/H("input",{ref:me,type:ue.type,accept:ue.accept,autoComplete:ue.autoComplete,id:ue.id,multiple:ue.multiple,onChange:ue.onChange,onClick:ue.onClick,style:ue.style,tabIndex:ue.tabIndex,"data-testid":"file-input"}),O?/*#__PURE__*/H(o,{xs:!0,behavior:d.item,children:/*#__PURE__*/H(b,{color:g.primary,disabled:c,isInverse:_,onClick:pe,style:{margin:0},ref:te,"aria-describedby":m?le:void 0,children:re.dropzone.browseFiles})}):/*#__PURE__*/L(o,{behavior:d.item,children:[/*#__PURE__*/H(M,{"aria-hidden":"true",color:_?ee.colors.neutral0:ee.colors.neutral700,size:48}),/*#__PURE__*/H(De,{isInverse:_,theme:ee,children:re.dropzone.dragMessage}),/*#__PURE__*/H(b,{color:g.primary,disabled:c,isInverse:_,onClick:pe,style:{margin:0},variant:u.solid,ref:te,"aria-describedby":m?le:void 0,children:re.dropzone.browseFiles})]})]}))]}),/*#__PURE__*/H(je,{children:G.map(e=>/*#__PURE__*/H(Oe,{children:/*#__PURE__*/H(ye,{accept:l,file:e,isInverse:_,maxSize:R,minSize:D,onDeleteFile:fe,onRemoveFile:he,thumbnails:T})},e.name))}),/*#__PURE__*/H(x,{children:/*#__PURE__*/H(z,{children:Q})})]})});export{Ae as Dropzone,Z as FileIcon};
|
|
85
|
-
//# sourceMappingURL=fileuploader.modern.mjs.map
|