Skip to content

Commit 73dc880

Browse files
committed
chore: playground tests
1 parent 01c5ba2 commit 73dc880

File tree

3 files changed

+50
-92
lines changed

3 files changed

+50
-92
lines changed

packages/playground/src/App.vue

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,12 @@
11
<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';
404
</script>
415

426
<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>
9710
</template>
9811

9912
<style>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div>
3+
<label v-bind="labelProps">{{ label }}</label>
4+
5+
<slot />
6+
7+
<p v-if="errorMessage" v-bind="errorMessageProps" class="error-message">{{ errorMessage }}</p>
8+
9+
<p v-else-if="description" v-bind="descriptionProps">{{ description }}</p>
10+
11+
{{ fieldValue }}
12+
</div>
13+
</template>
14+
15+
<script setup lang="ts">
16+
import { useFieldState, useFormField, FieldProps } from '@formwerk/core';
17+
18+
const props = defineProps<FieldProps>();
19+
20+
const state = useFieldState();
21+
const { errorMessage, fieldValue } = state;
22+
const { labelProps, errorMessageProps, descriptionProps } = useFormField(props, state);
23+
</script>
24+
25+
<style scoped>
26+
/** Your styles here */
27+
.error-message {
28+
color: red;
29+
}
30+
31+
label {
32+
display: block;
33+
}
34+
</style>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
import { TextControlProps, useTextControl } from '@formwerk/core';
3+
4+
const props = defineProps<TextControlProps>();
5+
6+
const { inputProps } = useTextControl(props);
7+
</script>
8+
9+
<template>
10+
<input v-bind="inputProps" class="border border-gray-300 rounded-md p-2" />
11+
</template>

0 commit comments

Comments
 (0)