Rating Badge
ProNewA compact trust badge with the source mark, score, stars and review count, inline or floating in a corner.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
| Prop | Type | Default |
|---|---|---|
| rating* | numberAverage rating, from 0 to `max`. | — |
| total | numberNumber of reviews behind the rating. `0` shows the empty state. | — |
| max | numberTop of the scale. | 5 |
| source | BrandReview site the rating comes from. Its mark leads the badge. | — |
| sources | Brand[]Several sites, shown as a stack of marks after the count. | — |
| variant | "stars" | "score" | "card"`stars` is score, stars and count in a row; `score` is one star and "4.8/5"; `card` stacks a title, a large score and the count. | "stars" |
| size | "sm" | "md" | "lg" | "md" |
| layout | "inline" | "floating"`inline` sits in the text flow; `floating` pins the badge to a corner. | "inline" |
| position | "bottom-left" | "bottom-right" | "top-left" | "top-right"Corner used by the floating layout. | "bottom-left" |
| anchor | "viewport" | "parent"What the floating badge pins to: the viewport, or the nearest positioned ancestor. | "viewport" |
| title | stringTitle line of the `card` variant. Defaults to "Google rating" for a Google source. | — |
| formatTotal | (total: number) => stringText for the count, e.g. to translate it. | defaultTotal |
| href | stringTurns the badge into a link, e.g. to your reviews page. | — |
| onClick | () => voidTurns the badge into a button. | — |
| onDismiss | () => voidAdds a close button to the floating badge. Called once it has been dismissed. | — |
| animated | booleanCount the score up and fill the stars when the badge scrolls into view. | true |
| loading | booleanShows a skeleton of the same size while the rating loads. | false |
| color | stringStar color. Any CSS color. | "#f5b301" |
| className | string | — |
Accessibility
- The whole badge reads as one phrase: “Rated 4.5 out of 5 from 1,720 reviews on Google”.
- With `href` it is a link and with `onClick` a button; otherwise it is a single image.
- The floating badge has a named Dismiss button that shows on hover, on focus and always on touch screens.
- While loading it is a status named “Loading rating”. Under reduced motion the score and stars appear filled, with no count-up.