@molecule/app-countdown-vue

Feature · countdown · App (browser) · v1.1.1 · Apache-2.0

useCountdown hook + Countdown component for time-to-event displays

npm install @molecule/app-countdown-vue

npm · Source on GitHub

How it works

@molecule/app-countdown-vue is a ready-made countdown feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { defineComponent, h } from 'vue'
import { Countdown } from '@molecule/app-countdown-vue'

const Sale = defineComponent({
  setup() {
    return () =>
      h(Countdown, {
        // Compact default: "3d 4h 12m 5s"
        target: '2026-12-31T23:59:59Z',
        expired: h('span', null, 'Sale ended!'),
      })
  },
})

// Colon format: "03:04:12:05"
h(Countdown, { target: new Date('2026-12-31'), format: 'colon' })

// Long format: "3 days 4 hours 12 minutes 5 seconds"
h(Countdown, { target: Date.now() + 3_600_000, format: 'long' })

Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue

Reference

Vue time-remaining countdown — the counterpart of @molecule/app-countdown-react: the same exports, the same props (React names) and the same DOM for the same input.

Exports:

  • useCountdown(target, tickMs?) — live state composable.
  • <Countdown> — display component with compact/long/colon formats and custom render.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { defineComponent, h } from 'vue'
import { Countdown } from '@molecule/app-countdown-vue'

const Sale = defineComponent({
  setup() {
    return () =>
      h(Countdown, {
        // Compact default: "3d 4h 12m 5s"
        target: '2026-12-31T23:59:59Z',
        expired: h('span', null, 'Sale ended!'),
      })
  },
})

// Colon format: "03:04:12:05"
h(Countdown, { target: new Date('2026-12-31'), format: 'colon' })

// Long format: "3 days 4 hours 12 minutes 5 seconds"
h(Countdown, { target: Date.now() + 3_600_000, format: 'long' })

Type

feature

Installation

npm install @molecule/app-countdown-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

API

Interfaces

CountdownState

Snapshot of time remaining until a target date.

interface CountdownState {
  /** Days remaining. */
  days: number
  /** Hours (0-23) within current day. */
  hours: number
  /** Minutes (0-59) within current hour. */
  minutes: number
  /** Seconds (0-59) within current minute. */
  seconds: number
  /** Total milliseconds remaining (negative if past). */
  msRemaining: number
  /** True once `target` is in the past. */
  expired: boolean
}

CountdownProps

Props accepted by the Countdown component — React's prop names.

Node-valued props (render's result, expired) arrive as VNodes; expired may also be passed as the same-named slot.

interface CountdownProps {
  /** Target date / ISO string / epoch ms. */
  target: Date | string | number
  /** Display format. Defaults to `'compact'`. */
  format?: 'compact' | 'long' | 'colon'
  /** Renderer override — receives the live state for full control. */
  render?: (state: CountdownState) => VNodeChild
  /** Optional rendered when the timer expires. */
  expired?: VNodeChild
  /** Extra classes. */
  className?: string
}

Functions

useCountdown(target, tickMs)

Live-updating countdown to a target date, React's useCountdown in Vue's idiom: the target and interval may each be a plain value or a reactive source (a ref or getter), and the composable follows a changed source on the same mount — a component re-rendering with a new target prop behaves as React's hook does.

function useCountdown(
  target: MaybeRefOrGetter<Date | string | number>,
  tickMs?: MaybeRefOrGetter<number | undefined>,
): {
  /** Days remaining. */
  days: ComputedRef<number>
  /** Hours (0-23) within current day. */
  hours: ComputedRef<number>
  /** Minutes (0-59) within current hour. */
  minutes: ComputedRef<number>
  /** Seconds (0-59) within current minute. */
  seconds: ComputedRef<number>
  /** Total milliseconds remaining (negative if past). */
  msRemaining: ComputedRef<number>
  /** True once the target is in the past. */
  expired: ComputedRef<boolean>
}
  • target — Date / ISO string / epoch ms.
  • tickMs — Refresh interval. Defaults to 1000; 0 or less disables it.

Returns: The live countdown fields — one computed read-only ref per value.

Constants

Countdown

Live countdown display with three default formats:

  • 'compact' — 3d 4h 12m 5s (skips zero leading units)
  • 'long' — 3 days 4 hours 12 minutes 5 seconds
  • 'colon' — 03:04:12:05

Pass render for full control over markup. Once the target has passed and an expired node was given, that node renders instead of the display.

const Countdown: DefineComponent<
  ExtractPropTypes<{
    target: { type: PropType<Date | string | number>; required: true }
    format: { type: PropType<'compact' | 'long' | 'colon'>; default: string }
    render: PropType<CountdownProps['render']>
    expired: null
    className: StringConstructor
  }>,
  () => VNodeChild,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      target: { type: PropType<Date | string | number>; required: true }
      format: { type: PropType<'compact' | 'long' | 'colon'>; default: string }
      render: PropType<CountdownProps['render']>
      expired: null
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  { format: 'compact' | 'long' | 'colon' },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (see CountdownProps).

Returns: The rendered countdown.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.5.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui
  • @molecule/app-ui-vue
  • @molecule/app-vue
  • vue

The built-in 'compact' and 'long' formats hardcode English unit labels and pluralization ("3d 4h", "3 days 4 hours") — there is no locale bond. For localized apps use the render prop with the useCountdown state and compose translated units via t() (or Intl.RelativeTimeFormat). expired only swaps the rendering once the target passes — schedule side effects (redirects, refetches) from useCountdown().expired in a watcher, not from the component.