Avatar displays a user's picture. This helps aid easy recognition of the user. This kit is normally not used by itself, but rather used within other kits.
The only time Avatar should be used instead of the User kit is when you are not going to display the user's name.
import React from 'react' import { Avatar } from 'playbook-ui' const AvatarDefault = (props) => { return ( <div> <Avatar imageAlt="Terry Johnson Standing" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="xxs" status="online" /> <br /> <Avatar imageAlt="Terry Johnson Standing" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="xs" status="online" /> <br /> <Avatar imageAlt="Terry Johnson Standing" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="sm" status="online" /> <br /> <Avatar imageAlt="Terry Johnson Standing" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="md" status="away" /> <br /> <Avatar imageAlt="Terry Johnson Standing" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="lg" status="offline" /> <br /> <Avatar imageAlt="Terry Johnson Standing" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="xl" status="offline" /> </div> ) } export default AvatarDefault
This is used when there is no avatar for a particular user.
import React from 'react' import { Avatar } from 'playbook-ui' const AvatarDefault = (props) => { return ( <div> <Avatar name="Terry Johnson" size="xxs" /> <Avatar name="Terry Johnson" size="xs" /> <Avatar name="Terry Johnson" size="sm" /> <Avatar name="Terry Johnson" size="md" /> <Avatar name="Terry Johnson" size="lg" /> <Avatar name="Terry Johnson" size="xl" /> </div> ) } export default AvatarDefault
A monagram is used as a fallback when an invalid or missing image url is provided.
import React from 'react' import { Avatar } from 'playbook-ui' const AvatarNoImage = (props) => { return ( <div> <Avatar imageUrl="Just some text here" name="Terry Johnson" size="xxs" /> <Avatar imageUrl="Just some text here" name="Terry Johnson" size="xs" /> <Avatar imageUrl={4} name="Terry Johnson" size="sm" /> <Avatar imageUrl="https://google.com" name="Terry Johnson" size="md" /> <Avatar imageUrl="" name="Terry Johnson" size="lg" /> <Avatar imageUrl="https://randomuser.me/api/portraits/men/notapicture.jpg" name="Terry Johnson" size="xl" /> </div> ) } export default AvatarNoImage
The Status prop is used to display a user's online status like popular chat apps.
import React from 'react' import { Avatar } from 'playbook-ui' const AvatarStatus = (props) => { return ( <> <Avatar imageAlt="Terry Johnson Status" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="sm" /> <br /> <Avatar imageAlt="Terry Johnson Online" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="sm" status="online" /> <br /> <Avatar imageAlt="Terry Johnson Away" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="sm" status="away" /> <br /> <Avatar imageAlt="Terry Johnson Offline" imageUrl="https://randomuser.me/api/portraits/men/44.jpg" name="Terry Johnson" size="sm" status="offline" /> <br /> </> ) } export default AvatarStatus
NOTE: All componentOverlay
implementations require a placement
prop, that accepts any of the following values: top-right
, top-left
, bottom-right
, bottom-left
, top-center
, bottom-center
, left-center
, and right-center
.
When passing the iconCircle
component as an overlay, you must also specify an icon
, and you may optionally control the color by passing an approved value as a variant
.
import React from "react"; import { Avatar } from 'playbook-ui' const AvatarCircleIconComponentOverlay = () => { return ( <div> <Avatar componentOverlay={{ component: "iconCircle", placement: "bottom-right", icon: "shield", variant: "royal" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="sm" /> <Avatar componentOverlay={{ component: "iconCircle", placement: "bottom-right", icon: "check", variant: "green" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="md" /> <Avatar componentOverlay={{ component: "iconCircle", placement: "top-left", icon: "lock", variant: "red" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="lg" /> <Avatar componentOverlay={{ component: "iconCircle", placement: "left-center", icon: "star", variant: "yellow" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="xl" /> </div> ) } export default AvatarCircleIconComponentOverlay
NOTE: All componentOverlay
implementations require a placement
prop, that accepts any of the following values: top-right
, top-left
, bottom-right
, bottom-left
, top-center
, bottom-center
, left-center
, and right-center
.
When passing the badge
component as an overlay, you must also specify its text content,and you may optionally control the color by passing an approved value as a variant
.
import React from "react"; import { Avatar } from 'playbook-ui' const AvatarBadgeComponentOverlay = () => { return ( <div> <Avatar componentOverlay={{ component: "badge", placement: "bottom-right", text: "12" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="sm" /> <Avatar componentOverlay={{ component: "badge", placement: "top-left", text: "12" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="md" /> <Avatar componentOverlay={{ component: "badge", placement: "top-center", text: "On Roadtip", variant: "info" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="lg" /> <Avatar componentOverlay={{ component: "badge", placement: "bottom-center", text: "Out of Office", variant: "error" }} imageUrl="https://randomuser.me/api/portraits/men/44.jpg" marginBottom="sm" size="xl" /> </div> ) } export default AvatarBadgeComponentOverlay
Avoid using Avatar with the user's name right next to it or under it. Use User kit instead. Do not use this kit for images that are not profile pictures.