add some styling to the selectable-list component

This commit is contained in:
taehoon 2019-04-03 23:35:43 -04:00
parent f6e9f28745
commit 3a318dc373
2 changed files with 22 additions and 4 deletions

View file

@ -21,7 +21,7 @@ const SelectableList = {
}, },
methods: { methods: {
toggle (checked, item) { toggle (checked, item) {
const oldChecked = this.isChecked(item) const oldChecked = this.isSelected(item)
if (checked !== oldChecked) { if (checked !== oldChecked) {
const key = this.getKey(item) const key = this.getKey(item)
if (checked) { if (checked) {
@ -31,7 +31,7 @@ const SelectableList = {
} }
} }
}, },
isChecked (item) { isSelected (item) {
return this.selected.indexOf(this.getKey(item)) !== -1 return this.selected.indexOf(this.getKey(item)) !== -1
} }
} }

View file

@ -1,7 +1,9 @@
<template> <template>
<div class="selectable-list"> <div class="selectable-list">
<div v-for="item in items" :key="getKey(item)"> <div v-for="item in items" :key="getKey(item)" class="selectable-list-item" :class="{ 'selectable-list-item-selected': isSelected(item) }">
<Checkbox :checked="isChecked(item)" @change="checked => toggle(checked, item)" /> <div class="selectable-list-checkbox-wrapper">
<Checkbox :checked="isSelected(item)" @change="checked => toggle(checked, item)" />
</div>
<slot name="item" :item="item" /> <slot name="item" :item="item" />
</div> </div>
<div class="selectable-list-empty-content faint" v-if="items.length === 0"> <div class="selectable-list-empty-content faint" v-if="items.length === 0">
@ -13,7 +15,23 @@
<script src="./selectable_list.js"></script> <script src="./selectable_list.js"></script>
<style lang="scss"> <style lang="scss">
@import '../../_variables.scss';
.selectable-list { .selectable-list {
&-item {
display: flex;
&-selected {
background-color: $fallback--lightBg;
background-color: var(--lightBg, $fallback--lightBg);
}
}
&-checkbox-wrapper {
padding: 10px;
flex: none;
}
&-empty-content { &-empty-content {
text-align: center; text-align: center;
padding: 10px; padding: 10px;