@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wq/form-native",
3
- "version": "3.0.0-alpha.0",
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.0",
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 { withWQ } from "@wq/react";
3
- import { AutoFormBase, AutoInput, Form, CancelButton } from "@wq/form-common";
4
- import * as components from "./components/index.js";
2
+ import { AutoFormBase } from "@wq/form-common";
3
+ import FormProvider from "./FormProvider.js";
5
4
 
6
- const AutoFormDefaults = {
7
- components: { ...components, AutoForm, AutoInput, Form, CancelButton },
8
- };
9
-
10
- function AutoForm(props) {
11
- if (!props.action && !props.onSubmit && !props.form) {
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 } = useComponents(),
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
- return new Promise((resolve) => {
36
- Alert.alert(
37
- confirmDeleteTitle,
38
- confirmDelete,
39
- [
40
- {
41
- text: confirmDeleteCancel,
42
- onPress() {
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
- onDismiss() {
57
- resolve(false);
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
- <Form
66
- action={action}
67
- method="DELETE"
68
- backgroundSync={false}
69
- onSubmit={confirmSubmit}
70
- >
71
- <HorizontalView>
72
- <View />
73
- <SubmitButton icon="delete" variant="text" color="secondary">
74
- Delete
75
- </SubmitButton>
76
- </HorizontalView>
77
- </Form>
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 });
@@ -0,0 +1,4 @@
1
+ import { Fragment } from "react";
2
+ import { withWQ } from "@wq/react";
3
+
4
+ export default withWQ(Fragment, "FormContainer");
@@ -1,4 +1,4 @@
1
1
  import { Fragment } from "react";
2
2
  import { withWQ } from "@wq/react";
3
3
 
4
- export default withWQ(Fragment, "FormRoot");
4
+ export default withWQ(Fragment, "FormContainer");
@@ -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
@@ -1,3 +1,4 @@
1
1
  import AutoForm from "./AutoForm.js";
2
- export { AutoForm };
2
+ import FormProvider from "./FormProvider.js";
3
+ export { AutoForm, FormProvider };
3
4
  export * from "./components/index.js";