This repository has been archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30a6371
commit e31bde6
Showing
13 changed files
with
461 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from 'react'; | ||
import { head } from 'lodash'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from 'styled-components'; | ||
import Flex from '../Flex'; | ||
import { createComponent } from '../utils'; | ||
|
||
const getWidthPercent = (width, columns) => `${(width / columns) * 100}%`; | ||
|
||
const getColumnWidth = (width, columns) => | ||
width / columns !== 1 | ||
? css` | ||
display: block; | ||
flex-basis: ${getWidthPercent(width, columns)}; | ||
max-width: ${getWidthPercent(width, columns)}; | ||
` | ||
: css` | ||
max-width: 100%; | ||
width: 100%; | ||
flex: auto; | ||
`; | ||
|
||
const getPadding = p => { | ||
if (p.collapse) return 0; | ||
return p.gutter ? p.gutter / 2 : p.theme.grid.gutter / 2; | ||
}; | ||
|
||
const getOffset = (offset, columns) => css` | ||
margin-left: ${offset === 0 ? 0 : getWidthPercent(offset, columns)}; | ||
`; | ||
|
||
const StyledColumn = createComponent({ | ||
name: 'Column', | ||
as: Flex, | ||
}).extend` | ||
box-sizing: border-box; | ||
flex: 1 0 auto; | ||
padding-left: ${getPadding}px; | ||
padding-right: ${getPadding}px; | ||
${p => { | ||
const sizes = Object.keys(p.theme.grid.sizes); | ||
const mediaQueries = sizes.filter(size => !!p[size]).map( | ||
size => | ||
// if smallest breakpoint no query needed | ||
size === head(sizes) | ||
? css` | ||
${getColumnWidth(p[size], p.theme.grid.columns)}; | ||
${p[`${size}Offset`] && getOffset(p[`${size}Offset`], p.theme.grid.columns)}; | ||
` | ||
: // all other breakpoints use a media query | ||
css` | ||
@media (min-width: ${p.theme.grid.sizes[size]}px) { | ||
${getColumnWidth(p[size], p.theme.grid.columns)}; | ||
${p[`${size}Offset`] !== undefined && getOffset(p[`${size}Offset`], p.theme.grid.columns)}; | ||
} | ||
` | ||
); | ||
return css` | ||
order: ${p.order ? p.order : 'initial'}; | ||
${mediaQueries}; | ||
`; | ||
}} | ||
`; | ||
|
||
const Column = props => <StyledColumn {...props} />; | ||
|
||
Column.propTypes = { | ||
/** | ||
* Lay row out vertically | ||
*/ | ||
vertical: PropTypes.number, | ||
|
||
/** | ||
* Margin between columns | ||
*/ | ||
gutter: PropTypes.number, | ||
|
||
/** | ||
* Reverse the order of the columns | ||
*/ | ||
reverse: PropTypes.bool, | ||
|
||
/** | ||
* Collapse columns by removing gutters | ||
*/ | ||
collapse: PropTypes.bool, | ||
}; | ||
|
||
Column.defaultProps = { | ||
vertical: false, | ||
reverse: false, | ||
collapse: false, | ||
}; | ||
|
||
export default Column; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
menu: Grid | ||
name: Column | ||
--- | ||
|
||
import { Playground, PropsTable } from 'docz'; | ||
|
||
import Container from './Container'; | ||
import Row from './Row'; | ||
import Column from './Column'; | ||
import ExampleBox from './ExampleBox' | ||
|
||
# Column | ||
|
||
## Properties | ||
|
||
<PropsTable of={Column} /> | ||
|
||
#### Equal Widths | ||
<Playground> | ||
<Container> | ||
<Row> | ||
<Column> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
</Row> | ||
</Container> | ||
</Playground> | ||
|
||
### One column set width | ||
<Playground> | ||
<Container> | ||
<Row> | ||
<Column xs={8}> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
</Row> | ||
</Container> | ||
</Playground> | ||
|
||
### Different widths for different breakpoints | ||
<Playground> | ||
<Container> | ||
<Row> | ||
<Column xs={8} sm={12} md={6} lg={12}> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>Column</ExampleBox> | ||
</Column> | ||
</Row> | ||
</Container> | ||
</Playground> | ||
|
||
### Column ordering | ||
<Playground> | ||
<Container> | ||
<Row> | ||
<Column order={12}> | ||
<ExampleBox>1</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>2</ExampleBox> | ||
</Column> | ||
<Column> | ||
<ExampleBox>3</ExampleBox> | ||
</Column> | ||
</Row> | ||
</Container> | ||
</Playground> | ||
|
||
### Column offsets | ||
<Playground> | ||
<Container> | ||
<Row> | ||
<Column xs={4} xsOffset={2}> | ||
<ExampleBox>1</ExampleBox> | ||
</Column> | ||
</Row> | ||
</Container> | ||
</Playground> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Box from '../Box'; | ||
import { createComponent } from '../utils'; | ||
|
||
const getPadding = p => (p.gutter ? p.gutter / 2 : p.theme.grid.gutter / 2); | ||
|
||
const StyledContainer = createComponent({ | ||
name: 'Container', | ||
as: Box, | ||
}).extend` | ||
margin-left: auto; | ||
margin-right: auto; | ||
max-width: ${p => (p.fluid ? '100%' : `${p.maxWidth || p.theme.grid.containerMaxWidth}px`)}; | ||
padding-left: ${getPadding}px; | ||
padding-right: ${getPadding}px; | ||
`; | ||
|
||
StyledContainer.displayName = 'Container'; | ||
|
||
const Container = ({ children, gutter, maxWidth, fluid }) => ( | ||
<StyledContainer fluid={fluid} gutter={gutter} maxWidth={maxWidth}> | ||
{React.Children.map(children, child => React.cloneElement(child, { gutter }))} | ||
</StyledContainer> | ||
); | ||
|
||
Container.propTypes = { | ||
gutter: PropTypes.number, | ||
}; | ||
|
||
export default Container; |
Oops, something went wrong.