@skyscanner/backpack-web 37.8.0 → 37.9.1

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.
Files changed (23) hide show
  1. package/bpk-component-card-list/src/BpkCardList.js +53 -79
  2. package/bpk-component-card-list/src/BpkCardListGridStack/BpkCardListGridStack.js +2 -2
  3. package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.d.ts +3 -0
  4. package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.js +106 -0
  5. package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.module.css +18 -0
  6. package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListRowRailContainer.d.ts +3 -0
  7. package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListRowRailContainer.js +68 -0
  8. package/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListRowRailContainer.module.css +18 -0
  9. package/bpk-component-card-list/src/BpkCardListRowRail/constants.d.ts +2 -0
  10. package/bpk-component-card-list/src/BpkCardListRowRail/constants.js +20 -0
  11. package/bpk-component-card-list/src/BpkCardListRowRail/index.d.ts +2 -0
  12. package/bpk-component-card-list/src/BpkCardListRowRail/index.js +20 -0
  13. package/bpk-component-card-list/src/BpkCardListRowRail/utils.d.ts +16 -0
  14. package/bpk-component-card-list/src/BpkCardListRowRail/utils.js +127 -0
  15. package/bpk-component-card-list/src/BpkExpand/ExpandAccessoryContent.d.ts +1 -1
  16. package/bpk-component-card-list/src/BpkExpand/ExpandAccessoryContent.js +2 -2
  17. package/bpk-component-card-list/src/common-types.d.ts +31 -4
  18. package/bpk-component-card-list/src/common-types.js +0 -16
  19. package/bpk-component-icon/lg/flame.js +14 -0
  20. package/bpk-component-icon/lg/incompatible.js +14 -0
  21. package/bpk-component-icon/sm/flame.js +14 -0
  22. package/bpk-component-icon/sm/incompatible.js +14 -0
  23. package/package.json +2 -2
@@ -15,21 +15,20 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
-
19
- import { useState, useEffect } from 'react';
20
18
  import BpkBreakpoint, { BREAKPOINTS } from "../../bpk-component-breakpoint";
21
19
  import { BpkButtonV2 } from "../../bpk-component-button";
22
20
  import BpkSectionHeader from "../../bpk-component-section-header";
23
21
  import { cssModules } from "../../bpk-react-utils";
24
22
  import BpkCardListGridStack from "./BpkCardListGridStack";
25
- // import BpkCardListRowRailContainer from './BpkCardListRowRail';
23
+ import BpkCardListRowRailContainer from "./BpkCardListRowRail";
26
24
  import { ACCESSORY_DESKTOP_TYPES, ACCESSORY_MOBILE_TYPES, LAYOUTS } from "./common-types";
27
25
  import STYLES from "./BpkCardList.module.css";
28
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
26
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
29
27
  const getClassName = cssModules(STYLES);
30
28
  const DEFAULT_ITEMS = 3;
