-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDropdownDisplayChoices.vue
More file actions
60 lines (59 loc) · 2.1 KB
/
DropdownDisplayChoices.vue
File metadata and controls
60 lines (59 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<!-- eslint-disable max-len -->
<div class="focus:outline-none ml-2 sm:flex-none" @focusout="close" tabindex="0">
<div v-bind:class="{'settings-button-choice': true, 'rounded-lg': true , 'border-gray-matcha': !closed}" @click="toggle">
<h1 v-bind:class="{ 'opacity-50': closed, 'noSelect': true, 'capitalize': true }">
{{ getName }}<span v-if="closed" class="ml-2">▼</span><span v-if="!closed" class="ml-2">▲</span></h1>
</div>
<div v-bind:class="{'sort-dropdown': true, 'z-10': true, 'h-auto': options.length < 5 , 'hidden': closed, 'right-0': position === 'right', 'md:right-auto': position === 'right'}">
<h1 v-for="(option, index) in options" :key="option + index + option"
v-bind:class="{'sort-dropdown-option': true, 'border-b': index !== options.length - 1, 'capitalize': true,
'font-extrabold': selectedFilters.indexOf(option) !== -1, 'text-gray-matcha': selectedFilters.indexOf(option) !== -1}"
v-on:click="select(option)">
{{option}}
</h1>
</div>
</div>
</template>
<script>
export default {
props: ['options', 'name', 'position', 'startingOptions', 'min', 'max'],
data: () => ({
closed: true,
selectedFilters: [],
}),
methods: {
select(option) {
const optionIndex = this.selectedFilters.indexOf(option);
if (optionIndex !== -1) {
if (this.selectedFilters.length > this.min) {
this.selectedFilters.splice(optionIndex, 1);
this.$emit('save-multiple-choice', this.name, this.selectedFilters);
}
} else if (this.selectedFilters.length < this.max) {
this.selectedFilters.push(option);
this.$emit('save-multiple-choice', this.name, this.selectedFilters);
}
},
toggle() {
this.closed = !this.closed;
},
close() {
this.closed = true;
},
},
computed: {
getName() {
if (this.selectedFilters.length) {
return this.selectedFilters[0];
}
return this.name;
},
},
beforeMount() {
if (this.startingOptions) {
this.selectedFilters = this.startingOptions;
}
},
};
</script>