Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
rating-star
Advanced tools
Rating Star UI Component powered by ReactJS
npm i rating-star
yarn add rating-star
The version of React has to be 16.8.0 or above.
Javascript / Typescript
import { RatingStar } from "rating-star";
export default function App() {
const [rating, setRating] = React.useState(30);
const onRatingChange = (score) => {
setRating(score);
};
return (
<div className="App">
<h1>Rating Star</h1>
<RatingStar
clickable
maxScore={100}
id="123"
rating={rating}
onRatingChange={onRatingChange}
/>
</div>
);
}
For more details, can go to Demos.
Name | Description |
---|---|
id | the element id |
clickable (optional) | enable click for the ratings, default is false |
noBorder (optional) | disable borders of the star icon, default is false |
size (optional) | icon size, default is 24 |
maxScore (optional) | the maximum score of the ratings, default is 5 |
rating (optional) | the current score, default is 0 |
numberOfStar (optional) | total number of star icons, default is 5 |
colors (optional) | colours of the star icon |
onRatingChange (optional) | a callback of rating changes |
interface ColourTheme {
stroke: string;
mask: string;
rear: string;
}
interface RatingStarProps {
id: string;
clickable?: boolean;
noBorder?: boolean;
size?: number;
maxScore?: number;
rating?: number;
numberOfStar?: number;
colors?: Partial<ColourTheme>;
onRatingChange?: (rating: number) => void;
}
You can customise the star icon with your needs.
Example:
import AcUnitIcon from "@material-ui/icons/AcUnit";
import { RatingStar } from "rating-star";
function App() {
return (
<RatingStar
id="custom-icon-wow"
rating={3}
starIcon={AcUnitIcon}
colors={{ mask: "#43a7e3" }}
noBorder
/>
);
}
The custom icon must be a SVG React component which contains only one child element.
The child element can be one of:
path
polygon
circle
rect
image
e.g.
function CustomIcon() {
return (
<svg>
<path d="..." />
</svg>
);
}
You can customise the styles of the rating-star
container by CSS class name, "rating-star",
or use the id
you have assigned to the rating-star
component.
For styled-components
lover, you can modify the styles with the power of the styled-components
.
import styled from "styled-components";
import { RatingStarContainer, RatingStarIconsWrapper } from "rating-star";
const YourStyledComponent = styled.div`
${RatingStarContainer} {
margin: 10px 0;
}
${RatingStarIconsWrapper} {
> svg {
margin: 3px 0;
}
}
`;
FAQs
React rating star merely using SVG + CSS
The npm package rating-star receives a total of 174 weekly downloads. As such, rating-star popularity was classified as not popular.
We found that rating-star demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.