2020-04-28 06:52:53 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import { StyledSwitch } from "./StyledControls";
|
|
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
|
|
|
|
import FormLabel from "components/editorComponents/FormLabel";
|
|
|
|
|
import { Field, WrappedFieldProps } from "redux-form";
|
2020-08-05 08:02:24 +00:00
|
|
|
import styled from "styled-components";
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
type Props = WrappedFieldProps & SwitchControlProps;
|
|
|
|
|
|
2020-08-05 08:02:24 +00:00
|
|
|
const StyledFormLabel = styled(FormLabel)`
|
|
|
|
|
margin-bottom: 0px;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const SwitchWrapped = styled.div`
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
.bp3-control {
|
|
|
|
|
margin-bottom: 0px;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-08-27 15:39:16 +00:00
|
|
|
const Info = styled.div`
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
opacity: 0.7;
|
|
|
|
|
margin-top: 8px;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-08-05 08:02:24 +00:00
|
|
|
export class SwitchField extends React.Component<Props> {
|
2020-04-28 06:52:53 +00:00
|
|
|
render() {
|
2020-08-27 15:39:16 +00:00
|
|
|
const { label, isRequired, input, info } = this.props;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
return (
|
2020-08-27 15:39:16 +00:00
|
|
|
<div>
|
2020-09-08 04:57:13 +00:00
|
|
|
<SwitchWrapped data-cy={this.props.configProperty}>
|
2020-08-27 15:39:16 +00:00
|
|
|
<StyledFormLabel>
|
|
|
|
|
{label} {isRequired && "*"}
|
|
|
|
|
</StyledFormLabel>
|
|
|
|
|
<StyledSwitch
|
|
|
|
|
checked={input.value}
|
|
|
|
|
onChange={value => input.onChange(value)}
|
|
|
|
|
large
|
|
|
|
|
/>
|
|
|
|
|
</SwitchWrapped>
|
|
|
|
|
{info && <Info>{info}</Info>}
|
|
|
|
|
</div>
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SwitchControl extends BaseControl<SwitchControlProps> {
|
|
|
|
|
render() {
|
|
|
|
|
const { configProperty } = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<Field name={configProperty} component={SwitchField} {...this.props} />
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
2020-09-15 16:54:15 +00:00
|
|
|
return "SWITCH";
|
2020-04-28 06:52:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 15:39:16 +00:00
|
|
|
export interface SwitchControlProps extends ControlProps {
|
|
|
|
|
info?: string;
|
|
|
|
|
}
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
export default SwitchControl;
|