gamebrary/src/components/Board/PlatformPicker.vue

91 lines
2 KiB
Vue
Raw Normal View History

2020-11-21 06:23:40 +00:00
<!-- TODO: return filteredPlatforms getter and return sort/filters -->
2020-08-22 18:59:58 +00:00
<template lang="html">
<div class="platform-picker">
2020-11-21 06:23:40 +00:00
<b-button
v-b-modal.platforms
:variant="value.length ? 'success' : 'warning'"
2020-10-14 23:57:10 +00:00
>
2020-11-21 06:23:40 +00:00
{{ buttonLabel }}
</b-button>
<b-modal
id="platforms"
scrollable
hide-footer
>
2020-11-21 06:23:40 +00:00
<template v-slot:modal-header="{ close }">
<modal-header
title="Board Platforms"
subtitle="Game search will be limited to the platforms selected."
@close="close"
2020-10-14 23:20:25 +00:00
/>
2020-11-21 06:23:40 +00:00
</template>
2020-10-14 23:20:25 +00:00
2020-11-21 06:23:40 +00:00
<b-list-group>
<b-list-group-item
v-for="platform in platforms"
:key="platform.id"
button
:active="value.includes(platform.id)"
@click="handleClick(platform.id)"
>
<b-img
:src="`/static/platform-logos/${platform.slug}.${platform.logoFormat}`"
:alt="platform.name"
width="40"
class="pr-2"
/>
2020-10-14 23:20:25 +00:00
2020-11-21 06:23:40 +00:00
{{ platform.name }}
</b-list-group-item>
</b-list-group>
</b-modal>
2020-08-22 18:59:58 +00:00
</div>
</template>
<script>
2020-11-21 06:23:40 +00:00
import { mapState } from 'vuex';
2020-08-22 18:59:58 +00:00
export default {
props: {
value: Array,
},
computed: {
2020-11-21 06:23:40 +00:00
...mapState(['platforms']),
2020-10-14 23:20:25 +00:00
2020-11-21 06:23:40 +00:00
buttonLabel() {
2020-10-14 23:20:25 +00:00
return this.value.length
? this.$t('board.settings.platformLabel', { platformCount: this.value.length })
: this.$t('board.settings.platformPlaceholder');
},
2020-08-22 18:59:58 +00:00
},
methods: {
handleClick(platformId) {
if (this.value.includes(platformId)) {
this.removePlatform(platformId);
} else {
this.selectPlatform(platformId);
}
},
selectPlatform(platformId) {
this.value.push(platformId);
},
removePlatform(platformId) {
const index = this.value.indexOf(platformId);
this.value.splice(index, 1);
},
},
};
</script>
2020-10-14 23:57:10 +00:00
2020-10-21 19:02:32 +00:00
<style lang="scss" rel="stylesheet/scss" scoped>
.dropdown {
max-height: 50vh;
2020-10-14 23:57:10 +00:00
}
</style>