Kanzo UI
Forms

Rating

Rate something on a fixed scale of stars.

Ark UI

Usage

import {
  Rating,
  RatingContext,
  RatingControl,
  RatingItem,
} from "@kanzo-tech/ui";
<Rating count={5} defaultValue={3}>
  <RatingControl>
    <RatingContext>
      {(api) =>
        api.items.map((index) => <RatingItem index={index} key={index} />)
      }
    </RatingContext>
  </RatingControl>
</Rating>

Anatomy

Rating
├── RatingLabel
├── RatingControl
│   └── RatingContext        renders one star per item
│       └── RatingItem
└── RatingHiddenInput

API Reference

Rating

No props of its own — the API is the machine's:

PropTypeDefault
countnumber5
valuenumber
defaultValuenumber-1
onValueChange(details) => void
allowHalfbooleanfalse
readOnlybooleanfalse
disabledbooleanfalse
requiredbooleanfalse

Extends React.ComponentProps<typeof ArkRatingGroup.Root>, so name, form, onHoverChange, ref and every native prop pass through. Control it with value + onValueChange, or leave it uncontrolled with defaultValue. There is no invalid on this machine; the recipe still styles data-invalid for a Field that sets it.

RatingItem

PropTypeDefault
indexnumber
childrenReact.ReactNodetwo stacked StarIcons

The default star reads data-highlighted to fill and data-half (from allowHalf) to clip itself in half. Pass children to swap the glyph and keep the machine's wiring.

Other parts

RatingLabel renders Ark's RatingGroup.Label inside a FieldLabel; RatingControl and RatingHiddenInput take their Ark part's props. RatingContext is Ark's RatingGroup.Context render prop — iterate api.items with it. useRating re-exports useRatingGroupContext.

On this page