forked from vasanthk/react-bits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06.layout-component.jsx
62 lines (55 loc) · 1.23 KB
/
06.layout-component.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Layout component
* We can extend the idea of Base components to create Layout components
*
* @Reference:
* http://jxnblk.com/writing/posts/patterns-for-style-composition-in-react/
* https://github.com/vasanthk/react-bits/blob/master/styling/05.base-component.jsx
*/
// Example
const Grid = (props) => (
<Box {...props}
display='inline-block'
verticalAlign='top'
px={2}/>
);
const Half = (props) => (
<Grid {...props}
width={1 / 2}/>
);
const Third = (props) => (
<Grid {...props}
width={1 / 3}/>
);
const Quarter = (props) => (
<Grid {...props}
width={1 / 4}/>
);
const Flex = (props) => (
<Box {...props}
display='flex'/>
);
const FlexAuto = (props) => (
<Box {...props}
flex='1 1 auto'/>
);
// Usage example
const Layout = () => (
<div>
<div>
<Half>Half width column</Half>
<Half>Half width column</Half>
</div>
<div>
<Third>Third width column</Third>
<Third>Third width column</Third>
<Third>Third width column</Third>
</div>
<div>
<Quarter>Quarter width column</Quarter>
<Quarter>Quarter width column</Quarter>
<Quarter>Quarter width column</Quarter>
<Quarter>Quarter width column</Quarter>
</div>
</div>
);