UNPKG

nano-jsx

Version:

SSR first, lightweight 1kB JSX library.

35 lines 1.51 kB
import { h } from './core.js'; import { Component } from './component.js'; import { Fragment } from './fragment.js'; import { Helmet } from './components/helmet.js'; export const withStyles = (...styles) => (WrappedComponent) => { return class extends Component { render() { const { children, ...rest } = this.props; const helmets = []; styles.forEach(style => { var _a; if (typeof style === 'string') { helmets.push(h(Helmet, null, h('style', null, style))); } else if (typeof style === 'function') { const _style = style(); if (typeof _style === 'string') { helmets.push(h(Helmet, null, h('style', null, _style))); } } else if (typeof style === 'object') { const _style = (_a = style.toString) === null || _a === void 0 ? void 0 : _a.call(style); if (typeof _style === 'string') { helmets.push(h(Helmet, null, h('style', null, _style))); } } }); const component = children && children.length > 0 ? h(WrappedComponent, { ...rest }, children) : h(WrappedComponent, { ...this.props }); return h(Fragment, null, ...helmets, component); } }; }; //# sourceMappingURL=withStyles.js.map