SimplePicker.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. value: any;
  15. }
  16. const SimplePicker: SFC<Props> = ({
  17. className,
  18. defaultValue,
  19. getOptionLabel,
  20. getOptionValue,
  21. onSelected,
  22. options,
  23. placeholder,
  24. width,
  25. value,
  26. }) => {
  27. return (
  28. <Select
  29. classNamePrefix={`gf-form-select-box`}
  30. className={`width-${width} gf-form-input gf-form-input--form-dropdown ${className || ''}`}
  31. components={{
  32. Option: DescriptionOption,
  33. }}
  34. defaultValue={defaultValue}
  35. value={value}
  36. getOptionLabel={getOptionLabel}
  37. getOptionValue={getOptionValue}
  38. isSearchable={false}
  39. onChange={onSelected}
  40. options={options}
  41. placeholder={placeholder || 'Choose'}
  42. styles={ResetStyles}
  43. />
  44. );
  45. };
  46. export default SimplePicker;