DitherCharts

Rating

Updated

Rating is a row of pixel stars over native radios in a fieldset, so the arrow keys change the rating and a form gets its number. Stars up to the rating are solid ink, and hovering previews one in a dithered fill. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

Chart quality
Locked
import "@/components/dithercharts/controls.css"
import { Rating } from "@/components/dithercharts/rating"

<Rating legend="Chart quality" name="quality" defaultValue={4} onValueChange={(stars) => setQuality(stars)} />
<Rating legend="Effort" max={10} />

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 rating

Props

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

Rating props
PropTypeDefaultDescription
legendrequiredType ReactNodeDefault –The rating's caption, read before its stars.
valueType numberDefault –The chosen rating, 1 to max, for a controlled rating; pair it with onValueChange.
defaultValueType numberDefault –The rating chosen at first, for an uncontrolled rating.
onValueChangeType (value: number) => voidDefault –
maxType numberDefault 5The number of stars.
nameType stringDefault a generated idThe stars' form field name.
disabledType booleanDefault false
classNameType stringDefault –