SimplePicker.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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-' + 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. menuShouldScrollIntoView={false}
  39. isSearchable={false}
  40. onChange={onSelected}
  41. options={options}
  42. placeholder={placeholder || 'Choose'}
  43. styles={ResetStyles}
  44. />
  45. );
  46. };
  47. export default SimplePicker;