UNPKG

react-basic-tabs

Version:
1 lines 15 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React")):"function"==typeof define&&define.amd?define(["React"],e):"object"==typeof exports?exports.TabPanel=e(require("React")):t.TabPanel=e(t.React)}(this,function(t){return function(t){function e(n){if(r[n])return r[n].exports;var s=r[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(){}var s=r(4),o=r(1).copy,i=r(1).copyList,l=r(1).copyKeys,a=r(1).copyExceptKeys,c=r(26),u=r(25),p=s.createFactory(c),f=s.createFactory(u),y=r(3),h=s.createClass({displayName:"TabPanel",propTypes:{activeIndex:s.PropTypes.number,activeStyle:s.PropTypes.object,activeClassName:s.PropTypes.string,defaultStyle:s.PropTypes.object,defaultClassName:s.PropTypes.string,titleStyle:s.PropTypes.object,titleClassName:s.PropTypes.string,activeTitleStyle:s.PropTypes.object,activeTitleClassName:s.PropTypes.string,onChange:s.PropTypes.func,stripListStyle:s.PropTypes.object,stripFactory:s.PropTypes.func,containerFactory:s.PropTypes.func,tabVerticalPosition:s.PropTypes.string},getDefaultProps:function(){return{activeIndex:0,activeStyle:{},activeClassName:"active",defaultStyle:{},defaultClassName:"",titleStyle:{},titleClassName:"",activeTitleStyle:{},activeTitleClassName:"active",tabVerticalPosition:"top"}},render:function(){var t=o(this.props);t.children=t.children||[];var e=t.activeIndex||0;t.activeIndex=Math.min(e,t.children.length-1),t.className=t.className||"",t.className+=" "+y;var r=this.renderStrip(t),n=this.renderContainer(t),i="bottom"==t.tabVerticalPosition?[n,r]:[r,n],l={className:t.className,style:t.style};return s.createElement("div",s.__spread({},l),i)},renderContainer:function(t){var e=i(t,["activeIndex","activeClassName","activeStyle","defaultStyle","defaultClassName","hiddenStyle","children"]);return e.key="container",t.containerFactory?t.containerFactory(e,f):f(e)},renderStrip:function(t){var e=a(t,{},{stripStyle:1,activeTitleStyle:1,activeTitleClassName:1});return l(t,e,{stripStyle:"style",activeTitleStyle:"activeStyle",activeTitleClassName:"activeClassName"}),e.key="strip",e.onChange=this.handleChange||n,t.stripFactory?t.stripFactory(e,p):p(e)},handleChange:function(t){this.props.onChange(t)}});h.Strip=c,h.Container=u,t.exports=h},function(t,e,r){t.exports=function(){"use strict";var t=Object.prototype.hasOwnProperty,e="object",n="undefined";return{copy:r(9),copyIf:r(10),copyAs:function(r,n){var s={};if(n=n||1,null!=r&&typeof r===e)for(var o in r)t.call(r,o)&&(s[o]=n);return s},copyList:r(5),copyListIf:r(6),copyKeys:r(11),copyKeysIf:r(12),copyExceptKeys:function(r,n,s){if(n=n||{},s=s||{},null!=r&&typeof r===e)for(var o in r)t.call(r,o)&&!t.call(s,o)&&(n[o]=r[o]);return n},bindCopyKeys:function(r,s,o){if(2==arguments.length&&(o=s,s=null),s=s||{},null!=r&&typeof r===e&&null!=o&&typeof o===e){var i,l,a,c;for(var u in o)t.call(o,u)&&(l=o[u],i=typeof l,c=r[u],a=typeof c,a!==n&&(s["string"==i?l:u]="function"==a?c.bind(r):c))}return s}}}()},function(t){"use strict";function e(t,e){function r(n){function s(){var s=arguments.length,o=[].concat(n);return s&&o.push.apply(o,arguments),o.length<e?r(o):t.apply(this,o)}return s}return"number"!=typeof e&&(e=t.length),r([])}t.exports=e},function(t){t.exports="basic-tabs"},function(e){e.exports=t},function(t){"use strict";var e="undefined";t.exports=function(t,r,n){arguments.length<3&&(n=r,r=null),r=r||{},n=n||Object.keys(t);for(var s,o=0,i=n.length;i>o;o++)s=n[o],typeof t[s]!==e&&(r[n[o]]=t[n[o]]);return r}},function(t){"use strict";var e="undefined";t.exports=function(t,r,n){arguments.length<3&&(n=r,r=null),r=r||{},n=n||Object.keys(t);for(var s,o=0,i=n.length;i>o;o++)s=n[o],typeof t[s]!==e&&typeof r[s]===e&&(r[s]=t[s]);return r}},function(t){"use strict";var e=Array.prototype.slice;t.exports=function(t,r){return function(){var n=e.call(r||[]);return arguments.length&&n.push.apply(n,arguments),t.apply(this,n)}}},function(t){"use strict";var e=Array.prototype.slice;t.exports=function(t,r){return function(){return Array.isArray(r)||(r=e.call(r||[])),t.apply(this,r)}}},function(t){"use strict";var e=Object.prototype.hasOwnProperty,r="object";t.exports=function(t,n){if(n=n||{},null!=t&&typeof t===r)for(var s in t)e.call(t,s)&&(n[s]=t[s]);return n}},function(t){"use strict";var e=Object.prototype.hasOwnProperty,r="object",n="undefined";t.exports=function(t,s){if(s=s||{},null!=t&&typeof t===r)for(var o in t)e.call(t,o)&&typeof s[o]===n&&(s[o]=t[o]);return s}},function(t,e,r){"use strict";var n="undefined",s="object",o=Object.prototype.hasOwnProperty,i=r(5);t.exports=function(t,e,r){if(arguments.length<3&&(r=e,e=null),e=e||{},!r||Array.isArray(r))return i(t,e,r);if(null!=t&&typeof t===s&&null!=r&&typeof r===s){var l,a;for(var c in r)o.call(r,c)&&(a=r[c],l=typeof a,typeof t[c]!==n&&(e["string"==l?a:c]=t[c]))}return e}},function(t,e,r){"use strict";var n="undefined",s="object",o=Object.prototype.hasOwnProperty,i=r(6);t.exports=function(t,e,r){if(arguments.length<3&&(r=e,e=null),e=e||{},!r||Array.isArray(r))return i(t,e,r);if(null!=t&&typeof t===s&&null!=r&&typeof r===s){var l,a,c;for(var u in r)o.call(r,u)&&(a=r[u],l=typeof a,c="string"==l?a:u,typeof t[u]!==n&&typeof e[c]===n&&(e[c]=t[u]))}return e}},function(t,e,r){var n=function(t){setTimeout(t,0)},s=clearTimeout,o=Array.prototype.slice,i=r(2),l=function(t,e,r){if(r="function"==typeof r?r:function(t){return t},Array.isArray(e)){for(var n,s=0,o=e.length;o>s;s++)if(n=e[s],t(n,s,e))return r(n,s,e)}else if("object"==typeof e)for(var i,n,l=Object.keys(e),s=0,o=l.length;o>s;s++)if(i=l[s],n=e[i],t(n,i,e))return r(n,i,e)},a=i(l,2),c=i(function(t,e){return l(t,e,function(t,e){return e})}),u=function(t){return Object.keys(t).forEach(function(e){"function"==typeof t[e]&&(t[e]=t[e].bind(t))}),t},p=r(18),f=r(17),y=r(24),h=r(7),d=r(16),v=r(8),m=r(20),S=function(t,e){return function(){var r=o.call(arguments,e||0);return t.apply(this,r)}},g=function(t,e,r){return function(){var n=[].from(arguments),s={stop:!1};r&&n.push(s);var o=e.apply(this,n);if(r){if(s.stop===!0)return o}else if(o===!1)return o;return t.apply(this,arguments)}},b=function(t,e,r){var s=1*e==e;return 2!=arguments.length||s?s||(e=0):(r=e,e=0),function(){var s=r||this,o=arguments;return 0>e?void t.apply(s,o):void(e||!n?setTimeout(function(){t.apply(s,o)},e):n(function(){t.apply(s,o)}))}},P=function(t,e){return b(t,0,e)},x=function(t,e,r){var o=-1;return function(){var i=r||this,l=arguments;if(0>e)return void t.apply(i,l);var a=e||!n,c=a?clearTimeout:s,u=a?setTimeout:n;-1!==o&&c(o),o=u(function(){t.apply(i,l),i=null},e)}},T=function(t,e,r){var n,s,o=-1;return function(){n=r||this,s=arguments,-1!==o||(o=setTimeout(function(){t.apply(n,s),n=null,o=-1},e))}},N=function(t,e,r){var n,s,o=-1,i=0,l=0,a={},c=!0;return s=n=function(){var u=arguments,p=r||this;c&&(a[i++]={args:u,scope:p}),-1!==o||(o=setTimeout(function(){t.apply(p,u),o=-1,l++,i!==l?(s=h(n,a[l].args).bind(a[l].scope),delete a[l],c=!1,s.apply(p),c=!0):a={}},e))}};t.exports={map:r(21),dot:r(19),maxArgs:r(22),compose:p,self:function(t){return t},buffer:x,delay:b,defer:P,skipArgs:S,intercept:function(t,e,r){return g(e,t,r)},throttle:T,spread:N,chain:function(t,e,r){return f(e,r,t)},before:function(t,e){return f("before",e,t)},after:function(t,e){return f("after",e,t)},curry:i,once:y,bindArgs:d,bindArgsArray:h,lockArgs:m,lockArgsArray:v,bindFunctionsOf:u,find:a,findIndex:c,newify:r(23)}},function(t){t.exports=function(){"use strict";var t={};return function(e){if(!t[e]){for(var r=[],n=0;e>n;n++)r.push("a["+n+"]");t[e]=new Function("c","a","return new c("+r.join(",")+")")}return t[e]}}()},function(t,e,r){var n=r(14);t.exports=function(t,e){return n(e.length)(t,e)}},function(t,e,r){"use strict";var n=Array.prototype.slice,s=r(7);t.exports=function(t){return s(t,n.call(arguments,1))}},function(t){"use strict";function e(t,e,r){return function(){"before"===t&&r.apply(this,arguments);var n=e.apply(this,arguments);return"before"!==t&&r.apply(this,arguments),n}}t.exports=e},function(t){"use strict";function e(t,e){return function(){return t(e.apply(this,arguments))}}t.exports=function(){for(var t=arguments,r=t.length,n=0,s=t[0];++n<r;)s=e(s,t[n]);return s}},function(t,e,r){"use strict";var n=r(2);t.exports=n(function(t,e){return void 0!=e?e[t]:void 0})},function(t,e,r){"use strict";var n=Array.prototype.slice,s=r(8);t.exports=function(t){return s(t,n.call(arguments,1))}},function(t,e,r){"use strict";var n=r(2);t.exports=n(function(t,e){return void 0!=e?e.map(t):t(e)})},function(t,e,r){"use strict";{var n=Array.prototype.slice;r(2)}t.exports=function(t,e){return function(){return t.apply(this,n.call(arguments,0,e))}}},function(t,e,r){"use strict";var n=r(15),s=r(2);t.exports=s(n)},function(t){"use once";function e(t,e){var r,n;return function(){return r?n:(r=!0,n=t.apply(e||this,arguments))}}t.exports=e},function(t,e,r){"use strict";var n=r(4),s=r(1).copy,o=r(3);t.exports=n.createClass({displayName:"TabPanel.Container",propTypes:{activeIndex:n.PropTypes.number,defaultClassName:n.PropTypes.string,defaultStyle:n.PropTypes.object,hiddenStyle:n.PropTypes.object,activeClassName:n.PropTypes.string,activeStyle:n.PropTypes.object},getDefaultProps:function(){return{activeIndex:0,hiddenStyle:{display:"none"}}},render:function(){return n.createElement("section",{className:o+"-container"},this.props.children.map(this.renderItem,this))},renderItem:function(t,e){var r=this.props,i=r.hiddenStyle,l=r.activeIndex||0,a={},c=o+"-item ";return e!==l?s(i,a):(s(r.activeStyle,a),c+=r.activeClassName||""),r.defaultStyle&&(t.props.style=s(r.defaultStyle,t.props.style)),r.defaultClassName&&(t.props.className=t.props.className||"",t.props.className+=" "+r.defaultClassName),n.createElement("article",{key:e,style:a,className:c},t)}})},function(t,e,r){"use strict";function n(t){t.preventDefault(),t.stopPropagation()}var s=r(4),o=r(1).copy,i=r(13),l=i.buffer,a=r(3),c={display:"inline-block"},u={margin:0,padding:0,listStyle:"none",position:"relative",display:"inline-block"},p={top:0,position:"absolute",height:"100%",cursor:"pointer"},f=s.createClass({displayName:"Scroller",display:"Scroller",getDefaultProps:function(){return{width:5}},render:function(){var t=this.props,e=this.props.side;t.className=t.className||"",t.className+=" "+a+"-scroller "+e,t.active&&t.visible&&(t.className+=" active");var r=o(p);return t.style=o(t.style,r),t.style.width=t.style.width||t.width,t.style[e]=0,t.visible||(t.style.display="none"),t.factory?t.factory(t,e):s.createElement("div",s.__spread({},t))}}),y=s.createFactory(f);t.exports=s.createClass({displayName:"exports",display:"TabPanel.Strip",propTypes:{activeIndex:s.PropTypes.number,activeStyle:s.PropTypes.object,activeClassName:s.PropTypes.string,titleStyle:s.PropTypes.object,titleClassName:s.PropTypes.string,anchorStyle:s.PropTypes.object,scrollerStyle:s.PropTypes.object,scrollerProps:s.PropTypes.object,scrollerWidth:s.PropTypes.number,scrollStep:s.PropTypes.number,scrollSpeed:s.PropTypes.number},getInitialState:function(){return{adjustScroll:!0,scrollPos:0}},componentWillUnmount:function(){this.props.enableScroll&&window.removeEventListener("resize",this.onResizeListener)},componentDidMount:function(){this.props.enableScroll&&setTimeout(function(){this.adjustScroll(),window.addEventListener("resize",this.onResizeListener=l(this.onWindowResize,this.props.onWindowResizeBuffer,this))}.bind(this),0)},componentDidUpdate:function(){this.props.enableScroll&&this.adjustScroll()},onWindowResize:function(){this.adjustScroll(),this.doScroll(0)},adjustScroll:function(){if(this.props.enableScroll){if(!this.state.adjustScroll)return void(this.state.adjustScroll=!0);var t=this.getAvailableStripWidth(),e=this.getCurrentListWidth(),r={adjustScroll:!1,hasLeftScroll:!1,hasRightScroll:!1};e>t?(r.maxScrollPos=e-t,r.hasLeftScroll=0!==this.state.scrollPos,r.hasRightScroll=this.state.scrollPos!=r.maxScrollPos):(r.maxScrollPos=0,r.scrollPos=0),this.setState(r)}},getCurrentListWidth:function(){return this.refs.list.getDOMNode().offsetWidth},getAvailableStripWidth:function(){var t=this.getDOMNode(),e=window.getComputedStyle(t),r=parseInt(e.left,10),n=parseInt(e.right,10);return isNaN(r)&&(r=0),isNaN(n)&&(n=0),t.clientWidth-r-n},handleScrollLeft:function(t){t.preventDefault(),this.handleScroll(-1)},handleScrollRight:function(t){t.preventDefault(),this.handleScroll(1)},handleScrollLeftMax:function(t){n(t),this.handleScrollMax(-1)},handleScrollRightMax:function(t){n(t),this.handleScrollMax(1)},handleScrollMax:function(t){var e=-1==t?0:this.state.maxScrollPos;this.setScrollPosition(e)},handleScroll:function(t){var e=function(){this.stopScroll(),window.removeEventListener("mouseup",e)}.bind(this);window.addEventListener("mouseup",e),this.scrollInterval=setInterval(this.doScroll.bind(this,t),this.props.scrollSpeed)},doScroll:function(t){this.setState({scrollDirection:t});var e=this.state.scrollPos+t*this.props.scrollStep;this.setScrollPosition(e)},setScrollPosition:function(t){t>this.state.maxScrollPos&&(t=this.state.maxScrollPos),0>t&&(t=0),this.setState({scrollPos:t,scrolling:!0})},stopScroll:function(){clearInterval(this.scrollInterval),this.setState({scrolling:!1})},getDefaultProps:function(){return{onWindowResizeBuffer:50,scrollStep:5,scrollSpeed:50,scrollerWidth:8,scrollerProps:{},enableScroll:!1,hasLeftScroll:!1,hasRightScroll:!1,activeClassName:"",activeStyle:{},anchorStyle:{color:"inherit",textDecoration:"inherit"}}},renderTitle:i.curry(function(t,e,r,n,i){var l=t.anchorStyle,a=t.activeStyle,c=t.activeClassName,u=t.activeIndex||0,p=n.props,f=p.tabTitle||p.title;r=o(r),o(p.titleStyle,r);var y=e.concat(p.titleClassName||"");return i==u&&(o(a,r),y.push(c||"")),s.createElement("li",{key:i,onClick:this.handleChange.bind(this,i),style:r,className:y.join(" ")},s.createElement("a",{href:"#",style:l},f))}),render:function(){var t=o(this.props),e=o(c);o(t.titleStyle,e);var r=[t.titleClassName||"",a+"-item-title"],n=t.children.map(this.renderTitle(t,r,e),this);t.className=t.className||"",t.className+=" "+a+"-strip",t.style=t.style||{},t.style.position="relative";var i=o(u);this.state.scrollPos&&(i.left=-this.state.scrollPos);var l=this.renderScroller(-1),p=this.renderScroller(1);return s.createElement("nav",s.__spread({},t),s.createElement("ul",{ref:"list",style:i},n),l,p)},handleChange:function(t,e){e.preventDefault(),this.props.onChange(t)},renderScroller:function(t){if(this.props.enableScroll){var e=-1==t?this.handleScrollLeftMax:this.handleScrollRightMax,r=-1==t?this.handleScrollLeft:this.handleScrollRight,n=-1==t?"left":"right",s=-1==t?this.state.hasLeftScroll:this.state.hasRightScroll;return y(o(this.props.scrollerProps,{factory:this.props.scrollerFactory,active:this.state.scrollDirection==t&&this.state.scrolling,onDoubleClick:e,onMouseDown:r,style:this.props.scrollerStyle,side:n,width:this.props.scrollerWidth,visible:s}))}}})}])});