生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

Avatar ​

Data display component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="avatar": root · image · fallback

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-avatar>
Vue componentsXhAvatarFallback XhAvatarImage XhAvatarRoot
ComposableuseAvatar
State machineavatarMachine
Skin@xihan-ui/styles/avatar.css

Props ​

PropTypeRequired
srcstring
altstring
sizeSize
toneTone
fallbackDelaynumber
onStatusChange(details: AvatarStatusChangeDetails) => void

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
status-changeAvatarStatusChangeDetails

State ​

Public state is written to data-state.

PartValues
root'idle' | 'loading' | 'loaded' | 'error'
image'idle' | 'loading' | 'loaded' | 'error'
fallback'idle' | 'loading' | 'loaded' | 'error'

The following names are internal to the state machine.

States: idle · loading · loaded · error

Events: SRC.CHANGE · IMAGE.LOAD · IMAGE.ERROR · FALLBACK.DUE · FALLBACK.RENDERED

Guards: hasSrc

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
statusAvatarStatus
loadedboolean
getRootProps() => T['element']
getImageProps() => T['img']
getFallbackProps() => T['element']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

No keyboard interaction: the component takes no focus, or focus behavior comes entirely from native elements.

Style reference ​

Skin ​

@xihan-ui/styles/avatar.css is written against [data-scope="avatar"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-avatar in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-sizeprops.size
rootdata-state'idle' | 'loading' | 'loaded' | 'error'
rootdata-toneprops.tone
imagedata-state'idle' | 'loading' | 'loaded' | 'error'
fallbackdata-state'idle' | 'loading' | 'loaded' | 'error'

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-avatar-bgrootbackgrounddefault
tone
--xh-_tone-subtle
--xh-bg-subtle-active-opaque
--xh-avatar-fgrootcolordefault
tone
--xh-_tone-fg
--xh-fg-default
--xh-avatar-font-sizerootfont-sizedefault--xh-_avatar-font-size
--xh-avatar-font-weightrootfont-weightdefault--xh-font-weight-medium
--xh-avatar-radiusrootborder-radiusdefault--xh-shape-circle
--xh-avatar-sizerootblock-size
font-size
inline-size
default
size=lg
size=sm
--xh-control-h-lg
--xh-control-h-md
--xh-control-h-sm

Released under The MIT License