DitherCharts

Radio cards

Updated

RadioCards is a radio group drawn as cards, for a choice that needs a line of detail, like a plan or a data region. The native radios keep arrow-key moves and form values; hover casts the dithered shadow and the checked card keeps it under a heavier frame, or with variant="solid" fills with ink or a checkedColor of your own. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

Data region
Billing
Density
import "@/components/dithercharts/controls.css"
import { RadioCards } from "@/components/dithercharts/radio-cards"

<RadioCards
  legend="Data region"
  name="region"
  defaultValue="us-east"
  onValueChange={(region) => setRegion(region)}
  options={[
    { value: "us-east", label: "US East", description: "Virginia, lowest latency for the Americas" },
    { value: "eu-west", label: "EU West", description: "Ireland, keeps data in the EU" },
  ]}
/>

// Fill the checked card instead of doubling its frame, in ink or any CSS color.
<RadioCards legend="Billing" variant="solid" checkedColor="#2f6fde" options={billing} />

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 radio-cards

Props

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

RadioCards props
PropTypeDefaultDescription
legendrequiredType ReactNodeDefault –The group's caption, read before its cards.
optionsrequiredType readonly RadioCardOption[]Default –
valueType stringDefault –The checked card's value, for a controlled group; pair it with onValueChange.
defaultValueType stringDefault –The card checked at first, for an uncontrolled group.
onValueChangeType (value: string) => voidDefault –
nameType stringDefault a generated idThe radios' form field name.
disabledType booleanDefault falseDisables every card.
variantType "outline" | "solid"Default "outline"How the checked card stands out: "outline" doubles its frame, "solid" fills it and turns its text paper.
checkedColorType stringDefault –The checked card's fill in the "solid" variant, as any CSS color. Default the ink color, with paper text. A color of your own gets white text in both themes; for a light fill, set --dc-radio-card-on-fill to a dark color.
classNameType stringDefault –