SimplePicker.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React, { SFC } from 'react';
  2. import Select from 'react-select';
  3. import DescriptionOption from './DescriptionOption';
  4. import IndicatorsContainer from './IndicatorsContainer';
  5. import ResetStyles from './ResetStyles';
  6. interface Props {
  7. className?: string;
  8. defaultValue?: any;
  9. getOptionLabel: (item: any) => string;
  10. getOptionValue: (item: any) => string;
  11. onSelected: (item: any) => {} | void;
  12. options: any[];
  13. placeholder?: string;
  14. width?: number;
  15. value: any;
  16. }
  17. const SimplePicker: SFC<Props> = ({
  18. className,
  19. defaultValue,
  20. getOptionLabel,
  21. getOptionValue,
  22. onSelected,
  23. options,
  24. placeholder,
  25. width,
  26. value,
  27. }) => {
  28. return (
  29. <Select
  30. classNamePrefix="gf-form-select-box"
  31. className={`${width ? 'width-' + width : ''} gf-form-input gf-form-input--form-dropdown ${className || ''}`}
  32. components={{
  33. Option: DescriptionOption,
  34. IndicatorsContainer,
  35. }}
  36. defaultValue={defaultValue}
  37. value={value}
  38. getOptionLabel={getOptionLabel}
  39. getOptionValue={getOptionValue}
  40. menuShouldScrollIntoView={false}
  41. isSearchable={false}
  42. onChange={onSelected}
  43. options={options}
  44. placeholder={placeholder || 'Choose'}
  45. styles={ResetStyles}
  46. />
  47. );
  48. };
  49. export default SimplePicker;