CngxAvatar
projects/common/display/avatar/avatar.component.ts
Import#
import { CngxAvatar } from '@cngx/common/display'
Description#
Display atom for user/person/entity avatars.
Rendering cascade:
- Image (
srcset and not errored). - Initials (
initialsset). - Projected content (
<ng-content>) - typically a<cngx-icon>.
Optional status indicator dot via status. Size and shape driven by
CSS custom properties.
Metadata#
Host#
Index#
Inputs#
"xs" | "sm" | "md" | "lg" | "xl"Size preset driving CSS custom properties on the host.
'md''online' | 'offline' | 'busy' | 'away' | undefinedOptional user-presence status indicator.
Instance Properties#
unknownWhether the image loaded successfully.
this.imageLoadedState.asReadonly()Methods#
HostBindings#
| Binding | Expression |
|---|---|
[class.cngx-avatar--xs] | size() === "xs" |
[class.cngx-avatar--sm] | size() === "sm" |
[class.cngx-avatar--md] | size() === "md" |
[class.cngx-avatar--lg] | size() === "lg" |
[class.cngx-avatar--xl] | size() === "xl" |
[class.cngx-avatar--square] | shape() === "square" |
[class.cngx-avatar--circle] | shape() === "circle" |
Default visuals for CngxAvatar. The host carries .cngx-avatar -
an inline-flex plate that renders an image, an initials block, or
projected content. Size and shape are driven by modifier classes,
each backed by a token, so a consumer can either swap one variant
globally or pin a specific instance via inline --cngx-avatar-*.
Shape variants
--circle- pill radius (--cngx-radius-pill)--square- 6px rounded corner
Size variants
Each size pins both --cngx-avatar-size and
--cngx-avatar-font-size to the matching scale step:
--xs- 1.5rem / 0.625rem--sm- 2rem / 0.75rem--md- 2.5rem / 1rem (default)--lg- 3rem / 1.125rem--xl- 4rem / 1.5rem
Slots
.cngx-avatar__img- cover-fit image, inherits border-radius.cngx-avatar__initials- uppercased text block.cngx-avatar__status- corner-positioned status dot
Status modifiers
__status--online- success-coded__status--offline- neutral__status--busy- danger-coded__status--away- warning-coded
Inheritance
--cngx-avatar-bg->--cngx-color-border--cngx-avatar-color->--cngx-color-text--cngx-avatar-circle-radius->--cngx-radius-pill--cngx-avatar-status-border->--cngx-color-surface--cngx-avatar-status-online->--cngx-color-success--cngx-avatar-status-busy->--cngx-color-danger--cngx-avatar-status-away->--cngx-color-warning--cngx-avatar-status-offline- leaf neutral token
Dark mode
Three hooks invert the initials plate to a mid-gray surface with light text and flip the status-dot ring to track the dark page surface so the dot still reads as cut out of the avatar:
prefers-color-scheme: dark[data-color-scheme="dark"]/.darkclass[data-color-scheme="light"]/.lightclass (explicit pin)
Index#
Layout
Typography
Variant / Shape
Variant / Size
Layout
*2.5remActive size of the avatar - consumed by the :scope rule and
pinned by the size-variant classes.
Typography
*1remActive font-size of the initials block. Scaled in step with
--cngx-avatar-size by the size-variant classes.
Surface
<color>oklch(0.92 0.01 240)Background of the avatar plate. Defaults to the foundation border tone so an avatar without an image still reads as a neutral surface.
Variant / Shape
<length>999pxCorner radius applied by .cngx-avatar--circle (pill default).
Variant / Size
*0.625remFont-size token for the .cngx-avatar--xs initials.
*1remFont-size token for the .cngx-avatar--md initials (default).
*1.125remFont-size token for the .cngx-avatar--lg initials.
State / Status
*0.65emDiameter of the status dot, expressed in em so it scales with
the avatar's font-size.
<color>oklch(1 0 0)Ring color around the status dot - defaults to the surface color so the dot reads as cut out of the avatar.
<color>oklch(0.68 0.01 240)Fallback background of the status dot when no state modifier is applied.
<color>oklch(0.68 0.18 145)Dot color for the .cngx-avatar__status--online modifier.
See: [[--cngx-color-success]]
<color>oklch(0.68 0.01 240)Dot color for the .cngx-avatar__status--offline modifier.
<color>oklch(0.62 0.22 25)Dot color for the .cngx-avatar__status--busy modifier.
See: [[--cngx-color-danger]]
<color>oklch(0.72 0.18 70)Dot color for the .cngx-avatar__status--away modifier.
See: [[--cngx-color-warning]]