Skip to content

Instantly share code, notes, and snippets.

@lnked
Created October 1, 2018 13:12
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 lnked/7ebc7fc695054bfe90d43e4b34a5f8be to your computer and use it in GitHub Desktop.
Save lnked/7ebc7fc695054bfe90d43e4b34a5f8be to your computer and use it in GitHub Desktop.
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