Socket
Socket
Sign inDemoInstall

@smastrom/react-rating

Package Overview
Dependencies
5
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.2 to 1.3.3

2

dist/index.js
"use client";
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),e=require("react"),t=r=>{},n="undefined"==typeof window?e.useEffect:e.useLayoutEffect,o=r=>"number"==typeof r&&r>0,s=r=>o(r)?r:0,a=r=>Math.round(100*r)/100,i=r=>Math.round(2*r)/2,c=r=>0===r?0:-1*a(r),l={},u="rr--focus-reset",f="rr--on",d="rr--off",h="rr--fx-zoom",m="rr--fx-position",p="rr--fx-opacity",g="rr--fx-colors",b="rr--rx-sm",x="rr--rx-md",y="rr--rx-lg",v="rr--rx-full",S="rr--gap-sm",R="rr--gap-md",B="rr--gap-lg",O="rr--space-sm",L="rr--space-md",C="rr--space-lg",w={FILL:"--rr--fill-on-color",BOX:"--rr--box-on-color",BORDER:"--rr--border-on-color",STROKE:"--rr--stroke-on-color"},k={FILL:"--rr--fill-off-color",BOX:"--rr--box-off-color",BORDER:"--rr--border-off-color",STROKE:"--rr--stroke-off-color"},E="horizontal",$="vertical",A="svg",j="none",I="small",F="medium",D="large",M="full",N="none",T="zoom",W="position",K="opacity",X="colors",V={FILL:"activeFillColor",BOX:"activeBoxColor",BORDER:"activeBoxBorderColor",STROKE:"activeStrokeColor"},H={FILL:"inactiveFillColor",BOX:"inactiveBoxColor",BORDER:"inactiveBoxBorderColor",STROKE:"inactiveStrokeColor"};function P({itemShapes:t,testId:o,itemStrokeWidth:s=0,orientation:i=E,hasHF:l=!1}){const u=s>0?-s/2:0,f=s>0?`${u} ${u}`:"0 0",d=e.useRef(null),h=e.useId(),[m,p]=e.useState(null);return n((()=>{if(d.current){const{width:r,height:e,x:t,y:n}=d.current.getBBox();if(((...r)=>r.every((r=>"number"==typeof r)))(r,e,t,n)){const o=`${f} ${a(r+s)} ${a(e+s)}`,i=`${c(t)} ${c(n)}`;p({viewBox:o,translateData:i})}}}),[t,s,l]),r.jsxs("svg",{"aria-hidden":"true",className:"rr--svg",xmlns:"http://www.w3.org/2000/svg",viewBox:m?m.viewBox:"0 0 0 0",preserveAspectRatio:"xMidYMid meet",...s>0?{strokeWidth:s}:{},...o,children:[l&&r.jsx("defs",{children:r.jsxs("linearGradient",{id:h,...i===$?{gradientTransform:"rotate(90)"}:{},children:[r.jsx("stop",{className:"rr--svg-stop-1",offset:"50%"}),r.jsx("stop",{className:"rr--svg-stop-2",offset:"50%"})]})}),r.jsx("g",{ref:d,shapeRendering:"geometricPrecision",...function(){if(m){const r=`translate(${null==m?void 0:m.translateData})`;return"translate(0 0)"===r?{}:{transform:r}}return{transform:void 0}}(),...l?{fill:`url('#${h}')`}:{},children:t})]})}function Z(r,e,t){switch(e){case V.FILL:return r[w.FILL]=t,!0;case V.BOX:return r[w.BOX]=t,!0;case V.BORDER:return r[w.BORDER]=t,!0;case V.STROKE:return r[w.STROKE]=t,!0}return!1}function q(r,e,t){if(!Z(r,e,t))switch(e){case H.FILL:r[k.FILL]=t;break;case H.BOX:r[k.BOX]=t;break;case H.BORDER:r[k.BORDER]=t;break;case H.STROKE:r[k.STROKE]=t}}function z(r,e,t){const n={};let o;for(const[s,a]of Object.entries(r))Z(n,s,a[e]);return t?(o=Array(e).fill({}),o.push(n)):o=Array(e+1).fill(n),o}const G=r=>`${r} ${g}`;function J(r,e,t){return Array.from({length:e},((e,n)=>r?n===t?f:d:n<=t?f:d))}function U(r,e,t){const n=Math.floor(i(r));return Array.from({length:e},((r,e)=>"box"===t?e>n?"rr--hf-box-off":e===n?"rr--hf-box-int":"rr--hf-box-on":e>n?"rr--hf-svg-off":"rr--hf-svg-on"))}function Y(r,e){const t={};o(e)&&(t["--rr--border-width"]=`${e}px`);const n=Object.entries(r);if(n.length>0)for(const[o,s]of n)q(t,o,s);return t}const Q=[V.FILL,V.BOX,V.STROKE,V.BORDER];function _(r,e,t=!1){return Array.from({length:r},((n,o)=>t&&e<0?o===r-1?0:-1:e<=0?0===o?0:-1:e>0?o===e?0:-1:void 0))}function rr(r,e){return r.shouldRender=!1,r.reason=(r=>`[@smastrom/react-rating] - Nothing's returned from rendering. Reason: ${r}.`)(e),r}const er="itemShapes is not a valid JSX element",tr=r.jsx("polygon",{points:"25 9.02 16.4 7.75 12.46 0 8.59 7.79 0 9.14 6.21 15.23 4.85 23.81 12.55 19.79 20.3 23.74 18.85 15.17 25 9.02"}),nr=r.jsx("path",{d:"M12.5,18.16l-7.73,5.61,2.95-9.08L0,9.07H9.55S12.5,0,12.5,0l2.95,9.07h9.55l-7.73,5.62,2.95,9.08-7.73-5.61Z"}),or=r.jsx("path",{d:"M112.46,57.88c-.23-.72-.88-1.22-1.63-1.27l-6.63-.46-2.45-6.19c-.27-.7-.95-1.16-1.7-1.16h0c-.75,0-1.42,.46-1.7,1.16l-2.5,6.23-6.58,.42c-.75,.05-1.4,.55-1.63,1.27-.24,.73,0,1.53,.58,2.02l5.07,4.28-1.51,5.92c-.21,.82,.1,1.69,.78,2.19,.66,.48,1.55,.5,2.24,.07l5.23-3.31h.02l5.63,3.56c.29,.19,.63,.29,.97,.29,1.02,0,1.83-.84,1.83-1.86,0-.16-.02-.31-.06-.47l-1.6-6.48,5.04-4.2c.59-.49,.82-1.29,.58-2.02Z"}),sr=r.jsx("path",{d:"M22.72,8.24h-6.68L13.97,1.88c-.81-2.51-2.13-2.51-2.95,0l-2.07,6.36H2.28c-2.63,0-3.04,1.25-.91,2.8l5.41,3.93-2.06,6.36c-.81,2.51,.25,3.28,2.39,1.73l5.41-3.93,5.41,3.93c2.13,1.55,3.2,.77,2.39-1.73l-2.07-6.36,5.41-3.93c2.13-1.55,1.72-2.8-.91-2.8Z"}),ar=r.jsx("path",{d:"M11.58,.77c.51-1.02,1.33-1.02,1.84,0l2.34,4.73c.5,1.02,1.84,2,2.98,2.16l5.22,.76c1.13,.17,1.39,.95,.57,1.75l-3.78,3.68c-.82,.8-1.33,2.37-1.14,3.5l.89,5.2c.19,1.13-.48,1.61-1.49,1.08l-4.67-2.45c-1.01-.53-2.67-.53-3.68,0l-4.67,2.46c-1.01,.53-1.68,.05-1.49-1.08l.89-5.2c.19-1.13-.32-2.7-1.14-3.5L.48,10.17c-.82-.8-.56-1.58,.57-1.75l5.22-.76c1.13-.16,2.47-1.14,2.98-2.16L11.58,.77h0Z"}),ir=r.jsx("path",{d:"M19.29,1.61c-2.15-2.15-5.63-2.15-7.78,0,0,0,0,0,0,0l-1.06,1.06-1.06-1.06C7.24-.54,3.76-.54,1.61,1.61-.54,3.76-.54,7.24,1.61,9.39l1.06,1.06,7.78,7.78,7.78-7.78,1.06-1.06c2.15-2.15,2.15-5.63,0-7.78,0,0,0,0,0,0Z"}),cr={itemShapes:tr,itemStrokeWidth:2,activeFillColor:"#ffb23f",inactiveFillColor:"#fff7ed",activeStrokeColor:"#e17b21",inactiveStrokeColor:"#eda76a"},lr=e.forwardRef((({value:o,items:a=5,readOnly:c=!1,onChange:f=t,onHoverChange:d=t,onFocus:w=t,onBlur:k=t,isDisabled:V=!1,highlightOnlySelected:H=!1,orientation:Z=E,spaceBetween:q=j,spaceInside:tr=I,radius:nr=j,transition:or=X,itemStyles:sr=cr,isRequired:ar=!1,halfFillMode:ir=A,visibleLabelId:lr,visibleItemLabelIds:ur,invisibleItemLabels:fr,invisibleLabel:dr=(c?o>0?`Rated ${o} on ${a}`:"Not rated":"Rating Selection"),resetLabel:hr="Reset rating",id:mr,className:pr,style:gr},br)=>{const xr=Array.from({length:a},((r,e)=>e+1)),yr=c&&!Number.isInteger(o),vr=yr&&!H,Sr=yr&&H?Math.round(o):o,Rr=!c&&!V,Br=Sr>=.25,Or="string"==typeof pr?pr:"",Lr="box"===ir?"box":A,Cr=vr&&(zr=Sr,!Number.isInteger(i(zr))),wr=!ar&&!c,kr=ar?a:a+1,Er=vr?function(r,e){const t=i(e);return Number.isInteger(t)?r.indexOf(t):Math.floor(t)}(xr,Sr):xr.indexOf(Sr),{staticColors:$r,arrayColors:Ar,itemShapes:jr,absoluteStrokeWidth:Ir,absoluteBoxBorderWidth:Fr}=e.useMemo((()=>{const{itemShapes:r,itemStrokeWidth:e,boxBorderWidth:t,...n}=sr,o=function(r){const e={...r},t={},n=Object.entries(e);if(n.length>0)for(const[o,s]of n)if(Array.isArray(s)||"string"==typeof s){if(Array.isArray(s))for(const r of Q)if(r===o){const r=s.filter((r=>"string"==typeof r));r.length>0&&(t[o]=r,delete e[o])}else delete e[o]}else delete e[o];return{arrayColors:t,staticColors:e}}(n);return{itemShapes:r,absoluteStrokeWidth:s(e),absoluteBoxBorderWidth:s(t),...o}}),[sr]),Dr=Object.keys(Ar).length>0,Mr=e.useCallback(((r,e)=>({dynamicClassNames:Cr?U(Sr,a,Lr):J(H,a,r),dynamicCssVars:e&&Dr?z(Ar,r,H):[]})),[Ar,Dr,H,Lr,Cr,a,Sr]),Nr=e.useCallback((()=>qr(_(kr,Er,!ar))),[Er,kr,ar]),Tr=e.useRef(!0),Wr=e.useRef(!0),Kr=e.useRef(null),Xr=e.useRef([]),Vr=e.useRef(!1),[Hr,Pr]=e.useState({staticCssVars:Y($r,Fr),...Mr(Er,Br)}),[Zr,qr]=e.useState((()=>Rr?_(kr,Er,!ar):[]));var zr;n((()=>{Rr&&Xr.current&&(Vr.current=function(r){return!!r&&"rtl"===getComputedStyle(r).getPropertyValue("direction")}(Xr.current[0]))}),[Rr]),e.useEffect((()=>{if(!Tr.current)return Pr({staticCssVars:Y($r,Fr),...Mr(Er,Br)});Tr.current=!1}),[$r,Mr,Fr,Er,Br]),e.useEffect((()=>{if(!Wr.current&&Rr)return Nr();Wr.current=!1}),[Rr,Nr]);const{shouldRender:Gr,reason:Jr}=function({items:r,itemShapes:t}){const n={shouldRender:!0,reason:""};if("number"!=typeof r||r<1||r>10)return rr(n,"items is invalid");if(!t)return rr(n,"itemStyles needs at least the property itemShapes set");if(!Array.isArray(t)&&!e.isValidElement(t))return rr(n,er);if(Array.isArray(t)){if(t.length!==r)return rr(n,"itemShapes length mismatch");if(!t.every((r=>e.isValidElement(r))))return rr(n,er)}return n}({items:a,itemShapes:jr});if(!Gr)return console.error(Jr),null;function Ur(r,e,t=(()=>{})){Xr.current.some((e=>e===r.relatedTarget))?t():e()}function Yr(){d(0),Nr()}function Qr(r){Ur(r,(()=>{Yr()})),Pr({...Hr,...Mr(Er,Br)})}function _r(r){Ur(r,(()=>{Yr(),k()}))}function re(r,e){const t=ar||e!==xr.length?e+1:0;Ur(r,(()=>{w(),d(t)}),(()=>{d(t)}))}function ee(r){qr(_(kr,r,!ar)),Xr.current[r].focus()}const te=function({className:r,radius:e,readOnly:t,isDisabled:n,isDynamic:o,transition:s,orientation:a,absoluteBoxBorderWidth:i,absoluteStrokeWidth:c,spaceBetween:l,spaceInside:u}){const f=o?"rr--pointer":"",d=function(r){switch(r){case I:return S;case F:return R;case D:return B;default:return""}}(l),w=function(r){switch(r){case I:return O;case F:return L;case D:return C;default:return""}}(u),k=!t&&n?"rr--disabled":"",E=o&&s!==N?function(r){switch(r){case T:return G(h);case W:return G(m);case K:return G(p);case X:return g;default:return""}}(s):"";return`rr--group ${a===$?"rr--dir-y":"rr--dir-x"} ${c>0?"rr--has-stroke":""} ${i>0?"rr--has-border":""}\n${E} ${function(r){switch(r){case I:return b;case F:return x;case D:return y;case M:return v;default:return""}}(e)} ${f} ${k} ${d}\n${w} ${r}`.replace(/ +/g," ").trimEnd()}({className:Or,radius:nr,readOnly:c,isDisabled:V,isDynamic:Rr,transition:or,orientation:Z,absoluteBoxBorderWidth:Fr,absoluteStrokeWidth:Ir,spaceBetween:q,spaceInside:tr});function ne(r){return{ref:e=>Xr.current[r]=e}}function oe(r){return{tabIndex:Zr[r],onKeyDown:e=>function(r,e){let t=0;const n=ar?xr.length-1:xr.length,o=e-1,s=e+1,a=!ar&&e===xr.length,i=0===e?n:o,c=n===e?0:s;switch(r.code){case"Shift":case"Tab":return!0;case"ArrowDown":case"ArrowRight":return t=Vr.current?i:c,ee(t);case"ArrowUp":case"ArrowLeft":return t=Vr.current?c:i,ee(t);case"Enter":case"Space":return r.preventDefault(),f(a?0:e+1)}r.preventDefault(),r.stopPropagation()}(e,r)}}function se(r){return{onClick:e=>{return t=r,e.stopPropagation(),void f(ar||Er!==t?t+1:0);var t},onMouseEnter:()=>{return d((e=r)+1),void Pr({...Hr,...Mr(e,!0)});var e},onMouseLeave:Qr}}function ae(r){if(c)return{};const e={};if(Array.isArray(ur))e["aria-labelledby"]=ur[r];else{const t=Array.isArray(fr)?fr:xr.map(((r,e)=>`Rate ${e+1}`));e["aria-label"]=t[r]}return V&&(e["aria-disabled"]="true"),{role:"radio","aria-checked":r+1===Sr,...e}}function ie(r){const e={itemShapes:Array.isArray(jr)?jr[r]:jr,itemStrokeWidth:Ir,orientation:Z,hasHF:!1,testId:{}};return Cr&&Lr===A&&(e.hasHF=r===Er),e}return r.jsx("div",{id:mr,className:te,style:{...gr,...Hr.staticCssVars},ref:function(r){Rr&&!ar&&(Kr.current=r),br&&(br.current=r)},...function(){if(!c){const r=ar&&!V,e={role:"radiogroup","aria-required":r};return r&&(e["aria-invalid"]=Sr<=0),"string"==typeof lr&&lr.length>0?e["aria-labelledby"]=lr:e["aria-label"]=dr,e}return{role:"img","aria-label":dr}}(),...l,children:xr.map(((t,n)=>{return r.jsxs(e.Fragment,{children:[r.jsx("div",{className:`rr--box ${Hr.dynamicClassNames[n]}`,style:Hr.dynamicCssVars[n],...ae(n),...(s=n,Rr?{...ne(s),...oe(s),...se(s),onFocus:r=>re(r,s),onBlur:r=>_r(r)}:{}),children:r.jsx(P,{...ie(n)})}),wr&&n===xr.length-1&&r.jsx("div",{...(o=n+1,{className:"rr--reset",role:"radio","aria-label":hr,"aria-checked":0===Sr,onClick:()=>f(0),onFocus:r=>{var e;re(r,o),null==(e=Kr.current)||e.classList.add(u)},onBlur:r=>{var e;_r(r),null==(e=Kr.current)||e.classList.remove(u)},...oe(o),...ne(o),...V?{"aria-disabled":"true"}:{}})})]},t);var o,s}))})}));lr.displayName="Rating",exports.Heart=ir,exports.Rating=lr,exports.RoundedStar=or,exports.Star=tr,exports.StickerStar=ar,exports.ThinRoundedStar=sr,exports.ThinStar=nr;
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),e=require("react"),t=r=>{},n="undefined"==typeof window?e.useEffect:e.useLayoutEffect,o=r=>"number"==typeof r&&r>0,s=r=>o(r)?r:0,a=r=>Math.round(100*r)/100,i=r=>Math.round(2*r)/2,c=r=>0===r?0:-1*a(r),l={},u="rr--focus-reset",f="rr--on",d="rr--off",h="rr--fx-zoom",m="rr--fx-position",p="rr--fx-opacity",g="rr--fx-colors",b="rr--rx-sm",x="rr--rx-md",y="rr--rx-lg",v="rr--rx-full",S="rr--gap-sm",R="rr--gap-md",B="rr--gap-lg",O="rr--space-sm",L="rr--space-md",C="rr--space-lg",w={FILL:"--rr--fill-on-color",BOX:"--rr--box-on-color",BORDER:"--rr--border-on-color",STROKE:"--rr--stroke-on-color"},k={FILL:"--rr--fill-off-color",BOX:"--rr--box-off-color",BORDER:"--rr--border-off-color",STROKE:"--rr--stroke-off-color"},E="horizontal",$="vertical",A="svg",j="none",I="small",D="medium",F="large",M="full",N="none",T="zoom",W="position",K="opacity",X="colors",V={FILL:"activeFillColor",BOX:"activeBoxColor",BORDER:"activeBoxBorderColor",STROKE:"activeStrokeColor"},H={FILL:"inactiveFillColor",BOX:"inactiveBoxColor",BORDER:"inactiveBoxBorderColor",STROKE:"inactiveStrokeColor"};function P({itemShapes:t,testId:o,itemStrokeWidth:s=0,orientation:i=E,hasHF:l=!1}){const u=s>0?-s/2:0,f=s>0?`${u} ${u}`:"0 0",d=e.useRef(null),h=e.useId(),[m,p]=e.useState(null);return n((()=>{if(d.current){const{width:r,height:e,x:t,y:n}=d.current.getBBox();if(((...r)=>r.every((r=>"number"==typeof r)))(r,e,t,n)){const o=`${f} ${a(r+s)} ${a(e+s)}`,i=`${c(t)} ${c(n)}`;p({viewBox:o,translateData:i})}}}),[t,s,l]),r.jsxs("svg",{"aria-hidden":"true",className:"rr--svg",xmlns:"http://www.w3.org/2000/svg",viewBox:m?m.viewBox:"0 0 0 0",preserveAspectRatio:"xMidYMid meet",...s>0?{strokeWidth:s}:{},...o,children:[l&&r.jsx("defs",{children:r.jsxs("linearGradient",{id:h,...i===$?{gradientTransform:"rotate(90)"}:{},children:[r.jsx("stop",{className:"rr--svg-stop-1",offset:"50%"}),r.jsx("stop",{className:"rr--svg-stop-2",offset:"50%"})]})}),r.jsx("g",{ref:d,shapeRendering:"geometricPrecision",...function(){if(m){const r=`translate(${null==m?void 0:m.translateData})`;return"translate(0 0)"===r?{}:{transform:r}}return{transform:void 0}}(),...l?{fill:`url('#${h}')`}:{},children:t})]})}function Z(r,e,t){switch(e){case V.FILL:return r[w.FILL]=t,!0;case V.BOX:return r[w.BOX]=t,!0;case V.BORDER:return r[w.BORDER]=t,!0;case V.STROKE:return r[w.STROKE]=t,!0}return!1}function q(r,e,t){if(!Z(r,e,t))switch(e){case H.FILL:r[k.FILL]=t;break;case H.BOX:r[k.BOX]=t;break;case H.BORDER:r[k.BORDER]=t;break;case H.STROKE:r[k.STROKE]=t}}function z(r,e,t){const n={};let o;for(const[s,a]of Object.entries(r))Z(n,s,a[e]);return t?(o=Array(e).fill({}),o.push(n)):o=Array(e+1).fill(n),o}const G=r=>`${r} ${g}`;function J(r,e,t){return Array.from({length:e},((e,n)=>r?n===t?f:d:n<=t?f:d))}function U(r,e,t){const n=Math.floor(i(r));return Array.from({length:e},((r,e)=>"box"===t?e>n?"rr--hf-box-off":e===n?"rr--hf-box-int":"rr--hf-box-on":e>n?"rr--hf-svg-off":"rr--hf-svg-on"))}function Y(r,e){const t={};o(e)&&(t["--rr--border-width"]=`${e}px`);const n=Object.entries(r);if(n.length>0)for(const[o,s]of n)q(t,o,s);return t}const Q=[V.FILL,V.BOX,V.STROKE,V.BORDER];function _(r,e,t=!1){return Array.from({length:r},((n,o)=>t&&e<0?o===r-1?0:-1:e<=0?0===o?0:-1:e>0?o===e?0:-1:void 0))}function rr(r,e){return r.shouldRender=!1,r.reason=(r=>`[@smastrom/react-rating] - Nothing's returned from rendering. Reason: ${r}.`)(e),r}const er="itemShapes is not a valid JSX element",tr=r.jsx("polygon",{points:"25 9.02 16.4 7.75 12.46 0 8.59 7.79 0 9.14 6.21 15.23 4.85 23.81 12.55 19.79 20.3 23.74 18.85 15.17 25 9.02"}),nr=r.jsx("path",{d:"M12.5,18.16l-7.73,5.61,2.95-9.08L0,9.07H9.55S12.5,0,12.5,0l2.95,9.07h9.55l-7.73,5.62,2.95,9.08-7.73-5.61Z"}),or=r.jsx("path",{d:"M112.46,57.88c-.23-.72-.88-1.22-1.63-1.27l-6.63-.46-2.45-6.19c-.27-.7-.95-1.16-1.7-1.16h0c-.75,0-1.42,.46-1.7,1.16l-2.5,6.23-6.58,.42c-.75,.05-1.4,.55-1.63,1.27-.24,.73,0,1.53,.58,2.02l5.07,4.28-1.51,5.92c-.21,.82,.1,1.69,.78,2.19,.66,.48,1.55,.5,2.24,.07l5.23-3.31h.02l5.63,3.56c.29,.19,.63,.29,.97,.29,1.02,0,1.83-.84,1.83-1.86,0-.16-.02-.31-.06-.47l-1.6-6.48,5.04-4.2c.59-.49,.82-1.29,.58-2.02Z"}),sr=r.jsx("path",{d:"M22.72,8.24h-6.68L13.97,1.88c-.81-2.51-2.13-2.51-2.95,0l-2.07,6.36H2.28c-2.63,0-3.04,1.25-.91,2.8l5.41,3.93-2.06,6.36c-.81,2.51,.25,3.28,2.39,1.73l5.41-3.93,5.41,3.93c2.13,1.55,3.2,.77,2.39-1.73l-2.07-6.36,5.41-3.93c2.13-1.55,1.72-2.8-.91-2.8Z"}),ar=r.jsx("path",{d:"M11.58,.77c.51-1.02,1.33-1.02,1.84,0l2.34,4.73c.5,1.02,1.84,2,2.98,2.16l5.22,.76c1.13,.17,1.39,.95,.57,1.75l-3.78,3.68c-.82,.8-1.33,2.37-1.14,3.5l.89,5.2c.19,1.13-.48,1.61-1.49,1.08l-4.67-2.45c-1.01-.53-2.67-.53-3.68,0l-4.67,2.46c-1.01,.53-1.68,.05-1.49-1.08l.89-5.2c.19-1.13-.32-2.7-1.14-3.5L.48,10.17c-.82-.8-.56-1.58,.57-1.75l5.22-.76c1.13-.16,2.47-1.14,2.98-2.16L11.58,.77h0Z"}),ir=r.jsx("path",{d:"M19.29,1.61c-2.15-2.15-5.63-2.15-7.78,0,0,0,0,0,0,0l-1.06,1.06-1.06-1.06C7.24-.54,3.76-.54,1.61,1.61-.54,3.76-.54,7.24,1.61,9.39l1.06,1.06,7.78,7.78,7.78-7.78,1.06-1.06c2.15-2.15,2.15-5.63,0-7.78,0,0,0,0,0,0Z"}),cr={itemShapes:tr,itemStrokeWidth:2,activeFillColor:"#ffb23f",inactiveFillColor:"#fff7ed",activeStrokeColor:"#e17b21",inactiveStrokeColor:"#eda76a"},lr=e.forwardRef((({value:o,items:a=5,readOnly:c=!1,onChange:f=t,onHoverChange:d=t,onFocus:w=t,onBlur:k=t,isDisabled:V=!1,highlightOnlySelected:H=!1,orientation:Z=E,spaceBetween:q=j,spaceInside:tr=I,radius:nr=j,transition:or=X,itemStyles:sr=cr,isRequired:ar=!1,halfFillMode:ir=A,visibleLabelId:lr,visibleItemLabelIds:ur,invisibleItemLabels:fr,invisibleLabel:dr=(c?o>0?`Rated ${o} on ${a}`:"Not rated":"Rating Selection"),resetLabel:hr="Reset rating",id:mr,className:pr,style:gr},br)=>{const xr=Array.from({length:a},((r,e)=>e+1)),yr=c&&!Number.isInteger(o),vr=yr&&!H,Sr=yr&&H?Math.round(o):o,Rr=!c&&!V,Br=Sr>=.25,Or="string"==typeof pr?pr:"",Lr="box"===ir?"box":A,Cr=vr&&(zr=Sr,!Number.isInteger(i(zr))),wr=!ar&&!c,kr=ar?a:a+1,Er=vr?function(r,e){const t=i(e);return Number.isInteger(t)?r.indexOf(t):Math.floor(t)}(xr,Sr):xr.indexOf(Sr),{staticColors:$r,arrayColors:Ar,itemShapes:jr,absoluteStrokeWidth:Ir,absoluteBoxBorderWidth:Dr}=e.useMemo((()=>{const{itemShapes:r,itemStrokeWidth:e,boxBorderWidth:t,...n}=sr,o=function(r){const e={...r},t={},n=Object.entries(e);if(n.length>0)for(const[o,s]of n)if(Array.isArray(s)||"string"==typeof s){if(Array.isArray(s))for(const r of Q)if(r===o){const r=s.filter((r=>"string"==typeof r));r.length>0&&(t[o]=r,delete e[o])}else delete e[o]}else delete e[o];return{arrayColors:t,staticColors:e}}(n);return{itemShapes:r,absoluteStrokeWidth:s(e),absoluteBoxBorderWidth:s(t),...o}}),[sr]),Fr=Object.keys(Ar).length>0,Mr=e.useCallback(((r,e)=>({dynamicClassNames:Cr?U(Sr,a,Lr):J(H,a,r),dynamicCssVars:e&&Fr?z(Ar,r,H):[]})),[Ar,Fr,H,Lr,Cr,a,Sr]),Nr=e.useCallback((()=>qr(_(kr,Er,!ar))),[Er,kr,ar]),Tr=e.useRef(!0),Wr=e.useRef(!0),Kr=e.useRef(null),Xr=e.useRef([]),Vr=e.useRef(!1),[Hr,Pr]=e.useState({staticCssVars:Y($r,Dr),...Mr(Er,Br)}),[Zr,qr]=e.useState((()=>Rr?_(kr,Er,!ar):[]));var zr;n((()=>{Rr&&Xr.current&&(Vr.current=function(r){return!!r&&"rtl"===getComputedStyle(r).getPropertyValue("direction")}(Xr.current[0]))}),[Rr]),e.useEffect((()=>{if(!Tr.current)return Pr({staticCssVars:Y($r,Dr),...Mr(Er,Br)});Tr.current=!1}),[$r,Mr,Dr,Er,Br]),e.useEffect((()=>{if(!Wr.current&&Rr)return Nr();Wr.current=!1}),[Rr,Nr]);const{shouldRender:Gr,reason:Jr}=function({items:r,itemShapes:t}){const n={shouldRender:!0,reason:""};if("number"!=typeof r||r<1||r>10)return rr(n,"items is invalid");if(!t)return rr(n,"itemStyles needs at least the property itemShapes set");if(!Array.isArray(t)&&!e.isValidElement(t))return rr(n,er);if(Array.isArray(t)){if(t.length!==r)return rr(n,"itemShapes length mismatch");if(!t.every((r=>e.isValidElement(r))))return rr(n,er)}return n}({items:a,itemShapes:jr});if(!Gr)return console.error(Jr),null;function Ur(r,e,t=(()=>{})){Xr.current.some((e=>e===r.relatedTarget))?t():e()}function Yr(){d(0),Nr()}function Qr(r){Ur(r,(()=>{Yr()})),Pr({...Hr,...Mr(Er,Br)})}function _r(r){Ur(r,(()=>{Yr(),k()}))}function re(r,e){const t=ar||e!==xr.length?e+1:0;Ur(r,(()=>{w(),d(t)}),(()=>{d(t)}))}function ee(r){qr(_(kr,r,!ar)),Xr.current[r].focus()}const te=function({className:r,radius:e,readOnly:t,isDisabled:n,isDynamic:o,transition:s,orientation:a,absoluteBoxBorderWidth:i,absoluteStrokeWidth:c,spaceBetween:l,spaceInside:u}){const f=o?"rr--pointer":"",d=function(r){switch(r){case I:return S;case D:return R;case F:return B;default:return""}}(l),w=function(r){switch(r){case I:return O;case D:return L;case F:return C;default:return""}}(u),k=!t&&n?"rr--disabled":"",E=o&&s!==N?function(r){switch(r){case T:return G(h);case W:return G(m);case K:return G(p);case X:return g;default:return""}}(s):"";return`rr--group ${a===$?"rr--dir-y":"rr--dir-x"} ${c>0?"rr--has-stroke":""} ${i>0?"rr--has-border":""}\n${E} ${function(r){switch(r){case I:return b;case D:return x;case F:return y;case M:return v;default:return""}}(e)} ${f} ${k} ${d}\n${w} ${r}`.replace(/ +/g," ").trimEnd()}({className:Or,radius:nr,readOnly:c,isDisabled:V,isDynamic:Rr,transition:or,orientation:Z,absoluteBoxBorderWidth:Dr,absoluteStrokeWidth:Ir,spaceBetween:q,spaceInside:tr});function ne(r){return{ref:e=>Xr.current[r]=e}}function oe(r){return{tabIndex:Zr[r],onKeyDown:e=>function(r,e){let t=0;const n=ar?xr.length-1:xr.length,o=e-1,s=e+1,a=!ar&&e===xr.length,i=0===e?n:o,c=n===e?0:s;switch(r.code){case"Shift":case"Tab":return!0;case"ArrowDown":case"ArrowRight":return t=Vr.current?i:c,ee(t);case"ArrowUp":case"ArrowLeft":return t=Vr.current?c:i,ee(t);case"Enter":case"Space":return r.preventDefault(),f(a?0:e+1)}r.preventDefault(),r.stopPropagation()}(e,r)}}function se(r){return{onClick:e=>{return n=r,(t=e).preventDefault(),t.stopPropagation(),void f(ar||Er!==n?n+1:0);var t,n},onMouseEnter:()=>{return d((e=r)+1),void Pr({...Hr,...Mr(e,!0)});var e},onMouseLeave:Qr}}function ae(r){if(c)return{};const e={};if(Array.isArray(ur))e["aria-labelledby"]=ur[r];else{const t=Array.isArray(fr)?fr:xr.map(((r,e)=>`Rate ${e+1}`));e["aria-label"]=t[r]}return V&&(e["aria-disabled"]="true"),{role:"radio","aria-checked":r+1===Sr,...e}}function ie(r){const e={itemShapes:Array.isArray(jr)?jr[r]:jr,itemStrokeWidth:Ir,orientation:Z,hasHF:!1,testId:{}};return Cr&&Lr===A&&(e.hasHF=r===Er),e}return r.jsx("div",{id:mr,className:te,style:{...gr,...Hr.staticCssVars},ref:function(r){Rr&&!ar&&(Kr.current=r),br&&(br.current=r)},...function(){if(!c){const r=ar&&!V,e={role:"radiogroup","aria-required":r};return r&&(e["aria-invalid"]=Sr<=0),"string"==typeof lr&&lr.length>0?e["aria-labelledby"]=lr:e["aria-label"]=dr,e}return{role:"img","aria-label":dr}}(),...l,children:xr.map(((t,n)=>{return r.jsxs(e.Fragment,{children:[r.jsx("div",{className:`rr--box ${Hr.dynamicClassNames[n]}`,style:Hr.dynamicCssVars[n],...ae(n),...(s=n,Rr?{...ne(s),...oe(s),...se(s),onFocus:r=>re(r,s),onBlur:r=>_r(r)}:{}),children:r.jsx(P,{...ie(n)})}),wr&&n===xr.length-1&&r.jsx("div",{...(o=n+1,{className:"rr--reset",role:"radio","aria-label":hr,"aria-checked":0===Sr,onClick:()=>f(0),onFocus:r=>{var e;re(r,o),null==(e=Kr.current)||e.classList.add(u)},onBlur:r=>{var e;_r(r),null==(e=Kr.current)||e.classList.remove(u)},...oe(o),...ne(o),...V?{"aria-disabled":"true"}:{}})})]},t);var o,s}))})}));lr.displayName="Rating",exports.Heart=ir,exports.Rating=lr,exports.RoundedStar=or,exports.Star=tr,exports.StickerStar=ar,exports.ThinRoundedStar=sr,exports.ThinStar=nr;
{
"name": "@smastrom/react-rating",
"version": "1.3.2",
"version": "1.3.3",
"private": false,

@@ -5,0 +5,0 @@ "keywords": [

@@ -10,3 +10,3 @@ ![react-rating-version](https://img.shields.io/npm/v/@smastrom/react-rating?color=22C55E) ![react-rating-build-workflow](https://img.shields.io/github/actions/workflow/status/smastrom/react-rating/build.yml?branch=main&color=22C55E)

[Demo and Examples](https://react-rating.onrender.com/) — [NextJS Page Router](https://stackblitz.com/edit/nextjs-5qw9id?file=pages/index.tsx) — [Vite](https://stackblitz.com/edit/vitejs-vite-gwqytd?file=src/App.tsx)
[Demo and Examples](https://react-rating-buo7.onrender.com/) — [NextJS Page Router](https://stackblitz.com/edit/nextjs-5qw9id?file=pages/index.tsx) — [Vite](https://stackblitz.com/edit/vitejs-vite-gwqytd?file=src/App.tsx)

@@ -93,3 +93,3 @@ <br />

```tsx
import '@smastrom/react-rating/style.css' // Import it only once in the whole app
import '@smastrom/react-rating/style.css'
```

@@ -133,3 +133,3 @@

```tsx
import '@smastrom/react-rating/style.css' // Import it only once in the whole app
import '@smastrom/react-rating/style.css'
```

@@ -136,0 +136,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc