import cx from "classnames"; import React from "react"; import { Icon } from "../Icon"; import type { IconSize } from "../Icon/Icon"; export interface StarRatingProps extends Omit, "children"> { /** Extra class name for root element. */ className?: string; /** Rating value. Rounded to nearest whole star. */ rating: number; /** Icon size for each star. */ size?: IconSize; } const CLASS_ROOT = "star-rating"; const STAR_COUNT = 5; const FILLED_ICON_NAME = "star-favourite"; const EMPTY_ICON_NAME = "star-empty-thin"; const clampRating = (rating: number) => Math.max(0, Math.min(Math.round(rating), STAR_COUNT)); const StarRating: React.FC = ({ className, rating, size, ...other }) => { const filledStars = clampRating(rating); return ( {Array.from({ length: STAR_COUNT }, (_, index) => { const isFilled = index < filledStars; return ( ); })} ); }; StarRating.displayName = "StarRating"; export { StarRating };