-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRatingComponent.jsx
More file actions
31 lines (26 loc) · 1023 Bytes
/
RatingComponent.jsx
File metadata and controls
31 lines (26 loc) · 1023 Bytes
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
import React from 'react';
import StarComponent from "./StarComponent.jsx";
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;