Sha256: ddc4eda03e4ee1c46e11c0791563a91f411a57bc9143ccd5649332b29a2cdd3d

Contents?: true

Size: 1.58 KB

Versions: 38

Compression:

Stored size: 1.58 KB

Contents

/* eslint-disable react/no-multi-comp */

import React, { useState } from 'react'
import {
  Body,
  FileUpload,
  List,
  ListItem,
} from 'playbook-ui'

const AcceptedFilesList = ({ files }) => (
  <List>
    {files.map((file) => (
      <ListItem key={file.name}>{file.name}</ListItem>
    ))}
  </List>
)
const RejectedFilesList = ({ files }) => (
  <List>
    {files.map((file) => (
      <ListItem key={file.file.name}><Body color="error">{`${file.file.name} (file too large)`}</Body></ListItem>
    ))}
  </List>
)

const FileUploadMaxSize = (props) => {
  const [filesToUpload, setFilesToUpload] = useState([])
  const [filesRejected, setFilesRejected] = useState([])
  const [error, setError] = useState()

  const handleOnFilesAccepted = (files) => {
    if (files.length) setError()
    setFilesToUpload([...filesToUpload, ...files])
  }

  const handleOnFilesRejected = (error, files) => {
    setError(error)
    setFilesRejected([...filesRejected, ...files])
  }

  return (
    <div>
      <AcceptedFilesList
          files={filesToUpload}
          {...props}
      />
      <RejectedFilesList
          files={filesRejected}
          {...props}
      />
      <FileUpload
          acceptedFilesDescription="Choose a file or drag it here. 1 MB size limit."
          maxSize={1000000}
          onFilesAccepted={handleOnFilesAccepted}
          onFilesRejected={handleOnFilesRejected}
          {...props}
      />
      { error && (
        <Body
            color="error"
            marginY="md"
        >
          {error}
        </Body>
      )}
    </div>
  )
}

export default FileUploadMaxSize

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
playbook_ui-14.11.1 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.11.0.pre.rc.17 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.11.0.pre.rc.17 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.11.0 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.11.0.pre.rc.16 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.11.0.pre.rc.16 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.10.0.pre.alpha.play16825301 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.10.0.pre.alpha.play16825301 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.11.0.pre.rc.15 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.11.0.pre.rc.15 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.11.0.pre.rc.14 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.11.0.pre.rc.14 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.11.0.pre.rc.13 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.11.0.pre.rc.13 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.11.0.pre.rc.12 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.11.0.pre.rc.12 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui_docs-14.9.0.pre.alpha.PLAY1660reactdropzone5020 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx
playbook_ui-14.9.0.pre.alpha.PLAY1660reactdropzone5020 app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx