Skip to content

Commit 58f8d61

Browse files
committed
Migrate Layout to themr
1 parent fee4a19 commit 58f8d61

File tree

7 files changed

+111
-35
lines changed

7 files changed

+111
-35
lines changed

components/layout/Layout.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
2+
import { themr } from 'react-css-themr';
23
import classnames from 'classnames';
3-
import style from './style';
44

5-
const Layout = ({ className, children }) => (
6-
<div data-react-toolbox='layout' className={classnames(style.root, className)}>
5+
const Layout = ({ className, children, theme }) => (
6+
<div data-react-toolbox='layout' className={classnames(theme.layout, className)}>
77
{children}
88
</div>
99
);
@@ -44,11 +44,14 @@ Layout.propTypes = {
4444
);
4545
}
4646
},
47-
className: React.PropTypes.string
47+
className: React.PropTypes.string,
48+
theme: React.PropTypes.shape({
49+
layout: React.PropTypes.string.isRequired
50+
})
4851
};
4952

5053
Layout.defaultProps = {
5154
className: ''
5255
};
5356

54-
export default Layout;
57+
export default themr('ToolboxLayout')(Layout);

components/layout/NavDrawer.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import React from 'react';
22
import classnames from 'classnames';
3-
import style from './style';
3+
import { themr } from 'react-css-themr';
44

