Interactive Star Rating Component
At Nykaa, product reviews and ratings are central to our user experience, helping customers make informed purchasing decisions and boosting product discoverability. A highly interactive and visually appealing star rating component is crucial for empowering users to easily provide feedback and for displaying product sentiment effectively.
Your task is to build a reusable StarRating React component that supports displaying and interacting with star ratings, including half-star precision.
rating prop (a number, e.g., 3.7) and visually represent it using a set of stars.onChange callback with the newly selected rating.readOnly boolean prop. When true, it should display the rating without any interactive capabilities.rating prop. A half-filled star should be clearly distinguishable.StarRating component renders correctly, displaying 5 stars, with the fill accurately representing the rating prop (e.g., 0, 2.5, 4.7, 5).readOnly={false}), hovering over different parts of the stars correctly updates the visual preview for potential selection, including half-star increments.onChange callback with the new rating.readOnly={true}, the component displays the rating prop without any hover effects, click interactions, or keyboard navigation.aria-label attributes are used for accessibility.Constraints
rating prop can be a floating-point number.rating) is managed by its parent via props.Loading editor...