2019-04-03 20:54:14 -07:00
|
|
|
import List from '../list/list.vue'
|
2019-04-03 18:43:24 -07:00
|
|
|
import Checkbox from '../checkbox/checkbox.js'
|
|
|
|
|
2019-04-03 19:38:48 -07:00
|
|
|
const SelectableList = {
|
2019-04-03 18:43:24 -07:00
|
|
|
components: {
|
2019-04-03 20:54:14 -07:00
|
|
|
List,
|
2019-04-03 18:43:24 -07:00
|
|
|
Checkbox
|
|
|
|
},
|
2019-04-03 21:00:21 -07:00
|
|
|
props: List.props,
|
2019-04-03 20:26:13 -07:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
selected: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2019-04-03 21:22:55 -07:00
|
|
|
toggle (checked, key) {
|
|
|
|
const oldChecked = this.isSelected(key)
|
2019-04-03 20:26:13 -07:00
|
|
|
if (checked !== oldChecked) {
|
|
|
|
if (checked) {
|
|
|
|
this.selected.push(key)
|
|
|
|
} else {
|
|
|
|
this.selected.splice(this.selected.indexOf(key), 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-04-03 21:22:55 -07:00
|
|
|
isSelected (key) {
|
|
|
|
return this.selected.indexOf(key) !== -1
|
2019-04-03 19:48:00 -07:00
|
|
|
}
|
2019-04-03 18:43:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 19:38:48 -07:00
|
|
|
export default SelectableList
|