@react-slate/core
Version:
Write interactive CLI apps with React
53 lines • 1.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const View_1 = __importDefault(require("./nodes/View"));
const Text_1 = __importDefault(require("./nodes/Text"));
const Paragraph_1 = __importDefault(require("./nodes/Paragraph"));
function createElement(type, props) {
if (typeof type === 'function') {
return type;
}
let instance;
switch (type) {
case View_1.default.TAG: {
instance = new View_1.default();
if (props.layoutStyle) {
instance.setLayoutStyle(props.layoutStyle);
}
break;
}
case Paragraph_1.default.TAG: {
instance = new Paragraph_1.default();
break;
}
case Text_1.default.TAG: {
instance = new Text_1.default();
instance.setBody(props.children);
break;
}
default: {
break;
}
}
if (instance) {
instance.testID = props.testID;
if (props.style) {
instance.style = props.style;
}
if (props.onLayout) {
instance.onLayoutHook = props.onLayout;
}
if (props.onClick) {
instance.eventListener.setOnClickListener(props.onClick);
}
if (props.onWheel) {
instance.eventListener.setOnWheelListener(props.onWheel);
}
}
return instance;
}
exports.default = createElement;
//# sourceMappingURL=createElement.js.map