Skip to content

Commit

Permalink
feat: creatable select
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Jan 30, 2019
1 parent 84b98be commit 24bdbb4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { ReactEventHandler } from 'react';
import ReactSelect from 'react-select';
import ReactAsyncSelect, { Props as AsyncProps } from 'react-select/lib/Async'; // we can live with it, as it adds very little overhead (just a wrapper around Select)
import ReactCreatableSelect, { Props as CreatableProps } from 'react-select/lib/Creatable';
import { Props } from 'react-select/lib/Select';

import { Omit } from '@stoplight/types';
Expand Down Expand Up @@ -35,13 +36,17 @@ export interface ISelectBaseProps {

export interface ISelectProps
extends ISelectBaseProps,
Omit<Omit<Props<ISelectOption>, 'noOptionsMessage'>, 'loadingMessage'> {} // pipe doesn't work for some reason
Omit<Props<ISelectOption>, 'noOptionsMessage' | 'loadingMessage'> {}

export interface ISelectAsyncProps
extends ISelectBaseProps,
Omit<Omit<AsyncProps<ISelectOption>, 'noOptionsMessage'>, 'loadingMessage'> {} // pipe doesn't work for some reason
Omit<AsyncProps<ISelectOption>, 'noOptionsMessage' | 'loadingMessage'> {}

export type ISelect = ISelectProps | ISelectAsyncProps;
export interface ISelectCreatableProps
extends ISelectBaseProps,
Omit<CreatableProps<ISelectOption>, 'noOptionsMessage' | 'loadingMessage'> {}

export type ISelect = ISelectProps | ISelectAsyncProps | ISelectCreatableProps;

export interface ISelectOption {
label: string;
Expand Down Expand Up @@ -97,10 +102,14 @@ export const Select: React.FunctionComponent<ISelect> = props => {
styles: customStyles(),
};

if ('loadOptions' in props || 'defaultOptions' in props) {
if ('loadOptions' in props) {
return <ReactAsyncSelect {...actualProps} />;
}

if ('onCreateOption' in props) {
return <ReactCreatableSelect {...actualProps} />;
}

return <ReactSelect {...actualProps} />;
};

Expand Down

0 comments on commit 24bdbb4

Please sign in to comment.