Created
August 17, 2018 10:19
-
-
Save lnked/9135cb6a0a3549b18a4ae4ef568936e4 to your computer and use it in GitHub Desktop.
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
export interface S { | |
bind: (css: any, args: Array<any>) => string; | |
styler: (css: any) => void; | |
} | |
export const classes: S = { | |
styler: (css, ...args: Array<any>): string => { | |
const r: Array<string> = [] | |
if (args.length) { | |
Object.keys(args).map(id => { | |
const item = args[id] || '' | |
const type = typeof item | |
if (['string', 'number'].indexOf(type) >= 0) { | |
r.push(item) | |
} else { | |
Object.keys(item).map(name => { | |
if (typeof item[name] !== 'undefined' && item[name]) { | |
r.push(css[name]) | |
} | |
}) | |
} | |
}) | |
} | |
return r.filter(i => i !== '').join(' ') | |
}, | |
bind: (css) => { | |
return classes.styler.bind(classes, css) | |
}, | |
} |
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
import * as React from 'react' | |
import * as css from './styles.scss' | |
import { classes } from 'helpers' | |
export interface P { | |
className?: string; | |
} | |
const cx = classes.bind(css) | |
export const Example = ({ className = '' }: P) => { | |
const cond1 = true | |
const cond2 = false | |
return ( | |
<div className={cx({ content: cond1 })}> | |
<div cx({ class: cond2 }, className) /> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment