PromucFlow_constructor/app/client/src/components/canvas/CreatableDropdown.tsx

47 lines
952 B
TypeScript
Raw Normal View History

2019-10-21 15:12:45 +00:00
import React from "react";
import Creatable from "react-select/creatable";
import { WrappedFieldInputProps } from "redux-form";
2019-10-21 15:12:45 +00:00
type DropdownProps = {
options: Array<{
value: string;
label: string;
}>;
placeholder: string;
isLoading?: boolean;
input: WrappedFieldInputProps;
onCreateOption: (inputValue: string) => void;
2019-10-21 15:12:45 +00:00
};
const selectStyles = {
container: (styles: any) => ({
...styles,
flex: 1,
}),
};
class CreatableDropdown extends React.Component<DropdownProps> {
render() {
const {
placeholder,
options,
isLoading,
onCreateOption,
input,
} = this.props;
2019-10-21 15:12:45 +00:00
return (
<Creatable
placeholder={placeholder}
options={options}
2019-10-21 15:12:45 +00:00
styles={selectStyles}
isLoading={isLoading}
onCreateOption={onCreateOption}
{...input}
onChange={value => input.onChange(value)}
2019-10-21 15:12:45 +00:00
/>
);
}
}
export default CreatableDropdown;