Toggle
Overview
Toggle is a design-system component intended for reusable, product-agnostic UI composition.
Import
import { Toggle, toggleVariants } from "@tesseract-nexus/tesserix-ui"Exports
export { Toggle, toggleVariants } from './toggle'
export type { ToggleProps } from './toggle'Props
export interface ToggleProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof toggleVariants> {
pressed?: boolean
onPressedChange?: (pressed: boolean) => void
}Variations
const toggleVariants = cva(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
{
variants: {
variant: {
default: "bg-transparent",
outline:
"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",
},
size: {
default: "h-10 px-3",
sm: "h-9 px-2.5",
lg: "h-11 px-5",
},
},
defaultVariants: {Usage Patterns
Basic
import { Toggle, toggleVariants } from "@tesseract-nexus/tesserix-ui"
export function Example() {
return <Toggle />
}Do / Don’t
Do
// Compose with domain wrappers in product code
<Toggle className="w-full" />Don’t
// Avoid one-off hardcoded values that bypass tokens
<Toggle 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.