PromucFlow_constructor/app/client/src/components/designSystems/appsmith/Dropdown.tsx

84 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-10-21 15:12:45 +00:00
import React from "react";
import Select from "react-select";
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";
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
export type DropdownProps = {
2019-10-21 15:12:45 +00:00
options: Array<{
value: string;
label?: string;
2019-10-21 15:12:45 +00:00
}>;
input: WrappedFieldInputProps;
placeholder: string;
width?: number | string;
isSearchable?: boolean;
isDisabled?: boolean;
customSelectStyles?: any;
maxMenuHeight: number;
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",
}),
indicatorSeparator: () => ({}),
menu: (provided: any) => ({ ...provided, zIndex: 2 }),
menuPortal: (base: any) => ({ ...base, zIndex: 2 }),
2019-10-21 15:12:45 +00:00
};
export function BaseDropdown(props: DropdownProps) {
2021-05-24 09:09:43 +00:00
const layer = React.useContext(LayersContext);
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}
isDisabled={props.isDisabled}
isSearchable={props.isSearchable}
onChange={(value) => input.onChange(value)}
width={props.width}
{...props}
2019-10-21 15:12:45 +00:00
/>
);
}
2019-10-21 15:12:45 +00:00
function Dropdown(props: DropdownProps) {
2019-10-21 15:12:45 +00:00
return <BaseDropdown {...props} />;
}
2019-10-21 15:12:45 +00:00
export default Dropdown;