From 3055acd40ed38982717036887ede7aac92387bbf Mon Sep 17 00:00:00 2001 From: Jiajun Chen Date: Mon, 12 Aug 2019 09:26:53 +0800 Subject: [PATCH] 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 --- components/drawer/Drawer.vue | 70 ++++- components/drawer/DrawerContent.vue | 1 + components/drawer/DrawerHeader.vue | 8 +- components/drawer/README.md | 268 +++++++++++++++++- components/drawer/__test__/Drawer.spec.js | 160 +++++++++++ .../__snapshots__/Drawer.spec.js.snap | 80 ++++++ 6 files changed, 567 insertions(+), 20 deletions(-) create mode 100644 components/drawer/__test__/Drawer.spec.js create mode 100644 components/drawer/__test__/__snapshots__/Drawer.spec.js.snap diff --git a/components/drawer/Drawer.vue b/components/drawer/Drawer.vue index d17cb699b..2ec8b0993 100644 --- a/components/drawer/Drawer.vue +++ b/components/drawer/Drawer.vue @@ -3,8 +3,30 @@ :class="classes" class="mdc-drawer" @MDCDrawer:closed="onClosed" + @MDCDrawer:opened="onOpened" > - +
+

+ {{ title }} +

+
+ {{ subtitle }} +
+ +
+ @@ -31,11 +53,20 @@ export default { open: { type: Boolean, default: false + }, + title: { + type: String, + default: '' + }, + subtitle: { + type: String, + default: '' } }, data () { return { - mdcDrawer: undefined + mdcDrawer: undefined, + hasHeaderClass: false } }, computed: { @@ -56,17 +87,39 @@ export default { }, watch: { modal () { - if (!this.mdcDrawer) this.mdcDrawer = new MDCDrawer(this.$el) + if (!this.modal) { + this.mdcDrawer.destroy() + this.mdcDrawer = undefined + } else { + this.$nextTick(function () { + this.mdcDrawer = new MDCDrawer(this.$el) + }) + } }, dismissible () { - if (!this.mdcDrawer) this.mdcDrawer = new MDCDrawer(this.$el) + if (!this.dismissible) { + this.mdcDrawer.destroy() + this.mdcDrawer = undefined + } else { + this.$nextTick(function () { + this.mdcDrawer = new MDCDrawer(this.$el) + }) + } }, open () { - this.mdcDrawer.open = this.open + if (this.mdcDrawer.open !== this.open) this.mdcDrawer.open = this.open + }, + 'mdcDrawer.open': function () { + this.model = this.mdcDrawer.open } }, mounted () { - if (!this.mdcDrawer && (this.dismissible || this.modal)) { this.mdcDrawer = new MDCDrawer(this.$el) } + // the slots can only be accessible in nextTick + this.$nextTick(function () { + // judge whether the slots have the header class + this.hasHeaderClass = this.$slots.header[0].elm.classList.contains('mdc-drawer__header') + if (!this.mdcDrawer && (this.dismissible || this.modal)) { this.mdcDrawer = new MDCDrawer(this.$el) } + }) }, provide: { mdcDrawer: this @@ -76,8 +129,11 @@ export default { }, methods: { onClosed () { - this.model = false + if (this.model) this.model = false this.$emit('closed') + }, + onOpened () { + this.$emit('opened') } } } diff --git a/components/drawer/DrawerContent.vue b/components/drawer/DrawerContent.vue index f6cfd5f5c..bc2eefde7 100644 --- a/components/drawer/DrawerContent.vue +++ b/components/drawer/DrawerContent.vue @@ -2,6 +2,7 @@
diff --git a/components/drawer/DrawerHeader.vue b/components/drawer/DrawerHeader.vue index c51e485c8..feca6dcf9 100644 --- a/components/drawer/DrawerHeader.vue +++ b/components/drawer/DrawerHeader.vue @@ -1,6 +1,6 @@