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

查看生态总览
Skip to content

Clipboard ​

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="clipboard": root · label · control · input · copy-trigger · indicator · status

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-clipboard>
Vue componentsXhClipboardControl XhClipboardCopyTrigger XhClipboardIndicator XhClipboardInput XhClipboardLabel XhClipboardRoot XhClipboardStatus
ComposableuseClipboard
State machineclipboardMachine
Skin@xihan-ui/styles/clipboard.css

Props ​

PropTypeRequired
labelledboolean
valuestring
timeoutnumber
disabledboolean
variantActionVariant
toneTone
sizeSize
translationsPartial<ClipboardTranslations>
onStatusChange(details: ClipboardStatusChangeDetails) => void
onCopyError(details: ClipboardCopyErrorDetails) => void

Events ​

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

EventPayload
status-changeClipboardStatusChangeDetails
copy-errorClipboardCopyErrorDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhClipboardRootdefaultClipboardRootSlotProps

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
XhClipboardIndicatorcopiedboolean
XhClipboardRootchildrenSlotChildren<ClipboardRootSlotProps>

State ​

Public state is written to data-state.

PartValues
root'idle' | 'copying' | 'copied'
label'idle' | 'copying' | 'copied'
control'idle' | 'copying' | 'copied'
input'idle' | 'copying' | 'copied'
copy-trigger'idle' | 'copying' | 'copied'
indicator'idle' | 'copying' | 'copied'
status'idle' | 'copying' | 'copied'

The following names are internal to the state machine.

States: idle · copying · copied

Events: COPY.TRIGGER · COPY.SUCCESS · COPY.ERROR · after.timeout · PRESS.START · PRESS.END

Guards: isDisabled · canPress

connect API ​

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

MemberType
statusClipboardStatus
disabledboolean
announcementstring
copiedboolean
valuestring
copy() => void
getRootProps() => T['element']
getLabelProps() => T['label']
getControlProps() => T['element']
getInputProps() => T['input']
getCopyTriggerProps() => T['button']
getIndicatorProps(props: ClipboardIndicatorProps) => T['element']
getStatusProps() => 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 / Spaceclipboard.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
inputaria-labelledbyid of the label part | undefined
copy-triggeraria-busy'true' | undefined
copy-triggeraria-disabled'true' | undefined
copy-triggeraria-labeltranslations.copy
indicatoraria-hiddenindicator.copied !== copied || undefined
statusaria-atomic'true'
statusaria-live'polite'
statusrole'status'

Style reference ​

Skin ​

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

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-clipboard-control-active-layercontrol
copy-trigger
input
z-indexfocus-visible
focus-within
hover
1
--xh-clipboard-control-gapcontrolgapdefault0
--xh-clipboard-control-min-wrootmin-inline-sizehas([data-scope='clipboard'][data-part='control'])--xh-control-min-w
--xh-clipboard-control-wrootinline-size
min-inline-size
has([data-scope='clipboard'][data-part='control'])--xh-control-w
--xh-clipboard-copy-trigger-attached-radiuscontrol
copy-trigger
border-end-end-radius
border-start-end-radius
not(:first-child)--xh-clipboard-input-radius
--xh-clipboard-copy-trigger-bgcopy-trigger--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-clipboard-copy-trigger-bg-activecopy-triggerbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-clipboard-copy-trigger-bg-disabledcopy-trigger--xh-ink-surface
background-color
disabled
xh-ink-surface
--xh-_action-variant-bg-disabled
--xh-clipboard-copy-trigger-bg-hovercopy-triggerbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-clipboard-copy-trigger-bordercontrol
copy-trigger
border
border-color
default
focus-visible
not(:first-child)
--xh-_action-variant-border-focus-visible
--xh-_action-variant-border-rest
--xh-border-control
--xh-clipboard-copy-trigger-border-disabledcopy-triggerborder-colordisabled--xh-_action-variant-border-disabled
--xh-clipboard-copy-trigger-border-hovercontrol
copy-trigger
border-colordisabled
hover
is(:active, [data-pressed])
loading
not(:first-child)
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-border-hover
--xh-_action-variant-border-pressed
--xh-border-control-hover
--xh-clipboard-copy-trigger-fgcopy-triggerborder
border-color
color
@media (prefers-reduced-motion: reduce)
@media print
copied
default
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
motion=reduce
not([data-disabled])
not([data-loading])
pressed
where([data-motion='reduce'])
xh-action-variant=solid
xh-loading-ring
xh-loading-ring=overlay
--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-clipboard-copy-trigger-fg-copiedcopy-triggercolorcopied
disabled
focus-visible
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-fg-success
--xh-clipboard-copy-trigger-font-sizecopy-triggerfont-sizedefault--xh-_clipboard-font-size
--xh-clipboard-copy-trigger-font-weightcopy-triggerfont-weightdefault--xh-text-label-weight
--xh-clipboard-copy-trigger-gapcopy-trigger
indicator
gapdefault--xh-control-gap-sm
--xh-clipboard-copy-trigger-hcopy-triggerblock-sizedefault--xh-_clipboard-h
--xh-clipboard-copy-trigger-pxcopy-triggerpadding-inlinedefault--xh-_clipboard-px
--xh-clipboard-copy-trigger-radiuscopy-triggerborder-radiusdefault--xh-shape-control
--xh-clipboard-copy-trigger-shadow-hovercopy-triggerbox-shadowdisabled
hover
loading
not([data-disabled])
not([data-loading])
none
--xh-clipboard-gaplabel
root
gap
margin-block-end
default--xh-space-1
--xh-clipboard-indicator-fg-copiedindicatorcolorcopied--xh-fg-success
--xh-clipboard-indicator-gapindicatorgapdefault--xh-clipboard-copy-trigger-gap
--xh-clipboard-input-autofill-bginputbox-shadow-webkit-autofill
autofill
--xh-bg-subtle-opaque
--xh-clipboard-input-autofill-fginput-webkit-text-fill-color-webkit-autofill
autofill
--xh-fg-default
--xh-clipboard-input-bginputbackgrounddefault--xh-bg-subtle
--xh-clipboard-input-bg-focusinputbackgroundfocus-within--xh-bg-surface
--xh-clipboard-input-borderinputborderdefault--xh-border-control
--xh-clipboard-input-border-focusinputborder-color
box-shadow
focus-within--xh-border-control-focus
--xh-clipboard-input-fginputcolordefault--xh-fg-default
--xh-clipboard-input-font-sizeinputfont-sizedefault--xh-text-body-size
--xh-clipboard-input-hinputblock-sizedefault--xh-_clipboard-h
--xh-clipboard-input-pxinputpadding-inlinedefault--xh-_clipboard-px
--xh-clipboard-input-radiuscontrol
copy-trigger
input
border-end-end-radius
border-radius
border-start-end-radius
default
not(:first-child)
--xh-shape-control
--xh-clipboard-label-fglabelcolordefault--xh-fg-muted
--xh-clipboard-label-font-sizelabelfont-sizedefault--xh-text-label-size
--xh-clipboard-label-font-weightlabelfont-weightdefault--xh-text-label-weight
--xh-clipboard-label-gaplabelmargin-block-enddefault--xh-space-2
--xh-clipboard-loading-durationcopy-triggeranimationxh-loading-ring--xh-motion-loop-spin

Released under The MIT License