Skip to content
UI

Timer

A component for displaying a countdown or stopwatch timer.

<script setup lang="ts">
import { Timer } from '@destyler-ui/vue'
</script>

<template>
  <Timer.Root :countdown="true" :auto-start="true" :start-ms="60000">
    <Timer.Area>
      <Timer.Item type="days" />
      <Timer.Separator>:</Timer.Separator>
      <Timer.Item type="hours" />
      <Timer.Separator>:</Timer.Separator>
      <Timer.Item type="minutes" />
      <Timer.Separator>:</Timer.Separator>
      <Timer.Item type="seconds" />
    </Timer.Area>
    <Timer.Control>
      <Timer.ActionTrigger action="start">START</Timer.ActionTrigger>
      <Timer.ActionTrigger action="pause">PAUSE</Timer.ActionTrigger>
      <Timer.ActionTrigger action="resume">RESUME</Timer.ActionTrigger>
      <Timer.ActionTrigger action="reset">RESET</Timer.ActionTrigger>
    </Timer.Control>
  </Timer.Root>
</template>
import { Timer } from '@destyler-ui/react'

export function Basic() {
  return (
    <Timer.Root countdown autoStart startMs={60000}>
      <Timer.Area>
        <Timer.Item type="days" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="hours" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="minutes" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="seconds" />
      </Timer.Area>
      <Timer.Control>
        <Timer.ActionTrigger action="start">START</Timer.ActionTrigger>
        <Timer.ActionTrigger action="pause">PAUSE</Timer.ActionTrigger>
        <Timer.ActionTrigger action="resume">RESUME</Timer.ActionTrigger>
        <Timer.ActionTrigger action="reset">RESET</Timer.ActionTrigger>
      </Timer.Control>
    </Timer.Root>
  )
}
import { Timer } from '@destyler-ui/solid/timer'

export function Basic() {
  return (
    <Timer.Root targetMs={60 * 60 * 1000}>
      <Timer.Area>
        <Timer.Item type="days" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="hours" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="minutes" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="seconds" />
      </Timer.Area>
      <Timer.Control>
        <Timer.ActionTrigger action="start">Play</Timer.ActionTrigger>
        <Timer.ActionTrigger action="resume">Resume</Timer.ActionTrigger>
        <Timer.ActionTrigger action="pause">Pause</Timer.ActionTrigger>
      </Timer.Control>
    </Timer.Root>
  )
}
<script lang="ts">
  import { Timer } from '@destyler-ui/svelte'
</script>

<Timer.Root countdown autoStart startMs={60000}>
  <Timer.Area>
    <Timer.Item type="days" />
    <Timer.Separator>:</Timer.Separator>
    <Timer.Item type="hours" />
    <Timer.Separator>:</Timer.Separator>
    <Timer.Item type="minutes" />
    <Timer.Separator>:</Timer.Separator>
    <Timer.Item type="seconds" />
  </Timer.Area>
  <Timer.Control>
    <Timer.ActionTrigger action="start">START</Timer.ActionTrigger>
    <Timer.ActionTrigger action="pause">PAUSE</Timer.ActionTrigger>
    <Timer.ActionTrigger action="resume">RESUME</Timer.ActionTrigger>
    <Timer.ActionTrigger action="reset">RESET</Timer.ActionTrigger>
  </Timer.Control>
</Timer.Root>
<script setup lang="ts">
import { Timer } from '@destyler-ui/vue'
</script>
<template>
<Timer.Root>
<Timer.Area>
<Timer.Item />
<Timer.Separator />
</Timer.Area>
<Timer.Control>
<Timer.ActionTrigger />
</Timer.Control>
</Timer.Root>
</template>
import { Timer } from '@destyler-ui/react'
export default function Basic() {
return (
<Timer.Root>
<Timer.Area>
<Timer.Item />
<Timer.Separator />
</Timer.Area>
<Timer.Control>
<Timer.ActionTrigger />
</Timer.Control>
</Timer.Root>
)
}
import { Timer } from '@destyler-ui/solid'
export default function Basic() {
return (
<Timer.Root>
<Timer.Area>
<Timer.Item type="seconds" />
<Timer.Separator />
</Timer.Area>
<Timer.Control>
<Timer.ActionTrigger action="start">Start</Timer.ActionTrigger>
</Timer.Control>
</Timer.Root>
)
}
<script lang="ts">
import { Timer } from '@destyler-ui/svelte'
</script>
<Timer.Root countdown autoStart startMs={60000}>
<Timer.Area>
<Timer.Item type="days" />
<Timer.Separator>:</Timer.Separator>
<Timer.Item type="hours" />
<Timer.Separator>:</Timer.Separator>
<Timer.Item type="minutes" />
<Timer.Separator>:</Timer.Separator>
<Timer.Item type="seconds" />
</Timer.Area>
<Timer.Control>
<Timer.ActionTrigger action="start">START</Timer.ActionTrigger>
<Timer.ActionTrigger action="pause">PAUSE</Timer.ActionTrigger>
<Timer.ActionTrigger action="resume">RESUME</Timer.ActionTrigger>
<Timer.ActionTrigger action="reset">RESET</Timer.ActionTrigger>
</Timer.Control>
</Timer.Root>
<script setup lang="ts">
import { Timer } from '@destyler-ui/vue'
</script>

