Turns one option on or off and stays pressed while on.
import { Toggle } from "@usememos/ui";
import { Pin } from "lucide-react";
<Toggle icon={<Pin />} pressed={pinnedOnly} onPressedChange={setPinnedOnly}>Pinned</Toggle>interface ToggleProps extends BaseToggle.Props {
size?: Size;
variant?: "ghost" | "soft"; // default "ghost", preserving the flat off state
shape?: "default" | "pill"; // default "default"; icon-only pills are circular
icon?: IconElement; // before the label; alone, the toggle is square
}Wraps Base UI's Toggle: pressed, defaultPressed, onPressedChange, disabled, value pass through. Renders a <button aria-pressed>.
- Provide
children, or aniconwitharia-labeland a Tooltip with the same text. - Use it for toolbar formatting and stacking filters ("Pinned", "Has tasks"). A clickable tag filter is a Toggle, not a Badge.
- Inside a ToggleGroup,
valuenames the item in the group's value. - For a setting that saves at once, use Switch. For one choice among several, use a ToggleGroup without
multiple.
- Default (
variant="ghost"): off: flattext-secondary, withhoveron hover. On: awellfill and thetextcolor, with a transparent reserved border; hover keeps that selected fill. Fill and text changes are immediate. Hover never adds a boundary; keyboard focus reusesmu-focus. variant="soft": off useshoverandtext-secondary; hover useswellandtext; on uses the distinctselectedfill andtext, retained on hover. The reserved border stays transparent; focus still usesmu-focus. No applicationdata-pressedcolor rules are needed.shape="pill"usesradius-fulland equal size-row horizontal padding. An icon-only pill is circular. Heights, icon sizes and hit boundaries stay unchanged.- Disabled soft toggles use
text-disabledandwellwhen off; an on toggle keepsselected. Neither responds to hover. - Disabled default toggles:
text-disabled; an on Toggle keeps its well and transparent border. In forced colors an on Toggle uses a system-colored boundary so selection survives when fills disappear. - For emoji, keep the Lucide-only
iconslot empty. Compose a span inchildren, hide the emoji from assistive technology when the control has anaria-label, and use the documented compact reaction picker layout for a square emoji cell. This does not rely on the internal icon-only class. - A label wraps when its row runs out of room; an icon-only toggle never shrinks. A ToggleGroup is at most as wide as its container and grows in height to keep long translated labels readable. Each Toggle keeps its size-row dimensions and hit boundaries for mouse and touch input.