Skip to content

Commit

Permalink
feat(formkit): integration module (#4435)
Browse files Browse the repository at this point in the history
Co-authored-by: Yauheni Prakopchyk <[email protected]>
Co-authored-by: raichev-dima <[email protected]>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent 09c949c commit b1aed63
Show file tree
Hide file tree
Showing 73 changed files with 3,364 additions and 30 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"lint:style": "yarn workspace vuestic-ui lint:style",
"serve:docs": "yarn workspace docs serve",
"build:docs": "yarn workspace docs build",
"build:docs:ci": "yarn workspace docs build:ci",
"build:docs:ci": "yarn workspace @vuestic/formkit build && yarn workspace docs build:ci",
"push": "yarn workspace vuestic-ui push",
"push-production": "yarn workspace vuestic-ui push-production",
"build:nuxt": "yarn workspace @vuestic/nuxt build",
Expand All @@ -34,7 +34,10 @@
"sandbox:nuxt": "yarn workspace sandbox dev:nuxt",
"sandbox:vue-cli": "yarn workspace sandbox dev:vue-cli",
"sandbox:web-components": "yarn workspace sandbox dev:web-components",
"release": "yarn workspace deploy release"
"release": "yarn workspace deploy release",
"serve:formkit": "yarn workspace @vuestic/formkit serve:storybook",
"build:formkit": "yarn workspace @vuestic/formkit build:storybook",
"start:formkit": "yarn workspace @vuestic/formkit start:storybook"
},
"workspaces": {
"packages": [
Expand All @@ -56,6 +59,7 @@
"@vue/server-renderer": "3.5.12",
"@vue/compiler-dom": "3.5.12",
"sass": "1.52.0",
"typescript": "5.3.2",
"vue-tsc": "2.0.7"
}
}
6 changes: 6 additions & 0 deletions packages/docs/formkit.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defaultConfig } from '@formkit/vue'
import * as inputs from '@vuestic/formkit'

export default defaultConfig({
inputs,
})
10 changes: 9 additions & 1 deletion packages/docs/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ export default defineNuxtConfig({
nitro: {
// compressPublicAssets: true,
},

gtm: {
id: process.env.GTM_ID, // Your GTM single container ID, array of container ids ['GTM-xxxxxx', 'GTM-yyyyyy'] or array of objects [{id: 'GTM-xxxxxx', queryParams: { gtm_auth: 'abc123', gtm_preview: 'env-4', gtm_cookies_win: 'x'}}, {id: 'GTM-yyyyyy', queryParams: {gtm_auth: 'abc234', gtm_preview: 'env-5', gtm_cookies_win: 'x'}}], // Your GTM single container ID or array of container ids ['GTM-xxxxxx', 'GTM-yyyyyy']
enabled: process.env.GTM_ENABLED === 'true', // defaults to true. Plugin can be disabled by setting this to false for Ex: enabled: !!GDPR_Cookie (optional)
},

modules: [
'@formkit/nuxt',
'./modules/repl',
'./modules/banner',
'./modules/vuestic',
Expand Down Expand Up @@ -139,7 +141,6 @@ export default defineNuxtConfig({
},
},


css: [
'@/assets/css/tailwind.css',
],
Expand Down Expand Up @@ -183,6 +184,13 @@ export default defineNuxtConfig({
}
},

formkit: {
defaultConfig: false,
autoImport: true,
},

compatibilityDate: '2024-11-29',

devtools: {
enabled: false,
}
Expand Down
1 change: 1 addition & 0 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"@docsearch/js": "^3.2.1",
"@formkit/nuxt": "^1.6.9",
"@funken-studio/sitemap-nuxt-3": "^4.0.4",
"@nuxtjs/google-fonts": "^3.0.1",
"@types/acorn": "^6.0.0",
Expand Down
174 changes: 174 additions & 0 deletions packages/docs/page-config/extensions/formkit/examples/AdvancedForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<template>
<FormKit
id="advancedForm"
v-slot="{ state: { valid } }"
v-model="form"
type="form"
class="flex flex-col items-baseline gap-6"
:actions="false"
>
<FormKit
name="firstName"
type="text"
label="First Name"
validation="required"
/>

<FormKit
name="lastName"
type="text"
label="Last Name"
validation="required"
/>

<FormKit
name="birthDate"
type="datepicker"
label="Birth Date"
clearable
:validation-rules="{ birthday }"
validation="required|birthday"
:validation-messages="{
birthday: 'You must be at least 18 years old'
}"
/>

<FormKit
name="count"
type="counter"
label="Amount"
validation="required|min:10"
:validation-messages="{
min: 'You can not buy less than 10 items'
}"
manual-input
/>

<FormKit
name="country"
type="select"
:options="countries"
label="Country"
validation="required|is:us,uk"
:validation-rules="{ is: (node, ...group) => group.includes(node.value?.value) }"
:validation-messages="{
is: 'Delivery currently unavailable in your country'
}"
/>

