Back to Shark UI

Timer

docs/components/timer

latest12.0 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Timer

Copy Markdown

Countdown or stopwatch with controls.

DocsAPI

PreviewCode

00

Days

:

00

Hours

:

00

Minutes

:

00

Seconds

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/timer

Anatomy#

Timer
├── TimerArea
│ ├── TimerItemGroup
│ │ ├── TimerItem
│ │ └── TimerItemLabel
│ ├── TimerSeparator
└── TimerControl
    ├── TimerActionTrigger
    ├── TimerStart
    ├── TimerPause
    ├── TimerResume
    ├── TimerReset
    ├── TimerRestart
    └── TimerPlay

Usage#

import {
  Timer,
  TimerArea,
  TimerItem,
  TimerItemGroup,
  TimerItemLabel,
  TimerSeparator,
  TimerControl,
  TimerActionTrigger,
  TimerStart,
  TimerPause,
  TimerResume,
  TimerReset,
  TimerRestart,
  TimerPlay,
} from "@/components/ui/timer";
<Timer targetMs={3600000} startMs={2400000}>
  <TimerArea>
    <TimerItemGroup>
      <TimerItem type="hours" />
      <TimerItemLabel>Hours</TimerItemLabel>
    </TimerItemGroup>
    <TimerSeparator />
    <TimerItemGroup>
      <TimerItem type="minutes" />
      <TimerItemLabel>Minutes</TimerItemLabel>
    </TimerItemGroup>
    <TimerSeparator />
    <TimerItemGroup>
      <TimerItem type="seconds" />
      <TimerItemLabel>Seconds</TimerItemLabel>
    </TimerItemGroup>
  </TimerArea>
  <TimerControl>
    <TimerPlay>Go</TimerPlay>
    <TimerPause>Pause</TimerPause>
    <TimerReset>Reset</TimerReset>
  </TimerControl>
</Timer>

Controlled#

Handle onTick and onComplete to react to timer progress and completion.

PreviewCode

Ticks: 0

00

Minutes

:

00

Seconds

Orientation#

Use the orientation prop on TimerItemGroup to change the orientation of the timer.

Vertical#

PreviewCode

05

minutes

:

00

seconds

Horizontal#

PreviewCode

05

minutes

:

00

seconds

Examples#

Countdown#

Create a countdown by setting countdown to true and startMs to the initial duration.

PreviewCode

05

minutes

:

00

seconds

Date-based#

Use remainingMsUntilDate to derive startMs from a calendar date.

PreviewCode

Until Jul 9, 2026

06

days

:

23

hours

:

59

minutes

:

59

seconds

Interval#

Use the interval prop to control update frequency.

PreviewCode

00

seconds

:

000

ms

Pomodoro#

Alternate between work and break sessions using onComplete.

PreviewCode

🍅

25

:

00

Focus

Trigger Behavior

Triggers hide when their action is not available. To keep a control in the layout, pass hidden={false}.

Custom separator#

Pass children to TimerSeparator to override the default colon (:).

PreviewCode

05

//

00

API Reference#

Timer#

Root component. Runs a stopwatch or countdown and provides timer state to child parts.

PropTypeDefault
targetMsnumber0
startMsnumber0
countdownbooleanfalse
intervalnumber1000
autoStartbooleanfalse
onTick(details: TickDetails) => void-
onComplete() => void-

TimerArea#

Live region that exposes the formatted time to assistive tech and lays out digit groups.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TimerItemGroup#

Groups a TimerItem with its TimerItemLabel and sets stack direction via orientation.

PropTypeDefault
orientation`"horizontal""vertical"`
classNamestring-
asChildbooleanfalse

TimerItemLabel#

Caption for the adjacent TimerItem (for example, “minutes”).

PropTypeDefault
classNamestring-
asChildbooleanfalse

TimerItem#

Renders one time field from the current timer value.

PropTypeDefault
type`"days""hours"
asChildbooleanfalse

TimerSeparator#

Visual delimiter between item groups (defaults to : when children are omitted).

PropTypeDefault
classNamestring-
asChildbooleanfalse

TimerControl#

Toolbar row for timer action controls.

PropTypeDefault
classNamestring-
asChildbooleanfalse

TimerActionTrigger#

Button that dispatches a timer action.

PropTypeDefault
action`"start""pause"
hiddenboolean-
asChildbooleanfalse

TimerStart#

Starts the timer. Wraps TimerActionTrigger with action="start".

PropTypeDefault
hiddenboolean-
classNamestring-
asChildbooleanfalse

TimerPause#

Pauses a running timer. Wraps TimerActionTrigger with action="pause".

PropTypeDefault
hiddenboolean-
classNamestring-
asChildbooleanfalse

TimerResume#

Resumes from paused. Wraps TimerActionTrigger with action="resume".

PropTypeDefault
hiddenboolean-
classNamestring-
asChildbooleanfalse

TimerReset#

Resets the timer to its initial startMs / idle state.

PropTypeDefault
hiddenboolean-
classNamestring-
asChildbooleanfalse

TimerRestart#

Restarts the timer. Wraps TimerActionTrigger with action="restart".

PropTypeDefault
hiddenboolean-
classNamestring-
asChildbooleanfalse

TimerPlay#

Shorthand for a single "go" control: renders TimerResume when the timer is paused, otherwise TimerStart.

PropTypeDefault
hiddenboolean-
classNamestring-
asChildbooleanfalse

remainingMsUntilDate#

ParameterType
dateDate

Returns a number of milliseconds until date, or 0 if date is in the past.


For a complete list of props, see the Ark UI documentation.

[

Previous page

Textarea ](/docs/components/textarea)[

Next page

Toast ](/docs/components/toast)

On This Page

InstallationAnatomyUsageControlledOrientationVerticalHorizontalExamplesCountdownDate-basedIntervalPomodoroCustom separatorAPI ReferenceTimerTimerAreaTimerItemGroupTimerItemLabelTimerItemTimerSeparatorTimerControlTimerActionTriggerTimerStartTimerPauseTimerResumeTimerResetTimerRestartTimerPlayremainingMsUntilDate