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

查看生态总览
Skip to content

Notification ​

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="notification": root · group · item · item-indicator · item-content · item-title · item-description · item-action-trigger · item-progress · item-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-notification>
Vue componentsXhNotificationGroup XhNotificationItem XhNotificationItemActionTrigger XhNotificationItemCloseTrigger XhNotificationItemContent XhNotificationItemDescription XhNotificationItemIndicator XhNotificationItemProgress XhNotificationItemTitle XhNotificationRoot
ComposableuseNotification
State machinenotificationMachine
Skin@xihan-ui/styles/notification.css

Props ​

PropTypeRequired
itemsNotificationRecord[]
defaultItemsNotificationRecord[]
presetNotificationPreset
placementNotificationPlacement
maxnumber
dedupeNotificationDedupe
gapnumber
durationnumber
stackedboolean
pauseOnPageIdleboolean
translationsPartial<NotificationTranslations>
onItemsChange(details: NotificationItemsChangeDetails) => void

NotificationRecord ​

Elements of items.

FieldTypeRequired
idstringYes
titlestring
descriptionstring
toneNotificationTone
loadingboolean
durationnumber
closableboolean
placementNotificationPlacement
actionLabelstring
prioritynumber
countnumber

Events ​

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

EventPayload
items-changeNotificationItemsChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhNotificationGroupdefaultNotificationGroupSlotProps
XhNotificationItemdefaultNotificationItemSlotProps
XhNotificationRootdefaultNotificationRootSlotProps

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
XhNotificationGroupplacementNotificationPlacement
XhNotificationGroupchildrenSlotChildren<NotificationGroupSlotProps>
XhNotificationItemidstring
XhNotificationItempresetNotificationPreset
XhNotificationItemtitlestring
XhNotificationItemdescriptionstring
XhNotificationItemtoneNotificationTone
XhNotificationItemloadingboolean
XhNotificationItemdurationnumber
XhNotificationItemclosableboolean
XhNotificationItempauseOnPageIdleboolean
XhNotificationItempausedboolean
XhNotificationItemtranslationsNotificationItemProps['translations']
XhNotificationItemonStatusChangeNotificationItemProps['onStatusChange']
XhNotificationItemonActionNotificationItemProps['onAction']
XhNotificationItemchildrenSlotChildren<NotificationItemSlotProps>
XhNotificationRootchildrenSlotChildren<NotificationRootSlotProps>

State ​

Public state is written to data-state.

PartValues
itemtoStatus(state.get())
item-progresstoStatus(state.get())

The following names are internal to the state machine.

States: idle

Events: ITEMS.CREATE · ITEMS.UPDATE · ITEMS.DISMISS · ITEMS.DISMISS_ALL · STACK.EXPAND · STACK.COLLAPSE

connect API ​

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

MemberType
presetNotificationPreset
stackedboolean
visibleNotificationsResolvedNotification[]
placementsNotificationPlacement[]
countnumber
getItemsByPlacement(placement: NotificationPlacement) => ResolvedNotification[]
create(options?: NotificationOptions) => string
update(id: string, options: Partial<NotificationOptions>) => void
dismiss(id: string) => void
dismissAll() => void
getRootProps() => T['element']
getGroupProps(props?: NotificationGroupProps) => 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.

KeysBehavior
Enter / Spacenotification.kbd.close
Enter / Spacenotification.kbd.action
Enter / Spacenotification.kbd.press
Escapenotification.kbd.collapse

ARIA ​

These attributes are produced by connect.

PartAttributeValue
grouparia-labeltranslations.region
grouprole'region'
itemaria-atomic'true'
itemaria-describedbyid of the description part | undefined
itemaria-labelledbyid of the title part | undefined
itemaria-live'assertive' | 'polite'
itemrole'alert' | 'status'
item-indicatoraria-hidden'true'
item-progressaria-hidden'true'
item-close-triggeraria-labeltranslations.close

Style reference ​

Skin ​

