Last active
September 17, 2019 23:36
-
-
Save gruppjo/e64b34f5b64ea376e9cb725452b9546f to your computer and use it in GitHub Desktop.
React: Component: mapLooksToStyles() - map a components this.props.looks to a joined string of css module styles `styles[look1] styles[look2] ...`
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
// map a components this.props.looks to a joined string of css module styles `styles[look1] styles[look2] ...` | |
// or allows to pass in css class names from parent | |
// <Component looks="isYellow"></Component> | |
// CSS: .isYellow { } | |
export function mapLooksToStyles(looks = '', styles = []) { | |
let customStyles = (looks && looks.trim().split(' ')) | |
|| []; | |
return customStyles.map(look => styles[look] || look).join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment