Demo
Rating basics
Documented in Rating.
Rating basics
Interactive ratings with half precision, clearing, labels and a value bubble, plus a read-only exact average.
Demo.tsx
'use client';
import { useState } from 'react';
import { Rating } from '@salmonui/inputs/rating';
// Half precision with clearing, labels and the value bubble; a read-only exact average.
export default function RatingBasicsDemo() {
const [value, setValue] = useState(3.5);
const [hover, setHover] = useState<number | null>(null);
return (
<div style={{ display: 'grid', gap: 16 }}>
<Rating label="Your rating" precision="half" value={value} onValueChange={setValue} onHoverChange={setHover} clearable showLabel showTooltip />
<output>{hover === null ? `Value: ${value}` : `Preview: ${hover}`}</output>
<Rating label="Average of 1,284 reviews" readOnly precision="exact" value={4.32} showLabel renderLabel={({ value: v }) => v.toFixed(2)} />
<Rating label="Favorites" icon="♥" emptyIcon="♡" count={3} defaultValue={2} size="lg" />
</div>
);
}
Hover the stars to preview a value; the read-only average clips the last star to the exact value.