@jobber/components-native 0.49.2 → 0.50.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/package.json +3 -3
- package/dist/src/InputFieldWrapper/index.js +0 -1
- package/dist/src/InputPressable/InputPressable.js +2 -1
- package/dist/src/InputText/InputText.js +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/InputDate/InputDate.d.ts +2 -1
- package/dist/types/src/InputFieldWrapper/index.d.ts +1 -2
- package/dist/types/src/InputPressable/InputPressable.d.ts +1 -1
- package/dist/types/src/InputText/InputText.d.ts +1 -1
- package/dist/types/src/InputTime/InputTime.d.ts +2 -1
- package/package.json +3 -3
- package/src/InputDate/InputDate.tsx +3 -1
- package/src/InputFieldWrapper/InputFieldWrapper.tsx +5 -4
- package/src/InputFieldWrapper/index.ts +1 -2
- package/src/InputPressable/InputPressable.tsx +2 -6
- package/src/InputText/InputText.tsx +2 -5
- package/src/InputTime/InputTime.tsx +4 -1
- package/dist/src/InputFieldWrapper/hooks/useShowClear.js +0 -15
- package/dist/types/src/InputFieldWrapper/hooks/useShowClear.d.ts +0 -10
- package/src/InputFieldWrapper/hooks/useShowClear.test.ts +0 -158
- package/src/InputFieldWrapper/hooks/useShowClear.ts +0 -31
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { UseControllerProps } from "react-hook-form";
|
|
3
3
|
import { XOR } from "ts-xor";
|
|
4
|
-
import { Clearable
|
|
4
|
+
import { Clearable } from "@jobber/hooks";
|
|
5
|
+
import { InputFieldWrapperProps } from "../InputFieldWrapper";
|
|
5
6
|
interface BaseInputDateProps extends Pick<InputFieldWrapperProps, "invalid" | "disabled" | "placeholder"> {
|
|
6
7
|
/**
|
|
7
8
|
* Defaulted to "always" so user can clear the dates whenever there's a value.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { commonInputStyles } from "./CommonInputStyles.style";
|
|
2
2
|
export { InputFieldWrapper } from "./InputFieldWrapper";
|
|
3
|
-
export type { InputFieldWrapperProps
|
|
4
|
-
export { useShowClear } from "./hooks/useShowClear";
|
|
3
|
+
export type { InputFieldWrapperProps } from "./InputFieldWrapper";
|
|
@@ -2,7 +2,7 @@ import React, { Ref } from "react";
|
|
|
2
2
|
import { IconNames } from "@jobber/design";
|
|
3
3
|
import { FieldError } from "react-hook-form";
|
|
4
4
|
import { Text as NativeText } from "react-native";
|
|
5
|
-
import { Clearable } from "
|
|
5
|
+
import { Clearable } from "@jobber/hooks";
|
|
6
6
|
export interface InputPressableProps {
|
|
7
7
|
/**
|
|
8
8
|
* Current value of the component
|
|
@@ -2,8 +2,8 @@ import React, { SyntheticEvent } from "react";
|
|
|
2
2
|
import { NativeSyntheticEvent, StyleProp, TextInput, TextInputFocusEventData, TextInputProps, TextStyle } from "react-native";
|
|
3
3
|
import { RegisterOptions } from "react-hook-form";
|
|
4
4
|
import { IconNames } from "@jobber/design";
|
|
5
|
+
import { Clearable } from "@jobber/hooks";
|
|
5
6
|
import { InputFieldStyleOverride } from "../InputFieldWrapper/InputFieldWrapper";
|
|
6
|
-
import { Clearable } from "../InputFieldWrapper";
|
|
7
7
|
export interface InputTextProps {
|
|
8
8
|
/**
|
|
9
9
|
* Highlights the field red and shows message below (if string) to indicate an error
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { UseControllerProps } from "react-hook-form";
|
|
3
3
|
import { XOR } from "ts-xor";
|
|
4
|
-
import { Clearable
|
|
4
|
+
import { Clearable } from "@jobber/hooks";
|
|
5
|
+
import { InputFieldWrapperProps } from "../InputFieldWrapper";
|
|
5
6
|
interface InputTimeBaseProps extends Pick<InputFieldWrapperProps, "invalid" | "disabled" | "placeholder"> {
|
|
6
7
|
/**
|
|
7
8
|
* Defaulted to "always" so user can clear the time whenever there's a value.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@jobber/design": "^0.51.0",
|
|
40
|
-
"@jobber/hooks": "^2.
|
|
40
|
+
"@jobber/hooks": "^2.8.0",
|
|
41
41
|
"@react-native-clipboard/clipboard": "^1.11.2",
|
|
42
42
|
"@react-native-picker/picker": "^2.4.10",
|
|
43
43
|
"autolinker": "^4.0.0",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"react-native-reanimated": "^2.17.0",
|
|
85
85
|
"react-native-safe-area-context": "^4.5.2"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "300688dd8bf005f2d0f6fb06a0f913f0a208a937"
|
|
88
88
|
}
|
|
@@ -3,7 +3,8 @@ import DateTimePicker from "react-native-modal-datetime-picker";
|
|
|
3
3
|
import { Platform } from "react-native";
|
|
4
4
|
import { FieldError, UseControllerProps } from "react-hook-form";
|
|
5
5
|
import { XOR } from "ts-xor";
|
|
6
|
-
import { Clearable
|
|
6
|
+
import { Clearable } from "@jobber/hooks";
|
|
7
|
+
import { InputFieldWrapperProps } from "../InputFieldWrapper";
|
|
7
8
|
import { FormField } from "../FormField";
|
|
8
9
|
import { InputPressable } from "../InputPressable";
|
|
9
10
|
import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
|
|
@@ -154,6 +155,7 @@ function InternalInputDate({
|
|
|
154
155
|
|
|
155
156
|
const date = useMemo(() => {
|
|
156
157
|
if (typeof value === "string") return new Date(value);
|
|
158
|
+
|
|
157
159
|
return value;
|
|
158
160
|
}, [value]);
|
|
159
161
|
|
|
@@ -228,6 +228,7 @@ function getLabelVariation(
|
|
|
228
228
|
} else if (focused) {
|
|
229
229
|
return "interactive";
|
|
230
230
|
}
|
|
231
|
+
|
|
231
232
|
return "subdued";
|
|
232
233
|
}
|
|
233
234
|
|
|
@@ -278,10 +279,10 @@ function Placeholder({
|
|
|
278
279
|
labelVariation,
|
|
279
280
|
hasMiniLabel,
|
|
280
281
|
}: {
|
|
281
|
-
placeholder?: string;
|
|
282
|
-
styleOverride: StyleProp<TextStyle>;
|
|
283
|
-
labelVariation: TextVariation;
|
|
284
|
-
hasMiniLabel: boolean;
|
|
282
|
+
readonly placeholder?: string;
|
|
283
|
+
readonly styleOverride: StyleProp<TextStyle>;
|
|
284
|
+
readonly labelVariation: TextVariation;
|
|
285
|
+
readonly hasMiniLabel: boolean;
|
|
285
286
|
}) {
|
|
286
287
|
return (
|
|
287
288
|
<>
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { commonInputStyles } from "./CommonInputStyles.style";
|
|
2
2
|
export { InputFieldWrapper } from "./InputFieldWrapper";
|
|
3
|
-
export type { InputFieldWrapperProps
|
|
4
|
-
export { useShowClear } from "./hooks/useShowClear";
|
|
3
|
+
export type { InputFieldWrapperProps } from "./InputFieldWrapper";
|
|
@@ -2,13 +2,9 @@ import React, { Ref, forwardRef, useEffect, useState } from "react";
|
|
|
2
2
|
import { IconNames } from "@jobber/design";
|
|
3
3
|
import { FieldError } from "react-hook-form";
|
|
4
4
|
import { Text as NativeText, Pressable } from "react-native";
|
|
5
|
+
import { Clearable, useShowClear } from "@jobber/hooks";
|
|
5
6
|
import { styles } from "./InputPressable.style";
|
|
6
|
-
import {
|
|
7
|
-
Clearable,
|
|
8
|
-
InputFieldWrapper,
|
|
9
|
-
commonInputStyles,
|
|
10
|
-
useShowClear,
|
|
11
|
-
} from "../InputFieldWrapper";
|
|
7
|
+
import { InputFieldWrapper, commonInputStyles } from "../InputFieldWrapper";
|
|
12
8
|
|
|
13
9
|
export interface InputPressableProps {
|
|
14
10
|
/**
|
|
@@ -25,15 +25,12 @@ import {
|
|
|
25
25
|
} from "react-hook-form";
|
|
26
26
|
import { IconNames } from "@jobber/design";
|
|
27
27
|
import identity from "lodash/identity";
|
|
28
|
+
import { Clearable, useShowClear } from "@jobber/hooks";
|
|
28
29
|
import { styles } from "./InputText.style";
|
|
29
30
|
import { useInputAccessoriesContext } from "./context";
|
|
30
31
|
import { useFormController } from "../hooks";
|
|
31
32
|
import { InputFieldStyleOverride } from "../InputFieldWrapper/InputFieldWrapper";
|
|
32
|
-
import {
|
|
33
|
-
Clearable,
|
|
34
|
-
InputFieldWrapper,
|
|
35
|
-
useShowClear,
|
|
36
|
-
} from "../InputFieldWrapper";
|
|
33
|
+
import { InputFieldWrapper } from "../InputFieldWrapper";
|
|
37
34
|
import { commonInputStyles } from "../InputFieldWrapper/CommonInputStyles.style";
|
|
38
35
|
|
|
39
36
|
export interface InputTextProps {
|
|
@@ -3,12 +3,13 @@ import { FieldError, UseControllerProps } from "react-hook-form";
|
|
|
3
3
|
import { XOR } from "ts-xor";
|
|
4
4
|
import DateTimePicker from "react-native-modal-datetime-picker";
|
|
5
5
|
import { View } from "react-native";
|
|
6
|
+
import { Clearable } from "@jobber/hooks";
|
|
6
7
|
import { styles } from "./InputTime.style";
|
|
7
8
|
import { getTimeZoneOffsetInMinutes, roundUpToNearestMinutes } from "./utils";
|
|
8
9
|
import { useAtlantisContext } from "../AtlantisContext";
|
|
9
10
|
import { InputPressable } from "../InputPressable";
|
|
10
11
|
import { FormField } from "../FormField";
|
|
11
|
-
import {
|
|
12
|
+
import { InputFieldWrapperProps } from "../InputFieldWrapper";
|
|
12
13
|
import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
|
|
13
14
|
|
|
14
15
|
interface InputTimeBaseProps
|
|
@@ -208,10 +209,12 @@ function InternalInputTime({
|
|
|
208
209
|
|
|
209
210
|
function getInitialPickerDate(date?: Date | null): Date {
|
|
210
211
|
if (date) return date;
|
|
212
|
+
|
|
211
213
|
return roundUpToNearestMinutes(new Date(), 30);
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
function getMinuteInterval(type: InputTimeBaseProps["type"]) {
|
|
215
217
|
if (type === "granular") return 1;
|
|
218
|
+
|
|
216
219
|
return 5;
|
|
217
220
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function useShowClear({ clearable, multiline, focused, hasValue, disabled = false, }) {
|
|
2
|
-
if (multiline && clearable !== "never") {
|
|
3
|
-
throw new Error("Multiline inputs can not be clearable");
|
|
4
|
-
}
|
|
5
|
-
// Do not show if there is no value
|
|
6
|
-
if (!hasValue || clearable === "never" || disabled) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
switch (clearable) {
|
|
10
|
-
case "while-editing":
|
|
11
|
-
return focused;
|
|
12
|
-
case "always":
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Clearable } from "../InputFieldWrapper";
|
|
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 {};
|
|
@@ -1,158 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|