You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractStatelessAvatar.tsx 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { PureComponent } from 'react';
  2. export type Props = {
  3. /**
  4. * Color of the (initials based) avatar, if needed.
  5. */
  6. color?: string;
  7. /**
  8. * Initials to be used to render the initials based avatars.
  9. */
  10. initials?: string;
  11. /**
  12. * Callback to signal the failure of the loading of the URL.
  13. */
  14. onAvatarLoadError?: Function;
  15. /**
  16. * Additional parameters to be passed to onAvatarLoadError function.
  17. */
  18. onAvatarLoadErrorParams?: Object;
  19. /**
  20. * Expected size of the avatar.
  21. */
  22. size?: number;
  23. /**
  24. * The URL of the avatar to render.
  25. */
  26. url?: string | Function;
  27. };
  28. /**
  29. * Implements an abstract stateless avatar component that renders an avatar purely from what gets passed through
  30. * props.
  31. */
  32. export default class AbstractStatelessAvatar<P extends Props> extends PureComponent<P> {
  33. /**
  34. * Checks if the passed prop is a loaded icon or not.
  35. *
  36. * @param {string? | Object?} iconProp - The prop to check.
  37. * @returns {boolean}
  38. */
  39. _isIcon(iconProp?: string | Function): iconProp is Function {
  40. return Boolean(iconProp) && (typeof iconProp === 'object' || typeof iconProp === 'function');
  41. }
  42. }