Skip to content

Commit 7f98331

Browse files
committed
refactor(FormKitDataEdit): use FormKit form slots and PrimeVue Button component - try to fix #59 - add some more styling
1 parent cc51941 commit 7f98331

File tree

2 files changed

+132
-10
lines changed

2 files changed

+132
-10
lines changed

src/components/FormKitDataEdit.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<script setup lang='ts'>
2-
import { FormKit, FormKitSchema } from '@formkit/vue'
2+
import { FormKit, FormKitMessages, FormKitSchema } from '@formkit/vue'
33
import { ref } from 'vue'
44
import FormKitDebug from './FormKitDebug.vue'
55
66
const props = defineProps({
7+
id: {
8+
type: String,
9+
default: 'form',
10+
},
711
data: {
812
type: Object,
913
default: null,
@@ -28,6 +32,10 @@ const props = defineProps({
2832
type: String,
2933
default: 'Save',
3034
},
35+
cancelLabel: {
36+
type: String,
37+
default: 'Cancel',
38+
},
3139
actionsClass: {
3240
type: String,
3341
default: '',
@@ -51,19 +59,23 @@ function handleSave() {
5159
<template>
5260
<div class="p-formkit-data-edit">
5361
<FormKit
54-
id="form"
62+
:id="id"
5563
v-model="formData"
5664
:form-class="formClass"
5765
:actions-class="actionsClass"
5866
type="form"
59-
:submit-label="submitLabel"
60-
:submit-attrs="{
61-
inputClass,
62-
}"
6367
@submit="handleSave"
6468
>
65-
<FormKitSchema v-if="formSchema" :schema="formSchema" :data="formData" />
66-
<slot />
69+
<template #default>
70+
<FormKitSchema v-if="formSchema" :schema="formSchema" :data="formData" />
71+
<slot />
72+
</template>
73+
<template #messages>
74+
<FormKitMessages class="p-formkit-data-edit-messages" />
75+
</template>
76+
<template #submit>
77+
<Button type="submit" :label="submitLabel" @submit="handleSave" />
78+
</template>
6779
</FormKit>
6880
<FormKitDebug v-if="debugData" :data="formData" header="Data" />
6981
<FormKitDebug v-if="debugSchema" :data="formSchema" header="Schema" />

src/sass/formkit-primevue.scss

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ $grid-breakpoints: (
3535
// General message item styling
3636
.formkit-messages {
3737
margin: 0.125rem 0;
38-
padding-top: 0.25rem;
39-
padding-left: 0;
38+
padding-top: 0.5rem;
39+
padding-left: 0.5rem;
4040
}
4141

4242
.formkit-message {
@@ -51,6 +51,12 @@ $grid-breakpoints: (
5151
.formkit-outer {
5252
padding-bottom: 0.8rem;
5353

54+
.formkit-messages {
55+
margin: 0.125rem 0;
56+
padding-top: 0.25rem;
57+
padding-left: 0;
58+
}
59+
5460
.formkit-inner {
5561
.p-formkit {
5662
.p-formkit-icon {
@@ -163,6 +169,110 @@ $grid-breakpoints: (
163169
}
164170
}
165171

172+
// data view only
173+
.p-formkit-data-view {
174+
.formkit-form {
175+
.formkit-outer {
176+
padding-bottom: 0;
177+
}
178+
179+
.formkit-help {
180+
margin: 0;
181+
}
182+
}
183+
}
184+
185+
// data edit only
186+
.p-formkit-data-edit {
187+
188+
.formkit-form {
189+
.formkit-label {
190+
//font-weight: normal;
191+
}
192+
193+
// specific checkbox stylings
194+
.formkit-outer[data-type="primeCheckbox"] {
195+
//padding-left: 0;
196+
197+
.formkit-wrapper {
198+
display: flex;
199+
flex-wrap: wrap;
200+
201+
.formkit-inner {
202+
width: auto !important;
203+
}
204+
205+
label {
206+
width: auto;
207+
order: 2;
208+
padding: 0.125rem 0;
209+
210+
&:after {
211+
content: "";
212+
}
213+
214+
// styling of output when label is used in schema
215+
+ .formkit-inner {
216+
margin-left: 0 !important;
217+
order: 1;
218+
flex-basis: 2rem;
219+
flex-grow: 0;
220+
flex-shrink: 0;
221+
overflow: hidden;
222+
// styling of suffix when suffix is used in addition to label
223+
&:has( label) {
224+
flex-grow: 1;
225+
flex-basis: 100%;
226+
}
227+
}
228+
}
229+
230+
// styling when both prefix and suffix are used in schema
231+
label:first-child:nth-last-child(3), label:first-child:nth-last-child(3) ~ label {
232+
width: auto;
233+
}
234+
235+
label:first-child:nth-last-child(3) {
236+
order: 1;
237+
238+
+ div.p-checkbox {
239+
order: 2;
240+
width: auto;
241+
}
242+
}
243+
244+
label:first-child:nth-last-child(3) ~ label {
245+
order: 3
246+
}
247+
248+
// end styling when both prefix and suffix are used in schema
249+
250+
251+
// styling of output when only suffix is used in schema
252+
.formkit-inner:first-child {
253+
margin-left: 0 !important;
254+
255+
.p-formkit {
256+
display: flex;
257+
}
258+
}
259+
260+
.p-checkbox:not(:only-child) {
261+
width: 2rem;
262+
overflow: hidden;
263+
}
264+
}
265+
266+
.formkit-help {
267+
width: auto !important;
268+
//padding-left: 2rem;
269+
}
270+
}
271+
}
272+
}
273+
274+
275+
166276
// Debug
167277
.p-formkit-data-debug {
168278
pre, span {

0 commit comments

Comments
 (0)