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

查看生态总览
Skip to content

Timer ​

Data display 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="timer": root · display · item · separator · control

API reference ​

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

Artifacts ​

LayerValue
Custom element<xh-timer>
Vue componentsXhTimerControl XhTimerDisplay XhTimerItem XhTimerRoot XhTimerSeparator
ComposableuseTimer
State machinetimerMachine
Skin@xihan-ui/styles/timer.css

Props ​

PropTypeRequired
startMsnumber
targetMsnumber
countdownboolean
valuenumber
activeboolean
autoStartboolean
intervalnumber
formatstring
precisionnumber
liveTimerLive
sizeSize
translationsPartial<TimerTranslations>
onTick(details: TimerTickDetails) => void
onComplete(details: TimerCompleteDetails) => void

Events ​

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

EventPayload
tickTimerTickDetails
completeTimerCompleteDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhTimerRootdefaultTimerRootSlotProps

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
XhTimerItemunitTimerUnitYes
XhTimerRootchildrenSlotChildren<TimerRootSlotProps>

State ​

Public state is written to data-state.

PartValues
root'idle' | 'running' | 'paused' | 'completed'
display'idle' | 'running' | 'paused' | 'completed'

The following names are internal to the state machine.

States: idle · running · paused · completed

Events: RUN.START · RUN.PAUSE · RUN.RESUME · RUN.RESET · CLOCK.TICK · CLOCK.SETTLE · CLOCK.SYNC · PRESS.START · PRESS.END

Guards: isSettled

connect API ​

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

MemberType
phaseTimerPhase
valuenumber
textstring
controlledboolean
elapsednumber
runningboolean
pausedboolean
completedboolean
countdownboolean
segmentsTimerSegments
segmentText(unit: TimerUnit) => string
controlActionTimerControlAction
controlLabelstring
start() => void
pause() => void
resume() => void
reset() => void
getRootProps() => T['element']
getDisplayProps() => T['element']
getItemProps(props: TimerItemProps) => T['element']
getSeparatorProps() => T['element']
getControlProps() => T['button']

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 / Spacetimer.kbd.control
Enter / Spacetimer.kbd.press

ARIA ​

These attributes are produced by connect.

PartAttributeValue
displayaria-labellabel.time(segments)
displayaria-liveprops.live
displayrole'timer'
itemaria-hidden'true'
separatoraria-hidden'true'
controlaria-labellabel[controlAction]

Style reference ​

Skin ​

@xihan-ui/styles/timer.css is written against [data-scope="timer"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-timer 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-controlled'' (present only while the condition holds)
rootdata-countdown'' (present only while the condition holds)
rootdata-sizeprops.size
rootdata-state'idle' | 'running' | 'paused' | 'completed'
displaydata-state'idle' | 'running' | 'paused' | 'completed'
itemdata-unititem.unit
controldata-action'pause' | 'resume' | 'reset' | 'start'
controldata-pressed'' (present only while the condition holds)
controldata-xh-action-control''
controldata-xh-action-display'always'
controldata-xh-action-profile'text'
controldata-xh-action-sizeprops.size
controldata-xh-action-variant'outline'

CSS variables ​

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

VariablePartCSS propertyStateDefault from
--xh-timer-completed-fgdisplaycolorstate=completed--xh-fg-muted
--xh-timer-control-bgcontrol--xh-ink-surface
background-color
default
xh-ink-surface
--xh-_action-variant-bg-rest
--xh-timer-control-bg-activecontrolbackground-colordisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-bg-pressed
--xh-timer-control-bg-disabledcontrol--xh-ink-surface
background-color
disabled
xh-ink-surface
--xh-_action-variant-bg-disabled
--xh-timer-control-bg-hovercontrolbackground-colordisabled
hover
loading
not([data-disabled])
not([data-loading])
--xh-_action-variant-bg-hover
--xh-timer-control-bordercontrolborderdefault--xh-_action-variant-border-rest
--xh-timer-control-border-disabledcontrolborder-colordisabled--xh-_action-variant-border-disabled
--xh-timer-control-border-focuscontrolborder-colorfocus-visible--xh-_action-variant-border-focus-visible
--xh-timer-control-border-hovercontrolborder-colordisabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-border-hover
--xh-_action-variant-border-pressed
--xh-timer-control-fgcontrolcolordefault
disabled
hover
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
--xh-_action-variant-fg-hover
--xh-_action-variant-fg-pressed
--xh-_action-variant-fg-rest
--xh-timer-control-gapcontrolgapdefault--xh-_action-profile-gap
--xh-timer-control-hcontrolblock-sizedefault--xh-_action-profile-visual-size
--xh-timer-control-pxcontrolpadding-inlinedefault--xh-_action-profile-padding-inline
--xh-timer-control-radiuscontrolborder-radiusdefault--xh-shape-control
--xh-timer-control-shadow-activecontrolbox-shadowdisabled
is(:active, [data-pressed])
loading
not([data-disabled])
not([data-loading])
pressed
none
--xh-timer-control-shadow-hovercontrolbox-shadowdisabled
hover
loading
not([data-disabled])
not([data-loading])
none
--xh-timer-digit-font-sizedisplayfont-sizedefault--xh-_timer-digit-size
--xh-timer-display-fgdisplaycolordefault--xh-fg-default
--xh-timer-fgrootcolordefault--xh-fg-default
--xh-timer-gaprootgapdefault--xh-_timer-gap
--xh-timer-icon-sizecontrol--xh-icon-sizedefault--xh-_action-profile-glyph-size
--xh-timer-item-fgitemcolordefaultinherit
--xh-timer-separator-fgseparatorcolordefault--xh-fg-subtle
--xh-timer-separator-pxseparatorpadding-inlinedefault--xh-space-0_5

Released under The MIT License