@skyscanner/backpack-web 36.12.0 → 36.13.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.
@@ -13,6 +13,11 @@ type DefaultProps = {
13
13
  minDate: Date;
14
14
  onDateClick: () => void;
15
15
  onDateKeyDown: () => void;
16
+ /**
17
+ * A function to format a human-readable month, for example: "January 2018":
18
+ * If you just need to quickly prototype, use the following from [`date-fns`](https://date-fns.org/docs/format#usage)
19
+ */
20
+ formatMonth: (month: Date) => string;
16
21
  preventKeyboardFocus: boolean;
17
22
  /**
18
23
  * An object to indicate which configuration of the calendar is being used. Choices are `single` date selection or `range` date selection.
@@ -21,7 +21,7 @@ import { cssModules, isDeviceIos } from "../../bpk-react-utils";
21
21
  import { addCalendarGridTransition } from "./BpkCalendarGridTransition";
22
22
  import BpkCalendarWeek from "./BpkCalendarWeek";
23
23
  import { CALENDAR_SELECTION_TYPE } from "./custom-proptypes";
24
- import { addMonths, getCalendar, getCalendarNoCustomLabel, isSameMonth } from "./date-utils";
24
+ import { addMonths, getCalendar, getCalendarNoCustomLabel, isSameMonth, format } from "./date-utils";
25
25
  import STYLES from "./BpkCalendarGrid.module.css";
26
26
 
27
27
  // This should be imported after `./BpkCalendarGrid.module.css`.
@@ -47,6 +47,7 @@ class BpkCalendarGrid extends Component {
47
47
  minDate: new Date(),
48
48
  onDateClick: () => {},
49
49
  onDateKeyDown: () => {},
50
+ formatMonth: month => format(month, 'MMMM yyyy'),
50
51
  preventKeyboardFocus: false,
51
52
  selectionConfiguration: {
52
53
  type: CALENDAR_SELECTION_TYPE.single,
@@ -84,6 +85,7 @@ class BpkCalendarGrid extends Component {
84
85
  dateModifiers,
85
86
  dateProps,
86
87
  focusedDate,
88
+ formatMonth,
87
89
  ignoreOutsideDate,
88
90
  isKeyboardFocusable,
89
91
  markOutsideDays,
@@ -105,6 +107,7 @@ class BpkCalendarGrid extends Component {
105
107
  className: classNames,
106
108
  "aria-hidden": !isKeyboardFocusable,
107
109
  role: "grid",
110
+ "aria-label": formatMonth(month),
108
111
  children: /*#__PURE__*/_jsx("div", {
109
112
  role: "rowgroup",
110
113
  children: calendarMonthWeeks.map(dates => /*#__PURE__*/_jsx(BpkCalendarWeek, {
@@ -1,5 +1,6 @@
1
1
  import type { ReactNode, ElementType, CSSProperties } from 'react';
2
2
  import { Component } from 'react';
3
+ import type { DebouncedFunc } from 'lodash';
3
4
  declare const computeScrollBarAwareHeight: (scrollerEl: HTMLElement | null, innerEl: HTMLElement | null) => string | null;
4
5
  declare const computeScrollIndicatorClassName: (scrollerEl: HTMLElement | null, leadingIndicatorClassName?: string, trailingIndicatorClassName?: string) => string[] | null;
5
6
  type Props = {
@@ -18,11 +19,12 @@ type State = {
18
19
  scrollIndicatorClassName: string | null;
19
20
  };
20
21
  declare class BpkMobileScrollContainer extends Component<Props, State> {
22
+ debouncedResize: DebouncedFunc<() => void>;
21
23
  static defaultProps: Partial<Props>;
22
24
  constructor(props: Props);
23
25
  componentDidMount(): void;
24
26
  componentWillUnmount(): void;
25
- onWindowResize: import("lodash").DebouncedFunc<() => void>;
27
+ onWindowResize: () => void;
26
28
  setScrollIndicatorClassName: () => void;
27
29
  setScrollBarAwareHeight: () => void;
28
30
  innerEl: HTMLElement | null;
@@ -62,21 +62,22 @@ class BpkMobileScrollContainer extends Component {
62
62
  computedHeight: 'auto',
63
63
  scrollIndicatorClassName: null
64
64
  };
65
+ this.debouncedResize = debounce(this.onWindowResize, 100);
65
66
  }
66
67
  componentDidMount() {
67
68
  requestAnimationFrame(() => {
68
69
  this.setScrollBarAwareHeight();
69
70
  this.setScrollIndicatorClassName();
70
71
  });
71
- window.addEventListener('resize', this.onWindowResize);
72
+ window.addEventListener('resize', this.debouncedResize);
72
73
  }
73
74
  componentWillUnmount() {
74
- window.removeEventListener('resize', this.onWindowResize);
75
+ window.removeEventListener('resize', this.debouncedResize);
75
76
  }
76
- onWindowResize = debounce(() => {
77
+ onWindowResize = () => {
77
78
  this.setScrollBarAwareHeight();
78
79
  this.setScrollIndicatorClassName();
79
- }, 100);
80
+ };
80
81
  setScrollIndicatorClassName = () => {
81
82
  const classNames = computeScrollIndicatorClassName(this.scrollerEl, this.props.leadingIndicatorClassName, this.props.trailingIndicatorClassName);
82
83
  if (!classNames) {
@@ -40,6 +40,7 @@ const BpkPrice = props => {
40
40
  const {
41
41
  align,
42
42
  className,
43
+ icon,
43
44
  leadingClassName,
44
45
  leadingText,
45
46
  previousPrice,
@@ -51,6 +52,25 @@ const BpkPrice = props => {
51
52
  const defaultTextStyle = getDefaultTextStyle(size);
52
53
  const priceTextStyle = getPriceTextStyle(size);
53
54
  const isAlignRight = align === ALIGNS.right;
55
+ const getTrailingTextNode = () => {
56
+ if (!trailingText) {
57
+ return null;
58
+ }
59
+ const textNode = /*#__PURE__*/_jsx(BpkText, {
60
+ textStyle: defaultTextStyle,
61
+ tagName: "span",
62
+ children: trailingText
63
+ });
64
+ // When aligned right, use a <div> as the text appears on a separate line.
65
+ // When aligned left, use a <span> as the test is inline.
66
+ return isAlignRight ? /*#__PURE__*/_jsx("div", {
67
+ className: getClassName('bpk-price__trailing'),
68
+ children: textNode
69
+ }) : /*#__PURE__*/_jsx("span", {
70
+ className: getClassName('bpk-price__trailing'),
71
+ children: textNode
72
+ });
73
+ };
54
74
  return /*#__PURE__*/_jsxs("div", {
55
75
  className: getClassName('bpk-price', isAlignRight && 'bpk-price--right', className)
56
76
  // $FlowFixMe[cannot-spread-inexact] - inexact rest. See 'decisions/flowfixme.md'.
@@ -78,23 +98,22 @@ const BpkPrice = props => {
78
98
  children: leadingText
79
99
  })]
80
100
  }), /*#__PURE__*/_jsxs("div", {
81
- className: getClassName(isAlignRight && 'bpk-price__column-container'),
101
+ className: getClassName(isAlignRight && 'bpk-price__main--right'),
82
102
  children: [/*#__PURE__*/_jsx("span", {
83
- className: getClassName('bpk-price__price', !isAlignRight && 'bpk-price__spacing'),
103
+ className: getClassName('bpk-price__price',
104
+ // When aligning right, we use the gap property to add space between the price and the icon.
105
+ // When aligning left, we use the ::after pseudo-element instead to achieve the desired wrapping behaviour.
106
+ !isAlignRight && 'bpk-price__spacing'),
84
107
  children: /*#__PURE__*/_jsx(BpkText, {
85
108
  textStyle: priceTextStyle,
86
109
  tagName: "span",
87
110
  children: price
88
111
  })
89
- }), trailingText && /*#__PURE__*/_jsx("span", {
90
- className: getClassName('bpk-price__trailing'),
91
- children: /*#__PURE__*/_jsx(BpkText, {
92
- textStyle: defaultTextStyle,
93
- tagName: "span",
94
- children: trailingText
95
- })
96
- })]
97
- })]
112
+ }), icon && /*#__PURE__*/_jsx("span", {
113
+ className: getClassName('bpk-price__icon', !isAlignRight && 'bpk-price__spacing'),
114
+ children: icon
115
+ }), !isAlignRight && getTrailingTextNode()]
116
+ }), isAlignRight && getTrailingTextNode()]
98
117
  });
99
118
  };
