Avatar
An avatar is a thumbnail representation of an entity, such as a user or an organization.
import {QAvatar} from "@qui/react"
Overview
By default, the Avatar renders as a clickable button
element. It is recommended that you supply a descriptive aria-label
to each element. You can change the root element using the as prop.
Examples
Variants
Use the variant property to alter the look and feel. When variant is set to text
, supply content to set the content. Only the first two characters will apply.
TextIconImage
import {ReactNode} from "react"import {User} from "lucide-react"import {QAvatar} from "@qui/react"export default function Variants(): ReactNode {return (<div className="grid justify-center"><div className="grid grid-cols-3 gap-x-8 gap-y-4"><span className="text-primary q-font-heading-xs">Text</span><span className="text-primary q-font-heading-xs">Icon</span><span className="text-primary q-font-heading-xs">Image</span><QAvatararia-label="Profile"color="brand"content="QC"variant="text"/><QAvatararia-label="Profile"color="purple"icon={User}variant="icon"/><QAvatararia-label="Profile"imgAlt="SH"imgSrc="/images/shashi.png"variant="image"/></div></div>)}
Shapes
Use the shape property to change the shape of the avatar to square
. The default is round
.
RoundSquare
import {ReactNode} from "react"import {Smartphone} from "lucide-react"import {QAvatar} from "@qui/react"export default function Shapes(): ReactNode {return (<div className="grid justify-center"><div className="grid grid-cols-2 gap-x-8 gap-y-4"><span className="text-primary q-font-heading-xs">Round</span><span className="text-primary q-font-heading-xs">Square</span><QAvatararia-label="Smartphone"color="magenta"icon={Smartphone}shape="round"size="l"variant="icon"/><QAvatararia-label="Smartphone"color="magenta"icon={Smartphone}shape="square"size="l"variant="icon"/></div></div>)}
States
Use the disabled property to show that an avatar exist, but is not available or active.
TextIconImageEnabledDisabled
import {ReactNode} from "react"import {Wifi} from "lucide-react"import {QAvatar} from "@qui/react"export default function States(): ReactNode {return (<div className="grid justify-center"><div className="grid grid-cols-4 grid-rows-3 items-center gap-x-8 gap-y-4"><div></div><span className="text-primary q-font-heading-xs">Text</span><span className="text-primary q-font-heading-xs">Icon</span><span className="text-primary q-font-heading-xs">Image</span><span className="text-primary q-font-heading-xs">Enabled</span><QAvatararia-label="Profile"color="blue"content="QC"onClick={() => alert("click is enabled!")}shape="round"size="l"variant="text"/><QAvatararia-label="Wifi"color="purple"icon={Wifi}onClick={() => alert("click is enabled!")}shape="round"size="l"variant="icon"/><QAvatararia-label="Profile"imgAlt="Shashi"imgSrc="/images/shashi.png"onClick={() => alert("click is enabled!")}shape="round"size="l"variant="image"/><span className="text-primary q-font-heading-xs">Disabled</span><QAvatararia-label="Profile"color="blue"content="QC"disabledonClick={() => alert("click should not be enabled!")}shape="round"size="l"variant="text"/><QAvatararia-label="Profile"color="purple"disabledicon={Wifi}onClick={() => alert("click should not be enabled!")}shape="round"size="l"variant="icon"/><QAvatararia-label="Profile"disabledimgAlt="Shashi"imgSrc="/images/shashi.png"onClick={() => alert("click should not be enabled!")}shape="round"size="l"variant="image"/></div></div>)}
Colors
Use the color property to set the color of avatar.
brandredorangeyellowkiwigreentealbluepurplefuchsiamagentaneutral
import {Fragment, ReactNode} from "react"import {Monitor, User} from "lucide-react"import {QAvatar} from "@qui/react"import colors from "./avatar-colors"export default function Colors(): ReactNode {return (<div className="grid justify-center"><div className="grid grid-cols-4 grid-rows-3 items-center gap-x-8 gap-y-4">{colors.map((color) => {return (<Fragment key={color}><span className="text-primary q-font-heading-xs">{color}</span><QAvatararia-label="Profile"color={color}icon={User}shape="round"size="l"variant="icon"/><QAvatararia-label="Monitor"color={color}icon={Monitor}shape="square"size="l"variant="icon"/><QAvatararia-label="Profile"color={color}content="QC"shape="round"size="l"variant="text"/></Fragment>)})}</div></div>)}
Emphasis
Use the emphasis property to set subtle
or strong
style. Defaults to subtle
.
SubtleStrongbrandredorangeyellowkiwigreentealbluepurplefuchsiamagentaneutral
import {Fragment, ReactNode} from "react"import {User} from "lucide-react"import {QAvatar} from "@qui/react"import colors from "./avatar-colors"export default function Variants(): ReactNode {return (<div className="grid justify-center"><div className="grid grid-cols-3 items-center gap-x-8 gap-y-4"><div></div><span className="text-primary q-font-heading-xs">Subtle</span><span className="text-primary q-font-heading-xs">Strong</span>{colors.map((color) => {return (<Fragment key={color}><span className="text-primary q-font-heading-xs">{color}</span><QAvatararia-label="Profile"color={color}icon={User}shape="round"size="l"variant="icon"/><QAvatararia-label="Profile"color={color}emphasis="strong"icon={User}shape="round"size="l"variant="icon"/></Fragment>)})}</div></div>)}
Sizes
Use the size property to set size of the avatar. There are five available values: xs
, s
, m
, l
, xl
. Should you need more control over the rendered size, supply a number instead which will be converted to pixels. Use iconSize and fontSize to separately control the size of icon and text respectively.
import {ReactNode} from "react"import {User} from "lucide-react"import {QAvatarSize} from "@qui/base"import {QAvatar} from "@qui/react"const sizes: QAvatarSize[] = ["xs", "s", "m", "l", "xl"]export default function Sizes(): ReactNode {return (<div className="grid justify-center gap-4"><div className="flex items-end justify-center gap-4">{sizes.map((size) => (<QAvatarkey={size}aria-label="Profile"color="purple"icon={User}shape="round"size={size}variant="icon"/>))}</div><div className="flex items-center justify-center gap-4"><QAvatararia-label="Profile"color="purple"icon={User}iconSize="24"shape="round"size="50"variant="icon"/><QAvatararia-label="Profile"color="brand"content="QC"fontSize="26"shape="round"size="57"variant="text"/><QAvatararia-label="Profile"imgAlt="Shashi"imgSrc="/images/shashi.png"shape="round"size="65"variant="image"/></div></div>)}
API
Props
Name & Description | Option(s) | Default |
---|---|---|
The component used for the root node. It can be a React component or
element. |
| 'button' |
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element. |
| |
If true , the avatar will be clickable. |
| true |
The color variant of the avatar. |
| 'neutral' |
| ||
If true , the component is disabled. |
| false |
The style emphasis of the avatar. |
| 'subtle' |
| ||
| ||
| ||
HTML img alt attribute.
Does nothing is variant is anything other than 'image' . |
| |
HTML img src attribute.
Does nothing is variant is anything other than 'image' . |
| |
The shape of the avatar. |
| 'round' |
The size of the avatar. If supplied as a number, the value will be applied as
px. Otherwise, the string value of the property will apply. |
| 'm' |
The style global attribute
contains CSS styling
declarations to be applied to the element. | CSSProperties | |
The variant of the avatar. |
| 'text' |
Type
| ElementType| ComponentType
Default
'button'
Description
The component used for the root node. It can be a React component or
element.
Type
string
Description
The className property of the Element
interface gets and sets the value of the
class attribute
of the specified element.
Type
boolean
Default
true
Description
If
true
, the avatar will be clickable.Type
| 'brand'| 'red'| 'orange'| 'yellow'| 'kiwi'| 'green'| 'teal'| 'blue'| 'purple'| 'fuchsia'| 'magenta'| 'neutral'
Default
'neutral'
Description
The color variant of the avatar.
Type
string
Description
The avatar's string content. This value only applies when variant is
'text'
. Due to size constraints, only the first two
characters are rendered.Type
boolean
Default
false
Description
If
true
, the component is disabled.Type
| 'subtle'| 'strong'
Default
'subtle'
Description
The style emphasis of the avatar.
Type
| LucideIcon| ReactNode
Description
lucide-react icon, positioned in the center of the component. Does nothing
if variant is anything other than
icon
.Type
| 'xs'| 's'| 'm'| 'l'| 'xl'| string| number
Description
Override the size of the endIcon. Provide one of the preset sizes, or
customize with a number or string. If supplied as a number, the value will be
applied as px. Otherwise, the string value of the property will apply. If
this property is omitted, the size is used as a fallback.
Type
string
Description
HTML img alt attribute.
Does nothing is variant is anything other than
'image'
.Type
string
Description
HTML img src attribute.
Does nothing is variant is anything other than
'image'
.Type
| 'round'| 'square'
Default
'round'
Description
The shape of the avatar.
Type
| 'xs'| 's'| 'm'| 'l'| 'xl'| string| number
Default
'm'
Description
The size of the avatar. If supplied as a number, the value will be applied as
px. Otherwise, the string value of the property will apply.
Type
CSSProperties
Description
The style global attribute
contains CSS styling
declarations to be applied to the element.
Type
| 'icon'| 'text'| 'image'
Default
'text'
Description
The variant of the avatar.