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";
|
|
|
|
|
import { Button, MenuItem } from "@blueprintjs/core";
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
import { IItemRendererProps } from "@blueprintjs/select";
|
2020-02-26 12:44:56 +00:00
|
|
|
import { StyledDropDown, StyledDropDownContainer } from "./StyledControls";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { DropdownOption } from "widgets/DropdownWidget";
|
2019-09-18 10:19:50 +00:00
|
|
|
|
|
|
|
|
class DropDownControl extends BaseControl<DropDownControlProps> {
|
|
|
|
|
render() {
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
const selected: DropdownOption | undefined = this.props.options.find(
|
|
|
|
|
option => option.value === this.props.propertyValue,
|
|
|
|
|
);
|
2019-09-18 10:19:50 +00:00
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledDropDownContainer>
|
|
|
|
|
<StyledDropDown
|
|
|
|
|
items={this.props.options}
|
|
|
|
|
filterable={false}
|
|
|
|
|
itemRenderer={this.renderItem}
|
|
|
|
|
onItemSelect={this.onItemSelect}
|
|
|
|
|
noResults={<MenuItem disabled={true} text="No results." />}
|
|
|
|
|
popoverProps={{
|
|
|
|
|
minimal: true,
|
|
|
|
|
usePortal: false,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
text={selected ? selected.label : ""}
|
|
|
|
|
rightIcon="chevron-down"
|
|
|
|
|
/>
|
|
|
|
|
</StyledDropDown>
|
|
|
|
|
</StyledDropDownContainer>
|
2019-09-18 10:19:50 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 05:09:50 +00:00
|
|
|
onItemSelect = (item: DropdownOption): void => {
|
2019-09-18 10:19:50 +00:00
|
|
|
this.updateProperty(this.props.propertyName, item.value);
|
2019-10-31 05:28:11 +00:00
|
|
|
};
|
2019-09-18 10:19:50 +00:00
|
|
|
|
2019-10-31 05:28:11 +00:00
|
|
|
renderItem = (option: DropdownOption, itemProps: IItemRendererProps) => {
|
2019-09-18 10:19:50 +00:00
|
|
|
if (!itemProps.modifiers.matchesPredicate) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-11-05 05:09:50 +00:00
|
|
|
const isSelected: boolean = this.isOptionSelected(option);
|
2019-09-18 10:19:50 +00:00
|
|
|
return (
|
|
|
|
|
<MenuItem
|
2020-02-18 10:41:52 +00:00
|
|
|
className="single-select"
|
|
|
|
|
active={isSelected}
|
2019-09-18 10:19:50 +00:00
|
|
|
key={option.value}
|
|
|
|
|
onClick={itemProps.handleClick}
|
|
|
|
|
text={option.label}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2019-10-31 05:28:11 +00:00
|
|
|
};
|
2019-09-18 10:19:50 +00:00
|
|
|
|
2019-11-05 05:09:50 +00:00
|
|
|
isOptionSelected = (selectedOption: DropdownOption) => {
|
|
|
|
|
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 {
|
|
|
|
|
options: DropdownOption[];
|
2019-11-05 05:09:50 +00:00
|
|
|
placeholderText: string;
|
|
|
|
|
propertyValue: string;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DropDownControl;
|