1
1
<script lang="ts" setup>
2
- import { NFlex , NInput } from ' naive-ui' ;
2
+ import { NFlex , NInput , NPopselect } from ' naive-ui' ;
3
3
4
4
import { computed , nextTick , type PropType , ref , toRefs } from ' vue' ;
5
5
@@ -22,14 +22,18 @@ const props = defineProps({
22
22
type: String as PropType <AliasScope >,
23
23
required: true ,
24
24
},
25
+ options: {
26
+ type: Array as PropType <string []>,
27
+ required: false ,
28
+ },
25
29
placeholder: {
26
30
type: String ,
27
31
required: false ,
28
32
default: ' none' ,
29
33
},
30
34
});
31
35
32
- const { scope, id, placeholder } = toRefs (props );
36
+ const { scope, id, placeholder, options } = toRefs (props );
33
37
34
38
const { aliasEnabled } = useLinksStoreRefs ();
35
39
const { getAliasRef } = useLinksStore ();
@@ -44,7 +48,7 @@ const value = computed(() => {
44
48
const hover = ref (false );
45
49
const focus = ref (false );
46
50
47
- const inputRef = ref <InputInst >();
51
+ const inputRef = ref <InputInst & { $el ? : HTMLInputElement } >();
48
52
49
53
const onClick = async () => {
50
54
if (! id .value || ! aliasEnabled .value ) return ;
@@ -53,6 +57,17 @@ const onClick = async () => {
53
57
inputRef .value ?.focus ();
54
58
};
55
59
60
+ const popOptions = computed (() => {
61
+ if (! options ?.value ) return [];
62
+ return options .value .map (option => ({ label: option , value: option }));
63
+ });
64
+
65
+ const popWidth = computed (() => {
66
+ const _input = inputRef ?.value ?.$el ?.querySelector (' input' );
67
+ if (! _input ?.offsetWidth ) return ;
68
+ return _input .offsetWidth + 32 ;
69
+ });
70
+
56
71
const i18n = useI18n (' panel' , ' alias' );
57
72
</script >
58
73
@@ -64,21 +79,34 @@ const i18n = useI18n('panel', 'alias');
64
79
size =" large"
65
80
justify =" center"
66
81
>
67
- <!-- Alias Input -->
68
- <NInput
82
+ <!-- Options select -->
83
+ <NPopselect
69
84
v-if =" hover || focus"
70
- ref =" inputRef"
71
85
v-model:value =" alias"
72
- class =" alias-input"
73
- :placeholder =" placeholder"
74
- @focus =" focus = true"
75
- @blur =" focus = false"
76
- @mouseleave =" hover = false"
86
+ class =" alias-pop-select"
87
+ :options =" popOptions"
88
+ :disabled =" !popOptions?.length"
89
+ :width =" popWidth"
90
+ placement =" bottom-end"
91
+ style =" --custom-bg-color : var (--bg-color-70 )"
92
+ scrollable
77
93
>
78
- <template #prefix >
79
- <span class =" alias-prefix" >{{ i18n('label') }}</span >
80
- </template >
81
- </NInput >
94
+ <!-- Alias Input -->
95
+ <NInput
96
+ ref =" inputRef"
97
+ v-model:value =" alias"
98
+ class =" alias-input"
99
+ :placeholder =" placeholder"
100
+ clearable
101
+ @focus =" focus = true"
102
+ @blur =" focus = false"
103
+ @mouseleave =" hover = false"
104
+ >
105
+ <template #prefix >
106
+ <span class =" alias-prefix" >{{ i18n('label') }}</span >
107
+ </template >
108
+ </NInput >
109
+ </NPopselect >
82
110
83
111
<!-- Alias -->
84
112
<TextField
@@ -107,7 +135,8 @@ const i18n = useI18n('panel', 'alias');
107
135
font-size : 1rem ;
108
136
109
137
.alias-prefix {
110
- min-width : 3rem ;
138
+ min-width : var (--prefix-min-width , 4rem );
139
+ margin-right : 0.5rem ;
111
140
color : var (--white-50 );
112
141
font-weight : 600 ;
113
142
}
0 commit comments