v2.15.0

Calendar

Календарь для выбора одной даты, нескольких дат или диапазона.

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

Выбранной датой управляет директива v-model.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, апрель 2012 г.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar v-model="value" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar v-model="value" />
</template>

Пропс default-value задаёт начальное значение, если управлять состоянием не нужно.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, апрель 2012 г.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const defaultValue = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar :default-value="defaultValue" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const defaultValue = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar :default-value="defaultValue" />
</template>
Для форматирования с учётом локали компонент использует пакет @internationalized/date. Формат даты определяет пропс locale компонента App.
Для форматирования с учётом локали компонент использует пакет @internationalized/date. Формат даты определяет пропс locale компонента App.

Тип 2.14+

Пропс type меняет то, что выбирается в календаре. По умолчанию — date.

При date щелчок по заголовку переключает вид дней на вид месяцев, а затем лет — так удобно быстро перейти к нужному периоду; потом вы возвращаетесь к выбору дня.

янв.
февр.
март
апр.
май
июнь
июль
авг.
сент.
окт.
нояб.
дек.
Выбор месяца, 2012
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar type="month" v-model="value" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar type="month" v-model="value" />
</template>

type="year" отрисовывает отдельный выбор года.

2010 - 2021
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
Выбор года, 2010 - 2021
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar type="year" v-model="value" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar type="year" v-model="value" />
</template>

Множественный выбор

Пропс multiple разрешает выбрать несколько дат.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, апрель 2012 г.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const value = shallowRef([
  new CalendarDate(2012, 4, 4),
  new CalendarDate(2012, 4, 12),
  new CalendarDate(2012, 4, 20)
])
</script>

<template>
  <B24Calendar multiple v-model="value" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const value = shallowRef([
  new CalendarDate(2012, 4, 4),
  new CalendarDate(2012, 4, 12),
  new CalendarDate(2012, 4, 20)
])
</script>

<template>
  <B24Calendar multiple v-model="value" />
</template>

Локаль

Пропс locale меняет локаль календаря.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, 2012年4月
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar v-model="value" locale="zh-CN" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const value = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Calendar v-model="value" locale="zh-CN" />
</template>

Диапазон

Пропс range включает выбор диапазона дат.

Дата события, апрель 2012 г.
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const value = shallowRef({
  start: new CalendarDate(2012, 4, 3),
  end: new CalendarDate(2012, 4, 20)
})
</script>

<template>
  <B24Calendar range v-model="value" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const value = shallowRef({
  start: new CalendarDate(2012, 4, 3),
  end: new CalendarDate(2012, 4, 20)
})
</script>

<template>
  <B24Calendar range v-model="value" />
</template>

Пропс range работает и с type="month" и type="year" — можно выбрать диапазон месяцев или лет.

Выбор месяца, 2012
янв.
февр.
март
апр.
май
июнь
июль
авг.
сент.
окт.
нояб.
дек.
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'

const value = shallowRef({
  start: new CalendarDate(2012, 4, 3),
  end: new CalendarDate(2012, 4, 20)
})
</script>

<template>
  <B24Calendar type="month" range v-model="value" />
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const value = shallowRef({
  start: new CalendarDate(2012, 4, 3),
  end: new CalendarDate(2012, 4, 20)
})
</script>

<template>
  <B24Calendar type="month" range v-model="value" />
</template>

Число месяцев

Пропс numberOfMonths меняет число месяцев в календаре.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
Дата события, ноябрь 2026 - январь 2027
<template>
  <B24Calendar :number-of-months="3" />
</template>

Управление месяцами

Пропс month-controls показывает кнопки переключения месяцев. По умолчанию — true.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar :month-controls="false" />
</template>

Пропсы prev-month и next-month переопределяют кнопки месяцев.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar
    :prev-month="{
      color: 'air-primary'
    }"
    :next-month="{
      color: 'air-primary-alert'
    }"
  />
</template>

Управление годами

Пропс year-controls показывает кнопки переключения годов. По умолчанию — true.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar :year-controls="false" />
</template>

