PickerOption.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from 'react';
  2. import { components } from '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. export const SingleValue = (props: ExtendedOptionProps) => {
  27. const { children, data } = props;
  28. return (
  29. <components.SingleValue {...props}>
  30. <div className="gf-form-select-box__img-value">
  31. {data.imgUrl && <img className="gf-form-select-box__desc-option__img" src={data.imgUrl} />}
  32. {children}
  33. </div>
  34. </components.SingleValue>
  35. );
  36. };
  37. export default Option;