-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterDropdown.vue
More file actions
50 lines (45 loc) · 1.49 KB
/
FilterDropdown.vue
File metadata and controls
50 lines (45 loc) · 1.49 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
<template>
<div
class="filter-container"
:style="{ width: width ? `${width}px` : '' }"
:class="width === 'full' && 'grow'">
<span class="filter-title">{{ title }}</span>
<div
ref="htmlRef"
class="filter-dropdown"
@click="toggleDropdown">
<span class="grow text-center">{{
optionList?.filter(el => el.value === value)[0].content
}}</span>
<CommonIcons :name="dropdownIcon" />
<ul
@click.stop
v-if="isDropdownOpened"
class="filter-dropdown-option-list">
<li
class="filter-dropdown-option hover:bg-background-2"
v-for="option in optionList"
:key="option.value"
@click="() => onOptionClick(option.value)">
{{ option.content }}
</li>
</ul>
</div>
</div>
</template>
<script setup lang="ts">
import { dropdownIcon } from '@/constants/iconPath'
import { useOutsideClick } from '@/hooks/useOutsideClick'
import type { Filter } from '@/types/common'
import { ref } from 'vue'
import CommonIcons from '../common/CommonIcons.vue'
const { title, value, width = '120', optionList } = defineProps<Filter>()
const emit = defineEmits(['update:value'])
const isDropdownOpened = ref(false)
const toggleDropdown = () => (isDropdownOpened.value = !isDropdownOpened.value)
const onOptionClick = (option: string) => {
emit('update:value', option)
toggleDropdown()
}
const { htmlRef } = useOutsideClick(() => isDropdownOpened.value && toggleDropdown())
</script>