import React from "react"; import type { ControlProps } from "./BaseControl"; import BaseControl from "./BaseControl"; import { Switch } from "design-system"; import type { ControlType } from "constants/PropertyControlConstants"; import type { WrappedFieldProps } from "redux-form"; import { Field } from "redux-form"; import styled from "styled-components"; type SwitchFieldProps = WrappedFieldProps & { label: string; isRequired: boolean; info: string; disabled: boolean; }; const SwitchWrapped = styled.div` flex-direction: row; display: flex; align-items: center; justify-content: end; position: relative; max-width: 60vw; `; export class SwitchField extends React.Component { get value() { const { input } = this.props; if (typeof input.value !== "string") return !!input.value; else { if (input.value.toLocaleLowerCase() === "false") return false; else return !!input.value; } } render() { return ( {/* TODO: refactor so that the label of the field props is also passed down and a part of Switch.*/} this.props.input.onChange(isSelected)} /> ); } } class SwitchControl extends BaseControl { render() { const { configProperty, disabled, info, isRequired, label } = this.props; return ( ); } getControlType(): ControlType { return "SWITCH"; } } export interface SwitchControlProps extends ControlProps { info?: string; } export default SwitchControl;