2019-07-03 15:39:39 +00:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
|
|
|
export type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Color of the (initials based) avatar, if needed.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
color?: string;
|
2019-07-03 15:39:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initials to be used to render the initials based avatars.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
initials?: string;
|
2019-07-03 15:39:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to signal the failure of the loading of the URL.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onAvatarLoadError?: Function;
|
2019-07-03 15:39:39 +00:00
|
|
|
|
2021-12-17 00:16:24 +00:00
|
|
|
/**
|
|
|
|
* Additional parameters to be passed to onAvatarLoadError function.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onAvatarLoadErrorParams?: Object;
|
2021-12-17 00:16:24 +00:00
|
|
|
|
2019-07-03 15:39:39 +00:00
|
|
|
/**
|
|
|
|
* Expected size of the avatar.
|
|
|
|
*/
|
|
|
|
size?: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The URL of the avatar to render.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
url?: string | Function;
|
2019-07-03 15:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements an abstract stateless avatar component that renders an avatar purely from what gets passed through
|
|
|
|
* props.
|
|
|
|
*/
|
2022-08-26 09:54:03 +00:00
|
|
|
export default class AbstractStatelessAvatar<P extends Props> extends PureComponent<P> {
|
2019-07-04 08:31:23 +00:00
|
|
|
/**
|
2019-08-30 16:39:06 +00:00
|
|
|
* Checks if the passed prop is a loaded icon or not.
|
2019-07-04 08:31:23 +00:00
|
|
|
*
|
2019-08-30 16:39:06 +00:00
|
|
|
* @param {string? | Object?} iconProp - The prop to check.
|
|
|
|
* @returns {boolean}
|
2019-07-04 08:31:23 +00:00
|
|
|
*/
|
2022-08-26 09:54:03 +00:00
|
|
|
_isIcon(iconProp?: string | Function): iconProp is Function {
|
2019-09-20 13:47:53 +00:00
|
|
|
return Boolean(iconProp) && (typeof iconProp === 'object' || typeof iconProp === 'function');
|
2019-07-04 08:31:23 +00:00
|
|
|
}
|
|
|
|
}
|