<template>
  <Timer.Root :countdown="true" :auto-start="true" :start-ms="60000">
    <Timer.Area>
      <Timer.Item type="days" />
      <Timer.Separator>:</Timer.Separator>
      <Timer.Item type="hours" />
      <Timer.Separator>:</Timer.Separator>
      <Timer.Item type="minutes" />
      <Timer.Separator>:</Timer.Separator>
      <Timer.Item type="seconds" />
    </Timer.Area>
    <Timer.Control>
      <Timer.ActionTrigger action="start">START</Timer.ActionTrigger>
      <Timer.ActionTrigger action="pause">PAUSE</Timer.ActionTrigger>
      <Timer.ActionTrigger action="resume">RESUME</Timer.ActionTrigger>
      <Timer.ActionTrigger action="reset">RESET</Timer.ActionTrigger>
    </Timer.Control>
  </Timer.Root>
</template>
import { Timer } from '@destyler-ui/react'

export function Basic() {
  return (
    <Timer.Root countdown autoStart startMs={60000}>
      <Timer.Area>
        <Timer.Item type="days" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="hours" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="minutes" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="seconds" />
      </Timer.Area>
      <Timer.Control>
        <Timer.ActionTrigger action="start">START</Timer.ActionTrigger>
        <Timer.ActionTrigger action="pause">PAUSE</Timer.ActionTrigger>
        <Timer.ActionTrigger action="resume">RESUME</Timer.ActionTrigger>
        <Timer.ActionTrigger action="reset">RESET</Timer.ActionTrigger>
      </Timer.Control>
    </Timer.Root>
  )
}
import { Timer } from '@destyler-ui/solid/timer'

export function Basic() {
  return (
    <Timer.Root targetMs={60 * 60 * 1000}>
      <Timer.Area>
        <Timer.Item type="days" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="hours" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="minutes" />
        <Timer.Separator>:</Timer.Separator>
        <Timer.Item type="seconds" />
      </Timer.Area>
      <Timer.Control>
        <Timer.ActionTrigger action="start">Play</Timer.ActionTrigger>
        <Timer.ActionTrigger action="resume">Resume</Timer.ActionTrigger>
        <Timer.ActionTrigger action="pause">Pause</Timer.ActionTrigger>
      </Timer.Control>
    </Timer.Root>
  )
}
<script lang="ts">
  import { Timer } from '@destyler-ui/svelte'
</script>

<Timer.Root countdown autoStart startMs={60000}>
  <Timer.Area>
    <Timer.Item type="days" />
    <Timer.Separator>:</Timer.Separator>
    <Timer.Item type="hours" />
    <Timer.Separator>:</Timer.Separator>
    <Timer.Item type="minutes" />
    <Timer.Separator>:</Timer.Separator>
    <Timer.Item type="seconds" />
  </Timer.Area>
  <Timer.Control>
    <Timer.ActionTrigger action="start">START</Timer.ActionTrigger>
    <Timer.ActionTrigger action="pause">PAUSE</Timer.ActionTrigger>
    <Timer.ActionTrigger action="resume">RESUME</Timer.ActionTrigger>
    <Timer.ActionTrigger action="reset">RESET</Timer.ActionTrigger>
  </Timer.Control>
</Timer.Root>

Root

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

autoStartfalse | true

Whether the timer should start automatically

countdownfalse | true

Whether the timer should countdown, decrementing the timer on each tick.

idstring

