-
Notifications
You must be signed in to change notification settings - Fork 481
/
EqualColumns.jsx
40 lines (37 loc) · 1.2 KB
/
EqualColumns.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
/** @file Arranges child components as columns of equal width, filling available space */
import React, {PropTypes} from 'react';
import Radium from 'radium';
import {AnyChildren} from './types';
export default Radium(class EqualColumns extends React.Component {
static propTypes = {
// Space between columns, in pixels
intercolumnarDistance: PropTypes.number,
children: AnyChildren
};
static defaultProps = {intercolumnarDistance: 0};
render() {
const {children, intercolumnarDistance} = this.props;
const childCount = React.Children.count(children);
const outerColumnStyle = {
float: 'left',
width: (100 / childCount) + '%',
};
return (
<div>
{React.Children.map(this.props.children, (child, index) => {
const innerColumnStyle = {
marginLeft: (index > 0) && (intercolumnarDistance / 2),
marginRight: (index < childCount - 1) && (intercolumnarDistance / 2)
};
return (
<div style={outerColumnStyle}>
<div style={innerColumnStyle}>
{child}
</div>
</div>);
})}
<div style={{clear:'both'}}/>
</div>
);
}
});