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

94 lines
2.3 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";
import { SelectComponentsConfig } from "react-select/src/components";
import { LayersContext } from "constants/Layers";
import { Colors } from "constants/Colors";
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,
minHeight: "36px",
2019-11-14 09:01:23 +00:00
border: state.isFocused
? `var(--appsmith-input-focus-border-color) solid 1px`
: `${Colors.ALTO2} solid 1px`,
2019-11-14 09:01:23 +00:00
boxShadow: state.isFocused ? 0 : 0,
padding: "1px 3px 1px",
"border-radius": "0px",
2019-11-14 09:01:23 +00:00
"&:hover": {
background: "#FAFAFA",
2019-11-14 09:01:23 +00:00
},
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,
backgroundColor: Colors.GREY_1,
borderRadius: 0,
}),
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, placeholder } = 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}
2021-12-07 09:45:18 +00:00
classNamePrefix="appsmith-select"
2021-09-02 08:33:10 +00:00
menuPlacement="auto"
placeholder={placeholder}
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;