source: my-react-app/src/components/StarRating.js

main
Last change on this file was e48199a, checked in by Aleksandar Panovski <apano77@…>, 10 days ago

Final version for DB

  • Property mode set to 100644
File size: 730 bytes
Line 
1import React from 'react';
2
3const StarRating = ({ rating }) => {
4 const normalizedRating = Math.min(Math.max(0, rating), 5);
5 const filledStars = Math.floor(normalizedRating);
6 const hasHalfStar = normalizedRating - filledStars >= 0.5;
7
8 return (
9 <div>
10 {[...Array(filledStars)].map((_, index) => (
11 <span key={`filled-${index}`} className="star">&#9733;</span>
12 ))}
13
14 {hasHalfStar && <span className="star half">&#9733;</span>}
15
16 {[...Array(5 - filledStars - (hasHalfStar ? 1 : 0))].map((_, index) => (
17 <span key={`empty-${index}`} className="star">&#9734;</span>
18 ))}
19 </div>
20 );
21};
22
23export default StarRating;
24
Note: See TracBrowser for help on using the repository browser.