@skyscanner/backpack-web 42.27.3 → 43.0.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/bpk-component-accordion/src/BpkAccordionItem.d.ts +1 -1
- package/bpk-component-accordion/src/withAccordionItemState.d.ts +2 -7
- package/bpk-component-accordion/src/withAccordionItemState.js +4 -6
- package/bpk-component-accordion/src/withSingleItemAccordionState.d.ts +1 -1
- package/bpk-component-aria-live/src/BpkAriaLive.d.ts +1 -1
- package/bpk-component-aria-live/src/BpkAriaLive.story-helpers.d.ts +2 -2
- package/bpk-component-autosuggest/src/BpkAutosuggestV2/BpkAutosuggest.d.ts +4 -4
- package/bpk-component-badge/src/BpkBadge.module.css +1 -1
- package/bpk-component-banner-alert/src/AnimateAndFade.d.ts +4 -7
- package/bpk-component-banner-alert/src/AnimateAndFade.js +14 -10
- package/bpk-component-banner-alert/src/withBannerAlertState.d.ts +0 -10
- package/bpk-component-banner-alert/src/withBannerAlertState.js +3 -13
- package/bpk-component-barchart/src/BpkBarchart.js +24 -41
- package/bpk-component-barchart/src/BpkBarchartBar.js +7 -16
- package/bpk-component-barchart/src/BpkBarchartBars.js +6 -14
- package/bpk-component-barchart/src/BpkChartAxis.js +5 -12
- package/bpk-component-barchart/src/BpkChartDataTable.js +1 -4
- package/bpk-component-barchart/src/BpkChartGridLines.js +3 -8
- package/bpk-component-calendar/index.d.ts +2 -2
- package/bpk-component-calendar/index.js +2 -2
- package/bpk-component-calendar/src/BpkCalendarContainer.d.ts +3 -28
- package/bpk-component-calendar/src/BpkCalendarContainer.js +47 -34
- package/bpk-component-calendar/src/BpkCalendarDate.d.ts +0 -1
- package/bpk-component-calendar/src/BpkCalendarDate.js +32 -31
- package/bpk-component-calendar/src/BpkCalendarGrid.d.ts +13 -14
- package/bpk-component-calendar/src/BpkCalendarGrid.js +28 -37
- package/bpk-component-calendar/src/BpkCalendarGridHeader.d.ts +0 -4
- package/bpk-component-calendar/src/BpkCalendarGridHeader.js +2 -6
- package/bpk-component-calendar/src/BpkCalendarGridTransition.d.ts +0 -5
- package/bpk-component-calendar/src/BpkCalendarGridTransition.js +0 -5
- package/bpk-component-calendar/src/BpkCalendarWeek.d.ts +0 -1
- package/bpk-component-calendar/src/BpkCalendarWeek.js +19 -27
- package/bpk-component-calendar/src/custom-proptypes.d.ts +1 -1
- package/bpk-component-card-list/src/BpkCardList.js +0 -3
- package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.js +1 -3
- package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListRowRailContainer.js +1 -14
- package/bpk-component-card-list/src/BpkCardListRowRail/utils.d.ts +1 -2
- package/bpk-component-card-list/src/BpkCardListRowRail/utils.js +0 -21
- package/bpk-component-card-list/src/common-types.d.ts +4 -7
- package/bpk-component-chatbot-input/src/hooks/useChatbotInput.d.ts +1 -1
- package/bpk-component-chatbot-input/src/hooks/useTextAreaAutoResize.d.ts +1 -1
- package/bpk-component-datepicker/src/BpkDatepicker.d.ts +6 -192
- package/bpk-component-datepicker/src/BpkDatepicker.js +46 -53
- package/bpk-component-dialog/src/BpkDialogInner.d.ts +0 -7
- package/bpk-component-drawer/src/BpkDrawerContent.d.ts +2 -2
- package/bpk-component-drawer/src/BpkDrawerContent.js +13 -1
- package/bpk-component-fieldset/src/BpkFieldset.d.ts +1 -1
- package/bpk-component-floating-notification/src/BpkFloatingNotification.js +4 -1
- package/bpk-component-grid-toggle/src/BpkGridToggle.js +9 -7
- package/bpk-component-image/src/BpkBackgroundImage.d.ts +1 -9
- package/bpk-component-image/src/BpkBackgroundImage.js +18 -18
- package/bpk-component-image/src/BpkImage.d.ts +1 -8
- package/bpk-component-image/src/BpkImage.js +10 -18
- package/bpk-component-image/src/withLazyLoading.d.ts +0 -4
- package/bpk-component-image/src/withLazyLoading.js +2 -6
- package/bpk-component-infinite-scroll/src/withInfiniteScroll.js +6 -8
- package/bpk-component-info-banner/src/AnimateAndFade.d.ts +4 -7
- package/bpk-component-info-banner/src/AnimateAndFade.js +14 -10
- package/bpk-component-info-banner/src/withBannerAlertState.d.ts +0 -10
- package/bpk-component-info-banner/src/withBannerAlertState.js +3 -13
- package/bpk-component-input/index.d.ts +2 -2
- package/bpk-component-input/index.js +2 -2
- package/bpk-component-input/src/BpkInput.d.ts +0 -13
- package/bpk-component-input/src/BpkInput.js +13 -12
- package/bpk-component-input/src/common-types.d.ts +0 -32
- package/bpk-component-input/src/common-types.js +1 -56
- package/bpk-component-input/src/withOpenEvents.d.ts +1 -12
- package/bpk-component-input/src/withOpenEvents.js +2 -14
- package/bpk-component-layout/src/types.d.ts +19 -35
- package/bpk-component-map/src/BpkBasicMapMarker.d.ts +1 -8
- package/bpk-component-map/src/BpkBasicMapMarker.js +0 -6
- package/bpk-component-map/src/BpkIconMarker.js +4 -10
- package/bpk-component-map/src/BpkIconMarkerBackground.js +3 -8
- package/bpk-component-map/src/BpkMap.js +14 -30
- package/bpk-component-map/src/withGoogleMapsScript.js +4 -8
- package/bpk-component-mobile-scroll-container/src/BpkMobileScrollContainer.d.ts +0 -1
- package/bpk-component-mobile-scroll-container/src/BpkMobileScrollContainer.js +1 -5
- package/bpk-component-modal/index.d.ts +1 -2
- package/bpk-component-modal/index.js +1 -3
- package/bpk-component-navigation-bar/src/BpkNavigationBar.d.ts +2 -2
- package/bpk-component-phone-input/src/BpkPhoneInput.js +6 -14
- package/bpk-component-progress/src/BpkProgress.d.ts +0 -8
- package/bpk-component-progress/src/BpkProgress.js +10 -16
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendar.d.ts +0 -14
- package/bpk-component-section-list/src/BpkSectionListItem.js +4 -10
- package/bpk-component-section-list/src/BpkSectionListSection.js +1 -4
- package/bpk-component-segmented-control/src/BpkSegmentedControl.d.ts +1 -1
- package/bpk-component-select/src/BpkSelect.d.ts +1 -1
- package/bpk-component-slider/src/BpkSlider.js +1 -1
- package/bpk-component-spinner/src/SpinnerLayout.story-helpers.d.ts +1 -7
- package/bpk-component-spinner/src/SpinnerLayout.story-helpers.js +0 -4
- package/bpk-component-split-input/src/BpkInputField.d.ts +2 -6
- package/bpk-component-split-input/src/BpkInputField.js +2 -6
- package/bpk-component-split-input/src/BpkSplitInput.d.ts +0 -6
- package/bpk-component-split-input/src/BpkSplitInput.js +7 -13
- package/bpk-component-star-rating/src/withInteractiveStarRatingState.d.ts +0 -3
- package/bpk-component-star-rating/src/withInteractiveStarRatingState.js +0 -3
- package/bpk-component-ticket/src/BpkTicket.js +6 -14
- package/bpk-mixins/_badges.scss +3 -3
- package/bpk-react-utils/index.d.ts +3 -1
- package/bpk-react-utils/src/BpkDialogWrapper/BpkDialogWrapper.js +1 -0
- package/bpk-react-utils/src/Portal.d.ts +10 -22
- package/bpk-react-utils/src/Portal.js +22 -19
- package/bpk-react-utils/src/TransitionInitialMount.d.ts +4 -2
- package/bpk-react-utils/src/TransitionInitialMount.js +23 -14
- package/bpk-scrim-utils/index.d.ts +0 -7
- package/bpk-scrim-utils/src/withScrim.d.ts +0 -7
- package/bpk-scrim-utils/src/withScrim.js +10 -15
- package/package.json +3 -3
- package/bpk-component-modal/src/legacy-prop-types.js +0 -74
|
@@ -26,6 +26,13 @@ import composeCalendar from "./composeCalendar";
|
|
|
26
26
|
import { CALENDAR_SELECTION_TYPE } from "./custom-proptypes";
|
|
27
27
|
import { addDays, addMonths, dateToBoundaries, isAfter, isSameMonth, isSameDay, lastDayOfMonth, setMonthYear, startOfDay, startOfMonth } from "./date-utils";
|
|
28
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
|
+
export const DEFAULT_MARK_TODAY = true;
|
|
30
|
+
export const DEFAULT_MAX_DATE = addMonths(new Date(), 12);
|
|
31
|
+
export const DEFAULT_MIN_DATE = new Date();
|
|
32
|
+
const DEFAULT_SELECTION_CONFIGURATION = {
|
|
33
|
+
type: CALENDAR_SELECTION_TYPE.single,
|
|
34
|
+
date: null
|
|
35
|
+
};
|
|
29
36
|
/**
|
|
30
37
|
* Updates the current focused date
|
|
31
38
|
* @param {Object} prevProps previous input properties
|
|
@@ -33,8 +40,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
33
40
|
* @returns {Boolean} if the selected date has changed
|
|
34
41
|
*/
|
|
35
42
|
const focusedDateHasChanged = (prevProps, currentProps) => {
|
|
36
|
-
const prevSelectConfig = prevProps.selectionConfiguration;
|
|
37
|
-
const currentSelectConfig = currentProps.selectionConfiguration;
|
|
43
|
+
const prevSelectConfig = prevProps.selectionConfiguration ?? DEFAULT_SELECTION_CONFIGURATION;
|
|
44
|
+
const currentSelectConfig = currentProps.selectionConfiguration ?? DEFAULT_SELECTION_CONFIGURATION;
|
|
38
45
|
const rawCurrentSelectedDate = currentSelectConfig.type === CALENDAR_SELECTION_TYPE.single ? currentSelectConfig.date : currentSelectConfig.startDate;
|
|
39
46
|
const rawPrevSelectedDate = prevSelectConfig.type === CALENDAR_SELECTION_TYPE.single ? prevSelectConfig.date : prevSelectConfig.startDate;
|
|
40
47
|
if (!rawPrevSelectedDate && !rawCurrentSelectedDate) {
|
|
@@ -88,37 +95,31 @@ const getRawSelectedDate = selectionConfig => {
|
|
|
88
95
|
};
|
|
89
96
|
const withCalendarState = Calendar => {
|
|
90
97
|
class BpkCalendarContainer extends Component {
|
|
91
|
-
static defaultProps = {
|
|
92
|
-
fixedWidth: true,
|
|
93
|
-
maxDate: addMonths(new Date(), 12),
|
|
94
|
-
minDate: new Date(),
|
|
95
|
-
onDateSelect: null,
|
|
96
|
-
onMonthChange: null,
|
|
97
|
-
selectionConfiguration: {
|
|
98
|
-
type: CALENDAR_SELECTION_TYPE.single,
|
|
99
|
-
date: null
|
|
100
|
-
},
|
|
101
|
-
initiallyFocusedDate: null,
|
|
102
|
-
markToday: true,
|
|
103
|
-
markOutsideDays: true
|
|
104
|
-
};
|
|
105
98
|
constructor(props) {
|
|
106
99
|
super(props);
|
|
107
|
-
const minDate = startOfDay(this.props.minDate);
|
|
108
|
-
const maxDate = startOfDay(this.props.maxDate);
|
|
109
|
-
const rawSelectedDate = getRawSelectedDate(this.props.selectionConfiguration);
|
|
110
100
|
const {
|
|
111
|
-
initiallyFocusedDate
|
|
101
|
+
initiallyFocusedDate = null,
|
|
102
|
+
maxDate: maxDateProp = DEFAULT_MAX_DATE,
|
|
103
|
+
minDate: minDateProp = DEFAULT_MIN_DATE,
|
|
104
|
+
selectionConfiguration = DEFAULT_SELECTION_CONFIGURATION
|
|
112
105
|
} = this.props;
|
|
106
|
+
const minDate = startOfDay(minDateProp);
|
|
107
|
+
const maxDate = startOfDay(maxDateProp);
|
|
108
|
+
const rawSelectedDate = getRawSelectedDate(selectionConfiguration);
|
|
113
109
|
this.state = {
|
|
114
110
|
preventKeyboardFocus: true,
|
|
115
111
|
focusedDate: determineFocusedDate(rawSelectedDate[0], initiallyFocusedDate, minDate, maxDate)
|
|
116
112
|
};
|
|
117
113
|
}
|
|
118
114
|
componentDidUpdate(prevProps) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
const {
|
|
116
|
+
maxDate: maxDateProp = DEFAULT_MAX_DATE,
|
|
117
|
+
minDate: minDateProp = DEFAULT_MIN_DATE,
|
|
118
|
+
selectionConfiguration = DEFAULT_SELECTION_CONFIGURATION
|
|
119
|
+
} = this.props;
|
|
120
|
+
const rawNextSelectedDate = getRawSelectedDate(selectionConfiguration);
|
|
121
|
+
const minDate = startOfDay(minDateProp);
|
|
122
|
+
const maxDate = startOfDay(maxDateProp);
|
|
122
123
|
if (focusedDateHasChanged(prevProps, this.props)) {
|
|
123
124
|
this.setState({
|
|
124
125
|
focusedDate: dateToBoundaries(rawNextSelectedDate[0], minDate, maxDate)
|
|
@@ -130,9 +131,11 @@ const withCalendarState = Calendar => {
|
|
|
130
131
|
source
|
|
131
132
|
}) => {
|
|
132
133
|
const {
|
|
133
|
-
|
|
134
|
+
maxDate = DEFAULT_MAX_DATE,
|
|
135
|
+
minDate = DEFAULT_MIN_DATE,
|
|
136
|
+
onMonthChange = null
|
|
134
137
|
} = this.props;
|
|
135
|
-
const focusedDate = dateToBoundaries(date, startOfDay(
|
|
138
|
+
const focusedDate = dateToBoundaries(date, startOfDay(minDate), startOfDay(maxDate));
|
|
136
139
|
const didMonthChange = !isSameMonth(this.state.focusedDate, focusedDate);
|
|
137
140
|
this.setState({
|
|
138
141
|
preventKeyboardFocus: false,
|
|
@@ -148,15 +151,17 @@ const withCalendarState = Calendar => {
|
|
|
148
151
|
};
|
|
149
152
|
handleDateSelect = date => {
|
|
150
153
|
const {
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
maxDate = DEFAULT_MAX_DATE,
|
|
155
|
+
minDate = DEFAULT_MIN_DATE,
|
|
156
|
+
onDateSelect = null,
|
|
157
|
+
selectionConfiguration = DEFAULT_SELECTION_CONFIGURATION
|
|
153
158
|
} = this.props;
|
|
154
159
|
const keyboardFocusState = {
|
|
155
160
|
preventKeyboardFocus: false
|
|
156
161
|
};
|
|
157
162
|
if (onDateSelect) {
|
|
158
|
-
const newDate = dateToBoundaries(date, startOfDay(
|
|
159
|
-
if (selectionConfiguration
|
|
163
|
+
const newDate = dateToBoundaries(date, startOfDay(minDate), startOfDay(maxDate));
|
|
164
|
+
if (selectionConfiguration.type === CALENDAR_SELECTION_TYPE.range && selectionConfiguration.startDate && !selectionConfiguration.endDate && (isAfter(newDate, selectionConfiguration.startDate) || isSameDay(newDate, selectionConfiguration.startDate))) {
|
|
160
165
|
onDateSelect(selectionConfiguration.startDate, newDate);
|
|
161
166
|
} else {
|
|
162
167
|
onDateSelect(newDate);
|
|
@@ -240,11 +245,15 @@ const withCalendarState = Calendar => {
|
|
|
240
245
|
};
|
|
241
246
|
render() {
|
|
242
247
|
const {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
fixedWidth = true,
|
|
249
|
+
initiallyFocusedDate = null,
|
|
250
|
+
markOutsideDays = true,
|
|
251
|
+
markToday = DEFAULT_MARK_TODAY,
|
|
252
|
+
maxDate = DEFAULT_MAX_DATE,
|
|
253
|
+
minDate = DEFAULT_MIN_DATE,
|
|
254
|
+
onDateSelect = null,
|
|
255
|
+
onMonthChange = null,
|
|
256
|
+
selectionConfiguration = DEFAULT_SELECTION_CONFIGURATION,
|
|
248
257
|
...calendarProps
|
|
249
258
|
} = this.props;
|
|
250
259
|
const sanitisedMinDate = startOfDay(minDate);
|
|
@@ -258,6 +267,10 @@ const withCalendarState = Calendar => {
|
|
|
258
267
|
onDateKeyDown: this.handleDateKeyDown,
|
|
259
268
|
preventKeyboardFocus: this.state.preventKeyboardFocus,
|
|
260
269
|
focusedDate: sanitisedFocusedDate,
|
|
270
|
+
fixedWidth: fixedWidth,
|
|
271
|
+
initiallyFocusedDate: initiallyFocusedDate,
|
|
272
|
+
markOutsideDays: markOutsideDays,
|
|
273
|
+
markToday: markToday,
|
|
261
274
|
...calendarProps,
|
|
262
275
|
minDate: sanitisedMinDate,
|
|
263
276
|
maxDate: sanitisedMaxDate,
|
|
@@ -36,24 +36,16 @@ export const ROW_TYPES = {
|
|
|
36
36
|
both: 'both'
|
|
37
37
|
};
|
|
38
38
|
const navigatedByMonthNudger = () => document?.activeElement?.id && document.activeElement.id.indexOf('month_nudger') !== -1;
|
|
39
|
+
const EMPTY_MODIFIERS = {};
|
|
40
|
+
const EMPTY_STYLE = {};
|
|
41
|
+
const noopKeyDown = () => {};
|
|
39
42
|
class BpkCalendarDate extends PureComponent {
|
|
40
|
-
static defaultProps = {
|
|
41
|
-
className: null,
|
|
42
|
-
isBlocked: false,
|
|
43
|
-
isFocused: false,
|
|
44
|
-
isKeyboardFocusable: true,
|
|
45
|
-
isOutside: false,
|
|
46
|
-
isSelected: false,
|
|
47
|
-
isToday: false,
|
|
48
|
-
modifiers: {},
|
|
49
|
-
onClick: null,
|
|
50
|
-
onDateKeyDown: () => {},
|
|
51
|
-
preventKeyboardFocus: true,
|
|
52
|
-
selectionType: SELECTION_TYPES.none,
|
|
53
|
-
style: {}
|
|
54
|
-
};
|
|
55
43
|
componentDidMount() {
|
|
56
|
-
|
|
44
|
+
const {
|
|
45
|
+
isFocused = false,
|
|
46
|
+
preventKeyboardFocus = true
|
|
47
|
+
} = this.props;
|
|
48
|
+
if (!preventKeyboardFocus && isFocused) {
|
|
57
49
|
// If we got here by clicking the nudger, don't focus this date
|
|
58
50
|
if (!navigatedByMonthNudger()) {
|
|
59
51
|
// Giving focus after instantiation
|
|
@@ -62,37 +54,45 @@ class BpkCalendarDate extends PureComponent {
|
|
|
62
54
|
}
|
|
63
55
|
}
|
|
64
56
|
componentDidUpdate(prevProps) {
|
|
65
|
-
|
|
57
|
+
const {
|
|
58
|
+
isFocused = false,
|
|
59
|
+
isKeyboardFocusable = true,
|
|
60
|
+
preventKeyboardFocus = true
|
|
61
|
+
} = this.props;
|
|
62
|
+
const {
|
|
63
|
+
isFocused: prevIsFocused = false,
|
|
64
|
+
isKeyboardFocusable: prevIsKeyboardFocusable = true
|
|
65
|
+
} = prevProps;
|
|
66
|
+
if (!isKeyboardFocusable || preventKeyboardFocus || navigatedByMonthNudger()) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
// Giving focus after keyboard navigation
|
|
70
|
-
if (!
|
|
71
|
+
if (!prevIsFocused && isFocused && isKeyboardFocusable) {
|
|
71
72
|
this.button?.focus();
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
// Giving focus after changing months with transition
|
|
76
|
-
if (
|
|
77
|
+
if (isFocused && !prevIsKeyboardFocusable && isKeyboardFocusable) {
|
|
77
78
|
this.button?.focus();
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
button = null;
|
|
81
82
|
render() {
|
|
82
83
|
const {
|
|
83
|
-
className,
|
|
84
|
+
className = null,
|
|
84
85
|
date,
|
|
85
|
-
isBlocked,
|
|
86
|
-
isFocused,
|
|
87
|
-
isKeyboardFocusable,
|
|
88
|
-
isOutside,
|
|
89
|
-
isSelected,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
style,
|
|
86
|
+
isBlocked = false,
|
|
87
|
+
isFocused = false,
|
|
88
|
+
isKeyboardFocusable = true,
|
|
89
|
+
isOutside = false,
|
|
90
|
+
isSelected = false,
|
|
91
|
+
modifiers = EMPTY_MODIFIERS,
|
|
92
|
+
onClick = null,
|
|
93
|
+
onDateKeyDown = noopKeyDown,
|
|
94
|
+
selectionType = SELECTION_TYPES.none,
|
|
95
|
+
style = EMPTY_STYLE,
|
|
96
96
|
...buttonProps
|
|
97
97
|
} = this.props;
|
|
98
98
|
const classNames = [getClassName('bpk-calendar-date')];
|
|
@@ -121,6 +121,7 @@ class BpkCalendarDate extends PureComponent {
|
|
|
121
121
|
}
|
|
122
122
|
delete buttonProps.preventKeyboardFocus;
|
|
123
123
|
delete buttonProps.isoLabel;
|
|
124
|
+
delete buttonProps.isToday;
|
|
124
125
|
return /*#__PURE__*/_jsx("button", {
|
|
125
126
|
type: "button",
|
|
126
127
|
style: style,
|
|
@@ -5,26 +5,26 @@ type DefaultProps = {
|
|
|
5
5
|
className?: string | null;
|
|
6
6
|
dateModifiers?: DateModifiers;
|
|
7
7
|
focusedDate?: Date | null;
|
|
8
|
-
cellClassName
|
|
9
|
-
isKeyboardFocusable
|
|
10
|
-
markOutsideDays
|
|
11
|
-
markToday
|
|
12
|
-
maxDate
|
|
13
|
-
minDate
|
|
14
|
-
onDateClick
|
|
15
|
-
onDateKeyDown
|
|
8
|
+
cellClassName?: string | null;
|
|
9
|
+
isKeyboardFocusable?: boolean;
|
|
10
|
+
markOutsideDays?: boolean;
|
|
11
|
+
markToday?: boolean;
|
|
12
|
+
maxDate?: Date;
|
|
13
|
+
minDate?: Date;
|
|
14
|
+
onDateClick?: () => void;
|
|
15
|
+
onDateKeyDown?: () => void;
|
|
16
16
|
/**
|
|
17
17
|
* A function to format a human-readable month, for example: "January 2018":
|
|
18
18
|
* If you just need to quickly prototype, use the following from [`date-fns`](https://date-fns.org/docs/format#usage)
|
|
19
19
|
*/
|
|
20
|
-
formatMonth
|
|
21
|
-
preventKeyboardFocus
|
|
20
|
+
formatMonth?: (month: Date) => string;
|
|
21
|
+
preventKeyboardFocus?: boolean;
|
|
22
22
|
/**
|
|
23
23
|
* An object to indicate which configuration of the calendar is being used. Choices are `single` date selection or `range` date selection.
|
|
24
24
|
*/
|
|
25
|
-
selectionConfiguration
|
|
26
|
-
ignoreOutsideDate
|
|
27
|
-
dateProps
|
|
25
|
+
selectionConfiguration?: SelectionConfiguration;
|
|
26
|
+
ignoreOutsideDate?: boolean;
|
|
27
|
+
dateProps?: {};
|
|
28
28
|
};
|
|
29
29
|
export type Props = DefaultProps & {
|
|
30
30
|
DateComponent: ElementType;
|
|
@@ -47,7 +47,6 @@ type State = {
|
|
|
47
47
|
calendarMonthWeeks: DateProps[][];
|
|
48
48
|
};
|
|
49
49
|
declare class BpkCalendarGrid extends Component<Props, State> {
|
|
50
|
-
static defaultProps: DefaultProps;
|
|
51
50
|
constructor(props: Props);
|
|
52
51
|
componentDidMount(): void;
|
|
53
52
|
componentDidUpdate(prevProps: Props): void;
|
|
@@ -32,31 +32,22 @@ import STYLES from "./BpkCalendarGrid.module.css";
|
|
|
32
32
|
// class is applyed it should override the calendar style.
|
|
33
33
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
34
34
|
const getClassName = cssModules(STYLES);
|
|
35
|
+
const EMPTY_DATE_MODIFIERS = {};
|
|
36
|
+
const EMPTY_DATE_PROPS = {};
|
|
37
|
+
const DEFAULT_MAX_DATE = addMonths(new Date(), 12);
|
|
38
|
+
const DEFAULT_MIN_DATE = new Date();
|
|
39
|
+
const DEFAULT_SELECTION_CONFIGURATION = {
|
|
40
|
+
type: CALENDAR_SELECTION_TYPE.single,
|
|
41
|
+
date: null
|
|
42
|
+
};
|
|
43
|
+
const noopDateClick = () => {};
|
|
44
|
+
const noopDateKeyDown = () => {};
|
|
45
|
+
const defaultFormatMonth = month => format(month, 'MMMM yyyy');
|
|
46
|
+
|
|
35
47
|
/*
|
|
36
48
|
BpkCalendarGrid - the grid representing a whole month
|
|
37
49
|
*/
|
|
38
50
|
class BpkCalendarGrid extends Component {
|
|
39
|
-
static defaultProps = {
|
|
40
|
-
className: null,
|
|
41
|
-
dateModifiers: {},
|
|
42
|
-
focusedDate: null,
|
|
43
|
-
isKeyboardFocusable: true,
|
|
44
|
-
markOutsideDays: true,
|
|
45
|
-
markToday: true,
|
|
46
|
-
maxDate: addMonths(new Date(), 12),
|
|
47
|
-
minDate: new Date(),
|
|
48
|
-
onDateClick: () => {},
|
|
49
|
-
onDateKeyDown: () => {},
|
|
50
|
-
formatMonth: month => format(month, 'MMMM yyyy'),
|
|
51
|
-
preventKeyboardFocus: false,
|
|
52
|
-
selectionConfiguration: {
|
|
53
|
-
type: CALENDAR_SELECTION_TYPE.single,
|
|
54
|
-
date: null
|
|
55
|
-
},
|
|
56
|
-
ignoreOutsideDate: false,
|
|
57
|
-
dateProps: {},
|
|
58
|
-
cellClassName: null
|
|
59
|
-
};
|
|
60
51
|
constructor(props) {
|
|
61
52
|
super(props);
|
|
62
53
|
this.state = {
|
|
@@ -80,23 +71,23 @@ class BpkCalendarGrid extends Component {
|
|
|
80
71
|
render() {
|
|
81
72
|
const {
|
|
82
73
|
DateComponent,
|
|
83
|
-
cellClassName,
|
|
84
|
-
className,
|
|
85
|
-
dateModifiers,
|
|
86
|
-
dateProps,
|
|
87
|
-
focusedDate,
|
|
88
|
-
formatMonth,
|
|
89
|
-
ignoreOutsideDate,
|
|
90
|
-
isKeyboardFocusable,
|
|
91
|
-
markOutsideDays,
|
|
92
|
-
markToday,
|
|
93
|
-
maxDate,
|
|
94
|
-
minDate,
|
|
74
|
+
cellClassName = null,
|
|
75
|
+
className = null,
|
|
76
|
+
dateModifiers = EMPTY_DATE_MODIFIERS,
|
|
77
|
+
dateProps = EMPTY_DATE_PROPS,
|
|
78
|
+
focusedDate = null,
|
|
79
|
+
formatMonth = defaultFormatMonth,
|
|
80
|
+
ignoreOutsideDate = false,
|
|
81
|
+
isKeyboardFocusable = true,
|
|
82
|
+
markOutsideDays = true,
|
|
83
|
+
markToday = true,
|
|
84
|
+
maxDate = DEFAULT_MAX_DATE,
|
|
85
|
+
minDate = DEFAULT_MIN_DATE,
|
|
95
86
|
month,
|
|
96
|
-
onDateClick,
|
|
97
|
-
onDateKeyDown,
|
|
98
|
-
preventKeyboardFocus,
|
|
99
|
-
selectionConfiguration,
|
|
87
|
+
onDateClick = noopDateClick,
|
|
88
|
+
onDateKeyDown = noopDateKeyDown,
|
|
89
|
+
preventKeyboardFocus = false,
|
|
90
|
+
selectionConfiguration = DEFAULT_SELECTION_CONFIGURATION,
|
|
100
91
|
weekStartsOn
|
|
101
92
|
} = this.props;
|
|
102
93
|
const {
|
|
@@ -18,10 +18,6 @@ type DefaultProps = {
|
|
|
18
18
|
weekDayKey?: WeekDayKey;
|
|
19
19
|
};
|
|
20
20
|
declare class BpkCalendarGridHeader extends PureComponent<Props> {
|
|
21
|
-
static defaultProps: {
|
|
22
|
-
className: null;
|
|
23
|
-
weekDayKey: string;
|
|
24
|
-
};
|
|
25
21
|
render(): import("react/jsx-runtime").JSX.Element;
|
|
26
22
|
}
|
|
27
23
|
export default BpkCalendarGridHeader;
|
|
@@ -40,14 +40,10 @@ const WeekDayComponent = ({
|
|
|
40
40
|
})
|
|
41
41
|
});
|
|
42
42
|
class BpkCalendarGridHeader extends PureComponent {
|
|
43
|
-
static defaultProps = {
|
|
44
|
-
className: null,
|
|
45
|
-
weekDayKey: 'nameAbbr'
|
|
46
|
-
};
|
|
47
43
|
render() {
|
|
48
44
|
const {
|
|
49
|
-
className,
|
|
50
|
-
weekDayKey,
|
|
45
|
+
className = null,
|
|
46
|
+
weekDayKey = 'nameAbbr',
|
|
51
47
|
weekStartsOn
|
|
52
48
|
} = this.props;
|
|
53
49
|
const daysOfWeek = orderDaysOfWeek(this.props.daysOfWeek, weekStartsOn);
|
|
@@ -17,11 +17,6 @@ type State = {
|
|
|
17
17
|
};
|
|
18
18
|
declare class BpkCalendarGridTransition extends Component<Props, State> {
|
|
19
19
|
isTransitionEndSupported: boolean;
|
|
20
|
-
static defaultProps: {
|
|
21
|
-
className: null;
|
|
22
|
-
month: Date;
|
|
23
|
-
focusedDate: null;
|
|
24
|
-
};
|
|
25
20
|
constructor(props: Props);
|
|
26
21
|
componentDidUpdate(prevProps: Props): void;
|
|
27
22
|
onMonthTransitionEnd(): void;
|
|
@@ -30,11 +30,6 @@ const transitionValues = {
|
|
|
30
30
|
};
|
|
31
31
|
const getFocusedDateForMonth = (month, currentFocusedDate, minDate, maxDate) => dateToBoundaries(setMonthYear(currentFocusedDate, month.getMonth(), month.getFullYear()), startOfDay(minDate), startOfDay(maxDate));
|
|
32
32
|
class BpkCalendarGridTransition extends Component {
|
|
33
|
-
static defaultProps = {
|
|
34
|
-
className: null,
|
|
35
|
-
month: new Date(),
|
|
36
|
-
focusedDate: null
|
|
37
|
-
};
|
|
38
33
|
constructor(props) {
|
|
39
34
|
super(props);
|
|
40
35
|
const {
|
|
@@ -26,7 +26,6 @@ type DefaultProps = {
|
|
|
26
26
|
selectionConfiguration?: SelectionConfiguration;
|
|
27
27
|
};
|
|
28
28
|
declare class BpkCalendarWeek extends Component<Props> {
|
|
29
|
-
static defaultProps: DefaultProps;
|
|
30
29
|
shouldComponentUpdate(nextProps: Props): boolean;
|
|
31
30
|
render(): import("react/jsx-runtime").JSX.Element | null;
|
|
32
31
|
}
|
|
@@ -136,8 +136,8 @@ function getSelectionType(date, selectionConfiguration, month, weekStartsOn, ign
|
|
|
136
136
|
* @returns {Boolean} based on if the date has changed
|
|
137
137
|
*/
|
|
138
138
|
const singleDateHandler = (props, nextProps) => {
|
|
139
|
-
const currentSelectConfig = props.selectionConfiguration;
|
|
140
|
-
const nextSelectConfig = nextProps.selectionConfiguration;
|
|
139
|
+
const currentSelectConfig = props.selectionConfiguration ?? DEFAULT_SELECTION_CONFIGURATION;
|
|
140
|
+
const nextSelectConfig = nextProps.selectionConfiguration ?? DEFAULT_SELECTION_CONFIGURATION;
|
|
141
141
|
if ((nextSelectConfig.date && isSameWeek(nextSelectConfig.date, nextProps.dates[0].val, {
|
|
142
142
|
weekStartsOn: nextProps.weekStartsOn
|
|
143
143
|
}) || currentSelectConfig.date && isSameWeek(currentSelectConfig.date, props.dates[0].val, {
|
|
@@ -158,11 +158,11 @@ const rangeDateHandler = (props, nextProps) => {
|
|
|
158
158
|
const {
|
|
159
159
|
endDate,
|
|
160
160
|
startDate
|
|
161
|
-
} = props.selectionConfiguration;
|
|
161
|
+
} = props.selectionConfiguration ?? DEFAULT_SELECTION_CONFIGURATION;
|
|
162
162
|
const {
|
|
163
163
|
endDate: nextEndDate,
|
|
164
164
|
startDate: nextStartDate
|
|
165
|
-
} = nextProps.selectionConfiguration;
|
|
165
|
+
} = nextProps.selectionConfiguration ?? DEFAULT_SELECTION_CONFIGURATION;
|
|
166
166
|
const startDateChanged = startDate && nextStartDate && !isSameDay(startDate, nextStartDate);
|
|
167
167
|
const endDateChanged = endDate && nextEndDate && !isSameDay(endDate, nextEndDate);
|
|
168
168
|
if (startDateChanged || endDateChanged) {
|
|
@@ -170,24 +170,16 @@ const rangeDateHandler = (props, nextProps) => {
|
|
|
170
170
|
}
|
|
171
171
|
return false;
|
|
172
172
|
};
|
|
173
|
+
const DEFAULT_SELECTION_CONFIGURATION = {
|
|
174
|
+
type: CALENDAR_SELECTION_TYPE.single,
|
|
175
|
+
date: null
|
|
176
|
+
};
|
|
177
|
+
const noop = () => {};
|
|
178
|
+
|
|
173
179
|
/*
|
|
174
180
|
BpkCalendarWeek - table row containing a week full of DateContainer components
|
|
175
181
|
*/
|
|
176
182
|
class BpkCalendarWeek extends Component {
|
|
177
|
-
static defaultProps = {
|
|
178
|
-
dateProps: {},
|
|
179
|
-
focusedDate: null,
|
|
180
|
-
ignoreOutsideDate: false,
|
|
181
|
-
maxDate: null,
|
|
182
|
-
minDate: null,
|
|
183
|
-
onDateClick: () => {},
|
|
184
|
-
onDateKeyDown: () => {},
|
|
185
|
-
selectionConfiguration: {
|
|
186
|
-
type: CALENDAR_SELECTION_TYPE.single,
|
|
187
|
-
date: null
|
|
188
|
-
},
|
|
189
|
-
cellClassName: null
|
|
190
|
-
};
|
|
191
183
|
shouldComponentUpdate(nextProps) {
|
|
192
184
|
const shallowProps = ['DateComponent', 'dateModifiers', 'isKeyboardFocusable', 'markOutsideDays', 'markToday', 'onDateClick', 'onDateKeyDown', 'preventKeyboardFocus', 'weekStartsOn', 'dates', 'cellClassName'];
|
|
193
185
|
|
|
@@ -241,21 +233,21 @@ class BpkCalendarWeek extends Component {
|
|
|
241
233
|
render() {
|
|
242
234
|
const {
|
|
243
235
|
DateComponent,
|
|
244
|
-
cellClassName,
|
|
236
|
+
cellClassName = null,
|
|
245
237
|
dateModifiers,
|
|
246
|
-
dateProps,
|
|
247
|
-
focusedDate,
|
|
248
|
-
ignoreOutsideDate,
|
|
238
|
+
dateProps = {},
|
|
239
|
+
focusedDate = null,
|
|
240
|
+
ignoreOutsideDate = false,
|
|
249
241
|
isKeyboardFocusable,
|
|
250
242
|
markOutsideDays,
|
|
251
243
|
markToday,
|
|
252
|
-
maxDate,
|
|
253
|
-
minDate,
|
|
244
|
+
maxDate = null,
|
|
245
|
+
minDate = null,
|
|
254
246
|
month,
|
|
255
|
-
onDateClick,
|
|
256
|
-
onDateKeyDown,
|
|
247
|
+
onDateClick = noop,
|
|
248
|
+
onDateKeyDown = noop,
|
|
257
249
|
preventKeyboardFocus,
|
|
258
|
-
selectionConfiguration,
|
|
250
|
+
selectionConfiguration = DEFAULT_SELECTION_CONFIGURATION,
|
|
259
251
|
weekStartsOn
|
|
260
252
|
} = this.props;
|
|
261
253
|
if (ignoreOutsideDate) {
|
|
@@ -38,7 +38,6 @@ const BpkCardList = props => {
|
|
|
38
38
|
chipGroup,
|
|
39
39
|
description,
|
|
40
40
|
expandText,
|
|
41
|
-
initiallyInViewCardIndex = 0,
|
|
42
41
|
initiallyShownCardsDesktop = DEFAULT_ITEMS_DESKTOP,
|
|
43
42
|
initiallyShownCardsMobile = DEFAULT_ITEMS_MOBILE,
|
|
44
43
|
layoutDesktop,
|
|
@@ -79,7 +78,6 @@ const BpkCardList = props => {
|
|
|
79
78
|
initiallyShownCards: initiallyShownCardsMobile,
|
|
80
79
|
layout: layoutMobile,
|
|
81
80
|
accessibilityLabels: accessibilityLabels,
|
|
82
|
-
initiallyInViewCardIndex: initiallyInViewCardIndex,
|
|
83
81
|
isMobile: true,
|
|
84
82
|
children: cardList
|
|
85
83
|
}), layoutMobile === LAYOUTS.stack && /*#__PURE__*/_jsx(BpkCardListGridStack, {
|
|
@@ -99,7 +97,6 @@ const BpkCardList = props => {
|
|
|
99
97
|
initiallyShownCards: initiallyShownCardsDesktop,
|
|
100
98
|
layout: layoutDesktop,
|
|
101
99
|
accessibilityLabels: accessibilityLabels,
|
|
102
|
-
initiallyInViewCardIndex: initiallyInViewCardIndex,
|
|
103
100
|
children: cardList
|
|
104
101
|
}), layoutDesktop === LAYOUTS.grid && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.pagination && /*#__PURE__*/_jsx(BpkCardListGridStack, {
|
|
105
102
|
accessory: accessoryDesktop,
|
|
@@ -30,7 +30,6 @@ const BpkCardListCarousel = props => {
|
|
|
30
30
|
carouselLabel = (initiallyShownCards, childrenLength) => `Entering Carousel with ${initiallyShownCards} slides shown at a time, ${childrenLength} slides in total. Please use Pagination below with the Previous and Next buttons to navigate, or the slide dot buttons at the end to jump to slides.`,
|
|
31
31
|
children,
|
|
32
32
|
currentIndex,
|
|
33
|
-
initialPageIndex,
|
|
34
33
|
initiallyShownCards,
|
|
35
34
|
isMobile = false,
|
|
36
35
|
layout,
|
|
@@ -59,8 +58,7 @@ const BpkCardListCarousel = props => {
|
|
|
59
58
|
cardRefs,
|
|
60
59
|
visibilityList,
|
|
61
60
|
container: root,
|
|
62
|
-
enabled: !isMobile
|
|
63
|
-
initialPageIndex
|
|
61
|
+
enabled: !isMobile
|
|
64
62
|
});
|
|
65
63
|
|
|
66
64
|
// Similar to Virtual Scrolling to improve performance
|
|
@@ -28,7 +28,6 @@ const BpkCardListRowRailContainer = props => {
|
|
|
28
28
|
accessibilityLabels,
|
|
29
29
|
accessory,
|
|
30
30
|
children,
|
|
31
|
-
initiallyInViewCardIndex,
|
|
32
31
|
initiallyShownCards,
|
|
33
32
|
isMobile = false,
|
|
34
33
|
layout
|
|
@@ -36,18 +35,7 @@ const BpkCardListRowRailContainer = props => {
|
|
|
36
35
|
const childrenCount = Children.count(children);
|
|
37
36
|
const totalIndicators = Math.ceil(childrenCount / initiallyShownCards);
|
|
38
37
|
const showAccessory = childrenCount > initiallyShownCards;
|
|
39
|
-
|
|
40
|
-
// Calculate initial page from card index
|
|
41
|
-
const [initialPageIndex] = useState(() => {
|
|
42
|
-
if (initiallyInViewCardIndex < 0) {
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
if (initiallyInViewCardIndex >= childrenCount) {
|
|
46
|
-
return Math.max(0, totalIndicators - 1);
|
|
47
|
-
}
|
|
48
|
-
return Math.floor(initiallyInViewCardIndex / initiallyShownCards);
|
|
49
|
-
});
|
|
50
|
-
const [currentIndex, setCurrentIndex] = useState(initialPageIndex);
|
|
38
|
+
const [currentIndex, setCurrentIndex] = useState(0);
|
|
51
39
|
const accessoryContent = layout === LAYOUTS.row && accessory === ACCESSORY_DESKTOP_TYPES.pagination ? /*#__PURE__*/_jsx(BpkPageIndicator, {
|
|
52
40
|
currentIndex: currentIndex,
|
|
53
41
|
totalIndicators: totalIndicators,
|
|
@@ -69,7 +57,6 @@ const BpkCardListRowRailContainer = props => {
|
|
|
69
57
|
isMobile: isMobile,
|
|
70
58
|
carouselLabel: accessibilityLabels?.carouselLabel,
|
|
71
59
|
slideLabel: accessibilityLabels?.slideLabel,
|
|
72
|
-
initialPageIndex: initialPageIndex,
|
|
73
60
|
children: children
|
|
74
61
|
}), accessoryContent && showAccessory && /*#__PURE__*/_jsx("div", {
|
|
75
62
|
role: "region",
|
|
@@ -15,7 +15,6 @@ type UsePageScrollSyncOptions = {
|
|
|
15
15
|
visibilityList: number[];
|
|
16
16
|
container: HTMLElement | null;
|
|
17
17
|
enabled: boolean;
|
|
18
|
-
initialPageIndex: number;
|
|
19
18
|
};
|
|
20
19
|
/**
|
|
21
20
|
* Provides bidirectional synchronisation between page index state and scroll position.
|
|
@@ -28,5 +27,5 @@ type UsePageScrollSyncOptions = {
|
|
|
28
27
|
* The hook uses a lock mechanism to prevent conflicts between programmatic and
|
|
29
28
|
* user-initiated scrolling.
|
|
30
29
|
*/
|
|
31
|
-
export declare const usePageScrollSync: ({ cardRefs, container, currentIndex, enabled,
|
|
30
|
+
export declare const usePageScrollSync: ({ cardRefs, container, currentIndex, enabled, initiallyShownCards, setCurrentIndex, visibilityList, }: UsePageScrollSyncOptions) => void;
|
|
32
31
|
export {};
|