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";
|
2021-02-16 10:29:08 +00:00
|
|
|
import {
|
|
|
|
|
StyledDropDown,
|
|
|
|
|
StyledDropDownContainer,
|
|
|
|
|
DropdownStyles,
|
|
|
|
|
} from "./StyledControls";
|
|
|
|
|
import { ControlIcons, ControlIconName } from "icons/ControlIcons";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { DropdownOption } from "widgets/DropdownWidget";
|
2021-02-16 10:29:08 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
|
|
const MenuItemWrapper = styled(MenuItem)`
|
|
|
|
|
z-index: 2;
|
|
|
|
|
&&&& span {
|
|
|
|
|
width: auto;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
color: #2e3d49;
|
|
|
|
|
}
|
|
|
|
|
&&&& div:first-child {
|
|
|
|
|
flex: none;
|
|
|
|
|
}
|
|
|
|
|
`;
|
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(
|
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-02-16 10:29:08 +00:00
|
|
|
const controlIconName: ControlIconName =
|
|
|
|
|
selected && selected.icon ? selected.icon : -1;
|
|
|
|
|
const ControlIcon =
|
|
|
|
|
controlIconName !== -1 ? ControlIcons[controlIconName] : null;
|
2019-09-18 10:19:50 +00:00
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledDropDownContainer>
|
2021-02-16 10:29:08 +00:00
|
|
|
<DropdownStyles />
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledDropDown
|
|
|
|
|
items={this.props.options}
|
|
|
|
|
filterable={false}
|
|
|
|
|
itemRenderer={this.renderItem}
|
|
|
|
|
onItemSelect={this.onItemSelect}
|
|
|
|
|
noResults={<MenuItem disabled={true} text="No results." />}
|
|
|
|
|
popoverProps={{
|
|
|
|
|
minimal: true,
|
2021-02-16 10:29:08 +00:00
|
|
|
usePortal: true,
|
|
|
|
|
popoverClassName: "select-popover-wrapper",
|
2020-02-26 12:44:56 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
2021-02-16 10:29:08 +00:00
|
|
|
icon={
|
|
|
|
|
selected && selected.icon && ControlIcon ? (
|
|
|
|
|
<ControlIcon width={24} height={24} />
|
|
|
|
|
) : null
|
|
|
|
|
}
|
|
|
|
|
text={selected ? selected.label : "No Selection"}
|
2020-02-26 12:44:56 +00:00
|
|
|
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);
|
2021-02-16 10:29:08 +00:00
|
|
|
const controlIconName: ControlIconName = option.icon ? option.icon : -1;
|
|
|
|
|
const ControlIcon =
|
|
|
|
|
controlIconName !== -1 ? ControlIcons[controlIconName] : null;
|
2019-09-18 10:19:50 +00:00
|
|
|
return (
|
2021-02-16 10:29:08 +00:00
|
|
|
<MenuItemWrapper
|
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}
|
2021-02-16 10:29:08 +00:00
|
|
|
label={option.subText ? option.subText : undefined}
|
|
|
|
|
icon={
|
|
|
|
|
option.icon && ControlIcon ? (
|
|
|
|
|
<ControlIcon width={24} height={24} />
|
|
|
|
|
) : (
|
|
|
|
|
undefined
|
|
|
|
|
)
|
|
|
|
|
}
|
2019-09-18 10:19:50 +00:00
|
|
|
/>
|
|
|
|
|
);
|
2021-02-16 10:29:08 +00:00
|
|
|
// label={option.subText ? option.subText : undefined}
|
|
|
|
|
// icon={option.icon && ControlIcon ? <ControlIcon /> : undefined}
|
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;
|