1
1
<script setup lang='ts'>
2
- import { type PropType , computed } from ' vue'
2
+ import type { PropType } from ' vue'
3
3
import type { FormKitFrameworkContext } from ' @formkit/core'
4
4
5
5
import IconField from ' primevue/iconfield'
6
6
import InputIcon from ' primevue/inputicon'
7
7
import type { InputTextProps } from ' primevue/inputtext'
8
- import { useFormKitInput } from ' ../composables'
8
+ import { useFormKitIcon , useFormKitInput } from ' ../composables'
9
9
10
10
export interface FormKitPrimeInputTextProps {
11
11
pt? : InputTextProps [' pt' ]
@@ -24,27 +24,13 @@ const props = defineProps({
24
24
})
25
25
26
26
const { styleClass, wrapperClass, handleInput, handleBlur } = useFormKitInput (props .context )
27
-
28
- const hasIcon = computed (() => {
29
- if (props .context ?.icon && props .context ?.icon .length > 0 )
30
- return true
31
-
32
- return props .context ?.attrs ?.icon && props .context ?.attrs ?.icon .length > 0
33
- })
34
-
35
- const icon = computed (() => {
36
- return props .context ?.icon ?? props .context ?.attrs ?.icon
37
- })
38
-
39
- const iconPosition = computed (() => {
40
- return props .context ?.attrs ?.iconPosition ?? undefined
41
- })
27
+ const { hasIcon, icon, iconPosition } = useFormKitIcon (props .context )
42
28
</script >
43
29
44
30
<template >
45
31
<div :class =" wrapperClass" >
46
- <IconField v-if = " hasIcon " :icon-position = " iconPosition " >
47
- <InputIcon :class =" icon" />
32
+ <IconField >
33
+ <InputIcon v-if = " hasIcon && iconPosition === 'left' " :class =" icon" />
48
34
<InputText
49
35
:id =" context.id"
50
36
v-model =" context._value"
@@ -63,25 +49,7 @@ const iconPosition = computed(() => {
63
49
@input =" handleInput"
64
50
@blur =" handleBlur"
65
51
/>
52
+ <InputIcon v-if =" hasIcon && iconPosition === 'right'" :class =" icon" />
66
53
</IconField >
67
- <InputText
68
- v-else
69
- :id =" context.id"
70
- v-model =" context._value"
71
- v-bind =" context?.attrs"
72
- :disabled =" !!context?.disabled"
73
- :readonly =" context?.attrs.readonly ?? false"
74
- :style =" context?.attrs.style"
75
- :class =" styleClass"
76
- :tabindex =" context?.attrs.tabindex"
77
- :aria-label =" context?.attrs.ariaLabel"
78
- :aria-labelledby =" context?.attrs.ariaLabelledby"
79
- :placeholder =" context.placeholder"
80
- :pt =" context.pt"
81
- :pt-options =" context.ptOptions"
82
- :unstyled =" context.unstyled ?? false"
83
- @input =" handleInput"
84
- @blur =" handleBlur"
85
- />
86
54
</div >
87
55
</template >
0 commit comments