2020-08-12 06:27:35 +00:00
|
|
|
import React from "react";
|
2021-12-27 12:04:45 +00:00
|
|
|
import Checkbox from "components/ads/Checkbox";
|
2020-08-12 06:27:35 +00:00
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
2021-12-27 12:04:45 +00:00
|
|
|
import {
|
|
|
|
|
Field,
|
|
|
|
|
WrappedFieldInputProps,
|
|
|
|
|
WrappedFieldMetaProps,
|
|
|
|
|
} from "redux-form";
|
2020-08-12 06:27:35 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
2021-12-27 12:04:45 +00:00
|
|
|
const StyledCheckbox = styled(Checkbox)``;
|
2020-08-12 06:27:35 +00:00
|
|
|
|
|
|
|
|
class CheckboxControl extends BaseControl<CheckboxControlProps> {
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "CHECKBOX";
|
|
|
|
|
}
|
|
|
|
|
render() {
|
2021-12-27 12:04:45 +00:00
|
|
|
return (
|
|
|
|
|
<Field
|
|
|
|
|
component={renderComponent}
|
|
|
|
|
name={this.props.configProperty}
|
|
|
|
|
props={{ ...this.props }}
|
|
|
|
|
type="checkbox"
|
|
|
|
|
/>
|
|
|
|
|
);
|
2020-08-12 06:27:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 12:04:45 +00:00
|
|
|
type renderComponentProps = CheckboxControlProps & {
|
|
|
|
|
input?: WrappedFieldInputProps;
|
|
|
|
|
meta?: WrappedFieldMetaProps;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function renderComponent(props: renderComponentProps) {
|
|
|
|
|
const onChangeHandler = (value: boolean) => {
|
|
|
|
|
props.input && props.input.onChange && props.input.onChange(value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<StyledCheckbox
|
2022-07-21 10:40:36 +00:00
|
|
|
cypressSelector={props?.input?.name}
|
2021-12-27 12:04:45 +00:00
|
|
|
isDefaultChecked={props?.input?.checked as boolean}
|
|
|
|
|
{...props}
|
|
|
|
|
info={undefined}
|
|
|
|
|
label={""}
|
|
|
|
|
name={props?.input?.name}
|
|
|
|
|
onCheckChange={onChangeHandler}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-02-11 12:54:00 +00:00
|
|
|
export interface CheckboxControlProps extends ControlProps {
|
|
|
|
|
info?: string;
|
|
|
|
|
}
|
2020-08-12 06:27:35 +00:00
|
|
|
|
|
|
|
|
export default CheckboxControl;
|