Skip to content

Instantly share code, notes, and snippets.

@gruppjo
Last active September 17, 2019 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gruppjo/e64b34f5b64ea376e9cb725452b9546f to your computer and use it in GitHub Desktop.
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] ...`
// 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