Officina UI
Components

Rating

Star rating input with half-step precision and read-only mode.

Rating captures or displays a star score. When onChange is provided it is an interactive, keyboard-adjustable input (arrow keys step by precision); set readOnly to render it as a static score display. Use precision of 1 for whole stars or 0.5 for half steps, and size the stars with size ('sm' | 'md' | 'lg').

Example

Preview
import { Rating } from '@officina/ui';
import { useState } from 'react';

function ReviewStars() {
  const [value, setValue] = useState(3);
  return (
    <>
      <Rating value={value} onChange={setValue} precision={0.5} />
      <Rating value={4} readOnly size="sm" />
    </>
  );
}

API

PropTypeDefaultDescription
value*number—Current rating value.
invalidboolean—Marks the field invalid for validation styling and `aria-invalid`.
labelstringRatingAccessible label for the rating group.
maxnumber5Number of stars. Defaults to 5.
onChange(value: number) => void—Called with the chosen value; omit for a read-only display.
precisionenum1Selectable granularity: whole or half stars.
readOnlyboolean—Render as a non-interactive display.
sizeenummdStar size.

On this page