11import { zodResolver } from '@hookform/resolvers/zod' ;
22import { Switch } from '@lambdacurry/forms/remix-hook-form/switch' ;
3+ import type { FormLabel , FormMessage } from '@lambdacurry/forms/remix-hook-form/form' ;
34import { Button } from '@lambdacurry/forms/ui/button' ;
4- import { FormLabel , FormMessage } from '@lambdacurry/forms/ui/form' ;
5- import * as SwitchPrimitives from '@radix-ui/react-switch' ;
5+ import * as SwitchPrimitive from '@radix-ui/react-switch' ;
66import type { Meta , StoryObj } from '@storybook/react-vite' ;
7- import { expect , userEvent , within } from 'storybook/test' ;
7+ import { expect , userEvent , within } from '@ storybook/test' ;
88import type * as React from 'react' ;
99import type { ActionFunctionArgs } from 'react-router' ;
1010import { useFetcher } from 'react-router' ;
11- import { RemixFormProvider , getValidatedFormData , useRemixForm } from 'remix-hook-form' ;
11+ import { RemixFormProvider , createFormData , getValidatedFormData , useRemixForm } from 'remix-hook-form' ;
1212import { z } from 'zod' ;
1313import { withReactRouterStubDecorator } from '../lib/storybook/react-router-stub' ;
1414
@@ -21,19 +21,19 @@ const formSchema = z.object({
2121type FormData = z . infer < typeof formSchema > ;
2222
2323// Custom Switch component
24- const PurpleSwitch = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitives . Root > ) => (
25- < SwitchPrimitives . Root
24+ const PurpleSwitch = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitive . Root > ) => (
25+ < SwitchPrimitive . Root
2626 { ...props }
2727 className = "peer inline-flex h-8 w-16 shrink-0 cursor-pointer items-center rounded-full border-2 border-purple-300 bg-purple-100 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-purple-500 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-purple-600 data-[state=unchecked]:bg-purple-200"
2828 >
2929 { props . children }
30- </ SwitchPrimitives . Root >
30+ </ SwitchPrimitive . Root >
3131) ;
3232PurpleSwitch . displayName = 'PurpleSwitch' ;
3333
3434// Custom Switch Thumb component
35- const PurpleSwitchThumb = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitives . Thumb > ) => (
36- < SwitchPrimitives . Thumb
35+ const PurpleSwitchThumb = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitive . Thumb > ) => (
36+ < SwitchPrimitive . Thumb
3737 { ...props }
3838 className = "pointer-events-none flex h-7 w-7 items-center justify-center rounded-full bg-white shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-8 data-[state=unchecked]:translate-x-0 relative overflow-hidden data-[state=checked]:[--on-opacity:1] data-[state=checked]:[--off-opacity:0] data-[state=unchecked]:[--on-opacity:0] data-[state=unchecked]:[--off-opacity:1]"
3939 >
@@ -43,7 +43,7 @@ const PurpleSwitchThumb = (props: React.ComponentPropsWithoutRef<typeof SwitchPr
4343 < span className = "absolute inset-0 opacity-[var(--off-opacity)] flex items-center justify-center text-xs font-bold text-purple-600 transition-opacity duration-200 z-10" >
4444 OFF
4545 </ span >
46- </ SwitchPrimitives . Thumb >
46+ </ SwitchPrimitive . Thumb >
4747) ;
4848PurpleSwitchThumb . displayName = 'PurpleSwitchThumb' ;
4949
@@ -60,19 +60,19 @@ const PurpleMessage = (props: React.ComponentPropsWithoutRef<typeof FormMessage>
6060PurpleMessage . displayName = 'PurpleMessage' ;
6161
6262// Green Switch component
63- const GreenSwitch = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitives . Root > ) => (
64- < SwitchPrimitives . Root
63+ const GreenSwitch = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitive . Root > ) => (
64+ < SwitchPrimitive . Root
6565 { ...props }
6666 className = "peer inline-flex h-7 w-14 shrink-0 cursor-pointer items-center rounded-full border-2 border-green-300 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-green-500 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-green-600 data-[state=unchecked]:bg-white"
6767 >
6868 { props . children }
69- </ SwitchPrimitives . Root >
69+ </ SwitchPrimitive . Root >
7070) ;
7171GreenSwitch . displayName = 'GreenSwitch' ;
7272
7373// Green Switch Thumb component
74- const GreenSwitchThumb = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitives . Thumb > ) => (
75- < SwitchPrimitives . Thumb
74+ const GreenSwitchThumb = ( props : React . ComponentPropsWithoutRef < typeof SwitchPrimitive . Thumb > ) => (
75+ < SwitchPrimitive . Thumb
7676 { ...props }
7777 className = "pointer-events-none flex h-6 w-6 items-center justify-center rounded-full bg-green-100 shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-7 data-[state=unchecked]:translate-x-0 data-[state=checked]:bg-white"
7878 >
@@ -86,7 +86,7 @@ const GreenSwitchThumb = (props: React.ComponentPropsWithoutRef<typeof SwitchPri
8686 < title > Check mark</ title >
8787 < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = { 2 } d = "M5 13l4 4L19 7" />
8888 </ svg >
89- </ SwitchPrimitives . Thumb >
89+ </ SwitchPrimitive . Thumb >
9090) ;
9191GreenSwitchThumb . displayName = 'GreenSwitchThumb' ;
9292
@@ -234,17 +234,17 @@ The \`components\` prop allows you to override any of the internal components us
234234
235235// APPROACH 2: Custom Switch with purple styling and ON/OFF text
236236const PurpleSwitch = React.forwardRef((props, ref) => (
237- <SwitchPrimitives .Root
237+ <SwitchPrimitive .Root
238238 ref={ref}
239239 {...props}
240240 className="peer inline-flex h-8 w-16 shrink-0 cursor-pointer items-center rounded-full border-2 border-purple-300 bg-purple-100 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-purple-500 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-purple-600 data-[state=unchecked]:bg-purple-200"
241241 >
242242 {props.children}
243- </SwitchPrimitives .Root>
243+ </SwitchPrimitive .Root>
244244));
245245
246246const PurpleSwitchThumb = React.forwardRef((props, ref) => (
247- <SwitchPrimitives .Thumb
247+ <SwitchPrimitive .Thumb
248248 ref={ref}
249249 {...props}
250250 className="pointer-events-none flex h-7 w-7 items-center justify-center rounded-full bg-white shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-8 data-[state=unchecked]:translate-x-0 relative overflow-hidden data-[state=checked]:[--on-opacity:1] data-[state=checked]:[--off-opacity:0] data-[state=unchecked]:[--on-opacity:0] data-[state=unchecked]:[--off-opacity:1]"
@@ -255,7 +255,7 @@ const PurpleSwitchThumb = React.forwardRef((props, ref) => (
255255 <span className="absolute inset-0 opacity-[var(--off-opacity)] flex items-center justify-center text-xs font-bold text-purple-600 transition-opacity duration-200 z-10">
256256 OFF
257257 </span>
258- </SwitchPrimitives .Thumb>
258+ </SwitchPrimitive .Thumb>
259259));
260260
261261<Switch
@@ -270,17 +270,17 @@ const PurpleSwitchThumb = React.forwardRef((props, ref) => (
270270
271271// APPROACH 3: Fully customized switch with green styling, checkmark icon, and custom form components
272272const GreenSwitch = React.forwardRef((props, ref) => (
273- <SwitchPrimitives .Root
273+ <SwitchPrimitive .Root
274274 ref={ref}
275275 {...props}
276276 className="peer inline-flex h-7 w-14 shrink-0 cursor-pointer items-center rounded-full border-2 border-green-300 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-green-500 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-green-600 data-[state=unchecked]:bg-white"
277277 >
278278 {props.children}
279- </SwitchPrimitives .Root>
279+ </SwitchPrimitive .Root>
280280));
281281
282282const GreenSwitchThumb = React.forwardRef((props, ref) => (
283- <SwitchPrimitives .Thumb
283+ <SwitchPrimitive .Thumb
284284 ref={ref}
285285 {...props}
286286 className="pointer-events-none flex h-6 w-6 items-center justify-center rounded-full bg-green-100 shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-7 data-[state=unchecked]:translate-x-0 data-[state=checked]:bg-white"
@@ -294,7 +294,7 @@ const GreenSwitchThumb = React.forwardRef((props, ref) => (
294294 >
295295 <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
296296 </svg>
297- </SwitchPrimitives .Thumb>
297+ </SwitchPrimitive .Thumb>
298298));
299299
300300const PurpleLabel = React.forwardRef((props, ref) => (
0 commit comments