2019-09-18 10:19:50 +00:00
|
|
|
import React, { SyntheticEvent } from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
2019-09-24 12:11:32 +00:00
|
|
|
import { ControlType } from "../constants/PropertyControlConstants";
|
2019-09-18 10:19:50 +00:00
|
|
|
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";
|
|
|
|
|
import { ControlWrapper, StyledDropDown } from "./StyledControls";
|
2019-09-18 10:19:50 +00:00
|
|
|
|
|
|
|
|
class DropDownControl extends BaseControl<DropDownControlProps> {
|
|
|
|
|
constructor(props: DropDownControlProps) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.onItemSelect = this.onItemSelect.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 (
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
<ControlWrapper>
|
|
|
|
|
<label>{this.props.label}</label>
|
|
|
|
|
<StyledDropDown
|
|
|
|
|
items={this.props.options}
|
|
|
|
|
itemPredicate={this.filterOption}
|
|
|
|
|
itemRenderer={this.renderItem}
|
|
|
|
|
onItemSelect={this.onItemSelect}
|
|
|
|
|
noResults={<MenuItem disabled={true} text="No results." />}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
text={selected ? selected.label : ""}
|
|
|
|
|
rightIcon="chevron-down"
|
|
|
|
|
/>
|
|
|
|
|
</StyledDropDown>
|
|
|
|
|
</ControlWrapper>
|
2019-09-18 10:19:50 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onItemSelect(
|
|
|
|
|
item: DropdownOption,
|
|
|
|
|
event?: SyntheticEvent<HTMLElement>,
|
|
|
|
|
): void {
|
|
|
|
|
this.updateProperty(this.props.propertyName, item.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderItem(option: DropdownOption, itemProps: IItemRendererProps) {
|
|
|
|
|
if (!itemProps.modifiers.matchesPredicate) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<MenuItem
|
|
|
|
|
active={itemProps.modifiers.active}
|
|
|
|
|
key={option.value}
|
|
|
|
|
label={option.label}
|
|
|
|
|
onClick={itemProps.handleClick}
|
|
|
|
|
text={option.label}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filterOption(query: string, option: DropdownOption): boolean {
|
|
|
|
|
return (
|
|
|
|
|
option.label.toLowerCase().indexOf(query.toLowerCase()) >= 0 ||
|
|
|
|
|
option.value.toLowerCase().indexOf(query.toLowerCase()) >= 0
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "DROP_DOWN";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DropdownOption {
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DropDownControlProps extends ControlProps {
|
|
|
|
|
options: DropdownOption[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DropDownControl;
|