@skyscanner/backpack-web 41.11.1 → 41.13.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-card-list/src/BpkCardList.js +3 -0
- package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.js +15 -30
- package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.module.css +1 -1
- package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListRowRailContainer.js +14 -1
- package/bpk-component-card-list/src/BpkCardListRowRail/constants.d.ts +1 -1
- package/bpk-component-card-list/src/BpkCardListRowRail/constants.js +1 -1
- package/bpk-component-card-list/src/BpkCardListRowRail/utils.d.ts +25 -8
- package/bpk-component-card-list/src/BpkCardListRowRail/utils.js +118 -35
- package/bpk-component-card-list/src/common-types.d.ts +3 -0
- package/bpk-component-content-cards/src/BpkContentCard.module.css +1 -1
- package/bpk-component-nudger/src/BpkNudger.js +2 -2
- package/bpk-component-panel/index.d.ts +2 -0
- package/bpk-component-panel/index.js +1 -0
- package/bpk-component-panel/src/BpkPanel.d.ts +14 -1
- package/bpk-component-panel/src/BpkPanel.js +4 -1
- package/bpk-component-panel/src/BpkPanel.module.css +1 -1
- package/bpk-mixins/_index.scss +1 -0
- package/bpk-mixins/_surfaces.scss +52 -0
- package/bpk-react-utils/index.d.ts +13 -1
- package/bpk-react-utils/index.js +4 -2
- package/bpk-react-utils/src/surfaceColors.d.ts +11 -0
- package/bpk-react-utils/src/surfaceColors.js +29 -0
- package/package.json +1 -1
|
@@ -38,6 +38,7 @@ const BpkCardList = props => {
|
|
|
38
38
|
chipGroup,
|
|
39
39
|
description,
|
|
40
40
|
expandText,
|
|
41
|
+
initiallyInViewCardIndex = 0,
|
|
41
42
|
initiallyShownCardsDesktop = DEFAULT_ITEMS_DESKTOP,
|
|
42
43
|
initiallyShownCardsMobile = DEFAULT_ITEMS_MOBILE,
|
|
43
44
|
layoutDesktop,
|
|
@@ -78,6 +79,7 @@ const BpkCardList = props => {
|
|
|
78
79
|
initiallyShownCards: initiallyShownCardsMobile,
|
|
79
80
|
layout: layoutMobile,
|
|
80
81
|
accessibilityLabels: accessibilityLabels,
|
|
82
|
+
initiallyInViewCardIndex: initiallyInViewCardIndex,
|
|
81
83
|
isMobile: true,
|
|
82
84
|
children: cardList
|
|
83
85
|
}), layoutMobile === LAYOUTS.stack && /*#__PURE__*/_jsx(BpkCardListGridStack, {
|
|
@@ -97,6 +99,7 @@ const BpkCardList = props => {
|
|
|
97
99
|
initiallyShownCards: initiallyShownCardsDesktop,
|
|
98
100
|
layout: layoutDesktop,
|
|
99
101
|
accessibilityLabels: accessibilityLabels,
|
|
102
|
+
initiallyInViewCardIndex: initiallyInViewCardIndex,
|
|
100
103
|
children: cardList
|
|
101
104
|
}), layoutDesktop === LAYOUTS.grid && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.pagination && /*#__PURE__*/_jsx(BpkCardListGridStack, {
|
|
102
105
|
accessory: accessoryDesktop,
|
|
@@ -20,7 +20,7 @@ import { useRef, useState, useEffect, isValidElement, Children, useMemo } from '
|
|
|
20
20
|
import throttle from 'lodash/throttle';
|
|
21
21
|
import { cssModules, getDataComponentAttribute } from "../../../bpk-react-utils";
|
|
22
22
|
import { RENDER_BUFFER_SIZE } from "./constants";
|
|
23
|
-
import {
|
|
23
|
+
import { setA11yTabIndex, useIntersectionObserver, usePageScrollSync } from "./utils";
|
|
24
24
|
import STYLES from "./BpkCardListCarousel.module.css";
|
|
25
25
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
26
|
const getClassName = cssModules(STYLES);
|
|
@@ -30,6 +30,7 @@ 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,
|
|
33
34
|
initiallyShownCards,
|
|
34
35
|
isMobile = false,
|
|
35
36
|
layout,
|
|
@@ -47,13 +48,20 @@ const BpkCardListCarousel = props => {
|
|
|
47
48
|
const firstCardWidthRef = useRef(null);
|
|
48
49
|
const firstCardHeightRef = useRef(null);
|
|
49
50
|
const [visibilityList, setVisibilityList] = useState(Array(childrenLength).fill(0));
|
|
50
|
-
const stateScrollingLockRef = useRef(false);
|
|
51
|
-
const openSetStateLockTimeoutRef = useRef(null);
|
|
52
51
|
const observerVisibility = useIntersectionObserver({
|
|
53
52
|
root,
|
|
54
53
|
threshold: 0.5
|
|
55
54
|
}, setVisibilityList);
|
|
56
|
-
|
|
55
|
+
usePageScrollSync({
|
|
56
|
+
currentIndex,
|
|
57
|
+
setCurrentIndex,
|
|
58
|
+
initiallyShownCards,
|
|
59
|
+
cardRefs,
|
|
60
|
+
visibilityList,
|
|
61
|
+
container: root,
|
|
62
|
+
enabled: !isMobile,
|
|
63
|
+
initialPageIndex
|
|
64
|
+
});
|
|
57
65
|
|
|
58
66
|
// Similar to Virtual Scrolling to improve performance
|
|
59
67
|
const firstVisibleIndex = Math.max(0, visibilityList.indexOf(1));
|
|
@@ -87,22 +95,6 @@ const BpkCardListCarousel = props => {
|
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
}), [childrenLength, observerVisibility, visibilityList, firstCardWidthRef, firstCardHeightRef]);
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
const container = root;
|
|
92
|
-
if (isMobile || !container) return undefined;
|
|
93
|
-
const lockScrollDuringInteraction = () => {
|
|
94
|
-
lockScroll(stateScrollingLockRef, openSetStateLockTimeoutRef);
|
|
95
|
-
};
|
|
96
|
-
container.addEventListener('wheel', lockScrollDuringInteraction);
|
|
97
|
-
container.addEventListener('touchmove', lockScrollDuringInteraction);
|
|
98
|
-
return () => {
|
|
99
|
-
container.removeEventListener('touchmove', lockScrollDuringInteraction);
|
|
100
|
-
container.removeEventListener('wheel', lockScrollDuringInteraction);
|
|
101
|
-
if (openSetStateLockTimeoutRef.current) {
|
|
102
|
-
clearTimeout(openSetStateLockTimeoutRef.current);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}, [root]);
|
|
106
98
|
useEffect(() => {
|
|
107
99
|
// update hasBeenVisibleRef to include the range of cards that should be visible
|
|
108
100
|
const start = currentIndex * initiallyShownCards;
|
|
@@ -111,15 +103,6 @@ const BpkCardListCarousel = props => {
|
|
|
111
103
|
hasBeenVisibleRef.current.add(i);
|
|
112
104
|
}
|
|
113
105
|
}, [currentIndex, initiallyShownCards, childrenLength, dynamicRenderBufferSize]);
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
const firstVisible = visibilityList.indexOf(1);
|
|
116
|
-
if (firstVisible >= 0) {
|
|
117
|
-
const newIndex = Math.floor(firstVisible / initiallyShownCards);
|
|
118
|
-
if (newIndex !== currentIndex) {
|
|
119
|
-
setCurrentIndex(newIndex);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}, [initiallyShownCards]);
|
|
123
106
|
useEffect(() => {
|
|
124
107
|
const handleResize = throttle(() => {
|
|
125
108
|
firstCardWidthRef.current = null;
|
|
@@ -149,8 +132,9 @@ const BpkCardListCarousel = props => {
|
|
|
149
132
|
if (firstCardHeightRef.current) {
|
|
150
133
|
cardDimensionStyle.height = `${firstCardHeightRef.current}px`;
|
|
151
134
|
}
|
|
135
|
+
const isPageStart = index % initiallyShownCards === 0;
|
|
152
136
|
const commonProps = {
|
|
153
|
-
className: getClassName(`bpk-card-list-row-rail__${layout}__card
|
|
137
|
+
className: getClassName(`bpk-card-list-row-rail__${layout}__card`, isPageStart && 'bpk-card-list-row-rail__card--page-start'),
|
|
154
138
|
style: shownNumberStyle,
|
|
155
139
|
key: `carousel-card-${index.toString()}`,
|
|
156
140
|
role: 'group'
|
|
@@ -161,6 +145,7 @@ const BpkCardListCarousel = props => {
|
|
|
161
145
|
if (!shouldRenderCard) {
|
|
162
146
|
return /*#__PURE__*/_jsx("div", {
|
|
163
147
|
...commonProps,
|
|
148
|
+
ref: cardRefFns[index],
|
|
164
149
|
style: {
|
|
165
150
|
...commonProps.style,
|
|
166
151
|
...cardDimensionStyle,
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{--spacing-offset: 0.5rem;--carousel-card-gap: 1.25rem;display:flex;overflow-x:
|
|
18
|
+
.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{--spacing-offset: 0.5rem;--carousel-card-gap: 1.25rem;display:flex;overflow-x:scroll;box-sizing:border-box;gap:var(--carousel-card-gap);margin-block:-1.5rem;margin-inline:-0.5rem;-webkit-overflow-scrolling:touch;padding-block:1.5rem;padding-inline:.5rem;scroll-snap-type:x mandatory;scrollbar-width:none}@media(max-width: 32rem){.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{--spacing-offset: 1rem;--carousel-card-gap: 1rem;overflow-x:scroll}}.bpk-card-list-row-rail__row::-webkit-scrollbar,.bpk-card-list-row-rail__rail::-webkit-scrollbar{display:none}.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{position:relative;flex:0 0 calc((100% - (var(--carousel-card-gap)*(var(--initially-shown-cards, 3) - 1) + var(--spacing-offset)*2/var(--initially-shown-cards, 3)))/var(--initially-shown-cards, 3));overflow:visible;box-sizing:border-box;scroll-margin-inline:var(--spacing-offset);scroll-snap-align:start}@media(min-width: 32.0625rem){.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{scroll-snap-align:none}}@media(max-width: 32rem){.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{flex:0 0 calc((100% - var(--carousel-card-gap)*(var(--initially-shown-cards, 3) - 1))/max(1,var(--initially-shown-cards, 3) - .8))}}@media(min-width: 32.0625rem){.bpk-card-list-row-rail__card--page-start{scroll-snap-align:start;scroll-snap-stop:always}}.bpk-card-list-row-rail__rail{-webkit-overflow-scrolling:touch}@media(max-width: 32rem){.bpk-card-list-row-rail__rail{margin-inline:calc(-1*var(--spacing-offset));padding-inline:var(--spacing-offset)}}.bpk-card-list-row-rail__card-slot{display:grid;height:100%}
|
|
@@ -28,6 +28,7 @@ const BpkCardListRowRailContainer = props => {
|
|
|
28
28
|
accessibilityLabels,
|
|
29
29
|
accessory,
|
|
30
30
|
children,
|
|
31
|
+
initiallyInViewCardIndex,
|
|
31
32
|
initiallyShownCards,
|
|
32
33
|
isMobile = false,
|
|
33
34
|
layout
|
|
@@ -35,7 +36,18 @@ const BpkCardListRowRailContainer = props => {
|
|
|
35
36
|
const childrenCount = Children.count(children);
|
|
36
37
|
const totalIndicators = Math.ceil(childrenCount / initiallyShownCards);
|
|
37
38
|
const showAccessory = childrenCount > initiallyShownCards;
|
|
38
|
-
|
|
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);
|
|
39
51
|
const accessoryContent = layout === LAYOUTS.row && accessory === ACCESSORY_DESKTOP_TYPES.pagination ? /*#__PURE__*/_jsx(BpkPageIndicator, {
|
|
40
52
|
currentIndex: currentIndex,
|
|
41
53
|
totalIndicators: totalIndicators,
|
|
@@ -57,6 +69,7 @@ const BpkCardListRowRailContainer = props => {
|
|
|
57
69
|
isMobile: isMobile,
|
|
58
70
|
carouselLabel: accessibilityLabels?.carouselLabel,
|
|
59
71
|
slideLabel: accessibilityLabels?.slideLabel,
|
|
72
|
+
initialPageIndex: initialPageIndex,
|
|
60
73
|
children: children
|
|
61
74
|
}), accessoryContent && showAccessory && /*#__PURE__*/_jsx("div", {
|
|
62
75
|
role: "region",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const RELEASE_LOCK_DELAY =
|
|
1
|
+
export declare const RELEASE_LOCK_DELAY = 200;
|
|
2
2
|
export declare const RENDER_BUFFER_SIZE = 3;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Typically used to prevent useScrollToCard() from being called, to prevent scrollings caused by state changes, so as to avoid cyclic dependencies.
|
|
3
|
-
* @param stateScrollingLockRef - Ref to the state that indicates if scrollIntoView should be locked
|
|
4
|
-
* @param openSetStateLockTimeoutRef - Ref to the timeout that releases the lock after a delay. Should be renewed every time another scroll action is triggered, with a new lock is added.
|
|
5
|
-
*/
|
|
6
|
-
export declare const lockScroll: (stateScrollingLockRef: React.MutableRefObject<boolean>, openSetStateLockTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>) => void;
|
|
1
|
+
import type { Dispatch, SetStateAction, RefObject } from 'react';
|
|
7
2
|
/**
|
|
8
3
|
* Only sets the tabIndex of focusable elements as 0 if the card is visible, otherwise sets it to -1, including all its children.
|
|
9
4
|
* For example, if there is a button inside a card which is not shown, it cannot be focused as well.
|
|
@@ -11,5 +6,27 @@ export declare const lockScroll: (stateScrollingLockRef: React.MutableRefObject<
|
|
|
11
6
|
* @param index - Current container index
|
|
12
7
|
*/
|
|
13
8
|
export declare const setA11yTabIndex: (el: HTMLDivElement | null, index: number, visibilityList: number[]) => void;
|
|
14
|
-
export declare const
|
|
15
|
-
|
|
9
|
+
export declare const useIntersectionObserver: ({ root, threshold }: IntersectionObserverInit, setVisibilityList: Dispatch<SetStateAction<number[]>>) => (element: HTMLElement | null, index: number) => void;
|
|
10
|
+
type UsePageScrollSyncOptions = {
|
|
11
|
+
currentIndex: number;
|
|
12
|
+
setCurrentIndex: Dispatch<SetStateAction<number>>;
|
|
13
|
+
initiallyShownCards: number;
|
|
14
|
+
cardRefs: RefObject<Array<HTMLDivElement | null>>;
|
|
15
|
+
visibilityList: number[];
|
|
16
|
+
container: HTMLElement | null;
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
initialPageIndex: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Provides bidirectional synchronisation between page index state and scroll position.
|
|
22
|
+
*
|
|
23
|
+
* - **State → Scroll**: When `currentIndex` changes (e.g. via pagination buttons),
|
|
24
|
+
* the container scrolls to bring the corresponding page into view.
|
|
25
|
+
* - **Scroll → State**: When the user scrolls (via wheel or touch), `currentIndex`
|
|
26
|
+
* is updated to reflect the first visible page.
|
|
27
|
+
*
|
|
28
|
+
* The hook uses a lock mechanism to prevent conflicts between programmatic and
|
|
29
|
+
* user-initiated scrolling.
|
|
30
|
+
*/
|
|
31
|
+
export declare const usePageScrollSync: ({ cardRefs, container, currentIndex, enabled, initialPageIndex, initiallyShownCards, setCurrentIndex, visibilityList, }: UsePageScrollSyncOptions) => void;
|
|
32
|
+
export {};
|
|
@@ -19,25 +19,6 @@
|
|
|
19
19
|
import { useEffect, useRef } from 'react';
|
|
20
20
|
import { RELEASE_LOCK_DELAY } from "./constants";
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Typically used to prevent useScrollToCard() from being called, to prevent scrollings caused by state changes, so as to avoid cyclic dependencies.
|
|
24
|
-
* @param stateScrollingLockRef - Ref to the state that indicates if scrollIntoView should be locked
|
|
25
|
-
* @param openSetStateLockTimeoutRef - Ref to the timeout that releases the lock after a delay. Should be renewed every time another scroll action is triggered, with a new lock is added.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
export const lockScroll = (stateScrollingLockRef, openSetStateLockTimeoutRef) => {
|
|
29
|
-
// eslint-disable-next-line no-param-reassign
|
|
30
|
-
stateScrollingLockRef.current = true;
|
|
31
|
-
if (openSetStateLockTimeoutRef.current) {
|
|
32
|
-
clearTimeout(openSetStateLockTimeoutRef.current);
|
|
33
|
-
}
|
|
34
|
-
// eslint-disable-next-line no-param-reassign
|
|
35
|
-
openSetStateLockTimeoutRef.current = setTimeout(() => {
|
|
36
|
-
// eslint-disable-next-line no-param-reassign
|
|
37
|
-
stateScrollingLockRef.current = false;
|
|
38
|
-
}, RELEASE_LOCK_DELAY);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
22
|
/**
|
|
42
23
|
* Only sets the tabIndex of focusable elements as 0 if the card is visible, otherwise sets it to -1, including all its children.
|
|
43
24
|
* For example, if there is a button inside a card which is not shown, it cannot be focused as well.
|
|
@@ -53,22 +34,6 @@ export const setA11yTabIndex = (el, index, visibilityList) => {
|
|
|
53
34
|
targetElement.tabIndex = visibilityList[index] === 1 ? 0 : -1;
|
|
54
35
|
});
|
|
55
36
|
};
|
|
56
|
-
export const useScrollToCard = (currentIndex, container, cardRefs, stateScrollingLockRef) => {
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
const isVisible = container && container.getBoundingClientRect().bottom > 0 && container.getBoundingClientRect().bottom <= window.innerHeight;
|
|
59
|
-
if (!isVisible) return; // Escape from scrollIntoView if the container is not visible, otherwise the webpage will scroll down to the last rendered & non-visible container
|
|
60
|
-
|
|
61
|
-
if (stateScrollingLockRef.current && stateScrollingLockRef.current === true) return;
|
|
62
|
-
const targetCard = cardRefs.current[currentIndex];
|
|
63
|
-
if (targetCard) {
|
|
64
|
-
targetCard.scrollIntoView({
|
|
65
|
-
behavior: 'smooth',
|
|
66
|
-
block: 'nearest',
|
|
67
|
-
inline: 'start'
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}, [currentIndex]);
|
|
71
|
-
};
|
|
72
37
|
export const useIntersectionObserver = ({
|
|
73
38
|
root,
|
|
74
39
|
threshold
|
|
@@ -115,4 +80,122 @@ export const useIntersectionObserver = ({
|
|
|
115
80
|
}
|
|
116
81
|
};
|
|
117
82
|
return observeElement;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Provides bidirectional synchronisation between page index state and scroll position.
|
|
86
|
+
*
|
|
87
|
+
* - **State → Scroll**: When `currentIndex` changes (e.g. via pagination buttons),
|
|
88
|
+
* the container scrolls to bring the corresponding page into view.
|
|
89
|
+
* - **Scroll → State**: When the user scrolls (via wheel or touch), `currentIndex`
|
|
90
|
+
* is updated to reflect the first visible page.
|
|
91
|
+
*
|
|
92
|
+
* The hook uses a lock mechanism to prevent conflicts between programmatic and
|
|
93
|
+
* user-initiated scrolling.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export const usePageScrollSync = ({
|
|
97
|
+
cardRefs,
|
|
98
|
+
container,
|
|
99
|
+
currentIndex,
|
|
100
|
+
enabled,
|
|
101
|
+
initialPageIndex,
|
|
102
|
+
initiallyShownCards,
|
|
103
|
+
setCurrentIndex,
|
|
104
|
+
visibilityList
|
|
105
|
+
}) => {
|
|
106
|
+
const isUserScrollingRef = useRef(false);
|
|
107
|
+
const scrollEndTimeoutRef = useRef(null);
|
|
108
|
+
const lastCurrentIndexRef = useRef(currentIndex);
|
|
109
|
+
const hasInitialScrolled = useRef(false);
|
|
110
|
+
|
|
111
|
+
// Effect 0: Initial scroll (instant, runs once on mount)
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (hasInitialScrolled.current) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
hasInitialScrolled.current = true;
|
|
117
|
+
if (!enabled || initialPageIndex === 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const targetCard = cardRefs.current?.[initialPageIndex * initiallyShownCards];
|
|
121
|
+
if (targetCard) {
|
|
122
|
+
targetCard.scrollIntoView({
|
|
123
|
+
behavior: 'instant',
|
|
124
|
+
block: 'nearest',
|
|
125
|
+
inline: 'start'
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}, [cardRefs, enabled, initialPageIndex, initiallyShownCards]); // Run once on mount only
|
|
129
|
+
|
|
130
|
+
// Effect 1: Programmatic scroll when currentIndex changes
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (!enabled ||
|
|
133
|
+
// Avoid triggering programmatic scroll when currentIndex changes due to user scroll
|
|
134
|
+
isUserScrollingRef.current || lastCurrentIndexRef.current === currentIndex) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
lastCurrentIndexRef.current = currentIndex;
|
|
138
|
+
const isVisible = container && container.getBoundingClientRect().bottom > 0 && container.getBoundingClientRect().bottom <= window.innerHeight;
|
|
139
|
+
if (!isVisible) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const targetCard = cardRefs.current?.[currentIndex * initiallyShownCards];
|
|
143
|
+
if (targetCard) {
|
|
144
|
+
targetCard.scrollIntoView({
|
|
145
|
+
behavior: 'smooth',
|
|
146
|
+
block: 'nearest',
|
|
147
|
+
inline: 'start'
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}, [currentIndex, enabled, container, initiallyShownCards, cardRefs]);
|
|
151
|
+
|
|
152
|
+
// Effect 2: Scroll detection and silence-based lock release
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (!enabled || !container) return undefined;
|
|
155
|
+
const handleScrollActivity = e => {
|
|
156
|
+
// Set flag only for user input events, not scroll events
|
|
157
|
+
if (e.type === 'wheel' || e.type === 'touchstart') {
|
|
158
|
+
isUserScrollingRef.current = true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Reset silence timer on every scroll-related event
|
|
162
|
+
if (scrollEndTimeoutRef.current) {
|
|
163
|
+
clearTimeout(scrollEndTimeoutRef.current);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Release lock after scroll silence
|
|
167
|
+
scrollEndTimeoutRef.current = setTimeout(() => {
|
|
168
|
+
isUserScrollingRef.current = false;
|
|
169
|
+
}, RELEASE_LOCK_DELAY);
|
|
170
|
+
};
|
|
171
|
+
container.addEventListener('scroll', handleScrollActivity, {
|
|
172
|
+
passive: true
|
|
173
|
+
});
|
|
174
|
+
container.addEventListener('wheel', handleScrollActivity, {
|
|
175
|
+
passive: true
|
|
176
|
+
});
|
|
177
|
+
container.addEventListener('touchstart', handleScrollActivity, {
|
|
178
|
+
passive: true
|
|
179
|
+
});
|
|
180
|
+
return () => {
|
|
181
|
+
container.removeEventListener('scroll', handleScrollActivity);
|
|
182
|
+
container.removeEventListener('wheel', handleScrollActivity);
|
|
183
|
+
container.removeEventListener('touchstart', handleScrollActivity);
|
|
184
|
+
if (scrollEndTimeoutRef.current) {
|
|
185
|
+
clearTimeout(scrollEndTimeoutRef.current);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}, [enabled, container]);
|
|
189
|
+
|
|
190
|
+
// Effect 3: Update currentIndex from visibility during user scroll
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (!enabled || !isUserScrollingRef.current) return;
|
|
193
|
+
const firstVisibleIndex = visibilityList.indexOf(1);
|
|
194
|
+
if (firstVisibleIndex === -1) return;
|
|
195
|
+
const newPageIndex = Math.floor(firstVisibleIndex / initiallyShownCards);
|
|
196
|
+
if (newPageIndex !== currentIndex) {
|
|
197
|
+
setCurrentIndex(newPageIndex);
|
|
198
|
+
lastCurrentIndexRef.current = newPageIndex;
|
|
199
|
+
}
|
|
200
|
+
}, [visibilityList, enabled, initiallyShownCards, currentIndex, setCurrentIndex]);
|
|
118
201
|
};
|
|
@@ -36,6 +36,7 @@ type CardListBaseProps = {
|
|
|
36
36
|
accessoryMobile?: (typeof ACCESSORY_MOBILE_TYPES)[keyof typeof ACCESSORY_MOBILE_TYPES];
|
|
37
37
|
initiallyShownCardsDesktop?: number;
|
|
38
38
|
initiallyShownCardsMobile?: number;
|
|
39
|
+
initiallyInViewCardIndex?: number;
|
|
39
40
|
chipGroup?: ReactElement;
|
|
40
41
|
buttonContent?: React.ReactNode;
|
|
41
42
|
onButtonClick?: () => void;
|
|
@@ -69,6 +70,7 @@ type CardListRowRailProps = {
|
|
|
69
70
|
accessory?: typeof ACCESSORY_DESKTOP_TYPES.pagination;
|
|
70
71
|
isMobile?: boolean;
|
|
71
72
|
accessibilityLabels?: AccessibilityLabels;
|
|
73
|
+
initiallyInViewCardIndex: number;
|
|
72
74
|
};
|
|
73
75
|
type CardListCarouselProps = {
|
|
74
76
|
children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
|
|
@@ -79,6 +81,7 @@ type CardListCarouselProps = {
|
|
|
79
81
|
isMobile?: boolean;
|
|
80
82
|
carouselLabel?: (initiallyShownCards: number, childrenLength: number) => string;
|
|
81
83
|
slideLabel?: (index: number, childrenLength: number) => string;
|
|
84
|
+
initialPageIndex: number;
|
|
82
85
|
};
|
|
83
86
|
type CardListProps = CardListBaseProps;
|
|
84
87
|
export default CardListProps;
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
.bpk-content-card--link{color:inherit;font:inherit;text-decoration:inherit}.bpk-content-card--horizontal{display:grid;column-gap:2.5rem;grid-template-columns:minmax(10%, 38.75rem) 40%;align-items:center}@media(max-width: 32rem){.bpk-content-card--horizontal{grid-template-columns:1fr}}.bpk-content-card--horizontal .bpk-content-card--image-container{width:100%;height:26.25rem}@media(max-width: 32rem){.bpk-content-card--horizontal .bpk-content-card--image-container{max-height:11.25rem;margin-bottom:1rem}}@media(max-width: 64rem){.bpk-content-card--horizontal .bpk-content-card--image-container{height:100%}}.bpk-content-card--vertical .bpk-content-card--image{height:28.75rem;margin-bottom:1rem}@media(max-width: 48rem){.bpk-content-card--vertical .bpk-content-card--image{width:100%;height:auto;max-height:16.25rem}}@media(max-width: 32rem){.bpk-content-card--vertical .bpk-content-card--image{max-height:11.25rem}}.bpk-content-card--headline{margin-bottom:.25rem;font-size:1.25rem;line-height:1.5rem;font-weight:700}.bpk-content-card--description{color:#626971;font-size:1rem;line-height:1.5rem;font-weight:400}.bpk-content-card--image{width:100%;height:100%;border-radius:.75rem;object-fit:cover}
|
|
18
|
+
.bpk-content-card--link{position:relative;display:block;border-radius:.75rem;color:inherit;font:inherit;text-decoration:inherit}.bpk-content-card--link:focus{outline:.125rem solid #0062e3;outline-offset:.125rem}.bpk-content-card--horizontal{display:grid;column-gap:2.5rem;grid-template-columns:minmax(10%, 38.75rem) 40%;align-items:center}@media(max-width: 32rem){.bpk-content-card--horizontal{grid-template-columns:1fr}}.bpk-content-card--horizontal .bpk-content-card--image-container{width:100%;height:26.25rem}@media(max-width: 32rem){.bpk-content-card--horizontal .bpk-content-card--image-container{max-height:11.25rem;margin-bottom:1rem}}@media(max-width: 64rem){.bpk-content-card--horizontal .bpk-content-card--image-container{height:100%}}.bpk-content-card--vertical .bpk-content-card--image{height:28.75rem;margin-bottom:1rem}@media(max-width: 48rem){.bpk-content-card--vertical .bpk-content-card--image{width:100%;height:auto;max-height:16.25rem}}@media(max-width: 32rem){.bpk-content-card--vertical .bpk-content-card--image{max-height:11.25rem}}.bpk-content-card--headline{margin-bottom:.25rem;font-size:1.25rem;line-height:1.5rem;font-weight:700}.bpk-content-card--description{color:#626971;font-size:1rem;line-height:1.5rem;font-weight:400}.bpk-content-card--image{width:100%;height:100%;border-radius:.75rem;object-fit:cover}
|
|
@@ -110,7 +110,7 @@ const BpkNudger = ({
|
|
|
110
110
|
inputRef.current && setNativeValue(inputRef.current, newValue);
|
|
111
111
|
},
|
|
112
112
|
disabled: minButtonDisabled,
|
|
113
|
-
|
|
113
|
+
"aria-label": decreaseButtonLabel,
|
|
114
114
|
"aria-controls": id,
|
|
115
115
|
children: /*#__PURE__*/_jsx(AlignedMinusIcon, {})
|
|
116
116
|
}), /*#__PURE__*/_jsx("input", {
|
|
@@ -151,7 +151,7 @@ const BpkNudger = ({
|
|
|
151
151
|
inputRef.current && setNativeValue(inputRef.current, newValue);
|
|
152
152
|
},
|
|
153
153
|
disabled: maxButtonDisabled,
|
|
154
|
-
|
|
154
|
+
"aria-label": increaseButtonLabel,
|
|
155
155
|
"aria-controls": id,
|
|
156
156
|
children: /*#__PURE__*/_jsx(AlignedPlusIcon, {})
|
|
157
157
|
})]
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
+
import type { SurfaceBgColor } from '../../bpk-react-utils';
|
|
3
|
+
export declare const PANEL_BG_COLORS: {
|
|
4
|
+
readonly surfaceDefault: "surface-default";
|
|
5
|
+
readonly surfaceElevated: "surface-elevated";
|
|
6
|
+
readonly surfaceHero: "surface-hero";
|
|
7
|
+
readonly surfaceContrast: "surface-contrast";
|
|
8
|
+
readonly surfaceHighlight: "surface-highlight";
|
|
9
|
+
readonly surfaceSubtle: "surface-subtle";
|
|
10
|
+
readonly surfaceLowContrast: "surface-low-contrast";
|
|
11
|
+
readonly surfaceTint: "surface-tint";
|
|
12
|
+
};
|
|
13
|
+
export type PanelBgColor = SurfaceBgColor;
|
|
2
14
|
export type Props = {
|
|
3
15
|
children: ReactNode;
|
|
16
|
+
bgColor?: PanelBgColor;
|
|
4
17
|
padded?: boolean;
|
|
5
18
|
fullWidth?: boolean;
|
|
6
19
|
className?: string | null;
|
|
7
20
|
keyline?: boolean;
|
|
8
21
|
[rest: string]: any;
|
|
9
22
|
};
|
|
10
|
-
declare const BpkPanel: ({ children, className, fullWidth, keyline, padded, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
declare const BpkPanel: ({ bgColor, children, className, fullWidth, keyline, padded, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
11
24
|
export default BpkPanel;
|
|
@@ -16,11 +16,13 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { cssModules, getDataComponentAttribute } from "../../bpk-react-utils";
|
|
19
|
+
import { cssModules, getDataComponentAttribute, SURFACE_COLORS } from "../../bpk-react-utils";
|
|
20
20
|
import STYLES from "./BpkPanel.module.css";
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
22
|
const getClassName = cssModules(STYLES);
|
|
23
|
+
export const PANEL_BG_COLORS = SURFACE_COLORS;
|
|
23
24
|
const BpkPanel = ({
|
|
25
|
+
bgColor = PANEL_BG_COLORS.surfaceDefault,
|
|
24
26
|
children,
|
|
25
27
|
className = null,
|
|
26
28
|
fullWidth = false,
|
|
@@ -42,6 +44,7 @@ const BpkPanel = ({
|
|
|
42
44
|
classNames.push(getClassName('bpk-panel--keyline'));
|
|
43
45
|
}
|
|
44
46
|
}
|
|
47
|
+
classNames.push(getClassName(`bpk-panel--${bgColor}`));
|
|
45
48
|
if (className) {
|
|
46
49
|
classNames.push(className);
|
|
47
50
|
}
|
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
.bpk-panel{display:block;background-color:#fff;border-radius:.75rem}.bpk-panel--padded{padding:1rem}.bpk-panel--full-width{border-radius:0}.bpk-panel--keyline{box-shadow:0 0 0 1px #c1c7cf inset}.bpk-panel--full-width-keyline{box-shadow:#c1c7cf 0 -0.0625rem 0 0 inset,#c1c7cf 0 .0625rem 0 0 inset}
|
|
18
|
+
.bpk-panel{display:block;background-color:#fff;border-radius:.75rem}.bpk-panel--surface-default{background-color:#fff}.bpk-panel--surface-elevated{background-color:#fff}.bpk-panel--surface-hero{background-color:#0062e3}.bpk-panel--surface-contrast{background-color:#05203c}.bpk-panel--surface-highlight{background-color:#e0e4e9}.bpk-panel--surface-subtle{background-color:#e3f0ff}.bpk-panel--surface-low-contrast{background-color:#f5f7fa}.bpk-panel--surface-tint{background-color:hsla(0,0%,100%,.1)}.bpk-panel--padded{padding:1rem}.bpk-panel--full-width{border-radius:0}.bpk-panel--keyline{box-shadow:0 0 0 1px #c1c7cf inset}.bpk-panel--full-width-keyline{box-shadow:#c1c7cf 0 -0.0625rem 0 0 inset,#c1c7cf 0 .0625rem 0 0 inset}
|
package/bpk-mixins/_index.scss
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/* stylelint-disable at-rule-disallowed-list */
|
|
20
|
+
|
|
21
|
+
@use 'tokens';
|
|
22
|
+
|
|
23
|
+
////
|
|
24
|
+
/// @group surfaces
|
|
25
|
+
////
|
|
26
|
+
|
|
27
|
+
// Keys must stay in sync with bpk-react-utils/src/surfaceColors.ts
|
|
28
|
+
$bpk-surface-bg-colors: (
|
|
29
|
+
'surface-default': tokens.$bpk-surface-default-day,
|
|
30
|
+
'surface-elevated': tokens.$bpk-surface-elevated-day,
|
|
31
|
+
'surface-hero': tokens.$bpk-surface-hero-day,
|
|
32
|
+
'surface-contrast': tokens.$bpk-surface-contrast-day,
|
|
33
|
+
'surface-highlight': tokens.$bpk-surface-highlight-day,
|
|
34
|
+
'surface-subtle': tokens.$bpk-surface-subtle-day,
|
|
35
|
+
'surface-low-contrast': tokens.$bpk-surface-low-contrast-day,
|
|
36
|
+
'surface-tint': tokens.$bpk-surface-tint-day,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
/// Generates background-color modifier classes for all surface colors.
|
|
40
|
+
///
|
|
41
|
+
/// @example scss
|
|
42
|
+
/// .bpk-panel {
|
|
43
|
+
/// @include bpk-surface-bg-colors;
|
|
44
|
+
/// }
|
|
45
|
+
|
|
46
|
+
@mixin bpk-surface-bg-colors {
|
|
47
|
+
@each $color-name, $color-value in $bpk-surface-bg-colors {
|
|
48
|
+
&--#{$color-name} {
|
|
49
|
+
background-color: $color-value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -7,9 +7,11 @@ import { isDeviceIphone, isDeviceIpad, isDeviceIos } from './src/deviceDetection
|
|
|
7
7
|
import { getDataComponentAttribute } from './src/getDataComponentAttribute';
|
|
8
8
|
import isRTL from './src/isRTL';
|
|
9
9
|
import { setNativeValue } from './src/nativeEventHandler';
|
|
10
|
+
import { SURFACE_COLORS } from './src/surfaceColors';
|
|
10
11
|
import withDefaultProps from './src/withDefaultProps';
|
|
11
12
|
import wrapDisplayName from './src/wrapDisplayName';
|
|
12
|
-
export {
|
|
13
|
+
export type { SurfaceBgColor } from './src/surfaceColors';
|
|
14
|
+
export { Portal, TransitionInitialMount, cssModules, deprecated, withDefaultProps, wrapDisplayName, isDeviceIphone, isDeviceIpad, isDeviceIos, isRTL, BpkDialogWrapper, setNativeValue, getDataComponentAttribute, SURFACE_COLORS, };
|
|
13
15
|
declare const _default: {
|
|
14
16
|
Portal: typeof Portal;
|
|
15
17
|
TransitionInitialMount: ({ appearActiveClassName, appearClassName, children, transitionTimeout, }: {
|
|
@@ -43,5 +45,15 @@ declare const _default: {
|
|
|
43
45
|
getDataComponentAttribute: (componentName: string) => {
|
|
44
46
|
"data-backpack-ds-component": string;
|
|
45
47
|
};
|
|
48
|
+
SURFACE_COLORS: {
|
|
49
|
+
readonly surfaceDefault: "surface-default";
|
|
50
|
+
readonly surfaceElevated: "surface-elevated";
|
|
51
|
+
readonly surfaceHero: "surface-hero";
|
|
52
|
+
readonly surfaceContrast: "surface-contrast";
|
|
53
|
+
readonly surfaceHighlight: "surface-highlight";
|
|
54
|
+
readonly surfaceSubtle: "surface-subtle";
|
|
55
|
+
readonly surfaceLowContrast: "surface-low-contrast";
|
|
56
|
+
readonly surfaceTint: "surface-tint";
|
|
57
|
+
};
|
|
46
58
|
};
|
|
47
59
|
export default _default;
|
package/bpk-react-utils/index.js
CHANGED
|
@@ -26,9 +26,10 @@ import { isDeviceIphone, isDeviceIpad, isDeviceIos } from "./src/deviceDetection
|
|
|
26
26
|
import { getDataComponentAttribute } from "./src/getDataComponentAttribute";
|
|
27
27
|
import isRTL from "./src/isRTL";
|
|
28
28
|
import { setNativeValue } from "./src/nativeEventHandler";
|
|
29
|
+
import { SURFACE_COLORS } from "./src/surfaceColors";
|
|
29
30
|
import withDefaultProps from "./src/withDefaultProps";
|
|
30
31
|
import wrapDisplayName from "./src/wrapDisplayName";
|
|
31
|
-
export { Portal, TransitionInitialMount, cssModules, deprecated, withDefaultProps, wrapDisplayName, isDeviceIphone, isDeviceIpad, isDeviceIos, isRTL, BpkDialogWrapper, setNativeValue, getDataComponentAttribute };
|
|
32
|
+
export { Portal, TransitionInitialMount, cssModules, deprecated, withDefaultProps, wrapDisplayName, isDeviceIphone, isDeviceIpad, isDeviceIos, isRTL, BpkDialogWrapper, setNativeValue, getDataComponentAttribute, SURFACE_COLORS };
|
|
32
33
|
export default {
|
|
33
34
|
Portal,
|
|
34
35
|
TransitionInitialMount,
|
|
@@ -42,5 +43,6 @@ export default {
|
|
|
42
43
|
isRTL,
|
|
43
44
|
BpkDialogWrapper,
|
|
44
45
|
setNativeValue,
|
|
45
|
-
getDataComponentAttribute
|
|
46
|
+
getDataComponentAttribute,
|
|
47
|
+
SURFACE_COLORS
|
|
46
48
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const SURFACE_COLORS: {
|
|
2
|
+
readonly surfaceDefault: "surface-default";
|
|
3
|
+
readonly surfaceElevated: "surface-elevated";
|
|
4
|
+
readonly surfaceHero: "surface-hero";
|
|
5
|
+
readonly surfaceContrast: "surface-contrast";
|
|
6
|
+
readonly surfaceHighlight: "surface-highlight";
|
|
7
|
+
readonly surfaceSubtle: "surface-subtle";
|
|
8
|
+
readonly surfaceLowContrast: "surface-low-contrast";
|
|
9
|
+
readonly surfaceTint: "surface-tint";
|
|
10
|
+
};
|
|
11
|
+
export type SurfaceBgColor = (typeof SURFACE_COLORS)[keyof typeof SURFACE_COLORS];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Values must stay in sync with bpk-mixins/_surfaces.scss
|
|
20
|
+
export const SURFACE_COLORS = {
|
|
21
|
+
surfaceDefault: 'surface-default',
|
|
22
|
+
surfaceElevated: 'surface-elevated',
|
|
23
|
+
surfaceHero: 'surface-hero',
|
|
24
|
+
surfaceContrast: 'surface-contrast',
|
|
25
|
+
surfaceHighlight: 'surface-highlight',
|
|
26
|
+
surfaceSubtle: 'surface-subtle',
|
|
27
|
+
surfaceLowContrast: 'surface-low-contrast',
|
|
28
|
+
surfaceTint: 'surface-tint'
|
|
29
|
+
};
|