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

查看生态总览
Skip to content

Button ​

General 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="button": root · label · indicator · prefix · suffix

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-button>
Vue componentsXhButton XhButtonIndicator XhButtonLabel XhButtonPrefix XhButtonSuffix
State machinebuttonMachine
Skin@xihan-ui/styles/button.css

Props ​

PropTypeRequired
type'button' | 'submit' | 'reset'
disabledboolean
loadingboolean
variantButtonVariant
toneTone
sizeSize
iconOnlyboolean
ariaLabelstring
ariaLabelledbystring
fullWidthboolean
asButtonElement

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
XhButtonhrefComponentPropsWithRef<'a'>['href']
XhButtontargetComponentPropsWithRef<'a'>['target']
XhButtonrelComponentPropsWithRef<'a'>['rel']
XhButtondownloadComponentPropsWithRef<'a'>['download']

State ​

The following names are internal to the state machine.

States: idle

Events: PRESS.START · PRESS.END

Guards: canPress

connect API ​

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

MemberType
disabledboolean
loadingboolean
getRootProps() => T['button']
getLabelProps() => T['element']
getIndicatorProps() => T['element']
getPrefixProps() => T['element']
getSuffixProps() => 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 / Spacebutton.kbd.activate
Enter / Spacebutton.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
rootaria-busy'true' | undefined
rootaria-disabled'true' | undefined
indicatoraria-hidden'true'
prefixaria-hidden'true'
suffixaria-hidden'true'

Style reference ​

Skin ​

@xihan-ui/styles/button.css is written against [data-scope="button"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-button 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-disabled'' (present only while the condition holds)
rootdata-full-width'' (present only while the condition holds)
rootdata-icon-only'' (present only while the condition holds)
rootdata-loading'' (present only while the condition holds)
rootdata-pressed'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-toneprops.tone
rootdata-variantprops.variant
rootdata-xh-action-control''
rootdata-xh-action-display'always'
rootdata-xh-action-profile'icon' | 'text'
rootdata-xh-action-sizeprops.size
rootdata-xh-action-variantprops.variant
rootdata-xh-ink-surface'' (present only while the condition holds)
indicatordata-loading'' (present only while the condition holds)
indicatordata-xh-loading-ring'overlay'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-button-bgroot--xh-ink-surface
background-color
default
focus-visible
loading
xh-ink-surface
--xh-_action-variant-bg-focus-visible
--xh-_action-variant-bg-loading
--xh-_action-variant-bg-rest
--xh-button-bg-activerootbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-button-bg-hoverrootbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-button-fgrootcolordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-fg-focus-visible
--xh-_action-variant-fg-hover
--xh-_action-variant-fg-loading
--xh-_action-variant-fg-pressed
--xh-_action-variant-fg-rest
--xh-button-font-sizerootfont-sizedefault--xh-_action-profile-font-size
--xh-button-font-weightrootfont-weightdefault--xh-text-label-weight
--xh-button-gaprootgapdefault--xh-_action-profile-gap
--xh-button-glint-durationrootanimation@media (hover: hover) and (pointer: fine) and (forced-colors: none)
disabled
hover
loading
material=liquid
not([data-disabled])
not([data-loading])
where([data-material='liquid'])
xh-action-variant=solid
--xh-motion-duration-glint
--xh-button-hrootblock-size
inline-size
default
xh-action-profile=icon
--xh-_action-profile-visual-size
--xh-button-icon-sizeroot--xh-icon-sizedefault--xh-_action-profile-glyph-size
--xh-button-pxrootpadding-inlinedefault--xh-_button-group-px
--xh-button-radiusrootborder-radiusdefault--xh-_button-radius
--xh-button-shadowrootbox-shadowdefaultnone
--xh-button-shadow-hoverrootbox-shadowdisabled
hover
loading
not([data-disabled])
not([data-loading])
none
--xh-button-spin-durationindicatoranimationdefault--xh-motion-loop-spin

Released under The MIT License