import { Switch as SwitchPrimitive, useSwitchContext } from "@seed-design/react-switch"; import { switchStyle, type SwitchVariantProps } from "@seed-design/css/recipes/switch"; import { switchmark, type SwitchmarkVariantProps } from "@seed-design/css/recipes/switchmark"; import { createSlotRecipeContext } from "../../utils/createSlotRecipeContext"; import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive"; import { createWithStateProps } from "../../utils/createWithStateProps"; import React from "react"; import clsx from "clsx"; import { splitMultipleVariantsProps } from "../../utils/splitMultipleVariantsProps"; const { withContext, ClassNamesProvider } = createSlotRecipeContext(switchStyle); const { withContext: withControlContext, PropsProvider: ControlPropsProvider, withProvider: withControlProvider, } = createSlotRecipeContext(switchmark); const withStateProps = createWithStateProps([useSwitchContext]); //////////////////////////////////////////////////////////////////////////////////// export interface SwitchRootProps extends SwitchVariantProps, Omit, SwitchPrimitive.RootProps {} export const SwitchRoot = React.forwardRef( ({ className, ...props }, ref) => { const [{ switch: switchVariantProps, switchmark: switchmarkVariantProps }, otherProps] = splitMultipleVariantsProps(props, { switchmark, switch: switchStyle }); const classNames = switchStyle(switchVariantProps); return ( ); }, ); SwitchRoot.displayName = "SwitchRoot"; //////////////////////////////////////////////////////////////////////////////////// export interface SwitchControlProps extends SwitchmarkVariantProps, SwitchPrimitive.ControlProps {} export const SwitchControl = withControlProvider( SwitchPrimitive.Control, "root", ); //////////////////////////////////////////////////////////////////////////////////// export interface SwitchThumbProps extends SwitchPrimitive.ThumbProps {} export const SwitchThumb = withControlContext( SwitchPrimitive.Thumb, "thumb", ); //////////////////////////////////////////////////////////////////////////////////// export interface SwitchLabelProps extends PrimitiveProps, React.HTMLAttributes {} export const SwitchLabel = withContext( withStateProps(Primitive.span), "label", ); //////////////////////////////////////////////////////////////////////////////////// export interface SwitchHiddenInputProps extends SwitchPrimitive.HiddenInputProps {} export const SwitchHiddenInput = SwitchPrimitive.HiddenInput;