shadcn.io is not affiliated with official shadcn/ui
Star Threshold Histogram Reviews Block for React
A star-rating threshold for a lambswool blanket: a Slider sets the lowest rating that counts, a bracket spans the rows it keeps, and a reading panel gives the share that clears it and the newest review that does.
Installation
Overview
A star threshold for React with Base UI, for a fictional Skerryhouse lambswool blanket. A header with the title and one sentence sits over a split behind a divider. At the start, five distribution rows (the star, a bar drawn from the count, the count and the share of all 20 ratings) with a bracket at their end that spans the rows from five stars down to the chosen one; under them, a Slider labelled "Ratings of 4 stars and up". Drag it, or use the arrow keys, and the rows inside the bracket stay solid while the rest step back. At the end, a reading panel: the share of the ratings that clear the bar as a rolling figure ("70%"), a sentence ("14 of 20 ratings are 4 stars or more.") that a screen reader hears politely, and the newest review that clears the bar, with its stars, title, text, reviewer and date. Nothing is filtered by pressing a row, and nothing is coloured by sentiment: the rows, the bracket and the stars are your theme's text colour. All 20 reviews are typed at the top of the file and every figure is worked out from them. It's built from Slider, Sliding Number, Rating, Avatar and Guides, with CSS transitions only.
FAQ
How do I use my own reviews?
Replace REVIEWS at the top of the file, newest first. Each review has an id, name, rating from 1 to 5, an ISO date, a title and a body. The counts per star, each row's percentage (by the largest remainder method, so the rows add up to 100), the share that clears each bar and the newest review that clears it are all worked out from that list when the module loads. If you have thousands of reviews, type the counts instead and keep a short sample for the newest-review panel, as the Rating Breakdown block does.
What does the Slider change?
The lowest star rating that counts, from 1 to 5. The label under the rows says it in words ("Ratings of 4 stars and up"), the bracket resizes to span the rows that are kept, the rows below it step back to a lighter tone, the rolling figure shows the share, and the reading panel shows the newest review that clears the bar. At 1 star everything counts: 100%. The slider is a native range on every target, so arrow keys, Home, End and Page Up and Down all work.
The Slider takes value={[n]} and reads onValueChange with a number or an array; the label is tied to it by aria-labelledby.
Why doesn't the block change height as I slide?
The reading panel holds the newest review for every bar, unseen, in the same grid cell as the live one, so the tallest review sets the height. The sentence above it has a reserved height on phones too. Nothing below the block moves.
Why aren't the high ratings drawn in a colour?
A colour would say how to feel about a number. Rows inside the bracket use your theme's text colour at full strength and the rest a faint step of the same colour, so the shape is the message and the primary colour stays free for your page's calls to action. Stars in the review are the catalog Rating, read-only, in the same text colour, with the rating in words beside them.
Related
- Pro
Rating Breakdown Reviews
Score summariesA review summary for a carry-on suitcase whose star rows filter the reviews: the average, the count, the share that would recommend it and a five-row distribution, beside the four most helpful reviews with a Helpful vote each.
- Pro
Distribution Bars Reviews
Score summariesA rating distribution for a hiking boot: five ruled rows of bars, counts and shares, a Bars and Table switch, and a readout of mean, median, mode and the share rated four or more.
- Pro
Verified Toggle Reviews
Score summariesA review summary with a Verified purchases only switch: the average, the count, the share rated four or more and five distribution rows are worked out again, with a delta line against all reviews.
- Pro
Satisfaction Meter Reviews
Survey scoresA support-survey score whose definition you can change: a segmented control picks which scores count as satisfied, and a rolling percentage, a five-part bar with a bracket and five counted cells follow.
- Pro
Rating Breakdown Testimonials
Ratings and reviewsA review summary whose histogram rows are filter buttons: press a star row and the featured reviews narrow to that rating, with a live count and an empty state.
- Pro
Recommendation Rate Reviews
Survey scoresThe share of owners who would recommend a mattress, by how long they have owned it: three tabs, a rolling percentage over a two-part bar with a tick for everyone, and the gap in words.