PromucFlow_constructor/app/client/src/components/formControls/SwitchControl.tsx

95 lines
2.1 KiB
TypeScript
Raw Normal View History

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
feat: import changes batch 2 (#15722) * Remove treedropdown from ads * Change Treedropdown imports * Remove Notification Banner, change imports * Remove Toggle from ads * Change toggle imports * explicitly declare function argument types * Remove Menu from ads * Change menu imports * Remove Spinner from ads * Change spinner imports * Remove Radio, import changes * test: updated flaky test under default meta (#15707) * updated flaky test * Updated tests * updated tests * updated the tests * updated tests * Update constants.ts * add more typecasting * Remove ListSegmentHeader, import changes * Remove TagInputComponent, import changes * Remove Switch, import changes * Remove SearchInput, change imports * Rename TagInputComponent to TagInput * Remove ProgressiveImage, import changes * import changes for SearchVariant * Remove menu divider, import changes * Remove TableDropdown, import changes * Remove Switcher * Remove StatusBar, import changes * Remove showcase carousel * Remove RectangularSwitcher, import change * Add types to TableDropdown's args * Remove MultiSwitch, import change * Remove GifPlayerComponent, import change * Remove DraggableList, import change * Remove DisplayImageUpload, import change * Remove DatePickerComponent, import change * Remove CopyToClipBoard, import change * Remove ColorSelector, import change * Remove TabItemBackgroundFill, NumberedStep, ColorPickerComponent * GifPlayerComponent -> GifPlayer * change named import * Remove FormFieldError, change imports * Update to new version of Tree Dropdown * Fix issue with ads/index.ts * Test file fix * Fix issue with merge?!?!?? * update design system to 1.0.18 * Bump ds version * bump ds version * bump ds version Co-authored-by: NandanAnantharamu <67676905+NandanAnantharamu@users.noreply.github.com> Co-authored-by: Albin <albin@appsmith.com>
2022-09-02 08:38:17 +00:00
import { Toggle } from "design-system";
import { ControlType } from "constants/PropertyControlConstants";
import { Field, WrappedFieldProps } from "redux-form";
import styled from "styled-components";
type SwitchFieldProps = WrappedFieldProps & {
label: string;
isRequired: boolean;
info: string;
disabled: boolean;
};
const StyledToggle = styled(Toggle)`
.slider {
margin-left: 10px;
width: 40px;
height: 20px;
}
.slider::before {
height: 16px;
width: 16px;
}
input:checked + .slider::before {
transform: translateX(19px);
}
`;
const SwitchWrapped = styled.div`
flex-direction: row;
display: flex;
align-items: center;
.bp3-control {
margin-bottom: 0px;
}
max-width: 60vw;
`;
export class SwitchField extends React.Component<SwitchFieldProps, any> {
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 (
<div>
<SwitchWrapped data-cy={this.props.input.name}>
<StyledToggle
className="switch-control"
disabled={this.props.disabled}
name={this.props.input.name}
feat: import changes batch 2 (#15722) * Remove treedropdown from ads * Change Treedropdown imports * Remove Notification Banner, change imports * Remove Toggle from ads * Change toggle imports * explicitly declare function argument types * Remove Menu from ads * Change menu imports * Remove Spinner from ads * Change spinner imports * Remove Radio, import changes * test: updated flaky test under default meta (#15707) * updated flaky test * Updated tests * updated tests * updated the tests * updated tests * Update constants.ts * add more typecasting * Remove ListSegmentHeader, import changes * Remove TagInputComponent, import changes * Remove Switch, import changes * Remove SearchInput, change imports * Rename TagInputComponent to TagInput * Remove ProgressiveImage, import changes * import changes for SearchVariant * Remove menu divider, import changes * Remove TableDropdown, import changes * Remove Switcher * Remove StatusBar, import changes * Remove showcase carousel * Remove RectangularSwitcher, import change * Add types to TableDropdown's args * Remove MultiSwitch, import change * Remove GifPlayerComponent, import change * Remove DraggableList, import change * Remove DisplayImageUpload, import change * Remove DatePickerComponent, import change * Remove CopyToClipBoard, import change * Remove ColorSelector, import change * Remove TabItemBackgroundFill, NumberedStep, ColorPickerComponent * GifPlayerComponent -> GifPlayer * change named import * Remove FormFieldError, change imports * Update to new version of Tree Dropdown * Fix issue with ads/index.ts * Test file fix * Fix issue with merge?!?!?? * update design system to 1.0.18 * Bump ds version * bump ds version * bump ds version Co-authored-by: NandanAnantharamu <67676905+NandanAnantharamu@users.noreply.github.com> Co-authored-by: Albin <albin@appsmith.com>
2022-09-02 08:38:17 +00:00
onToggle={(value: boolean) => {
this.props.input.onChange(value);
}}
value={this.value}
/>
</SwitchWrapped>
</div>
);
}
}
class SwitchControl extends BaseControl<SwitchControlProps> {
render() {
const { configProperty, disabled, info, isRequired, label } = this.props;
return (
<Field
component={SwitchField}
disabled={disabled}
info={info}
isRequired={isRequired}
label={label}
name={configProperty}
/>
);
}
getControlType(): ControlType {
return "SWITCH";
}
}
export interface SwitchControlProps extends ControlProps {
info?: string;
}
export default SwitchControl;