// Importing the Ant Design Switch component import { Switch as AntdSwitch } from "antd"; // Defining the Props type for the Switch component // This includes the structure of the props passed to the component type Props = { state?: "AND" | "OR"; // Current state of the switch, either "AND" or "OR" placement?: "outside_group" | "inside_group"; // Placement of the switch relative to a group onChange: (state: "AND" | "OR") => void; // Callback function triggered when the switch state changes }; const Switch = ({ state, placement, onChange }: Props) => { return ( // Wrapper div with conditional styling based on placement
{/* Horizontal line with centered switch */}
{/* Container for the switch with background styling based on placement */}
{/* Ant Design Switch component */} { // Trigger the onChange callback with the new state onChange(checked ? "OR" : "AND"); }} checkedChildren="OR" // Label displayed when the switch is checked unCheckedChildren="AND" // Label displayed when the switch is unchecked style={{ backgroundColor: state === "OR" ? "#eaa808" : "#08adea", // Dynamic background color }} />
); }; export default Switch;