Skip to content

Commit

Permalink
File uploader beta item preview example (#5339)
Browse files Browse the repository at this point in the history
  • Loading branch information
epfeiffe committed Jun 28, 2024
1 parent f9b49b6 commit 88edd5d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions documentation-site/examples/file-uploader-beta/item-preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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: "success",
};
resolve({ errorMessage: null, fileInfo });
}, 2000);
});
};

return (
<FileUploaderBeta
fileRows={fileRows}
hint={
"Try uploading a file to see the item preview. Image files will show a thumbnail."
}
itemPreview
processFileOnDrop={processFileOnDrop}
setFileRows={setFileRows}
/>
);
}
5 changes: 5 additions & 0 deletions documentation-site/pages/components/file-uploader-beta.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Layout from "../../components/layout";
import Exports from "../../components/exports";

import FileUploaderBetaBasic from "examples/file-uploader-beta/basic.tsx";
import FileUploaderBetaItemPreview from "examples/file-uploader-beta/item-preview.tsx";
import FileUploaderBetaUploadRestrictions from "examples/file-uploader-beta/upload-restrictions.tsx";

import * as FileUploaderBetaExports from "baseui/file-uploader-beta";
Expand Down Expand Up @@ -45,6 +46,10 @@ To learn more, read the corresponding [OWASP article on file uploads](https://ww
<FileUploaderBetaBasic />
</Example>

<Example title="Item preview" path="file-uploader-beta/item-preview.tsx">
<FileUploaderBetaItemPreview />
</Example>

<Example
title="Upload restrictions"
path="file-uploader-beta/upload-restrictions.tsx"
Expand Down

0 comments on commit 88edd5d

Please sign in to comment.