@mittwald/flow-react-components 0.2.0-alpha.155 → 0.2.0-alpha.157
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/CHANGELOG.md +12 -0
- package/dist/assets/doc-properties.json +5333 -5313
- package/dist/js/components/src/components/Overlay/Overlay.mjs +1 -1
- package/dist/js/components/src/components/Overlay/Overlay.mjs.map +1 -1
- package/dist/js/components/src/integrations/react-hook-form/components/AfterFormSubmitEffect/AfterFormSubmitEffect.mjs +32 -0
- package/dist/js/components/src/integrations/react-hook-form/components/AfterFormSubmitEffect/AfterFormSubmitEffect.mjs.map +1 -0
- package/dist/js/components/src/integrations/react-hook-form/components/Form/Form.mjs +13 -5
- package/dist/js/components/src/integrations/react-hook-form/components/Form/Form.mjs.map +1 -1
- package/dist/types/integrations/react-hook-form/components/AfterFormSubmitEffect/AfterFormSubmitEffect.d.ts +15 -0
- package/dist/types/integrations/react-hook-form/components/AfterFormSubmitEffect/AfterFormSubmitEffect.d.ts.map +1 -0
- package/dist/types/integrations/react-hook-form/components/Form/Form.d.ts.map +1 -1
- package/dist/types/integrations/react-hook-form/components/Form/stories/Form.stories.d.ts +7 -0
- package/dist/types/integrations/react-hook-form/components/Form/stories/Form.stories.d.ts.map +1 -0
- package/package.json +4 -4
- package/dist/js/components/src/integrations/react-hook-form/components/AutoFormResetEffect/AutoFormResetEffect.mjs +0 -31
- package/dist/js/components/src/integrations/react-hook-form/components/AutoFormResetEffect/AutoFormResetEffect.mjs.map +0 -1
- package/dist/types/integrations/react-hook-form/components/AutoFormResetEffect/AutoFormResetEffect.d.ts +0 -7
- package/dist/types/integrations/react-hook-form/components/AutoFormResetEffect/AutoFormResetEffect.d.ts.map +0 -1
|
@@ -32,7 +32,7 @@ const Overlay = (props) => {
|
|
|
32
32
|
ref,
|
|
33
33
|
isDismissable,
|
|
34
34
|
className: rootClassName,
|
|
35
|
-
children: /* @__PURE__ */ jsx(OverlayContextProvider, { type: "Modal", controller, children })
|
|
35
|
+
children: /* @__PURE__ */ jsx(OverlayContextProvider, { type: "Modal", controller, children: isOpen && children })
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Overlay.mjs","sources":["../../../../../../src/components/Overlay/Overlay.tsx"],"sourcesContent":["import type { FC, PropsWithChildren, Ref } from \"react\";\nimport React from \"react\";\nimport styles from \"./Overlay.module.scss\";\nimport clsx from \"clsx\";\nimport type { OverlayController } from \"@/lib/controller\";\nimport { useOverlayController } from \"@/lib/controller\";\nimport OverlayContextProvider from \"@/lib/controller/overlay/OverlayContextProvider\";\nimport type { PropsWithClassName } from \"@/lib/types/props\";\nimport OverlayContentView from \"@/views/OverlayContentView\";\n\nexport interface OverlayProps extends PropsWithChildren, PropsWithClassName {\n ref?: Ref<HTMLDivElement>;\n /** The controller to control the overlay state. */\n controller?: OverlayController;\n /** Whether the overlay can be closed by clicking outside of it. */\n isDismissable?: boolean;\n /** Whether the overlay is a modal or a light box. */\n overlayType?: \"Modal\" | \"LightBox\";\n}\n\nexport const Overlay: FC<OverlayProps> = (props) => {\n const {\n controller: controllerFromProps,\n children,\n isDismissable = true,\n className,\n overlayType = \"Modal\",\n ref,\n } = props;\n\n const controllerFromContext = useOverlayController(overlayType, {\n reuseControllerFromContext: true,\n });\n\n const controller = controllerFromProps ?? controllerFromContext;\n\n const isOpen = controller.useIsOpen();\n\n const rootClassName = clsx(styles.overlay, className);\n\n return (\n <OverlayContentView\n onOpenChange={(isOpen) => controller.setOpen(isOpen)}\n isOpen={isOpen}\n ref={ref}\n isDismissable={isDismissable}\n className={rootClassName}\n >\n <OverlayContextProvider type=\"Modal\" controller={controller}>\n {children}\n </OverlayContextProvider>\n </OverlayContentView>\n );\n};\n\nexport default Overlay;\n"],"names":["isOpen"],"mappings":";;;;;;;;;AAoBa,MAAA,OAAA,GAA4B,CAAC,KAAU,KAAA;AAClD,EAAM,MAAA;AAAA,IACJ,UAAY,EAAA,mBAAA;AAAA,IACZ,QAAA;AAAA,IACA,aAAgB,GAAA,IAAA;AAAA,IAChB,SAAA;AAAA,IACA,WAAc,GAAA,OAAA;AAAA,IACd;AAAA,GACE,GAAA,KAAA;AAEJ,EAAM,MAAA,qBAAA,GAAwB,qBAAqB,WAAa,EAAA;AAAA,IAC9D,0BAA4B,EAAA;AAAA,GAC7B,CAAA;AAED,EAAA,MAAM,aAAa,mBAAuB,IAAA,qBAAA;AAE1C,EAAM,MAAA,MAAA,GAAS,WAAW,SAAU,EAAA;AAEpC,EAAA,MAAM,aAAgB,GAAA,IAAA,CAAK,MAAO,CAAA,OAAA,EAAS,SAAS,CAAA;AAEpD,EACE,uBAAA,GAAA;AAAA,IAAC,kBAAA;AAAA,IAAA;AAAA,MACC,YAAc,EAAA,CAACA,OAAW,KAAA,UAAA,CAAW,QAAQA,OAAM,CAAA;AAAA,MACnD,MAAA;AAAA,MACA,GAAA;AAAA,MACA,aAAA;AAAA,MACA,SAAW,EAAA,aAAA;AAAA,MAEX,
|
|
1
|
+
{"version":3,"file":"Overlay.mjs","sources":["../../../../../../src/components/Overlay/Overlay.tsx"],"sourcesContent":["import type { FC, PropsWithChildren, Ref } from \"react\";\nimport React from \"react\";\nimport styles from \"./Overlay.module.scss\";\nimport clsx from \"clsx\";\nimport type { OverlayController } from \"@/lib/controller\";\nimport { useOverlayController } from \"@/lib/controller\";\nimport OverlayContextProvider from \"@/lib/controller/overlay/OverlayContextProvider\";\nimport type { PropsWithClassName } from \"@/lib/types/props\";\nimport OverlayContentView from \"@/views/OverlayContentView\";\n\nexport interface OverlayProps extends PropsWithChildren, PropsWithClassName {\n ref?: Ref<HTMLDivElement>;\n /** The controller to control the overlay state. */\n controller?: OverlayController;\n /** Whether the overlay can be closed by clicking outside of it. */\n isDismissable?: boolean;\n /** Whether the overlay is a modal or a light box. */\n overlayType?: \"Modal\" | \"LightBox\";\n}\n\nexport const Overlay: FC<OverlayProps> = (props) => {\n const {\n controller: controllerFromProps,\n children,\n isDismissable = true,\n className,\n overlayType = \"Modal\",\n ref,\n } = props;\n\n const controllerFromContext = useOverlayController(overlayType, {\n reuseControllerFromContext: true,\n });\n\n const controller = controllerFromProps ?? controllerFromContext;\n\n const isOpen = controller.useIsOpen();\n\n const rootClassName = clsx(styles.overlay, className);\n\n return (\n <OverlayContentView\n onOpenChange={(isOpen) => controller.setOpen(isOpen)}\n isOpen={isOpen}\n ref={ref}\n isDismissable={isDismissable}\n className={rootClassName}\n >\n <OverlayContextProvider type=\"Modal\" controller={controller}>\n {isOpen && children}\n </OverlayContextProvider>\n </OverlayContentView>\n );\n};\n\nexport default Overlay;\n"],"names":["isOpen"],"mappings":";;;;;;;;;AAoBa,MAAA,OAAA,GAA4B,CAAC,KAAU,KAAA;AAClD,EAAM,MAAA;AAAA,IACJ,UAAY,EAAA,mBAAA;AAAA,IACZ,QAAA;AAAA,IACA,aAAgB,GAAA,IAAA;AAAA,IAChB,SAAA;AAAA,IACA,WAAc,GAAA,OAAA;AAAA,IACd;AAAA,GACE,GAAA,KAAA;AAEJ,EAAM,MAAA,qBAAA,GAAwB,qBAAqB,WAAa,EAAA;AAAA,IAC9D,0BAA4B,EAAA;AAAA,GAC7B,CAAA;AAED,EAAA,MAAM,aAAa,mBAAuB,IAAA,qBAAA;AAE1C,EAAM,MAAA,MAAA,GAAS,WAAW,SAAU,EAAA;AAEpC,EAAA,MAAM,aAAgB,GAAA,IAAA,CAAK,MAAO,CAAA,OAAA,EAAS,SAAS,CAAA;AAEpD,EACE,uBAAA,GAAA;AAAA,IAAC,kBAAA;AAAA,IAAA;AAAA,MACC,YAAc,EAAA,CAACA,OAAW,KAAA,UAAA,CAAW,QAAQA,OAAM,CAAA;AAAA,MACnD,MAAA;AAAA,MACA,GAAA;AAAA,MACA,aAAA;AAAA,MACA,SAAW,EAAA,aAAA;AAAA,MAEX,8BAAC,sBAAuB,EAAA,EAAA,IAAA,EAAK,OAAQ,EAAA,UAAA,EAClC,oBAAU,QACb,EAAA;AAAA;AAAA,GACF;AAEJ;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
/* */
|
|
3
|
+
import { useFormContext } from '../context/formContext.mjs';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { useFormState } from 'react-hook-form';
|
|
6
|
+
|
|
7
|
+
const callAfterSubmitFunction = (result) => {
|
|
8
|
+
const callFn = (something) => {
|
|
9
|
+
if (typeof something === "function") {
|
|
10
|
+
something();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
if (result instanceof Promise) {
|
|
14
|
+
result.then(callFn);
|
|
15
|
+
} else {
|
|
16
|
+
callFn(result);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const AfterFormSubmitEffect = (props) => {
|
|
20
|
+
const { submitHandlerResultRef } = props;
|
|
21
|
+
const form = useFormContext().form;
|
|
22
|
+
const { isValid, isSubmitSuccessful } = useFormState(form);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (isSubmitSuccessful && isValid) {
|
|
25
|
+
callAfterSubmitFunction(submitHandlerResultRef.current);
|
|
26
|
+
}
|
|
27
|
+
}, [isSubmitSuccessful, isValid, form]);
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { AfterFormSubmitEffect };
|
|
32
|
+
//# sourceMappingURL=AfterFormSubmitEffect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AfterFormSubmitEffect.mjs","sources":["../../../../../../../../src/integrations/react-hook-form/components/AfterFormSubmitEffect/AfterFormSubmitEffect.tsx"],"sourcesContent":["import { useFormContext } from \"@/integrations/react-hook-form/components/context/formContext\";\nimport type { FC, RefObject } from \"react\";\nimport { useEffect } from \"react\";\nimport { useFormState } from \"react-hook-form\";\n\ninterface Props {\n submitHandlerResultRef: RefObject<unknown>;\n}\n\nconst callAfterSubmitFunction = (result: unknown) => {\n const callFn = (something: unknown) => {\n if (typeof something === \"function\") {\n something();\n }\n };\n\n if (result instanceof Promise) {\n result.then(callFn);\n } else {\n callFn(result);\n }\n};\n\n/**\n * This effect has its own component to prevent unnecessary re-renders of the\n * entire form when the form state changes (useFormState).\n *\n * This component mimics the required effect to reset a form after submit with a\n * simpler to use callback function. See the React Hook docs about resetting\n * form on submit: https://arc.net/l/quote/zslpdgfz\n */\nexport const AfterFormSubmitEffect: FC<Props> = (props) => {\n const { submitHandlerResultRef } = props;\n const form = useFormContext().form;\n const { isValid, isSubmitSuccessful } = useFormState(form);\n\n useEffect(() => {\n if (isSubmitSuccessful && isValid) {\n callAfterSubmitFunction(submitHandlerResultRef.current);\n }\n }, [isSubmitSuccessful, isValid, form]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;AASA,MAAM,uBAAA,GAA0B,CAAC,MAAoB,KAAA;AACnD,EAAM,MAAA,MAAA,GAAS,CAAC,SAAuB,KAAA;AACrC,IAAI,IAAA,OAAO,cAAc,UAAY,EAAA;AACnC,MAAU,SAAA,EAAA;AAAA;AACZ,GACF;AAEA,EAAA,IAAI,kBAAkB,OAAS,EAAA;AAC7B,IAAA,MAAA,CAAO,KAAK,MAAM,CAAA;AAAA,GACb,MAAA;AACL,IAAA,MAAA,CAAO,MAAM,CAAA;AAAA;AAEjB,CAAA;AAUa,MAAA,qBAAA,GAAmC,CAAC,KAAU,KAAA;AACzD,EAAM,MAAA,EAAE,wBAA2B,GAAA,KAAA;AACnC,EAAM,MAAA,IAAA,GAAO,gBAAiB,CAAA,IAAA;AAC9B,EAAA,MAAM,EAAE,OAAA,EAAS,kBAAmB,EAAA,GAAI,aAAa,IAAI,CAAA;AAEzD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,sBAAsB,OAAS,EAAA;AACjC,MAAA,uBAAA,CAAwB,uBAAuB,OAAO,CAAA;AAAA;AACxD,GACC,EAAA,CAAC,kBAAoB,EAAA,OAAA,EAAS,IAAI,CAAC,CAAA;AAEtC,EAAO,OAAA,IAAA;AACT;;;;"}
|
|
@@ -5,7 +5,7 @@ import { SubmitButtonStateProvider } from '../ActionGroupWrapper/SubmitButtonSta
|
|
|
5
5
|
import { FormContextProvider } from '../context/formContext.mjs';
|
|
6
6
|
import { useId, useRef } from 'react';
|
|
7
7
|
import { FormProvider } from 'react-hook-form';
|
|
8
|
-
import {
|
|
8
|
+
import { AfterFormSubmitEffect } from '../AfterFormSubmitEffect/AfterFormSubmitEffect.mjs';
|
|
9
9
|
|
|
10
10
|
const DefaultFormComponent = (p) => /* @__PURE__ */ jsx("form", { ...p });
|
|
11
11
|
function Form(props) {
|
|
@@ -18,6 +18,7 @@ function Form(props) {
|
|
|
18
18
|
} = props;
|
|
19
19
|
const formId = useId();
|
|
20
20
|
const isAsyncSubmit = useRef(false);
|
|
21
|
+
const submitHandlerResultRef = useRef(null);
|
|
21
22
|
const handleOnSubmit = (e) => {
|
|
22
23
|
const { isSubmitting, isValidating } = form.control._formState;
|
|
23
24
|
e.stopPropagation();
|
|
@@ -25,16 +26,23 @@ function Form(props) {
|
|
|
25
26
|
e.preventDefault();
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
29
|
+
submitHandlerResultRef.current = void 0;
|
|
28
30
|
form.handleSubmit((values) => {
|
|
29
31
|
const result = onSubmit(values, e);
|
|
30
32
|
isAsyncSubmit.current = result instanceof Promise;
|
|
33
|
+
submitHandlerResultRef.current = result;
|
|
31
34
|
return result;
|
|
32
35
|
})(e);
|
|
33
36
|
};
|
|
34
|
-
return /* @__PURE__ */ jsx(FormProvider, { ...form, children: /* @__PURE__ */
|
|
35
|
-
/* @__PURE__ */ jsx(FormView, { ...formProps, id: formId, onSubmit: handleOnSubmit, children }),
|
|
36
|
-
/* @__PURE__ */ jsx(
|
|
37
|
-
|
|
37
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...form, children: /* @__PURE__ */ jsxs(FormContextProvider, { value: { form, id: formId }, children: [
|
|
38
|
+
/* @__PURE__ */ jsx(SubmitButtonStateProvider, { isAsyncSubmit, children: /* @__PURE__ */ jsx(FormView, { ...formProps, id: formId, onSubmit: handleOnSubmit, children }) }),
|
|
39
|
+
/* @__PURE__ */ jsx(
|
|
40
|
+
AfterFormSubmitEffect,
|
|
41
|
+
{
|
|
42
|
+
submitHandlerResultRef
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
] }) });
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
export { Form };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.mjs","sources":["../../../../../../../../src/integrations/react-hook-form/components/Form/Form.tsx"],"sourcesContent":["import { SubmitButtonStateProvider } from \"@/integrations/react-hook-form/components/ActionGroupWrapper/SubmitButtonStateProvider\";\nimport { FormContextProvider } from \"@/integrations/react-hook-form/components/context/formContext\";\nimport type {\n ComponentProps,\n ComponentType,\n FormEventHandler,\n PropsWithChildren,\n} from \"react\";\nimport { useId, useRef } from \"react\";\nimport type { FieldValues, UseFormReturn } from \"react-hook-form\";\nimport { FormProvider as RhfFormContextProvider } from \"react-hook-form\";\nimport {
|
|
1
|
+
{"version":3,"file":"Form.mjs","sources":["../../../../../../../../src/integrations/react-hook-form/components/Form/Form.tsx"],"sourcesContent":["import { SubmitButtonStateProvider } from \"@/integrations/react-hook-form/components/ActionGroupWrapper/SubmitButtonStateProvider\";\nimport { FormContextProvider } from \"@/integrations/react-hook-form/components/context/formContext\";\nimport type {\n ComponentProps,\n ComponentType,\n FormEventHandler,\n PropsWithChildren,\n} from \"react\";\nimport { useId, useRef } from \"react\";\nimport type { FieldValues, UseFormReturn } from \"react-hook-form\";\nimport { FormProvider as RhfFormContextProvider } from \"react-hook-form\";\nimport { AfterFormSubmitEffect } from \"../AfterFormSubmitEffect/AfterFormSubmitEffect\";\n\nexport type FormOnSubmitHandler<F extends FieldValues> = Parameters<\n UseFormReturn<F>[\"handleSubmit\"]\n>[0];\n\ntype FormComponentType = ComponentType<\n PropsWithChildren<{ id: string; onSubmit?: FormEventHandler }>\n>;\n\nexport interface FormProps<F extends FieldValues>\n extends Omit<ComponentProps<\"form\">, \"onSubmit\">,\n PropsWithChildren {\n form: UseFormReturn<F>;\n onSubmit: FormOnSubmitHandler<F>;\n formComponent?: FormComponentType;\n}\n\nconst DefaultFormComponent: FormComponentType = (p) => <form {...p} />;\n\nexport function Form<F extends FieldValues>(props: FormProps<F>) {\n const {\n form,\n children,\n onSubmit,\n formComponent: FormView = DefaultFormComponent,\n ...formProps\n } = props;\n\n const formId = useId();\n const isAsyncSubmit = useRef(false);\n const submitHandlerResultRef = useRef<unknown>(null);\n\n const handleOnSubmit: FormEventHandler = (e) => {\n const { isSubmitting, isValidating } = form.control._formState;\n\n e.stopPropagation();\n\n if (isSubmitting || isValidating) {\n e.preventDefault();\n return;\n }\n\n submitHandlerResultRef.current = undefined;\n\n form.handleSubmit((values) => {\n const result = onSubmit(values, e);\n isAsyncSubmit.current = result instanceof Promise;\n submitHandlerResultRef.current = result;\n return result;\n })(e);\n };\n\n return (\n <RhfFormContextProvider {...form}>\n <FormContextProvider value={{ form, id: formId }}>\n <SubmitButtonStateProvider isAsyncSubmit={isAsyncSubmit}>\n <FormView {...formProps} id={formId} onSubmit={handleOnSubmit}>\n {children}\n </FormView>\n </SubmitButtonStateProvider>\n <AfterFormSubmitEffect\n submitHandlerResultRef={submitHandlerResultRef}\n />\n </FormContextProvider>\n </RhfFormContextProvider>\n );\n}\n"],"names":["RhfFormContextProvider"],"mappings":";;;;;;;AA6BA,MAAM,uBAA0C,CAAC,CAAA,qBAAO,GAAA,CAAA,MAAA,EAAA,EAAM,GAAG,CAAG,EAAA,CAAA;AAE7D,SAAS,KAA4B,KAAqB,EAAA;AAC/D,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,eAAe,QAAW,GAAA,oBAAA;AAAA,IAC1B,GAAG;AAAA,GACD,GAAA,KAAA;AAEJ,EAAA,MAAM,SAAS,KAAM,EAAA;AACrB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, RefObject } from 'react';
|
|
2
|
+
interface Props {
|
|
3
|
+
submitHandlerResultRef: RefObject<unknown>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* This effect has its own component to prevent unnecessary re-renders of the
|
|
7
|
+
* entire form when the form state changes (useFormState).
|
|
8
|
+
*
|
|
9
|
+
* This component mimics the required effect to reset a form after submit with a
|
|
10
|
+
* simpler to use callback function. See the React Hook docs about resetting
|
|
11
|
+
* form on submit: https://arc.net/l/quote/zslpdgfz
|
|
12
|
+
*/
|
|
13
|
+
export declare const AfterFormSubmitEffect: FC<Props>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=AfterFormSubmitEffect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AfterFormSubmitEffect.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/react-hook-form/components/AfterFormSubmitEffect/AfterFormSubmitEffect.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI3C,UAAU,KAAK;IACb,sBAAsB,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CAC5C;AAgBD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,KAAK,CAY3C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/react-hook-form/components/Form/Form.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIlE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,WAAW,IAAI,UAAU,CACjE,aAAa,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CACjC,CAAC,CAA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,CAAC,CAAC,CAAC,CAAC;IACvB,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAID,wBAAgB,IAAI,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,2CA+C9D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Form } from '../Form';
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
declare const meta: Meta<typeof Form>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof Form>;
|
|
6
|
+
export declare const Default: Story;
|
|
7
|
+
//# sourceMappingURL=Form.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Form.stories.d.ts","sourceRoot":"","sources":["../../../../../../../src/integrations/react-hook-form/components/Form/stories/Form.stories.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,IAAI,EAAE,MAAM,qDAAqD,CAAC;AAG3E,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAKvD,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,IAAI,CAgD3B,CAAC;AACF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/flow-react-components",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.157",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A React implementation of Flow, mittwald’s design system",
|
|
6
6
|
"homepage": "https://mittwald.github.io/flow",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@chakra-ui/live-region": "^2.1.0",
|
|
55
55
|
"@internationalized/string-compiler": "^3.2.6",
|
|
56
|
-
"@mittwald/react-tunnel": "0.2.0-alpha.
|
|
56
|
+
"@mittwald/react-tunnel": "0.2.0-alpha.157",
|
|
57
57
|
"@mittwald/react-use-promise": "^3.0.4",
|
|
58
58
|
"@react-aria/form": "^3.0.14",
|
|
59
59
|
"@react-aria/utils": "^3.28.1",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@faker-js/faker": "^9.6.0",
|
|
94
94
|
"@internationalized/date": "^3.7.0",
|
|
95
|
-
"@mittwald/flow-design-tokens": "0.2.0-alpha.
|
|
95
|
+
"@mittwald/flow-design-tokens": "0.2.0-alpha.157",
|
|
96
96
|
"@mittwald/react-use-promise": "^2.6.0",
|
|
97
97
|
"@mittwald/remote-dom-react": "1.2.2-mittwald.3",
|
|
98
98
|
"@mittwald/typescript-config": "",
|
|
@@ -173,5 +173,5 @@
|
|
|
173
173
|
"optional": true
|
|
174
174
|
}
|
|
175
175
|
},
|
|
176
|
-
"gitHead": "
|
|
176
|
+
"gitHead": "20331b9b110c2246e76d1214ca356d155698bf45"
|
|
177
177
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
/* */
|
|
3
|
-
import { useEffect } from 'react';
|
|
4
|
-
import { useFormContext } from '../context/formContext.mjs';
|
|
5
|
-
import { useFormState } from 'react-hook-form';
|
|
6
|
-
|
|
7
|
-
const AutoFormResetEffect = () => {
|
|
8
|
-
const form = useFormContext().form;
|
|
9
|
-
const { isValid, isSubmitted } = useFormState(form);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (isSubmitted && isValid && form) {
|
|
12
|
-
form.reset(void 0, {
|
|
13
|
-
keepIsSubmitted: false,
|
|
14
|
-
keepIsSubmitSuccessful: false,
|
|
15
|
-
keepDefaultValues: true,
|
|
16
|
-
keepValues: true,
|
|
17
|
-
keepDirtyValues: true,
|
|
18
|
-
keepIsValid: true,
|
|
19
|
-
keepDirty: true,
|
|
20
|
-
keepErrors: true,
|
|
21
|
-
keepTouched: true,
|
|
22
|
-
keepIsValidating: true,
|
|
23
|
-
keepSubmitCount: true
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}, [isSubmitted, isValid, form]);
|
|
27
|
-
return null;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { AutoFormResetEffect };
|
|
31
|
-
//# sourceMappingURL=AutoFormResetEffect.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormResetEffect.mjs","sources":["../../../../../../../../src/integrations/react-hook-form/components/AutoFormResetEffect/AutoFormResetEffect.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { useEffect } from \"react\";\nimport { useFormContext } from \"@/integrations/react-hook-form/components/context/formContext\";\nimport { useFormState } from \"react-hook-form\";\n\n/**\n * This effect has its own component to prevent unnecessary re-renders of the\n * entire form when the form state changes (useFormState).\n */\nexport const AutoFormResetEffect: FC = () => {\n const form = useFormContext().form;\n const { isValid, isSubmitted } = useFormState(form);\n\n useEffect(() => {\n if (isSubmitted && isValid && form) {\n form.reset(undefined, {\n keepIsSubmitted: false,\n keepIsSubmitSuccessful: false,\n keepDefaultValues: true,\n keepValues: true,\n keepDirtyValues: true,\n keepIsValid: true,\n keepDirty: true,\n keepErrors: true,\n keepTouched: true,\n keepIsValidating: true,\n keepSubmitCount: true,\n });\n }\n }, [isSubmitted, isValid, form]);\n\n return null;\n};\n"],"names":[],"mappings":";;;;AASO,MAAM,sBAA0B,MAAM;AAC3C,EAAM,MAAA,IAAA,GAAO,gBAAiB,CAAA,IAAA;AAC9B,EAAA,MAAM,EAAE,OAAA,EAAS,WAAY,EAAA,GAAI,aAAa,IAAI,CAAA;AAElD,EAAA,SAAA,CAAU,MAAM;AACd,IAAI,IAAA,WAAA,IAAe,WAAW,IAAM,EAAA;AAClC,MAAA,IAAA,CAAK,MAAM,MAAW,EAAA;AAAA,QACpB,eAAiB,EAAA,KAAA;AAAA,QACjB,sBAAwB,EAAA,KAAA;AAAA,QACxB,iBAAmB,EAAA,IAAA;AAAA,QACnB,UAAY,EAAA,IAAA;AAAA,QACZ,eAAiB,EAAA,IAAA;AAAA,QACjB,WAAa,EAAA,IAAA;AAAA,QACb,SAAW,EAAA,IAAA;AAAA,QACX,UAAY,EAAA,IAAA;AAAA,QACZ,WAAa,EAAA,IAAA;AAAA,QACb,gBAAkB,EAAA,IAAA;AAAA,QAClB,eAAiB,EAAA;AAAA,OAClB,CAAA;AAAA;AACH,GACC,EAAA,CAAC,WAAa,EAAA,OAAA,EAAS,IAAI,CAAC,CAAA;AAE/B,EAAO,OAAA,IAAA;AACT;;;;"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* This effect has its own component to prevent unnecessary re-renders of the
|
|
4
|
-
* entire form when the form state changes (useFormState).
|
|
5
|
-
*/
|
|
6
|
-
export declare const AutoFormResetEffect: FC;
|
|
7
|
-
//# sourceMappingURL=AutoFormResetEffect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormResetEffect.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/react-hook-form/components/AutoFormResetEffect/AutoFormResetEffect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAKhC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,EAuBjC,CAAC"}
|