@@ -17,8 +17,6 @@ var _radium = require('radium');
17
17
18
18
var _radium2 = _interopRequireDefault ( _radium ) ;
19
19
20
- var _reactMotion = require ( 'react-motion' ) ;
21
-
22
20
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
23
21
24
22
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
@@ -58,73 +56,93 @@ var OffCanvas = (0, _radium2.default)(_class = (_temp = _class2 = function (_Com
58
56
var style = _props . style ;
59
57
var leftStyle = _props . leftStyle ;
60
58
var rightStyle = _props . rightStyle ;
59
+ var leftType = _props . leftType ;
60
+ var rightType = _props . rightType ;
61
61
var _state = this . state ;
62
62
var openLeft = _state . openLeft ;
63
63
var openRight = _state . openRight ;
64
64
var expanded = _state . expanded ;
65
65
66
- var sidebarStyles = function sidebarStyles ( width ) {
67
- return [ styles . sidebar , { width : width } , leftStyle ] ;
68
- } ;
69
- var mainStyles = function mainStyles ( paddingLeft , paddingRight ) {
70
- return [ styles . content , { paddingLeft : paddingLeft , paddingRight : paddingRight } , style ] ;
71
- } ;
72
- var auxbarStyles = function auxbarStyles ( width ) {
73
- return [ styles . auxbar , { width : width } , rightStyle ] ;
74
- } ;
66
+ var leftPushStyles = [ leftType === 'push' && styles . push , { left : 0 } ] ;
75
67
76
- var defaults = {
77
- leftWidth : this . _calculateLeft ( 'width' ) ,
78
- rightWidth : this . _calculateRight ( 'width' ) ,
79
- paddingLeft : this . _calculateLeft ( 'padding' ) ,
80
- paddingRight : this . _calculateRight ( 'padding' )
81
- } ;
68
+ var rightPushStyles = [ rightType === 'push' && styles . push , { right : 0 } ] ;
82
69
83
- var springs = {
84
- leftWidth : ( 0 , _reactMotion . spring ) ( this . _calculateLeft ( 'width' ) ) ,
85
- rightWidth : ( 0 , _reactMotion . spring ) ( this . _calculateRight ( 'width' ) ) ,
86
- paddingLeft : ( 0 , _reactMotion . spring ) ( this . _calculateLeft ( 'padding' ) ) ,
87
- paddingRight : ( 0 , _reactMotion . spring ) ( this . _calculateRight ( 'padding' ) )
70
+ var containerStyles = function containerStyles ( marginLeft ) {
71
+ return [ styles . container , { marginLeft : marginLeft } ] ;
72
+ } ,
73
+ sidebarStyles = function sidebarStyles ( width ) {
74
+ return [ styles . sidebar , { width : width } , leftType === 'overlay' && styles . overlay , leftPushStyles , leftStyle ] ;
75
+ } ,
76
+ mainStyles = [ styles . content , style ] ,
77
+ auxbarStyles = function auxbarStyles ( width ) {
78
+ return [ styles . auxbar , { width : width } , rightType === 'overlay' && styles . overlay , rightPushStyles , rightStyle ] ;
88
79
} ;
89
80
90
81
return _react2 . default . createElement (
91
82
'div' ,
92
- { style : styles . container } ,
83
+ { style : containerStyles ( this . _calculatePush ( ) ) } ,
93
84
_react2 . default . createElement (
94
85
'div' ,
95
86
{ style : sidebarStyles ( this . _calculateLeft ( 'width' ) ) } ,
96
87
this . props . leftSidebar
97
88
) ,
98
89
_react2 . default . createElement (
99
90
'div' ,
100
- { style : auxbarStyles ( this . _calculateRight ( 'width' ) ) } ,
101
- this . props . rightSidebar
91
+ { style : mainStyles } ,
92
+ this . props . children
102
93
) ,
103
94
_react2 . default . createElement (
104
95
'div' ,
105
- { style : mainStyles ( this . _calculateLeft ( 'padding' ) , this . _calculateRight ( 'padding ' ) ) } ,
106
- this . props . children
96
+ { style : auxbarStyles ( this . _calculateRight ( 'width ' ) ) } ,
97
+ this . props . rightSidebar
107
98
)
108
99
) ;
109
100
}
110
101
} , {
111
102
key : 'toggleLeft' ,
112
103
value : function toggleLeft ( ) {
113
- this . setState ( { openLeft : ! this . state . openLeft } ) ;
104
+ var _props2 = this . props ;
105
+ var leftType = _props2 . leftType ;
106
+ var rightType = _props2 . rightType ;
107
+
108
+ if ( leftType === 'push' && rightType === 'push' ) {
109
+ this . setState ( { openLeft : ! this . state . openLeft , openRight : false } ) ;
110
+ } else {
111
+ this . setState ( { openLeft : ! this . state . openLeft } ) ;
112
+ }
114
113
}
115
114
} , {
116
115
key : 'toggleRight' ,
117
116
value : function toggleRight ( ) {
117
+ var _props3 = this . props ;
118
+ var leftType = _props3 . leftType ;
119
+ var rightType = _props3 . rightType ;
118
120
119
- if ( this . state . openRight ) {
120
- this . setState ( {
121
- openRight : false ,
122
- expanded : false
123
- } ) ;
121
+ if ( leftType === 'push' && rightType === 'push' ) {
122
+
123
+ if ( this . state . openRight ) {
124
+ this . setState ( {
125
+ openRight : false ,
126
+ expanded : false
127
+ } ) ;
128
+ } else {
129
+ this . setState ( {
130
+ openRight : true ,
131
+ openLeft : false
132
+ } ) ;
133
+ }
124
134
} else {
125
- this . setState ( {
126
- openRight : true
127
- } ) ;
135
+
136
+ if ( this . state . openRight ) {
137
+ this . setState ( {
138
+ openRight : false ,
139
+ expanded : false
140
+ } ) ;
141
+ } else {
142
+ this . setState ( {
143
+ openRight : true
144
+ } ) ;
145
+ }
128
146
}
129
147
}
130
148
} , {
@@ -151,6 +169,29 @@ var OffCanvas = (0, _radium2.default)(_class = (_temp = _class2 = function (_Com
151
169
value : function closeRight ( ) {
152
170
this . setState ( { openRight : false } ) ;
153
171
}
172
+ } , {
173
+ key : '_calculatePush' ,
174
+ value : function _calculatePush ( ) {
175
+ var _props4 = this . props ;
176
+ var rightType = _props4 . rightType ;
177
+ var leftType = _props4 . leftType ;
178
+ var _state2 = this . state ;
179
+ var openLeft = _state2 . openLeft ;
180
+ var openRight = _state2 . openRight ;
181
+ var expanded = _state2 . expanded ;
182
+
183
+ if ( openLeft && leftType === 'push' ) {
184
+
185
+ return this . props . leftWidth ;
186
+ } else if ( openRight && rightType === 'push' ) {
187
+
188
+ if ( this . state . expanded ) {
189
+ return this . props . expandedWidth * - 1 ;
190
+ }
191
+
192
+ return this . props . rightWidth * - 1 ;
193
+ }
194
+ }
154
195
} , {
155
196
key : '_calculateRight' ,
156
197
value : function _calculateRight ( type ) {
@@ -159,10 +200,13 @@ var OffCanvas = (0, _radium2.default)(_class = (_temp = _class2 = function (_Com
159
200
case 'squeeze' :
160
201
if ( this . state . expanded ) return this . props . expandedWidth ;
161
202
return this . props . rightWidth ;
203
+
204
+ case 'push' :
205
+ if ( this . state . expanded ) return this . props . expandedWidth ;
206
+ return this . props . rightWidth ;
207
+
162
208
case 'overlay' :
163
- if ( this . state . expanded ) {
164
- return type === 'padding' ? 0 : this . props . expandedWidth ;
165
- }
209
+ if ( this . state . expanded ) return type === 'padding' ? 0 : this . props . expandedWidth ;
166
210
return type === 'padding' ? 0 : this . props . rightWidth ;
167
211
}
168
212
} else {
@@ -176,6 +220,8 @@ var OffCanvas = (0, _radium2.default)(_class = (_temp = _class2 = function (_Com
176
220
switch ( this . props . leftType ) {
177
221
case 'squeeze' :
178
222
return this . props . leftWidth ;
223
+ case 'push' :
224
+ return this . props . leftWidth ;
179
225
case 'overlay' :
180
226
return type === 'padding' ? 0 : this . props . leftWidth ;
181
227
}
@@ -216,35 +262,46 @@ var OffCanvas = (0, _radium2.default)(_class = (_temp = _class2 = function (_Com
216
262
exports . default = OffCanvas ;
217
263
218
264
var styles = {
219
- container : { height : '100%' } ,
265
+ container : {
266
+ height : '100%' ,
267
+ width : '100%' ,
268
+ display : 'flex' ,
269
+ flexDirection : 'row' ,
270
+ flex : 1 ,
271
+ transition : 'margin 0.4s ease-out'
272
+ } ,
220
273
sidebar : {
221
274
width : 0 ,
222
275
height : '100%' ,
223
- position : 'fixed ' ,
276
+ position : 'relative ' ,
224
277
paddingLeft : 0 ,
225
- float : 'left' ,
226
278
zIndex : 0 ,
227
279
overflow : 'hidden' ,
228
- transition : 'width 0.5s ease'
280
+ transition : 'width 0.4s ease-out '
229
281
} ,
230
282
auxbar : {
231
283
width : 0 ,
284
+ position : 'relative' ,
232
285
height : '100%' ,
233
- position : 'fixed' ,
234
286
right : 0 ,
235
- float : 'left' ,
236
287
zIndex : 0 ,
237
288
overflow : 'hidden' ,
238
- transition : 'width 0.5s ease'
289
+ transition : 'width 0.4s ease-out'
290
+ } ,
291
+ overlay : {
292
+ position : 'absolute' ,
293
+ zIndex : 2
294
+ } ,
295
+ push : {
296
+ position : 'absolute'
239
297
} ,
240
298
content : {
241
299
width : 'auto' ,
242
300
height : '100%' ,
243
301
paddingLeft : 0 ,
244
302
zIndex : 1 ,
245
- overflowX : 'hidden' ,
303
+ flex : 1 ,
246
304
position : 'relative' ,
247
- pointerEvents : 'none' ,
248
- transition : 'padding 0.5s ease'
305
+ pointerEvents : 'none'
249
306
}
250
307
} ;
0 commit comments