<FormKit
name="amount"
type="slider"
:min="1"
:max="100"
label="Weight, kg"
style="width: 100%"
validation="required|package"
:validation-rules="{
package: (node) => {
return node.parent.value.country.value === 'us' ? node.value < 20 : true
}
}"
:validation-messages="{ package: 'Package to US can not be more than 20kg' }"
/>

<FormKit
name="notifications"
type="toggle"
label="Notifications"
size="small"
validation="accepted"
:validation-messages="{
accepted: 'You must agree on notifications'
}"
/>

<div>
<span class="va-title">Payment method</span>
<FormKit
name="paymentMethod"
type="radio"
:options="['Visa', 'MasterCard', 'PayPal']"
validation="required|is:PayPal"
:validation-messages="{ is: 'Only PayPal is currently available' }"
/>
</div>

<FormKit
name="acknowledgement"
type="checkbox"
label="I'm okay if you lose my package"
validation="accepted"
:validation-messages="{ accepted: 'You must agree with terms and conditions' }"
/>

<FormKit type="submit" :disabled="!valid" @click="submit()">
Submit
</FormKit>
</FormKit>

<div class="mt-8 flex w-full gap-3 background-element">
<FormKit type="button" @click="submitForm('advancedForm')">
Validate
</FormKit>
<FormKit type="button" @click="reset('advancedForm', form)">
Reset validation
</FormKit>
<FormKit
type="button"
@click="resetForm()"
>
Reset
</FormKit>
</div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { reset, submitForm } from '@formkit/core'
const resetForm = () => reset('advancedForm', {
firstName: '',
lastName: '',
country: '',
birthDate: null as Date | null,
time: null as Date | null,
acknowledgement: false,
notifications: true,
paymentMethod: '',
amount: 1,
count: 1,
})
const form = ref({
firstName: '',
lastName: '',
country: '',
birthDate: null as Date | null,
acknowledgement: false,
notifications: true,
paymentMethod: '',
amount: 1,
count: 1,
})
const countries = [
{ value: 'ua', text: 'Ukraine' },
{ value: 'us', text: 'USA' },
{ value: 'uk', text: 'United Kingdom' },
]
const birthday = (node: any) => {
const today = new Date()
let yearDiff = today.getFullYear() - node.value.getFullYear()
const monthDiff = today.getMonth() - node.value.getMonth()
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < node.value.getDate())) {
yearDiff--
}
return yearDiff >= 18
}
const submit = () => alert('Form submitted!')
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<h1 class="text-2xl font-bold mb-4">
Carbon Sequestration Grant
</h1>

<FormKit
v-model="formValue"
type="form"
class="grid grid-cols-1 md:grid-cols-3 gap-6"
@submit="submitApp"
>
<div>
<FormKit
type="email"
name="email"
label="*Email address"
validation="required|email"
/>
</div>

<div>
<FormKit
type="text"
name="organization_name"
label="*Organization name"
validation="required|length:3"
/>
</div>

<div>
<FormKit
type="textarea"
name="money_use"
label="*How will you use the money?"
validation="required|length:5,10"
/>
</div>
</FormKit>

<VaCollapse
class="min-w-96 mt-4"
header="Form data"
>
<pre>{{ formValue }}</pre>
</VaCollapse>
</template>

<script setup>
// NEW: submit handler, which posts to our fake backend.
const submitApp = async (_formData, node) => {
await new Promise(resolve => setTimeout(resolve, 1400))
node.clearErrors()
alert('Your application was submitted successfully!')
}
const formValue = ref({})
</script>

<style scoped>
details {
border: 1px solid #ccccd7;;
background: #eeeef4;
border-radius: .15em;
padding: 1em;
}
</style>
Loading

0 comments on commit b1aed63

Please sign in to comment.