Dropzone component built with Mantine theme and components for file drag-and-drop functionality
npx @tessl/cli install tessl/npm-mantine--dropzone@8.2.0Mantine Dropzone is a React component library providing drag-and-drop file upload functionality built on top of react-dropzone. It integrates seamlessly with Mantine's theming system and component architecture, offering flexible file capture interfaces with built-in accessibility, validation, and visual feedback.
npm install @mantine/dropzone @mantine/core @mantine/hooksimport { Dropzone } from "@mantine/dropzone";For specific components:
import {
Dropzone,
DropzoneFullScreen,
DropzoneAccept,
DropzoneIdle,
DropzoneReject
} from "@mantine/dropzone";For MIME type utilities:
import {
MIME_TYPES,
IMAGE_MIME_TYPE,
PDF_MIME_TYPE
} from "@mantine/dropzone";For CommonJS:
const { Dropzone, DropzoneFullScreen } = require("@mantine/dropzone");For CSS styles:
import "@mantine/dropzone/styles.css";import { Dropzone, MIME_TYPES } from "@mantine/dropzone";
function Demo() {
return (
<Dropzone
onDrop={(files) => console.log('accepted files', files)}
onReject={(files) => console.log('rejected files', files)}
maxSize={3 * 1024 ** 2}
accept={[MIME_TYPES.png, MIME_TYPES.jpeg, MIME_TYPES.pdf]}
>
<Dropzone.Accept>Drop files here</Dropzone.Accept>
<Dropzone.Reject>Invalid files</Dropzone.Reject>
<Dropzone.Idle>Drop files or click to select</Dropzone.Idle>
</Dropzone>
);
}Mantine Dropzone is built around several key components:
Main dropzone component providing file drag-and-drop functionality with extensive configuration options, validation, and Mantine theming integration.
interface DropzoneProps {
onDrop: (files: FileWithPath[]) => void;
onReject?: (fileRejections: FileRejection[]) => void;
onDropAny?: (files: FileWithPath[], fileRejections: FileRejection[]) => void;
accept?: Accept | string[];
maxSize?: number;
maxFiles?: number;
multiple?: boolean;
disabled?: boolean;
loading?: boolean;
children?: React.ReactNode;
}
const Dropzone: React.FC<DropzoneProps> & {
Accept: typeof DropzoneAccept;
Idle: typeof DropzoneIdle;
Reject: typeof DropzoneReject;
FullScreen: typeof DropzoneFullScreen;
};Conditional rendering components that show different content based on the current dropzone state (idle, accept, reject).
interface DropzoneStatusProps {
children: React.ReactNode;
}
const DropzoneAccept: React.FC<DropzoneStatusProps>;
const DropzoneIdle: React.FC<DropzoneStatusProps>;
const DropzoneReject: React.FC<DropzoneStatusProps>;Browser-wide dropzone overlay that appears when files are dragged over the browser window, providing a full-screen drop target.
interface DropzoneFullScreenProps {
onDrop?: (files: FileWithPath[]) => void;
onReject?: (fileRejections: FileRejection[]) => void;
active?: boolean;
zIndex?: React.CSSProperties['zIndex'];
withinPortal?: boolean;
portalProps?: Omit<BasePortalProps, 'withinPortal'>;
children?: React.ReactNode;
}
const DropzoneFullScreen: React.FC<DropzoneFullScreenProps>;Pre-defined constants and arrays for common file type filtering and validation.
const MIME_TYPES: {
png: 'image/png';
gif: 'image/gif';
jpeg: 'image/jpeg';
svg: 'image/svg+xml';
webp: 'image/webp';
avif: 'image/avif';
heic: 'image/heic';
heif: 'image/heif';
mp4: 'video/mp4';
zip: 'application/zip';
rar: 'application/x-rar';
'7z': 'application/x-7z-compressed';
csv: 'text/csv';
pdf: 'application/pdf';
doc: 'application/msword';
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
xls: 'application/vnd.ms-excel';
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
ppt: 'application/vnd.ms-powerpoint';
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
exe: 'application/vnd.microsoft.portable-executable';
};
const IMAGE_MIME_TYPE: string[];
const PDF_MIME_TYPE: string[];
const MS_WORD_MIME_TYPE: string[];
const MS_EXCEL_MIME_TYPE: string[];
const MS_POWERPOINT_MIME_TYPE: string[];
const EXE_MIME_TYPE: string[];interface FileWithPath extends File {
readonly path?: string;
}
interface FileRejection {
file: FileWithPath;
errors: FileError[];
}
interface FileError {
code: string;
message: string;
}
type Accept = Record<string, string[]>;
type DropEvent = React.DragEvent<HTMLElement> | Event;type DropzoneVariant = 'filled' | 'light';
type DropzoneStylesNames = 'root' | 'inner';
type DropzoneCssVariables = {
root:
| '--dropzone-radius'
| '--dropzone-accept-color'
| '--dropzone-accept-bg'
| '--dropzone-reject-color'
| '--dropzone-reject-bg';
};type DropzoneFactory = Factory<{
props: DropzoneProps;
ref: HTMLDivElement;
stylesNames: DropzoneStylesNames;
vars: DropzoneCssVariables;
staticComponents: {
Accept: typeof DropzoneAccept;
Idle: typeof DropzoneIdle;
Reject: typeof DropzoneReject;
FullScreen: typeof DropzoneFullScreen;
};
}>;type MantineColor = string;
type MantineRadius = number | string;
interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {}
interface StylesApiProps<T> {
classNames?: Partial<Record<string, string>>;
styles?: Partial<Record<string, React.CSSProperties>>;
unstyled?: boolean;
}
interface ElementProps<T extends keyof JSX.IntrinsicElements, K extends keyof JSX.IntrinsicElements[T] = never>
extends Omit<JSX.IntrinsicElements[T], K> {}
interface Factory<T> {
(props: T): React.ReactElement;
}
interface LoaderProps {
size?: string | number;
color?: string;
variant?: string;
}
interface BasePortalProps {
target?: HTMLElement | string;
children?: React.ReactNode;
}