@skyscanner/backpack-web 9.3.0 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bpk-animate-height/package.json +3 -3
- package/bpk-component-accordion/package.json +8 -8
- package/bpk-component-accordion/src/BpkAccordion.module.scss +1 -1
- package/bpk-component-accordion/src/BpkAccordionItem.module.scss +1 -1
- package/bpk-component-aria-live/README.md +2 -2
- package/bpk-component-aria-live/index.js +0 -1
- package/bpk-component-aria-live/package.json +8 -9
- package/bpk-component-aria-live/src/BpkAriaLive.js +21 -20
- package/bpk-component-aria-live/src/BpkAriaLive.module.scss +1 -1
- package/bpk-component-autosuggest/package.json +5 -5
- package/bpk-component-autosuggest/src/BpkAutosuggest.module.scss +2 -2
- package/bpk-component-badge/package.json +6 -6
- package/bpk-component-badge/src/BpkBadge.module.scss +1 -1
- package/bpk-component-banner-alert/package.json +10 -10
- package/bpk-component-banner-alert/src/BpkAnimateAndFade.module.scss +1 -1
- package/bpk-component-banner-alert/src/BpkBannerAlert.module.scss +3 -3
- package/bpk-component-barchart/package.json +9 -9
- package/bpk-component-barchart/src/BpkBarchartBar.module.scss +3 -1
- package/bpk-component-barchart/src/BpkChartAxis.module.scss +1 -1
- package/bpk-component-barchart/src/BpkChartDataTable.module.scss +1 -1
- package/bpk-component-barchart/src/BpkChartGridLines.module.scss +2 -2
- package/bpk-component-blockquote/package.json +3 -3
- package/bpk-component-blockquote/src/BpkBlockquote.module.scss +1 -1
- package/bpk-component-breadcrumb/package.json +6 -6
- package/bpk-component-breadcrumb/src/BpkBreadcrumb.module.scss +1 -1
- package/bpk-component-breadcrumb/src/BpkBreadcrumbItem.module.scss +1 -1
- package/bpk-component-breakpoint/package.json +4 -4
- package/bpk-component-button/package.json +3 -3
- package/bpk-component-button/src/BpkButtonBase.module.scss +2 -2
- package/bpk-component-button/src/BpkButtonDestructive.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonFeatured.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonLink.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonLinkOnDark.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonOutline.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonPrimaryOnDark.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonPrimaryOnLight.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonSecondary.module.scss +1 -1
- package/bpk-component-button/src/BpkButtonSecondaryOnDark.module.scss +1 -1
- package/bpk-component-calendar/DOCS.md +1 -7
- package/bpk-component-calendar/README.md +0 -10
- package/bpk-component-calendar/index.js +0 -2
- package/bpk-component-calendar/package.json +10 -10
- package/bpk-component-calendar/src/BpkCalendar.module.scss +2 -2
- package/bpk-component-calendar/src/BpkCalendarDate.js +0 -15
- package/bpk-component-calendar/src/BpkCalendarDate.module.scss +18 -51
- package/bpk-component-calendar/src/BpkCalendarGrid.module.scss +8 -7
- package/bpk-component-calendar/src/BpkCalendarGridHeader.module.scss +2 -2
- package/bpk-component-calendar/src/BpkCalendarGridTransition.module.scss +2 -2
- package/bpk-component-calendar/src/BpkCalendarNav.module.scss +3 -3
- package/bpk-component-calendar/src/_variables.scss +2 -4
- package/bpk-component-card/package.json +5 -5
- package/bpk-component-card/src/BpkCard.module.scss +1 -1
- package/bpk-component-checkbox/package.json +6 -6
- package/bpk-component-checkbox/src/BpkCheckbox.module.scss +1 -1
- package/bpk-component-chip/package.json +6 -6
- package/bpk-component-chip/src/BpkSelectableChip.module.scss +1 -1
- package/bpk-component-close-button/package.json +5 -5
- package/bpk-component-close-button/src/BpkCloseButton.module.scss +3 -2
- package/bpk-component-code/package.json +3 -3
- package/bpk-component-code/src/BpkCode.module.scss +1 -1
- package/bpk-component-code/src/BpkCodeBlock.module.scss +1 -1
- package/bpk-component-content-cards/{index.ts → index.js} +0 -0
- package/bpk-component-content-cards/package.json +5 -5
- package/bpk-component-content-cards/src/{BpkContentCard/BpkContentCard.tsx → BpkContentCard.js} +10 -11
- package/bpk-component-content-cards/src/{BpkContentCard/BpkContentCard.module.scss → BpkContentCard.module.scss} +1 -1
- package/bpk-component-content-cards/src/{BpkContentCards.tsx → BpkContentCards.js} +11 -11
- package/bpk-component-content-cards/src/BpkContentCards.module.scss +1 -1
- package/bpk-component-content-container/package.json +3 -3
- package/bpk-component-content-container/src/BpkContentContainer.module.scss +1 -1
- package/bpk-component-datatable/README.md +78 -21
- package/bpk-component-datatable/package.json +6 -7
- package/bpk-component-datatable/src/BpkDataTable.js +176 -143
- package/bpk-component-datatable/src/BpkDataTable.module.scss +11 -16
- package/bpk-component-datatable/src/BpkDataTableColumn.js +37 -40
- package/bpk-component-datatable/src/BpkDataTableHeader.js +143 -0
- package/bpk-component-datatable/src/{BpkDataTableColumn.module.scss → BpkDataTableHeader.module.scss} +12 -12
- package/bpk-component-datatable/src/common-types.js +33 -11
- package/bpk-component-datatable/src/sort-types.js +6 -0
- package/bpk-component-datatable/src/utils.js +66 -9
- package/bpk-component-datepicker/package.json +10 -10
- package/bpk-component-datepicker/src/BpkDatepicker.module.scss +1 -1
- package/bpk-component-description-list/package.json +3 -3
- package/bpk-component-description-list/src/BpkDescriptionList.module.scss +1 -1
- package/bpk-component-dialog/package.json +9 -9
- package/bpk-component-dialog/src/BpkDialog.module.scss +1 -1
- package/bpk-component-dialog/src/BpkDialogInner.module.scss +3 -1
- package/bpk-component-drawer/package.json +10 -10
- package/bpk-component-drawer/src/BpkDrawer.module.scss +1 -1
- package/bpk-component-drawer/src/BpkDrawerContent.module.scss +1 -1
- package/bpk-component-fieldset/package.json +13 -13
- package/bpk-component-fieldset/src/BpkFieldset.module.scss +1 -1
- package/bpk-component-flare/package.json +5 -5
- package/bpk-component-flare/src/bpk-content-bubble.module.scss +2 -1
- package/bpk-component-flare/src/bpk-flare-bar.module.scss +2 -1
- package/bpk-component-floating-notification/README.md +0 -8
- package/bpk-component-floating-notification/index.js +0 -2
- package/bpk-component-floating-notification/package.json +6 -6
- package/bpk-component-floating-notification/src/BpkFloatingNotification.js +7 -26
- package/bpk-component-floating-notification/src/BpkFloatingNotification.module.scss +5 -18
- package/bpk-component-form-validation/package.json +11 -11
- package/bpk-component-form-validation/src/BpkFormValidation.module.scss +1 -1
- package/bpk-component-graphic-promotion/{index.ts → index.js} +0 -0
- package/bpk-component-graphic-promotion/package.json +7 -6
- package/bpk-component-graphic-promotion/src/{BpkGraphicPromo.tsx → BpkGraphicPromo.js} +26 -16
- package/bpk-component-graphic-promotion/src/BpkGraphicPromo.module.scss +1 -1
- package/bpk-component-grid/package.json +3 -3
- package/bpk-component-grid/src/BpkGridColumn.module.scss +1 -1
- package/bpk-component-grid/src/BpkGridContainer.module.scss +1 -1
- package/bpk-component-grid/src/BpkGridRow.module.scss +1 -1
- package/bpk-component-grid-toggle/package.json +4 -4
- package/bpk-component-grid-toggle/src/BpkGridToggle.module.scss +1 -1
- package/bpk-component-horizontal-nav/package.json +7 -7
- package/bpk-component-horizontal-nav/src/BpkHorizontalNav.module.scss +3 -3
- package/bpk-component-horizontal-nav/src/BpkHorizontalNavItem.module.scss +15 -15
- package/bpk-component-icon/README.md +1 -1
- package/bpk-component-icon/package.json +8 -8
- package/bpk-component-icon/src/BpkIcon.module.scss +1 -1
- package/bpk-component-icon/src/withDescription.module.scss +1 -1
- package/bpk-component-image/package.json +7 -7
- package/bpk-component-image/src/BpkBackgroundImage.module.scss +1 -1
- package/bpk-component-image/src/BpkImage.module.scss +1 -1
- package/bpk-component-infinite-scroll/package.json +7 -7
- package/bpk-component-infinite-scroll/src/withInfiniteScroll.module.scss +1 -1
- package/bpk-component-input/package.json +7 -7
- package/bpk-component-input/src/BpkClearButton.module.scss +2 -2
- package/bpk-component-input/src/BpkInput.module.scss +1 -1
- package/bpk-component-label/package.json +3 -3
- package/bpk-component-label/src/BpkLabel.module.scss +1 -1
- package/bpk-component-link/package.json +5 -5
- package/bpk-component-link/src/BpkLink.module.scss +1 -1
- package/bpk-component-list/README.md +8 -5
- package/bpk-component-list/package.json +3 -3
- package/bpk-component-list/src/BpkList.js +18 -2
- package/bpk-component-list/src/BpkList.module.scss +1 -1
- package/bpk-component-loading-button/package.json +7 -7
- package/bpk-component-loading-button/src/BpkLoadingButton.module.scss +1 -1
- package/bpk-component-map/package.json +7 -7
- package/bpk-component-map/src/BpkIconMarker.module.scss +3 -2
- package/bpk-component-map/src/BpkIconMarkerBackground.module.scss +1 -1
- package/bpk-component-map/src/BpkMap.js +1 -0
- package/bpk-component-map/src/BpkPriceMarker.module.scss +3 -1
- package/bpk-component-map/src/DefaultLoadingElement.module.scss +1 -1
- package/bpk-component-mobile-scroll-container/README.md +1 -1
- package/bpk-component-mobile-scroll-container/package.json +4 -4
- package/bpk-component-mobile-scroll-container/src/BpkMobileScrollContainer.module.scss +3 -1
- package/bpk-component-modal/package.json +10 -10
- package/bpk-component-modal/src/BpkModal.module.scss +1 -1
- package/bpk-component-modal/src/BpkModalInner.module.scss +3 -1
- package/bpk-component-navigation-bar/package.json +9 -9
- package/bpk-component-navigation-bar/src/BpkNavigationBar.module.scss +4 -4
- package/bpk-component-navigation-bar/src/BpkNavigationBarButtonLink.module.scss +5 -5
- package/bpk-component-navigation-bar/src/BpkNavigationBarIconButton.module.scss +4 -4
- package/bpk-component-nudger/package.json +8 -8
- package/bpk-component-nudger/src/BpkNudger.module.scss +1 -1
- package/bpk-component-overlay/package.json +5 -5
- package/bpk-component-overlay/src/BpkOverlay.module.scss +1 -1
- package/bpk-component-pagination/package.json +5 -5
- package/bpk-component-pagination/src/BpkPaginationList.module.scss +1 -1
- package/bpk-component-pagination/src/BpkPaginationNudger.module.scss +2 -2
- package/bpk-component-pagination/src/BpkPaginationPage.module.scss +1 -1
- package/bpk-component-panel/package.json +3 -3
- package/bpk-component-panel/src/BpkPanel.module.scss +1 -1
- package/bpk-component-phone-input/package.json +10 -10
- package/bpk-component-phone-input/src/BpkPhoneInput.module.scss +1 -1
- package/bpk-component-popover/package.json +9 -9
- package/bpk-component-popover/src/BpkPopover.module.scss +1 -2
- package/bpk-component-price/package.json +4 -4
- package/bpk-component-price/src/BpkPrice.module.scss +1 -1
- package/bpk-component-progress/package.json +6 -6
- package/bpk-component-progress/src/BpkProgress.module.scss +1 -1
- package/bpk-component-radio/package.json +5 -5
- package/bpk-component-radio/src/BpkRadio.module.scss +1 -2
- package/bpk-component-rating/package.json +5 -5
- package/bpk-component-rating/src/BpkRating.module.scss +1 -1
- package/bpk-component-rtl-toggle/package.json +3 -3
- package/bpk-component-scrollable-calendar/package.json +7 -7
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGrid.module.scss +1 -1
- package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGridList.module.scss +1 -2
- package/bpk-component-section-list/package.json +7 -7
- package/bpk-component-section-list/src/BpkSectionListItem.module.scss +1 -1
- package/bpk-component-section-list/src/BpkSectionListSection.module.scss +1 -1
- package/bpk-component-select/package.json +4 -4
- package/bpk-component-select/src/BpkSelect.module.scss +1 -1
- package/bpk-component-skip-link/package.json +3 -3
- package/bpk-component-skip-link/src/BpkSkipLink.module.scss +2 -1
- package/bpk-component-slider/package.json +5 -5
- package/bpk-component-slider/src/BpkSlider.module.scss +1 -2
- package/bpk-component-spinner/package.json +4 -4
- package/bpk-component-spinner/src/BpkSpinner.module.scss +1 -1
- package/bpk-component-split-input/package.json +4 -4
- package/bpk-component-split-input/src/BpkInputField.module.scss +1 -1
- package/bpk-component-split-input/src/BpkSplitInput.module.scss +1 -1
- package/bpk-component-star-rating/package.json +6 -6
- package/bpk-component-star-rating/src/BpkInteractiveStar.module.scss +3 -3
- package/bpk-component-star-rating/src/BpkStar.module.scss +1 -1
- package/bpk-component-switch/README.md +1 -1
- package/bpk-component-switch/package.json +3 -3
- package/bpk-component-switch/src/BpkSwitch.js +14 -13
- package/bpk-component-switch/src/BpkSwitch.module.scss +18 -12
- package/bpk-component-table/package.json +3 -3
- package/bpk-component-table/src/BpkTable.module.scss +1 -1
- package/bpk-component-text/package.json +3 -3
- package/bpk-component-text/src/BpkText.module.scss +1 -1
- package/bpk-component-textarea/package.json +5 -5
- package/bpk-component-textarea/src/BpkTextarea.module.scss +1 -1
- package/bpk-component-theme-toggle/package.json +6 -6
- package/bpk-component-theme-toggle/src/BpkThemeToggle.module.scss +1 -1
- package/bpk-component-ticket/package.json +5 -5
- package/bpk-component-ticket/src/BpkTicket.module.scss +1 -1
- package/bpk-component-tooltip/package.json +5 -5
- package/bpk-component-tooltip/src/BpkTooltip.module.scss +3 -2
- package/bpk-react-utils/README.md +1 -1
- package/bpk-react-utils/package.json +1 -1
- package/bpk-scrim-utils/package.json +3 -3
- package/bpk-scrim-utils/src/bpk-scrim-content.module.scss +1 -1
- package/bpk-scrim-utils/src/bpk-scrim.module.scss +1 -1
- package/bpk-theming/package.json +2 -2
- package/package.json +4 -4
- package/bpk-component-content-cards/src/BpkContentCard/BpkContentCard-test.tsx +0 -88
- package/bpk-component-content-cards/src/BpkContentCard/index.ts +0 -19
- package/bpk-component-content-cards/src/BpkContentCards-test.tsx +0 -126
- package/bpk-component-content-cards/src/accessibility-test.tsx +0 -64
- package/bpk-component-datatable/src/bpkHeaderRenderer.js +0 -110
- package/bpk-component-datatable/src/sorter.js +0 -166
- package/bpk-component-graphic-promotion/src/BpkGraphicPromo-test.tsx +0 -134
- package/bpk-component-graphic-promotion/src/accessibility-test.tsx +0 -147
|
@@ -1,166 +0,0 @@
|
|
|
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
|
-
/* @flow strict */
|
|
20
|
-
import React from 'react';
|
|
21
|
-
import _sortBy from 'lodash/sortBy';
|
|
22
|
-
import { SortDirection } from 'react-virtualized';
|
|
23
|
-
|
|
24
|
-
import { getSortIconDirection } from './bpkHeaderRenderer';
|
|
25
|
-
import type { Props, SortProps, SortDirectionType } from './common-types';
|
|
26
|
-
|
|
27
|
-
export type Sorter<Row> = {
|
|
28
|
-
rowCount: number,
|
|
29
|
-
getRow(indext: number): Row,
|
|
30
|
-
propsChange(props: Props<Row>): void,
|
|
31
|
-
onHeaderClick(sortBy: string, eventTarget: Element, column: any): Sorter<Row>,
|
|
32
|
-
sortProps: SortProps,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const getSortDirection = (
|
|
36
|
-
sortProps: SortProps,
|
|
37
|
-
newSortBy: ?string,
|
|
38
|
-
newSortDirection: ?SortDirectionType,
|
|
39
|
-
defaultSortDirection: SortDirectionType,
|
|
40
|
-
): SortDirectionType => {
|
|
41
|
-
const { sortBy, sortDirection } = sortProps;
|
|
42
|
-
if (newSortDirection != null) {
|
|
43
|
-
return newSortDirection;
|
|
44
|
-
}
|
|
45
|
-
if (sortBy === newSortBy) {
|
|
46
|
-
return sortDirection === SortDirection.ASC
|
|
47
|
-
? SortDirection.DESC
|
|
48
|
-
: SortDirection.ASC;
|
|
49
|
-
}
|
|
50
|
-
return defaultSortDirection;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
class NaiveSorter<Row> {
|
|
54
|
-
sortProps: SortProps;
|
|
55
|
-
|
|
56
|
-
list: Array<Row>;
|
|
57
|
-
|
|
58
|
-
sortedList: Array<Row>;
|
|
59
|
-
|
|
60
|
-
rowCount: number;
|
|
61
|
-
|
|
62
|
-
constructor(props: Props<Row>) {
|
|
63
|
-
const children = React.Children.toArray(props.children);
|
|
64
|
-
|
|
65
|
-
const sortBy =
|
|
66
|
-
React.Children.count(props.children) > 0
|
|
67
|
-
? children[props.defaultColumnSortIndex].props.dataKey
|
|
68
|
-
: undefined;
|
|
69
|
-
const sortDirection =
|
|
70
|
-
children[props.defaultColumnSortIndex].props.defaultSortDirection ||
|
|
71
|
-
SortDirection.ASC;
|
|
72
|
-
|
|
73
|
-
this.sortProps = {
|
|
74
|
-
sortBy,
|
|
75
|
-
sortDirection,
|
|
76
|
-
sort: null,
|
|
77
|
-
};
|
|
78
|
-
this.list = props.rows;
|
|
79
|
-
this.sort();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
getRow(index: number): Row {
|
|
83
|
-
return this.sortedList[index];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
sort() {
|
|
87
|
-
const sorted = _sortBy(this.list, this.sortProps.sortBy);
|
|
88
|
-
if (this.sortProps.sortDirection === 'DESC') {
|
|
89
|
-
sorted.reverse();
|
|
90
|
-
}
|
|
91
|
-
this.sortedList = sorted;
|
|
92
|
-
this.rowCount = this.sortedList.length;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
propsChange(nextProps: Props<Row>) {
|
|
96
|
-
this.list = nextProps.rows;
|
|
97
|
-
this.sort();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
onHeaderClick(sortBy: string, eventTarget: Element, column): Sorter<Row> {
|
|
101
|
-
const sortDirection = getSortDirection(
|
|
102
|
-
this.sortProps,
|
|
103
|
-
sortBy,
|
|
104
|
-
getSortIconDirection(eventTarget),
|
|
105
|
-
column.props.defaultSortDirection || SortDirection.ASC,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
this.sortProps = {
|
|
109
|
-
sortBy,
|
|
110
|
-
sortDirection,
|
|
111
|
-
sort: null,
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
this.sort();
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
class PropSorter<Row> {
|
|
120
|
-
sortProps: SortProps;
|
|
121
|
-
|
|
122
|
-
list: Array<Row>;
|
|
123
|
-
|
|
124
|
-
rowCount: number;
|
|
125
|
-
|
|
126
|
-
constructor(props: Props<Row>) {
|
|
127
|
-
this.sortProps = {
|
|
128
|
-
sortBy: props.sortBy,
|
|
129
|
-
sortDirection: props.sortDirection,
|
|
130
|
-
sort: props.sort,
|
|
131
|
-
};
|
|
132
|
-
this.list = props.rows;
|
|
133
|
-
this.rowCount = props.rows.length;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
getRow(index: number): Row {
|
|
137
|
-
return this.list[index];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
propsChange(nextProps: Props<Row>) {
|
|
141
|
-
this.sortProps = {
|
|
142
|
-
sortBy: nextProps.sortBy,
|
|
143
|
-
sortDirection: nextProps.sortDirection,
|
|
144
|
-
sort: nextProps.sort,
|
|
145
|
-
};
|
|
146
|
-
this.list = nextProps.rows;
|
|
147
|
-
this.rowCount = nextProps.rows.length;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
onHeaderClick(): Sorter<Row> {
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const makeSorter = <Row>(props: Props<Row>): Sorter<Row> => {
|
|
156
|
-
if (
|
|
157
|
-
props.sort !== null &&
|
|
158
|
-
props.sortBy !== null &&
|
|
159
|
-
props.sortDirection !== null
|
|
160
|
-
) {
|
|
161
|
-
return new PropSorter(props);
|
|
162
|
-
}
|
|
163
|
-
return new NaiveSorter(props);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export default makeSorter;
|
|
@@ -1,134 +0,0 @@
|
|
|
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 React from 'react';
|
|
20
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
21
|
-
|
|
22
|
-
// @ts-expect-error Untyped import. Not added as a stub declaration so consumers still have the suppression in their node_modules when shipped untranspiled.
|
|
23
|
-
import { cssModules } from '../../bpk-react-utils';
|
|
24
|
-
|
|
25
|
-
import BpkGraphicPromo, { TEXT_ALIGN } from './BpkGraphicPromo';
|
|
26
|
-
import type { Props } from './BpkGraphicPromo';
|
|
27
|
-
import STYLES from './BpkGraphicPromo.module.scss';
|
|
28
|
-
|
|
29
|
-
const getClassName = cssModules(STYLES);
|
|
30
|
-
|
|
31
|
-
const props: Props = {
|
|
32
|
-
buttonText: 'Learn more',
|
|
33
|
-
headline: 'Ride your wave',
|
|
34
|
-
invertVertically: false,
|
|
35
|
-
onClick: jest.fn(),
|
|
36
|
-
sponsor: {
|
|
37
|
-
label: 'Sponsored',
|
|
38
|
-
logo: 'path/to/logo.png',
|
|
39
|
-
altText: 'Airline Name',
|
|
40
|
-
},
|
|
41
|
-
subheading:
|
|
42
|
-
'Portugal and 6 more countries have just been added to the UK travel green list',
|
|
43
|
-
tagline: 'Tagline',
|
|
44
|
-
textAlign: TEXT_ALIGN.start,
|
|
45
|
-
contentId: 'mock-content-id',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
describe('BpkGraphicPromo', () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
(props.onClick as jest.MockedFunction<Props['onClick']>).mockReset();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should render correctly with all properties set', () => {
|
|
54
|
-
const { asFragment } = render(<BpkGraphicPromo {...props} />);
|
|
55
|
-
|
|
56
|
-
expect(asFragment()).toMatchSnapshot();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should support custom class names', () => {
|
|
60
|
-
const { asFragment } = render(
|
|
61
|
-
<BpkGraphicPromo className="custom-classname" {...props} />,
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
expect(asFragment()).toMatchSnapshot();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should render correctly when centre aligned', () => {
|
|
68
|
-
const customProps = { ...props, textAlign: TEXT_ALIGN.center };
|
|
69
|
-
const { asFragment } = render(<BpkGraphicPromo {...customProps} />);
|
|
70
|
-
|
|
71
|
-
expect(asFragment()).toMatchSnapshot();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should render correctly when right aligned', () => {
|
|
75
|
-
const customProps = { ...props, textAlign: TEXT_ALIGN.end };
|
|
76
|
-
const { asFragment } = render(<BpkGraphicPromo {...customProps} />);
|
|
77
|
-
|
|
78
|
-
expect(asFragment()).toMatchSnapshot();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should render correctly when inverted portrait', () => {
|
|
82
|
-
const customProps = { ...props, invertVertically: true };
|
|
83
|
-
const { asFragment } = render(<BpkGraphicPromo {...customProps} />);
|
|
84
|
-
|
|
85
|
-
expect(asFragment()).toMatchSnapshot();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should not display tagline or subheading when not provided', () => {
|
|
89
|
-
const customProps = { ...props };
|
|
90
|
-
delete customProps.tagline;
|
|
91
|
-
delete customProps.subheading;
|
|
92
|
-
const { asFragment } = render(<BpkGraphicPromo {...customProps} />);
|
|
93
|
-
|
|
94
|
-
expect(asFragment()).toMatchSnapshot();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should display the tagline and no sponsor for non-sponsored ad', () => {
|
|
98
|
-
const customProps = { ...props };
|
|
99
|
-
delete customProps.sponsor;
|
|
100
|
-
const { asFragment } = render(<BpkGraphicPromo {...customProps} />);
|
|
101
|
-
|
|
102
|
-
expect(asFragment()).toMatchSnapshot();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should redirect us to link when card is clicked', () => {
|
|
106
|
-
render(<BpkGraphicPromo {...props} />);
|
|
107
|
-
|
|
108
|
-
const graphicPromo = document.getElementsByClassName(
|
|
109
|
-
getClassName('bpk-graphic-promo'),
|
|
110
|
-
)[0];
|
|
111
|
-
fireEvent.click(graphicPromo);
|
|
112
|
-
|
|
113
|
-
expect(props.onClick).toHaveBeenCalledTimes(1);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should redirect us to link when button is clicked', () => {
|
|
117
|
-
render(<BpkGraphicPromo {...props} />);
|
|
118
|
-
|
|
119
|
-
const graphicPromoCTA = document.getElementsByClassName(
|
|
120
|
-
getClassName('bpk-graphic-promo__cta'),
|
|
121
|
-
)[0];
|
|
122
|
-
fireEvent.click(graphicPromoCTA);
|
|
123
|
-
|
|
124
|
-
expect(props.onClick).toHaveBeenCalledTimes(1);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should render as expected without a content ID', () => {
|
|
128
|
-
const { asFragment } = render(
|
|
129
|
-
<BpkGraphicPromo {...props} contentId={null} />,
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
expect(asFragment()).toMatchSnapshot();
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
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
|
-
import React from 'react';
|
|
19
|
-
import { render } from '@testing-library/react';
|
|
20
|
-
import { axe } from 'jest-axe';
|
|
21
|
-
|
|
22
|
-
import BpkGraphicPromo, { TEXT_ALIGN } from './BpkGraphicPromo';
|
|
23
|
-
|
|
24
|
-
const sponsor = {
|
|
25
|
-
label: 'Sponsored',
|
|
26
|
-
logo: 'path/to/logo.png',
|
|
27
|
-
altText: 'Airline Name',
|
|
28
|
-
};
|
|
29
|
-
const buttonText = 'Learn more';
|
|
30
|
-
const onClick = () => {
|
|
31
|
-
window.location.href = 'https://www.skyscanner.net';
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const tagline = 'Tagline';
|
|
35
|
-
const headline = 'Ride your wave';
|
|
36
|
-
const subheading =
|
|
37
|
-
'Portugal and 6 more countries have just been added to the UK travel green list';
|
|
38
|
-
|
|
39
|
-
describe('BpkGraphicPromo accessibility tests', () => {
|
|
40
|
-
// TODO: Temporarily disabling tests due to a newer version of jest-axe which causes tests to fail when using nested interactive elements
|
|
41
|
-
|
|
42
|
-
it('should not have programmatically-detectable accessibility issues', async () => {
|
|
43
|
-
const { container } = render(
|
|
44
|
-
<BpkGraphicPromo
|
|
45
|
-
buttonText={buttonText}
|
|
46
|
-
className="test"
|
|
47
|
-
headline={headline}
|
|
48
|
-
invertVertically={false}
|
|
49
|
-
onClick={onClick}
|
|
50
|
-
sponsor={sponsor}
|
|
51
|
-
subheading={subheading}
|
|
52
|
-
tagline={tagline}
|
|
53
|
-
textAlign={TEXT_ALIGN.start}
|
|
54
|
-
/>,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const results = await axe(container);
|
|
58
|
-
expect(results).toHaveNoViolations();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should not have programmatically-detectable accessibility issues in centre aligned', async () => {
|
|
62
|
-
const { container } = render(
|
|
63
|
-
<BpkGraphicPromo
|
|
64
|
-
buttonText={buttonText}
|
|
65
|
-
headline={headline}
|
|
66
|
-
invertVertically={false}
|
|
67
|
-
onClick={onClick}
|
|
68
|
-
sponsor={sponsor}
|
|
69
|
-
subheading={subheading}
|
|
70
|
-
tagline={tagline}
|
|
71
|
-
textAlign={TEXT_ALIGN.center}
|
|
72
|
-
/>,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const results = await axe(container);
|
|
76
|
-
expect(results).toHaveNoViolations();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should not have programmatically-detectable accessibility issues in right aligned', async () => {
|
|
80
|
-
const { container } = render(
|
|
81
|
-
<BpkGraphicPromo
|
|
82
|
-
buttonText={buttonText}
|
|
83
|
-
headline={headline}
|
|
84
|
-
invertVertically={false}
|
|
85
|
-
onClick={onClick}
|
|
86
|
-
sponsor={sponsor}
|
|
87
|
-
subheading={subheading}
|
|
88
|
-
tagline={tagline}
|
|
89
|
-
textAlign={TEXT_ALIGN.end}
|
|
90
|
-
/>,
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const results = await axe(container);
|
|
94
|
-
expect(results).toHaveNoViolations();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should not have programmatically-detectable accessibility issues in inverted portrait', async () => {
|
|
98
|
-
const { container } = render(
|
|
99
|
-
<BpkGraphicPromo
|
|
100
|
-
buttonText={buttonText}
|
|
101
|
-
headline={headline}
|
|
102
|
-
invertVertically
|
|
103
|
-
onClick={onClick}
|
|
104
|
-
sponsor={sponsor}
|
|
105
|
-
subheading={subheading}
|
|
106
|
-
tagline={tagline}
|
|
107
|
-
textAlign={TEXT_ALIGN.start}
|
|
108
|
-
/>,
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const results = await axe(container);
|
|
112
|
-
expect(results).toHaveNoViolations();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should not have programmatically-detectable accessibility issues when optional text is missing', async () => {
|
|
116
|
-
const { container } = render(
|
|
117
|
-
<BpkGraphicPromo
|
|
118
|
-
buttonText={buttonText}
|
|
119
|
-
headline={headline}
|
|
120
|
-
invertVertically={false}
|
|
121
|
-
onClick={onClick}
|
|
122
|
-
sponsor={sponsor}
|
|
123
|
-
textAlign={TEXT_ALIGN.start}
|
|
124
|
-
/>,
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const results = await axe(container);
|
|
128
|
-
expect(results).toHaveNoViolations();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should not have programmatically-detectable accessibility issues in non-sponsored', async () => {
|
|
132
|
-
const { container } = render(
|
|
133
|
-
<BpkGraphicPromo
|
|
134
|
-
buttonText={buttonText}
|
|
135
|
-
headline={headline}
|
|
136
|
-
invertVertically={false}
|
|
137
|
-
onClick={onClick}
|
|
138
|
-
subheading={subheading}
|
|
139
|
-
tagline={tagline}
|
|
140
|
-
textAlign={TEXT_ALIGN.start}
|
|
141
|
-
/>,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const results = await axe(container);
|
|
145
|
-
expect(results).toHaveNoViolations();
|
|
146
|
-
});
|
|
147
|
-
});
|