File tree Expand file tree Collapse file tree 5 files changed +31
-13
lines changed Expand file tree Collapse file tree 5 files changed +31
-13
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ Props that can be passed to the component are listed below:
7272 <td><code>undefined</code></td>
7373 </tr>
7474 <tr>
75- <td><code><b>renderLabel?:</b> (ratingId: number ): ReactElement</code></td>
75+ <td><code><b>renderLabel?:</b> (ratingId: string ): ReactElement</code></td>
7676 <td>A render function to customize your ratings label with your own element.</td>
7777 <td><code>undefined</code></td>
7878 </tr>
@@ -86,11 +86,17 @@ Props that can be passed to the component are listed below:
8686 <td>Boolean to enable and disable showing animations and transitions on the chart.</td>
8787 <td><code>true</code></td>
8888 </tr>
89+ <tr>
8990 <td><code><b>styles?:</b> object</code></td>
9091 <td>Provides you with a bunch of callback functions to override the default styles.(refer
9192 <a href="#style-customizations">Style Customizations</a>)
9293 <td><code>undefined</code></td>
9394 </tr>
95+ <tr>
96+ <td><code><b>onChartClick?:</b> (ratingId: string): void</code></td>
97+ <td>Click handler for each ratings chart</td>
98+ <td><code>undefined</code></td>
99+ </tr>
94100 </tbody>
95101</table >
96102
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ const RatingSummary: FC<ISummaryProp> = (props) => {
1313 showCount = true ,
1414 showAnimation = true ,
1515 styles = { } ,
16- chartColors
16+ chartColors,
17+ onChartClick
1718 } = props ;
1819
1920 const totalRatingCount = useMemo (
@@ -41,8 +42,11 @@ const RatingSummary: FC<ISummaryProp> = (props) => {
4142 ) }
4243 < div
4344 style = { { width : `${ getBarWidth ( Number ( ratingId ) ) * 100 } %` } }
44- className = { classes . barWrapper }
45+ className = { `${ classes . barWrapper }
46+ ${ showAnimation && classes . transitions }
47+ ${ onChartClick && classes . cursorPointer } ` }
4548 id = { `${ ratingId } -bar` }
49+ onClick = { ( ) : void => onChartClick && onChartClick ( ratingId ) }
4650 >
4751 < div
4852 style = { {
@@ -57,8 +61,7 @@ const RatingSummary: FC<ISummaryProp> = (props) => {
5761 { } ) ,
5862 ...getStyles ( Elements . Chart , Number ( ratingId ) )
5963 } }
60- className = { `${ classes . barContainer }
61- ${ showAnimation && classes . transitions } ` }
64+ className = { `${ classes . barContainer } ${ showAnimation && classes . animations } ` }
6265 >
6366 { showCount && (
6467 < span
Original file line number Diff line number Diff line change 3535 padding-left : 8px ;
3636 }
3737 }
38- .transitions {
39- animation-name : widthAnimation;
40- animation-duration : 300ms ;
41- animation-timing-function : ease-in-out ;
42- animation-iteration-count : 1 ;
43- transition : width 0.3s ease-in-out ;
44- }
38+ }
39+ .transitions {
40+ transition : width 0.3s ease-in-out ;
41+ }
42+ .animations {
43+ animation-name : widthAnimation;
44+ animation-duration : 300ms ;
45+ animation-timing-function : ease-in-out ;
46+ animation-iteration-count : 1 ;
47+ }
48+ .cursorPointer {
49+ cursor : pointer ;
4550 }
4651 .five {
4752 background-color : #9fc05a ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export type ISummaryProp = {
88 showAnimation ?: boolean ;
99 styles ?: { [ value in Elements ] : IStyleFunction } ;
1010 chartColors ?: { [ value in RatingValue ] : string } ;
11+ onChartClick ?: ( ratingId : string ) => void ;
1112} ;
1213
1314export type IRatings = {
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ RatingSummary.args = {
2323 3 : 141135 ,
2424 2 : 57472 ,
2525 1 : 134055
26- }
26+ } ,
2727 // renderLabel: (ratingId: string) => ((ratingId === '1' && (<>now</>) || <>{ratingId}</>)),
2828 // showCount: true,
2929 // showAnimation: true,
@@ -37,4 +37,7 @@ RatingSummary.args = {
3737 // 2: 'blue',
3838 // 1: 'green'
3939 // },
40+ onBarClick : ( ratingId : string ) => {
41+ console . log ( "🚀 ~ ratingId:" , ratingId )
42+ }
4043} ;
You can’t perform that action at this time.
0 commit comments