TWIGS

Switch

A control that allows the user to toggle between checked and unchecked states.

Playground

Installation

Install in any React + Tailwind project:

$npx shadcn@latest add https://twigs.globirdenergy.com.au/r/switch.json

Source

The exact file the registry serves to consumers.

'use client';

import * as React from 'react';
import { Switch as BaseSwitch } from '@base-ui/react/switch';
import { cn } from '@/lib/utils';

// Spec source: Figma "APP Re-design Phase 1" → page "Switch ✅"
function Switch({ className, ...props }: React.ComponentProps<typeof BaseSwitch.Root>) {
  return (
    <BaseSwitch.Root
      data-slot="switch"
      className={cn(
        'peer inline-flex h-7 w-[62px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-xs transition-colors outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50',
        'data-[checked]:bg-primary data-[unchecked]:bg-foreground',
        className,
      )}
      {...props}
    >
      <BaseSwitch.Thumb
        data-slot="switch-thumb"
        className="pointer-events-none block size-6 rounded-full bg-background shadow-sm ring-0 transition-transform data-[checked]:translate-x-[34px] data-[unchecked]:translate-x-0"
      />
    </BaseSwitch.Root>
  );
}

export { Switch };