ampersand-file-drop-view
v1.2.4
Published
Drag-and-drop file view based on ampersand-view, and for use in ampersand-form-view
Maintainers
Readme
ampersand-file-drop-view
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
nameString. Required. Name to use. Used byampersand-form-viewlabelString. Label to use for the view. Can be falsy to hide label. Defaults to"Drag and drop a file".requiredBoolean. Whether or not this view needs to have files. Defaults tofalsevalueArray. If present, the starting value must be an array ofFileorBlobobjects.multipleBoolean. Whether to allow one or multiple files. Defaults tofalseacceptString/Array. Which mime types to allow. Comma separated if string. Defaults to"*/*"holderClassString. Class to use for the main container. Defaults to"file-holder".holderHoverClassString. Class to use for the main container when hovering with a selection over the main container. Defaults to"file-holder-hover".documentHoverClassString. Class to use for the main container when hovering with a selection over the document body element. Defaults to"document-hover".hasFilesClassString. Class to use for the field has files. Defaults to"has-files".itemViewOptionsObject. Options object to pass to individual item views (see below)mainIndexString. Which property of the file to use to index. Indexing by a property such asnamecan prevent duplicates being added. See ampersand-collection for more information.
Item View Constructor Options (itemViewOptions)
displayPreviewBoolean. Whether or not to display an image preview, if available. Defaults tofalse.fileSizeUnitString. Which file size unit to use. E.g.: "kb", "mb", "gb", etc. Defaults to"kb".
Methods
setValue(files)filesis an array ofFileorBlobobjects.- sets the
valueof the view tofiles
- sets the
addFiles(files)filesis an array ofFileorBlobobjects.- appends the
valueof the view withfiles
- appends the
clear()- empties the view's
valueof all files
- empties the view's
reset()- sets the view's
valueto thevaluepassed in through the view's constructor options
- sets the view's
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
addFilesmethod (previoushandleFiles)
License
MIT
