mirror of
https://github.com/supabase/supabase.git
synced 2026-05-06 08:56:46 -04:00
0facd341a6
## Problem We used to have a `_Shadcn_` suffix for all the shadcn form components because we also had `formik` form components. This is not needed anymore. ## Solution - Remove the suffix - Update all usages
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useForm } from 'react-hook-form'
|
|
import { Button, Form, FormControl, FormField, Switch } from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import { z } from 'zod'
|
|
|
|
const FormSchema = z.object({
|
|
switch_option: z.boolean().default(false).optional(),
|
|
})
|
|
|
|
export default function FormItemLayoutDemo() {
|
|
// 1. Define your form.
|
|
const form = useForm<z.infer<typeof FormSchema>>({
|
|
resolver: zodResolver(FormSchema),
|
|
})
|
|
|
|
// 2. Define a submit handler.
|
|
function onSubmit(values: z.infer<typeof FormSchema>) {
|
|
// Do something with the form values.
|
|
// ✅ This will be type-safe and validated.
|
|
console.log(values)
|
|
// action('form form.handleSubmit(onSubmit)')(values)
|
|
}
|
|
return (
|
|
<Form {...form}>
|
|
<form className="w-96 flex flex-col gap-3" onSubmit={form.handleSubmit(onSubmit)}>
|
|
<FormField
|
|
control={form.control}
|
|
name="switch_option"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
afterLabel="Switch"
|
|
label="Use ./supabase directory for everything"
|
|
description="This is an explanation."
|
|
layout="flex"
|
|
>
|
|
<FormControl>
|
|
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
<Button size="small" type="secondary" htmlType="submit">
|
|
Submit
|
|
</Button>
|
|
</form>
|
|
</Form>
|
|
)
|
|
}
|