Atoms / Rating

Rating

Pixel stars, one tab stop that works as a slider. Read-only mode, optional halves.

import { Rating, Star } from "@forgeron/ui";
/01 → Stars
import { Rating } from "@forgeron/ui";
import { useState } from "react";

export default function Stars() {
  const [stars, setStars] = useState<number | null>(3);
  return <Rating label="Quality" value={stars} onChange={setStars} />;
}
/02 → Half and read only
import { Rating } from "@forgeron/ui";

export default function HalfAndReadOnly() {
  return (
    <div style={{ display: "grid", gap: 12 }}>
      <Rating label="Your rating" half defaultValue={3.5} />
      <Rating label="Average" readOnly value={4.5} size={12} />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
labelstring—Names the rating for assistive technology.
value / defaultValuenumber | null—Controlled or not. 0 to max.
onChange(value: number | null) => void—On every change.
maxnumber5How many stars.
halfbooleanfalseA click on the left half gives half a point; arrows move by half.
readOnlyboolean—Shows it as an image, no tab stop.
clearablebooleantrueBackspace and a second click remove it.
sizenumber24A star in px; a multiple of 12 keeps pixels whole.
disabledboolean—Not editable.
classNamestring—Extra classes.