Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Distribution Bars Reviews Block for React

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

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

A rating distribution for React with Base UI, for the Dalemoor Fellwalker, a fictional leather hiking boot. A start-aligned header holds the title, one sentence and a Bars / Table switch. Under the first rule, five ruled rows run rail to rail, five stars first: the star, a bar drawn from the count, the count and the share of all 366 ratings. Under a second rule, four readout cells give the mean, the median, the mode and the share rated four or more, so the reader sees why the mean sits under the median. Each row is a button: point at it, tab to it or press it, and its bar steps forward while the rest dim, and a line under the rows reads it out in words. The Table tab shows the same numbers as a real table with a running share, in the same height, so switching moves nothing. Every figure is worked out from the typed counts at the top of the file, and bars are drawn in your theme's text colour. It's built from Tabs and Guides, with CSS transitions only.

FAQ

How do I put in my own ratings?

Edit TALLY at the top of the file: how many ratings gave each star, five stars first. The total, the mean to one decimal (by whole-number maths, so 1,428 stars over 366 ratings is exactly 3.9), the median, the mode, the share rated four or more and each row's percentage are worked out when the module loads. The percentages use the largest remainder method, so the five rows always add up to 100. The median is the first star, counting up from one, where the running count reaches half the ratings.

What does pointing at a row do?

It reads the row. The row's bar stays solid and the other four step back to a lighter tone, the row takes a light tint, and the line under the rows says, for example, "4 stars: 121 ratings, 33% of 366." Hover works with a mouse only; a tap or the keyboard (Tab, then Enter or Space) reads the row through its press, and focus reads it too. Nothing is filtered: the readout cells always describe every rating. Each row is named in full for a screen reader ("4 stars: 121 ratings, 33%"), and the bar and figures are hidden from it so nothing is said twice.

Why is there a table as well as bars?

A table is the better view for exact figures, for a screen reader's table commands and for a reader who wants the running share from five stars down. Both views live in one grid cell with an unseen copy of each, so the taller one sets the height and the switch never shifts the page. The table has a caption, column headers and row headers, a native table on every target. The switch is the catalog Tabs: arrow keys move between triggers.

Why are the bars not coloured by rating?

Colour would tell the reader how to feel before the numbers do. The bars use your theme's text colour at full strength and one lighter step, so the shape is the message, and the primary colour stays free for the page's calls to action. Stars are drawn as icons next to the figure, not as colours.

Does it work right to left?

Yes. Each row runs star, bar, count, share from the start, the bar fills from the start, and every figure sits in its own isolating element so digits and the percent sign stay in order. The readout cells and the table follow the page's direction.

How does it fit on a phone?

The rows keep one line each at 320 pixels, the readout cells fold into two across and two down, and in the table the last column is shortened to "Running". Nothing scrolls sideways.

  • Pro

    A 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

    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.

  • Pro

    A 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

    NPS Display Reviews

    Survey scores

    A Net Promoter Score drawn as eleven score columns from 0 to 10 in three labelled brackets, with the score worked out and signed, and a press on a column listing the comments left with that score.

  • Pro

    A 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

    A vertical column histogram of one-to-five star reviews in one framed figure whose cells share hairlines: the score and a plain-words verdict, one owner's quote, and the chart with the value above each column and a dashed average marker. A Shine Button in the header links to the reviews.