@mantine/dropzone 3.3.1 → 3.3.5
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/README.md +21 -0
- package/package.json +3 -3
- package/src/Dropzone/Dropzone.story.tsx +0 -44
- package/src/Dropzone/Dropzone.styles.ts +0 -62
- package/src/Dropzone/Dropzone.test.tsx +0 -50
- package/src/Dropzone/Dropzone.tsx +0 -113
- package/src/Dropzone/demos/_base.tsx +0 -58
- package/src/Dropzone/demos/disabled.tsx +0 -54
- package/src/Dropzone/demos/index.ts +0 -4
- package/src/Dropzone/demos/loading.tsx +0 -18
- package/src/Dropzone/demos/manual.tsx +0 -45
- package/src/Dropzone/demos/usage.tsx +0 -62
- package/src/Dropzone/index.ts +0 -2
- package/src/FullScreenDropzone/FullScreenDropzone.story.tsx +0 -37
- package/src/FullScreenDropzone/FullScreenDropzone.test.tsx +0 -7
- package/src/FullScreenDropzone/FullScreenDropzone.tsx +0 -155
- package/src/FullScreenDropzone/FullscreenDropzone.styles.ts +0 -62
- package/src/FullScreenDropzone/demos/fullScreen.tsx +0 -65
- package/src/FullScreenDropzone/demos/index.ts +0 -1
- package/src/FullScreenDropzone/index.ts +0 -2
- package/src/demos.ts +0 -2
- package/src/index.ts +0 -3
- package/src/mime-types.ts +0 -33
- package/src/styles.api.ts +0 -20
- package/tsconfig.build.json +0 -34
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -34
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import { Portal, Transition, MantineNumberSize, ClassNames, DefaultProps } from '@mantine/core';
|
|
3
|
-
import { useIsomorphicEffect } from '@mantine/hooks';
|
|
4
|
-
import { DropzoneStatus } from '../Dropzone';
|
|
5
|
-
import useStyles from './FullscreenDropzone.styles';
|
|
6
|
-
|
|
7
|
-
export type FullScreenDropzoneStylesNames = ClassNames<typeof useStyles>;
|
|
8
|
-
|
|
9
|
-
export interface FullScreenDropzoneProps
|
|
10
|
-
extends DefaultProps<FullScreenDropzoneStylesNames>,
|
|
11
|
-
Omit<React.ComponentPropsWithoutRef<'div'>, 'onDrop'> {
|
|
12
|
-
/** Space between dropzone and viewport edges */
|
|
13
|
-
offset?: MantineNumberSize;
|
|
14
|
-
|
|
15
|
-
/** Overlay z-index */
|
|
16
|
-
zIndex?: number;
|
|
17
|
-
|
|
18
|
-
/** Disable dropzone */
|
|
19
|
-
disabled?: boolean;
|
|
20
|
-
|
|
21
|
-
/** Accepted mime types */
|
|
22
|
-
accept: string[];
|
|
23
|
-
|
|
24
|
-
/** Dropzone padding from theme or number to set padding in px */
|
|
25
|
-
padding?: MantineNumberSize;
|
|
26
|
-
|
|
27
|
-
/** Dropzone radius from theme or number to set border-radius in px */
|
|
28
|
-
radius?: MantineNumberSize;
|
|
29
|
-
|
|
30
|
-
/** Called when files are dropped to document */
|
|
31
|
-
onDrop(files: File[]): void;
|
|
32
|
-
|
|
33
|
-
/** Render children based on dragging state */
|
|
34
|
-
children(status: DropzoneStatus): React.ReactNode;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function isVisible(event: DragEvent) {
|
|
38
|
-
for (let i = 0; i < event.dataTransfer.items.length; i += 1) {
|
|
39
|
-
if (event.dataTransfer.items[i].kind !== 'file') {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function isValidDrop(event: DragEvent, mime: string[]) {
|
|
48
|
-
const items = event?.dataTransfer?.items;
|
|
49
|
-
|
|
50
|
-
if (mime.includes('*')) {
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
for (let i = 0; i < items?.length; i += 1) {
|
|
55
|
-
if (!mime.includes(items[i].type)) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function FullScreenDropzone({
|
|
64
|
-
className,
|
|
65
|
-
style,
|
|
66
|
-
offset = 'xl',
|
|
67
|
-
padding = 'md',
|
|
68
|
-
radius = 'sm',
|
|
69
|
-
classNames,
|
|
70
|
-
styles,
|
|
71
|
-
disabled,
|
|
72
|
-
accept = ['*'],
|
|
73
|
-
zIndex = 1000,
|
|
74
|
-
onDrop,
|
|
75
|
-
children,
|
|
76
|
-
sx,
|
|
77
|
-
...others
|
|
78
|
-
}: FullScreenDropzoneProps) {
|
|
79
|
-
const { classes, cx } = useStyles(
|
|
80
|
-
{ offset, padding, radius },
|
|
81
|
-
{ sx, classNames, styles, name: 'FullScreenDropzone' }
|
|
82
|
-
);
|
|
83
|
-
const [visible, setVisible] = useState(false);
|
|
84
|
-
const [error, setError] = useState(false);
|
|
85
|
-
|
|
86
|
-
const handleDragOver = (event: DragEvent) => {
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
setError(!isValidDrop(event, accept));
|
|
89
|
-
setVisible(isVisible(event));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const handleDragLeave = (event: DragEvent) => {
|
|
93
|
-
event.preventDefault();
|
|
94
|
-
setVisible(false);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const handleDrop = (event: DragEvent) => {
|
|
98
|
-
event.stopPropagation();
|
|
99
|
-
event.preventDefault();
|
|
100
|
-
setVisible(false);
|
|
101
|
-
if (isValidDrop(event, accept)) {
|
|
102
|
-
onDrop(Array.from(event.dataTransfer.files));
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
useIsomorphicEffect(() => {
|
|
107
|
-
if (!disabled) {
|
|
108
|
-
document.addEventListener('dragover', handleDragOver, false);
|
|
109
|
-
document.addEventListener('dragleave', handleDragLeave, false);
|
|
110
|
-
document.addEventListener('drop', handleDrop, false);
|
|
111
|
-
|
|
112
|
-
return () => {
|
|
113
|
-
document.removeEventListener('dragover', handleDragOver, false);
|
|
114
|
-
document.removeEventListener('dragleave', handleDragLeave, false);
|
|
115
|
-
document.removeEventListener('drop', handleDrop, false);
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return undefined;
|
|
120
|
-
}, [disabled]);
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
<Portal zIndex={zIndex}>
|
|
124
|
-
<Transition
|
|
125
|
-
transition="fade"
|
|
126
|
-
duration={200}
|
|
127
|
-
timingFunction="ease"
|
|
128
|
-
mounted={visible && !disabled}
|
|
129
|
-
>
|
|
130
|
-
{(transitionStyles) => (
|
|
131
|
-
<div
|
|
132
|
-
style={{ ...style, ...transitionStyles }}
|
|
133
|
-
className={cx(classes.root, className)}
|
|
134
|
-
{...others}
|
|
135
|
-
>
|
|
136
|
-
<div
|
|
137
|
-
className={cx(
|
|
138
|
-
classes.dropzone,
|
|
139
|
-
{
|
|
140
|
-
[classes.active]: visible && !error,
|
|
141
|
-
[classes.reject]: error,
|
|
142
|
-
},
|
|
143
|
-
className
|
|
144
|
-
)}
|
|
145
|
-
>
|
|
146
|
-
{children({ accepted: visible && !error, rejected: error })}
|
|
147
|
-
</div>
|
|
148
|
-
</div>
|
|
149
|
-
)}
|
|
150
|
-
</Transition>
|
|
151
|
-
</Portal>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
FullScreenDropzone.displayName = '@mantine/dropzone/FullScreenDropzone';
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { createStyles, MantineNumberSize, getSharedColorScheme } from '@mantine/core';
|
|
2
|
-
|
|
3
|
-
interface FullScreenDropzoneStyles {
|
|
4
|
-
offset: MantineNumberSize;
|
|
5
|
-
padding: MantineNumberSize;
|
|
6
|
-
radius: MantineNumberSize;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default createStyles((theme, { offset, padding, radius }: FullScreenDropzoneStyles) => {
|
|
10
|
-
const spacing = theme.fn.size({ size: offset, sizes: theme.spacing });
|
|
11
|
-
const rejected = getSharedColorScheme({ color: 'red', theme, variant: 'light' });
|
|
12
|
-
const accepted = getSharedColorScheme({ color: theme.primaryColor, theme, variant: 'light' });
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
root: {
|
|
16
|
-
position: 'fixed',
|
|
17
|
-
top: 0,
|
|
18
|
-
left: 0,
|
|
19
|
-
right: 0,
|
|
20
|
-
bottom: 0,
|
|
21
|
-
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.white,
|
|
22
|
-
padding: spacing,
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
dropzone: {
|
|
26
|
-
...theme.fn.fontStyles(),
|
|
27
|
-
boxSizing: 'border-box',
|
|
28
|
-
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[7] : theme.white,
|
|
29
|
-
border: `2px dashed ${
|
|
30
|
-
theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[4]
|
|
31
|
-
}`,
|
|
32
|
-
padding: theme.fn.size({ size: padding, sizes: theme.spacing }),
|
|
33
|
-
borderRadius: theme.fn.size({ size: radius, sizes: theme.radius }),
|
|
34
|
-
cursor: 'pointer',
|
|
35
|
-
userSelect: 'none',
|
|
36
|
-
transition: 'background-color 150ms ease',
|
|
37
|
-
position: 'relative',
|
|
38
|
-
height: `calc(100vh - ${spacing * 2}px)`,
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
active: {
|
|
42
|
-
backgroundColor:
|
|
43
|
-
theme.colorScheme === 'dark' ? accepted.background : theme.colors[theme.primaryColor][0],
|
|
44
|
-
borderColor:
|
|
45
|
-
theme.colorScheme === 'dark' ? accepted.border : theme.colors[theme.primaryColor][4],
|
|
46
|
-
|
|
47
|
-
'&:hover': {
|
|
48
|
-
backgroundColor:
|
|
49
|
-
theme.colorScheme === 'dark' ? accepted.background : theme.colors[theme.primaryColor][0],
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
reject: {
|
|
54
|
-
backgroundColor: theme.colorScheme === 'dark' ? rejected.background : theme.colors.red[0],
|
|
55
|
-
borderColor: theme.colorScheme === 'dark' ? rejected.border : theme.colors.red[4],
|
|
56
|
-
|
|
57
|
-
'&:hover': {
|
|
58
|
-
backgroundColor: theme.colorScheme === 'dark' ? rejected.background : theme.colors.red[0],
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import React, { useState } from 'react';
|
|
3
|
-
import { Button, useMantineTheme } from '@mantine/core';
|
|
4
|
-
import { dropzoneChildren } from '../../Dropzone/demos/_base';
|
|
5
|
-
import { FullScreenDropzone } from '../FullScreenDropzone';
|
|
6
|
-
import { IMAGE_MIME_TYPE } from '../../mime-types';
|
|
7
|
-
|
|
8
|
-
const code = `
|
|
9
|
-
import { useState } from 'react';
|
|
10
|
-
import { Button } from '@mantine/core';
|
|
11
|
-
import { FullScreenDropzone, IMAGE_MIME_TYPE } from '@mantine/dropzone';
|
|
12
|
-
|
|
13
|
-
function Demo() {
|
|
14
|
-
const [disabled, setDisabled] = useState(true);
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<>
|
|
18
|
-
<Button color={disabled ? 'blue' : 'red'} onClick={() => setDisabled((d) => !d)}>
|
|
19
|
-
{disabled ? 'Enable' : 'Disable'} full screen dropzone
|
|
20
|
-
</Button>
|
|
21
|
-
|
|
22
|
-
<FullScreenDropzone
|
|
23
|
-
disabled={disabled}
|
|
24
|
-
accept={IMAGE_MIME_TYPE}
|
|
25
|
-
onDrop={(files) => {
|
|
26
|
-
console.log(files);
|
|
27
|
-
setDisabled(true);
|
|
28
|
-
}}
|
|
29
|
-
>
|
|
30
|
-
{/* See dropzone children in previous demo */}
|
|
31
|
-
</FullScreenDropzone>
|
|
32
|
-
</>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
function Demo() {
|
|
38
|
-
const [disabled, setDisabled] = useState(true);
|
|
39
|
-
const theme = useMantineTheme();
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<>
|
|
43
|
-
<Button color={disabled ? 'blue' : 'red'} onClick={() => setDisabled((d) => !d)}>
|
|
44
|
-
{disabled ? 'Enable' : 'Disable'} full screen dropzone
|
|
45
|
-
</Button>
|
|
46
|
-
|
|
47
|
-
<FullScreenDropzone
|
|
48
|
-
disabled={disabled}
|
|
49
|
-
accept={IMAGE_MIME_TYPE}
|
|
50
|
-
onDrop={(files) => {
|
|
51
|
-
console.log(files);
|
|
52
|
-
setDisabled(true);
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
{(status) => dropzoneChildren(status, theme)}
|
|
56
|
-
</FullScreenDropzone>
|
|
57
|
-
</>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const fullScreen: MantineDemo = {
|
|
62
|
-
type: 'demo',
|
|
63
|
-
component: Demo,
|
|
64
|
-
code,
|
|
65
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { fullScreen } from './fullScreen';
|
package/src/demos.ts
DELETED
package/src/index.ts
DELETED
package/src/mime-types.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export const MIME_TYPES = {
|
|
2
|
-
// Images
|
|
3
|
-
png: 'image/png',
|
|
4
|
-
gif: 'image/gif',
|
|
5
|
-
jpeg: 'image/jpeg',
|
|
6
|
-
svg: 'image/svg+xml',
|
|
7
|
-
webp: 'image/webp',
|
|
8
|
-
|
|
9
|
-
// Documents
|
|
10
|
-
mp4: 'video/mp4',
|
|
11
|
-
zip: 'application/zip',
|
|
12
|
-
csv: 'text/csv',
|
|
13
|
-
pdf: 'application/pdf',
|
|
14
|
-
doc: 'application/msword',
|
|
15
|
-
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
16
|
-
xls: 'application/vnd.ms-excel',
|
|
17
|
-
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
18
|
-
ppt: 'application/vnd.ms-powerpoint',
|
|
19
|
-
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
20
|
-
} as const;
|
|
21
|
-
|
|
22
|
-
export const IMAGE_MIME_TYPE = [
|
|
23
|
-
MIME_TYPES.png,
|
|
24
|
-
MIME_TYPES.gif,
|
|
25
|
-
MIME_TYPES.jpeg,
|
|
26
|
-
MIME_TYPES.svg,
|
|
27
|
-
MIME_TYPES.webp,
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
export const PDF_MINE_TYPE = [MIME_TYPES.pdf];
|
|
31
|
-
export const MS_WORD_MIME_TYPE = [MIME_TYPES.doc, MIME_TYPES.docx];
|
|
32
|
-
export const MS_EXCEL_MIME_TYPE = [MIME_TYPES.xls, MIME_TYPES.xlsx];
|
|
33
|
-
export const MS_POWERPOINT_MIME_TYPE = [MIME_TYPES.ppt, MIME_TYPES.pptx];
|
package/src/styles.api.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { DropzoneStylesNames } from './Dropzone';
|
|
2
|
-
import type { FullScreenDropzoneStylesNames } from './FullScreenDropzone';
|
|
3
|
-
|
|
4
|
-
export const Dropzone: Record<DropzoneStylesNames, string> = {
|
|
5
|
-
root: 'Root element',
|
|
6
|
-
loading: 'Root element loading state modifier, controlled by loading prop',
|
|
7
|
-
active:
|
|
8
|
-
'Active state modifier, style is added to root element when valid files are dragged over dropzone',
|
|
9
|
-
reject:
|
|
10
|
-
'Active state modifier, style is added to root element when invalid files are dragged over dropzone',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const FullScreenDropzone: Record<FullScreenDropzoneStylesNames, string> = {
|
|
14
|
-
root: 'Root element',
|
|
15
|
-
dropzone: 'Dropzone itself',
|
|
16
|
-
active:
|
|
17
|
-
'Active state modifier, style is added to dropzone when valid files are dragged over browser window',
|
|
18
|
-
reject:
|
|
19
|
-
'Active state modifier, style is added to dropzone when invalid files are dragged over browser window',
|
|
20
|
-
};
|
package/tsconfig.build.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"include": ["./src", "./types", "../../configuration/types"],
|
|
4
|
-
"exclude": [
|
|
5
|
-
"./lib",
|
|
6
|
-
"./esm",
|
|
7
|
-
"./cjs",
|
|
8
|
-
"**/*.story.tsx",
|
|
9
|
-
"**/*.test.tsx",
|
|
10
|
-
"**/*.test.ts",
|
|
11
|
-
"**/styles.api.ts",
|
|
12
|
-
"src/components/*/demos/*",
|
|
13
|
-
"src/demos.ts"
|
|
14
|
-
],
|
|
15
|
-
"compilerOptions": {
|
|
16
|
-
"rootDir": "src",
|
|
17
|
-
"baseUrl": ".",
|
|
18
|
-
"outDir": "lib",
|
|
19
|
-
"declaration": true,
|
|
20
|
-
"declarationMap": true,
|
|
21
|
-
"declarationDir": "lib",
|
|
22
|
-
"composite": true,
|
|
23
|
-
"paths": {
|
|
24
|
-
"@mantine/core": ["../mantine-core/src"],
|
|
25
|
-
"@mantine/hooks": ["../mantine-hooks/src"],
|
|
26
|
-
"@mantine/tests": ["../mantine-tests/src"]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"references": [
|
|
30
|
-
{ "path": "../mantine-core" },
|
|
31
|
-
{ "path": "../mantine-hooks" },
|
|
32
|
-
{ "path": "../mantine-tests" }
|
|
33
|
-
]
|
|
34
|
-
}
|