Skip to content

Commit eb6a1ac

Browse files
Add transition example
1 parent 7b1c897 commit eb6a1ac

File tree

5 files changed

+182
-29
lines changed

5 files changed

+182
-29
lines changed

example/App.vue

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png" />
3+
<img
4+
alt="Vue logo"
5+
src="./assets/logo.png"
6+
/>
47
<div class="container ">
5-
<ul class="nav nav-tabs" role="tablist">
8+
<ul
9+
class="nav nav-tabs"
10+
role="tablist"
11+
>
612
<li class="nav-item">
713
<a
814
class="nav-link active"
@@ -11,8 +17,7 @@
1117
role="tab"
1218
aria-controls="profile"
1319
aria-selected="true"
14-
>Simple</a
15-
>
20+
>Simple</a>
1621
</li>
1722

1823
<li class="nav-item">
@@ -23,8 +28,7 @@
2328
role="tab"
2429
aria-controls="profile"
2530
aria-selected="false"
26-
>Two Lists</a
27-
>
31+
>Two Lists</a>
2832
</li>
2933

3034
<li class="nav-item">
@@ -35,48 +39,59 @@
3539
role="tab"
3640
aria-controls="profile"
3741
aria-selected="false"
38-
>Clone</a
39-
>
42+
>Clone</a>
4043
</li>
4144

4245
<li class="nav-item">
4346
<a
4447
class="nav-link"
4548
data-toggle="tab"
46-
href="#footerslot"
49+
href="#handler"
4750
role="tab"
4851
aria-controls="profile"
4952
aria-selected="false"
50-
>Footer slot</a
51-
>
53+
>Handler</a>
5254
</li>
5355

5456
<li class="nav-item">
5557
<a
5658
class="nav-link"
5759
data-toggle="tab"
58-
href="#headerlot"
60+
href="#transition"
5961
role="tab"
6062
aria-controls="profile"
6163
aria-selected="false"
62-
>Header slot</a
63-
>
64+
>Transition</a>
6465
</li>
6566

6667
<li class="nav-item">
6768
<a
6869
class="nav-link"
6970
data-toggle="tab"
70-
href="#handler"
71+
href="#footerslot"
7172
role="tab"
7273
aria-controls="profile"
7374
aria-selected="false"
74-
>Handler</a
75-
>
75+
>Footer slot</a>
7676
</li>
77+
78+
<li class="nav-item">
79+
<a
80+
class="nav-link"
81+
data-toggle="tab"
82+
href="#headerslot"
83+
role="tab"
84+
aria-controls="profile"
85+
aria-selected="false"
86+
>Header slot</a>
87+
</li>
88+
7789
</ul>
7890

79-
<div class="tab-content" id="tab-content">
91+
<div
92+
class="tab-content"
93+
id="tab-content"
94+
>
8095
<div
8196
class="tab-pane show active"
8297
id="simple"
@@ -115,7 +130,7 @@
115130

116131
<div
117132
class="tab-pane show"
118-
id="headerlot"
133+
id="headerslot"
119134
role="tabpanel"
120135
aria-labelledby="profile-tab"
121136
>
@@ -130,6 +145,15 @@
130145
>
131146
<handler />
132147
</div>
148+
149+
<div
150+
class="tab-pane show"
151+
id="transition"
152+
role="tabpanel"
153+
aria-labelledby="profile-tab"
154+
>
155+
<transition-example />
156+
</div>
133157
</div>
134158
</div>
135159
</div>
@@ -142,6 +166,7 @@ import clone from "./components/clone";
142166
import footerslot from "./components/footerslot";
143167
import headerslot from "./components/headerslot";
144168
import handler from "./components/handler";
169+
import transitionExample from "./components/transition-example";
145170
146171
export default {
147172
name: "app",
@@ -151,7 +176,8 @@ export default {
151176
clone,
152177
footerslot,
153178
headerslot,
154-
handler
179+
handler,
180+
transitionExample
155181
}
156182
};
157183
</script>

