SelectOption.tsx 1.5 KB

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