@nwebui/react-niagara-px
Version:
React Niagara Px View
39 lines • 1.52 kB
JavaScript
import React from "react";
import useWidgetChanged from "./useWidgetChanged";
import { color } from "./utils";
import { Widget } from "./Widget";
const CheckBox = function ({ nativeWidget, children }) {
useWidgetChanged(nativeWidget);
const fg = nativeWidget.gets("foreground");
const bg = nativeWidget.gets("background");
const selected = nativeWidget.getb("selected");
const text = nativeWidget.gets("text") ?? "";
const font = nativeWidget.gets("font");
const style = {
color: color(fg),
background: color(bg),
display: "flex",
alignItems: "center",
font: font?.replace("pt", "px"),
};
function handleClick() {
const selected = nativeWidget.getb("selected");
const binding = Array.from(nativeWidget.childComponents((c) => c.is("kitPx:SetPointBinding")))[0];
if (!binding) {
return;
}
const ord = binding.gets("ord");
const action = "set";
const value = !selected;
fetch("/webapi/controlpoint/invoke", {
method: "POST",
body: JSON.stringify([{ ord, action, value }]),
});
}
return (React.createElement(Widget, { nativeWidget: nativeWidget, style: style },
React.createElement("input", { type: "checkbox", checked: selected, onChange: handleClick, style: { cursor: "pointer" } }),
text,
children));
};
export default CheckBox;
//# sourceMappingURL=CheckBox.js.map