Skip to content

Commit 3827ed3

Browse files
committed
Autoinject Drawer theme
1 parent 1386a15 commit 3827ed3

File tree

4 files changed

+59
-45
lines changed

4 files changed

+59
-45
lines changed

components/drawer/Drawer.js

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
import React from 'react';
1+
import React, { PropTypes } from 'react';
22
import { themr } from 'react-css-themr';
33
import classnames from 'classnames';
4-
import ActivableRenderer from '../hoc/ActivableRenderer';
5-
import Overlay from '../overlay';
4+
import { DRAWER } from '../identifiers.js';
5+
import ActivableRenderer from '../hoc/ActivableRenderer.js';
6+
import InjectOverlay from '../overlay/Overlay.js';
67

7-
const Drawer = ({ active, children, className, onOverlayClick, theme, type }) => {
8-
const _className = classnames([theme.drawer, theme[type]], {
9-
[theme.active]: active
10-
}, className);
8+
const factory = (Overlay) => {
9+
const Drawer = ({ active, children, className, onOverlayClick, theme, type }) => {
10+
const _className = classnames([theme.drawer, theme[type]], {
11+
[theme.active]: active
12+
}, className);
1113

12-
return (
13-
<Overlay active={active} onClick={onOverlayClick}>
14-
<div data-react-toolbox='drawer' className={_className}>
15-
<aside className={theme.content}>
16-
{children}
17-
</aside>
18-
</div>
19-
</Overlay>
20-
);
21-
};
14+
return (
15+
<Overlay active={active} onClick={onOverlayClick}>
16+
<div data-react-toolbox='drawer' className={_className}>
17+
<aside className={theme.content}>
18+
{children}
19+
</aside>
20+
</div>
21+
</Overlay>
22+
);
23+
};
2224

23-
Drawer.propTypes = {
24-
active: React.PropTypes.bool,
25-
children: React.PropTypes.node,
26-
className: React.PropTypes.string,
27-
onOverlayClick: React.PropTypes.func,
28-
theme: React.PropTypes.shape({
29-
active: React.PropTypes.string.isRequired,
30-
content: React.PropTypes.string.isRequired,
31-
drawer: React.PropTypes.string.isRequired,
32-
left: React.PropTypes.string.isRequired,
33-
right: React.PropTypes.string.isRequired
34-
}),
35-
type: React.PropTypes.oneOf(['left', 'right'])
36-
};
25+
Drawer.propTypes = {
26+
active: PropTypes.bool,
27+
children: PropTypes.node,
28+
className: PropTypes.string,
29+
onOverlayClick: PropTypes.func,
30+
theme: PropTypes.shape({
31+
active: PropTypes.string.isRequired,
32+
content: PropTypes.string.isRequired,
33+
drawer: PropTypes.string.isRequired,
34+
left: PropTypes.string.isRequired,
35+
right: PropTypes.string.isRequired
36+
}),
37+
type: PropTypes.oneOf(['left', 'right'])
38+
};
39+
40+
Drawer.defaultProps = {
41+
active: false,
42+
className: '',
43+
type: 'left'
44+
};
3745

38-
Drawer.defaultProps = {
39-
active: false,
40-
className: '',
41-
type: 'left'
46+
return ActivableRenderer()(Drawer);
4247
};
4348

44-
export default themr('ToolboxDrawer')(ActivableRenderer()(Drawer));
49+
const Drawer = factory(InjectOverlay);
50+
export default themr(DRAWER)(Drawer);
51+
export { factory as drawerFactory };
52+
export { Drawer };

components/drawer/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
export default from './Drawer';
1+
import { themr } from 'react-css-themr';
2+
import { DRAWER } from '../identifiers.js';
3+
import { Overlay } from '../overlay';
4+
import { drawerFactory } from './Drawer.js';
5+
import theme from './theme.scss';
6+
7+
const Drawer = drawerFactory(Overlay);
8+
const ThemedDrawer = themr(DRAWER, theme)(Drawer);
9+
10+
export default ThemedDrawer;
11+
export { ThemedDrawer as Drawer };

components/drawer/readme.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ The [navigation drawer](https://www.google.com/design/spec/patterns/navigation-d
55
<!-- example -->
66
```jsx
77
import Drawer from 'react-toolbox/lib/drawer';
8-
import theme from 'react-toolbox/lib/drawer/theme';
9-
// Remember you can add styles using ThemeProvider
108

119
class DrawerTest extends React.Component {
1210
state = {
@@ -21,7 +19,7 @@ class DrawerTest extends React.Component {
2119
return (
2220
<div>
2321
<Button label='Show Drawer' raised accent onClick={this.handleToggle} />
24-
<Drawer active={this.state.active} onOverlayClick={this.handleToggle} theme={theme}>
22+
<Drawer active={this.state.active} onOverlayClick={this.handleToggle}>
2523
<h5>This is your Drawer.</h5>
2624
<p>You can embed any content you want, for example a Menu.</p>
2725
</Drawer>
@@ -31,6 +29,8 @@ class DrawerTest extends React.Component {
3129
}
3230
```
3331

32+
If you want to provide a theme via context, the component key is `RTDrawer`.
33+
3434
## Properties
3535

3636
| Name | Type | Default | Description|
@@ -40,9 +40,7 @@ class DrawerTest extends React.Component {
4040
| `onOverlayClick` | `Function` | | Callback function to be invoked when the overlay is clicked.|
4141
| `type` | `String` | `left` | Type of drawer. It can be `left` or `right` to display the drawer on the left or right side of the screen.|
4242

43-
## Theming
44-
45-
You can take a look to the `_config.scss` variables. The themed key for this component is `ToolboxDrawer`, it should implement the following interface:
43+
## Theme
4644

4745
| Name | Description|
4846
|:---------|:-----------|

spec/theme.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import '../components/commons.scss';
22

3-
import ToolboxDrawer from '../components/drawer/theme.scss';
43
import ToolboxDropdown from '../components/dropdown/theme.scss';
54
import ToolboxLayout from '../components/layout/theme.scss';
65
import ToolboxLink from '../components/link/theme.scss';
@@ -18,7 +17,6 @@ import ToolboxTimePicker from '../components/time_picker/theme.scss';
1817
import ToolboxTooltip from '../components/tooltip/theme.scss';
1918

2019
export default {
21-
ToolboxDrawer,
2220
ToolboxDropdown,
2321
ToolboxLayout,
2422
ToolboxLink,

0 commit comments

Comments
 (0)