@wq/form-native 3.0.0-alpha.0 → 3.0.0-alpha.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/package.json +2 -2
- package/src/AutoForm.js +8 -14
- package/src/FormProvider.js +18 -0
- package/src/components/DeleteForm.js +54 -39
- package/src/components/FormContainer.js +4 -0
- package/src/components/FormRoot.js +1 -1
- package/src/components/index.js +2 -0
- package/src/index.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wq/form-native",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"description": "React Native and Expo bindings for @wq/material",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://form.wq.io/@wq/form-native",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@wq/form-common": "^3.0.0-alpha.
|
|
31
|
+
"@wq/form-common": "^3.0.0-alpha.3",
|
|
32
32
|
"@wq/react": "^3.0.0-alpha.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
package/src/AutoForm.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import * as components from "./components/index.js";
|
|
2
|
+
import { AutoFormBase } from "@wq/form-common";
|
|
3
|
+
import FormProvider from "./FormProvider.js";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return props.children || null;
|
|
13
|
-
}
|
|
14
|
-
return <AutoFormBase {...props} />;
|
|
5
|
+
export default function AutoForm(props) {
|
|
6
|
+
return (
|
|
7
|
+
<FormProvider>
|
|
8
|
+
<AutoFormBase {...props} />
|
|
9
|
+
</FormProvider>
|
|
10
|
+
);
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
export default withWQ(AutoForm, { defaults: AutoFormDefaults });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fragment } from "react";
|
|
2
|
+
import { withWQ } from "@wq/react";
|
|
3
|
+
import {
|
|
4
|
+
AutoFormBase as AutoForm,
|
|
5
|
+
AutoInput,
|
|
6
|
+
Form,
|
|
7
|
+
CancelButton,
|
|
8
|
+
} from "@wq/form-common";
|
|
9
|
+
import * as components from "./components/index.js";
|
|
10
|
+
|
|
11
|
+
const FormProviderDefaults = {
|
|
12
|
+
components: { ...components, AutoForm, AutoInput, Form, CancelButton },
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default withWQ(Fragment, {
|
|
16
|
+
name: "FormProvider",
|
|
17
|
+
defaults: FormProviderDefaults,
|
|
18
|
+
});
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
createFallbackComponents,
|
|
7
7
|
} from "@wq/react";
|
|
8
8
|
import { Form } from "@wq/form-common";
|
|
9
|
+
import FormContainer from "./FormContainer.js";
|
|
9
10
|
import SubmitButton from "./SubmitButton.js";
|
|
10
11
|
import Alert from "react-native";
|
|
11
12
|
import PropTypes from "prop-types";
|
|
@@ -18,68 +19,82 @@ const DeleteFormFallback = {
|
|
|
18
19
|
CONFIRM_DELETE_CANCEL: "Cancel",
|
|
19
20
|
},
|
|
20
21
|
components: {
|
|
22
|
+
FormContainer,
|
|
21
23
|
Form,
|
|
22
24
|
SubmitButton,
|
|
23
25
|
...createFallbackComponents(["View", "HorizontalView"], "@wq/material"),
|
|
24
26
|
},
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
function DeleteForm({ action }) {
|
|
28
|
-
const { Form, SubmitButton, View, HorizontalView } =
|
|
29
|
+
function DeleteForm({ action, onSubmit, submitOptions }) {
|
|
30
|
+
const { FormContainer, Form, SubmitButton, View, HorizontalView } =
|
|
31
|
+
useComponents(),
|
|
29
32
|
confirmDelete = useMessage("CONFIRM_DELETE"),
|
|
30
33
|
confirmDeleteTitle = useMessage("CONFIRM_DELETE_TITLE"),
|
|
31
34
|
confirmDeleteOk = useMessage("CONFIRM_DELETE_OK"),
|
|
32
35
|
confirmDeleteCancel = useMessage("CONFIRM_DELETE_CANCEL");
|
|
33
36
|
|
|
34
|
-
async function confirmSubmit() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
resolve(false);
|
|
44
|
-
},
|
|
45
|
-
style: "cancel",
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
text: confirmDeleteOk,
|
|
49
|
-
onPress() {
|
|
50
|
-
resolve(true);
|
|
51
|
-
},
|
|
52
|
-
style: "destructive",
|
|
37
|
+
async function confirmSubmit(options) {
|
|
38
|
+
Alert.alert(
|
|
39
|
+
confirmDeleteTitle,
|
|
40
|
+
confirmDelete,
|
|
41
|
+
[
|
|
42
|
+
{
|
|
43
|
+
text: confirmDeleteCancel,
|
|
44
|
+
onPress() {
|
|
45
|
+
// noop
|
|
53
46
|
},
|
|
54
|
-
|
|
47
|
+
style: "cancel",
|
|
48
|
+
},
|
|
55
49
|
{
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
text: confirmDeleteOk,
|
|
51
|
+
onPress() {
|
|
52
|
+
if (onSubmit) {
|
|
53
|
+
onSubmit(options);
|
|
54
|
+
} else {
|
|
55
|
+
console.error(
|
|
56
|
+
"No onSubmit handler provided to DeleteForm",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
58
59
|
},
|
|
60
|
+
style: "destructive",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
{
|
|
64
|
+
onDismiss() {
|
|
65
|
+
// noop
|
|
59
66
|
},
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
},
|
|
68
|
+
);
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
return (
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
<FormContainer>
|
|
73
|
+
<Form
|
|
74
|
+
action={action}
|
|
75
|
+
method="DELETE"
|
|
76
|
+
onSubmit={confirmSubmit}
|
|
77
|
+
submitOptions={submitOptions}
|
|
78
|
+
>
|
|
79
|
+
<HorizontalView>
|
|
80
|
+
<View />
|
|
81
|
+
<SubmitButton
|
|
82
|
+
icon="delete"
|
|
83
|
+
variant="text"
|
|
84
|
+
color="secondary"
|
|
85
|
+
>
|
|
86
|
+
Delete
|
|
87
|
+
</SubmitButton>
|
|
88
|
+
</HorizontalView>
|
|
89
|
+
</Form>
|
|
90
|
+
</FormContainer>
|
|
78
91
|
);
|
|
79
92
|
}
|
|
80
93
|
|
|
81
94
|
DeleteForm.propTypes = {
|
|
82
95
|
action: PropTypes.string,
|
|
96
|
+
onSubmit: PropTypes.func.isRequired,
|
|
97
|
+
submitOptions: PropTypes.object,
|
|
83
98
|
};
|
|
84
99
|
|
|
85
100
|
export default withWQ(DeleteForm, { fallback: DeleteFormFallback });
|
package/src/components/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import FormContainer from "./FormContainer.js";
|
|
1
2
|
import FormRoot from "./FormRoot.js";
|
|
2
3
|
import FormError from "./FormError.js";
|
|
3
4
|
import Input from "./Input.js";
|
|
@@ -25,6 +26,7 @@ const Time = DateTime;
|
|
|
25
26
|
const dateTime = DateTime;
|
|
26
27
|
|
|
27
28
|
export {
|
|
29
|
+
FormContainer,
|
|
28
30
|
FormRoot,
|
|
29
31
|
FormError,
|
|
30
32
|
Input,
|
package/src/index.js
CHANGED