@wavv/ui 2.3.8 → 2.3.9
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.
|
@@ -24,6 +24,8 @@ type Props = {
|
|
|
24
24
|
supportedFormats?: string[];
|
|
25
25
|
/** Maximum file size string to display (e.g., '25MB') */
|
|
26
26
|
maxFileSize?: string;
|
|
27
|
+
/** Controlled array of files */
|
|
28
|
+
files?: DropZoneFile[];
|
|
27
29
|
/** Callback when files are added. */
|
|
28
30
|
onFilesAdded?: (files: DropZoneFile[]) => void;
|
|
29
31
|
/** Callback when files are removed. */
|
|
@@ -44,5 +46,5 @@ type Props = {
|
|
|
44
46
|
defaultCamera?: FileTriggerProps['defaultCamera'];
|
|
45
47
|
acceptDirectory?: FileTriggerProps['acceptDirectory'];
|
|
46
48
|
} & MarginPadding & WidthHeight & Omit<DropZoneProps, 'isDisabled' | 'children'> & Omit<FileTriggerProps, 'children' | 'onSelect'>;
|
|
47
|
-
declare const DropZone: ({ label, showFileList, disabled, invalid, errorMessage, supportedFormats, maxFileSize, acceptedFileTypes, allowsMultiple, defaultCamera, acceptDirectory, onDrop, onFilesAdded, onFilesRemoved, width, margin, marginTop, marginRight, marginBottom, marginLeft, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
49
|
+
declare const DropZone: ({ label, showFileList, disabled, invalid, errorMessage, supportedFormats, maxFileSize, files: controlledFiles, acceptedFileTypes, allowsMultiple, defaultCamera, acceptDirectory, onDrop, onFilesAdded, onFilesRemoved, width, margin, marginTop, marginRight, marginBottom, marginLeft, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
48
50
|
export default DropZone;
|
|
@@ -6,8 +6,10 @@ import matchesFileTypes from "../utils/matchesFileTypes.js";
|
|
|
6
6
|
import Button from "./Button/index.js";
|
|
7
7
|
import FileTrigger from "./FileTrigger.js";
|
|
8
8
|
import { marginProps, paddingProps, widthHeightProps } from "./helpers/styledProps.js";
|
|
9
|
-
const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled, invalid, errorMessage, supportedFormats, maxFileSize, acceptedFileTypes, allowsMultiple, defaultCamera, acceptDirectory, onDrop, onFilesAdded, onFilesRemoved, width, margin, marginTop, marginRight, marginBottom, marginLeft, ...rest })=>{
|
|
10
|
-
const [
|
|
9
|
+
const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled, invalid, errorMessage, supportedFormats, maxFileSize, files: controlledFiles, acceptedFileTypes, allowsMultiple, defaultCamera, acceptDirectory, onDrop, onFilesAdded, onFilesRemoved, width, margin, marginTop, marginRight, marginBottom, marginLeft, ...rest })=>{
|
|
10
|
+
const [internalFiles, setInternalFiles] = useState([]);
|
|
11
|
+
const isControlled = void 0 !== controlledFiles;
|
|
12
|
+
const files = isControlled ? controlledFiles : internalFiles;
|
|
11
13
|
const [sizeValidationError, setSizeValidationError] = useState(null);
|
|
12
14
|
const [typeValidationError, setTypeValidationError] = useState(null);
|
|
13
15
|
const instanceId = useId();
|
|
@@ -64,7 +66,7 @@ const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled,
|
|
|
64
66
|
...files,
|
|
65
67
|
...newEntries
|
|
66
68
|
] : newEntries;
|
|
67
|
-
|
|
69
|
+
if (!isControlled) setInternalFiles(updatedFiles);
|
|
68
70
|
onFilesAdded?.(newEntries);
|
|
69
71
|
};
|
|
70
72
|
const handleFileDrop = async (event)=>{
|
|
@@ -99,7 +101,7 @@ const DropZone_DropZone = ({ label = 'Drop here', showFileList = true, disabled,
|
|
|
99
101
|
const handleRemoveFile = (id)=>{
|
|
100
102
|
const removedFile = files.find((file)=>file.id === id);
|
|
101
103
|
const updatedFiles = files.filter((file)=>file.id !== id);
|
|
102
|
-
|
|
104
|
+
if (!isControlled) setInternalFiles(updatedFiles);
|
|
103
105
|
if (removedFile) onFilesRemoved?.([
|
|
104
106
|
removedFile
|
|
105
107
|
]);
|