This repository was archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathCard.vue
127 lines (125 loc) · 3.02 KB
/
Card.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
<template>
<div
:class="classes"
class="mdc-card"
>
<div
v-if="primaryAction"
class="mdc-card__primary-action"
tabindex="0"
v-on="$listeners"
>
<slot />
</div>
<slot v-else />
<div
v-if="$slots['actionButtons'] || $slots['actionIcons'] || $slots['fullBleedButton'] || $slots['actions']"
:class="actionClasses"
class="mdc-card__actions"
>
<slot
v-if="fullBleedAction && $slots['fullBleedButton']"
name="fullBleedButton"
/>
<slot
name="actions"
/>
<div
v-if="!fullBleedAction && $slots['actionButtons']"
class="mdc-card__action-buttons"
>
<slot name="actionButtons" />
</div>
<div
v-if="!fullBleedAction && $slots['actionIcons']"
class="mdc-card__action-icons"
>
<slot name="actionIcons" />
</div>
</div>
</div>
</template>
<script>
import { baseComponentMixin, themeClassMixin } from '../base'
export default {
mixins: [baseComponentMixin, themeClassMixin],
props: {
outlined: {
type: Boolean,
default: false
},
fullBleedAction: {
type: Boolean,
default: false
},
primaryAction: {
type: Boolean,
default: false
}
},
data () {
return {
slotObserver: undefined
}
},
computed: {
classes () {
return {
'mdc-card--outlined': this.outlined
}
},
actionClasses () {
return {
'mdc-card__actions--full-bleed': this.fullBleedAction
}
}
},
mounted () {
this.updateSlots()
this.slotObserver = new MutationObserver(() => this.updateSlots())
this.slotObserver.observe(this.$el, {
childList: true,
subtree: true
})
},
beforeDestroy () {
this.slotObserver.disconnect()
},
methods: {
updateSlots () {
if (this.$slots.fullBleedButton) {
this.$slots.fullBleedButton.map((n) => {
if (n.elm && n.elm.classList) {
n.elm.classList.add('mdc-card__action')
n.elm.classList.add('mdc-card__action--button')
}
})
}
if (this.$slots.actionButtons) {
this.$slots.actionButtons.forEach((n) => {
if (n.elm && n.elm.classList) {
n.elm.classList.add('mdc-card__action')
n.elm.classList.add('mdc-card__action--button')
}
})
}
if (this.$slots.actionIcons) {
this.$slots.actionIcons.forEach((n) => {
if (n.elm && n.elm.classList) {
n.elm.classList.add('mdc-card__action')
n.elm.classList.add('mdc-card__action--icon')
}
})
}
if (this.$slots.actions) {
this.$slots.actions.forEach((n) => {
if (n.elm && n.elm.classList) {
n.elm.classList.add('mdc-card__action')
n.elm.classList.contains('mdc-icon-button') ? n.elm.classList.add('mdc-card__action--icon') : n.elm.classList.add('mdc-card__action--button')
}
})
}
}
}
}
</script>