From d54ae582019b33d0c1f095b12999f31f81e45bf5 Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Thu, 14 Aug 2025 08:03:33 +0000 Subject: [PATCH] Add baseline Storybook story with autofill attributes --- .../autofill-baseline.stories.tsx | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 apps/docs/src/remix-hook-form/autofill-baseline.stories.tsx diff --git a/apps/docs/src/remix-hook-form/autofill-baseline.stories.tsx b/apps/docs/src/remix-hook-form/autofill-baseline.stories.tsx new file mode 100644 index 00000000..6b56b57d --- /dev/null +++ b/apps/docs/src/remix-hook-form/autofill-baseline.stories.tsx @@ -0,0 +1,152 @@ +import { zodResolver } from '@hookform/resolvers/zod'; +import { TextField } from '@lambdacurry/forms/remix-hook-form/text-field'; +import { Button } from '@lambdacurry/forms/ui/button'; +import type { Meta, StoryObj } from '@storybook/react-vite'; +import { type ActionFunctionArgs, useFetcher } from 'react-router'; +import { RemixFormProvider, getValidatedFormData, useRemixForm } from 'remix-hook-form'; +import { z } from 'zod'; +import { withReactRouterStubDecorator } from '../lib/storybook/react-router-stub'; + +const formSchema = z.object({ + name: z.string().min(1, 'Name is required'), + email: z.string().email('Invalid email address'), + phone: z.string().min(1, 'Phone number is required'), + address: z.string().min(1, 'Address is required'), + city: z.string().min(1, 'City is required'), + state: z.string().min(1, 'State is required'), + zipCode: z.string().min(1, 'Zip code is required'), +}); + +type FormData = z.infer; + +const AutofillBaselineExample = () => { + const fetcher = useFetcher<{ message: string }>(); + const methods = useRemixForm({ + resolver: zodResolver(formSchema), + defaultValues: { + name: '', + email: '', + phone: '', + address: '', + city: '', + state: '', + zipCode: '', + }, + fetcher, + submitConfig: { + action: '/', + method: 'post', + }, + }); + + return ( + + +
+

Personal Information Form

+

+ This form demonstrates browser autofill functionality. Try using your browser's autofill feature to populate these fields. +

+ +
+ + + + + + + + +
+ + + +
+ + + + + + {fetcher.data?.message && ( +

{fetcher.data.message}

+ )} +
+
+
+
+ ); +}; + +const handleFormSubmission = async (request: Request) => { + const { data, errors } = await getValidatedFormData(request, zodResolver(formSchema)); + + if (errors) { + return { errors }; + } + + return { message: 'Form submitted successfully' }; +}; + +const meta: Meta = { + title: 'RemixHookForm/AutofillBaseline', + component: TextField, + parameters: { + layout: 'centered', + docs: { + description: { + component: 'A baseline example showing form fields with standard HTML autocomplete attributes for browser autofill.' + } + } + }, + tags: ['autodocs'], +}; + +export default meta; +type Story = StoryObj; + +export const AutofillExample: Story = { + decorators: [ + withReactRouterStubDecorator({ + routes: [ + { + path: '/', + Component: AutofillBaselineExample, + action: async ({ request }: ActionFunctionArgs) => handleFormSubmission(request), + }, + ], + }), + ], +}; +