@skyscanner/backpack-web 34.10.1 → 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.
@@ -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
+ });
@@ -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", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "34.10.1",
3
+ "version": "34.11.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",