generated from Evobaso-J/nuxt-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseInput.vue
64 lines (56 loc) · 1.44 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
58
59
60
61
62
63
64
<template>
<InputLayout
:label="label"
:prepend-icon="prependIcon"
:icon-props="iconProps"
>
<input
v-bind="$attrs"
v-model="model"
:type
class="group w-full h-full bg-transparent focus:outline-none"
:disabled
@input="emit('input', $event)"
>
<button
type="button"
class="rounded-full ml-2 hover:bg-gray-200 transition-opacity"
:class="{
'opacity-0': !model || !clearable,
}"
>
<FontAwesomeIcon
:icon="{ prefix: 'fas', iconName: 'close' }"
class="text-gray-400 aspect-square"
size="lg"
@click="clear"
/>
</button>
</InputLayout>
</template>
<script setup lang="ts" generic="TModelValue">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import InputLayout, { type InputLayoutProps } from './InputLayout.vue'
export type BaseInputProps = {
type: HTMLInputElement['type']
label: string
clearable?: boolean
} & InputLayoutProps
export type BaseInputEmits = {
(event: 'input', value: Event): void
(event: 'clear'): void
}
defineComponent({ name: 'BaseInput' })
defineProps<BaseInputProps>()
type BaseInputSlots = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
prependIcon: () => any
}
defineSlots<BaseInputSlots>()
const emit = defineEmits<BaseInputEmits>()
const model = defineModel<TModelValue>()
const clear = () => {
model.value = undefined
emit('clear')
}
</script>