import { IconStar, IconStarFilled } from "@components/icons.tsx"; import { useSignal } from "@preact/signals"; import { useState } from "preact/hooks"; export const SmallRating = ( { max = 5, rating }: { max?: number; rating: number }, ) => { return (
{Array.from({ length: max }).map((_, i) => { return ( {(i + 1) <= rating ? : } ); })}
); }; export const Rating = ( props: { max?: number; rating: number }, ) => { const [rating, setRating] = useState(props.rating); const [hover, setHover] = useState(0); const max = useSignal(props.max || 5); return (
{Array.from({ length: max.value }).map((_, i) => { return ( setHover(i + 1)} onClick={() => setRating(i + 1)} > {(i + 1) <= rating || (i + 1) <= hover ? : } ); })}
); };