@skyscanner/backpack-web 37.8.0 → 37.9.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.
Files changed (23) hide show
  1. package/bpk-component-card-list/src/BpkCardList.js +50 -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 +103 -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 +67 -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 +5 -0
  14. package/bpk-component-card-list/src/BpkCardListRowRail/utils.js +112 -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 +20 -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 +3 -3
@@ -15,17 +15,15 @@
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 => {
@@ -38,92 +36,66 @@ const BpkCardList = props => {
38
36
  chipGroup,
39
37
  description,
40
38
  expandText,
41
- initiallyShownCards = DEFAULT_ITEMS,
39
+ initiallyShownCardsDesktop = DEFAULT_ITEMS,
40
+ initiallyShownCardsMobile = DEFAULT_ITEMS,
42
41
  layoutDesktop,
43
42
  layoutMobile,
44
43
  onButtonClick,
45
44
  onExpandClick,
46
45
  title
47
46
  } = 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);
47
+ const shouldShowHeaderButton = isMobile => {
48
+ if (!buttonContent) return false;
49
+ if (isMobile) {
50
+ return accessoryMobile !== ACCESSORY_MOBILE_TYPES.button;
55
51
  }
56
- }, [isMobileActive, buttonContent, accessoryMobile, accessoryDesktop]);
52
+ return accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.button;
53
+ };
57
54
  const headerButton = buttonContent && /*#__PURE__*/_jsx(BpkButtonV2, {
58
55
  onClick: onButtonClick,
59
56
  href: buttonHref,
60
57
  "data-testid": "bpk-card-list-header-button",
61
58
  children: buttonContent
62
59
  });
63
- return /*#__PURE__*/_jsxs("div", {
60
+ return /*#__PURE__*/_jsx("div", {
64
61
  className: getClassName('bpk-card-list'),
65
62
  "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, {
63
+ children: /*#__PURE__*/_jsx(BpkBreakpoint, {
64
+ query: BREAKPOINTS.MOBILE,
65
+ children: isMobile => /*#__PURE__*/_jsxs(_Fragment, {
66
+ children: [/*#__PURE__*/_jsx(BpkSectionHeader, {
67
+ title: title,
68
+ description: description,
69
+ button: shouldShowHeaderButton(isMobile) ? 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: isMobile ? /*#__PURE__*/_jsxs(_Fragment, {
74
+ children: [layoutMobile === LAYOUTS.rail && /*#__PURE__*/_jsx(BpkCardListRowRailContainer, {
75
+ initiallyShownCards: initiallyShownCardsMobile,
76
+ layout: layoutMobile,
77
+ isMobile: true,
78
+ children: cardList
79
+ }), layoutMobile === LAYOUTS.stack && /*#__PURE__*/_jsx(BpkCardListGridStack, {
80
+ accessory: accessoryMobile,
81
+ initiallyShownCards: initiallyShownCardsMobile,
82
+ buttonContent: buttonContent,
83
+ expandText: expandText,
84
+ onButtonClick: onButtonClick,
85
+ onExpandClick: onExpandClick,
86
+ layout: layoutMobile,
87
+ buttonHref: buttonHref,
88
+ children: cardList
89
+ })]
90
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
91
+ children: [layoutDesktop === LAYOUTS.row && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.expand && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.button && /*#__PURE__*/_jsx(BpkCardListRowRailContainer, {
92
+ accessory: accessoryDesktop,
93
+ initiallyShownCards: initiallyShownCardsDesktop,
94
+ layout: layoutDesktop,
95
+ children: cardList
96
+ }), layoutDesktop === LAYOUTS.grid && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.pagination && /*#__PURE__*/_jsx(BpkCardListGridStack, {
125
97
  accessory: accessoryDesktop,
126
- initiallyShownCards: initiallyShownCards,
98
+ initiallyShownCards: initiallyShownCardsDesktop,
127
99
  buttonContent: buttonContent,
128
100
  expandText: expandText,
129
101
  onButtonClick: onButtonClick,
@@ -131,12 +103,11 @@ const BpkCardList = props => {
131
103
  layout: layoutDesktop,
132
104
  buttonHref: buttonHref,
133
105
  children: cardList
134
- });
135
- }
136
- return null;
137
- }
106
+ })]
107
+ })
108
+ })]
138
109
  })
139
- })]
110
+ })
140
111
  });
141
112
  };
