PromucFlow_constructor/app/client/src/components/propertyControls/MultiSelectControl.tsx

49 lines
1.2 KiB
TypeScript
Raw Normal View History

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