22import { type PropType , computed } from ' vue'
33import type { FormKitFrameworkContext } from ' @formkit/core'
44import type { InputTextProps } from ' primevue/inputtext'
5+ import type { IconFieldProps } from ' primevue/iconfield'
56
67export interface FormKitPrimeInputTextProps {
78 pt? : InputTextProps [' pt' ]
89 ptOptions? : InputTextProps [' ptOptions' ]
910 unstyled? : InputTextProps [' unstyled' ]
1011 placeholder? : InputTextProps [' placeholder' ]
1112 icon? : string
13+ iconPosition? : IconFieldProps [' iconPosition' ]
1214}
1315
1416const props = defineProps ({
@@ -18,9 +20,21 @@ const props = defineProps({
1820 },
1921})
2022
21- function hasIcon() {
23+ const hasIcon = computed (() => {
24+ if (props .context ?.icon && props .context ?.icon .length > 0 ) {
25+ return true
26+ }
27+
2228 return props .context ?.attrs ?.icon && props .context ?.attrs ?.icon .length > 0
23- }
29+ })
30+
31+ const icon = computed (() => {
32+ return props .context ?.icon ?? props .context ?.attrs ?.icon
33+ })
34+
35+ const iconPosition = computed (() => {
36+ return props .context ?.attrs ?.iconPosition ?? undefined ;
37+ })
2438
2539function handleBlur(e : Event ) {
2640 props .context ?.handlers .blur (e )
@@ -35,9 +49,8 @@ const styleClass = computed(() => (props.context?.state.validationVisible && !pr
3549
3650<template >
3751 <div class =" p-formkit" >
38- {{ context.attrs.icon }}
39- <IconField v-if =" hasIcon()" :icon-position =" context?.attrs.iconPosition" >
40- <InputIcon :class =" context.attrs.icon" />
52+ <IconField v-if =" hasIcon" :icon-position =" iconPosition" >
53+ <InputIcon :class =" icon" />
4154 <InputText
4255 :id =" context.id"
4356 v-model =" context._value"
0 commit comments