@skyscanner/backpack-web 33.1.0 → 33.3.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.
@@ -17,5 +17,6 @@
17
17
  */
18
18
 
19
19
  import BpkBreakpoint, { BREAKPOINTS } from "./src/BpkBreakpoint";
20
- export { BREAKPOINTS };
20
+ import useMediaQuery from "./src/useMediaQuery";
21
+ export { BREAKPOINTS, useMediaQuery };
21
22
  export default BpkBreakpoint;
@@ -18,26 +18,33 @@
18
18
 
19
19
  import type { ReactNode } from 'react';
20
20
  declare const BREAKPOINTS: {
21
- readonly SMALL_MOBILE: any;
22
- readonly MOBILE: any;
23
- readonly SMALL_TABLET: any;
24
- readonly SMALL_TABLET_ONLY: any;
25
- readonly TABLET: any;
26
- readonly TABLET_ONLY: any;
27
- readonly ABOVE_MOBILE: any;
28
- readonly ABOVE_TABLET: any;
29
- readonly ABOVE_DESKTOP: any;
30
- readonly DESKTOP_ONLY: any;
21
+ readonly SMALL_MOBILE: any;
22
+ readonly MOBILE: any;
23
+ readonly SMALL_TABLET: any;
24
+ readonly SMALL_TABLET_ONLY: any;
25
+ readonly TABLET: any;
26
+ readonly TABLET_ONLY: any;
27
+ readonly ABOVE_MOBILE: any;
28
+ readonly ABOVE_TABLET: any;
29
+ readonly ABOVE_DESKTOP: any;
30
+ readonly DESKTOP_ONLY: any;
31
31
  };
32
32
  type Props = {
33
- /**
34
- * The content to render when the breakpoint matches.
35
- */
36
- children: ReactNode | ((matches: boolean) => ReactNode | null);
37
- query: string | (typeof BREAKPOINTS)[keyof typeof BREAKPOINTS];
38
- legacy?: boolean;
39
- matchSSR?: boolean;
33
+ /**
34
+ * The content to render when the breakpoint matches.
35
+ */
36
+ children: ReactNode | ((matches: boolean) => ReactNode | null);
37
+ query: string | (typeof BREAKPOINTS)[keyof typeof BREAKPOINTS];
38
+ legacy?: boolean;
39
+ matchSSR?: boolean;
40
40
  };
41
- declare const BpkBreakpoint: ({ children, legacy, query }: Props) => JSX.Element;
42
- export { BREAKPOINTS };
41
+ declare const BpkBreakpoint: ({
42
+ children,
43
+ legacy,
44
+ query,
45
+ }: Props) => JSX.Element;
46
+
47
+ declare const useMediaQuery: (query: string) => boolean;
48
+
49
+ export { BREAKPOINTS, useMediaQuery };
43
50
  export default BpkBreakpoint;
@@ -17,10 +17,9 @@
17
17
  */
18
18
 
19
19
  import { useState, useEffect } from 'react';
20
- import MediaQuery from "react-responsive/dist/react-responsive";
21
20
  // @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
22
21
  import { breakpoints } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
