UNPKG

@auraxy/carousel

Version:

A description for the module

10 lines (8 loc) 7.56 kB
/** * Bundle of @auraxy/carousel * Generated: 2020-01-15 * Version: 1.0.0 * License: MIT * Author: */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).Carousel={},e.React)}(this,function(I,M){"use strict";var R="default"in M?M.default:M;function O(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,o=!1,n=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){o=!0,n=e}finally{try{a||null==i.return||i.return()}finally{if(o)throw n}}return r}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var e,t,r,S=(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 o=u.apply(null,r);o&&e.push(o)}else if("object"==a)for(var n in r)i.call(r,n)&&r[n]&&e.push(n)}}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],o=document.createElement("style");o.type="text/css","top"===r&&a.firstChild?a.insertBefore(o,a.firstChild):a.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(t=I.VisibleWay||(I.VisibleWay={})).ALWAYS="always",t.HOVER="hover",t.NEVER="never",(r=I.Trigger||(I.Trigger={})).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 W(e){var a=e.children,r=e.vertical,t=e.activeIndex,o=e.total,n=e.resetIndex,u=e.duration,i=M.useMemo(function(){return e=R.Children.toArray(a),t=e[0],r=e[e.length-1],e.unshift(r),e.push(t),e;var e,t,r},[a]),l=M.useMemo(function(){return i.length},[i]),s=O(M.useState(!0),2),c=s[0],d=s[1],f=M.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:c?r?"top":"left":"none",transitionDuration:c?u+"ms":"0"}},[r,l,t,c,u]),m=M.useRef(null);return M.useEffect(function(){var e=null;return e=o-1<t||t<0?setTimeout(function(){n(t<0?o-1:0),d(!1)},u+100):setTimeout(function(){return d(!0)},100),m.current=e,function(){return clearInterval(m.current)}},[t,o,n,u]),R.createElement("div",{className:"au-carousel-slider",style:f},i.map(function(e,t){return R.createElement("div",{key:t,className:"au-carousel-item",style:{width:r?"100%":"".concat(100/l,"%"),height:r?"".concat(100/l,"%"):"100%"}},e)}))}function n(){return R.createElement("svg",{viewBox:"0 0 1024 1024",version:"1.1",width:"200",height:"200"},R.createElement("defs",null,R.createElement("style",{type:"text/css"})),R.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 R.createElement("svg",{viewBox:"0 0 1024 1024",version:"1.1",width:"200",height:"200"},R.createElement("defs",null,R.createElement("style",{type:"text/css"})),R.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,o;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%}"),(o=i=i||{}).PREV="PREV",o.NEXT="NEXT";function L(e){function t(t){a(function(e){return t===i.PREV?e-1:e+1})}var r=e.arrowVisible,a=e.onClick,o=M.useMemo(function(){return{display:r?"block":"none"}},[r]);return R.createElement("div",{className:"au-carousel-arrow",style:o},R.createElement("div",{className:"au-carousel-arrow-item au-carousel-arrow-left",onClick:function(){return t(i.PREV)}},R.createElement(n,null)),R.createElement("div",{className:"au-carousel-arrow-item au-carousel-arrow-right",onClick:function(){return t(i.NEXT)}},R.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 j(e){var r=e.dotsTrigger,a=e.vertical,t=e.total,o=e.activeIndex,n=e.resetIndex;return R.createElement("ul",{className:S("au-carousel-dots",a?"au-carousel-dots-vertical":"au-carousel-dots-horizontal")},Array.from(Array(t),function(e,t){return R.createElement("li",{className:S("au-carousel-dots-item",a?"au-carousel-dots-item-vertical":"au-carousel-dots-item-horizontal"),key:t},R.createElement("span",{className:S("au-carousel-dots-item-button",o===t?"au-carousel-dots-item-button-active":""),onMouseEnter:function(){return e=t,void(r===I.Trigger.HOVER&&n(e));var e},onClick:function(){return e=t,void(r===I.Trigger.CLICK&&n(e));var e}}))}))}a(".au-carousel{position:relative;overflow:hidden;height:300px}");I.ReactCarousel=function(e){function t(){w(!0),C()}function r(){w(f===I.VisibleWay.ALWAYS),N()}var a=e.children,o=e.className,n=e.vertical,u=void 0!==n&&n,i=e.autoplay,l=void 0===i||i,s=e.interval,c=void 0===s?3e3:s,d=e.arrowVisibleWay,f=void 0===d?I.VisibleWay.HOVER:d,m=e.dotsTrigger,p=void 0===m?I.Trigger.HOVER:m,v=O(M.useState(0),2),h=v[0],y=v[1],g=M.useMemo(function(){return R.Children.count(a)},[a]),E=M.useMemo(function(){return!u&&f!==I.VisibleWay.NEVER&&1!==g},[u,f,g]),x=O(M.useState(f===I.VisibleWay.ALWAYS),2),b=x[0],w=x[1],V=M.useRef(null),C=M.useCallback(function(){V&&clearInterval(V.current)},[V]),N=M.useCallback(function(){if(!l||1===g)return!1;C();var e=setInterval(function(){y(function(e){return e+1})},c);V.current=e},[l,V,c,C,g]);M.useEffect(function(){return N(),function(){return clearInterval(V.current)}},[N]);var k=M.useMemo(function(){return{duration:500,children:a,vertical:u,total:g,activeIndex:h,resetIndex:y}},[a,g,u,h]),T=M.useMemo(function(){return{arrowVisible:b,onClick:y}},[b,y]),A=M.useMemo(function(){return{vertical:u,total:g,activeIndex:h,resetIndex:y,dotsTrigger:p}},[u,g,h,p]);return R.createElement("div",{className:S("au-carousel",o),onMouseOver:function(){return t()},onMouseOut:function(){return r()}},R.createElement(W,k),E&&R.createElement(L,T),R.createElement(j,A))},Object.defineProperty(I,"__esModule",{value:!0})});