Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

solid-dzone

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solid-dzone

Simple, high-quality drag'n'drop primitive for Solid JS

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

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

solidjs card

pnpm NPM package bundle size package version npm downloads

Simple, high-quality drag'n'drop primitive for Solid JS

Quick start

Install it:

npm i solid-dzone
# or
yarn add solid-dzone
# or
pnpm add solid-dzone

Usage

import createDropzone from "solid-dzone"

const MyDropZone = () => {
  const { 
    getRootProps,
    getInputProps,
    setRefs,
  } = createDropzone<HTMLDivElement>() // You MUST specify the type of the root element for proper typing

  let inputRef!: HTMLInputElement
  let rootRef!: HTMLDivElement

  setTimeout(() => {
    // Refs must be set inside a timeout to ensure the elements have been mounted
    setRefs(rootRef, inputRef)
  })

  return (
    <div {...getRootProps()} ref={rootRef}>
      <input {...getInputProps()} ref={inputRef}/>
    </div>
  )
}

Dropzone Props Getters

The dropzone property getters are just two functions that return objects with properties you need to create the drag'n'drop zone. The root properties can be applied to whatever ellement you want, whereas the input properties must be applied to an <input>.

Note that whatever other props you want to add to the elements, you should always pass them through the functions, rather than applying them directly to avoid conflicts and unexpected behaviours.

<div
  {...getRootProps({
    role: "button",
    onDrop: e => console.log("FILE WAS DROPPED")
  })}
>

createDropzone options

NameTypeNotes
disabledbooleanDisable the dropzone
maxSizenumberMaximum file size in bytes
minSizenumberMinimum file size in bytes
multiplebooleanAllow multiple files
maxFilesnumberMaximum number of files
acceptstring[]Array of allowed file types, see link for possible values
noClickbooleanDisable click to open file dialog
noKeyboardbooleanDisable keyboard to open file dialog
noDragbooleanDisable drag'n'drop
validatorfunctionCustom file validation, overrides default

createDropzone return values

NameTypeNotes
isFocusedfunctionBoolean signal that indicates whether the dropzone is focused or not
isFileDialogActivefunctionBoolean signal that indicates whether the file dialog is open or not
isDraggingfunctionBoolean signal that indicates whether the a file is being dragged over the root or not
getRootPropsfunctionFunction that returns an object of props for the root element
getInputPropsfunctionFunction that returns an object of props for the input element
openFileDialogfunctionFunction to programmatically open the file dialog
setRefsfunctionSet the root and input refs. Must be called inside a setTimeout to ensure elements are mounted
filesfunctionSignal that returns an array of files
errorsfunctionObject containing errors. Each key is a file name and the value is an object containing the error message and the file
removeFilefunctionFunction to remove a specific file by name
removeErrorfunctionFunction to remove a specific error by file name
clearFilesfunctionFunction to clear all files

File type definition

NameType
sourcestring
namestring
sizenumber
fileFile

Contributors

contributors

Licence

MIT

Keywords

FAQs

Package last updated on 26 Feb 2023

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