react-compose-form 0.0.6-beta.0 → 0.0.6-beta.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.
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { ControllerProps } from "react-hook-form";
3
+ export declare const ControllerWithContext: React.FC<ControllerProps>;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Controller, useFormContext } from "react-hook-form";
3
+ export const ControllerWithContext = (props) => {
4
+ const { control } = useFormContext();
5
+ return (_jsx(Controller, Object.assign({}, props, { control: control })));
6
+ };
@@ -1,10 +1,11 @@
1
1
  import { ComponentType } from "react";
2
2
  import { Control, ControllerRenderProps, Message, ValidationRule, ControllerFieldState } from "react-hook-form";
3
- export type FormFieldProps<P = unknown> = P & Partial<ControllerRenderProps & ControllerFieldState>;
3
+ import { FormFieldProps } from "../types";
4
4
  export type FormControlProps<P = unknown> = Omit<P, "as" | "name" | "disabled" | "required" | keyof ControllerFieldState | keyof ControllerRenderProps> & {
5
5
  as?: ComponentType<FormFieldProps<P>>;
6
6
  name: string;
7
7
  disabled?: boolean;
8
+ withState?: boolean;
8
9
  required?: Message | ValidationRule<boolean>;
9
10
  control?: Control;
10
11
  };
@@ -10,20 +10,19 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { useFormContext, Controller } from "react-hook-form";
13
+ import { Controller } from "react-hook-form";
14
14
  import { FormControlContext } from "../contexts";
15
15
  import { useFormGroupName } from "../hooks";
16
- const ControllerWithContext = (props) => {
17
- const { control } = useFormContext();
18
- return (_jsx(Controller, Object.assign({}, props, { control: control })));
19
- };
16
+ import { ControllerWithContext } from "./ControllerWithContext";
20
17
  export const FormControl = (props) => {
21
- const { as: Component = "input", name, disabled = false, required, control } = props, rest = __rest(props, ["as", "name", "disabled", "required", "control"]);
18
+ const { as: Component = "input", name, disabled = false, withState, required, control } = props, rest = __rest(props, ["as", "name", "disabled", "withState", "required", "control"]);
22
19
  const fullName = useFormGroupName(name);
23
- const C = control ? Controller : ControllerWithContext;
24
- return (_jsx(C, { control: control, disabled: disabled, name: fullName, rules: {
20
+ const ControllerComponent = control
21
+ ? Controller
22
+ : ControllerWithContext;
23
+ return (_jsx(ControllerComponent, { control: control, disabled: disabled, name: fullName, rules: {
25
24
  required
26
25
  }, render: ({ field, fieldState }) => {
27
- return (_jsx(FormControlContext, { value: fieldState, children: _jsx(Component, Object.assign({}, rest, field)) }));
26
+ return (_jsx(FormControlContext, { value: fieldState, children: _jsx(Component, Object.assign({}, rest, withState ? fieldState : {}, field)) }));
28
27
  } }));
29
28
  };
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./blocks";
2
2
  export * from "./contexts";
3
3
  export * from "./hooks";
4
+ export * from "./types";
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./blocks";
2
2
  export * from "./contexts";
3
3
  export * from "./hooks";
4
+ export * from "./types";
@@ -0,0 +1,2 @@
1
+ import { ControllerRenderProps, ControllerFieldState } from "react-hook-form";
2
+ export type FormFieldProps<P = unknown> = P & Partial<ControllerRenderProps & ControllerFieldState>;
@@ -0,0 +1,2 @@
1
+ export * from "./FormFieldProps";
2
+ export * from "./PolymorphicComponentProps";
@@ -0,0 +1,2 @@
1
+ export * from "./FormFieldProps";
2
+ export * from "./PolymorphicComponentProps";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-compose-form",
3
- "version": "0.0.6-beta.0",
3
+ "version": "0.0.6-beta.2",
4
4
  "description": "Composable form components built on top of React Hook Form",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- export declare const useFormRegistry: () => void;
@@ -1,6 +0,0 @@
1
- import { useCallback } from "react";
2
- const formMap = new Map();
3
- export const useFormRegistry = () => {
4
- const subscribe = useCallback(() => {
5
- }, []);
6
- };
@@ -1,4 +0,0 @@
1
- import { FormState } from "react-hook-form";
2
- export type FormControl = {
3
- formState: FormState<any>;
4
- };
File without changes