Skip to content

Commit

Permalink
feat(docs): set up the FormKit Integration page
Browse files Browse the repository at this point in the history
  • Loading branch information
raichev-dima committed Dec 2, 2024
1 parent 2029c18 commit 19c9dcd
Show file tree
Hide file tree
Showing 21 changed files with 1,178 additions and 115 deletions.
9 changes: 8 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 @@ -175,4 +176,10 @@ export default defineNuxtConfig({
}
}
},

formkit: {
autoImport: true,
},

compatibilityDate: '2024-11-29',
});
2 changes: 2 additions & 0 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
},
"dependencies": {
"@docsearch/js": "^3.2.1",
"@formkit/nuxt": "^1.6.9",
"@formkit/vue": "^1.6.9",
"@funken-studio/sitemap-nuxt-3": "^4.0.4",
"@nuxtjs/google-fonts": "^3.0.1",
"@types/acorn": "^6.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<template>
<h1 class="text-2xl font-bold mb-4">
Carbon Sequestration Grant
</h1>

<FormKit
v-slot="{ value, state: { loading } }"
:type="types.form"
class="flex flex-col items-baseline gap-6"
:submit-label="loading ? 'Submitting...' : ''"
@submit="submitApp"
>
<h3 class="text-lg font-bold mb-2">
Contact info
</h3>
<FormKit
:type="types.email"
label="*Email address"
validation="required|email"
/>

<h3 class="text-lg font-bold mb-2">
Organization info
</h3>
<FormKit
:type="types.text"
label="*Organization name"
validation="required|length:3"
/>

<h3 class="text-lg font-bold mb-2">
Application
</h3>
<FormKit
:type="types.textarea"
label="*How will you use the money?"
validation="required|length:5,10"
/>

<details>
<summary>Form data</summary>
<pre>{{ value }}</pre>
</details>
</FormKit>
</template>

<script setup>
import * as types from '@vuestic/formkit'
// 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!')
}
</script>

<style scoped>
details {
border: 1px solid #ccccd7;;
background: #eeeef4;
border-radius: .15em;
padding: 1em;
}
</style>
15 changes: 15 additions & 0 deletions packages/docs/page-config/extensions/formkit/examples/Checkbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<FormKit
:type="types.checkbox"
label="Terms and Conditions"
help="Do you agree to our terms of service?"
name="terms"
:value="true"
validation="accepted"
validation-visibility="dirty"
/>
</template>

<script setup lang="ts">
import * as types from '@vuestic/formkit'
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<template>
<h1 class="text-2xl font-bold mb-4">
Carbon Sequestration Grant
</h1>

<VaTabs
v-model="activeStep"
>
<template #tabs>
<VaTab
v-for="(step, stepName) in steps"
:key="stepName"
:class="['step', { 'has-errors': checkStepValidity(stepName) }]"
:data-step-valid="step.valid && step.errorCount === 0"
:data-step-active="activeStep === stepName"
@click="activeStep = stepName"
>
<span
v-if="checkStepValidity(stepName)"
class="step--errors"
v-text="step.errorCount + step.blockingCount"
/>
<span
v-else-if="step.valid && step.errorCount === 0"
class="step--valid"
>
<VaIcon size="14px" class="material-icons">check</VaIcon>
</span>
{{ camel2title(stepName) }}
</VaTab>
</template>
</VaTabs>

<FormKit
v-slot="{ value, state: { valid, loading } }"
:type="types.form"
:plugins="[stepPlugin]"
:actions="false"
class="flex flex-col items-baseline gap-6 py-6"
@submit="submitApp"
>
<section
v-show="activeStep === 'contactInfo'"
class="flex-col items-baseline gap-6"
:class="{ flex: activeStep === 'contactInfo' }"
>
<FormKit
id="contactInfo"
type="group"
name="contactInfo"
>
<FormKit
:type="types.text"
label="*Full name"
name="full_name"
placeholder="First Last"
validation="required"
/>

