# Rating widget

Feedback 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.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Rating widget. Rate a ride. Move across the stars to see what each means; pick one for quick reasons fitted to it. Preview: https://chatcn.dev/preview/rating-widget-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/rating-widget
```

## Usage

```tsx
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

Example: States. The 0 to 10 scale, a rating picked with its reasons, and one already sent. Preview: https://chatcn.dev/preview/rating-widget-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.

Source: https://chatcn.dev/docs/components/rating-widget