Avatar
Avatar represents a person, team, object, or entity in compact UI surfaces.
@duskmoon-dev/components/avatar Usage
When to use
- Use it to clarify state, metadata, content hierarchy, or loading without creating a new workflow.
- Pair it with semantic content so visual treatment never becomes the only source of meaning.
Implementation notes
Features
Focuses on status, metadata, empty/loading states, or content grouping without owning application state.
Uses DuskMoon tokens so the component follows the active docs theme.
Avatar is most often configured through `size`, `shape`, `src`, `alt`.
Renders with default classes
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and Avatar from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Avatar } from "@duskmoon-dev/components/avatar";
export function Example() {
return (<Avatar className="avatar-primary">DM</Avatar>);
} Renders with default classes
test-backedAvatar scenario from the component test coverage: renders with default classes.
import "@duskmoon-dev/components/styles.css";
import { Avatar } from "@duskmoon-dev/components/avatar";
export function AvatarRendersWithDefaultClassesDemo() {
return (<Avatar className="avatar-primary">DM</Avatar>);
} Renders with custom size and shape
test-backedAvatar scenario from the component test coverage: renders with custom size and shape.
import "@duskmoon-dev/components/styles.css";
import { Avatar } from "@duskmoon-dev/components/avatar";
export function AvatarRendersWithCustomSizeDemo() {
return (<Avatar className="avatar-primary">DM</Avatar>);
} Renders image when src is provided
test-backedAvatar scenario from the component test coverage: renders image when src is provided.
import "@duskmoon-dev/components/styles.css";
import { Avatar } from "@duskmoon-dev/components/avatar";
export function AvatarRendersImageWhenSrcDemo() {
return (<Avatar className="avatar-primary">DM</Avatar>);
} Renders fallback when image fails to load
test-backedAvatar scenario from the component test coverage: renders fallback when image fails to load.
import "@duskmoon-dev/components/styles.css";
import { Avatar } from "@duskmoon-dev/components/avatar";
export function AvatarRendersFallbackWhenImageDemo() {
return (<Avatar className="avatar-primary">DM</Avatar>);
} Renders children as fallback when image fails to load and no fallback prop provided
test-backedAvatar scenario from the component test coverage: renders children as fallback when image fails to load and no fallback prop provided.
import "@duskmoon-dev/components/styles.css";
import { Avatar } from "@duskmoon-dev/components/avatar";
export function AvatarRendersChildrenAsFallbackDemo() {
return (<Avatar className="avatar-primary">DM</Avatar>);
} Renders fallback when no src is provided
test-backedAvatar scenario from the component test coverage: renders fallback when no src is provided.
import "@duskmoon-dev/components/styles.css";
import { Avatar } from "@duskmoon-dev/components/avatar";
export function AvatarRendersFallbackWhenNoDemo() {
return (<Avatar className="avatar-primary">DM</Avatar>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Avatar className="avatar-primary">DM</Avatar>
</div>
<div data-theme="moonlight">
<Avatar className="avatar-primary">DM</Avatar>
</div> API
The API reference below lists every parsed exported type or interface for Avatar. Start with `size`, `shape`, `src`, `alt` for common usage.
packages/components/src/components/avatar/Avatar.types.ts
Scenarios: packages/components/src/components/avatar/Avatar.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
size | AvatarSize | No | size configures Avatar. |
shape | AvatarShape | No | shape configures Avatar. |
src | string | No | src configures Avatar. |
alt | string | No | alt configures Avatar. |
fallback | React.ReactNode | No | fallback configures Avatar. |
"xs" | "sm" | "md" | "lg" | "xl" "circle" | "square"