<FormKit
:type="types.email"
name="email"
label="*Email address"
placeholder="[email protected]"
validation="required|email"
/>

<FormKit
:type="types.tel"
name="tel"
label="*Telephone"
mask="+1 (###) ###-####"
/>
</FormKit>
</section>

<section
v-show="activeStep === 'organizationInfo'"
class="flex-col items-baseline gap-6"
:class="{ flex: activeStep === 'organizationInfo' }"
>
<FormKit
id="organizationInfo"
type="group"
name="organizationInfo"
>
<FormKit
:type="types.text"
label="*Organization name"
name="org_name"
placeholder="MyOrg, Inc."
help="Enter your official organization name."
validation="required|length:3"
/>

<FormKit
:type="types.date"
label="Date of incorporation"
:validation="date_rule"
name="date_inc"
/>
</FormKit>
</section>

<section
v-show="activeStep === 'application'"
class="flex-col items-baseline gap-6"
:class="{ flex: activeStep === 'application' }"
>
<FormKit
id="application"
type="group"
name="application"
>
<FormKit
:type="types.checkbox"
label="*I'm not a previous grant recipient"
help="Have you received a grant from us before?"
name="not_previous_recipient"
validation="required|accepted"
:validation-messages="{ accepted: 'We can only give one grant per organization.' }"
/>
<FormKit
:type="types.textarea"
label="*How will you use the money?"
name="how_money"
help="Must be between 20 and 500 characters."
placeholder="Describe how the grant will accelerate your efforts."
validation="required|length:20,500"
/>
</FormKit>
</section>

<!-- NEW: Adds Next / Previous navigation buttons. -->
<div class="flex gap-6">
<FormKit
:type="types.button"
:disabled="activeStep === 'contactInfo'"
@click="setStep(-1)"
>
{{ 'Previous step' }}
</FormKit>
<FormKit
:type="types.button"
class="next"
:disabled="activeStep === 'application' "
@click="setStep(1)"
>
{{ 'Next step' }}
</FormKit>
</div>

<details>
<summary>Form data</summary>
<pre>{{ value }}</pre>
</details>

<!-- NEW: Adds submit button. -->
<FormKit :type="types.submit" :disabled="!valid">
{{ loading ? 'Submitting...' : 'Submit Application' }}
</FormKit>
</FormKit>

<p>
<small><em>*All the contents of this form are fictional (the company, grant, and form)
for the purposes of demonstrating the capabilities of FormKit.</em></small>
</p>
</template>

<script setup>
import * as types from '@vuestic/formkit'
import { camel2title, axios } from './utils'
import useSteps from './useSteps'
const { steps, visitedSteps, activeStep, setStep, stepPlugin } = useSteps()
const date_rule = [['date_before', new Date(Date.now())]]
// NEW: submit handler, which posts to our fake backend.
const submitApp = async (formData, node) => {
try {
await axios.post(formData)
node.clearErrors()
alert('Your application was submitted successfully!')
} catch (err) {
node.setErrors(err.formErrors, err.fieldErrors)
}
}
const checkStepValidity = (stepName) => {
return (steps[stepName].errorCount > 0 || steps[stepName].blockingCount > 0) && visitedSteps.value.includes(stepName)
}
</script>

<style scoped lang="scss">
details {
border: 1px solid #ccccd7;;
background: #eeeef4;
border-radius: .15em;
padding: 1em;
}
.step {
position: relative;
align-items: center;
display: flex;
padding: 0 1.5rem;
background: #eeeef4;
border-right: 1px solid #ccccd7;
}
[data-step-active="true"] {
background: white !important;
}
.step--errors,
.step--valid {
position: absolute;
top: 4px;
right: 4px;
height: 18px;
width: 18px;
border-radius: 50%;
z-index: 10;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
font-size: 10px;
background-color: #54A085;
color: white;
}
.step--errors {
background-color: #ff4949;
color: #fff;
z-index: 100;
}
</style>
Loading

0 comments on commit 19c9dcd

Please sign in to comment.