PickerOption.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import React from 'react';
  2. import { components } from '@torkelo/react-select';
  3. import { OptionProps } from 'react-select/lib/components/Option';
  4. // https://github.com/JedWatson/react-select/issues/3038
  5. interface ExtendedOptionProps extends OptionProps<any> {
  6. data: {
  7. description?: string;
  8. imgUrl?: string;
  9. };
  10. }
  11. export const Option = (props: ExtendedOptionProps) => {
  12. const { children, isSelected, data } = props;
  13. return (
  14. <components.Option {...props}>
  15. <div className="gf-form-select-box__desc-option">
  16. {data.imgUrl && <img className="gf-form-select-box__desc-option__img" src={data.imgUrl} />}
  17. <div className="gf-form-select-box__desc-option__body">
  18. <div>{children}</div>
  19. {data.description && <div className="gf-form-select-box__desc-option__desc">{data.description}</div>}
  20. </div>
  21. {isSelected && <i className="fa fa-check" aria-hidden="true" />}
  22. </div>
  23. </components.Option>
  24. );
  25. };
  26. // was not able to type this without typescript error
  27. export const SingleValue = props => {
  28. const { children, data } = props;
  29. return (
  30. <components.SingleValue {...props}>
  31. <div className="gf-form-select-box__img-value">
  32. {data.imgUrl && <img className="gf-form-select-box__desc-option__img" src={data.imgUrl} />}
  33. {children}
  34. </div>
  35. </components.SingleValue>
  36. );
  37. };
  38. export default Option;