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.8.3 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.8.2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.8.1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.8.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.7.0.pre.alpha1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.7.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.6.2.pre.alpha1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.6.2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.6.1.pre.alpha1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.6.1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.6.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.5.1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.5.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0.pre.alpha6 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0.pre.alpha5 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0.pre.test4 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-7.4.0.pre.test3 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx