View as Markdown

API reference: @salmonui/inputs/rating

Ratingcomponent

import { Rating } from '@salmonui/inputs/rating';
function Rating(props: RatingProps): ReactNode;

Rating: one native radio per step (two per item with precision="half") named by localeText.item, inside a <fieldset role="radiogroup"> named by label. Arrow keys are the browser's radio keys (mirrored in RTL); hover preview is CSS. Read-only 'quarter' / 'exact' precision renders one role="img" with a clipped fill. ref is the root element.

Props: RatingProps

Rating props (36)
NameSignatureDescription
labeloptionalinheritedlabel?: ReactNode;
descriptionoptionalinheriteddescription?: ReactNode;
errorMessageoptionalinheritederrorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) | ReactNode;

Error text (or a function of the errors) shown while the field is invalid.

invalidoptionalinheritedinvalid?: boolean;

Forces the error state.

validationoptionalinheritedvalidation?: FieldValidation;

Rules in the Data Grid vocabulary.

validateOnoptionalinheritedvalidateOn?: ValidateOn;

When errors appear; default the Form's, else 'blur'.

sizeoptionalinheritedsize?: FieldSize;

Metric set. Default 'md'.

valueoptionalreadonly value?: number | undefined;
defaultValueoptionalreadonly defaultValue?: number | undefined;

Default min.

onValueChangeoptionalreadonly onValueChange?: ((value: number, details: RatingChangeDetails) => void) | undefined;
countoptionalreadonly count?: number | undefined;

Number of items. Default 5.

minoptionalreadonly min?: number | undefined;

Lowest value a selection can set; the cleared value. Default 0.

precisionoptionalreadonly precision?: 'full' | 'half' | 'quarter' | 'exact' | undefined;

Step: 'full' or 'half' while editing; 'quarter' and 'exact' only with readOnly (a role="img" display). Default 'full'.

clearableoptionalreadonly clearable?: boolean | undefined;

Shows a clear button while the value is above min.

highlightSelectedOnlyoptionalreadonly highlightSelectedOnly?: boolean | undefined;

Fills only the selected item.

showLabeloptionalreadonly showLabel?: boolean | undefined;

Shows the value next to the items.

labelPlacementoptionalreadonly labelPlacement?: 'top' | 'bottom' | 'start' | 'end' | undefined;

Where the value label sits. Default 'end'.

renderLabeloptionalreadonly renderLabel?: ((ctx: { readonly value: number; readonly count: number; }) => ReactNode) | undefined;
iconoptionalreadonly icon?: ReactNode;

Filled icon. Default a star.

emptyIconoptionalreadonly emptyIcon?: ReactNode;

Empty icon. Default icon (drawn in the empty color).

renderItemoptionalreadonly renderItem?: ((ctx: { readonly index: number; readonly state: RatingItemState; readonly fill: number; }) => ReactNode) | undefined;

Replaces both icons of an item.

showTooltipoptionalreadonly showTooltip?: boolean | undefined;

Shows a value bubble over the hovered or focused step.

renderTooltipoptionalreadonly renderTooltip?: ((ctx: { readonly value: number; readonly count: number; }) => ReactNode) | undefined;
onHoverChangeoptionalreadonly onHoverChange?: ((value: number | null) => void) | undefined;

The step under the pointer, null when it leaves. Bound listeners only when given; no state.

nameoptionalreadonly name?: string | undefined;

Submitted name. Without it the radios share a generated name and are not submitted.

formoptionalreadonly form?: string | undefined;
requiredoptionalreadonly required?: boolean | undefined;
disabledoptionalreadonly disabled?: boolean | undefined;
readOnlyoptionalreadonly readOnly?: boolean | undefined;

Display only: radios stay focusable but ignore changes; 'quarter' / 'exact' render a role="img".

localeTextoptionalreadonly localeText?: RatingLocaleText | undefined;
idoptionalreadonly id?: string | undefined;
diroptionalreadonly dir?: 'ltr' | 'rtl' | 'auto' | undefined;
classNameoptionalreadonly className?: string | undefined;
styleoptionalreadonly style?: CSSProperties | undefined;
classNamesoptionalreadonly classNames?: { readonly label?: string; readonly items?: string; readonly item?: string; readonly value?: string; readonly description?: string; readonly error?: string; } | undefined;

Part classes: root is className; label, items, item, value, description, error.

refoptionalreadonly ref?: Ref<HTMLElement> | undefined;

The root element (<fieldset>, or <div> for the image display).