-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for flexbox helpers; add spacing helpers typedef
- Loading branch information
1 parent
9e74e9b
commit fbc25f7
Showing
7 changed files
with
164 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
const camelToSnake = (camel) => | ||
camel.replace(/[A-Z]/g, (cap) => `-${cap.toLowerCase()}`); | ||
|
||
const flexboxHelperPropTypes = { | ||
flexDirection: PropTypes.oneOf([ | ||
'row', | ||
'row-reverse', | ||
'column', | ||
'column-reverse', | ||
]), | ||
flexWrap: PropTypes.oneOf(['nowrap', 'wrap', 'wrap-reverse']), | ||
justifyContent: PropTypes.oneOf([ | ||
'flex-start', | ||
'flex-end', | ||
'center', | ||
'space-around', | ||
'space-between', | ||
'space-evenly', | ||
'start', | ||
'end', | ||
'left', | ||
'right', | ||
]), | ||
alignContent: PropTypes.oneOf([ | ||
'flex-start', | ||
'flex-end', | ||
'center', | ||
'space-around', | ||
'space-between', | ||
'space-evenly', | ||
'stretch', | ||
'start', | ||
'end', | ||
'baseline', | ||
]), | ||
alignItems: PropTypes.oneOf([ | ||
'auto', | ||
'flex-start', | ||
'flex-end', | ||
'center', | ||
'baseline', | ||
'stretch', | ||
]), | ||
flexGrow: PropTypes.oneOf([0, 1, 2, 3, 4, 5]), | ||
}; | ||
|
||
const flexboxHelperNames = Object.keys(flexboxHelperPropTypes); | ||
|
||
export default { | ||
propTypes: flexboxHelperPropTypes, | ||
defaultProps: flexboxHelperNames.reduce((defaults, flexboxHelperName) => { | ||
defaults[flexboxHelperName] = undefined; | ||
return defaults; | ||
}, {}), | ||
classnames: (props) => | ||
classNames( | ||
flexboxHelperNames.reduce((classes, flexboxHelper) => { | ||
const propValue = props[flexboxHelper]; | ||
classes[`is-${camelToSnake(flexboxHelper)}-${propValue}`] = propValue; | ||
return classes; | ||
}, {}), | ||
), | ||
clean: (props) => | ||
Object.keys(props).reduce((cleanedProps, propName) => { | ||
if (!flexboxHelperNames.includes(propName)) { | ||
cleanedProps[propName] = props[propName]; | ||
} | ||
return cleanedProps; | ||
}, {}), | ||
}; |
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