UNPKG

react-modern-slider

Version:

A modern image carousel component built with react that supports boxes with different sizes. Demo: https://shamouni.github.io/shop-react

72 lines (68 loc) 17.3 kB
(function(b,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],g):(b=typeof globalThis<"u"?globalThis:b||self,g(b["react-modern-slider"]={},b.React))})(this,(function(b,g){"use strict";var j={exports:{}},x={};/** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var $;function Z(){if($)return x;$=1;var l=Symbol.for("react.transitional.element"),s=Symbol.for("react.fragment");function n(e,r,o){var i=null;if(o!==void 0&&(i=""+o),r.key!==void 0&&(i=""+r.key),"key"in r){o={};for(var c in r)c!=="key"&&(o[c]=r[c])}else o=r;return r=o.ref,{$$typeof:l,type:e,key:i,ref:r!==void 0?r:null,props:o}}return x.Fragment=s,x.jsx=n,x.jsxs=n,x}var R={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var U;function Q(){return U||(U=1,process.env.NODE_ENV!=="production"&&(function(){function l(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Ee?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case k:return"Fragment";case ue:return"Profiler";case ce:return"StrictMode";case he:return"Suspense";case ve:return"SuspenseList";case be:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case A:return"Portal";case fe:return(t.displayName||"Context")+".Provider";case de:return(t._context.displayName||"Context")+".Consumer";case pe:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case me:return a=t.displayName||null,a!==null?a:l(t.type)||"Memo";case X:a=t._payload,t=t._init;try{return l(t(a))}catch{}}return null}function s(t){return""+t}function n(t){try{s(t);var a=!1}catch{a=!0}if(a){a=console;var u=a.error,h=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return u.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",h),s(t)}}function e(t){if(t===k)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===X)return"<...>";try{var a=l(t);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function r(){var t=M.A;return t===null?null:t.getOwner()}function o(){return Error("react-stack-top-frame")}function i(t){if(q.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function c(t,a){function u(){B||(B=!0,console.error("%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://react.dev/link/special-props)",a))}u.isReactWarning=!0,Object.defineProperty(t,"key",{get:u,configurable:!0})}function d(){var t=l(this.type);return V[t]||(V[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function f(t,a,u,h,y,E,D,Y){return u=E.ref,t={$$typeof:O,type:t,key:a,props:E,_owner:y},(u!==void 0?u:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:d}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Y}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function p(t,a,u,h,y,E,D,Y){var v=a.children;if(v!==void 0)if(h)if(ge(v)){for(h=0;h<v.length;h++)w(v[h]);Object.freeze&&Object.freeze(v)}else console.error("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 w(v);if(q.call(a,"key")){v=l(t);var _=Object.keys(a).filter(function(we){return we!=="key"});h=0<_.length?"{key: someKey, "+_.join(": ..., ")+": ...}":"{key: someKey}",G[v+h]||(_=0<_.length?"{"+_.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,h,v,_,v),G[v+h]=!0)}if(v=null,u!==void 0&&(n(u),v=""+u),i(a)&&(n(a.key),v=""+a.key),"key"in a){u={};for(var W in a)W!=="key"&&(u[W]=a[W])}else u=a;return v&&c(u,typeof t=="function"?t.displayName||t.name||"Unknown":t),f(t,v,E,y,r(),u,D,Y)}function w(t){typeof t=="object"&&t!==null&&t.$$typeof===O&&t._store&&(t._store.validated=1)}var T=g,O=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),k=Symbol.for("react.fragment"),ce=Symbol.for("react.strict_mode"),ue=Symbol.for("react.profiler"),de=Symbol.for("react.consumer"),fe=Symbol.for("react.context"),pe=Symbol.for("react.forward_ref"),he=Symbol.for("react.suspense"),ve=Symbol.for("react.suspense_list"),me=Symbol.for("react.memo"),X=Symbol.for("react.lazy"),be=Symbol.for("react.activity"),Ee=Symbol.for("react.client.reference"),M=T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,q=Object.prototype.hasOwnProperty,ge=Array.isArray,C=console.createTask?console.createTask:function(){return null};T={react_stack_bottom_frame:function(t){return t()}};var B,V={},J=T.react_stack_bottom_frame.bind(T,o)(),H=C(e(o)),G={};R.Fragment=k,R.jsx=function(t,a,u,h,y){var E=1e4>M.recentlyCreatedOwnerStacks++;return p(t,a,u,!1,h,y,E?Error("react-stack-top-frame"):J,E?C(e(t)):H)},R.jsxs=function(t,a,u,h,y){var E=1e4>M.recentlyCreatedOwnerStacks++;return p(t,a,u,!0,h,y,E?Error("react-stack-top-frame"):J,E?C(e(t)):H)}})()),R}var I;function K(){return I||(I=1,process.env.NODE_ENV==="production"?j.exports=Z():j.exports=Q()),j.exports}var m=K();/*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var z=function(l,s){return(z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,e){n.__proto__=e}||function(n,e){for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r])})(l,s)},ee,P,re=((function(l){/*! Copyright (c) 2017 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames */(function(){var s={}.hasOwnProperty;function n(){for(var e=[],r=0;r<arguments.length;r++){var o=arguments[r];if(o){var i=typeof o;if(i==="string"||i==="number")e.push(o);else if(Array.isArray(o)&&o.length){var c=n.apply(null,o);c&&e.push(c)}else if(i==="object")for(var d in o)s.call(o,d)&&o[d]&&e.push(d)}}return e.join(" ")}l.exports?(n.default=n,l.exports=n):window.classNames=n})()})(P={path:ee,exports:{},require:function(l,s){return(function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")})(s==null&&P.path)}},P.exports),P.exports);function N(l,s,n){var e,r,o,i,c;function d(){var p=Date.now()-i;p<s&&p>=0?e=setTimeout(d,s-p):(e=null,n||(c=l.apply(o,r),o=r=null))}s==null&&(s=100);var f=function(){o=this,r=arguments,i=Date.now();var p=n&&!e;return e||(e=setTimeout(d,s)),p&&(c=l.apply(o,r),o=r=null),c};return f.clear=function(){e&&(clearTimeout(e),e=null)},f.flush=function(){e&&(c=l.apply(o,r),o=r=null,clearTimeout(e),e=null)},f}N.debounce=N;var te=N;(function(l,s){s===void 0&&(s={});var n=s.insertAt;if(typeof document<"u"){var e=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",n==="top"&&e.firstChild?e.insertBefore(r,e.firstChild):e.appendChild(r),r.styleSheet?r.styleSheet.cssText=l:r.appendChild(document.createTextNode(l))}})(`.indiana-scroll-container { overflow: auto; } .indiana-scroll-container--dragging { scroll-behavior: auto !important; } .indiana-scroll-container--dragging > * { pointer-events: none; cursor: -webkit-grab; cursor: grab; } .indiana-scroll-container--hide-scrollbars { overflow: hidden; overflow: -moz-scrollbars-none; -ms-overflow-style: none; scrollbar-width: none; } .indiana-scroll-container--hide-scrollbars::-webkit-scrollbar { display: none !important; height: 0 !important; width: 0 !important; background: transparent !important; -webkit-appearance: none !important; } .indiana-scroll-container--native-scroll { overflow: auto; } .indiana-dragging { cursor: -webkit-grab; cursor: grab; }`);var L,ne=(L="indiana-scroll-container",function(l,s){if(!l)return L;var n;typeof l=="string"?n=l:s=l;var e=L;return n&&(e+="__"+n),e+(s?Object.keys(s).reduce((function(r,o){var i=s[o];return i&&(r+=" "+(typeof i=="boolean"?e+"--"+o:e+"--"+o+"_"+i)),r}),""):"")}),oe=(function(l){function s(n){var e=l.call(this,n)||this;return e.onEndScroll=function(){e.scrolling=!1,!e.pressed&&e.started&&e.processEnd()},e.onScroll=function(r){var o=e.container.current;o.scrollLeft===e.scrollLeft&&o.scrollTop===e.scrollTop||(e.scrolling=!0,e.processScroll(r),e.onEndScroll())},e.onTouchStart=function(r){var o=e.props.nativeMobileScroll;if(e.isDraggable(r.target))if(e.internal=!0,o&&e.scrolling)e.pressed=!0;else{var i=r.touches[0];e.processClick(r,i.clientX,i.clientY),!o&&e.props.stopPropagation&&r.stopPropagation()}},e.onTouchEnd=function(r){var o=e.props.nativeMobileScroll;e.pressed&&(!e.started||e.scrolling&&o?e.pressed=!1:e.processEnd(),e.forceUpdate())},e.onTouchMove=function(r){var o=e.props.nativeMobileScroll;if(e.pressed&&(!o||!e.isMobile)){var i=r.touches[0];i&&e.processMove(r,i.clientX,i.clientY),r.preventDefault(),e.props.stopPropagation&&r.stopPropagation()}},e.onMouseDown=function(r){e.isDraggable(r.target)&&e.isScrollable()&&(e.internal=!0,e.props.buttons.indexOf(r.button)!==-1&&(e.processClick(r,r.clientX,r.clientY),r.preventDefault(),e.props.stopPropagation&&r.stopPropagation()))},e.onMouseMove=function(r){e.pressed&&(e.processMove(r,r.clientX,r.clientY),r.preventDefault(),e.props.stopPropagation&&r.stopPropagation())},e.onMouseUp=function(r){e.pressed&&(e.started?e.processEnd():(e.internal=!1,e.pressed=!1,e.forceUpdate(),e.props.onClick&&e.props.onClick(r)),r.preventDefault(),e.props.stopPropagation&&r.stopPropagation())},e.container=g.createRef(),e.onEndScroll=te(e.onEndScroll,300),e.scrolling=!1,e.started=!1,e.pressed=!1,e.internal=!1,e.getRef=e.getRef.bind(e),e}return(function(n,e){function r(){this.constructor=n}z(n,e),n.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)})(s,l),s.prototype.componentDidMount=function(){var n=this.props.nativeMobileScroll,e=this.container.current;window.addEventListener("mouseup",this.onMouseUp),window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("touchmove",this.onTouchMove,{passive:!1}),window.addEventListener("touchend",this.onTouchEnd),e.addEventListener("touchstart",this.onTouchStart,{passive:!1}),e.addEventListener("mousedown",this.onMouseDown,{passive:!1}),n&&(this.isMobile=this.isMobileDevice(),this.isMobile&&this.forceUpdate())},s.prototype.componentWillUnmount=function(){window.removeEventListener("mouseup",this.onMouseUp),window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd)},s.prototype.getElement=function(){return this.container.current},s.prototype.isMobileDevice=function(){return window.orientation!==void 0||navigator.userAgent.indexOf("IEMobile")!==-1},s.prototype.isDraggable=function(n){var e=this.props.ignoreElements;if(e){var r=n.closest(e);return r===null||r.contains(this.getElement())}return!0},s.prototype.isScrollable=function(){var n=this.container.current;return n&&(n.scrollWidth>n.clientWidth||n.scrollHeight>n.clientHeight)},s.prototype.processClick=function(n,e,r){var o=this.container.current;this.scrollLeft=o.scrollLeft,this.scrollTop=o.scrollTop,this.clientX=e,this.clientY=r,this.pressed=!0},s.prototype.processStart=function(n){n===void 0&&(n=!0);var e=this.props.onStartScroll;this.started=!0,n&&document.body.classList.add("indiana-dragging"),e&&e({external:!this.internal}),this.forceUpdate()},s.prototype.processScroll=function(n){if(this.started){var e=this.props.onScroll;e&&e({external:!this.internal})}else this.processStart(!1)},s.prototype.processMove=function(n,e,r){var o=this.props,i=o.horizontal,c=o.vertical,d=o.activationDistance,f=o.onScroll,p=this.container.current;this.started?(i&&(p.scrollLeft-=e-this.clientX),c&&(p.scrollTop-=r-this.clientY),f&&f({external:!this.internal}),this.clientX=e,this.clientY=r,this.scrollLeft=p.scrollLeft,this.scrollTop=p.scrollTop):(i&&Math.abs(e-this.clientX)>d||c&&Math.abs(r-this.clientY)>d)&&(this.clientX=e,this.clientY=r,this.processStart())},s.prototype.processEnd=function(){var n=this.props.onEndScroll;this.container.current&&n&&n({external:!this.internal}),this.pressed=!1,this.started=!1,this.scrolling=!1,this.internal=!1,document.body.classList.remove("indiana-dragging"),this.forceUpdate()},s.prototype.getRef=function(n){[this.container,this.props.innerRef].forEach((function(e){e&&(typeof e=="function"?e(n):e.current=n)}))},s.prototype.render=function(){var n=this.props,e=n.children,r=n.draggingClassName,o=n.className,i=n.style,c=n.hideScrollbars,d=n.component;return g.createElement(d,{className:re(o,this.pressed&&r,ne({dragging:this.pressed,"hide-scrollbars":c,"native-scroll":this.isMobile})),style:i,ref:this.getRef,onScroll:this.onScroll},e)},s.defaultProps={nativeMobileScroll:!0,hideScrollbars:!0,activationDistance:10,vertical:!0,horizontal:!0,stopPropagation:!1,style:{},component:"div",buttons:[0]},s})(g.PureComponent);let S;const F=2,se=l=>{const{delay:s=0}=l,n=s>3e3?s:3e3;g.useEffect(()=>(s&&e(),()=>{r()}),[]);const e=()=>{const c=document.querySelector(".slider-container");window.addEventListener("load",i),window.addEventListener("resize",i),window.addEventListener("blur",()=>clearTimeout(S)),window.addEventListener("focus",i),c.addEventListener("mouseenter",()=>clearTimeout(S)),c.addEventListener("mouseleave",i);const d=document.getElementById("prev-slide"),f=document.getElementById("next-slide");d.addEventListener("click",()=>o("prev",!1)),f.addEventListener("click",()=>o("next",!1))},r=()=>{window.removeEventListener("load",i),window.removeEventListener("resize",i),window.removeEventListener("blur",()=>clearTimeout(S)),window.removeEventListener("focus",i)},o=(c="next",d=!0)=>{const f=document.querySelector(".scroll-container"),p=window.screen.availWidth/1.1,w=f.scrollLeft,T=f.scrollWidth-f.offsetWidth;c==="next"?f.scrollLeft=w+F<T?w+p:0:f.scrollLeft=w-F>0?w-p:f.scrollWidth,clearTimeout(S),d&&(S=setTimeout(o,n))};function i(){clearTimeout(S),window.screen.availWidth>1200&&(S=setTimeout(o,n))}return m.jsxs("section",{className:"slider",children:[m.jsx("button",{id:"prev-slide",className:"arrow-slide",role:"button","aria-label":"prev"}),m.jsx("div",{id:"slides",className:"slider-container",children:m.jsx(oe,{className:"scroll-container",children:l.children})}),m.jsx("button",{id:"next-slide",className:"arrow-slide",role:"button","aria-label":"next"})]})},ie=l=>{const{title:s,text:n="",src:e,link:r="#",lbl:o,color:i,fontSize:c="small",height:d,borderTop:f,borderBottom:p,borderLeft:w,borderRight:T}=l,O=[f&&"brd-top",p&&"brd-bottom",w&&"brd-left",T&&"brd-right"].filter(Boolean).join(" "),A=d?`h-${d}`:"",k=c==="large"?"box-large":"";return m.jsxs("div",{className:`box brd ${A} ${O} ${k}`,children:[m.jsx("img",{width:960,height:615,src:e,alt:s,role:"img"}),r&&m.jsx("a",{className:"link",href:r,"aria-label":s}),m.jsxs("div",{className:"text",children:[m.jsx("span",{className:`lbl ${i}`,children:o}),m.jsx("h4",{className:"bold",children:r?m.jsx("a",{href:r,children:s}):s}),n&&m.jsx("p",{children:n})]})]})},ae=({children:l,height:s="3"})=>m.jsx("div",{className:`col-group h-${s}`,children:l}),le=({children:l,width:s})=>m.jsx("div",{className:`col h-100 col-${s}`,children:l});b.HBox=ae,b.Slide=ie,b.Slider=se,b.VBox=le,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})})); //# sourceMappingURL=index.umd.js.map