@jobber/hooks 2.13.1 → 2.14.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.
|
@@ -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
|
-
|
|
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)({
|
|
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.
|
|
3
|
+
"version": "2.14.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": "
|
|
41
|
+
"gitHead": "05abc863b320dcb1f5f8e3fc9e950fb17a5d2ae3"
|
|
42
42
|
}
|