From ce6405063b7a6538913a4cb42cecf4fca4bc6870 Mon Sep 17 00:00:00 2001 From: Joffrey Berrier Date: Tue, 3 May 2022 10:46:12 +0200 Subject: [PATCH] use dayjs remove fecha --- package-lock.json | 22 +++++----- package.json | 4 +- src/components/Calendar.vue | 43 +++++++++++-------- src/components/CalendarDays.vue | 1 + .../__tests__/CalendarInput.spec.ts | 2 +- src/components/compose/useCreateMonth.ts | 2 +- .../compose/useGetNextBookingDate.ts | 3 +- src/components/generateMonth.ts | 2 +- src/components/helpers.ts | 10 +---- src/plugins/day.ts | 16 +++++++ 10 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 src/plugins/day.ts diff --git a/package-lock.json b/package-lock.json index 0001e88..73020c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.1.2", "license": "MIT", "dependencies": { - "fecha": "^4.2.1" + "dayjs": "^1.11.1" }, "devDependencies": { "@rushstack/eslint-patch": "^1.1.0", @@ -1285,6 +1285,11 @@ "node": ">=12" } }, + "node_modules/dayjs": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz", + "integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA==" + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -2206,11 +2211,6 @@ "reusify": "^1.0.4" } }, - "node_modules/fecha": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.1.tgz", - "integrity": "sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q==" - }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -5024,6 +5024,11 @@ "whatwg-url": "^10.0.0" } }, + "dayjs": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz", + "integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA==" + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -5618,11 +5623,6 @@ "reusify": "^1.0.4" } }, - "fecha": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.1.tgz", - "integrity": "sha512-MMMQ0ludy/nBs1/o0zVOiKTpG7qMbonKUzjJgQFEuvq6INZ1OraKPRAWkBq5vlKLOUMpmNYG1JoN3oDPUQ9m3Q==" - }, "file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", diff --git a/package.json b/package.json index d20fcec..70d7ddf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-calendar-3", - "version": "1.1.2", + "version": "1.1.4", "repository": "https://github.com/joffreyBerrier/vue-datepicker", "funding": "https://github.com/sponsors/joffreyBerrier", "author": "Joffrey Berrier ", @@ -34,7 +34,7 @@ "vue": "^3.2.31" }, "dependencies": { - "fecha": "^4.2.1" + "dayjs": "^1.11.1" }, "devDependencies": { "@rushstack/eslint-patch": "^1.1.0", diff --git a/src/components/Calendar.vue b/src/components/Calendar.vue index 082e08e..4450f13 100644 --- a/src/components/Calendar.vue +++ b/src/components/Calendar.vue @@ -8,8 +8,7 @@ export default { import { computed, ref, onBeforeMount, onUnmounted } from "vue"; import type { ComputedRef, PropType, Ref } from "vue"; -import { format } from "fecha"; - +import { format } from "../plugins/day"; import BaseIcon from "./BaseIcon.vue"; import CalendarDays from "./CalendarDays.vue"; import CalendarHeader from "./CalendarHeader.vue"; @@ -332,9 +331,11 @@ const dayMouseLeave = () => { // Trigger each time the click on day is triggered const dayClicked = (day: Day): void => { - if (isInBookingDates(day)) { - emit("select-booking-date", day, getBooking(day)); - } else if (props.checkIn === day.date) { + emit("select-booking-date", day, getBooking(day)); + + if (isInBookingDates(day) && !isInCheckinHalfDayAndCheckin(day)) return; + + if (props.checkIn === day.date) { // CheckIn when already CheckIn emit("update:checkIn", null); emit("update:checkOut", null); @@ -342,7 +343,10 @@ const dayClicked = (day: Day): void => { currentPeriod.value = null; hoveringDates.value = []; hoveringDay.value = null; - } else if (props.checkIn && !props.checkOut) { + } else if ( + (props.checkIn && !props.checkOut) || + (isInBookingDates(day) && isInCheckinHalfDayAndCheckin(day) && props.checkIn) + ) { // CheckIn + !ChecKout emit("update:checkOut", day.date); currentPeriod.value = null; @@ -413,14 +417,20 @@ const isInBookingDates = (day: Day) => { !isInCheckoutHalfDay(day) ); }; -const isInCheckinHalfDayAndCheckin = (day: Day) => { - return checkIncheckOutHalfDay.value[day.formatDay]?.checkIn && props.checkIn; +const isInCheckinHalfDayAndCheckin = (day: Day): boolean => { + return ( + Boolean(checkIncheckOutHalfDay.value[day.formatDay]?.checkIn) && + Boolean(props.checkIn) + ); }; -const isInCheckinHalfDayAndNotCheckin = (day: Day) => { - return checkIncheckOutHalfDay.value[day.formatDay]?.checkIn && !props.checkIn; +const isInCheckinHalfDayAndNotCheckin = (day: Day): boolean => { + return ( + Boolean(checkIncheckOutHalfDay.value[day.formatDay]?.checkIn) && + Boolean(!props.checkIn) + ); }; -const isInCheckoutHalfDay = (day: Day) => { - return checkIncheckOutHalfDay.value[day.formatDay]?.checkOut; +const isInCheckoutHalfDay = (day: Day): boolean => { + return Boolean(checkIncheckOutHalfDay.value[day.formatDay]?.checkOut); }; const getBooking = (day: Day): FlatBooking | null => { if ( @@ -501,8 +511,7 @@ const getBookingType = (day: Day): string | null => { `calendar_day--${getBookingType(day)}`, { 'calendar_day-wrap--no-border': !day.belongsToThisMonth }, { - 'calendar_day-wrap--disabled': - inDisabledDay(day) && !isInBookingDates(day), + 'calendar_day-wrap--disabled': inDisabledDay(day), }, ]" @mouseenter="dayMouseOver(day)" @@ -542,8 +551,7 @@ const getBookingType = (day: Day): string | null => { }, // Disabled date { - 'calendar_day--disabled': - inDisabledDay(day) && !isInBookingDates(day), + 'calendar_day--disabled': inDisabledDay(day), }, // Hovering date { @@ -674,6 +682,7 @@ body { @apply border-2; border-color: var(--day-today); } +.calendar_day--checkIn-checkOut, .calendar_day--checkIn-checkOut.calendar_day--hovering { background-color: var(--day-checkIn-checkOut); } @@ -704,7 +713,7 @@ body { @apply w-full; } .calendar_wrapper--year .calendar_wrapper_content { - @apply grid grid-cols-4 gap-x-6 gap-y-2; + @apply grid grid-cols-4 gap-x-6 gap-y-6; } .calendar_paginate-wrapper { diff --git a/src/components/CalendarDays.vue b/src/components/CalendarDays.vue index 3d7897f..ba536c6 100644 --- a/src/components/CalendarDays.vue +++ b/src/components/CalendarDays.vue @@ -5,6 +5,7 @@ export default {