Addon for using @shopify/draggable in ember projects.
- Easy to use
- FastBoot Compatible
- Easily Extendable
https://gavant.github.io/ember-shopify-draggable/#/sortable
ember install @gavant/ember-shopify-draggable
ember-shopify-draggable contains ember components for all of the @shopify/draggable modules (Swappable
, Sortable
, Droppable
, and Draggable
).
This addon allows you to pass in a list object to the container component, and an item object to the item component. This will give you the ability to keep track of the underlying JS list automatically. You can see an example of this below.
Here we pass in list which is an array of js objects, and give item
to each container.item
. When any action is performed the group.container
component sends an action and you can just have it mutate the list. So each time the list is modified by drag/drop your passed in list will be updated with those changes!
Angle bracket component style (Ember v3.4+)
You can listen to the Sortable's base interaction events by adding actions to the {{#sortable-group}}
component. See the above examples for the correct action names and structure.
Possible events for Sortable can be found at Sortable Events
NOTE: Currently only works with one container
Angle bracket component style (Ember v3.4+)
You can listen to the Sortable's base interaction events by adding actions to the {{#swappable-group}}
component. See the above examples for the correct action names and structure.
Possible events for Swappable can be found at Swappable Events
Droppable can be used via a similar set of components, but with the addition of a dropzone
component, which has the restriction that only a single draggable item may occupy a dropzone at any given time.
Angle bracket component style (Ember v3.4+)
You can listen to the Droppable's base interaction events by adding actions to the {{#droppable-group}}
component. See the above examples for the correct action names and structure.
Possible events for Droppable can be found at Droppable Events
Draggables are the base module from which all the others extend from, so on its own it doesn't offer much functionality. However, it can still be useful if you need the lower-level primitive to build on top of.
Angle bracket component style (Ember v3.4+)
You can listen to the Draggable's base interaction events by adding actions to the {{#draggable-group}}
component. See the above examples for the correct action names and structure.
Possible events for Draggable can be found at Draggable Events
You can customize several of the underlying Sortable
, Swappable
, Droppable
, or Draggable
instances' options by passing in additional properties to the {{sortable-group}}
, {{swappable-group}}
, {{droppable-group}}
and {{draggable-group}}
components.
delay
- (default:100
) adds a delay to the drag interaction when a sortable item is clicked.handle
- (default:null
) a CSS selector for a handle element within the sortable item elements if you don't want to allow dragging from anywhere on the entire item element.mirrorOptions
- (default:{constrainDimensions: true}
) a hash of options that are used to customize the behavior and appearance of the "mirror" element that gets created when dragging
For more details on these options see:
https://github.com/Shopify/draggable/tree/v1.0.0-beta.8/src/Draggable#options
https://github.com/Shopify/draggable/tree/master/src/Draggable/Plugins/Mirror#options
NOTE: These options do not support dynamically changing values, and will only respect the initial value that is passed in when the component is first rendered.
The ember components for each of the modules also support enabling the plugins that are provided by @shopify/draggable.
https://github.com/Shopify/draggable/tree/v1.0.0-beta.8/src/Plugins/ResizeMirror
Enable by setting resizeMirror=true
on the top level *-group
components. This plugin is supported by all components.
https://github.com/Shopify/draggable/tree/v1.0.0-beta.8/src/Plugins/Snappable
Enable by setting snappable=true
on the top level *-group
components. This plugin is supported by all components.
The Snappable plugin also exposes some additional events that can be listed to via actions on the supported group components:
Possible events for Snappable can be found at Snappable Events
https://github.com/Shopify/draggable/tree/v1.0.0-beta.8/src/Plugins/SwapAnimation
Enable by setting swapAnimation=true
on the top level *-group
component. It is currently only supported by {{sortable-group}}
.
An additional option property, swapAnimationOptions
is provided on the supported group components. (see options documentation)
https://github.com/Shopify/draggable/tree/v1.0.0-beta.8/src/Plugins/Collidable
Enable by setting collidable=true
on the top level *-group
components. It is currently supported by {{sortable-group}}
, {{swappable-group}}
and {{droppable-group}}
.
An additional option property, collidables
is provided on the supported group components (see options documentation)
The Collidable plugin also exposes some additional events that can be listed to via actions on the supported group components:
Possible events for Collidable can be found at Collidable Events
git clone <repository-url>
cd ember-shopify-draggable
npm install
npm run lint:js
npm run lint:js -- --fix
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versions
ember serve
- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.