UNPKG

@nwebui/react-niagara-px

Version:
29 lines 1.17 kB
import React from "react"; import useWidgetChanged from "./useWidgetChanged"; import { Widget } from "./Widget"; const ToggleButton = function ({ nativeWidget, children }) { useWidgetChanged(nativeWidget); const image = nativeWidget.gets("image")?.replace("file:^", "/file/"); const style = { cursor: "pointer", }; 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, onClick: handleClick }, image && React.createElement("img", { src: image, style: { width: "100%", height: "100%" } }), children)); }; export default ToggleButton; //# sourceMappingURL=ToggleButton.js.map