Пропсы prev-year и next-year переопределяют кнопки годов.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar
    :prev-year="{
      color: 'air-primary'
    }"
    :next-year="{
      color: 'air-primary'
    }"
  />
</template>

Переключение вида 2.14+

Пропс view-control превращает заголовок в кнопку, которая переключает виды дней, месяцев и лет. По умолчанию — true.

ноябрь 2026 г.
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar :view-control="false" />
</template>

Если передать в view-control объект, он переопределит кнопку заголовка.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar
    :view-control="{
      color: 'air-primary'
    }"
  />
</template>

Годов на странице 2.15+

Пропс years-per-page меняет число лет в виде годов. По умолчанию — 12.

2020 - 2039
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
Выбор года, 2020 - 2039
<template>
  <B24Calendar type="year" :years-per-page="20" />
</template>

Фиксированные недели

Пропс fixed-weeks показывает календарь с фиксированным числом недель.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar :fixed-weeks="false" />
</template>

Номера недель

Пропс week-numbers показывает номера недель.

44
26
27
28
29
30
31
1
45
2
3
4
5
6
7
8
46
9
10
11
12
13
14
15
47
16
17
18
19
20
21
22
48
23
24
25
26
27
28
29
49
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar week-numbers />
</template>

Цвет

Пропс color меняет цвет календаря.

Дата события, апрель 2012 г.
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
<template>
  <B24Calendar color="air-primary-alert" />
</template>

Размер

Пропс size меняет размер календаря.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar size="lg" />
</template>

Отключение

Пропс disabled отключает календарь.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<template>
  <B24Calendar disabled />
</template>

Примеры

С событиями в чипах

Компонент Chip добавляет события к отдельным дням.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, апрель 2012 г.
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const modelValue = shallowRef(new CalendarDate(2012, 4, 12))

function getColorByDate(date: Date) {
  const isWeekend = date.getUTCDay() % 6 == 0
  const isDayMeeting = date.getUTCDay() % 3 == 0

  if (isWeekend) {
    return undefined
  }

  if (isDayMeeting) {
    return 'air-primary-alert'
  }

  return 'air-primary-success'
}
</script>

<template>
  <B24Calendar v-model="modelValue" size="lg">
    <template #day="{ day }">
      <B24Chip
        :show="!!getColorByDate(day.toDate('UTC'))"
        :color="getColorByDate(day.toDate('UTC'))"
        size="sm"
      >
        {{ day.day }}
      </B24Chip>
    </template>
  </B24Calendar>
</template>

С отключёнными датами

Пропс is-date-disabled с функцией помечает отдельные даты как отключённые. При type="month" или type="year" используйте is-month-disabled или is-year-disabled.

Дата события, апрель 2012 г.
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
<script setup lang="ts">
import type { DateValue } from '@internationalized/date'
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const modelValue = shallowRef({
  start: new CalendarDate(2012, 4, 12),
  end: new CalendarDate(2012, 4, 14)
})

const isDateDisabled = (date: DateValue) => {
  return date.day >= 15 && date.day <= 17
}
</script>

<template>
  <B24Calendar v-model="modelValue" :is-date-disabled="isDateDisabled" range />
</template>

С недоступными датами

Пропс is-date-unavailable с функцией помечает отдельные даты как недоступные. При type="month" или type="year" используйте is-month-unavailable или is-year-unavailable.

Дата события, апрель 2012 г.
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
<script setup lang="ts">
import type { DateValue } from '@internationalized/date'
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const modelValue = shallowRef({
  start: new CalendarDate(2012, 4, 12),
  end: new CalendarDate(2012, 4, 14)
})

const isDateUnavailable = (date: DateValue) => {
  return date.day >= 15 && date.day <= 17
}
</script>

<template>
  <B24Calendar v-model="modelValue" :is-date-unavailable="isDateUnavailable" range />
</template>

С минимальной и максимальной датой

Пропсы min-value и max-value ограничивают диапазон дат.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, апрель 2012 г.
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const modelValue = shallowRef(new CalendarDate(2012, 4, 12))
const minDate = new CalendarDate(2012, 4, 3)
const maxDate = new CalendarDate(2012, 4, 27)
</script>

<template>
  <B24Calendar v-model="modelValue" :min-value="minDate" :max-value="maxDate" />
</template>

С другими календарными системами

Другие календари из @internationalized/date дают другую календарную систему.

25
26
27
28
29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
Дата события, тишрей 5781 г. AM
<script lang="ts" setup>
import { shallowRef } from 'vue'
import { CalendarDate, HebrewCalendar } from '@internationalized/date'

const hebrewDate = shallowRef(new CalendarDate(new HebrewCalendar(), 5781, 1, 1))
</script>

<template>
  <B24Calendar v-model="hebrewDate" />
</template>
Все доступные календари перечислены в документации @internationalized/date.

С внешним управлением

Календарём можно управлять извне, меняя дату в v-model.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, апрель 2012 г.
<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate } from '@internationalized/date'

const date = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <div class="flex flex-col gap-4">
    <B24Calendar v-model="date" :month-controls="false" :year-controls="false" />

    <div class="flex justify-between gap-4">
      <B24Button @click="date = date.subtract({ months: 1 })">
        Назад
      </B24Button>

      <B24Button @click="date = date.add({ months: 1 })">
        Вперёд
      </B24Button>
    </div>
  </div>
</template>

С сегодняшней датой

Функция today из @internationalized/date вместе с getLocalTimeZone задаёт текущую дату.

26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
Дата события, ноябрь 2026 г.
<script setup lang="ts">
import { getLocalTimeZone, today } from '@internationalized/date'

const date = shallowRef(today(getLocalTimeZone()))
</script>

<template>
  <div class="flex flex-col gap-4">
    <B24Calendar v-model="date" />

    <B24Button color="air-primary" class="justify-center" @click="date = today(getLocalTimeZone())">
      Сегодня
    </B24Button>
  </div>
</template>
<script setup lang="ts">
import { shallowRef } from 'vue'
import { getLocalTimeZone, today } from '@internationalized/date'

const date = shallowRef(today(getLocalTimeZone()))
</script>

<template>
  <div class="flex flex-col gap-4">
    <B24Calendar v-model="date" />

    <B24Button color="air-primary" class="justify-center" @click="date = today(getLocalTimeZone())">
      Сегодня
    </B24Button>
  </div>
</template>

Как выбор даты

Из Button и Popover собирается выбор даты.

<script setup lang="ts">
import { shallowRef } from 'vue'
import { CalendarDate, DateFormatter, getLocalTimeZone } from '@internationalized/date'
import Calendar1Icon from '@bitrix24/b24icons-vue/main/Calendar1Icon'

const df = new DateFormatter('en-US', {
  dateStyle: 'medium'
})

const modelValue = shallowRef(new CalendarDate(2012, 4, 12))
</script>

<template>
  <B24Popover>
    <B24Button :icon="Calendar1Icon">
      {{ modelValue ? df.format(modelValue.toDate(getLocalTimeZone())) : 'Выберите дату' }}
    </B24Button>

    <template #content>
      <B24Calendar v-model="modelValue" class="p-2" />
    </template>
  </B24Popover>
</template>

Как выбор диапазона дат

Из Button и Popover собирается выбор диапазона дат с готовыми диапазонами.

<script setup lang="ts">
import { shallowRef } from 'vue'
import { DateFormatter, getLocalTimeZone, today } from '@internationalized/date'
import Calendar1Icon from '@bitrix24/b24icons-vue/main/Calendar1Icon'

const { screen } = useDevice()
const df = new DateFormatter('en-US', { dateStyle: 'medium' })
const tz = getLocalTimeZone()

const ranges = [
  { label: 'Последние 7 дней', days: 7 },
  { label: 'Последние 14 дней', days: 14 },
  { label: 'Последние 30 дней', days: 30 },
  { label: 'Последние 3 месяца', months: 3 },
  { label: 'Последние 6 месяцев', months: 6 },
  { label: 'Последний год', years: 1 }
]

const initialEnd = today(tz)
const modelValue = shallowRef({
  start: initialEnd.subtract({ days: 14 }),
  end: initialEnd
})

const label = computed(() => {
  const { start, end } = modelValue.value
  if (!start) return 'Выберите дату'
  if (!end) return df.format(start.toDate(tz))
  return `${df.format(start.toDate(tz))} - ${df.format(end.toDate(tz))}`
})

function computeStart(range: typeof ranges[number]) {
  const end = today(tz)
  return { start: end.subtract({ days: range.days, months: range.months, years: range.years }), end }
}

function isRangeSelected(range: typeof ranges[number]) {
  if (!modelValue.value?.start || !modelValue.value?.end) return false
  const { start, end } = computeStart(range)
  return modelValue.value.start.compare(start) === 0 && modelValue.value.end.compare(end) === 0
}

function selectRange(range: typeof ranges[number]) {
  modelValue.value = computeStart(range)
}
</script>

<template>
  <B24Popover :content="{ align: 'center' }">
    <B24Button :icon="Calendar1Icon">
      {{ label }}
    </B24Button>

    <template #content>
      <div class="flex items-stretch divide-x divide-accented">
        <div class="hidden sm:flex flex-col justify-center py-2">
          <B24Button
            v-for="(range, index) in ranges"
            :key="index"
            :label="range.label"
            class="rounded-none px-4"
            :class="[isRangeSelected(range) ? 'bg-elevated' : 'hover:bg-elevated/50']"
            truncate
            @click="selectRange(range)"
          />
        </div>

        <B24Calendar v-model="modelValue" class="p-2" :number-of-months="screen.isDesktop ? 2 : 1" range />
      </div>
    </template>
  </B24Popover>
</template>
<script setup lang="ts">
import { shallowRef, computed } from 'vue'
import { DateFormatter, getLocalTimeZone, today } from '@internationalized/date'
import Calendar1Icon from '@bitrix24/b24icons-vue/main/Calendar1Icon'

const { screen } = useDevice()
const df = new DateFormatter('en-US', { dateStyle: 'medium' })
const tz = getLocalTimeZone()

const ranges = [
  { label: 'Последние 7 дней', days: 7 },
  { label: 'Последние 14 дней', days: 14 },
  { label: 'Последние 30 дней', days: 30 },
  { label: 'Последние 3 месяца', months: 3 },
  { label: 'Последние 6 месяцев', months: 6 },
  { label: 'Последний год', years: 1 }
]

const initialEnd = today(tz)
const modelValue = shallowRef({
  start: initialEnd.subtract({ days: 14 }),
  end: initialEnd
})

const label = computed(() => {
  const { start, end } = modelValue.value
  if (!start) return 'Выберите дату'
  if (!end) return df.format(start.toDate(tz))
  return `${df.format(start.toDate(tz))} - ${df.format(end.toDate(tz))}`
})

function computeStart(range: typeof ranges[number]) {
  const end = today(tz)
  return { start: end.subtract({ days: range.days, months: range.months, years: range.years }), end }
}

function isRangeSelected(range: typeof ranges[number]) {
  if (!modelValue.value?.start || !modelValue.value?.end) return false
  const { start, end } = computeStart(range)
  return modelValue.value.start.compare(start) === 0 && modelValue.value.end.compare(end) === 0
}

function selectRange(range: typeof ranges[number]) {
  modelValue.value = computeStart(range)
}
</script>

<template>
  <B24Popover :content="{ align: 'center' }">
    <B24Button :icon="Calendar1Icon">
      {{ label }}
    </B24Button>

    <template #content>
      <div class="flex items-stretch divide-x divide-accented">
        <div class="hidden sm:flex flex-col justify-center py-2">
          <B24Button
            v-for="(range, index) in ranges"
            :key="index"
            :label="range.label"
            class="rounded-none px-4"
            :class="[isRangeSelected(range) ? 'bg-elevated' : 'hover:bg-elevated/50']"
            truncate
            @click="selectRange(range)"
          />
        </div>

        <B24Calendar v-model="modelValue" class="p-2" :number-of-months="screen.isDesktop ? 2 : 1" range />
      </div>
    </template>
  </B24Popover>
