Created
October 1, 2018 13:12
-
-
Save lnked/7ebc7fc695054bfe90d43e4b34a5f8be 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 { | |
styler: (css: any) => string; | |
bind: (css: any) => any; | |
} | |
export const classes: S = { | |
styler: (css, ...args: any[]): string => { | |
const r: 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(item.length ? css[item[name]] : css[name]) | |
} | |
}) | |
} | |
}) | |
} | |
return r.filter(i => i !== '').join(' ') | |
}, | |
bind: css => { | |
return classes.styler.bind(classes, css) | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment