forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordInput.vue
More file actions
48 lines (42 loc) · 1.5 KB
/
Copy pathPasswordInput.vue
File metadata and controls
48 lines (42 loc) · 1.5 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
<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import { Eye, EyeOff } from '@lucide/vue'
import { useVModel } from '@vueuse/core'
import { cn } from '@/lib/utils'
const props = defineProps<{
defaultValue?: string
modelValue?: string
class?: HTMLAttributes[`class`]
placeholder?: string
}>()
const emits = defineEmits<{
(e: `update:modelValue`, payload: string): void
}>()
const modelValue = useVModel(props, `modelValue`, emits, {
passive: true,
defaultValue: props.defaultValue,
})
const showPassword = ref(false)
function togglePasswordVisibility() {
showPassword.value = !showPassword.value
}
</script>
<template>
<div class="relative">
<input
v-model="modelValue"
:type="showPassword ? 'text' : 'password'"
:placeholder="placeholder"
:class="cn('flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 pr-10 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50', props.class)"
>
<button
type="button"
class="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors"
aria-label="切换密码可见性"
@click="togglePasswordVisibility"
>
<Eye v-if="!showPassword" class="h-4 w-4" />
<EyeOff v-else class="h-4 w-4" />
</button>
</div>
</template>