Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-star

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-star - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

1

dist/models.d.ts

@@ -8,1 +8,2 @@ export declare const DEFAULT_MIN = 0;

export declare const NO_OPERATION: () => void;
export declare const DEFAULT_OTHER = 0;

2

dist/react-star.es.js

@@ -15,2 +15,2 @@ import t from"react";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,n){return Math.floor((e-t)/n)}function a(e){return t.isValidElement(e)?e:"object"==typeof e&&null!==e?t.createElement("span",{style:e}):"[object String]"===Object.prototype.toString.call(e)?t.createElement("span",{className:e}):null}var r=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return n(o,e),o.prototype.render=function(){var e,n=this.props,o=n.readOnly,i=n.onClick,r=n.index,l=n.onMouseMove,c=n.onTouchEnd,s=n.percent,p=n.emptyIcon,u=n.icon,h=s<100?{}:{visibility:"hidden"},d=((e={display:"inline-block",position:"absolute",overflow:"hidden",top:0})["rtl"===n.direction?"right":"left"]=0,e.width=s+"%",e),f={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function v(t){l&&l(r,t)}return t.createElement("span",{style:0===r?Object.assign({},f,{marginLeft:0}):f,onClick:function(t){i&&(t.preventDefault(),i(r,t))},onMouseMove:v,onTouchMove:v,onTouchEnd:function(t){c&&c(r,t)}},t.createElement("span",{style:h},a(p)),t.createElement("span",{style:d},a(u)))},o}(t.PureComponent),l=function(e){function i(t){var n=e.call(this,t)||this;return n.state={displayValue:n.props.value,interacting:!1},n.onMouseLeave=n.onMouseLeave.bind(n),n.iconClick=n.iconClick.bind(n),n.iconMouseMove=n.iconMouseMove.bind(n),n.iconEnd=n.iconEnd.bind(n),n}return n(i,e),i.prototype.onMouseLeave=function(){this.setState({displayValue:this.props.value,interacting:!1})},i.prototype.calculateHoverPercentage=function(t){var e=t.nativeEvent.type.indexOf("touch")>-1?t.nativeEvent.type.indexOf("touchend")>-1?t.changedTouches[0].clientX:t.touches[0].clientX:t.clientX,n=t.target.getBoundingClientRect(),o="rtl"===this.props.direction?n.right-e:e-n.left;return o<0?0:o/n.width},i.prototype.calculateDisplayValue=function(t,e){var n=this.calculateHoverPercentage(e),o=Math.ceil(n%1*this.props.fraction)/this.props.fraction,i=Math.pow(10,3),a=t+(Math.floor(n)+Math.floor(o*i)/i);return a>0?a>this.props.totalIcons?this.props.totalIcons:a:1/this.props.fraction},i.prototype.iconClick=function(t,e){var n=this.calculateDisplayValue(t,e);this.props.onClick(n,e)},i.prototype.iconMouseMove=function(t,e){var n=this.calculateDisplayValue(t,e);this.setState({interacting:!this.props.readOnly,displayValue:n})},i.prototype.iconEnd=function(t,e){this.props.quiet||(this.iconClick(t,e),e.preventDefault()),this.onMouseLeave()},i.prototype.UNSAFE_componentWillReceiveProps=function(t){var e=this.props.value!==t.value;this.setState((function(n){return{displayValue:e?t.value:n.displayValue}}))},i.prototype.componentDidUpdate=function(t,e){if(e.interacting&&!this.state.interacting)return this.props.onHover();this.state.interacting&&t.value==this.props.value&&this.props.onHover(this.state.displayValue)},i.prototype.render=function(){var e,n=this.props,i=n.id,a=n.style,l=n.direction,c=n.className,s=n.tabIndex,p=n.readOnly,u=n.totalIcons,h=n.emptyIcon,d=n.placeholderValue,f=n.value,v=n.placeholderIcon,y=n.icon,m=n.quiet,g=this.state,M=g.interacting,b=g.displayValue,V=[],E=[].concat(h),k=0!==d&&0===f&&!M,C=[].concat(v),O=[].concat(y);e=k?d:m?f:b;for(var I=Math.floor(e),w=0;w<u;w++){var x=void 0;x=w-I<0?100:w-I==0?100*(e-w):0,V.push(t.createElement(r,o({key:w,index:w,readOnly:p,emptyIcon:E[w%E.length],icon:k?C[w%O.length]:O[w%O.length],percent:x,direction:l},!p&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return t.createElement("span",o({id:""+i,style:o(o({},a),{display:"inline-block",outline:"none",direction:l}),className:c,tabIndex:s},!p&&{onMouseLeave:this.onMouseLeave}),V)},i}(t.PureComponent);function c(e){return t.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",style:e.style},t.createElement("path",{d:"M12 .288l2.833 8.718H24l-7.417 5.389 2.833 8.718L12 17.725l-7.417 5.388 2.833-8.718L0 9.006h9.167z"}))}var s=function(){},p=function(e){function o(t){var n=e.call(this,t)||this;return n.state={value:n.props.defaultValue},n.handleClick=n.handleClick.bind(n),n.handleHover=n.handleHover.bind(n),n}return n(o,e),o.prototype.tranlateValueToDisplayValue=function(t){if(void 0===t)return 0;var e=this.props,n=e.min,o=e.step;return n&&o?(t-n)/o:t},o.prototype.handleClick=function(t){var e=this,n=this.translateDisplayValueToValue(t||0);this.props.onClick(n),this.state.value!==n&&this.setState({value:n},(function(){return e.props.onChange(e.state.value)}))},o.prototype.handleHover=function(t){var e=void 0===t?t:this.translateDisplayValueToValue(t);this.props.onHover(e)},o.prototype.translateDisplayValueToValue=function(t){var e,n=this.props,o=n.min,i=n.step,a=n.fraction;return(e=t*(i||1)+(o||0))===o?e+1/(a||1):e},o.prototype.render=function(){var e=this.props,n=e.step,o=e.emptyIcon,a=e.icon,r=e.placeholderIcon,c=e.readOnly,s=e.quiet,p=e.fraction,u=e.direction,h=e.min,d=e.max,f=e.id,v=e.className,y=e.style,m=e.tabIndex;return t.createElement(l,{id:f||0,style:y,className:v,tabIndex:m||0,totalIcons:i(h||0,d||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:c||!1,quiet:s||!1,fraction:p||1,direction:u||"",emptyIcon:o||"",icon:a||"",placeholderIcon:r||"",onClick:this.handleClick,onHover:this.handleHover})},o.defaultProps={min:0,max:5,step:1,readOnly:!1,fraction:1,emptyIcon:t.createElement(c,{style:{fill:"#000000",stroke:"#000000",opacity:"26%"}}),icon:t.createElement(c,{style:{fill:"#ffb400",stroke:"#ffb400"}}),placeholderIcon:t.createElement(c,{style:{fill:"#ffb400",stroke:"#ffb400"}}),quiet:!1,direction:"ltr",onHover:s,onClick:s,onChange:s},o}(t.PureComponent);export{p as Star};
***************************************************************************** */var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e,n){return Math.floor((e-t)/n)}function a(e){return t.isValidElement(e)?e:"object"==typeof e&&null!==e?t.createElement("span",{style:e}):"[object String]"===Object.prototype.toString.call(e)?t.createElement("span",{className:e}):null}var r=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return n(o,e),o.prototype.render=function(){var e,n=this.props,o=n.readOnly,i=n.onClick,r=n.index,l=n.onMouseMove,c=n.onTouchEnd,s=n.percent,p=n.emptyIcon,u=n.icon,h=s<100?{}:{visibility:"hidden"},d=((e={display:"inline-block",position:"absolute",overflow:"hidden",top:0})["rtl"===n.direction?"right":"left"]=0,e.width=s+"%",e),v={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function f(t){l&&l(r,t)}return t.createElement("span",{style:0===r?Object.assign({},v,{marginLeft:0}):v,onClick:function(t){i&&(t.preventDefault(),i(r,t))},onMouseMove:f,onTouchMove:f,onTouchEnd:function(t){c&&c(r,t)}},t.createElement("span",{style:h},a(p)),t.createElement("span",{style:d},a(u)))},o}(t.PureComponent),l=function(e){function i(t){var n=e.call(this,t)||this;return n.state={displayValue:n.props.value,interacting:!1},n.onMouseLeave=n.onMouseLeave.bind(n),n.iconClick=n.iconClick.bind(n),n.iconMouseMove=n.iconMouseMove.bind(n),n.iconEnd=n.iconEnd.bind(n),n}return n(i,e),i.prototype.onMouseLeave=function(){this.setState({displayValue:this.props.value,interacting:!1})},i.prototype.calculateHoverPercentage=function(t){var e=t.nativeEvent.type.indexOf("touch")>-1?t.nativeEvent.type.indexOf("touchend")>-1?t.changedTouches[0].clientX:t.touches[0].clientX:t.clientX,n=t.target.getBoundingClientRect(),o="rtl"===this.props.direction?n.right-e:e-n.left;return o<0?0:o/n.width},i.prototype.calculateDisplayValue=function(t,e){var n=this.calculateHoverPercentage(e),o=Math.ceil(n%1*this.props.fraction)/this.props.fraction,i=Math.pow(10,3),a=t+(Math.floor(n)+Math.floor(o*i)/i);return a>0?a>this.props.totalIcons?this.props.totalIcons:a:1/this.props.fraction},i.prototype.iconClick=function(t,e){var n=this.calculateDisplayValue(t,e);this.props.onClick(n,e)},i.prototype.iconMouseMove=function(t,e){var n=this.calculateDisplayValue(t,e);this.setState({interacting:!this.props.readOnly,displayValue:n})},i.prototype.iconEnd=function(t,e){this.props.quiet||(this.iconClick(t,e),e.preventDefault()),this.onMouseLeave()},i.prototype.UNSAFE_componentWillReceiveProps=function(t){var e=this.props.value!==t.value;this.setState((function(n){return{displayValue:e?t.value:n.displayValue}}))},i.prototype.componentDidUpdate=function(t,e){if(e.interacting&&!this.state.interacting)return this.props.onHover();this.state.interacting&&t.value==this.props.value&&this.props.onHover(this.state.displayValue)},i.prototype.render=function(){var e,n=this.props,i=n.id,a=n.style,l=n.direction,c=n.className,s=n.tabIndex,p=n.readOnly,u=n.totalIcons,h=n.emptyIcon,d=n.placeholderValue,v=n.value,f=n.placeholderIcon,y=n.icon,m=n.quiet,g=this.state,M=g.interacting,b=g.displayValue,V=[],E=[].concat(h),k=0!==d&&0===v&&!M,C=[].concat(f),O=[].concat(y);e=k?d:m?v:b;for(var I=Math.floor(e),w=0;w<u;w++){var x=void 0;x=w-I<0?100:w-I==0?100*(e-w):0,V.push(t.createElement(r,o({key:w,index:w,readOnly:p,emptyIcon:E[w%E.length],icon:k?C[w%O.length]:O[w%O.length],percent:x,direction:l},!p&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return t.createElement("span",o({id:""+i,style:o(o({},a),{display:"inline-block",outline:"none",direction:l}),className:c,tabIndex:s},!p&&{onMouseLeave:this.onMouseLeave}),V)},i}(t.PureComponent);function c(e){return t.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",style:e.style},t.createElement("path",{d:"M12 .288l2.833 8.718H24l-7.417 5.389 2.833 8.718L12 17.725l-7.417 5.388 2.833-8.718L0 9.006h9.167z"}))}var s=function(){},p=function(e){function o(t){var n=e.call(this,t)||this;return n.state={value:n.props.defaultValue},n.handleClick=n.handleClick.bind(n),n.handleHover=n.handleHover.bind(n),n}return n(o,e),o.prototype.tranlateValueToDisplayValue=function(t){if(void 0===t)return 0;var e=this.props,n=e.min,o=e.step;return n&&o?(t-n)/o:t},o.prototype.handleClick=function(t){var e=this,n=this.translateDisplayValueToValue(t||0);n===this.state.value&&(n=0),this.props.onClick(n),this.state.value!==n&&this.setState({value:n},(function(){return e.props.onChange(e.state.value)}))},o.prototype.handleHover=function(t){var e=void 0===t?t:this.translateDisplayValueToValue(t);this.props.onHover(e)},o.prototype.translateDisplayValueToValue=function(t){var e,n=this.props,o=n.min,i=n.step,a=n.fraction;return(e=t*(i||1)+(o||0))===o?e+1/(a||1):e},o.prototype.render=function(){var e=this.props,n=e.step,o=e.emptyIcon,a=e.icon,r=e.placeholderIcon,c=e.readOnly,s=e.quiet,p=e.fraction,u=e.direction,h=e.min,d=e.max,v=e.id,f=e.className,y=e.style,m=e.tabIndex;return t.createElement(l,{id:v||0,style:y,className:f,tabIndex:m||0,totalIcons:i(h||0,d||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:c||!1,quiet:s||!1,fraction:p||1,direction:u||"",emptyIcon:o||"",icon:a||"",placeholderIcon:r||"",onClick:this.handleClick,onHover:this.handleHover})},o.defaultProps={min:0,max:5,step:1,readOnly:!1,fraction:1,emptyIcon:t.createElement(c,{style:{fill:"#000000",stroke:"#000000",opacity:"26%"}}),icon:t.createElement(c,{style:{fill:"#ffb400",stroke:"#ffb400"}}),placeholderIcon:t.createElement(c,{style:{fill:"#ffb400",stroke:"#ffb400"}}),quiet:!1,direction:"ltr",onHover:s,onClick:s,onChange:s},o}(t.PureComponent);export{p as Star};

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("react")),n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};
/*! *****************************************************************************

@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function o(e,t){function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var i=function(){return(i=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function a(e,t,n){return Math.floor((t-e)/n)}function r(e){return t.default.isValidElement(e)?e:"object"==typeof e&&null!==e?t.default.createElement("span",{style:e}):"[object String]"===Object.prototype.toString.call(e)?t.default.createElement("span",{className:e}):null}var l=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return o(n,e),n.prototype.render=function(){var e,n=this.props,o=n.readOnly,i=n.onClick,a=n.index,l=n.onMouseMove,c=n.onTouchEnd,s=n.percent,u=n.emptyIcon,p=n.icon,h=s<100?{}:{visibility:"hidden"},d=((e={display:"inline-block",position:"absolute",overflow:"hidden",top:0})["rtl"===n.direction?"right":"left"]=0,e.width=s+"%",e),f={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function v(e){l&&l(a,e)}return t.default.createElement("span",{style:0===a?Object.assign({},f,{marginLeft:0}):f,onClick:function(e){i&&(e.preventDefault(),i(a,e))},onMouseMove:v,onTouchMove:v,onTouchEnd:function(e){c&&c(a,e)}},t.default.createElement("span",{style:h},r(u)),t.default.createElement("span",{style:d},r(p)))},n}(t.default.PureComponent),c=function(e){function n(t){var n=e.call(this,t)||this;return n.state={displayValue:n.props.value,interacting:!1},n.onMouseLeave=n.onMouseLeave.bind(n),n.iconClick=n.iconClick.bind(n),n.iconMouseMove=n.iconMouseMove.bind(n),n.iconEnd=n.iconEnd.bind(n),n}return o(n,e),n.prototype.onMouseLeave=function(){this.setState({displayValue:this.props.value,interacting:!1})},n.prototype.calculateHoverPercentage=function(e){var t=e.nativeEvent.type.indexOf("touch")>-1?e.nativeEvent.type.indexOf("touchend")>-1?e.changedTouches[0].clientX:e.touches[0].clientX:e.clientX,n=e.target.getBoundingClientRect(),o="rtl"===this.props.direction?n.right-t:t-n.left;return o<0?0:o/n.width},n.prototype.calculateDisplayValue=function(e,t){var n=this.calculateHoverPercentage(t),o=Math.ceil(n%1*this.props.fraction)/this.props.fraction,i=Math.pow(10,3),a=e+(Math.floor(n)+Math.floor(o*i)/i);return a>0?a>this.props.totalIcons?this.props.totalIcons:a:1/this.props.fraction},n.prototype.iconClick=function(e,t){var n=this.calculateDisplayValue(e,t);this.props.onClick(n,t)},n.prototype.iconMouseMove=function(e,t){var n=this.calculateDisplayValue(e,t);this.setState({interacting:!this.props.readOnly,displayValue:n})},n.prototype.iconEnd=function(e,t){this.props.quiet||(this.iconClick(e,t),t.preventDefault()),this.onMouseLeave()},n.prototype.UNSAFE_componentWillReceiveProps=function(e){var t=this.props.value!==e.value;this.setState((function(n){return{displayValue:t?e.value:n.displayValue}}))},n.prototype.componentDidUpdate=function(e,t){if(t.interacting&&!this.state.interacting)return this.props.onHover();this.state.interacting&&e.value==this.props.value&&this.props.onHover(this.state.displayValue)},n.prototype.render=function(){var e,n=this.props,o=n.id,a=n.style,r=n.direction,c=n.className,s=n.tabIndex,u=n.readOnly,p=n.totalIcons,h=n.emptyIcon,d=n.placeholderValue,f=n.value,v=n.placeholderIcon,y=n.icon,m=n.quiet,g=this.state,M=g.interacting,b=g.displayValue,V=[],E=[].concat(h),k=0!==d&&0===f&&!M,C=[].concat(v),O=[].concat(y);e=k?d:m?f:b;for(var I=Math.floor(e),x=0;x<p;x++){var w=void 0;w=x-I<0?100:x-I==0?100*(e-x):0,V.push(t.default.createElement(l,i({key:x,index:x,readOnly:u,emptyIcon:E[x%E.length],icon:k?C[x%O.length]:O[x%O.length],percent:w,direction:r},!u&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return t.default.createElement("span",i({id:""+o,style:i(i({},a),{display:"inline-block",outline:"none",direction:r}),className:c,tabIndex:s},!u&&{onMouseLeave:this.onMouseLeave}),V)},n}(t.default.PureComponent);function s(e){return t.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",style:e.style},t.default.createElement("path",{d:"M12 .288l2.833 8.718H24l-7.417 5.389 2.833 8.718L12 17.725l-7.417 5.388 2.833-8.718L0 9.006h9.167z"}))}var u=function(){},p=function(e){function n(t){var n=e.call(this,t)||this;return n.state={value:n.props.defaultValue},n.handleClick=n.handleClick.bind(n),n.handleHover=n.handleHover.bind(n),n}return o(n,e),n.prototype.tranlateValueToDisplayValue=function(e){if(void 0===e)return 0;var t=this.props,n=t.min,o=t.step;return n&&o?(e-n)/o:e},n.prototype.handleClick=function(e){var t=this,n=this.translateDisplayValueToValue(e||0);this.props.onClick(n),this.state.value!==n&&this.setState({value:n},(function(){return t.props.onChange(t.state.value)}))},n.prototype.handleHover=function(e){var t=void 0===e?e:this.translateDisplayValueToValue(e);this.props.onHover(t)},n.prototype.translateDisplayValueToValue=function(e){var t,n=this.props,o=n.min,i=n.step,a=n.fraction;return(t=e*(i||1)+(o||0))===o?t+1/(a||1):t},n.prototype.render=function(){var e=this.props,n=e.step,o=e.emptyIcon,i=e.icon,r=e.placeholderIcon,l=e.readOnly,s=e.quiet,u=e.fraction,p=e.direction,h=e.min,d=e.max,f=e.id,v=e.className,y=e.style,m=e.tabIndex;return t.default.createElement(c,{id:f||0,style:y,className:v,tabIndex:m||0,totalIcons:a(h||0,d||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:l||!1,quiet:s||!1,fraction:u||1,direction:p||"",emptyIcon:o||"",icon:i||"",placeholderIcon:r||"",onClick:this.handleClick,onHover:this.handleHover})},n.defaultProps={min:0,max:5,step:1,readOnly:!1,fraction:1,emptyIcon:t.default.createElement(s,{style:{fill:"#000000",stroke:"#000000",opacity:"26%"}}),icon:t.default.createElement(s,{style:{fill:"#ffb400",stroke:"#ffb400"}}),placeholderIcon:t.default.createElement(s,{style:{fill:"#ffb400",stroke:"#ffb400"}}),quiet:!1,direction:"ltr",onHover:u,onClick:u,onChange:u},n}(t.default.PureComponent);exports.Star=p;
***************************************************************************** */function o(t,e){function o(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function a(t,e,n){return Math.floor((e-t)/n)}function r(t){return e.default.isValidElement(t)?t:"object"==typeof t&&null!==t?e.default.createElement("span",{style:t}):"[object String]"===Object.prototype.toString.call(t)?e.default.createElement("span",{className:t}):null}var l=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return o(n,t),n.prototype.render=function(){var t,n=this.props,o=n.readOnly,i=n.onClick,a=n.index,l=n.onMouseMove,s=n.onTouchEnd,c=n.percent,u=n.emptyIcon,p=n.icon,h=c<100?{}:{visibility:"hidden"},d=((t={display:"inline-block",position:"absolute",overflow:"hidden",top:0})["rtl"===n.direction?"right":"left"]=0,t.width=c+"%",t),f={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function v(t){l&&l(a,t)}return e.default.createElement("span",{style:0===a?Object.assign({},f,{marginLeft:0}):f,onClick:function(t){i&&(t.preventDefault(),i(a,t))},onMouseMove:v,onTouchMove:v,onTouchEnd:function(t){s&&s(a,t)}},e.default.createElement("span",{style:h},r(u)),e.default.createElement("span",{style:d},r(p)))},n}(e.default.PureComponent),s=function(t){function n(e){var n=t.call(this,e)||this;return n.state={displayValue:n.props.value,interacting:!1},n.onMouseLeave=n.onMouseLeave.bind(n),n.iconClick=n.iconClick.bind(n),n.iconMouseMove=n.iconMouseMove.bind(n),n.iconEnd=n.iconEnd.bind(n),n}return o(n,t),n.prototype.onMouseLeave=function(){this.setState({displayValue:this.props.value,interacting:!1})},n.prototype.calculateHoverPercentage=function(t){var e=t.nativeEvent.type.indexOf("touch")>-1?t.nativeEvent.type.indexOf("touchend")>-1?t.changedTouches[0].clientX:t.touches[0].clientX:t.clientX,n=t.target.getBoundingClientRect(),o="rtl"===this.props.direction?n.right-e:e-n.left;return o<0?0:o/n.width},n.prototype.calculateDisplayValue=function(t,e){var n=this.calculateHoverPercentage(e),o=Math.ceil(n%1*this.props.fraction)/this.props.fraction,i=Math.pow(10,3),a=t+(Math.floor(n)+Math.floor(o*i)/i);return a>0?a>this.props.totalIcons?this.props.totalIcons:a:1/this.props.fraction},n.prototype.iconClick=function(t,e){var n=this.calculateDisplayValue(t,e);this.props.onClick(n,e)},n.prototype.iconMouseMove=function(t,e){var n=this.calculateDisplayValue(t,e);this.setState({interacting:!this.props.readOnly,displayValue:n})},n.prototype.iconEnd=function(t,e){this.props.quiet||(this.iconClick(t,e),e.preventDefault()),this.onMouseLeave()},n.prototype.UNSAFE_componentWillReceiveProps=function(t){var e=this.props.value!==t.value;this.setState((function(n){return{displayValue:e?t.value:n.displayValue}}))},n.prototype.componentDidUpdate=function(t,e){if(e.interacting&&!this.state.interacting)return this.props.onHover();this.state.interacting&&t.value==this.props.value&&this.props.onHover(this.state.displayValue)},n.prototype.render=function(){var t,n=this.props,o=n.id,a=n.style,r=n.direction,s=n.className,c=n.tabIndex,u=n.readOnly,p=n.totalIcons,h=n.emptyIcon,d=n.placeholderValue,f=n.value,v=n.placeholderIcon,y=n.icon,m=n.quiet,g=this.state,M=g.interacting,b=g.displayValue,V=[],E=[].concat(h),k=0!==d&&0===f&&!M,C=[].concat(v),O=[].concat(y);t=k?d:m?f:b;for(var I=Math.floor(t),x=0;x<p;x++){var w=void 0;w=x-I<0?100:x-I==0?100*(t-x):0,V.push(e.default.createElement(l,i({key:x,index:x,readOnly:u,emptyIcon:E[x%E.length],icon:k?C[x%O.length]:O[x%O.length],percent:w,direction:r},!u&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return e.default.createElement("span",i({id:""+o,style:i(i({},a),{display:"inline-block",outline:"none",direction:r}),className:s,tabIndex:c},!u&&{onMouseLeave:this.onMouseLeave}),V)},n}(e.default.PureComponent);function c(t){return e.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",style:t.style},e.default.createElement("path",{d:"M12 .288l2.833 8.718H24l-7.417 5.389 2.833 8.718L12 17.725l-7.417 5.388 2.833-8.718L0 9.006h9.167z"}))}var u=function(){},p=function(t){function n(e){var n=t.call(this,e)||this;return n.state={value:n.props.defaultValue},n.handleClick=n.handleClick.bind(n),n.handleHover=n.handleHover.bind(n),n}return o(n,t),n.prototype.tranlateValueToDisplayValue=function(t){if(void 0===t)return 0;var e=this.props,n=e.min,o=e.step;return n&&o?(t-n)/o:t},n.prototype.handleClick=function(t){var e=this,n=this.translateDisplayValueToValue(t||0);n===this.state.value&&(n=0),this.props.onClick(n),this.state.value!==n&&this.setState({value:n},(function(){return e.props.onChange(e.state.value)}))},n.prototype.handleHover=function(t){var e=void 0===t?t:this.translateDisplayValueToValue(t);this.props.onHover(e)},n.prototype.translateDisplayValueToValue=function(t){var e,n=this.props,o=n.min,i=n.step,a=n.fraction;return(e=t*(i||1)+(o||0))===o?e+1/(a||1):e},n.prototype.render=function(){var t=this.props,n=t.step,o=t.emptyIcon,i=t.icon,r=t.placeholderIcon,l=t.readOnly,c=t.quiet,u=t.fraction,p=t.direction,h=t.min,d=t.max,f=t.id,v=t.className,y=t.style,m=t.tabIndex;return e.default.createElement(s,{id:f||0,style:y,className:v,tabIndex:m||0,totalIcons:a(h||0,d||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:l||!1,quiet:c||!1,fraction:u||1,direction:p||"",emptyIcon:o||"",icon:i||"",placeholderIcon:r||"",onClick:this.handleClick,onHover:this.handleHover})},n.defaultProps={min:0,max:5,step:1,readOnly:!1,fraction:1,emptyIcon:e.default.createElement(c,{style:{fill:"#000000",stroke:"#000000",opacity:"26%"}}),icon:e.default.createElement(c,{style:{fill:"#ffb400",stroke:"#ffb400"}}),placeholderIcon:e.default.createElement(c,{style:{fill:"#ffb400",stroke:"#ffb400"}}),quiet:!1,direction:"ltr",onHover:u,onClick:u,onChange:u},n}(e.default.PureComponent);exports.Star=p;
{
"name": "react-star",
"version": "1.0.1",
"version": "1.0.2",
"description": "A tiny star rating component with custom icons for React.",

@@ -5,0 +5,0 @@ "author": "Bunlong <bunlong.van@gmail.com>",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc