Skip to main content

Rating

Rating is a controlled rating input. It renders a row of elements (stars by default) that the user clicks to set a value. It supports fractional values (e.g. 2.5 for a half-filled element), size and variant presets, and a display-only mode for showing averages.

When to use

  • Capture a 1–5 (or custom range) score from the user.
  • Display an average or fixed score read-only (readOnly), including half values.

Import

import { Rating } from '@spartanfx/react';

Basic usage

Rating is controlled: hold the value in state and update it from onChange. value and onChange are required.

function Example() {
const [rating, setRating] = React.useState(3);
return <Rating value={rating} onChange={setRating} />;
}

Read-only display

Set readOnly to show a score without hover or click handling — ideal for an average. Fractional values render as partially-filled elements.

<Rating value={4.5} onChange={() => {}} readOnly label="Average rating" />

Range, size, and variant

import { Rating, RatingSize, RatingVariant } from '@spartanfx/react';

<Rating
value={value}
onChange={setValue}
max={10}
size={RatingSize.Large}
variant={RatingVariant.Circle}
inlineLabel
label="Satisfaction"
/>

Key props

PropTypeDefaultNotes
value (required)numberCurrent value; supports decimals like 2.5.
onChange (required)(value) => voidFires on selection; not called when readOnly.
maxnumber5Number of elements.
minnumber1Minimum selectable value.
readOnlybooleanfalseDisplay-only (no hover/click).
sizeRatingSizeMediumElement size preset.
variantRatingVariantStarVisual variant.
label / inlineLabelstring / boolean— / falseOptional label, shown above or inline.
onRenderElement(props) => ReactElementCustom element renderer.

See the full generated reference: Rating API ↗.

See also