Skip to content

Commit cb78ff9

Browse files
authored
Merge pull request #47 from OrigenStudio/feature/provide-layout-actions-trhough-context-API
implemented the LayoutAction context
2 parents bc25cf2 + 86e5fbc commit cb78ff9

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/components/Layout/Layout.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import styles from './styles';
1111

1212
import AppBar from '../AppBar';
1313
import Footer from '../Footer';
14+
import LayoutActions from './LayoutActions';
1415

1516
// FIXME remove once material-ui drawer style is fixed
1617
const isDocked = type => type === 'permanent' || type === 'persistent';
@@ -222,7 +223,16 @@ class Layout extends React.PureComponent {
222223
{rightDrawerContentWithProps}
223224
</Drawer>
224225
) : null}
225-
<main className={mainClassnames}>{children}</main>
226+
<LayoutActions.Provider
227+
value={{
228+
toggleLeftDrawer: this.toggleLeftDrawer,
229+
toggleRightDrawer: this.toggleRightDrawer,
230+
handleLeftDrawerClose: this.handleLeftDrawerClose,
231+
handleRightDrawerClose: this.handleRightDrawerClose,
232+
}}
233+
>
234+
<main className={mainClassnames}>{children}</main>
235+
</LayoutActions.Provider>
226236
{footerContent ? (
227237
<Footer {...footerProps}>{footerContent}</Footer>
228238
) : null}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
3+
const LayoutActions = React.createContext({
4+
toggleLeftDrawer: () => {},
5+
toggleRightDrawer: () => {},
6+
handleRightDrawerClose: () => {},
7+
handleLeftDrawerClose: () => {},
8+
});
9+
10+
export default LayoutActions;

src/components/Layout/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import Layout from './Layout';
2+
import LayoutActions from './LayoutActions';
23

4+
export { LayoutActions };
35
export default Layout;

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import Layout from './components/Layout';
1+
import Layout, { LayoutActions } from './components/Layout';
22

3+
export { LayoutActions };
34
export { default as AppBar } from './components/AppBar';
45
export { default as Footer } from './components/Footer';
56

6-
77
export { default as BasicAppBar } from './templates/AppBar/BasicAppBar';
88
export { default as TwoRowsAppBar } from './templates/AppBar/TwoRowsAppBar';
99
export { default as BasicFooter } from './templates/Footer/BasicFooter';

0 commit comments

Comments
 (0)