Skip to content

easily add a dropzone to enable file drag and drop to your ember app

License

Notifications You must be signed in to change notification settings

st-h/ember-file-drop-zone

Repository files navigation

ember-file-drop-zone

Greenkeeper badge Latest NPM release TravisCI Build Status Coverage Status Code Climate Ember Observer Score Dependencies Dev Dependencies

easily add a dropzone to enable file drag and drop to your ember app

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Since version 1.0.0 this addon makes use of glimmer components only.

Installation

ember install ember-file-drop-zone

Demo

check out the demo page

Usage

See the source code of the demo app for more complex examples

Component

<FileDropZone @onDrop={{this.addFiles}} @disabled={{this.dropZoneDisabled}} as |state|>
  {{#if state.hovering}}
    hovering over the dropzone
  {{else if state.dragging}}
    dragging is active
  {{else}}
    drop your files here...
  {{/if}}
</FileDropZone>

Filtering by file type

<FileDropZone
  @accept="image/*,.pdf"
  @onDrop={{this.addFiles}}
  @onDropRejected={{this.handleRejected}}
as |state|>
  drop images or PDFs here...
</FileDropZone>

Parameters

Paramter type default description
disabled boolean false when set to true, the dropzone is disabled and files can no longer be dropped
accept string undefined comma-separated list of accepted file types. Supports MIME types (application/pdf), extensions (.pdf), and wildcards (image/*). When set, only matching files are passed to onDrop; rejected files are passed to onDropRejected. When not set, all files are passed to onDrop.

Events

onDrop(files)

called when files have been dropped (or when only accepted files remain after filtering via @accept)

files an array of js file objects that were dropped

onDropRejected(files)

called when files have been dropped that do not match the @accept filter

files an array of js file objects that were rejected

onDragEnter()

called when files are being dragged over the dropzone

onDragLeave()

called when files are no longer dragged over the dropzone

Styling

This addon does not provide any predefined styles. However, it applies appropriate css class names so that look can be modified as needed.

class description
ember-file-drop-zone Used to style the default state of the dropzone
disabled Applied when the dropzone is disabled
dragging Applied when one or more files are current being dragged over the dropzone

Please see app.css for a styling example:

.ember-file-drop-zone {
  // initial styles
}

.ember-file-drop-zone.disabled {
  // styles when disabled
}

.ember-file-drop-zone.dragging:not(.disabled) {
  // styles when files are being dragged over the window, but not over the dropzone and dropzone is not disabled
}

.ember-file-drop-zone.hovering {
  // styles when files are being dragged over the dropzone (independent of the disabled state)
}

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

About

easily add a dropzone to enable file drag and drop to your ember app

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •