11import type { Meta , StoryObj } from '@storybook/react-vite' ;
22
3- import { Rating } from '@/components/rating' ;
3+ import * as RatingPrimitive from '@/components/rating' ;
4+ import { Rating , type RatingProps } from '@/components/rating' ;
45
5- const meta = {
6+ const meta : Meta < typeof Rating > = {
67 title : 'Components/Rating' ,
78 component : Rating ,
89 parameters : {
@@ -12,117 +13,97 @@ const meta = {
1213 argTypes : {
1314 rating : {
1415 control : { type : 'number' , min : 0 , max : 5 , step : 0.1 } ,
15- description : 'Rating value from 0 to 5' ,
16+ description : 'The rating value (0-5)' ,
17+ } ,
18+ totalReviews : {
19+ control : 'number' ,
20+ description : 'Total number of reviews to display' ,
1621 } ,
1722 showRating : {
1823 control : 'boolean' ,
19- description : 'Show numeric rating badge' ,
20- table : {
21- defaultValue : { summary : 'true' } ,
22- } ,
24+ description : 'Whether to show the numeric rating value' ,
25+ } ,
26+ showTotalReviews : {
27+ control : 'boolean' ,
28+ description : 'Whether to show the total reviews count' ,
2329 } ,
2430 className : {
2531 control : 'text' ,
26- description : 'Additional CSS classes' ,
32+ description : 'Additional CSS classes for the root element ' ,
2733 } ,
2834 } ,
29- args : {
30- rating : 4.5 ,
31- showRating : true ,
32- } ,
33- } satisfies Meta < typeof Rating > ;
35+ } ;
3436
3537export default meta ;
36-
37- type Story = StoryObj < typeof meta > ;
38+ type Story = StoryObj < RatingProps > ;
3839
3940export const Default : Story = {
4041 args : {
4142 rating : 4.5 ,
43+ totalReviews : 128 ,
4244 } ,
4345} ;
4446
45- export const FiveStars : Story = {
47+ export const FullStars : Story = {
4648 args : {
4749 rating : 5 ,
50+ totalReviews : 1024 ,
4851 } ,
4952} ;
5053
51- export const FourStars : Story = {
54+ export const HalfStar : Story = {
5255 args : {
53- rating : 4 ,
54- } ,
55- } ;
56-
57- export const ThreeStars : Story = {
58- args : {
59- rating : 3 ,
60- } ,
61- } ;
62-
63- export const TwoStars : Story = {
64- args : {
65- rating : 2 ,
66- } ,
67- } ;
68-
69- export const OneStar : Story = {
70- args : {
71- rating : 1 ,
56+ rating : 3.5 ,
57+ totalReviews : 42 ,
7258 } ,
7359} ;
7460
75- export const ZeroStars : Story = {
61+ export const LowRating : Story = {
7662 args : {
77- rating : 0 ,
63+ rating : 1.5 ,
64+ totalReviews : 7 ,
7865 } ,
7966} ;
8067
81- export const HalfStars : Story = {
68+ export const SingleReview : Story = {
8269 args : {
83- rating : 3.5 ,
70+ rating : 5 ,
71+ totalReviews : 1 ,
8472 } ,
8573} ;
8674
87- export const WithoutBadge : Story = {
75+ export const StarsOnly : Story = {
8876 args : {
89- rating : 4.5 ,
77+ rating : 4 ,
9078 showRating : false ,
79+ showTotalReviews : false ,
9180 } ,
9281} ;
9382
94- export const AllRatings : Story = {
83+ export const WithoutTotalReviews : Story = {
9584 args : {
9685 rating : 4.5 ,
86+ showTotalReviews : false ,
9787 } ,
98- render : ( ) => (
99- < div className = "flex flex-col gap-4" >
100- < Rating rating = { 5 } />
101- < Rating rating = { 4.5 } />
102- < Rating rating = { 4 } />
103- < Rating rating = { 3.5 } />
104- < Rating rating = { 3 } />
105- < Rating rating = { 2.5 } />
106- < Rating rating = { 2 } />
107- < Rating rating = { 1.5 } />
108- < Rating rating = { 1 } />
109- < Rating rating = { 0.5 } />
110- < Rating rating = { 0 } />
111- </ div >
112- ) ,
11388} ;
11489
115- export const WithoutBadges : Story = {
116- args : {
117- rating : 4.5 ,
118- } ,
90+ /**
91+ * The Rating component is built using composable primitives that can be used
92+ * independently to create custom layouts. Here's the anatomy:
93+ *
94+ * - `Root` - Context provider and container
95+ * - `Stars` - Renders all 5 stars based on the rating
96+ * - `Star` - Individual star icon (empty, half, or full)
97+ * - `Value` - Numeric rating display
98+ * - `Total` - Review count display
99+ */
100+ export const ComposableAnatomy : Story = {
119101 render : ( ) => (
120- < div className = "flex flex-col gap-4" >
121- < Rating rating = { 5 } showRating = { false } />
122- < Rating rating = { 4.5 } showRating = { false } />
123- < Rating rating = { 4 } showRating = { false } />
124- < Rating rating = { 3.5 } showRating = { false } />
125- < Rating rating = { 3 } showRating = { false } />
126- </ div >
102+ < RatingPrimitive . Root rating = { 4.5 } totalReviews = { 256 } >
103+ < RatingPrimitive . Stars />
104+ < RatingPrimitive . Value >
105+ < RatingPrimitive . Total />
106+ </ RatingPrimitive . Value >
107+ </ RatingPrimitive . Root >
127108 ) ,
128109} ;
0 commit comments