@mantine/dropzone 3.3.2 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +21 -0
  2. package/cjs/Dropzone/Dropzone.js +4 -10
  3. package/cjs/Dropzone/Dropzone.js.map +1 -1
  4. package/cjs/FullScreenDropzone/FullScreenDropzone.js +4 -6
  5. package/cjs/FullScreenDropzone/FullScreenDropzone.js.map +1 -1
  6. package/esm/Dropzone/Dropzone.js +5 -11
  7. package/esm/Dropzone/Dropzone.js.map +1 -1
  8. package/esm/FullScreenDropzone/FullScreenDropzone.js +5 -7
  9. package/esm/FullScreenDropzone/FullScreenDropzone.js.map +1 -1
  10. package/lib/Dropzone/Dropzone.d.ts.map +1 -1
  11. package/lib/FullScreenDropzone/FullScreenDropzone.d.ts +1 -1
  12. package/lib/FullScreenDropzone/FullScreenDropzone.d.ts.map +1 -1
  13. package/lib/FullScreenDropzone/demos/fullScreen.d.ts.map +1 -1
  14. package/package.json +3 -3
  15. package/src/Dropzone/Dropzone.story.tsx +0 -44
  16. package/src/Dropzone/Dropzone.styles.ts +0 -62
  17. package/src/Dropzone/Dropzone.test.tsx +0 -50
  18. package/src/Dropzone/Dropzone.tsx +0 -113
  19. package/src/Dropzone/demos/_base.tsx +0 -58
  20. package/src/Dropzone/demos/disabled.tsx +0 -54
  21. package/src/Dropzone/demos/index.ts +0 -4
  22. package/src/Dropzone/demos/loading.tsx +0 -18
  23. package/src/Dropzone/demos/manual.tsx +0 -45
  24. package/src/Dropzone/demos/usage.tsx +0 -62
  25. package/src/Dropzone/index.ts +0 -2
  26. package/src/FullScreenDropzone/FullScreenDropzone.story.tsx +0 -37
  27. package/src/FullScreenDropzone/FullScreenDropzone.test.tsx +0 -7
  28. package/src/FullScreenDropzone/FullScreenDropzone.tsx +0 -155
  29. package/src/FullScreenDropzone/FullscreenDropzone.styles.ts +0 -62
  30. package/src/FullScreenDropzone/demos/fullScreen.tsx +0 -65
  31. package/src/FullScreenDropzone/demos/index.ts +0 -1
  32. package/src/FullScreenDropzone/index.ts +0 -2
  33. package/src/demos.ts +0 -2
  34. package/src/index.ts +0 -3
  35. package/src/mime-types.ts +0 -33
  36. package/src/styles.api.ts +0 -20
  37. package/tsconfig.build.json +0 -34
  38. package/tsconfig.build.tsbuildinfo +0 -1
  39. package/tsconfig.json +0 -34
@@ -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
- });
@@ -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';