2019-10-21 15:12:45 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import Creatable from "react-select/creatable";
|
2019-10-22 14:59:58 +00:00
|
|
|
import { WrappedFieldInputProps } from "redux-form";
|
2019-10-21 15:12:45 +00:00
|
|
|
|
|
|
|
|
type DropdownProps = {
|
|
|
|
|
options: Array<{
|
|
|
|
|
value: string;
|
|
|
|
|
label: string;
|
|
|
|
|
}>;
|
|
|
|
|
placeholder: string;
|
2019-10-22 14:59:58 +00:00
|
|
|
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() {
|
2019-10-22 14:59:58 +00:00
|
|
|
const {
|
|
|
|
|
placeholder,
|
|
|
|
|
options,
|
|
|
|
|
isLoading,
|
|
|
|
|
onCreateOption,
|
|
|
|
|
input,
|
|
|
|
|
} = this.props;
|
2019-10-21 15:12:45 +00:00
|
|
|
return (
|
|
|
|
|
<Creatable
|
2019-10-22 14:59:58 +00:00
|
|
|
placeholder={placeholder}
|
|
|
|
|
options={options}
|
2019-10-21 15:12:45 +00:00
|
|
|
styles={selectStyles}
|
2019-10-22 14:59:58 +00:00
|
|
|
isLoading={isLoading}
|
|
|
|
|
onCreateOption={onCreateOption}
|
|
|
|
|
{...input}
|
|
|
|
|
onChange={value => input.onChange(value)}
|
2019-10-21 15:12:45 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default CreatableDropdown;
|