@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
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_2 = require("@testing-library/react");
|
|
8
|
-
const _1 = require(".");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react";
|
|
3
|
+
import { useOnKeyDown } from ".";
|
|
9
4
|
test("fires the method when the key is pressed", () => {
|
|
10
5
|
const keypressCallback = jest.fn();
|
|
11
|
-
const { container } =
|
|
6
|
+
const { container } = render(React.createElement(TestComponent, { callback: keypressCallback }));
|
|
12
7
|
expect(keypressCallback).toHaveBeenCalledTimes(0);
|
|
13
|
-
|
|
8
|
+
fireEvent(container, new KeyboardEvent("keydown", {
|
|
14
9
|
key: "Enter",
|
|
15
10
|
bubbles: true,
|
|
16
11
|
cancelable: false,
|
|
@@ -18,6 +13,6 @@ test("fires the method when the key is pressed", () => {
|
|
|
18
13
|
expect(keypressCallback).toHaveBeenCalledTimes(1);
|
|
19
14
|
});
|
|
20
15
|
function TestComponent({ callback }) {
|
|
21
|
-
|
|
22
|
-
return
|
|
16
|
+
useOnKeyDown(callback, "Enter");
|
|
17
|
+
return React.createElement(React.Fragment, null, "Look at me!");
|
|
23
18
|
}
|
package/dist/useOnMount/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useOnMount = void 0;
|
|
4
|
-
var useOnMount_1 = require("./useOnMount");
|
|
5
|
-
Object.defineProperty(exports, "useOnMount", { enumerable: true, get: function () { return useOnMount_1.useOnMount; } });
|
|
1
|
+
export { useOnMount } from "./useOnMount";
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useOnMount = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useCallbackRef_1 = require("../useCallbackRef");
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { useCallbackRef } from "../useCallbackRef";
|
|
6
3
|
/**
|
|
7
4
|
* A custom hook that will call the provided function only once when the component mounts. Useful for emitting
|
|
8
5
|
* analytics tracking events on component mount.
|
|
9
6
|
*/
|
|
10
|
-
const useOnMount = (fn) => {
|
|
11
|
-
const mountedRef =
|
|
12
|
-
const callback =
|
|
13
|
-
|
|
7
|
+
export const useOnMount = (fn) => {
|
|
8
|
+
const mountedRef = useRef(false);
|
|
9
|
+
const callback = useCallbackRef(fn);
|
|
10
|
+
useEffect(() => {
|
|
14
11
|
if (!mountedRef.current) {
|
|
15
12
|
mountedRef.current = true;
|
|
16
13
|
callback();
|
|
17
14
|
}
|
|
18
15
|
}, [callback]);
|
|
19
16
|
};
|
|
20
|
-
exports.useOnMount = useOnMount;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const react_1 = require("@testing-library/react");
|
|
4
|
-
const useOnMount_1 = require("./useOnMount");
|
|
1
|
+
import { renderHook } from "@testing-library/react";
|
|
2
|
+
import { useOnMount } from "./useOnMount";
|
|
5
3
|
describe("useOnMount", () => {
|
|
6
4
|
it("should call the function on mount", () => {
|
|
7
5
|
const fn = jest.fn();
|
|
8
|
-
|
|
6
|
+
renderHook(() => useOnMount(fn));
|
|
9
7
|
expect(fn).toHaveBeenCalledTimes(1);
|
|
10
8
|
});
|
|
11
9
|
it("should only call function once when re-rendered", () => {
|
|
12
10
|
const fn = jest.fn();
|
|
13
|
-
const view =
|
|
11
|
+
const view = renderHook(() => useOnMount(fn));
|
|
14
12
|
expect(fn).toHaveBeenCalledTimes(1);
|
|
15
13
|
view.rerender();
|
|
16
14
|
expect(fn).toHaveBeenCalledTimes(1);
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRefocusOnActivator = void 0;
|
|
4
|
-
var useRefocusOnActivator_1 = require("./useRefocusOnActivator");
|
|
5
|
-
Object.defineProperty(exports, "useRefocusOnActivator", { enumerable: true, get: function () { return useRefocusOnActivator_1.useRefocusOnActivator; } });
|
|
1
|
+
export { useRefocusOnActivator } from "./useRefocusOnActivator";
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useRefocusOnActivator = useRefocusOnActivator;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect } from "react";
|
|
5
2
|
/**
|
|
6
3
|
* Brings back the focus to the element that opened an overlaid element once
|
|
7
4
|
* said overlaid element is dismissed.
|
|
8
5
|
*
|
|
9
6
|
* @param active - Determines if it should focus or not
|
|
10
7
|
*/
|
|
11
|
-
function useRefocusOnActivator(active) {
|
|
12
|
-
|
|
8
|
+
export function useRefocusOnActivator(active) {
|
|
9
|
+
useEffect(() => {
|
|
13
10
|
let activator;
|
|
14
11
|
if (active && !activator) {
|
|
15
12
|
activator = document.activeElement;
|
|
@@ -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("./useResizeObserver"), exports);
|
|
1
|
+
export * from "./useResizeObserver";
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Breakpoints = void 0;
|
|
7
|
-
exports.useResizeObserver = useResizeObserver;
|
|
8
|
-
const react_1 = require("react");
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
9
2
|
// Importing the polyfilled version of ResizeObserver
|
|
10
3
|
// eslint-disable-next-line import/no-internal-modules
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
import useResizeObserverPackage from "use-resize-observer/polyfilled";
|
|
5
|
+
import throttle from "lodash/throttle";
|
|
6
|
+
export const Breakpoints = {
|
|
14
7
|
base: 640,
|
|
15
8
|
small: 500,
|
|
16
9
|
smaller: 265,
|
|
@@ -18,13 +11,13 @@ exports.Breakpoints = {
|
|
|
18
11
|
larger: 1024,
|
|
19
12
|
};
|
|
20
13
|
const wait = 100;
|
|
21
|
-
function useResizeObserver({ widths =
|
|
22
|
-
const [exactSize, setSize] =
|
|
14
|
+
export function useResizeObserver({ widths = Breakpoints, heights = Breakpoints, } = {}) {
|
|
15
|
+
const [exactSize, setSize] = useState({
|
|
23
16
|
width: undefined,
|
|
24
17
|
height: undefined,
|
|
25
18
|
});
|
|
26
|
-
const onResize =
|
|
27
|
-
return (
|
|
19
|
+
const onResize = useMemo(() => {
|
|
20
|
+
return throttle(({ width, height }) => {
|
|
28
21
|
if (!width || width <= 1) {
|
|
29
22
|
// Ignore invalid values. ResizeObserver is unexpectedly looping between 1 and the actual
|
|
30
23
|
// width of the element. This is only happening in playwright chromium.
|
|
@@ -34,7 +27,7 @@ function useResizeObserver({ widths = exports.Breakpoints, heights = exports.Bre
|
|
|
34
27
|
setSize({ width, height });
|
|
35
28
|
}, wait);
|
|
36
29
|
}, []);
|
|
37
|
-
const { ref } = (
|
|
30
|
+
const { ref } = useResizeObserverPackage({
|
|
38
31
|
onResize,
|
|
39
32
|
});
|
|
40
33
|
const exactWidth = exactSize.width;
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSafeLayoutEffect = void 0;
|
|
4
|
-
var useSafeLayoutEffect_1 = require("./useSafeLayoutEffect");
|
|
5
|
-
Object.defineProperty(exports, "useSafeLayoutEffect", { enumerable: true, get: function () { return useSafeLayoutEffect_1.useSafeLayoutEffect; } });
|
|
1
|
+
export { useSafeLayoutEffect } from "./useSafeLayoutEffect";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.useSafeLayoutEffect = (globalThis === null || globalThis === void 0 ? void 0 : globalThis.document)
|
|
6
|
-
? react_1.useLayoutEffect
|
|
7
|
-
: react_1.useEffect;
|
|
1
|
+
import { useEffect, useLayoutEffect } from "react";
|
|
2
|
+
export const useSafeLayoutEffect = (globalThis === null || globalThis === void 0 ? void 0 : globalThis.document)
|
|
3
|
+
? useLayoutEffect
|
|
4
|
+
: useEffect;
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useShowClear = void 0;
|
|
4
|
-
var useShowClear_1 = require("./useShowClear");
|
|
5
|
-
Object.defineProperty(exports, "useShowClear", { enumerable: true, get: function () { return useShowClear_1.useShowClear; } });
|
|
1
|
+
export { useShowClear } from "./useShowClear";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useShowClear = useShowClear;
|
|
4
|
-
function useShowClear({ clearable, multiline, focused, hasValue, readonly, disabled = false, }) {
|
|
1
|
+
export function useShowClear({ clearable, multiline, focused, hasValue, readonly, disabled = false, }) {
|
|
5
2
|
if (multiline && clearable !== "never") {
|
|
6
3
|
throw new Error("Multiline inputs can not be clearable");
|
|
7
4
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const useShowClear_1 = require("./useShowClear");
|
|
1
|
+
import { useShowClear } from "./useShowClear";
|
|
4
2
|
describe("useShowClear", () => {
|
|
5
3
|
describe.each([
|
|
6
4
|
{
|
|
@@ -156,7 +154,7 @@ describe("useShowClear", () => {
|
|
|
156
154
|
},
|
|
157
155
|
])("%j", ({ clearable, hasValue, focused, multiline, disabled, readonly, expected, }) => {
|
|
158
156
|
it(`returns ${expected}`, () => {
|
|
159
|
-
expect(
|
|
157
|
+
expect(useShowClear({
|
|
160
158
|
clearable,
|
|
161
159
|
multiline,
|
|
162
160
|
focused,
|
|
@@ -168,7 +166,7 @@ describe("useShowClear", () => {
|
|
|
168
166
|
});
|
|
169
167
|
it("throws an error if multiline is true and clearable isn't never", () => {
|
|
170
168
|
expect(() => {
|
|
171
|
-
|
|
169
|
+
useShowClear({
|
|
172
170
|
clearable: "always",
|
|
173
171
|
multiline: true,
|
|
174
172
|
focused: true,
|
|
@@ -177,7 +175,7 @@ describe("useShowClear", () => {
|
|
|
177
175
|
});
|
|
178
176
|
}).toThrow();
|
|
179
177
|
expect(() => {
|
|
180
|
-
|
|
178
|
+
useShowClear({
|
|
181
179
|
clearable: "while-editing",
|
|
182
180
|
multiline: true,
|
|
183
181
|
focused: true,
|
|
@@ -186,7 +184,7 @@ describe("useShowClear", () => {
|
|
|
186
184
|
});
|
|
187
185
|
}).toThrow();
|
|
188
186
|
expect(() => {
|
|
189
|
-
|
|
187
|
+
useShowClear({
|
|
190
188
|
clearable: "never",
|
|
191
189
|
multiline: true,
|
|
192
190
|
focused: true,
|
|
@@ -197,7 +195,7 @@ describe("useShowClear", () => {
|
|
|
197
195
|
});
|
|
198
196
|
it("respects readonly in multiline inputs", () => {
|
|
199
197
|
expect(() => {
|
|
200
|
-
|
|
198
|
+
useShowClear({
|
|
201
199
|
clearable: "never",
|
|
202
200
|
multiline: true,
|
|
203
201
|
focused: true,
|
package/dist/useStepper/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useStepper = void 0;
|
|
4
|
-
var useStepper_1 = require("./useStepper");
|
|
5
|
-
Object.defineProperty(exports, "useStepper", { enumerable: true, get: function () { return useStepper_1.useStepper; } });
|
|
1
|
+
export { useStepper } from "./useStepper";
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useStepper = useStepper;
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
9
|
-
function useStepper(steps, options = {}) {
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
2
|
+
import invariant from "tiny-invariant";
|
|
3
|
+
export function useStepper(steps, options = {}) {
|
|
10
4
|
var _a;
|
|
11
5
|
const firstStep = (_a = options === null || options === void 0 ? void 0 : options.defaultStep) !== null && _a !== void 0 ? _a : steps[0];
|
|
12
|
-
(
|
|
13
|
-
const [currentStep, setCurrentStep] =
|
|
14
|
-
const currentActiveStep =
|
|
6
|
+
invariant(firstStep, "Steps array cannot be empty");
|
|
7
|
+
const [currentStep, setCurrentStep] = useState(firstStep);
|
|
8
|
+
const currentActiveStep = useMemo(() => ({
|
|
15
9
|
currentStep,
|
|
16
10
|
isFirst: currentStep === steps[0],
|
|
17
11
|
isLast: currentStep === steps[steps.length - 1],
|
|
18
12
|
}), [currentStep, steps]);
|
|
19
|
-
const handlers =
|
|
13
|
+
const handlers = useMemo(() => ({
|
|
20
14
|
goToStep: (step) => {
|
|
21
15
|
setCurrentStep(step);
|
|
22
16
|
},
|
|
@@ -24,7 +18,7 @@ function useStepper(steps, options = {}) {
|
|
|
24
18
|
setCurrentStep(prevCurrentStep => {
|
|
25
19
|
const currentIndex = steps.indexOf(prevCurrentStep);
|
|
26
20
|
const nextStep = steps[Math.min(currentIndex + 1, steps.length - 1)];
|
|
27
|
-
(
|
|
21
|
+
invariant(nextStep, `Index out of bounds: ${currentIndex + 1}`);
|
|
28
22
|
return nextStep;
|
|
29
23
|
});
|
|
30
24
|
},
|
|
@@ -32,7 +26,7 @@ function useStepper(steps, options = {}) {
|
|
|
32
26
|
setCurrentStep(prevCurrentStep => {
|
|
33
27
|
const currentIndex = steps.indexOf(prevCurrentStep);
|
|
34
28
|
const previousStep = steps[Math.max(currentIndex - 1, 0)];
|
|
35
|
-
(
|
|
29
|
+
invariant(previousStep, `Index out of bounds: ${currentIndex - 1}`);
|
|
36
30
|
return previousStep;
|
|
37
31
|
});
|
|
38
32
|
},
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const react_1 = require("@testing-library/react");
|
|
4
|
-
const _1 = require(".");
|
|
1
|
+
import { act, renderHook } from "@testing-library/react";
|
|
2
|
+
import { useStepper } from ".";
|
|
5
3
|
const steps = ["step1", "step2", "step3"];
|
|
6
4
|
describe("useStepper", () => {
|
|
7
5
|
it("initializes with first step when no initial step provided", () => {
|
|
8
|
-
const { result } =
|
|
6
|
+
const { result } = renderHook(() => useStepper(steps));
|
|
9
7
|
expect(result.current.currentStep).toBe("step1");
|
|
10
8
|
expect(result.current.isFirst).toBe(true);
|
|
11
9
|
expect(result.current.isLast).toBe(false);
|
|
12
10
|
});
|
|
13
11
|
it("initializes with provided initial step", () => {
|
|
14
|
-
const { result } =
|
|
12
|
+
const { result } = renderHook(() => useStepper(["step1", "step2", "step3"], {
|
|
15
13
|
defaultStep: "step2",
|
|
16
14
|
}));
|
|
17
15
|
expect(result.current.currentStep).toBe("step2");
|
|
@@ -19,8 +17,8 @@ describe("useStepper", () => {
|
|
|
19
17
|
expect(result.current.isLast).toBe(false);
|
|
20
18
|
});
|
|
21
19
|
it("moves to next step when nextStep is called", () => {
|
|
22
|
-
const { result } =
|
|
23
|
-
|
|
20
|
+
const { result } = renderHook(() => useStepper(steps));
|
|
21
|
+
act(() => {
|
|
24
22
|
result.current.goToNextStep();
|
|
25
23
|
});
|
|
26
24
|
expect(result.current.currentStep).toBe("step2");
|
|
@@ -28,10 +26,10 @@ describe("useStepper", () => {
|
|
|
28
26
|
expect(result.current.isFirst).toBe(false);
|
|
29
27
|
});
|
|
30
28
|
it("moves to previous step when previousStep is called", () => {
|
|
31
|
-
const { result } =
|
|
29
|
+
const { result } = renderHook(() => useStepper(steps, {
|
|
32
30
|
defaultStep: "step2",
|
|
33
31
|
}));
|
|
34
|
-
|
|
32
|
+
act(() => {
|
|
35
33
|
result.current.goToPreviousStep();
|
|
36
34
|
});
|
|
37
35
|
expect(result.current.currentStep).toBe("step1");
|
|
@@ -39,10 +37,10 @@ describe("useStepper", () => {
|
|
|
39
37
|
expect(result.current.isFirst).toBe(true);
|
|
40
38
|
});
|
|
41
39
|
it("does not move past the last step", () => {
|
|
42
|
-
const { result } =
|
|
40
|
+
const { result } = renderHook(() => useStepper(steps, {
|
|
43
41
|
defaultStep: "step3",
|
|
44
42
|
}));
|
|
45
|
-
|
|
43
|
+
act(() => {
|
|
46
44
|
result.current.goToNextStep();
|
|
47
45
|
});
|
|
48
46
|
expect(result.current.currentStep).toBe("step3");
|
|
@@ -50,10 +48,10 @@ describe("useStepper", () => {
|
|
|
50
48
|
expect(result.current.isFirst).toBe(false);
|
|
51
49
|
});
|
|
52
50
|
it("does not move before the first step", () => {
|
|
53
|
-
const { result } =
|
|
51
|
+
const { result } = renderHook(() => useStepper(steps, {
|
|
54
52
|
defaultStep: "step1",
|
|
55
53
|
}));
|
|
56
|
-
|
|
54
|
+
act(() => {
|
|
57
55
|
result.current.goToPreviousStep();
|
|
58
56
|
});
|
|
59
57
|
expect(result.current.currentStep).toBe("step1");
|
|
@@ -61,8 +59,8 @@ describe("useStepper", () => {
|
|
|
61
59
|
expect(result.current.isLast).toBe(false);
|
|
62
60
|
});
|
|
63
61
|
it("moves to specific step when goToStep is called", () => {
|
|
64
|
-
const { result } =
|
|
65
|
-
|
|
62
|
+
const { result } = renderHook(() => useStepper(steps));
|
|
63
|
+
act(() => {
|
|
66
64
|
result.current.goToStep("step3");
|
|
67
65
|
});
|
|
68
66
|
expect(result.current.currentStep).toBe("step3");
|
|
@@ -72,7 +70,7 @@ describe("useStepper", () => {
|
|
|
72
70
|
describe("error handling", () => {
|
|
73
71
|
it("throws error when steps array is empty", () => {
|
|
74
72
|
expect(() => {
|
|
75
|
-
|
|
73
|
+
renderHook(() => useStepper([]));
|
|
76
74
|
}).toThrow(new Error("Invariant failed: Steps array cannot be empty"));
|
|
77
75
|
});
|
|
78
76
|
});
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useWindowDimensions = void 0;
|
|
4
|
-
var useWindowDimensions_1 = require("./useWindowDimensions");
|
|
5
|
-
Object.defineProperty(exports, "useWindowDimensions", { enumerable: true, get: function () { return useWindowDimensions_1.useWindowDimensions; } });
|
|
1
|
+
export { useWindowDimensions } from "./useWindowDimensions";
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const react_1 = require("@testing-library/react");
|
|
5
|
-
const useWindowDimensions_1 = require("./useWindowDimensions");
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { fireEvent } from "@testing-library/react";
|
|
3
|
+
import { useWindowDimensions } from "./useWindowDimensions";
|
|
6
4
|
describe("useWindowDimensions", () => {
|
|
7
5
|
it("should return window dimensions", () => {
|
|
8
6
|
window.innerHeight = 100;
|
|
9
7
|
window.innerWidth = 1000;
|
|
10
|
-
const { result } =
|
|
8
|
+
const { result } = renderHook(() => useWindowDimensions());
|
|
11
9
|
expect(result.current).toEqual({ width: 1000, height: 100 });
|
|
12
10
|
});
|
|
13
11
|
describe("resize event", () => {
|
|
14
12
|
it("should return window dimensions after resize", () => {
|
|
15
13
|
window.innerHeight = 100;
|
|
16
14
|
window.innerWidth = 1000;
|
|
17
|
-
const { result } =
|
|
15
|
+
const { result } = renderHook(() => useWindowDimensions());
|
|
18
16
|
window.innerWidth = 500;
|
|
19
|
-
|
|
17
|
+
fireEvent(window, new Event("resize"));
|
|
20
18
|
expect(result.current).toEqual({ width: 500, height: 100 });
|
|
21
19
|
});
|
|
22
20
|
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useWindowDimensions = useWindowDimensions;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
5
2
|
function getWindowDimensions() {
|
|
6
3
|
if (!(globalThis === null || globalThis === void 0 ? void 0 : globalThis.document)) {
|
|
7
4
|
return {
|
|
@@ -15,9 +12,9 @@ function getWindowDimensions() {
|
|
|
15
12
|
height,
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
|
-
function useWindowDimensions() {
|
|
19
|
-
const [windowDimensions, setWindowDimensions] =
|
|
20
|
-
|
|
15
|
+
export function useWindowDimensions() {
|
|
16
|
+
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
|
|
17
|
+
useEffect(() => {
|
|
21
18
|
function handleResize() {
|
|
22
19
|
setWindowDimensions(getWindowDimensions());
|
|
23
20
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,106 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/hooks",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.2",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./useBool": {
|
|
14
|
+
"types": "./dist/useBool/index.d.ts",
|
|
15
|
+
"import": "./dist/useBool/index.js",
|
|
16
|
+
"require": "./dist/useBool/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./useBreakpoints": {
|
|
19
|
+
"types": "./dist/useBreakpoints/index.d.ts",
|
|
20
|
+
"import": "./dist/useBreakpoints/index.js",
|
|
21
|
+
"require": "./dist/useBreakpoints/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./useCallbackRef": {
|
|
24
|
+
"types": "./dist/useCallbackRef/index.d.ts",
|
|
25
|
+
"import": "./dist/useCallbackRef/index.js",
|
|
26
|
+
"require": "./dist/useCallbackRef/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./useCollectionQuery": {
|
|
29
|
+
"types": "./dist/useCollectionQuery/index.d.ts",
|
|
30
|
+
"import": "./dist/useCollectionQuery/index.js",
|
|
31
|
+
"require": "./dist/useCollectionQuery/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./useDebounce": {
|
|
34
|
+
"types": "./dist/useDebounce/index.d.ts",
|
|
35
|
+
"import": "./dist/useDebounce/index.js",
|
|
36
|
+
"require": "./dist/useDebounce/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./useFocusTrap": {
|
|
39
|
+
"types": "./dist/useFocusTrap/index.d.ts",
|
|
40
|
+
"import": "./dist/useFocusTrap/index.js",
|
|
41
|
+
"require": "./dist/useFocusTrap/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./useFormState": {
|
|
44
|
+
"types": "./dist/useFormState/index.d.ts",
|
|
45
|
+
"import": "./dist/useFormState/index.js",
|
|
46
|
+
"require": "./dist/useFormState/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./useInView": {
|
|
49
|
+
"types": "./dist/useInView/index.d.ts",
|
|
50
|
+
"import": "./dist/useInView/index.js",
|
|
51
|
+
"require": "./dist/useInView/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./useIsMounted": {
|
|
54
|
+
"types": "./dist/useIsMounted/index.d.ts",
|
|
55
|
+
"import": "./dist/useIsMounted/index.js",
|
|
56
|
+
"require": "./dist/useIsMounted/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./useLiveAnnounce": {
|
|
59
|
+
"types": "./dist/useLiveAnnounce/index.d.ts",
|
|
60
|
+
"import": "./dist/useLiveAnnounce/index.js",
|
|
61
|
+
"require": "./dist/useLiveAnnounce/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./useOnKeyDown": {
|
|
64
|
+
"types": "./dist/useOnKeyDown/index.d.ts",
|
|
65
|
+
"import": "./dist/useOnKeyDown/index.js",
|
|
66
|
+
"require": "./dist/useOnKeyDown/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./useOnMount": {
|
|
69
|
+
"types": "./dist/useOnMount/index.d.ts",
|
|
70
|
+
"import": "./dist/useOnMount/index.js",
|
|
71
|
+
"require": "./dist/useOnMount/index.js"
|
|
72
|
+
},
|
|
73
|
+
"./useRefocusOnActivator": {
|
|
74
|
+
"types": "./dist/useRefocusOnActivator/index.d.ts",
|
|
75
|
+
"import": "./dist/useRefocusOnActivator/index.js",
|
|
76
|
+
"require": "./dist/useRefocusOnActivator/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./useResizeObserver": {
|
|
79
|
+
"types": "./dist/useResizeObserver/index.d.ts",
|
|
80
|
+
"import": "./dist/useResizeObserver/index.js",
|
|
81
|
+
"require": "./dist/useResizeObserver/index.js"
|
|
82
|
+
},
|
|
83
|
+
"./useSafeLayoutEffect": {
|
|
84
|
+
"types": "./dist/useSafeLayoutEffect/index.d.ts",
|
|
85
|
+
"import": "./dist/useSafeLayoutEffect/index.js",
|
|
86
|
+
"require": "./dist/useSafeLayoutEffect/index.js"
|
|
87
|
+
},
|
|
88
|
+
"./useShowClear": {
|
|
89
|
+
"types": "./dist/useShowClear/index.d.ts",
|
|
90
|
+
"import": "./dist/useShowClear/index.js",
|
|
91
|
+
"require": "./dist/useShowClear/index.js"
|
|
92
|
+
},
|
|
93
|
+
"./useStepper": {
|
|
94
|
+
"types": "./dist/useStepper/index.d.ts",
|
|
95
|
+
"import": "./dist/useStepper/index.js",
|
|
96
|
+
"require": "./dist/useStepper/index.js"
|
|
97
|
+
},
|
|
98
|
+
"./useWindowDimensions": {
|
|
99
|
+
"types": "./dist/useWindowDimensions/index.d.ts",
|
|
100
|
+
"import": "./dist/useWindowDimensions/index.js",
|
|
101
|
+
"require": "./dist/useWindowDimensions/index.js"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
7
104
|
"scripts": {
|
|
8
105
|
"build": "tsc --project . --skipLibCheck",
|
|
9
106
|
"clean": "rm -rf dist/* tsconfig.tsbuildinfo",
|
|
@@ -20,7 +117,7 @@
|
|
|
20
117
|
],
|
|
21
118
|
"devDependencies": {
|
|
22
119
|
"@apollo/react-testing": "^4.0.0",
|
|
23
|
-
"@jobber/formatters": "^0.4.
|
|
120
|
+
"@jobber/formatters": "^0.4.1",
|
|
24
121
|
"@types/lodash": "4.14.136",
|
|
25
122
|
"@types/react": "^18.0.28",
|
|
26
123
|
"@types/react-dom": "^18.0.11",
|
|
@@ -40,5 +137,5 @@
|
|
|
40
137
|
"@apollo/client": "^3.0.0",
|
|
41
138
|
"react": "^18.2.0"
|
|
42
139
|
},
|
|
43
|
-
"gitHead": "
|
|
140
|
+
"gitHead": "14679bfc84922e1c758fbd6118ce3fd7b5142315"
|
|
44
141
|
}
|