Skip to content

Commit ca65896

Browse files
author
Kevin Szymura
committed
feat: add icon left right on input mask
1 parent 4ebc0a8 commit ca65896

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

src/components/PrimeInputMask.vue

+46-20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export type FormKitPrimeInputMaskProps = {
1313
unstyled?: InputMaskProps['unstyled'];
1414
invalid?: InputMaskProps['invalid'];
1515
variant?: InputMaskProps['variant'];
16+
iconLeft?: string;
17+
iconRight?: string;
1618
}
1719
1820
const props = defineProps({
@@ -26,30 +28,54 @@ function handleInput(e: Event) {
2628
props.context?.node.input(props.context?._value)
2729
props.context?.handlers.blur(e)
2830
}
31+
32+
function hasLeftIcon() {
33+
return props.context?.iconLeft && props.context?.iconLeft.length > 0
34+
}
35+
36+
function hasRightIcon() {
37+
return props.context?.iconRight && props.context?.iconRight.length > 0
38+
}
39+
40+
function spanClass() {
41+
let result = ''
42+
if (hasLeftIcon())
43+
result = `${result}p-input-icon-left `
44+
if (hasRightIcon())
45+
result = `${result}p-input-icon-right `
46+
return result
47+
}
48+
2949
const styleClass = computed(() => (props.context?.state.validationVisible && !props.context?.state.valid) ? `${props.context?.attrs?.class} p-invalid` : props.context?.attrs?.class)
3050
</script>
3151

3252
<template>
3353
<div class="p-formkit">
34-
<InputMask
35-
:id="context.id"
36-
v-model="context._value"
37-
:disabled="!!context?.disabled"
38-
:readonly="context?.attrs._readonly ?? false"
39-
:class="styleClass"
40-
:tabindex="context?.attrs.tabindex"
41-
:aria-label="context?.attrs.ariaLabel"
42-
:aria-labelledby="context?.attrs.ariaLabelledby"
43-
:mask="context.mask ?? undefined"
44-
:slot-char="context.slotChar ?? '_'"
45-
:auto-clear="context.autoClear ?? true"
46-
:unmask="context.unmask ?? false"
47-
:pt="context.pt"
48-
:invalid="context.invalid"
49-
:variant="context.variant"
50-
:pt-options="context.ptOptions"
51-
:unstyled="context.unstyled ?? false"
52-
@blur="handleInput"
53-
/>
54+
<span :class="spanClass()">
55+
<i v-if="hasLeftIcon()" :class="context.iconLeft" />
56+
57+
<InputMask
58+
:id="context.id"
59+
v-model="context._value"
60+
:disabled="!!context?.disabled"
61+
:readonly="context?.attrs._readonly ?? false"
62+
:class="styleClass"
63+
:tabindex="context?.attrs.tabindex"
64+
:aria-label="context?.attrs.ariaLabel"
65+
:aria-labelledby="context?.attrs.ariaLabelledby"
66+
:mask="context.mask ?? undefined"
67+
:slot-char="context.slotChar ?? '_'"
68+
:auto-clear="context.autoClear ?? true"
69+
:unmask="context.unmask ?? false"
70+
:pt="context.pt"
71+
:invalid="context.invalid"
72+
:variant="context.variant"
73+
:pt-options="context.ptOptions"
74+
:unstyled="context.unstyled ?? false"
75+
@blur="handleInput"
76+
/>
77+
78+
<i v-if="hasRightIcon" :class="context.iconRight" />
79+
</span>
5480
</div>
5581
</template>

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export const primeInputMaskDefinition: FormKitTypeDefinition = createInput(Prime
8787
'unstyled',
8888
'invalid',
8989
'variant',
90+
'iconLeft',
91+
'iconRight',
9092
],
9193
})
9294

0 commit comments

Comments
 (0)