{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "switch",
  "type": "registry:ui",
  "title": "Switch",
  "description": "Switch is a binary toggle control — use it for settings that take immediate effect without a confirmation step.",
  "dependencies": [
    "@radix-ui/react-label@^2.1.8",
    "@radix-ui/react-switch@^1.2.6",
    "class-variance-authority@^0.7.1"
  ],
  "registryDependencies": [
    "https://wideset.co/r/motion.json",
    "https://wideset.co/r/styles.json",
    "https://wideset.co/r/utils.json"
  ],
  "files": [
    {
      "path": "src/components/switch/Switch.context.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/switch/Switch.context.ts",
      "content": "'use client';\n\nimport { createContext, useContext } from 'react';\n\nimport type { SwitchContextType } from './Switch.types';\n\nexport const SwitchContext = createContext<SwitchContextType | undefined>(undefined);\n\nexport const useSwitchContext = () => {\n  const context = useContext(SwitchContext);\n\n  if (context === undefined) {\n    throw new Error('useSwitchContext must be used within a <Switch>');\n  }\n\n  return context;\n};\n"
    },
    {
      "path": "src/components/switch/Switch.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/switch/Switch.tsx",
      "content": "'use client';\n\nimport * as Label from '@radix-ui/react-label';\nimport * as SwitchPrimitive from '@radix-ui/react-switch';\nimport React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { useDefaultMotion } from '@/lib/wideset/motion/MotionProvider';\nimport { SwitchContext } from './Switch.context';\nimport type { SwitchProps, SwitchWithVariants } from './Switch.types';\nimport {\n  switchMotionVariants,\n  switchThumbMotionVariants,\n  switchThumbVariants,\n  switchVariants,\n} from './Switch.variants';\nimport { SwitchLabel } from './SwitchLabel';\n\nconst Switch = React.forwardRef<React.ComponentRef<typeof SwitchPrimitive.Root>, SwitchProps>(\n  (\n    {\n      id,\n      label,\n      labelPosition = 'right',\n      size = 'lg',\n      className,\n      disabled,\n      defaultMotion,\n      children,\n      ...props\n    },\n    ref,\n  ) => {\n    const fallbackId = React.useId();\n    const motion = useDefaultMotion(defaultMotion);\n    const switchId = id || fallbackId;\n\n    const containerClassName = cn(\n      'gap-ws-7 flex w-fit items-center',\n      {\n        'flex-row-reverse': labelPosition === 'left',\n        'cursor-pointer': !disabled,\n        'pointer-events-none': disabled,\n      },\n      className,\n    );\n\n    const switchRoot = (\n      <SwitchPrimitive.Root\n        ref={ref}\n        className={cn(switchVariants({ size }), switchMotionVariants({ enabled: motion }))}\n        id={switchId}\n        disabled={disabled}\n        data-slot=\"switch\"\n        {...props}\n      >\n        <SwitchPrimitive.Thumb\n          className={cn(\n            switchThumbVariants({ size }),\n            switchThumbMotionVariants({ enabled: motion, size }),\n          )}\n        />\n      </SwitchPrimitive.Root>\n    );\n\n    return (\n      <SwitchContext.Provider value={{ disabled, id: switchId }}>\n        {label ? (\n          <Label.Root htmlFor={switchId} className={containerClassName}>\n            {switchRoot}\n            <span\n              data-slot=\"switch-label\"\n              className={cn(\n                'typography-label-sm text-ws-dynamic-secondary-default',\n                disabled && 'text-ws-dynamic-secondary-disabled',\n              )}\n            >\n              {label}\n            </span>\n          </Label.Root>\n        ) : (\n          <div className={containerClassName}>\n            {switchRoot}\n            {children && <div className=\"gap-ws-3 flex flex-col\">{children}</div>}\n          </div>\n        )}\n      </SwitchContext.Provider>\n    );\n  },\n) as SwitchWithVariants;\n\nSwitch.displayName = 'Switch';\nSwitch.Label = SwitchLabel;\n\nexport { Switch };\n"
    },
    {
      "path": "src/components/switch/Switch.types.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/switch/Switch.types.ts",
      "content": "import type * as Label from '@radix-ui/react-label';\nimport type * as RadixSwitch from '@radix-ui/react-switch';\nimport type { VariantProps } from 'class-variance-authority';\nimport type React from 'react';\n\nimport type { MotionProps } from '@/lib/wideset/motion/Motion.types';\nimport type { switchVariants } from './Switch.variants';\nimport type { SwitchLabel } from './SwitchLabel';\n\nexport type SwitchContextType = {\n  disabled?: boolean;\n  id?: string;\n};\n\n/** The text label associated with `Switch`. */\nexport type SwitchLabelProps = React.ComponentPropsWithoutRef<typeof Label.Root>;\n\n/** A binary setting that takes effect immediately. */\nexport type SwitchProps = Omit<React.ComponentProps<typeof RadixSwitch.Root>, 'children'> &\n  MotionProps &\n  VariantProps<typeof switchVariants> & {\n    /**\n     * Position of label in accordance to the Switch\n     *\n     * @default 'right'\n     */\n    labelPosition?: 'left' | 'right';\n    /**\n     * Label of the switch\n     */\n    label?: string;\n    /**\n     * Label as children\n     */\n    children?: React.ReactNode;\n  };\n\nexport type SwitchWithVariants = React.ForwardRefExoticComponent<\n  React.PropsWithoutRef<SwitchProps> &\n    React.RefAttributes<React.ComponentRef<typeof RadixSwitch.Root>>\n> & {\n  Label: typeof SwitchLabel;\n};\n"
    },
    {
      "path": "src/components/switch/Switch.variants.ts",
      "type": "registry:ui",
      "target": "components/ui/wideset/switch/Switch.variants.ts",
      "content": "import { cva } from 'class-variance-authority';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { switchThumbTravelMotion, switchTrackMotion } from '@/lib/wideset/motion/recipes';\n\nexport const switchVariants = cva(\n  cn(\n    'group focus-visible:wds-focus-visible focus-visible:outline-ws-dynamic-primary-strong-default relative cursor-pointer focus-visible:select-none disabled:pointer-events-none disabled:cursor-default',\n    'rounded-full',\n    'bg-ws-dynamic-secondary-alpha-strong-default hover:bg-ws-dynamic-secondary-alpha-strong-hover focus-visible:bg-ws-dynamic-secondary-alpha-strong-default active:bg-ws-dynamic-secondary-alpha-strong-pressed disabled:bg-ws-dynamic-secondary-disabled',\n    'radix-state-checked:disabled:bg-ws-dynamic-primary-disabled radix-state-checked:bg-ws-dynamic-primary-default radix-state-checked:hover:bg-ws-dynamic-primary-hover radix-state-checked:active:bg-ws-dynamic-primary-pressed',\n  ),\n  {\n    variants: {\n      size: {\n        sm: 'h-ws-control-sm w-ws-control-xl',\n        lg: 'h-ws-control-md w-ws-control-xxl',\n      },\n    },\n    defaultVariants: {\n      size: 'lg',\n    },\n  },\n);\n\nexport const switchThumbVariants = cva(\n  cn(\n    'absolute top-1/2 left-0 shrink-0 -translate-y-1/2 transform rounded-full',\n    'shadow-ws-medium bg-(--ws-dynamic-text-on-primary-default)',\n    'group-disabled:bg-(--ws-dynamic-text-on-primary-disabled) group-disabled:shadow-none',\n  ),\n  {\n    variants: {\n      size: {\n        sm: cn(\n          'h-ws-control-xs w-ws-control-xs translate-x-(--spacing-ws-2)',\n          'radix-state-checked:translate-x-[calc(100%+var(--spacing-ws-2))]',\n        ),\n        lg: cn(\n          'h-ws-control-sm w-ws-control-sm translate-x-(--spacing-ws-2)',\n          'radix-state-checked:translate-x-[calc(100%-var(--spacing-ws-2))]',\n        ),\n      },\n    },\n    defaultVariants: {\n      size: 'lg',\n    },\n  },\n);\n\nexport const switchMotionVariants = cva('', {\n  variants: {\n    enabled: { true: switchTrackMotion, false: '' },\n  },\n  defaultVariants: { enabled: true },\n});\n\nexport const switchThumbMotionVariants = cva('', {\n  variants: {\n    enabled: { true: switchThumbTravelMotion, false: '' },\n    size: { sm: '', lg: '' },\n  },\n  compoundVariants: [\n    {\n      enabled: true,\n      size: 'sm',\n      className: cn(\n        'group-[:active:not(:disabled)]:h-[calc(var(--spacing-ws-control-xs)*0.75)]',\n        'group-[:active:not(:disabled)]:w-[calc(var(--spacing-ws-control-xs)*1.3)]',\n        'group-[:active:not(:disabled)[data-state=checked]]:translate-x-[calc(100%+var(--spacing-ws-2)-var(--spacing-ws-control-xs)*0.6)]',\n      ),\n    },\n    {\n      enabled: true,\n      size: 'lg',\n      className: cn(\n        'group-[:active:not(:disabled)]:h-[calc(var(--spacing-ws-control-sm)*0.75)]',\n        'group-[:active:not(:disabled)]:w-[calc(var(--spacing-ws-control-sm)*1.3)]',\n        'group-[:active:not(:disabled)[data-state=checked]]:translate-x-[calc(100%-var(--spacing-ws-2)-var(--spacing-ws-control-sm)*0.6)]',\n      ),\n    },\n  ],\n  defaultVariants: { enabled: true, size: 'lg' },\n});\n"
    },
    {
      "path": "src/components/switch/SwitchLabel.tsx",
      "type": "registry:ui",
      "target": "components/ui/wideset/switch/SwitchLabel.tsx",
      "content": "'use client';\n\nimport * as Label from '@radix-ui/react-label';\nimport * as React from 'react';\nimport { cn } from '@/lib/wideset/utils';\n\nimport { useSwitchContext } from './Switch.context';\nimport type { SwitchLabelProps } from './Switch.types';\n\nexport const SwitchLabel = React.forwardRef<HTMLLabelElement, SwitchLabelProps>(\n  ({ children, htmlFor, className, ...props }, ref) => {\n    const { disabled, id } = useSwitchContext();\n\n    return (\n      <Label.Root\n        ref={ref}\n        htmlFor={htmlFor || id}\n        className={cn(\n          'typography-label-sm text-ws-dynamic-secondary-default cursor-pointer',\n          disabled && 'text-ws-dynamic-secondary-disabled pointer-events-none',\n          className,\n        )}\n        data-slot=\"switch-label\"\n        {...props}\n      >\n        {children}\n      </Label.Root>\n    );\n  },\n);\n\nSwitchLabel.displayName = 'Switch.Label';\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "commit": "8bb3627"
  }
}
