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

查看生态总览
Skip to content

Badge ​

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="badge": root · indicator

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-badge>
Vue componentsXhBadge XhBadgeIndicator XhBadgeRoot
State machinebadgeMachine
Skin@xihan-ui/styles/badge.css

Props ​

PropTypeRequired
countnumber
dotboolean
labelstring
maxnumber
placementBadgePlacement
pulseboolean
showZeroboolean
sizeSize
toneTone

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhBadgedefault—
XhBadgeIndicatordefault{ text: string }

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
XhBadgeIndicatorchildrenSlotChildren<BadgeIndicatorSlotProps>

State ​

Public state is written to data-state.

PartValues
indicator'visible' | 'hidden'

The following names are internal to the state machine.

States: idle

Events: INDICATOR.RENDERED

connect API ​

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

MemberType
visibleboolean
textstring
getRootProps() => T['element']
getIndicatorProps() => 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
indicatoraria-labelprops.label
indicatorrole'status' | undefined

Style reference ​

Skin ​

@xihan-ui/styles/badge.css is written against [data-scope="badge"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-badge 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-placementprops.placement
indicatordata-dot'' (present only while the condition holds)
indicatordata-instant'' (present only while the condition holds)
indicatordata-placementprops.placement
indicatordata-pulse'' (present only while the condition holds)
indicatordata-sizeprops.size
indicatordata-state'visible' | 'hidden'
indicatordata-toneprops.tone

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-badge-bgindicatorbackgrounddefault--xh-_tone
--xh-badge-dot-radiusindicatorborder-radiusdot--xh-shape-circle
--xh-badge-dot-sizeindicatorblock-size
inline-size
min-inline-size
dot--xh-_badge-dot
--xh-badge-fgindicatorcolordefault--xh-_tone-on
--xh-badge-font-sizeindicatorfont-sizedefault--xh-_badge-font
--xh-badge-font-weightindicatorfont-weightdefault--xh-font-weight-medium
--xh-badge-min-sizeindicatorblock-size
min-inline-size
default--xh-_badge-min
--xh-badge-offset-blockindicatorinset-block-end
inset-block-start
placement=bottom-end
placement=bottom-start
placement=top-end
placement=top-start
--xh-space-0
--xh-badge-offset-inlineindicatorinset-inline-end
inset-inline-start
placement=bottom-end
placement=bottom-start
placement=top-end
placement=top-start
--xh-space-0
--xh-badge-pxindicatorpadding-inlinedefault--xh-_badge-px
--xh-badge-radiusindicatorborder-radiusdefault--xh-shape-pill
--xh-badge-ringindicatorborderdefault--xh-bg-surface

Released under The MIT License