@skyscanner/backpack-web 36.17.0 → 36.17.1

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/README.md CHANGED
@@ -68,6 +68,7 @@ To contribute please see [contributing.md](CONTRIBUTING.md).
68
68
  [`bpk-component-panel`](/packages/bpk-component-panel)
69
69
  [`bpk-component-phone-input`](/packages/bpk-component-phone-input)
70
70
  [`bpk-component-popover`](/packages/bpk-component-popover)
71
+ [`bpk-component-price-range`](/packages/bpk-component-price-range)
71
72
  [`bpk-component-progress`](/packages/bpk-component-progress)
72
73
  [`bpk-component-radio`](/packages/bpk-component-radio)
73
74
  [`bpk-component-rtl-toggle`](/packages/bpk-component-rtl-toggle)
@@ -75,8 +75,8 @@ const BpkInsetBanner = ({
75
75
  label: callToAction?.popverLabel || '',
76
76
  placement: callToAction?.popoverPlacement || 'bottom',
77
77
  onClose: e => {
78
- e.stopPropagation();
79
- e.preventDefault();
78
+ e?.stopPropagation();
79
+ e?.preventDefault();
80
80
  },
81
81
  closeButtonText: callToAction?.buttonCloseLabel,
82
82
  closeButtonIcon: callToAction?.closeBtnIcon,
@@ -3,6 +3,7 @@ import type { Placement } from '@floating-ui/react';
3
3
  declare const EVENT_SOURCES: {
4
4
  CLOSE_BUTTON: string;
5
5
  CLOSE_LINK: string;
6
+ CLOSE_OUTSIDE: string;
6
7
  };
7
8
  type CloseButtonProps = {
8
9
  /**
@@ -16,7 +17,7 @@ export type Props = CloseButtonProps & {
16
17
  children: ReactNode;
17
18
  id: string;
18
19
  label: string;
19
- onClose: (event: SyntheticEvent<HTMLButtonElement>, props: {
20
+ onClose: (event: SyntheticEvent<HTMLButtonElement> | null, props: {
20
21
  source: (typeof EVENT_SOURCES)[keyof typeof EVENT_SOURCES];
21
22
  }) => void;
22
23
  className?: string | null;
@@ -32,7 +32,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
32
32
  const getClassName = cssModules(STYLES);
33
33
  const EVENT_SOURCES = {
34
34
  CLOSE_BUTTON: 'CLOSE_BUTTON',
35
- CLOSE_LINK: 'CLOSE_LINK'
35
+ CLOSE_LINK: 'CLOSE_LINK',
36
+ CLOSE_OUTSIDE: 'CLOSE_OUTSIDE'
36
37
  };
37
38
 
38
39
  // The stroke width is used to set the border width of the arrow.
@@ -75,13 +76,21 @@ const BpkPopover = ({
75
76
  }
76
77
  }, [isOpen]);
77
78
  const arrowRef = useRef(null);
79
+ const onFloatingChange = isFloatingOpen => {
80
+ setIsOpenState(isFloatingOpen);
81
+ if (!isFloatingOpen && onClose) {
82
+ onClose(null, {
83
+ source: EVENT_SOURCES.CLOSE_OUTSIDE
84
+ });
85
+ }
86
+ };
78
87
  const {
79
88
  context,
80
89
  floatingStyles,
81
90
  refs
82
91
  } = useFloating({
83
92
  open: isOpenState,
84
- onOpenChange: setIsOpenState,
93
+ onOpenChange: onFloatingChange,
85
94
  placement,
86
95
  middleware: [showArrow && offset(17), shift(), showArrow && arrow({
87
96
  element: arrowRef
@@ -0,0 +1,3 @@
1
+ import BpkPriceRange, { type Props as BpkPriceRangeProps } from './src/BpkPriceRange';
2
+ export type { BpkPriceRangeProps };
3
+ export default BpkPriceRange;
@@ -0,0 +1,20 @@
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 BpkPriceRange from "./src/BpkPriceRange";
20
+ export default BpkPriceRange;
@@ -0,0 +1,7 @@
1
+ import type { MarkerType } from './common-types';
2
+ type Props = {
3
+ priceLabel: string;
4
+ type: MarkerType;
5
+ };
6
+ declare const _default: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<HTMLDivElement>>;
7
+ export default _default;
@@ -0,0 +1,38 @@
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 { forwardRef } from 'react';
20
+ import BpkText, { TEXT_STYLES } from "../../bpk-component-text/src/BpkText";
21
+ import { cssModules } from "../../bpk-react-utils";
22
+ import STYLES from "./BpkPriceMarker.module.css";
23
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
+ const getClassName = cssModules(STYLES);
25
+ const BpkPriceMarker = ({
26
+ priceLabel,
27
+ type
28
+ }, ref) => /*#__PURE__*/_jsxs("div", {
29
+ className: getClassName('bpk-price-marker', `bpk-price-marker--${type}`),
30
+ ref: ref,
31
+ children: [/*#__PURE__*/_jsx(BpkText, {
32
+ textStyle: TEXT_STYLES.label2,
33
+ children: priceLabel
34
+ }), /*#__PURE__*/_jsx("div", {
35
+ className: getClassName('bpk-price-marker__arrow')
36
+ })]
37
+ });
38
+ export default /*#__PURE__*/forwardRef(BpkPriceMarker);
@@ -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-price-marker{position:relative;display:flex;z-index:1;flex-direction:column;align-items:center;flex:none;border:none;border-radius:.25rem;background:none;box-shadow:0px 1px 3px 0px rgba(37,32,31,.3);margin-block-end:.375rem}.bpk-price-marker span{display:inline-flex;z-index:1;padding:.125rem .5rem;border-radius:.25rem;color:#fff}.bpk-price-marker__arrow{position:absolute;top:50%;z-index:0;width:1rem;height:1rem;transform:rotate(45deg);border-radius:25%;background-color:inherit}.bpk-price-marker--low{background-color:#0c838a}.bpk-price-marker--medium{background-color:#05203c}.bpk-price-marker--high{background-color:#e70866}
@@ -0,0 +1,16 @@
1
+ type Marker = {
2
+ price: string;
3
+ percentage: number;
4
+ };
5
+ export type Props = {
6
+ min?: number;
7
+ max?: number;
8
+ showPriceIndicator?: boolean;
9
+ marker: Marker;
10
+ segments: {
11
+ low: Marker;
12
+ high: Marker;
13
+ };
14
+ };
15
+ declare const BpkPriceRange: ({ marker, max, min, segments, showPriceIndicator, }: Props) => import("react/jsx-runtime").JSX.Element;
16
+ export default BpkPriceRange;
@@ -0,0 +1,116 @@
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 { useEffect, useRef, useState } from 'react';
20
+ import clamp from 'lodash/clamp';
21
+ import BpkText, { TEXT_STYLES } from "../../bpk-component-text/src/BpkText";
22
+ import { cssModules } from "../../bpk-react-utils";
23
+ import BpkPriceMarker from "./BpkPriceMarker";
24
+ import { MARKER_TYPES } from "./common-types";
25
+ import STYLES from "./BpkPriceRange.module.css";
26
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
27
+ const getClassName = cssModules(STYLES);
28
+ const BpkPriceRange = ({
29
+ marker,
30
+ max = 100,
31
+ min = 0,
32
+ segments,
33
+ showPriceIndicator = true
34
+ }) => {
35
+ const linesRef = useRef(null);
36
+ const indicatorRef = useRef(null);
37
+ const [linesWidth, setLinesWidth] = useState(0);
38
+ const [prefilledWidth, setPrefilledWidth] = useState(0);
39
+ const calcPercentage = current => (clamp(current, min, max) - min) / (max - min);
40
+ const indicatorPercent = calcPercentage(marker.percentage);
41
+ let type;
42
+ if (marker.percentage < segments.low.percentage) {
43
+ type = MARKER_TYPES.LOW;
44
+ } else if (marker.percentage > segments.high.percentage) {
45
+ type = MARKER_TYPES.HIGH;
46
+ } else {
47
+ type = MARKER_TYPES.MEDIUM;
48
+ }
49
+ useEffect(() => {
50
+ const resizeObserver = new ResizeObserver(entries => {
51
+ if (entries[0].contentRect) {
52
+ // listen to the width of the lines
53
+ setLinesWidth(entries[0].contentRect.width);
54
+ }
55
+ });
56
+ if (linesRef.current) {
57
+ resizeObserver.observe(linesRef.current);
58
+ }
59
+ return () => {
60
+ resizeObserver.disconnect();
61
+ };
62
+ }, []);
63
+ useEffect(() => {
64
+ // to calculate the spacing ahead of the price indicator
65
+ if (indicatorRef.current && linesWidth) {
66
+ const estimatedWidth = indicatorPercent * linesWidth - indicatorRef.current.scrollWidth / 2;
67
+ const maxPrefilledWidth = linesWidth - indicatorRef.current.scrollWidth;
68
+ const actualPrefilledWidth = clamp(estimatedWidth, 0, maxPrefilledWidth);
69
+ setPrefilledWidth(actualPrefilledWidth);
70
+ }
71
+ }, [indicatorPercent, linesWidth]);
72
+ const linesClassName = getClassName('bpk-price-range__lines', showPriceIndicator && 'bpk-price-range__lines--large');
73
+ const lowClassName = getClassName('bpk-price-range__line--low', showPriceIndicator && 'bpk-price-range__line--lowLarge');
74
+ const highClassName = getClassName('bpk-price-range__line--high', showPriceIndicator && 'bpk-price-range__line--highLarge');
75
+ const mediumClassName = getClassName('bpk-price-range__line--medium');
76
+ const dotClassName = getClassName(`bpk-price-range__line--${type}`, 'bpk-price-range__line--dot');
77
+ return /*#__PURE__*/_jsxs("div", {
78
+ style: {
79
+ '--low': calcPercentage(segments.low.percentage),
80
+ '--high': calcPercentage(segments.high.percentage),
81
+ '--prefilled-width': `${prefilledWidth}px`
82
+ },
83
+ className: getClassName('bpk-price-range', showPriceIndicator && 'bpk-price-range--large'),
84
+ ref: linesRef,
85
+ children: [showPriceIndicator && /*#__PURE__*/_jsx("div", {
86
+ className: getClassName('bpk-price-range__marker'),
87
+ children: /*#__PURE__*/_jsx(BpkPriceMarker, {
88
+ ref: indicatorRef,
89
+ priceLabel: marker.price,
90
+ type: type
91
+ })
92
+ }), /*#__PURE__*/_jsxs("div", {
93
+ className: linesClassName,
94
+ children: [/*#__PURE__*/_jsx("div", {
95
+ className: lowClassName
96
+ }), /*#__PURE__*/_jsx("div", {
97
+ className: mediumClassName
98
+ }), /*#__PURE__*/_jsx("div", {
99
+ className: highClassName
100
+ }), !showPriceIndicator && /*#__PURE__*/_jsx("div", {
101
+ className: dotClassName,
102
+ ref: indicatorRef
103
+ })]
104
+ }), showPriceIndicator && /*#__PURE__*/_jsxs("div", {
105
+ className: getClassName('bpk-price-range__ranges'),
106
+ children: [/*#__PURE__*/_jsx(BpkText, {
107
+ textStyle: TEXT_STYLES.footnote,
108
+ children: segments.low.price
109
+ }), /*#__PURE__*/_jsx(BpkText, {
110
+ textStyle: TEXT_STYLES.footnote,
111
+ children: segments.high.price
112
+ })]
113
+ })]
114
+ });
115
+ };
116
+ export default BpkPriceRange;
@@ -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-price-range{display:flex;width:100%;flex-direction:column;padding-block:.25rem;row-gap:.25rem}.bpk-price-range--large{padding-block:0}.bpk-price-range__lines{position:relative;display:flex;height:.25rem;flex:none;gap:.125rem}.bpk-price-range__lines--large{height:.5rem}.bpk-price-range__line--low{width:calc(100%*var(--low));height:100%;background-color:#0c838a;border-end-start-radius:.5rem;border-start-start-radius:.5rem}.bpk-price-range__line--lowLarge{border-end-start-radius:.75rem;border-start-start-radius:.75rem}.bpk-price-range__line--medium{width:calc(100%*(var(--high) - var(--low)));height:100%;background-color:#05203c}.bpk-price-range__line--high{width:calc(100%*(1 - var(--high)));height:100%;background-color:#e70866;border-end-end-radius:.5rem;border-start-end-radius:.5rem}.bpk-price-range__line--highLarge{border-end-end-radius:.75rem;border-start-end-radius:.75rem}.bpk-price-range__line--dot{position:absolute;top:50%;display:flex;width:.75rem;height:.75rem;justify-content:center;align-items:center;transform:translate(0, -50%);border-radius:50%;margin-inline-start:var(--prefilled-width)}.bpk-price-range__line--dot::after{content:"";display:block;width:.25rem;height:.25rem;border-radius:50%;background-color:#fff}.bpk-price-range__marker{width:fit-content;margin-inline-start:var(--prefilled-width)}.bpk-price-range__ranges{position:relative;display:flex;width:100%;height:1.25rem}.bpk-price-range__ranges span{position:absolute;display:inline-block;transform:translate(-50%, 0)}html[dir=rtl] .bpk-price-range__ranges span{transform:translate(50%, 0)}.bpk-price-range__ranges span:first-child{inset-inline-start:calc(100%*var(--low))}.bpk-price-range__ranges span:last-child{inset-inline-start:calc(100%*var(--high))}
@@ -0,0 +1,6 @@
1
+ export declare const MARKER_TYPES: {
2
+ readonly LOW: "low";
3
+ readonly MEDIUM: "medium";
4
+ readonly HIGH: "high";
5
+ };
6
+ export type MarkerType = (typeof MARKER_TYPES)[keyof typeof MARKER_TYPES];
@@ -0,0 +1,23 @@
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 MARKER_TYPES = {
20
+ LOW: 'low',
21
+ MEDIUM: 'medium',
22
+ HIGH: 'high'
23
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "36.17.0",
3
+ "version": "36.17.1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",