@jobber/hooks 2.13.0 → 2.13.1-expose-ref-9ee8284.67

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
@@ -13,7 +13,6 @@ Shared hooks for components in Atlantis.
13
13
  - [useOnMount](../?path=/docs/hooks-useonmount--docs)
14
14
  - [useLiveAnnounce](../?path=/docs/hooks-useliveannounce--docs)
15
15
  - [useOnKeyDown](../?path=/docs/hooks-useonkeydown--docs)
16
- - [usePasswordStrength](../?path=/docs/hooks-usepasswordstrength--docs)
17
16
  - [useRefocusOnActivator](../?path=/docs/hooks-userefocusonactivator--docs)
18
17
  - [useResizeObserver](../?path=/docs/hooks-useresizeobserver--docs)
19
18
  - [useWindowDimensions](../?path=/docs/hooks-usewindowdimensions--docs)
package/dist/index.d.ts CHANGED
@@ -10,7 +10,6 @@ export * from "./useIsMounted";
10
10
  export * from "./useLiveAnnounce";
11
11
  export * from "./useOnKeyDown";
12
12
  export * from "./useOnMount";
13
- export * from "./usePasswordStrength";
14
13
  export * from "./useRefocusOnActivator";
15
14
  export * from "./useResizeObserver";
16
15
  export * from "./useSafeLayoutEffect";
package/dist/index.js CHANGED
@@ -26,7 +26,6 @@ __exportStar(require("./useIsMounted"), exports);
26
26
  __exportStar(require("./useLiveAnnounce"), exports);
27
27
  __exportStar(require("./useOnKeyDown"), exports);
28
28
  __exportStar(require("./useOnMount"), exports);
29
- __exportStar(require("./usePasswordStrength"), exports);
30
29
  __exportStar(require("./useRefocusOnActivator"), exports);
31
30
  __exportStar(require("./useResizeObserver"), exports);
32
31
  __exportStar(require("./useSafeLayoutEffect"), 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.0",
3
+ "version": "2.13.1-expose-ref-9ee8284.67+9ee82844",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -25,7 +25,6 @@
25
25
  "@types/react": "^18.0.28",
26
26
  "@types/react-dom": "^18.0.11",
27
27
  "@types/uuid": "^8.3.3",
28
- "@types/zxcvbn": "^4.4.1",
29
28
  "jsdom-testing-mocks": "^1.9.0",
30
29
  "uuid": "^8.3.2"
31
30
  },
@@ -33,12 +32,11 @@
33
32
  "lodash": "^4.17.20",
34
33
  "resize-observer-polyfill": "^1.5.1",
35
34
  "ts-xor": "^1.0.8",
36
- "use-resize-observer": "^6.1.0",
37
- "zxcvbn": "^4.4.2"
35
+ "use-resize-observer": "^6.1.0"
38
36
  },
39
37
  "peerDependencies": {
40
38
  "@apollo/client": "^3.0.0",
41
39
  "react": "^18.2.0"
42
40
  },
43
- "gitHead": "28e267f721a53c3aa458cdc30ea15b9aaf11c66e"
41
+ "gitHead": "9ee828441b72af014ffb3239bc61f0d35f1ca841"
44
42
  }
@@ -1 +0,0 @@
1
- export { usePasswordStrength } from "./usePasswordStrength";
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePasswordStrength = void 0;
4
- var usePasswordStrength_1 = require("./usePasswordStrength");
5
- Object.defineProperty(exports, "usePasswordStrength", { enumerable: true, get: function () { return usePasswordStrength_1.usePasswordStrength; } });
@@ -1,8 +0,0 @@
1
- import calculateStrength from "zxcvbn";
2
- export declare function usePasswordStrength(password: string, dictionary?: string[]): {
3
- guesses: number;
4
- score: calculateStrength.ZXCVBNScore;
5
- warning: calculateStrength.ZXCVBNFeedbackWarning;
6
- suggestions: string[];
7
- timeToCrack: string | number;
8
- };
@@ -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.usePasswordStrength = usePasswordStrength;
7
- const react_1 = require("react");
8
- const zxcvbn_1 = __importDefault(require("zxcvbn"));
9
- function usePasswordStrength(password, dictionary) {
10
- const { guesses, score, feedback: { warning, suggestions }, crack_times_display: { offline_fast_hashing_1e10_per_second: timeToCrack }, } = (0, react_1.useMemo)(() => (0, zxcvbn_1.default)(password, dictionary), [password, dictionary]);
11
- return {
12
- guesses,
13
- score,
14
- warning,
15
- suggestions,
16
- timeToCrack,
17
- };
18
- }
@@ -1 +0,0 @@
1
- export * from "./dist/usePasswordStrength";
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true,
5
- });
6
-
7
- var usePasswordStrength = require("./dist/usePasswordStrength");
8
-
9
- Object.keys(usePasswordStrength).forEach(function(key) {
10
- if (key === "default" || key === "__esModule") return;
11
- Object.defineProperty(exports, key, {
12
- enumerable: true,
13
- get: function get() {
14
- return usePasswordStrength[key];
15
- },
16
- });
17
- });