diff --git a/packages/ui/src/stories/form.stories.tsx b/packages/ui/src/stories/form.stories.tsx new file mode 100644 index 0000000..6854abd --- /dev/null +++ b/packages/ui/src/stories/form.stories.tsx @@ -0,0 +1,76 @@ +'use client'; + +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; + +import { Button } from '../button'; +import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '../form'; +import { Input } from '../input'; + +import { Meta, StoryObj } from '@storybook/react'; + +const formSchema = z.object({ + username: z.string().min(2, { + message: 'Username must be at least 2 characters.', + }), +}); + +function ProfileForm() { + // 1. Define your form. + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + username: '', + }, + }); + + // 2. Define a submit handler. + function onSubmit(values: z.infer) { + // Do something with the form values. + // ✅ This will be type-safe and validated. + console.log(values); + } + + return ( +
+ + ( + + Username + + + + This is your public display name. + + + )} + /> + + + + ); +} + +const meta = { + title: 'CODERUM/Form', + component: ProfileForm, + parameters: { + // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout + layout: 'centered', + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const FormExample: Story = {}; diff --git a/packages/ui/src/styles/tailwind.css b/packages/ui/src/styles/tailwind.css index 9ad451d..c386663 100644 --- a/packages/ui/src/styles/tailwind.css +++ b/packages/ui/src/styles/tailwind.css @@ -852,6 +852,12 @@ body { margin-bottom: calc(0.5rem * var(--tw-space-y-reverse)); } +.space-y-8 > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(2rem * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(2rem * var(--tw-space-y-reverse)); +} + .overflow-hidden { overflow: hidden; }