2020-04-28 06:52:53 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { MenuItem } from "@blueprintjs/core";
|
|
|
|
|
import { IItemRendererProps } from "@blueprintjs/select";
|
|
|
|
|
import DropdownField from "components/editorComponents/form/fields/DropdownField";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { DropdownOption } from "components/constants";
|
2020-04-28 06:52:53 +00:00
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
|
|
|
|
import { theme } from "constants/DefaultTheme";
|
2020-08-05 08:02:24 +00:00
|
|
|
import FormLabel from "components/editorComponents/FormLabel";
|
2021-02-26 06:58:47 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
const DropdownSelect = styled.div`
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
width: 50vh;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-02-26 06:58:47 +00:00
|
|
|
const StyledInfo = styled.span`
|
|
|
|
|
font-weight: normal;
|
|
|
|
|
line-height: normal;
|
|
|
|
|
color: ${Colors.DOVE_GRAY};
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
margin-left: 1px;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-04-28 06:52:53 +00:00
|
|
|
const customSelectStyles = {
|
|
|
|
|
option: (
|
|
|
|
|
styles: { [x: string]: any },
|
2020-11-19 03:32:58 +00:00
|
|
|
{ isDisabled, isFocused, isSelected }: any,
|
2020-04-28 06:52:53 +00:00
|
|
|
) => {
|
|
|
|
|
return {
|
|
|
|
|
...styles,
|
2021-10-04 15:34:37 +00:00
|
|
|
color: Colors.CODE_GRAY,
|
2020-04-28 06:52:53 +00:00
|
|
|
backgroundColor: isDisabled
|
|
|
|
|
? undefined
|
|
|
|
|
: isSelected
|
2021-10-04 15:34:37 +00:00
|
|
|
? Colors.GREY_3
|
2020-04-28 06:52:53 +00:00
|
|
|
: isFocused
|
2021-10-04 15:34:37 +00:00
|
|
|
? Colors.GREY_2
|
2020-04-28 06:52:53 +00:00
|
|
|
: undefined,
|
|
|
|
|
":active": {
|
|
|
|
|
...styles[":active"],
|
|
|
|
|
backgroundColor:
|
|
|
|
|
!isDisabled &&
|
2020-08-10 04:54:33 +00:00
|
|
|
(isSelected ? theme.colors.primaryOld : theme.colors.hover),
|
2020-04-28 06:52:53 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DropDownControl extends BaseControl<DropDownControlProps> {
|
|
|
|
|
render() {
|
2021-11-10 13:45:47 +00:00
|
|
|
const {
|
|
|
|
|
configProperty,
|
|
|
|
|
customStyles,
|
|
|
|
|
isDisabled,
|
|
|
|
|
isRequired,
|
|
|
|
|
isSearchable,
|
|
|
|
|
label,
|
|
|
|
|
options,
|
|
|
|
|
subtitle,
|
|
|
|
|
} = this.props;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
2021-11-10 13:45:47 +00:00
|
|
|
let width = "50vh";
|
|
|
|
|
if (customStyles && customStyles.width) {
|
|
|
|
|
width = customStyles.width;
|
|
|
|
|
}
|
2020-04-28 06:52:53 +00:00
|
|
|
return (
|
2020-08-05 08:02:24 +00:00
|
|
|
<div>
|
|
|
|
|
<FormLabel>
|
|
|
|
|
{label} {isRequired && "*"}
|
2021-02-26 06:58:47 +00:00
|
|
|
{subtitle && (
|
|
|
|
|
<>
|
|
|
|
|
<br />
|
|
|
|
|
<StyledInfo>{subtitle}</StyledInfo>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2020-08-05 08:02:24 +00:00
|
|
|
</FormLabel>
|
2021-11-10 13:45:47 +00:00
|
|
|
<DropdownSelect data-cy={configProperty} style={{ width }}>
|
2020-08-05 08:02:24 +00:00
|
|
|
<DropdownField
|
2021-04-28 10:28:39 +00:00
|
|
|
customSelectStyles={customSelectStyles}
|
2021-11-10 13:45:47 +00:00
|
|
|
isDisabled={isDisabled}
|
|
|
|
|
isSearchable={isSearchable}
|
2020-08-05 08:02:24 +00:00
|
|
|
name={configProperty}
|
|
|
|
|
options={options}
|
2021-04-28 10:28:39 +00:00
|
|
|
placeholder=""
|
2021-11-10 13:45:47 +00:00
|
|
|
width={width}
|
2020-08-05 08:02:24 +00:00
|
|
|
/>
|
|
|
|
|
</DropdownSelect>
|
|
|
|
|
</div>
|
2020-04-28 06:52:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderItem = (option: DropdownOption, itemProps: IItemRendererProps) => {
|
|
|
|
|
if (!itemProps.modifiers.matchesPredicate) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const isSelected: boolean = this.isOptionSelected(option);
|
|
|
|
|
return (
|
|
|
|
|
<MenuItem
|
|
|
|
|
active={isSelected}
|
2021-04-28 10:28:39 +00:00
|
|
|
className="single-select"
|
2020-04-28 06:52:53 +00:00
|
|
|
key={option.value}
|
|
|
|
|
onClick={itemProps.handleClick}
|
|
|
|
|
text={option.label}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isOptionSelected = (selectedOption: DropdownOption) => {
|
|
|
|
|
return selectedOption.value === this.props.propertyValue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "DROP_DOWN";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DropDownControlProps extends ControlProps {
|
|
|
|
|
options: DropdownOption[];
|
|
|
|
|
placeholderText: string;
|
|
|
|
|
propertyValue: string;
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle?: string;
|
2021-11-10 13:45:47 +00:00
|
|
|
isDisabled?: boolean;
|
|
|
|
|
isSearchable?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DropDownControl;
|