Last active
May 10, 2016 19:37
-
-
Save gustavoguichard/d18a8d958b198458240d31df48493331 to your computer and use it in GitHub Desktop.
BS SmartGrid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { cloneElement, PropTypes } from 'react' | |
| import { map, chunk, uniqueId } from 'lodash' | |
| export const SmartGrid = ({ columns = 3, minWidth = 'sm', children }) => { | |
| const cols = parseInt(12 / columns, 10) | |
| const join = (...classes) => classes.join(' ') | |
| return ( | |
| <div> | |
| {map(chunk(children, columns), (kids, index) => | |
| <div className="row" key={index}> | |
| {map(kids, child => | |
| cloneElement(child, { | |
| className: join(`col-${minWidth}-${cols}`, child.props.className), | |
| key: uniqueId('column'), | |
| }) | |
| )} | |
| </div> | |
| )} | |
| </div> | |
| ) | |
| } | |
| SmartGrid.propTypes = { | |
| columns: PropTypes.number, | |
| minWidth: PropTypes.string, | |
| children: PropTypes.array.isRequired, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment