forked from area17/twill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccordion.vue
executable file
·139 lines (121 loc) · 3.03 KB
/
Accordion.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
<div class="accordion" :class="visibilityClasses">
<button type="button" class="accordion__trigger" @click="onClickVisibility" :aria-expanded="visible ? 'true' : 'false'" >
<slot name="accordion__title"></slot>
<span class="accordion__value"><slot name="accordion__value"></slot></span>
<span v-svg symbol="dropdown_module"></span>
</button>
<transition :css="false" :duration="275" @before-enter="beforeEnter" @before-leave="beforeLeave" @enter="enter" @leave="leave">
<div class="accordion__dropdown" v-show="visible" :aria-hidden="!visible">
<div class="accordion__list">
<slot></slot>
</div>
</div>
</transition>
</div>
</template>
<script>
import VisibilityMixin from '@/mixins/toggleVisibility'
export default {
name: 'A17Accordion',
mixins: [VisibilityMixin],
watch: {
open: function () {
if (this.visible !== this.open) {
this.visible = this.open
}
}
},
methods: {
getMaxHeight: function () { // retrieve max height depending on the content height
return Math.min(250, this.$el.querySelector('.accordion__list').clientHeight + 1)
},
beforeEnter: function (el) {
el.style.maxHeight = '0px'
},
enter: function (el, done) {
el.style.maxHeight = this.getMaxHeight() + 'px'
},
beforeLeave: function (el, done) {
el.style.maxHeight = this.getMaxHeight() + 'px'
},
leave: function (el, done) {
el.style.maxHeight = '0px'
}
}
}
</script>
<style lang="scss" scoped>
.accordion {
border-bottom:1px solid $color__border--light;
background-color:$color__background;
transition: background-color .25s linear;
overflow:hidden;
}
.accordion__trigger {
@include accordion-trigger;
color:$color__text;
display:flex;
flex-flow: row nowrap;
align-items: center;
&:hover,
&:focus {
background:$color__ultralight;
}
.icon {
color:$color__text--light;
}
}
.accordion__value {
flex-grow:1;
text-align:right;
color:$color__text--light;
padding-left:10px;
overflow:hidden;
> * {
overflow:hidden;
text-overflow: ellipsis;
}
}
.accordion__dropdown {
overflow:hidden;
max-height:0;
height:auto;
transition: max-height 0.275s ease;
}
.accordion__list {
border-top:1px solid $color__border--light;
padding:12px 20px;
}
.accordion__fields {
border-top:1px solid $color__border--light;
padding:20px;
}
.accordion__list .accordion__fields {
border-top:0 none;
padding:8px 0;
}
/* Opened accordion */
.s--open {
background-color:$color__ultralight;
.accordion__dropdown {
max-height:250px;
overflow-y: auto;
}
.icon {
transform:rotate(180deg);
}
}
</style>
<style lang="scss">
.accordion {
.accordion__list {
.input {
margin-top: 0;
+ .input {
margin-top: 10px;
}
}
}
}
</style>