5-
const NavDrawer = (props) => {
6-
const rootClasses = classnames([style.navDrawer], {
7-
[style['permanent-' + props.permanentAt]]: props.permanentAt,
8-
[style.wide]: (props.width === 'wide'),
9-
[style.active]: props.active,
10-
[style.pinned]: props.pinned
11-
}, props.className);
5+
const NavDrawer = ({ active, children, className, onOverlayClick, permanentAt, pinned, scrollY, theme, width }) => {
6+
const rootClasses = classnames([theme.navDrawer], {
7+
[theme['permanent-' + permanentAt]]: permanentAt,
8+
[theme.wide]: (width === 'wide'),
9+
[theme.active]: active,
10+
[theme.pinned]: pinned
11+
}, className);
1212

13-
const drawerClasses = classnames(style.drawerContent, {
14-
[style.scrollY]: props.scrollY
13+
const drawerClasses = classnames(theme.drawerContent, {
14+
[theme.scrollY]: scrollY
1515
});
1616

1717
return (
18-
<div data-react-toolbox='nav-drawer' className={rootClasses} onClick={props.onOverlayClick}>
19-
<div data-react-toolbox='nav-drawer-scrim' className={style.scrim}>
18+
<div data-react-toolbox='nav-drawer' className={rootClasses} onClick={onOverlayClick}>
19+
<div data-react-toolbox='nav-drawer-scrim' className={theme.scrim}>
2020
<aside data-react-toolbox='nav-drawer-content' className={drawerClasses}>
21-
{props.children}
21+
{children}
2222
</aside>
2323
</div>
2424
</div>
@@ -33,6 +33,22 @@ NavDrawer.propTypes = {
3333
permanentAt: React.PropTypes.oneOf(['sm', 'md', 'lg', 'xl', 'xxl', 'xxxl']),
3434
pinned: React.PropTypes.bool,
3535
scrollY: React.PropTypes.bool,
36+
theme: React.PropTypes.shape({
37+
active: React.PropTypes.string.isRequired,
38+
drawerContent: React.PropTypes.string.isRequired,
39+
lgPermanent: React.PropTypes.string.isRequired,
40+
mdPermanent: React.PropTypes.string.isRequired,
41+
navDrawer: React.PropTypes.string.isRequired,
42+
normal: React.PropTypes.string.isRequired,
43+
pinned: React.PropTypes.string.isRequired,
44+
scrim: React.PropTypes.string.isRequired,
45+
scrollY: React.PropTypes.string.isRequired,
46+
smPermanent: React.PropTypes.string.isRequired,
47+
wide: React.PropTypes.string.isRequired,
48+
xlPermanent: React.PropTypes.string.isRequired,
49+
xxlPermanent: React.PropTypes.string.isRequired,
50+
xxxlPermanent: React.PropTypes.string.isRequired
51+
}),
3652
width: React.PropTypes.oneOf(['normal', 'wide'])
3753
};
3854

@@ -43,4 +59,4 @@ NavDrawer.defaultProps = {
4359
width: 'normal'
4460
};
4561

46-
export default NavDrawer;
62+
export default themr('ToolboxLayout')(NavDrawer);

components/layout/Panel.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import classnames from 'classnames';
3-
import style from './style';
3+
import { themr } from 'react-css-themr';
44

5-
const Panel = ({ children, className, scrollY }) => {
6-
const _className = classnames(style.panel, {
7-
[style.scrollY]: scrollY
5+
const Panel = ({ children, className, scrollY, theme }) => {
6+
const _className = classnames(theme.panel, {
7+
[theme.scrollY]: scrollY
88
}, className);
99

1010
return (
@@ -17,12 +17,16 @@ const Panel = ({ children, className, scrollY }) => {
1717
Panel.propTypes = {
1818
children: React.PropTypes.any,
1919
className: React.PropTypes.string,
20-
scrollY: React.PropTypes.bool
20+
scrollY: React.PropTypes.bool,
21+
theme: React.PropTypes.shape({
22+
panel: React.PropTypes.string.isRequired,
23+
scrollY: React.PropTypes.string.isRequired
24+
})
2125
};
2226

2327
Panel.defaultProps = {
2428
className: '',
2529
scrollY: false
2630
};
2731

28-
export default Panel;
32+
export default themr('ToolboxLayout')(Panel);

components/layout/Sidebar.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import React from 'react';
22
import classnames from 'classnames';
3-
import style from './style';
3+
import { themr } from 'react-css-themr';
44

5-
const Sidebar = (props) => {
6-
const wrapperClasses = classnames(style.sidebar, style[`width-${props.width}`], {
7-
[style.pinned]: props.pinned
8-
}, props.className);
5+
const Sidebar = ({ children, className, pinned, scrollY, theme, width }) => {
6+
const wrapperClasses = classnames(theme.sidebar, theme[`width-${width}`], {
7+
[theme.pinned]: pinned
8+
}, className);
99

10-
const innerClasses = classnames(style.sidebarContent, {
11-
[style.scrollY]: props.scrollY
10+
const innerClasses = classnames(theme.sidebarContent, {
11+
[theme.scrollY]: scrollY
1212
});
1313

1414
return (
1515
<div data-react-toolbox='sidebar' className={wrapperClasses}>
1616
<aside data-react-toolbox='sidebar-content' className={innerClasses}>
17-
{props.children}
17+
{children}
1818
</aside>
1919
</div>
2020
);
@@ -25,6 +25,12 @@ Sidebar.propTypes = {
2525
className: React.PropTypes.string,
2626
pinned: React.PropTypes.bool,
2727
scrollY: React.PropTypes.bool,
28+
theme: React.PropTypes.shape({
29+
pinned: React.PropTypes.string.isRequired,
30+
scrollY: React.PropTypes.string.isRequired,
31+
sidebar: React.PropTypes.string.isRequired,
32+
sidebarContent: React.PropTypes.string.isRequired
33+
}),
2834
width: React.PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 25, 33, 50, 66, 75, 100])
2935
};
3036

@@ -35,4 +41,4 @@ Sidebar.defaultProps = {
3541
width: 5
3642
};
3743

38-
export default Sidebar;
44+
export default themr('ToolboxLayout')(Sidebar);

components/layout/readme.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ with `flex` set to 1, and use whatever layout you like within it.
111111
| `children` | `Nodes` | | A `Panel`, optionally preceded by a `NavDrawer` and/or followed by a `Sidebar` |
112112
| `className` | `string` | | Additional class(es) for custom styling. |
113113

114+
### Theme
115+
The themed key the `Layout` in general is `ToolboxLayout`. For the `Layout` wrapper it should only provide one class interface:
116+
117+
| Name | Description|
118+
|:---------|:-----------|
119+
| `layout` | Class used in the container to position and align inner items.|
120+
114121
## NavDrawer
115122

116123
The [navigation drawer](https://www.google.com/design/spec/patterns/navigation-drawer.html) slides
@@ -138,6 +145,26 @@ and can also specify a breakpoint at which the drawer automatically becomes perm
138145
| `onOverlayClick` | `Function` | | Callback function to be invoked when the overlay is clicked.|
139146
| `className` | `string` | | Additional class(es) for custom styling. |
140147

148+
### Theme
149+
You can use `ToolboxLayout` as themed key for this component. The class interface is as follows:
150+
151+
| Name | Description|
152+
|:---------|:-----------|
153+
| `active` | Used when the drawer is active.|
154+
| `drawerContent` | Used for the content of the drawer.|
155+
| `lgPermanent` | Added to the root class for large drawer.|
156+
| `mdPermanent` | Added to the root class for medium drawer.|
157+
| `navDrawer` | Root class for the drawer.|
158+
| `normal` | Added to the root class if width is normal.|
159+
| `pinned` | Added to the root class if positioning is pinned.|
160+
| `scrim` | Used as a wrapper for the drawer content.|
161+
| `scrollY` | Added to the drawer content if its scrollable.|
162+
| `smPermanent` | Added to the root class for small drawer.|
163+
| `wide` | Added to the root class if width is wide.|
164+
| `xlPermanent` | Added to the root class for extra big drawer.|
165+
| `xxlPermanent` | Added to the root class for super big drawer.|
166+
| `xxxlPermanent` | Added to the root class for largest possible drawer.|
167+
141168
## Panel
142169

143170
The `Panel` is the main content area within a `Layout`. It is a full-height
@@ -150,6 +177,14 @@ and `Sidebar` are laid out.
150177
| `scrollY` | `bool` | `false` | If true, the panel will vertically scroll all content. |
151178
| `className` | `string` | | Additional class(es) for custom styling. |
152179

180+
### Theme
181+
You can use `ToolboxLayout` as themed key for this component. The class interface is as follows:
182+
183+
| Name | Description|
184+
|:---------|:-----------|
185+
| `panel` | Used as the root class of the panel component.|
186+
| `scrollY` | Used in case the panel is scrollable.|
187+
153188
## Sidebar
154189

155190
The `Sidebar` is an extra drawer that docks to the right side of the `Layout`.
@@ -166,6 +201,16 @@ covers the entire screen (see [examples](https://www.google.com/design/spec/layo
166201
| `scrollY` | `bool` | `false` | If true, the sidebar will vertically scroll all content. |
167202
| `className` | `string` | | Additional class(es) for custom styling. |
168203

204+
### Theme
205+
You can use `ToolboxLayout` as themed key for this component. The class interface is as follows:
206+
207+
| Name | Description|
208+
|:---------|:-----------|
209+
| `pinned` | Added to the root class if sidebar is pinned.|
210+
| `scrollY` | Add to the content of sidebar if its scrollable.|
211+
| `sidebar` | Root class of the sidebar.|
212+
| `sidebarContent` | Used in for the content element of the sidebar.|
213+
169214
## Nesting Layouts
170215

171216
The `Layout` is meant to be used near the top level of your application,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@import "./config";
33
@import "./mixins";
44

5-
.root {
5+
.layout {
66
position: relative;
77
display: flex;
88
width: 100%;

spec/theme.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ToolboxDatePicker from '../components/date_picker/theme.scss';
1010
import ToolboxDialog from '../components/dialog/theme.scss';
1111
import ToolboxDrawer from '../components/drawer/theme.scss';
1212
import ToolboxInput from '../components/input/theme.scss';
13+
import ToolboxLayout from '../components/layout/theme.scss';
1314
import ToolboxOverlay from '../components/overlay/theme.scss';
1415
import ToolboxRipple from '../components/ripple/theme.scss';
1516
import ToolboxTimePicker from '../components/time_picker/theme.scss';
@@ -26,6 +27,7 @@ export default defineTheme({
2627
ToolboxDialog,
2728
ToolboxDrawer,
2829
ToolboxInput,
30+
ToolboxLayout,
2931
ToolboxOverlay,
3032
ToolboxRipple,
3133
ToolboxTimePicker

0 commit comments

Comments
 (0)