Skip to content

Commit 2a1869a

Browse files
committed
feat(PrimeOutputText): add convertValue prop for custom value transformation
1 parent b21b255 commit 2a1869a

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

dev/pages/outputs/OutputText.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ function prefixClicked() {
99
function suffixClicked() {
1010
console.error('Suffix Icon Clicked')
1111
}
12+
13+
function toUpper(value: string) {
14+
return value.toUpperCase()
15+
}
1216
const schema
1317
= [
1418
{
@@ -51,6 +55,12 @@ const schema
5155
iconSuffix: 'pi pi-check text-yellow-500',
5256
onIconSuffixClicked: suffixClicked,
5357
},
58+
{
59+
$formkit: 'primeOutputText',
60+
name: 'name',
61+
label: 'Connvert to Uppercase',
62+
convertValue: toUpper,
63+
},
5464
5565
]
5666

src/components/PrimeOutputText.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ import FormKitIcon from './FormKitIcon.vue'
99
import FormKitPrefix from './FormKitPrefix.vue'
1010
import FormKitSuffix from './FormKitSuffix.vue'
1111
12+
export interface FormKitOutputTextProps {
13+
html?: boolean
14+
isTranslationKey?: boolean
15+
convertValue?: (value: string) => string
16+
}
17+
1218
const props = defineProps({
1319
context: {
14-
type: Object as PropType<FormKitFrameworkContext> & FormKitIconProps,
20+
type: Object as PropType<FormKitFrameworkContext> & FormKitIconProps & FormKitOutputTextProps,
1521
required: true,
1622
},
1723
})
@@ -20,10 +26,15 @@ const textValue = computed(() => {
2026
const value = props.context?._value
2127
const { t } = useI18n()
2228
if (value) {
23-
if (props.context?.isTranslationKey)
29+
if (props.context?.isTranslationKey) {
2430
return t(value)
25-
else
31+
}
32+
else if (typeof props.context?.convertValue === 'function') {
33+
return props.context?.convertValue(value)
34+
}
35+
else {
2636
return value
37+
}
2738
}
2839
else {
2940
return ''

src/definitions/output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import PrimeOutputReference from '../components/PrimeOutputReference.vue'
1010
import PrimeOutputText from '../components/PrimeOutputText.vue'
1111

1212
export const primeOutputTextDefinition: FormKitTypeDefinition = createInput(PrimeOutputText, {
13-
props: ['prefix', 'suffix', 'iconPrefix', 'iconSuffix', 'isTranslationKey', 'html', 'onIconPrefixClicked', 'onIconSuffixClicked'],
13+
props: ['prefix', 'suffix', 'iconPrefix', 'iconSuffix', 'isTranslationKey', 'html', 'onIconPrefixClicked', 'onIconSuffixClicked', 'convertValue'],
1414
})
1515

1616
export const primeOutputDateDefinition: FormKitTypeDefinition = createInput(PrimeOutputDate, {

0 commit comments

Comments
 (0)