Skip to content

Commit 206fbea

Browse files
committed
refactor(inputs): use prefix and suffix instead of labelLeft and labelRight
1 parent a0539e9 commit 206fbea

File tree

9 files changed

+81
-60
lines changed

9 files changed

+81
-60
lines changed

dev/pages/index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const schema = reactive(
4141
help: 'Enter your new password.',
4242
validation: 'required|length:5,16',
4343
feedback: true,
44+
outerClass: 'col-6',
4445
},
4546
{
4647
$formkit: 'primePassword',
@@ -49,12 +50,14 @@ const schema = reactive(
4950
help: 'Enter your new password again.',
5051
validation: 'required|confirm',
5152
validationLabel: 'password confirmation',
53+
outerClass: 'col-6',
5254
},
5355
{
5456
$formkit: 'primeCheckbox',
5557
name: 'eu_citizen',
5658
id: 'eu',
57-
label: 'Are you a european citizen?',
59+
prefix: 'Are you a european citizen?',
60+
outerClass: 'col-6',
5861
},
5962
{
6063
$formkit: 'primeSelect',
@@ -65,6 +68,7 @@ const schema = reactive(
6568
optionValue: 'value',
6669
options,
6770
help: 'How often should we display a cookie notice?',
71+
outerClass: 'col-6',
6872
},
6973
],
7074
)

dev/pages/inputs/Checkbox.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang='ts'>
22
const primeAttributes = 'binary (dfault = true), trueValue, falseValue'
3-
const customAttributes = 'labelLeft, labelRight'
3+
const customAttributes = 'prefix, suffix'
44
55
const schema
66
= [
@@ -13,12 +13,12 @@ const schema
1313
{
1414
$formkit: 'primeCheckbox',
1515
id: 'eu',
16-
labelLeft: 'Are you a european citizen: ',
16+
prefix: 'Are you a european citizen: ',
1717
},
1818
{
1919
$formkit: 'primeCheckbox',
2020
id: 'taxes',
21-
labelRight: 'Taxes includes ',
21+
suffix: 'Taxes includes ',
2222
},
2323
{
2424
$formkit: 'primeCheckbox',

dev/pages/inputs/RadioButton.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ const schema
99
id: 'basic',
1010
label: 'Select',
1111
name: 'basic',
12-
wrapperClass: 'mt-1 flex flex-col space-y-2',
13-
optionClass: 'flex space-x-2',
14-
labelClass: 'font-bold',
1512
optionLabel: 'label',
1613
optionValue: 'value',
1714
options: [
@@ -20,6 +17,22 @@ const schema
2017
{ label: 'Every day', value: 'daily' },
2118
],
2219
},
20+
{
21+
$formkit: 'primeRadioButton',
22+
id: 'answer',
23+
label: 'Select Answer',
24+
name: 'answer',
25+
optionLabel: 'label',
26+
optionValue: 'value',
27+
options: [
28+
{ label: 'A', value: 'A' },
29+
{ label: 'B', value: 'B' },
30+
{ label: 'C', value: 'C' },
31+
{ label: 'D', value: 'D' },
32+
{ label: 'E', value: 'E' },
33+
34+
],
35+
},
2336
]
2437
2538
const data = { basic: 'refresh' }
@@ -28,6 +41,7 @@ const data = { basic: 'refresh' }
2841
<template>
2942
<div>
3043
<PrimeInput
44+
class="space-x-2 items-center"
3145
header="PrimeRadioButton" :schema="schema" :data="data"
3246
:prime-attributes="primeAttributes" :custom-attributes="customAttributes"
3347
/>

