apps/www/content/docs/components/rating.mdx
import { RatingGroup } from "@chakra-ui/react"
<RatingGroup.Root>
<RatingGroup.Label />
<RatingGroup.HiddenInput />
<RatingGroup.Control>
<RatingGroup.Item>
<RatingGroup.ItemIndicator />
</RatingGroup.Item>
</RatingGroup.Control>
</RatingGroup.Root>
:::info
If you prefer a closed component composition, check out the snippet below.
:::
The Rating component also provides a set of shortcuts for common use cases.
This component renders the number of rating items specified in the count prop.
This works:
<RatingGroup.Control>
{Array.from({ length: 5 }).map((_, index) => (
<RatingGroup.Item key={index} index={index + 1}>
<RatingGroup.ItemIndicator />
</RatingGroup.Item>
))}
</RatingGroup.Control>
This might be more concise, if you don't need to customize the rating icons:
<RatingGroup.Control />
Use the size prop to change the size of the rating component.
Use the value and onValueChange prop to control the rating value.
An alternative way to control the rating is to use the RootProvider component
and the useRatingGroup store hook.
This way you can access the rating state and methods from outside the component.
<ExampleTabs name="rating-with-store" />Use the readOnly prop to make the rating component read-only.
Here's an example of how to use rating with react-hook-form.
Use the icon prop to pass a custom icon to the rating component. This will
override the default star icon.
Render the RatingGroup.Label component to provide a human-readable label for
the rating component.
Use the allowHalf prop to allow half-star ratings.
Compose the rating component with emojis.
<ExampleTabs name="rating-emoji" />Use the colorPalette prop to change the color of the rating
Use the rating component to show testimonials.
<ExampleTabs name="rating-in-testimonial" />Here's how to setup the Rating for a closed component composition.
<ExampleCode name="rating-closed-component" />Here's how to use the it
<Rating defaultValue={3} size="sm" />