New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-file-chooser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-file-chooser

a helper for choosing a file in react application.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-90%
Maintainers
1
Weekly downloads
 
Created
Source

react-file-chooser

a helper for choosing a file in react application.

Install

with npm:

npm install react-file-chooser

with yarn:

yarn add react-file-chooser

with pnpm:

pnpm add react-file-chooser

Usage

with drag and drop

export const FileChooser = () => {
  const { onChange, onDrag, destroy, isDragging, error, imageDataUrl } =
    useFileChooser()

  return (
    <div className="flex flex-col gap-4 items-center justify-center">
      {!!error && <p className="py-2 text-red-500">{error}</p>}
      <label
        onDragOver={(e) => e.preventDefault()}
        onDragLeave={(e) => onDrag(e, false)}
        onDragEnter={(e) => onDrag(e, true)}
        onDrop={(e) => onChange(e, true)}
        htmlFor="file"
        className={`${
          isDragging && 'bg-blue-50'
        } relative cursor-pointer w-96 h-56 border border-dashed border-blue-400 p-20 flex flex-col justify-center items-center gap-2 hover:bg-blue-50 duration-150 transition rounded-2xl`}
      >
        <input
          type="file"
          id="file"
          className="hidden"
          onChange={(e) => onChange(e, false)}
        />

        {!imageDataUrl && (
          <>
            <ArrowUpTrayIcon className="w-5 h-5" />
            <span className="text-blue-500 text-sm">
              Browse <span className="text-black/50">or</span> Drag & Drop
            </span>
          </>
        )}

        {!!imageDataUrl && (
          <>
            <img
              src={imageDataUrl}
              className="border border-black/5 w-32 h-32 rounded-full aspect-square object-cover object-center"
            />
          </>
        )}

        {!!imageDataUrl && (
          <span className="absolute top-2 right-2">
            <button onClick={(e) => destroy(e)}>
              <XMarkIcon className="w-5 h-5 fill-black" />
            </button>
          </span>
        )}
      </label>
    </div>
  )
}

without drag and drop

export const FileChooser = () => {
  const { onChange, onDrag, destroy, isDragging, error, imageDataUrl } =
    useFileChooser()

  return (
    <div className="flex flex-col gap-4 items-center justify-center">
      {!!error && <p className="py-2 text-red-500">{error}</p>}
      <label
        htmlFor="file"
        className={`${
          isDragging && 'bg-blue-50'
        } relative cursor-pointer w-96 h-56 border border-dashed border-blue-400 p-20 flex flex-col justify-center items-center gap-2 hover:bg-blue-50 duration-150 transition rounded-2xl`}
      >
        <input
          type="file"
          id="file"
          className="hidden"
          onChange={(e) => onChange(e, false)}
        />

        {!imageDataUrl && (
          <>
            <ArrowUpTrayIcon className="w-5 h-5" />
            <span className="text-blue-500 text-sm">
              Browse <span className="text-black/50">or</span> Drag & Drop
            </span>
          </>
        )}

        {!!imageDataUrl && (
          <>
            <img
              src={imageDataUrl}
              className="border border-black/5 w-32 h-32 rounded-full aspect-square object-cover object-center"
            />
          </>
        )}

        {!!imageDataUrl && (
          <span className="absolute top-2 right-2">
            <button onClick={(e) => destroy(e)}>
              <XMarkIcon className="w-5 h-5 fill-black" />
            </button>
          </span>
        )}
      </label>
    </div>
  )
}

Keywords

FAQs

Package last updated on 22 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc