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

查看生态总览
Skip to content

FloatButton ​

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="float-button": root · trigger · list

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-float-button>
Vue componentsXhFloatButtonList XhFloatButtonRoot XhFloatButtonTrigger
ComposableuseFloatButton
State machinefloatButtonMachine
Skin@xihan-ui/styles/float-button.css

Props ​

PropTypeRequired
defaultOpenboolean
defaultPositionFloatButtonPosition
dirDirection
disabledboolean
draggableboolean
expandTriggerFloatButtonExpandTrigger
offsetnumber
onOpenChange(details: CollapsibleOpenChangeDetails) => void
onPositionChange(details: FloatButtonPositionChangeDetails) => void
openboolean
placementFloatButtonPlacement
positionFloatButtonPosition
sizeSize
snapFloatButtonSnap
toneTone
translationsPartial<FloatButtonTranslations>
variantActionVariant

Events ​

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

EventPayload
open-changeCollapsibleOpenChangeDetails
position-changeFloatButtonPositionChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhFloatButtonRootdefaultFloatButtonRootSlotProps

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
XhFloatButtonRootchildrenSlotChildren<FloatButtonRootSlotProps>

State ​

Public state is written to data-state.

PartValues
root'open' | 'closed'
trigger'open' | 'closed'
list'open' | 'closed'

The following names are internal to the state machine.

States: open · closed

Events: OPEN · CLOSE · TOGGLE · DISABLE · CONTROLLED.OPEN · CONTROLLED.CLOSE · PRESS.START · PRESS.END · DRAG.START · DRAG.MOVE · DRAG.END · CLICK.SWALLOW · VIEWPORT.RESIZE

Guards: isDisabled · isOpenControlled · canPress · canDrag

connect API ​

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

MemberType
openboolean
setOpen(next: boolean) => void
positionFloatButtonPosition | null
setPosition(next: FloatButtonPosition) => void
draggingboolean
getRootProps() => T['element']
getTriggerProps() => T['button']
getListProps() => 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 / Spacefloat-button.kbd.toggle
Enter / Spacefloat-button.kbd.press
Escapefloat-button.kbd.escape
Tab / Shift+Tabfloat-button.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
triggeraria-controlsid of the list part
triggeraria-expanded'true' | 'false'
triggeraria-labeltranslations.trigger
listaria-labelledbyid of the trigger part
listrole'group'

Style reference ​

Skin ​

@xihan-ui/styles/float-button.css is written against [data-scope="float-button"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-float-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-draggable'' (present only while the condition holds)
rootdata-dragging'' (present only while the condition holds)
rootdata-edgeedge?.edge
rootdata-moving'' (present only while the condition holds)
rootdata-placementfloatButtonPlacementOf(position, context.get('viewpor… | props.placement
rootdata-point'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-state'open' | 'closed'
rootdata-toneprops.tone
rootdata-variantprops.variant
triggerdata-disabled'' (present only while the condition holds)
triggerdata-pressed'' (present only while the condition holds)
triggerdata-state'open' | 'closed'
triggerdata-xh-action-control''
triggerdata-xh-action-display'always'
triggerdata-xh-action-profile'floating'
triggerdata-xh-action-sizeprops.size
triggerdata-xh-action-variantprops.variant
triggerdata-xh-ink-surface'' (present only while the condition holds)
triggerdata-xh-liquid''
triggerdata-xh-material'frosted' | undefined
listdata-instant'' (present only while the condition holds)
listdata-placementfloatButtonPlacementOf(position, context.get('viewpor… | props.placement
listdata-state'open' | 'closed'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-float-button-bglist
root
trigger
--xh-ink-surface
background-color
default
disabled
focus-visible
not([data-scope])
variant=outline
variant=subtle
xh-ink-surface
--xh-_action-variant-bg-disabled
--xh-_action-variant-bg-focus-visible
--xh-_action-variant-bg-rest
--xh-_float-button-bg
--xh-_material-bg
--xh-_material-bg-focus
--xh-float-button-bg-activelist
root
trigger
background-coloractive
disabled
is(:active, [data-pressed])
loading
not(:disabled)
not([data-disabled])
not([data-loading])
not([data-scope])
pressed
variant=outline
variant=subtle
--xh-_action-variant-bg-pressed
--xh-_float-button-bg-active
--xh-_material-bg-pressed
--xh-float-button-bg-hoverlist
root
trigger
background-color@media (hover: hover)
disabled
hover
loading
not(:disabled)
not([data-disabled])
not([data-loading])
not([data-scope])
variant=outline
variant=subtle
--xh-_action-variant-bg-hover
--xh-_float-button-bg-hover
--xh-_material-bg-hover
--xh-float-button-borderlist
root
trigger
border
border-color
default
disabled
focus-visible
not([data-scope])
variant=outline
--xh-_action-variant-border-disabled
--xh-_action-variant-border-focus-visible
--xh-_action-variant-border-rest
--xh-_float-button-border
--xh-_material-border
--xh-float-button-border-hoverlist
root
trigger
border-color@media (hover: hover)
disabled
hover
is(:active, [data-pressed])
loading
not(:disabled)
not([data-disabled])
not([data-loading])
not([data-scope])
pressed
variant=outline
--xh-_action-variant-border-hover
--xh-_action-variant-border-pressed
--xh-_float-button-border-hover
--xh-_material-border
--xh-float-button-fglist
root
trigger
colordefault
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
not([data-scope])
pressed
variant=outline
--xh-_action-variant-fg-focus-visible
--xh-_action-variant-fg-hover
--xh-_action-variant-fg-pressed
--xh-_action-variant-fg-rest
--xh-_float-button-fg
--xh-_material-fg
--xh-float-button-gaplist
root
gapdefault--xh-space-2
--xh-float-button-icon-sizeroot
trigger
--xh-icon-sizedefault--xh-_float-button-glyph-size
--xh-float-button-layerrootz-indexdefault--xh-_layer
--xh-float-button-radiuslist
trigger
border-radiusdefault--xh-_action-profile-radius
--xh-shape-circle
--xh-float-button-shadowlist
root
trigger
box-shadowdefault
disabled
focus-visible
hover
is(:active, [data-pressed])
is(:hover, [data-loading])
loading
not([data-disabled])
not([data-loading])
not([data-scope])
pressed
variant=outline
--xh-_float-button-shadow
--xh-_material-shadow
none
--xh-float-button-sizelist
root
trigger
block-size
bottom
inline-size
inset-block-end
inset-block-start
inset-inline-end
inset-inline-start
left
min-inline-size
top
default
edge=block
edge=inline
moving
placement
placement=-end
placement=-start
placement=bottom
placement=top
point
xh-action-profile=floating
--xh-_float-button-size

Released under The MIT License