| @update:model-value="$emit('update:modelValue', $event as string)" |
| 9 | > |
| 10 | <template #trigger> |
| 11 | <button class="filter-trigger" :class="{ 'has-value': modelValue }" :style="minWidth && !isMobile ? { minWidth: minWidth + 'px' } : undefined"> |
| 12 | <span class="filter-label">{{ label }}:</span> |
| 13 | <span class="filter-value">{{ displayLabel }}</span> |
| 14 | <el-icon class="filter-arrow"><ArrowDown /></el-icon> |
| 15 | </button> |
| 16 | </template> |
| 17 | <PopoverMenuItem value="">{{ allLabel }}</PopoverMenuItem> |
| 18 | <PopoverMenuItem |
| 19 | v-for="opt in options" |
| 20 | :key="opt.value" |
| 21 | :value="opt.value" |
| 22 | > |
| 23 | {{ opt.label }} |
| 24 | </PopoverMenuItem> |
| 25 | </PopoverMenu> |
| 26 | </template> |
| 27 |
| 28 | <script setup lang="ts"> |
| 29 | import { computed } from 'vue' |
| 30 | import { ArrowDown } from '@element-plus/icons-vue' |
| 31 | import PopoverMenu from './PopoverMenu.vue' |
| 32 | import PopoverMenuItem from './PopoverMenuItem.vue' |
| 33 |
| 34 | interface Props { |
| 35 | modelValue: string |
| 36 | label: string |
| 37 | options: Array<{ label: string; value: string }> |
| 38 | allLabel?: string |
| 39 | width?: number |
| 40 | minWidth?: number |
| 41 | isMobile?: boolean |
| 42 | } |
| 43 |
| 44 | const props = withDefaults(defineProps<Props>(), { |
| 45 | allLabel: 'All', |
| 46 | width: 150, |
| 47 | }) |
| 48 |
| 49 | defineEmits<{ |
| 50 | 'update:modelValue': [value: string] |
| 51 | }>() |
| 52 |
| 53 | const displayLabel = computed(() => { |
| 54 | if (!props.modelValue) return props.allLabel |
| 55 | const found = props.options.find((o) => o.value === props.modelValue) |
| 56 | return found ? found.label : props.modelValue |
| 57 | }) |
| 58 | </script> |
| 59 |
| 60 | <style scoped lang="scss"> |
| 61 | .filter-trigger { |
| 62 | display: inline-flex; |
| 63 | align-items: center; |
| 64 | gap: $spacing-sm; |
| 65 | padding: 7px 12px; |
| 66 | background: $color-bg-primary; |
| 67 | border: none; |
| 68 | border-radius: $radius-md; |
| 69 | box-shadow: 0 0 0 1px $color-border-light inset; |
| 70 | font-size: $font-size-sm; |
| 71 | color: $color-text-secondary; |
| 72 | cursor: pointer; |
| 73 | transition: box-shadow $transition-fast; |
| 74 | white-space: nowrap; |
| 75 |
| 76 | &:hover { |
| 77 | box-shadow: 0 0 0 1px $color-border inset; |
| 78 | } |
| 79 |
| 80 | &.has-value .filter-value { |
| 81 | color: $color-text-primary; |
| 82 | } |
| 83 | } |
| 84 |
| 85 | .filter-label { |
| 86 | color: $color-text-muted; |
| 87 | flex-shrink: 0; |
| 88 | } |
| 89 |
| 90 | .filter-value { |
| 91 | color: $color-text-secondary; |
| 92 | margin-left: auto; |
| 93 | } |
| 94 |
| 95 | .filter-arrow { |
| 96 | font-size: 12px; |
| 97 | color: $color-text-light; |
| 98 | flex-shrink: 0; |
| 99 | } |
| 100 | </style> |