npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solid-dzone

v1.0.0

Published

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

Downloads

3

Readme

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

| Name | Type | Notes | |------------|----------|----------------------------------------------------------------------------------------------------------------------| | disabled | boolean | Disable the dropzone | | maxSize | number | Maximum file size in bytes | | minSize | number | Minimum file size in bytes | | multiple | boolean | Allow multiple files | | maxFiles | number | Maximum number of files | | accept | string[] | Array of allowed file types, see link for possible values | | noClick | boolean | Disable click to open file dialog | | noKeyboard | boolean | Disable keyboard to open file dialog | | noDrag | boolean | Disable drag'n'drop | | validator | function | Custom file validation, overrides default |

createDropzone return values

| Name | Type | Notes | |--------------------|----------|------------------------------------------------------------------------------------------------------------------------| | isFocused | function | Boolean signal that indicates whether the dropzone is focused or not | | isFileDialogActive | function | Boolean signal that indicates whether the file dialog is open or not | | isDragging | function | Boolean signal that indicates whether the a file is being dragged over the root or not | | getRootProps | function | Function that returns an object of props for the root element | | getInputProps | function | Function that returns an object of props for the input element | | openFileDialog | function | Function to programmatically open the file dialog | | setRefs | function | Set the root and input refs. Must be called inside a setTimeout to ensure elements are mounted | | files | function | Signal that returns an array of files | | errors | function | Object containing errors. Each key is a file name and the value is an object containing the error message and the file | | removeFile | function | Function to remove a specific file by name | | removeError | function | Function to remove a specific error by file name | | clearFiles | function | Function to clear all files |

File type definition

| Name | Type | |----------|----------| | source | string | | name | string | | size | number | | file | File |

Contributors

contributors

Licence

MIT