Forms & Inputs
@hacline/ui/ratingRating
Pick full-star or half-star ratings.
Usage
Hover to preview values. This example uses step={0.5}, and also supports arrow-key focus movement with Space to select.
"use client";
import { useState } from "react";
import { Rating } from "@/components/ui/hacline/components/rating";
export const Example = () => {
const [value, setValue] = useState<number | null>(3.5);
return (
<div className="flex flex-col items-center gap-2">
<Rating
aria-label="Documentation clarity rating"
getValueLabel={(score) => `${score} ${score === 1 ? "star" : "stars"}`}
max={5}
onValueChange={setValue}
step={0.5}
value={value}
/>
<output className="text-hl-fg-muted text-xs">
{value === null ? "Not rated yet" : `Rating ${value} / 5`}
</output>
</div>
);
};Read-Only Average Display
Set readOnly to present an aggregate average score that prevents edits.
4.2 / 5 from 18 reviews
"use client";
import { Rating } from "@/components/ui/hacline/components/rating";
export const Example = () => (
<div className="flex flex-col items-center gap-1">
<Rating
aria-label="Average tutorial rating 4.2 stars"
max={5}
readOnly
value={4.2}
/>
<p className="text-hl-fg-muted text-xs">4.2 / 5 from 18 reviews</p>
</div>
);Parts
| Part | Description |
|---|---|
RatingItem | One star. Put its icon inside: the state says how full it is, and the radios that pick its score sit over it. |
Props
Prop
Type