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

查看生态总览
Skip to content

Alert ​

Feedback 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="alert": root · indicator · content · title · description · action · close-trigger

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-alert>
Vue componentsXhAlertAction XhAlertCloseTrigger XhAlertContent XhAlertDescription XhAlertIndicator XhAlertRoot XhAlertTitle
State machinealertMachine
Skin@xihan-ui/styles/alert.css

Props ​

PropTypeRequired
toneTone
closableboolean
bannerboolean
openboolean
defaultOpenboolean
onOpenChange(details: AlertOpenChangeDetails) => void
partsTitleDescriptionParts
translationsPartial<AlertTranslations>

Events ​

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

EventPayload
open-changeAlertOpenChangeDetails

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
XhAlertRootchildrenReactNode

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · CLOSE · CONTROLLED.OPEN · CONTROLLED.CLOSE · PRESS.START · PRESS.END · ROOT.RENDERED

Guards: isOpenControlled · canPress

connect API ​

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

MemberType
openboolean
tonestring
closableboolean
bannerboolean
setOpen(next: boolean) => void
getRootProps() => T['element']
getIndicatorProps() => T['element']
getContentProps() => T['element']
getTitleProps() => T['element']
getDescriptionProps() => T['element']
getActionProps() => T['element']
getCloseTriggerProps() => T['button']

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.

KeysBehavior
Enter / Spacealert.kbd.close
Enter / Spacealert.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-atomic'true'
rootaria-describedbyid of the description part | undefined
rootaria-labelledbyid of the title part | undefined
rootaria-livelive
rootrolerole
indicatoraria-hidden'true'
close-triggeraria-labeltranslations.close

Style reference ​

Skin ​

@xihan-ui/styles/alert.css is written against [data-scope="alert"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-alert in place of data-scope (same specificity) and sits in the xihan.components and xihan.motion layers. 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-banner'' (present only while the condition holds)
rootdata-state'open' | 'closed'
rootdata-toneprops.tone
close-triggerdata-disabled'' (present only while the condition holds)
close-triggerdata-pressed'' (present only while the condition holds)
close-triggerdata-xh-action-control''
close-triggerdata-xh-action-display'always'
close-triggerdata-xh-action-profile'icon'
close-triggerdata-xh-action-size'sm'
close-triggerdata-xh-action-variant'ghost'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-alert-action-gapactiongapdefault--xh-space-2
--xh-alert-bgrootbackgrounddefault--xh-_tone-subtle
--xh-alert-borderrootborderdefault--xh-_tone-border
--xh-alert-close-bg-activeclose-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_tone-subtle-active
--xh-alert-close-bg-hoverclose-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_tone-subtle-hover
--xh-alert-close-fgclose-triggercolordefault--xh-fg-muted
--xh-alert-close-fg-hoverclose-triggercolordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-alert-close-radiusclose-triggerborder-radiusdefault--xh-shape-control
--xh-alert-close-sizeclose-triggerblock-size
inline-size
min-inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-alert-content-gapcontentgapdefault--xh-space-1
--xh-alert-description-fgdescriptioncolordefault--xh-fg-muted
--xh-alert-description-font-sizedescriptionfont-sizedefault--xh-text-secondary-size
--xh-alert-fgrootcolordefault--xh-fg-default
--xh-alert-font-sizerootfont-sizedefault--xh-text-body-size
--xh-alert-gaprootgapdefault--xh-space-2
--xh-alert-icon-sizeclose-trigger
root
--xh-icon-sizedefault--xh-_action-profile-glyph-size
--xh-glyph-size-md
--xh-alert-indicator-fgindicatorcolordefault--xh-_tone-fg
--xh-alert-indicator-pindicatorpaddingdefault--xh-space-1
--xh-alert-leadingrootline-heightdefault--xh-leading-normal
--xh-alert-pxrootpadding-inlinedefault--xh-surface-px-sm
--xh-alert-pyrootpadding-blockdefault--xh-space-2
--xh-alert-radiusrootborder-radiusdefault--xh-shape-control
--xh-alert-shadowrootbox-shadowdefaultnone
--xh-alert-title-fgtitlecolordefault--xh-fg-default
--xh-alert-title-font-sizetitlefont-sizedefault--xh-text-heading-3-size
--xh-alert-title-font-weighttitlefont-weightdefault--xh-text-heading-3-weight
--xh-alert-title-leadingtitleline-heightdefault--xh-leading-tight

Released under The MIT License