Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 3055acd

Browse files
authored
feat(drawer): update to mdc-web v3.1.0 (#381)
* feat(drawer): update to mdc-web v3.1.0 fixes #377 complete the docs simplify the drawer header * test(drawer): add snapshots
1 parent 92178bf commit 3055acd

File tree

6 files changed

+567
-20
lines changed

6 files changed

+567
-20
lines changed

components/drawer/Drawer.vue

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@
33
:class="classes"
44
class="mdc-drawer"
55
@MDCDrawer:closed="onClosed"
6+
@MDCDrawer:opened="onOpened"
67
>
7-
<slot name="header" />
8+
<div
9+
v-if="!hasHeaderClass || title !== '' || subtitle !== ''"
10+
class="mdc-drawer__header"
11+
>
12+
<h3
13+
v-if="title !== ''"
14+
class="mdc-drawer__title"
15+
>
16+
{{ title }}
17+
</h3>
18+
<h6
19+
v-if="subtitle !== ''"
20+
class="mdc-drawer__subtitle"
21+
>
22+
{{ subtitle }}
23+
</h6>
24+
<slot name="header" />
25+
</div>
26+
<slot
27+
v-else
28+
name="header"
29+
/>
830
<slot />
931
</aside>
1032
</template>
@@ -31,11 +53,20 @@ export default {
3153
open: {
3254
type: Boolean,
3355
default: false
56+
},
57+
title: {
58+
type: String,
59+
default: ''
60+
},
61+
subtitle: {
62+
type: String,
63+
default: ''
3464
}
3565
},
3666
data () {
3767
return {
38-
mdcDrawer: undefined
68+
mdcDrawer: undefined,
69+
hasHeaderClass: false
3970
}
4071
},
4172
computed: {
@@ -56,17 +87,39 @@ export default {
5687
},
5788
watch: {
5889
modal () {
59-
if (!this.mdcDrawer) this.mdcDrawer = new MDCDrawer(this.$el)
90+
if (!this.modal) {
91+
this.mdcDrawer.destroy()
92+
this.mdcDrawer = undefined
93+
} else {
94+
this.$nextTick(function () {
95+
this.mdcDrawer = new MDCDrawer(this.$el)
96+
})
97+
}
6098
},
6199
dismissible () {
62-
if (!this.mdcDrawer) this.mdcDrawer = new MDCDrawer(this.$el)
100+
if (!this.dismissible) {
101+
this.mdcDrawer.destroy()
102+
this.mdcDrawer = undefined
103+
} else {
104+
this.$nextTick(function () {
105+
this.mdcDrawer = new MDCDrawer(this.$el)
106+
})
107+
}
63108
},
64109
open () {
65-
this.mdcDrawer.open = this.open
110+
if (this.mdcDrawer.open !== this.open) this.mdcDrawer.open = this.open
111+
},
112+
'mdcDrawer.open': function () {
113+
this.model = this.mdcDrawer.open
66114
}
67115
},
68116
mounted () {
69-
if (!this.mdcDrawer && (this.dismissible || this.modal)) { this.mdcDrawer = new MDCDrawer(this.$el) }
117+
// the slots can only be accessible in nextTick
118+
this.$nextTick(function () {
119+
// judge whether the slots have the header class
120+
this.hasHeaderClass = this.$slots.header[0].elm.classList.contains('mdc-drawer__header')
121+
if (!this.mdcDrawer && (this.dismissible || this.modal)) { this.mdcDrawer = new MDCDrawer(this.$el) }
122+
})
70123
},
71124
provide: {
72125
mdcDrawer: this
@@ -76,8 +129,11 @@ export default {
76129
},
77130
methods: {
78131
onClosed () {
79-
this.model = false
132+
if (this.model) this.model = false
80133
this.$emit('closed')
134+
},
135+
onOpened () {
136+
this.$emit('opened')
81137
}
82138
}
83139
}

components/drawer/DrawerContent.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div
33
v-if="$slots['default']"
44
class="mdc-drawer__content"
5+
v-on="$listeners"
56
>
67
<slot />
78
</div>

components/drawer/DrawerHeader.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div
3-
v-if="$slots['default'] || title || subTitle"
3+
v-if="$slots['default'] || title || subtitle"
44
class="mdc-drawer__header"
55
>
66
<h3
@@ -10,10 +10,10 @@
1010
{{ title }}
1111
</h3>
1212
<h6
13-
v-if="subTitle"
13+
v-if="subtitle"
1414
class="mdc-drawer__subtitle"
1515
>
16-
{{ subTitle }}
16+
{{ subtitle }}
1717
</h6>
1818
<slot />
1919
</div>
@@ -29,7 +29,7 @@ export default {
2929
type: String,
3030
default: ''
3131
},
32-
subTitle: {
32+
subtitle: {
3333
type: String,
3434
default: ''
3535
}

0 commit comments

Comments
 (0)