@xihan-ui/styles/notification.css is written against [data-scope="notification"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-notification 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-countlist.length
rootdata-empty'' (present only while the condition holds)
groupdata-countgroup.length
groupdata-empty'' (present only while the condition holds)
groupdata-expanded'' (present only while the condition holds)
groupdata-placementprops.placement
groupdata-presetprops.preset
groupdata-stacked'' (present only while the condition holds)
itemdata-loading'' (present only while the condition holds)
itemdata-paused'' (present only while the condition holds)
itemdata-presetprops.preset
itemdata-statetoStatus(state.get())
itemdata-toneprops.tone
itemdata-xh-loading-ring''
item-indicatordata-loading'' (present only while the condition holds)
item-indicatordata-xh-loading-ring''
item-action-triggerdata-pressed'' (present only while the condition holds)
item-action-triggerdata-xh-action-control''
item-action-triggerdata-xh-action-display'always'
item-action-triggerdata-xh-action-profile'text'
item-action-triggerdata-xh-action-size'sm'
item-action-triggerdata-xh-action-variant'outline'
item-progressdata-statetoStatus(state.get())
item-close-triggerdata-disabled'' (present only while the condition holds)
item-close-triggerdata-pressed'' (present only while the condition holds)
item-close-triggerdata-xh-action-control''
item-close-triggerdata-xh-action-display'always'
item-close-triggerdata-xh-action-profile'icon'
item-close-triggerdata-xh-action-size'xs' | 'sm'
item-close-triggerdata-xh-action-variant'ghost'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-notification-action-bgitem-action-trigger--xh-ink-surface
background-color
default
xh-ink-surface
transparent
--xh-notification-action-bg-activeitem-action-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-bg-subtle-hover
--xh-notification-action-bg-hoveritem-action-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-bg-subtle
--xh-notification-action-borderitem-action-triggerborder
border-color
default
disabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-border-control
--xh-border-control-hover
--xh-notification-action-fgitem-action-triggercolordefault
disabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-notification-action-font-weightitem-action-triggerfont-weightdefault--xh-font-weight-medium
--xh-notification-action-hitem-action-triggerblock-size
inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-notification-action-pxitem-action-triggerpadding-inlinedefault--xh-_action-profile-padding-inline
--xh-notification-action-radiusitem-action-triggerborder-radiusdefault--xh-shape-control
--xh-notification-close-bgitem-close-trigger--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-notification-close-bg-activeitem-close-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-notification-close-bg-hoveritem-close-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-notification-close-borderitem-close-triggerborderdefault--xh-_action-variant-border-rest
--xh-notification-close-fgitem-close-triggercolordefault--xh-fg-muted
--xh-notification-close-fg-hoveritem-close-triggercolordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-default
--xh-notification-close-insetitem
item-close-trigger
item-title
inset-block-start
inset-inline-end
padding-inline-end
has([data-part='item-close-trigger'])
preset=card
--xh-notification-item-py
--xh-surface-action-inset
--xh-notification-close-radiusitem-close-triggerborder-radiusdefault--xh-shape-control
--xh-notification-close-sizeitem
item-close-trigger
item-title
block-size
inline-size
inset-block-start
min-inline-size
padding-inline-end
default
has([data-part='item-close-trigger'])
preset=card
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-control-h-sm
--xh-notification-description-fgitem
item-description
colordefault
preset=toast
--xh-fg-default
--xh-fg-muted
--xh-notification-description-font-sizeitem
item-description
font-sizedefault
preset=toast
--xh-text-body-size
--xh-text-secondary-size
--xh-notification-description-leadingitem
item-description
line-heightpreset=toast--xh-leading-normal
--xh-notification-description-max-hitem-descriptionmax-block-sizedefault--xh-viewport-h-md
--xh-notification-icon-sizeitem
item-action-trigger
item-close-trigger
--xh-icon-sizedefault--xh-_action-profile-glyph-size
--xh-glyph-size-md
--xh-glyph-size-xs
--xh-notification-indicator-fgitem
item-indicator
background-color
border
border-color
color
@media (prefers-reduced-motion: reduce)
@media print
default
motion=reduce
preset=toast
where([data-motion='reduce'])
xh-loading-ring
xh-loading-ring=overlay
--xh-_tone-fg
--xh-notification-indicator-pitem
item-indicator
paddingpreset=toast--xh-space-1
--xh-notification-indicator-sizeitem
item-indicator
--xh-icon-size
inline-size
default
preset=toast
--xh-_notification-title-line
--xh-glyph-size-md
--xh-notification-insetgroupinset-block-end
inset-block-start
inset-inline-end
inset-inline-start
padding-block-end
padding-block-start
padding-inline
default
not([data-stacked])
placement=-end
placement=-start
placement=bottom
placement=top
preset=toast
stacked
--xh-space-4
--xh-space-6
--xh-notification-item-bgitembackgrounddefault--xh-material-elevated-bg
--xh-notification-item-borderitemborderdefault--xh-material-elevated-border
--xh-notification-item-fgitemcolordefault--xh-material-elevated-fg
--xh-notification-item-font-sizeitemfont-sizedefault
preset=toast
--xh-text-body-size
--xh-text-label-size
--xh-notification-item-gapitemcolumn-gapdefault
preset=toast
--xh-space-2
--xh-space-3
--xh-notification-item-leadingitemline-heightdefault--xh-text-body-leading
--xh-notification-item-pxiteminset-inline-start
padding-inline
default
preset=toast
--xh-overlay-notification-p
--xh-space-4
--xh-notification-item-pyitem
item-close-trigger
inset-block-start
padding-block
default
preset=card
preset=toast
--xh-overlay-notification-p
--xh-space-2_5
--xh-notification-item-radiusitemborder-radiusdefault
preset=toast
--xh-shape-control
--xh-shape-sheet
--xh-notification-item-row-gapitem
item-content
row-gapdefault--xh-space-2
--xh-notification-item-shadowitembox-shadowdefault--xh-material-elevated-shadow
--xh-notification-item-wgroup
item
inline-sizedefault
preset=toast
stacked
--xh-overlay-notification-w
--xh-overlay-toast-w
--xh-notification-layergroupz-indexdefault--xh-layer-toast
--xh-notification-progress-bgitem-progressbackgrounddefault--xh-_tone-soft
--xh-notification-progress-durationitem-progressanimationdefault--xh-motion-duration-slide
--xh-notification-progress-radiusitem
item-progress
border-radius
clip-path
@keyframes xh-countdown
preset=card
--xh-shape-pill
--xh-notification-progress-thicknessitem-progressblock-sizedefault--xh-space-0_5
--xh-notification-stack-scale*
group
item
scale@keyframes xh-notification-stack-in
@keyframes xh-notification-stack-out
preset=toast
stacked
--xh-_notification-stack-scale
--xh-notification-title-fgitem
item-title
colordefault
preset=toast
--xh-_tone-fg
--xh-fg-default
--xh-notification-title-font-sizeitem
item-close-trigger
item-indicator
item-title
--xh-icon-size
block-size
font-size
inline-size
inset-block-start
default
preset=card
preset=toast
--xh-text-body-size
--xh-text-heading-3-size
--xh-notification-title-font-weightitem
item-title
font-weightdefault
preset=toast
--xh-font-weight-medium
--xh-text-heading-3-weight
--xh-notification-title-leadingitem
item-close-trigger
item-title
inset-block-start
line-height
default
preset=card
preset=toast
--xh-leading-normal
--xh-leading-tight

Released under The MIT License