142
113
  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,103 @@
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
+ children,
29
+ currentIndex,
30
+ initiallyShownCards,
31
+ isMobile = false,
32
+ layout,
33
+ setCurrentIndex
34
+ } = props;
35
+ const shownNumberStyle = {
36
+ '--initially-shown-cards': initiallyShownCards
37
+ };
38
+ const childrenLength = Children.count(children);
39
+ const [root, setRoot] = useState(null);
40
+ const cardRefs = useRef([]);
41
+ const [visibilityList, setVisibilityList] = useState(Array(childrenLength).fill(0));
42
+ const stateScrollingLockRef = useRef(false);
43
+ const openSetStateLockTimeoutRef = useRef(null);
44
+ const observerVisibility = useIntersectionObserver({
45
+ root,
46
+ threshold: 0.5
47
+ }, setVisibilityList);
48
+ useEffect(() => {
49
+ const container = root;
50
+ if (isMobile || !container) return undefined;
51
+ const lockScrollDuringInteraction = () => {
52
+ lockScroll(stateScrollingLockRef, openSetStateLockTimeoutRef);
53
+ };
54
+ container.addEventListener('wheel', lockScrollDuringInteraction);
55
+ container.addEventListener('touchmove', lockScrollDuringInteraction);
56
+ return () => {
57
+ container.removeEventListener('touchmove', lockScrollDuringInteraction);
58
+ container.removeEventListener('wheel', lockScrollDuringInteraction);
59
+ if (openSetStateLockTimeoutRef.current) {
60
+ clearTimeout(openSetStateLockTimeoutRef.current);
61
+ }
62
+ };
63
+ }, [root]);
64
+ useUpdateCurrentIndexByVisibility(isMobile, visibilityList, setCurrentIndex, stateScrollingLockRef, openSetStateLockTimeoutRef);
65
+ useScrollToCard(currentIndex, root, cardRefs, stateScrollingLockRef);
66
+ const firstVisibleIndex = Math.max(0, visibilityList.indexOf(1));
67
+ const lastVisibleIndex = firstVisibleIndex + initiallyShownCards - 1;
68
+ const renderList = visibilityList.map((_, index) => index >= firstVisibleIndex - RENDER_BUFFER_SIZE && index <= lastVisibleIndex + RENDER_BUFFER_SIZE ? 1 : 0);
69
+ const carouselAriaLabel = `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.`;
70
+ return /*#__PURE__*/_jsx("div", {
71
+ className: getClassName(`bpk-card-list-row-rail__${layout}`),
72
+ "data-testid": "bpk-card-list-row-rail__carousel",
73
+ "aria-label": carouselAriaLabel
74
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
75
+ ,
76
+ tabIndex: 0,
77
+ role: "region",
78
+ ref: setRoot,
79
+ children: children.map((card, index) => {
80
+ if (! /*#__PURE__*/isValidElement(card)) return null;
81
+ const cardRefCallback = el => {
82
+ cardRefs.current[index] = el;
83
+ observerVisibility(el, index);
84
+ setA11yTabIndex(el, index, visibilityList);
85
+ };
86
+ const slideAriaLabel = `slide ${index + 1} of ${childrenLength}`;
87
+ const cardStyle = isMobile ? {
88
+ ...shownNumberStyle,
89
+ visibility: renderList[index] === 1 ? 'visible' : 'hidden'
90
+ } : shownNumberStyle;
91
+ return /*#__PURE__*/_jsx("div", {
92
+ className: getClassName(`bpk-card-list-row-rail__${layout}__card`),
93
+ ref: cardRefCallback,
94
+ style: cardStyle,
95
+ role: "group",
96
+ "aria-label": slideAriaLabel,
97
+ "aria-current": index === currentIndex ? 'true' : 'false',
98
+ children: isMobile ? card : renderList[index] === 1 && card
99
+ }, `carousel-card-${index.toString()}`);
100
+ })
101
+ });
102
+ };
103
+ 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,67 @@
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
+ accessory,
29
+ children,
30
+ initiallyShownCards,
31
+ isMobile = false,
32
+ layout
33
+ } = props;
34
+ const totalIndicators = Children.count(children);
35
+ const [currentIndex, setCurrentIndex] = useState(0);
36
+ const showAccessory = totalIndicators > initiallyShownCards;
37
+ const accessoryContent = layout === LAYOUTS.row && accessory === ACCESSORY_DESKTOP_TYPES.pagination ? /*#__PURE__*/_jsx(BpkPageIndicator, {
38
+ currentIndex: currentIndex,
39
+ totalIndicators: totalIndicators,
40
+ onClick: (_e, index) => {
41
+ setCurrentIndex(index);
42
+ },
43
+ showNav: true,
44
+ indicatorLabel: "Go to slide",
45
+ prevNavLabel: "Previous slide",
46
+ nextNavLabel: "Next slide"
47
+ }) : null;
48
+ return /*#__PURE__*/_jsxs("div", {
49
+ className: getClassName('bpk-card-list-row-rail'),
50
+ "data-testid": "bpk-card-list-row-rail",
51
+ children: [/*#__PURE__*/_jsx(BpkCardListCarousel, {
52
+ initiallyShownCards: initiallyShownCards,
53
+ layout: layout,
54
+ currentIndex: currentIndex,
55
+ setCurrentIndex: setCurrentIndex,
56
+ isMobile: isMobile,
57
+ children: children
58
+ }), accessoryContent && showAccessory && /*#__PURE__*/_jsx("div", {
59
+ role: "region",
60
+ "aria-label": "pagination",
61
+ className: getClassName(`bpk-card-list-row-rail__accessory`),
62
+ "data-testid": "bpk-card-list-row-rail__accessory",
63
+ children: accessoryContent
64
+ })]
65
+ });
66
+ };
67
+ 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,5 @@
1
+ export declare const lockScroll: (stateScrollingLockRef: React.MutableRefObject<boolean>, openSetStateLockTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>) => void;
2
+ export declare const setA11yTabIndex: (el: HTMLDivElement | null, index: number, visibilityList: number[]) => void;
3
+ export declare const useUpdateCurrentIndexByVisibility: (isMobile: boolean, visibilityList: number[], setCurrentIndex: (index: number) => void, stateScrollingLockRef: React.MutableRefObject<boolean>, openSetStateLockTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>) => void;
4
+ export declare const useScrollToCard: (currentIndex: number, container: HTMLElement | null, cardRefs: React.MutableRefObject<Array<HTMLDivElement | null>>, stateScrollingLockRef: React.MutableRefObject<boolean>) => void;
5
+ export declare const useIntersectionObserver: ({ root, threshold }: IntersectionObserverInit, setVisibilityList: React.Dispatch<React.SetStateAction<number[]>>) => (element: HTMLElement | null, index: number) => void;
@@ -0,0 +1,112 @@
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
+ export const lockScroll = (stateScrollingLockRef, openSetStateLockTimeoutRef) => {
22
+ // eslint-disable-next-line no-param-reassign
23
+ stateScrollingLockRef.current = true;
24
+ if (openSetStateLockTimeoutRef.current) {
25
+ clearTimeout(openSetStateLockTimeoutRef.current);
26
+ }
27
+ // eslint-disable-next-line no-param-reassign
28
+ openSetStateLockTimeoutRef.current = setTimeout(() => {
29
+ // eslint-disable-next-line no-param-reassign
30
+ stateScrollingLockRef.current = false;
31
+ }, RELEASE_LOCK_DELAY);
32
+ };
33
+ export const setA11yTabIndex = (el, index, visibilityList) => {
34
+ if (!el) return;
35
+ const focusableElements = el.querySelectorAll('a, button, input, textarea, select, [tabindex]:not([tabindex="-1"])');
36
+ focusableElements.forEach(element => {
37
+ const targetElement = element;
38
+ targetElement.tabIndex = visibilityList[index] === 1 ? 0 : -1;
39
+ });
40
+ };
41
+ export const useUpdateCurrentIndexByVisibility = (isMobile, visibilityList, setCurrentIndex, stateScrollingLockRef, openSetStateLockTimeoutRef) => {
42
+ useEffect(() => {
43
+ if (isMobile) return;
44
+ if (!visibilityList || visibilityList.length === 0) return;
45
+ const firstVisibleIndex = visibilityList.findIndex(visibility => visibility === 1);
46
+ if (firstVisibleIndex !== -1) {
47
+ setCurrentIndex(firstVisibleIndex);
48
+ lockScroll(stateScrollingLockRef, openSetStateLockTimeoutRef);
49
+ }
50
+ }, [visibilityList]);
51
+ };
52
+ export const useScrollToCard = (currentIndex, container, cardRefs, stateScrollingLockRef) => {
53
+ useEffect(() => {
54
+ const isVisible = container && container.getBoundingClientRect().bottom > 0 && container.getBoundingClientRect().bottom <= window.innerHeight;
55
+ if (!isVisible) return; // Escape from scrollIntoView if the container is not visible
56
+
57
+ if (stateScrollingLockRef.current && stateScrollingLockRef.current === true) return;
58
+ const targetCard = cardRefs.current[currentIndex];
59
+ if (targetCard) {
60
+ targetCard.scrollIntoView({
61
+ behavior: 'smooth',
62
+ block: 'nearest',
63
+ inline: 'start'
64
+ });
65
+ }
66
+ }, [currentIndex]);
67
+ };
68
+ export const useIntersectionObserver = ({
69
+ root,
70
+ threshold
71
+ }, setVisibilityList) => {
72
+ const callbackRef = useRef(setVisibilityList);
73
+ useEffect(() => {
74
+ callbackRef.current = setVisibilityList;
75
+ });
76
+ const observeAll = useMemo(() => {
77
+ if (!root) return () => {};
78
+ const observer = new IntersectionObserver(entries => {
79
+ entries.forEach(entry => {
80
+ const {
81
+ index
82
+ } = entry.target.dataset;
83
+ if (!index) return;
84
+ const currentIndex = parseInt(index, 10);
85
+ if (entry.isIntersecting) {
86
+ setVisibilityList(prevList => {
87
+ const newList = [...prevList];
88
+ newList[currentIndex] = 1;
89
+ return newList;
90
+ });
91
+ } else {
92
+ setVisibilityList(prevList => {
93
+ const newList = [...prevList];
94
+ newList[currentIndex] = 0;
95
+ return newList;
96
+ });
97
+ }
98
+ });
99
+ }, {
100
+ root,
101
+ threshold
102
+ });
103
+ const observeElement = (element, index) => {
104
+ if (element && observer) {
105
+ element.setAttribute('data-index', index.toString());
106
+ observer.observe(element);
107
+ }
108
+ };
109
+ return observeElement;
110
+ }, [root, threshold]);
111
+ return observeAll;
112
+ };
@@ -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,7 @@ 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
23
  };
