@jobber/components-native 0.21.1 → 0.22.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/InputText/InputText.js +138 -0
- package/dist/src/InputText/InputText.style.js +20 -0
- package/dist/src/InputText/context/InputAccessoriesContext.js +17 -0
- package/dist/src/InputText/context/InputAccessoriesProvider.js +73 -0
- package/dist/src/InputText/context/InputAccessoriesProvider.style.js +21 -0
- package/dist/src/InputText/context/InputAccessory.style.js +16 -0
- package/dist/src/InputText/context/index.js +2 -0
- package/dist/src/InputText/context/types.js +1 -0
- package/dist/src/InputText/index.js +2 -0
- package/dist/src/hooks/index.js +1 -0
- package/dist/src/hooks/useFormController.js +38 -0
- package/dist/src/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/InputText/InputText.d.ts +165 -0
- package/dist/types/src/InputText/InputText.style.d.ts +16 -0
- package/dist/types/src/InputText/context/InputAccessoriesContext.d.ts +4 -0
- package/dist/types/src/InputText/context/InputAccessoriesProvider.d.ts +4 -0
- package/dist/types/src/InputText/context/InputAccessoriesProvider.style.d.ts +17 -0
- package/dist/types/src/InputText/context/InputAccessory.style.d.ts +14 -0
- package/dist/types/src/InputText/context/index.d.ts +2 -0
- package/dist/types/src/InputText/context/types.d.ts +23 -0
- package/dist/types/src/InputText/index.d.ts +3 -0
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/useFormController.d.ts +12 -0
- package/dist/types/src/index.d.ts +1 -0
- package/package.json +4 -2
- package/src/InputText/InputText.style.ts +25 -0
- package/src/InputText/InputText.test.tsx +534 -0
- package/src/InputText/InputText.tsx +483 -0
- package/src/InputText/context/InputAccessoriesContext.ts +21 -0
- package/src/InputText/context/InputAccessoriesProvider.style.tsx +23 -0
- package/src/InputText/context/InputAccessoriesProvider.test.tsx +84 -0
- package/src/InputText/context/InputAccessoriesProvider.tsx +121 -0
- package/src/InputText/context/InputAccessory.style.ts +17 -0
- package/src/InputText/context/index.ts +2 -0
- package/src/InputText/context/types.ts +28 -0
- package/src/InputText/index.ts +3 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useFormController.ts +68 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import React, { SyntheticEvent } from "react";
|
|
2
|
+
import { NativeSyntheticEvent, StyleProp, TextInput, TextInputFocusEventData, TextInputProps, TextStyle } from "react-native";
|
|
3
|
+
import { RegisterOptions } from "react-hook-form";
|
|
4
|
+
import { IconNames } from "@jobber/design";
|
|
5
|
+
import { InputFieldStyleOverride } from "../InputFieldWrapper/InputFieldWrapper";
|
|
6
|
+
import { Clearable } from "../InputFieldWrapper";
|
|
7
|
+
export interface InputTextProps {
|
|
8
|
+
/**
|
|
9
|
+
* Highlights the field red and shows message below (if string) to indicate an error
|
|
10
|
+
*/
|
|
11
|
+
readonly invalid?: boolean | string;
|
|
12
|
+
/**
|
|
13
|
+
* Disable the input
|
|
14
|
+
*/
|
|
15
|
+
readonly disabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Name of the input.
|
|
18
|
+
*/
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Hint text that goes above the value once the field is filled out
|
|
22
|
+
*/
|
|
23
|
+
readonly placeholder?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Text that helps the user understand the input
|
|
26
|
+
*/
|
|
27
|
+
readonly assistiveText?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Determines what keyboard is shown
|
|
30
|
+
*/
|
|
31
|
+
keyboard?: "default" | "numeric" | "phone-pad" | "email-address" | "numbers-and-punctuation" | "decimal-pad";
|
|
32
|
+
/**
|
|
33
|
+
* Set the component to a given value
|
|
34
|
+
*/
|
|
35
|
+
readonly value?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Default value for when component is uncontrolled
|
|
38
|
+
*/
|
|
39
|
+
readonly defaultValue?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Automatically focus the input after it is rendered
|
|
42
|
+
*/
|
|
43
|
+
readonly autoFocus?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Shows an error message below the field and highlight the field red when value is invalid
|
|
46
|
+
*/
|
|
47
|
+
readonly validations?: RegisterOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Simplified callback that only provides the new value
|
|
50
|
+
* @param newValue
|
|
51
|
+
*/
|
|
52
|
+
onChangeText?: (newValue: string) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Callback that is called when the text input's submit button is pressed
|
|
55
|
+
* @param event
|
|
56
|
+
*/
|
|
57
|
+
onSubmitEditing?: (event?: SyntheticEvent) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Callback that is called when the text input is focused
|
|
60
|
+
* @param event
|
|
61
|
+
*/
|
|
62
|
+
onFocus?: (event?: NativeSyntheticEvent<TextInputFocusEventData>) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Callback that is called when the text input is blurred
|
|
65
|
+
*/
|
|
66
|
+
onBlur?: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* VoiceOver will read this string when a user selects the associated element
|
|
69
|
+
*/
|
|
70
|
+
readonly accessibilityLabel?: string;
|
|
71
|
+
/**
|
|
72
|
+
* An accessibility hint helps users understand what will happen when they perform an action on the
|
|
73
|
+
* accessibility element when that result is not clear from the accessibility label
|
|
74
|
+
*/
|
|
75
|
+
readonly accessibilityHint?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Turn off autocorrect
|
|
78
|
+
*/
|
|
79
|
+
readonly autoCorrect?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Determines where to autocapitalize
|
|
82
|
+
*/
|
|
83
|
+
readonly autoCapitalize?: "characters" | "words" | "sentences" | "none";
|
|
84
|
+
/**
|
|
85
|
+
* Determines which content to suggest on auto complete, e.g.`username`.
|
|
86
|
+
* Default is `off` which disables auto complete
|
|
87
|
+
*
|
|
88
|
+
* *Android Only*
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
readonly autoComplete?: TextInputProps["autoComplete"];
|
|
92
|
+
/**
|
|
93
|
+
* Determines which content to suggest on auto complete, e.g.`username`.
|
|
94
|
+
* Default is `none` which disables auto complete
|
|
95
|
+
*
|
|
96
|
+
* *iOS Only*
|
|
97
|
+
*/
|
|
98
|
+
readonly textContentType?: TextInputProps["textContentType"];
|
|
99
|
+
/**
|
|
100
|
+
* Determines if inputText will span multiple lines.
|
|
101
|
+
* Default is `false`
|
|
102
|
+
*
|
|
103
|
+
* https://reactnative.dev/docs/textinput#multiline
|
|
104
|
+
*/
|
|
105
|
+
readonly multiline?: TextInputProps["multiline"];
|
|
106
|
+
/**
|
|
107
|
+
* Symbol to display before the text input
|
|
108
|
+
*/
|
|
109
|
+
readonly prefix?: {
|
|
110
|
+
icon?: IconNames;
|
|
111
|
+
label?: string;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Symbol to display after the text input
|
|
115
|
+
*/
|
|
116
|
+
readonly suffix?: {
|
|
117
|
+
icon?: IconNames;
|
|
118
|
+
label?: string;
|
|
119
|
+
onPress?: () => void;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* transform object is used to transform the internal TextInput value
|
|
123
|
+
* It's useful for components like InputNumber where we want to transform
|
|
124
|
+
* the internal value to a number.
|
|
125
|
+
* "input" is a function that transform the value to the string format that should be shown to the user
|
|
126
|
+
* "output" is a function that transform the string representation of the value to the value that is sent to onChange and the form
|
|
127
|
+
*/
|
|
128
|
+
transform?: {
|
|
129
|
+
input?: (v: any) => string | undefined;
|
|
130
|
+
output?: (v: string | undefined) => any;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Add a clear action on the input that clears the value.
|
|
134
|
+
*
|
|
135
|
+
* You should always use `while-editing` if you want the input to be
|
|
136
|
+
* clearable. if the input value isn't editable (i.e. `InputDateTime`) you can
|
|
137
|
+
* set it to `always`.
|
|
138
|
+
*/
|
|
139
|
+
readonly clearable?: Clearable;
|
|
140
|
+
/**
|
|
141
|
+
* Used to locate this view in end-to-end tests
|
|
142
|
+
*/
|
|
143
|
+
testID?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Use secure text entry
|
|
146
|
+
*/
|
|
147
|
+
readonly secureTextEntry?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Determines whether spell check is used. Turn it off to hide empty autoCorrect
|
|
150
|
+
* suggestions when autoCorrect is off.
|
|
151
|
+
*
|
|
152
|
+
* *iOS Only*
|
|
153
|
+
*/
|
|
154
|
+
readonly spellCheck?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Custom styling to override default style of the input text
|
|
157
|
+
*/
|
|
158
|
+
readonly styleOverride?: InputTextStyleOverride;
|
|
159
|
+
}
|
|
160
|
+
interface InputTextStyleOverride extends InputFieldStyleOverride {
|
|
161
|
+
inputText?: StyleProp<TextStyle>;
|
|
162
|
+
}
|
|
163
|
+
export type InputTextRef = Pick<TextInput, "clear" | "focus" | "blur">;
|
|
164
|
+
export declare const InputText: React.ForwardRefExoticComponent<InputTextProps & React.RefAttributes<InputTextRef>>;
|
|
165
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const styles: {
|
|
2
|
+
inputPaddingTop: {
|
|
3
|
+
paddingTop: number | undefined;
|
|
4
|
+
};
|
|
5
|
+
multiLineInput: {
|
|
6
|
+
paddingTop: number;
|
|
7
|
+
paddingBottom: number;
|
|
8
|
+
lineHeight: number | undefined;
|
|
9
|
+
};
|
|
10
|
+
multiLineInputWithMini: {
|
|
11
|
+
paddingTop: number;
|
|
12
|
+
};
|
|
13
|
+
multilineInputiOS: {
|
|
14
|
+
paddingTop: number;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { InputAccessoriesContextProps } from "./types";
|
|
3
|
+
export declare const InputAccessoriesContext: import("react").Context<InputAccessoriesContextProps>;
|
|
4
|
+
export declare function useInputAccessoriesContext(): InputAccessoriesContextProps;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const styles: {
|
|
2
|
+
container: {
|
|
3
|
+
flexDirection: "row";
|
|
4
|
+
justifyContent: "flex-end";
|
|
5
|
+
alignItems: "center";
|
|
6
|
+
paddingHorizontal: number;
|
|
7
|
+
borderTopWidth: number;
|
|
8
|
+
borderTopColor: string;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
lightTheme: {
|
|
12
|
+
backgroundColor: string;
|
|
13
|
+
};
|
|
14
|
+
darkTheme: {
|
|
15
|
+
backgroundColor: import("react-native").OpaqueColorValue;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const styles: {
|
|
2
|
+
container: {
|
|
3
|
+
flexDirection: "row";
|
|
4
|
+
justifyContent: "space-between";
|
|
5
|
+
alignItems: "center";
|
|
6
|
+
paddingHorizontal: number;
|
|
7
|
+
backgroundColor: string;
|
|
8
|
+
borderTopWidth: number;
|
|
9
|
+
borderTopColor: string;
|
|
10
|
+
};
|
|
11
|
+
buttonContainer: {
|
|
12
|
+
flexDirection: "row";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type Name = string;
|
|
2
|
+
export interface InputAccessoriesContextProps {
|
|
3
|
+
/**
|
|
4
|
+
* Registered elements.
|
|
5
|
+
*/
|
|
6
|
+
readonly elements: Record<Name, () => void>;
|
|
7
|
+
readonly focusedInput: string;
|
|
8
|
+
readonly canFocusNext: boolean;
|
|
9
|
+
readonly canFocusPrevious: boolean;
|
|
10
|
+
readonly inputAccessoryID?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Registers the element to the context.
|
|
13
|
+
*/
|
|
14
|
+
readonly register: (name: Name, onFocus: () => void) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Un-registers the element from the context.
|
|
17
|
+
*/
|
|
18
|
+
readonly unregister: (name: Name) => void;
|
|
19
|
+
readonly onFocusNext: () => void;
|
|
20
|
+
readonly onFocusPrevious: () => void;
|
|
21
|
+
readonly setFocusedInput: (name: string) => void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useFormController";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FieldError, RegisterOptions, UseControllerReturn } from "react-hook-form";
|
|
2
|
+
interface UseFormControllerProps<T> {
|
|
3
|
+
name?: string;
|
|
4
|
+
value?: T;
|
|
5
|
+
validations?: RegisterOptions;
|
|
6
|
+
}
|
|
7
|
+
interface UseFormController {
|
|
8
|
+
error?: FieldError;
|
|
9
|
+
field: UseControllerReturn["field"];
|
|
10
|
+
}
|
|
11
|
+
export declare function useFormController<T>({ name, value, validations, }: UseFormControllerProps<T>): UseFormController;
|
|
12
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"module": "dist/src/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@jobber/design": "^0.41.2",
|
|
25
25
|
"lodash.chunk": "^4.2.0",
|
|
26
|
+
"lodash.identity": "^3.0.0",
|
|
26
27
|
"react-hook-form": "^7.30.0",
|
|
27
28
|
"react-intl": "^6.4.2",
|
|
28
29
|
"react-native-gesture-handler": "^2.5.0",
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"@testing-library/react-hooks": "^7.0.2",
|
|
38
39
|
"@testing-library/react-native": "^12.0.1",
|
|
39
40
|
"@types/lodash.chunk": "^4.2.7",
|
|
41
|
+
"@types/lodash.identity": "^3.0.7",
|
|
40
42
|
"@types/react": "^18.0.28",
|
|
41
43
|
"@types/react-native": "^0.71.6",
|
|
42
44
|
"@types/react-native-uuid": "^1.4.0",
|
|
@@ -49,5 +51,5 @@
|
|
|
49
51
|
"react": "^18",
|
|
50
52
|
"react-native": ">=0.69.2"
|
|
51
53
|
},
|
|
52
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "4924f4190c152e4d11b9f52adcd8dd91a727ae16"
|
|
53
55
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
3
|
+
import { typographyStyles } from "../Typography";
|
|
4
|
+
|
|
5
|
+
export const styles = StyleSheet.create({
|
|
6
|
+
inputPaddingTop: {
|
|
7
|
+
paddingTop: typographyStyles.smallSize.fontSize,
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
multiLineInput: {
|
|
11
|
+
paddingTop: tokens["space-base"] - tokens["space-smallest"],
|
|
12
|
+
paddingBottom: tokens["space-smaller"],
|
|
13
|
+
lineHeight: typographyStyles.defaultSize.lineHeight,
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
multiLineInputWithMini: {
|
|
17
|
+
paddingTop: tokens["space-large"],
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
multilineInputiOS: {
|
|
21
|
+
// for placeholder
|
|
22
|
+
paddingTop:
|
|
23
|
+
(typographyStyles.smallSize.fontSize || 0) + tokens["space-smallest"],
|
|
24
|
+
},
|
|
25
|
+
});
|