Switch
Overview
Switch is a design-system component intended for reusable, product-agnostic UI composition.
Import
import { Switch } from "@tesseract-nexus/tesserix-ui"Exports
export { Switch } from './switch'
export type { SwitchProps } from './switch'Props
export interface SwitchProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> {}
const Switch = React.forwardRef<HTMLInputElement, SwitchProps>(
({ className, ...props }, ref) => {
return (
<label className={cn("relative inline-flex cursor-pointer items-center", className)}>
<input
type="checkbox"
className="peer sr-only"
ref={ref}
{...props}
/>
<div className={cn(
"peer h-6 w-11 rounded-full bg-input shadow-sm transition-all duration-200",
"after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:bg-background after:shadow-md after:transition-all after:content-['']",
"peer-checked:bg-primary peer-checked:after:translate-x-5",
"peer-focus-visible:ring-4 peer-focus-visible:ring-ring/20",
"peer-disabled:cursor-not-allowed peer-disabled:opacity-50"
)} />
</label>
)
}
)
Switch.displayName = "Switch"
export { Switch }Variations
No explicit cva variant map found. Variations are primarily structural/compositional for this component.Usage Patterns
Basic
import { Switch } from "@tesseract-nexus/tesserix-ui"
export function Example() {
return <Switch />
}Do / Don’t
Do
// Compose with domain wrappers in product code
<Switch className="w-full" />Don’t
// Avoid one-off hardcoded values that bypass tokens
<Switch className="bg-[#123456] text-[#fafafa] px-[13px]" />Token / Theming Mapping
- Color tokens: —primary, —secondary, —muted, —destructive, —foreground, —background
- Shape tokens: —radius
- Border/input tokens: —border, —input, —ring
- Spacing and typography: Tailwind scale via design-system preset
Interaction Test Checklist
- Interaction: click/keyboard activation for primary paths.
- Focus: visible focus styles and logical tab order.
- Variants: core variants and sizes render correctly.
- Disabled/error states: behavior and ARIA attributes are correct.
- Regression: Storybook visual check for primary states.
Accessibility
- Verify keyboard behavior for all interactive states.
- Ensure labels and semantic roles are present in consuming screens.
- Validate focus treatment and screen-reader output during QA.