Rating
Pixel stars, one tab stop that works as a slider. Read-only mode, optional halves.
import { Rating, Star } from "@forgeron/ui";import { Rating } from "@forgeron/ui";
import { useState } from "react";
export default function Stars() {
const [stars, setStars] = useState<number | null>(3);
return <Rating label="Quality" value={stars} onChange={setStars} />;
}import { Rating } from "@forgeron/ui";
export default function HalfAndReadOnly() {
return (
<div style={{ display: "grid", gap: 12 }}>
<Rating label="Your rating" half defaultValue={3.5} />
<Rating label="Average" readOnly value={4.5} size={12} />
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the rating for assistive technology. |
value / defaultValue | number | null | — | Controlled or not. 0 to max. |
onChange | (value: number | null) => void | — | On every change. |
max | number | 5 | How many stars. |
half | boolean | false | A click on the left half gives half a point; arrows move by half. |
readOnly | boolean | — | Shows it as an image, no tab stop. |
clearable | boolean | true | Backspace and a second click remove it. |
size | number | 24 | A star in px; a multiple of 12 keeps pixels whole. |
disabled | boolean | — | Not editable. |
className | string | — | Extra classes. |