Rating
A standalone star-rating component for both input and display. Supports controlled and uncontrolled usage, half-star precision, a read-only display mode, custom icons, and full keyboard accessibility as a radiogroup.
Installation
Install via CLI
npx @moontra/moonui-cli add ratingUsage
Examples
Interactive Rating
A controlled star rating. Click a star to set the value, or focus it and use the arrow keys. The selected value is stored in state and reflected below.
You rated 3 out of 5
Read-Only Display
Set readOnly to render the rating as a non-interactive display — perfect for showing an average score next to a label.
Half-Star Precision
With precision="half", each star is split into two selectable halves so users can pick values in 0.5 increments.
Current value: 3.5
Sizes
Three preset sizes — sm, md, and lg — control the icon dimensions and the gap between stars.
Custom Icon
Pass any React element to the icon prop to replace the default star. The component clones it and applies fill-current for the filled portion — here with a lucide Heart.
4 out of 5 hearts