RatingBreakdown
A reviews summary.
4.86 out of 5128 reviews
- 5 stars
- 4 stars
- 3 stars
- 2 stars
- 1 star
- Cleanliness
- Accuracy
- Check-in
- Communication
- Location
- Value
View code
<RatingBreakdown score={4.86} count="128 reviews">
<RatingBreakdown.Group kind="stars" aria-label="Ratings by star">
{stars.map((star) => (
<RatingBreakdown.Bar label={`${star.level} stars`} value={star.share} display={star.percent} />
))}
</RatingBreakdown.Group>
<RatingBreakdown.Group kind="categories" aria-label="Ratings by category">
<RatingBreakdown.Bar label="Cleanliness" icon={<SparklesIcon />} value={4.9} display="4.9" />
<RatingBreakdown.Bar label="Location" icon={<MapPinIcon />} value={4.7} display="4.7" />
</RatingBreakdown.Group>
</RatingBreakdown>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
import { RatingBreakdown } from "@sdxc/ui/travel";Renders the summary: a <section> opening with the score, its star and the review count,
followed by its RatingBreakdown.Group children. A screen reader hears the score as
"4.86 out of 5".
Composition
The parts the component publishes, each a static property of the host.
RatingBreakdownRatingBreakdown.GroupRenders a list of bars of one kind: star levels one under another, or categories in a grid that runs two to a row once the summary is 30rem wide.RatingBreakdown.BarRenders one bar as an ARIA meter named bylabeland valued bydisplay, filled tovalue / maxof its track; the figure at its end is hidden from assistive technology, which reads it as the meter's value.
Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Required | Description |
|---|---|---|---|
score | number | Yes | The average rating, such as 4.86. |
max | number | No | |
display | string | No | The score as shown, already formatted for the reader's locale. |
count | RemixNode | No | The review count as shown, such as "128 reviews". |
outOf | string | No | What follows the score for a screen reader, completing "4.86 out of 5". |
Also accepts everything in TagProps<"section">.
RatingBreakdown.Group
| Prop | Type | Required | Description |
|---|---|---|---|
kind | "stars" | "categories" | Yes |
Also accepts everything in TagProps<"ul">.
RatingBreakdown.Bar
| Prop | Type | Required | Description |
|---|---|---|---|
label | string | Yes | What the bar measures, such as "5 stars" or "Cleanliness"; it names the meter. |
icon | RemixNode | No | Drawn before the label, such as a star or a category's icon. |
value | number | Yes | The measured amount: a share from 0 to max, or a category's score. |
max | number | No | |
display | string | Yes | The figure shown at the bar's end and read as its value, such as "92%" or "4.9". |
Also accepts everything in Omit<TagProps<"li">, "children">.
Types
| Name | Values | What it decides |
|---|---|---|
Kind | "stars" | "categories" | "stars" sets each bar on one line, label and figure either side of it, for the share of reviews at each star level; "categories" sets the label over its bar, two to a row when there is room, for per-category scores. |