-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSort.vue
More file actions
41 lines (40 loc) · 1.29 KB
/
Sort.vue
File metadata and controls
41 lines (40 loc) · 1.29 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
<template>
<!-- eslint-disable max-len -->
<div class="focus:outline-none flex-1 sm:flex-none" @focusout="close" tabindex="0">
<div v-bind:class="{'sort-button': true, 'border-gray-matcha': !closed}" @click="toggle">
<h1 v-bind:class="{ 'opacity-50': closed, 'noSelect': true, 'capitalize': true }">↑↓</h1>
</div>
<div v-bind:class="{'sort-dropdown': true, 'hidden': closed, 'left-0': position === 'left', 'md:left-auto': position === 'left'}">
<h1 v-for="(option, index) in options" :key="option + index + option"
v-bind:class="{'sort-dropdown-option': true, 'border-b': index !== options.length - 1, 'font-extrabold': option === currentOption, 'text-gray-matcha': option === currentOption}"
v-on:click="select(option)">
{{option}}
</h1>
</div>
</div>
</template>
<script>
export default {
props: ['options', 'name', 'position', 'startingOption'],
data: () => ({
closed: true,
currentOption: '',
}),
methods: {
select(option) {
this.close();
this.currentOption = option;
this.$emit('save-sort', option);
},
toggle() {
this.closed = !this.closed;
},
close() {
this.closed = true;
},
},
beforeMount() {
this.currentOption = this.startingOption;
},
};
</script>