prettystars
Version:
A simple node module to generate stars that can be partially filled
1 lines • 5.35 kB
JavaScript
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var a=e[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)r.d(n,a,function(e){return t[e]}.bind(null,a));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e){t.exports=require("react")},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),a=i(r(0)),o=i(r(2));function i(t){return t&&t.__esModule?t:{default:t}}function l(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}var s=function(t){function e(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var r=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return r.state={actualStars:null!==r.props.actualStars?r.props.actualStars:5,possibleStars:r.props.possibleStars||5,starWidth:r.props.size||"32px",starHeight:r.props.size||"32px"},r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,a.default.Component),n(e,[{key:"componentDidUpdate",value:function(){this.props.actualStars!==this.state.actualStars&&this.setState({actualStars:this.props.actualStars}),this.render()}},{key:"buildStarsArray",value:function(){var t=[];if(this.state.actualStars>this.state.possibleStars)t=Array(this.state.possibleStars).fill(1);else if(this.state.actualStars<=0)t=Array(this.state.possibleStars).fill(0);else{var e,r,n=0|this.state.actualStars,a=Number((this.state.actualStars%1).toFixed(2)),o=this.state.possibleStars-this.state.actualStars|0;(e=t).push.apply(e,l(Array(n).fill(1))),0!==a&&t.push(a),(r=t).push.apply(r,l(Array(o).fill(0)))}return t}},{key:"render",value:function(){var t=this;return a.default.createElement("div",null,this.buildStarsArray().map(function(e){return a.default.createElement(o.default,{key:Math.random(),fill:e,height:t.state.starHeight,width:t.state.starWidth})}))}}]),e}();e.default=s},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),a=function(t){return t&&t.__esModule?t:{default:t}}(r(0));var o={stroke:"#FFD700",stopColor:"#FFD700",strokeWidth:.4},i=function(t){function e(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var r=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return r.state={fill:null!==r.props.fill?r.props.fill:1,width:r.props.width||"32px",height:r.props.height||"32px"},r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,a.default.Component),n(e,[{key:"getFill",value:function(){return 100*this.state.fill+"%"}},{key:"render",value:function(){var t,e=Math.random();return t=1===this.state.fill?"#FFD700":0===this.state.fill?"none":"url(#variableGradient?"+e+")",a.default.createElement("svg",{style:o,viewBox:"0 0 32 32",width:this.state.width,height:this.state.height},a.default.createElement("linearGradient",{id:"variableGradient?"+e},a.default.createElement("stop",{stopOpacity:"1",offset:this.getFill(),stopColor:o.stopColor}),a.default.createElement("stop",{stopOpacity:"0",offset:this.getFill()})),a.default.createElement("g",{id:"icon-star",fill:t},a.default.createElement("path",{d:"M20.388,10.918L32,12.118l-8.735,7.749L25.914,31.4l-9.893-6.088L6.127,31.4l2.695-11.533L0,12.118 l11.547-1.2L16.026,0.6L20.388,10.918z"})))}}]),e}();e.default=i}]);