armstrong-react
Advanced tools
Comparing version
@@ -6,2 +6,4 @@ /// <reference types="react" /> | ||
defaultSelectedIndex?: number; | ||
/** (number) The index of the tab selected. Use this if you want a stateless component */ | ||
forceSelectedIndex?: number; | ||
/** (TabItem[]) The tab items. Controls the header and the content */ | ||
@@ -21,2 +23,3 @@ children?: React.ReactNode | TabItem | TabItem[]; | ||
componentWillMount(): void; | ||
private getSelectedIndex(); | ||
render(): JSX.Element; | ||
@@ -23,0 +26,0 @@ } |
@@ -15,19 +15,32 @@ "use strict"; | ||
TabControl.prototype.changeTab = function (newIndex) { | ||
var onTabChanged = this.props.onTabChanged; | ||
this.setState({ selectedTabIndex: newIndex }, function () { | ||
var _a = this.props, onTabChanged = _a.onTabChanged, forceSelectedIndex = _a.forceSelectedIndex; | ||
var tabChanged = function () { | ||
if (onTabChanged) { | ||
onTabChanged(newIndex); | ||
} | ||
}); | ||
}; | ||
if (forceSelectedIndex === undefined) { | ||
this.setState({ selectedTabIndex: newIndex }, tabChanged); | ||
} | ||
else { | ||
tabChanged(); | ||
} | ||
}; | ||
TabControl.prototype.componentWillMount = function () { | ||
var defaultSelectedIndex = this.props.defaultSelectedIndex; | ||
if (defaultSelectedIndex !== undefined) { | ||
var _a = this.props, defaultSelectedIndex = _a.defaultSelectedIndex, forceSelectedIndex = _a.forceSelectedIndex; | ||
if (defaultSelectedIndex !== undefined && forceSelectedIndex === undefined) { | ||
this.setState({ selectedTabIndex: defaultSelectedIndex }); | ||
} | ||
}; | ||
TabControl.prototype.getSelectedIndex = function () { | ||
var forceSelectedIndex = this.props.forceSelectedIndex; | ||
var selectedTabIndex = this.state.selectedTabIndex; | ||
if (forceSelectedIndex !== undefined) { | ||
return forceSelectedIndex; | ||
} | ||
return selectedTabIndex; | ||
}; | ||
TabControl.prototype.render = function () { | ||
var _this = this; | ||
var _a = this.props, className = _a.className, children = _a.children, onTabChanged = _a.onTabChanged, tabAlignment = _a.tabAlignment, defaultSelectedIndex = _a.defaultSelectedIndex, attrs = tslib_1.__rest(_a, ["className", "children", "onTabChanged", "tabAlignment", "defaultSelectedIndex"]); | ||
var selectedTabIndex = this.state.selectedTabIndex; | ||
var _a = this.props, className = _a.className, children = _a.children, onTabChanged = _a.onTabChanged, tabAlignment = _a.tabAlignment, defaultSelectedIndex = _a.defaultSelectedIndex, forceSelectedIndex = _a.forceSelectedIndex, attrs = tslib_1.__rest(_a, ["className", "children", "onTabChanged", "tabAlignment", "defaultSelectedIndex", "forceSelectedIndex"]); | ||
if (!tabAlignment) { | ||
@@ -41,9 +54,10 @@ tabAlignment = "left"; | ||
var filteredChildren = React.Children.toArray(children).filter(function (c) { return !!c; }); | ||
var selectedIndex = this.getSelectedIndex(); | ||
return (React.createElement("div", tslib_1.__assign({}, attrs, { className: classes }), | ||
React.createElement("div", { className: "tab-control-header" }, filteredChildren.map(function (c, i) { | ||
return React.createElement("div", { className: "tab-item-header" + (selectedTabIndex === i ? ' selected' : ''), onClick: function () { return _this.changeTab(i); } }, | ||
return React.createElement("div", { className: "tab-item-header" + (selectedIndex === i ? ' selected' : ''), onClick: function () { return _this.changeTab(i); } }, | ||
c.props.icon ? React.createElement(icon_1.Icon, { className: "m-right-xsmall", icon: c.props.icon }) : null, | ||
c.props.title); | ||
})), | ||
filteredChildren[selectedTabIndex])); | ||
filteredChildren[selectedIndex])); | ||
}; | ||
@@ -50,0 +64,0 @@ return TabControl; |
{ | ||
"name": "armstrong-react", | ||
"version": "2.5.14", | ||
"version": "2.5.15", | ||
"description": "Rocketmakers Armstrong library of React components", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
15051
0.21%707154
-7.06%148
-0.67%