Rating The Rating component provides a way to select a value from a range of values, typically used for feedback on a scale.
Import
import { Rating , RatingParts } from '@cerberus/react'
Usage
The Rating component is an abstracted client component that provides a way to select a value from a range of values. It is used to provide feedback on a scale. The default count is 5, and the default value is 0.
Loading example...
Readonly State
To render the Rating component in a read-only state, you can use the readOnly prop.
Loading example...
Orientation
The Rating component supports two layout orientations for label usage: horizontal, and vertical. The default orientation is vertical.
Loading example...
Sizes
The Rating component supports two sizes: sm, and md. The default size is sm.
Loading example...
Customizing
To customize the Rating component use style props or the Primitive components .
Loading example...
Primitives
You can utilize the primitive components or the css prop to customize the radio.
Component Description RatingRootThe context provider for the Rating parts RatingLabelThe label of the rating RatingControlThe visual control of the rating RatingContextThe context provider for the rating RatingItemThe container of the rating item RatingItemContextThe context provider for a rating item RatingHiddenInputThe native input for the rating
API
Root
Props
Prop Type Required Default Description allowHalfbooleanfalse undefinedWhether to allow half stars. asChildbooleanfalse undefinedUse the provided child element as the default rendered element, combining their props and behavior. autoFocusbooleanfalse undefinedWhether to autofocus the rating. countnumberfalse 5The total number of ratings. defaultValuenumberfalse undefinedThe initial value of the rating when rendered. Use when you don't need to control the value of the rating. disabledbooleanfalse undefinedWhether the rating is disabled. formstringfalse undefinedThe associate form of the underlying input element. idstringfalse undefinedThe unique identifier of the machine. idsPartial<{ root: string, label: string, hiddenInput: string, control: string, item: (id: string) => string }>false undefinedThe ids of the elements in the rating. Useful for composition. namestringfalse undefinedThe name attribute of the rating element (used in forms). onHoverChange(details: HoverChangeDetails) => voidfalse undefinedFunction to be called when the rating value is hovered. onValueChange(details: ValueChangeDetails) => voidfalse undefinedFunction to be called when the rating value changes. readOnlybooleanfalse undefinedWhether the rating is readonly. requiredbooleanfalse undefinedWhether the rating is required. translationsIntlTranslationsfalse undefinedSpecifies the localized strings that identifies the accessibility elements and their states valuenumberfalse undefinedThe controlled value of the rating
Control
Props
Prop Type Required Default Description asChildbooleanfalse undefinedUse the provided child element as the default rendered element, combining their props and behavior.
Data Attributes
Attribute Description / Value data-scoperating-group data-partcontrol data-readonlyPresent when read-only data-disabledPresent when disabled
HiddenInput
Props
Prop Type Required Default Description asChildbooleanfalse undefinedUse the provided child element as the default rendered element, combining their props and behavior.
Item
Props
Prop Type Required Default Description indexnumbertrue undefinedundefined asChildbooleanfalse undefinedUse the provided child element as the default rendered element, combining their props and behavior.
Data Attributes
Attribute Description / Value data-scoperating-group data-partitem data-disabledPresent when disabled data-readonlyPresent when read-only data-checkedPresent when checked data-highlightedPresent when highlighted data-half
Label
Props
Prop Type Required Default Description asChildbooleanfalse undefinedUse the provided child element as the default rendered element, combining their props and behavior.
Data Attributes
Attribute Description / Value data-scoperating-group data-partlabel data-disabledPresent when disabled data-requiredPresent when required
RootProvider
Props
Prop Type Required Default Description valueUseRatingGroupReturntrue undefinedundefined asChildbooleanfalse undefinedUse the provided child element as the default rendered element, combining their props and behavior.
Context
API:
Property Type Description setValue(value: number) => voidSets the value of the rating group clearValueVoidFunctionClears the value of the rating group hoveringbooleanWhether the rating group is being hovered valuenumberThe current value of the rating group hoveredValuenumberThe value of the currently hovered rating countnumberThe total number of ratings itemsnumber[]The array of rating values. Returns an array of numbers from 1 to the max value. getItemState(props: ItemProps) => ItemStateReturns the state of a rating item
Accessibility
Keyboard Support
Key Description ArrowRightMoves focus to the next star, increasing the rating value based on the allowHalf property. ArrowLeftMoves focus to the previous star, decreasing the rating value based on the allowHalf property. EnterSelects the focused star in the rating group.