"use client"; import { IconStar, IconStarFilled } from "@tabler/icons-react"; import { motion } from "motion/react"; import { useState } from "react"; interface StarRatingProps { value: number; onChange: (value: number) => void; } export function StarRating({ value, onChange }: StarRatingProps) { const [hover, setHover] = useState(0); return (
setHover(0)} > {[1, 2, 3, 4, 5].map((star) => { const filled = star <= (hover || value); return ( onChange(star === value ? 0 : star)} onMouseEnter={() => setHover(star)} className="p-0.5" whileHover={{ scale: 1.15 }} whileTap={{ scale: 0.9 }} animate={ filled && star === value ? { scale: [1, 1.25, 1] } : { scale: 1 } } transition={{ type: "spring" as const, stiffness: 400, damping: 15, }} > {filled ? ( ) : ( )} ); })}
); }