The unique identifier of the machine.

idsPartial<{ root: string; area: string; }>

The ids of the timer parts

interval250number

The interval in milliseconds to update the timer count.

startMsnumber

The total duration of the timer in milliseconds.

targetMsnumber

The minimum count of the timer in milliseconds.

EmitEvent
complete[]

Function invoked when the timer is completed

tick[details: TickDetails]

Function invoked when the timer ticks

ActionTrigger

PropDefaultType
action*TimerAction
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Area

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Context

No serializable props or emits are declared for this part.

Control

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Item

PropDefaultType
type*keyof Time<number>
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

RootProvider

PropDefaultType
value*MachineApi<PropTypes>
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Separator

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Root

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

autoStartfalse | true

Whether the timer should start automatically

countdownfalse | true

Whether the timer should countdown, decrementing the timer on each tick.

idsPartial<{ root: string; area: string; }>

The ids of the timer parts

interval250number

The interval in milliseconds to update the timer count.

onComplete() => void

Function invoked when the timer is completed

onTick(details: timer.TickDetails) => void

Function invoked when the timer ticks

startMsnumber

The total duration of the timer in milliseconds.

targetMsnumber

The minimum count of the timer in milliseconds.

ActionTrigger

PropDefaultType
action*TimerAction
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Area

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Context

PropDefaultType
children*(context: UseTimerContext) => ReactNode

Control

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Item

PropDefaultType
type*keyof Time<number>
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

RootProvider

PropDefaultType
value*UseTimerReturn
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Separator

PropDefaultType
asChildfalse | true

Use the provided child element as the default rendered element, combining their props and behavior.

Root

PropDefaultType
asChild(props: (userProps?: solid_js295.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

autoStartfalse | true

Whether the timer should start automatically

countdownfalse | true

Whether the timer should countdown, decrementing the timer on each tick.

idsPartial<{ root: string; area: string; }>

The ids of the timer parts

interval250number

The interval in milliseconds to update the timer count.

onComplete() => void

Function invoked when the timer is completed

onTick(details: TickDetails) => void

Function invoked when the timer ticks

startMsnumber

The total duration of the timer in milliseconds.

targetMsnumber

The minimum count of the timer in milliseconds.

ActionTrigger

PropDefaultType
action*TimerAction
asChild(props: (userProps?: solid_js295.JSX.ButtonHTMLAttributes<HTMLButtonElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Area

PropDefaultType
asChild(props: (userProps?: solid_js295.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Context

PropDefaultType
children*(context: UseTimerContext) => Element

Control

PropDefaultType
asChild(props: (userProps?: solid_js295.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Item

PropDefaultType
type*keyof Time<number>
asChild(props: (userProps?: solid_js295.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

RootProvider

PropDefaultType
value*UseTimerReturn
asChild(props: (userProps?: solid_js295.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Separator

PropDefaultType
asChild(props: (userProps?: solid_js295.JSX.HTMLAttributes<HTMLDivElement> | undefined) => JSX.HTMLAttributes<any>) => JSX.Element

Use the provided child element as the default rendered element, combining their props and behavior.

Root

PropDefaultType
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
autoStartfalse | true

Whether the timer should start automatically

childrenSnippet<[]> | undefined
countdownfalse | true

Whether the timer should countdown, decrementing the timer on each tick.

idstring
idsPartial<{ root: string; area: string; }>

The ids of the timer parts

interval250number

The interval in milliseconds to update the timer count.

onComplete() => void

Function invoked when the timer is completed

onTick(details: import("/home/runner/work/ui/ui/packages/svelte/dist/index").TimerTickDetails) => void

Function invoked when the timer ticks

startMsnumber

The total duration of the timer in milliseconds.

targetMsnumber

The minimum count of the timer in milliseconds.

ActionTrigger

PropDefaultType
action*TimerAction
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"button">]>
childrenSnippet<[]> | undefined

Area

PropDefaultType
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined

Context

PropDefaultType
apiSnippet<[UseTimerContext]>

Control

PropDefaultType
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined

Item

PropDefaultType
type*keyof Time<number>
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined

RootProvider

PropDefaultType
value*UseTimerReturn
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined

Separator

PropDefaultType
asChildimport("svelte").Snippet<[import("/home/runner/work/ui/ui/packages/svelte/dist/types").PropsFn<"div">]>
childrenSnippet<[]> | undefined