@auraxy/carousel
Version:
A description for the module
10 lines (8 loc) • 7.39 kB
JavaScript
/**
* Bundle of @auraxy/carousel
* Generated: 2020-01-15
* Version: 1.0.0
* License: MIT
* Author:
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e=e||self).CarouselCarousel=t(e.React)}(this,function(R){"use strict";var V="default"in R?R.default:R;function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],a=!0,n=!1,o=void 0;try{for(var u,i=e[Symbol.iterator]();!(a=(u=i.next()).done)&&(r.push(u.value),!t||r.length!==t);a=!0);}catch(e){n=!0,o=e}finally{try{a||null==i.return||i.return()}finally{if(n)throw o}}return r}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var e,S,t,O,r,L=(function(e){function u(){for(var e=[],t=0;t<arguments.length;t++){var r=arguments[t];if(r){var a=typeof r;if("string"==a||"number"==a)e.push(r);else if(Array.isArray(r)&&r.length){var n=u.apply(null,r);n&&e.push(n)}else if("object"==a)for(var o in r)i.call(r,o)&&r[o]&&e.push(o)}}return e.join(" ")}var i;i={}.hasOwnProperty,e.exports?(u.default=u,e.exports=u):window.classNames=u}(e={exports:{}},e.exports),e.exports);function a(e,t){void 0===t&&(t={});var r=t.insertAt;if(e&&"undefined"!=typeof document){var a=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===r&&a.firstChild?a.insertBefore(n,a.firstChild):a.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}}(t=S=S||{}).ALWAYS="always",t.HOVER="hover",t.NEVER="never",(r=O=O||{}).CLICK="click",r.HOVER="hover";a(".au-carousel-slider{position:absolute;overflow:hidden}.au-carousel-slider .au-carousel-item{float:left;background:#364d79}.au-carousel-slider .au-carousel-item img{width:100%}");function z(e){var a=e.children,r=e.vertical,t=e.activeIndex,n=e.total,o=e.resetIndex,u=e.duration,i=R.useMemo(function(){return e=V.Children.toArray(a),t=e[0],r=e[e.length-1],e.unshift(r),e.push(t),e;var e,t,r},[a]),l=R.useMemo(function(){return i.length},[i]),c=T(R.useState(!0),2),s=c[0],d=c[1],f=R.useMemo(function(){return{width:r?"100%":"".concat(100*l,"%"),height:r?"".concat(100*l,"%"):"100%",left:r?"0px":"-".concat(100*(t+1),"%"),top:r?"-".concat(100*(t+1),"%"):"0px",transitionProperty:s?r?"top":"left":"none",transitionDuration:s?u+"ms":"0"}},[r,l,t,s,u]),m=R.useRef(null);return R.useEffect(function(){var e=null;return e=n-1<t||t<0?setTimeout(function(){o(t<0?n-1:0),d(!1)},u+100):setTimeout(function(){return d(!0)},100),m.current=e,function(){return clearInterval(m.current)}},[t,n,o,u]),V.createElement("div",{className:"au-carousel-slider",style:f},i.map(function(e,t){return V.createElement("div",{key:t,className:"au-carousel-item",style:{width:r?"100%":"".concat(100/l,"%"),height:r?"".concat(100/l,"%"):"100%"}},e)}))}function o(){return V.createElement("svg",{viewBox:"0 0 1024 1024",version:"1.1",width:"200",height:"200"},V.createElement("defs",null,V.createElement("style",{type:"text/css"})),V.createElement("path",{d:"M589.088 790.624L310.464 512l278.624-278.624 45.248 45.248L400.96 512l233.376 233.376z",fill:"#ffffff","p-id":"5950"}))}function u(){return V.createElement("svg",{viewBox:"0 0 1024 1024",version:"1.1",width:"200",height:"200"},V.createElement("defs",null,V.createElement("style",{type:"text/css"})),V.createElement("path",{d:"M434.944 790.624l-45.248-45.248L623.04 512l-233.376-233.376 45.248-45.248L713.568 512z",fill:"#ffffff","p-id":"6275"}))}var i,n;a(".au-carousel-arrow .au-carousel-arrow-item{position:absolute;top:50%;transform:translateY(-50%);width:30px;height:30px;cursor:pointer}.au-carousel-arrow .au-carousel-arrow-item.au-carousel-arrow-left{left:20px}.au-carousel-arrow .au-carousel-arrow-item.au-carousel-arrow-right{right:20px}.au-carousel-arrow .au-carousel-arrow-item>svg{width:100%;height:100%}"),(n=i=i||{}).PREV="PREV",n.NEXT="NEXT";function j(e){function t(t){a(function(e){return t===i.PREV?e-1:e+1})}var r=e.arrowVisible,a=e.onClick,n=R.useMemo(function(){return{display:r?"block":"none"}},[r]);return V.createElement("div",{className:"au-carousel-arrow",style:n},V.createElement("div",{className:"au-carousel-arrow-item au-carousel-arrow-left",onClick:function(){return t(i.PREV)}},V.createElement(o,null)),V.createElement("div",{className:"au-carousel-arrow-item au-carousel-arrow-right",onClick:function(){return t(i.NEXT)}},V.createElement(u,null)))}a(".au-carousel-dots{position:absolute;list-style:none;margin:0;padding:0;z-index:2}.au-carousel-dots.au-carousel-dots-horizontal{bottom:0;left:50%;transform:translateX(-50%)}.au-carousel-dots.au-carousel-dots-vertical{right:0;top:50%;transform:translateY(-50%)}.au-carousel-dots-item{background-color:transparent;cursor:pointer}.au-carousel-dots-item.au-carousel-dots-item-horizontal{display:inline-block;padding:12px 4px}.au-carousel-dots-item.au-carousel-dots-item-vertical{display:block;padding:4px 12px}.au-carousel-dots-item.au-carousel-dots-item-vertical .au-carousel-dots-item-button{width:2px;height:15px}.au-carousel-dots-item-button{display:block;width:30px;height:2px;opacity:.48;background-color:#fff;border:none;outline:none;padding:0;margin:0;cursor:pointer;transition:.5s}.au-carousel-dots-item-button.au-carousel-dots-item-button-active{opacity:1}");function P(e){var r=e.dotsTrigger,a=e.vertical,t=e.total,n=e.activeIndex,o=e.resetIndex;return V.createElement("ul",{className:L("au-carousel-dots",a?"au-carousel-dots-vertical":"au-carousel-dots-horizontal")},Array.from(Array(t),function(e,t){return V.createElement("li",{className:L("au-carousel-dots-item",a?"au-carousel-dots-item-vertical":"au-carousel-dots-item-horizontal"),key:t},V.createElement("span",{className:L("au-carousel-dots-item-button",n===t?"au-carousel-dots-item-button-active":""),onMouseEnter:function(){return e=t,void(r===O.HOVER&&o(e));var e},onClick:function(){return e=t,void(r===O.CLICK&&o(e));var e}}))}))}a(".au-carousel{position:relative;overflow:hidden;height:300px}");return function(e){function t(){b(!0),N()}function r(){b(f===S.ALWAYS),k()}var a=e.children,n=e.className,o=e.vertical,u=void 0!==o&&o,i=e.autoplay,l=void 0===i||i,c=e.interval,s=void 0===c?3e3:c,d=e.arrowVisibleWay,f=void 0===d?S.HOVER:d,m=e.dotsTrigger,p=void 0===m?O.HOVER:m,v=T(R.useState(0),2),h=v[0],y=v[1],E=R.useMemo(function(){return V.Children.count(a)},[a]),g=R.useMemo(function(){return!u&&f!==S.NEVER&&1!==E},[u,f,E]),x=T(R.useState(f===S.ALWAYS),2),w=x[0],b=x[1],C=R.useRef(null),N=R.useCallback(function(){C&&clearInterval(C.current)},[C]),k=R.useCallback(function(){if(!l||1===E)return!1;N();var e=setInterval(function(){y(function(e){return e+1})},s);C.current=e},[l,C,s,N,E]);R.useEffect(function(){return k(),function(){return clearInterval(C.current)}},[k]);var A=R.useMemo(function(){return{duration:500,children:a,vertical:u,total:E,activeIndex:h,resetIndex:y}},[a,E,u,h]),I=R.useMemo(function(){return{arrowVisible:w,onClick:y}},[w,y]),M=R.useMemo(function(){return{vertical:u,total:E,activeIndex:h,resetIndex:y,dotsTrigger:p}},[u,E,h,p]);return V.createElement("div",{className:L("au-carousel",n),onMouseOver:function(){return t()},onMouseOut:function(){return r()}},V.createElement(z,A),g&&V.createElement(j,I),V.createElement(P,M))}});