import React, { useState } from "react"; import Stack, { StackProps } from "./Stack"; import classNames from "./lib/classNames"; import { StarIcon } from "@heroicons/react/solid"; export interface CustomRatingProps { onChangeValue?: (value: number) => void; size?: "small" | "default" | "large"; amountOfStars?: number; value?: number; } export interface RatingProps extends StackProps, CustomRatingProps {} export default function Rating({ amountOfStars = 5, size = "default", onChangeValue, value = 0, className, ...rest }: RatingProps) { const [hovering, setHovering] = useState(); const numbers = Array.from(Array(amountOfStars).keys()); return ( { setHovering(undefined); }} {...rest} className={classNames("!gap-0", className)} > {numbers.map((n) => { const highlighted = typeof hovering === "number" ? n < hovering + 1 : n < value; const isFirst = !n; const isLast = n === numbers.length - 1; return ( ); })} ); }