support indeterminate checkbox state

This commit is contained in:
taehoon 2019-04-06 13:45:28 -04:00
parent 3f5e798de7
commit ecff6acf2d
3 changed files with 15 additions and 3 deletions

View file

@ -1,6 +1,6 @@
<template> <template>
<label class="checkbox"> <label class="checkbox">
<input type="checkbox" :checked="checked" @change="$emit('change', $event.target.checked)"> <input type="checkbox" :checked="checked" @change="$emit('change', $event.target.checked)" :indeterminate.prop="indeterminate">
<i class="checkbox-indicator" /> <i class="checkbox-indicator" />
<span v-if="!!$slots.default"><slot></slot></span> <span v-if="!!$slots.default"><slot></slot></span>
</label> </label>
@ -12,7 +12,7 @@ export default {
prop: 'checked', prop: 'checked',
event: 'change' event: 'change'
}, },
props: ['checked'] props: ['checked', 'indeterminate']
} }
</script> </script>
@ -57,6 +57,12 @@ export default {
color: var(--text, $fallback--text); color: var(--text, $fallback--text);
} }
&:indeterminate + .checkbox-indicator::before {
content: '';
color: $fallback--text;
color: var(--text, $fallback--text);
}
&:disabled + .checkbox-indicator::before { &:disabled + .checkbox-indicator::before {
opacity: .5; opacity: .5;
} }

View file

@ -24,6 +24,12 @@ const SelectableList = {
computed: { computed: {
allSelected () { allSelected () {
return !this.items.find(item => !this.isSelected(item)) return !this.items.find(item => !this.isSelected(item))
},
noneSelected () {
return !this.items.find(item => this.isSelected(item))
},
someSelected () {
return !this.allSelected && !this.noneSelected
} }
}, },
methods: { methods: {

View file

@ -2,7 +2,7 @@
<div class="selectable-list"> <div class="selectable-list">
<div class="selectable-list-header" v-if="items.length > 0"> <div class="selectable-list-header" v-if="items.length > 0">
<div class="selectable-list-checkbox-wrapper"> <div class="selectable-list-checkbox-wrapper">
<Checkbox :checked="allSelected" @change="toggleAll">{{ $t('selectable_list.select_all') }}</Checkbox> <Checkbox :checked="allSelected" @change="toggleAll" :indeterminate="someSelected">{{ $t('selectable_list.select_all') }}</Checkbox>
</div> </div>
<div class="selectable-list-header-actions"> <div class="selectable-list-header-actions">
<slot name="header" :selected="selected" /> <slot name="header" :selected="selected" />