@prototyp/skeletor 1.0.2
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/.eslintrc.json +19 -0
- package/.github/CODEOWNERS +2 -0
- package/.gitignore +5 -0
- package/README.md +418 -0
- package/lib/module/components/Block/Block.js +71 -0
- package/lib/module/components/Block/Block.js.map +1 -0
- package/lib/module/components/Block/index.js +2 -0
- package/lib/module/components/Block/index.js.map +1 -0
- package/lib/module/components/InputFocusScrollView/InputFocusScrollView.js +93 -0
- package/lib/module/components/InputFocusScrollView/InputFocusScrollView.js.map +1 -0
- package/lib/module/components/InputFocusScrollView/index.js +2 -0
- package/lib/module/components/InputFocusScrollView/index.js.map +1 -0
- package/lib/module/components/Screen/Screen.js +55 -0
- package/lib/module/components/Screen/Screen.js.map +1 -0
- package/lib/module/components/Screen/index.js +2 -0
- package/lib/module/components/Screen/index.js.map +1 -0
- package/lib/module/components/SkeletorProvider/SkeletorContext.js +9 -0
- package/lib/module/components/SkeletorProvider/SkeletorContext.js.map +1 -0
- package/lib/module/components/SkeletorProvider/SkeletorProvider.js +17 -0
- package/lib/module/components/SkeletorProvider/SkeletorProvider.js.map +1 -0
- package/lib/module/components/SkeletorProvider/index.js +3 -0
- package/lib/module/components/SkeletorProvider/index.js.map +1 -0
- package/lib/module/components/Text/Text.js +64 -0
- package/lib/module/components/Text/Text.js.map +1 -0
- package/lib/module/components/Text/index.js +2 -0
- package/lib/module/components/Text/index.js.map +1 -0
- package/lib/module/components/index.js +6 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/hooks/index.js +7 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/hooks/useAndroidBackHandler.js +24 -0
- package/lib/module/hooks/useAndroidBackHandler.js.map +1 -0
- package/lib/module/hooks/useAnimation.js +33 -0
- package/lib/module/hooks/useAnimation.js.map +1 -0
- package/lib/module/hooks/useAnimationTimeline.js +97 -0
- package/lib/module/hooks/useAnimationTimeline.js.map +1 -0
- package/lib/module/hooks/useAppState.js +21 -0
- package/lib/module/hooks/useAppState.js.map +1 -0
- package/lib/module/hooks/useForm.js +159 -0
- package/lib/module/hooks/useForm.js.map +1 -0
- package/lib/module/hooks/useSkeletor.js +6 -0
- package/lib/module/hooks/useSkeletor.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/models/Alignment.js +2 -0
- package/lib/module/models/Alignment.js.map +1 -0
- package/lib/module/models/Border.js +2 -0
- package/lib/module/models/Border.js.map +1 -0
- package/lib/module/models/Size.js +2 -0
- package/lib/module/models/Size.js.map +1 -0
- package/lib/module/models/SkeletorConfig.js +2 -0
- package/lib/module/models/SkeletorConfig.js.map +1 -0
- package/lib/module/models/Spacing.js +2 -0
- package/lib/module/models/Spacing.js.map +1 -0
- package/lib/module/models/index.js +6 -0
- package/lib/module/models/index.js.map +1 -0
- package/lib/module/types/Font.d.js +2 -0
- package/lib/module/types/Font.d.js.map +1 -0
- package/lib/module/utils/extractAlignmentProperties.js +10 -0
- package/lib/module/utils/extractAlignmentProperties.js.map +1 -0
- package/lib/module/utils/extractSizeProperties.js +12 -0
- package/lib/module/utils/extractSizeProperties.js.map +1 -0
- package/lib/module/utils/index.js +3 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/lib/module/components/Block/Block.d.ts +4 -0
- package/lib/typescript/lib/module/components/Block/Block.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/Block/index.d.ts +2 -0
- package/lib/typescript/lib/module/components/Block/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/InputFocusScrollView/InputFocusScrollView.d.ts +4 -0
- package/lib/typescript/lib/module/components/InputFocusScrollView/InputFocusScrollView.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/InputFocusScrollView/index.d.ts +2 -0
- package/lib/typescript/lib/module/components/InputFocusScrollView/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/Screen/Screen.d.ts +5 -0
- package/lib/typescript/lib/module/components/Screen/Screen.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/Screen/index.d.ts +2 -0
- package/lib/typescript/lib/module/components/Screen/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/SkeletorProvider/SkeletorContext.d.ts +14 -0
- package/lib/typescript/lib/module/components/SkeletorProvider/SkeletorContext.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/SkeletorProvider/SkeletorProvider.d.ts +8 -0
- package/lib/typescript/lib/module/components/SkeletorProvider/SkeletorProvider.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/SkeletorProvider/index.d.ts +3 -0
- package/lib/typescript/lib/module/components/SkeletorProvider/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/Text/Text.d.ts +4 -0
- package/lib/typescript/lib/module/components/Text/Text.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/Text/index.d.ts +2 -0
- package/lib/typescript/lib/module/components/Text/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/components/index.d.ts +6 -0
- package/lib/typescript/lib/module/components/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks/index.d.ts +7 -0
- package/lib/typescript/lib/module/hooks/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks/useAndroidBackHandler.d.ts +2 -0
- package/lib/typescript/lib/module/hooks/useAndroidBackHandler.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks/useAnimation.d.ts +9 -0
- package/lib/typescript/lib/module/hooks/useAnimation.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks/useAnimationTimeline.d.ts +10 -0
- package/lib/typescript/lib/module/hooks/useAnimationTimeline.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks/useAppState.d.ts +2 -0
- package/lib/typescript/lib/module/hooks/useAppState.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks/useForm.d.ts +33 -0
- package/lib/typescript/lib/module/hooks/useForm.d.ts.map +1 -0
- package/lib/typescript/lib/module/hooks/useSkeletor.d.ts +7 -0
- package/lib/typescript/lib/module/hooks/useSkeletor.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +5 -0
- package/lib/typescript/lib/module/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/models/Alignment.d.ts +2 -0
- package/lib/typescript/lib/module/models/Alignment.d.ts.map +1 -0
- package/lib/typescript/lib/module/models/Border.d.ts +1 -0
- package/lib/typescript/lib/module/models/Border.d.ts.map +1 -0
- package/lib/typescript/lib/module/models/Size.d.ts +1 -0
- package/lib/typescript/lib/module/models/Size.d.ts.map +1 -0
- package/lib/typescript/lib/module/models/SkeletorConfig.d.ts +1 -0
- package/lib/typescript/lib/module/models/SkeletorConfig.d.ts.map +1 -0
- package/lib/typescript/lib/module/models/Spacing.d.ts +1 -0
- package/lib/typescript/lib/module/models/Spacing.d.ts.map +1 -0
- package/lib/typescript/lib/module/models/index.d.ts +2 -0
- package/lib/typescript/lib/module/models/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/types/Font.d.d.ts +1 -0
- package/lib/typescript/lib/module/types/Font.d.d.ts.map +1 -0
- package/lib/typescript/lib/module/utils/extractAlignmentProperties.d.ts +8 -0
- package/lib/typescript/lib/module/utils/extractAlignmentProperties.d.ts.map +1 -0
- package/lib/typescript/lib/module/utils/extractSizeProperties.d.ts +10 -0
- package/lib/typescript/lib/module/utils/extractSizeProperties.d.ts.map +1 -0
- package/lib/typescript/lib/module/utils/index.d.ts +3 -0
- package/lib/typescript/lib/module/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Block/Block.d.ts +23 -0
- package/lib/typescript/src/components/Block/Block.d.ts.map +1 -0
- package/lib/typescript/src/components/Block/index.d.ts +2 -0
- package/lib/typescript/src/components/Block/index.d.ts.map +1 -0
- package/lib/typescript/src/components/InputFocusScrollView/InputFocusScrollView.d.ts +18 -0
- package/lib/typescript/src/components/InputFocusScrollView/InputFocusScrollView.d.ts.map +1 -0
- package/lib/typescript/src/components/InputFocusScrollView/index.d.ts +2 -0
- package/lib/typescript/src/components/InputFocusScrollView/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Screen/Screen.d.ts +16 -0
- package/lib/typescript/src/components/Screen/Screen.d.ts.map +1 -0
- package/lib/typescript/src/components/Screen/index.d.ts +2 -0
- package/lib/typescript/src/components/Screen/index.d.ts.map +1 -0
- package/lib/typescript/src/components/SkeletorProvider/SkeletorContext.d.ts +5 -0
- package/lib/typescript/src/components/SkeletorProvider/SkeletorContext.d.ts.map +1 -0
- package/lib/typescript/src/components/SkeletorProvider/SkeletorProvider.d.ts +8 -0
- package/lib/typescript/src/components/SkeletorProvider/SkeletorProvider.d.ts.map +1 -0
- package/lib/typescript/src/components/SkeletorProvider/index.d.ts +3 -0
- package/lib/typescript/src/components/SkeletorProvider/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Text/Text.d.ts +21 -0
- package/lib/typescript/src/components/Text/Text.d.ts.map +1 -0
- package/lib/typescript/src/components/Text/index.d.ts +2 -0
- package/lib/typescript/src/components/Text/index.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +6 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +7 -0
- package/lib/typescript/src/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useAndroidBackHandler.d.ts +16 -0
- package/lib/typescript/src/hooks/useAndroidBackHandler.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useAnimation.d.ts +20 -0
- package/lib/typescript/src/hooks/useAnimation.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useAnimationTimeline.d.ts +30 -0
- package/lib/typescript/src/hooks/useAnimationTimeline.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useAppState.d.ts +7 -0
- package/lib/typescript/src/hooks/useAppState.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useForm.d.ts +52 -0
- package/lib/typescript/src/hooks/useForm.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSkeletor.d.ts +3 -0
- package/lib/typescript/src/hooks/useSkeletor.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/models/Alignment.d.ts +9 -0
- package/lib/typescript/src/models/Alignment.d.ts.map +1 -0
- package/lib/typescript/src/models/Border.d.ts +16 -0
- package/lib/typescript/src/models/Border.d.ts.map +1 -0
- package/lib/typescript/src/models/Size.d.ts +10 -0
- package/lib/typescript/src/models/Size.d.ts.map +1 -0
- package/lib/typescript/src/models/SkeletorConfig.d.ts +7 -0
- package/lib/typescript/src/models/SkeletorConfig.d.ts.map +1 -0
- package/lib/typescript/src/models/Spacing.d.ts +21 -0
- package/lib/typescript/src/models/Spacing.d.ts.map +1 -0
- package/lib/typescript/src/models/index.d.ts +6 -0
- package/lib/typescript/src/models/index.d.ts.map +1 -0
- package/lib/typescript/src/utils/extractAlignmentProperties.d.ts +3 -0
- package/lib/typescript/src/utils/extractAlignmentProperties.d.ts.map +1 -0
- package/lib/typescript/src/utils/extractSizeProperties.d.ts +3 -0
- package/lib/typescript/src/utils/extractSizeProperties.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +3 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +63 -0
- package/prototyp-skeletor-v1.0.0.tgz +0 -0
- package/src/components/Block/Block.tsx +106 -0
- package/src/components/Block/index.ts +1 -0
- package/src/components/InputFocusScrollView/InputFocusScrollView.tsx +120 -0
- package/src/components/InputFocusScrollView/index.ts +1 -0
- package/src/components/Screen/Screen.tsx +91 -0
- package/src/components/Screen/index.ts +1 -0
- package/src/components/SkeletorProvider/SkeletorContext.ts +12 -0
- package/src/components/SkeletorProvider/SkeletorProvider.tsx +18 -0
- package/src/components/SkeletorProvider/index.ts +2 -0
- package/src/components/Text/Text.tsx +99 -0
- package/src/components/Text/index.ts +1 -0
- package/src/components/index.ts +5 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useAndroidBackHandler.ts +45 -0
- package/src/hooks/useAnimation.ts +62 -0
- package/src/hooks/useAnimationTimeline.ts +139 -0
- package/src/hooks/useAppState.ts +26 -0
- package/src/hooks/useForm.ts +190 -0
- package/src/hooks/useSkeletor.ts +7 -0
- package/src/index.ts +4 -0
- package/src/models/Alignment.ts +9 -0
- package/src/models/Border.ts +15 -0
- package/src/models/Size.ts +9 -0
- package/src/models/SkeletorConfig.ts +6 -0
- package/src/models/Spacing.ts +20 -0
- package/src/models/index.ts +5 -0
- package/src/types/Font.d.ts +1 -0
- package/src/utils/extractAlignmentProperties.ts +13 -0
- package/src/utils/extractSizeProperties.ts +13 -0
- package/src/utils/index.ts +2 -0
- package/tsconfig.json +16 -0
- package/yarn.lock +6080 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
type Validation<T> = { [K in keyof Partial<T>]?: boolean };
|
|
4
|
+
type Rules<T> = {
|
|
5
|
+
[K in keyof T]?: (value: T[K], state: T) => boolean | undefined;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type Values<T> = {
|
|
9
|
+
[K in keyof T]: T[K];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type FormConfig<R> = {
|
|
13
|
+
/** List of optional properties. Optional properties will be marked as valid if left empty. */
|
|
14
|
+
optional?: Array<keyof R>;
|
|
15
|
+
/** Validation rules by specified property name. If you define a validation rule function here, the field will be validated against it. If no rule is set, a crude value check will be used instead (Boolean(value)) */
|
|
16
|
+
rules?: Rules<R>;
|
|
17
|
+
/** Will compare key/value pairs instead of just top level JSON.stringify on complex objects/arrays */
|
|
18
|
+
deepCompare?: boolean;
|
|
19
|
+
logging?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** One-fits-all solution to manage state changes, field validation and optional entries within a form.
|
|
23
|
+
* @example <caption>Simple use case:</caption>
|
|
24
|
+
* const { state, validation, update } = useForm({ email: '', password: '', });
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* @example <caption>For more complex form states (ie one field can be of multiple types), you should pass the form's type:</caption>
|
|
28
|
+
* const { state, validation, update } = useForm<{ numericOrUndefined: number | undefined }>({ numericOrUndefined: undefined }, { rules: { numericOrUndefined: (value: number | undefined): boolean | undefined => ... }});
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export function useForm<T>(values: Values<T>, config?: FormConfig<T>) {
|
|
32
|
+
const keys = Object.keys(values) as Array<keyof T>;
|
|
33
|
+
const [validation, setValidation] = useState<Validation<T>>({});
|
|
34
|
+
const [initialState, setInitialState] = useState(values);
|
|
35
|
+
const [state, setState] = useState(values);
|
|
36
|
+
const { fieldValidation, stateValidation, isOptional } = useFormUtils(config);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const changed = keys.filter((key) => values[key] !== initialState[key]);
|
|
40
|
+
if (!changed.length) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const updatedState = { ...state };
|
|
45
|
+
changed.forEach((key) => (updatedState[key] = values[key]));
|
|
46
|
+
|
|
47
|
+
setInitialState({ ...values, ...updatedState });
|
|
48
|
+
setState(updatedState);
|
|
49
|
+
}, [values]);
|
|
50
|
+
|
|
51
|
+
/** This function updates the specific property with a new value and validates it if it needs to do so.
|
|
52
|
+
* @example <caption>Usage:</caption>
|
|
53
|
+
* <TextInput ... onChange={(event) => update("nameOfProp", event.nativeEvent.text, false)} onBlur={(event) => update("nameOfProp", event.nativeEvent.text, true)}
|
|
54
|
+
* */
|
|
55
|
+
function update<K extends keyof T>(
|
|
56
|
+
key: K,
|
|
57
|
+
value: Values<T>[K],
|
|
58
|
+
shouldValidate?: boolean,
|
|
59
|
+
) {
|
|
60
|
+
setState((s) => ({ ...s, [key]: value }));
|
|
61
|
+
setValidation((s) => ({
|
|
62
|
+
...s,
|
|
63
|
+
[key]: shouldValidate ? fieldValidation(key, value, state) : undefined,
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function validate<K extends keyof T>(key: K) {
|
|
68
|
+
setValidation((s) => ({
|
|
69
|
+
...s,
|
|
70
|
+
[key]: fieldValidation(key, state[key], state),
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Validate entire form, store validation state and return validation value.
|
|
75
|
+
* In human readable terms, use this when you want to validate the form on submit.
|
|
76
|
+
*/
|
|
77
|
+
function validateForm(): boolean {
|
|
78
|
+
const formValidationState = stateValidation(state);
|
|
79
|
+
setValidation(formValidationState.validation);
|
|
80
|
+
return formValidationState.valid;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Boolean value of whether the form is valid (ie can be submitted). Use this to disable/enable form submission.
|
|
84
|
+
* Only use when validating fields separately, has no value when valiating on form submit. */
|
|
85
|
+
function isFormValid() {
|
|
86
|
+
return !keys.some((key) =>
|
|
87
|
+
isOptional(key) ? validation[key] === false : !validation[key],
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Resets changed values to initial state */
|
|
92
|
+
function resetState() {
|
|
93
|
+
setState(values);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Re-initializes initial state from currently passed values. Use this if you need to reinitialize the form after the source values change, i.e. if a different state object comes into play after submitting the form (such as reducer data or API endpoint response data) */
|
|
97
|
+
function resetInitialValues() {
|
|
98
|
+
setInitialState(values);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Resets validation to initial state. */
|
|
102
|
+
function resetValidation() {
|
|
103
|
+
setValidation({});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Resets entire form, state and validation included */
|
|
107
|
+
function clearForm() {
|
|
108
|
+
resetInitialValues();
|
|
109
|
+
resetState();
|
|
110
|
+
resetValidation();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
state,
|
|
115
|
+
validation,
|
|
116
|
+
update,
|
|
117
|
+
validate,
|
|
118
|
+
validateForm,
|
|
119
|
+
isFormValid,
|
|
120
|
+
clearForm,
|
|
121
|
+
resetState,
|
|
122
|
+
resetValidation,
|
|
123
|
+
resetInitialValues,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Helper hook to validate form state outside of the scope of useForm. */
|
|
128
|
+
export function useFormUtils<T>(config?: FormConfig<T>) {
|
|
129
|
+
function doesValueExist(value: T[keyof T] | undefined): value is T[keyof T] {
|
|
130
|
+
if (value === null || value === undefined || value === "" || value < 0) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function validateByRule<K extends keyof T>(
|
|
137
|
+
key: K,
|
|
138
|
+
value: T[K],
|
|
139
|
+
state: Values<T>,
|
|
140
|
+
) {
|
|
141
|
+
// If rule exists, validate with rule
|
|
142
|
+
if (config?.rules && config.rules[key]) {
|
|
143
|
+
return config.rules[key]?.(value, state);
|
|
144
|
+
}
|
|
145
|
+
// else return true because we know the value exists already.
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isOptional(key: keyof T) {
|
|
150
|
+
return config?.optional?.includes(key);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function fieldValidation(
|
|
154
|
+
key: keyof T,
|
|
155
|
+
value: T[keyof T] | undefined,
|
|
156
|
+
state: Values<T>,
|
|
157
|
+
) {
|
|
158
|
+
const hasValue = doesValueExist(value);
|
|
159
|
+
const optional = isOptional(key);
|
|
160
|
+
if (!hasValue) {
|
|
161
|
+
return !!optional;
|
|
162
|
+
} else {
|
|
163
|
+
return validateByRule(key, value, state);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function stateValidation(state: Values<T>) {
|
|
168
|
+
const keys = Object.keys(state).map((key) => key as keyof T);
|
|
169
|
+
const validation: Validation<T> = {};
|
|
170
|
+
|
|
171
|
+
keys.forEach((key) => {
|
|
172
|
+
const value = state[key];
|
|
173
|
+
// Force true / false values for entire form. Undefined has no value when submitting.
|
|
174
|
+
validation[key] = fieldValidation(key, value, state) || false;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
valid: !keys.some((key) => !validation[key]),
|
|
179
|
+
validation,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
doesValueExist,
|
|
185
|
+
validateByRule,
|
|
186
|
+
isOptional,
|
|
187
|
+
fieldValidation,
|
|
188
|
+
stateValidation,
|
|
189
|
+
};
|
|
190
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ViewStyle } from "react-native";
|
|
2
|
+
|
|
3
|
+
export interface Alignment {
|
|
4
|
+
align?: ViewStyle["alignItems"];
|
|
5
|
+
alignSelf?: ViewStyle["alignSelf"];
|
|
6
|
+
justify?: ViewStyle["justifyContent"];
|
|
7
|
+
flexDirection?: ViewStyle["flexDirection"];
|
|
8
|
+
flexWrap?: ViewStyle["flexWrap"];
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Border {
|
|
2
|
+
border?: {
|
|
3
|
+
borderWidth?: number;
|
|
4
|
+
borderTopWidth?: number;
|
|
5
|
+
borderBottomWidth?: number;
|
|
6
|
+
borderLeftWidth?: number;
|
|
7
|
+
borderRightWidth?: number;
|
|
8
|
+
borderColor?: string;
|
|
9
|
+
borderRadius?: number;
|
|
10
|
+
borderTopLeftRadius?: number;
|
|
11
|
+
borderTopRightRadius?: number;
|
|
12
|
+
borderBottomLeftRadius?: number;
|
|
13
|
+
borderBottomRightRadius?: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Spacing {
|
|
2
|
+
margins?: {
|
|
3
|
+
marginTop?: number | string;
|
|
4
|
+
marginBottom?: number | string;
|
|
5
|
+
marginLeft?: number | string;
|
|
6
|
+
marginRight?: number | string;
|
|
7
|
+
marginHorizontal?: number | string;
|
|
8
|
+
marginVertical?: number | string;
|
|
9
|
+
margin?: number | string;
|
|
10
|
+
};
|
|
11
|
+
paddings?: {
|
|
12
|
+
paddingTop?: number | string;
|
|
13
|
+
paddingBottom?: number | string;
|
|
14
|
+
paddingLeft?: number | string;
|
|
15
|
+
paddingRight?: number | string;
|
|
16
|
+
paddingHorizontal?: number | string;
|
|
17
|
+
paddingVertical?: number | string;
|
|
18
|
+
padding?: number | string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
type Font = string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Alignment } from "../models";
|
|
2
|
+
|
|
3
|
+
export function extractAlignmentProperties<Props extends Alignment>(
|
|
4
|
+
props: Props,
|
|
5
|
+
): Alignment {
|
|
6
|
+
return {
|
|
7
|
+
align: props.align,
|
|
8
|
+
alignSelf: props.alignSelf,
|
|
9
|
+
justify: props.justify,
|
|
10
|
+
flexDirection: props.flexDirection,
|
|
11
|
+
flexWrap: props.flexWrap,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Size } from "../models";
|
|
2
|
+
|
|
3
|
+
export function extractSizeProperties<Props extends Size>(props: Props): Size {
|
|
4
|
+
return {
|
|
5
|
+
flex: props.flex,
|
|
6
|
+
height: props.height,
|
|
7
|
+
width: props.width,
|
|
8
|
+
maxHeight: props.maxHeight,
|
|
9
|
+
maxWidth: props.maxWidth,
|
|
10
|
+
minHeight: props.minHeight,
|
|
11
|
+
minWidth: props.minWidth,
|
|
12
|
+
};
|
|
13
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/react-native/tsconfig.json" /* Recommended React Native TSConfig base */,
|
|
3
|
+
"exclude": ["__tests__", "./*.config.js", "index.js", "node_modules"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
6
|
+
|
|
7
|
+
/* Completeness */
|
|
8
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
|
|
9
|
+
"baseUrl": "src",
|
|
10
|
+
"rootDirs": ["src"],
|
|
11
|
+
"typeRoots": ["./src/types"],
|
|
12
|
+
"lib": ["es2016"],
|
|
13
|
+
"jsx": "react-native",
|
|
14
|
+
"noEmit": false
|
|
15
|
+
}
|
|
16
|
+
}
|