@jobber/hooks 2.17.1 → 2.17.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.
- package/dist/index.js +18 -34
- package/dist/useBool/index.js +1 -5
- package/dist/useBool/useBool.js +6 -9
- package/dist/useBool/useBool.test.js +9 -11
- package/dist/useBreakpoints/index.js +2 -20
- package/dist/useBreakpoints/mockViewportWidth/index.js +1 -17
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.js +2 -6
- package/dist/useBreakpoints/mockViewportWidth/mockViewportWidth.test.js +4 -6
- package/dist/useBreakpoints/useBreakpoints.js +9 -13
- package/dist/useBreakpoints/useBreakpoints.test.js +30 -35
- package/dist/useBreakpoints/useMediaQuery.js +5 -9
- package/dist/useCallbackRef/index.js +1 -5
- package/dist/useCallbackRef/useCallbackRef.js +5 -8
- package/dist/useCallbackRef/useCallbackRef.test.js +4 -6
- package/dist/useCollectionQuery/index.js +1 -5
- package/dist/useCollectionQuery/mdxUtils.js +8 -12
- package/dist/useCollectionQuery/test-utilities/index.js +3 -19
- package/dist/useCollectionQuery/test-utilities/mocks.js +19 -30
- package/dist/useCollectionQuery/test-utilities/queries.js +4 -7
- package/dist/useCollectionQuery/test-utilities/utils.js +1 -4
- package/dist/useCollectionQuery/uniqueEdges.js +2 -6
- package/dist/useCollectionQuery/uniqueNodes.js +1 -4
- package/dist/useCollectionQuery/useCollectionQuery.js +27 -34
- package/dist/useCollectionQuery/useCollectionQuery.test.js +126 -128
- package/dist/useDebounce/index.js +1 -5
- package/dist/useDebounce/useDebounce.js +8 -11
- package/dist/useDebounce/useDebounce.test.js +42 -70
- package/dist/useFocusTrap/index.js +1 -5
- package/dist/useFocusTrap/useFocusTrap.js +4 -7
- package/dist/useFocusTrap/useFocusTrap.test.js +26 -31
- package/dist/useFormState/index.js +1 -5
- package/dist/useFormState/useFormState.js +3 -6
- package/dist/useInView/index.js +1 -17
- package/dist/useInView/useInView.js +6 -9
- package/dist/useInView/useInView.test.js +12 -17
- package/dist/useIsMounted/index.js +1 -5
- package/dist/useIsMounted/useIsMounted.js +5 -8
- package/dist/useIsMounted/useIsMounted.test.js +4 -6
- package/dist/useLiveAnnounce/index.js +1 -5
- package/dist/useLiveAnnounce/useLiveAnnounce.js +4 -7
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +19 -24
- package/dist/useOnKeyDown/index.js +1 -5
- package/dist/useOnKeyDown/useOnKeyDown.js +3 -6
- package/dist/useOnKeyDown/useOnKeyDown.test.js +7 -12
- package/dist/useOnMount/index.js +1 -5
- package/dist/useOnMount/useOnMount.js +6 -10
- package/dist/useOnMount/useOnMount.test.js +4 -6
- package/dist/useRefocusOnActivator/index.js +1 -5
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +3 -6
- package/dist/useResizeObserver/index.js +1 -17
- package/dist/useResizeObserver/useResizeObserver.js +9 -16
- package/dist/useSafeLayoutEffect/index.js +1 -5
- package/dist/useSafeLayoutEffect/useSafeLayoutEffect.js +4 -7
- package/dist/useShowClear/index.js +1 -5
- package/dist/useShowClear/useShowClear.js +1 -4
- package/dist/useShowClear/useShowClear.test.js +6 -8
- package/dist/useStepper/index.js +1 -5
- package/dist/useStepper/useStepper.js +9 -15
- package/dist/useStepper/useStepper.test.js +15 -17
- package/dist/useWindowDimensions/index.js +1 -5
- package/dist/useWindowDimensions/useWIndowDimensions.test.js +6 -8
- package/dist/useWindowDimensions/useWindowDimensions.js +4 -7
- package/package.json +102 -5
package/dist/index.js
CHANGED
|
@@ -1,34 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
__exportStar(require("./useCallbackRef"), exports);
|
|
20
|
-
__exportStar(require("./useCollectionQuery"), exports);
|
|
21
|
-
__exportStar(require("./useDebounce"), exports);
|
|
22
|
-
__exportStar(require("./useFocusTrap"), exports);
|
|
23
|
-
__exportStar(require("./useFormState"), exports);
|
|
24
|
-
__exportStar(require("./useInView"), exports);
|
|
25
|
-
__exportStar(require("./useIsMounted"), exports);
|
|
26
|
-
__exportStar(require("./useLiveAnnounce"), exports);
|
|
27
|
-
__exportStar(require("./useOnKeyDown"), exports);
|
|
28
|
-
__exportStar(require("./useOnMount"), exports);
|
|
29
|
-
__exportStar(require("./useRefocusOnActivator"), exports);
|
|
30
|
-
__exportStar(require("./useResizeObserver"), exports);
|
|
31
|
-
__exportStar(require("./useSafeLayoutEffect"), exports);
|
|
32
|
-
__exportStar(require("./useShowClear"), exports);
|
|
33
|
-
__exportStar(require("./useStepper"), exports);
|
|
34
|
-
__exportStar(require("./useWindowDimensions"), exports);
|
|
1
|
+
export * from "./useBool";
|
|
2
|
+
export * from "./useBreakpoints";
|
|
3
|
+
export * from "./useCallbackRef";
|
|
4
|
+
export * from "./useCollectionQuery";
|
|
5
|
+
export * from "./useDebounce";
|
|
6
|
+
export * from "./useFocusTrap";
|
|
7
|
+
export * from "./useFormState";
|
|
8
|
+
export * from "./useInView";
|
|
9
|
+
export * from "./useIsMounted";
|
|
10
|
+
export * from "./useLiveAnnounce";
|
|
11
|
+
export * from "./useOnKeyDown";
|
|
12
|
+
export * from "./useOnMount";
|
|
13
|
+
export * from "./useRefocusOnActivator";
|
|
14
|
+
export * from "./useResizeObserver";
|
|
15
|
+
export * from "./useSafeLayoutEffect";
|
|
16
|
+
export * from "./useShowClear";
|
|
17
|
+
export * from "./useStepper";
|
|
18
|
+
export * from "./useWindowDimensions";
|
package/dist/useBool/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useBool = void 0;
|
|
4
|
-
var useBool_1 = require("./useBool");
|
|
5
|
-
Object.defineProperty(exports, "useBool", { enumerable: true, get: function () { return useBool_1.useBool; } });
|
|
1
|
+
export { useBool } from "./useBool";
|
package/dist/useBool/useBool.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const setTrue = (0, react_1.useCallback)(() => setState(true), []);
|
|
8
|
-
const setFalse = (0, react_1.useCallback)(() => setState(false), []);
|
|
9
|
-
const toggle = (0, react_1.useCallback)(() => setState(current => !current), []);
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
export function useBool(initialState = false) {
|
|
3
|
+
const [state, setState] = useState(initialState);
|
|
4
|
+
const setTrue = useCallback(() => setState(true), []);
|
|
5
|
+
const setFalse = useCallback(() => setState(false), []);
|
|
6
|
+
const toggle = useCallback(() => setState(current => !current), []);
|
|
10
7
|
return [state, setTrue, setFalse, toggle];
|
|
11
8
|
}
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const react_1 = require("@testing-library/react");
|
|
4
|
-
const useBool_1 = require("./useBool");
|
|
1
|
+
import { act, renderHook } from "@testing-library/react";
|
|
2
|
+
import { useBool } from "./useBool";
|
|
5
3
|
describe("useBool, a hook for managing boolean state", () => {
|
|
6
4
|
it("by default has an initial state that is `false`", () => {
|
|
7
|
-
const [value] =
|
|
5
|
+
const [value] = renderHook(() => useBool()).result.current;
|
|
8
6
|
expect(value).toBe(false);
|
|
9
7
|
});
|
|
10
8
|
it("can be provided an initial state", () => {
|
|
11
|
-
const [value] =
|
|
9
|
+
const [value] = renderHook(() => useBool(true)).result.current;
|
|
12
10
|
expect(value).toBe(true);
|
|
13
11
|
});
|
|
14
12
|
it("provides helpful setters and a toggle method", () => {
|
|
15
|
-
const { result } =
|
|
13
|
+
const { result } = renderHook(() => useBool());
|
|
16
14
|
const value = () => result.current[0];
|
|
17
15
|
const [, setTrue, setFalse, toggle] = result.current;
|
|
18
16
|
expect(value()).toBe(false);
|
|
19
|
-
|
|
17
|
+
act(setTrue);
|
|
20
18
|
expect(value()).toBe(true);
|
|
21
|
-
|
|
19
|
+
act(setFalse);
|
|
22
20
|
expect(value()).toBe(false);
|
|
23
|
-
|
|
21
|
+
act(toggle);
|
|
24
22
|
expect(value()).toBe(true);
|
|
25
|
-
|
|
23
|
+
act(toggle);
|
|
26
24
|
expect(value()).toBe(false);
|
|
27
25
|
});
|
|
28
26
|
});
|
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.mockViewportWidth = void 0;
|
|
18
|
-
__exportStar(require("./useBreakpoints"), exports);
|
|
19
|
-
var mockViewportWidth_1 = require("./mockViewportWidth");
|
|
20
|
-
Object.defineProperty(exports, "mockViewportWidth", { enumerable: true, get: function () { return mockViewportWidth_1.mockViewportWidth; } });
|
|
1
|
+
export * from "./useBreakpoints";
|
|
2
|
+
export { mockViewportWidth } from "./mockViewportWidth";
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./mockViewportWidth"), exports);
|
|
1
|
+
export * from "./mockViewportWidth";
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockViewportWidth = mockViewportWidth;
|
|
4
|
-
exports.isQueryMatching = isQueryMatching;
|
|
5
1
|
const defaultMatchMedia = window.matchMedia;
|
|
6
2
|
const defaultResizeTo = window.resizeTo;
|
|
7
3
|
const defaultInnerWidth = window.innerWidth;
|
|
8
|
-
function mockViewportWidth() {
|
|
4
|
+
export function mockViewportWidth() {
|
|
9
5
|
return { cleanup, setViewportWidth };
|
|
10
6
|
}
|
|
11
7
|
function setViewportWidth(newWidth) {
|
|
@@ -49,7 +45,7 @@ function cleanup() {
|
|
|
49
45
|
window.resizeTo = defaultResizeTo;
|
|
50
46
|
window.innerWidth = defaultInnerWidth;
|
|
51
47
|
}
|
|
52
|
-
function isQueryMatching(query) {
|
|
48
|
+
export function isQueryMatching(query) {
|
|
53
49
|
const match = query.match(/(min-width|max-width):\s*(\d+)/);
|
|
54
50
|
if (!match)
|
|
55
51
|
return false;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const mockViewportWidth_1 = require("./mockViewportWidth");
|
|
1
|
+
import { isQueryMatching } from "./mockViewportWidth";
|
|
4
2
|
describe("isQueryMatching", () => {
|
|
5
3
|
it("should return false on max-width", () => {
|
|
6
|
-
const result =
|
|
4
|
+
const result = isQueryMatching(`max-width: ${window.innerWidth - 1}`);
|
|
7
5
|
expect(result).toBe(false);
|
|
8
6
|
});
|
|
9
7
|
it("should return true on min-width", () => {
|
|
10
|
-
const result =
|
|
8
|
+
const result = isQueryMatching(`min-width: ${window.innerWidth}`);
|
|
11
9
|
expect(result).toBe(true);
|
|
12
10
|
});
|
|
13
11
|
it("should return false when the width is not a number", () => {
|
|
14
|
-
const result =
|
|
12
|
+
const result = isQueryMatching(`width = not-a-number`);
|
|
15
13
|
expect(result).toBe(false);
|
|
16
14
|
});
|
|
17
15
|
});
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BREAKPOINT_SIZES = void 0;
|
|
4
|
-
exports.useBreakpoints = useBreakpoints;
|
|
5
|
-
const useMediaQuery_1 = require("./useMediaQuery");
|
|
6
|
-
exports.BREAKPOINT_SIZES = { sm: 490, md: 768, lg: 1080, xl: 1440 };
|
|
1
|
+
import { useMediaQuery } from "./useMediaQuery";
|
|
2
|
+
export const BREAKPOINT_SIZES = { sm: 490, md: 768, lg: 1080, xl: 1440 };
|
|
7
3
|
/**
|
|
8
4
|
* Hook equivalent of CSS media queries with our
|
|
9
5
|
* [supported breakpoints](https://atlantis.getjobber.com/design/breakpoints).
|
|
10
6
|
*/
|
|
11
|
-
function useBreakpoints() {
|
|
12
|
-
const { sm, md, lg, xl } =
|
|
13
|
-
const extraSmallOnly =
|
|
14
|
-
const smallAndUp =
|
|
15
|
-
const mediumAndUp =
|
|
16
|
-
const largeAndUp =
|
|
17
|
-
const extraLargeAndUp =
|
|
7
|
+
export function useBreakpoints() {
|
|
8
|
+
const { sm, md, lg, xl } = BREAKPOINT_SIZES;
|
|
9
|
+
const extraSmallOnly = useMediaQuery(`(max-width: ${sm - 1}px)`);
|
|
10
|
+
const smallAndUp = useMediaQuery(`(min-width: ${sm}px)`);
|
|
11
|
+
const mediumAndUp = useMediaQuery(`(min-width: ${md}px)`);
|
|
12
|
+
const largeAndUp = useMediaQuery(`(min-width: ${lg}px)`);
|
|
13
|
+
const extraLargeAndUp = useMediaQuery(`(min-width: ${xl}px)`);
|
|
18
14
|
return {
|
|
19
15
|
smallAndUp,
|
|
20
16
|
mediumAndUp,
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const react_1 = require("@testing-library/react");
|
|
7
|
-
const random_1 = __importDefault(require("lodash/random"));
|
|
8
|
-
const mockViewportWidth_1 = require("./mockViewportWidth");
|
|
9
|
-
const useBreakpoints_1 = require("./useBreakpoints");
|
|
10
|
-
const { cleanup, setViewportWidth } = (0, mockViewportWidth_1.mockViewportWidth)();
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import random from "lodash/random";
|
|
3
|
+
import { mockViewportWidth } from "./mockViewportWidth";
|
|
4
|
+
import { BREAKPOINT_SIZES, useBreakpoints } from "./useBreakpoints";
|
|
5
|
+
const { cleanup, setViewportWidth } = mockViewportWidth();
|
|
11
6
|
afterEach(cleanup);
|
|
12
7
|
describe("useBreakpoints", () => {
|
|
13
8
|
describe("and up", () => {
|
|
14
9
|
it("should have the correct breakpoint values on xl size screens", () => {
|
|
15
|
-
setViewportWidth(
|
|
16
|
-
const { result } =
|
|
10
|
+
setViewportWidth(BREAKPOINT_SIZES.xl);
|
|
11
|
+
const { result } = renderHook(useBreakpoints);
|
|
17
12
|
expect(result.current).toMatchObject({
|
|
18
13
|
smallAndUp: true,
|
|
19
14
|
mediumAndUp: true,
|
|
@@ -22,8 +17,8 @@ describe("useBreakpoints", () => {
|
|
|
22
17
|
});
|
|
23
18
|
});
|
|
24
19
|
it("should have the correct breakpoint values on lg size screens", () => {
|
|
25
|
-
setViewportWidth(
|
|
26
|
-
const { result } =
|
|
20
|
+
setViewportWidth(BREAKPOINT_SIZES.lg);
|
|
21
|
+
const { result } = renderHook(useBreakpoints);
|
|
27
22
|
expect(result.current).toMatchObject({
|
|
28
23
|
smallAndUp: true,
|
|
29
24
|
mediumAndUp: true,
|
|
@@ -32,8 +27,8 @@ describe("useBreakpoints", () => {
|
|
|
32
27
|
});
|
|
33
28
|
});
|
|
34
29
|
it("should have the correct breakpoint values on md size screens", () => {
|
|
35
|
-
setViewportWidth(
|
|
36
|
-
const { result } =
|
|
30
|
+
setViewportWidth(BREAKPOINT_SIZES.md);
|
|
31
|
+
const { result } = renderHook(useBreakpoints);
|
|
37
32
|
expect(result.current).toMatchObject({
|
|
38
33
|
smallAndUp: true,
|
|
39
34
|
mediumAndUp: true,
|
|
@@ -42,8 +37,8 @@ describe("useBreakpoints", () => {
|
|
|
42
37
|
});
|
|
43
38
|
});
|
|
44
39
|
it("should have the correct breakpoint values on sm size screens", () => {
|
|
45
|
-
setViewportWidth(
|
|
46
|
-
const { result } =
|
|
40
|
+
setViewportWidth(BREAKPOINT_SIZES.sm);
|
|
41
|
+
const { result } = renderHook(useBreakpoints);
|
|
47
42
|
expect(result.current).toMatchObject({
|
|
48
43
|
smallAndUp: true,
|
|
49
44
|
mediumAndUp: false,
|
|
@@ -54,8 +49,8 @@ describe("useBreakpoints", () => {
|
|
|
54
49
|
});
|
|
55
50
|
describe("only", () => {
|
|
56
51
|
it("should only set the extraSmallOnly to true on smaller than sm", () => {
|
|
57
|
-
setViewportWidth(
|
|
58
|
-
const { result } =
|
|
52
|
+
setViewportWidth(BREAKPOINT_SIZES.sm - 1);
|
|
53
|
+
const { result } = renderHook(useBreakpoints);
|
|
59
54
|
expect(result.current).toMatchObject({
|
|
60
55
|
extraSmallOnly: true,
|
|
61
56
|
smallOnly: false,
|
|
@@ -64,8 +59,8 @@ describe("useBreakpoints", () => {
|
|
|
64
59
|
});
|
|
65
60
|
});
|
|
66
61
|
it("should only set the smallOnly to true on sm", () => {
|
|
67
|
-
setViewportWidth(
|
|
68
|
-
const { result } =
|
|
62
|
+
setViewportWidth(BREAKPOINT_SIZES.sm);
|
|
63
|
+
const { result } = renderHook(useBreakpoints);
|
|
69
64
|
expect(result.current).toMatchObject({
|
|
70
65
|
extraSmallOnly: false,
|
|
71
66
|
smallOnly: true,
|
|
@@ -74,8 +69,8 @@ describe("useBreakpoints", () => {
|
|
|
74
69
|
});
|
|
75
70
|
});
|
|
76
71
|
it("should only set the mediumOnly to true on md", () => {
|
|
77
|
-
setViewportWidth(
|
|
78
|
-
const { result } =
|
|
72
|
+
setViewportWidth(BREAKPOINT_SIZES.md);
|
|
73
|
+
const { result } = renderHook(useBreakpoints);
|
|
79
74
|
expect(result.current).toMatchObject({
|
|
80
75
|
extraSmallOnly: false,
|
|
81
76
|
smallOnly: false,
|
|
@@ -84,8 +79,8 @@ describe("useBreakpoints", () => {
|
|
|
84
79
|
});
|
|
85
80
|
});
|
|
86
81
|
it("should only set the largeOnly to true on lg", () => {
|
|
87
|
-
setViewportWidth(
|
|
88
|
-
const { result } =
|
|
82
|
+
setViewportWidth(BREAKPOINT_SIZES.lg);
|
|
83
|
+
const { result } = renderHook(useBreakpoints);
|
|
89
84
|
expect(result.current).toMatchObject({
|
|
90
85
|
extraSmallOnly: false,
|
|
91
86
|
smallOnly: false,
|
|
@@ -96,11 +91,11 @@ describe("useBreakpoints", () => {
|
|
|
96
91
|
});
|
|
97
92
|
describe("in between values", () => {
|
|
98
93
|
function randomBreakpoint(min, max) {
|
|
99
|
-
return (
|
|
94
|
+
return random(min, max - 1);
|
|
100
95
|
}
|
|
101
96
|
it("should have the correct breakpoint values on higher than xl size screens", () => {
|
|
102
|
-
setViewportWidth(randomBreakpoint(
|
|
103
|
-
const { result } =
|
|
97
|
+
setViewportWidth(randomBreakpoint(BREAKPOINT_SIZES.xl, 10000));
|
|
98
|
+
const { result } = renderHook(useBreakpoints);
|
|
104
99
|
expect(result.current).toMatchObject({
|
|
105
100
|
smallAndUp: true,
|
|
106
101
|
mediumAndUp: true,
|
|
@@ -109,8 +104,8 @@ describe("useBreakpoints", () => {
|
|
|
109
104
|
});
|
|
110
105
|
});
|
|
111
106
|
it("should have the correct breakpoint values on lg size screens", () => {
|
|
112
|
-
setViewportWidth(randomBreakpoint(
|
|
113
|
-
const { result } =
|
|
107
|
+
setViewportWidth(randomBreakpoint(BREAKPOINT_SIZES.lg, BREAKPOINT_SIZES.xl));
|
|
108
|
+
const { result } = renderHook(useBreakpoints);
|
|
114
109
|
expect(result.current).toMatchObject({
|
|
115
110
|
smallAndUp: true,
|
|
116
111
|
mediumAndUp: true,
|
|
@@ -119,8 +114,8 @@ describe("useBreakpoints", () => {
|
|
|
119
114
|
});
|
|
120
115
|
});
|
|
121
116
|
it("should have the correct breakpoint values on md size screens", () => {
|
|
122
|
-
setViewportWidth(randomBreakpoint(
|
|
123
|
-
const { result } =
|
|
117
|
+
setViewportWidth(randomBreakpoint(BREAKPOINT_SIZES.md, BREAKPOINT_SIZES.lg));
|
|
118
|
+
const { result } = renderHook(useBreakpoints);
|
|
124
119
|
expect(result.current).toMatchObject({
|
|
125
120
|
smallAndUp: true,
|
|
126
121
|
mediumAndUp: true,
|
|
@@ -129,8 +124,8 @@ describe("useBreakpoints", () => {
|
|
|
129
124
|
});
|
|
130
125
|
});
|
|
131
126
|
it("should have the correct breakpoint values on sm size screens", () => {
|
|
132
|
-
setViewportWidth(randomBreakpoint(
|
|
133
|
-
const { result } =
|
|
127
|
+
setViewportWidth(randomBreakpoint(BREAKPOINT_SIZES.sm, BREAKPOINT_SIZES.md));
|
|
128
|
+
const { result } = renderHook(useBreakpoints);
|
|
134
129
|
expect(result.current).toMatchObject({
|
|
135
130
|
smallAndUp: true,
|
|
136
131
|
mediumAndUp: false,
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.mediaQueryStore = void 0;
|
|
4
|
-
exports.useMediaQuery = useMediaQuery;
|
|
5
|
-
const react_1 = require("react");
|
|
6
|
-
exports.mediaQueryStore = {
|
|
1
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
2
|
+
export const mediaQueryStore = {
|
|
7
3
|
subscribe(onChange, query) {
|
|
8
4
|
const matchMedia = window.matchMedia(query);
|
|
9
5
|
matchMedia.addEventListener("change", onChange);
|
|
@@ -15,8 +11,8 @@ exports.mediaQueryStore = {
|
|
|
15
11
|
return () => window.matchMedia(query).matches;
|
|
16
12
|
},
|
|
17
13
|
};
|
|
18
|
-
function useMediaQuery(query) {
|
|
19
|
-
const subscribeMediaQuery =
|
|
20
|
-
const matches =
|
|
14
|
+
export function useMediaQuery(query) {
|
|
15
|
+
const subscribeMediaQuery = useCallback((onChange) => mediaQueryStore.subscribe(onChange, query), [query]);
|
|
16
|
+
const matches = useSyncExternalStore(subscribeMediaQuery, mediaQueryStore.getSnapshot(query), () => true);
|
|
21
17
|
return matches;
|
|
22
18
|
}
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCallbackRef = void 0;
|
|
4
|
-
var useCallbackRef_1 = require("./useCallbackRef");
|
|
5
|
-
Object.defineProperty(exports, "useCallbackRef", { enumerable: true, get: function () { return useCallbackRef_1.useCallbackRef; } });
|
|
1
|
+
export { useCallbackRef } from "./useCallbackRef";
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCallbackRef = useCallbackRef;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
5
2
|
/**
|
|
6
3
|
* A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
7
4
|
* prop or avoid re-executing effects when passed as a dependency
|
|
8
5
|
*/
|
|
9
|
-
function useCallbackRef(callback) {
|
|
10
|
-
const callbackRef =
|
|
11
|
-
|
|
6
|
+
export function useCallbackRef(callback) {
|
|
7
|
+
const callbackRef = useRef(callback);
|
|
8
|
+
useEffect(() => {
|
|
12
9
|
callbackRef.current = callback;
|
|
13
10
|
});
|
|
14
|
-
return
|
|
11
|
+
return useMemo(() => ((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }), []);
|
|
15
12
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const react_1 = require("@testing-library/react");
|
|
4
|
-
const _1 = require(".");
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { useCallbackRef } from ".";
|
|
5
3
|
describe("useCallbackRef", () => {
|
|
6
4
|
it("should replace function when a new one is provided", () => {
|
|
7
5
|
const callbackInitial = jest.fn();
|
|
8
6
|
const callbackReplaced = jest.fn();
|
|
9
|
-
const { rerender, result } =
|
|
7
|
+
const { rerender, result } = renderHook(useCallbackRef, {
|
|
10
8
|
initialProps: callbackInitial,
|
|
11
9
|
});
|
|
12
10
|
result.current("my args");
|
|
@@ -17,7 +15,7 @@ describe("useCallbackRef", () => {
|
|
|
17
15
|
});
|
|
18
16
|
it("should not run function when it's undefined", () => {
|
|
19
17
|
const callbackInitial = jest.fn();
|
|
20
|
-
const { rerender, result } =
|
|
18
|
+
const { rerender, result } = renderHook(useCallbackRef, {
|
|
21
19
|
initialProps: callbackInitial,
|
|
22
20
|
});
|
|
23
21
|
result.current("my args");
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCollectionQuery = void 0;
|
|
4
|
-
var useCollectionQuery_1 = require("./useCollectionQuery");
|
|
5
|
-
Object.defineProperty(exports, "useCollectionQuery", { enumerable: true, get: function () { return useCollectionQuery_1.useCollectionQuery; } });
|
|
1
|
+
export { useCollectionQuery } from "./useCollectionQuery";
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.returnValues = exports.subscriptionPropsList = exports.propsList = exports.apolloClient = exports.LIST_QUERY = void 0;
|
|
4
|
-
exports.getLoadingState = getLoadingState;
|
|
5
|
-
const client_1 = require("@apollo/client");
|
|
6
|
-
exports.LIST_QUERY = (0, client_1.gql) `
|
|
1
|
+
import { ApolloClient, InMemoryCache, gql } from "@apollo/client";
|
|
2
|
+
export const LIST_QUERY = gql `
|
|
7
3
|
query ListQuery($cursor: String) {
|
|
8
4
|
allPlanets(first: 4, after: $cursor) {
|
|
9
5
|
pageInfo {
|
|
@@ -20,11 +16,11 @@ exports.LIST_QUERY = (0, client_1.gql) `
|
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
18
|
`;
|
|
23
|
-
|
|
19
|
+
export const apolloClient = new ApolloClient({
|
|
24
20
|
uri: "https://swapi-graphql.netlify.app/graphql",
|
|
25
|
-
cache: new
|
|
21
|
+
cache: new InMemoryCache(),
|
|
26
22
|
});
|
|
27
|
-
function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage) {
|
|
23
|
+
export function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage) {
|
|
28
24
|
if (loadingInitialContent) {
|
|
29
25
|
return {
|
|
30
26
|
loading: true,
|
|
@@ -48,7 +44,7 @@ function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage)
|
|
|
48
44
|
loadingStatus: "Loaded",
|
|
49
45
|
};
|
|
50
46
|
}
|
|
51
|
-
|
|
47
|
+
export const propsList = [
|
|
52
48
|
{
|
|
53
49
|
id: 0,
|
|
54
50
|
title: "query",
|
|
@@ -79,7 +75,7 @@ exports.propsList = [
|
|
|
79
75
|
value: "SubscriptionProps",
|
|
80
76
|
},
|
|
81
77
|
];
|
|
82
|
-
|
|
78
|
+
export const subscriptionPropsList = [
|
|
83
79
|
{
|
|
84
80
|
id: 0,
|
|
85
81
|
title: "document",
|
|
@@ -106,7 +102,7 @@ exports.subscriptionPropsList = [
|
|
|
106
102
|
value: "GetNodeByPath<TSubscription>",
|
|
107
103
|
},
|
|
108
104
|
];
|
|
109
|
-
|
|
105
|
+
export const returnValues = [
|
|
110
106
|
{
|
|
111
107
|
id: 0,
|
|
112
108
|
title: "data",
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./queries"), exports);
|
|
18
|
-
__exportStar(require("./utils"), exports);
|
|
19
|
-
__exportStar(require("./mocks"), exports);
|
|
1
|
+
export * from "./queries";
|
|
2
|
+
export * from "./utils";
|
|
3
|
+
export * from "./mocks";
|