Skip to content

Instantly share code, notes, and snippets.

@iegik
Last active September 12, 2018 09:35
Show Gist options
  • Save iegik/b7f62baa91ad59affada49d16ff7bcc1 to your computer and use it in GitHub Desktop.
Save iegik/b7f62baa91ad59affada49d16ff7bcc1 to your computer and use it in GitHub Desktop.
export default styles => Object.keys(styles)
.filter((key) => !/^_/.test(key))
.reduce((prev, next) => ({...prev, [next]:styles[next]}), {});
import React from 'react';
import ReactDOM from "react-dom";
import BEM from './BEM';
const styles = {
favorites: {
color: 'green',
_list: {
listStyle: 'none',
padding: 0,
},
_listItem: {
color: 'red',
__active: {
color: 'brown',
}
},
}
};
const Foo = () => (
<div style={BEM(styles.favorites)}>
Foo
<ul style={BEM(styles.favorites._list)}>
<li style={BEM(styles.favorites._listItem)}>Bar</li>
<li
style={{
...BEM(styles.favorites._listItem),
...BEM(styles.favorites._listItem.__active)
}}
>
Tar
</li>
</ul>
</div>
);
const rootElement = document.body;
ReactDOM.render(<Foo />, rootElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment