@pablo-v/file-upload 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/FileUpload.d.ts +34 -0
- package/dist/FileUpload.d.ts.map +1 -0
- package/dist/FileUpload.js +121 -0
- package/dist/FileUpload.js.map +1 -0
- package/dist/file-upload.css +169 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pablo Viniegra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pablo-v/file-upload
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Drag-and-drop file picker with a file list
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pnpm add @pablo-v/file-upload @pablo-v/tokens
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import '@pablo-v/tokens/styles.css';
|
|
11
|
+
import '@pablo-v/file-upload/style.css';
|
|
12
|
+
import { FileUpload } from '@pablo-v/file-upload';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Import `@pablo-v/pixel-icons/style.css` too if you want the drop icon to animate while a file is dragged over; without it the first frame shows.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, type ReactNode } from 'react';
|
|
2
|
+
export type FileRejectionReason = 'type' | 'size' | 'count';
|
|
3
|
+
export interface FileRejection {
|
|
4
|
+
file: File;
|
|
5
|
+
reason: FileRejectionReason;
|
|
6
|
+
}
|
|
7
|
+
export interface FileUploadProps extends Omit<ComponentPropsWithRef<'div'>, 'onChange' | 'defaultValue'> {
|
|
8
|
+
value?: File[];
|
|
9
|
+
defaultValue?: File[];
|
|
10
|
+
onChange?: (files: File[]) => void;
|
|
11
|
+
/** Files refused by `accept`, `maxSize` or `maxFiles`. */
|
|
12
|
+
onReject?: (rejections: FileRejection[]) => void;
|
|
13
|
+
/** Same syntax as the input attribute: `image/*,.pdf`. */
|
|
14
|
+
accept?: string;
|
|
15
|
+
multiple?: boolean;
|
|
16
|
+
/** Largest accepted file, in bytes. */
|
|
17
|
+
maxSize?: number;
|
|
18
|
+
maxFiles?: number;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
/** @default 'Drop files here or browse' */
|
|
21
|
+
label?: ReactNode;
|
|
22
|
+
/** Secondary line under the label, e.g. the accepted types. */
|
|
23
|
+
hint?: ReactNode;
|
|
24
|
+
/** Message shown under the zone for each refused file; `false` hides it. */
|
|
25
|
+
rejectionMessage?: false | ((rejection: FileRejection) => ReactNode);
|
|
26
|
+
}
|
|
27
|
+
export declare function formatBytes(bytes: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Drop zone over a native file input, with the chosen files listed below.
|
|
30
|
+
* Click, Enter or Space opens the picker; dropped files are validated against
|
|
31
|
+
* `accept`, `maxSize` and `maxFiles`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function FileUpload({ value: valueProp, defaultValue, onChange, onReject, accept, multiple, maxSize, maxFiles, disabled, label, hint, rejectionMessage, className, ...rest }: FileUploadProps): import("react").JSX.Element;
|
|
34
|
+
//# sourceMappingURL=FileUpload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileUpload.d.ts","sourceRoot":"","sources":["../src/FileUpload.tsx"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,qBAAqB,EAE1B,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AAEf,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED,MAAM,WAAW,eACf,SAAQ,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,UAAU,GAAG,cAAc,CAAC;IACvE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,KAAK,IAAI,CAAC;IACjD,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,SAAS,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC;CACtE;AAiBD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,UAQxC;AAcD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EAAE,SAAS,EAChB,YAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAgB,EAChB,OAAO,EACP,QAAQ,EACR,QAAgB,EAChB,KAAmC,EACnC,IAAI,EACJ,gBAAgB,EAChB,SAAS,EACT,GAAG,IAAI,EACR,EAAE,eAAe,+BAuIjB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cx, useControllableState } from '@pablo-v/core';
|
|
4
|
+
import { CloseIcon, FileIcon, UploadIcon, UploadingIcon, WarningIcon } from '@pablo-v/pixel-icons';
|
|
5
|
+
import { useId, useRef, useState, } from 'react';
|
|
6
|
+
function matches(file, accept) {
|
|
7
|
+
if (!accept)
|
|
8
|
+
return true;
|
|
9
|
+
const type = file.type.toLowerCase();
|
|
10
|
+
const name = file.name.toLowerCase();
|
|
11
|
+
return accept.split(',').some((raw) => {
|
|
12
|
+
const rule = raw.trim().toLowerCase();
|
|
13
|
+
if (!rule)
|
|
14
|
+
return false;
|
|
15
|
+
if (rule.startsWith('.'))
|
|
16
|
+
return name.endsWith(rule);
|
|
17
|
+
if (rule.endsWith('/*'))
|
|
18
|
+
return type.startsWith(rule.slice(0, -1));
|
|
19
|
+
return type === rule;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const units = ['B', 'KB', 'MB', 'GB'];
|
|
23
|
+
export function formatBytes(bytes) {
|
|
24
|
+
let n = bytes;
|
|
25
|
+
let unit = 0;
|
|
26
|
+
while (n >= 1024 && unit < units.length - 1) {
|
|
27
|
+
n /= 1024;
|
|
28
|
+
unit++;
|
|
29
|
+
}
|
|
30
|
+
return `${unit === 0 ? n : n.toFixed(n < 10 ? 1 : 0)} ${units[unit]}`;
|
|
31
|
+
}
|
|
32
|
+
function describeRejection({ file, reason }, maxSize, maxFiles) {
|
|
33
|
+
if (reason === 'type')
|
|
34
|
+
return `${file.name} is not an accepted file type`;
|
|
35
|
+
if (reason === 'size')
|
|
36
|
+
return `${file.name} is larger than ${formatBytes(maxSize ?? 0)}`;
|
|
37
|
+
return `${file.name} was not added: the limit is ${maxFiles} ${maxFiles === 1 ? 'file' : 'files'}`;
|
|
38
|
+
}
|
|
39
|
+
const fileKey = (file) => `${file.name}-${file.size}-${file.lastModified}`;
|
|
40
|
+
/**
|
|
41
|
+
* Drop zone over a native file input, with the chosen files listed below.
|
|
42
|
+
* Click, Enter or Space opens the picker; dropped files are validated against
|
|
43
|
+
* `accept`, `maxSize` and `maxFiles`.
|
|
44
|
+
*/
|
|
45
|
+
export function FileUpload({ value: valueProp, defaultValue = [], onChange, onReject, accept, multiple = false, maxSize, maxFiles, disabled = false, label = 'Drop files here or browse', hint, rejectionMessage, className, ...rest }) {
|
|
46
|
+
const [files, setFiles] = useControllableState({
|
|
47
|
+
value: valueProp,
|
|
48
|
+
defaultValue,
|
|
49
|
+
onChange,
|
|
50
|
+
});
|
|
51
|
+
const [dragging, setDragging] = useState(false);
|
|
52
|
+
const [rejected, setRejected] = useState([]);
|
|
53
|
+
const id = useId();
|
|
54
|
+
const inputRef = useRef(null);
|
|
55
|
+
const listRef = useRef(null);
|
|
56
|
+
const limit = multiple ? (maxFiles ?? Number.POSITIVE_INFINITY) : 1;
|
|
57
|
+
const errors = rejectionMessage === false
|
|
58
|
+
? []
|
|
59
|
+
: rejected.map((rejection) => ({
|
|
60
|
+
key: fileKey(rejection.file),
|
|
61
|
+
message: rejectionMessage
|
|
62
|
+
? rejectionMessage(rejection)
|
|
63
|
+
: describeRejection(rejection, maxSize, limit),
|
|
64
|
+
}));
|
|
65
|
+
const add = (incoming) => {
|
|
66
|
+
const rejections = [];
|
|
67
|
+
const accepted = [];
|
|
68
|
+
const base = multiple ? files : [];
|
|
69
|
+
const keys = new Set(base.map(fileKey));
|
|
70
|
+
for (const file of incoming) {
|
|
71
|
+
if (keys.has(fileKey(file)))
|
|
72
|
+
continue;
|
|
73
|
+
keys.add(fileKey(file));
|
|
74
|
+
if (!matches(file, accept))
|
|
75
|
+
rejections.push({ file, reason: 'type' });
|
|
76
|
+
else if (maxSize != null && file.size > maxSize)
|
|
77
|
+
rejections.push({ file, reason: 'size' });
|
|
78
|
+
else if (base.length + accepted.length >= limit)
|
|
79
|
+
rejections.push({ file, reason: 'count' });
|
|
80
|
+
else
|
|
81
|
+
accepted.push(file);
|
|
82
|
+
}
|
|
83
|
+
if (accepted.length)
|
|
84
|
+
setFiles([...base, ...accepted]);
|
|
85
|
+
setRejected(rejections);
|
|
86
|
+
if (rejections.length)
|
|
87
|
+
onReject?.(rejections);
|
|
88
|
+
};
|
|
89
|
+
// Focus moves to a neighbouring remove button, or back to the zone, so it is not lost with the row.
|
|
90
|
+
const remove = (index) => {
|
|
91
|
+
const buttons = listRef.current?.querySelectorAll('.pxl-file-upload__remove');
|
|
92
|
+
const next = buttons?.[index + 1] ?? buttons?.[index - 1];
|
|
93
|
+
if (next)
|
|
94
|
+
next.focus();
|
|
95
|
+
else
|
|
96
|
+
inputRef.current?.focus();
|
|
97
|
+
setRejected([]);
|
|
98
|
+
setFiles(files.filter((_, j) => j !== index));
|
|
99
|
+
};
|
|
100
|
+
const handleDrop = (event) => {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
setDragging(false);
|
|
103
|
+
if (!disabled)
|
|
104
|
+
add(Array.from(event.dataTransfer.files));
|
|
105
|
+
};
|
|
106
|
+
const handleInput = (event) => {
|
|
107
|
+
add(Array.from(event.target.files ?? []));
|
|
108
|
+
event.target.value = '';
|
|
109
|
+
};
|
|
110
|
+
return (_jsxs("div", { className: cx('pxl-file-upload', className), "data-disabled": disabled || undefined, ...rest, children: [_jsxs("label", { className: "pxl-file-upload__zone", "data-dragging": dragging || undefined, onDragOver: (event) => {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
if (!disabled)
|
|
113
|
+
setDragging(true);
|
|
114
|
+
}, onDragLeave: (event) => {
|
|
115
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
116
|
+
setDragging(false);
|
|
117
|
+
}, onDrop: handleDrop, children: [_jsx("input", { ref: inputRef, type: "file", className: "pxl-file-upload__input", accept: accept, multiple: multiple, disabled: disabled, "aria-describedby": [hint != null && `${id}-hint`, errors.length > 0 && `${id}-error`]
|
|
118
|
+
.filter(Boolean)
|
|
119
|
+
.join(' ') || undefined, onChange: handleInput }), _jsx("span", { className: "pxl-file-upload__icon", "aria-hidden": "true", children: dragging ? _jsx(UploadingIcon, {}) : _jsx(UploadIcon, {}) }), _jsx("span", { className: "pxl-file-upload__label", children: label }), hint != null && (_jsx("span", { id: `${id}-hint`, className: "pxl-file-upload__hint", children: hint }))] }), errors.length > 0 && (_jsx("div", { id: `${id}-error`, className: "pxl-file-upload__error", role: "alert", children: errors.map(({ key, message }) => (_jsxs("p", { className: "pxl-file-upload__message", children: [_jsx(WarningIcon, { className: "pxl-file-upload__message-icon" }), message] }, key))) })), files.length > 0 && (_jsx("ul", { ref: listRef, className: "pxl-file-upload__list", "aria-label": "Selected files", children: files.map((file, i) => (_jsxs("li", { className: "pxl-file-upload__file", children: [_jsx(FileIcon, {}), _jsx("span", { className: "pxl-file-upload__name", children: file.name }), _jsx("span", { className: "pxl-file-upload__size", children: formatBytes(file.size) }), _jsx("button", { type: "button", className: "pxl-file-upload__remove", "aria-label": `Remove ${file.name}`, disabled: disabled, onClick: () => remove(i), children: _jsx(CloseIcon, {}) })] }, fileKey(file)))) }))] }));
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=FileUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileUpload.js","sourceRoot":"","sources":["../src/FileUpload.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,EAAE,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAKL,KAAK,EACL,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AA+Bf,SAAS,OAAO,CAAC,IAAU,EAAE,MAA0B;IACrD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QACtC,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QACxB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CA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,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAChC,aAAa,SAAS,EAAC,0BAA0B,aAC/C,KAAC,WAAW,IAAC,SAAS,EAAC,+BAA+B,GAAG,EACxD,OAAO,KAFF,GAAG,CAGP,CACL,CAAC,GACE,CACP,EACA,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CACnB,aAAI,GAAG,EAAE,OAAO,EAAE,SAAS,EAAC,uBAAuB,gBAAY,gBAAgB,YAC5E,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CACtB,cAAwB,SAAS,EAAC,uBAAuB,aACvD,KAAC,QAAQ,KAAG,EACZ,eAAM,SAAS,EAAC,uBAAuB,YAAE,IAAI,CAAC,IAAI,GAAQ,EAC1D,eAAM,SAAS,EAAC,uBAAuB,YAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,GAAQ,EACvE,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,yBAAyB,gBACvB,UAAU,IAAI,CAAC,IAAI,EAAE,EACjC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,YAExB,KAAC,SAAS,KAAG,GACN,KAZF,OAAO,CAAC,IAAI,CAAC,CAajB,CACN,CAAC,GACC,CACN,IACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
.pxl-file-upload {
|
|
2
|
+
display: grid;
|
|
3
|
+
gap: var(--pxl-space-3);
|
|
4
|
+
font-family: var(--pxl-font-sans);
|
|
5
|
+
font-size: var(--pxl-text-sm);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.pxl-file-upload__zone {
|
|
9
|
+
position: relative;
|
|
10
|
+
display: grid;
|
|
11
|
+
justify-items: center;
|
|
12
|
+
gap: var(--pxl-space-1);
|
|
13
|
+
padding: var(--pxl-space-8) var(--pxl-space-6);
|
|
14
|
+
border: 1px dashed var(--pxl-gray-600);
|
|
15
|
+
border-radius: var(--pxl-radius-lg);
|
|
16
|
+
background: var(--pxl-bg-subtle);
|
|
17
|
+
color: var(--pxl-fg);
|
|
18
|
+
text-align: center;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
transition:
|
|
21
|
+
background-color var(--pxl-dur-fast) linear,
|
|
22
|
+
border-color var(--pxl-dur-fast) linear;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.pxl-file-upload__zone:hover {
|
|
26
|
+
border-color: var(--pxl-gray-800);
|
|
27
|
+
background: var(--pxl-bg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.pxl-file-upload__zone[data-dragging] {
|
|
31
|
+
border-style: solid;
|
|
32
|
+
border-color: var(--pxl-accent);
|
|
33
|
+
background: var(--pxl-accent-subtle);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.pxl-file-upload__zone:has(:focus-visible) {
|
|
37
|
+
outline: 2px solid var(--pxl-accent);
|
|
38
|
+
outline-offset: 2px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.pxl-file-upload[data-disabled] .pxl-file-upload__zone {
|
|
42
|
+
border-color: var(--pxl-border);
|
|
43
|
+
opacity: var(--pxl-opacity-disabled);
|
|
44
|
+
cursor: not-allowed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.pxl-file-upload__input {
|
|
48
|
+
position: absolute;
|
|
49
|
+
width: 1px;
|
|
50
|
+
height: 1px;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
clip-path: inset(50%);
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.pxl-file-upload__icon {
|
|
57
|
+
display: grid;
|
|
58
|
+
place-items: center;
|
|
59
|
+
width: var(--pxl-size-md);
|
|
60
|
+
height: var(--pxl-size-md);
|
|
61
|
+
margin-bottom: var(--pxl-space-2);
|
|
62
|
+
border: 1px solid var(--pxl-border);
|
|
63
|
+
border-radius: var(--pxl-radius-md);
|
|
64
|
+
background: var(--pxl-bg);
|
|
65
|
+
color: var(--pxl-fg-muted);
|
|
66
|
+
transition:
|
|
67
|
+
color var(--pxl-dur-fast) linear,
|
|
68
|
+
translate var(--pxl-dur-base) var(--pxl-ease-spring);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.pxl-file-upload__zone[data-dragging] .pxl-file-upload__icon {
|
|
72
|
+
color: var(--pxl-accent-text);
|
|
73
|
+
translate: 0 -4px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.pxl-file-upload__label {
|
|
77
|
+
font-weight: 500;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.pxl-file-upload__hint {
|
|
81
|
+
color: var(--pxl-fg-muted);
|
|
82
|
+
font-size: var(--pxl-text-xs);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.pxl-file-upload__error {
|
|
86
|
+
display: grid;
|
|
87
|
+
gap: var(--pxl-space-1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.pxl-file-upload__message {
|
|
91
|
+
display: flex;
|
|
92
|
+
align-items: flex-start;
|
|
93
|
+
gap: var(--pxl-space-2);
|
|
94
|
+
margin: 0;
|
|
95
|
+
color: var(--pxl-danger);
|
|
96
|
+
font-size: var(--pxl-text-sm);
|
|
97
|
+
line-height: 1.5;
|
|
98
|
+
text-wrap: pretty;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* Optically centre the 16px icon on the first 13px/1.5 line, as in Field. */
|
|
102
|
+
.pxl-file-upload__message-icon {
|
|
103
|
+
flex: none;
|
|
104
|
+
margin-top: 2px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.pxl-file-upload__list {
|
|
108
|
+
display: grid;
|
|
109
|
+
gap: var(--pxl-space-1);
|
|
110
|
+
margin: 0;
|
|
111
|
+
padding: 0;
|
|
112
|
+
list-style: none;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.pxl-file-upload__file {
|
|
116
|
+
display: flex;
|
|
117
|
+
align-items: center;
|
|
118
|
+
gap: var(--pxl-space-2);
|
|
119
|
+
height: var(--pxl-size-md);
|
|
120
|
+
padding: 0 var(--pxl-space-1) 0 var(--pxl-space-3);
|
|
121
|
+
border: 1px solid var(--pxl-border);
|
|
122
|
+
border-radius: var(--pxl-radius-md);
|
|
123
|
+
background: var(--pxl-bg);
|
|
124
|
+
color: var(--pxl-fg-muted);
|
|
125
|
+
animation: pxl-pop-in var(--pxl-dur-base) var(--pxl-ease-out);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.pxl-file-upload__name {
|
|
129
|
+
flex: 1;
|
|
130
|
+
min-width: 0;
|
|
131
|
+
overflow: hidden;
|
|
132
|
+
color: var(--pxl-fg);
|
|
133
|
+
text-overflow: ellipsis;
|
|
134
|
+
white-space: nowrap;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.pxl-file-upload__size {
|
|
138
|
+
flex: none;
|
|
139
|
+
font-family: var(--pxl-font-mono);
|
|
140
|
+
font-size: var(--pxl-text-xs);
|
|
141
|
+
font-variant-numeric: tabular-nums;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.pxl-file-upload__remove {
|
|
145
|
+
display: grid;
|
|
146
|
+
flex: none;
|
|
147
|
+
place-items: center;
|
|
148
|
+
width: var(--pxl-size-sm);
|
|
149
|
+
height: var(--pxl-size-sm);
|
|
150
|
+
padding: 0;
|
|
151
|
+
border: 0;
|
|
152
|
+
border-radius: var(--pxl-radius-sm);
|
|
153
|
+
background: transparent;
|
|
154
|
+
color: var(--pxl-fg-muted);
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
transition:
|
|
157
|
+
background-color var(--pxl-dur-fast) linear,
|
|
158
|
+
color var(--pxl-dur-fast) linear;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.pxl-file-upload__remove:hover:not(:disabled) {
|
|
162
|
+
background: var(--pxl-gray-100);
|
|
163
|
+
color: var(--pxl-fg);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.pxl-file-upload__remove:focus-visible {
|
|
167
|
+
outline: 2px solid var(--pxl-accent);
|
|
168
|
+
outline-offset: -2px;
|
|
169
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,UAAU,EACV,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAEV,WAAW,GACZ,MAAM,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pablo-v/file-upload",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Drag-and-drop file picker with a file list",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/PabloViniegra/pixel-ui.git",
|
|
9
|
+
"directory": "packages/file-upload"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"*.css"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"source": "./src/index.ts",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./style.css": {
|
|
22
|
+
"source": "./src/file-upload.css",
|
|
23
|
+
"default": "./dist/file-upload.css"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@pablo-v/core": "^0.2.1",
|
|
32
|
+
"@pablo-v/pixel-icons": "^1.3.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": "^19.0.0",
|
|
36
|
+
"@pablo-v/tokens": "^0.2.4"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -b && node ../../scripts/copy-assets.mjs",
|
|
43
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
44
|
+
}
|
|
6
45
|
}
|