Rating widget (Pro)
ProIncluded in $99Feedback in one tap that invites a little more: stars that name what they mean, or a 0 to 10 scale, then quick reasons and a comment.
On this page
Installation
Needs chatcn Pro
This command works with a Pro license, along with every Pro component.
Or start free: sign up and get three Pro components on us, with a new one every month.
Usage
import { RatingWidget } from "@/components/ui/chatcn/pro/rating-widget"
<RatingWidget
title="Your ride to the airport"
tags={(v) => (v <= 3 ? ["Late pickup", "Rough driving"] : ["On time", "Smooth driving"])}
onSubmit={({ value, tags, comment }) => send(value, tags, comment)}
/>Stars fill as you move across them and the word for each shows beneath, so 3 means Good and not a guess. Picking one brings in quick reasons, which can depend on the rating, and a comment box that grows with its text; switching to a rating whose reasons differ drops the ones that no longer fit. kind="scale" is the 0 to 10 likely to recommend question with both ends named. Sent, it thanks you, keeps the answer and the reasons in a line, and Change reopens it.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
kind | "stars" | "scale" | Default stars |
title, meta, question | What is being rated | |
tags | string[] | (value) => string[] | Quick reasons |
comment | boolean | Default true |
defaultValue, defaultSubmitted | For a rating already given | |
onSubmit | ({ value, tags, comment }) => void | Sends |
labels | Partial<RatingWidgetLabels> | Every string, including the star words |
Keyboard
| Key | Action |
|---|---|
| Arrow keys | Move between ratings |
| Space | Toggle a reason |
Accessibility
- Ratings are a native radio group in a fieldset; each star is named with its number and word.
- Reasons are toggle buttons; the thanks is announced.
Motion
The hovered star lifts with scale; reasons and the thanks rise in. Reduced motion keeps them still.