100
119
  BpkPrice.propTypes = {
@@ -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-price{display:flex;flex-direction:column;color:#626971}.bpk-price--right{text-align:right}html[dir=rtl] .bpk-price--right{text-align:left}.bpk-price__leading{display:flex;flex-direction:row}.bpk-price__leading--right{display:flex;justify-content:flex-end}.bpk-price__previous-price{display:flex;color:#e70866;text-decoration-line:line-through}.bpk-price__separator{display:flex;margin:0 .25rem}.bpk-price__column-container{display:flex;flex-direction:column}.bpk-price__price{display:contents;color:#161616;word-break:break-all}.bpk-price__spacing::after{content:"";margin-right:.25rem}html[dir=rtl] .bpk-price__spacing::after{margin-right:unset;margin-left:.25rem}.bpk-price__trailing{display:contents;white-space:nowrap}
18
+ .bpk-price{display:flex;flex-direction:column;color:#626971}.bpk-price--right{align-items:flex-end}.bpk-price__leading{display:flex;flex-direction:row}.bpk-price__leading--right{display:flex;justify-content:flex-end}.bpk-price__previous-price{display:flex;color:#e70866;text-decoration-line:line-through}.bpk-price__separator{display:flex;margin:0 .25rem}.bpk-price__main--right{display:flex;align-items:center;gap:.25rem}.bpk-price__price{display:contents;color:#161616;word-break:break-all}.bpk-price__spacing::after{content:"";margin-inline-end:.25rem}.bpk-price__icon{display:contents}.bpk-price__trailing{display:contents;white-space:nowrap}
@@ -42,6 +42,7 @@ const BpkScrollableCalendarGrid = ({
42
42
  }), /*#__PURE__*/_jsx(BpkCalendarGrid, {
43
43
  month: month,
44
44
  ignoreOutsideDate: true,
45
+ formatMonth: formatMonth,
45
46
  ...rest
46
47
  })]
47
48
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "36.12.0",
3
+ "version": "36.13.1",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",