2019-10-21 15:12:45 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import Select from "react-select";
|
2019-12-23 12:16:33 +00:00
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
import { WrappedFieldInputProps } from "redux-form";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { theme } from "constants/DefaultTheme";
|
2020-05-14 07:27:00 +00:00
|
|
|
import { SelectComponentsConfig } from "react-select/src/components";
|
2021-05-24 09:09:43 +00:00
|
|
|
import { LayersContext } from "../../../constants/Layers";
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2020-04-28 06:52:53 +00:00
|
|
|
export type DropdownProps = {
|
2019-10-21 15:12:45 +00:00
|
|
|
options: Array<{
|
|
|
|
|
value: string;
|
2021-02-11 12:54:00 +00:00
|
|
|
label?: string;
|
2019-10-21 15:12:45 +00:00
|
|
|
}>;
|
|
|
|
|
input: WrappedFieldInputProps;
|
2019-10-25 05:35:20 +00:00
|
|
|
placeholder: string;
|
2020-04-28 06:52:53 +00:00
|
|
|
width?: number | string;
|
2020-04-14 12:34:14 +00:00
|
|
|
isSearchable?: boolean;
|
|
|
|
|
isDisabled?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
customSelectStyles?: any;
|
|
|
|
|
maxMenuHeight: number;
|
2020-05-14 07:27:00 +00:00
|
|
|
components?: SelectComponentsConfig<any>;
|
2019-10-21 15:12:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const selectStyles = {
|
2020-01-02 13:36:35 +00:00
|
|
|
placeholder: (provided: any) => ({
|
|
|
|
|
...provided,
|
|
|
|
|
color: "#a3b3bf",
|
|
|
|
|
}),
|
2019-11-14 09:01:23 +00:00
|
|
|
control: (styles: any, state: any) => ({
|
2019-10-21 15:12:45 +00:00
|
|
|
...styles,
|
2020-02-07 02:32:52 +00:00
|
|
|
width: state.selectProps.width || 100,
|
2019-11-13 11:34:11 +00:00
|
|
|
minHeight: "32px",
|
2019-11-14 09:01:23 +00:00
|
|
|
border: state.isFocused
|
|
|
|
|
? `${theme.colors.secondary} solid 1px`
|
|
|
|
|
: `${theme.colors.inputInactiveBorders} solid 1px`,
|
|
|
|
|
boxShadow: state.isFocused ? 0 : 0,
|
|
|
|
|
"&:hover": {
|
|
|
|
|
border: `${theme.colors.secondary} solid 1px`,
|
|
|
|
|
},
|
2019-10-21 15:12:45 +00:00
|
|
|
}),
|
2019-11-13 11:34:11 +00:00
|
|
|
indicatorsContainer: (provided: any) => ({
|
|
|
|
|
...provided,
|
|
|
|
|
height: "30px",
|
|
|
|
|
}),
|
|
|
|
|
clearIndicator: (provided: any) => ({
|
|
|
|
|
...provided,
|
|
|
|
|
padding: "5px",
|
|
|
|
|
}),
|
|
|
|
|
dropdownIndicator: (provided: any) => ({
|
|
|
|
|
...provided,
|
|
|
|
|
padding: "5px",
|
|
|
|
|
}),
|
2020-04-28 06:52:53 +00:00
|
|
|
indicatorSeparator: () => ({}),
|
2021-06-04 05:39:31 +00:00
|
|
|
menu: (provided: any) => ({ ...provided, zIndex: 2 }),
|
|
|
|
|
menuPortal: (base: any) => ({ ...base, zIndex: 2 }),
|
2019-10-21 15:12:45 +00:00
|
|
|
};
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function BaseDropdown(props: DropdownProps) {
|
2021-05-24 09:09:43 +00:00
|
|
|
const layer = React.useContext(LayersContext);
|
2021-05-13 08:35:39 +00:00
|
|
|
const { customSelectStyles, input } = props;
|
2021-05-24 09:09:43 +00:00
|
|
|
const menuPortalStyle = {
|
|
|
|
|
menuPortal: (styles: any) => ({ ...styles, zIndex: layer.max }),
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
return (
|
|
|
|
|
<Select
|
2021-05-07 07:35:00 +00:00
|
|
|
menuPortalTarget={document.body}
|
2021-05-24 09:09:43 +00:00
|
|
|
styles={{ ...selectStyles, ...customSelectStyles, ...menuPortalStyle }}
|
2019-10-21 15:12:45 +00:00
|
|
|
{...input}
|
2020-04-14 12:34:14 +00:00
|
|
|
isDisabled={props.isDisabled}
|
2021-04-28 10:28:39 +00:00
|
|
|
isSearchable={props.isSearchable}
|
|
|
|
|
onChange={(value) => input.onChange(value)}
|
|
|
|
|
width={props.width}
|
2020-04-28 06:52:53 +00:00
|
|
|
{...props}
|
2019-10-21 15:12:45 +00:00
|
|
|
/>
|
|
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
function Dropdown(props: DropdownProps) {
|
2019-10-21 15:12:45 +00:00
|
|
|
return <BaseDropdown {...props} />;
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
|
|
|
|
|
export default Dropdown;
|