Examples

Rate a stay

Give each star a meaningful name with optionLabel.

Preview
Rate your stay

Choose 1 to 5 stars.

Example.tsx
import { Rating } from '@reactloom/ui';
import { useState } from 'react';

const words = ['', 'Poor', 'Fair', 'Good', 'Very good', 'Excellent'];

export default function Example() {
  const [value, setValue] = useState<number | null>(null);
  return (
    <Rating
      label="Rate your stay"
      description={value ? words[value] : 'Choose 1 to 5 stars.'}
      value={value}
      onValueChange={setValue}
      optionLabel={(n) => `${n} star${n === 1 ? '' : 's'}, ${words[n]}`}
      name="stay-rating"
    />
  );
}

Average rating

readOnly renders an image with a text name.

Preview

4.3 (1,284 reviews)

Example.tsx
import { HStack, Rating, Text } from '@reactloom/ui';

export default function Example() {
  return (
    <HStack gap="2" align="center">
      <Rating readOnly value={4.3} size="sm" valueLabel={(v, max) => `Average rating ${v} out of ${max}`} />
      <Text size="sm" tone="muted">
        4.3 (1,284 reviews)
      </Text>
    </HStack>
  );
}

API reference

Rating props
PropTypeDefault
value / defaultValue
number | null—
onValueChange
(value) => void—
max
Number of stars.
number5
readOnly
Display only; fractional values allowed.
booleanfalse
name
Submitted with forms.
string—
optionLabel
Name of each star.
(n, max) => string`n out of max`
valueLabel
Read-only name.
(value, max) => string`Rated value out of max`
icon
Custom symmetric symbol.
ReactNode—
label
Visible label.
ReactNode—
description · error
Help text and error, linked with aria-describedby.
ReactNode—
hideLabel · required · disabled · size
As on Input.
—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-disabled]present when on
[data-size]sm · md · lg

Theme tokens it reads

--pl-color-fg-muted --pl-color-warning-solid --pl-focus-ring-color --pl-focus-ring-width

Accessibility

  • Each star is a native radio: arrows move and select (wrapping, mirrored right to left) in every browser.
  • Read-only ratings are role="img" with the value in text.
  • Stars use a 3:1 contrast outline in every theme and Highlight in forced colours.
Keyboard interactions
KeyAction
TabMove to the selected star (or the first)
← → ↑ ↓Choose the previous or next value

Usage guidelines

Do

  • Show the number of reviews next to an average.
  • Name the stars when the scale has words (Poor … Excellent).

Don’t

  • Don’t use stars for settings or yes/no choices.