forked from didi/mand-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.vue
117 lines (106 loc) · 2.4 KB
/
list.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
<template>
<md-check-group
ref="group"
class="md-check-list"
:class="{ 'is-align-center': alignCenter }"
:value="value"
@input="$_onInput"
>
<md-cell-item
v-for="(item, index) in options"
:key="index"
class="md-check-item"
:class="{
'is-checked': value.indexOf(item.value) !== -1,
}"
:title="hasSlot ? '' : (item.text || item.label)"
:brief="hasSlot ? '' : item.brief"
:disabled="item.disabled"
@click="$_check(item, index)"
>
<template v-if="hasSlot">
<slot :option="item" :index="index" :selected="value.indexOf(item.value) > -1"></slot>
</template>
<md-check
v-if="!alignCenter"
:name="item.value"
:disabled="item.disabled"
:size="iconSize"
:icon="icon"
:icon-inverse="iconInverse"
:icon-disabled="iconDisabled"
:icon-svg="iconSvg"
:slot="iconPosition === 'right' ? 'right' : 'left'"
/>
</md-cell-item>
</md-check-group>
</template>
<script>import Check from './index'
import CheckGroup from './group'
import CellItem from '../cell-item'
import checkMixin from './mixin'
export default {
name: 'md-check-list',
mixins: [checkMixin],
components: {
[Check.name]: Check,
[CheckGroup.name]: CheckGroup,
[CellItem.name]: CellItem,
},
props: {
options: {
type: Array,
default() {
/* istanbul ignore next */
return []
},
},
value: {
type: Array,
default() {
/* istanbul ignore next */
return []
},
},
alignCenter: {
type: Boolean,
default: false,
},
isSlotScope: {
type: Boolean,
default: undefined,
},
},
computed: {
hasSlot() {
return this.isSlotScope !== undefined ? this.isSlotScope : !!this.$scopedSlots.default
},
},
methods: {
// MARK: private methods
$_check(option) {
this.$refs.group.toggle(option.value)
},
// MARK: private events
$_onInput(value) {
this.$emit('input', value)
},
},
}
</script>
<style lang="stylus">
.md-check-item
.md-check
margin-top 0
margin-bottom 0
pointer-events none
.md-cell-item-body.multilines .md-cell-item-title
font-weight font-weight-medium
.md-check-list.is-align-center
.md-cell-item-content
text-align center
.md-cell-left,
.md-cell-right
display none
</style>