@skyscanner/backpack-web 42.12.0 → 42.13.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 (26) hide show
  1. package/bpk-component-comparison-table/index.d.ts +4 -1
  2. package/bpk-component-comparison-table/index.js +3 -1
  3. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTable.d.ts +17 -0
  4. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTable.js +41 -0
  5. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTable.module.css +18 -0
  6. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableColumnHeader.d.ts +8 -0
  7. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableColumnHeader.js +66 -0
  8. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableColumnHeaderPlaceholder.d.ts +7 -0
  9. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableColumnHeaderPlaceholder.js +49 -0
  10. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableContent.d.ts +3 -0
  11. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableContent.js +94 -0
  12. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableHeader.d.ts +3 -0
  13. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableHeader.js +42 -0
  14. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableHeaderRow.d.ts +9 -0
  15. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableHeaderRow.js +52 -0
  16. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableRoot.d.ts +3 -0
  17. package/bpk-component-comparison-table/src/BpkComparisonTable/BpkComparisonTableRoot.js +38 -0
  18. package/bpk-component-comparison-table/src/BpkComparisonTable/common-types.d.ts +73 -0
  19. package/bpk-component-comparison-table/src/BpkComparisonTable/common-types.js +1 -0
  20. package/bpk-component-comparison-table/src/BpkComparisonTray/BpkComparisonTray.module.css +1 -1
  21. package/bpk-scrim-utils/src/bpk-scrim-content.module.css +1 -1
  22. package/bpk-scrim-utils/src/focusStore.js +3 -1
  23. package/bpk-scrim-utils/src/scroll-utils.d.ts +2 -0
  24. package/bpk-scrim-utils/src/scroll-utils.js +78 -8
  25. package/bpk-scrim-utils/src/withScrim.js +25 -28
  26. package/package.json +1 -1
@@ -1,3 +1,6 @@
1
+ import BpkComparisonTable from './src/BpkComparisonTable/BpkComparisonTable';
1
2
  import BpkComparisonTray from './src/BpkComparisonTray/BpkComparisonTray';
2
3
  export type { BpkComparisonItem, BpkComparisonTrayRootProps, BpkComparisonTrayItemProps, BpkComparisonTrayNamespace, } from './src/BpkComparisonTray/common-types';
3
- export default BpkComparisonTray;
4
+ export type { BpkCompareRow, BpkCompareColumn, BpkComparisonTableRootProps, BpkComparisonTableStrings, BpkComparisonTableNamespace, } from './src/BpkComparisonTable/common-types';
5
+ export { BpkComparisonTray };
6
+ export default BpkComparisonTable;
@@ -16,5 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ import BpkComparisonTable from "./src/BpkComparisonTable/BpkComparisonTable";
19
20
  import BpkComparisonTray from "./src/BpkComparisonTray/BpkComparisonTray";
