|
1 | 1 | <script setup lang="ts">
|
2 |
| -import { useStepFormFlow } from '@formwerk/core'; |
3 |
| -import InputText from './components/InputText.vue'; |
4 |
| -import InputTextArea from './components/InputTextArea.vue'; |
5 |
| -import z from 'zod'; |
6 |
| -
|
7 |
| -const { |
8 |
| - formProps, |
9 |
| - nextButtonProps, |
10 |
| - previousButtonProps, |
11 |
| - onDone, |
12 |
| - isLastStep, |
13 |
| - FormStep, |
14 |
| - goToStep, |
15 |
| - isCurrentStep, |
16 |
| - getStepValue, |
17 |
| - onBeforeStepResolve, |
18 |
| -} = useStepFormFlow({}); |
19 |
| -
|
20 |
| -onBeforeStepResolve(ctx => { |
21 |
| - if (ctx.currentStep.name === 'step-1' && ctx.values.name === 'ahmad') { |
22 |
| - return 'step-3'; |
23 |
| - } |
24 |
| -
|
25 |
| - return ctx.next(); |
26 |
| -}); |
27 |
| -
|
28 |
| -const step1 = z.object({ |
29 |
| - name: z.string(), |
30 |
| - email: z.string().email(), |
31 |
| -}); |
32 |
| -
|
33 |
| -const step2 = z.object({ |
34 |
| - address: z.string(), |
35 |
| -}); |
36 |
| -
|
37 |
| -onDone(data => { |
38 |
| - console.log(data.toObject()); |
39 |
| -}); |
| 2 | +import FormField from './components/FormField.vue'; |
| 3 | +import TextControl from './components/TextControl.vue'; |
40 | 4 | </script>
|
41 | 5 |
|
42 | 6 | <template>
|
43 |
| - <form v-bind="formProps" class="w-full h-full flex flex-col items-center justify-center"> |
44 |
| - <div class="flex gap-2 my-8"> |
45 |
| - <button |
46 |
| - type="button" |
47 |
| - class="bg-gray-700 p-2 rounded-full aria-selected:bg-emerald-500 hover:bg-gray-500" |
48 |
| - :aria-selected="isCurrentStep(0)" |
49 |
| - @click="goToStep(0)" |
50 |
| - > |
51 |
| - Go to step 1 |
52 |
| - </button> |
53 |
| - <button |
54 |
| - type="button" |
55 |
| - class="bg-gray-700 p-2 rounded-full aria-selected:bg-emerald-500 hover:bg-gray-500" |
56 |
| - :aria-selected="isCurrentStep(1)" |
57 |
| - @click="goToStep(1)" |
58 |
| - > |
59 |
| - Go to step 2 |
60 |
| - </button> |
61 |
| - <button |
62 |
| - type="button" |
63 |
| - class="bg-gray-700 p-2 rounded-full aria-selected:bg-emerald-500 hover:bg-gray-500" |
64 |
| - :aria-selected="isCurrentStep(2)" |
65 |
| - @click="goToStep(2)" |
66 |
| - > |
67 |
| - Go to step 3 |
68 |
| - </button> |
69 |
| - </div> |
70 |
| - |
71 |
| - <FormStep name="step-1" :schema="step1"> |
72 |
| - {{ getStepValue(0) }} |
73 |
| - |
74 |
| - <InputText name="name" label="Name" /> |
75 |
| - <InputText name="email" label="Email" /> |
76 |
| - </FormStep> |
77 |
| - |
78 |
| - <FormStep name="step-2" :schema="step2"> |
79 |
| - {{ getStepValue(1) }} |
80 |
| - |
81 |
| - <InputTextArea name="address" label="Address" /> |
82 |
| - </FormStep> |
83 |
| - |
84 |
| - <FormStep name="step-3"> |
85 |
| - {{ getStepValue(2) }} |
86 |
| - |
87 |
| - <InputText name="city" label="City" /> |
88 |
| - </FormStep> |
89 |
| - |
90 |
| - <div class="mt-10 grid grid-cols-2 gap-4"> |
91 |
| - <button class="bg-gray-700 p-2 rounded-md" v-bind="previousButtonProps">⬅️ Previous</button> |
92 |
| - <button class="bg-gray-700 p-2 rounded-md" v-bind="nextButtonProps"> |
93 |
| - {{ isLastStep ? 'Submit' : 'Next ➡️' }} |
94 |
| - </button> |
95 |
| - </div> |
96 |
| - </form> |
| 7 | + <FormField label="Name"> |
| 8 | + <TextControl required /> |
| 9 | + </FormField> |
97 | 10 | </template>
|
98 | 11 |
|
99 | 12 | <style>
|
|
0 commit comments