import { useState } from 'react'; import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; import { IconTwentyStarFilled } from '@/ui/display/icon/components/IconTwentyStarFilled'; const StyledContainer = styled.div` align-items: center; display: flex; `; const StyledRatingIconContainer = styled.div<{ isActive?: boolean }>` color: ${({ isActive, theme }) => isActive ? theme.font.color.secondary : theme.background.quaternary}; display: inline-flex; `; type RatingInputProps = { onChange: (newValue: number) => void; value: number; readonly?: boolean; }; const RATING_LEVELS_NB = 5; export const RatingInput = ({ onChange, value, readonly, }: RatingInputProps) => { const theme = useTheme(); const [hoveredValue, setHoveredValue] = useState(null); const currentValue = hoveredValue ?? value; return ( {Array.from({ length: RATING_LEVELS_NB }, (_, index) => { const rating = index + 1; return ( onChange(rating)} onMouseEnter={readonly ? undefined : () => setHoveredValue(rating)} onMouseLeave={readonly ? undefined : () => setHoveredValue(null)} > ); })} ); };