File size: 1,879 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
// @flow
import * as React from "react";
import { Icon } from "../";
import cn from "classnames";
import AvatarList from "./AvatarList.react";
import type { MouseEvents, PointerEvents } from "../../";
export type Props = {|
...MouseEvents,
...PointerEvents,
+children?: React.Node,
+className?: string,
/**
* The URL of the image to be displayed
*/
+imageURL?: string,
+style?: Object,
+size?: "sm" | "md" | "lg" | "xl" | "xxl",
/**
* Display a colored status dot with the avatar
*/
+status?: "grey" | "red" | "yellow" | "green",
/**
* Displays the user icon as a placeholder
*/
+placeholder?: boolean,
/**
* Render an icon instead of an imageURL
*/
+icon?: string,
/**
* The background and font color of the circle
*/
+color?: string,
|};
/**
* Renders a single circular avatar
*/
function Avatar({
className,
children,
imageURL,
style,
size = "",
status,
placeholder,
icon,
color = "",
onClick,
onMouseEnter,
onMouseLeave,
onPointerEnter,
onPointerLeave,
}: Props): React.Node {
const classes = cn(
{
avatar: true,
[`avatar-${size}`]: !!size,
"avatar-placeholder": placeholder,
[`avatar-${color}`]: !!color,
},
className
);
return (
<span
className={classes}
style={
imageURL
? Object.assign(
{
backgroundImage: `url(${imageURL})`,
},
style
)
: style
}
onClick={onClick}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onPointerEnter={onPointerEnter}
onPointerLeave={onPointerLeave}
>
{icon && <Icon name={icon} />}
{status && <span className={`avatar-status bg-${status}`} />}
{children}
</span>
);
}
Avatar.List = AvatarList;
export default Avatar;
|