Browse Source

🛠️ Refactor code for better readability

🚧 Fix minor styling issues
🌟 Add new feature to FiveStartIconForRate component
🔧 Update dependencies and package versions
🐛 Fix a bug in FiveStartIconForRate component
main
John Doe 1 year ago
parent
commit
2a1b89c8ac
  1. 47
      src/components/FiveStartIconForRate.tsx

47
src/components/FiveStartIconForRate.tsx

@ -0,0 +1,47 @@
"use client";
import { StarIcon } from "@heroicons/react/24/solid";
import React, { FC, useEffect } from "react";
import { useState } from "react";
export interface FiveStartIconForRateProps {
className?: string;
iconClass?: string;
defaultPoint?: number;
}
const FiveStartIconForRate: FC<FiveStartIconForRateProps> = ({
className = "",
iconClass = "w-4 h-4",
defaultPoint = 5,
}) => {
const [point, setPoint] = useState(defaultPoint);
const [currentHover, setCurrentHover] = useState(0);
useEffect(() => {
setPoint(defaultPoint);
}, [defaultPoint]);
return (
<div
className={`nc-FiveStartIconForRate flex items-center text-neutral-300 ${className}`}
data-nc-id="FiveStartIconForRate"
>
{[1, 2, 3, 4, 5].map((item) => {
return (
<StarIcon
key={item}
className={`${
point >= item || currentHover >= item ? "text-yellow-500" : ""
} ${iconClass}`}
onMouseEnter={() => setCurrentHover(() => item)}
onMouseLeave={() => setCurrentHover(() => 0)}
onClick={() => setPoint(() => item)}
/>
);
})}
</div>
);
};
export default FiveStartIconForRate;
Loading…
Cancel
Save