UNPKG

product-slider-react

Version:

React slider component for showing product images to be used in e-commerce application

12 lines (11 loc) 18.2 kB
"use strict";var e,t=require("react"),r={exports:{}},n={};var o,i={}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */"production"===process.env.NODE_ENV?r.exports=function(){if(e)return n;e=1;var r=t,o=Symbol.for("react.element"),i=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,s=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function l(e,t,r){var n,i={},l=null,u=null;for(n in void 0!==r&&(l=""+r),void 0!==t.key&&(l=""+t.key),void 0!==t.ref&&(u=t.ref),t)a.call(t,n)&&!c.hasOwnProperty(n)&&(i[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===i[n]&&(i[n]=t[n]);return{$$typeof:o,type:e,key:l,ref:u,props:i,_owner:s.current}}return n.Fragment=i,n.jsx=l,n.jsxs=l,n}():r.exports=(o||(o=1,"production"!==process.env.NODE_ENV&&function(){var e=t,r=Symbol.for("react.element"),n=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),a=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),g=Symbol.iterator,v="@@iterator",h=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=h.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(t+="%s",r=r.concat([n]));var o=r.map((function(e){return String(e)}));o.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,o)}("error",e,r)}var w,x=!1,k=!1,j=!1,_=!1,S=!1;function R(e){return e.displayName||"Context"}function O(e){if(null==e)return null;if("number"==typeof e.tag&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case n:return"Portal";case s:return"Profiler";case a:return"StrictMode";case f:return"Suspense";case p:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case l:return R(e)+".Consumer";case c:return R(e._context)+".Provider";case u:return function(e,t,r){var n=e.displayName;if(n)return n;var o=t.displayName||t.name||"";return""!==o?r+"("+o+")":r}(e,e.render,"ForwardRef");case d:var t=e.displayName||null;return null!==t?t:O(e.type)||"Memo";case y:var r=e,i=r._payload,m=r._init;try{return O(m(i))}catch(e){return null}}return null}w=Symbol.for("react.module.reference");var E,C,T,P,$,N,I,D=Object.assign,F=0;function L(){}L.__reactDisabledLog=!0;var z,W=h.ReactCurrentDispatcher;function B(e,t,r){if(void 0===z)try{throw Error()}catch(e){var n=e.stack.trim().match(/\n( *(at )?)/);z=n&&n[1]||""}return"\n"+z+e}var M,U=!1,A="function"==typeof WeakMap?WeakMap:Map;function X(e,t){if(!e||U)return"";var r,n=M.get(e);if(void 0!==n)return n;U=!0;var o,i=Error.prepareStackTrace;Error.prepareStackTrace=void 0,o=W.current,W.current=null,function(){if(0===F){E=console.log,C=console.info,T=console.warn,P=console.error,$=console.group,N=console.groupCollapsed,I=console.groupEnd;var e={configurable:!0,enumerable:!0,value:L,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}F++}();try{if(t){var a=function(){throw Error()};if(Object.defineProperty(a.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(a,[])}catch(e){r=e}Reflect.construct(e,[],a)}else{try{a.call()}catch(e){r=e}e.call(a.prototype)}}else{try{throw Error()}catch(e){r=e}e()}}catch(t){if(t&&r&&"string"==typeof t.stack){for(var s=t.stack.split("\n"),c=r.stack.split("\n"),l=s.length-1,u=c.length-1;l>=1&&u>=0&&s[l]!==c[u];)u--;for(;l>=1&&u>=0;l--,u--)if(s[l]!==c[u]){if(1!==l||1!==u)do{if(l--,--u<0||s[l]!==c[u]){var f="\n"+s[l].replace(" at new "," at ");return e.displayName&&f.includes("<anonymous>")&&(f=f.replace("<anonymous>",e.displayName)),"function"==typeof e&&M.set(e,f),f}}while(l>=1&&u>=0);break}}}finally{U=!1,W.current=o,function(){if(0==--F){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:E}),info:D({},e,{value:C}),warn:D({},e,{value:T}),error:D({},e,{value:P}),group:D({},e,{value:$}),groupCollapsed:D({},e,{value:N}),groupEnd:D({},e,{value:I})})}F<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=i}var p=e?e.displayName||e.name:"",d=p?B(p):"";return"function"==typeof e&&M.set(e,d),d}function Y(e,t,r){if(null==e)return"";if("function"==typeof e)return X(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return B(e);switch(e){case f:return B("Suspense");case p:return B("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case u:return X(e.render,!1);case d:return Y(e.type,t,r);case y:var o=e,i=o._payload,a=o._init;try{return Y(a(i),t,r)}catch(e){}}return""}M=new A;var V=Object.prototype.hasOwnProperty,q={},J=h.ReactDebugCurrentFrame;function K(e){if(e){var t=e._owner,r=Y(e.type,e._source,t?t.type:null);J.setExtraStackFrame(r)}else J.setExtraStackFrame(null)}var H=Array.isArray;function G(e){return H(e)}function Q(e){return""+e}function Z(e){if(function(e){try{return Q(e),!1}catch(e){return!0}}(e))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),Q(e)}var ee,te,re,ne=h.ReactCurrentOwner,oe={key:!0,ref:!0,__self:!0,__source:!0};re={};var ie=function(e,t,n,o,i,a,s){var c={$$typeof:r,type:e,key:t,ref:n,props:s,_owner:a,_store:{}};return Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c};function ae(e,t,r,n,o){var i,a={},s=null,c=null;for(i in void 0!==r&&(Z(r),s=""+r),function(e){if(V.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(Z(t.key),s=""+t.key),function(e){if(V.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e,t){if("string"==typeof e.ref&&ne.current&&t&&ne.current.stateNode!==t){var r=O(ne.current.type);re[r]||(b('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',O(ne.current.type),e.ref),re[r]=!0)}}(t,o)),t)V.call(t,i)&&!oe.hasOwnProperty(i)&&(a[i]=t[i]);if(e&&e.defaultProps){var l=e.defaultProps;for(i in l)void 0===a[i]&&(a[i]=l[i])}if(s||c){var u="function"==typeof e?e.displayName||e.name||"Unknown":e;s&&function(e,t){var r=function(){ee||(ee=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(a,u),c&&function(e,t){var r=function(){te||(te=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(a,u)}return ie(e,s,c,o,n,ne.current,a)}var se,ce=h.ReactCurrentOwner,le=h.ReactDebugCurrentFrame;function ue(e){if(e){var t=e._owner,r=Y(e.type,e._source,t?t.type:null);le.setExtraStackFrame(r)}else le.setExtraStackFrame(null)}function fe(e){return"object"==typeof e&&null!==e&&e.$$typeof===r}function pe(){if(ce.current){var e=O(ce.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}se=!1;var de={};function ye(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=pe();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!de[r]){de[r]=!0;var n="";e&&e._owner&&e._owner!==ce.current&&(n=" It was passed a child from "+O(e._owner.type)+"."),ue(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,n),ue(null)}}}function me(e,t){if("object"==typeof e)if(G(e))for(var r=0;r<e.length;r++){var n=e[r];fe(n)&&ye(n,t)}else if(fe(e))e._store&&(e._store.validated=!0);else if(e){var o=function(e){if(null===e||"object"!=typeof e)return null;var t=g&&e[g]||e[v];return"function"==typeof t?t:null}(e);if("function"==typeof o&&o!==e.entries)for(var i,a=o.call(e);!(i=a.next()).done;)fe(i.value)&&ye(i.value,t)}}function ge(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==u&&r.$$typeof!==d)return;t=r.propTypes}if(t){var n=O(r);!function(e,t,r,n,o){var i=Function.call.bind(V);for(var a in e)if(i(e,a)){var s=void 0;try{if("function"!=typeof e[a]){var c=Error((n||"React class")+": "+r+" type `"+a+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[a]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw c.name="Invariant Violation",c}s=e[a](t,a,n,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(e){s=e}!s||s instanceof Error||(K(o),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",r,a,typeof s),K(null)),s instanceof Error&&!(s.message in q)&&(q[s.message]=!0,K(o),b("Failed %s type: %s",r,s.message),K(null))}}(t,e.props,"prop",n,e)}else void 0===r.PropTypes||se||(se=!0,b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",O(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}var ve={};function he(e,t,n,i,g,v){var h=function(e){return"string"==typeof e||"function"==typeof e||!!(e===o||e===s||S||e===a||e===f||e===p||_||e===m||x||k||j)||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===d||e.$$typeof===c||e.$$typeof===l||e.$$typeof===u||e.$$typeof===w||void 0!==e.getModuleId)}(e);if(!h){var R,E="";(void 0===e||"object"==typeof e&&null!==e&&0===Object.keys(e).length)&&(E+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),E+=pe(),null===e?R="null":G(e)?R="array":void 0!==e&&e.$$typeof===r?(R="<"+(O(e.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):R=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",R,E)}var C=ae(e,t,n,g,v);if(null==C)return C;if(h){var T=t.children;if(void 0!==T)if(i)if(G(T)){for(var P=0;P<T.length;P++)me(T[P],e);Object.freeze&&Object.freeze(T)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else me(T,e)}if(V.call(t,"key")){var $=O(e),N=Object.keys(t).filter((function(e){return"key"!==e})),I=N.length>0?"{key: someKey, "+N.join(": ..., ")+": ...}":"{key: someKey}";ve[$+I]||(b('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',I,$,N.length>0?"{"+N.join(": ..., ")+": ...}":"{}",$),ve[$+I]=!0)}return e===o?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){ue(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),ue(null);break}}null!==e.ref&&(ue(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),ue(null))}(C):ge(C),C}var be=function(e,t,r){return he(e,t,r,!1)},we=function(e,t,r){return he(e,t,r,!0)};i.Fragment=o,i.jsx=be,i.jsxs=we}()),i);var a=r.exports,s=function(e){var r=e.imgUrl,n=e.magnifierSize,o=void 0===n?200:n,i=e.zoomLevel,s=void 0===i?3:i,c=e.BorderRadius,l=void 0===c?"50":c,u=t.useState({x:0,y:0});u[0];var f=u[1],p=t.useState(!1),d=p[0],y=p[1],m=t.useState({x:0,y:0}),g=m[0],v=m[1],h=t.useState({width:0,height:0}),b=h[0],w=h[1],x=t.useRef(null);t.useEffect((function(){var e=function(){x.current&&w({width:x.current.width,height:x.current.height})};return window.addEventListener("resize",e),e(),function(){return window.removeEventListener("resize",e)}}),[]);var k=o/2;return a.jsxs("div",{className:"img-magnifier-container",style:{position:"relative",overflow:"hidden"},onMouseEnter:function(){return y(!0)},onMouseLeave:function(){return y(!1)},onMouseMove:function(e){var t=x.current.getBoundingClientRect(),r=t.left,n=t.top,o=t.width,i=t.height,a=(e.pageX-r)/o*100,s=(e.pageY-n)/i*100;f({x:a,y:s}),v({x:e.pageX-r,y:e.pageY-n})},children:[a.jsx("img",{ref:x,className:"magnifier-img",src:r,alt:"product-img",style:{display:"block",width:"100%",height:"80vh"}}),d&&a.jsx("div",{style:{position:"absolute",left:"".concat(g.x-k,"px"),top:"".concat(g.y-k,"px"),pointerEvents:"none",width:"".concat(o,"px"),height:"".concat(o,"px"),border:"2px solid white",borderRadius:"".concat(l,"%"),boxShadow:"0 0 10px rgba(0,0,0,0.25)",overflow:"hidden"},children:a.jsx("div",{style:{width:"".concat(o*s,"px"),height:"".concat(o*s,"px"),backgroundImage:"url(".concat(r,")"),backgroundSize:"".concat(b.width*s,"px ").concat(b.height*s,"px"),backgroundPosition:"".concat(-g.x*s+k,"px ").concat(-g.y*s+k,"px")}})})]})};!function(e,t){void 0===t&&(t={});var r=t.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("@keyframes slideLeft {\r\n from {\r\n transform: translateX(100%);\r\n }\r\n to {\r\n transform: translateX(0);\r\n }\r\n}\r\n\r\n@keyframes slideRight {\r\n from {\r\n transform: translateX(-100%);\r\n }\r\n to {\r\n transform: translateX(0);\r\n }\r\n}");exports.Magnifier=s,exports.ProductSlider=function(e){var r=e.width,n=void 0===r?"700px":r,o=e.height,i=void 0===o?"100%":o,c=e.magnify,l=void 0===c||c,u=e.images,f=e.magnifierSize,p=e.zoomLevel,d=e.MagnifierBorderRadius,y=e.prevIcon,m=void 0===y?"<":y,g=e.nextIcon,v=void 0===g?">":g,h=e.buttonBg,b=void 0===h?"#b8b7b4":h,w=e.imgBg,x=void 0===w?"#b8b7b4":w,k=e.imgRadius,j=void 0===k?"20px":k,_=e.tileRadius,S=void 0===_?"10px":_,R=e.tilePosition,O=void 0===R?"bottom":R,E=t.useState(0),C=E[0],T=E[1],P=t.useState(!1),$=P[0],N=P[1],I=t.useState(""),D=I[0],F=I[1],L=u[C].img;t.useEffect((function(){if($){var e=setTimeout((function(){N(!1)}),250);return function(){return clearTimeout(e)}}}),[$]);return a.jsxs("div",{style:{display:"flex",flexDirection:"bottom"===O?"column":"right"===O?"row":"row-reverse",width:"".concat(n),height:"".concat(i)},children:[a.jsxs("div",{style:{width:"100%",display:"flex",justifyContent:"center",alignItems:"center",overflow:"hidden",border:"2px solid #ccc",background:x,borderRadius:j,position:"relative"},children:[l?a.jsx("div",{style:{width:"100%",animation:$?"left"===D?"slideLeft 0.25s forwards":"slideRight 0.25s forwards":"none"},children:a.jsx(s,{imgUrl:L,magnifierSize:f,zoomLevel:p,BorderRadius:d})}):a.jsx("img",{src:L,alt:"product-img",style:{width:"100%",height:"80vh",animation:$?"left"===D?"slideLeft 0.25s forwards":"slideRight 0.25s forwards":"none"}}),a.jsx("button",{style:{position:"absolute",left:"1rem",borderRadius:"50%",fontWeight:"600",width:"2.5rem",height:"2.5rem",padding:"0.5rem",color:"white",display:"flex",justifyContent:"center",alignItems:"center",background:b,border:"none"},onClick:function(){N(!0),F("left"),T((function(e){return 0===e?u.length-1:e-1}))},children:m}),a.jsx("button",{style:{position:"absolute",right:"1rem",borderRadius:"50%",fontWeight:"600",width:"2.5rem",height:"2.5rem",padding:"0.5rem",color:"white",display:"flex",justifyContent:"center",alignItems:"center",background:b,border:"none"},onClick:function(){N(!0),F("right"),T((function(e){return e===u.length-1?0:e+1}))},children:v})]}),a.jsx("div",{style:{width:"bottom"!==O?"25%":"auto",padding:"1rem",display:"bottom"===O?"block":"flex",justifyContent:"center",alignItems:"center"},children:a.jsx("ul",{style:{display:"flex",height:"auto",overflow:"hidden",flexWrap:"wrap",gap:"0.5rem",listStyle:"none",justifyContent:"space-evenly",paddingLeft:"0"},children:u.slice(0,"bottom"===O?14:10).map((function(e,t){return a.jsx("li",{style:{width:"bottom"===O?"12%":"40%",aspectRatio:"1/1",cursor:"pointer"},onClick:function(){N(!0),F(t<C?"right":"left"),T(t)},children:a.jsx("img",{src:e.img,alt:"tileImage",style:{borderRadius:"".concat(S),objectFit:"contain",height:"100%"}})},t)}))})})]})}; //# sourceMappingURL=index.js.map