gctGenerator/site/.vuepress/components/CodeList.vue

123 lines
1.9 KiB
Vue
Raw Normal View History

2020-06-28 06:33:20 +09:00
<template>
<ul>
<li
v-for="code in availableCodes"
:class="code.selected ? 'checked' : ''"
@click="toggle(code)"
@mouseover="inspect(code)"
>
{{ code.title }}
</li>
</ul>
</template>
<script>
export default {
props: {
codes: { type: Array },
onSelectionChanged: { type: Function },
onInspect: { type: Function },
},
mounted() {
this.populate();
},
watch: {
2020-07-01 14:26:48 +09:00
codes: function () {
2020-06-28 06:33:20 +09:00
this.populate();
},
},
data() {
return {
availableCodes: [],
};
},
methods: {
toggle(code) {
code.selected = !code.selected;
2020-07-01 14:26:48 +09:00
this.onSelectionChanged(this.availableCodes.filter((c) => c.selected));
2020-06-28 06:33:20 +09:00
},
populate() {
2020-07-01 14:26:48 +09:00
this.availableCodes = this.codes.map((c) => ({ ...c, selected: false }));
2020-06-28 06:33:20 +09:00
},
inspect(code) {
this.onInspect(code);
},
},
};
</script>
<style scoped>
ul {
list-style-type: none;
padding-left: 0;
}
ul li {
cursor: pointer;
color: #262626;
transition: 0.1s;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
outline: none;
display: block;
min-width: 280px;
padding-right: 15px;
2020-06-29 00:35:18 +09:00
text-align: left;
2020-06-28 06:33:20 +09:00
}
ul li:nth-child(odd) {
2020-06-29 00:35:18 +09:00
background: #e7e7e7;
2020-06-28 06:33:20 +09:00
}
ul li:hover {
background: #3eaf7c;
color: #fff;
}
ul li.checked:hover {
background: #3eaf7c;
color: #fff;
}
ul li.checked {
background: #434343;
color: #fff;
}
li {
position: relative;
padding-left: 26px;
}
li::before {
2020-06-29 00:35:18 +09:00
content: '';
2020-06-28 06:33:20 +09:00
position: absolute;
border-color: #a6a6a6;
border-style: solid;
border-width: 2px;
border-radius: 50%;
left: 6px;
top: 6px;
height: 10px;
width: 10px;
}
li:hover::before {
border-color: #fff;
2020-06-29 00:35:18 +09:00
background-color: #1fa76e;
2020-06-28 06:33:20 +09:00
}
li.checked::before {
border-color: #fff;
background-color: #d85e55;
}
2020-06-29 00:35:18 +09:00
@media screen and (max-width: 400px) {
ul li {
min-width: 180px;
}
}
2020-06-28 06:33:20 +09:00
</style>