SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

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

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

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

  • RatingBreakdown
  • RatingBreakdown.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 by label and valued by display, filled to value / max of 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.

PropTypeRequiredDescription
scorenumberYesThe average rating, such as 4.86.
maxnumberNo
displaystringNoThe score as shown, already formatted for the reader's locale.
countRemixNodeNoThe review count as shown, such as "128 reviews".
outOfstringNoWhat follows the score for a screen reader, completing "4.86 out of 5".

Also accepts everything in TagProps<"section">.

RatingBreakdown.Group

PropTypeRequiredDescription
kind"stars" | "categories"Yes

Also accepts everything in TagProps<"ul">.

RatingBreakdown.Bar

PropTypeRequiredDescription
labelstringYesWhat the bar measures, such as "5 stars" or "Cleanliness"; it names the meter.
iconRemixNodeNoDrawn before the label, such as a star or a category's icon.
valuenumberYesThe measured amount: a share from 0 to max, or a category's score.
maxnumberNo
displaystringYesThe 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

NameValuesWhat 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.
@sdxc/ui

Can’t find it? Contact us