@jobber/components 4.87.1 → 4.87.2

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 +1,7 @@
1
- export declare function useMediaQuery(CSSMediaQuery: string): boolean;
1
+ type MediaQuery = `(${string}:${string})`;
2
+ export declare const mediaQueryStore: {
3
+ subscribe(onChange: () => void, query: MediaQuery): () => void;
4
+ getSnapshot(query: MediaQuery): () => boolean;
5
+ };
6
+ export declare function useMediaQuery(query: MediaQuery): boolean;
7
+ export {};
@@ -101,7 +101,19 @@ function useDataListContext() {
101
101
  return React.useContext(DataListContext);
102
102
  }
103
103
 
104
- function useMediaQuery(CSSMediaQuery) {
104
+ const mediaQueryStore = {
105
+ subscribe(onChange, query) {
106
+ const matchMedia = window.matchMedia(query);
107
+ matchMedia.addEventListener("change", onChange);
108
+ return () => {
109
+ matchMedia.removeEventListener("change", onChange);
110
+ };
111
+ },
112
+ getSnapshot(query) {
113
+ return () => window.matchMedia(query).matches;
114
+ },
115
+ };
116
+ function useMediaQuery(query) {
105
117
  /**
106
118
  * matchMedia have had full support for browsers since 2012 but jest, being a
107
119
  * lite version of a DOM, doesn't support it.
@@ -113,18 +125,12 @@ function useMediaQuery(CSSMediaQuery) {
113
125
  * screen sizes, they can use the `mockViewportWidth` function from
114
126
  * `@jobber/components/useBreakpoints`.
115
127
  */
116
- if (window.matchMedia === undefined)
128
+ if (typeof window === "undefined" ||
129
+ typeof window.matchMedia === "undefined") {
117
130
  return true;
118
- const [matches, setMatches] = React.useState(window.matchMedia(CSSMediaQuery).matches);
119
- React.useEffect(() => {
120
- const media = window.matchMedia(CSSMediaQuery);
121
- if (media.matches !== matches) {
122
- setMatches(media.matches);
123
- }
124
- const listener = () => setMatches(media.matches);
125
- media.addEventListener("change", listener);
126
- return () => media.removeEventListener("change", listener);
127
- }, [CSSMediaQuery]);
131
+ }
132
+ const subscribeMediaQuery = React.useCallback((onChange) => mediaQueryStore.subscribe(onChange, query), [query]);
133
+ const matches = React.useSyncExternalStore(subscribeMediaQuery, mediaQueryStore.getSnapshot(query), () => true);
128
134
  return matches;
129
135
  }
130
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "4.87.1",
3
+ "version": "4.87.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "dependencies": {
22
22
  "@jobber/design": "^0.56.0",
23
23
  "@jobber/formatters": "*",
24
- "@jobber/hooks": "^2.9.1",
24
+ "@jobber/hooks": "^2.9.2",
25
25
  "@popperjs/core": "^2.0.6",
26
26
  "@std-proposal/temporal": "0.0.1",
27
27
  "@tanstack/react-table": "8.5.13",
@@ -80,5 +80,5 @@
80
80
  "> 1%",
81
81
  "IE 10"
82
82
  ],
83
- "gitHead": "76163e4b81edfc151e30c29407956a507b853706"
83
+ "gitHead": "2cc393810288051850e827744f6d533469c5a0d6"
84
84
  }