Skip to content

Commit

Permalink
feat(storybook): add MultiStep form to storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
raichev-dima committed Dec 31, 2024
1 parent 543efd1 commit 222b853
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 77 deletions.
2 changes: 1 addition & 1 deletion packages/formkit/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type StorybookConfig } from '@storybook/vue3-vite'

const config: StorybookConfig = {
stories: ['../stories/*.stories.ts'],
stories: ['../stories/**/**.stories.ts'],
framework: '@storybook/vue3-vite',
}

Expand Down
5 changes: 5 additions & 0 deletions packages/formkit/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import { DefineComponent } from '@vue/runtime-core'
const component: DefineComponent<{}, {}, any>
export default component
}
76 changes: 0 additions & 76 deletions packages/formkit/stories/Form.stories.ts

This file was deleted.

70 changes: 70 additions & 0 deletions packages/formkit/stories/form/BasicForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<template>
<h1 class="text-2xl font-bold mb-4">
Carbon Sequestration Grant
</h1>

<FormKit
v-slot="{ state: { loading } }"
v-model="formValue"
type="form"
class="grid grid-cols-1 md:grid-cols-3 gap-6"
:submit-label="loading ? 'Submitting...' : ''"
@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>
import { ref } from 'vue'
// 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>
21 changes: 21 additions & 0 deletions packages/formkit/stories/form/Form.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { StoryFn } from '@storybook/vue3'
import BasicForm from './BasicForm.vue'
import MultiStepForm from './MultiStepForm.vue'

export default {
title: 'Formkit Integration/Form',
}

export const Basic: StoryFn = () => ({
components: {
BasicForm
},
template: `<BasicForm />`,
})

export const MultiStep: StoryFn = () => ({
components: {
MultiStepForm
},
template: `<MultiStepForm />`,
})
Loading

0 comments on commit 222b853

Please sign in to comment.