Skip to content

Commit

Permalink
feat(compositions): add rating
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Jun 19, 2024
1 parent eb94ad2 commit d7226a4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/react/composition/rating.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RatingGroup } from "@chakra-ui/react"
import { forwardRef } from "react"

export interface RatingProps extends RatingGroup.RootProps {
icon?: React.ReactElement
count?: number
}

export const Rating = forwardRef<HTMLDivElement, RatingProps>(
function Rating(props, ref) {
const { icon, count = 5, ...rest } = props
return (
<RatingGroup.Root ref={ref} count={count} {...rest}>
<RatingGroup.Control>
{Array.from({ length: count }).map((_, index) => (
<RatingGroup.Item key={index} index={index + 1}>
<RatingGroup.ItemIndicator icon={icon} />
</RatingGroup.Item>
))}
</RatingGroup.Control>
</RatingGroup.Root>
)
},
)

0 comments on commit d7226a4

Please sign in to comment.