@inkline/paper
Version:
Paper is a unified interface for defining components for Vue and React using a single code base.
42 lines (34 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.h = void 0;
var _react = require("react");
var _helpers = require("./helpers");
const h = (type, props, ...children) => {
if (props?.class) {
const {
class: className,
...properties
} = props;
props = properties;
props.className = className;
}
if (typeof type !== "string" && typeof children[0] === "object" && !Array.isArray(children[0]) && !children[0].$$typeof) {
const slots = children[0];
const slotKeys = Object.keys(slots);
if (slotKeys.length === 1 && slotKeys[0] === "default") {
children = [slots.default()].flat();
} else {
children = slotKeys.map(slotKey => {
const slotName = (0, _helpers.capitalizeFirst)(slotKey);
const slotComponent = type[slotName];
return h(slotComponent, {
key: slotName
}, slots[slotKey]());
});
}
}
return (0, _react.createElement)(type, props, ...children);
};
exports.h = h;