-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Select.vue
139 lines (119 loc) 路 3.13 KB
/
Select.vue
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<script lang="ts" setup>
const props = defineProps<{
value?: string | string[]
placeholder?: string
mode?: 'multiple' | 'tags'
dropdownClassName?: string
showSearch?: boolean
// filterOptions is a function
filterOption?: (input: string, option: any) => boolean
dropdownMatchSelectWidth?: boolean
allowClear?: boolean
loading?: boolean
}>()
const emits = defineEmits(['update:value', 'change'])
const placeholder = computed(() => props.placeholder)
const dropdownClassName = computed(() => {
let className = 'nc-select-dropdown'
if (props.dropdownClassName) {
className += ` ${props.dropdownClassName}`
}
return className
})
const showSearch = computed(() => props.showSearch)
const filterOption = computed(() => props.filterOption)
const dropdownMatchSelectWidth = computed(() => props.dropdownMatchSelectWidth)
const loading = computed(() => props.loading)
const mode = computed(() => props.mode)
const vModel = useVModel(props, 'value', emits)
const onChange = (value: string) => {
emits('change', value)
}
</script>
<template>
<a-select
v-model:value="vModel"
:allow-clear="allowClear"
:disabled="loading"
:dropdown-class-name="dropdownClassName"
:dropdown-match-select-width="dropdownMatchSelectWidth"
:filter-option="filterOption"
:loading="loading"
:mode="mode"
:placeholder="placeholder"
:show-search="showSearch"
class="nc-select"
@change="onChange"
>
<template #suffixIcon>
<GeneralLoader v-if="loading" />
<GeneralIcon v-else class="text-gray-800 nc-select-expand-btn" icon="arrowDown" />
</template>
<slot />
</a-select>
</template>
<style lang="scss">
.ant-select-item {
@apply !xs:h-13 !min-h-[2.375rem] !p-2;
}
.ant-select-item-option-content {
@apply !xs:mt-2.5;
}
.ant-select-item-option-state {
@apply !xs:mt-1.75;
}
.ant-select-item-option {
@apply !rounded-md;
}
.nc-select.ant-select {
height: fit-content;
.ant-select-selector {
box-shadow: 0px 5px 3px -2px rgba(0, 0, 0, 0.02), 0px 3px 1px -2px rgba(0, 0, 0, 0.06);
@apply border-1 border-gray-200 rounded-lg;
}
.ant-select-selection-item {
@apply font-medium pr-3 rounded-md;
}
.ant-select-selection-placeholder {
@apply text-gray-600;
}
.ant-select-selection-item-remove {
@apply text-gray-800 !pb-1;
}
}
.nc-select.ant-select-focused:not(.ant-select-disabled).ant-select:not(.ant-select-customize-input) .ant-select-selector {
box-shadow: none;
@apply border-brand-500;
}
.nc-select.ant-select.ant-select-disabled .nc-select-expand-btn {
@apply text-gray-300;
}
.nc-select-dropdown {
@apply !rounded-xl py-1.5;
.rc-virtual-list-holder {
overflow-y: auto;
overflow-x: hidden;
font-weight: 500;
.ant-select-item-option-content {
font-weight: 500;
}
&::-webkit-scrollbar {
width: 4px;
height: 4px;
}
&::-webkit-scrollbar-track-piece {
width: 0px;
}
&::-webkit-scrollbar {
@apply bg-transparent;
}
&::-webkit-scrollbar-thumb {
width: 4px;
@apply bg-gray-300;
}
&::-webkit-scrollbar-thumb:hover {
@apply bg-gray-400;
}
}
}
</style>