31
29
  const BpkCardList = props => {
32
30
  const {
31
+ accessibilityLabels,
33
32
  accessoryDesktop,
34
33
  accessoryMobile,
35
34
  buttonContent,
@@ -38,92 +37,68 @@ const BpkCardList = props => {
38
37
  chipGroup,
39
38
  description,
40
39
  expandText,
41
- initiallyShownCards = DEFAULT_ITEMS,
40
+ initiallyShownCardsDesktop = DEFAULT_ITEMS,
41
+ initiallyShownCardsMobile = DEFAULT_ITEMS,
42
42
  layoutDesktop,
43
43
  layoutMobile,
44
44
  onButtonClick,
45
45
  onExpandClick,
46
46
  title
47
47
  } = props;
48
- const [showHeaderButton, setShowHeaderButton] = useState(false);
49
- const [isMobileActive, setIsMobileActive] = useState(false);
50
- useEffect(() => {
51
- if (isMobileActive) {
52
- setShowHeaderButton(!!buttonContent && accessoryMobile !== ACCESSORY_MOBILE_TYPES.button);
53
- } else {
54
- setShowHeaderButton(!!buttonContent && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.button);
48
+ const shouldShowHeaderButton = isMobile => {
49
+ if (!buttonContent) return false;
50
+ if (isMobile) {
51
+ return accessoryMobile !== ACCESSORY_MOBILE_TYPES.button;
55
52
  }
56
- }, [isMobileActive, buttonContent, accessoryMobile, accessoryDesktop]);
53
+ return accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.button;
54
+ };
57
55
  const headerButton = buttonContent && /*#__PURE__*/_jsx(BpkButtonV2, {
58
56
  onClick: onButtonClick,
59
57
  href: buttonHref,
60
58
  "data-testid": "bpk-card-list-header-button",
61
59
  children: buttonContent
62
60
  });
63
- return /*#__PURE__*/_jsxs("div", {
61
+ return /*#__PURE__*/_jsx("div", {
64
62
  className: getClassName('bpk-card-list'),
65
63
  "data-testid": "bpk-card-list",
66
- children: [/*#__PURE__*/_jsx(BpkSectionHeader, {
67
- title: title,
68
- description: description,
69
- button: showHeaderButton ? headerButton : null
70
- }), chipGroup, /*#__PURE__*/_jsx("div", {
71
- className: getClassName('bpk-card-list--card-list'),
72
- "data-testid": "bpk-card-list--card-list",
73
- children: /*#__PURE__*/_jsx(BpkBreakpoint, {
74
- query: BREAKPOINTS.MOBILE,
75
- children: isActive => {
76
- if (isActive) {
77
- setIsMobileActive(isActive);
78
-
79
- // if (layoutMobile === LAYOUTS.rail) {
80
- // return (
81
- // <BpkCardListRowRailContainer
82
- // initiallyShownCards={initiallyShownCards}
83
- // layout={layoutMobile}
84
- // >
85
- // {cardList}
86
- // </BpkCardListRowRailContainer>
87
- // );
88
- // }
89
-
90
- if (layoutMobile === LAYOUTS.stack) {
91
- return /*#__PURE__*/_jsx(BpkCardListGridStack, {
92
- accessory: accessoryMobile,
93
- initiallyShownCards: initiallyShownCards,
94
- buttonContent: buttonContent,
95
- expandText: expandText,
96
- onButtonClick: onButtonClick,
97
- onExpandClick: onExpandClick,
98
- layout: layoutMobile,
99
- buttonHref: buttonHref,
100
- children: cardList
101
- });
102
- }
103
- }
104
-
105
- /// ///// Desktop Cases ////////
106
-
107
- // if (
108
- // layoutDesktop === LAYOUTS.row &&
109
- // accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.expand &&
110
- // accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.button
111
- // ) {
112
- // return (
113
- // <BpkCardListRowRailContainer
114
- // accessory={accessoryDesktop}
115
- // initiallyShownCards={initiallyShownCards}
116
- // layout={layoutDesktop}
117
- // >
118
- // {cardList}
119
- // </BpkCardListRowRailContainer>
120
- // );
121
- // }
122
-
123
- if (layoutDesktop === LAYOUTS.grid && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.pagination) {
124
- return /*#__PURE__*/_jsx(BpkCardListGridStack, {
64
+ children: /*#__PURE__*/_jsx(BpkBreakpoint, {
65
+ query: BREAKPOINTS.MOBILE,
66
+ children: isMobile => /*#__PURE__*/_jsxs(_Fragment, {
67
+ children: [/*#__PURE__*/_jsx(BpkSectionHeader, {
68
+ title: title,
69
+ description: description,
70
+ button: shouldShowHeaderButton(isMobile) ? headerButton : null
71
+ }), chipGroup, /*#__PURE__*/_jsx("div", {
72
+ className: getClassName('bpk-card-list--card-list'),
73
+ "data-testid": "bpk-card-list--card-list",
74
+ children: isMobile ? /*#__PURE__*/_jsxs(_Fragment, {
75
+ children: [layoutMobile === LAYOUTS.rail && /*#__PURE__*/_jsx(BpkCardListRowRailContainer, {
76
+ initiallyShownCards: initiallyShownCardsMobile,
77
+ layout: layoutMobile,
78
+ accessibilityLabels: accessibilityLabels,
79
+ isMobile: true,
80
+ children: cardList
81
+ }), layoutMobile === LAYOUTS.stack && /*#__PURE__*/_jsx(BpkCardListGridStack, {
82
+ accessory: accessoryMobile,
83
+ initiallyShownCards: initiallyShownCardsMobile,
84
+ buttonContent: buttonContent,
85
+ expandText: expandText,
86
+ onButtonClick: onButtonClick,
87
+ onExpandClick: onExpandClick,
88
+ layout: layoutMobile,
89
+ buttonHref: buttonHref,
90
+ children: cardList
91
+ })]
92
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
93
+ children: [layoutDesktop === LAYOUTS.row && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.expand && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.button && /*#__PURE__*/_jsx(BpkCardListRowRailContainer, {
94
+ accessory: accessoryDesktop,
95
+ initiallyShownCards: initiallyShownCardsDesktop,
96
+ layout: layoutDesktop,
97
+ accessibilityLabels: accessibilityLabels,
98
+ children: cardList
99
+ }), layoutDesktop === LAYOUTS.grid && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.pagination && /*#__PURE__*/_jsx(BpkCardListGridStack, {
125
100
  accessory: accessoryDesktop,
126
- initiallyShownCards: initiallyShownCards,
101
+ initiallyShownCards: initiallyShownCardsDesktop,
127
102
  buttonContent: buttonContent,
128
103
  expandText: expandText,
129
104
  onButtonClick: onButtonClick,
@@ -131,12 +106,11 @@ const BpkCardList = props => {
131
106
  layout: layoutDesktop,
132
107
  buttonHref: buttonHref,
133
108
  children: cardList
134
- });
135
- }
136
- return null;
137
- }
109
+ })]
110
+ })
111
+ })]
138
112
  })
139
- })]
113
+ })
140
114
  });
141
115
  };
142
116
  export default BpkCardList;
@@ -47,13 +47,13 @@ const BpkCardListGridStack = props => {
47
47
  const childrenArray = Children.toArray(children);
48
48
  const initialCards = childrenArray.slice(0, defaultInitiallyShownCards);
49
49
  const restCards = childrenArray.slice(defaultInitiallyShownCards, childrenArray.length);
50
- const onExpandTogle = () => {
50
+ const onExpandToggle = () => {
51
51
  setCollapsed(prev => !prev);
52
52
  onExpandClick?.();
53
53
  };
54
54
  const expandAccessoryContent = /*#__PURE__*/_jsx(ExpandAccessoryContent, {
55
55
  collapsed: collapsed,
56
- onExpandTogle: onExpandTogle,
56
+ onExpandToggle: onExpandToggle,
57
57
  children: expandText || ''
58
58
  });
59
59
  const buttonAccessoryContent = /*#__PURE__*/_jsx("div", {
@@ -0,0 +1,3 @@
1
+ import type { CardListCarouselProps } from '../common-types';
2
+ declare const BpkCardListCarousel: (props: CardListCarouselProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default BpkCardListCarousel;
@@ -0,0 +1,106 @@
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
+ import { useRef, useState, useEffect, isValidElement, Children } from 'react';
20
+ import { cssModules } from "../../../bpk-react-utils";
21
+ import { RENDER_BUFFER_SIZE } from "./constants";
22
+ import { lockScroll, setA11yTabIndex, useUpdateCurrentIndexByVisibility, useScrollToCard, useIntersectionObserver } from "./utils";
23
+ import STYLES from "./BpkCardListCarousel.module.css";
24
+ import { jsx as _jsx } from "react/jsx-runtime";
25
+ const getClassName = cssModules(STYLES);
26
+ const BpkCardListCarousel = props => {
27
+ const {
28
+ 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.`,
29
+ children,
30
+ currentIndex,
31
+ initiallyShownCards,
32
+ isMobile = false,
33
+ layout,
34
+ setCurrentIndex,
35
+ slideLabel = (index, childrenLength) => `slide ${index + 1} of ${childrenLength}`
36
+ } = props;
37
+ const shownNumberStyle = {
38
+ '--initially-shown-cards': initiallyShownCards
39
+ };
40
+ const childrenLength = Children.count(children);
41
+ const [root, setRoot] = useState(null);
42
+ const cardRefs = useRef([]);
43
+ const [visibilityList, setVisibilityList] = useState(Array(childrenLength).fill(0));
44
+ const stateScrollingLockRef = useRef(false);
45
+ const openSetStateLockTimeoutRef = useRef(null);
46
+ const observerVisibility = useIntersectionObserver({
47
+ root,
48
+ threshold: 0.5
49
+ }, setVisibilityList);
50
+ useEffect(() => {
51
+ const container = root;
52
+ if (isMobile || !container) return undefined;
53
+ const lockScrollDuringInteraction = () => {
54
+ lockScroll(stateScrollingLockRef, openSetStateLockTimeoutRef);
55
+ };
56
+ container.addEventListener('wheel', lockScrollDuringInteraction);
57
+ container.addEventListener('touchmove', lockScrollDuringInteraction);
58
+ return () => {
59
+ container.removeEventListener('touchmove', lockScrollDuringInteraction);
60
+ container.removeEventListener('wheel', lockScrollDuringInteraction);
61
+ if (openSetStateLockTimeoutRef.current) {
62
+ clearTimeout(openSetStateLockTimeoutRef.current);
63
+ }
64
+ };
65
+ }, [root]);
66
+ useUpdateCurrentIndexByVisibility(isMobile, visibilityList, setCurrentIndex, stateScrollingLockRef, openSetStateLockTimeoutRef);
67
+ useScrollToCard(currentIndex, root, cardRefs, stateScrollingLockRef);
68
+
69
+ // Similar to Virtual Scrolling to improve performance
70
+ const firstVisibleIndex = Math.max(0, visibilityList.indexOf(1));
71
+ const lastVisibleIndex = firstVisibleIndex + initiallyShownCards - 1;
72
+ const renderList = visibilityList.map((_, index) => index >= firstVisibleIndex - RENDER_BUFFER_SIZE && index <= lastVisibleIndex + RENDER_BUFFER_SIZE ? 1 : 0);
73
+ return /*#__PURE__*/_jsx("div", {
74
+ className: getClassName(`bpk-card-list-row-rail__${layout}`),
75
+ "data-testid": "bpk-card-list-row-rail__carousel",
76
+ "aria-label": carouselLabel(initiallyShownCards, childrenLength),
77
+ "aria-roledescription": "carousel"
78
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
79
+ ,
80
+ tabIndex: 0,
81
+ role: "region",
82
+ ref: setRoot,
83
+ children: children.map((card, index) => {
84
+ if (! /*#__PURE__*/isValidElement(card)) return null;
85
+ const cardRefCallback = el => {
86
+ cardRefs.current[index] = el;
87
+ observerVisibility(el, index);
88
+ setA11yTabIndex(el, index, visibilityList);
89
+ };
90
+ const cardStyle = isMobile ? {
91
+ ...shownNumberStyle,
92
+ visibility: renderList[index] === 1 ? 'visible' : 'hidden' // for mobile, {renderList[index] === 1 && card} will cause reflowing and bugs, implementing visibility improvement instead
93
+ } : shownNumberStyle;
94
+ return /*#__PURE__*/_jsx("div", {
95
+ className: getClassName(`bpk-card-list-row-rail__${layout}__card`),
96
+ ref: cardRefCallback,
97
+ style: cardStyle,
98
+ role: "group",
99
+ "aria-label": slideLabel(index, childrenLength),
100
+ "aria-current": index === currentIndex ? 'true' : 'false',
101
+ children: isMobile ? card : renderList[index] === 1 && card
102
+ }, `carousel-card-${index.toString()}`);
103
+ })
104
+ });
105
+ };
106
+ export default BpkCardListCarousel;
@@ -0,0 +1,18 @@
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
+ .bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{display:flex;padding-top:.25rem;padding-bottom:.25rem;overflow-x:scroll;box-sizing:border-box;gap:.25rem;scroll-snap-stop:always;scroll-snap-type:x mandatory;scrollbar-width:none}.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;padding:.5rem;flex:0 0 calc((100% - .5rem*(var(--initially-shown-cards, 3) - 1))/var(--initially-shown-cards, 3));overflow:visible;box-sizing:border-box;scroll-snap-align:start}.bpk-card-list-row-rail__rail{-webkit-overflow-scrolling:touch}
@@ -0,0 +1,3 @@
1
+ import type { CardListRowRailProps } from '../common-types';
2
+ declare const BpkCardListRowRailContainer: (props: CardListRowRailProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default BpkCardListRowRailContainer;
@@ -0,0 +1,68 @@
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
+ import { useState, Children } from 'react';
19
+ import BpkPageIndicator from "../../../bpk-component-page-indicator";
20
+ import { cssModules } from "../../../bpk-react-utils";
21
+ import { ACCESSORY_DESKTOP_TYPES, LAYOUTS } from "../common-types";
22
+ import BpkCardListCarousel from "./BpkCardListCarousel";
23
+ import STYLES from "./BpkCardListRowRailContainer.module.css";
24
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
25
+ const getClassName = cssModules(STYLES);
26
+ const BpkCardListRowRailContainer = props => {
27
+ const {
28
+ accessibilityLabels,
29
+ accessory,
30
+ children,
31
+ initiallyShownCards,
32
+ isMobile = false,
33
+ layout
34
+ } = props;
35
+ const totalIndicators = Children.count(children);
36
+ const [currentIndex, setCurrentIndex] = useState(0);
37
+ const showAccessory = totalIndicators > initiallyShownCards;
38
+ const accessoryContent = layout === LAYOUTS.row && accessory === ACCESSORY_DESKTOP_TYPES.pagination ? /*#__PURE__*/_jsx(BpkPageIndicator, {
39
+ currentIndex: currentIndex,
40
+ totalIndicators: totalIndicators,
41
+ onClick: (_e, index) => setCurrentIndex(index),
42
+ showNav: true,
43
+ indicatorLabel: accessibilityLabels?.indicatorLabel ?? 'Go to slide',
44
+ prevNavLabel: accessibilityLabels?.prevNavLabel ?? 'Previous slide',
45
+ nextNavLabel: accessibilityLabels?.nextNavLabel ?? 'Next slide'
46
+ }) : null;
47
+ return /*#__PURE__*/_jsxs("div", {
48
+ className: getClassName('bpk-card-list-row-rail'),
49
+ "data-testid": "bpk-card-list-row-rail",
50
+ children: [/*#__PURE__*/_jsx(BpkCardListCarousel, {
51
+ initiallyShownCards: initiallyShownCards,
52
+ layout: layout,
53
+ currentIndex: currentIndex,
54
+ setCurrentIndex: setCurrentIndex,
55
+ isMobile: isMobile,
56
+ carouselLabel: accessibilityLabels?.carouselLabel,
57
+ slideLabel: accessibilityLabels?.slideLabel,
58
+ children: children
59
+ }), accessoryContent && showAccessory && /*#__PURE__*/_jsx("div", {
60
+ role: "region",
61
+ "aria-label": "pagination",
62
+ className: getClassName(`bpk-card-list-row-rail__accessory`),
63
+ "data-testid": "bpk-card-list-row-rail__accessory",
64
+ children: accessoryContent
65
+ })]
66
+ });
67
+ };
68
+ export default BpkCardListRowRailContainer;
@@ -0,0 +1,18 @@
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
+ .bpk-card-list-row-rail{display:flex;flex-direction:column}.bpk-card-list-row-rail__accessory{width:100%}
@@ -0,0 +1,2 @@
1
+ export declare const RELEASE_LOCK_DELAY = 20;
2
+ export declare const RENDER_BUFFER_SIZE = 3;
@@ -0,0 +1,20 @@
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
+ export const RELEASE_LOCK_DELAY = 20;
20
+ export const RENDER_BUFFER_SIZE = 3;
@@ -0,0 +1,2 @@
1
+ import BpkCardListRowRailContainer from './BpkCardListRowRailContainer';
2
+ export default BpkCardListRowRailContainer;
@@ -0,0 +1,20 @@
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
+ import BpkCardListRowRailContainer from "./BpkCardListRowRailContainer";
20
+ export default BpkCardListRowRailContainer;
@@ -0,0 +1,16 @@
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;
7
+ /**
8
+ * Only sets the tabIndex of focusable elements as 0 if the card is visible, otherwise sets it to -1, including all its children.
9
+ * For example, if there is a button inside a card which is not shown, it cannot be focused as well.
10
+ * @param el - Card container element, typically a div used to wrap the card content.
11
+ * @param index - Current container index
12
+ */
13
+ export declare const setA11yTabIndex: (el: HTMLDivElement | null, index: number, visibilityList: number[]) => void;
14
+ export declare const useUpdateCurrentIndexByVisibility: (isMobile: boolean, visibilityList: number[], setCurrentIndex: (index: number) => void, stateScrollingLockRef: React.MutableRefObject<boolean>, openSetStateLockTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>) => void;
15
+ export declare const useScrollToCard: (currentIndex: number, container: HTMLElement | null, cardRefs: React.MutableRefObject<Array<HTMLDivElement | null>>, stateScrollingLockRef: React.MutableRefObject<boolean>) => void;
16
+ export declare const useIntersectionObserver: ({ root, threshold }: IntersectionObserverInit, setVisibilityList: React.Dispatch<React.SetStateAction<number[]>>) => (element: HTMLElement | null, index: number) => void;
@@ -0,0 +1,127 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2022 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
+ import { useEffect, useRef, useMemo } from 'react';
20
+ import { RELEASE_LOCK_DELAY } from "./constants";
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
+ /**
42
+ * Only sets the tabIndex of focusable elements as 0 if the card is visible, otherwise sets it to -1, including all its children.
43
+ * For example, if there is a button inside a card which is not shown, it cannot be focused as well.
44
+ * @param el - Card container element, typically a div used to wrap the card content.
45
+ * @param index - Current container index
46
+ */
47
+
48
+ export const setA11yTabIndex = (el, index, visibilityList) => {
49
+ if (!el) return;
50
+ const focusableElements = el.querySelectorAll('a, button, input, textarea, select, [tabindex]:not([tabindex="-1"])');
51
+ focusableElements.forEach(element => {
52
+ const targetElement = element;
53
+ targetElement.tabIndex = visibilityList[index] === 1 ? 0 : -1;
54
+ });
55
+ };
56
+ export const useUpdateCurrentIndexByVisibility = (isMobile, visibilityList, setCurrentIndex, stateScrollingLockRef, openSetStateLockTimeoutRef) => {
57
+ useEffect(() => {
58
+ if (isMobile) return; // No pagination on mobile, so no need to update the current index
59
+ if (!visibilityList || visibilityList.length === 0) return;
60
+ const firstVisibleIndex = visibilityList.findIndex(visibility => visibility === 1);
61
+ if (firstVisibleIndex !== -1) {
62
+ setCurrentIndex(firstVisibleIndex);
63
+ lockScroll(stateScrollingLockRef, openSetStateLockTimeoutRef); // prevent scrollIntoView from being called immediately after the current index is set
64
+ }
65
+ }, [visibilityList]);
66
+ };
67
+ export const useScrollToCard = (currentIndex, container, cardRefs, stateScrollingLockRef) => {
68
+ useEffect(() => {
69
+ const isVisible = container && container.getBoundingClientRect().bottom > 0 && container.getBoundingClientRect().bottom <= window.innerHeight;
70
+ 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
71
+
72
+ if (stateScrollingLockRef.current && stateScrollingLockRef.current === true) return;
73
+ const targetCard = cardRefs.current[currentIndex];
74
+ if (targetCard) {
75
+ targetCard.scrollIntoView({
76
+ behavior: 'smooth',
77
+ block: 'nearest',
78
+ inline: 'start'
79
+ });
80
+ }
81
+ }, [currentIndex]);
82
+ };
83
+ export const useIntersectionObserver = ({
84
+ root,
85
+ threshold
86
+ }, setVisibilityList) => {
87
+ const callbackRef = useRef(setVisibilityList);
88
+ useEffect(() => {
89
+ callbackRef.current = setVisibilityList;
90
+ });
91
+ const observeAll = useMemo(() => {
92
+ if (!root) return () => {};
93
+ const observer = new IntersectionObserver(entries => {
94
+ entries.forEach(entry => {
95
+ const {
96
+ index
97
+ } = entry.target.dataset;
98
+ if (!index) return;
99
+ const currentIndex = parseInt(index, 10);
100
+ if (entry.isIntersecting) {
101
+ setVisibilityList(prevList => {
102
+ const newList = [...prevList];
103
+ newList[currentIndex] = 1;
104
+ return newList;
105
+ });
106
+ } else {
107
+ setVisibilityList(prevList => {
108
+ const newList = [...prevList];
109
+ newList[currentIndex] = 0;
110
+ return newList;
111
+ });
112
+ }
113
+ });
114
+ }, {
115
+ root,
116
+ threshold
117
+ });
118
+ const observeElement = (element, index) => {
119
+ if (element && observer) {
120
+ element.setAttribute('data-index', index.toString());
121
+ observer.observe(element);
122
+ }
123
+ };
124
+ return observeElement;
125
+ }, [root, threshold]);
126
+ return observeAll;
127
+ };
@@ -1,3 +1,3 @@
1
1
  import type { ExpandProps } from '../common-types';
2
- declare const ExpandAccessoryContent: ({ children, collapsed, onExpandTogle, }: ExpandProps) => import("react/jsx-runtime").JSX.Element;
2
+ declare const ExpandAccessoryContent: ({ children, collapsed, onExpandToggle, }: ExpandProps) => import("react/jsx-runtime").JSX.Element;
3
3
  export default ExpandAccessoryContent;
@@ -26,11 +26,11 @@ const AlignedChevronUpIcon = withButtonAlignment(withRtlSupport(ChevronUp));
26
26
  const ExpandAccessoryContent = ({
27
27
  children,
28
28
  collapsed,
29
- onExpandTogle
29
+ onExpandToggle
30
30
  }) => /*#__PURE__*/_jsxs(BpkButtonV2, {
31
31
  "data-testid": "bpk-card-list__accessory-expand-button",
32
32
  type: BUTTON_TYPES.link,
33
- onClick: () => onExpandTogle(),
33
+ onClick: onExpandToggle,
34
34
  "aria-expanded": !collapsed,
35
35
  children: [children, collapsed ? /*#__PURE__*/_jsx(AlignedChevronDownIcon, {}) : /*#__PURE__*/_jsx(AlignedChevronUpIcon, {})]
36
36
  });
@@ -1,4 +1,4 @@
1
- import type { ReactElement } from 'react';
1
+ import type { ReactElement, Dispatch, SetStateAction } from 'react';
2
2
  declare const LAYOUTS: {
3
3
  readonly grid: "grid";
4
4
  readonly stack: "stack";
@@ -19,7 +19,14 @@ declare const ACCESSORY_MOBILE_TYPES: {
19
19
  type ExpandProps = {
20
20
  children: string | ReactElement;
21
21
  collapsed: boolean;
22
- onExpandTogle: () => void;
22
+ onExpandToggle: () => void;
23
+ };
24
+ type AccessibilityLabels = {
25
+ indicatorLabel?: string;
26
+ prevNavLabel?: string;
27
+ nextNavLabel?: string;
28
+ carouselLabel?: (initiallyShownCards: number, childrenLength: number) => string;
29
+ slideLabel?: (index: number, childrenLength: number) => string;
23
30
  };
24
31
  type CardListBaseProps = {
25
32
  title: string;
@@ -29,13 +36,15 @@ type CardListBaseProps = {
29
36
  layoutDesktop: LayoutDesktop;
30
37
  accessoryDesktop?: (typeof ACCESSORY_DESKTOP_TYPES)[keyof typeof ACCESSORY_DESKTOP_TYPES];
31
38
  accessoryMobile?: (typeof ACCESSORY_MOBILE_TYPES)[keyof typeof ACCESSORY_MOBILE_TYPES];
32
- initiallyShownCards?: number;
39
+ initiallyShownCardsDesktop?: number;
40
+ initiallyShownCardsMobile?: number;
33
41
  chipGroup?: ReactElement;
34
42
  buttonContent?: React.ReactNode;
35
43
  onButtonClick?: () => void;
36
44
  onExpandClick?: () => void;
37
45
  buttonHref?: string;
38
46
  expandText?: string;
47
+ accessibilityLabels?: AccessibilityLabels;
39
48
  };
40
49
  type CardListGridStackProps = {
41
50
  children: ReactElement[];
@@ -48,7 +57,25 @@ type CardListGridStackProps = {
48
57
  onExpandClick?: () => void;
49
58
  buttonHref?: string;
50
59
  };
60
+ type CardListRowRailProps = {
61
+ children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
62
+ initiallyShownCards: number;
63
+ layout: typeof LAYOUTS.row | typeof LAYOUTS.rail;
64
+ accessory?: typeof ACCESSORY_DESKTOP_TYPES.pagination;
65
+ isMobile?: boolean;
66
+ accessibilityLabels?: AccessibilityLabels;
67
+ };
68
+ type CardListCarouselProps = {
69
+ children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
70
+ initiallyShownCards: number;
71
+ layout: typeof LAYOUTS.row | typeof LAYOUTS.rail;
72
+ currentIndex: number;
73
+ setCurrentIndex: Dispatch<SetStateAction<number>>;
74
+ isMobile?: boolean;
75
+ carouselLabel?: (initiallyShownCards: number, childrenLength: number) => string;
76
+ slideLabel?: (index: number, childrenLength: number) => string;
77
+ };
51
78
  type CardListProps = CardListBaseProps;
52
79
  export default CardListProps;
53
80
  export { LAYOUTS, ACCESSORY_DESKTOP_TYPES, ACCESSORY_MOBILE_TYPES };
54
- export type { LayoutDesktop, LayoutMobile, CardListGridStackProps, ExpandProps, };
81
+ export type { LayoutDesktop, LayoutMobile, CardListGridStackProps, CardListRowRailProps, CardListCarouselProps, ExpandProps, };
@@ -31,20 +31,4 @@ const ACCESSORY_MOBILE_TYPES = {
31
31
  expand: 'expand',
32
32
  button: 'button'
33
33
  };
34
-
35
- // type CardListRowRailProps = {
36
- // children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
37
- // initiallyShownCards: number;
38
- // layout: typeof LAYOUTS.row | typeof LAYOUTS.rail;
39
- // accessory?: typeof ACCESSORY_DESKTOP_TYPES.Pagination;
40
- // };
41
-
42
- // type CardListCarouselProps = {
43
- // children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
44
- // initiallyShownCards: number;
45
- // layout: typeof LAYOUTS.row | typeof LAYOUTS.rail;
46
- // currentIndex: number;
47
- // setCurrentIndex: Dispatch<SetStateAction<number>>;
48
- // }
49
-
50
34
  export { LAYOUTS, ACCESSORY_DESKTOP_TYPES, ACCESSORY_MOBILE_TYPES };
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ const FlameIcon = props => /*#__PURE__*/_jsx("svg", {
4
+ xmlns: "http://www.w3.org/2000/svg",
5
+ viewBox: "0 0 24 24",
6
+ "aria-hidden": "true",
7
+ width: "1.5rem",
8
+ height: "1.5rem",
9
+ ...props,
10
+ children: /*#__PURE__*/_jsx("path", {
11
+ d: "M13.473 6.517C11.313 4.604 12.485.5 12.485.5S6.315 4.357 7.44 12.827c-1.897-.756-1.897-3.07-1.126-4.613C4.771 9.757 4 12.41 4 14.478c0 4.427 3.487 8.022 7.791 8.022s7.776-3.595 7.776-8.022c0-4.428-3.456-5.616-6.094-7.946zm-1.682 13.5c-1.543 0-2.947-.695-3.919-1.76 0 0 3.75-.123 4.845-4.582.586.448.956 1.805.57 2.978.942.092 3.024-2.67 1.374-6.68 1.234.756 2.607 2.252 2.607 4.535 0 3.055-2.515 5.508-5.477 5.508"
12
+ })
13
+ });
14
+ export default FlameIcon;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ const IncompatibleIcon = props => /*#__PURE__*/_jsx("svg", {
4
+ xmlns: "http://www.w3.org/2000/svg",
5
+ viewBox: "0 0 24 24",
6
+ "aria-hidden": "true",
7
+ width: "1.5rem",
8
+ height: "1.5rem",
9
+ ...props,
10
+ children: /*#__PURE__*/_jsx("path", {
11
+ d: "M21.364 10.293a1 1 0 1 1 1.414 1.414l-6.364 6.363h4.657a1 1 0 0 1 0 2h-7.07a1 1 0 0 1-1-1V12a1 1 0 1 1 2 0v4.656zM10.071 4a1 1 0 0 1 1 1v7.07a1 1 0 0 1-2 0V7.414l-6.364 6.363a1 1 0 1 1-1.414-1.414L7.657 6H3a1 1 0 0 1 0-2z"
12
+ })
13
+ });
14
+ export default IncompatibleIcon;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ const FlameIcon = props => /*#__PURE__*/_jsx("svg", {
4
+ xmlns: "http://www.w3.org/2000/svg",
5
+ viewBox: "0 0 24 24",
6
+ "aria-hidden": "true",
7
+ width: "1rem",
8
+ height: "1rem",
9
+ ...props,
10
+ children: /*#__PURE__*/_jsx("path", {
11
+ d: "M13.71 6.6c-2.1-1.86-.96-5.85-.96-5.85s-6 3.75-4.905 11.985C6 12 6 9.75 6.75 8.25c-1.5 1.5-2.25 4.08-2.25 6.09 0 4.305 3.39 7.8 7.575 7.8s7.56-3.495 7.56-7.8-3.36-5.46-5.925-7.725zm-1.635 13.125c-1.5 0-2.865-.675-3.81-1.71 0 0 3.645-.12 4.71-4.455.57.435.93 1.755.555 2.895.915.09 2.94-2.595 1.335-6.495 1.2.735 2.535 2.19 2.535 4.41 0 2.97-2.445 5.355-5.325 5.355"
12
+ })
13
+ });
14
+ export default FlameIcon;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ const IncompatibleIcon = props => /*#__PURE__*/_jsx("svg", {
4
+ xmlns: "http://www.w3.org/2000/svg",
5
+ viewBox: "0 0 24 24",
6
+ "aria-hidden": "true",
7
+ width: "1rem",
8
+ height: "1rem",
9
+ ...props,
10
+ children: /*#__PURE__*/_jsx("path", {
11
+ d: "M21.364 10.292a1.001 1.001 0 0 1 1.415 1.415l-6.365 6.363h4.657a1 1 0 0 1 0 2.001H14a1 1 0 0 1-1.001-1V12a1 1 0 0 1 2 0v4.657zM10.071 3.999a1 1 0 0 1 1 1v7.071a1.001 1.001 0 0 1-2 0V7.414l-6.363 6.364a1.001 1.001 0 0 1-1.415-1.415L7.657 6H3.001a1 1 0 0 1 0-2.001z"
12
+ })
13
+ });
14
+ export default IncompatibleIcon;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "37.8.0",
3
+ "version": "37.9.1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "@radix-ui/react-slider": "1.1.2",
29
29
  "@react-google-maps/api": "^2.19.3",
30
30
  "@skyscanner/bpk-foundations-web": "^19.5.0",
31
- "@skyscanner/bpk-svgs": "^20.5.0",
31
+ "@skyscanner/bpk-svgs": "^20.6.0",
32
32
  "a11y-focus-scope": "^1.1.3",
33
33
  "a11y-focus-store": "^1.0.0",
34
34
  "d3-path": "^2.0.0",