-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File uploader beta upload restrictions example (#5338)
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
documentation-site/examples/file-uploader-beta/upload-restrictions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from "react"; | ||
import { FileUploaderBeta, type FileRow } from "baseui/file-uploader-beta"; | ||
|
||
export default function Example() { | ||
const [fileRows, setFileRows] = React.useState<Array<FileRow>>([]); | ||
|
||
const processFileOnDrop = ( | ||
file: File, | ||
): Promise<{ errorMessage: string | null; fileInfo?: any }> => { | ||
return new Promise((resolve) => { | ||
// Fake an upload process for 2 seconds | ||
// For a real-world scenario, replace this with application upload logic | ||
setTimeout(() => { | ||
let fileInfo = { | ||
file, | ||
objectID: "1234", | ||
uploadID: "1234", | ||
uploadStatus: "error", | ||
}; | ||
resolve({ errorMessage: "Custom user error", fileInfo }); | ||
}, 2000); | ||
}); | ||
}; | ||
|
||
return ( | ||
<FileUploaderBeta | ||
accept={["image/png", "application/pdf"]} | ||
fileRows={fileRows} | ||
hint={ | ||
'Try uploading files that break these conditions: 1. accept set to ["image/png", "application/pdf"], 2. minSize set to 20000 bytes (20 KB), 3. maxSize set to 100000 bytes (100 KB), 4. maxFiles set to 3' | ||
} | ||
maxFiles={3} | ||
maxSize={100000} | ||
minSize={20000} | ||
processFileOnDrop={processFileOnDrop} | ||
setFileRows={setFileRows} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters