@@ -11,96 +11,99 @@ function OptionManager(getDeps, {options}) {
11
11
this . initialTabs = [ ] ;
12
12
this . _setSetting ( ) . _setInitialData ( ) ;
13
13
}
14
- OptionManager . prototype . getOption = function ( optionName ) {
15
- if ( optionName === 'tabs' ) {
16
- // returned result should be immutable
17
- let arr = [ ] ;
18
- for ( let i = 0 , tabs = this . options . tabs , l = tabs . length ; i < l ; i ++ ) {
19
- arr . push ( { ...tabs [ i ] } ) ;
14
+ Object . assign ( OptionManager . prototype , {
15
+ getOption : function ( optionName ) {
16
+ if ( optionName === 'tabs' ) {
17
+ // returned result should be immutable
18
+ let arr = [ ] ;
19
+ for ( let i = 0 , tabs = this . options . tabs , l = tabs . length ; i < l ; i ++ ) {
20
+ arr . push ( { ...tabs [ i ] } ) ;
21
+ }
22
+ return arr ;
20
23
}
21
- return arr ;
22
- }
23
- return this . options [ optionName ] ;
24
- } ;
25
- OptionManager . prototype . setOption = function ( name = missingParamEr ( 'setOption' ) , value = missingParamEr ( 'setOption' ) ) {
26
- if ( [ 'SELECTEDTABID' , 'TABS' ] . indexOf ( name . toUpperCase ( ) ) >= 0 ) return this ;
27
- if ( Object . prototype . hasOwnProperty . call ( this . _defaultOptions , name ) ) this . options [ name ] = value ;
28
- return this ;
29
- } ;
30
- OptionManager . prototype . validatePanelComponent = function ( tabData ) {
31
- // convert panel element into a function component.
32
- if (
33
- tabData . panelComponent &&
34
- typeof tabData . panelComponent !== 'function' &&
35
- React . isValidElement ( tabData . panelComponent )
36
- ) {
37
- const PanelElement = tabData . panelComponent ;
38
- tabData . panelComponent = function ( ) {
39
- return PanelElement ;
40
- } ;
41
- }
42
- return this ;
43
- } ;
44
- OptionManager . prototype . validateObjectiveTabData = function ( tabData ) {
45
- if ( Object . prototype . toString . call ( tabData ) !== '[object Object]' ) throw new Error ( 'tabData must be type of Object' ) ;
46
- return this ;
47
- } ;
48
- OptionManager . prototype . validateTabData = function ( tabData ) {
49
- this . validateObjectiveTabData ( tabData ) . validatePanelComponent ( tabData ) ;
50
- tabData = Object . assign ( this . setting . getDefaultTabData ( ) , tabData ) ;
51
- tabData . id = tabData . id + '' ; //make sure id is string
52
- return tabData ;
53
- } ;
54
- OptionManager . prototype . _validateOptions = function ( options ) {
55
- if ( Object . prototype . toString . call ( options ) !== '[object Object]' )
56
- throw 'Invalid argument in "useDynamicTabs" function. Argument must be type of an object' ;
57
- return this ;
58
- } ;
59
- OptionManager . prototype . _setInitialData = function ( ) {
60
- // set this.initialTabs and this.initialState
61
- const { selectedTabID, tabs} = this . options ,
62
- openTabIDs = [ ] ;
63
- tabs . map ( ( tab ) => {
64
- const newTab = this . validateTabData ( tab ) ;
65
- this . initialTabs . push ( newTab ) ;
66
- openTabIDs . push ( newTab . id ) ;
67
- } ) ;
68
- this . initialState = {
69
- selectedTabID : selectedTabID + '' , //make sure it is type of string
70
- openTabIDs,
71
- } ;
72
- return this ;
73
- } ;
74
- OptionManager . prototype . _setSetting = function ( ) {
75
- this . setting = {
76
- tabClass : 'rc-dyn-tabs-tab' ,
77
- titleClass : 'rc-dyn-tabs-title' ,
78
- iconClass : 'rc-dyn-tabs-icon' ,
79
- selectedClass : 'rc-dyn-tabs-selected' ,
80
- hoverClass : 'rc-dyn-tabs-hover' ,
81
- tablistClass : 'rc-dyn-tabs-tablist' ,
82
- closeClass : 'rc-dyn-tabs-close' ,
83
- panelClass : 'rc-dyn-tabs-panel' ,
84
- panellistClass : 'rc-dyn-tabs-panellist' ,
85
- disableClass : 'rc-dyn-tabs-disable' ,
86
- ltrClass : 'rc-dyn-tabs-ltr' ,
87
- rtlClass : 'rc-dyn-tabs-rtl' ,
88
- verticalClass : 'rc-dyn-tabs-vertical' ,
89
- panelIdTemplate : ( id ) => `rc-dyn-tabs-p-${ id } ` ,
90
- ariaLabelledbyIdTemplate : ( id ) => `rc-dyn-tabs-l-${ id } ` ,
91
- getDefaultTabData : ( ) => {
92
- return {
93
- title : '' ,
94
- tooltip : '' ,
95
- panelComponent : this . options . defaultPanelComponent ,
96
- closable : true ,
97
- iconClass : '' ,
98
- disable : false ,
99
- lazy : false ,
100
- id : `tab_${ new Date ( ) . getTime ( ) } ` ,
24
+ return this . options [ optionName ] ;
25
+ } ,
26
+ setOption : function ( name = missingParamEr ( 'setOption' ) , value = missingParamEr ( 'setOption' ) ) {
27
+ if ( [ 'SELECTEDTABID' , 'TABS' ] . indexOf ( name . toUpperCase ( ) ) >= 0 ) return this ;
28
+ if ( Object . prototype . hasOwnProperty . call ( this . _defaultOptions , name ) ) this . options [ name ] = value ;
29
+ return this ;
30
+ } ,
31
+ validatePanelComponent : function ( tabData ) {
32
+ // convert panel element into a function component.
33
+ if (
34
+ tabData . panelComponent &&
35
+ typeof tabData . panelComponent !== 'function' &&
36
+ React . isValidElement ( tabData . panelComponent )
37
+ ) {
38
+ const PanelElement = tabData . panelComponent ;
39
+ tabData . panelComponent = function ( ) {
40
+ return PanelElement ;
101
41
} ;
102
- } ,
103
- } ;
104
- return this ;
105
- } ;
42
+ }
43
+ return this ;
44
+ } ,
45
+ validateObjectiveTabData : function ( tabData ) {
46
+ if ( Object . prototype . toString . call ( tabData ) !== '[object Object]' )
47
+ throw new Error ( 'tabData must be type of Object' ) ;
48
+ return this ;
49
+ } ,
50
+ validateTabData : function ( tabData ) {
51
+ this . validateObjectiveTabData ( tabData ) . validatePanelComponent ( tabData ) ;
52
+ tabData = Object . assign ( this . setting . getDefaultTabData ( ) , tabData ) ;
53
+ tabData . id = tabData . id + '' ; //make sure id is string
54
+ return tabData ;
55
+ } ,
56
+ _validateOptions : function ( options ) {
57
+ if ( Object . prototype . toString . call ( options ) !== '[object Object]' )
58
+ throw 'Invalid argument in "useDynamicTabs" function. Argument must be type of an object' ;
59
+ return this ;
60
+ } ,
61
+ _setInitialData : function ( ) {
62
+ // set this.initialTabs and this.initialState
63
+ const { selectedTabID, tabs} = this . options ,
64
+ openTabIDs = [ ] ;
65
+ tabs . map ( ( tab ) => {
66
+ const newTab = this . validateTabData ( tab ) ;
67
+ this . initialTabs . push ( newTab ) ;
68
+ openTabIDs . push ( newTab . id ) ;
69
+ } ) ;
70
+ this . initialState = {
71
+ selectedTabID : selectedTabID + '' , //make sure it is type of string
72
+ openTabIDs,
73
+ } ;
74
+ return this ;
75
+ } ,
76
+ _setSetting : function ( ) {
77
+ this . setting = {
78
+ tabClass : 'rc-dyn-tabs-tab' ,
79
+ titleClass : 'rc-dyn-tabs-title' ,
80
+ iconClass : 'rc-dyn-tabs-icon' ,
81
+ selectedClass : 'rc-dyn-tabs-selected' ,
82
+ hoverClass : 'rc-dyn-tabs-hover' ,
83
+ tablistClass : 'rc-dyn-tabs-tablist' ,
84
+ closeClass : 'rc-dyn-tabs-close' ,
85
+ panelClass : 'rc-dyn-tabs-panel' ,
86
+ panellistClass : 'rc-dyn-tabs-panellist' ,
87
+ disableClass : 'rc-dyn-tabs-disable' ,
88
+ ltrClass : 'rc-dyn-tabs-ltr' ,
89
+ rtlClass : 'rc-dyn-tabs-rtl' ,
90
+ verticalClass : 'rc-dyn-tabs-vertical' ,
91
+ panelIdTemplate : ( id ) => `rc-dyn-tabs-p-${ id } ` ,
92
+ ariaLabelledbyIdTemplate : ( id ) => `rc-dyn-tabs-l-${ id } ` ,
93
+ getDefaultTabData : ( ) => {
94
+ return {
95
+ title : '' ,
96
+ tooltip : '' ,
97
+ panelComponent : this . options . defaultPanelComponent ,
98
+ closable : true ,
99
+ iconClass : '' ,
100
+ disable : false ,
101
+ lazy : false ,
102
+ id : `tab_${ new Date ( ) . getTime ( ) } ` ,
103
+ } ;
104
+ } ,
105
+ } ;
106
+ return this ;
107
+ } ,
108
+ } ) ;
106
109
export default OptionManager ;
0 commit comments