@jobber/hooks 2.7.2 → 2.8.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/useShowClear/index.d.ts +1 -0
- package/dist/useShowClear/index.js +5 -0
- package/dist/useShowClear/useShowClear.d.ts +10 -0
- package/dist/useShowClear/useShowClear.js +19 -0
- package/dist/useShowClear/useShowClear.test.d.ts +1 -0
- package/dist/useShowClear/useShowClear.test.js +136 -0
- package/package.json +2 -2
- package/useShowClear.d.ts +1 -0
- package/useShowClear.js +17 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -27,3 +27,4 @@ __exportStar(require("./useOnKeyDown"), exports);
|
|
|
27
27
|
__exportStar(require("./usePasswordStrength"), exports);
|
|
28
28
|
__exportStar(require("./useRefocusOnActivator"), exports);
|
|
29
29
|
__exportStar(require("./useResizeObserver"), exports);
|
|
30
|
+
__exportStar(require("./useShowClear"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useShowClear, Clearable } from "./useShowClear";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
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; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type Clearable = "never" | "while-editing" | "always";
|
|
2
|
+
interface UseShowClearParameters {
|
|
3
|
+
clearable: Clearable;
|
|
4
|
+
multiline: boolean;
|
|
5
|
+
focused: boolean;
|
|
6
|
+
hasValue: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function useShowClear({ clearable, multiline, focused, hasValue, disabled, }: UseShowClearParameters): boolean | undefined;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useShowClear = void 0;
|
|
4
|
+
function useShowClear({ clearable, multiline, focused, hasValue, disabled = false, }) {
|
|
5
|
+
if (multiline && clearable !== "never") {
|
|
6
|
+
throw new Error("Multiline inputs can not be clearable");
|
|
7
|
+
}
|
|
8
|
+
// Do not show if there is no value
|
|
9
|
+
if (!hasValue || clearable === "never" || disabled) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
switch (clearable) {
|
|
13
|
+
case "while-editing":
|
|
14
|
+
return focused;
|
|
15
|
+
case "always":
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.useShowClear = useShowClear;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const useShowClear_1 = require("./useShowClear");
|
|
4
|
+
describe("useShowClear", () => {
|
|
5
|
+
describe.each([
|
|
6
|
+
{
|
|
7
|
+
clearable: "always",
|
|
8
|
+
hasValue: true,
|
|
9
|
+
focused: false,
|
|
10
|
+
multiline: false,
|
|
11
|
+
disabled: false,
|
|
12
|
+
expected: true,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
clearable: "always",
|
|
16
|
+
hasValue: true,
|
|
17
|
+
focused: true,
|
|
18
|
+
multiline: false,
|
|
19
|
+
disabled: false,
|
|
20
|
+
expected: true,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
clearable: "always",
|
|
24
|
+
hasValue: true,
|
|
25
|
+
focused: false,
|
|
26
|
+
multiline: false,
|
|
27
|
+
disabled: true,
|
|
28
|
+
expected: false,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
clearable: "always",
|
|
32
|
+
hasValue: false,
|
|
33
|
+
focused: false,
|
|
34
|
+
multiline: false,
|
|
35
|
+
disabled: true,
|
|
36
|
+
expected: false,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
clearable: "while-editing",
|
|
40
|
+
hasValue: true,
|
|
41
|
+
focused: false,
|
|
42
|
+
multiline: false,
|
|
43
|
+
disabled: false,
|
|
44
|
+
expected: false,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
clearable: "while-editing",
|
|
48
|
+
hasValue: true,
|
|
49
|
+
focused: true,
|
|
50
|
+
multiline: false,
|
|
51
|
+
disabled: false,
|
|
52
|
+
expected: true,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
clearable: "while-editing",
|
|
56
|
+
hasValue: false,
|
|
57
|
+
focused: false,
|
|
58
|
+
multiline: false,
|
|
59
|
+
disabled: true,
|
|
60
|
+
expected: false,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
clearable: "while-editing",
|
|
64
|
+
hasValue: true,
|
|
65
|
+
focused: false,
|
|
66
|
+
multiline: false,
|
|
67
|
+
disabled: true,
|
|
68
|
+
expected: false,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
clearable: "never",
|
|
72
|
+
hasValue: true,
|
|
73
|
+
focused: false,
|
|
74
|
+
multiline: false,
|
|
75
|
+
disabled: false,
|
|
76
|
+
expected: false,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
clearable: "never",
|
|
80
|
+
hasValue: true,
|
|
81
|
+
focused: true,
|
|
82
|
+
multiline: false,
|
|
83
|
+
disabled: false,
|
|
84
|
+
expected: false,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
clearable: "never",
|
|
88
|
+
hasValue: false,
|
|
89
|
+
focused: false,
|
|
90
|
+
multiline: false,
|
|
91
|
+
disabled: true,
|
|
92
|
+
expected: false,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
clearable: "never",
|
|
96
|
+
hasValue: true,
|
|
97
|
+
focused: false,
|
|
98
|
+
multiline: false,
|
|
99
|
+
disabled: true,
|
|
100
|
+
expected: false,
|
|
101
|
+
},
|
|
102
|
+
])("%j", ({ clearable, hasValue, focused, multiline, disabled, expected, }) => {
|
|
103
|
+
it(`returns ${expected}`, () => {
|
|
104
|
+
expect((0, useShowClear_1.useShowClear)({ clearable, multiline, focused, hasValue, disabled })).toEqual(expected);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
it("throws an error if multiline is true and clearable isn't never", () => {
|
|
108
|
+
expect(() => {
|
|
109
|
+
(0, useShowClear_1.useShowClear)({
|
|
110
|
+
clearable: "always",
|
|
111
|
+
multiline: true,
|
|
112
|
+
focused: true,
|
|
113
|
+
hasValue: true,
|
|
114
|
+
disabled: false,
|
|
115
|
+
});
|
|
116
|
+
}).toThrow();
|
|
117
|
+
expect(() => {
|
|
118
|
+
(0, useShowClear_1.useShowClear)({
|
|
119
|
+
clearable: "while-editing",
|
|
120
|
+
multiline: true,
|
|
121
|
+
focused: true,
|
|
122
|
+
hasValue: true,
|
|
123
|
+
disabled: false,
|
|
124
|
+
});
|
|
125
|
+
}).toThrow();
|
|
126
|
+
expect(() => {
|
|
127
|
+
(0, useShowClear_1.useShowClear)({
|
|
128
|
+
clearable: "never",
|
|
129
|
+
multiline: true,
|
|
130
|
+
focused: true,
|
|
131
|
+
hasValue: true,
|
|
132
|
+
disabled: false,
|
|
133
|
+
});
|
|
134
|
+
}).not.toThrow();
|
|
135
|
+
});
|
|
136
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/hooks",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.js",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"@apollo/client": "^3.0.0",
|
|
45
45
|
"react": "^18"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "300688dd8bf005f2d0f6fb06a0f913f0a208a937"
|
|
48
48
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dist/useShowClear";
|
package/useShowClear.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var useShowClear = require("./dist/useShowClear");
|
|
8
|
+
|
|
9
|
+
Object.keys(useShowClear).forEach(function(key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
Object.defineProperty(exports, key, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function get() {
|
|
14
|
+
return useShowClear[key];
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
});
|