-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseInput.vue
57 lines (54 loc) · 1.47 KB
/
BaseInput.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
<template>
<!-- Base Input (text, email, password) -->
<div>
<label class="label-style" :for="label" v-if="label">{{ label }}</label>
<div class="relative">
<input
:id="label"
:type="type"
:value="modelValue"
:placeholder="placeholder"
v-bind="$attrs"
@input="$emit('update:modelValue', ($event.target as HTMLInputElement).value)"
class="input-style"
:class="{ err: error }"
/>
<span
v-if="password"
class="mdi absolute top-1/2 -translate-y-1/2 right-4 cursor-pointer"
@click="$emit('changeType')"
>
<Icon name="mdi:eye" v-if="type === 'password'" />
<Icon name="mdi:eye-off" v-else />
</span>
</div>
<small
:class="{ 'err-message': error }"
v-if="error && errorMessage"
aria-live="assertive"
:id="`${label}-error`"
>{{ errorMessage }}</small
>
<small
:class="{ 'err-message': error }"
v-else-if="error && !errorMessage"
aria-live="assertive"
:id="`${label}-error`"
>{{ label }} is required</small
>
</div>
</template>
<script setup lang="ts">
interface Props {
type: string
modelValue: string | number
label?: string
placeholder?: string
password?: boolean
error?: string | boolean
errorMessage?: string | boolean
}
const props = defineProps<Props>()
const emit = defineEmits(['changeType', 'update:modelValue'])
</script>
<style lang="scss" scoped></style>