@nwebui/react-niagara-px
Version:
React Niagara Px View
39 lines • 1.55 kB
JavaScript
import React, { useCallback } from "react";
import { usePxView } from "../PxViewContext";
import useWidgetChanged from "./useWidgetChanged";
import { color } from "./utils";
import { Widget } from "./Widget";
const Label = function ({ nativeWidget, children }) {
const { popup } = usePxView();
useWidgetChanged(nativeWidget);
const text = nativeWidget.gets("text");
const font = nativeWidget.gets("font");
const fg = nativeWidget.gets("foreground");
const bg = nativeWidget.gets("background");
const halign = nativeWidget.gets("halign");
const valign = nativeWidget.gets("valign");
const bindings = Array.from(nativeWidget.childComponents((c) => c.is("kitPx:PopupBinding")));
const hasPopup = bindings.length > 0;
const handleClick = useCallback(() => {
const binding = Array.from(nativeWidget.childComponents((c) => c.is("kitPx:PopupBinding")))[0];
if (binding) {
const ord = binding.gets("ord");
popup(ord);
}
}, [popup]);
const style = {
font: font?.replace("pt", "px"),
whiteSpace: "nowrap",
color: color(fg),
background: color(bg),
display: "flex",
alignItems: valign,
justifyContent: halign,
cursor: hasPopup ? "pointer" : undefined,
};
return (React.createElement(Widget, { nativeWidget: nativeWidget, style: style, onClick: handleClick },
text,
children));
};
export default Label;
//# sourceMappingURL=Label.js.map