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

66 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-11-05 05:09:50 +00:00
import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import { StyledDropDown, StyledDropDownContainer } from "./StyledControls";
import { DropdownOption } from "components/ads/Dropdown";
class DropDownControl extends BaseControl<DropDownControlProps> {
render() {
let defaultSelected: DropdownOption = {
label: "No results.",
value: undefined,
};
if (this.props.defaultValue) {
defaultSelected = this.props.options.find(
(option) => option.value === this.props.defaultValue,
);
}
const selected: DropdownOption = this.props.options.find(
2020-12-24 04:32:25 +00:00
(option) => option.value === this.props.propertyValue,
);
if (selected) {
defaultSelected = selected;
}
return (
<StyledDropDownContainer>
<StyledDropDown
onSelect={this.onItemSelect}
optionWidth={
this.props.optionWidth ? this.props.optionWidth : "231px"
}
options={this.props.options}
selected={defaultSelected}
showLabelOnly
width="100%"
/>
</StyledDropDownContainer>
);
}
onItemSelect = (value?: string): void => {
if (value) {
this.updateProperty(this.props.propertyName, value);
}
2019-10-31 05:28:11 +00:00
};
isOptionSelected = (selectedOption: any) => {
2019-11-05 05:09:50 +00:00
return selectedOption.value === this.props.propertyValue;
};
static getControlType() {
return "DROP_DOWN";
}
}
export interface DropDownControlProps extends ControlProps {
options: any[];
defaultValue?: string;
2019-11-05 05:09:50 +00:00
placeholderText: string;
propertyValue: string;
optionWidth?: string;
}
export default DropDownControl;