PromucFlow_constructor/app/client/src/components/propertyControls/MultiSwitchControl.tsx
Satish Gandham 7f7f6f666b
Development: Add eslint rules for code consistency (#4083)
Co-authored-by: Satish Gandham <satish@appsmith.com>
Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2021-04-28 15:58:39 +05:30

47 lines
1.3 KiB
TypeScript

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import { IconName, ButtonGroup, Button, Classes } from "@blueprintjs/core";
import { IconNames } from "@blueprintjs/icons";
const iconNames: string[] = Object.values({ ...IconNames });
class MultiSwitchControl extends BaseControl<MultiSwitchControlProps> {
renderOption = (option: SwitchOption) => {
const isIcon: boolean =
!!option.icon && iconNames.indexOf(option.icon) > -1;
return (
<Button
active={this.props.propertyValue === option.value}
icon={isIcon ? (option.icon as IconName) : undefined}
key={option.label || option.icon}
onClick={() =>
this.updateProperty(this.props.propertyName, option.value)
}
text={!isIcon && option.label}
/>
);
};
render() {
return (
<ButtonGroup className={Classes.DARK}>
{this.props.options.map(this.renderOption)}
</ButtonGroup>
);
}
static getControlType() {
return "MULTI_SWITCH";
}
}
interface SwitchOption {
label?: string;
icon?: string;
altText?: string;
value: string | number;
}
export interface MultiSwitchControlProps extends ControlProps {
options: SwitchOption[];
}
export default MultiSwitchControl;