Skip to content
Overlay ColorModeAvatar

ColorModeAvatar

An avatar with one image per color mode.

On this page

Examples

Color mode avatar

Both images are rendered and CSS shows the right one.

Razor
<KlyColorModeAvatar Light="@Avatar("#ffd23f", "#0a0b0c")" Dark="@Avatar("#0a0b0c", "#ffd23f")" Alt="Ada Lovelace" Size="KlySize.Xl" data-testid="color-mode-avatar" />
<KlyColorModeAvatar Light="@Avatar("#14b8a6", "#ffffff")" Dark="@Avatar("#134e4a", "#5eead4")" Alt="Grace Hopper" />

@code {
    // A tiny SVG per color mode stands in for two real image files.
    private static string Avatar(string background, string foreground) =>
        "data:image/svg+xml," + Uri.EscapeDataString(
            $"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'><rect width='48' height='48' fill='{background}'/><circle cx='24' cy='19' r='8' fill='{foreground}'/><path d='M8 44c2-10 9-14 16-14s14 4 16 14z' fill='{foreground}'/></svg>");
}

API

KlyColorModeAvatar

Avatar with one picture for light mode and one for dark mode. CSS shows the matching one, so there is no flash.

Parameters

Name Type Default Description
Alt string Alternative text of the picture. Both pictures carry it.
Class string Classes added to the root element, merged last so they win over the theme.
Dark string Image in dark mode. Defaults to Light .
ImageOptions KlyImageOptions Image settings forwarded to both avatars, see ImageOptions .
Light string Image in light mode.
Size KlySize KlySize.Md Size of the color mode avatar, from Xs to Xl . When not set, Size applies, else the default of the component. Values: Xs, Sm, Md, Lg, Xl.
Text string Initials shown when there is no picture.
Ui AvatarUi Per-instance class overrides of the slots of the color mode avatar, see AvatarUi . They are merged after the theme and the Class parameter wins on the root slot.

Slots

Name Type Description
Icon RenderFragment Icon shown when there is no picture and no text, as markup such as a KlyIcon .

Ui slots

Ui takes a AvatarUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyAvatar and KlyColorModeAvatar , after the theme and the app configuration.
Image Classes merged into the image slot of KlyAvatar and KlyColorModeAvatar , after the theme and the app configuration.
Fallback Classes merged into the fallback slot of KlyAvatar and KlyColorModeAvatar , after the theme and the app configuration.