2019-11-05 05:09:50 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import _ from "lodash";
|
2021-03-15 12:17:56 +00:00
|
|
|
import { DropdownOption } from "components/ads/Dropdown";
|
|
|
|
|
import { StyledMultiSelectDropDown } from "./StyledControls";
|
2019-11-05 05:09:50 +00:00
|
|
|
|
|
|
|
|
class MultiSelectControl extends BaseControl<MultiSelectControlProps> {
|
|
|
|
|
render() {
|
2021-03-15 12:17:56 +00:00
|
|
|
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;
|
|
|
|
|
});
|
2021-03-15 12:17:56 +00:00
|
|
|
if (option) selectedItems.push(option.value as string);
|
2019-11-05 05:09:50 +00:00
|
|
|
return option;
|
|
|
|
|
});
|
2021-03-15 12:17:56 +00:00
|
|
|
|
2019-11-05 05:09:50 +00:00
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledMultiSelectDropDown
|
2021-03-15 12:17:56 +00:00
|
|
|
onSelect={this.onItemSelect}
|
|
|
|
|
optionWidth="187px"
|
2021-04-28 10:28:39 +00:00
|
|
|
options={this.props.options}
|
|
|
|
|
selectAll
|
2021-03-15 12:17:56 +00:00
|
|
|
selectAllQuantifier="*"
|
2021-04-28 10:28:39 +00:00
|
|
|
selected={selectedItems}
|
|
|
|
|
showLabelOnly
|
|
|
|
|
width="100%"
|
2020-02-26 12:44:56 +00:00
|
|
|
/>
|
2019-11-05 05:09:50 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 12:17:56 +00:00
|
|
|
onItemSelect = (value: string[]): void => {
|
|
|
|
|
this.updateProperty(this.props.propertyName, value);
|
2019-11-05 05:09:50 +00:00
|
|
|
};
|
|
|
|
|
|
2020-04-14 05:35:16 +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;
|