6.1 Building a Star Rating Component: fill functions required by StarRating component
parent
d38c22ac87
commit
09b754eddc
|
@ -14,7 +14,7 @@ export default function Menu({ recipes }) {
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<StarRating />
|
<StarRating totalStars={10}/>
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FaStar } from "react-icons/fa";
|
import { FaStar } from "react-icons/fa";
|
||||||
|
|
||||||
export default function StarRating() {
|
export default function StarRating({ totalStars = 5 }) {
|
||||||
return [
|
return createArray(totalStars).map((n, i) => <Star key={i} />);
|
||||||
<FaStar color="red" />,
|
}
|
||||||
<FaStar color="red" />,
|
|
||||||
<FaStar color="red" />,
|
const Star = ({ selected = false }) => (
|
||||||
<FaStar color="grey" />,
|
<FaStar color={selected ? "red" : "grey"} />
|
||||||
<FaStar color="grey" />
|
)
|
||||||
];
|
|
||||||
}
|
const createArray = length => [...Array(length)];
|
Loading…
Reference in New Issue