nano-jsx
Version:
SSR first, lightweight 1kB JSX library.
39 lines • 1.87 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.withStyles = void 0;
const core_js_1 = require("./core.js");
const component_js_1 = require("./component.js");
const fragment_js_1 = require("./fragment.js");
const helmet_js_1 = require("./components/helmet.js");
const withStyles = (...styles) => (WrappedComponent) => {
return class extends component_js_1.Component {
render() {
const { children, ...rest } = this.props;
const helmets = [];
styles.forEach(style => {
var _a;
if (typeof style === 'string') {
helmets.push((0, core_js_1.h)(helmet_js_1.Helmet, null, (0, core_js_1.h)('style', null, style)));
}
else if (typeof style === 'function') {
const _style = style();
if (typeof _style === 'string') {
helmets.push((0, core_js_1.h)(helmet_js_1.Helmet, null, (0, core_js_1.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((0, core_js_1.h)(helmet_js_1.Helmet, null, (0, core_js_1.h)('style', null, _style)));
}
}
});
const component = children && children.length > 0
? (0, core_js_1.h)(WrappedComponent, { ...rest }, children)
: (0, core_js_1.h)(WrappedComponent, { ...this.props });
return (0, core_js_1.h)(fragment_js_1.Fragment, null, ...helmets, component);
}
};
};
exports.withStyles = withStyles;
//# sourceMappingURL=withStyles.js.map
;