DitherCharts

Toggle

Updated

Toggle is a single on/off button, drawn like one toggle-group segment: muted when off, solid ink when on. It reports its state with aria-pressed. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

import "@/components/dithercharts/controls.css"
import { Toggle } from "@/components/dithercharts/toggle"

<Toggle defaultPressed>Grid</Toggle>
<Toggle pressed={labels} onPressedChange={setLabels}>Labels</Toggle>
<Toggle size="sm">Legend</Toggle>
<Toggle disabled>Locked</Toggle>

Install

Controls install with DitherCharts Pro. See Installation to log in, then import controls.css once, e.g. in your root layout.

npx dithercharts add toggle

Props

It renders a native element, so every other attribute that element takes passes through.

Toggle props
PropTypeDefaultDescription
pressedType booleanDefault –Whether it's on, for a controlled toggle; pair it with onPressedChange.
defaultPressedType booleanDefault falseWhether it starts on, for an uncontrolled toggle.
onPressedChangeType (pressed: boolean) => voidDefault –
sizeType "sm" | "md"Default "md" (40px, or 32px for "sm")The toggle's height.