diff --git a/src/App.jsx b/src/App.jsx index 37ae72b..58b51bb 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,7 +6,7 @@ import Header from "@/layouts/header"; import Home from "@/pages/Home"; import NotFound from "@/pages/404"; import Accordion from "@/pages/accordion/accordion"; -import RandomColor from "@/pages/RandomColor" +import RandomColor from "@/pages/RandomColor"; import StarRating from "@/pages/starRating"; function App() { @@ -15,10 +15,10 @@ function App() {
- } /> + } /> {/* Accordion component */} } /> - {/* Random color generator */} + {/* Random color generator */} } /> {/* Star Rating */} } /> diff --git a/src/pages/starRating.jsx b/src/pages/starRating.jsx index 49774d8..7c4debe 100644 --- a/src/pages/starRating.jsx +++ b/src/pages/starRating.jsx @@ -1,9 +1,45 @@ -export default function StarRating() { +import PropTypes from "prop-types"; +import { useState } from "react"; +import { FaStar } from "react-icons/fa"; // Correct import for FaStar + +function StarRating({ numOfStars = 5 }) { + const [rating, setRating] = useState(0); + const [hover, setHover] = useState(0); + + function handleClick(getCurrentLIndex) { + setRating(getCurrentLIndex) + } + function handleMouseEnter(getCurrentLIndex) { + setHover(getCurrentLIndex) + } + function handleMouseLeave() { + setHover(rating) + } + return (
+ {[...Array(numOfStars)].map((_, index) => { + index += 1; + return ( + handleClick(index)} + onMouseMove={() => handleMouseEnter(index)} + onMouseLeave={() => handleMouseLeave(index)} + size={40} + /> + ); + })}
); } + +StarRating.propTypes = { + numOfStars: PropTypes.number, +}; + +export default StarRating