@jobber/hooks 2.6.3 → 2.7.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.
package/README.mdx CHANGED
@@ -5,6 +5,7 @@ Shared hooks for components in Atlantis.
5
5
  ## Hooks
6
6
 
7
7
  - [useAssert](../?path=/docs/hooks-useassert--page)
8
+ - [useBool](../?path=/docs/hooks-usebool--page)
8
9
  - [useCollectionQuery](../?path=/docs/hooks-usecollectionquery--use-collection-query)
9
10
  - [useFormState](../?path=/docs/hooks-useformstate--use-form-state)
10
11
  - [useIsMounted](../?path=/docs/hooks-useismounted--use-is-mounted)
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./useAssert";
2
+ export * from "./useBool";
2
3
  export * from "./useBreakpoints";
3
4
  export * from "./useCollectionQuery";
4
5
  export * from "./useFocusTrap";
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./useAssert"), exports);
18
+ __exportStar(require("./useBool"), exports);
18
19
  __exportStar(require("./useBreakpoints"), exports);
19
20
  __exportStar(require("./useCollectionQuery"), exports);
20
21
  __exportStar(require("./useFocusTrap"), exports);
@@ -0,0 +1 @@
1
+ export { useBool } from "./useBool";
@@ -0,0 +1,5 @@
1
+ "use strict";
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; } });
@@ -0,0 +1,13 @@
1
+ declare const brand: unique symbol;
2
+ type Callback = () => void;
3
+ export type SetTrue = Callback & {
4
+ [brand]: "SetTrue";
5
+ };
6
+ export type SetFalse = Callback & {
7
+ [brand]: "SetFalse";
8
+ };
9
+ export type Toggle = Callback & {
10
+ [brand]: "Toggle";
11
+ };
12
+ export declare function useBool(initialState?: boolean): [boolean, SetTrue, SetFalse, Toggle];
13
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useBool = void 0;
4
+ const react_1 = require("react");
5
+ function useBool(initialState = false) {
6
+ const [state, setState] = (0, react_1.useState)(initialState);
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), []);
10
+ return [state, setTrue, setFalse, toggle];
11
+ }
12
+ exports.useBool = useBool;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("@testing-library/react");
4
+ const useBool_1 = require("./useBool");
5
+ describe("useBool, a hook for managing boolean state", () => {
6
+ it("by default has an initial state that is `false`", () => {
7
+ const [value] = (0, react_1.renderHook)(() => (0, useBool_1.useBool)()).result.current;
8
+ expect(value).toBe(false);
9
+ });
10
+ it("can be provided an initial state", () => {
11
+ const [value] = (0, react_1.renderHook)(() => (0, useBool_1.useBool)(true)).result.current;
12
+ expect(value).toBe(true);
13
+ });
14
+ it("provides helpful setters and a toggle method", () => {
15
+ const { result } = (0, react_1.renderHook)(() => (0, useBool_1.useBool)());
16
+ const value = () => result.current[0];
17
+ const [, setTrue, setFalse, toggle] = result.current;
18
+ expect(value()).toBe(false);
19
+ (0, react_1.act)(setTrue);
20
+ expect(value()).toBe(true);
21
+ (0, react_1.act)(setFalse);
22
+ expect(value()).toBe(false);
23
+ (0, react_1.act)(toggle);
24
+ expect(value()).toBe(true);
25
+ (0, react_1.act)(toggle);
26
+ expect(value()).toBe(false);
27
+ });
28
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/hooks",
3
- "version": "2.6.3",
3
+ "version": "2.7.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -45,5 +45,5 @@
45
45
  "@apollo/client": "^3.0.0",
46
46
  "react": "^18"
47
47
  },
48
- "gitHead": "6e42ff7d712d09ecd2214b0fccae8c39bc51afec"
48
+ "gitHead": "7d69952a16458e6fcafd0a5e4215bab444d074dc"
49
49
  }
package/useBool.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./dist/useBool";
package/useBool.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+
7
+ var useBool = require("./dist/useBool");
8
+
9
+ Object.keys(useBool).forEach(function(key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ Object.defineProperty(exports, key, {
12
+ enumerable: true,
13
+ get: function get() {
14
+ return useBool[key];
15
+ },
16
+ });
17
+ });