Sha256: 75d9693e32ea0cd02943a3f8813a61632c7ad2a40d887b44c90fe2d9b8a17db3

Contents?: true

Size: 1.27 KB

Versions: 174

Compression:

Stored size: 1.27 KB

Contents

/* @flow */

import React, { useCallback } from 'react'
import { useDropzone } from 'react-dropzone'
import { buildCss, noop } from '../utilities/props'
import classnames from 'classnames'
import { globalProps } from '../utilities/globalProps.js'

import type { Callback } from '../types.js'

import { Body, Card } from '..'

type FileUploadProps = {
  accept?: array<string>,
  className?: string,
  onFilesAccepted: Callback,
}

const FileUpload = (props: FileUploadProps) => {
  const {
    accept = ['image/png', 'image/jpg', 'image/jpeg', 'image/svg+xml'],
    className,
    onFilesAccepted = noop,
  } = props
  const onDrop = useCallback((files) => {
    onFilesAccepted(files)
  })

  const { getRootProps, getInputProps, isDragActive } = useDropzone({
    accept,
    onDrop,
  })

  return (
    <div
        className={classnames(buildCss('pb_file_upload_kit'), globalProps(props), className)}
        {...getRootProps()}
    >
      <Card>
        <input {...getInputProps()} />
        <Body color="light">
          <If condition={isDragActive}>
            <p>{'Drop the files here ...'}</p>
            <Else />
            <p>{'Drag & drop some files here, or click to select files'}</p>
          </If>
        </Body>
      </Card>
    </div>
  )
}

export default FileUpload

Version data entries

174 entries across 174 versions & 1 rubygems

Version Path
playbook_ui-7.4.0.pre.test2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0.pre.alpha4 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0.pre.alpha2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0.pre.alpha1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha12 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha11 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha10 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha9 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha8 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha7 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha6 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha5 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha4 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha3 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.3.0.pre.alpha1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.2.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.1.2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.1.0.pre.alpha2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx