@skyscanner/backpack-web 33.4.0 → 34.0.0-premajor.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 (153) hide show
  1. package/bpk-component-accordion/index.js +1 -1
  2. package/bpk-component-accordion/src/BpkAccordionItem.js +12 -12
  3. package/bpk-component-accordion/src/BpkAccordionItem.module.css +1 -1
  4. package/bpk-component-autosuggest/src/BpkAutosuggestSuggestion.js +4 -1
  5. package/bpk-component-banner-alert/index.js +1 -1
  6. package/bpk-component-banner-alert/src/AnimateAndFade.js +33 -31
  7. package/bpk-component-banner-alert/src/BpkBannerAlertInner.js +11 -4
  8. package/bpk-component-barchart/src/BpkBarchart.js +8 -8
  9. package/bpk-component-bottom-sheet/src/BpkBottomSheet.js +3 -3
  10. package/bpk-component-breadcrumb/src/BpkBreadcrumbItem.js +17 -12
  11. package/bpk-component-breadcrumb/src/BpkBreadcrumbItem.module.css +1 -1
  12. package/bpk-component-button/index.js +5 -5
  13. package/bpk-component-button/src/BpkButtonDestructive.js +10 -9
  14. package/bpk-component-button/src/BpkButtonFeatured.js +10 -9
  15. package/bpk-component-button/src/BpkButtonLink.js +11 -10
  16. package/bpk-component-button/src/BpkButtonLinkOnDark.js +11 -10
  17. package/bpk-component-button/src/BpkButtonPrimary.js +2 -2
  18. package/bpk-component-button/src/BpkButtonPrimaryOnDark.js +10 -9
  19. package/bpk-component-button/src/BpkButtonPrimaryOnLight.js +10 -9
  20. package/bpk-component-button/src/BpkButtonSecondary.js +10 -10
  21. package/bpk-component-button/src/BpkButtonSecondaryOnDark.js +10 -9
  22. package/bpk-component-calendar/index.js +1 -1
  23. package/bpk-component-calendar/src/BpkCalendarContainer.js +3 -3
  24. package/bpk-component-calendar/src/BpkCalendarGrid.js +2 -2
  25. package/bpk-component-calendar/src/BpkCalendarGrid.module.css +1 -1
  26. package/bpk-component-calendar/src/BpkCalendarGridHeader.js +4 -1
  27. package/bpk-component-calendar/src/BpkCalendarGridTransition.js +5 -2
  28. package/bpk-component-calendar/src/BpkCalendarNav.js +9 -3
  29. package/bpk-component-calendar/src/Week.js +6 -3
  30. package/bpk-component-calendar/src/composeCalendar.js +8 -2
  31. package/bpk-component-calendar/src/date-utils.js +14 -14
  32. package/bpk-component-card/src/BpkDividedCard.js +18 -13
  33. package/bpk-component-card-button/src/BpkSaveButton.js +13 -4
  34. package/bpk-component-chip/index.d.ts +3 -5
  35. package/bpk-component-chip/index.js +3 -2
  36. package/bpk-component-chip/src/BpkDismissibleChip.js +7 -2
  37. package/bpk-component-chip/src/BpkIconChip.d.ts +25 -0
  38. package/bpk-component-chip/src/BpkIconChip.js +31 -0
  39. package/bpk-component-chip/src/BpkSelectableChip.d.ts +0 -2
  40. package/bpk-component-chip/src/BpkSelectableChip.js +3 -3
  41. package/bpk-component-chip/src/BpkSelectableChip.module.css +1 -1
  42. package/bpk-component-chip/src/commonTypes.d.ts +1 -1
  43. package/bpk-component-chip/src/commonTypes.js +1 -24
  44. package/bpk-component-content-cards/src/BpkContentCard.js +8 -2
  45. package/bpk-component-datatable/src/BpkDataTable.js +1 -1
  46. package/bpk-component-datatable/src/BpkDataTableHeader.js +12 -8
  47. package/bpk-component-datatable/src/BpkDataTableHeader.module.css +1 -1
  48. package/bpk-component-datepicker/src/BpkDatepicker.js +2 -2
  49. package/bpk-component-description-list/index.js +1 -1
  50. package/bpk-component-description-list/src/ComponentFactory.js +10 -5
  51. package/bpk-component-dialog/src/BpkDialog.js +6 -4
  52. package/bpk-component-dialog/src/BpkDialog.module.css +1 -1
  53. package/bpk-component-dialog/src/BpkDialogInner.js +6 -3
  54. package/bpk-component-drawer/src/BpkDrawer.js +1 -4
  55. package/bpk-component-drawer/src/BpkDrawerContent.js +7 -5
  56. package/bpk-component-fieldset/src/BpkFieldset.js +9 -7
  57. package/bpk-component-flare/index.js +2 -2
  58. package/bpk-component-flare/src/BpkContentBubble.js +4 -1
  59. package/bpk-component-flare/src/BpkFlareBar.js +13 -4
  60. package/bpk-component-flare/src/__generated__/corner-radius.d.ts +6 -0
  61. package/bpk-component-flare/src/__generated__/pointer.d.ts +6 -0
  62. package/bpk-component-floating-notification/src/BpkFloatingNotification.js +8 -2
  63. package/bpk-component-form-validation/src/BpkFormValidation.js +5 -4
  64. package/bpk-component-graphic-promotion/src/BpkGraphicPromo.js +9 -11
  65. package/bpk-component-graphic-promotion/src/BpkGraphicPromo.module.css +1 -1
  66. package/bpk-component-grid-toggle/src/BpkGridToggle.js +8 -6
  67. package/bpk-component-horizontal-nav/src/BpkHorizontalNav.js +16 -14
  68. package/bpk-component-horizontal-nav/src/BpkHorizontalNav.module.css +1 -1
  69. package/bpk-component-horizontal-nav/src/BpkHorizontalNavItem.js +2 -2
  70. package/bpk-component-icon/index.js +1 -1
  71. package/bpk-component-icon/src/classNameModifierHOCFactory.js +3 -0
  72. package/bpk-component-image/index.js +2 -2
  73. package/bpk-component-image/src/BpkBackgroundImage.js +2 -1
  74. package/bpk-component-image/src/BpkImage.js +2 -1
  75. package/bpk-component-infinite-scroll/src/withInfiniteScroll.js +3 -3
  76. package/bpk-component-info-banner/src/AnimateAndFade.js +33 -31
  77. package/bpk-component-info-banner/src/BpkInfoBanner.module.css +1 -1
  78. package/bpk-component-info-banner/src/BpkInfoBannerInner.js +16 -12
  79. package/bpk-component-input/index.js +1 -1
  80. package/bpk-component-input/src/BpkClearButton.js +3 -1
  81. package/bpk-component-input/src/BpkInput.js +4 -1
  82. package/bpk-component-input/src/withOpenEvents.js +4 -1
  83. package/bpk-component-link/index.js +2 -2
  84. package/bpk-component-list/src/BpkList.js +4 -1
  85. package/bpk-component-loading-button/src/BpkLoadingButton.js +6 -3
  86. package/bpk-component-map/index.js +4 -4
  87. package/bpk-component-map/src/BpkIconMarker.js +1 -1
  88. package/bpk-component-map/src/BpkMap.js +2 -2
  89. package/bpk-component-map/src/BpkPriceMarker.js +7 -5
  90. package/bpk-component-map/src/BpkPriceMarkerV2/BpkPriceMarker.js +1 -1
  91. package/bpk-component-mobile-scroll-container/src/BpkMobileScrollContainer.js +4 -1
  92. package/bpk-component-modal/index.js +4 -3
  93. package/bpk-component-modal/src/BpkModal.d.ts +2 -1
  94. package/bpk-component-modal/src/BpkModal.js +8 -3
  95. package/bpk-component-modal/src/BpkModalInner.d.ts +2 -0
  96. package/bpk-component-modal/src/BpkModalInner.js +24 -8
  97. package/bpk-component-modal/src/BpkModalInner.module.css +1 -1
  98. package/bpk-component-modal/src/BpkModalV2/BpKModal.module.css +1 -1
  99. package/bpk-component-modal/src/BpkModalV2/BpkModal.d.ts +2 -0
  100. package/bpk-component-modal/src/BpkModalV2/BpkModal.js +19 -8
  101. package/bpk-component-navigation-bar/index.js +1 -1
  102. package/bpk-component-navigation-bar/src/BpkNavigationBar.js +7 -5
  103. package/bpk-component-navigation-bar/src/BpkNavigationBarButtonLink.js +4 -1
  104. package/bpk-component-navigation-bar/src/BpkNavigationBarIconButton.js +4 -1
  105. package/bpk-component-nudger/index.js +1 -1
  106. package/bpk-component-nudger/src/BpkConfigurableNudger.js +16 -4
  107. package/bpk-component-nudger/src/BpkNudger.js +16 -5
  108. package/bpk-component-page-indicator/src/BpkPageIndicator.module.css +1 -1
  109. package/bpk-component-page-indicator/src/NavButton.js +1 -1
  110. package/bpk-component-pagination/src/BpkPaginationList.js +1 -1
  111. package/bpk-component-pagination/src/BpkPaginationNudger.js +13 -4
  112. package/bpk-component-pagination/src/BpkPaginationPage.js +4 -1
  113. package/bpk-component-phone-input/src/BpkPhoneInput.js +15 -4
  114. package/bpk-component-popover/index.js +3 -3
  115. package/bpk-component-popover/src/BpkPopover.js +131 -101
  116. package/bpk-component-popover/src/BpkPopover.module.css +1 -1
  117. package/bpk-component-popover/src/themeAttributes.js +4 -1
  118. package/bpk-component-price/src/BpkPrice.js +17 -5
  119. package/bpk-component-rating/src/BpkRating.js +17 -5
  120. package/bpk-component-rtl-toggle/src/BpkRtlToggle.js +4 -1
  121. package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGrid.js +6 -3
  122. package/bpk-component-scrollable-calendar/src/BpkScrollableCalendarGridList.js +6 -3
  123. package/bpk-component-section-header/src/BpkSectionHeader.js +9 -3
  124. package/bpk-component-section-list/index.js +1 -1
  125. package/bpk-component-section-list/src/BpkSectionListItem.js +10 -4
  126. package/bpk-component-section-list/src/BpkSectionListSection.js +1 -1
  127. package/bpk-component-slider/src/BpkSlider.js +4 -1
  128. package/bpk-component-spinner/index.js +3 -3
  129. package/bpk-component-spinner/src/BpkExtraLargeSpinner.js +7 -4
  130. package/bpk-component-spinner/src/BpkLargeSpinner.js +7 -4
  131. package/bpk-component-spinner/src/BpkSpinner.js +7 -4
  132. package/bpk-component-split-input/src/BpkInputField.js +2 -2
  133. package/bpk-component-split-input/src/BpkSplitInput.js +3 -3
  134. package/bpk-component-star-rating/index.js +4 -4
  135. package/bpk-component-star-rating/src/BpkInteractiveStar.js +6 -2
  136. package/bpk-component-star-rating/src/BpkInteractiveStarRating.js +1 -1
  137. package/bpk-component-star-rating/src/BpkStar.js +22 -15
  138. package/bpk-component-swap-button/src/BpkSwapButton.js +2 -1
  139. package/bpk-component-table/index.js +2 -2
  140. package/bpk-component-text/src/BpkText.js +10 -5
  141. package/bpk-component-theme-toggle/src/BpkThemeToggle.js +4 -1
  142. package/bpk-component-theme-toggle/src/updateOnThemeChange.js +1 -1
  143. package/bpk-component-tooltip/src/BpkTooltipPortal.js +4 -1
  144. package/bpk-mixins/_chips.scss +9 -0
  145. package/bpk-react-utils/index.js +3 -3
  146. package/bpk-react-utils/src/withDefaultProps.js +4 -1
  147. package/bpk-scrim-utils/src/withScrimmedPortal.js +1 -1
  148. package/bpk-theming/src/BpkThemeProvider.js +1 -1
  149. package/package.json +4 -3
  150. package/unstable__bpk-mixins/_chips.scss +9 -0
  151. package/bpk-component-button/src/commonButtonTests.js +0 -133
  152. package/bpk-component-popover/src/BpkPopoverPortal.js +0 -216
  153. package/bpk-component-popover/src/keyboardFocusScope.js +0 -76
@@ -18,8 +18,8 @@
18
18
 
19
19
  import { useState, useEffect } from 'react';
20
20
  import { createPortal } from 'react-dom';
21
- import withScrim from "./withScrim";
22
21
  import BpkScrim from "./BpkScrim";
22
+ import withScrim from "./withScrim";
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  const getPortalElement = target => {
25
25
  const portalElement = target && typeof target === 'function' ? target() : null;
@@ -16,8 +16,8 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- import { Component } from 'react';
20
19
  import PropTypes from 'prop-types';
20
+ import { Component } from 'react';
21
21
  import { jsx as _jsx } from "react/jsx-runtime";
22
22
  const uniq = (arr = []) => {
23
23
  const seen = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "33.4.0",
3
+ "version": "34.0.0-premajor.1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,9 +22,10 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@popperjs/core": "^2.11.5",
25
+ "@floating-ui/react": "^0.26.12",
26
+ "@popperjs/core": "^2.11.8",
26
27
  "@react-google-maps/api": "^2.12.0",
27
- "@skyscanner/bpk-foundations-web": "^17.5.3",
28
+ "@skyscanner/bpk-foundations-web": "^17.9.0",
28
29
  "@skyscanner/bpk-svgs": "^19.1.0",
29
30
  "a11y-focus-scope": "^1.1.3",
30
31
  "a11y-focus-store": "^1.0.0",
@@ -237,4 +237,13 @@
237
237
  color: tokens.$bpk-text-disabled-day;
238
238
  cursor: not-allowed;
239
239
  }
240
+
241
+ &--icon-only {
242
+ padding-inline-end: tokens.bpk-spacing-md();
243
+ padding-inline-start: tokens.bpk-spacing-md();
244
+
245
+ &__leading-accessory-view {
246
+ @include margins.bpk-margin-trailing(0);
247
+ }
248
+ }
240
249
  }
@@ -1,133 +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
- import { render } from '@testing-library/react';
20
- import { jsx as _jsx } from "react/jsx-runtime";
21
- const commonButtonTests = ButtonToTest => {
22
- describe('ButtonToTest', () => {
23
- it('should render correctly', () => {
24
- const {
25
- asFragment
26
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
27
- children: "My button"
28
- }));
29
- expect(asFragment()).toMatchSnapshot();
30
- });
31
- it('should render correctly with a "href" attribute', () => {
32
- const {
33
- asFragment
34
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
35
- href: "#",
36
- children: "My button"
37
- }));
38
- expect(asFragment()).toMatchSnapshot();
39
- });
40
- it('should render correctly with a "disabled" attribute', () => {
41
- const {
42
- asFragment
43
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
44
- disabled: true,
45
- children: "My button"
46
- }));
47
- expect(asFragment()).toMatchSnapshot();
48
- });
49
- it('should render correctly with a "large" attribute', () => {
50
- const {
51
- asFragment
52
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
53
- large: true,
54
- children: "My button"
55
- }));
56
- expect(asFragment()).toMatchSnapshot();
57
- });
58
- it('should render correctly with an "iconOnly" attribute', () => {
59
- const {
60
- asFragment
61
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
62
- iconOnly: true,
63
- children: "My button"
64
- }));
65
- expect(asFragment()).toMatchSnapshot();
66
- });
67
- it('should respect the class names entered as a string', () => {
68
- const {
69
- asFragment
70
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
71
- large: true,
72
- className: "custom-class-1 custom-class-2",
73
- children: "My button"
74
- }));
75
- expect(asFragment()).toMatchSnapshot();
76
- });
77
- it('should add only bpk specific classes if className prop is set to empty string', () => {
78
- const {
79
- asFragment
80
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
81
- large: true,
82
- className: "",
83
- children: "My button"
84
- }));
85
- expect(asFragment()).toMatchSnapshot();
86
- });
87
- it('should render correctly with "blank" attribute', () => {
88
- const {
89
- asFragment
90
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
91
- href: "#",
92
- blank: true,
93
- children: "My button"
94
- }));
95
- expect(asFragment()).toMatchSnapshot();
96
- });
97
- it('should render correctly with "rel" attribute', () => {
98
- const {
99
- asFragment
100
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
101
- href: "#",
102
- rel: "rel-attr",
103
- children: "My button"
104
- }));
105
- expect(asFragment()).toMatchSnapshot();
106
- });
107
- it('should render correctly with "blank" and "rel" attributes', () => {
108
- const {
109
- asFragment
110
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
111
- href: "#",
112
- blank: true,
113
- rel: "rel-overwrite",
114
- children: "My button"
115
- }));
116
- expect(asFragment()).toMatchSnapshot();
117
- });
118
- it('should render correctly with "disabled" and "href" attributes', () => {
119
- const {
120
- asFragment
121
- } = render( /*#__PURE__*/_jsx(ButtonToTest, {
122
- href: "#",
123
- disabled: true,
124
- children: "My button"
125
- }));
126
- expect(asFragment()).toMatchSnapshot();
127
- });
128
- });
129
- };
130
-
131
- // We export these to reuse them in other tests for buttons.
132
- // eslint-disable-next-line jest/no-export
133
- export default commonButtonTests;
@@ -1,216 +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
- */import PropTypes from 'prop-types';
18
- import { Component } from 'react';
19
- import { createPopper } from '@popperjs/core';
20
- import focusStore from 'a11y-focus-store';
21
- import { Portal, cssModules } from "../../bpk-react-utils";
22
- import keyboardFocusScope from "./keyboardFocusScope";
23
- import BpkPopover from "./BpkPopover";
24
- import STYLES from "./BpkPopover.module.css";
25
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
26
- const getClassName = cssModules(STYLES);
27
- class BpkPopoverPortal extends Component {
28
- constructor() {
29
- super();
30
- this.popper = null;
31
- this.previousTargetElement = null;
32
- }
33
- onRender = (popoverElement, targetElement) => {
34
- this.position(popoverElement, targetElement);
35
- };
36
-
37
- // The order of events here is as follows:
38
- // - `onClose` is called by `Portal`
39
- // - The consumer changes `isOpen` to `false`
40
- // - `beforeClose` is called by `Portal`
41
- // - `beforeClose` calls the `done` callback which closes the `Portal`
42
-
43
- // `onClose` is called by the `Portal` to inform the consumer that `isOpen` should be made false.
44
- // Before we pass this information to the consumer, we want to note if restoring focus should be suppressed
45
- onClose = (event, information) => {
46
- // If the user has clicked outside the popover then we don't want focus to be restored
47
- // otherwise it will be stolen back from the element they clicked on.
48
- // Here we suppress restoring focus before the consumer is told about the close and updates state.
49
- this.suppressRestoreFocus = information.source === 'DOCUMENT_CLICK';
50
- if (this.props.onClose) {
51
- this.props.onClose(event, information);
52
- }
53
- };
54
-
55
- // `beforeClose` is called by the `Portal` when `isOpen` is changed to false.
56
- // As a result, `onClose` is called first, followed by `beforeClose`.
57
- beforeClose = done => {
58
- if (this.popper) {
59
- this.popper.destroy();
60
- this.popper = null;
61
- this.previousTargetElement = null;
62
- }
63
- keyboardFocusScope.unscopeFocus();
64
- if (!this.suppressRestoreFocus) {
65
- focusStore.restoreFocus();
66
- this.suppressRestoreFocus = false;
67
- }
68
- done();
69
- };
70
- position(popoverElement, targetElement) {
71
- if (!targetElement) {
72
- return;
73
- }
74
- const targetElementHasChanged = targetElement !== this.previousTargetElement;
75
- if (targetElementHasChanged && this.popper) {
76
- this.popper.destroy();
77
- this.popper = null;
78
- }
79
-
80
- // Custom modifier that makes the arrow display at the edge of the target.
81
- const applyArrowHide = {
82
- name: 'applyArrowHide',
83
- enabled: true,
84
- phase: 'write',
85
- fn({
86
- state
87
- }) {
88
- const {
89
- arrow
90
- } = state.elements;
91
- if (arrow) {
92
- if (state.modifiersData.arrow.centerOffset !== 0) {
93
- arrow.setAttribute('data-hide', '');
94
- } else {
95
- arrow.removeAttribute('data-hide');
96
- }
97
- }
98
- }
99
- };
100
-
101
- // The default modifiers for the popper
102
- // Note that GPU acceleration should be disabled otherwise Popper will use `translate3d`
103
- // which can cause blurriness in Safari and Chrome.
104
- const stdModifiers = [{
105
- name: 'computeStyles',
106
- options: {
107
- gpuAcceleration: false
108
- }
109
- }, {
110
- name: 'offset',
111
- options: {
112
- offset: [0, 17]
113
- }
114
- }, applyArrowHide];
115
- if (!this.popper) {
116
- this.popper = createPopper(targetElement, popoverElement, {
117
- placement: this.props.placement,
118
- onFirstUpdate: () => {
119
- if (targetElement) {
120
- targetElement.focus();
121
- }
122
- focusStore.storeFocus();
123
- keyboardFocusScope.scopeFocus(popoverElement);
124
- },
125
- modifiers: this.props.popperModifiers ? [...this.props.popperModifiers, ...stdModifiers] : stdModifiers
126
- });
127
- }
128
- this.previousTargetElement = targetElement;
129
- if (this.popper) {
130
- this.popper.update();
131
- }
132
- }
133
- render() {
134
- const {
135
- isOpen,
136
- onClose,
137
- placement,
138
- popperModifiers,
139
- portalClassName,
140
- portalStyle,
141
- renderTarget,
142
- target,
143
- ...rest
144
- } = this.props;
145
- const classNames = [getClassName('bpk-popover-portal')];
146
- if (portalClassName) {
147
- classNames.push(portalClassName);
148
- }
149
- return /*#__PURE__*/_jsxs(_Fragment, {
150
- children: [typeof target !== 'function' && target, /*#__PURE__*/_jsx(Portal, {
151
- beforeClose: this.beforeClose,
152
- className: classNames.join(' '),
153
- isOpen: isOpen,
154
- onClose: this.onClose,
155
- onRender: this.onRender,
156
- style: portalStyle,
157
- renderTarget: renderTarget,
158
- target: target,
159
- children: /*#__PURE__*/_jsx(BpkPopover, {
160
- onClose: this.onClose,
161
- ...rest
162
- })
163
- })]
164
- });
165
- }
166
- }
167
- export const propTypes = {
168
- // BpkPopover props - when migrating the popover to TS, we can import the type from BpkPopover
169
- children: PropTypes.node.isRequired,
170
- closeButtonText: PropTypes.string.isRequired,
171
- id: PropTypes.string.isRequired,
172
- label: PropTypes.string.isRequired,
173
- onClose: PropTypes.func.isRequired,
174
- className: PropTypes.string,
175
- closeButtonIcon: PropTypes.bool,
176
- closeButtonProps: PropTypes.object,
177
- labelAsTitle: PropTypes.bool,
178
- padded: PropTypes.bool,
179
- // BpkPopoverPortal additional props
180
- /**
181
- * In order to attach the popover to a regular DOM element, provide a function which returns it to `target`.
182
- * `target` can be a DOM element with a `ref` attached to it or a function that returns a DOM element.
183
- */
184
- target: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
185
- isOpen: PropTypes.bool.isRequired,
186
- placement: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
187
- portalStyle: PropTypes.object,
188
- portalClassName: PropTypes.string,
189
- renderTarget: PropTypes.func,
190
- /**
191
- * Please refer to the [documentation](https://popper.js.org/docs/v2/modifiers/) for the underlying positioning library "Popper.js".
192
- * You can achieve various behaviours such as allowing the popover to overflow the viewport etc.
193
- */
194
- popperModifiers: PropTypes.arrayOf(PropTypes.object)
195
- };
196
- export const defaultProps = {
197
- // BpkPopover props - when migrating the popover to TS, we can import the type from BpkPopover
198
- className: null,
199
- closeButtonIcon: true,
200
- closeButtonProps: null,
201
- labelAsTitle: false,
202
- padded: true,
203
- // BpkPopoverPortal additional props
204
- placement: 'bottom',
205
- portalStyle: null,
206
- portalClassName: null,
207
- renderTarget: null,
208
- popperModifiers: null
209
- };
210
- BpkPopoverPortal.propTypes = {
211
- ...propTypes
212
- };
213
- BpkPopoverPortal.defaultProps = {
214
- ...defaultProps
215
- };
216
- export default BpkPopoverPortal;
@@ -1,76 +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
- // This code is based on that from `a11y-focus-scope`.
20
- // Instead of completely preventing focus leaving the target element,
21
- // it only prevents it leaving due to keyboard events.
22
- // Clicks outside the target element will move focus as normal.
23
-
24
- import tabbable from 'tabbable';
25
- import focusin from 'focusin';
26
- let polyfilled = false;
27
- let focusTrapped = false;
28
- const init = element => {
29
- // lazily polyfill focusin for firefox
30
- if (!polyfilled) {
31
- focusin.polyfill();
32
- polyfilled = true;
33
- }
34
- const focus = () => {
35
- (tabbable(element)[0] || element).focus();
36
- };
37
- const enableFocusTrapping = () => {
38
- focusTrapped = true;
39
- };
40
- const disableFocusTrapping = () => {
41
- focusTrapped = false;
42
- };
43
- const checkFocus = event => {
44
- if (!focusTrapped) {
45
- return;
46
- }
47
- if (element !== event.target && !element.contains(event.target)) {
48
- focus();
49
- }
50
- };
51
- focus();
52
-
53
- // As we only want to trap focus for keyboard navigation, we enable focus trapping on keydown and disable it again on keyup.
54
- // This means that focus is trapped when pressing the tab key, but not trapped for other navigation events such as mouse clicks.
55
- document.addEventListener('keydown', enableFocusTrapping);
56
- document.addEventListener('focusin', checkFocus);
57
- document.addEventListener('keyup', disableFocusTrapping);
58
- return () => {
59
- document.removeEventListener('keydown', enableFocusTrapping);
60
- document.removeEventListener('focusin', checkFocus);
61
- document.removeEventListener('keyup', disableFocusTrapping);
62
- };
63
- };
64
- let teardownFn;
65
- const scopeFocus = element => {
66
- if (teardownFn) teardownFn();
67
- teardownFn = init(element);
68
- };
69
- const unscopeFocus = () => {
70
- if (teardownFn) teardownFn();
71
- teardownFn = null;
72
- };
73
- export default {
74
- scopeFocus,
75
- unscopeFocus
76
- };