@nwebui/react-niagara-px
Version:
React Niagara Px View
30 lines • 1.18 kB
JavaScript
import clsx from "clsx";
import React, { forwardRef } from "react";
import useWidgetChanged from "./useWidgetChanged";
export const Widget = forwardRef(function Widget({ nativeWidget, className, style, children, ...others }, ref) {
useWidgetChanged(nativeWidget);
const layout = nativeWidget.gets("layout");
const style2 = {};
if (layout) {
if (layout == "fill") {
Object.assign(style2, {
width: "100%",
height: "100%",
});
}
else {
const [x, y, w, h] = layout.split(",").map((x) => +x);
Object.assign(style2, {
position: "absolute",
left: `${x}px`,
top: `${y}px`,
width: `${w}px`,
height: `${h}px`,
});
}
}
return (React.createElement("div", { ref: ref, className: clsx(className, nativeWidget.type.toString()), style: Object.assign(style2, style ?? {}), ...others },
children,
React.createElement("pre", { style: { display: "none" } }, nativeWidget.elem.outerHTML)));
});
//# sourceMappingURL=Widget.js.map