@behivetech/forms.form-provider 0.0.0-stage → 0.1.5

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,3 +1,53 @@
1
- # Temporary Holding Version
1
+ # form-provider
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The single place `react-hook-form` is imported directly in this repo. Everything else should import form state/control from here instead of `react-hook-form` — that keeps the underlying library swappable from one spot later.
4
+
5
+ Re-exports: `FormProvider` (thin wrapper around RHF's own `FormProvider`), `Form` (convenience `<form>` wired to `handleSubmit`, with `FormProvider` already applied), `useForm`, `useFormContext`, `useController`, `useFormState`, `useWatch`, `Controller`, plus the common RHF types (`UseFormReturn`, `FieldValues`, `SubmitHandler`, `Control`, `FieldErrors`, ...).
6
+
7
+ ## Usage
8
+
9
+ The common case — a form with a real submit action — use `Form`:
10
+
11
+ ```jsx
12
+ import { Form, useForm } from "@behivetech/forms.form-provider";
13
+ import { FormField } from "@behivetech/forms.form-field";
14
+ import { TextField } from "@behivetech/atoms.text-field";
15
+ import { Button } from "@behivetech/atoms.button";
16
+
17
+ function MyForm() {
18
+ const methods = useForm({ defaultValues: { email: "" } });
19
+ const { register } = methods;
20
+
21
+ return (
22
+ <Form methods={methods} onSubmit={(values) => console.log(values)}>
23
+ <FormField label="Email" htmlFor="email">
24
+ <TextField id="email" {...register("email")} />
25
+ </FormField>
26
+ <Button type="submit">Save</Button>
27
+ </Form>
28
+ );
29
+ }
30
+ ```
31
+
32
+ If you need the raw `<form>` element for something `Form` doesn't cover, use `FormProvider` + `handleSubmit` directly:
33
+
34
+ ```jsx
35
+ import { FormProvider, useForm } from "@behivetech/forms.form-provider";
36
+ import { TextField } from "@behivetech/atoms.text-field";
37
+ import { Button } from "@behivetech/atoms.button";
38
+
39
+ function Example() {
40
+ const methods = useForm({ defaultValues: { name: "" } });
41
+ const onSubmit = (values) => alert(JSON.stringify(values));
42
+ return (
43
+ <FormProvider methods={methods}>
44
+ <form onSubmit={methods.handleSubmit(onSubmit)}>
45
+ <TextField {...methods.register("name")} placeholder="Name" />
46
+ <Button type="submit">Save</Button>
47
+ </form>
48
+ </FormProvider>
49
+ );
50
+ }
51
+ ```
52
+
53
+ **Not every input needs this.** `TextField`, `Checkbox`, etc. all work standalone with plain `useState` for simple one-off cases, and UI with no real submit moment — live/instant field-by-field editing, for example — should just use the bare atoms + `FormField` for layout, not `Form`/`useForm`. Reach for this package when you actually need multi-field form state, validation, or a real submit action.
package/dist/index.cjs ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Controller: () => import_react_hook_form2.Controller,
24
+ Form: () => Form,
25
+ FormProvider: () => FormProvider,
26
+ useController: () => import_react_hook_form2.useController,
27
+ useForm: () => import_react_hook_form2.useForm,
28
+ useFormContext: () => import_react_hook_form2.useFormContext,
29
+ useFormState: () => import_react_hook_form2.useFormState,
30
+ useWatch: () => import_react_hook_form2.useWatch
31
+ });
32
+ module.exports = __toCommonJS(index_exports);
33
+
34
+ // form-provider.tsx
35
+ var import_react_hook_form = require("react-hook-form");
36
+ var import_jsx_runtime = require("react/jsx-runtime");
37
+ var FormProvider = ({
38
+ methods,
39
+ children
40
+ }) => {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_hook_form.FormProvider, { ...methods, children });
42
+ };
43
+
44
+ // form.tsx
45
+ var import_jsx_runtime2 = require("react/jsx-runtime");
46
+ var Form = ({
47
+ methods,
48
+ onSubmit,
49
+ children,
50
+ ...rest
51
+ }) => {
52
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FormProvider, { methods, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("form", { ...rest, onSubmit: methods.handleSubmit(onSubmit), children }) });
53
+ };
54
+
55
+ // index.ts
56
+ var import_react_hook_form2 = require("react-hook-form");
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ Controller,
60
+ Form,
61
+ FormProvider,
62
+ useController,
63
+ useForm,
64
+ useFormContext,
65
+ useFormState,
66
+ useWatch
67
+ });
@@ -0,0 +1,38 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, FormHTMLAttributes } from 'react';
3
+ import { FieldValues, UseFormReturn, SubmitHandler } from 'react-hook-form';
4
+ export { Control, Controller, ControllerFieldState, ControllerProps, ControllerRenderProps, FieldErrors, FieldPath, FieldValues, RegisterOptions, SubmitHandler, UseFormProps, UseFormReturn, useController, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
5
+
6
+ interface FormProviderProps<TFieldValues extends FieldValues = FieldValues> {
7
+ /** The return value of `useForm()` (re-exported from this package) */
8
+ methods: UseFormReturn<TFieldValues>;
9
+ /** Descendants that will consume the form context via `useFormContext()` */
10
+ children: ReactNode;
11
+ }
12
+ /**
13
+ * Thin wrapper around react-hook-form's `FormProvider`. Import this (and
14
+ * `useForm`, `Controller`, etc.) from this package instead of importing
15
+ * `react-hook-form` directly anywhere else — this is the one place that
16
+ * knows about the underlying form library, so it can be swapped later
17
+ * without touching every consumer.
18
+ */
19
+ declare const FormProvider: <TFieldValues extends FieldValues = FieldValues>({ methods, children, }: FormProviderProps<TFieldValues>) => react.JSX.Element;
20
+
21
+ interface FormProps<TFieldValues extends FieldValues = FieldValues> extends Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit"> {
22
+ /** The return value of `useForm()` */
23
+ methods: UseFormReturn<TFieldValues>;
24
+ /** Called with the validated values when the form is submitted */
25
+ onSubmit: SubmitHandler<TFieldValues>;
26
+ /** Form content, typically FormField-wrapped controls */
27
+ children: ReactNode;
28
+ }
29
+ /**
30
+ * Convenience wrapper for the common case: a `<form>` whose submit is wired
31
+ * to react-hook-form's `handleSubmit`, with `FormProvider` already applied
32
+ * so descendants can use `useFormContext()`. For editing UIs with no submit
33
+ * moment (live/instant field-by-field updates), use the bare atoms +
34
+ * `FormField` instead — this component assumes a real submit action exists.
35
+ */
36
+ declare const Form: <TFieldValues extends FieldValues = FieldValues>({ methods, onSubmit, children, ...rest }: FormProps<TFieldValues>) => react.JSX.Element;
37
+
38
+ export { Form, type FormProps, FormProvider, type FormProviderProps };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ // form-provider.tsx
2
+ import {
3
+ FormProvider as RHFFormProvider
4
+ } from "react-hook-form";
5
+ import { jsx } from "react/jsx-runtime";
6
+ var FormProvider = ({
7
+ methods,
8
+ children
9
+ }) => {
10
+ return /* @__PURE__ */ jsx(RHFFormProvider, { ...methods, children });
11
+ };
12
+
13
+ // form.tsx
14
+ import { jsx as jsx2 } from "react/jsx-runtime";
15
+ var Form = ({
16
+ methods,
17
+ onSubmit,
18
+ children,
19
+ ...rest
20
+ }) => {
21
+ return /* @__PURE__ */ jsx2(FormProvider, { methods, children: /* @__PURE__ */ jsx2("form", { ...rest, onSubmit: methods.handleSubmit(onSubmit), children }) });
22
+ };
23
+
24
+ // index.ts
25
+ import {
26
+ useForm,
27
+ useFormContext,
28
+ useController,
29
+ useFormState,
30
+ useWatch,
31
+ Controller
32
+ } from "react-hook-form";
33
+ export {
34
+ Controller,
35
+ Form,
36
+ FormProvider,
37
+ useController,
38
+ useForm,
39
+ useFormContext,
40
+ useFormState,
41
+ useWatch
42
+ };
@@ -0,0 +1,39 @@
1
+ import { FormField } from "@behivetech/forms.form-field";
2
+ import { TextField } from "@behivetech/atoms.text-field";
3
+ import { Button } from "@behivetech/atoms.button";
4
+ import { Form, FormProvider, useForm } from "./index.js";
5
+
6
+ interface DemoValues {
7
+ email: string;
8
+ }
9
+
10
+ export const BasicFormProvider = () => {
11
+ const methods = useForm<DemoValues>({ defaultValues: { email: "" } });
12
+ const { register, handleSubmit } = methods;
13
+
14
+ return (
15
+ <FormProvider methods={methods}>
16
+ <form onSubmit={handleSubmit((values) => console.log(values))}>
17
+ <FormField label="Email" htmlFor="email">
18
+ <TextField id="email" {...register("email")} />
19
+ </FormField>
20
+ </form>
21
+ </FormProvider>
22
+ );
23
+ };
24
+
25
+ export const BasicForm = () => {
26
+ const methods = useForm<DemoValues>({ defaultValues: { email: "" } });
27
+ const { register } = methods;
28
+
29
+ return (
30
+ <Form methods={methods} onSubmit={(values) => console.log(values)}>
31
+ <FormField label="Email" htmlFor="email-form">
32
+ <TextField id="email-form" {...register("email")} />
33
+ </FormField>
34
+ <Button type="submit" variant="primary" size="sm">
35
+ Save
36
+ </Button>
37
+ </Form>
38
+ );
39
+ };
@@ -0,0 +1,29 @@
1
+ import { type ReactNode } from "react";
2
+ import {
3
+ FormProvider as RHFFormProvider,
4
+ type FieldValues,
5
+ type UseFormReturn,
6
+ } from "react-hook-form";
7
+
8
+ export interface FormProviderProps<
9
+ TFieldValues extends FieldValues = FieldValues,
10
+ > {
11
+ /** The return value of `useForm()` (re-exported from this package) */
12
+ methods: UseFormReturn<TFieldValues>;
13
+ /** Descendants that will consume the form context via `useFormContext()` */
14
+ children: ReactNode;
15
+ }
16
+
17
+ /**
18
+ * Thin wrapper around react-hook-form's `FormProvider`. Import this (and
19
+ * `useForm`, `Controller`, etc.) from this package instead of importing
20
+ * `react-hook-form` directly anywhere else — this is the one place that
21
+ * knows about the underlying form library, so it can be swapped later
22
+ * without touching every consumer.
23
+ */
24
+ export const FormProvider = <TFieldValues extends FieldValues = FieldValues>({
25
+ methods,
26
+ children,
27
+ }: FormProviderProps<TFieldValues>) => {
28
+ return <RHFFormProvider {...methods}>{children}</RHFFormProvider>;
29
+ };
package/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ export { FormProvider } from "./form-provider.js";
2
+ export type { FormProviderProps } from "./form-provider.js";
3
+
4
+ export { Form } from "./form.js";
5
+ export type { FormProps } from "./form.js";
6
+
7
+ export {
8
+ useForm,
9
+ useFormContext,
10
+ useController,
11
+ useFormState,
12
+ useWatch,
13
+ Controller,
14
+ } from "react-hook-form";
15
+ export type {
16
+ UseFormReturn,
17
+ UseFormProps,
18
+ FieldValues,
19
+ SubmitHandler,
20
+ Control,
21
+ ControllerProps,
22
+ ControllerRenderProps,
23
+ ControllerFieldState,
24
+ FieldPath,
25
+ RegisterOptions,
26
+ FieldErrors,
27
+ } from "react-hook-form";
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@behivetech/forms.form-provider",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.5",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "private": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ },
13
+ "./styles.css": "./dist/index.css"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "index.ts",
19
+ "form-provider.tsx",
20
+ "form-provider.module.scss",
21
+ "*.example.tsx",
22
+ "docs.json"
23
+ ],
24
+ "registry": {
25
+ "status": "stable",
26
+ "tags": []
27
+ },
28
+ "dependencies": {
29
+ "react-hook-form": "^7.83.0"
30
+ },
31
+ "peerDependencies": {
32
+ "react": "^19.2.7",
33
+ "react-dom": "^19.2.7"
34
+ },
35
+ "devDependencies": {
36
+ "@types/react": "19.2.17",
37
+ "@types/react-dom": "19.2.3",
38
+ "eslint": "^9.39.5",
39
+ "tsup": "^8.5.1",
40
+ "typescript": "^6.0.3",
41
+ "vitest": "^4.1.10",
42
+ "@behivetech/atoms.button": "0.4.3",
43
+ "@behivetech/atoms.text-field": "0.3.3",
44
+ "@behivetech/forms.form-field": "0.3.3",
45
+ "@bht-component-registry/env": "0.1.0"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/behivetech/bht-galaxy.git",
50
+ "directory": "registry/behivetech/forms/form-provider"
51
+ },
52
+ "publishConfig": {
53
+ "registry": "https://registry.npmjs.org",
54
+ "access": "public",
55
+ "provenance": true
56
+ },
57
+ "scripts": {
58
+ "build": "tsup && bht-registry-docgen",
59
+ "dev": "tsup --watch",
60
+ "lint": "eslint . --max-warnings 0",
61
+ "check-types": "tsc --noEmit",
62
+ "test": "vitest run"
63
+ }
6
64
  }