---
title: Countdown
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, TokensTable, PropsTable } from '../../src/components'
import { Box, Countdown } from '@telus-uds/components-web'
import { Countdown as WebDocs } from 'docs/@telus-uds/components-web'
import AvailableOnWebOnly from '../../partials/_platform-considerations-web-only.mdx'

# Countdown

<LibraryInfo
  packageType="Web Component"
  figmaLink="https://www.figma.com/file/4zJn2Qn6uXOqPP1GVDipy6/%F0%9F%8D%80-UDS-TELUS-Components?node-id=74498-204817&t=0jl8P0RnbmeTfoZ7-11"
/>

```jsx live
function DefaultCountdownExample() {
  const targetTime = new Date()
  targetTime.setDate(targetTime.getDate() + 10)

  return <Countdown targetTime={targetTime} />
}
```

## Introduction

The purpose of the `Countdown` component is to provide a dynamic display of time
remaining to a specific moment in the future.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

- Use `Countdown` to display time remaining to a specific moment
- Default variant of the `Countdown` will inherit text style of parent container
- Use `large` or `feature` variants to render a standalone component for visual emphasis
- `Countdown` is only responsive for XS breakpoint (keep in mind, however, that you may
  still need to adjust its props to make sure it does not exceed the smallest expected
  width)

:::caution

Note that the component will throw an exception if the target time provided is invalid.
If the time is in the past, the all-zero countdown will be displayed.
:::

### Accessibility

Currently, `Countdown` component is focusable for a11y purposes, it also allows
passing standard accessibility attributes via props.

### Platform considerations

<AvailableOnWebOnly />

## Props

<PropsTable web={WebDocs} />

## Tokens

<TokensTable web={WebDocs} component="Countdown" />

## Variants

### Feature

Use the `feature` variant in order to display a visually emphasized version of the `Countdown`:

```jsx live
function FeatureCountdownExample() {
  const targetTime = new Date()
  targetTime.setDate(targetTime.getDate() + 10)

  return <Countdown targetTime={targetTime} variant={{ feature: true }} />
}
```

### Inverse

Use the `inverse` variant to display the `Countdown` on darker backgrounds:

```jsx live
function InverseCountdownExample() {
  const targetTime = new Date()
  targetTime.setDate(targetTime.getDate() + 10)

  return (
    <Box variant={{ background: 'darkest' }} space={1}>
      <Countdown targetTime={targetTime} variant={{ inverse: true }} />
      <Countdown targetTime={targetTime} variant={{ inverse: true, large: true }} />
      <Countdown targetTime={targetTime} variant={{ inverse: true, feature: true }} />
    </Box>
  )
}
```

### Large

Set the `large` field on the `variant` prop to `true` in order to display a
larger version of the `Countdown`:

```jsx live
function LargeCountdownExample() {
  const targetTime = new Date()
  targetTime.setDate(targetTime.getDate() + 10)

  return <Countdown targetTime={targetTime} variant={{ large: true }} />
}
```

### Label

Use the `label` variant to annotate the numbers on the `Countdown`:

```jsx live
function LabelCountdownExample() {
  const targetTime = new Date()
  targetTime.setDate(targetTime.getDate() + 10)

  return (
    <StackView>
      <Box space={1}>
        <Countdown targetTime={targetTime} variant={{ label: true }} />
        <Countdown targetTime={targetTime} variant={{ label: true, large: true }} />
        <Countdown targetTime={targetTime} variant={{ feature: true, label: true }} />
      </Box>
      <Box variant={{ background: 'darkest' }} space={1}>
        <Countdown targetTime={targetTime} variant={{ inverse: true, label: true }} />
        <Countdown targetTime={targetTime} variant={{ inverse: true, label: true, large: true }} />
        <Countdown
          targetTime={targetTime}
          variant={{ inverse: true, feature: true, label: true }}
        />
      </Box>
    </StackView>
  )
}
```

### No divider

Use the `noDivider` variant to omit the colon delimiters on the `Countdown`:

```jsx live
function NoDividerCountdownExample() {
  const targetTime = new Date()
  targetTime.setDate(targetTime.getDate() + 10)

  return (
    <StackView>
      <Box space={1}>
        <Countdown targetTime={targetTime} variant={{ label: true, noDivider: true }} />
        <Countdown
          targetTime={targetTime}
          variant={{ label: true, large: true, noDivider: true }}
        />
        <Countdown
          targetTime={targetTime}
          variant={{ feature: true, label: true, noDivider: true }}
        />
      </Box>
      <Box variant={{ background: 'darkest' }} space={1}>
        <Countdown
          targetTime={targetTime}
          variant={{ inverse: true, label: true, noDivider: true }}
        />
        <Countdown
          targetTime={targetTime}
          variant={{ inverse: true, label: true, large: true, noDivider: true }}
        />
        <Countdown
          targetTime={targetTime}
          variant={{ inverse: true, feature: true, label: true, noDivider: true }}
        />
      </Box>
    </StackView>
  )
}
```

:::caution

Note that the component throws an exception if you're trying to use the `noDivider` variant without the `label` one,
and that is by design.
:::

### Hide fields

Use the `units` prop to render only specific units of time:

```jsx live
function hideFields() {
  const targetTime = new Date()
  targetTime.setDate(targetTime.getDate() + 10)

  return (
    <StackView>
      <Box space={1}>
        <Countdown
          targetTime={targetTime}
          variant={{ large: true, label: false, noDivider: true }}
          units={['days']}
        />
        <Countdown
          targetTime={targetTime}
          variant={{ label: true, large: true, noDivider: true }}
          units={['days', 'minutes']}
        />
        <Countdown
          targetTime={targetTime}
          variant={{ feature: true, label: true, noDivider: true }}
          units={['days', 'hours']}
        />
      </Box>
      <Box variant={{ background: 'darkest' }} space={1}>
        <Countdown
          targetTime={targetTime}
          variant={{ inverse: true, label: true, noDivider: true }}
          units={['minutes', 'seconds']}
        />
        <Countdown
          targetTime={targetTime}
          variant={{ inverse: true, label: true, large: true, noDivider: true }}
          units={['days']}
        />
        <Countdown
          targetTime={targetTime}
          variant={{ inverse: true, feature: true, label: true, noDivider: true }}
          units={['seconds']}
        />
      </Box>
    </StackView>
  )
}
```

## Feedback

<Feedback component="Countdown" />
