docs: add new-york version of example
This commit is contained in:
parent
f5adb2ebd5
commit
bfe4c3d3c2
63
apps/www/src/lib/registry/new-york/example/SliderForm.vue
Normal file
63
apps/www/src/lib/registry/new-york/example/SliderForm.vue
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<script setup lang="ts">
|
||||
import { h } from 'vue'
|
||||
import { useForm } from 'vee-validate'
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import * as z from 'zod'
|
||||
|
||||
import { Button } from '@/lib/registry/new-york/ui/button'
|
||||
import {
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from '@/lib/registry/new-york/ui/form'
|
||||
import { Slider } from '@/lib/registry/new-york/ui/slider'
|
||||
import { toast } from '@/lib/registry/new-york/ui/toast'
|
||||
|
||||
const formSchema = toTypedSchema(z.object({
|
||||
duration: z.array(
|
||||
z.number().min(1).max(1440)
|
||||
),
|
||||
}))
|
||||
|
||||
const { handleSubmit } = useForm({
|
||||
validationSchema: formSchema,
|
||||
})
|
||||
|
||||
const onSubmit = handleSubmit((values) => {
|
||||
toast({
|
||||
title: 'You submitted the following values:',
|
||||
description: h('pre', { class: 'mt-2 w-[340px] rounded-md bg-slate-950 p-4' }, h('code', { class: 'text-white' }, JSON.stringify(values, null, 2))),
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<form class="w-2/3 space-y-6" @submit="onSubmit">
|
||||
<FormField v-slot="{ componentField }" name="duration">
|
||||
<FormItem>
|
||||
<FormLabel>Duration</FormLabel>
|
||||
<FormControl>
|
||||
<Slider
|
||||
v-bind="componentField"
|
||||
:default-value="[30]"
|
||||
:max="60"
|
||||
:min="5"
|
||||
:step="5"
|
||||
/>
|
||||
<FormDescription class="flex justify-between">
|
||||
<span>How many minutes are you available?</span>
|
||||
<span>{{ componentField.modelValue?.[0] ?? "30" }} min</span>
|
||||
</FormDescription>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
</FormField>
|
||||
|
||||
<Button type="submit">
|
||||
Submit
|
||||
</Button>
|
||||
</form>
|
||||
</template>
|
||||
Loading…
Reference in New Issue
Block a user