@nwebui/react-niagara-px
Version:
React Niagara Px View
33 lines • 1.16 kB
JavaScript
import React, { useEffect, useRef, useState, } from "react";
import YAML from "yaml";
import { loadPx } from "./loader";
import { PxViewContext } from "./PxViewContext";
import render from "./render";
const PxView = function ({ url, factory, context }) {
const [elem, setElem] = useState(null);
const divRef = useRef(null);
useEffect(() => {
async function load() {
const px = await loadPx(url);
const elem = render(px, factory);
setElem(elem);
}
load();
}, [url]);
return (React.createElement("div", { ref: divRef, style: { width: "100%", height: "100%" } },
React.createElement(PxViewContext.Provider, { value: context }, elem)));
};
export default PxView;
export function customizedLabelFactory(widgets) {
return (widget) => {
if (widget.is("bajaui:Label")) {
const text = widget.gets("text") ?? "";
if (text.match(/^type:/)) {
const args = YAML.parse(text);
return widgets[args.type];
}
}
return;
};
}
//# sourceMappingURL=PxView.js.map