@sqlrooms/dropzone 0.0.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.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint.log +4 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +9 -0
- package/dist/file-dropzone.d.ts +11 -0
- package/dist/file-dropzone.d.ts.map +1 -0
- package/dist/file-dropzone.js +25 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/eslint.config.js +4 -0
- package/package.json +30 -0
- package/src/file-dropzone.tsx +85 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +12 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Ilya Boyandin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
export type Props = {
|
|
3
|
+
className?: string;
|
|
4
|
+
isInvalid?: boolean;
|
|
5
|
+
onDrop: (files: File[]) => Promise<void>;
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
acceptedFormats?: Record<string, string[]>;
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export declare const FileDropzone: FC<Props>;
|
|
11
|
+
//# sourceMappingURL=file-dropzone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-dropzone.d.ts","sourceRoot":"","sources":["../src/file-dropzone.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,EAAE,EAAW,MAAM,OAAO,CAAC;AAKnC,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,EAAE,CAAC,KAAK,CAsElC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { useDropzone } from 'react-dropzone';
|
|
4
|
+
import { Plus } from 'lucide-react';
|
|
5
|
+
import { cn, Spinner } from '@sqlrooms/ui';
|
|
6
|
+
export const FileDropzone = (props) => {
|
|
7
|
+
const { isInvalid, onDrop, multiple = true, className, acceptedFormats, children, } = props;
|
|
8
|
+
const [isAddingDropped, setIsAddingDropped] = useState(false);
|
|
9
|
+
const { getRootProps, getInputProps, isDragActive, open } = useDropzone({
|
|
10
|
+
onDrop: async (files) => {
|
|
11
|
+
setIsAddingDropped(true);
|
|
12
|
+
try {
|
|
13
|
+
await onDrop(files);
|
|
14
|
+
}
|
|
15
|
+
finally {
|
|
16
|
+
setIsAddingDropped(false);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
accept: acceptedFormats,
|
|
20
|
+
multiple,
|
|
21
|
+
noClick: true,
|
|
22
|
+
noKeyboard: true,
|
|
23
|
+
});
|
|
24
|
+
return (_jsx("div", { className: cn('relative flex h-full cursor-pointer flex-col overflow-hidden rounded-lg border-2 border-dashed p-2 transition-colors', isDragActive ? 'border-muted bg-muted/50' : 'border-muted', isInvalid && 'border-destructive', !isAddingDropped && 'hover:border-muted', className), ...getRootProps(), onClick: isAddingDropped ? undefined : open, children: isAddingDropped ? (_jsxs("div", { className: "flex h-full w-full items-center justify-center gap-4 text-xs text-muted-foreground", children: [_jsx(Spinner, { className: "h-4 w-4" }), "Adding files..."] })) : (_jsxs(_Fragment, { children: [_jsx("input", { ...getInputProps() }), _jsx("div", { className: "relative flex h-full flex-col", children: _jsxs("div", { className: "flex h-full flex-col items-center justify-center gap-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Plus, { className: "h-6 w-6" }), _jsx("p", { className: "text-sm text-muted-foreground", children: isDragActive ? 'Drop here ...' : 'Add files' })] }), acceptedFormats && (_jsxs("div", { className: "flex flex-wrap justify-center gap-2", children: [_jsx("p", { className: "text-xs font-bold", children: "Supported formats:" }), _jsx("p", { className: "text-xs text-muted-foreground", children: Object.values(acceptedFormats).flat().join(', ') })] })), children] }) })] })) }));
|
|
25
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file-dropzone';
|
package/eslint.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sqlrooms/dropzone",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "src/index.ts",
|
|
11
|
+
"module": "dist/index.js",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./src/index.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./src/*": "./src/components/*.tsx"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "tsc -w",
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"lint": "eslint ."
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@sqlrooms/ui": "0.0.0",
|
|
26
|
+
"lucide-react": "^0.473.0",
|
|
27
|
+
"react-dropzone": "^14.3.5"
|
|
28
|
+
},
|
|
29
|
+
"gitHead": "4b0c709542475e4f95db0b2a8405ecadcf2ec186"
|
|
30
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {FC, useState} from 'react';
|
|
2
|
+
import {useDropzone} from 'react-dropzone';
|
|
3
|
+
import {Plus} from 'lucide-react';
|
|
4
|
+
import {cn, Spinner} from '@sqlrooms/ui';
|
|
5
|
+
|
|
6
|
+
export type Props = {
|
|
7
|
+
className?: string;
|
|
8
|
+
isInvalid?: boolean;
|
|
9
|
+
onDrop: (files: File[]) => Promise<void>;
|
|
10
|
+
multiple?: boolean;
|
|
11
|
+
acceptedFormats?: Record<string, string[]>;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const FileDropzone: FC<Props> = (props) => {
|
|
16
|
+
const {
|
|
17
|
+
isInvalid,
|
|
18
|
+
onDrop,
|
|
19
|
+
multiple = true,
|
|
20
|
+
className,
|
|
21
|
+
acceptedFormats,
|
|
22
|
+
children,
|
|
23
|
+
} = props;
|
|
24
|
+
|
|
25
|
+
const [isAddingDropped, setIsAddingDropped] = useState(false);
|
|
26
|
+
|
|
27
|
+
const {getRootProps, getInputProps, isDragActive, open} = useDropzone({
|
|
28
|
+
onDrop: async (files) => {
|
|
29
|
+
setIsAddingDropped(true);
|
|
30
|
+
try {
|
|
31
|
+
await onDrop(files);
|
|
32
|
+
} finally {
|
|
33
|
+
setIsAddingDropped(false);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
accept: acceptedFormats,
|
|
37
|
+
multiple,
|
|
38
|
+
noClick: true,
|
|
39
|
+
noKeyboard: true,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
className={cn(
|
|
45
|
+
'relative flex h-full cursor-pointer flex-col overflow-hidden rounded-lg border-2 border-dashed p-2 transition-colors',
|
|
46
|
+
isDragActive ? 'border-muted bg-muted/50' : 'border-muted',
|
|
47
|
+
isInvalid && 'border-destructive',
|
|
48
|
+
!isAddingDropped && 'hover:border-muted',
|
|
49
|
+
className,
|
|
50
|
+
)}
|
|
51
|
+
{...getRootProps()}
|
|
52
|
+
onClick={isAddingDropped ? undefined : open}
|
|
53
|
+
>
|
|
54
|
+
{isAddingDropped ? (
|
|
55
|
+
<div className="flex h-full w-full items-center justify-center gap-4 text-xs text-muted-foreground">
|
|
56
|
+
<Spinner className="h-4 w-4" />
|
|
57
|
+
Adding files...
|
|
58
|
+
</div>
|
|
59
|
+
) : (
|
|
60
|
+
<>
|
|
61
|
+
<input {...getInputProps()} />
|
|
62
|
+
<div className="relative flex h-full flex-col">
|
|
63
|
+
<div className="flex h-full flex-col items-center justify-center gap-2">
|
|
64
|
+
<div className="flex items-center gap-2">
|
|
65
|
+
<Plus className="h-6 w-6" />
|
|
66
|
+
<p className="text-sm text-muted-foreground">
|
|
67
|
+
{isDragActive ? 'Drop here ...' : 'Add files'}
|
|
68
|
+
</p>
|
|
69
|
+
</div>
|
|
70
|
+
{acceptedFormats && (
|
|
71
|
+
<div className="flex flex-wrap justify-center gap-2">
|
|
72
|
+
<p className="text-xs font-bold">Supported formats:</p>
|
|
73
|
+
<p className="text-xs text-muted-foreground">
|
|
74
|
+
{Object.values(acceptedFormats).flat().join(', ')}
|
|
75
|
+
</p>
|
|
76
|
+
</div>
|
|
77
|
+
)}
|
|
78
|
+
{children}
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</>
|
|
82
|
+
)}
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file-dropzone';
|
package/tsconfig.json
ADDED