{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "primitives-base-switch",
  "title": "Base Switch",
  "description": "A control that indicates whether a setting is on or off.",
  "dependencies": [
    "motion",
    "@base-ui-components/react"
  ],
  "registryDependencies": [
    "@animate-ui/lib-get-strict-context",
    "@animate-ui/hooks-use-controlled-state"
  ],
  "files": [
    {
      "path": "registry/primitives/base/switch/index.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { Switch as SwitchPrimitives } from '@base-ui-components/react/switch';\nimport {\n  motion,\n  type TargetAndTransition,\n  type VariantLabels,\n  type HTMLMotionProps,\n  type LegacyAnimationControls,\n} from 'motion/react';\n\nimport { getStrictContext } from '@/lib/get-strict-context';\nimport { useControlledState } from '@/hooks/use-controlled-state';\n\ntype SwitchContextType = {\n  isChecked: boolean;\n  setIsChecked: SwitchProps['onCheckedChange'];\n  isPressed: boolean;\n  setIsPressed: (isPressed: boolean) => void;\n};\n\nconst [SwitchProvider, useSwitch] =\n  getStrictContext<SwitchContextType>('SwitchContext');\n\ntype SwitchProps = Omit<\n  React.ComponentProps<typeof SwitchPrimitives.Root>,\n  'render'\n> &\n  HTMLMotionProps<'button'>;\n\nfunction Switch({\n  name,\n  defaultChecked,\n  checked,\n  onCheckedChange,\n  nativeButton,\n  disabled,\n  readOnly,\n  required,\n  inputRef,\n  id,\n  ...props\n}: SwitchProps) {\n  const [isPressed, setIsPressed] = React.useState(false);\n  const [isChecked, setIsChecked] = useControlledState({\n    value: checked,\n    defaultValue: defaultChecked,\n    onChange: onCheckedChange,\n  });\n\n  return (\n    <SwitchProvider\n      value={{ isChecked, setIsChecked, isPressed, setIsPressed }}\n    >\n      <SwitchPrimitives.Root\n        name={name}\n        defaultChecked={defaultChecked}\n        checked={checked}\n        onCheckedChange={setIsChecked}\n        nativeButton={nativeButton}\n        disabled={disabled}\n        readOnly={readOnly}\n        required={required}\n        inputRef={inputRef}\n        id={id}\n        render={\n          <motion.button\n            data-slot=\"switch\"\n            whileTap=\"tap\"\n            initial={false}\n            onTapStart={() => setIsPressed(true)}\n            onTapCancel={() => setIsPressed(false)}\n            onTap={() => setIsPressed(false)}\n            {...props}\n          />\n        }\n      />\n    </SwitchProvider>\n  );\n}\n\ntype SwitchThumbProps = Omit<\n  React.ComponentProps<typeof SwitchPrimitives.Thumb>,\n  'render'\n> &\n  HTMLMotionProps<'div'> & {\n    pressedAnimation?:\n      | TargetAndTransition\n      | VariantLabels\n      | boolean\n      | LegacyAnimationControls;\n  };\n\nfunction SwitchThumb({\n  pressedAnimation,\n  transition = { type: 'spring', stiffness: 300, damping: 25 },\n  ...props\n}: SwitchThumbProps) {\n  const { isPressed } = useSwitch();\n\n  return (\n    <SwitchPrimitives.Thumb\n      render={\n        <motion.div\n          data-slot=\"switch-thumb\"\n          whileTap=\"tab\"\n          layout\n          transition={transition}\n          animate={isPressed ? pressedAnimation : undefined}\n          {...props}\n        />\n      }\n    />\n  );\n}\n\ntype SwitchIconPosition = 'left' | 'right' | 'thumb';\n\ntype SwitchIconProps = HTMLMotionProps<'div'> & {\n  position: SwitchIconPosition;\n};\n\nfunction SwitchIcon({\n  position,\n  transition = { type: 'spring', bounce: 0 },\n  ...props\n}: SwitchIconProps) {\n  const { isChecked } = useSwitch();\n\n  const isAnimated = React.useMemo(() => {\n    if (position === 'right') return !isChecked;\n    if (position === 'left') return isChecked;\n    if (position === 'thumb') return true;\n    return false;\n  }, [position, isChecked]);\n\n  return (\n    <motion.div\n      data-slot={`switch-${position}-icon`}\n      animate={isAnimated ? { scale: 1, opacity: 1 } : { scale: 0, opacity: 0 }}\n      transition={transition}\n      {...props}\n    />\n  );\n}\n\nexport {\n  Switch,\n  SwitchThumb,\n  SwitchIcon,\n  useSwitch,\n  type SwitchProps,\n  type SwitchThumbProps,\n  type SwitchIconProps,\n  type SwitchIconPosition,\n  type SwitchContextType,\n};\n",
      "type": "registry:ui",
      "target": "components/animate-ui/primitives/base/switch.tsx"
    }
  ],
  "type": "registry:ui"
}