Data Entryduskmoonimplemented11 demos

Rate

Rate captures or displays simple rating values.

Import@duskmoon-dev/components/rate
5API sections
15documented props
8behavior scenarios
Key API
valuedefaultValueonChangecountallowHalfallowClear

Usage

When to use

  • Use it inside forms, filters, settings, and any workflow that captures user input.
  • Prefer controlled props when the value must stay synchronized with application state.

Implementation notes

StylesheetImport @duskmoon-dev/components/styles.css once in the app or docs shell.
StateStart with default props for static examples, then switch to controlled props when state must be shared.
ThemeThe preview inherits the active DuskMoon data-theme value from the docs layout.

Features

Controlled and uncontrolled usage

Documents default values, value props, and change callbacks for form integration.

Validation state

Surfaces status, size, disabled, and option data patterns where the component supports them.

Primary API surface

Rate is most often configured through `value`, `defaultValue`, `onChange`, `count`.

Covered behavior

Renders with default classes

Feature Demos

Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.

Preview
primary
★★★★★
secondary
★★★★★
tertiary
★★★★★
accent
★★★★★
neutral
★★★★★
base
★★★★★
info
★★★★★
success
★★★★★
warning
★★★★★
error
★★★★★

Colors

authored

Rate supports the full semantic color palette: primary, secondary, tertiary, accent, neutral, base, info, success, warning, error.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

const colors = [
  "primary",
  "secondary",
  "tertiary",
  "accent",
  "neutral",
  "base",
  "info",
  "success",
  "warning",
  "error"
] as const;

export function RateColorsDemo() {
  return (<div style={{ display: "grid", gap: 10 }}>
  {colors.map((color) => (
    <Rate key={color} color={color} defaultValue={4} readOnly />
  ))}
</div>);
}
Preview
★★★★★

Basic usage

authored

Import the component stylesheet and Rate from its package subpath, then render it with the core props.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function Example() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Renders with default classes

test-backed

Rate scenario from the component test coverage: renders with default classes.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateRendersWithDefaultClassesDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Supports custom count

test-backed

Rate scenario from the component test coverage: supports custom count.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateSupportsCustomCountDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Fills items from defaultValue

test-backed

Rate scenario from the component test coverage: fills items from defaultvalue.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateFillsItemsFromDefaultValueDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Marks the half item when allowHalf is enabled

test-backed

Rate scenario from the component test coverage: marks the half item when allowhalf is enabled.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateMarksTheHalfItemDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Applies disabled class

test-backed

Rate scenario from the component test coverage: applies disabled class.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateAppliesDisabledClassDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Calls onChange with clicked value

test-backed

Rate scenario from the component test coverage: calls onchange with clicked value.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateCallsOnChangeWithClickedDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Clears when allowClear is enabled and current value is clicked

test-backed

Rate scenario from the component test coverage: clears when allowclear is enabled and current value is clicked.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateClearsWhenAllowClearIsDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
★★★★★

Applies custom className

test-backed

Rate scenario from the component test coverage: applies custom classname.

Source
import "@duskmoon-dev/components/styles.css";
import { Rate } from "@duskmoon-dev/components/rate";

export function RateAppliesCustomClassNameDemo() {
  return (<Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>);
}
Preview
Sunshine Theme
★★★★★
Moonlight Theme
★★★★★

Theme aware

authored

Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.

Source
<div data-theme="sunshine">
  <Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>
</div>

<div data-theme="moonlight">
  <Rate
  defaultValue={3.5}
  allowHalf
  color="warning"
  size="lg"
/>
</div>

API

The API reference below lists every parsed exported type or interface for Rate. Start with `value`, `defaultValue`, `onChange`, `count` for common usage.

Types: packages/components/src/components/rate/Rate.types.tsScenarios: packages/components/src/components/rate/Rate.test.tsx
RatePropsinterface extends Omit< ComponentProps<"div">, "children" | "className" | "color" | "defaultValue" | "onChange" >
PropTypeRequiredDescription
valuenumberNovalue configures Rate.
defaultValuenumberNodefaultValue configures Rate.
onChange(value: number) => voidNoonChange configures Rate.
countnumberNocount configures Rate.
allowHalfbooleanNoallowHalf configures Rate.
allowClearbooleanNoallowClear configures Rate.
disabledbooleanNodisabled configures Rate.
readOnlybooleanNoreadOnly configures Rate.
characterRateCharacterNocharacter configures Rate.
tooltipsstring[]Notooltips configures Rate.
classNamestringNoclassName configures Rate.
sizeRateSizeNosize configures Rate.
colorRateColorNocolor configures Rate.
RateCharacterRenderInfointerface
PropTypeRequiredDescription
indexnumberYesindex configures Rate.
valuenumberYesvalue configures Rate.
RateSizetype
"sm" | "md" | "lg" | "xl"
RateColortype
| "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error"
RateCharactertype
ReactNode | ((info: RateCharacterRenderInfo) => ReactNode)