Skip to content

Can't pass both classes and styles in #2

@serle

Description

@serle

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;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions