@alextheman/components 7.0.1 → 7.0.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.
|
@@ -92,7 +92,7 @@ interface QueryBoundaryErrorProps {
|
|
|
92
92
|
declare function QueryBoundaryError({
|
|
93
93
|
children,
|
|
94
94
|
logError
|
|
95
|
-
}: QueryBoundaryErrorProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> |
|
|
95
|
+
}: QueryBoundaryErrorProps): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
|
|
96
96
|
//#endregion
|
|
97
97
|
//#region src/QueryBoundary/QueryBoundaryNullable.d.ts
|
|
98
98
|
interface QueryBoundaryNullablePropsWithUndefinedOrNull {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createFormHook as createFormHook$1 } from "@tanstack/react-form";
|
|
2
|
+
import { ButtonProps } from "@mui/material/Button";
|
|
3
|
+
import { TextFieldProps } from "@mui/material/TextField";
|
|
4
|
+
import { ComponentType } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/form/createFormHook.d.ts
|
|
7
|
+
interface AlexFieldComponents {
|
|
8
|
+
TextField: typeof TextField;
|
|
9
|
+
}
|
|
10
|
+
interface AlexFormComponents {
|
|
11
|
+
SubmitButton: typeof SubmitButton;
|
|
12
|
+
}
|
|
13
|
+
/** Create the hooks for your app form with `@tanstack/react-form` using our default configuration. */
|
|
14
|
+
declare function createFormHook<FieldComponents extends Record<string, ComponentType<any>> = Record<string, never>, FormComponents extends Record<string, ComponentType<any>> = Record<string, never>>(options?: Partial<Omit<Parameters<typeof createFormHook$1>[0], "formComponents" | "fieldComponents"> & {
|
|
15
|
+
fieldComponents?: FieldComponents;
|
|
16
|
+
formComponents?: FormComponents;
|
|
17
|
+
}>): ReturnType<typeof createFormHook$1<AlexFieldComponents & FieldComponents, AlexFormComponents & FormComponents>>;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/form/SubmitButton.d.ts
|
|
20
|
+
interface SubmitButtonProps extends Omit<ButtonProps, "type"> {
|
|
21
|
+
/** An option to disable the button on submit if the form is not dirty. */
|
|
22
|
+
disableClean?: boolean;
|
|
23
|
+
/** The label for the button. */
|
|
24
|
+
label?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A Submit Button for use with TanStack Form's app form pattern. Must be used in a `<form.AppForm />` context.
|
|
28
|
+
*
|
|
29
|
+
* This should be initialised in your app form in the following way:
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const { useAppForm } = createFormHook({
|
|
33
|
+
* fieldContext,
|
|
34
|
+
* formContext,
|
|
35
|
+
* formComponents: {
|
|
36
|
+
* SubmitButton,
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
* And then used as such:
|
|
41
|
+
*
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <form.AppField>
|
|
44
|
+
* ...
|
|
45
|
+
* </form.AppField>
|
|
46
|
+
* <form.AppForm>
|
|
47
|
+
* <form.SubmitButton />
|
|
48
|
+
* </form.AppForm>
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare function SubmitButton({
|
|
52
|
+
disableClean,
|
|
53
|
+
label,
|
|
54
|
+
...buttonProps
|
|
55
|
+
}: SubmitButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/form/TextField.d.ts
|
|
58
|
+
/**
|
|
59
|
+
* A text field component for use with TanStack Form's app form pattern. Must be used in a `<form.AppField />` context.
|
|
60
|
+
*
|
|
61
|
+
* This should be initialised in your app form in the following way:
|
|
62
|
+
*
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const { useAppForm } = createFormHook({
|
|
65
|
+
* fieldContext,
|
|
66
|
+
* formContext,
|
|
67
|
+
* fieldComponents: {
|
|
68
|
+
* TextField,
|
|
69
|
+
* },
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
* And then used as such:
|
|
73
|
+
*
|
|
74
|
+
* ```tsx
|
|
75
|
+
* <form.AppField name="firstName">
|
|
76
|
+
* {(field) => {
|
|
77
|
+
* return <field.TextField />
|
|
78
|
+
* }}
|
|
79
|
+
* </form.AppField>
|
|
80
|
+
* <form.AppForm>
|
|
81
|
+
* <form.SubmitButton />
|
|
82
|
+
* </form.AppForm>
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function TextField({
|
|
86
|
+
label,
|
|
87
|
+
type,
|
|
88
|
+
...props
|
|
89
|
+
}: TextFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/form/formHooks.d.ts
|
|
92
|
+
declare const fieldContext: import("react").Context<import("@tanstack/react-form").AnyFieldApi>, formContext: import("react").Context<import("@tanstack/react-form").AnyFormApi>, useFieldContext: <TData>() => import("@tanstack/react-form").FieldApi<any, string, TData, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>, useFormContext: () => import("@tanstack/react-form").ReactFormExtendedApi<Record<string, never>, any, any, any, any, any, any, any, any, any, any, any>;
|
|
93
|
+
//#endregion
|
|
94
|
+
export { SubmitButton, type SubmitButtonProps, TextField, createFormHook, fieldContext, formContext, useFieldContext, useFormContext };
|
|
95
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{omitProperties as e}from"@alextheman/utility";import{createFormHook as t,createFormHookContexts as n}from"@tanstack/react-form";import r from"@mui/material/Button";import{jsx as i}from"react/jsx-runtime";import a from"@mui/material/TextField";const{fieldContext:o,formContext:s,useFieldContext:c,useFormContext:l}=n();function u(n){return t({fieldContext:o,formContext:s,fieldComponents:{TextField:f,...n?.fieldComponents},formComponents:{SubmitButton:d,...n?.formComponents},...e(n??{},[`formComponents`,`fieldComponents`])})}function d({disableClean:e,label:t=`Submit`,...n}){let a=l();return i(r,{color:`primary`,disabled:n.disabled||e&&!a.state.isDirty,loading:a.state.isSubmitting,type:`submit`,variant:`contained`,...n,children:t})}function f({label:e,type:t,...n}){let r=c();return i(a,{...n,label:e,error:r.state.meta.errors.length!==0,type:t??`text`,value:r.state.value,onChange:e=>r.handleChange(e.target.value),onBlur:r.handleBlur,placeholder:typeof e==`string`?e:r.name,helperText:r.state.meta.errors[0]??``})}export{d as SubmitButton,f as TextField,u as createFormHook,o as fieldContext,s as formContext,c as useFieldContext,l as useFormContext};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["createTanstackFormHook"],"sources":["../../src/form/formHooks.ts","../../src/form/createFormHook.ts","../../src/form/SubmitButton.tsx","../../src/form/TextField.tsx"],"sourcesContent":["import { createFormHookContexts } from \"@tanstack/react-form\";\n\nexport const { fieldContext, formContext, useFieldContext, useFormContext } =\n createFormHookContexts();\n","import type { ComponentType } from \"react\";\n\nimport { omitProperties } from \"@alextheman/utility\";\nimport { createFormHook as createTanstackFormHook } from \"@tanstack/react-form\";\n\nimport { SubmitButton, TextField } from \"src/form\";\nimport { fieldContext, formContext } from \"src/form/formHooks\";\n\nexport interface AlexFieldComponents {\n TextField: typeof TextField;\n}\n\nexport interface AlexFormComponents {\n SubmitButton: typeof SubmitButton;\n}\n\n/** Create the hooks for your app form with `@tanstack/react-form` using our default configuration. */\nfunction createFormHook<\n FieldComponents extends Record<string, ComponentType<any>> = Record<string, never>,\n FormComponents extends Record<string, ComponentType<any>> = Record<string, never>,\n>(\n options?: Partial<\n Omit<Parameters<typeof createTanstackFormHook>[0], \"formComponents\" | \"fieldComponents\"> & {\n fieldComponents?: FieldComponents;\n formComponents?: FormComponents;\n }\n >,\n): ReturnType<\n typeof createTanstackFormHook<\n AlexFieldComponents & FieldComponents,\n AlexFormComponents & FormComponents\n >\n> {\n return createTanstackFormHook({\n fieldContext,\n formContext,\n fieldComponents: {\n TextField,\n ...options?.fieldComponents,\n } as AlexFieldComponents & FieldComponents,\n formComponents: {\n SubmitButton,\n ...options?.formComponents,\n } as AlexFormComponents & FormComponents,\n ...omitProperties(options ?? {}, [\"formComponents\", \"fieldComponents\"]),\n });\n}\n\nexport default createFormHook;\n","import type { ButtonProps } from \"@mui/material/Button\";\n\nimport Button from \"@mui/material/Button\";\n\nimport { useFormContext } from \"src/form/formHooks\";\n\nexport interface SubmitButtonProps extends Omit<ButtonProps, \"type\"> {\n /** An option to disable the button on submit if the form is not dirty. */\n disableClean?: boolean;\n /** The label for the button. */\n label?: string;\n}\n\n/**\n * A Submit Button for use with TanStack Form's app form pattern. Must be used in a `<form.AppForm />` context.\n *\n * This should be initialised in your app form in the following way:\n *\n * ```typescript\n * const { useAppForm } = createFormHook({\n * fieldContext,\n * formContext,\n * formComponents: {\n * SubmitButton,\n * },\n * });\n * ```\n * And then used as such:\n *\n * ```tsx\n * <form.AppField>\n * ...\n * </form.AppField>\n * <form.AppForm>\n * <form.SubmitButton />\n * </form.AppForm>\n * ```\n */\nfunction SubmitButton({ disableClean, label = \"Submit\", ...buttonProps }: SubmitButtonProps) {\n const form = useFormContext();\n\n return (\n <Button\n color=\"primary\"\n disabled={buttonProps.disabled || (disableClean && !form.state.isDirty)}\n loading={form.state.isSubmitting}\n type=\"submit\"\n variant=\"contained\"\n {...buttonProps}\n >\n {label}\n </Button>\n );\n}\n\nexport default SubmitButton;\n","import type { TextFieldProps as MUITextFieldProps } from \"@mui/material/TextField\";\n\nimport MUITextField from \"@mui/material/TextField\";\n\nimport { useFieldContext } from \"src/form/formHooks\";\n\n/**\n * A text field component for use with TanStack Form's app form pattern. Must be used in a `<form.AppField />` context.\n *\n * This should be initialised in your app form in the following way:\n *\n * ```typescript\n * const { useAppForm } = createFormHook({\n * fieldContext,\n * formContext,\n * fieldComponents: {\n * TextField,\n * },\n * });\n * ```\n * And then used as such:\n *\n * ```tsx\n * <form.AppField name=\"firstName\">\n * {(field) => {\n * return <field.TextField />\n * }}\n * </form.AppField>\n * <form.AppForm>\n * <form.SubmitButton />\n * </form.AppForm>\n * ```\n */\nfunction TextField({ label, type, ...props }: MUITextFieldProps) {\n const field = useFieldContext();\n\n return (\n <MUITextField\n {...props}\n label={label}\n error={field.state.meta.errors.length !== 0}\n type={type ?? \"text\"}\n value={field.state.value}\n onChange={(event) => {\n return field.handleChange(event.target.value);\n }}\n onBlur={field.handleBlur}\n placeholder={typeof label === \"string\" ? label : field.name}\n helperText={field.state.meta.errors[0] ?? \"\"}\n />\n );\n}\n\nexport default TextField;\n"],"mappings":"0PAEA,KAAa,CAAE,eAAc,cAAa,kBAAiB,kBACzD,EAAuB,ECczB,SAAS,EAIP,EAWA,CACA,OAAOA,EAAuB,CAC5B,eACA,cACA,gBAAiB,CACf,YACA,GAAG,GAAS,eACd,EACA,eAAgB,CACd,eACA,GAAG,GAAS,cACd,EACA,GAAG,EAAe,GAAW,CAAC,EAAG,CAAC,iBAAkB,iBAAiB,CAAC,CACxE,CAAC,CACH,CCRA,SAAS,EAAa,CAAE,eAAc,QAAQ,SAAU,GAAG,GAAkC,CAC3F,IAAM,EAAO,EAAe,EAE5B,OACE,EAAC,EAAD,CACE,MAAM,UACN,SAAU,EAAY,UAAa,GAAgB,CAAC,EAAK,MAAM,QAC/D,QAAS,EAAK,MAAM,aACpB,KAAK,SACL,QAAQ,YACR,GAAI,WAEH,CACK,CAAA,CAEZ,CCpBA,SAAS,EAAU,CAAE,QAAO,OAAM,GAAG,GAA4B,CAC/D,IAAM,EAAQ,EAAgB,EAE9B,OACE,EAAC,EAAD,CACE,GAAI,EACG,QACP,MAAO,EAAM,MAAM,KAAK,OAAO,SAAW,EAC1C,KAAM,GAAQ,OACd,MAAO,EAAM,MAAM,MACnB,SAAW,GACF,EAAM,aAAa,EAAM,OAAO,KAAK,EAE9C,OAAQ,EAAM,WACd,YAAa,OAAO,GAAU,SAAW,EAAQ,EAAM,KACvD,WAAY,EAAM,MAAM,KAAK,OAAO,IAAM,EAC3C,CAAA,CAEL"}
|