DeepWorks Studios Blazor Component Library

Demo user Administrator ยท Blazor Server Library 20261206222504-6e8ff32.dirty

DwsAvatar

Examples of different avatar types and configurations. A profile picture is a DwsImage and an icon a DwsIcon inside the disc.

API Reference — DwsAvatar API Reference — DwsAvatarGroup

Avatar Types

The content of an avatar: a profile picture, initials, initials taken from a full name, or an icon.

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_ProfileImage" ProfileImage="https://example.com/photo.jpg" Size="DwsSize.Medium" Color="DwsColor.Primary" />
<DwsAvatar Name="Avatar_Initials" Initials="JD" Size="DwsSize.Medium" Color="DwsColor.Success" />
<DwsAvatar Name="Avatar_FullName" FullName="Ada Lovelace" Size="DwsSize.Medium" Color="DwsColor.Info" />
<DwsAvatar Name="Avatar_Icon" Icon="fas fa-user" Size="DwsSize.Medium" Color="DwsColor.Error" />
Avatar.razor.cs
// No additional code-behind is required for this example.

Colour from the name

ColorFromName picks one of eight colours from the person's name: the same name always gets the same colour, in every session. The colours are built from the theme's palette (softened with the surface colour), so they follow the theme; the initials are black or white, whichever reads on the fill. Without a name the Initials decide; with neither, Color is used.

Show Code
Avatar.razor
<div class="d-flex flex-wrap align-items-center gap-2">
    @foreach (string person in _people)
    {
        <DwsAvatar @key="person" Name="@("Avatar_Named_" + person.Replace(' ', '_'))" FullName="@person" ColorFromName="true" Tooltip="@person" />
    }
    <DwsAvatar Name="Avatar_Named_Outline" FullName="Ada Lovelace" ColorFromName="true" Appearance="DwsAppearance.Outline" Tooltip="Ada Lovelace, outline" />
</div>
Avatar.razor.cs
private static readonly string[] _people =
[
    "Ada Lovelace", "Grace Hopper", "Alan Turing", "Katherine Johnson", "Linus Torvalds",
    "Margaret Hamilton", "Tim Berners-Lee", "Barbara Liskov", "Edsger Dijkstra", "Radia Perlman",
];

// The slot is also available from code, e.g. to colour a row like the person's avatar:
// int slot = DwsAvatar.GetNameColorIndex("Ada Lovelace"); // 0 .. DwsAvatar.NameColorCount - 1

Fallbacks

A broken image falls back to the initials or icon underneath it; without either, the empty disc stays.

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_BrokenWithInitials" ProfileImage="/does-not-exist/avatar.png" Initials="JD" AriaLabel="Jane Doe" Color="DwsColor.Info" />
<DwsAvatar Name="Avatar_BrokenWithIcon" ProfileImage="/does-not-exist/avatar.png" Icon="fas fa-user" AriaLabel="Unknown user" Color="DwsColor.Secondary" />
<DwsAvatar Name="Avatar_BrokenOnly" ProfileImage="/does-not-exist/avatar.png" AriaLabel="Broken image, nothing else" Color="DwsColor.Warning" />
Avatar.razor.cs
// No additional code-behind is required for this example.

Cropping

A wide and a tall picture are cropped to the circle without distortion.

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_Wide" ProfileImage="@_wideImage" AriaLabel="Wide picture" />
<DwsAvatar Name="Avatar_Tall" ProfileImage="@_tallImage" AriaLabel="Tall picture" />
Avatar.razor.cs
// 3:1 and 1:3 inline SVG pictures (a striped band) to show cropping without distortion.
private const string _wideImage = "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='100'><rect width='300' height='100' fill='%23264653'/><rect x='100' width='100' height='100' fill='%23e9c46a'/><circle cx='150' cy='50' r='30' fill='%23e76f51'/></svg>";
private const string _tallImage = "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='300'><rect width='100' height='300' fill='%232a9d8f'/><rect y='100' width='100' height='100' fill='%23f4a261'/><circle cx='50' cy='150' r='30' fill='%23264653'/></svg>";

Long initials

Long initials and an emoji stay inside the circle.

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_LongInitials" Initials="ABCDE" AriaLabel="Long initials" Color="DwsColor.Success" />
<DwsAvatar Name="Avatar_EmojiInitials" Initials="😀" AriaLabel="Emoji initials" Color="DwsColor.Primary" />
Avatar.razor.cs
// No additional code-behind is required for this example.

Appearance

Avatars support Filled and Outline appearances.

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_Filled" Initials="JD" Appearance="DwsAppearance.Filled" Color="DwsColor.Primary" />
<DwsAvatar Name="Avatar_Outline" Initials="JD" Appearance="DwsAppearance.Outline" Color="DwsColor.Primary" />
Avatar.razor.cs
// No additional code-behind is required for this example.

Shapes

Avatars can be rendered as a circle (Round) or a rounded square (Square).

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_ShapeRound" Initials="JD" Shape="DwsShape.Round" Color="DwsColor.Secondary" />
<DwsAvatar Name="Avatar_ShapeSquare" Initials="JD" Shape="DwsShape.Square" Color="DwsColor.Secondary" />
Avatar.razor.cs
// No additional code-behind is required for this example.

Avatar Colors

Examples of avatars with different colors

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_ColorPrimary" Initials="JD" Size="DwsSize.Medium" Color="DwsColor.Primary" />
<DwsAvatar Name="Avatar_ColorSecondary" Initials="JD" Size="DwsSize.Medium" Color="DwsColor.Secondary" />
<DwsAvatar Name="Avatar_ColorSuccess" Initials="JD" Size="DwsSize.Medium" Color="DwsColor.Success" />
<DwsAvatar Name="Avatar_ColorWarning" Initials="JD" Size="DwsSize.Medium" Color="DwsColor.Warning" />
<DwsAvatar Name="Avatar_ColorError" Initials="JD" Size="DwsSize.Medium" Color="DwsColor.Error" />
<DwsAvatar Name="Avatar_ColorInfo" Initials="JD" Size="DwsSize.Medium" Color="DwsColor.Info" />
Avatar.razor.cs
// No additional code-behind is required for this example.

