DitherCharts

Toggle group

Updated

ToggleGroup is a segmented control: joined ink segments over native radios, or checkboxes when several can be on. Chosen segments go solid, and arrow keys move a single choice. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

Range
Series
import "@/components/dithercharts/controls.css"
import { ToggleGroup } from "@/components/dithercharts/toggle-group"

<ToggleGroup
  label="Range"
  defaultValue={["30d"]}
  options={[
    { value: "7d", label: "7D" },
    { value: "30d", label: "30D" },
    { value: "90d", label: "90D" },
    { value: "1y", label: "1Y", disabled: true },
  ]}
/>
<ToggleGroup
  label="Series"
  multiple
  defaultValue={["revenue", "profit"]}
  options={[
    { value: "revenue", label: "Revenue" },
    { value: "costs", label: "Costs" },
    { value: "profit", label: "Profit" },
  ]}
/>

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-group

Props

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

ToggleGroup props
PropTypeDefaultDescription
labelrequiredType ReactNodeDefault –The group's caption, read before its segments.
hideLabelType booleanDefault falseKeeps the caption for screen readers only, e.g. for a range switcher in a chart's header.
optionsrequiredType readonly ToggleOption[]Default –
multipleType booleanDefault falseLets several segments be on at once (checkboxes) instead of exactly one (radios).
valueType readonly string[]Default –The chosen values, for a controlled group; pair it with onValueChange. One at most unless multiple.
defaultValueType readonly string[]Default –The values chosen at first, for an uncontrolled group.
onValueChangeType (value: string[]) => voidDefault –Called with the chosen values, in option order.
nameType stringDefault a generated idThe inputs' form field name.
disabledType booleanDefault falseDisables every segment.
classNameType stringDefault –