Browse components

Rating

import Rating from "@shpaw415/mui-lite/Rating";

Why use it

Rating captures or displays a star score (reviews, satisfaction, difficulty). Use controlled value + onChange for input; readOnly for display-only averages.

  • Half-star steps by default (precision={0.5})
  • Hover preview with a soft glow so users see the score before clicking
  • Built on radio inputs for keyboard and screen-reader support

Demo

Interactive (half-star)

Hover to preview · click to set · default step is ½ star

Value: 2.5

States & sizes
Read-only
Disabled
Whole
Sizes

Example

import { useState } from "react";
import Rating from "@shpaw415/mui-lite/Rating";
import Typography from "@shpaw415/mui-lite/Typography";
 
export function ReviewScore() {
  const [value, setValue] = useState<number | null>(3.5);
  return (
    <>
      {/* Interactive: hover previews fill + glow; click commits */}
      <Rating
        name="review"
        value={value}
        precision={0.5}
        onChange={(_e, v) => setValue(v)}
      />
      <Typography>{value ?? "unset"}</Typography>
 
      {/* Display-only average */}
      <Rating name="avg" value={4.5} precision={0.5} readOnly />
 
      {/* Whole stars only */}
      <Rating name="whole" defaultValue={3} precision={1} />
    </>
  );
}

Props

PropTypeDefault
value / defaultValuenumber | null— / null
maxnumber5
precisionnumber0.5 (half stars)
readOnly / disabledbooleanfalse
sizesmall | medium | largemedium
onChange(e, value) => void
onChangeActive(e, value) => voidhover/focus preview
icon / emptyIconReactNodedefault stars
getLabelText(value) => string"N Stars"