Skip to content

Commit

Permalink
faet(forms): add new form sample
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxcode committed Oct 3, 2024
1 parent 918c3d9 commit ba5f9c1
Show file tree
Hide file tree
Showing 7 changed files with 1,271 additions and 1,208 deletions.
1 change: 1 addition & 0 deletions app/App.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "assets/sass/sidebar";
@import "assets/sass/form";
@import "assets/sass/main";


Expand Down
15 changes: 15 additions & 0 deletions app/assets/sass/form.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.p-formkit-data-view {
.formkit-form {
.formkit-outer {
padding-bottom: 0.8rem;
}

&.form-horizontal {
padding-bottom: 1.2rem;
}

.formkit-help {
margin: 0;
}
}
}
9 changes: 8 additions & 1 deletion app/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export function useNavigationMenu() {
child: [
{ href: '/prime/datatable', title: 'DataTable' },
{ href: '/prime/messages', title: 'Messages' },
{ href: '/prime/Validation', title: 'Validation' },
],
},
{
title: 'Forms',
icon: 'pi pi-check-square',
child: [
{ href: '/form', title: 'Basic' },
{ href: '/form/toggle', title: 'Edit / View' },
],
},
{
Expand Down
5 changes: 1 addition & 4 deletions app/pages/prime/validation.vue → app/pages/form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async function submitHandler() {
<template>
<div class="card flex flex-wrap gap-10">
<div class="basis-1/3 md:basis-1/4">
<h2>Data Edit</h2>
<h2>Basic Demo</h2>

<div v-if="data" class="min-w-25rem">
<FormKitDataEdit
Expand All @@ -152,7 +152,4 @@ async function submitHandler() {
</template>

<style lang='scss' scoped>
.myFormkit {
}
</style>
140 changes: 140 additions & 0 deletions app/pages/form/toggle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<script setup lang="ts">
import { FormKitDataEdit, FormKitDataView } from '@sfxcode/formkit-primevue/components'
import { useFormKitSchema } from '@sfxcode/formkit-primevue/composables'
const { addElement } = useFormKitSchema()
const { t } = useI18n()
const horizontal = ref(false)
const edit = ref(true)
const schema = reactive(
[
addElement('h2', ['Register ', '$email']),
addElement('h3', 'Header Text H3'),
{
$formkit: 'primeInputText',
name: 'name',
label: 'Name',
validation: 'required',
},
{
$formkit: 'primeInputText',
name: 'email',
label: 'Email',
help: 'This will be used for your account.',
validation: 'required|email',
iconPrefix: 'pi pi-book',
},
{
$formkit: 'primeTextarea',
name: 'text',
label: 'Text',
validation: '',
rows: '6',
},
{
$formkit: 'primeInputNumber',
name: 'number',
label: 'Balance',
validation: 'max:10000',
useGrouping: true,
minFractionDigits: 2,
},
{
$formkit: 'primeDatePicker',
name: 'date',
label: 'Date',
},
addElement('h3', 'Useful Links'),
{
$formkit: 'primeOutputLink',
name: 'field',
label: 'Google',
value: 'https://www.google.de',
iconSuffix: 'pi pi-check',
prefix: '-> ',
},
],
)
const outputSchema = reactive(
[
addElement('h2', ['Register ', '$email']),
addElement('h3', 'Header Text H3'),
{
$formkit: 'primeOutputText',
name: 'name',
label: 'Name',
validation: 'required',
},
{
$formkit: 'primeOutputText',
name: 'email',
label: 'Email',
iconPrefix: 'pi pi-book',
},
{
$formkit: 'primeOutputText',
name: 'text',
label: 'Text',
class: 'text-justify',
},
{
$formkit: 'primeOutputNumber',
name: 'number',
label: 'Balance',
format: 'currency',
},
{
$formkit: 'primeOutputDate',
name: 'date',
label: 'Date',
},
addElement('h3', 'Useful Links'),
{
$formkit: 'primeOutputLink',
name: 'field',
value: 'https://www.google.de',
label: 'Google',
iconSuffix: 'pi pi-check',
prefix: '-> ',
},
],
)
const data = ref({ name: 'Tom', email: 'tom@coding-universe.com', date: new Date(), number: 2222.33, text: 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.' })
const { showSuccessMessage } = useMessages()
async function submitHandler() {
showSuccessMessage('Form Submitted ...', 'Form submitted successfully')
}
</script>

<template>
<div class="card gap-10">
<div class="basis-1/2 md:basis-1/3">
<h2>Data Edit</h2>
<div class="flex gap-2 mb-4">
Edit Mode <ToggleSwitch v-model="edit" />
Horizontal <ToggleSwitch v-model="horizontal" />
</div>
<div class="max-w-100">
<FormKitDataEdit
v-if="edit"
:data="data"
:schema="schema"
:submit-label="t('save')"
:form-class="horizontal ? 'form-horizontal' : ''"
:debug-data="true"
@data-saved="submitHandler"
/>
<FormKitDataView
v-if="!edit" :data="data" :schema="outputSchema"
:form-class="horizontal ? 'form-horizontal' : ''"
:debug-data="true"
/>
</div>
</div>
</div>
</template>
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@antfu/eslint-config": "3.6.0",
"@formkit/nuxt": "1.6.6",
"@formkit/nuxt": "^1.6.7",
"@iconify-json/carbon": "^1.2.1",
"@iconify-json/mdi": "^1.2.0",
"@iconify-json/prime": "^1.2.0",
Expand All @@ -30,21 +30,21 @@
"@nuxt/content": "2.13.2",
"@nuxt/devtools": "1.4.2",
"@nuxt/fonts": "^0.8.0",
"@nuxt/image": "^1.8.0",
"@nuxt/image": "^1.8.1",
"@nuxt/test-utils": "^3.14.2",
"@nuxtjs/i18n": "8.5.5",
"@pinia/nuxt": "^0.5.4",
"@pinia/nuxt": "^0.5.5",
"@primevue/nuxt-module": "4.0.7",
"@primevue/themes": "4.0.7",
"@sfxcode/formkit-primevue": "^2.4.19",
"@tiptap/extension-highlight": "^2.7.4",
"@tiptap/extension-text-align": "^2.7.4",
"@tiptap/extension-text-style": "^2.7.4",
"@tiptap/pm": "^2.7.4",
"@tiptap/starter-kit": "^2.7.4",
"@tiptap/vue-3": "^2.7.4",
"@sfxcode/formkit-primevue": "^2.5.3",
"@tiptap/extension-highlight": "^2.8.0",
"@tiptap/extension-text-align": "^2.8.0",
"@tiptap/extension-text-style": "^2.8.0",
"@tiptap/pm": "^2.8.0",
"@tiptap/starter-kit": "^2.8.0",
"@tiptap/vue-3": "^2.8.0",
"@unocss/nuxt": "^0.62.4",
"@vitest/ui": "^2.1.1",
"@vitest/ui": "^2.1.2",
"@vue/test-utils": "^2.4.6",
"@vueuse/nuxt": "^11.1.0",
"c8": "^10.1.2",
Expand All @@ -57,9 +57,9 @@
"sass": "1.78.0",
"typescript": "^5.6.2",
"unstorage": "^1.12.0",
"vitest": "^2.1.1",
"vitest": "^2.1.2",
"vue-i18n": "9.14.0",
"vue-sidebar-menu": "^5.4.2"
},
"packageManager": "pnpm@9.11.0+sha256.1c0e33f70e5df9eede84a357bdfa0b1f9dba6e58194628d48a1055756f553754"
"packageManager": "pnpm@9.12.0+sha256.a61b67ff6cc97af864564f4442556c22a04f2e5a7714fbee76a1011361d9b726"
}
Loading

0 comments on commit ba5f9c1

Please sign in to comment.