diff --git a/src/components/demo-components/dropzone-demo/CodeDemoDropzoneActionButtons.jsx b/src/components/demo-components/dropzone-demo/CodeDemoDropzoneActionButtons.jsx index 4d2c8ee3da6ba9acc78d6f3326be367fcfa7350a..1a91e3a18b12ba9f7bd7bac19d30087cbf561544 100644 --- a/src/components/demo-components/dropzone-demo/CodeDemoDropzoneActionButtons.jsx +++ b/src/components/demo-components/dropzone-demo/CodeDemoDropzoneActionButtons.jsx @@ -1,5 +1,5 @@ import ShowDemoCode from "../../show-demo-code/ShowDemoCode"; -const CodeDemoDropzoneActionButtons = ({ splittedOnly = false }) => { +const CodeDemoDropzoneActionButtons = ({ splittedOnly = false,button }) => { return ( <ShowDemoCode splittedOnly={splittedOnly} diff --git a/src/components/demo-components/dropzone-demo/CodeDemoDropzoneUploading.jsx b/src/components/demo-components/dropzone-demo/CodeDemoDropzoneUploading.jsx index ce53cfa9e72b2220744e097348b8ff6c51c59a9f..69324428f5094369dd028b430c2f63ba414233f1 100644 --- a/src/components/demo-components/dropzone-demo/CodeDemoDropzoneUploading.jsx +++ b/src/components/demo-components/dropzone-demo/CodeDemoDropzoneUploading.jsx @@ -1,6 +1,18 @@ import ShowDemoCode from "../../show-demo-code/ShowDemoCode"; -const CodeDemoDropzoneUploading = ({ splittedOnly = false }) => { +const CodeDemoDropzoneUploading = ({ splittedOnly = false, button=false }) => { + if (button) return ( + <ShowDemoCode + splittedOnly={splittedOnly} + codeCompleteJS={completeCodeJSButton} + codeCompleteTS={completeCodeTSButton} + codeSandboxJS="https://codesandbox.io/s/dropzone-ui-basic-3j01v" + codeSandboxTS="https://codesandbox.io/s/dropzone-ui-basic-3j01v" + codeSplittedJS={splittedCodeJSButton} + codeSplittedTS={splittedCodeTSButton} + /> + ); + return ( <ShowDemoCode splittedOnly={splittedOnly} codeCompleteJS={completeCodeJS} @@ -14,6 +26,200 @@ const CodeDemoDropzoneUploading = ({ splittedOnly = false }) => { }; export default CodeDemoDropzoneUploading; + +const splittedCodeJSButton = `<FileInputButton + onChange={updateFiles} + value={files} + accept={"image/*"} + maxFileSize={28 * 1024 * 1024} + maxFiles={2} + actionButtons={{ + position: "bottom", + uploadButton: {}, + abortButton: {}, + }} + uploadConfig={{ + url: "https://www.myawsomeserver.com/upload", + method: "POST", + headers: { + Authorization: + "bearer HTIBI/IBYG/&GU&/GV%&G/&IC%&V/Ibi76bfh8g67gg68g67i6g7G&58768&/(&/(FR&G/&H%&/", + }, + cleanOnUpload: true, + }} + onUploadFinish={handleFinishUpload} + fakeUpload +/> +{files.map((file) => ( + <FileCard key={file.id} {...file} onDelete={removeFile} info preview/> +))}`; +const splittedCodeTSButton = `<FileInputButton + onChange={updateFiles} + value={files} + accept={"image/*"} + maxFileSize={28 * 1024 * 1024} + maxFiles={2} + actionButtons={{ + position: "bottom", + uploadButton: {}, + abortButton: {}, + }} + uploadConfig={{ + url: "https://www.myawsomeserver.com/upload", + method: "POST", + headers: { + Authorization: + "bearer HTIBI/IBYG/&GU&/GV%&G/&IC%&V/Ibi76bfh8g67gg68g67i6g7G&58768&/(&/(FR&G/&H%&/", + }, + cleanOnUpload: true, + }} + onUploadFinish={handleFinishUpload} + fakeUpload +/> +{files.map((file: ExtFile) => ( + <FileCard key={file.id} {...file} onDelete={removeFile} info preview/> +))}`; +const completeCodeJSButton =`import { FileInputButton, FileCard } from "@files-ui/react"; +import * as React from "react"; + +export default function App() { + const [files, setFiles] = React.useState([]); + const updateFiles = (incommingFiles) => { + //do something with the files + setFiles(incommingFiles); + //even your own upload implementation + }; + const removeFile = (id) => { + setFiles(files.filter((x) => x.id !== id)); + }; + const handleFinishUpload=(uploadedFiles)=>{ + console.log("Upload has finished", uploadedFiles); + } + return ( + <div + style={{ + display: "flex", + alignItems: "center", + justifyContent: "space-evenly", + gap: "10px", + flexWrap: "wrap", + width: "100%", + }} + > + <FileInputButton + onChange={updateFiles} + value={files} + accept={"image/*"} + maxFileSize={28 * 1024 * 1024} + maxFiles={2} + actionButtons={{ + position: "bottom", + uploadButton: {}, + abortButton: {}, + }} + uploadConfig={{ + url: "https://www.myawsomeserver.com/upload", + method: "POST", + headers: { + Authorization: + "bearer HTIBI/IBYG/&GU&/GV%&G/&IC%&V/Ibi76bfh8g67gg68g67i6g7G&58768&/(&/(FR&G/&H%&/", + }, + cleanOnUpload: true, + }} + onUploadFinish={handleFinishUpload} + fakeUpload + /> + {files.length > 0 && ( + <div + style={{ + display: "flex", + justifyContent:"center", + flexWrap:"wrap", + gap:"5px", + minWidth:"50%" + }} + > + {files.map((file) => ( + <FileCard key={file.id} {...file} onDelete={removeFile} info preview/> + ))} + </div> + )} + </div> + ); +}`; +const completeCodeTSButton = `import { FileInputButton, FileCard, ExtFile } from "@files-ui/react"; +import * as React from "react"; + +export default function App() { + const [files, setFiles] = React.useState<ExtFile[]>([]); + const updateFiles = (incommingFiles:ExtFile[]) => { + //do something with the files + setFiles(incommingFiles); + //even your own upload implementation + }; + const removeFile = (id: number | string | undefined) => { + setFiles(files.filter((x) => x.id !== id)); + }; + const handleFinishUpload=(uploadedFiles:ExtFile[])=>{ + console.log("Upload has finished", uploadedFiles); + } + return ( + <div + style={{ + display: "flex", + alignItems: "center", + justifyContent: "space-evenly", + gap: "10px", + flexWrap: "wrap", + width: "100%", + }} + > + <FileInputButton + onChange={updateFiles} + value={files} + accept={"image/*"} + maxFileSize={28 * 1024 * 1024} + maxFiles={2} + actionButtons={{ + position: "bottom", + uploadButton: {}, + abortButton: {}, + }} + uploadConfig={{ + url: "https://www.myawsomeserver.com/upload", + method: "POST", + headers: { + Authorization: + "bearer HTIBI/IBYG/&GU&/GV%&G/&IC%&V/Ibi76bfh8g67gg68g67i6g7G&58768&/(&/(FR&G/&H%&/", + }, + cleanOnUpload: true, + }} + onUploadFinish={handleFinishUpload} + fakeUpload + /> + {files.length > 0 && ( + <div + style={{ + display: "flex", + justifyContent:"center", + flexWrap:"wrap", + gap:"5px", + minWidth:"50%" + }} + > + {files.map((file: ExtFile) => ( + <FileCard key={file.id} {...file} onDelete={removeFile} info preview/> + ))} + </div> + )} + </div> + ); +}`; + +///// + + + const splittedCodeJS = `<Dropzone onChange={updateFiles} value={files} @@ -30,11 +236,12 @@ const splittedCodeJS = `<Dropzone }, cleanOnUpload: true, }} + onUploadFinish={handleFinishUpload} fakeUpload > {files.length > 0 && files.map((file) => ( - <FileMosaic key={file.id} {...file} onDelete={removeFile} info/> + <FileMosaic key={file.id} {...file} onDelete={removeFile} info preview/> ))} </Dropzone>`; const splittedCodeTS = `<Dropzone @@ -53,11 +260,12 @@ const splittedCodeTS = `<Dropzone }, cleanOnUpload: true, }} + onUploadFinish={handleFinishUpload} fakeUpload > {files.length > 0 && files.map((file: ExtFile) => ( - <FileMosaic key={file.id} {...file} onDelete={removeFile} info/> + <FileMosaic key={file.id} {...file} onDelete={removeFile} info preview/> ))} </Dropzone>`; const completeCodeJS = `import { Dropzone,FileMosaic } from "@files-ui/react"; @@ -94,7 +302,7 @@ export default function App() { > {files.length > 0 && files.map((file) => ( - <FileMosaic key={file.id} {...file} onDelete={removeFile} info /> + <FileMosaic key={file.id} {...file} onDelete={removeFile} info preview/> ))} </Dropzone> ); @@ -134,7 +342,7 @@ export default function App() { > {files.length > 0 && files.map((file:ExtFile) => ( - <FileMosaic key={file.id} {...file} onDelete={removeFile} info /> + <FileMosaic key={file.id} {...file} onDelete={removeFile} info preview/> ))} </Dropzone> ); diff --git a/src/components/demo-components/dropzone-demo/DemoDropzoneActionButtons.jsx b/src/components/demo-components/dropzone-demo/DemoDropzoneActionButtons.jsx index 955d11b99a07be54c33ab668b0aa1ea5c085e9b9..a7cd9b2c46d5d5cf586faf6a9a61b5e8e4d89a58 100644 --- a/src/components/demo-components/dropzone-demo/DemoDropzoneActionButtons.jsx +++ b/src/components/demo-components/dropzone-demo/DemoDropzoneActionButtons.jsx @@ -1,7 +1,7 @@ import * as React from "react"; import { Dropzone, FileMosaic } from "../../../files-ui"; -const DemoDropzoneActionButtons = (props) => { +const DemoDropzoneActionButtons = ({button}) => { const [files, setFiles] = React.useState([]); const updateFiles = (incommingFiles) => { //do something with the files diff --git a/src/components/demo-components/dropzone-demo/DemoDropzoneUploading.jsx b/src/components/demo-components/dropzone-demo/DemoDropzoneUploading.jsx index 47757694c38db7e4f50d05aa3217d6bafdb69bd0..2a43ef33abdeaa8d6ef7328d25d20dd0734aa6fd 100644 --- a/src/components/demo-components/dropzone-demo/DemoDropzoneUploading.jsx +++ b/src/components/demo-components/dropzone-demo/DemoDropzoneUploading.jsx @@ -1,7 +1,12 @@ import * as React from "react"; -import { Dropzone, FileMosaic } from "../../../files-ui"; +import { + Dropzone, + FileCard, + FileInputButton, + FileMosaic, +} from "../../../files-ui"; -const DemoDropzoneUploading = (props) => { +const DemoDropzoneUploading = ({ button }) => { const [files, setFiles] = React.useState([]); const updateFiles = (incommingFiles) => { //do something with the files @@ -11,12 +16,67 @@ const DemoDropzoneUploading = (props) => { const removeFile = (id) => { setFiles(files.filter((x) => x.id !== id)); }; + const handleFinishUpload=(uploadedFiles)=>{ + console.log("Upload has finished", uploadedFiles); + } + if (button) + return ( + <div + style={{ + display: "flex", + alignItems: "center", + justifyContent: "space-evenly", + gap: "10px", + flexWrap: "wrap", + width: "100%", + }} + > + <FileInputButton + onChange={updateFiles} + value={files} + accept={"image/*"} + maxFileSize={28 * 1024 * 1024} + maxFiles={2} + actionButtons={{ + position: "bottom", + uploadButton: {}, + abortButton: {}, + }} + uploadConfig={{ + url: "https://www.myawsomeserver.com/upload", + method: "POST", + headers: { + Authorization: + "bearer HTIBI/IBYG/&GU&/GV%&G/&IC%&V/Ibi76bfh8g67gg68g67i6g7G&58768&/(&/(FR&G/&H%&/", + }, + cleanOnUpload: true, + }} + onUploadFinish={handleFinishUpload} + fakeUpload + /> + {files.length > 0 && ( + <div + style={{ + display: "flex", + justifyContent: "center", + flexWrap: "wrap", + gap: "5px", + minWidth: "50%", + }} + > + {files.map((file) => ( + <FileCard key={file.id} {...file} onDelete={removeFile} info preview/> + ))} + </div> + )} + </div> + ); return ( <Dropzone onChange={updateFiles} value={files} accept={"image/*"} - maxFileSize={28 * 1024*1024} + maxFileSize={28 * 1024 * 1024} maxFiles={2} actionButtons={{ position: "bottom", uploadButton: {}, abortButton: {} }} uploadConfig={{ @@ -28,11 +88,12 @@ const DemoDropzoneUploading = (props) => { }, cleanOnUpload: true, }} + onUploadFinish={handleFinishUpload} fakeUpload > {files.length > 0 && files.map((file) => ( - <FileMosaic key={file.id} {...file} onDelete={removeFile} info /> + <FileMosaic key={file.id} {...file} onDelete={removeFile} info preview/> ))} </Dropzone> ); diff --git a/src/pages/demo/DropzoneDemoPage.jsx b/src/pages/demo/DropzoneDemoPage.jsx index 935aac1ca78027994b5016d2fc9e385a202ebfa0..eba342f7c8e98568b5d5c8c5724fa29a7b8506d7 100644 --- a/src/pages/demo/DropzoneDemoPage.jsx +++ b/src/pages/demo/DropzoneDemoPage.jsx @@ -199,10 +199,11 @@ const DropzoneDemoPage = (props) => { </DescParagraph> <Paper variant="outlined" style={{ padding: "25px" }}> - <DemoDropzoneUploading /> + <DemoDropzoneUploading button/> </Paper> - <CodeDemoDropzoneUploading /> + <CodeDemoDropzoneUploading button/> + <Alert severity="info"> <AlertTitle> Server response </AlertTitle> For uploading files through files-ui, server must return the @@ -219,8 +220,8 @@ const DropzoneDemoPage = (props) => { <Alert severity="info"> <AlertTitle> "fakeUpload" </AlertTitle> By giving this prop, the {"<Dropzone/>"} component will simulate the - upload operation by randomly set the upload status and message in - ech uploadable <TypeHighlight>ExtFile</TypeHighlight>. It also will + upload operation by randomly set the upload status and message on + each uploadable <TypeHighlight>ExtFile</TypeHighlight>. It will also set a fake progress. </Alert> <br /> @@ -238,7 +239,7 @@ const DropzoneDemoPage = (props) => { <li> <TypeHighlight>cleanOnUpload</TypeHighlight> : By setting this prop, you can control whether the upload process should "clean" - the non valid files before uploading or not By default this + the non valid files before uploading or not. By default this value is true. </li> </ul> diff --git a/src/pages/demo/FileInputButtonDemoPage.tsx b/src/pages/demo/FileInputButtonDemoPage.tsx index 6dfb619f4b20e2fbc7e5df9df281dd6542177968..a94655b007b075a96a1c87fbe4d18b9170b76554 100644 --- a/src/pages/demo/FileInputButtonDemoPage.tsx +++ b/src/pages/demo/FileInputButtonDemoPage.tsx @@ -165,8 +165,9 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( <section id="custom-validation"> <SubTitle content="Custom validation" /> <DescParagraph> - You can also override the FileInputButton validation operation by giving a - custom validation function that must fit the following signature:{" "} + You can also override the FileInputButton validation operation by + giving a custom validation function that must fit the following + signature:{" "} <CodeHighlight> {"validator?: (f: "} <AnchorToTab href="https://developer.mozilla.org/en-US/docs/Web/API/File"> @@ -183,9 +184,9 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( <TypeHighlight>maxFiles</TypeHighlight> props. </DescParagraph> <Paper variant="outlined" style={{ padding: "25px" }}> - <DemoDropzoneCustomValidation button/> + <DemoDropzoneCustomValidation button /> </Paper> - <CodeDemoDropzoneCustomValidation button/> + <CodeDemoDropzoneCustomValidation button /> </section> <section id="uploading"> @@ -199,10 +200,10 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( </DescParagraph> <Paper variant="outlined" style={{ padding: "25px" }}> - <DemoDropzoneUploading /> + <DemoDropzoneUploading button /> </Paper> - <CodeDemoDropzoneUploading /> + <CodeDemoDropzoneUploading button /> <Alert severity="info"> <AlertTitle> Server response </AlertTitle> For uploading files through files-ui, server must return the @@ -218,10 +219,10 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( <br /> <Alert severity="info"> <AlertTitle> "fakeUpload" </AlertTitle> - By giving this prop, the {"<Dropzone/>"} component will simulate the - upload operation by randomly set the upload status and message in - ech uploadable <TypeHighlight>ExtFile</TypeHighlight>. It also will - set a fake progress. + By giving this prop, the {"<FileInputButton/>"} component will + simulate the upload operation by randomly set the upload status and + message on each uploadable <TypeHighlight>ExtFile</TypeHighlight>. + It will also set a fake progress. </Alert> <br /> <Alert severity="info"> @@ -238,7 +239,7 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( <li> <TypeHighlight>cleanOnUpload</TypeHighlight> : By setting this prop, you can control whether the upload process should "clean" - the non valid files before uploading or not By default this + the non valid files before uploading or not. By default this value is true. </li> </ul> @@ -248,16 +249,16 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( </section> <section id="action-buttons"> - <SubTitle content="Dropzone with action buttons" /> + <SubTitle content="FileInputButton with action buttons" /> <DescParagraph> If you need to display buttons that trigger the default events in - the <CodeHighlight>{"<Dropzone/>"}</CodeHighlight> component, you - can do it by adding the <TypeHighlight>actionButtons</TypeHighlight>{" "} - prop. This will add buttons to the top or to the bottom of this - component. + the <CodeHighlight>{"<FileInputButton/>"}</CodeHighlight> component, + you can do it by adding the{" "} + <TypeHighlight>actionButtons</TypeHighlight> prop. This will add + buttons to the top or to the bottom of this component. <ul> <li> - Dropzone with the{" "} + FileInputButton with the{" "} <TypeHighlight>actionButtons.cleanButton</TypeHighlight> prop defined will display a button which triggers the clean process. <br /> @@ -265,7 +266,7 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( <strong>when the "upload" process is not active</strong>. </li> <li> - Dropzone with the{" "} + FileInputButton with the{" "} <TypeHighlight>actionButtons.deleteButton</TypeHighlight> prop defined will display a button which deletes all files. <br /> @@ -273,14 +274,14 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( <strong>when the "upload" process is not active</strong>. </li> <li> - Dropzone with the{" "} + FileInputButton with the{" "} <TypeHighlight>actionButtons.uploadButton</TypeHighlight> prop defined will display a button which starts the upload process. This button will <strong>not</strong> be visible{" "} <strong>during the "upload" process</strong>. </li> <li> - Dropzone with the{" "} + FileInputButton with the{" "} <TypeHighlight>actionButtons.abortButton</TypeHighlight> prop defined will display a button which stops the upload process. <br /> @@ -291,10 +292,10 @@ const FileInputButtonDemoPage: React.FC<FileInputButtonDemoPageProps> = ( </DescParagraph> <Paper variant="outlined" style={{ padding: "25px" }}> - <DemoDropzoneActionButtons /> + <DemoDropzoneActionButtons button /> </Paper> - <CodeDemoDropzoneActionButtons /> + <CodeDemoDropzoneActionButtons button /> </section> <section id="header-config">