</template>

API

Пропсы

Prop Default Type
as'div'any

The element or component this component should render as.

type'date' "date" | "month" | "year"

The type of picker.

  • date renders a day calendar whose heading can switch to a month then year view.
  • month renders a standalone month picker.
  • year renders a standalone year picker.
nextYearIconicons.chevronDoubleRightIconComponent

The icon to use for the next year control.

nextYear Omit<ButtonProps, LinkPropsKeys>

Configure the next year button. { color: 'air-tertiary' }

nextMonthIconicons.chevronRightIconComponent

The icon to use for the next month control.

nextMonth Omit<ButtonProps, LinkPropsKeys>

Configure the next month button. { color: 'air-tertiary' }

prevYearIconicons.chevronDoubleLeftIconComponent

The icon to use for the previous year control.

prevYear Omit<ButtonProps, LinkPropsKeys>

Configure the prev year button. { color: 'air-tertiary' }

prevMonthIconicons.chevronLeftIconComponent

The icon to use for the previous month control.

prevMonth Omit<ButtonProps, LinkPropsKeys>

Configure the prev month button. { color: 'air-tertiary' }

viewControltrueboolean | Omit<ButtonProps, LinkPropsKeys>

Whether to make the heading a button that switches between the day, month and year views. Has no effect when type is year. Can be an object to override the button props. { color: 'air-tertiary', block: true }

color'air-primary'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot"
size'md' "xs" | "sm" | "md" | "lg"
range R

Whether or not a range of dates can be selected

multiple M

Whether or not multiple dates can be selected

monthControlstrueboolean

Show month controls

yearControlstrueboolean

Show year controls

defaultValueCalendarDate | CalendarDateTime | ZonedDateTime | DateRange | DateValue[]
modelValuenull | CalendarDate | CalendarDateTime | ZonedDateTime | DateRange | DateValue[]
weekNumbersboolean
defaultPlaceholderCalendarDate | CalendarDateTime | ZonedDateTime
placeholderCalendarDate | CalendarDateTime | ZonedDateTime
allowNonContiguousRangesboolean

When combined with isDateUnavailable, determines whether non-contiguous ranges, i.e. ranges containing unavailable dates, may be selected.

pagedNavigationboolean

This property causes the previous and next buttons to navigate by the number of months displayed at once, rather than one month

preventDeselectboolean

Whether or not to prevent the user from deselecting a date without selecting another date first

maximumDays number

The maximum number of days that can be selected in a range

weekStartsOn 0 | 1 | 2 | 4 | 3 | 5 | 6

The day of the week to start the calendar on

weekdayFormat "narrow" | "short" | "long"

The format to use for the weekday strings provided via the weekdays slot prop

fixedWeekstrueboolean

Whether or not to always display 6 weeks in the calendar

maxValueCalendarDate | CalendarDateTime | ZonedDateTime
minValueCalendarDate | CalendarDateTime | ZonedDateTime
locale string

The locale to use for formatting dates

numberOfMonths number

The number of months to display at once

disabledboolean

Whether or not the calendar is disabled

readonlyboolean

Whether or not the calendar is readonly

initialFocusboolean

If true, the calendar will focus the selected day, today, or the first day of the month depending on what is visible when the calendar is mounted

isDateDisabled (date: DateValue): boolean

A function that returns whether or not a date is disabled

isDateUnavailable (date: DateValue): boolean

A function that returns whether or not a date is unavailable

isDateHighlightable (date: DateValue): boolean

A function that returns whether or not a date is hightable

nextPage (placeholder: DateValue): DateValue

A function that returns the next page of the calendar. It receives the current placeholder as an argument inside the component.

prevPage (placeholder: DateValue): DateValue

A function that returns the previous page of the calendar. It receives the current placeholder as an argument inside the component.

