Avatar

A visual representation of a user or entity.

import { ... } from '@corndev/ui'
XS
SM
MD
LG
XL
CI
SQ
User avatar

HTML

No JavaScript required — these classes are the whole component.

<img class="corn-avatar" data-size="md" data-shape="circle" src="/me.jpg" alt="Ada" />

Classes

Class
.corn-avatar

Attributes

AttributeValues
data-sizexs|sm|md|lg|xl
data-shapecircle|square

Vanilla JS

Optional. createAvatar only adds and removes the classes and attributes above, so the HTML is equivalent. Reach for it when you need to change options at runtime.

import { createAvatar } from '@corndev/ui';
import '@corndev/ui/theme';

const el = document.querySelector('#target');
const instance = createAvatar(el, { /* options */ });

Options

OptionTypeDefault
size'xs'|'sm'|'md'|'lg'|'xl''md'
shape'circle'|'square''circle'

React

Avatar — from @corndev/ui-react.

The React version renders the image or initials for you via src/alt/initials. The vanilla version only applies sizing and shape — supply the <img> or initials text yourself.

Props

PropTypeDefaultDescription
size'xs'|'sm'|'md'|'lg'|'xl''md'
shape'circle'|'square''circle'
srcstringundefinedImage URL. When set, renders an <img>.
altstring''Alt text for the image.
initialsReact.ReactNodeundefinedFallback shown when src is absent.
classNamestringundefinedMerged with the Corn UI classes.

Default

JD
<Avatar initials="JD" />

Sizes

XS
SM
MD
LG
XL
<Avatar size="xs" initials="XS" />
<Avatar size="sm" initials="SM" />
<Avatar size="md" initials="MD" />
<Avatar size="lg" initials="LG" />
<Avatar size="xl" initials="XL" />

Shape

CI
SQ
<Avatar shape="circle" initials="CI" />
<Avatar shape="square" initials="SQ" />

With image

User avatar
<Avatar src="/avatar.jpg" alt="User avatar" size="lg" />