import React from "react"; import BaseControl, { ControlProps } from "./BaseControl"; import { StyledDropDown, StyledDropDownContainer } from "./StyledControls"; import { DropdownOption } from "components/ads/Dropdown"; import { isNil } from "lodash"; import { isDynamicValue } from "utils/DynamicBindingUtils"; class DropDownControl extends BaseControl { render() { let defaultSelected: DropdownOption = { label: "No selection.", value: undefined, }; const options = this.props?.options || []; if (this.props.defaultValue) { defaultSelected = options.find( (option) => option.value === this.props.defaultValue, ); } const computedValue = !isNil(this.props.propertyValue) && isDynamicValue(this.props.propertyValue) ? this.props.evaluatedValue : this.props.propertyValue; const selected: DropdownOption = options.find( (option) => option.value === computedValue, ); if (selected) { defaultSelected = selected; } return ( ); } onItemSelect = (value?: string): void => { if (!isNil(value)) { this.updateProperty(this.props.propertyName, value); } }; isOptionSelected = (selectedOption: any) => { return selectedOption.value === this.props.propertyValue; }; static getControlType() { return "DROP_DOWN"; } } export interface DropDownControlProps extends ControlProps { options?: any[]; defaultValue?: string; placeholderText: string; dropdownHeight?: string; enableSearch?: boolean; propertyValue: string; optionWidth?: string; hideSubText?: boolean; } export default DropDownControl;