react-compose-form 0.0.4 → 0.0.5-beta.0

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/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # react-compose-form
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/react-compose-form.svg)](https://www.npmjs.com/package/react-compose-form)
4
- [![Publish](https://github.com/kearisp/react-compose-form/actions/workflows/publish-latest.yml/badge.svg?event=release)](https://github.com/kearisp/react-compose-form/actions/workflows/publish-latest.yml)
4
+ [![Beta](https://github.com/kearisp/react-compose-form/actions/workflows/publish-beta.yml/badge.svg?branch=v0.0.5&event=pull_request)](https://github.com/kearisp/react-compose-form/actions/workflows/publish-beta.yml)
5
5
  [![License](https://img.shields.io/npm/l/react-compose-form)](https://github.com/kearisp/react-compose-form/blob/master/LICENSE)
6
6
 
7
7
  [![npm total downloads](https://img.shields.io/npm/dt/react-compose-form.svg)](https://www.npmjs.com/package/react-compose-form)
8
8
  [![bundle size](https://img.shields.io/bundlephobia/minzip/react-compose-form)](https://bundlephobia.com/package/react-compose-form)
9
- ![Coverage](https://gist.githubusercontent.com/kearisp/f17f46c6332ea3bb043f27b0bddefa9f/raw/coverage-react-compose-form-latest.svg)
9
+ ![Coverage](https://gist.githubusercontent.com/kearisp/f17f46c6332ea3bb043f27b0bddefa9f/raw/coverage-react-compose-form-beta.svg)
10
10
 
11
11
  ```shell
12
12
  npm i react-hook-form react-compose-form
@@ -1,10 +1,11 @@
1
1
  import { ComponentType } from "react";
2
- import { ControllerRenderProps, Message, ValidationRule, ControllerFieldState } from "react-hook-form";
2
+ import { Control, ControllerRenderProps, Message, ValidationRule, ControllerFieldState } from "react-hook-form";
3
3
  export type FormFieldProps<P = unknown> = P & Partial<ControllerRenderProps & ControllerFieldState>;
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
8
  required?: Message | ValidationRule<boolean>;
9
+ control?: Control;
9
10
  };
10
11
  export declare const FormControl: <P = unknown>(props: FormControlProps<P>) => import("react/jsx-runtime").JSX.Element;
@@ -13,11 +13,15 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { useFormContext, Controller } from "react-hook-form";
14
14
  import { FormControlContext } from "../contexts";
15
15
  import { useFormGroupName } from "../hooks";
16
- export const FormControl = (props) => {
17
- const { as: Component = "input", name, disabled = false, required } = props, rest = __rest(props, ["as", "name", "disabled", "required"]);
16
+ const ControllerWithContext = (props) => {
18
17
  const { control } = useFormContext();
18
+ return (_jsx(Controller, Object.assign({}, props, { control: control })));
19
+ };
20
+ export const FormControl = (props) => {
21
+ const { as: Component = "input", name, disabled = false, required, control } = props, rest = __rest(props, ["as", "name", "disabled", "required", "control"]);
19
22
  const fullName = useFormGroupName(name);
20
- return (_jsx(Controller, { control: control, disabled: disabled, name: fullName, rules: {
23
+ const C = control ? Controller : ControllerWithContext;
24
+ return (_jsx(C, { control: control, disabled: disabled, name: fullName, rules: {
21
25
  required
22
26
  }, render: ({ field, fieldState }) => {
23
27
  return (_jsx(FormControlContext, { value: fieldState, children: _jsx(Component, Object.assign({}, rest, field)) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-compose-form",
3
- "version": "0.0.4",
3
+ "version": "0.0.5-beta.0",
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",