-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FileUploaderBeta Basic Example (#5337)
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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>>([ | ||
{ | ||
file: new File(["test file"], "file.txt"), | ||
status: "processed", | ||
errorMessage: null, | ||
}, | ||
]); | ||
|
||
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: "success", | ||
}; | ||
resolve({ errorMessage: null, fileInfo }); | ||
}, 2000); | ||
}); | ||
}; | ||
|
||
return ( | ||
<FileUploaderBeta | ||
fileRows={fileRows} | ||
itemPreview | ||
maxFiles={5} | ||
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