@skyscanner/backpack-web 42.14.0 → 42.15.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.
@@ -1,3 +1,3 @@
1
1
  import type { Props } from './types';
2
- declare const BpkCarousel: ({ accessibilityLabels, bottom, images, initialImageIndex, onImageChanged, }: Props) => import("react/jsx-runtime").JSX.Element;
2
+ declare const BpkCarousel: ({ accessibilityLabels, bottom, images, initialImageIndex, onImageChanged, pageIndicatorVariant, showPageIndicatorNav, }: Props) => import("react/jsx-runtime").JSX.Element;
3
3
  export default BpkCarousel;
@@ -30,11 +30,14 @@ const BpkCarousel = ({
30
30
  bottom,
31
31
  images,
32
32
  initialImageIndex = 0,
33
- onImageChanged = null
33
+ onImageChanged = null,
34
+ pageIndicatorVariant = VARIANT.overImageSpaced,
35
+ showPageIndicatorNav
34
36
  }) => {
35
37
  const [shownImageIndex, updateShownImageIndex] = useState(initialImageIndex);
36
38
  const imagesRef = useRef([]);
37
39
  const isDesktop = useMediaQuery(BREAKPOINTS.ABOVE_TABLET);
40
+ const showNav = showPageIndicatorNav ?? isDesktop;
38
41
  const handleIndicatorClick = (e, newIndex) => {
39
42
  e.stopPropagation();
40
43
  let target = newIndex;
@@ -59,12 +62,12 @@ const BpkCarousel = ({
59
62
  children: /*#__PURE__*/_jsx(BpkPageIndicator, {
60
63
  currentIndex: shownImageIndex,
61
64
  totalIndicators: images.length,
62
- variant: VARIANT.overImageSpaced,
65
+ variant: pageIndicatorVariant,
63
66
  indicatorLabel: accessibilityLabels.indicatorLabel ?? "Go to slide",
64
67
  prevNavLabel: accessibilityLabels.prevNavLabel ?? "Previous slide",
65
68
  nextNavLabel: accessibilityLabels.nextNavLabel ?? "Next slide",
66
- showNav: isDesktop,
67
- onClick: isDesktop ? handleIndicatorClick : () => {}
69
+ showNav: showNav,
70
+ onClick: showNav ? handleIndicatorClick : () => {}
68
71
  })
69
72
  })]
70
73
  });
@@ -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-carousel{position:relative;width:100%;height:100%}.bpk-carousel__page-indicator-over-image{position:absolute;right:0;bottom:.25rem;left:0;display:flex;margin:auto 1rem;justify-content:center;overflow:clip}
18
+ .bpk-carousel{position:relative;width:100%;height:100%}.bpk-carousel__page-indicator-over-image{position:absolute;right:0;bottom:.25rem;left:0;display:flex;margin:auto 1rem;justify-content:center}
@@ -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-carousel-image{display:inline-flex;width:100%;min-width:0;height:100%;min-height:0;justify-content:center;scroll-snap-align:start;scroll-snap-stop:always;isolation:isolate}.bpk-carousel-image img{max-width:100%;max-height:100%;object-fit:initial}
18
+ .bpk-carousel-image{display:inline-flex;width:100%;min-width:0;height:100%;min-height:0;justify-content:center;scroll-snap-align:start;scroll-snap-stop:always;isolation:isolate}.bpk-carousel-image img{display:block;max-width:100%;max-height:100%;object-fit:initial}
@@ -1,10 +1,12 @@
1
1
  import type { ReactNode } from "react";
2
+ import type { VARIANT } from '../../bpk-component-page-indicator';
2
3
  export type OnImageChangedHandler = ((shownImageIndex: number) => void) | null | undefined;
3
4
  export type AccessibilityLabels = {
4
5
  indicatorLabel?: string;
5
6
  prevNavLabel?: string;
6
7
  nextNavLabel?: string;
7
8
  };
9
+ export type PageIndicatorVariant = typeof VARIANT.overImageSpaced | typeof VARIANT.carousel;
8
10
  export type Props = {
9
11
  images: ReactNode[];
10
12
  initialImageIndex?: number;
@@ -14,4 +16,10 @@ export type Props = {
14
16
  */
15
17
  bottom?: number;
16
18
  accessibilityLabels?: AccessibilityLabels;
19
+ pageIndicatorVariant?: PageIndicatorVariant;
20
+ /**
21
+ * Force the page indicator's nav buttons on or off.
22
+ * When omitted, the nav buttons are shown on desktop breakpoints only.
23
+ */
24
+ showPageIndicatorNav?: boolean;
17
25
  };
@@ -1,11 +1,9 @@
1
1
  import type { MouseEvent } from 'react';
2
2
  import { DIRECTIONS } from './NavButton';
3
- export declare const VARIANT: {
4
- readonly default: "default";
5
- readonly overImage: "overImage";
6
- readonly overImageSpaced: "overImageSpaced";
7
- };
8
- type Variant = (typeof VARIANT)[keyof typeof VARIANT];
3
+ import { VARIANT } from './common-types';
4
+ import type { Variant } from './common-types';
5
+ export { VARIANT };
6
+ export type { Variant };
9
7
  type Direction = (typeof DIRECTIONS)[keyof typeof DIRECTIONS];
10
8
  export type Props = {
11
9
  indicatorLabel?: string;
@@ -19,16 +19,13 @@
19
19
  import { BUTTON_TYPES } from "../../bpk-component-button";
20
20
  import { cssModules, getDataComponentAttribute } from "../../bpk-react-utils";
21
21
  import NavButton, { DIRECTIONS } from "./NavButton";
22
+ import { VARIANT } from "./common-types";
22
23
  import STYLES from "./BpkPageIndicator.module.css";
23
24
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
25
  const getClassName = cssModules(STYLES);
25
26
  const DISPLAYED_TOTAL = 5;
26
27
  const START_SCROLL_INDEX = Math.floor(DISPLAYED_TOTAL / 2);
27
- export const VARIANT = {
28
- default: 'default',
29
- overImage: 'overImage',
30
- overImageSpaced: 'overImageSpaced'
31
- };
28
+ export { VARIANT };
32
29
  const BpkPageIndicator = ({
33
30
  className = undefined,
34
31
  currentIndex,
@@ -50,7 +47,7 @@ const BpkPageIndicator = ({
50
47
  '--scroll-index': totalIndicators > DISPLAYED_TOTAL ? Math.min(currentIndex - START_SCROLL_INDEX, totalIndicators - DISPLAYED_TOTAL) : 0
51
48
  };
52
49
  return /*#__PURE__*/_jsx("div", {
53
- className: variant === VARIANT.overImageSpaced ? getClassName('bpk-page-indicator-fullWidth__container') : className,
50
+ className: variant === VARIANT.overImageSpaced || variant === VARIANT.carousel ? getClassName('bpk-page-indicator-fullWidth__container') : className,
54
51
  "aria-hidden": isInteractive ? 'false' : 'true',
55
52
  "data-testid": "indicator-container",
56
53
  children: /*#__PURE__*/_jsxs("div", {
@@ -59,10 +56,11 @@ const BpkPageIndicator = ({
59
56
  children: [showNav && /*#__PURE__*/_jsx(NavButton, {
60
57
  currentIndex: currentIndex,
61
58
  onClick: onClick,
62
- disabled: variant === VARIANT.overImageSpaced ? totalIndicators <= 1 : currentIndex === 0 || totalIndicators <= 1,
59
+ disabled: variant === VARIANT.overImageSpaced || variant === VARIANT.carousel ? totalIndicators <= 1 : currentIndex === 0 || totalIndicators <= 1,
63
60
  direction: DIRECTIONS.PREV,
64
61
  ariaLabel: prevNavLabel,
65
- type: variant === VARIANT.overImageSpaced ? BUTTON_TYPES.secondaryOnDark : BUTTON_TYPES.link
62
+ variant: variant,
63
+ type: variant === VARIANT.overImageSpaced || variant === VARIANT.carousel ? BUTTON_TYPES.secondaryOnDark : BUTTON_TYPES.link
66
64
  }), /*#__PURE__*/_jsx("div", {
67
65
  className: getClassName('bpk-page-indicator__container'),
68
66
  children: /*#__PURE__*/_jsx("div", {
@@ -85,10 +83,11 @@ const BpkPageIndicator = ({
85
83
  }), showNav && /*#__PURE__*/_jsx(NavButton, {
86
84
  currentIndex: currentIndex,
87
85
  onClick: onClick,
88
- disabled: variant === VARIANT.overImageSpaced ? totalIndicators <= 1 : currentIndex === totalIndicators - 1 || totalIndicators <= 1,
86
+ disabled: variant === VARIANT.overImageSpaced || variant === VARIANT.carousel ? totalIndicators <= 1 : currentIndex === totalIndicators - 1 || totalIndicators <= 1,
89
87
  ariaLabel: nextNavLabel,
90
88
  direction: DIRECTIONS.NEXT,
91
- type: variant === VARIANT.overImageSpaced ? BUTTON_TYPES.secondaryOnDark : BUTTON_TYPES.link
89
+ variant: variant,
90
+ type: variant === VARIANT.overImageSpaced || variant === VARIANT.carousel ? BUTTON_TYPES.secondaryOnDark : BUTTON_TYPES.link
92
91
  })]
93
92
  })
94
93
  });
@@ -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-page-indicator-fullWidth__container{width:100%}.bpk-page-indicator{display:flex;width:100%;justify-content:center;align-items:center}.bpk-page-indicator__showNav{justify-content:space-between}.bpk-page-indicator__container{max-width:5rem;min-height:.5rem;overflow:hidden}.bpk-page-indicator__indicators-container{--direction: -1;transform:translateX(calc(var(--direction) * var(--scroll-index, 0) * 1rem));transition:transform 200ms ease-in-out;white-space:nowrap}html[dir=rtl] .bpk-page-indicator__indicators-container{--direction: 1}.bpk-page-indicator__indicator{display:inline-block;width:.5rem;height:.5rem;padding:0;border:none;border-radius:50%;margin-inline:.25rem}.bpk-page-indicator__indicator:hover{cursor:pointer}.bpk-page-indicator__indicator--default{background-color:#c1c7cf}.bpk-page-indicator__indicator--overImage,.bpk-page-indicator__indicator--overImageSpaced{background-color:hsla(0,0%,100%,.5)}.bpk-page-indicator__indicator--active-default{background-color:#626971;pointer-events:none}.bpk-page-indicator__indicator--active-overImage,.bpk-page-indicator__indicator--active-overImageSpaced{background-color:#fff;pointer-events:none}
18
+ .bpk-page-indicator-fullWidth__container{width:100%}.bpk-page-indicator{display:flex;width:100%;justify-content:center;align-items:center}.bpk-page-indicator__showNav{justify-content:space-between}.bpk-page-indicator__container{max-width:5rem;min-height:.5rem;overflow:hidden}.bpk-page-indicator__indicators-container{--direction: -1;transform:translateX(calc(var(--direction) * var(--scroll-index, 0) * 1rem));transition:transform 200ms ease-in-out;white-space:nowrap}html[dir=rtl] .bpk-page-indicator__indicators-container{--direction: 1}.bpk-page-indicator__indicator{display:inline-block;width:.5rem;height:.5rem;padding:0;border:none;border-radius:50%;margin-inline:.25rem}.bpk-page-indicator__indicator:hover{cursor:pointer}.bpk-page-indicator__indicator--default{background-color:#c1c7cf}.bpk-page-indicator__indicator--overImage,.bpk-page-indicator__indicator--overImageSpaced,.bpk-page-indicator__indicator--carousel{background-color:hsla(0,0%,100%,.5)}.bpk-page-indicator__indicator--active-default{background-color:#626971;pointer-events:none}.bpk-page-indicator__indicator--active-overImage,.bpk-page-indicator__indicator--active-overImageSpaced,.bpk-page-indicator__indicator--active-carousel{background-color:#fff;pointer-events:none}.bpk-page-indicator__nav-carousel{--bpk-button-border-radius: 50%;--bpk-button-secondary-on-dark-background-color: rgba(255, 255, 255, 0.5);--bpk-button-secondary-on-dark-hover-background-color: rgba(255, 255, 255, 0.8);--bpk-button-secondary-on-dark-active-background-color: rgba(255, 255, 255, 0.8);--bpk-button-secondary-on-dark-text-color: rgb(22, 22, 22);--bpk-button-secondary-on-dark-hover-text-color: rgb(22, 22, 22);--bpk-button-secondary-on-dark-active-text-color: rgb(22, 22, 22)}.bpk-page-indicator__nav-carousel-button{display:inline-flex;width:2rem;height:2rem;min-height:2rem;padding:0;justify-content:center;align-items:center}
@@ -1,5 +1,6 @@
1
1
  import type { MouseEvent } from 'react';
2
2
  import { BUTTON_TYPES } from '../../bpk-component-button';
3
+ import type { Variant } from './common-types';
3
4
  export declare const DIRECTIONS: {
4
5
  readonly PREV: "PREV";
5
6
  readonly INDICATORS: "INDICATORS";
@@ -14,6 +15,7 @@ type Props = {
14
15
  disabled?: boolean;
15
16
  onClick?: (event: MouseEvent<HTMLButtonElement>, newIndex: number, direction: Direction) => void;
16
17
  type?: ButtonType;
18
+ variant?: Variant;
17
19
  };
18
- declare const NavButton: ({ ariaLabel, currentIndex, direction, disabled, onClick, type, }: Props) => import("react/jsx-runtime").JSX.Element;
20
+ declare const NavButton: ({ ariaLabel, currentIndex, direction, disabled, onClick, type, variant, }: Props) => import("react/jsx-runtime").JSX.Element;
19
21
  export default NavButton;
@@ -17,36 +17,58 @@
17
17
  */
18
18
 
19
19
  import BpkButton, { BUTTON_TYPES } from "../../bpk-component-button";
20
- import { withLargeButtonAlignment, withRtlSupport } from "../../bpk-component-icon";
21
- import LeftArrowIcon from "../../bpk-component-icon/lg/chevron-left";
22
- import RightArrowIcon from "../../bpk-component-icon/lg/chevron-right";
20
+ import { withButtonAlignment, withRtlSupport } from "../../bpk-component-icon";
21
+ import SmallLeftArrowIcon from "../../bpk-component-icon/sm/chevron-left";
22
+ import SmallRightArrowIcon from "../../bpk-component-icon/sm/chevron-right";
23
+ import { cssModules } from "../../bpk-react-utils";
24
+ import { VARIANT } from "./common-types";
25
+ import STYLES from "./BpkPageIndicator.module.css";
23
26
  import { jsx as _jsx } from "react/jsx-runtime";
27
+ const getClassName = cssModules(STYLES);
24
28
  export const DIRECTIONS = {
25
29
  PREV: 'PREV',
26
30
  INDICATORS: 'INDICATORS',
27
31
  NEXT: 'NEXT'
28
32
  };
29
- const AlignedLeftArrowIcon = withLargeButtonAlignment(withRtlSupport(LeftArrowIcon));
30
- const AlignedRightArrowIcon = withLargeButtonAlignment(withRtlSupport(RightArrowIcon));
33
+ const AlignedLeftArrowIcon = withButtonAlignment(withRtlSupport(SmallLeftArrowIcon));
34
+ const AlignedRightArrowIcon = withButtonAlignment(withRtlSupport(SmallRightArrowIcon));
35
+ const RtlSmallLeftArrowIcon = withRtlSupport(SmallLeftArrowIcon);
36
+ const RtlSmallRightArrowIcon = withRtlSupport(SmallRightArrowIcon);
31
37
  const NavButton = ({
32
38
  ariaLabel,
33
39
  currentIndex,
34
40
  direction,
35
41
  disabled = false,
36
42
  onClick = () => {},
37
- type = BUTTON_TYPES.link
38
- }) => /*#__PURE__*/_jsx(BpkButton, {
39
- iconOnly: true,
40
- type: type,
41
- onClick: e => {
42
- if (direction === DIRECTIONS.PREV) {
43
- onClick(e, currentIndex - 1, direction);
44
- } else {
45
- onClick(e, currentIndex + 1, direction);
46
- }
47
- },
48
- "aria-label": ariaLabel,
49
- disabled: disabled,
50
- children: direction === DIRECTIONS.PREV ? /*#__PURE__*/_jsx(AlignedLeftArrowIcon, {}) : /*#__PURE__*/_jsx(AlignedRightArrowIcon, {})
51
- });
43
+ type = BUTTON_TYPES.link,
44
+ variant
45
+ }) => {
46
+ const isCarousel = variant === VARIANT.carousel;
47
+ const PrevIcon = isCarousel ? RtlSmallLeftArrowIcon : AlignedLeftArrowIcon;
48
+ const NextIcon = isCarousel ? RtlSmallRightArrowIcon : AlignedRightArrowIcon;
49
+ const button = /*#__PURE__*/_jsx(BpkButton, {
50
+ iconOnly: true,
51
+ type: type
52
+ // eslint-disable-next-line @skyscanner/rules/forbid-component-props
53
+ ,
54
+ className: isCarousel ? getClassName('bpk-page-indicator__nav-carousel-button') : undefined,
55
+ onClick: e => {
56
+ if (direction === DIRECTIONS.PREV) {
57
+ onClick(e, currentIndex - 1, direction);
58
+ } else {
59
+ onClick(e, currentIndex + 1, direction);
60
+ }
61
+ },
62
+ "aria-label": ariaLabel,
63
+ disabled: disabled,
64
+ children: direction === DIRECTIONS.PREV ? /*#__PURE__*/_jsx(PrevIcon, {}) : /*#__PURE__*/_jsx(NextIcon, {})
65
+ });
66
+ if (isCarousel) {
67
+ return /*#__PURE__*/_jsx("span", {
68
+ className: getClassName('bpk-page-indicator__nav-carousel'),
69
+ children: button
70
+ });
71
+ }
72
+ return button;
73
+ };
52
74
  export default NavButton;
@@ -0,0 +1,7 @@
1
+ export declare const VARIANT: {
2
+ readonly default: "default";
3
+ readonly overImage: "overImage";
4
+ readonly overImageSpaced: "overImageSpaced";
5
+ readonly carousel: "carousel";
6
+ };
7
+ export type Variant = (typeof VARIANT)[keyof typeof VARIANT];
@@ -0,0 +1,24 @@
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
+ export const VARIANT = {
20
+ default: 'default',
21
+ overImage: 'overImage',
22
+ overImageSpaced: 'overImageSpaced',
23
+ carousel: 'carousel'
24
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "42.14.0",
3
+ "version": "42.15.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "@radix-ui/react-compose-refs": "^1.1.1",
29
29
  "@radix-ui/react-slider": "1.3.5",
30
30
  "@react-google-maps/api": "^2.19.3",
31
- "@skyscanner/bpk-foundations-web": "^24.4.1",
31
+ "@skyscanner/bpk-foundations-web": "^24.5.0",
32
32
  "@skyscanner/bpk-svgs": "^20.11.0",
33
33
  "tabbable": "^6.4.0",
34
34
  "d3-path": "^3.1.0",