react-dyn-tabs
Version:
React dynamic tabs with full API
42 lines • 1.14 kB
JavaScript
import Helper from '../helper.js';
export default Helper.module(function Tabs(_temp) {
var _this = this;
var _ref = _temp === void 0 ? {
initialTabs: []
} : _temp,
initialTabs = _ref.initialTabs;
this._data = [];
if (initialTabs && initialTabs.constructor === Array && initialTabs.length) {
initialTabs.forEach(function (tab) {
_this._addTab(tab);
});
}
}, {
_addTab: function _addTab(tabObj) {
this._data.push(tabObj);
return this;
},
_removeTab: function _removeTab(id) {
var delIndex = this._data.findIndex(function (tab) {
return tab.id === id;
});
delIndex >= 0 && this._data.splice(delIndex, 1);
return this;
},
getTab: function getTab(id) {
return this._data.find(function (tab) {
return tab.id === id;
});
},
_setTab: function _setTab(id, newData) {
var _index = this._data.findIndex(function (tab) {
return tab.id == id;
});
if (_index >= 0) {
var oldData = this._data[_index];
newData.id = oldData.id; // id can not be changed.
Object.assign(this._data[_index], newData);
}
return this;
}
});