@skyscanner/backpack-web 34.10.1 → 34.12.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.
@@ -38,7 +38,7 @@ const BpkAccordion = props => {
38
38
  onDark,
39
39
  divider
40
40
  },
41
- children: /*#__PURE__*/_jsx("dl", {
41
+ children: /*#__PURE__*/_jsx("div", {
42
42
  className: classNames,
43
43
  ...rest,
44
44
  children: children
@@ -86,7 +86,7 @@ const BpkAccordionItem = props => {
86
86
  _jsxs("div", {
87
87
  id: id,
88
88
  ...rest,
89
- children: [/*#__PURE__*/_jsx("dt", {
89
+ children: [/*#__PURE__*/_jsx("div", {
90
90
  className: titleClassNames.join(' '),
91
91
  children: /*#__PURE__*/_jsx("button", {
92
92
  type: "button",
@@ -109,7 +109,7 @@ const BpkAccordionItem = props => {
109
109
  })]
110
110
  })
111
111
  })
112
- }), /*#__PURE__*/_jsx("dd", {
112
+ }), /*#__PURE__*/_jsx("div", {
113
113
  id: contentId,
114
114
  className: contentClassNames.join(' '),
115
115
  children: /*#__PURE__*/_jsx(AnimateHeight, {
@@ -18,15 +18,25 @@
18
18
 
19
19
  import { useEffect, useMemo, useRef } from 'react';
20
20
  export function useScrollToInitialImage(initialImageIndex, imagesRef) {
21
- useEffect(() => {
22
- const element = imagesRef.current[initialImageIndex];
21
+ const handleIntersecting = index => {
22
+ const element = imagesRef.current[index];
23
23
  if (element) {
24
24
  element.scrollIntoView({
25
25
  block: 'nearest',
26
26
  inline: 'start'
27
27
  });
28
28
  }
29
- }, [initialImageIndex, imagesRef]);
29
+ };
30
+ const observe = useIntersectionObserver(handleIntersecting, {
31
+ root: null,
32
+ threshold: 0.1
33
+ });
34
+ useEffect(() => {
35
+ const element = imagesRef.current[initialImageIndex];
36
+ if (element) {
37
+ observe(element);
38
+ }
39
+ }, [initialImageIndex, imagesRef, observe]);
30
40
  }
31
41
  export function useIntersectionObserver(onIntersecting, {
32
42
  root,
@@ -0,0 +1,12 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import { useScrollToInitialImage } from "./utils";
3
+ describe('useScrollToInitialImage', () => {
4
+ it('should scroll to initial image on mount', () => {
5
+ const imagesRef = {
6
+ current: [document.createElement('div'), document.createElement('div')]
7
+ };
8
+ const initialImageIndex = 0;
9
+ renderHook(() => useScrollToInitialImage(initialImageIndex, imagesRef));
10
+ expect(imagesRef.current[initialImageIndex].scrollIntoView).toHaveBeenCalledTimes(1);
11
+ });
12
+ });
@@ -0,0 +1,4 @@
1
+ import BpkInsetBanner, { type Props as BpkInsetBannerProps, VARIANT } from './src/BpkInsetBanner';
2
+ export type { BpkInsetBannerProps };
3
+ export { VARIANT };
4
+ export default BpkInsetBanner;
@@ -0,0 +1,21 @@
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 BpkInsetBanner, { VARIANT } from "./src/BpkInsetBanner";
20
+ export { VARIANT };
21
+ export default BpkInsetBanner;
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ export declare const VARIANT: {
3
+ onLight: string;
4
+ onDark: string;
5
+ };
6
+ export type Props = {
7
+ accessibilityLabel?: string;
8
+ backgroundColor?: string;
9
+ body?: {
10
+ text: string;
11
+ link?: string;
12
+ linkText?: string;
13
+ };
14
+ callToAction?: {
15
+ text?: string;
16
+ };
17
+ logo?: string;
18
+ subheadline?: string;
19
+ title?: string;
20
+ variant?: (typeof VARIANT)[keyof typeof VARIANT];
21
+ };
22
+ declare const BpkInsetBanner: ({ accessibilityLabel, backgroundColor, body, callToAction, logo, subheadline, title, variant, }: Props) => JSX.Element;
23
+ export default BpkInsetBanner;
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Backpack - Skyscanner's Design System
3
+ *
4
+ * Copyright 2016 Skyscanner Ltd
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ import { surfaceHighlightDay } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
19
+ import BpkText, { TEXT_STYLES } from "../../bpk-component-text/src/BpkText";
20
+ import { cssModules } from "../../bpk-react-utils";
21
+ import STYLES from "./BpkInsetBanner.module.css";
22
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
+ const getClassName = cssModules(STYLES);
24
+ export const VARIANT = {
25
+ onLight: 'on-light',
26
+ onDark: 'on-dark'
27
+ };
28
+ const BpkInsetBanner = ({
29
+ accessibilityLabel,
30
+ backgroundColor = surfaceHighlightDay,
31
+ body,
32
+ callToAction,
33
+ logo,
34
+ subheadline,
35
+ title,
36
+ variant = VARIANT.onLight
37
+ }) => {
38
+ const classNames = getClassName('bpk-inset-banner', `bpk-inset-banner--${variant}`, body && 'bpk-inset-banner--with-body');
39
+ return /*#__PURE__*/_jsxs("div", {
40
+ children: [/*#__PURE__*/_jsxs("div", {
41
+ "aria-label": accessibilityLabel,
42
+ className: classNames,
43
+ style: {
44
+ backgroundColor
45
+ },
46
+ children: [/*#__PURE__*/_jsxs("div", {
47
+ className: getClassName('bpk-inset-banner--content-container'),
48
+ children: [logo && /*#__PURE__*/_jsx("img", {
49
+ className: getClassName('bpk-inset-banner--image'),
50
+ src: logo,
51
+ alt: "",
52
+ "aria-hidden": true
53
+ }), /*#__PURE__*/_jsxs("div", {
54
+ className: getClassName('bpk-inset-banner--text-container'),
55
+ children: [/*#__PURE__*/_jsx(BpkText, {
56
+ textStyle: TEXT_STYLES.label2,
57
+ children: title
58
+ }), /*#__PURE__*/_jsx(BpkText, {
59
+ textStyle: TEXT_STYLES.caption,
60
+ children: subheadline
61
+ })]
62
+ })]
63
+ }), /*#__PURE__*/_jsx("div", {
64
+ className: getClassName('bpk-inset-banner--cta-container'),
65
+ children: callToAction?.text && /*#__PURE__*/_jsx(BpkText, {
66
+ textStyle: TEXT_STYLES.caption,
67
+ children: callToAction.text
68
+ })
69
+ })]
70
+ }), body && /*#__PURE__*/_jsxs("div", {
71
+ className: getClassName('bpk-inset-banner-body-container'),
72
+ children: [/*#__PURE__*/_jsx(BpkText, {
73
+ textStyle: TEXT_STYLES.caption,
74
+ children: body.text
75
+ }), body.link && body.linkText && /*#__PURE__*/_jsx("a", {
76
+ href: body.link,
77
+ className: getClassName('bpk-inset-banner-body-container--link-text'),
78
+ children: /*#__PURE__*/_jsx(BpkText, {
79
+ textStyle: TEXT_STYLES.caption,
80
+ children: body.linkText
81
+ })
82
+ })]
83
+ })]
84
+ });
85
+ };
86
+ export default BpkInsetBanner;
@@ -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-inset-banner{display:flex;padding:.5rem 1rem;justify-content:space-between;border-radius:.5rem}.bpk-inset-banner--with-body{border-radius:.5rem .5rem 0 0}.bpk-inset-banner--on-light{color:#161616;fill:#161616}.bpk-inset-banner--on-dark{color:#fff;fill:#fff}.bpk-inset-banner--content-container{display:flex;align-items:center}.bpk-inset-banner--image{max-height:2rem;object-fit:contain;padding-inline-end:1rem}@media(max-width: 32rem){.bpk-inset-banner--image{max-height:1.5rem}}.bpk-inset-banner--text-container{display:flex;flex-direction:column}.bpk-inset-banner--cta-container{display:flex;align-items:center}.bpk-inset-banner-body-container{display:flex;padding:1rem;flex-direction:column;border-radius:0 0 .5rem .5rem;background-color:#eff3f8;color:#161616}.bpk-inset-banner-body-container--link-text{color:#0062e3;text-decoration:none}.bpk-no-touch-support .bpk-inset-banner-body-container--link-text:hover:not(:active):not(:disabled){color:#024daf}:global(.bpk-no-touch-support) .bpk-inset-banner-body-container--link-text:hover:not(:active):not(:disabled){color:#024daf}
@@ -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-icon-marker__wrapper{position:absolute;top:-32px;left:-13px;z-index:1;padding:16px 13px;border:none;background:none}.bpk-icon-marker__wrapper--selected{top:-40px;left:-16px;z-index:2;padding:20px 16px}.bpk-icon-marker__icon{position:absolute;top:4.8px;left:5px;color:#fff}.bpk-icon-marker__icon>svg{position:absolute;width:16px !important;height:16px !important;fill:currentcolor}.bpk-icon-marker__icon--interactive{cursor:pointer}.bpk-icon-marker__icon--selected{top:8px;left:8px;color:#fff;color:var(--bpk-icon-marker-default-selected-color, rgb(255, 255, 255))}
18
+ .bpk-icon-marker__wrapper{position:absolute;top:-32px;left:-13px;z-index:1;padding:16px 13px;border:none;background:none}.bpk-icon-marker__wrapper--selected{top:-40px;left:-16px;z-index:2;padding:20px 16px}.bpk-icon-marker__icon{position:absolute;top:4.8px;left:5px;color:#fff}html[dir=rtl] .bpk-icon-marker__icon{transform:scaleX(-1)}.bpk-icon-marker__icon>svg{position:absolute;width:16px !important;height:16px !important;fill:currentcolor}.bpk-icon-marker__icon--interactive{cursor:pointer}.bpk-icon-marker__icon--selected{top:8px;left:8px;color:#fff;color:var(--bpk-icon-marker-default-selected-color, rgb(255, 255, 255))}html[dir=rtl] .bpk-icon-marker__icon--selected{transform:scaleX(-1)}
@@ -94,25 +94,29 @@ class BpkMobileScrollContainer extends Component {
94
94
  this.setScrollIndicatorClassName();
95
95
  }, 100);
96
96
  setScrollIndicatorClassName = () => {
97
- const classNames = computeScrollIndicatorClassName(this.scrollerEl, this.props.leadingIndicatorClassName, this.props.trailingIndicatorClassName);
98
- if (!classNames) {
99
- return;
100
- }
101
- this.setState(() => ({
102
- scrollIndicatorClassName: classNames.join(' ')
103
- }));
97
+ requestAnimationFrame(() => {
98
+ const classNames = computeScrollIndicatorClassName(this.scrollerEl, this.props.leadingIndicatorClassName, this.props.trailingIndicatorClassName);
99
+ if (!classNames) {
100
+ return;
101
+ }
102
+ this.setState(() => ({
103
+ scrollIndicatorClassName: classNames.join(' ')
104
+ }));
105
+ });
104
106
  };
105
107
  setScrollBarAwareHeight = () => {
106
108
  if (this.props.showScrollbar) {
107
109
  return;
108
110
  }
109
- const computedHeight = computeScrollBarAwareHeight(this.scrollerEl, this.innerEl);
110
- if (!computedHeight) {
111
- return;
112
- }
113
- this.setState(() => ({
114
- computedHeight
115
- }));
111
+ requestAnimationFrame(() => {
112
+ const computedHeight = computeScrollBarAwareHeight(this.scrollerEl, this.innerEl);
113
+ if (!computedHeight) {
114
+ return;
115
+ }
116
+ this.setState(() => ({
117
+ computedHeight
118
+ }));
119
+ });
116
120
  };
117
121
  render() {
118
122
  const classNames = [getClassName('bpk-mobile-scroll-container')];
@@ -31,6 +31,7 @@ export type Props = CloseButtonProps & {
31
31
  closeButtonLabel?: string;
32
32
  actionText?: string;
33
33
  onAction?: () => void;
34
+ renderTarget?: () => HTMLElement | HTMLElement | null;
34
35
  };
35
- declare const BpkPopover: ({ actionText, children, className, closeButtonIcon, closeButtonLabel, closeButtonProps, closeButtonText, id, isOpen, label, labelAsTitle, onAction, onClose, padded, placement, showArrow, target, ...rest }: Props) => JSX.Element;
36
+ declare const BpkPopover: ({ actionText, children, className, closeButtonIcon, closeButtonLabel, closeButtonProps, closeButtonText, id, isOpen, label, labelAsTitle, onAction, onClose, padded, placement, renderTarget, showArrow, target, ...rest }: Props) => JSX.Element;
36
37
  export default BpkPopover;
@@ -61,6 +61,7 @@ const BpkPopover = ({
61
61
  onClose,
62
62
  padded = true,
63
63
  placement = 'bottom',
64
+ renderTarget = () => null,
64
65
  showArrow = true,
65
66
  target,
66
67
  ...rest
@@ -114,8 +115,10 @@ const BpkPopover = ({
114
115
  const classNames = getClassName('bpk-popover', className);
115
116
  const bodyClassNames = getClassName(padded && 'bpk-popover__body--padded');
116
117
  const labelId = `bpk-popover-label-${id}`;
118
+ const renderElement = typeof renderTarget === 'function' ? renderTarget() : renderTarget;
117
119
  return /*#__PURE__*/_jsxs(_Fragment, {
118
120
  children: [targetElement, isOpenState && /*#__PURE__*/_jsx(FloatingPortal, {
121
+ root: renderElement,
119
122
  children: /*#__PURE__*/_jsx(FloatingFocusManager, {
120
123
  context: context,
121
124
  children: /*#__PURE__*/_jsx("div", {
@@ -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-segmented-control-group{display:flex;flex-wrap:nowrap;overflow:hidden;border-radius:.5rem}.bpk-segmented-control-group-shadow{box-shadow:0px 1px 3px 0px rgba(37,32,31,.3)}.bpk-segmented-control{min-height:2rem;padding:.5rem 1rem;flex:1;border:none;text-overflow:ellipsis;cursor:pointer;overflow:hidden;font-size:.875rem;line-height:1.25rem;font-weight:700}.bpk-segmented-control--canvas-default{background-color:#eff3f8;color:#161616}.bpk-segmented-control--canvas-default-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--canvas-contrast{background-color:#fff;color:#161616}.bpk-segmented-control--canvas-contrast-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--surface-default{background-color:#eff3f8;color:#161616}.bpk-segmented-control--surface-default-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--surface-contrast{background-color:rgba(255,255,255,.1);color:#fff}.bpk-segmented-control--surface-contrast-selected{background-color:#024daf;color:#fff}.bpk-segmented-control:not(:first-of-type,[class*=selected]){border-left:.0625rem solid #c1c7cf}.bpk-segmented-control--surface-contrast:not(:first-of-type,[class*=selected]){border-left:.0625rem solid rgba(255,255,255,.5)}.bpk-segmented-control[class*=rightOfOption]{border-left:none}
18
+ .bpk-segmented-control-group{display:flex;flex-wrap:nowrap;overflow:hidden;border-radius:.5rem}.bpk-segmented-control-group-shadow{box-shadow:0px 1px 3px 0px rgba(37,32,31,.3)}.bpk-segmented-control{min-height:2rem;padding:.5rem 1rem;flex:1;border:none;text-overflow:ellipsis;cursor:pointer;overflow:hidden;font-size:.875rem;line-height:1.25rem;font-weight:700}.bpk-segmented-control--canvas-default{background-color:#eff3f8;color:#161616}.bpk-segmented-control--canvas-default-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--canvas-contrast{background-color:#fff;color:#161616}.bpk-segmented-control--canvas-contrast-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--surface-default{background-color:#eff3f8;color:#161616}.bpk-segmented-control--surface-default-selected{background-color:#05203c;color:#fff}.bpk-segmented-control--surface-contrast{background-color:rgba(255,255,255,.1);color:#fff}.bpk-segmented-control--surface-contrast-selected{background-color:#024daf;color:#fff}.bpk-segmented-control:not(:first-of-type,[class*=selected]){border-inline-start:.0625rem solid #c1c7cf}.bpk-segmented-control--surface-contrast:not(:first-of-type,[class*=selected]){border-inline-start:.0625rem solid rgba(255,255,255,.5)}.bpk-segmented-control[class*=rightOfOption]{border-inline-start:none}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "34.10.1",
3
+ "version": "34.12.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",