@skyscanner/backpack-web 37.3.2 → 37.4.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.
|
@@ -7,6 +7,7 @@ export type BpkBackgroundImageProps = {
|
|
|
7
7
|
loading?: boolean;
|
|
8
8
|
src: string;
|
|
9
9
|
className?: string;
|
|
10
|
+
onError?: (() => void) | null;
|
|
10
11
|
onLoad?: (() => void) | null;
|
|
11
12
|
style?: {};
|
|
12
13
|
imageStyle?: CSSProperties;
|
|
@@ -18,12 +19,15 @@ declare class BpkBackgroundImage extends Component<BpkBackgroundImageProps> {
|
|
|
18
19
|
inView: boolean;
|
|
19
20
|
loading: boolean;
|
|
20
21
|
onLoad: null;
|
|
22
|
+
onError: null;
|
|
21
23
|
style: {};
|
|
22
24
|
imageStyle: {};
|
|
23
25
|
};
|
|
24
26
|
constructor(props: BpkBackgroundImageProps);
|
|
25
27
|
componentDidMount(): void;
|
|
26
28
|
UNSAFE_componentWillReceiveProps(newProps: BpkBackgroundImageProps): void;
|
|
29
|
+
componentDidUpdate(prevProps: BpkBackgroundImageProps): void;
|
|
30
|
+
onBackgroundImageError: () => void;
|
|
27
31
|
onBackgroundImageLoad: () => void;
|
|
28
32
|
getAspectRatio: () => number;
|
|
29
33
|
startImageLoad: () => void;
|
|
@@ -30,6 +30,7 @@ class BpkBackgroundImage extends Component {
|
|
|
30
30
|
inView: true,
|
|
31
31
|
loading: false,
|
|
32
32
|
onLoad: null,
|
|
33
|
+
onError: null,
|
|
33
34
|
style: {},
|
|
34
35
|
imageStyle: {}
|
|
35
36
|
};
|
|
@@ -47,6 +48,16 @@ class BpkBackgroundImage extends Component {
|
|
|
47
48
|
this.startImageLoad();
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
componentDidUpdate(prevProps) {
|
|
52
|
+
if (prevProps.src !== this.props.src) {
|
|
53
|
+
this.startImageLoad();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
onBackgroundImageError = () => {
|
|
57
|
+
if (this.props.onError) {
|
|
58
|
+
this.props.onError();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
50
61
|
onBackgroundImageLoad = () => {
|
|
51
62
|
if (this.props.onLoad) {
|
|
52
63
|
this.props.onLoad();
|
|
@@ -62,6 +73,7 @@ class BpkBackgroundImage extends Component {
|
|
|
62
73
|
startImageLoad = () => {
|
|
63
74
|
this.trackImg = new Image();
|
|
64
75
|
this.trackImg.src = this.props.src;
|
|
76
|
+
this.trackImg.onerror = this.onBackgroundImageError;
|
|
65
77
|
this.trackImg.onload = this.onBackgroundImageLoad;
|
|
66
78
|
};
|
|
67
79
|
render() {
|
|
@@ -23,8 +23,8 @@ The actual component that developers create (i.e. the default export from this p
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { cloneElement, useRef, useState, useEffect } from 'react';
|
|
26
|
-
import { arrow, FloatingArrow, FloatingPortal, offset, shift, useFloating, useHover, useInteractions, useRole } from '@floating-ui/react';
|
|
27
|
-
import { surfaceHighlightDay } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
|
|
26
|
+
import { arrow, FloatingArrow, FloatingPortal, offset, safePolygon, shift, useFloating, useFocus, useHover, useInteractions, useRole } from '@floating-ui/react';
|
|
27
|
+
import { surfaceHighlightDay, onePixelRem } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
|
|
28
28
|
import { TransitionInitialMount, cssModules } from "../../bpk-react-utils";
|
|
29
29
|
import { ARROW_ID, TOOLTIP_TYPES } from "./constants";
|
|
30
30
|
import STYLES from "./BpkTooltip.module.css";
|
|
@@ -39,12 +39,12 @@ const strokeWidth = 1;
|
|
|
39
39
|
const getArrowAlignment = placement => {
|
|
40
40
|
if (placement.includes('bottom')) {
|
|
41
41
|
return {
|
|
42
|
-
bottom:
|
|
42
|
+
bottom: `calc(100% - ${onePixelRem})`
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
if (placement.includes('top')) {
|
|
46
46
|
return {
|
|
47
|
-
top:
|
|
47
|
+
top: `calc(100% - ${onePixelRem})`
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
return undefined;
|
|
@@ -82,7 +82,8 @@ const BpkTooltip = ({
|
|
|
82
82
|
})]
|
|
83
83
|
});
|
|
84
84
|
const hover = useHover(context, {
|
|
85
|
-
mouseOnly: !hasTouchSupport() || !hideOnTouchDevices
|
|
85
|
+
mouseOnly: !hasTouchSupport() || !hideOnTouchDevices,
|
|
86
|
+
handleClose: safePolygon()
|
|
86
87
|
});
|
|
87
88
|
const role = useRole(context, {
|
|
88
89
|
role: 'tooltip'
|
|
@@ -90,7 +91,7 @@ const BpkTooltip = ({
|
|
|
90
91
|
const {
|
|
91
92
|
getFloatingProps,
|
|
92
93
|
getReferenceProps
|
|
93
|
-
} = useInteractions([hover, role]);
|
|
94
|
+
} = useInteractions([hover, role, useFocus(context)]);
|
|
94
95
|
const targetWithAccessibilityProps = /*#__PURE__*/cloneElement(target, {
|
|
95
96
|
tabIndex: '0',
|
|
96
97
|
'aria-label': ariaLabel,
|