@reactables/react-forms 0.4.0-alpha.2 → 0.4.0-alpha.3

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.
@@ -1,16 +1,17 @@
1
1
  import React from 'react';
2
- import { AbstractControlConfig, ControlModels, RxFormActions } from '@reactables/forms';
3
- export declare const FormContext: React.Context<{
2
+ import { ControlModels, RxFormActions } from '@reactables/forms';
3
+ interface HookedRxForm {
4
4
  state: ControlModels.Form<unknown>;
5
5
  actions: RxFormActions;
6
- }>;
6
+ }
7
+ export declare const FormContext: React.Context<HookedRxForm>;
7
8
  export interface FormChildrenProps {
8
9
  state: ControlModels.Form<unknown>;
9
10
  actions: RxFormActions;
10
11
  }
11
12
  interface FormProps {
12
- formConfig: AbstractControlConfig;
13
- children?: (props: FormChildrenProps) => React.ReactNode;
13
+ rxForm: HookedRxForm;
14
+ children?: React.ReactNode;
14
15
  }
15
- export declare const Form: ({ formConfig, children }: FormProps) => React.JSX.Element;
16
+ export declare const Form: ({ rxForm, children }: FormProps) => React.JSX.Element;
16
17
  export {};
@@ -0,0 +1 @@
1
+ export { useForm } from './useForm';
@@ -0,0 +1,5 @@
1
+ import { AbstractControlConfig } from '@reactables/forms';
2
+ export declare const useForm: (config: AbstractControlConfig) => {
3
+ state: import("@reactables/forms/dist/Models/Controls").Form<unknown>;
4
+ actions: import("@reactables/forms").RxFormActions;
5
+ };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './Components';
2
+ export * from './Hooks';
2
3
  export * from '@reactables/forms';
package/dist/index.js CHANGED
@@ -12,16 +12,8 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
12
 
13
13
  var FormContext = React__default["default"].createContext(null);
14
14
  var Form = function (_a) {
15
- var formConfig = _a.formConfig, children = _a.children;
16
- var _b = reactHelpers.useReactable(forms.RxForm.build(formConfig)), state = _b.state, actions = _b.actions;
17
- var formChildrenProps = {
18
- state: state,
19
- actions: actions
20
- };
21
- return (React__default["default"].createElement(FormContext.Provider, { value: {
22
- state: state,
23
- actions: actions
24
- } }, state !== undefined && children && children(formChildrenProps)));
15
+ var rxForm = _a.rxForm, children = _a.children;
16
+ return React__default["default"].createElement(FormContext.Provider, { value: rxForm }, rxForm.state && children);
25
17
  };
26
18
 
27
19
  /******************************************************************************
@@ -103,9 +95,15 @@ var FormArray = function (_a) {
103
95
  return React__default["default"].createElement("div", null, children && children(formArrayChildrenProps));
104
96
  };
105
97
 
98
+ var useForm = function (config) {
99
+ var rxForm = reactHelpers.useReactable(forms.RxForm.build(config));
100
+ return rxForm;
101
+ };
102
+
106
103
  exports.Field = Field;
107
104
  exports.Form = Form;
108
105
  exports.FormArray = FormArray;
106
+ exports.useForm = useForm;
109
107
  Object.keys(forms).forEach(function (k) {
110
108
  if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
111
109
  enumerable: true,
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
19
  "@reactables/core": "*",
20
- "@reactables/forms": "^0.4.0-alpha.2",
20
+ "@reactables/forms": "^0.4.0-alpha.3",
21
21
  "@reactables/react-helpers": "*"
22
22
  },
23
23
  "peerDependencies": {
@@ -25,5 +25,5 @@
25
25
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
26
26
  "rxjs": "^6.0.0 || ^7.0.0"
27
27
  },
28
- "version": "0.4.0-alpha.2"
28
+ "version": "0.4.0-alpha.3"
29
29
  }