Rating
Pick or show a score from 1 to a maximum, as stars.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native elements
- Editable: a radio group (native radios) with arrow-key selection; each star is named "N of M".
- Read-only: role="img" with a text label such as "4 out of 5".
- Styles in one file:
rating.css
Import
import '@monoline/css';
import {Rating} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add rating
Usage
import {Rating} from '@monoline/react';
<Rating aria-label="Rate this page" defaultValue={3} />
Examples
Editable
Read only
Props
RatingProps
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label required | string | – | Names the control, for example "Rate this article". |
value | number | – | The current score (0 to `max`) when controlled. Pair with `onValueChange`. |
defaultValue | number | 0 | The initial score when uncontrolled. Default 0. |
onValueChange | ((value: number) => void) | – | Called with the new score (1 to `max`) when the user picks a star. |
max | number | 5 | Number of stars. Default 5. |
readOnly | boolean | – | Shows the score without letting anyone change it. |
name | string | – | Name of the underlying radio inputs, so the score submits with a native form. A unique name is generated if omitted. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-on] | rating.css |
CSS classes
| Class | Stylesheet |
|---|---|
.rating | rating.css |
.rating-star | rating.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.rating {
border-color: var(--accent);
}
.rating[data-on] {
background: var(--wash);
}
Accessibility
- Editable: a radio group (native radios) with arrow-key selection; each star is named "N of M".
- Read-only: role="img" with a text label such as "4 out of 5".