@@ -7,7 +7,9 @@ import type { ComponentConfig } from '../types/utils'
7
7
8
8
type PinInput = ComponentConfig <typeof theme , AppConfig , ' pinInput' >
9
9
10
- export interface PinInputProps extends Pick <PinInputRootProps , ' defaultValue' | ' disabled' | ' id' | ' mask' | ' modelValue' | ' name' | ' otp' | ' placeholder' | ' required' | ' type' > {
10
+ type PinInputType = ' text' | ' number'
11
+
12
+ export interface PinInputProps <T extends PinInputType = ' text' > extends Pick <PinInputRootProps <T >, ' defaultValue' | ' disabled' | ' id' | ' mask' | ' modelValue' | ' name' | ' otp' | ' placeholder' | ' required' | ' type' > {
11
13
/**
12
14
* The element or component this component should render as.
13
15
* @defaultValue 'div'
@@ -37,14 +39,14 @@ export interface PinInputProps extends Pick<PinInputRootProps, 'defaultValue' |
37
39
ui? : PinInput [' slots' ]
38
40
}
39
41
40
- export type PinInputEmits = PinInputRootEmits & {
42
+ export type PinInputEmits < T extends PinInputType = ' text ' > = PinInputRootEmits < T > & {
41
43
change: [payload : Event ]
42
44
blur: [payload : Event ]
43
45
}
44
46
45
47
</script >
46
48
47
- <script setup lang="ts">
49
+ <script setup lang="ts" generic = " T extends PinInputType = ' text ' " >
48
50
import type { ComponentPublicInstance } from ' vue'
49
51
import { ref , computed , onMounted } from ' vue'
50
52
import { PinInputInput , PinInputRoot , useForwardPropsEmits } from ' reka-ui'
@@ -54,16 +56,16 @@ import { useFormField } from '../composables/useFormField'
54
56
import { looseToNumber } from ' ../utils'
55
57
import { tv } from ' ../utils/tv'
56
58
57
- const props = withDefaults (defineProps <PinInputProps >(), {
58
- type: ' text' ,
59
+ const props = withDefaults (defineProps <PinInputProps < T > >(), {
60
+ type: ' text' as never ,
59
61
length: 5 ,
60
62
autofocusDelay: 0
61
63
})
62
- const emits = defineEmits <PinInputEmits >()
64
+ const emits = defineEmits <PinInputEmits < T > >()
63
65
64
66
const appConfig = useAppConfig () as PinInput [' AppConfig' ]
65
67
66
- const rootProps = useForwardPropsEmits (reactivePick (props , ' defaultValue' , ' disabled' , ' id' , ' mask' , ' modelValue' , ' name' , ' otp' , ' placeholder ' , ' required' , ' type' ), emits )
68
+ const rootProps = useForwardPropsEmits (reactivePick (props , ' defaultValue' , ' disabled' , ' id' , ' mask' , ' modelValue' , ' name' , ' otp' , ' required' , ' type' ), emits )
67
69
68
70
const { emitFormInput, emitFormFocus, emitFormChange, emitFormBlur, size, color, id, name, highlight, disabled, ariaAttrs } = useFormField <PinInputProps >(props )
69
71
@@ -77,7 +79,7 @@ const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.pinInput ||
77
79
const inputsRef = ref <ComponentPublicInstance []>([])
78
80
79
81
const completed = ref (false )
80
- function onComplete(value : string []) {
82
+ function onComplete(value : string [] | number [] ) {
81
83
// @ts-expect-error - 'target' does not exist in type 'EventInit'
82
84
const event = new Event (' change' , { target: { value } })
83
85
emits (' change' , event )
@@ -113,6 +115,7 @@ defineExpose({
113
115
v-bind =" { ...rootProps, ...ariaAttrs }"
114
116
:id =" id"
115
117
:name =" name"
118
+ :placeholder =" placeholder"
116
119
:class =" ui.root({ class: [props.ui?.root, props.class] })"
117
120
@update:model-value =" emitFormInput()"
118
121
@complete =" onComplete"
0 commit comments