Lynx/Modules/DaisyUI/RatingAlso available onWebNative
@sigx/lynx-daisyui · Stable · Component library

Rating#

A tap-to-set star rating, with two-way model binding, color and size ramps, a read-only display mode, a custom max, and optional half-step precision.

Import#

TSX
import { Rating } from '@sigx/lynx-daisyui';

Overview#

Rating renders a row of star glyphs; tapping a star sets the value to its 1-based index. Bind it two-way with model (the sigx way), or drive it as a controlled component with the static value prop plus the onChange event. Set readOnly to show a score without accepting taps, and allowHalf to allow half-star values (tapping the left or right half of a star sets i - 0.5 or i).

Props#

PropTypeDefaultDescription
modelModel<number>-Two-way binding to a signal number. Pass an accessor (e.g. () => state.stars) so taps flow back into your state.
valuenumber0Controlled value when no model is bound. A star is filled when its index is <= value.
maxnumber5Number of stars.
colorRatingColor-Fill color. One of primary, secondary, accent, info, success, warning, error.
size'xs' | 'sm' | 'md' | 'lg''md'Star size.
readOnlybooleanfalseDisplay mode — taps are ignored. Use for showing an average.
allowHalfbooleanfalseAllow 0.5 increments; each star can render a left-half fill. Tapping the left/right half of a star sets i - 0.5 / i.
classstring-Additional CSS classes appended to the root.

Events#

EventTypeDescription
onChange(value: number) => voidFired on tap with the new value (a 0.5 increment when allowHalf is set). Use this for the controlled (no-model) case.

Basic usage#

Bind a signal with model; tapping a star updates it:

TSX
import { component, signal } from '@sigx/lynx';
import { Col, Rating, Text } from '@sigx/lynx-daisyui';

const Stars = component(() => {
  const stars = signal(3);
  return () => (
    <Col gap={8}>
      <Rating model={() => stars.value} />
      <Text class="opacity-60">value: {stars.value}</Text>
    </Col>
  );
});

Half steps#

Set allowHalf for half-star precision — useful for showing and capturing fractional scores:

TSX
import { component, signal } from '@sigx/lynx';
import { Col, Rating, Text } from '@sigx/lynx-daisyui';

const HalfSteps = component(() => {
  const half = signal(2.5);
  return () => (
    <Col gap={8}>
      <Rating model={() => half.value} allowHalf size="lg" />
      <Text class="opacity-60">value: {half.value}</Text>
    </Col>
  );
});

Read-only and custom max#

Use readOnly to display an average (combine with allowHalf for fractional scores), and max for a different number of stars:

TSX
import { component } from '@sigx/lynx';
import { Col, Rating } from '@sigx/lynx-daisyui';

const Display = component(() => () => (
  <Col gap={8}>
    <Rating value={4} readOnly color="warning" />
    <Rating value={3.5} allowHalf readOnly />
    <Rating value={7} max={10} color="primary" size="sm" />
  </Col>
));