-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from primer/responsive_flex_component
Responsive flex component
- Loading branch information
Showing
7 changed files
with
71 additions
and
46 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,36 +1,31 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import classnames from 'classnames' | ||
import Block from './Block' | ||
import {mapAllProps, oneOrMoreOf} from './props' | ||
|
||
const FlexContainer = ({children, inline, wrap, direction, justifyContent, alignItems, alignContent, ...rest}) => { | ||
const classes = classnames( | ||
{ | ||
'd-flex': !inline, | ||
'd-inline-flex': inline | ||
}, | ||
wrap && `flex-${wrap}`, | ||
direction && `flex-${direction}`, | ||
justifyContent && `flex-justify-${justifyContent}`, | ||
alignItems && `flex-items-${alignItems}`, | ||
alignContent && `flex-content-${alignContent}` | ||
) | ||
const FlexContainer = props => { | ||
const {className, children, ...rest} = mapAllProps(props) | ||
|
||
return ( | ||
<Block {...rest} className={classes}> | ||
<Block {...rest} className={className}> | ||
{children} | ||
</Block> | ||
) | ||
} | ||
|
||
FlexContainer.propTypes = { | ||
alignContent: PropTypes.oneOf(['start', 'end', 'center', 'between', 'around', 'stretch']), | ||
alignItems: PropTypes.oneOf(['start', 'end', 'center', 'baseline', 'stretch']), | ||
alignContent: oneOrMoreOf(PropTypes.oneOf(['start', 'end', 'center', 'between', 'around', 'stretch'])), | ||
alignItems: oneOrMoreOf(PropTypes.oneOf(['start', 'end', 'center', 'baseline', 'stretch'])), | ||
children: PropTypes.node, | ||
direction: PropTypes.oneOf(['row', 'row-reverse', 'column']), | ||
direction: oneOrMoreOf(PropTypes.oneOf(['row', 'row-reverse', 'column'])), | ||
display: oneOrMoreOf(PropTypes.oneOf(['flex', 'inline-flex'])), | ||
inline: PropTypes.bool, | ||
justifyContent: PropTypes.oneOf(['start', 'end', 'center', 'between', 'around']), | ||
wrap: PropTypes.oneOf(['wrap', 'nowrap']) | ||
justifyContent: oneOrMoreOf(PropTypes.oneOf(['start', 'end', 'center', 'between', 'around'])), | ||
wrap: oneOrMoreOf(PropTypes.oneOf(['wrap', 'nowrap'])) | ||
} | ||
|
||
FlexContainer.defaultProps = { | ||
display: 'flex' | ||
} | ||
|
||
export default FlexContainer |
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