shadcn.io is not affiliated with official shadcn/ui
Rating Column Table Block for React
A recipe table with a rating column of five read-only stars, the average and the count, a hover card with the five-row star spread, sortable heads and a switch that takes recipes with fewer than 20 ratings out of the ranking.
Installation
Overview
Make a rating a column you can sort and question, with this rating table for React with Base UI. A compact header names the table. Inside a hairline frame with a plus mark on each corner, a band says how the rows are ordered, then a band holds a Switch labelled "At least 20 ratings", over a native table of nine Forkful recipes with a category, a rating, the number of ratings and the saves. The rating is five read-only stars from the Rating component, in the text colour with half stars, beside the average to one decimal. Pressing or focusing it opens a Hover Card with the spread: five rows from five stars to one, each with a bar, the count and the share. The average and the spread come from the same star counts, so they cannot disagree. The Recipe, Rating, Ratings and Saves heads sort, and the switch takes small samples out of the ranking: their rows stay in place, dashed and quiet, and a polite line says how many are hidden. It is built from Rating, Hover Card, Switch and Guides. For recipe sites, review lists, marketplaces and any table where a score needs its sample size.
FAQ
How do I use my own items and ratings?
Edit RECIPES. Each has a name, a category, the saves and stars, the number of people who gave five, four, three, two and one stars. The average, the half-star drawing, the count and the shares in the card are all derived, so there is one number to maintain per star. Change MINIMUM for a different sample size.
What does the switch do to the rows?
With it on, recipes with fewer than 20 ratings stop being ranked: they move below the others, show "Under 20 ratings" in a dashed row and lose their stars, but they keep their row height so the table does not jump. A polite line in the band says how many are hidden. Turn it off and they return in the order you had sorted.
How does the spread card open?
By hover, by keyboard focus and by touch. The trigger is a real button named with the recipe and its average, so Tab reaches it, and the card opens on focus and closes on blur or Escape. On a touch screen a tap opens it. The card is extra: the average and the count are always in the table, so nothing is hidden behind it.
Why do the shares add up to 100?
Each row is rounded to a whole percent, which can leave the total at 99 or 101. sharesOf rounds down, then gives the missing points to the rows with the largest remainders, so the five shares always add to exactly 100 and the same data always gives the same numbers.
What stays local, and how do I wire real data?
The ratings are constants; the sort and the switch are two useState calls. To use real data, load recipes with their star counts and pass them in; to let people rate, post to your API and refetch the counts, since everything else is derived from them. The stars here are read-only on purpose.
Related
- Pro
Sortable Members Table
Sort and searchA members table whose column heads are buttons: press one to sort, again to reverse, a third time for the original order, with aria-sort on the active head, ties settled by name and a spoken line for each result.
- Pro
Effective Priority Table
Rich cellsA ticket queue where a switch raises any ticket due within two days by one level, shown as drawn bars, a word and a raised-from note, and the Priority head sorts by that effective rank.
- Pro
Link Cell Table
Rich cellsA reading list whose titles are real links: an arrow and a name that says opens in a new tab on links to other sites, plain links inside the app, truncated hosts with the whole address in a title, and a preview card on hover or focus.
- 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
Star Threshold Histogram Reviews
Score summariesA 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.
- 1212Pro
Sort Builder Segments Table
Sort and searchA customer segments table ordered by a two-rule sort builder: pick a column and a direction for the first rule and for the tie-break, see the order as a 1 and a 2 on the heads, and Reset to start again.