Ballmac UI home

Switch

A Radix toggle switch in two sizes with a CSS-animated thumb, for settings that take effect immediately. Stops animating under reduced motion.

Installation

$ pnpm dlx shadcn@latest add @ballmac/switch

Usage

import { Switch } from "@/components/ballmac/switch"

The full example is in the Code tab above.

Examples

Settings rows

A summary of activity every Monday.

Notify me when someone @mentions me.

Occasional emails about new features.

API reference

PropTypeDefault
size"sm" | "default""default"

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
SpaceToggles the switch
EnterToggles the switch
TabMoves focus to the switch

Use with AI

On/off control for settings that apply immediately. Pair with a Label via id/htmlFor; use size="sm" in dense lists. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Switch (@ballmac/switch) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Enabling or disabling a feature or notification
  • Settings pages with labelled rows
  • Toggles inside dense menus or tables (size sm)

Not for

  • Choices submitted later with a form, or agreeing to terms (use checkbox)
  • More than two options (use select)

Registry JSON: https://ui.ballmac.com/r/switch.json

Credits

Based on shadcn/ui Switch, adapted by Ballmac. Free to use in personal and commercial projects.

Registry
shadcn/utils