Ravox KitForms

Toggle

A button that stays pressed (aria-pressed): bold, pin, mute. When pressed, it fills with the text color. A hidden checkbox next to it carries name, value and ref, so it works in a plain form and with React Hook Form's register().

Settings

Variante
Tamanho
Conteúdo
Toggles

Examples

Controlled, with the icon swapping

Style bar with React Hook Form

Plain form

Ghost and outline

Installation

The command creates components/ui/toggle.tsx in your project and installs the theme with it. The file is yours: edit it as you like.

npx @ravox-ui/cli add toggle

Props

PropTypeDefaultDescription
pressedboolean—Current state (controlled mode).
defaultPressedbooleanfalsePressed at the start (uncontrolled mode).
onPressedChange(pressed: boolean) => void—Called when it toggles.
variant"ghost" | "outline""ghost"Without a border (toolbars) or with a border (standing alone).
size"sm" | "md" | "lg" | "icon" | "icon-sm""md"The icon sizes are square: give them an aria-label.
name / valuestring—When pressed, the form receives the value (or "on"); when released, nothing.
ref / onChange / onBlurdo checkbox escondido—What register() uses: {...register("bold")} returns true/false.
buttonRefRef<HTMLButtonElement>—Ref of the visible <button>.
...propsComponentProps<"button">—The rest goes to the <button> (aria-label, onClick, disabled).

More in Forms