20
- export default BpkComparisonTray;
21
+ export { BpkComparisonTray };
22
+ export default BpkComparisonTable;
@@ -0,0 +1,17 @@
1
+ import type { BpkComparisonTableNamespace } from './common-types';
2
+ /**
3
+ * BpkComparisonTable — side-by-side comparison modal.
4
+ *
5
+ * @example
6
+ * <BpkComparisonTable.Root isOpen={isOpen} onClose={() => setIsOpen(false)}>
7
+ * <BpkComparisonTable.Header title="Compare cars" strings={strings} />
8
+ * <BpkComparisonTable.Content
9
+ * columns={columns}
10
+ * onRemove={(itemId) => handleRemove(itemId)}
11
+ * onAddMoreClick={() => setIsOpen(false)}
12
+ * strings={strings}
13
+ * />
14
+ * </BpkComparisonTable.Root>
15
+ */
16
+ declare const BpkComparisonTable: BpkComparisonTableNamespace;
17
+ export default BpkComparisonTable;
@@ -0,0 +1,41 @@
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 BpkComparisonTableContent from "./BpkComparisonTableContent";
20
+ import BpkComparisonTableHeader from "./BpkComparisonTableHeader";
21
+ import BpkComparisonTableRoot from "./BpkComparisonTableRoot";
22
+ /**
23
+ * BpkComparisonTable — side-by-side comparison modal.
24
+ *
25
+ * @example
26
+ * <BpkComparisonTable.Root isOpen={isOpen} onClose={() => setIsOpen(false)}>
27
+ * <BpkComparisonTable.Header title="Compare cars" strings={strings} />
28
+ * <BpkComparisonTable.Content
29
+ * columns={columns}
30
+ * onRemove={(itemId) => handleRemove(itemId)}
31
+ * onAddMoreClick={() => setIsOpen(false)}
32
+ * strings={strings}
33
+ * />
34
+ * </BpkComparisonTable.Root>
35
+ */
36
+ const BpkComparisonTable = {
37
+ Root: BpkComparisonTableRoot,
38
+ Header: BpkComparisonTableHeader,
39
+ Content: BpkComparisonTableContent
40
+ };
41
+ export default BpkComparisonTable;
@@ -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-comparison-table__scroll-container{flex:1;overflow:auto;min-block-size:0;overscroll-behavior:contain}.bpk-comparison-table__scroll-container tbody{transform:translateY(var(--bpk-rows-offset, 0))}.bpk-comparison-table__scroll-container td:not(:last-child){border-inline-end:1px solid #c1c7cf}.bpk-comparison-table__scroll-container th:not(:last-child)::after{position:absolute;content:"";background-color:#c1c7cf;inline-size:1px;inset-block-end:0;inset-block-start:1rem;inset-inline-end:0}.bpk-comparison-table__scroll-container table{border-collapse:separate;border-spacing:0;min-inline-size:33.75rem}.bpk-comparison-table__scroll-container th{position:sticky;z-index:1;padding:0;background-color:#fff;vertical-align:top;inset-block-start:0}.bpk-comparison-table__header-content{display:flex;padding:1rem;flex-direction:column}.bpk-comparison-table__header-image-wrapper{position:relative;opacity:var(--bpk-image-opacity, 1);margin-block-end:1rem}.bpk-comparison-table__header-image-area{display:flex;justify-content:center;align-items:center;border-radius:.25rem;background-color:#e0e4e9;overflow:hidden;block-size:5.1875rem}.bpk-comparison-table__header-image-area img{max-block-size:100%;max-inline-size:100%;object-fit:contain}.bpk-comparison-table__header-id-section{margin-block-start:calc(6.1875rem*(var(--bpk-image-opacity, 1) - 1))}.bpk-comparison-table__best-tag{position:absolute;z-index:1;transform:translateY(-50%);inset-block-start:0}.bpk-comparison-table__remove-button{opacity:var(--bpk-image-opacity, 1);overflow:clip;margin-block-start:calc(.5rem*var(--bpk-image-opacity, 1));max-block-size:calc(5rem*var(--bpk-image-opacity, 1));overflow-clip-margin:.25rem}.bpk-comparison-table__placeholder-cell{background-color:#fff}
@@ -0,0 +1,8 @@
1
+ import type { BpkCompareColumn } from './common-types';
2
+ type BpkComparisonTableColumnHeaderProps = Pick<BpkCompareColumn, 'imageSrc' | 'imageAlt' | 'headerContent' | 'itemId' | 'bestTag' | 'removeA11yLabel'> & {
3
+ removeLabel: string;
4
+ bestTagLabel: string;
5
+ onRemove: (itemId: string) => void;
6
+ };
7
+ declare const BpkComparisonTableColumnHeader: ({ bestTag, bestTagLabel, headerContent, imageAlt, imageSrc, itemId, onRemove, removeA11yLabel, removeLabel, }: BpkComparisonTableColumnHeaderProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default BpkComparisonTableColumnHeader;
@@ -0,0 +1,66 @@
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 BpkBadge, { BADGE_TYPES } from "../../../bpk-component-badge";
20
+ import BpkButton, { BUTTON_TYPES, SIZE_TYPES } from "../../../bpk-component-button";
21
+ import { cssModules } from "../../../bpk-react-utils";
22
+ import STYLES from "./BpkComparisonTable.module.css";
23
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
+ const getClassName = cssModules(STYLES);
25
+ const BpkComparisonTableColumnHeader = ({
26
+ bestTag = false,
27
+ bestTagLabel,
28
+ headerContent,
29
+ imageAlt = '',
30
+ imageSrc,
31
+ itemId,
32
+ onRemove,
33
+ removeA11yLabel,
34
+ removeLabel
35
+ }) => /*#__PURE__*/_jsxs("div", {
36
+ className: getClassName('bpk-comparison-table__header-content'),
37
+ children: [/*#__PURE__*/_jsxs("div", {
38
+ className: getClassName('bpk-comparison-table__header-image-wrapper'),
39
+ children: [/*#__PURE__*/_jsx("div", {
40
+ className: getClassName('bpk-comparison-table__header-image-area'),
41
+ children: imageSrc && /*#__PURE__*/_jsx("img", {
42
+ src: imageSrc,
43
+ alt: imageAlt
44
+ })
45
+ }), bestTag && /*#__PURE__*/_jsx("span", {
46
+ className: getClassName('bpk-comparison-table__best-tag'),
47
+ children: /*#__PURE__*/_jsx(BpkBadge, {
48
+ type: BADGE_TYPES.brand,
49
+ children: bestTagLabel
50
+ })
51
+ })]
52
+ }), /*#__PURE__*/_jsx("div", {
53
+ className: getClassName('bpk-comparison-table__header-id-section'),
54
+ children: headerContent
55
+ }), /*#__PURE__*/_jsx("div", {
56
+ className: getClassName('bpk-comparison-table__remove-button'),
57
+ children: /*#__PURE__*/_jsx(BpkButton, {
58
+ type: BUTTON_TYPES.link,
59
+ size: SIZE_TYPES.small,
60
+ onClick: () => onRemove(itemId),
61
+ "aria-label": removeA11yLabel,
62
+ children: removeLabel
63
+ })
64
+ })]
65
+ });
66
+ export default BpkComparisonTableColumnHeader;
@@ -0,0 +1,7 @@
1
+ type BpkComparisonTableColumnHeaderPlaceholderProps = {
2
+ addMoreDescription: string;
3
+ addMoreLinkText: string;
4
+ onAddMoreClick: () => void;
5
+ };
6
+ declare const BpkComparisonTableColumnHeaderPlaceholder: ({ addMoreDescription, addMoreLinkText, onAddMoreClick, }: BpkComparisonTableColumnHeaderPlaceholderProps) => import("react/jsx-runtime").JSX.Element;
7
+ export default BpkComparisonTableColumnHeaderPlaceholder;
@@ -0,0 +1,49 @@
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 BpkButton, { BUTTON_TYPES, SIZE_TYPES } from "../../../bpk-component-button";
20
+ import { BpkFlex, BpkSpacing } from "../../../bpk-component-layout";
21
+ import BpkText, { TEXT_COLORS, TEXT_STYLES } from "../../../bpk-component-text";
22
+ import { cssModules } from "../../../bpk-react-utils";
23
+ import STYLES from "./BpkComparisonTable.module.css";
24
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
25
+ const getClassName = cssModules(STYLES);
26
+ const BpkComparisonTableColumnHeaderPlaceholder = ({
27
+ addMoreDescription,
28
+ addMoreLinkText,
29
+ onAddMoreClick
30
+ }) => /*#__PURE__*/_jsxs(BpkFlex, {
31
+ direction: "column",
32
+ align: "center",
33
+ gap: BpkSpacing.MD,
34
+ paddingTop: BpkSpacing.LG,
35
+ paddingInline: BpkSpacing.XL,
36
+ children: [/*#__PURE__*/_jsx(BpkText, {
37
+ textAlign: "center",
38
+ tagName: "p",
39
+ textStyle: TEXT_STYLES.bodyDefault,
40
+ color: TEXT_COLORS.textSecondary,
41
+ children: addMoreDescription
42
+ }), /*#__PURE__*/_jsx(BpkButton, {
43
+ type: BUTTON_TYPES.link,
44
+ size: SIZE_TYPES.small,
45
+ onClick: onAddMoreClick,
46
+ children: addMoreLinkText
47
+ })]
48
+ });
49
+ export default BpkComparisonTableColumnHeaderPlaceholder;
@@ -0,0 +1,3 @@
1
+ import type { BpkComparisonTableContentProps } from './common-types';
2
+ declare const BpkComparisonTableContent: ({ columns, onAddMoreClick, onRemove, strings, }: BpkComparisonTableContentProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default BpkComparisonTableContent;
@@ -0,0 +1,94 @@
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 { useEffect, useRef } from 'react';
20
+ import { BpkTable, BpkTableBody, BpkTableCell, BpkTableRow, TABLE_BODY_TYPES } from "../../../bpk-component-table";
21
+ import { cssModules } from "../../../bpk-react-utils";
22
+ import BpkComparisonTableHeaderRow from "./BpkComparisonTableHeaderRow";
23
+ import STYLES from "./BpkComparisonTable.module.css";
24
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
25
+ const getClassName = cssModules(STYLES);
26
+ const MAX_COLUMNS = 3;
27
+
28
+ // Matches the image area height (5.1875rem × 16px). Opacity goes from 1 → 0 as the user scrolls 0 → 83 px, giving a smooth parallax fade.
29
+ const IMAGE_FADE_THRESHOLD_PX = 83;
30
+ const BpkComparisonTableContent = ({
31
+ columns,
32
+ onAddMoreClick,
33
+ onRemove,
34
+ strings
35
+ }) => {
36
+ const scrollContainerRef = useRef(null);
37
+
38
+ // Pad with nulls so the table always renders exactly MAX_COLUMNS slots.
39
+ const displayColumns = [...columns, null, null, null].slice(0, MAX_COLUMNS);
40
+ const rowIds = columns[0]?.rows.map(row => row.rowId) ?? [];
41
+
42
+ // Dev-mode guard: warn if not all columns share the same rowId sequence.
43
+ if (process.env.NODE_ENV !== 'production' && columns.length > 1) {
44
+ const rowIdsByColumn = columns.map(column => column.rows.map(row => row.rowId).join(','));
45
+ const allMatch = rowIdsByColumn.every(ids => ids === rowIdsByColumn[0]);
46
+ if (!allMatch) {
47
+ // eslint-disable-next-line no-console
48
+ console.warn('[BpkComparisonTable] Not all columns share the same rowId sequence. Rows may misalign.');
49
+ }
50
+ }
51
+
52
+ // Pre-index cells by itemId → rowId for O(1) lookup during render.
53
+ const cellsByItemAndRow = new Map(columns.map(column => [column.itemId, new Map(column.rows.map(row => [row.rowId, row.cell]))]));
54
+ useEffect(() => {
55
+ const container = scrollContainerRef.current;
56
+ if (!container) return undefined;
57
+ const handleScroll = () => {
58
+ const {
59
+ scrollTop
60
+ } = container;
61
+ // During the animation phase, push tbody down by the scroll amount so rows appear locked in place.
62
+ // Once the fade-out completes the offset is fixed at the threshold and normal scrolling resumes.
63
+ container.style.setProperty('--bpk-rows-offset', `${Math.min(scrollTop, IMAGE_FADE_THRESHOLD_PX)}px`);
64
+ container.style.setProperty('--bpk-image-opacity', `${1 - Math.min(scrollTop / IMAGE_FADE_THRESHOLD_PX, 1)}`);
65
+ };
66
+ container.addEventListener('scroll', handleScroll, {
67
+ passive: true
68
+ });
69
+ return () => container.removeEventListener('scroll', handleScroll);
70
+ }, []);
71
+ return /*#__PURE__*/_jsx("div", {
72
+ ref: scrollContainerRef,
73
+ className: getClassName('bpk-comparison-table__scroll-container'),
74
+ children: /*#__PURE__*/_jsxs(BpkTable, {
75
+ children: [/*#__PURE__*/_jsx(BpkComparisonTableHeaderRow, {
76
+ displayColumns: displayColumns,
77
+ onRemove: onRemove,
78
+ onAddMoreClick: onAddMoreClick,
79
+ strings: strings
80
+ }), /*#__PURE__*/_jsx(BpkTableBody, {
81
+ type: TABLE_BODY_TYPES.striped,
82
+ children: rowIds.map(rowId => /*#__PURE__*/_jsx(BpkTableRow, {
83
+ children: displayColumns.map((column, index) => /*#__PURE__*/_jsx(BpkTableCell, {
84
+ // Placeholder need a distinct background colour not available via BpkTableCell props
85
+ // eslint-disable-next-line @skyscanner/rules/forbid-component-props
86
+ className: column ? undefined : getClassName('bpk-comparison-table__placeholder-cell'),
87
+ children: column ? cellsByItemAndRow.get(column.itemId)?.get(rowId) ?? null : null
88
+ }, column ? `${rowId}-${column.itemId}` : `${rowId}-placeholder-${index}`))
89
+ }, rowId))
90
+ })]
91
+ })
92
+ });
93
+ };
94
+ export default BpkComparisonTableContent;
@@ -0,0 +1,3 @@
1
+ import type { BpkComparisonTableHeaderProps } from './common-types';
2
+ declare const BpkComparisonTableHeader: ({ children, strings, title }: BpkComparisonTableHeaderProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default BpkComparisonTableHeader;
@@ -0,0 +1,42 @@
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 { BpkBox, BpkSpacing } from "../../../bpk-component-layout";
20
+ import { BpkModalV3 } from "../../../bpk-component-modal";
21
+ import BpkVisuallyHidden from "../../../bpk-component-visually-hidden";
22
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
23
+ const BpkComparisonTableHeader = ({
24
+ children,
25
+ strings,
26
+ title
27
+ }) => /*#__PURE__*/_jsxs(_Fragment, {
28
+ children: [/*#__PURE__*/_jsxs(BpkModalV3.Header, {
29
+ children: [/*#__PURE__*/_jsx(BpkModalV3.Title, {
30
+ children: title ?? /*#__PURE__*/_jsx(BpkVisuallyHidden, {
31
+ children: strings.accessibleLabel
32
+ })
33
+ }), /*#__PURE__*/_jsx(BpkModalV3.CloseTrigger, {
34
+ label: strings.closeLabel
35
+ })]
36
+ }), children && /*#__PURE__*/_jsx(BpkBox, {
37
+ paddingBottom: BpkSpacing.MD,
38
+ paddingInline: BpkSpacing.Base,
39
+ children: children
40
+ })]
41
+ });
42
+ export default BpkComparisonTableHeader;
@@ -0,0 +1,9 @@
1
+ import type { BpkComparisonTableStrings, BpkCompareColumn } from './common-types';
2
+ type BpkComparisonTableHeaderRowProps = {
3
+ displayColumns: Array<BpkCompareColumn | null>;
4
+ onRemove: (itemId: string) => void;
5
+ onAddMoreClick: () => void;
6
+ strings: BpkComparisonTableStrings;
7
+ };
8
+ declare const BpkComparisonTableHeaderRow: ({ displayColumns, onAddMoreClick, onRemove, strings, }: BpkComparisonTableHeaderRowProps) => import("react/jsx-runtime").JSX.Element;
9
+ export default BpkComparisonTableHeaderRow;
@@ -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
+ import { BpkTableHead, BpkTableHeadCell, BpkTableRow } from "../../../bpk-component-table";
20
+ import BpkComparisonTableColumnHeader from "./BpkComparisonTableColumnHeader";
21
+ import BpkComparisonTableColumnHeaderPlaceholder from "./BpkComparisonTableColumnHeaderPlaceholder";
22
+ import { jsx as _jsx } from "react/jsx-runtime";
23
+ const BpkComparisonTableHeaderRow = ({
24
+ displayColumns,
25
+ onAddMoreClick,
26
+ onRemove,
27
+ strings
28
+ }) => {
29
+ const {
30
+ addMoreDescription,
31
+ addMoreLinkText,
32
+ bestTagLabel,
33
+ removeLabel
34
+ } = strings;
35
+ return /*#__PURE__*/_jsx(BpkTableHead, {
36
+ children: /*#__PURE__*/_jsx(BpkTableRow, {
37
+ children: displayColumns.map((column, index) => /*#__PURE__*/_jsx(BpkTableHeadCell, {
38
+ children: column ? /*#__PURE__*/_jsx(BpkComparisonTableColumnHeader, {
39
+ ...column,
40
+ removeLabel: removeLabel,
41
+ onRemove: onRemove,
42
+ bestTagLabel: bestTagLabel
43
+ }) : /*#__PURE__*/_jsx(BpkComparisonTableColumnHeaderPlaceholder, {
44
+ addMoreDescription: addMoreDescription,
45
+ addMoreLinkText: addMoreLinkText,
46
+ onAddMoreClick: onAddMoreClick
47
+ })
48
+ }, column ? column.itemId : `placeholder-${index}`))
49
+ })
50
+ });
51
+ };
52
+ export default BpkComparisonTableHeaderRow;
@@ -0,0 +1,3 @@
1
+ import type { BpkComparisonTableRootProps } from './common-types';
2
+ declare const BpkComparisonTableRoot: ({ children, isOpen, onClose }: BpkComparisonTableRootProps) => import("react/jsx-runtime").JSX.Element;
3
+ export default BpkComparisonTableRoot;
@@ -0,0 +1,38 @@
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 { BpkModalV3 } from "../../../bpk-component-modal";
20
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
21
+ const BpkComparisonTableRoot = ({
22
+ children,
23
+ isOpen,
24
+ onClose
25
+ }) => /*#__PURE__*/_jsx(BpkModalV3.Root, {
26
+ open: isOpen,
27
+ onOpenChange: details => {
28
+ if (!details.open) {
29
+ onClose();
30
+ }
31
+ },
32
+ children: /*#__PURE__*/_jsxs(BpkModalV3.Portal, {
33
+ children: [/*#__PURE__*/_jsx(BpkModalV3.Scrim, {}), /*#__PURE__*/_jsx(BpkModalV3.Content, {
34
+ children: children
35
+ })]
36
+ })
37
+ });
38
+ export default BpkComparisonTableRoot;
@@ -0,0 +1,73 @@
1
+ import type { ReactNode } from 'react';
2
+ /** A single row entry within a comparison column. */
3
+ export type BpkCompareRow = {
4
+ /** Stable unique identifier used to align rows across columns. */
5
+ rowId: string;
6
+ /** Cell content — consumer-controlled ReactNode. */
7
+ cell: ReactNode;
8
+ };
9
+ /** Data for one filled comparison column. */
10
+ export type BpkCompareColumn = {
11
+ /** Stable unique identifier used for removal callbacks. */
12
+ itemId: string;
13
+ /** When true, renders a BpkBadge type=brand overlaying the top-left of the image area. */
14
+ bestTag?: boolean;
15
+ /** Image src for the header image area. */
16
+ imageSrc?: string;
17
+ /** Alt text for the header image. */
18
+ imageAlt?: string;
19
+ /** Consumer-owned slot rendered below the image area (name, description, price, CTA...). */
20
+ headerContent: ReactNode;
21
+ /** Row data — must match rowId sequences across all columns. */
22
+ rows: BpkCompareRow[];
23
+ /** Accessible label for the Remove button (e.g. "Remove rentalcars.com deal"). */
24
+ removeA11yLabel: string;
25
+ };
26
+ /** All strings required by BpkComparisonTable. */
27
+ export type BpkComparisonTableStrings = {
28
+ /** Accessible dialog name, used via BpkVisuallyHidden when no visible title is provided. */
29
+ accessibleLabel: string;
30
+ /** Accessible label for the modal close button. */
31
+ closeLabel: string;
32
+ /** Visible label for the Remove button in each column header. */
33
+ removeLabel: string;
34
+ /** Text inside the BpkBadge when bestTag=true (e.g. "Best"). */
35
+ bestTagLabel: string;
36
+ /** Description text inside the placeholder column. */
37
+ addMoreDescription: string;
38
+ /** Link text inside the placeholder column. */
39
+ addMoreLinkText: string;
40
+ };
41
+ /** Props for BpkComparisonTable.Root — modal shell only. */
42
+ export type BpkComparisonTableRootProps = {
43
+ /** Controls whether the modal is open. */
44
+ isOpen: boolean;
45
+ /** Called when the modal close trigger is activated or Escape is pressed. */
46
+ onClose: () => void;
47
+ /** BpkComparisonTable.Header and BpkComparisonTable.Content. */
48
+ children: ReactNode;
49
+ };
50
+ /** Props for BpkComparisonTable.Header — modal header + optional AiBlurb slot. */
51
+ export type BpkComparisonTableHeaderProps = {
52
+ /** Optional modal title rendered via BpkModalV3.Title. */
53
+ title?: string;
54
+ strings: BpkComparisonTableStrings;
55
+ /** Optional slot for AI blurb or any content below the title/close row. */
56
+ children?: ReactNode;
57
+ };
58
+ /** Props for BpkComparisonTable.Content — modal body with the comparison table. */
59
+ export type BpkComparisonTableContentProps = {
60
+ /** 1–3 filled columns. Component pads to 3 with placeholder cells automatically. */
61
+ columns: BpkCompareColumn[];
62
+ /** Called when a Remove button is clicked, with the column's itemId. */
63
+ onRemove: (itemId: string) => void;
64
+ /** Called when the Add more link in a placeholder column is clicked. */
65
+ onAddMoreClick: () => void;
66
+ strings: BpkComparisonTableStrings;
67
+ };
68
+ /** Namespace type covering all BpkComparisonTable subcomponents. */
69
+ export type BpkComparisonTableNamespace = {
70
+ Root: (props: BpkComparisonTableRootProps) => ReactNode;
71
+ Header: (props: BpkComparisonTableHeaderProps) => ReactNode;
72
+ Content: (props: BpkComparisonTableContentProps) => ReactNode;
73
+ };
@@ -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-comparison-tray{width:22.1875rem;max-width:100%}@media(max-width: 32rem){.bpk-comparison-tray{width:auto;min-width:0;flex:1}}.bpk-comparison-tray__item{position:relative;width:3.875rem;height:1.75rem;flex-shrink:0}.bpk-comparison-tray__item-image-container{width:100%;height:100%;background-color:#eff3f8;overflow:hidden;border-radius:.25rem}.bpk-comparison-tray__item-image-container img{object-fit:cover}.bpk-comparison-tray__item-close{position:relative;position:absolute;top:0;right:0;display:flex;width:1rem;height:1rem;justify-content:center;align-items:center;transform:translate(50%, -50%);border:.125rem solid #fff;border-radius:50%;background-color:#161616;color:#fff;cursor:pointer;box-shadow:0px 4px 14px 0px rgba(37,32,31,.25)}.bpk-comparison-tray__item-close::before{position:absolute;top:calc(-2.75rem/2 + 50%);left:calc(-2.75rem/2 + 50%);content:"";width:2.75rem;height:2.75rem}.bpk-comparison-tray__item-close svg{width:.5rem;height:.5rem;flex-shrink:0;fill:#fff}.bpk-comparison-tray__item-close:focus-visible{outline:.125rem solid #0062e3;outline-offset:.125rem}.bpk-comparison-tray__item-placeholder{width:3.875rem;height:1.75rem;flex-shrink:0;border:.0625rem dashed #c1c7cf;border-radius:.25rem}
18
+ .bpk-comparison-tray{width:22.1875rem;max-width:100%}@media(max-width: 32rem){.bpk-comparison-tray{width:auto;min-width:0;flex:1}}.bpk-comparison-tray__item{position:relative;width:3.875rem;height:1.75rem;flex-shrink:0}.bpk-comparison-tray__item-image-container{width:100%;height:100%;background-color:#eff3f8;overflow:hidden;border-radius:.25rem}.bpk-comparison-tray__item-image-container img{object-fit:cover}.bpk-comparison-tray__item-close{position:relative;position:absolute;top:0;inset-inline-end:calc(-8*0.0625rem);display:flex;width:1rem;height:1rem;justify-content:center;align-items:center;transform:translateY(-50%);border:.125rem solid #fff;border-radius:50%;background-color:#161616;color:#fff;cursor:pointer;box-shadow:0px 4px 14px 0px rgba(37,32,31,.25)}.bpk-comparison-tray__item-close::before{position:absolute;top:calc(-2.75rem/2 + 50%);left:calc(-2.75rem/2 + 50%);content:"";width:2.75rem;height:2.75rem}.bpk-comparison-tray__item-close svg{width:.5rem;height:.5rem;flex-shrink:0;fill:#fff}.bpk-comparison-tray__item-close:focus-visible{outline:.125rem solid #0062e3;outline-offset:.125rem}.bpk-comparison-tray__item-placeholder{width:3.875rem;height:1.75rem;flex-shrink:0;border:.0625rem dashed #c1c7cf;border-radius:.25rem}
@@ -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-scrim-content{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1000;overflow:auto;overflow-x:hidden;overflow-y:auto;-webkit-overflow-scrolling:touch}
18
+ .bpk-scrim-content{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1000;overflow:auto;overflow-x:hidden;overflow-y:auto;-webkit-overflow-scrolling:touch;touch-action:pan-y}
@@ -64,7 +64,9 @@ const focusStore = {
64
64
  return;
65
65
  }
66
66
  try {
67
- storedFocusElement.focus();
67
+ storedFocusElement.focus({
68
+ preventScroll: true
69
+ });
68
70
  } catch {
69
71
  // Element may have been detached from the DOM
70
72
  }
@@ -4,3 +4,5 @@ export declare const fixBody: () => void;
4
4
  export declare const unfixBody: () => void;
5
5
  export declare const lockScroll: () => void;
6
6
  export declare const unlockScroll: () => void;
7
+ export declare const lockTouchAction: () => void;
8
+ export declare const unlockTouchAction: () => void;
@@ -16,7 +16,19 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
+ // Module-level state is intentional: the <body> element is a global singleton,
20
+ // so nested scrims must coordinate through a shared counter. Each lock/unlock
21
+ // pair maintains its own depth counter so the "save original value, apply
22
+ // locked value" logic only runs on the 0↔1 transition. Inner nested calls are
23
+ // no-ops that simply bump the counter. This prevents the inner scrim from
24
+ // overwriting the outer scrim's saved "pre-lock" value — see the Nested story
25
+ // in BpkModal.stories.tsx.
19
26
  let scrollOffset = 0;
27
+ let savedTouchAction = '';
28
+ let savedOverscrollBehavior = '';
29
+ let fixBodyDepth = 0;
30
+ let lockScrollDepth = 0;
31
+ let lockTouchActionDepth = 0;
20
32
  const getWindow = () => typeof window !== 'undefined' ? window : null;
21
33
  const getBodyElement = () => typeof document !== 'undefined' && typeof document.body !== 'undefined' ? document.body : null;
22
34
  const getScrollBarWidth = () => {
@@ -41,6 +53,12 @@ const getScrollBarWidth = () => {
41
53
  return scrollBarWidth === 0 ? '' : `${scrollBarWidth}px`;
42
54
  };
43
55
  export const storeScroll = () => {
56
+ // Skip while an outer scrim already fixed the body: pageYOffset reads 0 once
57
+ // the body is position:fixed, so capturing it would clobber the outer
58
+ // scroll position and cause restoreScroll to jump back to the top on close.
59
+ if (fixBodyDepth > 0) {
60
+ return;
61
+ }
44
62
  const window = getWindow();
45
63
  if (window) {
46
64
  scrollOffset = window.pageYOffset;
@@ -57,29 +75,81 @@ export const fixBody = () => {
57
75
  if (!body) {
58
76
  return;
59
77
  }
60
- body.style.position = 'fixed';
78
+ if (fixBodyDepth === 0) {
79
+ // Set top before position:fixed so the browser doesn't jump to scrollY=0.
80
+ // scrollOffset is captured by storeScroll() immediately before this call.
81
+ body.style.top = `-${scrollOffset}px`;
82
+ body.style.width = '100%';
83
+ body.style.position = 'fixed';
84
+ }
85
+ fixBodyDepth += 1;
61
86
  };
62
87
  export const unfixBody = () => {
63
88
  const body = getBodyElement();
64
- if (!body) {
89
+ if (!body || fixBodyDepth === 0) {
65
90
  return;
66
91
  }
67
- body.style.position = '';
92
+ fixBodyDepth -= 1;
93
+ if (fixBodyDepth === 0) {
94
+ body.style.position = '';
95
+ body.style.top = '';
96
+ body.style.width = '';
97
+ }
68
98
  };
99
+
100
+ // Locks background scroll on the body. Safe to call on all platforms.
101
+ // None of these block user touch gestures.
69
102
  export const lockScroll = () => {
70
103
  const body = getBodyElement();
71
104
  if (!body) {
72
105
  return;
73
106
  }
74
- const paddingRight = getScrollBarWidth();
75
- body.style.overflow = 'hidden';
76
- body.style.paddingRight = paddingRight;
107
+ if (lockScrollDepth === 0) {
108
+ savedOverscrollBehavior = body.style.overscrollBehavior;
109
+ body.style.overflow = 'hidden';
110
+ body.style.paddingRight = getScrollBarWidth();
111
+ body.style.overscrollBehavior = 'contain';
112
+ }
113
+ lockScrollDepth += 1;
77
114
  };
78
115
  export const unlockScroll = () => {
116
+ const body = getBodyElement();
117
+ if (!body || lockScrollDepth === 0) {
118
+ return;
119
+ }
120
+ lockScrollDepth -= 1;
121
+ if (lockScrollDepth === 0) {
122
+ body.style.overflow = '';
123
+ body.style.paddingRight = '';
124
+ body.style.overscrollBehavior = savedOverscrollBehavior;
125
+ }
126
+ };
127
+
128
+ // Blocks touch gestures on the body via `touch-action: none`. iOS-only.
129
+ //
130
+ // On iOS Safari, `overflow: hidden` alone does not stop touch-scroll or
131
+ // rubber-band overscroll on the body — `touch-action: none` is needed. Do NOT
132
+ // call this on non-iOS platforms: `touch-action` combines with descendants'
133
+ // effective touch-action, so setting `none` on body blocks touch scrolling in
134
+ // any modal content that doesn't explicitly declare its own `touch-action`.
135
+ export const lockTouchAction = () => {
79
136
  const body = getBodyElement();
80
137
  if (!body) {
81
138
  return;
82
139
  }
83
- body.style.overflow = '';
84
- body.style.paddingRight = '';
140
+ if (lockTouchActionDepth === 0) {
141
+ savedTouchAction = body.style.touchAction;
142
+ body.style.touchAction = 'none';
143
+ }
144
+ lockTouchActionDepth += 1;
145
+ };
146
+ export const unlockTouchAction = () => {
147
+ const body = getBodyElement();
148
+ if (!body || lockTouchActionDepth === 0) {
149
+ return;
150
+ }
151
+ lockTouchActionDepth -= 1;
152
+ if (lockTouchActionDepth === 0) {
153
+ body.style.touchAction = savedTouchAction;
154
+ }
85
155
  };
@@ -21,7 +21,7 @@ import { cssModules, isDeviceIpad, isDeviceIphone, wrapDisplayName } from "../..
21
21
  import BpkScrim from "./BpkScrim";
22
22
  import focusScope from "./focusScope";
23
23
  import focusStore from "./focusStore";
24
- import { fixBody, lockScroll, restoreScroll, storeScroll, unfixBody, unlockScroll } from "./scroll-utils";
24
+ import { fixBody, lockScroll, lockTouchAction, restoreScroll, storeScroll, unfixBody, unlockScroll, unlockTouchAction } from "./scroll-utils";
25
25
  import STYLES from "./bpk-scrim-content.module.css";
26
26
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
27
27
  const getClassName = cssModules(STYLES);
@@ -41,33 +41,27 @@ const withScrim = WrappedComponent => {
41
41
  isIphone
42
42
  } = this.props;
43
43
  const applicationElement = getApplicationElement();
44
- requestAnimationFrame(() => {
45
- /**
46
- * iPhones & iPads need to have a fixed body
47
- * and scrolling stored to prevent some iOS specific issues occuring
48
- *
49
- * Issue description:
50
- * iOS safari does not prevent scrolling on the underlying content.
51
- * Without the below fixes this results in users being able to scroll below any modal or dialog that uses withScrim.
52
- *
53
- * The fixes can be summaried here: https://markus.oberlehner.net/blog/simple-solution-to-prevent-body-scrolling-on-ios/
54
- *
55
- * The most dangerous of the fixes below is the fixBody, this function applies changes to the <body> style.
56
- * This has the potential to override any custom styles already applied. The assumption here is that no one internally is making these changes to body.
57
- *
58
- * There is a corresponding set of functions in the componentWillUnmount block that deals with undoing these changes.
59
- */
60
- if (isIphone || isIpad) {
61
- storeScroll();
62
- fixBody();
63
- }
64
- /**
65
- * lockScroll and the associated unlockScroll is how we control the scroll behaviour of the application when the scrim is active.
66
- * The desired behaviour is to prevent the user from scrolling content behind the scrim. The above iOS fixes are in place because lockScroll alone does not solve due to iOS specific issues.
67
- */
68
44
 
69
- lockScroll();
70
- });
45
+ /**
46
+ * iPhones & iPads need to have a fixed body and scrolling stored to prevent some iOS
47
+ * specific issues occurring. iOS Safari does not prevent scrolling on the underlying
48
+ * content — without these fixes users can scroll below a modal or dialog that uses
49
+ * withScrim. See: https://markus.oberlehner.net/blog/simple-solution-to-prevent-body-scrolling-on-ios/
50
+ *
51
+ * The most dangerous of the fixes below is fixBody — it applies changes to the <body>
52
+ * style and has the potential to override any custom styles already applied. The
53
+ * assumption here is that no one internally is making these changes to body.
54
+ *
55
+ * These must run synchronously (not inside requestAnimationFrame) so the body is
56
+ * locked before the first paint, otherwise a visible scroll-jump occurs on open.
57
+ * componentWillUnmount has a corresponding set of calls that undo these changes.
58
+ */
59
+ if (isIphone || isIpad) {
60
+ storeScroll();
61
+ fixBody();
62
+ lockTouchAction();
63
+ }
64
+ lockScroll();
71
65
  if (applicationElement) {
72
66
  applicationElement.setAttribute('aria-hidden', 'true');
73
67
  }
@@ -84,8 +78,11 @@ const withScrim = WrappedComponent => {
84
78
  } = this.props;
85
79
  const applicationElement = getApplicationElement();
86
80
  if (isIphone || isIpad) {
87
- setTimeout(restoreScroll, 0);
81
+ // unfixBody before restoreScroll: restoring scroll while body is still fixed
82
+ // prevents a second visual jump on close.
88
83
  unfixBody();
84
+ restoreScroll();
85
+ unlockTouchAction();
89
86
  }
90
87
  unlockScroll();
91
88
  if (applicationElement) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "42.12.0",
3
+ "version": "42.13.1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",