example/components/footerslot.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
<draggable
88
:list="list"
99
class="list-group"
10+
:options="{ draggable: '.item' }"
1011
@start="dragging = true"
1112
@end="dragging = false"
1213
>
1314
<div
14-
class="list-group-item"
15+
class="list-group-item item"
1516
v-for="element in list"
1617
:key="element.name"
1718
>

example/components/handler.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,16 @@
2222
</draggable>
2323
</div>
2424

25-
<rawDisplayer
26-
class="col-3"
27-
:value="list"
28-
title="List"
29-
/>
25+
<rawDisplayer class="col-3" :value="list" title="List" />
3026
</div>
3127
</div>
3228
</template>
3329

3430
<script>
3531
import draggable from "@/vuedraggable";
3632
import rawDisplayer from "./raw-displayer.vue";
37-
let id = 1;
3833
export default {
39-
name: "header",
34+
name: "handler",
4035
components: {
4136
draggable,
4237
rawDisplayer

example/components/headerslot.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
<draggable
88
:list="list"
99
class="list-group"
10+
:options="{ draggable: '.item' }"
1011
@start="dragging = true"
1112
@end="dragging = false"
1213
>
1314
<div
14-
class="list-group-item"
15+
class="list-group-item item"
1516
v-for="element in list"
1617
:key="element.name"
1718
>
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<template>
2+
<div class="justify-content-center jumbotron">
3+
<div class="row">
4+
5+
<div class="col-2">
6+
<button
7+
class="btn btn-secondary button"
8+
@click="sort"
9+
>To original order</button>
10+
</div>
11+
12+
<div class="col-6">
13+
<h3>Transition</h3>
14+
<draggable
15+
class="list-group"
16+
element="ul"
17+
v-model="list"
18+
:options="dragOptions"
19+
@start="isDragging = true"
20+
@end="isDragging = false"
21+
>
22+
<transition-group
23+
type="transition"
24+
:name="'flip-list'"
25+
>
26+
<li
27+
class="list-group-item"
28+
v-for="element in list"
29+
:key="element.order"
30+
>
31+
<i
32+
:class="
33+
element.fixed ? 'fa fa-anchor' : 'glyphicon glyphicon-pushpin'
34+
"
35+
@click="element.fixed = !element.fixed"
36+
aria-hidden="true"
37+
></i>
38+
{{ element.name }}
39+
</li>
40+
</transition-group>
41+
</draggable>
42+
</div>
43+
44+
<rawDisplayer
45+
class="col-3"
46+
:value="list"
47+
title="List"
48+
/>
49+
50+
</div>
51+
</div>
52+
53+
</template>
54+
55+
<script>
56+
import draggable from "@/vuedraggable";
57+
import rawDisplayer from "./raw-displayer.vue";
58+
59+
const message = [
60+
"vue.draggable",
61+
"draggable",
62+
"component",
63+
"for",
64+
"vue.js 2.0",
65+
"based",
66+
"on",
67+
"Sortablejs"
68+
];
69+
70+
export default {
71+
name: "tranistion-example",
72+
components: {
73+
draggable,
74+
rawDisplayer
75+
},
76+
data() {
77+
return {
78+
list: message.map((name, index) => {
79+
return { name, order: index + 1, fixed: false };
80+
})
81+
};
82+
},
83+
methods:{
84+
sort(){
85+
this.list = this.list.sort((a,b) => a.order - b.order);
86+
}
87+
},
88+
computed: {
89+
dragOptions() {
90+
return {
91+
animation: 0,
92+
group: "description",
93+
disabled: false,
94+
ghostClass: "ghost"
95+
};
96+
}
97+
}
98+
};
99+
</script>
100+
101+
<style>
102+
.button {
103+
margin-top: 50px;
104+
}
105+
106+
.flip-list-move {
107+
transition: transform 0.5s;
108+
}
109+
110+
.no-move {
111+
transition: transform 0s;
112+
}
113+
114+
.ghost {
115+
opacity: 0.5;
116+
background: #c8ebfb;
117+
}
118+
119+
.list-group {
120+
min-height: 20px;
121+
}
122+
123+
.list-group-item {
124+
cursor: move;
125+
}
126+
127+
.list-group-item i {
128+
cursor: pointer;
129+
}
130+
</style>

0 commit comments

Comments
 (0)