@jobber/components-native 0.9.0 → 0.11.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/src/Button/Button.js +78 -0
- package/dist/src/Button/Button.style.js +92 -0
- package/dist/src/Button/components/InternalButtonLoading/InternalButtonLoading.js +36 -0
- package/dist/src/Button/components/InternalButtonLoading/InternalButtonLoading.style.js +4 -0
- package/dist/src/Button/components/InternalButtonLoading/index.js +1 -0
- package/dist/src/Button/index.js +1 -0
- package/dist/src/Button/types.js +1 -0
- package/dist/src/InputFieldWrapper/CommonInputStyles.style.js +33 -0
- package/dist/src/InputFieldWrapper/InputFieldWrapper.js +88 -0
- package/dist/src/InputFieldWrapper/InputFieldWrapper.style.js +79 -0
- package/dist/src/InputFieldWrapper/components/ClearAction/ClearAction.js +12 -0
- package/dist/src/InputFieldWrapper/components/ClearAction/ClearAction.style.js +25 -0
- package/dist/src/InputFieldWrapper/components/ClearAction/index.js +2 -0
- package/dist/src/InputFieldWrapper/components/ClearAction/messages.js +8 -0
- package/dist/src/InputFieldWrapper/components/Prefix/Prefix.js +34 -0
- package/dist/src/InputFieldWrapper/components/Suffix/Suffix.js +35 -0
- package/dist/src/InputFieldWrapper/hooks/useShowClear.js +15 -0
- package/dist/src/InputFieldWrapper/index.js +3 -0
- package/dist/src/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/Button/Button.d.ts +71 -0
- package/dist/types/src/Button/Button.style.d.ts +86 -0
- package/dist/types/src/Button/components/InternalButtonLoading/InternalButtonLoading.d.ts +11 -0
- package/dist/types/src/Button/components/InternalButtonLoading/InternalButtonLoading.style.d.ts +4 -0
- package/dist/types/src/Button/components/InternalButtonLoading/index.d.ts +1 -0
- package/dist/types/src/Button/index.d.ts +2 -0
- package/dist/types/src/Button/types.d.ts +3 -0
- package/dist/types/src/InputFieldWrapper/CommonInputStyles.style.d.ts +30 -0
- package/dist/types/src/InputFieldWrapper/InputFieldWrapper.d.ts +63 -0
- package/dist/types/src/InputFieldWrapper/InputFieldWrapper.style.d.ts +82 -0
- package/dist/types/src/InputFieldWrapper/components/ClearAction/ClearAction.d.ts +10 -0
- package/dist/types/src/InputFieldWrapper/components/ClearAction/ClearAction.style.d.ts +22 -0
- package/dist/types/src/InputFieldWrapper/components/ClearAction/index.d.ts +2 -0
- package/dist/types/src/InputFieldWrapper/components/ClearAction/messages.d.ts +7 -0
- package/dist/types/src/InputFieldWrapper/components/Prefix/Prefix.d.ts +23 -0
- package/dist/types/src/InputFieldWrapper/components/Suffix/Suffix.d.ts +25 -0
- package/dist/types/src/InputFieldWrapper/hooks/useShowClear.d.ts +10 -0
- package/dist/types/src/InputFieldWrapper/index.d.ts +4 -0
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +5 -2
- package/src/Button/Button.style.ts +116 -0
- package/src/Button/Button.test.tsx +298 -0
- package/src/Button/Button.tsx +223 -0
- package/src/Button/components/InternalButtonLoading/InternalButtonLoading.style.ts +5 -0
- package/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.tsx +39 -0
- package/src/Button/components/InternalButtonLoading/InternalButtonLoading.tsx +77 -0
- package/src/Button/components/InternalButtonLoading/index.ts +1 -0
- package/src/Button/index.ts +2 -0
- package/src/Button/types.ts +3 -0
- package/src/InputFieldWrapper/CommonInputStyles.style.ts +37 -0
- package/src/InputFieldWrapper/InputFieldWrapper.style.ts +93 -0
- package/src/InputFieldWrapper/InputFieldWrapper.test.tsx +243 -0
- package/src/InputFieldWrapper/InputFieldWrapper.tsx +317 -0
- package/src/InputFieldWrapper/components/ClearAction/ClearAction.style.ts +27 -0
- package/src/InputFieldWrapper/components/ClearAction/ClearAction.test.tsx +15 -0
- package/src/InputFieldWrapper/components/ClearAction/ClearAction.tsx +32 -0
- package/src/InputFieldWrapper/components/ClearAction/index.ts +2 -0
- package/src/InputFieldWrapper/components/ClearAction/messages.ts +9 -0
- package/src/InputFieldWrapper/components/Prefix/Prefix.test.tsx +221 -0
- package/src/InputFieldWrapper/components/Prefix/Prefix.tsx +104 -0
- package/src/InputFieldWrapper/components/Suffix/Suffix.test.tsx +101 -0
- package/src/InputFieldWrapper/components/Suffix/Suffix.tsx +113 -0
- package/src/InputFieldWrapper/hooks/useShowClear.test.ts +158 -0
- package/src/InputFieldWrapper/hooks/useShowClear.ts +31 -0
- package/src/InputFieldWrapper/index.ts +4 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { useShowClear } from "./useShowClear";
|
|
2
|
+
import { Clearable } from "..";
|
|
3
|
+
|
|
4
|
+
interface UseShowClearParameters {
|
|
5
|
+
clearable: Clearable;
|
|
6
|
+
hasValue: boolean;
|
|
7
|
+
focused: boolean;
|
|
8
|
+
multiline: boolean;
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
expected: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("useShowClear", () => {
|
|
14
|
+
describe.each<UseShowClearParameters>([
|
|
15
|
+
{
|
|
16
|
+
clearable: "always",
|
|
17
|
+
hasValue: true,
|
|
18
|
+
focused: false,
|
|
19
|
+
multiline: false,
|
|
20
|
+
disabled: false,
|
|
21
|
+
expected: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
clearable: "always",
|
|
25
|
+
hasValue: true,
|
|
26
|
+
focused: true,
|
|
27
|
+
multiline: false,
|
|
28
|
+
disabled: false,
|
|
29
|
+
expected: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
clearable: "always",
|
|
33
|
+
hasValue: true,
|
|
34
|
+
focused: false,
|
|
35
|
+
multiline: false,
|
|
36
|
+
disabled: true,
|
|
37
|
+
expected: false,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
clearable: "always",
|
|
41
|
+
hasValue: false,
|
|
42
|
+
focused: false,
|
|
43
|
+
multiline: false,
|
|
44
|
+
disabled: true,
|
|
45
|
+
expected: false,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
clearable: "while-editing",
|
|
49
|
+
hasValue: true,
|
|
50
|
+
focused: false,
|
|
51
|
+
multiline: false,
|
|
52
|
+
disabled: false,
|
|
53
|
+
expected: false,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
clearable: "while-editing",
|
|
57
|
+
hasValue: true,
|
|
58
|
+
focused: true,
|
|
59
|
+
multiline: false,
|
|
60
|
+
disabled: false,
|
|
61
|
+
expected: true,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
clearable: "while-editing",
|
|
65
|
+
hasValue: false,
|
|
66
|
+
focused: false,
|
|
67
|
+
multiline: false,
|
|
68
|
+
disabled: true,
|
|
69
|
+
expected: false,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
clearable: "while-editing",
|
|
73
|
+
hasValue: true,
|
|
74
|
+
focused: false,
|
|
75
|
+
multiline: false,
|
|
76
|
+
disabled: true,
|
|
77
|
+
expected: false,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
clearable: "never",
|
|
81
|
+
hasValue: true,
|
|
82
|
+
focused: false,
|
|
83
|
+
multiline: false,
|
|
84
|
+
disabled: false,
|
|
85
|
+
expected: false,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
clearable: "never",
|
|
89
|
+
hasValue: true,
|
|
90
|
+
focused: true,
|
|
91
|
+
multiline: false,
|
|
92
|
+
disabled: false,
|
|
93
|
+
expected: false,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
clearable: "never",
|
|
97
|
+
hasValue: false,
|
|
98
|
+
focused: false,
|
|
99
|
+
multiline: false,
|
|
100
|
+
disabled: true,
|
|
101
|
+
expected: false,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
clearable: "never",
|
|
105
|
+
hasValue: true,
|
|
106
|
+
focused: false,
|
|
107
|
+
multiline: false,
|
|
108
|
+
disabled: true,
|
|
109
|
+
expected: false,
|
|
110
|
+
},
|
|
111
|
+
])(
|
|
112
|
+
"%j",
|
|
113
|
+
({
|
|
114
|
+
clearable,
|
|
115
|
+
hasValue,
|
|
116
|
+
focused,
|
|
117
|
+
multiline,
|
|
118
|
+
disabled,
|
|
119
|
+
expected,
|
|
120
|
+
}: UseShowClearParameters) => {
|
|
121
|
+
it(`returns ${expected}`, () => {
|
|
122
|
+
expect(
|
|
123
|
+
useShowClear({ clearable, multiline, focused, hasValue, disabled }),
|
|
124
|
+
).toEqual(expected);
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
it("throws an error if multiline is true and clearable isn't never", () => {
|
|
130
|
+
expect(() => {
|
|
131
|
+
useShowClear({
|
|
132
|
+
clearable: "always",
|
|
133
|
+
multiline: true,
|
|
134
|
+
focused: true,
|
|
135
|
+
hasValue: true,
|
|
136
|
+
disabled: false,
|
|
137
|
+
});
|
|
138
|
+
}).toThrow();
|
|
139
|
+
expect(() => {
|
|
140
|
+
useShowClear({
|
|
141
|
+
clearable: "while-editing",
|
|
142
|
+
multiline: true,
|
|
143
|
+
focused: true,
|
|
144
|
+
hasValue: true,
|
|
145
|
+
disabled: false,
|
|
146
|
+
});
|
|
147
|
+
}).toThrow();
|
|
148
|
+
expect(() => {
|
|
149
|
+
useShowClear({
|
|
150
|
+
clearable: "never",
|
|
151
|
+
multiline: true,
|
|
152
|
+
focused: true,
|
|
153
|
+
hasValue: true,
|
|
154
|
+
disabled: false,
|
|
155
|
+
});
|
|
156
|
+
}).not.toThrow();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Clearable } from "../InputFieldWrapper";
|
|
2
|
+
|
|
3
|
+
interface UseShowClearParameters {
|
|
4
|
+
clearable: Clearable;
|
|
5
|
+
multiline: boolean;
|
|
6
|
+
focused: boolean;
|
|
7
|
+
hasValue: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useShowClear({
|
|
12
|
+
clearable,
|
|
13
|
+
multiline,
|
|
14
|
+
focused,
|
|
15
|
+
hasValue,
|
|
16
|
+
disabled = false,
|
|
17
|
+
}: UseShowClearParameters): boolean | undefined {
|
|
18
|
+
if (multiline && clearable !== "never") {
|
|
19
|
+
throw new Error("Multiline inputs can not be clearable");
|
|
20
|
+
}
|
|
21
|
+
// Do not show if there is no value
|
|
22
|
+
if (!hasValue || clearable === "never" || disabled) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
switch (clearable) {
|
|
26
|
+
case "while-editing":
|
|
27
|
+
return focused;
|
|
28
|
+
case "always":
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|