react-rating-tooltip-hooks
Version:
React Star Rating/Review Component with tooltip support
1 lines • 12.2 kB
JavaScript
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){e.exports=require("react")},function(e,t,n){var r=n(3);"string"==typeof r&&(r=[[e.i,r,""]]);var o={hmr:!0,transform:void 0,insertInto:void 0};n(5)(r,o);r.locals&&(e.exports=r.locals)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&u.return&&u.return()}finally{if(o)throw i}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},o=n(0),i=l(o);n(1);var a=l(n(7)),u=l(n(8));function l(e){return e&&e.__esModule?e:{default:e}}function s(e){for(var t=(0,o.useState)(e.defaultRating),n=r(t,2),u=n[0],l=n[1],s=(0,o.useState)(-1),c=r(s,2),f=c[0],p=c[1],d=function(t){var n=e.clearRating,r=e.ratingValue,o=e.onChange;n&&u===t+1?(l(0),p(-1),o(0,"-")):(l(t+1),o(t+1,r?r[t]:""))},y=function(e){p(e+1)},v=function(){p(-1)},h=e.max,m=e.counterPosition,b=e.textPosition,g=e.tooltipContent,x=e.ratingValue,S=e.styleConfig,C=e.disabled,w=new Array(h),O=f>=0?f:u,j=0;j<w.length;j++)w[j]=i.default.createElement(a.default,{tooltipStyle:S&&S.tooltipStyle?S.tooltipStyle:{},tpText:g&&g[j]?g[j]:null,selected:j<O,key:j,onMouseLeave:C?function(){}:v,onHover:C?function(){}:y,index:j,selectStar:C?function(){}:d,InActiveComponent:e.InActiveComponent,ActiveComponent:e.ActiveComponent});return m&&("left"===m?w.unshift(i.default.createElement("div",{key:w.length+1,style:S&&S.counterStyle?S.counterStyle:{}},u)):w.push(i.default.createElement("div",{key:w.length+1,style:S&&S.counterStyle?S.counterStyle:{}},u))),b&&("left"===b?w.unshift(i.default.createElement("div",{key:w.length+1,style:S&&S.statusStyle?S.statusStyle:{}},x&&x[u-1]?x[u-1]:"-")):w.push(i.default.createElement("div",{key:w.length+1,style:S&&S.statusStyle?S.statusStyle:{}},x&&x[u-1]?x[u-1]:"-"))),i.default.createElement("div",null,i.default.createElement("div",{className:"wrap-container"},i.default.createElement("div",{className:"rating-container",style:S&&S.starContainer?S.starContainer:{}},w)))}s.propTypes={max:u.default.number.isRequired,defaultRating:u.default.number,counterPosition:u.default.oneOf(["left","right"]),clearRating:u.default.bool,disabled:u.default.bool,textPosition:u.default.oneOf(["left","right"]),tooltipContent:u.default.array,ratingValue:u.default.array,styleConfig:u.default.shape({counterStyle:u.default.object,starContainer:u.default.object,statusStyle:u.default.object,tooltipStyle:u.default.object}),onChange:u.default.func.isRequired,ActiveComponent:u.default.oneOfType([u.default.node,u.default.element]).isRequired,InActiveComponent:u.default.oneOfType([u.default.node,u.default.element]).isRequired},s.defaultProps={clearRating:!0,disabled:!1,defaultRating:0,styleConfig:{counterStyle:{height:"28px",backgroundColor:"#F58220",paddingLeft:"12px",paddingRight:"12px",color:"#FFF",lineHeight:"28px"},starContainer:{fontSize:"24px",backgroundColor:"#F2F2F2",height:"28px"},statusStyle:{height:"28px",backgroundColor:"#F58220",paddingLeft:"12px",paddingRight:"12px",color:"#FFF",lineHeight:"28px",minWidth:"100px",fontSize:"18px",textAlign:"center"},tooltipStyle:{fontSize:"14px",padding:"5px"}}},t.default=s},function(e,t,n){(e.exports=n(4)(!1)).push([e.i,".rating-container{\n display: flex;\n min-width: 100px;\n }\n \n .wrap-container{\n display: flex;\n justify-content: center;\n }\n \n .tooltiptext{\n position: absolute;\n top: 100%;\n left: -50%;\n background: rgba(0,0,0,0.8);\n color: #fff;\n z-index: 9999;\n min-width: 70px;\n text-align: center;\n }\n \n .tp-container{\n position: relative;\n }",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var n=function(e,t){var n=e[1]||"",r=e[3];if(!r)return n;if(t&&"function"==typeof btoa){var o=(a=r,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(a))))+" */"),i=r.sources.map((function(e){return"/*# sourceURL="+r.sourceRoot+e+" */"}));return[n].concat(i).concat([o]).join("\n")}var a;return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n})).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var r={},o=0;o<this.length;o++){var i=this[o][0];"number"==typeof i&&(r[i]=!0)}for(o=0;o<e.length;o++){var a=e[o];"number"==typeof a[0]&&r[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),t.push(a))}},t}},function(e,t,n){var r,o,i={},a=(r=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===o&&(o=r.apply(this,arguments)),o}),u=function(e,t){return t?t.querySelector(e):document.querySelector(e)},l=function(e){var t={};return function(e,n){if("function"==typeof e)return e();if(void 0===t[e]){var r=u.call(this,e,n);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}t[e]=r}return t[e]}}(),s=null,c=0,f=[],p=n(6);function d(e,t){for(var n=0;n<e.length;n++){var r=e[n],o=i[r.id];if(o){o.refs++;for(var a=0;a<o.parts.length;a++)o.parts[a](r.parts[a]);for(;a<r.parts.length;a++)o.parts.push(g(r.parts[a],t))}else{var u=[];for(a=0;a<r.parts.length;a++)u.push(g(r.parts[a],t));i[r.id]={id:r.id,refs:1,parts:u}}}}function y(e,t){for(var n=[],r={},o=0;o<e.length;o++){var i=e[o],a=t.base?i[0]+t.base:i[0],u={css:i[1],media:i[2],sourceMap:i[3]};r[a]?r[a].parts.push(u):n.push(r[a]={id:a,parts:[u]})}return n}function v(e,t){var n=l(e.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var r=f[f.length-1];if("top"===e.insertAt)r?r.nextSibling?n.insertBefore(t,r.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),f.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var o=l(e.insertAt.before,n);n.insertBefore(t,o)}}function h(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=f.indexOf(e);t>=0&&f.splice(t,1)}function m(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var r=function(){0;return n.nc}();r&&(e.attrs.nonce=r)}return b(t,e.attrs),v(e,t),t}function b(e,t){Object.keys(t).forEach((function(n){e.setAttribute(n,t[n])}))}function g(e,t){var n,r,o,i;if(t.transform&&e.css){if(!(i=t.transform(e.css)))return function(){};e.css=i}if(t.singleton){var a=c++;n=s||(s=m(t)),r=C.bind(null,n,a,!1),o=C.bind(null,n,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",b(t,e.attrs),v(e,t),t}(t),r=O.bind(null,n,t),o=function(){h(n),n.href&&URL.revokeObjectURL(n.href)}):(n=m(t),r=w.bind(null,n),o=function(){h(n)});return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else o()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=y(e,t);return d(n,t),function(e){for(var r=[],o=0;o<n.length;o++){var a=n[o];(u=i[a.id]).refs--,r.push(u)}e&&d(y(e,t),t);for(o=0;o<r.length;o++){var u;if(0===(u=r[o]).refs){for(var l=0;l<u.parts.length;l++)u.parts[l]();delete i[u.id]}}}};var x,S=(x=[],function(e,t){return x[e]=t,x.filter(Boolean).join("\n")});function C(e,t,n,r){var o=n?"":r.css;if(e.styleSheet)e.styleSheet.cssText=S(t,o);else{var i=document.createTextNode(o),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function w(e,t){var n=t.css,r=t.media;if(r&&e.setAttribute("media",r),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}function O(e,t,n){var r=n.css,o=n.sourceMap,i=void 0===t.convertToAbsoluteUrls&&o;(t.convertToAbsoluteUrls||i)&&(r=p(r)),o&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var a=new Blob([r],{type:"text/css"}),u=e.href;e.href=URL.createObjectURL(a),u&&URL.revokeObjectURL(u)}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,r=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(e,t){var o,i=t.trim().replace(/^"(.*)"$/,(function(e,t){return t})).replace(/^'(.*)'$/,(function(e,t){return t}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(o=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:r+i.replace(/^\.\//,""),"url("+JSON.stringify(o)+")")}))}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r,o=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{!r&&u.return&&u.return()}finally{if(o)throw i}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},i=n(0),a=(r=i)&&r.__esModule?r:{default:r};n(1),t.default=function(e){var t=(0,i.useState)(e.selected),n=o(t,2),r=n[0],u=n[1],l=(0,i.useState)(!1),s=o(l,2),c=s[0],f=s[1];return(0,i.useEffect)((function(){u(e.selected)}),[e.selected]),a.default.createElement("div",{onClick:function(){e.selectStar(e.index)},onMouseOver:function(){e.onHover(e.index),f(!0)},onMouseLeave:function(){e.onMouseLeave(),f(!1)},className:"tp-container"},r?e.ActiveComponent:e.InActiveComponent,c&&e.tpText&&a.default.createElement("span",{className:"tooltiptext",style:e.tooltipStyle},e.tpText))}},function(e,t,n){e.exports=n(9)()},function(e,t,n){"use strict";var r=n(10);function o(){}function i(){}i.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,i,a){if(a!==r){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:o};return n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}]);