aboutsummaryrefslogtreecommitdiff
path: root/src/components/selectable_list/selectable_list.js
diff options
context:
space:
mode:
authortaehoon <th.dev91@gmail.com>2019-04-04 04:32:36 -0400
committertaehoon <th.dev91@gmail.com>2019-04-17 11:32:49 -0400
commitcf2c411db34953e65c186e214bd9bae44073c881 (patch)
treec36a042ce991a03328ffc01a194132a141487c20 /src/components/selectable_list/selectable_list.js
parent83faa96f1b7405be2fb17b717c72c10ff8a65b59 (diff)
add header to selectable-list component
Diffstat (limited to 'src/components/selectable_list/selectable_list.js')
-rw-r--r--src/components/selectable_list/selectable_list.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/components/selectable_list/selectable_list.js b/src/components/selectable_list/selectable_list.js
index 93efa840..809133f5 100644
--- a/src/components/selectable_list/selectable_list.js
+++ b/src/components/selectable_list/selectable_list.js
@@ -6,14 +6,32 @@ const SelectableList = {
List,
Checkbox
},
- props: List.props,
+ props: {
+ items: {
+ type: Array,
+ default: () => []
+ },
+ getKey: {
+ type: Function,
+ default: item => item.id
+ }
+ },
data () {
return {
selected: []
}
},
+ computed: {
+ allSelected () {
+ return !this.items.find(item => !this.isSelected(item))
+ }
+ },
methods: {
- toggle (checked, key) {
+ isSelected (item) {
+ return this.selected.indexOf(this.getKey(item)) !== -1
+ },
+ toggle (checked, item) {
+ const key = this.getKey(item)
const oldChecked = this.isSelected(key)
if (checked !== oldChecked) {
if (checked) {
@@ -23,8 +41,12 @@ const SelectableList = {
}
}
},
- isSelected (key) {
- return this.selected.indexOf(key) !== -1
+ toggleAll (value) {
+ if (value) {
+ this.selected = this.items.map(this.getKey)
+ } else {
+ this.selected = []
+ }
}
}
}