4.2.0
Core

Toggle

A button that stays pressed — bold on, a filter active — for a state held in a toolbar rather than a setting on a form.

Toggle

Press to hold one boolean setting — bold on, bold off. The pressed fill is `bg-brand-soft` with a `border-brand/40`, the low-weight accent `Button`'s `secondary` variant already uses; upstream's `data-[state=on]:bg-accent` is unaliased here and would have painted nothing.

Usage

import { Toggle } from '@oceanic-hub/brand-system'

Reach for it when pressing IS the setting: bold on, a filter active, a view pinned. A plain Button fires an action and forgets it happened; a Toggle remembers, which is the whole difference — if the control needs to look different a second later because of what you did to it the first time, it is a toggle.

The moment a press should matter relative to its neighbours — a mutually-exclusive set of views, an independent multi-select in one toolbar — stop reaching for several Toggles side by side and use ToggleGroup instead. It shares this component's pressed-state styling through context, so the two can never disagree about what "on" looks like, and it is where type and the roving selection live. A lone Toggle has no relationship to any other on the page; that is what makes it the lone one.

pressed / onPressedChange make it controlled; defaultPressed is first-class for the common uncontrolled case. asChild is inherited from Radix rather than added, and it comes with a caveat the type cannot carry: the pressed state lives in aria-pressed, which is only meaningful on a button-role element — swapping in an <a> produces a link that claims a pressed state it cannot own.

The pressed fill is not upstream's. data-[state=on]:bg-accent is unaliased in this package and would paint nothing — a toggle that looks identical pressed and unpressed, on a green build. Pressed here is bg-brand-soft with a border-brand/40, the same low-weight accent Button's secondary variant already uses. Sizes are this package's own scale too — sm/md/lg are 32/40/48px, matching Button's heights, not upstream's own numbers, so a toggle sits flush next to a same-size button in one toolbar.

RTL is not supported. Nothing in this package has ever been laid out or measured right-to-left; the refusal is recorded once, in pairings.json under direction, rather than advertising support here that was never tested.

Upstream's With Text example (an icon and a label sharing one toggle) is not a separate demo here: Toggle accepts any children, so pairing an icon with text needs nothing beyond what Button's equivalent demo already shows the same way.

Outline

Bordered, no shadow — core-layer.md's elevation is a 1px border, and upstream's shadow-sm is refused rather than replaced. Reach for it over a filled surface, where the default variant's transparent rest state would be invisible until pressed.

Sizes

sm / md / lg are 32 / 40 / 48px, matching Button's own height scale rather than upstream's numbers — so a toggle sits flush next to a same-size button in one toolbar. There is no xs: 24px sits below the 32px touch floor this scale is pinned to.

Disabled

disabled fades the control and drops pointer events on both states. Reach for it when a setting is temporarily out of the reader's control — a plan-gated feature, a field locked by another user's edit — not for a setting that should simply not be offered.

Pill

shape="pill" is default's colours in a rounded-pill corner — its own axis, not a new selected-state vocabulary. Reach for it inside a ToggleGroup standing in for a pill-styled tab row; a lone pill Toggle has no relationship to any other on the page and the shape signals a grouping that does not exist.

API Reference

See the Toggle API page for every prop of every part, with types, defaults and the contract that pins them. It also documents toggleVariants — exported alongside the parts, and signatures rather than props.

On this page