gamebrary/src/components/Board/PlatformPicker.vue

70 lines
1.5 KiB
Vue
Raw Normal View History

2020-08-22 18:59:58 +00:00
<template lang="html">
<div class="platform-picker">
2020-10-14 23:20:25 +00:00
<b-dropdown>
<template v-slot:button-content>
{{ dropdownLabel }}
</template>
2020-08-22 18:59:58 +00:00
2020-10-14 23:20:25 +00:00
<b-dropdown-item
v-for="platform in filteredPlatforms"
2020-10-14 23:20:25 +00:00
:key="platform"
:active="value.includes(platform.id)"
@click="handleClick(platform.id)"
>
2020-10-14 23:20:25 +00:00
<b-img
:src="`/static/platform-logos/${platform.slug}.${platform.logoFormat}`"
:alt="platform.name"
width="40"
class="pr-2"
/>
{{ platform.name }}
</b-dropdown-item>
</b-dropdown>
<b-alert :show="value.length > 1" class="mt-3 mb-0">
Game search will be limited to the platforms selected.
</b-alert>
2020-08-22 18:59:58 +00:00
</div>
</template>
<script>
2020-08-25 04:21:24 +00:00
import { mapGetters } from 'vuex';
2020-08-22 18:59:58 +00:00
export default {
props: {
value: Array,
},
computed: {
2020-08-25 04:21:24 +00:00
...mapGetters(['filteredPlatforms']),
2020-10-14 23:20:25 +00:00
dropdownLabel() {
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>