-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Scenario, I have a width property on a control. The user of the control can either pass in a classname or a pixel width. The rest of my themes are specified in the theme object as global classes. The theme function picks either style or className, but does not allow a mix.
Here is my re-write:
require('babel-polyfill');
function is_string(str) {
return (typeof(str) === 'string' || str instanceof String);
}
export default theme => (key, ...names) => {
const classes = names
.map(name => theme[name])
.filter(v => is_string(v))
.filter(v => v);
const styles = names
.map(name => theme[name])
.filter(v => !is_string(v))
.filter(v => v);
let result = { key: key };
if (classes.length > 0) result.className = classes.join(' ');
if (styles.length > 0) result.style = Object.assign({}, ...styles);
return result;
};