23
- import { jsx as _jsx } from "react/jsx-runtime";
22
+ import useMediaQuery from "./useMediaQuery";
24
23
  const BREAKPOINTS = {
25
24
  SMALL_MOBILE: breakpoints.breakpointQuerySmallMobile,
26
25
  MOBILE: breakpoints.breakpointQueryMobile,
@@ -40,6 +39,7 @@ const BpkBreakpoint = ({
40
39
  query
41
40
  }) => {
42
41
  const [isClient, setIsClient] = useState(false);
42
+ const matches = useMediaQuery(query);
43
43
  useEffect(() => {
44
44
  setIsClient(true);
45
45
  }, []);
@@ -47,10 +47,10 @@ const BpkBreakpoint = ({
47
47
  if (!legacy && !Object.values(BREAKPOINTS).includes(query)) {
48
48
  console.warn(`Invalid query ${query}. Use one of the supported queries or pass the legacy prop.`);
49
49
  }
50
- return /*#__PURE__*/_jsx(MediaQuery, {
51
- query: query,
52
- children: children
53
- });
50
+ if (typeof children === 'function') {
51
+ return children(matches);
52
+ }
53
+ return matches ? children : null;
54
54
  }
55
55
 
56
56
  // Below code is executed when running in SSR mode
@@ -0,0 +1,36 @@
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 { useState, useEffect } from 'react';
20
+ const useMediaQuery = query => {
21
+ const [matches, setMatches] = useState(window.matchMedia ? window.matchMedia(query).matches : false);
22
+ useEffect(() => {
23
+ if (window.matchMedia) {
24
+ const media = window.matchMedia(query);
25
+ setMatches(media.matches);
26
+ const listener = () => {
27
+ setMatches(media.matches);
28
+ };
29
+ media.addEventListener('change', listener);
30
+ return () => media.removeEventListener('change', listener);
31
+ }
32
+ return undefined;
33
+ }, [query]);
34
+ return matches;
35
+ };
36
+ export default useMediaQuery;
@@ -78,6 +78,7 @@ class BpkHorizontalNav extends Component {
78
78
  };
79
79
  render() {
80
80
  const {
81
+ ariaLabel,
81
82
  autoScrollToSelected,
82
83
  children: rawChildren,
83
84
  className,
@@ -113,6 +114,7 @@ class BpkHorizontalNav extends Component {
113
114
  /*#__PURE__*/
114
115
  // $FlowFixMe[cannot-spread-inexact] - inexact rest. See 'decisions/flowfixme.md'.
115
116
  _jsx(BpkMobileScrollContainer, {
117
+ ariaLabel: ariaLabel,
116
118
  innerContainerTagName: "nav",
117
119
  className: classNames,
118
120
  leadingIndicatorClassName: leadingScrollIndicatorClassName,
@@ -131,6 +133,7 @@ class BpkHorizontalNav extends Component {
131
133
  }
132
134
  }
133
135
  BpkHorizontalNav.propTypes = {
136
+ ariaLabel: PropTypes.string,
134
137
  children: PropTypes.node.isRequired,
135
138
  /**
136
139
  * Ensures that the selected item is within view when loaded on narrow-screened devices.
@@ -139,7 +142,7 @@ BpkHorizontalNav.propTypes = {
139
142
  className: PropTypes.string,
140
143
  leadingScrollIndicatorClassName: PropTypes.string,
141
144
  /**
142
- * When set to "false", the bottom border on the component isn't included. This refers
145
+ * When set to "false", the bottom border on the component isn't included. This refers
143
146
  * to the underline on the whole "BpkHorizontalNav", not the line that appears under the selected item.
144
147
  */
145
148
  showUnderline: PropTypes.bool,
@@ -147,6 +150,7 @@ BpkHorizontalNav.propTypes = {
147
150
  type: PropTypes.oneOf(Object.keys(HORIZONTAL_NAV_TYPES))
148
151
  };
149
152
  BpkHorizontalNav.defaultProps = {
153
+ ariaLabel: null,
150
154
  autoScrollToSelected: false,
151
155
  className: null,
152
156
  leadingScrollIndicatorClassName: null,
@@ -59,6 +59,7 @@ const computeScrollIndicatorClassName = (scrollerEl, leadingIndicatorClassName =
59
59
  return classNames;
60
60
  };
61
61
  const propTypes = {
62
+ ariaLabel: PropTypes.string,
62
63
  children: PropTypes.node.isRequired,
63
64
  scrollerRef: PropTypes.func,
64
65
  innerContainerTagName: PropTypes.string,
@@ -69,6 +70,7 @@ const propTypes = {
69
70
  showScrollbar: PropTypes.bool
70
71
  };
71
72
  const defaultProps = {
73
+ ariaLabel: null,
72
74
  scrollerRef: null,
73
75
  innerContainerTagName: 'div',
74
76
  className: null,
@@ -121,6 +123,7 @@ class BpkMobileScrollContainer extends Component {
121
123
  render() {
122
124
  const classNames = [getClassName('bpk-mobile-scroll-container')];
123
125
  const {
126
+ ariaLabel,
124
127
  children,
125
128
  className,
126
129
  innerContainerTagName,
@@ -156,6 +159,7 @@ class BpkMobileScrollContainer extends Component {
156
159
  onScroll: this.setScrollIndicatorClassName,
157
160
  className: scrollerClassNames,
158
161
  children: /*#__PURE__*/_jsx(InnerContainer, {
162
+ "aria-label": ariaLabel,
159
163
  ref: el => {
160
164
  this.innerEl = el;
161
165
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "33.1.0",
3
+ "version": "33.3.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,7 +25,7 @@
25
25
  "@popperjs/core": "^2.11.5",
26
26
  "@react-google-maps/api": "^2.12.0",
27
27
  "@skyscanner/bpk-foundations-web": "^17.5.3",
28
- "@skyscanner/bpk-svgs": "^19.0.1",
28
+ "@skyscanner/bpk-svgs": "^19.1.0",
29
29
  "a11y-focus-scope": "^1.1.3",
30
30
  "a11y-focus-store": "^1.0.0",
31
31
  "d3-path": "^2.0.0",
@@ -39,7 +39,6 @@
39
39
  "object-assign": "^4.1.1",
40
40
  "prop-types": "^15.7.2",
41
41
  "react-autosuggest": "^9.4.3",
42
- "react-responsive": "^9.0.2",
43
42
  "react-slider": "^2.0.6",
44
43
  "react-table": "^7.8.0",
45
44
  "react-virtualized-auto-sizer": "1.0.20",
@@ -47,11 +46,11 @@
47
46
  },
48
47
  "peerDependencies": {
49
48
  "node-sass": ">= 7",
50
- "sass": "^1",
51
- "sass-embedded": "^1",
52
49
  "react": "^17.0.2",
53
50
  "react-dom": "^17.0.2",
54
- "react-transition-group": "^4.4.5"
51
+ "react-transition-group": "^4.4.5",
52
+ "sass": "^1",
53
+ "sass-embedded": "^1"
55
54
  },
56
55
  "peerDependenciesMeta": {
57
56
  "node-sass": {