import React, { memo } from "react"; import { Classes as BlueprintClasses, Switch as BlueprintSwitch, SwitchProps as BlueprintSwitchProps, } from "@blueprintjs/core"; import { preventReactFlowDragClass } from "../../cmem/react-flow/ReactFlow/constants"; import { CLASSPREFIX as eccgui } from "../../configuration/constants"; import { Label } from "../Label/Label"; export interface SwitchProps extends Omit { /** * Event handler for changed state. */ onChange?: (value: boolean) => void; /** * class names */ className?: string; /** Adds the 'nodrag' class to the element, preventing dragging via the Switch element. Default: true */ noDrag?: boolean; } export const Switch = ({ onChange, className, label, noDrag = true, ...otherProps }: SwitchProps) => { const handleChange = (e: React.ChangeEvent) => { if (onChange) { onChange(!!e.target?.checked); } }; const noDragClass = noDrag ? `${preventReactFlowDragClass} ` : ""; return ( ) : undefined } {...otherProps} onChange={handleChange} /> ); }; export default memo(Switch);