import { Switch } from "@medusajs/ui" import { ReactNode } from "react" import { ControllerProps, FieldPath, FieldValues } from "react-hook-form" import { Form } from "../../common/form" interface HeadlessControllerProps< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath > extends Omit, "render"> {} interface SwitchBoxProps< TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath > extends HeadlessControllerProps { label: string description: string optional?: boolean tooltip?: ReactNode /** * Callback for performing additional actions when the checked state changes. * This does not intercept the form control, it is only used for injecting side-effects. */ onCheckedChange?: (checked: boolean) => void } /** * Wrapper for the Switch component to be used with `react-hook-form`. * * Use this component whenever a design calls for wrapping the Switch component * in a container with a label and description. */ export const SwitchBox = < TFieldValues extends FieldValues = FieldValues, TName extends FieldPath = FieldPath >({ label, description, optional = false, tooltip, onCheckedChange, ...props }: SwitchBoxProps) => { return ( { return (
{ onCheckedChange?.(e) onChange(e) }} />
{label} {description}
) }} /> ) }