import React, { useEffect, useState } from "react"; import "./StarRating.scss"; const StarRating = ({ countStars = 1, countActiveStars = 1, color = "#52B709", size = 61, }) => { const [shadedStars, setShadedStars] = useState([]); const [noShadedStars, setNoShadedStars] = useState([]); const percent = Math.abs(countActiveStars) >= countStars ? 100 : (countActiveStars * 100) / countStars; useEffect(() => { for (let index = 0; index < countStars; index++) { setShadedStars((prev) => [...prev, "★"]); setNoShadedStars((prev) => [...prev, "☆"]); } }, []); const ratingStyle = { "--size": size + "px", }; const activeStyle = { "--width": percent + "%", "--color": color, "--content": shadedStars.join(""), }; const bodyStyle = { "--content": noShadedStars.join(""), "--color": color, }; return (
); }; export default React.memo(StarRating);