Skip to content

Commit

Permalink
Add FileUploaderBeta Basic Example (#5337)
Browse files Browse the repository at this point in the history
  • Loading branch information
epfeiffe committed Jun 28, 2024
1 parent 41166cd commit 9f7f6b6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
40 changes: 40 additions & 0 deletions documentation-site/examples/file-uploader-beta/basic.tsx
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}
/>
);
}
8 changes: 8 additions & 0 deletions documentation-site/pages/components/file-uploader-beta.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Example from "../../components/example";
import Layout from "../../components/layout";
import Exports from "../../components/exports";

import FileUploaderBetaBasic from "examples/file-uploader-beta/basic.tsx";

import * as FileUploaderBetaExports from "baseui/file-uploader-beta";

import Yard from "../../components/yard/index";
Expand Down Expand Up @@ -36,6 +38,12 @@ By default, the file uploader does not concern itself with validating and discar

To learn more, read the corresponding [OWASP article on file uploads](https://www.owasp.org/index.php/Unrestricted_File_Upload).

## Examples

<Example title="Basic usage" path="file-uploader-beta/basic.tsx">
<FileUploaderBetaBasic />
</Example>

<Exports
component={FileUploaderBetaExports}
title="File uploader beta exports"
Expand Down

0 comments on commit 9f7f6b6

Please sign in to comment.