Install
Requires Vue 3. Vue 2 projects should stay on vue-hotel-datepicker@4.
npm install vue-hotel-datepickerimport HotelDatePicker from 'vue-hotel-datepicker'
import 'vue-hotel-datepicker/dist/vueHotelDatepicker.css'
export default {
components: { HotelDatePicker },
}<HotelDatePicker :modelValue="true" />Props
modelValueBooleandefaultfalse- The v-model prop. Controls the visibility of the date picker. Breaking change since v4, where it was
value. alwaysVisibleBooleandefaultfalse- Shows the calendar in the page without needing to click the input.
bookingsArraydefault[]- Existing bookings to draw on the calendar. See Bookings below.
closeDatepickerOnClickOutsideBooleandefaulttrue- Closes the date picker when the user clicks outside it. Set to
falseto control it with the methods below. disableCheckoutOnCheckinBooleandefaultfalse- Disables check-out on the same day as check-in. Try it
disabledDatesArraydefault[]- Strings in
YYYY-MM-DDformat. Every date in the list is disabled. Try it disabledDaysOfWeekArraydefault[]Deprecated · Use disabledWeekDays instead.- Day names to disable, such as
Monday. Depends on the translated names. disabledWeekDaysObjectdefault{}- Keys
sundaytosaturday. A value oftruedisables that weekday;falseenables it. Try it displayClearButtonBooleandefaulttrue- Shows a clear button at the right of the input once dates are set.
enableCheckoutBooleandefaultfalse- Allows check-out on a disabled date. Try it
endDateDate | String | NumberdefaultInfinity- The last selectable date. Everything after it is disabled. Try it
endingDateValueDatedefaultnull- The initial check-out date. Try it
firstDayOfWeekNumberdefault0- Sunday is 0, Monday is 1, up to Saturday as 6. Set the matching order in
i18n.day-namestoo. formatStringdefault'YYYY-MM-DD'- The date format, using dayjs tokens. Try it
gridStyleBooleandefaulttrue- When
false, hides the grid lines around days. halfDayBooleandefaulttrue- Allows check-in at noon on the day a previous booking checks out before noon. Try it
hoveringTooltipBoolean | Functiondefaulttrue- Shows a tooltip with the number of nights while hovering a date.
i18nObjectdefaultEnglish- Translations for the picker. See Translations below.
lastDateAvailableNumber | DatedefaultInfinity- Stops calendar pagination after the month of this date.
maxNightsNumberdefaultnull- The longest selectable stay.
0ornullmeans no limit. Try it minNightsNumberdefault1- The shortest selectable stay. Try it
periodDatesArraydefault[]- Periods with their own minimum stay, type or price. See Period dates below.
positionRightBooleandefaultfalse- Opens the calendar to the right of the input.
priceDecimalsNumberdefault0- Decimals shown in prices for weekly periods.
priceSymbolStringdefault''- Symbol placed before the price when
showPriceis on and a period has aprice. showPriceBooleandefaultfalse- Displays the
priceof each period fromperiodDates. showSingleMonthBooleandefaultfalse- Displays one month instead of two.
showWeekNumbersBooleandefaultfalse- Displays ISO week numbers.
showYearBooleandefaulttrue- Shows the year next to the month name.
singleDaySelectionBooleandefaultfalse- Selects one day instead of a range. Try it
startDateDate | Stringdefaultnew Date()- The first selectable date. Everything before it is disabled.
startingDateValueDatedefaultnull- The initial check-in date. Try it
tooltipMessageStringdefaultnull- Replaces the default “X nights” tooltip. Accepts HTML. Try it
yearBeforeMonthBooleandefaultfalse- Puts the year before the month. Only applies when
showYearistrue.
Period dates
Give date ranges their own minimum stay, period type or price. Weekly periods only allow check-out on their weekday, and their minimumDuration is counted in weeks.
| Key | Type | Description |
|---|---|---|
startAt | String | YYYY-MM-DD. |
endAt | String | YYYY-MM-DD. |
minimumDuration | Number | Minimum stay. Counted in nights for nightly and in weeks for the weekly types. |
periodType | String | nightly, weekly_by_saturday or weekly_by_sunday. |
price | Number | Price shown on each day of the period. |
periodDates: [
{
startAt: '2020-06-09',
endAt: '2020-07-26',
minimumDuration: 4,
periodType: 'nightly',
},
{
startAt: '2020-07-26',
endAt: '2020-09-30',
minimumDuration: 1,
periodType: 'weekly_by_saturday',
},
{
startAt: '2020-09-30',
endAt: '2020-11-30',
minimumDuration: 2,
periodType: 'weekly_by_sunday',
price: 4000.0,
},
]Bookings
Draws existing bookings on the calendar. Clicking one emits booking-clicked.
| Key | Type | Description |
|---|---|---|
checkInDate | String | YYYY-MM-DD. |
checkOutDate | String | YYYY-MM-DD. |
style | Object | Inline style for the booking marker, such as backgroundColor. |
bookings: [
{
event: true,
checkInDate: '2020-08-26',
checkOutDate: '2020-08-29',
style: { backgroundColor: '#399694' },
},
{
event: false,
checkInDate: '2020-07-01',
checkOutDate: '2020-07-08',
style: { backgroundColor: '#9DC1C9' },
},
]Events
| Name | Payload | Description |
|---|---|---|
booking-clicked | MouseEvent, Date, Object | A booking was clicked. Receives the mouse event, the clicked date and the booking. |
check-in-changed | Date | A new check-in date was selected. |
check-out-changed | Date | A new check-out date was selected. |
clear-selection | — | The clear button was clicked. |
day-clicked | Date, String, Date | Number | String | A day was clicked. Receives the date, its formatted string and the next disabled date. |
handle-checkin-checkout-half-day | Object | Emitted before mount, on clear and on check-out. Receives an object with the check-in and check-out dates. |
next-month-rendered | — | The next month was rendered. |
period-selected | Event, Date, Date | A check-out was clicked. Receives the mouse event, the check-in and the check-out. |
Methods
To open or close the picker from your own button, set closeDatepickerOnClickOutside to false and call these methods through a template ref.
| Name | Description |
|---|---|
showDatepicker | Shows the datepicker. |
hideDatepicker | Hides the datepicker. |
toggleDatepicker | Shows the datepicker if hidden, hides it if shown. |
Translations
Pass an object to i18n. Bundled locales in this repo: Portuguese, French, English, Spanish (Spain and Latin America) and Italian. These are the English defaults:
i18n: {
night: 'Night',
nights: 'Nights',
week: 'week',
weeks: 'weeks',
'day-names': ['Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'],
'check-in': 'Check-in',
'check-out': 'Check-out',
'month-names': [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December',
],
tooltip: {
halfDayCheckIn: 'Available CheckIn',
halfDayCheckOut: 'Available CheckOut',
saturdayToSaturday: 'Only Saturday to Saturday',
sundayToSunday: 'Only Sunday to Sunday',
minimumRequiredPeriod: '%{minNightInPeriod} %{night} minimum.',
},
}