pleroma-fe/src/components/selectable_list/selectable_list.js

33 lines
626 B
JavaScript
Raw Normal View History

import List from '../list/list.vue'
2019-04-04 12:43:24 +11:00
import Checkbox from '../checkbox/checkbox.js'
const SelectableList = {
2019-04-04 12:43:24 +11:00
components: {
List,
2019-04-04 12:43:24 +11:00
Checkbox
},
2019-04-04 15:00:21 +11:00
props: List.props,
2019-04-04 14:26:13 +11:00
data () {
return {
selected: []
}
},
methods: {
toggle (checked, key) {
const oldChecked = this.isSelected(key)
2019-04-04 14:26:13 +11:00
if (checked !== oldChecked) {
if (checked) {
this.selected.push(key)
} else {
this.selected.splice(this.selected.indexOf(key), 1)
}
}
},
isSelected (key) {
return this.selected.indexOf(key) !== -1
}
2019-04-04 12:43:24 +11:00
}
}
export default SelectableList