@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 ADDED
@@ -0,0 +1,21 @@
1
+ # Mantine Dropzone
2
+
3
+ @mantine/dropzone is a set of components to handle files drag'n'drop at specific area or browser window.
4
+
5
+ [Read documentation on Mantine website](https://mantine.dev/others/dropzone/)
6
+
7
+ ## Installation
8
+
9
+ Package depends on [react](https://www.npmjs.com/package/react), [react-dom](https://www.npmjs.com/package/react-dom), [@mantine/hooks](https://www.npmjs.com/package/@mantine/hooks), [@mantine/core](https://www.npmjs.com/package/@mantine/core).
10
+
11
+ Install with npm:
12
+
13
+ ```sh
14
+ npm install @mantine/dropzone @mantine/core @mantine/hooks
15
+ ```
16
+
17
+ Install with yarn:
18
+
19
+ ```sh
20
+ yarn add @mantine/dropzone @mantine/core @mantine/hooks
21
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mantine/dropzone",
3
3
  "description": "Dropzone component built with Mantine theme and components",
4
- "version": "3.3.1",
4
+ "version": "3.3.5",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -15,8 +15,8 @@
15
15
  "directory": "src/mantine-prism"
16
16
  },
17
17
  "peerDependencies": {
18
- "@mantine/core": "3.3.1",
19
- "@mantine/hooks": "3.3.1",
18
+ "@mantine/core": "3.3.5",
19
+ "@mantine/hooks": "3.3.5",
20
20
  "react": ">=16.8.0",
21
21
  "react-dom": ">=16.8.0"
22
22
  },
@@ -1,44 +0,0 @@
1
- /* eslint-disable no-console */
2
- import React, { useRef } from 'react';
3
- import { storiesOf } from '@storybook/react';
4
- import { Button } from '@mantine/core';
5
- import { Dropzone, DropzoneStatus } from './Dropzone';
6
- import { IMAGE_MIME_TYPE } from '../mime-types';
7
-
8
- const children = (status: DropzoneStatus) =>
9
- status.accepted ? <div>Drop files here</div> : <div>Drag and drop files here</div>;
10
-
11
- function ManualTrigger() {
12
- const openRef = useRef<() => void>(() => {});
13
-
14
- return (
15
- <div style={{ padding: 40 }}>
16
- <Dropzone onDrop={() => {}} openRef={openRef}>
17
- {children}
18
- </Dropzone>
19
- <Button onClick={() => openRef.current()}>Browse files</Button>
20
- </div>
21
- );
22
- }
23
-
24
- storiesOf('@mantine/dropzone/Dropzone', module)
25
- .add('General usage', () => (
26
- <div style={{ padding: 40 }}>
27
- <Dropzone onDrop={() => {}}>{children}</Dropzone>
28
- </div>
29
- ))
30
- .add('Manual open trigger', () => <ManualTrigger />)
31
- .add('Accept only images', () => (
32
- <div style={{ padding: 40 }}>
33
- <Dropzone onDrop={console.log} accept={IMAGE_MIME_TYPE}>
34
- {children}
35
- </Dropzone>
36
- </div>
37
- ))
38
- .add('Loading', () => (
39
- <div style={{ padding: 40 }}>
40
- <Dropzone onDrop={() => {}} loading>
41
- {children}
42
- </Dropzone>
43
- </div>
44
- ));
@@ -1,62 +0,0 @@
1
- import { createStyles, MantineNumberSize, getSharedColorScheme } from '@mantine/core';
2
-
3
- interface DropzoneStyles {
4
- padding: MantineNumberSize;
5
- radius: MantineNumberSize;
6
- }
7
-
8
- export default createStyles((theme, { padding, radius }: DropzoneStyles) => {
9
- const rejected = getSharedColorScheme({ color: 'red', theme, variant: 'light' });
10
- const accepted = getSharedColorScheme({ color: theme.primaryColor, theme, variant: 'light' });
11
-
12
- return {
13
- root: {
14
- ...theme.fn.fontStyles(),
15
- ...theme.fn.focusStyles(),
16
- boxSizing: 'border-box',
17
- backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[7] : theme.white,
18
- border: `2px dashed ${
19
- theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[4]
20
- }`,
21
- padding: theme.fn.size({ size: padding, sizes: theme.spacing }),
22
- borderRadius: theme.fn.size({ size: radius, sizes: theme.radius }),
23
- cursor: 'pointer',
24
- userSelect: 'none',
25
- transition: 'background-color 150ms ease',
26
- position: 'relative',
27
-
28
- '&:hover': {
29
- backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0],
30
- },
31
- },
32
-
33
- loading: {
34
- cursor: 'default',
35
-
36
- '&:hover': {
37
- backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[7] : theme.white,
38
- },
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,50 +0,0 @@
1
- import React from 'react';
2
- import { mount, shallow } from 'enzyme';
3
- import {
4
- itSupportsClassName,
5
- itSupportsMargins,
6
- itSupportsOthers,
7
- itSupportsStyle,
8
- itSupportsRef,
9
- } from '@mantine/tests';
10
- import { LoadingOverlay } from '@mantine/core';
11
- import { Dropzone } from './Dropzone';
12
-
13
- const defaultProps = {
14
- onDrop: () => {},
15
- children: () => null,
16
- };
17
-
18
- describe('@mantine/core/Dropzone', () => {
19
- itSupportsClassName(Dropzone, defaultProps);
20
- itSupportsMargins(Dropzone, defaultProps);
21
- itSupportsOthers(Dropzone, defaultProps);
22
- itSupportsStyle(Dropzone, defaultProps);
23
- itSupportsRef(Dropzone, defaultProps, HTMLDivElement);
24
-
25
- it('displays LoadingOverlay based on loading prop', () => {
26
- const loading = shallow(<Dropzone {...defaultProps} loading />);
27
- const notLoading = shallow(<Dropzone {...defaultProps} loading={false} />);
28
-
29
- expect(loading.find(LoadingOverlay).prop('visible')).toBe(true);
30
- expect(notLoading.find(LoadingOverlay).prop('visible')).toBe(false);
31
- });
32
-
33
- it('assigns open function to given openRef', () => {
34
- let ref = null;
35
- mount(
36
- <Dropzone
37
- {...defaultProps}
38
- openRef={(openFn) => {
39
- ref = openFn;
40
- }}
41
- />
42
- );
43
-
44
- expect(typeof ref).toBe('function');
45
- });
46
-
47
- it('has correct displayName', () => {
48
- expect(Dropzone.displayName).toEqual('@mantine/dropzone/Dropzone');
49
- });
50
- });
@@ -1,113 +0,0 @@
1
- import React, { forwardRef } from 'react';
2
- import { useDropzone } from 'react-dropzone';
3
- import {
4
- DefaultProps,
5
- ClassNames,
6
- MantineNumberSize,
7
- useExtractedMargins,
8
- LoadingOverlay,
9
- } from '@mantine/core';
10
- import { assignRef } from '@mantine/hooks';
11
- import useStyles from './Dropzone.styles';
12
-
13
- export type DropzoneStylesNames = ClassNames<typeof useStyles>;
14
-
15
- export interface DropzoneStatus {
16
- accepted: boolean;
17
- rejected: boolean;
18
- }
19
-
20
- export interface DropzoneProps extends DefaultProps<DropzoneStylesNames> {
21
- /** Padding from theme.spacing, or number to set padding in px */
22
- padding?: MantineNumberSize;
23
-
24
- /** Border radius from theme.radius or number to set border-radius in px */
25
- radius?: MantineNumberSize;
26
-
27
- /** Render children based on dragging state */
28
- children(status: DropzoneStatus): React.ReactNode;
29
-
30
- /** Disable files capturing */
31
- disabled?: boolean;
32
-
33
- /** Called when files are dropped into dropzone */
34
- onDrop(files: File[]): void;
35
-
36
- /** Display loading overlay over dropzone */
37
- loading?: boolean;
38
-
39
- /** File types to accept */
40
- accept?: string[];
41
-
42
- /** Get open function as ref */
43
- openRef?: React.ForwardedRef<() => void>;
44
-
45
- /** Allow selection of multiple files */
46
- multiple?: boolean;
47
-
48
- /** Set maximum file size in bytes */
49
- maxSize?: number;
50
- }
51
-
52
- export const Dropzone = forwardRef<HTMLDivElement, DropzoneProps>(
53
- (
54
- {
55
- className,
56
- padding = 'md',
57
- radius = 'sm',
58
- disabled,
59
- classNames,
60
- style,
61
- styles,
62
- loading = false,
63
- multiple = true,
64
- maxSize = Infinity,
65
- accept,
66
- children,
67
- onDrop,
68
- openRef,
69
- sx,
70
- ...others
71
- }: DropzoneProps,
72
- ref
73
- ) => {
74
- const { classes, cx } = useStyles(
75
- { radius, padding },
76
- { sx, classNames, styles, name: 'Dropzone' }
77
- );
78
- const { mergedStyles, rest } = useExtractedMargins({ others, style });
79
-
80
- const { getRootProps, getInputProps, isDragAccept, isDragReject, open } = useDropzone({
81
- onDropAccepted: (files) => onDrop(files),
82
- disabled: disabled || loading,
83
- accept,
84
- multiple,
85
- maxSize,
86
- });
87
-
88
- assignRef(openRef, open);
89
-
90
- return (
91
- <div
92
- {...rest}
93
- {...getRootProps({ ref })}
94
- style={mergedStyles}
95
- className={cx(
96
- classes.root,
97
- {
98
- [classes.active]: isDragAccept,
99
- [classes.reject]: isDragReject,
100
- [classes.loading]: loading,
101
- },
102
- className
103
- )}
104
- >
105
- <LoadingOverlay visible={loading} radius={radius} />
106
- <input {...getInputProps()} />
107
- {children({ accepted: isDragAccept, rejected: isDragReject })}
108
- </div>
109
- );
110
- }
111
- );
112
-
113
- Dropzone.displayName = '@mantine/dropzone/Dropzone';
@@ -1,58 +0,0 @@
1
- /* eslint-disable no-console */
2
- import React from 'react';
3
- import { Group, Text, useMantineTheme, MantineTheme } from '@mantine/core';
4
- import { ImageIcon, UploadIcon, CrossCircledIcon } from '@modulz/radix-icons';
5
- import { Dropzone, DropzoneStatus, DropzoneProps } from '../Dropzone';
6
- import { IMAGE_MIME_TYPE } from '../../mime-types';
7
-
8
- function getIconColor(status: DropzoneStatus, theme: MantineTheme) {
9
- return status.accepted
10
- ? theme.colors[theme.primaryColor][theme.colorScheme === 'dark' ? 4 : 6]
11
- : status.rejected
12
- ? theme.colors.red[theme.colorScheme === 'dark' ? 4 : 6]
13
- : theme.colorScheme === 'dark'
14
- ? theme.colors.dark[0]
15
- : theme.colors.gray[7];
16
- }
17
-
18
- function ImageUploadIcon({
19
- status,
20
- ...props
21
- }: React.ComponentPropsWithoutRef<typeof ImageIcon> & { status: DropzoneStatus }) {
22
- if (status.accepted) {
23
- return <UploadIcon {...props} />;
24
- }
25
-
26
- if (status.rejected) {
27
- return <CrossCircledIcon {...props} />;
28
- }
29
-
30
- return <ImageIcon {...props} />;
31
- }
32
-
33
- export const dropzoneChildren = (status: DropzoneStatus, theme: MantineTheme) => (
34
- <Group position="center" spacing="xl" style={{ minHeight: 220, pointerEvents: 'none' }}>
35
- <ImageUploadIcon
36
- status={status}
37
- style={{ width: 80, height: 80, color: getIconColor(status, theme) }}
38
- />
39
-
40
- <div>
41
- <Text size="xl" inline>
42
- Drag images here or click to select files
43
- </Text>
44
- <Text size="sm" color="dimmed" inline mt={7}>
45
- Attach as many files as you like, each file should not exceed 5mb
46
- </Text>
47
- </div>
48
- </Group>
49
- );
50
-
51
- export function BaseDemo(props: Partial<DropzoneProps>) {
52
- const theme = useMantineTheme();
53
- return (
54
- <Dropzone onDrop={console.log} maxSize={3 * 1024 ** 2} accept={IMAGE_MIME_TYPE} {...props}>
55
- {(status) => dropzoneChildren(status, theme)}
56
- </Dropzone>
57
- );
58
- }
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- import { createStyles } from '@mantine/core';
3
- import { BaseDemo } from './_base';
4
-
5
- const code = `
6
- import { createStyles } from '@mantine/core';
7
- import { Dropzone } from '@mantine/dropzone';
8
-
9
- // Add your own disabled styles
10
- const useStyles = createStyles((theme) => ({
11
- disabled: {
12
- backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0],
13
- borderColor: theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[2],
14
- cursor: 'not-allowed',
15
-
16
- '& *': {
17
- color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5],
18
- },
19
- },
20
- }));
21
-
22
- function Demo() {
23
- const { classes } = useStyles();
24
-
25
- return (
26
- <Dropzone disabled className={classes.disabled}>
27
- {/* children, see previous demo */}
28
- </Dropzone>
29
- );
30
- }
31
- `;
32
-
33
- const useStyles = createStyles((theme) => ({
34
- disabled: {
35
- backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0],
36
- borderColor: theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[2],
37
- cursor: 'not-allowed',
38
-
39
- '& *': {
40
- color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5],
41
- },
42
- },
43
- }));
44
-
45
- function Demo() {
46
- const { classes } = useStyles();
47
- return <BaseDemo disabled className={classes.disabled} />;
48
- }
49
-
50
- export const disabled: MantineDemo = {
51
- type: 'demo',
52
- component: Demo,
53
- code,
54
- };
@@ -1,4 +0,0 @@
1
- export { usage } from './usage';
2
- export { loading } from './loading';
3
- export { disabled } from './disabled';
4
- export { manual } from './manual';
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
- import { BaseDemo } from './_base';
3
-
4
- const code = `
5
- <Dropzone loading>
6
- {/* children */}
7
- </Dropzone>
8
- `;
9
-
10
- function Demo() {
11
- return <BaseDemo loading />;
12
- }
13
-
14
- export const loading: MantineDemo = {
15
- type: 'demo',
16
- component: Demo,
17
- code,
18
- };
@@ -1,45 +0,0 @@
1
- import React, { useRef } from 'react';
2
- import { Button, Group } from '@mantine/core';
3
- import { BaseDemo } from './_base';
4
-
5
- const code = `
6
- import { useRef } from 'react';
7
- import { Button, Group } from '@mantine/core';
8
- import { Dropzone } from '@mantine/dropzone';
9
-
10
- function Demo() {
11
- const openRef = useRef();
12
- return (
13
- <>
14
- <Dropzone openRef={openRef}>
15
- {/* children */}
16
- </Dropzone>
17
-
18
- <Group position="center" mt="md">
19
- <Button onClick={() => openRef.current()}>Select files</Button>
20
- </Group>
21
- </>
22
- );
23
- }
24
-
25
-
26
- `;
27
-
28
- function Demo() {
29
- const openRef = useRef<() => void>();
30
-
31
- return (
32
- <>
33
- <BaseDemo openRef={openRef} />
34
- <Group position="center" mt="md">
35
- <Button onClick={() => openRef.current()}>Select files</Button>
36
- </Group>
37
- </>
38
- );
39
- }
40
-
41
- export const manual: MantineDemo = {
42
- type: 'demo',
43
- component: Demo,
44
- code,
45
- };
@@ -1,62 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { BaseDemo } from './_base';
3
-
4
- const code = `
5
- import { Group, Text, useMantineTheme } from '@mantine/core';
6
- import { ImageIcon, UploadIcon, CrossCircledIcon } from '@modulz/radix-icons';
7
-
8
- function ImageUploadIcon({ status, ...props }) {
9
- if (status.accepted) {
10
- return <UploadIcon {...props} />;
11
- }
12
-
13
- if (status.rejected) {
14
- return <CrossCircledIcon {...props} />;
15
- }
16
-
17
- return <ImageIcon {...props} />;
18
- }
19
-
20
- function getIconColor(status, theme) {
21
- return status.accepted
22
- ? theme.colors[theme.primaryColor][6]
23
- : status.rejected
24
- ? theme.colors.red[6]
25
- : theme.colorScheme === 'dark'
26
- ? theme.colors.dark[0]
27
- : theme.black;
28
- }
29
-
30
- function Demo() {
31
- const theme = useMantineTheme();
32
-
33
- return (
34
- // See results in console after dropping files to Dropzone
35
- <Dropzone onDrop={console.log} maxSize={3 * 1024 ** 2} accept={IMAGE_MIME_TYPE}>
36
- {(status) => (
37
- <Group position="center" spacing="xl" style={{ minHeight: 220, pointerEvents: 'none' }}>
38
- <ImageUploadIcon
39
- status={status}
40
- style={{ width: 80, height: 80, color: getIconColor(status, theme) }}
41
- />
42
-
43
- <div>
44
- <Text size="xl" inline>
45
- Drag images here or click to select files
46
- </Text>
47
- <Text size="sm" color="dimmed" inline mt={7}>
48
- Attach as many files as you like, each file should not exceed 5mb
49
- </Text>
50
- </div>
51
- </Group>
52
- )}
53
- </Dropzone>
54
- );
55
- }
56
- `;
57
-
58
- export const usage: MantineDemo = {
59
- type: 'demo',
60
- component: BaseDemo,
61
- code,
62
- };
@@ -1,2 +0,0 @@
1
- export { Dropzone } from './Dropzone';
2
- export type { DropzoneStylesNames, DropzoneProps, DropzoneStatus } from './Dropzone';
@@ -1,37 +0,0 @@
1
- /* eslint-disable no-console */
2
- import React from 'react';
3
- import { storiesOf } from '@storybook/react';
4
- import { FullScreenDropzone } from './FullScreenDropzone';
5
- import { DropzoneStatus } from '../Dropzone';
6
- import { IMAGE_MIME_TYPE } from '../mime-types';
7
-
8
- const children = (status: DropzoneStatus) =>
9
- status.accepted ? <div>Drop files here</div> : <div>Drag and drop files here</div>;
10
-
11
- storiesOf('@mantine/dropzone/FullScreenDropzone', module).add('General usage', () => (
12
- <div>
13
- <p>
14
- Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusantium dolores expedita
15
- accusamus aperiam dolorem veniam maxime alias distinctio ullam magnam aspernatur nam delectus,
16
- dolorum sapiente ea aliquid sunt, molestias quam.
17
- </p>
18
- <p>
19
- Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusantium dolores expedita
20
- accusamus aperiam dolorem veniam maxime alias distinctio ullam magnam aspernatur nam delectus,
21
- dolorum sapiente ea aliquid sunt, molestias quam.
22
- </p>
23
- <p>
24
- Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusantium dolores expedita
25
- accusamus aperiam dolorem veniam maxime alias distinctio ullam magnam aspernatur nam delectus,
26
- dolorum sapiente ea aliquid sunt, molestias quam.
27
- </p>
28
- <p>
29
- Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusantium dolores expedita
30
- accusamus aperiam dolorem veniam maxime alias distinctio ullam magnam aspernatur nam delectus,
31
- dolorum sapiente ea aliquid sunt, molestias quam.
32
- </p>
33
- <FullScreenDropzone onDrop={console.log} accept={IMAGE_MIME_TYPE}>
34
- {children}
35
- </FullScreenDropzone>
36
- </div>
37
- ));
@@ -1,7 +0,0 @@
1
- import { FullScreenDropzone } from './FullScreenDropzone';
2
-
3
- describe('@mantine/dropzone/FullScreenDropzone', () => {
4
- it('has correct displayName', () => {
5
- expect(FullScreenDropzone.displayName).toEqual('@mantine/dropzone/FullScreenDropzone');
6
- });
7
- });