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

查看生态总览
Skip to content

Image ​

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="image": root · image · placeholder · 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-image>
Vue componentsXhImageFallback XhImageImage XhImagePlaceholder XhImageRoot
ComposableuseImage
State machineimageMachine
Skin@xihan-ui/styles/image.css

Props ​

PropTypeRequired
srcstring
altstring
fallbackDelaynumber
onStatusChange(details: ImageStatusChangeDetails) => void

Events ​

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

EventPayload
status-changeImageStatusChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhImageRootdefaultImageRootSlotProps

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhImageRootchildrenSlotChildren<ImageRootSlotProps>

State ​

Public state is written to data-state.

PartValues
root'idle' | 'loading' | 'loaded' | 'error'
image'idle' | 'loading' | 'loaded' | 'error'
placeholder'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 · after.fallbackDelay · PART.RENDERED

Guards: hasSrc

connect API ​

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

MemberType
statusImageStatus
loadedboolean
showFallbackboolean
showPlaceholderboolean
getRootProps() => T['element']
getImageProps() => T['img']
getPlaceholderProps() => T['element']
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.

ARIA ​

These attributes are produced by connect.

PartAttributeValue
placeholderaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/image.css is written against [data-scope="image"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-image 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-state'idle' | 'loading' | 'loaded' | 'error'
imagedata-state'idle' | 'loading' | 'loaded' | 'error'
placeholderdata-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-image-bgrootbackgrounddefault--xh-bg-subtle
--xh-image-fallback-bgfallbackbackgrounddefault--xh-bg-subtle-opaque
--xh-image-fallback-fgfallbackcolordefault--xh-fg-subtle
--xh-image-fallback-font-sizefallbackfont-sizedefault--xh-text-caption-size
--xh-image-fallback-min-hfallbackmin-block-sizedefault--xh-control-h-lg
--xh-image-fallback-pxfallbackpadding-inlinedefault--xh-space-4
--xh-image-fallback-pyfallbackpadding-blockdefault--xh-space-2
--xh-image-fitimageobject-fitdefaultcover
--xh-image-hrootblock-sizedefaultauto
--xh-image-placeholder-bgplaceholderbackgrounddefault--xh-bg-subtle-opaque
--xh-image-placeholder-fgplaceholdercolordefault--xh-fg-subtle
--xh-image-radiusrootborder-radiusdefault--xh-shape-control
--xh-image-ratiorootaspect-ratiodefaultauto
--xh-image-wrootinline-sizedefault100%

Released under The MIT License