import { Field, Label, Switch as HeadlessSwitch } from '@headlessui/react' import { type ReactNode } from 'react' import { Controller, get, type FieldError, type FieldValues, type Path, type RegisterOptions, } from 'react-hook-form' import { useRemixFormContext } from 'remix-hook-form' import { twMerge } from 'tailwind-merge' type TSwitchProperties = { id: string label?: ReactNode name: Path rules?: RegisterOptions containerClassName?: string labelClassName?: string className?: string inputClassName?: string options?: { true: string false: string } } export const Switch = >( properties: TSwitchProperties, ) => { const { id, label, name, rules, containerClassName, labelClassName, className, inputClassName, options, } = properties const { control, formState: { errors }, } = useRemixFormContext() const error: FieldError = get(errors, name) return ( (
{ field.onChange(checked) }} className={twMerge( 'group flex h-7 cursor-pointer items-center rounded-full bg-[#2E2F7C]/10 p-1 shadow transition-colors duration-200 ease-in-out focus:outline-none data-[checked]:bg-[#2E2F7C]/90 data-[focus]:outline-1 data-[focus]:outline-white', inputClassName, )} >
{field.value ? options?.true : options?.false}
)} /> ) }