@skyscanner/backpack-web 33.2.0 → 33.3.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.
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "33.2.0",
3
+ "version": "33.3.1",
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": {