A customizable React component for displaying star ratings.
Install the package using npm:
npm install lite-react-rating
Or with yarn:
yarn add lite-react-rating
Peer Dependencies Ensure you have react and react-dom installed in your project:
npm install react react-dom
Import the RatingHandler component and use it in your React application.
Type definitions are included with the package, allowing seamless integration in TypeScript projects.
Mais Aburabie
import RatingHandler from 'lite-react-rating';
const App = () => {
return (
<div>
<h1>Product Rating</h1>
<RatingHandler value={3} readOnly={true} dir="ltr"/>
</div>
);
};
export default App;
-
Type:
number
- Description: The current rating value.
-
Type:
(value: number) => void
- Description: Callback function called when the rating changes.
-
Type:
boolean
-
Default:
false
-
Description: If
true
, the rating component is read-only.
-
Type:
number
-
Default:
5
- Description: The maximum number of stars to display.
-
Type:
ltr
|rtl
-
Default:
ltr
- Description: The Direction of stars to display.
Here's a more detailed example demonstrating all available props:
import React, { useState } from 'react';
import RatingHandler from 'lite-react-rating';
const ProductReview = () => {
const [rating, setRating] = useState(0);
const handleRatingChange = (value) => {
console.log('Selected rating:', value);
setRating(value);
};
return (
<div>
<h2>Rate Our Product</h2>
<RatingHandler
value={rating}
onChange={handleRatingChange}
readOnly={false}
dir="ltr"
max={10}
/>
<p>Your rating: {rating}</p>
</div>
);
};
export default ProductReview;
This project is licensed under the ISC License.