Skip to content

Commit d3dce50

Browse files
committed
Add SortAnimation plugin and example
1 parent 3226fe5 commit d3dce50

File tree

13 files changed

+360
-1
lines changed

13 files changed

+360
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ You can find the documentation for each module within their respective directori
126126
- [ResizeMirror](src/Plugins/ResizeMirror)
127127
- [Snappable](src/Plugins/Snappable)
128128
- [SwapAnimation](src/Plugins/SwapAnimation)
129+
- [SortAnimation](src/Plugins/SortAnimation)
129130
- [Sortable](src/Sortable)
130131
- [SortableEvent](src/Sortable/SortableEvent)
131132
- [Swappable](src/Swappable)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% import 'components/Block/Block.html' as Block %}
2+
3+
{% macro render(id) %}
4+
<section id="{{ id }}" class="{{ id }}">
5+
<article class="BlockLayout BlockLayout--typeFlex">
6+
{{ Block.render('one', {index: 1, draggable: true}) }}
7+
{{ Block.render('two', {index: 2, draggable: true}) }}
8+
{{ Block.render('three', {index: 3, draggable: true}) }}
9+
{{ Block.render('four', {index: 4, draggable: true}) }}
10+
{{ Block.render('five', {index: 5, draggable: true}) }}
11+
{{ Block.render('six', {index: 6, draggable: true}) }}
12+
{{ Block.render('seven', {index: 7, draggable: true}) }}
13+
{{ Block.render('eight', {index: 8, draggable: true}) }}
14+
{{ Block.render('nine', {index: 9, draggable: true}) }}
15+
</article>
16+
</section>
17+
{% endmacro %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
////
2+
/// Content
3+
/// SortAnimation
4+
////
5+
6+
@import 'utils/shared/functions';
7+
@import 'utils/shared/layout';
8+
9+
$sort-anim-block-name: unquote('Block');
10+
11+
.SortAnimation {
12+
@include draggable-source-layout($sort-anim-block-name, 1, 2, 4, 5, 7, 8) {
13+
flex-basis: 50%;
14+
}
15+
16+
@include draggable-source-layout($sort-anim-block-name, 3, 6, 9) {
17+
flex-basis: 100%;
18+
}
19+
20+
@media screen and (min-width: get-breakpoint(tablet)) {
21+
@include draggable-source-layout($sort-anim-block-name, 1, 2, 3, 4, 5, 6, 7, 8, 9) {
22+
flex-basis: 33.333%;
23+
}
24+
}
25+
26+
.BlockContent {
27+
@media screen and (min-width: get-breakpoint(tablet)) {
28+
height: rows(3);
29+
}
30+
31+
@media screen and (min-width: get-breakpoint(desktop)) {
32+
height: rows(4);
33+
}
34+
35+
@media screen and (min-width: get-breakpoint('1080p', wide)) {
36+
height: rows(5);
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// eslint-disable-next-line import/no-unresolved
2+
import {Sortable, Plugins} from '@shopify/draggable';
3+
4+
export default function SortAnimation() {
5+
const containers = document.querySelectorAll('#SortAnimation .BlockLayout');
6+
7+
if (containers.length === 0) {
8+
return false;
9+
}
10+
11+
const sortable = new Sortable(containers, {
12+
draggable: '.Block--isDraggable',
13+
mirror: {
14+
constrainDimensions: true,
15+
},
16+
plugins: [Plugins.SortAnimation],
17+
swapAnimation: {
18+
duration: 200,
19+
easingFunction: 'ease-in-out',
20+
},
21+
});
22+
23+
return sortable;
24+
}

examples/src/content/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import GridLayout from './Swappable/GridLayout';
1616
import PluginsCollidable from './Plugins/Collidable';
1717
import PluginsSnappable from './Plugins/Snappable';
1818
import PluginsSwapAnimation from './Plugins/SwapAnimation';
19+
import PluginsSortAnimation from './Plugins/SortAnimation';
1920

2021
const Content = {
2122
Home,
@@ -30,6 +31,7 @@ const Content = {
3031
PluginsCollidable,
3132
PluginsSnappable,
3233
PluginsSwapAnimation,
34+
PluginsSortAnimation,
3335
};
3436

3537
export default Content;

examples/src/styles/examples-app.scss

+1
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@
5858
@import 'content/Plugins/Collidable/Collidable';
5959
@import 'content/Plugins/Snappable/Snappable';
6060
@import 'content/Plugins/SwapAnimation/SwapAnimation';
61+
@import 'content/Plugins/SortAnimation/SortAnimation';

examples/src/views/data-pages.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"Plugins": [
3232
"Collidable",
3333
"Snappable",
34-
"~Swap Animation"
34+
"~Swap Animation",
35+
"Sort Animation"
3536
]
3637
}
3738
]
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{% extends 'templates/document.html' %}
2+
3+
{% import 'components/Document/Head.html' as Head %}
4+
{% import 'components/Sidebar/Sidebar.html' as Sidebar %}
5+
{% import 'components/PageHeader/PageHeader.html' as PageHeader %}
6+
7+
{% import 'content/Plugins/SortAnimation/SortAnimation.html' as SortAnimation %}
8+
9+
{% set ViewAttr = {
10+
id: 'SortAnimation',
11+
parent: 'Plugins',
12+
child: 'Sort Animation',
13+
subheading: 'Adds sort animation on all sorted elements with both horizontal and vertical within grid layout'
14+
} %}
15+
16+
{% block PageId %}{{ ViewAttr.id }}{% endblock %}
17+
18+
{% block head %}
19+
{{ Head.render(ViewAttr) }}
20+
{% endblock %}
21+
22+
{% block sidebar %}
23+
{{ Sidebar.render(ViewAttr, DataPages) }}
24+
{% endblock %}
25+
26+
{% block main %}
27+
{{ PageHeader.render(ViewAttr) }}
28+
{{ SortAnimation.render(ViewAttr.id) }}
29+
{% endblock %}

scripts/build/bundles.js

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ const bundles = [
6868
source: 'Plugins/SwapAnimation/index',
6969
path: 'plugins/',
7070
},
71+
72+
{
73+
name: 'SortAnimation',
74+
filename: 'sort-animation',
75+
source: 'Plugins/SortAnimation/index',
76+
path: 'plugins/',
77+
},
7178
];
7279

7380
module.exports = {bundles};

src/Plugins/SortAnimation/README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## SortAnimation
2+
3+
The sort animation plugin currently only works with `Sortable`. It adds sort animation on `sortable:sorted` with both horizontal and vertical within grid layout,
4+
and animates all sorted elements via `translate3d`. It is currently possible to change the duration and
5+
the easing function of the animation.
6+
7+
It different with (SwapAnimation)[https://github.com/Shopify/draggable/tree/master/src/Plugins/SwapAnimation] plugin because SwapAnimation only support horizontal or vertical layout.
8+
9+
This plugin is not included by default, so make sure to import it before using.
10+
11+
**NOTE**: Don't use this plugin with (SwapAnimation)[https://github.com/Shopify/draggable/tree/master/src/Plugins/SwapAnimation] plugin to avoid conflict.
12+
13+
### Import
14+
15+
```js
16+
import { Plugins } from '@shopify/draggable';
17+
```
18+
19+
```js
20+
import SortAnimation from '@shopify/draggable/lib/plugins/sort-animation';
21+
```
22+
23+
```html
24+
<script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/plugins.js"></script>
25+
```
26+
27+
```html
28+
<script src="https://cdn.jsdelivr.net/npm/@shopify/[email protected]/lib/plugins/sort-animation.js"></script>
29+
```
30+
31+
### API
32+
33+
**`new SortAnimation(draggable: Draggable): SortAnimation`**
34+
To create a sort animation plugin instance.
35+
36+
### Options
37+
38+
**`duration {Integer}`**
39+
The duration option allows you to specify the animation during for a single sort. Default: `150`
40+
41+
**`easingFunction {String}`**
42+
The easing option allows you to specify an animation easing function. Default: `'ease-in-out'`
43+
44+
### Examples
45+
46+
```js
47+
import { Sortable, Plugins } from '@shopify/draggable';
48+
49+
const sortable = new Sortable(document.querySelectorAll('ul'), {
50+
draggable: 'li',
51+
sortAnimation: {
52+
duration: 200,
53+
easingFunction: 'ease-in-out',
54+
},
55+
plugins: [Plugins.SortAnimation]
56+
});
57+
```
58+
59+
### Caveats
60+
61+
- Only works within same container
62+
- Animations don't stagger
63+
- Only works with `Sortable`

0 commit comments

Comments
 (0)