@cutting/react-hook-form-components 0.4.5 → 0.4.6

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,17 +1,13 @@
1
- import type { ComponentProps } from 'react';
1
+ import type { FunctionComponent, ReactNode } from 'react';
2
2
  import { FormInput, FormTextArea } from '@cutting/component-library';
3
- import type { UseFormRegister, UseFormReturn } from 'react-hook-form';
4
- declare module 'react' {
5
- function forwardRef<T, P = Record<string, unknown>>(render: (props: P, ref: React.Ref<T>) => React.ReactElement | null): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
6
- }
7
- type Controls = typeof FormInput | typeof FormTextArea;
8
- export type FormProps<C extends Controls, E> = ComponentProps<C> & {
3
+ import type { FieldValues, UseFormRegister, UseFormReturn } from 'react-hook-form';
4
+ import type { FormElementFromComponent, ComponentProps } from '@cutting/component-library';
5
+ export type FormProps<C extends FunctionComponent<any>> = ComponentProps<C> & {
9
6
  required?: boolean;
10
7
  className?: string;
11
- errors?: E;
12
- } & ReturnType<UseFormRegister<any>> & Partial<Pick<UseFormReturn<any>, 'setValue'>>;
13
- export declare function createFormComponent(Component: Controls): <F extends HTMLElement>(props: FormProps<Controls, any> & import("react").RefAttributes<F>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
14
- export declare const Input: <F extends HTMLElement>(props: FormProps<Controls, any> & import("react").RefAttributes<F>) => React.ReactElement | null;
15
- export declare const TextArea: <F extends HTMLElement>(props: FormProps<Controls, any> & import("react").RefAttributes<F>) => React.ReactElement | null;
16
- export {};
8
+ errors?: unknown;
9
+ } & ReturnType<UseFormRegister<FieldValues>> & Partial<Pick<UseFormReturn<FieldValues>, 'setValue'>>;
10
+ export declare function createFormComponent<C extends FunctionComponent<any>>(Component: C): import("react").ForwardRefExoticComponent<import("react").PropsWithoutRef<ComponentProps<C>> & import("react").RefAttributes<FormElementFromComponent<C>>>;
11
+ export declare const Input: (props: FormProps<typeof FormInput>) => ReactNode;
12
+ export declare const TextArea: (props: FormProps<typeof FormTextArea>) => ReactNode;
17
13
  //# sourceMappingURL=FormComponents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormComponents.d.ts","sourceRoot":"","sources":["../../../../src/components/FormComponents/FormComponents.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAO,MAAM,OAAO,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,QAAQ,OAAO,CAAC;IACrB,SAAS,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChD,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,GAAG,IAAI,GACjE,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;CACrE;AAED,KAAK,QAAQ,GAAG,OAAO,SAAS,GAAG,OAAO,YAAY,CAAC;AAEvD,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,CAAC,CAAC;CAGZ,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,GAElC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;AAGhD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,QAAQ,gMAmBtD;AAED,eAAO,MAAM,KAAK,iGArC0B,kBAAkB,GAAG,IAqCd,CAAC;AACpD,eAAO,MAAM,QAAQ,iGAtCuB,kBAAkB,GAAG,IAsCR,CAAC"}
1
+ {"version":3,"file":"FormComponents.d.ts","sourceRoot":"","sources":["../../../../src/components/FormComponents/FormComponents.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAO,MAAM,OAAO,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE3F,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,iBAAiB,CAAC,GAAG,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG;IAC5E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,UAAU,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,GAC1C,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;AAGxD,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,iBAAiB,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,8JAOjF;AAKD,eAAO,MAAM,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,SAAS,CAAC,KAAK,SAA0C,CAAC;AACvG,eAAO,MAAM,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,YAAY,CAAC,KAAK,SAA6C,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{jsx as n}from"react/jsx-runtime";import{forwardRef as r}from"react";import{FormInput as e,FormTextArea as o}from"@cutting/component-library";function t(e){return r((function({onChange:r,onBlur:o,name:t,label:a,className:m,...c},i){return n(e,{innerRef:i,className:m,label:a,name:t,onChange:r,onBlur:o,...c})}))}const a=t(e),m=t(o);export{a as Input,m as TextArea,t as createFormComponent};
1
+ import{jsx as r}from"react/jsx-runtime";import{forwardRef as t}from"react";import{FormInput as n,FormTextArea as o}from"@cutting/component-library";function e(n){return t((function(t,o){return r(n,{innerRef:o,...t})}))}const i=e(n),m=e(o);export{i as Input,m as TextArea,e as createFormComponent};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/components/FormComponents/FormComponents.tsx"],"sourcesContent":["import type { ComponentProps, Ref } from 'react';\nimport { forwardRef } from 'react';\nimport { FormInput, FormTextArea } from '@cutting/component-library';\nimport type { UseFormRegister, UseFormReturn } from 'react-hook-form';\n\ndeclare module 'react' {\n function forwardRef<T, P = Record<string, unknown>>(\n render: (props: P, ref: React.Ref<T>) => React.ReactElement | null,\n ): (props: P & React.RefAttributes<T>) => React.ReactElement | null;\n}\n\ntype Controls = typeof FormInput | typeof FormTextArea;\n\nexport type FormProps<C extends Controls, E> = ComponentProps<C> & {\n required?: boolean;\n className?: string;\n errors?: E;\n // TODO: remove any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & ReturnType<UseFormRegister<any>> &\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Partial<Pick<UseFormReturn<any>, 'setValue'>>;\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function createFormComponent(Component: Controls) {\n return forwardRef(function ReactHookFormComponent<F extends HTMLElement>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n { onChange, onBlur, name, label, className, ...props }: FormProps<typeof Component, any>,\n ref: Ref<F>,\n ): JSX.Element {\n return (\n <Component\n innerRef={ref}\n className={className}\n label={label}\n name={name}\n onChange={onChange}\n onBlur={onBlur}\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n {...(props as any)}\n />\n );\n });\n}\n\nexport const Input = createFormComponent(FormInput);\nexport const TextArea = createFormComponent(FormTextArea);\n"],"names":["createFormComponent","Component","forwardRef","onChange","onBlur","name","label","className","props","ref","_jsx","innerRef","Input","FormInput","TextArea","FormTextArea"],"mappings":"oJAwBM,SAAUA,EAAoBC,GAClC,OAAOC,GAAW,UAEhBC,SAAEA,EAAQC,OAAEA,EAAMC,KAAEA,EAAIC,MAAEA,EAAKC,UAAEA,KAAcC,GAC/CC,GAEA,OACEC,EAACT,EAAS,CACRU,SAAUF,EACVF,UAAWA,EACXD,MAAOA,EACPD,KAAMA,EACNF,SAAUA,EACVC,OAAQA,KAEHI,GAGX,GACF,OAEaI,EAAQZ,EAAoBa,GAC5BC,EAAWd,EAAoBe"}
1
+ {"version":3,"file":"index.js","sources":["../../src/components/FormComponents/FormComponents.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { FunctionComponent, ReactNode, Ref } from 'react';\nimport { forwardRef } from 'react';\nimport { FormInput, FormTextArea } from '@cutting/component-library';\nimport type { FieldValues, UseFormRegister, UseFormReturn } from 'react-hook-form';\nimport type { FormElementFromComponent, ComponentProps } from '@cutting/component-library';\n\nexport type FormProps<C extends FunctionComponent<any>> = ComponentProps<C> & {\n required?: boolean;\n className?: string;\n errors?: unknown;\n} & ReturnType<UseFormRegister<FieldValues>> &\n Partial<Pick<UseFormReturn<FieldValues>, 'setValue'>>;\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function createFormComponent<C extends FunctionComponent<any>>(Component: C) {\n return forwardRef<FormElementFromComponent<typeof Component>, ComponentProps<C>>(function ReactHookFormComponent(\n props: FormProps<typeof Component>,\n ref: Ref<FormElementFromComponent<typeof Component>>,\n ) {\n return <Component innerRef={ref} {...(props as any)} />;\n });\n}\n\n// TODO: remove annotations. Currently weird type error\n// The inferred type of 'Input' cannot be named without a reference to '@cutting/component-library/node_modules/@types/react'.\n// This is likely not portable. A type annotation is necessary.\nexport const Input: (props: FormProps<typeof FormInput>) => ReactNode = createFormComponent(FormInput);\nexport const TextArea: (props: FormProps<typeof FormTextArea>) => ReactNode = createFormComponent(FormTextArea);\n"],"names":["createFormComponent","Component","forwardRef","props","ref","_jsx","innerRef","Input","FormInput","TextArea","FormTextArea"],"mappings":"oJAeM,SAAUA,EAAsDC,GACpE,OAAOC,GAA0E,SAC/EC,EACAC,GAEA,OAAOC,EAACJ,EAAU,CAAAK,SAAUF,KAAUD,GACxC,GACF,OAKaI,EAA2DP,EAAoBQ,GAC/EC,EAAiET,EAAoBU"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cutting/react-hook-form-components",
3
3
  "description": "components for react-hook-form.",
4
- "version": "0.4.5",
4
+ "version": "0.4.6",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
@@ -16,18 +16,20 @@
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "assert-ts": "^0.3.4",
19
- "react-hook-form": "7.44.1",
20
- "@cutting/component-library": "5.39.2",
19
+ "react-hook-form": "7.44.3",
20
+ "@cutting/component-library": "5.40.0",
21
21
  "@cutting/util": "4.58.2"
22
22
  },
23
23
  "devDependencies": {
24
- "@types/react": "18.2.7",
25
- "@vanilla-extract/css": "^1.11.0",
26
- "eslint": "8.41.0",
24
+ "@types/react": "18.2.12",
25
+ "@types/react-dom": "18.2.5",
26
+ "@vanilla-extract/css": "^1.11.1",
27
+ "eslint": "8.43.0",
27
28
  "react": "18.2.0",
28
29
  "react-dom": "18.2.0",
29
30
  "react-syntax-highlighter": "15.5.0",
30
- "typescript": "5.0.4",
31
+ "@testing-library/react": "14.0.0",
32
+ "typescript": "5.1.3",
31
33
  "@cutting/devtools": "4.63.1",
32
34
  "@cutting/eslint-config": "4.44.1",
33
35
  "@cutting/tsconfig": "4.40.1",
@@ -62,7 +64,8 @@
62
64
  },
63
65
  "scripts": {
64
66
  "start": "echo no demo",
65
- "test": "echo no tests yet",
67
+ "test": "NODE_ENV=test vitest",
68
+ "test:ci": "CI=true pnpm test",
66
69
  "lint": "eslint ./src/**/*.{ts,tsx} --fix",
67
70
  "lint:fix": "pnpm lint --fix",
68
71
  "build": "NODE_ENV=production devtools rollup"