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

ampersand-file-drop-view

v1.2.4

Published

Drag-and-drop file view based on ampersand-view, and for use in ampersand-form-view

Downloads

28

Readme

ampersand-file-drop-view

Build Status Monthly npm downloads

Drag-and-drop file view based on ampersand-view, and for use in ampersand-form-view.

Example

Use with ampersand-form-view:

var FormView = require('ampersand-form-view');
var FileDropView = require('ampersand-file-drop-view');

new FormView({
	
	fields: function() {
		return [
			new FileDropView({
				holderClass: "file-drop-holder",
				name: "files",
				multiple: true,
				accept: "image/*,video/*",
				parent: this
			})
		];
	}
	
});

For a live demo, git clone this repo, run npm install to install the dependencies, and npm run demo to start a small local server that hosts the demo html page.

Constructor Options

  • name String. Required. Name to use. Used by ampersand-form-view
  • label String. Label to use for the view. Can be falsy to hide label. Defaults to "Drag and drop a file".
  • required Boolean. Whether or not this view needs to have files. Defaults to false
  • value Array. If present, the starting value must be an array of File or Blob objects.
  • multiple Boolean. Whether to allow one or multiple files. Defaults to false
  • accept String/Array. Which mime types to allow. Comma separated if string. Defaults to "*/*"
  • holderClass String. Class to use for the main container. Defaults to "file-holder".
  • holderHoverClass String. Class to use for the main container when hovering with a selection over the main container. Defaults to "file-holder-hover".
  • documentHoverClass String. Class to use for the main container when hovering with a selection over the document body element. Defaults to "document-hover".
  • hasFilesClass String. Class to use for the field has files. Defaults to "has-files".
  • itemViewOptions Object. Options object to pass to individual item views (see below)
  • mainIndex String. Which property of the file to use to index. Indexing by a property such as name can prevent duplicates being added. See ampersand-collection for more information.

Item View Constructor Options (itemViewOptions)

  • displayPreview Boolean. Whether or not to display an image preview, if available. Defaults to false.
  • fileSizeUnit String. Which file size unit to use. E.g.: "kb", "mb", "gb", etc. Defaults to "kb".

Methods

  • setValue(files) files is an array of File or Blob objects.
    • sets the value of the view to files
  • addFiles(files) files is an array of File or Blob objects.
    • appends the value of the view with files
  • clear()
    • empties the view's value of all files
  • reset()
    • sets the view's value to the value passed in through the view's constructor options

Tests

Run tests with npm test

Changelog

v1.0.0

  • ampersand-view-conventions compliance
    • supports setting a value (an array of File or Blob-like objects) programatically, including as an initial value
  • more reliable triggering of classes when hovering over the body or the file-holder element
  • addition of hasFilesClass
  • addition of addFiles method (previous handleFiles)

License

MIT