Update code sample

This commit is contained in:
2023-10-13 17:07:58 +07:00
parent 272c64463a
commit 53c6727f2b
2 changed files with 16 additions and 4 deletions
@@ -25,7 +25,6 @@ export const Secondary: Story = {
args: { args: {
size: 50, size: 50,
maxRating: 5, maxRating: 5,
color: "beach",
defaultRating: 5, defaultRating: 5,
messages: ["Worst", "Worse", "Normal", "Good", "Best"], messages: ["Worst", "Worse", "Normal", "Good", "Best"],
}, },
+16 -3
View File
@@ -11,11 +11,25 @@ const starContainerStyle = {
}; };
interface IStarRating { interface IStarRating {
/**
* The max of star for rating
*/
maxRating?: number; maxRating?: number;
/**
* The color of star
*/
color?: string; color?: string;
/**
* The size of star
*/
size?: number; size?: number;
className?: string; /**
* The array of message for each star (The length of array must equal with amount of star)
*/
messages?: string[]; messages?: string[];
/**
* The default rating
*/
defaultRating?: number; defaultRating?: number;
} }
@@ -23,7 +37,6 @@ export const StarRating = ({
maxRating = 5, maxRating = 5,
color = "#fcc419", color = "#fcc419",
size = 48, size = 48,
className = "",
messages = [], messages = [],
defaultRating = 0, defaultRating = 0,
}: IStarRating) => { }: IStarRating) => {
@@ -42,7 +55,7 @@ export const StarRating = ({
}; };
return ( return (
<div style={containerStyle} className={className}> <div style={containerStyle}>
<div style={starContainerStyle}> <div style={starContainerStyle}>
{Array.from({ length: maxRating }, (_, i) => ( {Array.from({ length: maxRating }, (_, i) => (
<span key={i}> <span key={i}>