disableDaysOutsideCurrentViewboolean

Whether or not to disable days outside the current view.

fixedDate "start" | "end"

Which part of the range should be fixed

isMonthDisabled (date: DateValue): boolean

A function that returns whether or not a month is disabled

isMonthUnavailable (date: DateValue): boolean

A function that returns whether or not a month is unavailable

isYearDisabled (date: DateValue): boolean

A function that returns whether or not a year is disabled

isYearUnavailable (date: DateValue): boolean

A function that returns whether or not a year is unavailable

yearsPerPage number

Number of years to display per page

b24ui { root?: SlotClass; header?: SlotClass; body?: SlotClass; heading?: SlotClass; headingLabel?: SlotClass; grid?: SlotClass; gridRow?: SlotClass; gridWeekDaysRow?: SlotClass; gridBody?: SlotClass; headCell?: SlotClass; headCellWeek?: SlotClass; cell?: SlotClass; cellTrigger?: SlotClass; cellWeek?: SlotClass; }

Слоты

Slot Type
heading{ value: string; view: CalendarView; date: DateValue; setView: (view: CalendarView) => void; setPlaceholder: (date: DateValue) => void; }
dayPick<CalendarCellTriggerProps, "day">
week-day{ day: string; }
month-cell{ month: DateValue; selected: boolean; disabled: boolean; }
year-cell{ year: DateValue; selected: boolean; disabled: boolean; }

События

