shadcn.io is not affiliated with official shadcn/ui
Summary Header Reviews Block for React Aria
The header of a product's reviews page: the product name, a Write a review button that opens a real form in a dialog, and a three-cell band with the score, the share that recommend it and five distribution rows.
Installation
Overview
A reviews page header for React with React Aria, for the Ruckfield Commuter 28, a fictional 28-litre backpack. The title is the product name, with one sentence and the Shine Button, Write a review, which opens a dialog with a real form: a star rating you can set with the arrow keys and name through its own words (Poor to Excellent), a text box, checks when you submit (a rating, at least 20 characters) with the error under its field and focus sent to the first problem, and a thanks that says plainly that nothing was sent. Under a rule, a band of three cells between hairlines holds the summary of all 52 reviews: the score beside read-only stars and the count, the share that would buy it again, and five distribution rows, each with a bar, a count and a percentage. Every figure is worked out from the typed counts at the top of the file. On a phone the cells stack and the button sits under the sentence. It's built from Dialog, Field, Textarea, Rating, Guides, Button and Shine Button.
FAQ
How do I put in my own ratings?
Edit TALLY (how many reviews gave each star rating) and RECOMMENDED (how many would buy it again) at the top of the file. The total, the average to one decimal (by whole-number maths), the stars drawn to the nearest half, the recommend share and each row's percentage by the largest remainder method, so the five rows always add up to 100, are all worked out from them.
Is the review sent anywhere?
No. The form is local state: it checks the rating and the text, then shows a thanks that says "Your review shows here only; this page does not send anything." Close the dialog and open it again and the form starts empty. To keep reviews, post rating and review to your own endpoint from the submit handler and show the thanks when it answers.
Where does focus go?
When the dialog opens it follows your library's own rule. On a failed submit, focus moves to the first field with a problem: the first star when the rating is missing, the text box when the review is too short. After a good submit it moves to the thanks, and closing the dialog returns focus to Write a review.
How is the button wired to the dialog?
Write a review is the dialog's trigger and the section's one primary control.
The Shine Button sits inside DialogTrigger beside the dialog.