/*! For license information please see 8201.ff1d9b9a.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["8201"],{49871:function(t,n,s){"use strict";s.r(n);var a=s("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

Calendar

\n

Intro

\n

Calendar component for selecting dates or date ranges.

\n

Install

\n

Register component globally via app.use, refer to Component Registration for more registration ways.

\n
import { createApp } from 'vue';\nimport { Calendar } from 'vant';\n\nconst app = createApp();\napp.use(Calendar);\n
\n

Usage

\n

Select Single Date

\n

The confirm event will be emitted after the date selection is completed.

\n
<van-cell title="Select Single Date" :value="date" @click="show = true" />\n<van-calendar v-model:show="show" @confirm="onConfirm" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const date = ref('');\n    const show = ref(false);\n\n    const formatDate = (date) => `${date.getMonth() + 1}/${date.getDate()}`;\n    const onConfirm = (value) => {\n      show.value = false;\n      date.value = formatDate(value);\n    };\n\n    return {\n      date,\n      show,\n      onConfirm,\n    };\n  },\n};\n
\n

Select Multiple Date

\n
<van-cell title="Select Multiple Date" :value="text" @click="show = true" />\n<van-calendar v-model:show="show" type="multiple" @confirm="onConfirm" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const text = ref('');\n    const show = ref(false);\n\n    const onConfirm = (dates) => {\n      show.value = false;\n      text.value = `\u9009\u62E9\u4E86 ${dates.length} \u4E2A\u65E5\u671F`;\n    };\n\n    return {\n      text,\n      show,\n      onConfirm,\n    };\n  },\n};\n
\n

Select Date Range

\n

You can select a date range after setting type torange. In range mode, the date returned by the confirm event is an array, the first item in the array is the start time and the second item is the end time.

\n
<van-cell title="Select Date Range" :value="date" @click="show = true" />\n<van-calendar v-model:show="show" type="range" @confirm="onConfirm" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const date = ref('');\n    const show = ref(false);\n\n    const formatDate = (date) => `${date.getMonth() + 1}/${date.getDate()}`;\n    const onConfirm = (values) => {\n      const [start, end] = values;\n      show.value = false;\n      date.value = `${formatDate(start)} - ${formatDate(end)}`;\n    };\n\n    return {\n      date,\n      show,\n      onConfirm,\n    };\n  },\n};\n
\n

Quick Select

\n

Set show-confirm to false to hide the confirm button. In this case, the confirm event will be emitted immediately after the selection is completed.

\n
<van-calendar v-model:show="show" :show-confirm="false" />\n
\n

Custom Color

\n

Use color prop to custom calendar color.

\n
<van-calendar v-model:show="show" color="#ee0a24" />\n
\n

Custom Date Range

\n

Use min-date and max-date to custom date range.

\n
<van-calendar v-model:show="show" :min-date="minDate" :max-date="maxDate" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const show = ref(false);\n\n    return {\n      show,\n      minDate: new Date(2010, 0, 1),\n      maxDate: new Date(2010, 0, 31),\n    };\n  },\n};\n
\n

Custom Confirm Text

\n

Use confirm-text and confirm-disabled-text to custom confirm text.

\n
<van-calendar\n  v-model:show="show"\n  type="range"\n  confirm-text="OK"\n  confirm-disabled-text="Select End Time"\n/>\n
\n

Custom Day Text

\n

Use formatter to custom day text.

\n
<van-calendar v-model:show="show" type="range" :formatter="formatter" />\n
\n
export default {\n  setup() {\n    const formatter = (day) => {\n      const month = day.date.getMonth() + 1;\n      const date = day.date.getDate();\n\n      if (month === 5) {\n        if (date === 1) {\n          day.topInfo = 'Labor Day';\n        } else if (date === 4) {\n          day.topInfo = 'Youth Day';\n        } else if (date === 11) {\n          day.text = 'Today';\n        }\n      }\n\n      if (day.type === 'start') {\n        day.bottomInfo = 'In';\n      } else if (day.type === 'end') {\n        day.bottomInfo = 'Out';\n      }\n\n      return day;\n    };\n\n    return {\n      formatter,\n    };\n  },\n};\n
\n

Custom Position

\n

Use position to custom popup position, can be set to top\u3001left\u3001right.

\n
<van-calendar v-model:show="show" :round="false" position="right" />\n
\n

Max Range

\n

When selecting a date range, you can use the max-range prop to specify the maximum number of selectable days.

\n
<van-calendar type="range" :max-range="3" :style="{ height: '500px' }" />\n
\n

Custom First Day Of Week

\n

Use first-day-of-week to custom the start day of week

\n
<van-calendar first-day-of-week="1" />\n
\n

Tiled display

\n

Set poppable to false, the calendar will be displayed directly on the page instead of appearing as a popup

\n
<van-calendar\n  title="Calendar"\n  :poppable="false"\n  :show-confirm="false"\n  :style="{ height: '500px' }"\n/>\n
\n

API

\n

Props

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
typeType, can be set to range multiplestringsingle
titleTitle of calendarstringCalendar
colorColor for the bottom button and selected datestring#1989fa
min-dateMin dateDateToday
max-dateMax dateDateSix months after the today
default-dateDefault selected dateDate | Date[] | nullToday
row-heightRow heightnumber | string64
formatterDay formatter(day: Day) => Day-
poppableWhether to show the calendar inside a popupbooleantrue
lazy-renderWhether to enable lazy renderbooleantrue
show-markWhether to show background month markbooleantrue
show-titleWhether to show titlebooleantrue
show-subtitleWhether to show subtitlebooleantrue
show-confirmWhether to show confirm buttonbooleantrue
readonlyWhether to be readonlybooleanfalse
confirm-textConfirm button textstringConfirm
confirm-disabled-textConfirm button text when disabledstringConfirm
first-day-of-weekSet the start day of week0-60
\n

Calendar Poppable Props

\n

Following props are supported when the poppable is true

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
v-model:showWhether to show calendarbooleanfalse
positionPopup position, can be set to top right leftstringbottom
roundWhether to show round cornerbooleantrue
close-on-popstateWhether to close when popstatebooleantrue
close-on-click-overlayWhether to close when overlay is clickedbooleantrue
safe-area-inset-topWhether to enable top safe area adaptationbooleanfalse
safe-area-inset-bottomWhether to enable bottom safe area adaptationbooleantrue
teleportSpecifies a target element where Calendar will be mountedstring | Element-
\n

Calendar Range Props

\n

Following props are supported when the type is range

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
max-rangeNumber of selectable daysnumber | stringUnlimited
range-promptError message when exceeded max rangestringChoose no more than xx days
show-range-promptWhether prompt error message when exceeded max rangebooleantrue
allow-same-dayWhether the start and end time of the range is allowed on the same daybooleanfalse
\n

Calendar Multiple Props

\n

Following props are supported when the type is multiple

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
max-rangeMax count of selectable daysnumber | stringUnlimited
range-promptError message when exceeded max countstringChoose no more than xx days
\n

Data Structure of Day

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
KeyDescriptionType
dateDateDate
typeType, can be set to selected\u3001start\u3001middle\u3001end\u3001disabledstring
textTextstring
topInfoTop infostring
bottomInfoBottom infostring
classNameExtra classNamestring
\n

Events

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
EventDescriptionArguments
selectEmitted when date is selectedvalue: Date | Date[]
confirmEmitted after date selection is complete, if show-confirm is true, it is Emitted after clicking the confirm buttonvalue: Date | Date[]
openEmitted when opening Popup-
closeEmitted when closing Popup-
openedEmitted when Popup is opened-
closedEmitted when Popup is closed-
unselectEmitted when unselect date when type is multiplevalue: Date
month-showEmitted when a month enters the visible areavalue: { date: Date, title: string }
over-rangeEmitted when exceeded max range-
click-subtitleEmitted when clicking the subtitleevent: MouseEvent
click-disabled-date v4.7.0Emitted when clicking disabled datevalue: Date | Date[]
\n

Slots

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionSlotProps
titleCustom title-
subtitleCustom subtitle{ text: string, date?: Date }
month-title v4.0.9Custom title of every month{ text: string, date: Date }
footerCustom footer-
confirm-textCustom confirm text{ disabled: boolean }
top-infoCustom top info of dayday: Day
bottom-infoCustom bottom info of dayday: Day
\n

Methods

\n

Use ref to get Calendar instance and call instance methods.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionAttributeReturn value
resetReset selected date, will reset to default date when no params passeddate?: Date | Date[]-
scrollToDateScroll to datedate: Date-
getSelectedDateget selected date-Date | Date[] | null
\n

Types

\n

The component exports the following type definitions:

\n
import type {\n  CalendarType,\n  CalendarProps,\n  CalendarDayItem,\n  CalendarDayType,\n  CalendarInstance,\n} from 'vant';\n
\n

CalendarInstance is the type of component instance:

\n
import { ref } from 'vue';\nimport type { CalendarInstance } from 'vant';\n\nconst calendarRef = ref<CalendarInstance>();\n\ncalendarRef.value?.reset();\n
\n

Theming

\n

CSS Variables

\n

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDefault ValueDescription
--van-calendar-backgroundvar(--van-background-2)-
--van-calendar-popup-height80%-
--van-calendar-header-shadow0 2px 10px rgba(125, 126, 128, 0.16)-
--van-calendar-header-title-height44px-
--van-calendar-header-title-font-sizevar(--van-font-size-lg)-
--van-calendar-header-subtitle-font-sizevar(--van-font-size-md)-
--van-calendar-weekdays-height30px-
--van-calendar-weekdays-font-sizevar(--van-font-size-sm)-
--van-calendar-month-title-font-sizevar(--van-font-size-md)-
--van-calendar-month-mark-colorfade(var(--van-gray-2), 80%)-
--van-calendar-month-mark-font-size160px-
--van-calendar-day-height64px-
--van-calendar-day-font-sizevar(--van-font-size-lg)-
--van-calendar-day-margin-bottom4px-
--van-calendar-range-edge-colorvar(--van-white)-
--van-calendar-range-edge-backgroundvar(--van-primary-color)-
--van-calendar-range-middle-colorvar(--van-primary-color)-
--van-calendar-range-middle-background-opacity0.1-
--van-calendar-selected-day-size54px-
--van-calendar-selected-day-colorvar(--van-white)-
--van-calendar-info-font-sizevar(--van-font-size-xs)-
--van-calendar-info-line-heightvar(--van-line-height-xs)-
--van-calendar-selected-day-backgroundvar(--van-primary-color)-
--van-calendar-day-disabled-colorvar(--van-text-color-3)-
--van-calendar-confirm-button-height36px-
--van-calendar-confirm-button-margin7px 0-
\n
'},null,8,e))}}}]);