24
24
  type CardListBaseProps = {
25
25
  title: string;
@@ -29,7 +29,8 @@ type CardListBaseProps = {
29
29
  layoutDesktop: LayoutDesktop;
30
30
  accessoryDesktop?: (typeof ACCESSORY_DESKTOP_TYPES)[keyof typeof ACCESSORY_DESKTOP_TYPES];
31
31
  accessoryMobile?: (typeof ACCESSORY_MOBILE_TYPES)[keyof typeof ACCESSORY_MOBILE_TYPES];
32
- initiallyShownCards?: number;
32
+ initiallyShownCardsDesktop?: number;
33
+ initiallyShownCardsMobile?: number;
33
34
  chipGroup?: ReactElement;
34
35
  buttonContent?: React.ReactNode;
35
36
  onButtonClick?: () => void;
@@ -48,7 +49,22 @@ type CardListGridStackProps = {
48
49
  onExpandClick?: () => void;
49
50
  buttonHref?: string;
50
51
  };
52
+ type CardListRowRailProps = {
53
+ children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
54
+ initiallyShownCards: number;
55
+ layout: typeof LAYOUTS.row | typeof LAYOUTS.rail;
56
+ accessory?: typeof ACCESSORY_DESKTOP_TYPES.pagination;
57
+ isMobile?: boolean;
58
+ };
59
+ type CardListCarouselProps = {
60
+ children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
61
+ initiallyShownCards: number;
62
+ layout: typeof LAYOUTS.row | typeof LAYOUTS.rail;
63
+ currentIndex: number;
64
+ setCurrentIndex: Dispatch<SetStateAction<number>>;
65
+ isMobile?: boolean;
66
+ };
51
67
  type CardListProps = CardListBaseProps;
52
68
  export default CardListProps;
53
69
  export { LAYOUTS, ACCESSORY_DESKTOP_TYPES, ACCESSORY_MOBILE_TYPES };
54
- export type { LayoutDesktop, LayoutMobile, CardListGridStackProps, ExpandProps, };
70
+ 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.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,13 +22,13 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@floating-ui/react": "^0.26.12",
25
+ "@floating-ui/react": "^0.27.8",
26
26
  "@popperjs/core": "^2.11.8",
27
27
  "@radix-ui/react-compose-refs": "^1.1.1",
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",