@platform/css
Version:
Helpers for working with inline CSS.
27 lines (26 loc) • 794 B
JavaScript
import { R, jss } from '../common';
const PluginGlobal = require('jss-plugin-global').default;
jss.jss.use(PluginGlobal);
export const global = (styles, options = {}) => {
if (R.isEmpty(styles)) {
return;
}
const { prefix } = options;
const global = {};
Object.keys(styles).forEach(key => {
const style = styles[key];
key.split(',').forEach(key => {
const selector = toCssSelector({ key, prefix });
global[selector] = style;
});
});
jss.jss.createStyleSheet({ '@global': global }).attach();
};
function toCssSelector(args) {
const { key, prefix } = args;
const selector = prefix ? `${prefix} ${key}` : key;
return selector
.replace(/^\n/, '')
.replace(/\n$/, '')
.trim();
}