React simple star rating is a simple yet powerful react component for adding a nice rating icons to your project.
Basic Props for react-simple-star-rating
is here
import React from 'react';
import { Rating } from 'react-simple-star-rating';
const DefaultRatings = () => {
return (
<>
<Rating
initialValue={2.5}
fillColor="#298DFF"
allowFraction
/>
<Rating
initialValue={2}
allowFraction
/>
</>
);
};
export default DefaultRatings;
Use fillColorArray={[]}
prop for progressive range of colors in <Rating>
.
import React from 'react';
import { Rating } from 'react-simple-star-rating';
const ProgressiveRating = () => {
return (
<>
<Rating
initialValue={3}
fillColorArray={[
"#FF0000",
"#E75410",
"#FFC400",
"#0FFF9F",
"#00D67F"
]}
transition
/>
</>
);
};
export default ProgressiveRating;
You can prevent the ratings from user intraction by enabling readonly
.
import React from 'react';
import { Rating } from 'react-simple-star-rating';
const ReadOnlyRatings = () => {
return (
<>
<Rating
initialValue={2.5}
fillColor="#298DFF"
readonly
/>
<Rating
initialValue={2}
readonly
/>
</>
);
};
export default ReadOnlyRatings;
You can add your custom tooltip in <Rating>
by using tooltipArray={[]}
prop.
import React from 'react';
import { Rating } from 'react-simple-star-rating';
const RatingWithTooltip = () => {
return (
<Rating
initialValue={3}
showTooltip
tooltipArray={[
'Poor',
'Fair',
'Good',
'Excellent',
'Wow'
]}
/>
);
};
export default RatingWithTooltip;
You can adjust your rating star sizes by adding size
prop in px
import React from 'react';
import { Rating } from 'react-simple-star-rating';
const RatingWithTooltip = () => {
return (
<>
<Rating initialValue={2} size="20" />
<Rating initialValue={2} size="30" />
<Rating initialValue={2} />
</>
);
};
export default RatingWithTooltip;
Prop | Type | Default | Description |
---|---|---|---|
size | number | 40 | SVG Icon width / height in px |