@skyscanner/backpack-web 34.10.0 → 34.11.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-component-accordion/src/BpkAccordion.js +1 -1
- package/bpk-component-accordion/src/BpkAccordionItem.js +2 -2
- package/bpk-component-carousel/src/utils.js +13 -3
- package/bpk-component-carousel/src/utils.test.js +12 -0
- package/bpk-component-map/src/BpkIconMarker.module.css +1 -1
- package/bpk-component-mobile-scroll-container/src/BpkMobileScrollContainer.js +18 -14
- package/bpk-component-popover/src/BpkPopover.d.ts +2 -1
- package/bpk-component-popover/src/BpkPopover.js +6 -3
- package/package.json +1 -1
|
@@ -86,7 +86,7 @@ const BpkAccordionItem = props => {
|
|
|
86
86
|
_jsxs("div", {
|
|
87
87
|
id: id,
|
|
88
88
|
...rest,
|
|
89
|
-
children: [/*#__PURE__*/_jsx("
|
|
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("
|
|
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
|
-
|
|
22
|
-
const element = imagesRef.current[
|
|
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
|
-
}
|
|
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
|
+
});
|
|
@@ -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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
|
@@ -93,15 +94,15 @@ const BpkPopover = ({
|
|
|
93
94
|
getFloatingProps,
|
|
94
95
|
getReferenceProps
|
|
95
96
|
} = useInteractions([click, dismiss]);
|
|
96
|
-
const targetClick = target
|
|
97
|
-
const referenceProps = getReferenceProps({
|
|
97
|
+
const targetClick = target?.props?.onClick;
|
|
98
|
+
const referenceProps = targetClick ? getReferenceProps({
|
|
98
99
|
onClick: event => {
|
|
99
100
|
if (targetClick) {
|
|
100
101
|
event.stopPropagation();
|
|
101
102
|
targetClick(event);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
|
-
});
|
|
105
|
+
}) : getReferenceProps();
|
|
105
106
|
const targetElement = /*#__PURE__*/isValidElement(target) ? ( /*#__PURE__*/cloneElement(target, {
|
|
106
107
|
...referenceProps,
|
|
107
108
|
// @ts-ignore - we're adding a popover ref to the target element so we can position the popover relative to it
|
|
@@ -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", {
|