@@ -27,6 +27,26 @@ export interface DataProps {
27
27
* Custom set render `Tab Title` method.
28
28
*/
29
29
renderTitle ?: ( title ?: string ) => React . ReactNode ;
30
+ /**
31
+ * If true, will add animate to tabs in out.
32
+ */
33
+ useAnimate ?: boolean ;
34
+ /**
35
+ * Set tabs animate mode.
36
+ */
37
+ animateMode ?: "in" | "out" | "in-out" ;
38
+ /**
39
+ * Set tabs animate speed.
40
+ */
41
+ animateSpeed ?: number ;
42
+ /**
43
+ * Set tab animate enter style.
44
+ */
45
+ animateEnterStyle ?: React . CSSProperties ;
46
+ /**
47
+ * Set tab animate leave style.
48
+ */
49
+ animateLeaveStyle ?: React . CSSProperties ;
30
50
}
31
51
32
52
export interface TabsProps extends DataProps , React . HTMLAttributes < HTMLDivElement > { }
@@ -37,7 +57,18 @@ export interface TabsState {
37
57
38
58
export class Tabs extends React . Component < TabsProps , TabsState > {
39
59
static defaultProps : TabsProps = {
40
- renderTitle : ( title : string ) => title
60
+ renderTitle : ( title : string ) => title ,
61
+ useAnimate : true ,
62
+ animateMode : "in" ,
63
+ animateSpeed : 500 ,
64
+ animateEnterStyle : {
65
+ transform : "translateX(0)" ,
66
+ opacity : 1
67
+ } ,
68
+ animateLeaveStyle : {
69
+ transform : "translateX(100%)" ,
70
+ opacity : 0
71
+ }
41
72
} ;
42
73
43
74
state : TabsState = {
@@ -65,53 +96,65 @@ export class Tabs extends React.Component<TabsProps, TabsState> {
65
96
children,
66
97
tabStyle,
67
98
renderTitle,
99
+ useAnimate,
100
+ animateMode,
101
+ animateSpeed,
102
+ animateEnterStyle,
103
+ animateLeaveStyle,
104
+ className,
105
+ style,
68
106
...attributes
69
107
} = this . props ;
70
108
const { theme } = this . context ;
71
109
const { tabFocusIndex } = this . state ;
72
- const styles = getStyles ( this ) ;
73
110
74
111
const childrenArray = React . Children . toArray ( children ) ;
75
112
const isAvailableArray = childrenArray && childrenArray . length > 0 ;
76
113
const tabs : Tab [ ] | false = isAvailableArray && childrenArray . filter ( ( child : any ) => child . type === Tab ) as any ;
77
114
const currTab : Tab | false = tabs && tabs [ tabFocusIndex ] as any ;
78
115
const tabTitle = currTab && currTab . props . title ;
79
116
117
+ const inlineStyles = getStyles ( this ) ;
118
+ const styles = theme . prepareStyles ( {
119
+ className : "tabs" ,
120
+ styles : inlineStyles
121
+ } ) ;
122
+
123
+ const normalRender = (
124
+ < div key = { `${ tabFocusIndex } ` } { ...styles . tabStyle } >
125
+ { currTab }
126
+ </ div >
127
+ ) ;
128
+
80
129
return (
81
130
< div
82
131
{ ...attributes }
83
- style = { styles . root }
132
+ style = { styles . root . style }
133
+ className = { styles . root . className }
84
134
>
85
- < div style = { styles . titles } >
135
+ < div { ... styles . titles } >
86
136
{ tabs && tabs . map ( ( tab , index ) => (
87
137
< span
88
- style = { index === tabFocusIndex ? {
89
- ...styles . title ,
90
- ...styles . titleFocus
91
- } : styles . title }
138
+ { ...( index === tabFocusIndex ? styles . titleFocus : styles . title ) }
92
139
key = { `${ index } ` }
93
140
onClick = { ( ) => this . setState ( { tabFocusIndex : index } ) }
94
141
>
95
142
{ renderTitle ( tab . props . title || `Tabs Items ${ index + 1 } ` ) }
96
143
</ span >
97
144
) ) }
98
145
</ div >
99
- < CustomAnimate
100
- leaveStyle = { {
101
- transform : "translateX(100%)" ,
102
- opacity : 1
103
- } }
104
- enterStyle = { {
105
- transform : "translateX(0)" ,
106
- opacity : 1
107
- } }
108
- wrapperStyle = { { width : "100%" , height : "100%" } }
109
- appearAnimate = { false }
110
- >
111
- < div key = { `${ tabFocusIndex } ` } style = { styles . tabStyle } >
112
- { currTab }
113
- </ div >
114
- </ CustomAnimate >
146
+ { useAnimate ? (
147
+ < CustomAnimate
148
+ mode = { animateMode }
149
+ speed = { animateSpeed }
150
+ enterStyle = { animateEnterStyle }
151
+ leaveStyle = { animateLeaveStyle }
152
+ wrapperStyle = { { width : "100%" , height : "100%" } }
153
+ appearAnimate = { false }
154
+ >
155
+ { normalRender }
156
+ </ CustomAnimate >
157
+ ) : normalRender }
115
158
</ div >
116
159
) ;
117
160
}
@@ -156,12 +199,18 @@ function getStyles(Tabs: Tabs): {
156
199
fontWeight : "lighter" ,
157
200
cursor : "pointer" ,
158
201
fontSize : 18 ,
159
- padding : 4 ,
160
- marginRight : 4 ,
202
+ padding : "4px 12px" ,
161
203
transition : "all .25s" ,
162
204
...tabTitleStyle
163
205
} ) ,
164
206
titleFocus : prefixStyle ( {
207
+ color : theme . baseHigh ,
208
+ fontWeight : "lighter" ,
209
+ cursor : "pointer" ,
210
+ fontSize : 18 ,
211
+ padding : "4px 12px" ,
212
+ transition : "all .25s" ,
213
+ ...tabTitleStyle ,
165
214
borderBottom : `2px solid ${ theme . accent } ` ,
166
215
...tabTitleFocusStyle
167
216
} ) ,
0 commit comments