Comparing version 1.0.6 to 1.1.0
@@ -15,2 +15,2 @@ import e from"react"; | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var t=function(e,n){return(t=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,n)};function n(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function a(e,t,n){return Math.floor((t-e)/n)}function i(t){return e.isValidElement(t)?t:"object"==typeof t&&null!==t?e.createElement("span",{style:t}):"[object String]"===Object.prototype.toString.call(t)?e.createElement("span",{className:t}):null}var l=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return n(o,t),o.prototype.render=function(){var t,n=this.props,o=n.readOnly,a=n.onClick,l=n.index,r=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}).left=0,t.width=c+"%",t),f={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function v(e){r&&r(l,e)}return e.createElement("span",{style:0===l?Object.assign({},f,{marginLeft:0}):f,onClick:function(e){a&&(e.preventDefault(),a(l,e))},onMouseMove:v,onTouchMove:v,onTouchEnd:function(e){s&&s(l,e)}},e.createElement("span",{style:h},i(u)),e.createElement("span",{style:d},i(p)))},o}(e.PureComponent),r=function(t){function a(e){var n=t.call(this,e)||this;return n.state={displayValue:n.props.value,interacting:!1,value:n.props.value},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(a,t),a.prototype.onMouseLeave=function(){this.setState({displayValue:this.props.value,interacting:!1})},a.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=t-n.left;return o<0?0:o/n.width},a.prototype.calculateDisplayValue=function(e,t){var n=this.calculateHoverPercentage(t),o=Math.ceil(n%1*this.props.fraction)/this.props.fraction,a=Math.pow(10,3),i=e+(Math.floor(n)+Math.floor(o*a)/a);return i>0?i>this.props.totalIcons?this.props.totalIcons:i:1/this.props.fraction},a.prototype.iconClick=function(e,t){var n=this.calculateDisplayValue(e,t);this.props.onClick(n,t)},a.prototype.iconMouseMove=function(e,t){var n=this.calculateDisplayValue(e,t);this.setState({interacting:!this.props.readOnly,displayValue:n})},a.prototype.iconEnd=function(e,t){this.props.quiet||(this.iconClick(e,t),t.preventDefault()),this.onMouseLeave()},a.getDerivedStateFromProps=function(e,t){return e.value!==t.value?{displayValue:e.value,value:e.value}:null},a.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)},a.prototype.render=function(){var t,n=this.props,a=n.id,i=n.style,r=n.className,s=n.tabIndex,c=n.readOnly,u=n.totalIcons,p=n.emptyIcon,h=n.placeholderValue,d=n.value,f=n.placeholderIcon,v=n.icon,y=n.quiet,m=this.state,g=m.interacting,M=m.displayValue,V=[],b=[].concat(p),k=0!==h&&0===d&&!g,E=[].concat(f),C=[].concat(v);t=k?h:y?d:M;for(var O=Math.floor(t),I=0;I<u;I++){var D=void 0;D=I-O<0?100:I-O==0?100*(t-I):0,V.push(e.createElement(l,o({key:I,index:I,readOnly:c,emptyIcon:b[I%b.length],icon:k?E[I%C.length]:C[I%C.length],percent:D},!c&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return e.createElement("span",o({id:""+a,style:o(o({},i),{display:"inline-block",outline:"none"}),className:r,tabIndex:s},!c&&{onMouseLeave:this.onMouseLeave}),V)},a}(e.PureComponent);function s(t){return e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",style:t.style},e.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 c=function(){},u=function(t){function o(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 n(o,t),o.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},o.getDerivedStateFromProps=function(e,t){return e.defaultValue!==t.defaultValue?{defaultValue:e.defaultValue,value:e.defaultValue}:null},o.prototype.handleClick=function(e){var t=this,n=this.translateDisplayValueToValue(e||0);n===this.state.value&&(n=0),this.props.onClick(n),this.state.value!==n&&this.setState({value:n},(function(){return t.props.onChange(t.state.value)}))},o.prototype.handleHover=function(e){var t=void 0===e?e:this.translateDisplayValueToValue(e);this.props.onHover(t)},o.prototype.translateDisplayValueToValue=function(e){var t,n=this.props,o=n.min,a=n.step,i=n.fraction;return(t=e*(a||1)+(o||0))===o?t+1/(i||1):t},o.prototype.render=function(){var t=this.props,n=t.step,o=t.emptyIcon,i=t.icon,l=t.placeholderIcon,s=t.readOnly,c=t.quiet,u=t.fraction,p=t.min,h=t.max,d=t.id,f=t.className,v=t.style,y=t.tabIndex;return e.createElement(r,{id:d||0,style:v,className:f,tabIndex:y||0,totalIcons:a(p||0,h||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:s||!1,quiet:c||!1,fraction:u||1,emptyIcon:o||"",icon:i||"",placeholderIcon:l||"",onClick:this.handleClick,onHover:this.handleHover})},o.defaultProps={defaultValue:0,min:0,max:5,step:1,readOnly:!1,fraction:1,icon:e.createElement(s,{style:{fill:"#ffb400",stroke:"#ffb400"}}),emptyIcon:e.createElement(s,{style:{fill:"#000000",stroke:"#000000",opacity:"26%"}}),placeholderIcon:e.createElement(s,{style:{fill:"#ffb400",stroke:"#ffb400"}}),quiet:!1,onHover:c,onClick:c,onChange:c},o}(e.PureComponent);export{u as Star}; | ||
***************************************************************************** */var t=function(e,n){return(t=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,n)};function n(e,n){function o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}var o=function(){return(o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function a(e,t,n){return Math.floor((t-e)/n)}function r(t){return e.isValidElement(t)?t:"object"==typeof t&&null!==t?e.createElement("span",{style:t}):"[object String]"===Object.prototype.toString.call(t)?e.createElement("span",{className:t}):null}var i=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return n(o,t),o.prototype.render=function(){var t,n=this.props,o=n.readOnly,a=n.onClick,i=n.index,l=n.onMouseMove,s=n.onTouchEnd,c=n.percent,p=n.emptyIcon,u=n.icon,h=c<100?{}:{visibility:"hidden"},d=((t={display:"inline-block",position:"absolute",overflow:"hidden",top:0}).left=0,t.width=c+"%",t),v={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function f(e){l&&l(i,e)}return e.createElement("span",{style:0===i?Object.assign({},v,{marginLeft:0}):v,onClick:function(e){a&&(e.preventDefault(),a(i,e))},onMouseMove:f,onTouchMove:f,onTouchEnd:function(e){s&&s(i,e)}},e.createElement("span",{style:h},r(p)),e.createElement("span",{style:d},r(u)))},o}(e.PureComponent),l=function(t){function a(e){var n=t.call(this,e)||this;return n.state={displayValue:n.props.value,interacting:!1,value:n.props.value},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(a,t),a.prototype.onMouseLeave=function(){this.setState({displayValue:this.props.value,interacting:!1})},a.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=t-n.left;return o<0?0:o/n.width},a.prototype.calculateDisplayValue=function(e,t){var n=this.calculateHoverPercentage(t),o=Math.ceil(n%1*this.props.fraction)/this.props.fraction,a=Math.pow(10,3),r=e+(Math.floor(n)+Math.floor(o*a)/a);return r>0?r>this.props.totalIcons?this.props.totalIcons:r:1/this.props.fraction},a.prototype.iconClick=function(e,t){var n=this.calculateDisplayValue(e,t);this.props.onClick(n,t)},a.prototype.iconMouseMove=function(e,t){var n=this.calculateDisplayValue(e,t);this.setState({interacting:!this.props.readOnly,displayValue:n})},a.prototype.iconEnd=function(e,t){this.props.quiet||(this.iconClick(e,t),t.preventDefault()),this.onMouseLeave()},a.getDerivedStateFromProps=function(e,t){return e.value!==t.value?{displayValue:e.value,value:e.value}:null},a.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)},a.prototype.render=function(){var t,n=this.props,a=n.id,r=n.style,l=n.className,s=n.tabIndex,c=n.readOnly,p=n.totalIcons,u=n.emptyIcon,h=n.placeholderValue,d=n.value,v=n.placeholderIcon,f=n.icon,y=n.quiet,m=this.state,g=m.interacting,M=m.displayValue,V=[],E=[].concat(u),b=0!==h&&0===d&&!g,k=[].concat(v),C=[].concat(f);t=b?h:y?d:M;for(var I=Math.floor(t),w=0;w<p;w++){var O=void 0;O=w-I<0?100:w-I==0?100*(t-w):0,V.push(e.createElement(i,o({key:w,index:w,readOnly:c,emptyIcon:E[w%E.length],icon:b?k[w%C.length]:C[w%C.length],percent:O},!c&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return e.createElement("span",o({id:""+a,style:o(o({},r),{display:"inline-block",outline:"none"}),className:l,tabIndex:s},!c&&{onMouseLeave:this.onMouseLeave}),V)},a}(e.PureComponent);function s(t){return e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",style:t.style},e.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"}))}function c(t){return e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",style:t.style},e.createElement("path",{d:"M12 .587l3.668 7.568L24 9.306l-6.064 5.828 1.48 8.279L12 19.446l-7.417 3.967 1.481-8.279L0 9.306l8.332-1.151z"}))}var p=function(){},u="#000000",h="#ffb400",d={fill:u,stroke:u,opacity:"26%"},v={fill:h,stroke:h},f=function(t){function o(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 n(o,t),o.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},o.getDerivedStateFromProps=function(e,t){return e.defaultValue!==t.defaultValue?{defaultValue:e.defaultValue,value:e.defaultValue}:null},o.prototype.handleClick=function(e){var t=this,n=this.translateDisplayValueToValue(e||0);n===this.state.value&&(n=0),this.props.onClick(n),this.state.value!==n&&this.setState({value:n},(function(){return t.props.onChange(t.state.value)}))},o.prototype.handleHover=function(e){var t=void 0===e?e:this.translateDisplayValueToValue(e);this.props.onHover(t)},o.prototype.translateDisplayValueToValue=function(e){var t,n=this.props,o=n.min,a=n.step,r=n.fraction;return(t=e*(a||1)+(o||0))===o?t+1/(r||1):t},o.prototype.renderEmptyIcon=function(){var t=this.props,n=t.shape,o=t.emptyIcon;return o||("fat"===n?e.createElement(c,{style:d}):e.createElement(s,{style:d}))},o.prototype.renderIcon=function(){var t=this.props,n=t.shape,o=t.icon;return o||("fat"===n?e.createElement(c,{style:v}):e.createElement(s,{style:v}))},o.prototype.renderPlaceholderIcon=function(){var t=this.props,n=t.shape,o=t.placeholderIcon;return o||("fat"===n?e.createElement(c,{style:v}):e.createElement(s,{style:v}))},o.prototype.render=function(){var t=this.props,n=t.step,o=t.readOnly,r=t.quiet,i=t.fraction,s=t.min,c=t.max,p=t.id,u=t.className,h=t.style,d=t.tabIndex;return e.createElement(l,{id:p||0,style:h,className:u,tabIndex:d||0,totalIcons:a(s||0,c||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:o||!1,quiet:r||!1,fraction:i||1,emptyIcon:this.renderEmptyIcon(),icon:this.renderIcon(),placeholderIcon:this.renderPlaceholderIcon,onClick:this.handleClick,onHover:this.handleHover})},o.defaultProps={defaultValue:0,min:0,max:5,step:1,readOnly:!1,fraction:1,quiet:!1,onHover:p,onClick:p,onChange:p},o}(e.PureComponent);export{f as Star}; |
@@ -15,2 +15,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)}; | ||
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 a=function(){return(a=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function l(e,t,n){return Math.floor((t-e)/n)}function i(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 r=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,a=n.onClick,l=n.index,r=n.onMouseMove,s=n.onTouchEnd,u=n.percent,c=n.emptyIcon,p=n.icon,d=u<100?{}:{visibility:"hidden"},f=((e={display:"inline-block",position:"absolute",overflow:"hidden",top:0}).left=0,e.width=u+"%",e),h={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function v(e){r&&r(l,e)}return t.default.createElement("span",{style:0===l?Object.assign({},h,{marginLeft:0}):h,onClick:function(e){a&&(e.preventDefault(),a(l,e))},onMouseMove:v,onTouchMove:v,onTouchEnd:function(e){s&&s(l,e)}},t.default.createElement("span",{style:d},i(c)),t.default.createElement("span",{style:f},i(p)))},n}(t.default.PureComponent),s=function(e){function n(t){var n=e.call(this,t)||this;return n.state={displayValue:n.props.value,interacting:!1,value:n.props.value},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=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,a=Math.pow(10,3),l=e+(Math.floor(n)+Math.floor(o*a)/a);return l>0?l>this.props.totalIcons?this.props.totalIcons:l: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.getDerivedStateFromProps=function(e,t){return e.value!==t.value?{displayValue:e.value,value:e.value}:null},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,l=n.style,i=n.className,s=n.tabIndex,u=n.readOnly,c=n.totalIcons,p=n.emptyIcon,d=n.placeholderValue,f=n.value,h=n.placeholderIcon,v=n.icon,y=n.quiet,m=this.state,g=m.interacting,M=m.displayValue,V=[],b=[].concat(p),k=0!==d&&0===f&&!g,E=[].concat(h),C=[].concat(v);e=k?d:y?f:M;for(var O=Math.floor(e),I=0;I<c;I++){var x=void 0;x=I-O<0?100:I-O==0?100*(e-I):0,V.push(t.default.createElement(r,a({key:I,index:I,readOnly:u,emptyIcon:b[I%b.length],icon:k?E[I%C.length]:C[I%C.length],percent:x},!u&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return t.default.createElement("span",a({id:""+o,style:a(a({},l),{display:"inline-block",outline:"none"}),className:i,tabIndex:s},!u&&{onMouseLeave:this.onMouseLeave}),V)},n}(t.default.PureComponent);function u(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 c=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.getDerivedStateFromProps=function(e,t){return e.defaultValue!==t.defaultValue?{defaultValue:e.defaultValue,value:e.defaultValue}:null},n.prototype.handleClick=function(e){var t=this,n=this.translateDisplayValueToValue(e||0);n===this.state.value&&(n=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,a=n.step,l=n.fraction;return(t=e*(a||1)+(o||0))===o?t+1/(l||1):t},n.prototype.render=function(){var e=this.props,n=e.step,o=e.emptyIcon,a=e.icon,i=e.placeholderIcon,r=e.readOnly,u=e.quiet,c=e.fraction,p=e.min,d=e.max,f=e.id,h=e.className,v=e.style,y=e.tabIndex;return t.default.createElement(s,{id:f||0,style:v,className:h,tabIndex:y||0,totalIcons:l(p||0,d||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:r||!1,quiet:u||!1,fraction:c||1,emptyIcon:o||"",icon:a||"",placeholderIcon:i||"",onClick:this.handleClick,onHover:this.handleHover})},n.defaultProps={defaultValue:0,min:0,max:5,step:1,readOnly:!1,fraction:1,icon:t.default.createElement(u,{style:{fill:"#ffb400",stroke:"#ffb400"}}),emptyIcon:t.default.createElement(u,{style:{fill:"#000000",stroke:"#000000",opacity:"26%"}}),placeholderIcon:t.default.createElement(u,{style:{fill:"#ffb400",stroke:"#ffb400"}}),quiet:!1,onHover:c,onClick:c,onChange:c},n}(t.default.PureComponent);exports.Star=p; | ||
***************************************************************************** */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 a=function(){return(a=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function l(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 i=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,a=n.onClick,l=n.index,i=n.onMouseMove,s=n.onTouchEnd,u=n.percent,c=n.emptyIcon,p=n.icon,d=u<100?{}:{visibility:"hidden"},h=((e={display:"inline-block",position:"absolute",overflow:"hidden",top:0}).left=0,e.width=u+"%",e),f={cursor:o?"inherit":"pointer",display:"inline-block",position:"relative",marginLeft:5};function v(e){i&&i(l,e)}return t.default.createElement("span",{style:0===l?Object.assign({},f,{marginLeft:0}):f,onClick:function(e){a&&(e.preventDefault(),a(l,e))},onMouseMove:v,onTouchMove:v,onTouchEnd:function(e){s&&s(l,e)}},t.default.createElement("span",{style:d},r(c)),t.default.createElement("span",{style:h},r(p)))},n}(t.default.PureComponent),s=function(e){function n(t){var n=e.call(this,t)||this;return n.state={displayValue:n.props.value,interacting:!1,value:n.props.value},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=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,a=Math.pow(10,3),l=e+(Math.floor(n)+Math.floor(o*a)/a);return l>0?l>this.props.totalIcons?this.props.totalIcons:l: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.getDerivedStateFromProps=function(e,t){return e.value!==t.value?{displayValue:e.value,value:e.value}:null},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,l=n.style,r=n.className,s=n.tabIndex,u=n.readOnly,c=n.totalIcons,p=n.emptyIcon,d=n.placeholderValue,h=n.value,f=n.placeholderIcon,v=n.icon,y=n.quiet,m=this.state,g=m.interacting,M=m.displayValue,V=[],E=[].concat(p),b=0!==d&&0===h&&!g,k=[].concat(f),C=[].concat(v);e=b?d:y?h:M;for(var I=Math.floor(e),O=0;O<c;O++){var w=void 0;w=O-I<0?100:O-I==0?100*(e-O):0,V.push(t.default.createElement(i,a({key:O,index:O,readOnly:u,emptyIcon:E[O%E.length],icon:b?k[O%C.length]:C[O%C.length],percent:w},!u&&{onClick:this.iconClick,onMouseMove:this.iconMouseMove,onTouchMove:this.iconMouseMove,onTouchEnd:this.iconEnd})))}return t.default.createElement("span",a({id:""+o,style:a(a({},l),{display:"inline-block",outline:"none"}),className:r,tabIndex:s},!u&&{onMouseLeave:this.onMouseLeave}),V)},n}(t.default.PureComponent);function u(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"}))}function c(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 .587l3.668 7.568L24 9.306l-6.064 5.828 1.48 8.279L12 19.446l-7.417 3.967 1.481-8.279L0 9.306l8.332-1.151z"}))}var p=function(){},d="#000000",h="#ffb400",f={fill:d,stroke:d,opacity:"26%"},v={fill:h,stroke:h},y=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.getDerivedStateFromProps=function(e,t){return e.defaultValue!==t.defaultValue?{defaultValue:e.defaultValue,value:e.defaultValue}:null},n.prototype.handleClick=function(e){var t=this,n=this.translateDisplayValueToValue(e||0);n===this.state.value&&(n=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,a=n.step,l=n.fraction;return(t=e*(a||1)+(o||0))===o?t+1/(l||1):t},n.prototype.renderEmptyIcon=function(){var e=this.props,n=e.shape,o=e.emptyIcon;return o||("fat"===n?t.default.createElement(c,{style:f}):t.default.createElement(u,{style:f}))},n.prototype.renderIcon=function(){var e=this.props,n=e.shape,o=e.icon;return o||("fat"===n?t.default.createElement(c,{style:v}):t.default.createElement(u,{style:v}))},n.prototype.renderPlaceholderIcon=function(){var e=this.props,n=e.shape,o=e.placeholderIcon;return o||("fat"===n?t.default.createElement(c,{style:v}):t.default.createElement(u,{style:v}))},n.prototype.render=function(){var e=this.props,n=e.step,o=e.readOnly,a=e.quiet,r=e.fraction,i=e.min,u=e.max,c=e.id,p=e.className,d=e.style,h=e.tabIndex;return t.default.createElement(s,{id:c||0,style:d,className:p,tabIndex:h||0,totalIcons:l(i||0,u||5,n||1),value:this.tranlateValueToDisplayValue(this.state.value),placeholderValue:this.tranlateValueToDisplayValue(this.props.placeholderRating||0),readOnly:o||!1,quiet:a||!1,fraction:r||1,emptyIcon:this.renderEmptyIcon(),icon:this.renderIcon(),placeholderIcon:this.renderPlaceholderIcon,onClick:this.handleClick,onHover:this.handleHover})},n.defaultProps={defaultValue:0,min:0,max:5,step:1,readOnly:!1,fraction:1,quiet:!1,onHover:p,onClick:p,onChange:p},n}(t.default.PureComponent);exports.Star=y; |
@@ -21,2 +21,3 @@ import React from 'react'; | ||
onChange: (index?: number, event?: any) => void; | ||
shape: 'thin' | 'fat'; | ||
} | ||
@@ -38,4 +39,7 @@ interface State { | ||
translateDisplayValueToValue(displayValue: number): number; | ||
renderEmptyIcon(): string | object; | ||
renderIcon(): string | object; | ||
renderPlaceholderIcon(): string | object; | ||
render(): JSX.Element; | ||
} | ||
export default Star; |
{ | ||
"name": "react-star", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "A tiny star rating component with custom icons for React.", | ||
@@ -19,3 +19,4 @@ "author": "Bunlong <bunlong.van@gmail.com>", | ||
"star", | ||
"rating" | ||
"rating", | ||
"react-rating" | ||
], | ||
@@ -22,0 +23,0 @@ "homepage": "https://github.com/Bunlong/react-star", |
@@ -69,2 +69,8 @@ <p align="center"> | ||
<tr> | ||
<td>shape</td> | ||
<td>'thin' | 'fat'</td> | ||
<td>'thin'</td> | ||
<td>The shape of the star.</td> | ||
</tr> | ||
<tr> | ||
<td>fraction</td> | ||
@@ -71,0 +77,0 @@ <td>number</td> |
27394
13
199
174