react-tabs
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
@@ -124,2 +124,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var DEFAULT_CLASS = 'react-tabs__tab'; | ||
var Tab = function (_Component) { | ||
@@ -170,3 +172,4 @@ _inherits(Tab, _Component); | ||
ref: function ref(node) { | ||
_this2.node = node;if (tabRef) tabRef(node); | ||
_this2.node = node; | ||
if (tabRef) tabRef(node); | ||
}, | ||
@@ -188,4 +191,4 @@ role: 'tab', | ||
Tab.defaultProps = { | ||
className: 'ReactTabs__Tab', | ||
disabledClassName: 'ReactTabs__Tab--disabled', | ||
className: DEFAULT_CLASS, | ||
disabledClassName: DEFAULT_CLASS + '--disabled', | ||
focus: false, | ||
@@ -195,6 +198,6 @@ id: null, | ||
selected: false, | ||
selectedClassName: 'ReactTabs__Tab--selected' | ||
selectedClassName: DEFAULT_CLASS + '--selected' | ||
}; | ||
exports.default = Tab; | ||
true ? Tab.propTypes = { | ||
Tab.propTypes = true ? { | ||
children: _propTypes2.default.oneOfType([_propTypes2.default.array, _propTypes2.default.object, _propTypes2.default.string]), | ||
@@ -209,3 +212,3 @@ className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]), | ||
selectedClassName: _propTypes2.default.string, // private | ||
tabRef: _propTypes2.default.func } : void 0; | ||
tabRef: _propTypes2.default.func } : {}; | ||
@@ -262,6 +265,3 @@ /***/ }), | ||
'ul', | ||
_extends({}, attributes, { | ||
className: (0, _classnames2.default)(className), | ||
role: 'tablist' | ||
}), | ||
_extends({}, attributes, { className: (0, _classnames2.default)(className), role: 'tablist' }), | ||
children | ||
@@ -275,9 +275,9 @@ ); | ||
TabList.defaultProps = { | ||
className: 'ReactTabs__TabList' | ||
className: 'react-tabs__tab-list' | ||
}; | ||
exports.default = TabList; | ||
true ? TabList.propTypes = { | ||
TabList.propTypes = true ? { | ||
children: _propTypes2.default.oneOfType([_propTypes2.default.object, _propTypes2.default.array]), | ||
className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]) | ||
} : void 0; | ||
} : {}; | ||
@@ -317,2 +317,4 @@ /***/ }), | ||
var DEFAULT_CLASS = 'react-tabs__tab-panel'; | ||
var TabPanel = function (_Component) { | ||
@@ -337,5 +339,4 @@ _inherits(TabPanel, _Component); | ||
selectedClassName = _props.selectedClassName, | ||
style = _props.style, | ||
tabId = _props.tabId, | ||
attributes = _objectWithoutProperties(_props, ['children', 'className', 'forceRender', 'id', 'selected', 'selectedClassName', 'style', 'tabId']); | ||
attributes = _objectWithoutProperties(_props, ['children', 'className', 'forceRender', 'id', 'selected', 'selectedClassName', 'tabId']); | ||
@@ -358,9 +359,9 @@ return _react2.default.createElement( | ||
TabPanel.defaultProps = { | ||
className: 'ReactTabs__TabPanel', | ||
className: DEFAULT_CLASS, | ||
forceRender: false, | ||
selectedClassName: 'ReactTabs__TabPanel--selected', | ||
selectedClassName: DEFAULT_CLASS + '--selected', | ||
style: {} | ||
}; | ||
exports.default = TabPanel; | ||
true ? TabPanel.propTypes = { | ||
TabPanel.propTypes = true ? { | ||
selectedClassName: _propTypes2.default.string, // private | ||
@@ -372,4 +373,3 @@ children: _propTypes2.default.node, | ||
selected: _propTypes2.default.bool, // private | ||
style: _propTypes2.default.object, | ||
tabId: _propTypes2.default.string } : void 0; | ||
tabId: _propTypes2.default.string } : {}; | ||
@@ -689,3 +689,3 @@ /***/ }), | ||
exports.default = Tabs; | ||
true ? Tabs.propTypes = { | ||
Tabs.propTypes = true ? { | ||
children: _propTypes3.childrenPropType, | ||
@@ -701,3 +701,3 @@ className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]), | ||
selectedTabPanelClassName: _propTypes2.default.string | ||
} : void 0; | ||
} : {}; | ||
@@ -767,2 +767,4 @@ /***/ }), | ||
var canUseActiveElement = !!(typeof window !== 'undefined' && window.document && window.document.activeElement); | ||
var UncontrolledTabs = function (_Component) { | ||
@@ -804,4 +806,4 @@ _inherits(UncontrolledTabs, _Component); | ||
var node = e.target; | ||
// eslint-disable-next-line no-cond-assign | ||
do { | ||
// eslint-disable-line no-cond-assign | ||
if (_this.isTabFromContainer(node)) { | ||
@@ -927,8 +929,12 @@ if (isTabDisabled(node)) { | ||
// If it is we should keep the focus on the next selected tab | ||
var wasTabFocused = _react2.default.Children.toArray(child.props.children).filter(function (tab) { | ||
return tab.type === _Tab2.default; | ||
}).some(function (tab, i) { | ||
return document.activeElement === _this2.getTab(i); | ||
}); | ||
var wasTabFocused = false; | ||
if (canUseActiveElement) { | ||
wasTabFocused = _react2.default.Children.toArray(child.props.children).filter(function (tab) { | ||
return tab.type === _Tab2.default; | ||
}).some(function (tab, i) { | ||
return document.activeElement === _this2.getTab(i); | ||
}); | ||
} | ||
result = (0, _react.cloneElement)(child, { | ||
@@ -1043,7 +1049,7 @@ children: _react2.default.Children.map(child.props.children, function (tab) { | ||
UncontrolledTabs.defaultProps = { | ||
className: 'ReactTabs', | ||
className: 'react-tabs', | ||
focus: false | ||
}; | ||
exports.default = UncontrolledTabs; | ||
true ? UncontrolledTabs.propTypes = { | ||
UncontrolledTabs.propTypes = true ? { | ||
children: _propTypes3.childrenPropType, | ||
@@ -1058,3 +1064,3 @@ className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]), | ||
selectedTabPanelClassName: _propTypes2.default.string | ||
} : void 0; | ||
} : {}; | ||
@@ -1061,0 +1067,0 @@ /***/ }), |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("classnames")):"function"==typeof define&&define.amd?define(["react","classnames"],t):"object"==typeof exports?exports.ReactTabs=t(require("react"),require("classnames")):e.ReactTabs=t(e.React,e.classNames)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=9)}([function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(0),u=r(i),f=n(1),d=r(f),p=function(e){function t(){return a(this,t),s(this,e.apply(this,arguments))}return l(t,e),t.prototype.componentDidMount=function(){this.checkFocus()},t.prototype.componentDidUpdate=function(){this.checkFocus()},t.prototype.checkFocus=function(){this.props.selected&&this.props.focus&&this.node.focus()},t.prototype.render=function(){var e,t=this,n=this.props,r=n.children,a=n.className,s=n.disabled,l=n.disabledClassName,i=(n.focus,n.id),f=n.panelId,p=n.selected,b=n.selectedClassName,h=n.tabRef,y=o(n,["children","className","disabled","disabledClassName","focus","id","panelId","selected","selectedClassName","tabRef"]);return u.default.createElement("li",c({},y,{className:(0,d.default)(a,(e={},e[b]=p,e[l]=s,e)),ref:function(e){t.node=e,h&&h(e)},role:"tab",id:i,"aria-selected":p?"true":"false","aria-disabled":s?"true":"false","aria-controls":f,tabIndex:p?"0":null}),r)},t}(i.Component);p.defaultProps={className:"ReactTabs__Tab",disabledClassName:"ReactTabs__Tab--disabled",focus:!1,id:null,panelId:null,selected:!1,selectedClassName:"ReactTabs__Tab--selected"},t.default=p},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(0),u=r(i),f=n(1),d=r(f),p=function(e){function t(){return a(this,t),s(this,e.apply(this,arguments))}return l(t,e),t.prototype.render=function(){var e=this.props,t=e.children,n=e.className,r=o(e,["children","className"]);return u.default.createElement("ul",c({},r,{className:(0,d.default)(n),role:"tablist"}),t)},t}(i.Component);p.defaultProps={className:"ReactTabs__TabList"},t.default=p},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i=n(0),u=r(i),f=n(1),d=r(f),p=function(e){function t(){return a(this,t),s(this,e.apply(this,arguments))}return l(t,e),t.prototype.render=function(){var e,t=this.props,n=t.children,r=t.className,a=t.forceRender,s=t.id,l=t.selected,i=t.selectedClassName,f=(t.style,t.tabId),p=o(t,["children","className","forceRender","id","selected","selectedClassName","style","tabId"]);return u.default.createElement("div",c({},p,{className:(0,d.default)(r,(e={},e[i]=l,e)),role:"tabpanel",id:s,"aria-labelledby":f}),a||l?n:null)},t}(i.Component);p.defaultProps={className:"ReactTabs__TabPanel",forceRender:!1,selectedClassName:"ReactTabs__TabPanel--selected",style:{}},t.default=p},function(e,t,n){"use strict";function r(){return"react-tabs-"+a++}function o(){a=0}t.__esModule=!0,t.default=r,t.reset=o;var a=0},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e){var t=l.default.Children.toArray(e).filter(function(e){return e.type===i.default});return t[0]&&t[0].props.children?l.default.Children.count(l.default.Children.toArray(t[0].props.children).filter(function(e){return e.type===f.default})):0}function a(e){return l.default.Children.count(l.default.Children.toArray(e).filter(function(e){return e.type===p.default}))}t.__esModule=!0,t.getTabsCount=o,t.getPanelsCount=a;var s=n(0),l=r(s),c=n(3),i=r(c),u=n(2),f=r(u),d=n(4),p=r(d)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var c=n(0),i=r(c),u=n(8),f=r(u),d=n(6),p=function(e){function t(n){a(this,t);var r=s(this,e.call(this,n));return r.handleSelected=function(e,n,o){if("function"!=typeof r.props.onSelect||!1!==r.props.onSelect(e,n,o)){var a={focus:"keydown"===o.type};t.inUncontrolledMode(r.props)&&(a.selectedIndex=e),r.setState(a)}},r.state=t.copyPropsToState(r.props,{},r.props.defaultFocus),r}return l(t,e),t.prototype.componentWillReceiveProps=function(e){this.setState(function(n){return t.copyPropsToState(e,n)})},t.inUncontrolledMode=function(e){return null===e.selectedIndex},t.copyPropsToState=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o={focus:r};if(t.inUncontrolledMode(e)){var a=(0,d.getTabsCount)(e.children)-1,s=null;s=null!=n.selectedIndex?Math.min(n.selectedIndex,a):e.defaultIndex||0,o.selectedIndex=s}return o},t.prototype.render=function(){var e=this.props,t=e.children,n=(e.defaultIndex,e.defaultFocus,o(e,["children","defaultIndex","defaultFocus"]));return n.focus=this.state.focus,n.onSelect=this.handleSelected,null!=this.state.selectedIndex&&(n.selectedIndex=this.state.selectedIndex),i.default.createElement(f.default,n,t)},t}(c.Component);p.defaultProps={defaultFocus:!1,forceRenderTabPanel:!1,selectedIndex:null,defaultIndex:null},t.default=p},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function c(e){return"LI"===e.nodeName&&"tab"===e.getAttribute("role")}function i(e){return"true"===e.getAttribute("aria-disabled")}t.__esModule=!0;var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},f=n(0),d=r(f),p=n(1),b=r(p),h=n(5),y=r(h),m=n(2),v=r(m),T=n(3),C=r(T),_=n(4),O=r(_),w=n(6),g=function(e){function t(){var n,r,o;a(this,t);for(var l=arguments.length,u=Array(l),f=0;f<l;f++)u[f]=arguments[f];return n=r=s(this,e.call.apply(e,[this].concat(u))),r.tabNodes=[],r.handleKeyDown=function(e){if(r.isTabFromContainer(e.target)){var t=r.props.selectedIndex,n=!1;37===e.keyCode||38===e.keyCode?(t=r.getPrevTab(t),n=!0):39!==e.keyCode&&40!==e.keyCode||(t=r.getNextTab(t),n=!0),n&&e.preventDefault(),r.setSelected(t,e)}},r.handleClick=function(e){var t=e.target;do{if(r.isTabFromContainer(t)){if(i(t))return;var n=[].slice.call(t.parentNode.children).filter(c).indexOf(t);return void r.setSelected(n,e)}}while(null!==(t=t.parentNode))},o=n,s(r,o)}return l(t,e),t.prototype.setSelected=function(e,t){e!==this.props.selectedIndex&&(e<0||e>=this.getTabsCount()||this.props.onSelect(e,this.props.selectedIndex,t))},t.prototype.getNextTab=function(e){for(var t=this.getTabsCount(),n=e+1;n<t;n++)if(!i(this.getTab(n)))return n;for(var r=0;r<e;r++)if(!i(this.getTab(r)))return r;return e},t.prototype.getPrevTab=function(e){for(var t=e;t--;)if(!i(this.getTab(t)))return t;for(t=this.getTabsCount();t-- >e;)if(!i(this.getTab(t)))return t;return e},t.prototype.getTabsCount=function(){return(0,w.getTabsCount)(this.props.children)},t.prototype.getPanelsCount=function(){return(0,w.getPanelsCount)(this.props.children)},t.prototype.getTab=function(e){return this.tabNodes["tabs-"+e]},t.prototype.getChildren=function(){var e=this,t=0,n=this.props,r=n.children,o=n.disabledTabClassName,a=n.focus,s=n.forceRenderTabPanel,l=n.selectedIndex,c=n.selectedTabClassName,i=n.selectedTabPanelClassName;this.tabIds=this.tabIds||[],this.panelIds=this.panelIds||[];for(var u=this.tabIds.length-this.getTabsCount();u++<0;)this.tabIds.push((0,y.default)()),this.panelIds.push((0,y.default)());return d.default.Children.map(r,function(n){if(null===n)return null;var r=n;if(n.type===C.default){var u=0,p=d.default.Children.toArray(n.props.children).filter(function(e){return e.type===v.default}).some(function(t,n){return document.activeElement===e.getTab(n)});r=(0,f.cloneElement)(n,{children:d.default.Children.map(n.props.children,function(t){if(null===t)return null;if(t.type!==v.default)return t;var n="tabs-"+u,r=l===u,s={tabRef:function(t){e.tabNodes[n]=t},id:e.tabIds[u],panelId:e.panelIds[u],selected:r,focus:r&&(a||p)};return c&&(s.selectedClassName=c),o&&(s.disabledClassName=o),u++,(0,f.cloneElement)(t,s)})})}else if(n.type===O.default){var b={id:e.panelIds[t],tabId:e.tabIds[t],selected:l===t};s&&(b.forceRender=s),i&&(b.selectedClassName=i),t++,r=(0,f.cloneElement)(n,b)}return r})},t.prototype.isTabFromContainer=function(e){if(!c(e))return!1;var t=e.parentElement;do{if(t===this.node)return!0;if(t.getAttribute("data-tabs"))break;t=t.parentElement}while(t);return!1},t.prototype.render=function(){var e=this,t=this.props,n=(t.children,t.className),r=(t.disabledTabClassName,t.focus,t.forceRenderTabPanel,t.onSelect,t.selectedIndex,t.selectedTabClassName,t.selectedTabPanelClassName,o(t,["children","className","disabledTabClassName","focus","forceRenderTabPanel","onSelect","selectedIndex","selectedTabClassName","selectedTabPanelClassName"]));return d.default.createElement("div",u({},r,{className:(0,b.default)(n),onClick:this.handleClick,onKeyDown:this.handleKeyDown,ref:function(t){e.node=t},"data-tabs":!0}),this.getChildren())},t}(f.Component);g.defaultProps={className:"ReactTabs",focus:!1},t.default=g},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.resetIdCounter=t.Tabs=t.TabPanel=t.TabList=t.Tab=void 0;var o=n(7),a=r(o),s=n(3),l=r(s),c=n(2),i=r(c),u=n(4),f=r(u),d=n(5);t.Tab=i.default,t.TabList=l.default,t.TabPanel=f.default,t.Tabs=a.default,t.resetIdCounter=d.reset}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("classnames")):"function"==typeof define&&define.amd?define(["react","classnames"],t):"object"==typeof exports?exports.ReactTabs=t(require("react"),require("classnames")):e.ReactTabs=t(e.React,e.classNames)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=9)}([function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c=n(0),u=r(c),f=n(1),d=r(f),p=function(e){function t(){return a(this,t),s(this,e.apply(this,arguments))}return l(t,e),t.prototype.componentDidMount=function(){this.checkFocus()},t.prototype.componentDidUpdate=function(){this.checkFocus()},t.prototype.checkFocus=function(){this.props.selected&&this.props.focus&&this.node.focus()},t.prototype.render=function(){var e,t=this,n=this.props,r=n.children,a=n.className,s=n.disabled,l=n.disabledClassName,c=(n.focus,n.id),f=n.panelId,p=n.selected,b=n.selectedClassName,h=n.tabRef,y=o(n,["children","className","disabled","disabledClassName","focus","id","panelId","selected","selectedClassName","tabRef"]);return u.default.createElement("li",i({},y,{className:(0,d.default)(a,(e={},e[b]=p,e[l]=s,e)),ref:function(e){t.node=e,h&&h(e)},role:"tab",id:c,"aria-selected":p?"true":"false","aria-disabled":s?"true":"false","aria-controls":f,tabIndex:p?"0":null}),r)},t}(c.Component);p.defaultProps={className:"react-tabs__tab",disabledClassName:"react-tabs__tab--disabled",focus:!1,id:null,panelId:null,selected:!1,selectedClassName:"react-tabs__tab--selected"},t.default=p,p.propTypes={}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c=n(0),u=r(c),f=n(1),d=r(f),p=function(e){function t(){return a(this,t),s(this,e.apply(this,arguments))}return l(t,e),t.prototype.render=function(){var e=this.props,t=e.children,n=e.className,r=o(e,["children","className"]);return u.default.createElement("ul",i({},r,{className:(0,d.default)(n),role:"tablist"}),t)},t}(c.Component);p.defaultProps={className:"react-tabs__tab-list"},t.default=p,p.propTypes={}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c=n(0),u=r(c),f=n(1),d=r(f),p=function(e){function t(){return a(this,t),s(this,e.apply(this,arguments))}return l(t,e),t.prototype.render=function(){var e,t=this.props,n=t.children,r=t.className,a=t.forceRender,s=t.id,l=t.selected,c=t.selectedClassName,f=t.tabId,p=o(t,["children","className","forceRender","id","selected","selectedClassName","tabId"]);return u.default.createElement("div",i({},p,{className:(0,d.default)(r,(e={},e[c]=l,e)),role:"tabpanel",id:s,"aria-labelledby":f}),a||l?n:null)},t}(c.Component);p.defaultProps={className:"react-tabs__tab-panel",forceRender:!1,selectedClassName:"react-tabs__tab-panel--selected",style:{}},t.default=p,p.propTypes={}},function(e,t,n){"use strict";function r(){return"react-tabs-"+a++}function o(){a=0}t.__esModule=!0,t.default=r,t.reset=o;var a=0},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e){var t=l.default.Children.toArray(e).filter(function(e){return e.type===c.default});return t[0]&&t[0].props.children?l.default.Children.count(l.default.Children.toArray(t[0].props.children).filter(function(e){return e.type===f.default})):0}function a(e){return l.default.Children.count(l.default.Children.toArray(e).filter(function(e){return e.type===p.default}))}t.__esModule=!0,t.getTabsCount=o,t.getPanelsCount=a;var s=n(0),l=r(s),i=n(3),c=r(i),u=n(2),f=r(u),d=n(4),p=r(d)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var i=n(0),c=r(i),u=n(8),f=r(u),d=n(6),p=function(e){function t(n){a(this,t);var r=s(this,e.call(this,n));return r.handleSelected=function(e,n,o){if("function"!=typeof r.props.onSelect||!1!==r.props.onSelect(e,n,o)){var a={focus:"keydown"===o.type};t.inUncontrolledMode(r.props)&&(a.selectedIndex=e),r.setState(a)}},r.state=t.copyPropsToState(r.props,{},r.props.defaultFocus),r}return l(t,e),t.prototype.componentWillReceiveProps=function(e){this.setState(function(n){return t.copyPropsToState(e,n)})},t.inUncontrolledMode=function(e){return null===e.selectedIndex},t.copyPropsToState=function(e,n){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o={focus:r};if(t.inUncontrolledMode(e)){var a=(0,d.getTabsCount)(e.children)-1,s=null;s=null!=n.selectedIndex?Math.min(n.selectedIndex,a):e.defaultIndex||0,o.selectedIndex=s}return o},t.prototype.render=function(){var e=this.props,t=e.children,n=(e.defaultIndex,e.defaultFocus,o(e,["children","defaultIndex","defaultFocus"]));return n.focus=this.state.focus,n.onSelect=this.handleSelected,null!=this.state.selectedIndex&&(n.selectedIndex=this.state.selectedIndex),c.default.createElement(f.default,n,t)},t}(i.Component);p.defaultProps={defaultFocus:!1,forceRenderTabPanel:!1,selectedIndex:null,defaultIndex:null},t.default=p,p.propTypes={}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e){return"LI"===e.nodeName&&"tab"===e.getAttribute("role")}function c(e){return"true"===e.getAttribute("aria-disabled")}t.__esModule=!0;var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},f=n(0),d=r(f),p=n(1),b=r(p),h=n(5),y=r(h),m=n(2),v=r(m),C=n(3),_=r(C),T=n(4),w=r(T),O=n(6),g=!("undefined"==typeof window||!window.document||!window.document.activeElement),N=function(e){function t(){var n,r,o;a(this,t);for(var l=arguments.length,u=Array(l),f=0;f<l;f++)u[f]=arguments[f];return n=r=s(this,e.call.apply(e,[this].concat(u))),r.tabNodes=[],r.handleKeyDown=function(e){if(r.isTabFromContainer(e.target)){var t=r.props.selectedIndex,n=!1;37===e.keyCode||38===e.keyCode?(t=r.getPrevTab(t),n=!0):39!==e.keyCode&&40!==e.keyCode||(t=r.getNextTab(t),n=!0),n&&e.preventDefault(),r.setSelected(t,e)}},r.handleClick=function(e){var t=e.target;do{if(r.isTabFromContainer(t)){if(c(t))return;var n=[].slice.call(t.parentNode.children).filter(i).indexOf(t);return void r.setSelected(n,e)}}while(null!==(t=t.parentNode))},o=n,s(r,o)}return l(t,e),t.prototype.setSelected=function(e,t){e!==this.props.selectedIndex&&(e<0||e>=this.getTabsCount()||this.props.onSelect(e,this.props.selectedIndex,t))},t.prototype.getNextTab=function(e){for(var t=this.getTabsCount(),n=e+1;n<t;n++)if(!c(this.getTab(n)))return n;for(var r=0;r<e;r++)if(!c(this.getTab(r)))return r;return e},t.prototype.getPrevTab=function(e){for(var t=e;t--;)if(!c(this.getTab(t)))return t;for(t=this.getTabsCount();t-- >e;)if(!c(this.getTab(t)))return t;return e},t.prototype.getTabsCount=function(){return(0,O.getTabsCount)(this.props.children)},t.prototype.getPanelsCount=function(){return(0,O.getPanelsCount)(this.props.children)},t.prototype.getTab=function(e){return this.tabNodes["tabs-"+e]},t.prototype.getChildren=function(){var e=this,t=0,n=this.props,r=n.children,o=n.disabledTabClassName,a=n.focus,s=n.forceRenderTabPanel,l=n.selectedIndex,i=n.selectedTabClassName,c=n.selectedTabPanelClassName;this.tabIds=this.tabIds||[],this.panelIds=this.panelIds||[];for(var u=this.tabIds.length-this.getTabsCount();u++<0;)this.tabIds.push((0,y.default)()),this.panelIds.push((0,y.default)());return d.default.Children.map(r,function(n){if(null===n)return null;var r=n;if(n.type===_.default){var u=0,p=!1;g&&(p=d.default.Children.toArray(n.props.children).filter(function(e){return e.type===v.default}).some(function(t,n){return document.activeElement===e.getTab(n)})),r=(0,f.cloneElement)(n,{children:d.default.Children.map(n.props.children,function(t){if(null===t)return null;if(t.type!==v.default)return t;var n="tabs-"+u,r=l===u,s={tabRef:function(t){e.tabNodes[n]=t},id:e.tabIds[u],panelId:e.panelIds[u],selected:r,focus:r&&(a||p)};return i&&(s.selectedClassName=i),o&&(s.disabledClassName=o),u++,(0,f.cloneElement)(t,s)})})}else if(n.type===w.default){var b={id:e.panelIds[t],tabId:e.tabIds[t],selected:l===t};s&&(b.forceRender=s),c&&(b.selectedClassName=c),t++,r=(0,f.cloneElement)(n,b)}return r})},t.prototype.isTabFromContainer=function(e){if(!i(e))return!1;var t=e.parentElement;do{if(t===this.node)return!0;if(t.getAttribute("data-tabs"))break;t=t.parentElement}while(t);return!1},t.prototype.render=function(){var e=this,t=this.props,n=(t.children,t.className),r=(t.disabledTabClassName,t.focus,t.forceRenderTabPanel,t.onSelect,t.selectedIndex,t.selectedTabClassName,t.selectedTabPanelClassName,o(t,["children","className","disabledTabClassName","focus","forceRenderTabPanel","onSelect","selectedIndex","selectedTabClassName","selectedTabPanelClassName"]));return d.default.createElement("div",u({},r,{className:(0,b.default)(n),onClick:this.handleClick,onKeyDown:this.handleKeyDown,ref:function(t){e.node=t},"data-tabs":!0}),this.getChildren())},t}(f.Component);N.defaultProps={className:"react-tabs",focus:!1},t.default=N,N.propTypes={}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}t.__esModule=!0,t.resetIdCounter=t.Tabs=t.TabPanel=t.TabList=t.Tab=void 0;var o=n(7),a=r(o),s=n(3),l=r(s),i=n(2),c=r(i),u=n(4),f=r(u),d=n(5);t.Tab=c.default,t.TabList=l.default,t.TabPanel=f.default,t.Tabs=a.default,t.resetIdCounter=d.reset}])}); | ||
//# sourceMappingURL=react-tabs.min.js.map |
@@ -29,2 +29,4 @@ 'use strict'; | ||
var DEFAULT_CLASS = 'react-tabs__tab'; | ||
var Tab = function (_Component) { | ||
@@ -75,3 +77,4 @@ _inherits(Tab, _Component); | ||
ref: function ref(node) { | ||
_this2.node = node;if (tabRef) tabRef(node); | ||
_this2.node = node; | ||
if (tabRef) tabRef(node); | ||
}, | ||
@@ -93,4 +96,4 @@ role: 'tab', | ||
Tab.defaultProps = { | ||
className: 'ReactTabs__Tab', | ||
disabledClassName: 'ReactTabs__Tab--disabled', | ||
className: DEFAULT_CLASS, | ||
disabledClassName: DEFAULT_CLASS + '--disabled', | ||
focus: false, | ||
@@ -100,6 +103,6 @@ id: null, | ||
selected: false, | ||
selectedClassName: 'ReactTabs__Tab--selected' | ||
selectedClassName: DEFAULT_CLASS + '--selected' | ||
}; | ||
exports.default = Tab; | ||
process.env.NODE_ENV !== "production" ? Tab.propTypes = { | ||
Tab.propTypes = process.env.NODE_ENV !== "production" ? { | ||
children: _propTypes2.default.oneOfType([_propTypes2.default.array, _propTypes2.default.object, _propTypes2.default.string]), | ||
@@ -114,2 +117,2 @@ className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]), | ||
selectedClassName: _propTypes2.default.string, // private | ||
tabRef: _propTypes2.default.func } : void 0; | ||
tabRef: _propTypes2.default.func } : {}; |
@@ -46,6 +46,3 @@ 'use strict'; | ||
'ul', | ||
_extends({}, attributes, { | ||
className: (0, _classnames2.default)(className), | ||
role: 'tablist' | ||
}), | ||
_extends({}, attributes, { className: (0, _classnames2.default)(className), role: 'tablist' }), | ||
children | ||
@@ -59,8 +56,8 @@ ); | ||
TabList.defaultProps = { | ||
className: 'ReactTabs__TabList' | ||
className: 'react-tabs__tab-list' | ||
}; | ||
exports.default = TabList; | ||
process.env.NODE_ENV !== "production" ? TabList.propTypes = { | ||
TabList.propTypes = process.env.NODE_ENV !== "production" ? { | ||
children: _propTypes2.default.oneOfType([_propTypes2.default.object, _propTypes2.default.array]), | ||
className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]) | ||
} : void 0; | ||
} : {}; |
@@ -29,2 +29,4 @@ 'use strict'; | ||
var DEFAULT_CLASS = 'react-tabs__tab-panel'; | ||
var TabPanel = function (_Component) { | ||
@@ -49,5 +51,4 @@ _inherits(TabPanel, _Component); | ||
selectedClassName = _props.selectedClassName, | ||
style = _props.style, | ||
tabId = _props.tabId, | ||
attributes = _objectWithoutProperties(_props, ['children', 'className', 'forceRender', 'id', 'selected', 'selectedClassName', 'style', 'tabId']); | ||
attributes = _objectWithoutProperties(_props, ['children', 'className', 'forceRender', 'id', 'selected', 'selectedClassName', 'tabId']); | ||
@@ -70,9 +71,9 @@ return _react2.default.createElement( | ||
TabPanel.defaultProps = { | ||
className: 'ReactTabs__TabPanel', | ||
className: DEFAULT_CLASS, | ||
forceRender: false, | ||
selectedClassName: 'ReactTabs__TabPanel--selected', | ||
selectedClassName: DEFAULT_CLASS + '--selected', | ||
style: {} | ||
}; | ||
exports.default = TabPanel; | ||
process.env.NODE_ENV !== "production" ? TabPanel.propTypes = { | ||
TabPanel.propTypes = process.env.NODE_ENV !== "production" ? { | ||
selectedClassName: _propTypes2.default.string, // private | ||
@@ -84,3 +85,2 @@ children: _propTypes2.default.node, | ||
selected: _propTypes2.default.bool, // private | ||
style: _propTypes2.default.object, | ||
tabId: _propTypes2.default.string } : void 0; | ||
tabId: _propTypes2.default.string } : {}; |
@@ -134,3 +134,3 @@ 'use strict'; | ||
exports.default = Tabs; | ||
process.env.NODE_ENV !== "production" ? Tabs.propTypes = { | ||
Tabs.propTypes = process.env.NODE_ENV !== "production" ? { | ||
children: _propTypes3.childrenPropType, | ||
@@ -146,2 +146,2 @@ className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]), | ||
selectedTabPanelClassName: _propTypes2.default.string | ||
} : void 0; | ||
} : {}; |
@@ -59,2 +59,4 @@ 'use strict'; | ||
var canUseActiveElement = !!(typeof window !== 'undefined' && window.document && window.document.activeElement); | ||
var UncontrolledTabs = function (_Component) { | ||
@@ -96,4 +98,4 @@ _inherits(UncontrolledTabs, _Component); | ||
var node = e.target; | ||
// eslint-disable-next-line no-cond-assign | ||
do { | ||
// eslint-disable-line no-cond-assign | ||
if (_this.isTabFromContainer(node)) { | ||
@@ -219,8 +221,12 @@ if (isTabDisabled(node)) { | ||
// If it is we should keep the focus on the next selected tab | ||
var wasTabFocused = _react2.default.Children.toArray(child.props.children).filter(function (tab) { | ||
return tab.type === _Tab2.default; | ||
}).some(function (tab, i) { | ||
return document.activeElement === _this2.getTab(i); | ||
}); | ||
var wasTabFocused = false; | ||
if (canUseActiveElement) { | ||
wasTabFocused = _react2.default.Children.toArray(child.props.children).filter(function (tab) { | ||
return tab.type === _Tab2.default; | ||
}).some(function (tab, i) { | ||
return document.activeElement === _this2.getTab(i); | ||
}); | ||
} | ||
result = (0, _react.cloneElement)(child, { | ||
@@ -335,7 +341,7 @@ children: _react2.default.Children.map(child.props.children, function (tab) { | ||
UncontrolledTabs.defaultProps = { | ||
className: 'ReactTabs', | ||
className: 'react-tabs', | ||
focus: false | ||
}; | ||
exports.default = UncontrolledTabs; | ||
process.env.NODE_ENV !== "production" ? UncontrolledTabs.propTypes = { | ||
UncontrolledTabs.propTypes = process.env.NODE_ENV !== "production" ? { | ||
children: _propTypes3.childrenPropType, | ||
@@ -350,2 +356,2 @@ className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object]), | ||
selectedTabPanelClassName: _propTypes2.default.string | ||
} : void 0; | ||
} : {}; |
{ | ||
"name": "react-tabs", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.2", | ||
"description": "React tabs component", | ||
@@ -13,3 +13,5 @@ "main": "lib/index.js", | ||
"bundle": "mkdir -p dist && npm run build:umd && npm run build:umd:min", | ||
"format": "prettier --write --single-quote --print-width 100 --trailing-comma all \"src/**/*.js\"", | ||
"lint": "eslint src", | ||
"precommit": "lint-staged", | ||
"preversion": "npm run lint && npm test && npm run build && npm run bundle && git add dist/ && git commit -m 'publish: Distribution'", | ||
@@ -48,4 +50,4 @@ "prepublish": "npm run build", | ||
"babel-eslint": "^7.0.0", | ||
"babel-jest": "^19.0.0", | ||
"babel-loader": "^6.2.4", | ||
"babel-jest": "^20.0.0", | ||
"babel-loader": "^7.0.0", | ||
"babel-plugin-transform-class-properties": "^6.11.5", | ||
@@ -64,3 +66,6 @@ "babel-plugin-transform-object-rest-spread": "^6.8.0", | ||
"eslint-plugin-react": "^6.2.1", | ||
"jest-cli": "^19.0.2", | ||
"husky": "^0.13.3", | ||
"jest-cli": "^20.0.0", | ||
"lint-staged": "^3.4.0", | ||
"prettier": "^1.2.2", | ||
"react": "^15.0.0", | ||
@@ -72,3 +77,3 @@ "react-addons-test-utils": "^15.0.0", | ||
"rimraf": "^2.5.2", | ||
"style-loader": "^0.16.1", | ||
"style-loader": "^0.17.0", | ||
"uglifyjs-webpack-plugin": "^0.4.2", | ||
@@ -86,3 +91,9 @@ "webpack": "^2.3.3", | ||
] | ||
}, | ||
"lint-staged": { | ||
"src/**/*.js": [ | ||
"prettier --single-quote --print-width 100 --trailing-comma all --write", | ||
"git add" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
224868
1625
0
32