Avatar Sizes

Examples of different avatar sizes

Show Code
Avatar.razor
<DwsAvatar Name="Avatar_SizeXSmall" Initials="XS" Size="DwsSize.XSmall" Color="DwsColor.Primary" />
<DwsAvatar Name="Avatar_SizeSmall" Initials="S" Size="DwsSize.Small" Color="DwsColor.Secondary" />
<DwsAvatar Name="Avatar_SizeMedium" Initials="M" Size="DwsSize.Medium" Color="DwsColor.Success" />
<DwsAvatar Name="Avatar_SizeLarge" Initials="L" Size="DwsSize.Large" Color="DwsColor.Warning" />
<DwsAvatar Name="Avatar_SizeXLarge" Initials="XL" Size="DwsSize.XLarge" Color="DwsColor.Error" />
Avatar.razor.cs
// No additional code-behind is required for this example.

Avatars with Badges

Wrap an avatar in a DwsBadge to overlay a status or notification indicator.

3
Show Code
Avatar.razor
<DwsBadge Name="Avatar_OnlineBadge" IsDot="true" Color="DwsColor.Success" Overlap="DwsBadgeOverlap.Circular">
    <DwsAvatar Name="Avatar_WithStatusBadge" Initials="JD" Color="DwsColor.Primary" />
</DwsBadge>
<DwsBadge Name="Avatar_NotificationBadge" Content="3" Color="DwsColor.Error" Overlap="DwsBadgeOverlap.Circular">
    <DwsAvatar Name="Avatar_WithNotificationBadge" Initials="AB" Color="DwsColor.Secondary" />
</DwsBadge>
Avatar.razor.cs
// No additional code-behind is required for this example.

Avatar Groups

DwsAvatarGroup shares Size/Color/Shape/Appearance across its avatars and can collapse overflow into a '+N' indicator.

Show Code
Avatar.razor
<DwsAvatarGroup Name="Avatar_Group" GroupSize="DwsSize.Medium" MaxVisible="3">
    <DwsAvatar Name="Avatar_Group1" Initials="AB" Color="DwsColor.Primary" />
    <DwsAvatar Name="Avatar_Group2" Initials="CD" Color="DwsColor.Success" />
    <DwsAvatar Name="Avatar_Group3" Initials="EF" Color="DwsColor.Warning" />
    <DwsAvatar Name="Avatar_Group4" Initials="GH" Color="DwsColor.Error" />
    <DwsAvatar Name="Avatar_Group5" Initials="IJ" Color="DwsColor.Info" />
</DwsAvatarGroup>
Avatar.razor.cs
// No additional code-behind is required for this example.

Interface-Description

Name Typ Default Description
ProfileImage string string.Empty URL of the profile image. When provided, the image (a decorative DwsImage, object-fit cover) is displayed instead of, or layered above, the Initials/Icon fallback while it loads.
Initials string string.Empty One or two characters displayed as text inside the avatar when no profile image is set (or as a fallback while the image loads).
FullName string? null The name of the person. Without Initials the avatar shows the initials taken from it (first letter of the first and of the last word); without AriaLabel it is the accessible name of the avatar.
ColorFromName bool false Picks one of eight theme-built colours from FullName (or Initials) instead of Color; the same name always gets the same colour. Static helper: DwsAvatar.GetNameColorIndex(name).
Icon string string.Empty CSS icon class (e.g. 'fas fa-user') displayed when Initials is not set, as a decorative DwsIcon that takes the disc's size and text colour.
IconStyle string string.Empty Inline style string applied to the icon (the DwsIcon's Style).
Size DwsSize DwsSize.Medium Size of the avatar. Accepts XSmall, Small, Medium, Large, XLarge.
Color DwsColor DwsColor.Primary Theme colour of the avatar, applied through the --dws-avatar-color CSS variable.
Appearance DwsAppearance DwsAppearance.Filled Visual style of the avatar: Filled (solid background) or Outline (bordered, transparent background).
Shape DwsShape DwsShape.Round Shape of the avatar: Round (circle) or Square (rounded square).
Width int? null Optional explicit width in pixels, overriding the size-driven width.
Height int? null Optional explicit height in pixels, overriding the size-driven height.
Tooltip string string.Empty Optional tooltip text shown on hover.
TooltipPosition DwsTooltipPosition DwsTooltipPosition.Top Kept so existing markup still compiles: the tooltip is the browser's native title, which has no position.
AriaLabel string? null Overrides the automatically resolved aria-label (defaults to Initials, or a localized 'Avatar' label).
OnClick EventCallback<MouseEventArgs> - Raised when the avatar is clicked. Adds a pointer cursor and button role when subscribed.
OnImageLoadError EventCallback<string> - Raised with the failed ProfileImage URL when the image cannot be loaded; the component falls back to Initials/Icon.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.

Interface-Description

Name Typ Default Description
ChildContent RenderFragment? null The DwsAvatar instances to render inside the group.
GroupSize DwsSize? null When set, pushed onto every registered avatar's Size.
GroupColor DwsColor? null When set, pushed onto every registered avatar's Color.
GroupShape DwsShape? null When set, pushed onto every registered avatar's Shape.
GroupAppearance DwsAppearance? null When set, pushed onto every registered avatar's Appearance.
MaxVisible int? null When set, only the first N avatars are shown; the rest collapse into a trailing '+N' overflow indicator.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.