RatingField

Displays a numeric rating as a row of filled / half / outlined star icons.

Installation

pnpm dlx shadcn@latest add @shadmin/rating-field

Usage

import { RatingField } from '@/components/admin';
 
<RatingField source="rating" />
<RatingField source="rating" max={10} allowHalf />
<RatingField source="rating" countSource="reviewCount" empty="No ratings yet" />

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-Record field to read
maxOptionalnumber5Total stars rendered
allowHalfOptionalbooleanfalseRender half-stars for fractional values
countSourceOptionalstring-Sibling field rendered as (N) next to the stars
emptyOptionalReactNode-Fallback when value is null/undefined
classNameOptionalstring-CSS class on the wrapping <span>
defaultValueOptionalnumber-Default when no record value exists
recordOptionalRecordType-Record to read instead of useRecordContext()

max

Defaults to 5. Set to 10 for 10-star scales.

allowHalf

When true, values like 3.5 render the third and fourth stars as one filled star plus one half-filled star. When false, fractional values are rounded toward zero.

countSource

Reads a sibling field from the same record and renders it in parentheses to the right of the stars.