2019-11-05 05:09:50 +00:00
|
|
|
import React from "react";
|
2019-09-18 10:19:50 +00:00
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
2021-03-15 12:17:56 +00:00
|
|
|
import { StyledDropDown, StyledDropDownContainer } from "./StyledControls";
|
|
|
|
|
import { DropdownOption } from "components/ads/Dropdown";
|
2019-09-18 10:19:50 +00:00
|
|
|
|
|
|
|
|
class DropDownControl extends BaseControl<DropDownControlProps> {
|
|
|
|
|
render() {
|
2021-03-15 12:17:56 +00:00
|
|
|
let defaultSelected: DropdownOption = {
|
|
|
|
|
label: "No results.",
|
|
|
|
|
value: undefined,
|
|
|
|
|
};
|
2021-05-06 14:06:41 +00:00
|
|
|
if (this.props.defaultValue) {
|
|
|
|
|
defaultSelected = this.props.options.find(
|
|
|
|
|
(option) => option.value === this.props.defaultValue,
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-03-15 12:17:56 +00:00
|
|
|
|
|
|
|
|
const selected: DropdownOption = this.props.options.find(
|
2020-12-24 04:32:25 +00:00
|
|
|
(option) => option.value === this.props.propertyValue,
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
);
|
2021-03-15 12:17:56 +00:00
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
|
defaultSelected = selected;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-18 10:19:50 +00:00
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledDropDownContainer>
|
|
|
|
|
<StyledDropDown
|
2021-03-15 12:17:56 +00:00
|
|
|
onSelect={this.onItemSelect}
|
2021-03-24 08:53:39 +00:00
|
|
|
optionWidth={
|
2021-03-30 08:48:14 +00:00
|
|
|
this.props.optionWidth ? this.props.optionWidth : "231px"
|
2021-03-24 08:53:39 +00:00
|
|
|
}
|
2021-04-28 10:28:39 +00:00
|
|
|
options={this.props.options}
|
|
|
|
|
selected={defaultSelected}
|
|
|
|
|
showLabelOnly
|
|
|
|
|
width="100%"
|
2021-03-15 12:17:56 +00:00
|
|
|
/>
|
2020-02-26 12:44:56 +00:00
|
|
|
</StyledDropDownContainer>
|
2019-09-18 10:19:50 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 12:17:56 +00:00
|
|
|
onItemSelect = (value?: string): void => {
|
|
|
|
|
if (value) {
|
|
|
|
|
this.updateProperty(this.props.propertyName, value);
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
2019-10-31 05:28:11 +00:00
|
|
|
};
|
2019-09-18 10:19:50 +00:00
|
|
|
|
2021-03-15 12:17:56 +00:00
|
|
|
isOptionSelected = (selectedOption: any) => {
|
2019-11-05 05:09:50 +00:00
|
|
|
return selectedOption.value === this.props.propertyValue;
|
|
|
|
|
};
|
2019-09-18 10:19:50 +00:00
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
static getControlType() {
|
2019-09-18 10:19:50 +00:00
|
|
|
return "DROP_DOWN";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DropDownControlProps extends ControlProps {
|
2021-03-15 12:17:56 +00:00
|
|
|
options: any[];
|
2021-05-06 14:06:41 +00:00
|
|
|
defaultValue?: string;
|
2019-11-05 05:09:50 +00:00
|
|
|
placeholderText: string;
|
|
|
|
|
propertyValue: string;
|
2021-03-24 08:53:39 +00:00
|
|
|
optionWidth?: string;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DropDownControl;
|