2020-04-28 06:52:53 +00:00
|
|
|
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";
|
2020-04-28 06:52:53 +00:00
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
|
|
|
|
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
|
|
|
|
2021-12-27 12:04:45 +00:00
|
|
|
type SwitchFieldProps = WrappedFieldProps & {
|
2020-11-19 03:32:58 +00:00
|
|
|
label: string;
|
|
|
|
|
isRequired: boolean;
|
|
|
|
|
info: string;
|
2022-01-06 14:39:21 +00:00
|
|
|
disabled: boolean;
|
2020-11-19 03:32:58 +00:00
|
|
|
};
|
2020-04-28 06:52:53 +00:00
|
|
|
|
2021-12-27 12:04:45 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2020-08-05 08:02:24 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const SwitchWrapped = styled.div`
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
.bp3-control {
|
|
|
|
|
margin-bottom: 0px;
|
|
|
|
|
}
|
2021-10-04 06:57:17 +00:00
|
|
|
max-width: 60vw;
|
2020-08-05 08:02:24 +00:00
|
|
|
`;
|
|
|
|
|
|
2021-12-27 12:04:45 +00:00
|
|
|
export class SwitchField extends React.Component<SwitchFieldProps, any> {
|
2021-02-19 11:00:07 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 06:52:53 +00:00
|
|
|
render() {
|
|
|
|
|
return (
|
2020-08-27 15:39:16 +00:00
|
|
|
<div>
|
2020-11-19 03:32:58 +00:00
|
|
|
<SwitchWrapped data-cy={this.props.input.name}>
|
2021-12-27 12:04:45 +00:00
|
|
|
<StyledToggle
|
|
|
|
|
className="switch-control"
|
2022-01-06 14:39:21 +00:00
|
|
|
disabled={this.props.disabled}
|
2021-12-27 12:04:45 +00:00
|
|
|
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) => {
|
2021-12-27 12:04:45 +00:00
|
|
|
this.props.input.onChange(value);
|
|
|
|
|
}}
|
|
|
|
|
value={this.value}
|
2020-08-27 15:39:16 +00:00
|
|
|
/>
|
|
|
|
|
</SwitchWrapped>
|
|
|
|
|
</div>
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SwitchControl extends BaseControl<SwitchControlProps> {
|
|
|
|
|
render() {
|
2022-01-06 14:39:21 +00:00
|
|
|
const { configProperty, disabled, info, isRequired, label } = this.props;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
return (
|
2021-04-28 10:28:39 +00:00
|
|
|
<Field
|
|
|
|
|
component={SwitchField}
|
2022-01-06 14:39:21 +00:00
|
|
|
disabled={disabled}
|
2021-04-28 10:28:39 +00:00
|
|
|
info={info}
|
|
|
|
|
isRequired={isRequired}
|
|
|
|
|
label={label}
|
|
|
|
|
name={configProperty}
|
|
|
|
|
/>
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|