SimplePicker.tsx 1.1 KB

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