PromucFlow_constructor/app/client/src/components/propertyControls/MultiSelectControl.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

49 lines
1.2 KiB
TypeScript

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import _ from "lodash";
import { DropdownOption } from "components/ads/Dropdown";
import { StyledMultiSelectDropDown } from "./StyledControls";
class MultiSelectControl extends BaseControl<MultiSelectControlProps> {
render() {
const selectedItems: string[] = [];
_.map(this.props.propertyValue, (value) => {
const option = _.find(this.props.options, (option) => {
return option.value === value;
});
if (option) selectedItems.push(option.value as string);
return option;
});
return (
<StyledMultiSelectDropDown
onSelect={this.onItemSelect}
optionWidth="187px"
options={this.props.options}
selectAll
selectAllQuantifier="*"
selected={selectedItems}
showLabelOnly
width="100%"
/>
);
}
onItemSelect = (value: string[]): void => {
this.updateProperty(this.props.propertyName, value);
};
static getControlType() {
return "MULTI_SELECT";
}
}
export interface MultiSelectControlProps extends ControlProps {
options: DropdownOption[];
placeholderText: string;
propertyValue: string[];
}
export default MultiSelectControl;