File tree Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import Header from "@/layouts/header";
6
6
import Home from "@/pages/Home" ;
7
7
import NotFound from "@/pages/404" ;
8
8
import Accordion from "@/pages/accordion/accordion" ;
9
- import RandomColor from "@/pages/RandomColor"
9
+ import RandomColor from "@/pages/RandomColor" ;
10
10
import StarRating from "@/pages/starRating" ;
11
11
12
12
function App ( ) {
@@ -15,10 +15,10 @@ function App() {
15
15
< Header />
16
16
< Routes >
17
17
< Route path = "React-Project" >
18
- < Route index element = { < Home /> } />
18
+ < Route index element = { < Home /> } />
19
19
{ /* Accordion component */ }
20
20
< Route path = "accordion" element = { < Accordion /> } />
21
- { /* Random color generator */ }
21
+ { /* Random color generator */ }
22
22
< Route path = "color-generator" element = { < RandomColor /> } />
23
23
{ /* Star Rating */ }
24
24
< Route path = "star-rating" element = { < StarRating /> } />
Original file line number Diff line number Diff line change 1
- export default function StarRating ( ) {
1
+ import PropTypes from "prop-types" ;
2
+ import { useState } from "react" ;
3
+ import { FaStar } from "react-icons/fa" ; // Correct import for FaStar
4
+
5
+ function StarRating ( { numOfStars = 5 } ) {
6
+ const [ rating , setRating ] = useState ( 0 ) ;
7
+ const [ hover , setHover ] = useState ( 0 ) ;
8
+
9
+ function handleClick ( getCurrentLIndex ) {
10
+ setRating ( getCurrentLIndex )
11
+ }
12
+ function handleMouseEnter ( getCurrentLIndex ) {
13
+ setHover ( getCurrentLIndex )
14
+ }
15
+ function handleMouseLeave ( ) {
16
+ setHover ( rating )
17
+ }
18
+
2
19
return (
3
20
< div
4
- className = { `container flex flex-1 flex-col items-center justify-start gap-8 my-10 w-full h-screen` }
21
+ className = { `container flex flex-1 items-center justify-center gap-8 my-10 w-full h-screen` }
5
22
>
23
+ { [ ...Array ( numOfStars ) ] . map ( ( _ , index ) => {
24
+ index += 1 ;
6
25
26
+ return (
27
+ < FaStar
28
+ key = { index }
29
+ className = { index <= ( hover || rating ) ? 'active text-primary' : 'inactive text-white' }
30
+ onClick = { ( ) => handleClick ( index ) }
31
+ onMouseMove = { ( ) => handleMouseEnter ( index ) }
32
+ onMouseLeave = { ( ) => handleMouseLeave ( index ) }
33
+ size = { 40 }
34
+ />
35
+ ) ;
36
+ } ) }
7
37
</ div >
8
38
) ;
9
39
}
40
+
41
+ StarRating . propTypes = {
42
+ numOfStars : PropTypes . number ,
43
+ } ;
44
+
45
+ export default StarRating
You can’t perform that action at this time.
0 commit comments