willba-component-library 0.3.26 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -113
- package/lib/components/FilterBar/FilterBar.d.ts +1 -1
- package/lib/components/FilterCalendar/FilterCalendar.d.ts +1 -1
- package/lib/core/i18n/I18nProvider.d.ts +6 -0
- package/lib/core/i18n/index.d.ts +1 -0
- package/lib/embed.d.ts +18 -0
- package/lib/embed.esm.js +74 -0
- package/lib/embed.esm.js.map +1 -0
- package/lib/embed.umd.js +74 -0
- package/lib/embed.umd.js.map +1 -0
- package/lib/i18n.d.ts +2 -2
- package/lib/index.d.ts +2 -2
- package/lib/index.esm.js +1112 -931
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1111 -930
- package/lib/index.js.map +1 -1
- package/package.json +9 -1
- package/.nvmrc +0 -1
- package/.storybook/main.ts +0 -17
- package/.storybook/preview.ts +0 -15
- package/lib/components/FilterBar/components/buttons/index.d.ts +0 -4
- package/lib/components/FilterBar/components/buttons/select-button/SelectButton.d.ts +0 -13
- package/lib/components/FilterBar/components/buttons/tab-button/TabButton.d.ts +0 -10
- package/lib/components/FilterBar/components/cards/image-card/ImageCard.d.ts +0 -11
- package/lib/components/FilterBar/components/cards/index.d.ts +0 -1
- package/lib/components/FilterBar/components/categories/Categories.d.ts +0 -8
- package/lib/components/FilterBar/components/common/FilterSectionHeader.d.ts +0 -8
- package/lib/components/FilterBar/components/dates/Dates.d.ts +0 -17
- package/lib/components/FilterBar/components/dates/index.d.ts +0 -1
- package/lib/components/FilterBar/components/guests/GuestCount/GuestCount.d.ts +0 -4
- package/lib/components/FilterBar/components/guests/Guests.d.ts +0 -12
- package/lib/components/FilterBar/components/locations/Locations.d.ts +0 -14
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +0 -32
- package/lib/components/FilterBar/hooks/useFilterUi.d.ts +0 -8
- package/lib/components/FilterBar/utils/calculateDropdownPosition.d.ts +0 -12
- package/lib/components/FilterBar/utils/getLocalizedContent.d.ts +0 -8
- package/lib/core/components/buttons/close-button/CloseButton.d.ts +0 -7
- package/lib/core/components/buttons/submit-button/SubmitButton.d.ts +0 -14
- package/lib/index.umd.js +0 -12489
- package/lib/index.umd.js.map +0 -1
- package/prettier.config.js +0 -6
- package/rollup.config.mjs +0 -63
- package/src/assets/IconsSvg.tsx +0 -69
- package/src/components/Button/Button.stories.tsx +0 -34
- package/src/components/Button/Button.tsx +0 -56
- package/src/components/Button/button.css +0 -30
- package/src/components/Button/index.ts +0 -1
- package/src/components/FilterBar/FilterBar.css +0 -35
- package/src/components/FilterBar/FilterBar.stories.tsx +0 -116
- package/src/components/FilterBar/FilterBar.tsx +0 -64
- package/src/components/FilterBar/FilterBarTypes.ts +0 -71
- package/src/components/FilterBar/components/Divider/Divider.css +0 -14
- package/src/components/FilterBar/components/Divider/Divider.tsx +0 -7
- package/src/components/FilterBar/components/FilterControls/FilterControls.css +0 -22
- package/src/components/FilterBar/components/FilterControls/FilterControls.tsx +0 -139
- package/src/components/FilterBar/components/FilterPanels/Categories/Categories.css +0 -21
- package/src/components/FilterBar/components/FilterPanels/Categories/Categories.tsx +0 -49
- package/src/components/FilterBar/components/FilterPanels/Dates/Dates.css +0 -9
- package/src/components/FilterBar/components/FilterPanels/Dates/Dates.tsx +0 -60
- package/src/components/FilterBar/components/FilterPanels/FilterPanels.css +0 -22
- package/src/components/FilterBar/components/FilterPanels/FilterPanels.tsx +0 -111
- package/src/components/FilterBar/components/FilterPanels/Guests/GuestCount/GuestCount.css +0 -58
- package/src/components/FilterBar/components/FilterPanels/Guests/GuestCount/GuestCount.tsx +0 -85
- package/src/components/FilterBar/components/FilterPanels/Guests/Guests.css +0 -24
- package/src/components/FilterBar/components/FilterPanels/Guests/Guests.tsx +0 -59
- package/src/components/FilterBar/components/FilterPanels/Locations/Locations.css +0 -16
- package/src/components/FilterBar/components/FilterPanels/Locations/Locations.tsx +0 -94
- package/src/components/FilterBar/components/FilterPanels/SectionHeader/SectionHeader.css +0 -34
- package/src/components/FilterBar/components/FilterPanels/SectionHeader/SectionHeader.tsx +0 -17
- package/src/components/FilterBar/components/FilterTabs/FilterTabs.css +0 -10
- package/src/components/FilterBar/components/FilterTabs/FilterTabs.tsx +0 -50
- package/src/components/FilterBar/components/ImageCard/ImageCard.css +0 -30
- package/src/components/FilterBar/components/ImageCard/ImageCard.tsx +0 -45
- package/src/components/FilterBar/components/SelectButton/SelectButton.css +0 -76
- package/src/components/FilterBar/components/SelectButton/SelectButton.tsx +0 -54
- package/src/components/FilterBar/components/TabButton/TabButton.css +0 -36
- package/src/components/FilterBar/components/TabButton/TabButton.tsx +0 -23
- package/src/components/FilterBar/components/index.ts +0 -6
- package/src/components/FilterBar/hooks/index.ts +0 -5
- package/src/components/FilterBar/hooks/useFilterActions.tsx +0 -126
- package/src/components/FilterBar/hooks/useFilterRefs.tsx +0 -21
- package/src/components/FilterBar/hooks/useFilterState.tsx +0 -86
- package/src/components/FilterBar/hooks/usePanelPosition.tsx +0 -52
- package/src/components/FilterBar/hooks/useScrollInToView.tsx +0 -29
- package/src/components/FilterBar/index.ts +0 -3
- package/src/components/FilterBar/providers/FilterBarProvider.tsx +0 -172
- package/src/components/FilterBar/providers/index.ts +0 -1
- package/src/components/FilterBar/utils/ageCategoriesRules.ts +0 -27
- package/src/components/FilterBar/utils/index.tsx +0 -3
- package/src/components/FilterBar/utils/parseGuests.tsx +0 -65
- package/src/components/FilterBar/utils/parseLocations.ts +0 -28
- package/src/components/FilterCalendar/FilterCalendar.css +0 -109
- package/src/components/FilterCalendar/FilterCalendar.stories.tsx +0 -554
- package/src/components/FilterCalendar/FilterCalendar.tsx +0 -115
- package/src/components/FilterCalendar/FilterCalendarTypes.ts +0 -11
- package/src/components/FilterCalendar/components/Footer.tsx +0 -96
- package/src/components/FilterCalendar/hooks/useFilterCalendar.ts +0 -163
- package/src/components/FilterCalendar/index.ts +0 -3
- package/src/core/components/buttons/CloseButton/CloseButton.css +0 -33
- package/src/core/components/buttons/CloseButton/CloseButton.tsx +0 -16
- package/src/core/components/buttons/SubmitButton/SubmitButton.css +0 -54
- package/src/core/components/buttons/SubmitButton/SubmitButton.tsx +0 -42
- package/src/core/components/calendar/Calendar.css +0 -280
- package/src/core/components/calendar/Calendar.tsx +0 -253
- package/src/core/components/calendar/CalendarTypes.ts +0 -48
- package/src/core/components/calendar/hooks/index.ts +0 -3
- package/src/core/components/calendar/hooks/useCalendarLoadingSpinner.tsx +0 -19
- package/src/core/components/calendar/hooks/useCalendarTooltips.tsx +0 -125
- package/src/core/components/calendar/hooks/useUpdateDisabledDates.tsx +0 -105
- package/src/core/components/calendar/utils/calendarSelectionRules.tsx +0 -180
- package/src/core/components/calendar/utils/checkForContinuousSelection.tsx +0 -86
- package/src/core/components/calendar/utils/disabledDatesByPage.tsx +0 -31
- package/src/core/components/calendar/utils/handleCalendarModifiers.tsx +0 -118
- package/src/core/components/calendar/utils/handleRangeContextDisabledDates.tsx +0 -75
- package/src/core/components/calendar/utils/index.ts +0 -8
- package/src/core/components/calendar/utils/nightsCount.tsx +0 -19
- package/src/core/components/calendar/utils/parseDate.tsx +0 -17
- package/src/core/components/calendar/utils/parseDates.tsx +0 -12
- package/src/core/components/index.ts +0 -7
- package/src/core/hooks/index.ts +0 -4
- package/src/core/hooks/useAutoFocus.tsx +0 -27
- package/src/core/hooks/useAwaitRender.tsx +0 -12
- package/src/core/hooks/useCloseFilterSection.tsx +0 -29
- package/src/core/hooks/useUpdateTranslations.tsx +0 -14
- package/src/i18n.ts +0 -27
- package/src/index.ts +0 -8
- package/src/locales/en/common.json +0 -18
- package/src/locales/en/filterBar.json +0 -33
- package/src/locales/fi/common.json +0 -19
- package/src/locales/fi/filterBar.json +0 -33
- package/src/themes/Default.css +0 -69
- package/src/themes/useTheme.tsx +0 -27
- package/stories/Button.stories.ts +0 -50
- package/stories/Button.tsx +0 -53
- package/stories/Configure.mdx +0 -364
- package/stories/Header.stories.ts +0 -27
- package/stories/Header.tsx +0 -70
- package/stories/Page.stories.ts +0 -29
- package/stories/Page.tsx +0 -91
- package/stories/assets/accessibility.png +0 -0
- package/stories/assets/accessibility.svg +0 -5
- package/stories/assets/addon-library.png +0 -0
- package/stories/assets/assets.png +0 -0
- package/stories/assets/context.png +0 -0
- package/stories/assets/discord.svg +0 -15
- package/stories/assets/docs.png +0 -0
- package/stories/assets/figma-plugin.png +0 -0
- package/stories/assets/github.svg +0 -3
- package/stories/assets/share.png +0 -0
- package/stories/assets/styling.png +0 -0
- package/stories/assets/testing.png +0 -0
- package/stories/assets/theming.png +0 -0
- package/stories/assets/tutorials.svg +0 -12
- package/stories/assets/youtube.svg +0 -4
- package/stories/button.css +0 -30
- package/stories/header.css +0 -32
- package/stories/page.css +0 -69
- package/tsconfig.json +0 -29
- /package/lib/components/FilterBar/components/{divider → Divider}/Divider.d.ts +0 -0
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import React, { forwardRef } from 'react'
|
|
2
|
-
import { addDays, startOfDay } from 'date-fns'
|
|
3
|
-
import { fi, enUS } from 'date-fns/locale'
|
|
4
|
-
import { useTranslation } from 'react-i18next'
|
|
5
|
-
import { DateRange, DayPicker } from 'react-day-picker'
|
|
6
|
-
import { useMediaQuery } from 'react-responsive'
|
|
7
|
-
|
|
8
|
-
import { CalendarTypes } from './CalendarTypes'
|
|
9
|
-
import { IconsSvg } from '../../../assets/IconsSvg'
|
|
10
|
-
import {
|
|
11
|
-
calendarSelectionRules,
|
|
12
|
-
checkForContinuousSelection,
|
|
13
|
-
handleCalendarModifiers,
|
|
14
|
-
disabledDatesByPage as handleDisabledDatesByPage,
|
|
15
|
-
handleRangeContextDisabledDates,
|
|
16
|
-
} from './utils'
|
|
17
|
-
import {
|
|
18
|
-
useCalendarLoadingSpinner,
|
|
19
|
-
useCalendarTooltips,
|
|
20
|
-
useUpdateDisabledDates,
|
|
21
|
-
} from './hooks'
|
|
22
|
-
import { useAutoFocus } from '../../hooks'
|
|
23
|
-
|
|
24
|
-
import 'react-day-picker/dist/style.css'
|
|
25
|
-
import './Calendar.css'
|
|
26
|
-
|
|
27
|
-
export const Calendar = forwardRef<HTMLDivElement, CalendarTypes>(
|
|
28
|
-
(
|
|
29
|
-
{
|
|
30
|
-
selectedPath,
|
|
31
|
-
calendarRange,
|
|
32
|
-
setCalendarRange,
|
|
33
|
-
language,
|
|
34
|
-
disableCalendarDates,
|
|
35
|
-
requestDates,
|
|
36
|
-
disabledDates,
|
|
37
|
-
updateCalendarMonthNavigation,
|
|
38
|
-
setUpdateCalendarMonthNavigation,
|
|
39
|
-
updateCalendarDefaultMonth,
|
|
40
|
-
loadingData,
|
|
41
|
-
showFeedback,
|
|
42
|
-
palette,
|
|
43
|
-
setCalendarHasError,
|
|
44
|
-
setUpdatedForSubmit,
|
|
45
|
-
rangeContext,
|
|
46
|
-
calendarHasError,
|
|
47
|
-
autoFocus,
|
|
48
|
-
}: CalendarTypes,
|
|
49
|
-
ref
|
|
50
|
-
) => {
|
|
51
|
-
// Translations
|
|
52
|
-
const { t } = useTranslation('common')
|
|
53
|
-
|
|
54
|
-
const calendarContainerRef = useAutoFocus<HTMLDivElement>(autoFocus)
|
|
55
|
-
|
|
56
|
-
const isTablet = useMediaQuery({ maxWidth: 960 })
|
|
57
|
-
const today = startOfDay(new Date())
|
|
58
|
-
const selectedStartDate = calendarRange?.from
|
|
59
|
-
const rangeContextStartDate = rangeContext?.from
|
|
60
|
-
|
|
61
|
-
// Handle initial disable dates including overlapping availableDates.lastCheckOut and disabledDates.start
|
|
62
|
-
const { newDisableCalendarDates, overlappingDate, lastPossibleCheckout } =
|
|
63
|
-
useUpdateDisabledDates({
|
|
64
|
-
disableCalendarDates,
|
|
65
|
-
calendarRange,
|
|
66
|
-
updateCalendarMonthNavigation,
|
|
67
|
-
updateCalendarDefaultMonth,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// Handle disable dates by page
|
|
71
|
-
const disabledDatesByPage = handleDisabledDatesByPage({
|
|
72
|
-
today,
|
|
73
|
-
selectedPath,
|
|
74
|
-
newDisableCalendarDates,
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
// Handle tooltip
|
|
78
|
-
useCalendarTooltips({
|
|
79
|
-
showFeedback,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// Handle loading spinner
|
|
83
|
-
useCalendarLoadingSpinner({
|
|
84
|
-
loadingData,
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
// Handle the date selection and availability for selection logic.
|
|
88
|
-
const handleOnSelect = (range?: DateRange) => {
|
|
89
|
-
setCalendarHasError && calendarHasError && setCalendarHasError(false)
|
|
90
|
-
|
|
91
|
-
calendarSelectionRules({
|
|
92
|
-
range,
|
|
93
|
-
newDisableCalendarDates,
|
|
94
|
-
setCalendarRange,
|
|
95
|
-
calendarRange,
|
|
96
|
-
overlappingDate,
|
|
97
|
-
setCalendarHasError,
|
|
98
|
-
rangeContext,
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
setUpdatedForSubmit && setUpdatedForSubmit(true)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Handle disabled dates for range context
|
|
105
|
-
const {
|
|
106
|
-
findFirstPossibleRangeContextCheckIn,
|
|
107
|
-
findLastPossibleRangeContextCheckOut,
|
|
108
|
-
firstPossibleRangeContextCheckIn,
|
|
109
|
-
lastPossibleRangeContextCheckOut,
|
|
110
|
-
currentSelectionAvailability,
|
|
111
|
-
} = handleRangeContextDisabledDates({
|
|
112
|
-
rangeContext,
|
|
113
|
-
availableDates: newDisableCalendarDates?.availableDates,
|
|
114
|
-
calendarRange,
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
// Handle check for continuous selection in the range context
|
|
118
|
-
checkForContinuousSelection({
|
|
119
|
-
setCalendarHasError,
|
|
120
|
-
rangeContext,
|
|
121
|
-
calendarRange,
|
|
122
|
-
calendarHasError,
|
|
123
|
-
disabledDates: newDisableCalendarDates?.disabledDates,
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const disabledInsideSelectableRange = () => {
|
|
127
|
-
if (
|
|
128
|
-
// Range end already selected
|
|
129
|
-
calendarRange?.to ||
|
|
130
|
-
// No current check-in availability
|
|
131
|
-
!currentSelectionAvailability ||
|
|
132
|
-
// No gap between check-in and first possible check-out, nothing to disable
|
|
133
|
-
addDays(currentSelectionAvailability.checkIn, 1) >=
|
|
134
|
-
currentSelectionAvailability.firstCheckOut
|
|
135
|
-
) {
|
|
136
|
-
return []
|
|
137
|
-
}
|
|
138
|
-
// Disable dates between current check-in and first possible check-out
|
|
139
|
-
return [
|
|
140
|
-
{
|
|
141
|
-
from: addDays(currentSelectionAvailability.checkIn, 1),
|
|
142
|
-
to: addDays(currentSelectionAvailability.firstCheckOut, -1),
|
|
143
|
-
},
|
|
144
|
-
]
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const base = disabledDatesByPage.length
|
|
148
|
-
? disabledDatesByPage
|
|
149
|
-
: disabledDates?.length
|
|
150
|
-
? disabledDates
|
|
151
|
-
: newDisableCalendarDates?.disabledDates || []
|
|
152
|
-
|
|
153
|
-
const disabled = disabledDatesByPage.length
|
|
154
|
-
? base
|
|
155
|
-
: [
|
|
156
|
-
lastPossibleCheckout,
|
|
157
|
-
...base,
|
|
158
|
-
...firstPossibleRangeContextCheckIn,
|
|
159
|
-
...lastPossibleRangeContextCheckOut,
|
|
160
|
-
...disabledInsideSelectableRange(),
|
|
161
|
-
]
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
<div className="will-filter-bar-calendar" ref={ref}>
|
|
165
|
-
<div
|
|
166
|
-
className="will-calendar-filter-container"
|
|
167
|
-
ref={calendarContainerRef}
|
|
168
|
-
>
|
|
169
|
-
<DayPicker
|
|
170
|
-
key={updateCalendarDefaultMonth}
|
|
171
|
-
id="will-calendar"
|
|
172
|
-
mode="range"
|
|
173
|
-
locale={language === 'en' ? enUS : fi}
|
|
174
|
-
numberOfMonths={!isTablet ? 2 : 1}
|
|
175
|
-
weekStartsOn={1}
|
|
176
|
-
selected={calendarRange}
|
|
177
|
-
onSelect={(range) => handleOnSelect(range)}
|
|
178
|
-
captionLayout="dropdown-buttons"
|
|
179
|
-
defaultMonth={
|
|
180
|
-
calendarRange?.from ||
|
|
181
|
-
selectedStartDate ||
|
|
182
|
-
rangeContextStartDate ||
|
|
183
|
-
(newDisableCalendarDates?.disabledDates?.length
|
|
184
|
-
? newDisableCalendarDates.disabledDates[0].from
|
|
185
|
-
: today)
|
|
186
|
-
}
|
|
187
|
-
disabled={disabled}
|
|
188
|
-
fromMonth={today}
|
|
189
|
-
onMonthChange={(val) => {
|
|
190
|
-
requestDates?.(val)
|
|
191
|
-
setUpdateCalendarMonthNavigation?.((prev) => !prev)
|
|
192
|
-
}}
|
|
193
|
-
classNames={{
|
|
194
|
-
day_range_start: calendarRange?.from ? 'rdp-day_range_start' : '',
|
|
195
|
-
day_range_end: calendarRange?.to ? 'rdp-day_range_end' : '',
|
|
196
|
-
}}
|
|
197
|
-
modifiersClassNames={{
|
|
198
|
-
today: 'my-today',
|
|
199
|
-
booked: 'booked',
|
|
200
|
-
disabledAfterCheckIn: 'disabled-after-check-in',
|
|
201
|
-
overlappingDate: 'overlapping-date',
|
|
202
|
-
|
|
203
|
-
noActiveSelectionStart: 'no-active-selection-start',
|
|
204
|
-
noActiveSelectionMid: 'no-active-selection-mid',
|
|
205
|
-
noActiveSelectionEnd: 'no-active-selection-end',
|
|
206
|
-
|
|
207
|
-
checkoutOptionsMid:
|
|
208
|
-
'rdp-day_selected rdp-day_range_middle checkout-option',
|
|
209
|
-
|
|
210
|
-
checkInOnly: 'check-in-only',
|
|
211
|
-
checkOutOnly: 'check-out-only',
|
|
212
|
-
}}
|
|
213
|
-
modifiers={
|
|
214
|
-
// This function handles conditions for applying the modifiersClassNames
|
|
215
|
-
handleCalendarModifiers({
|
|
216
|
-
calendarRange,
|
|
217
|
-
disabledDates: disabled,
|
|
218
|
-
overlappingDate,
|
|
219
|
-
rangeContext,
|
|
220
|
-
findFirstPossibleRangeContextCheckIn,
|
|
221
|
-
findLastPossibleRangeContextCheckOut,
|
|
222
|
-
currentSelectionLastCheckoutDate: currentSelectionAvailability,
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
/>
|
|
226
|
-
|
|
227
|
-
<div className={'will-calendar-tooltip'}>
|
|
228
|
-
<div>{t('noCheckIn')}</div>
|
|
229
|
-
</div>
|
|
230
|
-
<div className={'will-calendar-tooltip-check-out'}>
|
|
231
|
-
<div>{t('noCheckOut')}</div>
|
|
232
|
-
</div>
|
|
233
|
-
<div className={'will-calendar-tooltip-overlapping-date'}>
|
|
234
|
-
<div>{t('checkOutOnly')}</div>
|
|
235
|
-
</div>
|
|
236
|
-
<div className={'will-calendar-tooltip-check-in-only'}>
|
|
237
|
-
<div>{t('checkInOnly')}</div>
|
|
238
|
-
</div>
|
|
239
|
-
<div className={'will-calendar-tooltip-check-out-only'}>
|
|
240
|
-
<div>{t('checkOutOnly')}</div>
|
|
241
|
-
</div>
|
|
242
|
-
<div className={'will-calendar-spinner'}>
|
|
243
|
-
<IconsSvg
|
|
244
|
-
fill={palette?.primary || 'inherit'}
|
|
245
|
-
size={50}
|
|
246
|
-
icon="spinner"
|
|
247
|
-
/>
|
|
248
|
-
</div>
|
|
249
|
-
</div>
|
|
250
|
-
</div>
|
|
251
|
-
)
|
|
252
|
-
}
|
|
253
|
-
)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { DateRange, Matcher } from 'react-day-picker'
|
|
2
|
-
import { Palette } from '../../../themes/useTheme'
|
|
3
|
-
|
|
4
|
-
export type CalendarOffset = {
|
|
5
|
-
[key: string]: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type DisableCalendarDates = {
|
|
9
|
-
availableDates?: {
|
|
10
|
-
checkIn: Date
|
|
11
|
-
firstCheckOut: Date
|
|
12
|
-
lastCheckOut: Date
|
|
13
|
-
}[]
|
|
14
|
-
disabledDates?: { to: Date; from: Date }[]
|
|
15
|
-
disabledDatesByPage?: {
|
|
16
|
-
page: string
|
|
17
|
-
offset: number
|
|
18
|
-
}[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type RangeContext = {
|
|
22
|
-
from: Date
|
|
23
|
-
to: Date
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type CalendarTypes = {
|
|
27
|
-
calendarRange?: DateRange | undefined
|
|
28
|
-
setCalendarRange: (range: DateRange | undefined) => void
|
|
29
|
-
calendarOffset?: CalendarOffset
|
|
30
|
-
selectedPath?: string
|
|
31
|
-
language?: string
|
|
32
|
-
disableCalendarDates?: DisableCalendarDates
|
|
33
|
-
requestDates?: (val: Date) => void
|
|
34
|
-
disabledDates?: Matcher[]
|
|
35
|
-
setDisabledDates?: (arg: Matcher[]) => void
|
|
36
|
-
loadingData?: boolean
|
|
37
|
-
showFeedback?: boolean
|
|
38
|
-
noActiveSelection?: boolean
|
|
39
|
-
palette?: Palette
|
|
40
|
-
updateCalendarMonthNavigation?: boolean
|
|
41
|
-
setUpdateCalendarMonthNavigation?: (arg: (prev: boolean) => boolean) => void
|
|
42
|
-
updateCalendarDefaultMonth?: number
|
|
43
|
-
setCalendarHasError?: (arg: boolean) => void
|
|
44
|
-
setUpdatedForSubmit?: (arg: boolean) => void
|
|
45
|
-
rangeContext?: RangeContext
|
|
46
|
-
calendarHasError?: boolean
|
|
47
|
-
autoFocus?: boolean
|
|
48
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
loadingData?: boolean
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const useCalendarLoadingSpinner = ({ loadingData }: Props) =>
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (typeof document === 'undefined') return
|
|
10
|
-
|
|
11
|
-
const loadingSpinner: HTMLElement | null = document.querySelector(
|
|
12
|
-
'.will-filter-bar-calendar .rdp-months .will-calendar-spinner'
|
|
13
|
-
)
|
|
14
|
-
if (loadingData) {
|
|
15
|
-
if (loadingSpinner) loadingSpinner.style.display = 'flex'
|
|
16
|
-
} else {
|
|
17
|
-
if (loadingSpinner) loadingSpinner.style.display = 'none'
|
|
18
|
-
}
|
|
19
|
-
})
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
type Props = {
|
|
4
|
-
showFeedback?: boolean
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const useCalendarTooltips = ({ showFeedback }: Props) =>
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (typeof document === 'undefined' || !showFeedback) return
|
|
10
|
-
|
|
11
|
-
// Children
|
|
12
|
-
const calendarTooltip = document.querySelector('.will-calendar-tooltip')
|
|
13
|
-
const calendarTooltipCheckOut = document.querySelector(
|
|
14
|
-
'.will-calendar-tooltip-check-out'
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
const calendarTooltipOverlappingDate = document.querySelector(
|
|
18
|
-
'.will-calendar-tooltip-overlapping-date'
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
const loadingSpinner = document.querySelector(
|
|
22
|
-
'.will-filter-bar-calendar .will-calendar-spinner'
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
const calendarTooltipCheckInOnly = document.querySelector(
|
|
26
|
-
'.will-calendar-tooltip-check-in-only'
|
|
27
|
-
)
|
|
28
|
-
const calendarTooltipCheckOutOnly = document.querySelector(
|
|
29
|
-
'.will-calendar-tooltip-check-out-only'
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
// Parents
|
|
33
|
-
const calendarButtons = document.querySelectorAll(
|
|
34
|
-
'.will-filter-bar-calendar .rdp-cell:has(.booked):not(:has(.disabled-after-check-in))'
|
|
35
|
-
)
|
|
36
|
-
const calendarButtonsCheckOut = document.querySelectorAll(
|
|
37
|
-
'.will-filter-bar-calendar .rdp-cell:has(.booked.disabled-after-check-in)'
|
|
38
|
-
)
|
|
39
|
-
const calendarMonthContainer = document.querySelector(
|
|
40
|
-
'.will-filter-bar-calendar .rdp-months'
|
|
41
|
-
)
|
|
42
|
-
const calendarOverlappingDate = document.querySelectorAll(
|
|
43
|
-
'.will-filter-bar-calendar .rdp-cell:has(.overlapping-date)'
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
const calendarCheckInOnly = document.querySelectorAll(
|
|
47
|
-
'.will-filter-bar-calendar .rdp-cell:has(.check-in-only)'
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
const calendarCheckOutOnly = document.querySelectorAll(
|
|
51
|
-
'.will-filter-bar-calendar .rdp-cell:has(.check-out-only)'
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
// Append children to parents
|
|
55
|
-
|
|
56
|
-
const tooltipClonesCheckIn: Element[] = []
|
|
57
|
-
const tooltipClonesCheckOut: Element[] = []
|
|
58
|
-
const tooltipClonesCheckInOnly: Element[] = []
|
|
59
|
-
const tooltipClonesCheckOutOnly: Element[] = []
|
|
60
|
-
const tooltipClonesSpinner: Element[] = []
|
|
61
|
-
const tooltipClonesOverlappingDates: Element[] = []
|
|
62
|
-
|
|
63
|
-
if (calendarTooltip && calendarButtons.length > 0) {
|
|
64
|
-
calendarButtons.forEach((element) => {
|
|
65
|
-
const tooltipClone: Element = calendarTooltip.cloneNode(true) as Element
|
|
66
|
-
element.appendChild(tooltipClone)
|
|
67
|
-
tooltipClonesCheckIn.push(tooltipClone)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (calendarTooltipCheckOut && calendarButtonsCheckOut.length > 0) {
|
|
72
|
-
calendarButtonsCheckOut.forEach((element) => {
|
|
73
|
-
const tooltipClone: Element = calendarTooltipCheckOut.cloneNode(
|
|
74
|
-
true
|
|
75
|
-
) as Element
|
|
76
|
-
element.appendChild(tooltipClone)
|
|
77
|
-
tooltipClonesCheckOut.push(tooltipClone)
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (calendarTooltipCheckOutOnly && calendarCheckOutOnly.length > 0) {
|
|
82
|
-
calendarCheckOutOnly.forEach((element) => {
|
|
83
|
-
const tooltipClone: Element = calendarTooltipCheckOutOnly.cloneNode(
|
|
84
|
-
true
|
|
85
|
-
) as Element
|
|
86
|
-
element.appendChild(tooltipClone)
|
|
87
|
-
tooltipClonesCheckOutOnly.push(tooltipClone)
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (calendarTooltipCheckInOnly && calendarCheckInOnly.length > 0) {
|
|
92
|
-
calendarCheckInOnly.forEach((element) => {
|
|
93
|
-
const tooltipClone: Element = calendarTooltipCheckInOnly.cloneNode(
|
|
94
|
-
true
|
|
95
|
-
) as Element
|
|
96
|
-
element.appendChild(tooltipClone)
|
|
97
|
-
tooltipClonesCheckInOnly.push(tooltipClone)
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (loadingSpinner && calendarMonthContainer) {
|
|
102
|
-
const tooltipClone: Element = loadingSpinner.cloneNode(true) as Element
|
|
103
|
-
calendarMonthContainer.appendChild(tooltipClone)
|
|
104
|
-
tooltipClonesSpinner.push(tooltipClone)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (calendarTooltipOverlappingDate && calendarOverlappingDate.length > 0) {
|
|
108
|
-
calendarOverlappingDate.forEach((element) => {
|
|
109
|
-
const tooltipClone: Element = calendarTooltipOverlappingDate.cloneNode(
|
|
110
|
-
true
|
|
111
|
-
) as Element
|
|
112
|
-
element.appendChild(tooltipClone)
|
|
113
|
-
tooltipClonesOverlappingDates.push(tooltipClone)
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return () => {
|
|
118
|
-
tooltipClonesCheckIn.forEach((clone) => clone.remove())
|
|
119
|
-
tooltipClonesCheckOut.forEach((clone) => clone.remove())
|
|
120
|
-
tooltipClonesSpinner.forEach((clone) => clone.remove())
|
|
121
|
-
tooltipClonesOverlappingDates.forEach((clone) => clone.remove())
|
|
122
|
-
tooltipClonesCheckInOnly.forEach((clone) => clone.remove())
|
|
123
|
-
tooltipClonesCheckOutOnly.forEach((clone) => clone.remove())
|
|
124
|
-
}
|
|
125
|
-
})
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react'
|
|
2
|
-
import { addDays, format } from 'date-fns'
|
|
3
|
-
import { DateRange, Matcher } from 'react-day-picker'
|
|
4
|
-
|
|
5
|
-
import { DisableCalendarDates } from '../CalendarTypes'
|
|
6
|
-
|
|
7
|
-
type Props = {
|
|
8
|
-
disableCalendarDates?: DisableCalendarDates
|
|
9
|
-
calendarRange?: DateRange
|
|
10
|
-
updateCalendarMonthNavigation?: boolean
|
|
11
|
-
updateCalendarDefaultMonth?: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const useUpdateDisabledDates = ({
|
|
15
|
-
disableCalendarDates,
|
|
16
|
-
calendarRange,
|
|
17
|
-
updateCalendarMonthNavigation,
|
|
18
|
-
updateCalendarDefaultMonth,
|
|
19
|
-
}: Props) => {
|
|
20
|
-
const [overlappingDate, setOverlappingDate] = useState<
|
|
21
|
-
DateRange[] | undefined
|
|
22
|
-
>(undefined)
|
|
23
|
-
|
|
24
|
-
const [lastPossibleCheckout, setLatsPossibleCheckout] = useState<Matcher>([])
|
|
25
|
-
|
|
26
|
-
const newDisableCalendarDates = useMemo(() => {
|
|
27
|
-
if (disableCalendarDates?.availableDates) {
|
|
28
|
-
const dateFormat = 'dd-MM-yyyy'
|
|
29
|
-
|
|
30
|
-
const { disabledDates } = disableCalendarDates
|
|
31
|
-
|
|
32
|
-
const { updatedDisabledDates, newOverlappingDates } = (
|
|
33
|
-
disabledDates || []
|
|
34
|
-
).reduce(
|
|
35
|
-
(
|
|
36
|
-
acc: {
|
|
37
|
-
updatedDisabledDates: { to: Date; from: Date }[]
|
|
38
|
-
newOverlappingDates: { to: Date; from: Date }[]
|
|
39
|
-
},
|
|
40
|
-
dateRange
|
|
41
|
-
) => {
|
|
42
|
-
const formattedFromDate = format(dateRange.from, dateFormat)
|
|
43
|
-
const formattedToDate = format(dateRange.to, dateFormat)
|
|
44
|
-
|
|
45
|
-
const hasTwoOverlappingDates =
|
|
46
|
-
disableCalendarDates.availableDates?.some(
|
|
47
|
-
(item) =>
|
|
48
|
-
format(item.lastCheckOut, dateFormat) === formattedFromDate &&
|
|
49
|
-
format(item.lastCheckOut, dateFormat) === formattedToDate
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
const hasOneOverlappingDate =
|
|
53
|
-
disableCalendarDates.availableDates?.some(
|
|
54
|
-
(item) =>
|
|
55
|
-
format(item.lastCheckOut, dateFormat) === formattedFromDate &&
|
|
56
|
-
format(item.lastCheckOut, dateFormat) !== formattedToDate
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
if (hasTwoOverlappingDates) {
|
|
60
|
-
acc.newOverlappingDates.push(dateRange)
|
|
61
|
-
} else if (hasOneOverlappingDate) {
|
|
62
|
-
acc.newOverlappingDates.push(dateRange)
|
|
63
|
-
acc.updatedDisabledDates.push({
|
|
64
|
-
...dateRange,
|
|
65
|
-
from: addDays(dateRange.from, 1),
|
|
66
|
-
})
|
|
67
|
-
} else {
|
|
68
|
-
acc.updatedDisabledDates.push(dateRange)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return acc
|
|
72
|
-
},
|
|
73
|
-
{ updatedDisabledDates: [], newOverlappingDates: [] }
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
// Find last possible checkout ( disable all dates after the last possible checkout )
|
|
77
|
-
const lastPossibleCheckoutDate: Date | undefined =
|
|
78
|
-
disableCalendarDates.availableDates.at(-1)?.lastCheckOut
|
|
79
|
-
|
|
80
|
-
if (lastPossibleCheckoutDate) {
|
|
81
|
-
setLatsPossibleCheckout({ after: lastPossibleCheckoutDate })
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Extract overlapping dates ( dates that are only available for checkout )
|
|
85
|
-
if (newOverlappingDates.length) {
|
|
86
|
-
setOverlappingDate([...newOverlappingDates])
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const newDisableCalendarDates = {
|
|
90
|
-
...disableCalendarDates,
|
|
91
|
-
disabledDates: updatedDisabledDates,
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return newDisableCalendarDates
|
|
95
|
-
}
|
|
96
|
-
return disableCalendarDates
|
|
97
|
-
}, [
|
|
98
|
-
disableCalendarDates,
|
|
99
|
-
calendarRange,
|
|
100
|
-
updateCalendarMonthNavigation,
|
|
101
|
-
updateCalendarDefaultMonth,
|
|
102
|
-
])
|
|
103
|
-
|
|
104
|
-
return { newDisableCalendarDates, overlappingDate, lastPossibleCheckout }
|
|
105
|
-
}
|