Event Type
update:modelValue[value: CalendarModelValue<R, M>]
update:placeholder[date: DateValue]
update:validModelValue[date: DateRange]
update:startValue[date: DateValue | undefined]

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/calendar.ts
export default {
  slots: {
    root: 'font-[family-name:var(--ui-font-family-primary)]',
    header: 'flex items-center justify-between',
    body: 'flex flex-col space-y-4 pt-4 sm:flex-row sm:space-x-4 sm:space-y-0',
    heading: 'flex-1 min-w-0 text-center',
    headingLabel: 'text-legend font-(--ui-font-weight-semi-bold) block truncate p-1.5',
    grid: 'w-full border-collapse select-none space-y-1 focus:outline-none',
    gridRow: 'grid',
    gridWeekDaysRow: 'mb-1 grid w-full grid-cols-7',
    gridBody: 'grid',
    headCell: 'font-(--ui-font-weight-normal) text-(--ui-color-design-plain-na-content-secondary)',
    headCellWeek: 'text-(--ui-color-design-plain-na-content-secondary)',
    cell: 'relative text-center cursor-pointer aria-disabled:cursor-not-allowed',
    cellTrigger: 'm-0 sm:m-0.5 relative flex items-center justify-center whitespace-nowrap focus-visible:ring-2 focus:outline-none text-label data-[disabled]:text-(--ui-color-design-plain-na-content-secondary) data-disabled:opacity-30 data-unavailable:text-(--ui-color-design-plain-na-content-secondary) data-selected:text-(--b24ui-color) focus-visible:ring-(--b24ui-background-hover) data-selected:focus-visible:ring-(--b24ui-background-hover) data-selected:bg-(--b24ui-background) data-today:not-data-selected:text-(--b24ui-background) data-highlighted:bg-(--b24ui-background) data-highlighted:text-(--b24ui-color) hover:not-data-[disabled]:not-data-[selected]:bg-(--b24ui-background) hover:not-data-[disabled]:not-data-[selected]:text-(--b24ui-color) data-unavailable:line-through data-unavailable:pointer-events-none data-today:font-(--ui-font-weight-semi-bold) transition',
    cellWeek: 'relative text-center text-(--ui-color-design-plain-na-content-secondary)'
  },
  variants: {
    color: {
      'air-primary': {
        root: 'style-filled'
      },
      'air-primary-success': {
        root: 'style-filled-success'
      },
      'air-primary-alert': {
        root: 'style-filled-alert'
      },
      'air-primary-copilot': {
        root: 'style-filled-copilot'
      },
      'air-primary-warning': {
        root: 'style-filled-warning'
      },
      default: {
        root: 'style-old-default'
      },
      danger: {
        root: 'style-old-danger'
      },
      success: {
        root: 'style-old-success'
      },
      warning: {
        root: 'style-old-warning'
      },
      primary: {
        root: 'style-old-primary'
      },
      secondary: {
        root: 'style-old-secondary'
      },
      collab: {
        root: 'style-old-collab'
      },
      ai: {
        root: 'style-old-ai'
      }
    },
    size: {
      xs: {
        headingLabel: 'text-(length:--ui-font-size-md)',
        cell: 'text-(length:--ui-font-size-sm)',
        cellWeek: 'text-(length:--ui-font-size-4xs)',
        headCell: 'text-(length:--ui-font-size-4xs)',
        headCellWeek: 'text-(length:--ui-font-size-4xs)',
        body: 'space-y-2 pt-2'
      },
      sm: {
        headingLabel: 'text-(length:--ui-font-size-md)',
        headCell: 'text-(length:--ui-font-size-3xs)',
        headCellWeek: 'text-(length:--ui-font-size-3xs)',
        cellWeek: 'text-(length:--ui-font-size-3xs)',
        cell: 'text-(length:--ui-font-size-sm)'
      },
      md: {
        headingLabel: 'text-(length:--ui-font-size-lg)',
        headCell: 'text-(length:--ui-font-size-xs)',
        headCellWeek: 'text-(length:--ui-font-size-xs)',
        cellWeek: 'text-(length:--ui-font-size-xs)',
        cell: 'text-(length:--ui-font-size-md)'
      },
      lg: {
        headingLabel: 'text-(length:--ui-font-size-2xl)',
        headCell: 'text-(length:--ui-font-size-xs)',
        headCellWeek: 'text-(length:--ui-font-size-xs)',
        cellWeek: 'text-(length:--ui-font-size-xs)',
        cell: 'text-(length:--ui-font-size-lg)'
      }
    },
    view: {
      day: {
        gridRow: 'grid-cols-7 place-items-center',
        cellTrigger: 'rounded-full data-outside-view:text-(--ui-color-design-plain-na-content-secondary)'
      },
      month: {
        gridRow: 'grid-cols-4',
        cellTrigger: 'rounded-md'
      },
      year: {
        gridRow: 'grid-cols-4',
        cellTrigger: 'rounded-md'
      }
    },
    weekNumbers: {
      true: ''
    }
  },
  compoundVariants: [
    {
      size: 'xs',
      view: 'day',
      class: {
        cellTrigger: 'size-11 sm:size-6'
      }
    },
    {
      size: 'sm',
      view: 'day',
      class: {
        cellTrigger: 'size-11 sm:size-7'
      }
    },
    {
      size: 'md',
      view: 'day',
      class: {
        cellTrigger: 'size-11 sm:size-8'
      }
    },
    {
      size: 'lg',
      view: 'day',
      class: {
        cellTrigger: 'size-11 sm:size-9'
      }
    },
    {
      size: 'xs',
      view: [
        'month',
        'year'
      ],
      class: {
        cellTrigger: 'h-11 sm:h-6 px-2'
      }
    },
    {
      size: 'sm',
      view: [
        'month',
        'year'
      ],
      class: {
        cellTrigger: 'h-11 sm:h-7 px-2'
      }
    },
    {
      size: 'md',
      view: [
        'month',
        'year'
      ],
      class: {
        cellTrigger: 'h-11 sm:h-8 px-3'
      }
    },
    {
      size: 'lg',
      view: [
        'month',
        'year'
      ],
      class: {
        cellTrigger: 'h-11 sm:h-9 px-4'
      }
    },
    {
      view: 'day',
      weekNumbers: true,
      class: {
        gridRow: 'grid-cols-8',
        gridWeekDaysRow: 'grid-cols-8 [&>*:first-child]:col-start-2'
      }
    }
  ],
  defaultVariants: {
    size: 'md',
    color: 'air-primary',
    view: 'day'
  }
}