![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@keyvaluesystems/react-star-rating-summary
Advanced tools
A ready to use star rating summary UI package on 5 star rating concept for React.
Try tweaking a rating summary component using this code sandbox link here
npm install @keyvaluesystems/react-star-rating-summary
You’ll need to install React separately since it isn't included in the package.
React Star Rating Summary can be directly used in your project by just providing the ratings
props like this:
import React, { useState } from 'react';
import RatingSummary from '@keyvaluesystems/react-star-rating-summary';
function App() {
const ratingsVal = {
5: 100,
4: 200,
3: 300,
2: 1000,
1: 400
};
return (
<RatingSummary
ratings={ratingsVal}
/>
);
};
export default App;
The ratings
prop expects an object with star rating number as key (can be 1, 2, 3, 4 and 5) and count of the respective ratings as the value.
Note: The total rating count will be calculated by the package and chart length for each rating will be considered with respect to total count.
Props that can be passed to the component are listed below:
Prop | Description | Default |
---|---|---|
ratings: object | An object with ratingIds as key and respective count as value. | undefined |
chartColors?: object | An object with ratingIds as key and respective chart color as value. | undefined |
renderLabel?: (ratingId: string): ReactElement | A render function to customize your ratings label with your own element. | undefined |
showCount?: boolean | Boolean to enable and disable showing count on the chart. | true |
showAnimation?: boolean | Boolean to enable and disable showing animations and transitions on the chart. | true |
styles?: object | Provides you with a bunch of callback functions to override the default styles.(refer Style Customizations) | undefined |
onChartClick?: (ratingId: string): void | Click handler for each ratings chart | undefined |
Note: The numbers from 1 to 5 are only taken as
ratingIds
Basic customization like changing the chart color for each ratings can be done using the chartColors
prop:
<RatingSummary
ratings={ratingsVal}
chartColors={{
5: '#000',
4: 'yellow',
3: 'orange',
2: 'blue',
1: 'green'
}}
/>
Further customizations can by done by overriding default styles using the styles
prop,
the below code shows all the overridable styles:
import React from 'react';
import RatingSummary from '@keyvaluesystems/react-star-rating-summary';
function App() {
const stylesOverride = {
Chart: (ratingId) => ({...styles}),
Count: (ratingId) => ({...styles})
};
return (
<RatingSummary
ratings={ratingsVal}
styles={stylesOverride}
/>
);
}
export default App;
Chart
- overrides the Chart style for each rating.Count
- overrides the rating count style for each rating.Note: if you provides both
chartColors
prop and overridesChart
styles usingstyles
prop, the customizations viastyles
prop are given more priority.
FAQs
A ready to use rating summary component
The npm package @keyvaluesystems/react-star-rating-summary receives a total of 17 weekly downloads. As such, @keyvaluesystems/react-star-rating-summary popularity was classified as not popular.
We found that @keyvaluesystems/react-star-rating-summary demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.