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

Commit ff93da9

Browse files
committed
feat(chips): Synchronise with mdc-web (#96)
1 parent d262bab commit ff93da9

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

components/chips/Chip.vue

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<template>
22
<div
33
class="mdc-chip"
4+
:class="classes"
45
tabindex="0"
5-
@MDCChip:interaction="onInteraction()">
6+
@MDCChip:interaction="$emit('change', !selected)"
7+
@MDCChip:removal="$emit('remove') && $emit('change', false)">
68
<slot
79
name="leadingIcon"
810
v-if="$slots['leadingIcon']"/>
@@ -34,7 +36,7 @@ import themeClassMixin from '../base/themeClassMixin.js'
3436
export default {
3537
mixins: [themeClassMixin],
3638
model: {
37-
props: 'selected',
39+
prop: 'selected',
3840
event: 'change'
3941
},
4042
props: {
@@ -45,23 +47,20 @@ export default {
4547
},
4648
data () {
4749
return {
48-
mdcChip: undefined,
4950
slotObserver: undefined
5051
}
5152
},
5253
computed: {
53-
model: {
54-
get () {
55-
return this.selected
56-
},
57-
set (value) {
58-
this.$emit('change', value)
54+
classes () {
55+
return {
56+
'mdc-chip--selected': this.selected,
57+
'mdc-chip__icon--leading-hidden': this.selected
5958
}
6059
}
6160
},
6261
mounted () {
6362
this.updateSlots()
64-
this.slotObserver = new MutationObserver( () => this.updateSlots())
63+
this.slotObserver = new MutationObserver(() => this.updateSlots())
6564
this.slotObserver.observe(this.$el, {
6665
childList: true,
6766
subtree: true
@@ -70,18 +69,14 @@ export default {
7069
beforeDestroy () {
7170
this.slotObserver.disconnect()
7271
},
73-
methods: {
74-
onInteraction () {
75-
this.model = this.mdcChip.isSelected()
76-
},
72+
methods: {
7773
updateSlots () {
7874
if (this.$slots.leadingIcon) {
7975
this.$slots.leadingIcon.map((n) => {
8076
n.elm.classList.add('mdc-chip__icon')
8177
n.elm.classList.add('mdc-chip__icon--leading')
8278
})
8379
}
84-
8580
if (this.$slots.trailingIcon) {
8681
this.$slots.trailingIcon.map((n) => {
8782
n.elm.classList.add('mdc-chip__icon')

components/chips/ChipSet.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div
3-
class="mdc-chip-set"
4-
:class="classes">
3+
:class="classes"
4+
class="mdc-chip-set">
55
<slot/>
66
</div>
77
</template>
@@ -21,6 +21,10 @@ export default {
2121
filter: {
2222
type: Boolean,
2323
default: false
24+
},
25+
input: {
26+
type: Boolean,
27+
default: false
2428
}
2529
},
2630
data () {
@@ -32,12 +36,16 @@ export default {
3236
classes () {
3337
return {
3438
'mdc-chip-set--choice': this.choice,
35-
'mdc-chip-set--filter': this.filter
39+
'mdc-chip-set--filter': this.filter,
40+
'mdc-chip-set--input': this.input
3641
}
3742
}
3843
},
3944
mounted () {
4045
this.mdcChipSet = MDCChipSet.attachTo(this.$el)
46+
},
47+
beforeDestroy () {
48+
this.mdcChipSet.destroy()
4149
}
4250
}
4351
</script>

components/chips/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
```html
66
<m-chip-set>
77
<m-chip>Chip content</m-chip>
8-
<m-chip>
8+
<m-chip v-model="selected">
99
<m-icon
1010
icon="event"
1111
slot="leadingIcon"/>
@@ -14,12 +14,23 @@
1414
</m-chip-set>
1515
```
1616

17-
### Props & methods
17+
### Script
18+
19+
```javascript
20+
data() {
21+
return {
22+
selected: false
23+
}
24+
}
25+
```
26+
27+
### Props
1828

1929
| Prop | Type | Default | Description |
2030
|------|------|---------|-------------|
2131
| choice | Boolean | false | single selection chips in set |
2232
| filter | Boolean | false | multiple selection chips in set |
33+
| input | Boolean | false | indicates that the chips in the set are input chips |
2334

2435
## Chip
2536

demo/views/ChipsView.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<m-layout-grid-inner>
33
<m-layout-grid-cell :span="12">
4-
<m-typo-title>Entry</m-typo-title>
5-
<m-chip-set>
4+
<m-typo-title>Input</m-typo-title>
5+
<m-chip-set input>
66
<m-chip>
77
<m-icon
88
icon="person"
@@ -27,26 +27,26 @@
2727
<m-typo-title>Choice</m-typo-title>
2828
<m-chip-set choice>
2929
<m-chip v-model="choiceSelected">Chip #1</m-chip>
30-
<m-chip>Chip #2</m-chip>
31-
<m-chip>Chip #3</m-chip>
30+
<m-chip v-model="choiceSelected">Chip #2</m-chip>
31+
<m-chip v-model="choiceSelected">Chip #3</m-chip>
3232
</m-chip-set>
3333
</m-layout-grid-cell>
3434
<m-layout-grid-cell :span="12">
3535
<m-typo-title>Filter</m-typo-title>
3636
<m-chip-set filter>
37-
<m-chip>
37+
<m-chip v-model="filterSelected">
3838
Chip #1
3939
<m-icon
4040
icon="cancel"
4141
slot="trailingIcon"/>
4242
</m-chip>
43-
<m-chip>
43+
<m-chip v-model="filterSelected">
4444
Chip #2
4545
<m-icon
4646
icon="cancel"
4747
slot="trailingIcon"/>
4848
</m-chip>
49-
<m-chip>
49+
<m-chip v-model="filterSelected">
5050
Chip #3
5151
<m-icon
5252
icon="cancel"
@@ -66,7 +66,8 @@ Vue.use(Chips)
6666
export default {
6767
data () {
6868
return {
69-
choiceSelected: false
69+
choiceSelected: false,
70+
filterSelected: false
7071
}
7172
}
7273
}

0 commit comments

Comments
 (0)