aboutsummaryrefslogtreecommitdiff
path: root/src/components/selectable_list/selectable_list.js
blob: 93efa8405733b42220058453b028037470a1db28 (plain)
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
import List from '../list/list.vue'
import Checkbox from '../checkbox/checkbox.js'

const SelectableList = {
  components: {
    List,
    Checkbox
  },
  props: List.props,
  data () {
    return {
      selected: []
    }
  },
  methods: {
    toggle (checked, key) {
      const oldChecked = this.isSelected(key)
      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
    }
  }
}

export default SelectableList