Sha256: c44b5ecaad2aaf731b4dcbb3d3b4071b8889bcce228da6606d018994cb6d32b0

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 KB

Contents

/* @flow */

import React, { useCallback } from 'react'
import { useDropzone } from 'react-dropzone'
import classnames from 'classnames'

import { buildCss, noop } from '../utilities/props'
import { globalProps } from '../utilities/globalProps'
import type { Callback } from '../types'

import Body from '../pb_body/_body'
import Card from '../pb_card/_card'

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

15 entries across 15 versions & 1 rubygems

Version Path
playbook_ui-10.4.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.3.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.2.1.alpha.sisensefix app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.2.1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.2.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.1.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.3.pre.alpha.walkthrough2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.3.pre.alpha.walkthrough app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.1.alpha.railscusticon app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.2.pre.alpha.pre.iconfix app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.1.alpha.rtflexfix app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.0.pre.alphafonts app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.1 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-10.0.0 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx
playbook_ui-9.19.0.pre.alpha.pre.fonts2 app/pb_kits/playbook/pb_file_upload/_file_upload.jsx