@@ -12,7 +12,8 @@ import styles from './styles';
12
12
import AppBar from '../AppBar' ;
13
13
import Footer from '../Footer' ;
14
14
15
- // TODO create Layout Library
15
+ // FIXME remove once material-ui drawer style is fixed
16
+ const isDocked = type => type === 'permanent' || type === 'persistent' ;
16
17
17
18
class Layout extends React . PureComponent {
18
19
static propTypes = {
@@ -21,16 +22,22 @@ class Layout extends React.PureComponent {
21
22
children : PropTypes . element . isRequired ,
22
23
appBarPosition : PropTypes . string ,
23
24
stickyFooter : PropTypes . bool ,
24
- footerContent : PropTypes . element ,
25
25
appBarContent : PropTypes . element ,
26
+ appBarProps : PropTypes . shape ( { } ) ,
27
+ footerContent : PropTypes . element ,
28
+ footerProps : PropTypes . shape ( { } ) ,
26
29
leftDrawerOpen : PropTypes . bool . isRequired ,
27
30
onLeftDrawerOpenChange : PropTypes . func ,
28
31
leftDrawerContent : PropTypes . element ,
29
32
leftDrawerType : PropTypes . string ,
30
33
leftDrawerUnder : PropTypes . bool ,
31
- appBarProps : PropTypes . shape ( { } ) ,
32
34
leftDrawerProps : PropTypes . shape ( { } ) ,
33
- footerProps : PropTypes . shape ( { } ) ,
35
+ rightDrawerOpen : PropTypes . bool . isRequired ,
36
+ onRightDrawerOpenChange : PropTypes . func ,
37
+ rightDrawerContent : PropTypes . element ,
38
+ rightDrawerType : PropTypes . string ,
39
+ rightDrawerUnder : PropTypes . bool ,
40
+ rightDrawerProps : PropTypes . shape ( { } ) ,
34
41
width : PropTypes . string ,
35
42
} ;
36
43
@@ -54,6 +61,18 @@ class Layout extends React.PureComponent {
54
61
this . props . onLeftDrawerOpenChange ( ! this . props . leftDrawerOpen ) ;
55
62
} ;
56
63
64
+ handleRightDrawerClose = ( ) => {
65
+ if ( ! this . props . onRightDrawerOpenChange ) return ;
66
+
67
+ this . props . onRightDrawerOpenChange ( false ) ;
68
+ } ;
69
+
70
+ toggleRightDrawer = ( ) => {
71
+ if ( ! this . props . onRightDrawerOpenChange ) return ;
72
+
73
+ this . props . onRightDrawerOpenChange ( ! this . props . rightDrawerOpen ) ;
74
+ } ;
75
+
57
76
render ( ) {
58
77
const {
59
78
classes : defaultClasses ,
@@ -67,6 +86,11 @@ class Layout extends React.PureComponent {
67
86
leftDrawerType,
68
87
leftDrawerUnder,
69
88
leftDrawerProps,
89
+ rightDrawerContent,
90
+ rightDrawerOpen,
91
+ rightDrawerType,
92
+ rightDrawerUnder,
93
+ rightDrawerProps,
70
94
footerContent,
71
95
stickyFooter,
72
96
footerProps,
@@ -79,37 +103,59 @@ class Layout extends React.PureComponent {
79
103
80
104
const smallScreen = isWidthDown ( 'xs' , width ) ;
81
105
82
- const mainShift =
106
+ const mainLeftShift =
83
107
! smallScreen &&
84
108
( leftDrawerType === 'permanent' ||
85
109
( leftDrawerOpen && leftDrawerType === 'persistent' ) ) ;
86
110
87
- const mainClassnames = classNames (
88
- classes . main ,
89
- { [ `${ classes . mainFixedAppBar } ` ] : appBarPosition === 'fixed' } ,
90
- { [ `${ classes . mainStickyFooter } ` ] : stickyFooter } ,
91
- { [ `${ classes . mainShift } ` ] : mainShift } ,
92
- ) ;
111
+ const mainRightShift =
112
+ ! smallScreen &&
113
+ ( rightDrawerType === 'permanent' ||
114
+ ( rightDrawerOpen && rightDrawerType === 'persistent' ) ) ;
115
+
116
+ const mainClassnames = classNames ( classes . main , {
117
+ [ `${ classes . mainFixedAppBar } ` ] : appBarPosition === 'fixed' ,
118
+ [ `${ classes . mainStickyFooter } ` ] : stickyFooter ,
119
+ [ `${ classes . mainShift } ` ] : mainLeftShift || mainRightShift ,
120
+ [ `${ classes . mainLeftShift } ` ] : mainLeftShift ,
121
+ [ `${ classes . mainRightShift } ` ] : mainRightShift ,
122
+ [ `${ classes . mainLeftRightShift } ` ] : mainLeftShift && mainRightShift ,
123
+ } ) ;
93
124
94
- const appBarShift =
125
+ const appBarLeftShift =
95
126
! smallScreen &&
96
127
( ! leftDrawerUnder &&
97
128
( ( leftDrawerOpen && leftDrawerType === 'persistent' ) ||
98
129
leftDrawerType === 'permanent' ) ) ;
99
130
131
+ const appBarRightShift =
132
+ ! smallScreen &&
133
+ ( ! rightDrawerUnder &&
134
+ ( ( rightDrawerOpen && rightDrawerType === 'persistent' ) ||
135
+ rightDrawerType === 'permanent' ) ) ;
136
+
100
137
const appBarClassnames = classNames ( classes . appBar , {
101
- [ `${ classes . appBarShift } ` ] : appBarShift ,
138
+ [ `${ classes . appBarShift } ` ] : appBarLeftShift || appBarRightShift ,
139
+ [ `${ classes . appBarLeftShift } ` ] : appBarLeftShift ,
140
+ [ `${ classes . appBarRightShift } ` ] : appBarRightShift ,
141
+ [ `${ classes . appBarLeftRightShift } ` ] : appBarLeftShift && appBarRightShift ,
102
142
} ) ;
103
143
104
- const drawerPaperClassnames = classNames ( classes . drawerPaper , {
144
+ const leftDrawerPaperClassnames = classNames ( classes . drawerPaper , {
105
145
[ `${ classes . drawerPaperUnder } ` ] : ! smallScreen && leftDrawerUnder ,
106
146
} ) ;
147
+ console . log ( isDocked ( rightDrawerType ) ) ;
148
+ const rightDrawerPaperClassnames = classNames ( classes . drawerPaper , {
149
+ [ `${ classes . drawerPaperUnder } ` ] : ! smallScreen && rightDrawerUnder ,
150
+ [ `${ classes . rightDrawerDockedFix } ` ] : isDocked ( rightDrawerType ) , // FIXME remove once material-ui drawer style is fixed
151
+ } ) ;
107
152
108
153
return (
109
154
< div className = { classes . layout } >
110
155
< AppBar
111
156
position = { appBarPosition }
112
- onIconClick = { this . toggleLeftDrawer }
157
+ toggleLeftDrawer = { this . toggleLeftDrawer }
158
+ toggleRightDrawer = { this . toggleRightDrawer }
113
159
className = { appBarClassnames }
114
160
{ ...appBarProps }
115
161
>
@@ -120,7 +166,7 @@ class Layout extends React.PureComponent {
120
166
open = { leftDrawerOpen }
121
167
onRequestClose = { this . handleLeftDrawerClose }
122
168
type = { ! smallScreen && leftDrawerType }
123
- classes = { { paper : drawerPaperClassnames } }
169
+ classes = { { paper : leftDrawerPaperClassnames } }
124
170
{ ...leftDrawerProps }
125
171
>
126
172
{ ! smallScreen && leftDrawerUnder ? (
@@ -129,6 +175,21 @@ class Layout extends React.PureComponent {
129
175
{ leftDrawerContent }
130
176
</ Drawer >
131
177
) : null }
178
+ { rightDrawerContent ? (
179
+ < Drawer
180
+ anchor = "right"
181
+ open = { rightDrawerOpen }
182
+ onRequestClose = { this . handleRightDrawerClose }
183
+ type = { ! smallScreen && rightDrawerType }
184
+ classes = { { paper : rightDrawerPaperClassnames } }
185
+ { ...rightDrawerProps }
186
+ >
187
+ { ! smallScreen && rightDrawerUnder ? (
188
+ < div className = { classes . drawerHeader } />
189
+ ) : null }
190
+ { rightDrawerContent }
191
+ </ Drawer >
192
+ ) : null }
132
193
< main className = { mainClassnames } > { children } </ main >
133
194
{ footerContent ? (
134
195
< Footer { ...footerProps } > { footerContent } </ Footer >
@@ -140,4 +201,5 @@ class Layout extends React.PureComponent {
140
201
141
202
export default controllable ( compose ( withStyles ( styles ) , withWidth ( ) ) ( Layout ) , [
142
203
'leftDrawerOpen' ,
204
+ 'rightDrawerOpen' ,
143
205
] ) ;
0 commit comments