-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRatingComponent.jsx
More file actions
33 lines (29 loc) · 1.1 KB
/
RatingComponent.jsx
File metadata and controls
33 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react';
import StarComponent from "./StarComponent.jsx";
/**
* Component that handles reviews in the form of stars. StarComponent is used for the actual stars.
*/
const RatingComponent = ({ value = 0, onChange, readOnly = false, className = "" }) => {
const handleRating = (starIndex, isLeftHalf) => {
if (readOnly) return;
const newRating = isLeftHalf ? starIndex + 0.5 : starIndex + 1;
onChange(newRating);
};
return (
<div className={`font-kanit flex justify-center items-center bg-transparent ${className}`}>
{/* <div className="flex gap-1 sm:gap-2"> */}
<div className="flex gap-[1px] text-xs leading-none">
{Array.from({ length: 5 }, (_, index) => (
<StarComponent
key={index}
index={index}
rating={value}
onRatingChange={handleRating}
readOnly={readOnly}
/>
))}
</div>
</div>
);
};
export default RatingComponent;