@jobber/hooks 2.13.1 → 2.15.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.md CHANGED
@@ -4,7 +4,6 @@ Shared hooks for components in Atlantis.
4
4
 
5
5
  ## Hooks
6
6
 
7
- - [useAssert](../?path=/docs/hooks-useassert--docs)
8
7
  - [useCallbackRef](../?path=/docs/hooks-usecallbackref--docs)
9
8
  - [useBool](../?path=/docs/hooks-usebool--docs)
10
9
  - [useCollectionQuery](../?path=/docs/hooks-usecollectionquery--docs)
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./useAssert";
2
1
  export * from "./useBool";
3
2
  export * from "./useBreakpoints";
4
3
  export * from "./useCallbackRef";
package/dist/index.js CHANGED
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./useAssert"), exports);
18
17
  __exportStar(require("./useBool"), exports);
19
18
  __exportStar(require("./useBreakpoints"), exports);
20
19
  __exportStar(require("./useCallbackRef"), exports);
@@ -5,6 +5,7 @@ interface UseShowClearParameters {
5
5
  focused: boolean;
6
6
  hasValue: boolean;
7
7
  disabled?: boolean;
8
+ readonly?: boolean;
8
9
  }
9
- export declare function useShowClear({ clearable, multiline, focused, hasValue, disabled, }: UseShowClearParameters): boolean | undefined;
10
+ export declare function useShowClear({ clearable, multiline, focused, hasValue, readonly, disabled, }: UseShowClearParameters): boolean | undefined;
10
11
  export {};
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useShowClear = useShowClear;
4
- function useShowClear({ clearable, multiline, focused, hasValue, disabled = false, }) {
4
+ function useShowClear({ clearable, multiline, focused, hasValue, readonly, disabled = false, }) {
5
5
  if (multiline && clearable !== "never") {
6
6
  throw new Error("Multiline inputs can not be clearable");
7
7
  }
8
8
  // Do not show if there is no value
9
- if (!hasValue || clearable === "never" || disabled) {
9
+ if (!hasValue || clearable === "never" || disabled || readonly) {
10
10
  return false;
11
11
  }
12
12
  switch (clearable) {
@@ -99,9 +99,71 @@ describe("useShowClear", () => {
99
99
  disabled: true,
100
100
  expected: false,
101
101
  },
102
- ])("%j", ({ clearable, hasValue, focused, multiline, disabled, expected, }) => {
102
+ // Readonly cases
103
+ {
104
+ clearable: "always",
105
+ hasValue: true,
106
+ focused: false,
107
+ multiline: false,
108
+ disabled: false,
109
+ readonly: true,
110
+ expected: false,
111
+ },
112
+ {
113
+ clearable: "always",
114
+ hasValue: true,
115
+ focused: true,
116
+ multiline: false,
117
+ disabled: false,
118
+ readonly: true,
119
+ expected: false,
120
+ },
121
+ {
122
+ clearable: "while-editing",
123
+ hasValue: true,
124
+ focused: false,
125
+ multiline: false,
126
+ disabled: false,
127
+ readonly: true,
128
+ expected: false,
129
+ },
130
+ {
131
+ clearable: "while-editing",
132
+ hasValue: true,
133
+ focused: true,
134
+ multiline: false,
135
+ disabled: false,
136
+ readonly: true,
137
+ expected: false,
138
+ },
139
+ {
140
+ clearable: "never",
141
+ hasValue: true,
142
+ focused: false,
143
+ multiline: false,
144
+ disabled: false,
145
+ readonly: true,
146
+ expected: false,
147
+ },
148
+ {
149
+ clearable: "never",
150
+ hasValue: true,
151
+ focused: true,
152
+ multiline: false,
153
+ disabled: false,
154
+ readonly: true,
155
+ expected: false,
156
+ },
157
+ ])("%j", ({ clearable, hasValue, focused, multiline, disabled, readonly, expected, }) => {
103
158
  it(`returns ${expected}`, () => {
104
- expect((0, useShowClear_1.useShowClear)({ clearable, multiline, focused, hasValue, disabled })).toEqual(expected);
159
+ expect((0, useShowClear_1.useShowClear)({
160
+ clearable,
161
+ multiline,
162
+ focused,
163
+ hasValue,
164
+ disabled,
165
+ readonly,
166
+ })).toEqual(expected);
105
167
  });
106
168
  });
107
169
  it("throws an error if multiline is true and clearable isn't never", () => {
@@ -133,4 +195,16 @@ describe("useShowClear", () => {
133
195
  });
134
196
  }).not.toThrow();
135
197
  });
198
+ it("respects readonly in multiline inputs", () => {
199
+ expect(() => {
200
+ (0, useShowClear_1.useShowClear)({
201
+ clearable: "never",
202
+ multiline: true,
203
+ focused: true,
204
+ hasValue: true,
205
+ disabled: false,
206
+ readonly: true,
207
+ });
208
+ }).not.toThrow();
209
+ });
136
210
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/hooks",
3
- "version": "2.13.1",
3
+ "version": "2.15.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -38,5 +38,5 @@
38
38
  "@apollo/client": "^3.0.0",
39
39
  "react": "^18.2.0"
40
40
  },
41
- "gitHead": "eeadd690623d3d194d257bd7e5833c83bb10f218"
41
+ "gitHead": "065748b88086d7e331a152db5e2db163c8f26f42"
42
42
  }
@@ -1 +0,0 @@
1
- export { useAssert } from "./useAssert";
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useAssert = void 0;
4
- var useAssert_1 = require("./useAssert");
5
- Object.defineProperty(exports, "useAssert", { enumerable: true, get: function () { return useAssert_1.useAssert; } });
@@ -1,5 +0,0 @@
1
- interface Options {
2
- readonly warn: boolean;
3
- }
4
- export declare function useAssert(shouldShow: boolean, message: string, options?: Options): void;
5
- export {};
@@ -1,18 +0,0 @@
1
- "use strict";
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.useAssert = useAssert;
7
- const process_1 = __importDefault(require("process"));
8
- function useAssert(shouldShow, message, options) {
9
- var _a;
10
- if (((_a = process_1.default === null || process_1.default === void 0 ? void 0 : process_1.default.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) !== "production" && shouldShow) {
11
- if (options === null || options === void 0 ? void 0 : options.warn) {
12
- console.warn(message);
13
- }
14
- else {
15
- throw new Error(message);
16
- }
17
- }
18
- }
package/useAssert.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/useAssert";
package/useAssert.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true,
5
- });
6
-
7
- var useAssert = require("./dist/useAssert");
8
-
9
- Object.keys(useAssert).forEach(function(key) {
10
- if (key === "default" || key === "__esModule") return;
11
- Object.defineProperty(exports, key, {
12
- enumerable: true,
13
- get: function get() {
14
- return useAssert[key];
15
- },
16
- });
17
- });