dev/pages/inputs/ToggleSwitch.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang='ts'>
22
const primeAttributes = 'trueValue, falseValue'
3-
const customAttributes = 'labelLeft, labelRight'
3+
const customAttributes = 'prefix, suffix'
44
55
const schema
66
= [
@@ -14,14 +14,13 @@ const schema
1414
$formkit: 'primeToggleSwitch',
1515
name: 'eu_citizen',
1616
id: 'eu',
17-
labelRight: 'Are you a european citizen: ',
18-
wrapperClass: 'flex items-center',
17+
suffix: 'Are you a european citizen: ',
1918
},
2019
{
2120
$formkit: 'primeToggleSwitch',
2221
name: 'confirmation',
2322
id: 'confirm',
24-
labelLeft: 'Are you sure ?',
23+
prefix: 'Are you sure ?',
2524
wrapperClass: 'flex items-center',
2625
},
2726
{

src/components/PrimeCheckbox.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { PropType } from 'vue'
33
import type { FormKitFrameworkContext } from '@formkit/core'
44
55
import type { CheckboxProps } from 'primevue/checkbox'
6-
import { useFormKitInput } from '../composables'
6+
import { useFormKitInput, useFormKitSection } from '../composables'
77
88
export interface FormKitPrimeCheckboxProps {
99
binary?: CheckboxProps['binary']
@@ -14,9 +14,6 @@ export interface FormKitPrimeCheckboxProps {
1414
unstyled?: CheckboxProps['unstyled']
1515
indeterminate?: CheckboxProps['indeterminate']
1616
variant?: CheckboxProps['variant']
17-
labelLeft?: string
18-
labelRight?: string
19-
2017
}
2118
2219
const props = defineProps({
@@ -26,12 +23,16 @@ const props = defineProps({
2623
},
2724
})
2825
26+
const { hasPrefix, hasSuffix } = useFormKitSection(props.context)
27+
2928
const { styleClass, handleInput, handleBlur } = useFormKitInput(props.context)
3029
</script>
3130

3231
<template>
3332
<div class="p-formkit">
34-
<span v-if="context.labelLeft" class="formkit-prime-left">{{ context.labelLeft }}</span>
33+
<span v-if="hasPrefix" class="formkit-prefix">
34+
{{ context?.prefix }}
35+
</span>
3536
<Checkbox
3637
v-model="context._value"
3738
v-bind="context?.attrs"
@@ -54,6 +55,8 @@ const { styleClass, handleInput, handleBlur } = useFormKitInput(props.context)
5455
@change="handleInput"
5556
@blur="handleBlur"
5657
/>
57-
<span v-if="context.labelRight" class="formkit-prime-right">{{ context.labelRight }}</span>
58+
<span v-if="hasSuffix" class="formkit-suffix">
59+
{{ context?.suffix }}
60+
</span>
5861
</div>
5962
</template>

src/components/PrimeToggleSwitch.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import type { PropType } from 'vue'
33
import type { FormKitFrameworkContext } from '@formkit/core'
44
55
import type { ToggleSwitchProps } from 'primevue/toggleswitch'
6-
import { useFormKitInput } from '../composables'
6+
import { useFormKitInput, useFormKitSection } from '../composables'
77
88
export interface FormKitPrimeToggleSwitchProps {
99
trueValue?: ToggleSwitchProps['trueValue']
1010
falseValue?: ToggleSwitchProps['falseValue']
1111
pt?: ToggleSwitchProps['pt']
1212
ptOptions?: ToggleSwitchProps['ptOptions']
1313
unstyled?: ToggleSwitchProps['unstyled']
14-
labelLeft?: string
15-
labelRight?: string
16-
1714
}
1815
1916
const props = defineProps({
@@ -23,12 +20,16 @@ const props = defineProps({
2320
},
2421
})
2522
23+
const { hasPrefix, hasSuffix } = useFormKitSection(props.context)
24+
2625
const { styleClass, handleInput, handleBlur } = useFormKitInput(props.context)
2726
</script>
2827

2928
<template>
3029
<div class="p-formkit">
31-
<span v-if="context.labelLeft" class="formkit-prime-left">{{ context.labelLeft }}</span>
30+
<span v-if="hasPrefix" class="formkit-prefix">
31+
{{ context?.prefix }}
32+
</span>
3233
<ToggleSwitch
3334
v-model="context._value"
3435
v-bind="context?.attrs"
@@ -48,6 +49,8 @@ const { styleClass, handleInput, handleBlur } = useFormKitInput(props.context)
4849
@change="handleInput"
4950
@blur="handleBlur"
5051
/>
51-
<span v-if="context.labelRight" class="formkit-prime-right">{{ context.labelRight }}</span>
52+
<span v-if="hasSuffix" class="formkit-suffix">
53+
{{ context?.suffix }}
54+
</span>
5255
</div>
5356
</template>

src/composables/useFormKitSection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { computed } from 'vue'
22

33
export function useFormKitSection(context: any) {
44
const hasPrefix = computed(() => {
5-
return context?.attrs?.prefix && context?.attrs?.prefix.length > 0
5+
return context?.prefix && context?.prefix.length > 0
66
})
77

88
const hasPrefixIcon = computed(() => {
@@ -14,7 +14,7 @@ export function useFormKitSection(context: any) {
1414
})
1515

1616
const hasSuffix = computed(() => {
17-
return context?.attrs?.suffix && context?.attrs?.suffix.length > 0
17+
return context?.suffix && context?.suffix.length > 0
1818
})
1919

2020
return { hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon }

0 commit comments

Comments
 (0)