---
title: "Countdown"
description: "Обратный отсчёт с настраиваемыми параметрами."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/countdown"
---
# Countdown

> Обратный отсчёт с настраиваемыми параметрами.

## Использование

Пропс `seconds` задаёт число секунд для Countdown.

```vue
<template>
  <B24Countdown :seconds="120" />
</template>
```

### Показ минут

Свойство `show-minutes` показывает или скрывает минуты в Countdown. По умолчанию `true`.

```vue
<template>
  <B24Countdown :show-minutes="false" :seconds="120" />
</template>
```

### Размер

Пропс `size` меняет размер Countdown.

```vue
<template>
  <B24Countdown size="xl" :seconds="120" />
</template>
```

### Круг

Свойство `useCircle` рисует вокруг Countdown круг (`circle`).

```vue
<template>
  <B24Countdown use-circle :seconds="120" size="xl" />
</template>
```

### Иконка

Пропс `icon` показывает [иконку](https://bitrix24.github.io/b24icons/icons/).

```vue
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>

<template>
  <B24Countdown :icon="RocketIcon" :seconds="120" size="xl" />
</template>
```

### Аватар

Пропс `avatar` показывает [аватар](https://b24-ui.bx-shef.by/raw/docs/components/avatar.md).

```vue
<template>
  <B24Countdown :avatar="{src:'/b24ui/avatar/employee.png',loading:'lazy'}" :seconds="120" size="xl" />
</template>
```

## Примеры

### Отображаемая информация

Слот по умолчанию позволяет управлять отображаемой информацией.

```vue [CountdownInformationDisplayedExample.vue]
<script setup lang="ts">
import { ref } from 'vue'

const value = ref(2 * 24 * 60 * 60)
</script>

<template>
  <B24Countdown
    v-slot="{ days, hours, minutes, seconds }"
    :seconds="value"
  >
    Осталось：{{ days }} дн., {{ hours }} ч, {{ minutes }} мин, {{ seconds }} с.
  </B24Countdown>
</template>
```

### С интервалом

Интервал отсчёта задаёт пропс `interval`.

```vue [CountdownIntervalExample.vue]
<script setup lang="ts">
import { ref } from 'vue'

const now = new Date()
const newYear = new Date(now.getFullYear() + 1, 0, 1)

const secondsNY = ref((newYear.getTime() - now.getTime()) / 1000)
</script>

<template>
  <B24Countdown
    v-slot="{ days, hours, minutes, seconds, milliseconds }"
    :seconds="secondsNY"
    :interval="100"
  >
    <span>До Нового года：{{ days }} дн., {{ hours }} ч, {{ minutes }} мин, {{ seconds }}.<small>{{ Math.floor(milliseconds / 100) }}</small> с.</span>
  </B24Countdown>
</template>
```

### Обработка событий отсчёта

События `start`, `end`, `abort` и `progress` позволяют реагировать на изменения отсчёта.

```vue [CountdownEmitsExample.vue]
<script setup lang="ts">
import { ref } from 'vue'

const value = ref(5)
const counting = ref(false)

const startCountdown = () => {
  counting.value = true
}

const onCountdownEnd = () => {
  counting.value = false
}
</script>

<template>
  <B24Button
    color="air-primary"
    size="xl"
    :disabled="counting"
    @click="startCountdown"
  >
    <B24Countdown
      v-if="counting"
      v-slot="{ totalSeconds }"
      :seconds="value"
      class="text-white dark:text-white text-xl leading-none"
      @end="onCountdownEnd"
    >
      Повторный запрос через {{ totalSeconds }} с
    </B24Countdown>
    <span v-else>
      Получить код подтверждения
    </span>
  </B24Button>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the Countdown component
 */
interface CountdownProps {
  /**
   * The element or component this component should render as
   * @default 'span'
   */
  as?: any;
  /**
   * @default 'md'
   */
  size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
  /**
   * Emits the countdown events
   * @default true
   */
  emitEvents?: boolean | undefined;
  /**
   * Number of seconds to countdown
   * @default 0
   */
  seconds?: string | number | undefined;
  /**
   * Should seconds be divided into minutes?
   * @default true
   */
  showMinutes?: boolean | undefined;
  /**
   * Shows a `Circle` around the countdown
   * @default false
   */
  useCircle?: boolean | undefined;
  /**
   * The interval time (in milliseconds) of the countdown progress
   * @default 1000
   */
  interval?: number | undefined;
  /**
   * Starts the countdown automatically when initialized
   * @default true
   */
  needStartImmediately?: boolean | undefined;
  /**
   * Generate the current time of a specific time zone
   * @default Date.now()
   */
  now?: (): number | undefined;
  b24ui?: { base?: SlotClass; label?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; circleBase?: SlotClass; circleGroup?: SlotClass; circleElement?: SlotClass; circlePath?: SlotClass; } | undefined;
  /**
   * Display an icon on the left side.
   */
  icon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * Display an avatar on the left side.
   */
  avatar?: AvatarProps | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the Countdown component
 */
interface CountdownSlots {
  leading(): any;
  default(): any;
}
```

### События

```ts
/**
 * Emitted events for the Countdown component
 */
interface CountdownEmits {
  abort: (payload: []) => void;
  progress: (payload: [value: CountdownData]) => void;
  start: (payload: []) => void;
  end: (payload: []) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    countdown: {
      slots: {
        base: 'relative flex flex-row flex-nowrap items-center justify-between text-legend',
        label: '',
        leadingIcon: 'shrink-0',
        leadingAvatar: 'shrink-0',
        leadingAvatarSize: '',
        circleBase: '-scale-x-100 absolute inset-x-0 inset-y-0',
        circleGroup: 'fill-none stroke-none',
        circleElement: 'stroke-transparent stroke-1',
        circlePath: 'stroke-[7px] rotate-90 origin-center stroke-current transition-all duration-1000 ease-linear'
      },
      variants: {
        size: {
          xs: {
            base: 'gap-0.5 text-(length:--ui-font-size-5xs)/(--ui-font-line-height-reset)',
            leadingIcon: 'size-sm',
            leadingAvatarSize: '3xs'
          },
          sm: {
            base: 'gap-1 text-(length:--ui-font-size-4xs)/(--ui-font-line-height-reset)',
            leadingIcon: 'size-sm2',
            leadingAvatarSize: '3xs'
          },
          md: {
            base: 'gap-1 text-(length:--ui-font-size-md)/(--ui-font-line-height-reset)',
            leadingIcon: 'size-[16px]',
            leadingAvatarSize: '3xs'
          },
          lg: {
            base: 'gap-1 text-(length:--ui-font-size-lg)/(--ui-font-line-height-reset)',
            leadingIcon: 'size-[22px]',
            leadingAvatarSize: '2xs'
          },
          xl: {
            base: 'gap-1 text-(length:--ui-font-size-xl)/(--ui-font-line-height-reset)',
            leadingIcon: 'size-[26px]',
            leadingAvatarSize: 'xs'
          }
        },
        leading: {
          true: ''
        },
        useCircle: {
          true: {
            base: 'justify-center',
            circleBase: 'size-full'
          }
        }
      },
      compoundVariants: [
        {
          size: 'xs',
          useCircle: true,
          class: 'text-(length:--ui-font-size-7xs)/[normal] p-0.5'
        },
        {
          size: 'sm',
          useCircle: true,
          class: 'text-(length:--ui-font-size-6xs)/[normal] p-1.5'
        },
        {
          size: 'md',
          useCircle: true,
          class: 'text-(length:--ui-font-size-3xs)/[normal] p-1.5'
        },
        {
          size: 'lg',
          useCircle: true,
          class: 'text-(length:--ui-font-size-xs)/[normal] p-1.5 pb-2'
        },
        {
          size: 'xl',
          useCircle: true,
          class: 'text-(length:--ui-font-size-sm)/[normal] p-2 pb-2.5'
        }
      ],
      defaultVariants: {
        size: 'md'
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
