Skip to content

Commit 5ce9d69

Browse files
committed
add createDefaultOptions.js
1 parent 6520fa4 commit 5ce9d69

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const CreateDefaultOptions = function (fn, DefaulTabInnerComponent = null) {
2+
this.fn = fn;
3+
this.defaultDirection = 'ltr';
4+
this._DefaulTabInnerComponent = DefaulTabInnerComponent;
5+
this.directionsRange = ['ltr', 'rtl'];
6+
this._create(this._getOptions());
7+
};
8+
CreateDefaultOptions.prototype._create = function (options) {
9+
this.fn.options = options;
10+
};
11+
CreateDefaultOptions.prototype._getOptions = function () {
12+
const _options = {
13+
tabs: [],
14+
selectedTabID: '',
15+
beforeSelect: function (e, id) { return true; },
16+
beforeClose: function (e, id) { return true; },
17+
onOpen: function (IDs) { },
18+
onClose: function (IDs) { },
19+
onSelect: function ({ currentSelectedTabId, perviousSelectedTabId }) { },
20+
onChange: function ({ currentData, perviousData }) { },
21+
onLoad: function (api) { },
22+
onDestroy: function () { },
23+
isCustomTabComponent: false,// shoud be removed
24+
accessibility: true,
25+
defaultPanelComponent: null
26+
};
27+
let _direction = this.defaultDirection, _tabComponent = this._DefaulTabInnerComponent;
28+
const that = this;
29+
Object.defineProperties(_options, {
30+
direction: {
31+
get() { return _direction; },
32+
set(value) {
33+
if (that.directionsRange.indexOf(value) === -1)
34+
throw 'Invalid direction value! it can be eather of "ltr" or "rtl" ';
35+
_direction = value;
36+
}
37+
},
38+
tabComponent: {
39+
get() {
40+
return _tabComponent
41+
},
42+
set(fn) {
43+
if (fn && (typeof fn !== 'function'))
44+
throw 'tabComponent property must be type of a function.';
45+
_options.isCustomTabComponent = fn ? true : false;
46+
_tabComponent = fn ? fn : that._DefaulTabInnerComponent;
47+
}
48+
}
49+
});
50+
return _options;
51+
};
52+
export default CreateDefaultOptions;
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import factory from './optionManager.factory';
2-
import Setting from './setting';
3-
import useDynamicTabs from '../../../useDynamicTabs';
4-
import DefaulTabInnerComponent from '../../../tab/defaulTabInner';
1+
import factory from './optionManager.factory.js';
2+
import useDynamicTabs from '../../../useDynamicTabs/index.js';
53
const getDeps = function () {
6-
const setting = new (Setting)().get(), globalDefaultOptions = useDynamicTabs.defaultOptions;
7-
return { setting, globalDefaultOptions, DefaulTabInnerComponent };
4+
const globalDefaultOptions = useDynamicTabs.options;
5+
return { globalDefaultOptions };
86
};
97
export default factory.bind(null, getDeps);

0 commit comments

Comments
 (0)