@siddhantmadhur/react-rating
Advanced tools
Comparing version 1.2.7 to 1.2.8
@@ -7,6 +7,7 @@ import React, { SetStateAction } from "react"; | ||
value: number; | ||
setValue: React.Dispatch<SetStateAction<number>>; | ||
setValue?: React.Dispatch<SetStateAction<number>>; | ||
color: string; | ||
readOnly?: boolean; | ||
} | ||
declare function Rating(props: RatingProps): React.JSX.Element; | ||
export default Rating; |
@@ -8,4 +8,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
useEffect(() => { | ||
setHoverValue(props.value); | ||
if (props.readOnly) { | ||
setHoverValue(props.value); | ||
} | ||
}, [props.value]); | ||
const readOnly = props.readOnly || false; | ||
return (React.createElement("div", { onMouseLeave: () => { | ||
@@ -16,3 +19,3 @@ setHoverValue(props.value); | ||
color: props.color, | ||
}, className: "icon" }, | ||
}, className: !readOnly ? "icon" : "" }, | ||
React.createElement("button", { style: { | ||
@@ -23,3 +26,8 @@ position: "absolute", | ||
width: (props.size || 24) / 2, | ||
}, onClick: () => props.setValue(key + 0.5), onMouseEnter: () => setHoverValue(key + 0.5) }, | ||
cursor: !readOnly ? "pointer" : "", | ||
}, onClick: () => (props.setValue ? props.setValue(key + 0.5) : null), onMouseEnter: () => { | ||
if (!readOnly) { | ||
setHoverValue(key + 0.5); | ||
} | ||
}, disabled: readOnly }, | ||
React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: key < hoverValue ? props.color : "none", viewBox: "0 0 12 24", strokeWidth: 1.5, stroke: "currentColor", style: { | ||
@@ -35,3 +43,8 @@ width: (props.size || 24) / 2, | ||
width: (props.size || 24) / 2, | ||
}, onClick: () => props.setValue(key + 1), onMouseEnter: () => setHoverValue(key + 1) }, | ||
cursor: !readOnly ? "pointer" : "", | ||
}, onClick: () => (props.setValue ? props.setValue(key + 0.5) : null), onMouseEnter: () => { | ||
if (!readOnly) { | ||
setHoverValue(key + 1); | ||
} | ||
}, disabled: readOnly }, | ||
" ", | ||
@@ -38,0 +51,0 @@ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: key + 0.5 < hoverValue ? props.color : "none", viewBox: "12 0 12 24", strokeWidth: 1.5, stroke: "currentColor", width: (props.size || 24) / 2, height: props.size || 24 }, |
{ | ||
"name": "@siddhantmadhur/react-rating", | ||
"private": false, | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/SiddhantMadhur/react-rating", |
Sorry, the diff of this file is not supported yet
7099
83