@fuf-stack/uniform 0.14.5 → 0.16.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/dist/CheckboxGroup/index.cjs +7 -6
- package/dist/CheckboxGroup/index.cjs.map +1 -1
- package/dist/CheckboxGroup/index.d.cts +2 -2
- package/dist/CheckboxGroup/index.d.ts +2 -2
- package/dist/CheckboxGroup/index.js +6 -5
- package/dist/{CheckboxGroup-o-qWkWe1.d.cts → CheckboxGroup-fAdey3Td.d.cts} +1 -1
- package/dist/{CheckboxGroup-o-qWkWe1.d.ts → CheckboxGroup-fAdey3Td.d.ts} +1 -1
- package/dist/Controller/index.cjs +4 -2
- package/dist/Controller/index.cjs.map +1 -1
- package/dist/Controller/index.d.cts +7 -3
- package/dist/Controller/index.d.ts +7 -3
- package/dist/Controller/index.js +7 -5
- package/dist/Controller-8Nqugui5.d.cts +37 -0
- package/dist/Controller-8Nqugui5.d.ts +37 -0
- package/dist/FieldArray/index.cjs +6 -5
- package/dist/FieldArray/index.cjs.map +1 -1
- package/dist/FieldArray/index.d.cts +5 -3
- package/dist/FieldArray/index.d.ts +5 -3
- package/dist/FieldArray/index.js +5 -4
- package/dist/FieldArray-AqM2XKIh.d.cts +151 -0
- package/dist/FieldArray-AqM2XKIh.d.ts +151 -0
- package/dist/Form/index.cjs +5 -4
- package/dist/Form/index.cjs.map +1 -1
- package/dist/Form/index.js +4 -3
- package/dist/Grid/index.cjs +1 -0
- package/dist/Grid/index.cjs.map +1 -1
- package/dist/Grid/index.js +1 -0
- package/dist/Input/index.cjs +7 -6
- package/dist/Input/index.cjs.map +1 -1
- package/dist/Input/index.d.cts +2 -2
- package/dist/Input/index.d.ts +2 -2
- package/dist/Input/index.js +6 -5
- package/dist/{Input-IkWP4cWg.d.cts → Input-B_wjhY9e.d.cts} +1 -1
- package/dist/{Input-IkWP4cWg.d.ts → Input-B_wjhY9e.d.ts} +1 -1
- package/dist/RadioGroup/index.cjs +7 -6
- package/dist/RadioGroup/index.cjs.map +1 -1
- package/dist/RadioGroup/index.d.cts +2 -2
- package/dist/RadioGroup/index.d.ts +2 -2
- package/dist/RadioGroup/index.js +6 -5
- package/dist/{RadioGroup-1J39ASHa.d.cts → RadioGroup-Dxd2FPQj.d.cts} +1 -1
- package/dist/{RadioGroup-1J39ASHa.d.ts → RadioGroup-Dxd2FPQj.d.ts} +1 -1
- package/dist/Select/index.cjs +7 -6
- package/dist/Select/index.cjs.map +1 -1
- package/dist/Select/index.d.cts +2 -2
- package/dist/Select/index.d.ts +2 -2
- package/dist/Select/index.js +6 -5
- package/dist/{Select-BhS4z0Pj.d.cts → Select-JRwrSDew.d.cts} +1 -1
- package/dist/{Select-BhS4z0Pj.d.ts → Select-JRwrSDew.d.ts} +1 -1
- package/dist/SubmitButton/index.cjs +5 -4
- package/dist/SubmitButton/index.cjs.map +1 -1
- package/dist/SubmitButton/index.js +4 -3
- package/dist/Switch/index.cjs +7 -6
- package/dist/Switch/index.cjs.map +1 -1
- package/dist/Switch/index.d.cts +2 -2
- package/dist/Switch/index.d.ts +2 -2
- package/dist/Switch/index.js +6 -5
- package/dist/{Switch-Fdldj8LV.d.cts → Switch-mdolzzEc.d.cts} +1 -1
- package/dist/{Switch-Fdldj8LV.d.ts → Switch-mdolzzEc.d.ts} +1 -1
- package/dist/TextArea/index.cjs +7 -6
- package/dist/TextArea/index.cjs.map +1 -1
- package/dist/TextArea/index.d.cts +2 -2
- package/dist/TextArea/index.d.ts +2 -2
- package/dist/TextArea/index.js +6 -5
- package/dist/{TextArea-B-sKvTkd.d.cts → TextArea-DNpInDsW.d.cts} +1 -1
- package/dist/{TextArea-B-sKvTkd.d.ts → TextArea-DNpInDsW.d.ts} +1 -1
- package/dist/{chunk-QCVTB2NI.js → chunk-3QBYSFDX.js} +10 -9
- package/dist/chunk-3QBYSFDX.js.map +1 -0
- package/dist/chunk-4DAZAO6Y.cjs +59 -0
- package/dist/chunk-4DAZAO6Y.cjs.map +1 -0
- package/dist/{chunk-BS52M4SZ.js → chunk-5YDNHSEU.js} +47 -41
- package/dist/chunk-5YDNHSEU.js.map +1 -0
- package/dist/chunk-7ROOJK7G.cjs +110 -0
- package/dist/chunk-7ROOJK7G.cjs.map +1 -0
- package/dist/{chunk-WKM2D7LF.js → chunk-ASPOGQPS.js} +2 -5
- package/dist/chunk-ASPOGQPS.js.map +1 -0
- package/dist/{chunk-XCZKNTFT.cjs → chunk-BDVAK232.cjs} +23 -24
- package/dist/chunk-BDVAK232.cjs.map +1 -0
- package/dist/chunk-CESGUF6F.cjs +63 -0
- package/dist/chunk-CESGUF6F.cjs.map +1 -0
- package/dist/chunk-CRTRMMJ7.js +59 -0
- package/dist/chunk-CRTRMMJ7.js.map +1 -0
- package/dist/{chunk-VP7WDLJM.js → chunk-DS7GUNDT.js} +17 -14
- package/dist/chunk-DS7GUNDT.js.map +1 -0
- package/dist/chunk-ECDLVJLZ.js +246 -0
- package/dist/chunk-ECDLVJLZ.js.map +1 -0
- package/dist/{chunk-GN5NJ6ZU.js → chunk-GNDW3TAU.js} +3 -6
- package/dist/chunk-GNDW3TAU.js.map +1 -0
- package/dist/{chunk-VZ5MMFIF.cjs → chunk-H65I56SI.cjs} +4 -7
- package/dist/chunk-H65I56SI.cjs.map +1 -0
- package/dist/chunk-HCQJGNWT.cjs +246 -0
- package/dist/chunk-HCQJGNWT.cjs.map +1 -0
- package/dist/chunk-IBQCNI5H.js +372 -0
- package/dist/chunk-IBQCNI5H.js.map +1 -0
- package/dist/chunk-IUVEFLF3.cjs +133 -0
- package/dist/chunk-IUVEFLF3.cjs.map +1 -0
- package/dist/{chunk-Y3SFF6RN.cjs → chunk-KIAIGPG7.cjs} +11 -10
- package/dist/chunk-KIAIGPG7.cjs.map +1 -0
- package/dist/{chunk-QW44EUAH.js → chunk-MEK7YR46.js} +10 -10
- package/dist/chunk-MEK7YR46.js.map +1 -0
- package/dist/{chunk-OHJYXA6R.cjs → chunk-OE5IW4ZG.cjs} +4 -7
- package/dist/chunk-OE5IW4ZG.cjs.map +1 -0
- package/dist/chunk-PHGFXKPU.cjs +51 -0
- package/dist/chunk-PHGFXKPU.cjs.map +1 -0
- package/dist/{chunk-PZ4LZQI4.cjs → chunk-Q23XGBJ5.cjs} +18 -15
- package/dist/chunk-Q23XGBJ5.cjs.map +1 -0
- package/dist/{chunk-DDZMDOSG.js → chunk-STU7SBQX.js} +25 -23
- package/dist/chunk-STU7SBQX.js.map +1 -0
- package/dist/{chunk-BZAPTLMC.js → chunk-T4N6TMUL.js} +49 -49
- package/dist/chunk-T4N6TMUL.js.map +1 -0
- package/dist/chunk-TJESSWIB.cjs +372 -0
- package/dist/chunk-TJESSWIB.cjs.map +1 -0
- package/dist/chunk-UAV6PVB4.js +63 -0
- package/dist/chunk-UAV6PVB4.js.map +1 -0
- package/dist/{chunk-BYKOCVCK.js → chunk-WKJN5A2E.js} +22 -23
- package/dist/chunk-WKJN5A2E.js.map +1 -0
- package/dist/{chunk-XJZAS7NG.cjs → chunk-WRIXKFKW.cjs} +25 -23
- package/dist/chunk-WRIXKFKW.cjs.map +1 -0
- package/dist/{chunk-RBIX6EWU.cjs → chunk-Y7MJBI4A.cjs} +11 -11
- package/dist/chunk-Y7MJBI4A.cjs.map +1 -0
- package/dist/chunk-ZI22WT2P.js +51 -0
- package/dist/chunk-ZI22WT2P.js.map +1 -0
- package/dist/helpers/index.cjs +9 -2
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/helpers/index.d.cts +67 -4
- package/dist/helpers/index.d.ts +67 -4
- package/dist/helpers/index.js +10 -3
- package/dist/hooks/index.cjs +6 -3
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +3 -2
- package/dist/hooks/index.d.ts +3 -2
- package/dist/hooks/index.js +7 -4
- package/dist/index.cjs +25 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -10
- package/dist/index.d.ts +11 -10
- package/dist/index.js +31 -22
- package/dist/partials/FieldCopyTestIdButton/index.cjs +1 -0
- package/dist/partials/FieldCopyTestIdButton/index.cjs.map +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.js +1 -0
- package/dist/partials/FieldValidationError/index.cjs +3 -3
- package/dist/partials/FieldValidationError/index.js +2 -2
- package/package.json +18 -20
- package/dist/FieldArray-DD9z-xZ3.d.cts +0 -37
- package/dist/FieldArray-DD9z-xZ3.d.ts +0 -37
- package/dist/chunk-BBB4FEY6.cjs +0 -22
- package/dist/chunk-BBB4FEY6.cjs.map +0 -1
- package/dist/chunk-BS52M4SZ.js.map +0 -1
- package/dist/chunk-BYKOCVCK.js.map +0 -1
- package/dist/chunk-BZAPTLMC.js.map +0 -1
- package/dist/chunk-DDZMDOSG.js.map +0 -1
- package/dist/chunk-EKE5URXQ.cjs +0 -104
- package/dist/chunk-EKE5URXQ.cjs.map +0 -1
- package/dist/chunk-GN5NJ6ZU.js.map +0 -1
- package/dist/chunk-HOETR36J.cjs +0 -299
- package/dist/chunk-HOETR36J.cjs.map +0 -1
- package/dist/chunk-HZP3EXGR.cjs +0 -241
- package/dist/chunk-HZP3EXGR.cjs.map +0 -1
- package/dist/chunk-IUNDGVMC.js +0 -241
- package/dist/chunk-IUNDGVMC.js.map +0 -1
- package/dist/chunk-KOKIM2ND.js +0 -9
- package/dist/chunk-KOKIM2ND.js.map +0 -1
- package/dist/chunk-OHJYXA6R.cjs.map +0 -1
- package/dist/chunk-PZ4LZQI4.cjs.map +0 -1
- package/dist/chunk-QCVTB2NI.js.map +0 -1
- package/dist/chunk-QW44EUAH.js.map +0 -1
- package/dist/chunk-RBIX6EWU.cjs.map +0 -1
- package/dist/chunk-V46BHM2U.js +0 -22
- package/dist/chunk-V46BHM2U.js.map +0 -1
- package/dist/chunk-VP7WDLJM.js.map +0 -1
- package/dist/chunk-VQWKXSHW.cjs +0 -9
- package/dist/chunk-VQWKXSHW.cjs.map +0 -1
- package/dist/chunk-VZ5MMFIF.cjs.map +0 -1
- package/dist/chunk-WKM2D7LF.js.map +0 -1
- package/dist/chunk-XCZKNTFT.cjs.map +0 -1
- package/dist/chunk-XJWEUCV3.cjs +0 -133
- package/dist/chunk-XJWEUCV3.cjs.map +0 -1
- package/dist/chunk-XJZAS7NG.cjs.map +0 -1
- package/dist/chunk-Y3SFF6RN.cjs.map +0 -1
- package/dist/chunk-Y53IHK6B.js +0 -299
- package/dist/chunk-Y53IHK6B.js.map +0 -1
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
Controller_default
|
|
3
|
+
} from "./chunk-ZI22WT2P.js";
|
|
4
4
|
import {
|
|
5
5
|
FieldCopyTestIdButton_default
|
|
6
6
|
} from "./chunk-2CRY7VDQ.js";
|
|
7
7
|
import {
|
|
8
8
|
FieldValidationError_default
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ASPOGQPS.js";
|
|
10
10
|
import {
|
|
11
11
|
useFormContext
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-T4N6TMUL.js";
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
__objRest,
|
|
15
|
+
__spreadProps,
|
|
16
|
+
__spreadValues
|
|
17
|
+
} from "./chunk-CRTRMMJ7.js";
|
|
16
18
|
|
|
17
19
|
// src/RadioGroup/RadioGroup.tsx
|
|
18
|
-
import { RadioGroup as
|
|
19
|
-
import { cn as cn3, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
20
|
+
import { RadioGroup as HeroRadioGroup, Radio } from "@heroui/radio";
|
|
21
|
+
import { cn as cn3, slugify, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
20
22
|
import { ButtonGroup } from "@fuf-stack/pixels";
|
|
21
23
|
import Tabs from "@fuf-stack/pixels/Tabs";
|
|
22
24
|
|
|
23
25
|
// src/RadioGroup/Variants/RadioBox.tsx
|
|
24
|
-
import { useRadio } from "@
|
|
26
|
+
import { useRadio } from "@heroui/radio";
|
|
25
27
|
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
26
28
|
import { cn } from "@fuf-stack/pixel-utils";
|
|
27
29
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
28
|
-
var RadioBox = (
|
|
30
|
+
var RadioBox = (_a) => {
|
|
31
|
+
var _b = _a, { icon = void 0 } = _b, props = __objRest(_b, ["icon"]);
|
|
29
32
|
const {
|
|
30
33
|
children,
|
|
31
34
|
Component,
|
|
@@ -40,8 +43,7 @@ var RadioBox = ({ icon = void 0, ...props }) => {
|
|
|
40
43
|
} = useRadio(props);
|
|
41
44
|
return /* @__PURE__ */ jsxs(
|
|
42
45
|
Component,
|
|
43
|
-
{
|
|
44
|
-
...getBaseProps(),
|
|
46
|
+
__spreadProps(__spreadValues({}, getBaseProps()), {
|
|
45
47
|
className: cn(
|
|
46
48
|
"group inline-flex flex-auto cursor-pointer items-center justify-between gap-4 rounded-lg border-2 border-default p-4 hover:bg-content2 data-[selected=true]:border-focus",
|
|
47
49
|
{
|
|
@@ -50,22 +52,21 @@ var RadioBox = ({ icon = void 0, ...props }) => {
|
|
|
50
52
|
}
|
|
51
53
|
),
|
|
52
54
|
children: [
|
|
53
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
|
|
54
|
-
/* @__PURE__ */ jsx("span", {
|
|
55
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", __spreadValues({}, getInputProps())) }),
|
|
56
|
+
/* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, getWrapperProps()), { children: /* @__PURE__ */ jsx("span", __spreadValues({}, getControlProps())) })),
|
|
55
57
|
icon,
|
|
56
58
|
/* @__PURE__ */ jsxs(
|
|
57
59
|
"div",
|
|
58
|
-
{
|
|
59
|
-
...getLabelWrapperProps(),
|
|
60
|
+
__spreadProps(__spreadValues({}, getLabelWrapperProps()), {
|
|
60
61
|
className: cn(getLabelWrapperProps().className, "grow"),
|
|
61
62
|
children: [
|
|
62
|
-
children && /* @__PURE__ */ jsx("span", {
|
|
63
|
+
children && /* @__PURE__ */ jsx("span", __spreadProps(__spreadValues({}, getLabelProps()), { children })),
|
|
63
64
|
description && /* @__PURE__ */ jsx("span", { className: "text-small text-foreground opacity-70", children: description })
|
|
64
65
|
]
|
|
65
|
-
}
|
|
66
|
+
})
|
|
66
67
|
)
|
|
67
68
|
]
|
|
68
|
-
}
|
|
69
|
+
})
|
|
69
70
|
);
|
|
70
71
|
};
|
|
71
72
|
|
|
@@ -113,7 +114,8 @@ var radioGroupVariants = tv({
|
|
|
113
114
|
itemLabelWrapper: "",
|
|
114
115
|
itemWrapper: 'group-data-[invalid=true]:!border-danger [&:not(group-data-[invalid="true"]):not(group-data-[selected="false"])]:border-focus',
|
|
115
116
|
// TODO: get rid of !.
|
|
116
|
-
//
|
|
117
|
+
// see HeroUI styles for group-data condition,
|
|
118
|
+
// e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/select.ts
|
|
117
119
|
label: "text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:text-danger",
|
|
118
120
|
wrapper: "",
|
|
119
121
|
// Tabs
|
|
@@ -141,7 +143,7 @@ var RadioGroup = ({
|
|
|
141
143
|
const variants = radioGroupVariants();
|
|
142
144
|
const classNames = variantsToClassNames(variants, className, "base");
|
|
143
145
|
return /* @__PURE__ */ jsx3(
|
|
144
|
-
|
|
146
|
+
Controller_default,
|
|
145
147
|
{
|
|
146
148
|
control,
|
|
147
149
|
disabled,
|
|
@@ -240,7 +242,7 @@ var RadioGroup = ({
|
|
|
240
242
|
});
|
|
241
243
|
}
|
|
242
244
|
return /* @__PURE__ */ jsx3(
|
|
243
|
-
|
|
245
|
+
HeroRadioGroup,
|
|
244
246
|
{
|
|
245
247
|
classNames,
|
|
246
248
|
"data-invalid": invalid,
|
|
@@ -276,4 +278,4 @@ export {
|
|
|
276
278
|
RadioGroup_default,
|
|
277
279
|
RadioGroup_default2
|
|
278
280
|
};
|
|
279
|
-
//# sourceMappingURL=chunk-
|
|
281
|
+
//# sourceMappingURL=chunk-STU7SBQX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/RadioGroup/RadioGroup.tsx","../src/RadioGroup/Variants/RadioBox.tsx","../src/RadioGroup/Variants/RadioButton.tsx","../src/RadioGroup/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { TabProps } from '@fuf-stack/pixels/Tabs';\nimport type { ReactElement, ReactNode } from 'react';\n\nimport { RadioGroup as HeroRadioGroup, Radio } from '@heroui/radio';\n\nimport { cn, slugify, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\nimport { ButtonGroup } from '@fuf-stack/pixels';\nimport Tabs from '@fuf-stack/pixels/Tabs';\n\nimport { Controller } from '../Controller';\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\nimport { RadioBox } from './Variants/RadioBox';\nimport { RadioButton } from './Variants/RadioButton';\n\nexport const radioGroupVariants = tv({\n slots: {\n base: 'group', // Needs group for group-data condition\n buttonGroup:\n 'rounded-xl group-data-[invalid=true]:border group-data-[invalid=true]:border-danger', // optional if a button group is used\n itemBase: '',\n itemBaseActive: 'bg-opacity-50', // optional if a button group is used\n itemControl: 'bg-focus group-data-[invalid=true]:bg-danger',\n itemDescription: '',\n itemLabel: 'text-sm',\n itemLabelWrapper: '',\n itemWrapper:\n 'group-data-[invalid=true]:!border-danger [&:not(group-data-[invalid=\"true\"]):not(group-data-[selected=\"false\"])]:border-focus', // TODO: get rid of !.\n // see HeroUI styles for group-data condition,\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/select.ts\n label:\n 'text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:text-danger',\n wrapper: '',\n // Tabs\n tabList: '',\n tab: '',\n tabContent: '',\n cursor: '',\n panel: '',\n },\n});\n\ntype VariantProps = TVProps<typeof radioGroupVariants>;\ntype ClassName = TVClassName<typeof radioGroupVariants>;\n\nexport interface RadioGroupOption {\n /** Description of the value. Works with variant radioBox. */\n description?: React.ReactNode;\n /** disables the option */\n disabled?: boolean;\n /** option label */\n label?: React.ReactNode;\n /** option icon */\n icon?: ReactNode;\n /** HTML data-testid attribute of the option */\n testId?: string;\n /** option value */\n value: string;\n}\n\nexport interface RadioGroupProps<\n V extends 'default' | 'radioBox' | 'radioButton' | 'tabs',\n> extends VariantProps {\n /** CSS class name */\n className?: ClassName;\n /** Determines if the Buttons are disabled or not. */\n disabled?: boolean;\n /** determines orientation of the Buttons. */\n inline?: boolean;\n /** Label displayed next to the RadioButton. */\n label?: ReactNode;\n /** Name the RadioButtons are registered at in HTML forms (react-hook-form). */\n name: string;\n /** Radio button configuration. */\n options: V extends 'default' | 'radioBox' | 'radioButton'\n ? RadioGroupOption[]\n : TabProps[];\n /** Id to grab element in internal tests. */\n testId?: string;\n /** How the RadioGroup should look like. */\n variant?: V;\n}\n\n/**\n * RadioGroup component based on [HeroUI RadioGroup](https://www.heroui.com//docs/components/radio-group)\n */\nconst RadioGroup = ({\n className = undefined,\n disabled = false,\n inline = false,\n label = undefined,\n name,\n options,\n testId: _testId = undefined,\n variant = 'default',\n}: RadioGroupProps<\n 'default' | 'radioBox' | 'radioButton' | 'tabs'\n>): ReactElement => {\n const { control, debugMode, getFieldState, getValues } = useFormContext();\n\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n const showTestIdCopyButton = debugMode === 'debug-testids';\n const showLabel = label || showTestIdCopyButton;\n\n const variants = radioGroupVariants();\n const classNames = variantsToClassNames(variants, className, 'base');\n\n return (\n <Controller\n control={control}\n disabled={disabled}\n name={name}\n render={({ field: { onChange, disabled: isDisabled, onBlur, ref } }) => {\n let RadioComponents: ReactNode;\n\n const itemClassNames = {\n base: classNames.itemBase,\n control: classNames.itemControl,\n description: classNames.itemDescription,\n label: classNames.itemLabel,\n labelWrapper: classNames.itemLabelWrapper,\n wrapper: classNames.itemWrapper,\n tabList: classNames.tabList,\n tab: classNames.tab,\n tabContent: classNames.tabContent,\n cursor: classNames.cursor,\n panel: classNames.panel,\n };\n\n switch (variant) {\n case 'radioBox':\n RadioComponents = options.map((option) => {\n if ('value' in option) {\n return (\n <RadioBox\n classNames={itemClassNames}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n description={option.description}\n icon={option.icon}\n isDisabled={isDisabled || option.disabled}\n key={option.value}\n onChange={onChange}\n value={option.value}\n >\n {option.label ? option.label : option.value}\n </RadioBox>\n );\n }\n return null;\n });\n break;\n case 'radioButton':\n RadioComponents = options.map((option) => {\n if ('value' in option) {\n return (\n <RadioButton\n className={cn(classNames.itemBase, {\n [classNames.itemBaseActive]:\n getValues()[name] !== option.value,\n })}\n isDisabled={isDisabled || option.disabled}\n key={option.value}\n testID={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n onChange={onChange}\n value={option.value}\n // TODO: how to do the classNames properly (make selected option darker with same color)\n >\n {option.label ? option.label : option.value}\n </RadioButton>\n );\n }\n return null;\n });\n break;\n\n case 'tabs':\n RadioComponents = (\n <Tabs\n fullWidth={false}\n tabs={options as TabProps[]}\n onSelectionChange={onChange}\n />\n );\n break;\n default:\n RadioComponents = options.map((option) => {\n if ('value' in option) {\n return (\n <Radio\n classNames={itemClassNames}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n isDisabled={isDisabled || option.disabled}\n key={option.value}\n onChange={onChange}\n value={option.value}\n >\n {option.label ? option.label : option.value}\n </Radio>\n );\n }\n return null;\n });\n }\n\n return (\n <HeroRadioGroup\n classNames={classNames}\n // see HeroUI styles for group-data condition (data-invalid),\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/components/select/src/use-select.ts\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n errorMessage={error && <FieldValidationError error={error} />}\n isDisabled={isDisabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n showLabel && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label>\n {label}\n {showTestIdCopyButton && (\n <FieldCopyTestIdButton testId={testId} />\n )}\n </label>\n )\n }\n name={name}\n orientation={inline ? 'horizontal' : 'vertical'}\n onBlur={onBlur}\n onChange={onChange}\n ref={ref}\n >\n {variant === 'radioButton' ? (\n <ButtonGroup className={classNames.buttonGroup}>\n {RadioComponents}\n </ButtonGroup>\n ) : (\n RadioComponents\n )}\n </HeroRadioGroup>\n );\n }}\n />\n );\n};\n\nexport default RadioGroup;\n","import type { RadioProps as HeroRadioProps } from '@heroui/radio';\nimport type { ReactNode } from 'react';\n\nimport { useRadio } from '@heroui/radio';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\ninterface RadioProps extends HeroRadioProps {\n /** icon for the option */\n icon?: ReactNode;\n}\n\nexport const RadioBox = ({ icon = undefined, ...props }: RadioProps) => {\n const {\n children,\n Component,\n description,\n getBaseProps,\n getControlProps,\n getInputProps,\n getLabelProps,\n getLabelWrapperProps,\n getWrapperProps,\n isDisabled,\n } = useRadio(props);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getBaseProps()}\n className={cn(\n 'group inline-flex flex-auto cursor-pointer items-center justify-between gap-4 rounded-lg border-2 border-default p-4 hover:bg-content2 data-[selected=true]:border-focus',\n {\n // disabled styles\n 'pointer-events-none opacity-disabled': isDisabled,\n },\n )}\n >\n <VisuallyHidden>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <input {...getInputProps()} />\n </VisuallyHidden>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <span {...getWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <span {...getControlProps()} />\n </span>\n {icon}\n <div\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getLabelWrapperProps()}\n className={cn(getLabelWrapperProps().className, 'grow')}\n >\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n {children && <span {...getLabelProps()}>{children}</span>}\n {description && (\n <span className=\"text-small text-foreground opacity-70\">\n {description}\n </span>\n )}\n </div>\n </Component>\n );\n};\n\nexport default RadioBox;\n","import { cn } from '@fuf-stack/pixel-utils';\nimport { Button } from '@fuf-stack/pixels';\n\ninterface RadioButtonProps {\n /** label of the value. */\n children: React.ReactNode;\n /** CSS class name */\n className?: string;\n /** disables the option */\n isDisabled?: boolean;\n /** HTML data-testid attribute of the option */\n testID?: string;\n /** Callback function. Executed if the option is clicked. */\n onChange: (...event: unknown[]) => void;\n /** value of the option. */\n value: string;\n}\n\nexport const RadioButton = ({\n children,\n className = undefined,\n isDisabled = false,\n onChange,\n testID = undefined,\n value,\n}: RadioButtonProps) => {\n return (\n <Button\n className={cn(className)}\n testId={testID}\n disabled={isDisabled}\n key={`index_${value}`}\n onClick={() => {\n return onChange(value);\n }}\n >\n {children}\n </Button>\n );\n};\n\nexport default RadioButton;\n","import RadioGroup from './RadioGroup';\n\nexport type { RadioGroupProps } from './RadioGroup';\n\nexport { RadioGroup };\n\nexport default RadioGroup;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA,SAAS,cAAc,gBAAgB,aAAa;AAEpD,SAAS,MAAAA,KAAI,SAAS,IAAI,4BAA4B;AACtD,SAAS,mBAAmB;AAC5B,OAAO,UAAU;;;ACLjB,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAE/B,SAAS,UAAU;AAmCX,cAQF,YARE;AA5BD,IAAM,WAAW,CAAC,OAA+C;AAA/C,eAAE,SAAO,OAblC,IAayB,IAAuB,kBAAvB,IAAuB,CAArB;AACzB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,SAAS,KAAK;AAElB,SACE;AAAA,IAAC;AAAA,qCAEK,aAAa,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A,oBACA,OAAO,OAAO;AAAA,oBAEb,iBAAO,QAAQ,OAAO,QAAQ,OAAO;AAAA;AAAA,kBAJjC,OAAO;AAAA,gBAKd;AAAA,cAEJ;AACA,qBAAO;AAAA,YACT,CAAC;AAAA,QACL;AAEA,eACE,gBAAAA;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YAGA,gBAAc;AAAA,YACd,iBAAe;AAAA,YACf,eAAa;AAAA,YACb,cAAc,SAAS,gBAAAA,KAAC,gCAAqB,OAAc;AAAA,YAC3D;AAAA,YACA,WAAW;AAAA,YACX,YAAY;AAAA,YACZ,OACE;AAAA,YAEE,gBAAAC,MAAC,WACE;AAAA;AAAA,cACA,wBACC,gBAAAD,KAAC,iCAAsB,QAAgB;AAAA,eAE3C;AAAA,YAGJ;AAAA,YACA,aAAa,SAAS,eAAe;AAAA,YACrC;AAAA,YACA;AAAA,YACA;AAAA,YAEC,sBAAY,gBACX,gBAAAA,KAAC,eAAY,WAAW,WAAW,aAChC,2BACH,IAEA;AAAA;AAAA,QAEJ;AAAA,MAEJ;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,qBAAQ;;;AG1Pf,IAAOG,sBAAQ;","names":["cn","cn","jsx","jsx","jsxs","cn","RadioGroup_default"]}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
toValidationFormat
|
|
3
|
+
} from "./chunk-UAV6PVB4.js";
|
|
4
|
+
import {
|
|
5
|
+
__async,
|
|
6
|
+
__objRest,
|
|
7
|
+
__spreadProps,
|
|
8
|
+
__spreadValues
|
|
9
|
+
} from "./chunk-CRTRMMJ7.js";
|
|
4
10
|
|
|
5
11
|
// src/hooks/useFieldArray/useFieldArray.ts
|
|
6
12
|
import { useFieldArray } from "react-hook-form";
|
|
@@ -8,19 +14,13 @@ import { useFieldArray } from "react-hook-form";
|
|
|
8
14
|
// src/hooks/useFormContext/useFormContext.ts
|
|
9
15
|
import { useContext } from "react";
|
|
10
16
|
import { useFormContext as useHookFormContext } from "react-hook-form";
|
|
17
|
+
import { slugify } from "@fuf-stack/pixel-utils";
|
|
11
18
|
|
|
12
19
|
// src/Form/subcomponents/FormContext.tsx
|
|
13
20
|
import React, { useMemo, useState } from "react";
|
|
14
21
|
import { FormProvider as HookFormProvider, useForm } from "react-hook-form";
|
|
15
22
|
import { useLocalStorage } from "@fuf-stack/pixels";
|
|
16
23
|
import { jsx } from "react/jsx-runtime";
|
|
17
|
-
var removeNullishFields = (obj) => {
|
|
18
|
-
return JSON.parse(
|
|
19
|
-
JSON.stringify(obj, (_key, value) => {
|
|
20
|
-
return value === "" || value === null ? void 0 : value;
|
|
21
|
-
})
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
24
|
var DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = "uniform:debug-mode";
|
|
25
25
|
var UniformContext = React.createContext({
|
|
26
26
|
debugMode: "off",
|
|
@@ -38,14 +38,14 @@ var FormProvider = ({
|
|
|
38
38
|
}) => {
|
|
39
39
|
const [preventSubmit, setPreventSubmit] = useState(false);
|
|
40
40
|
const [debugMode, setDebugMode] = useLocalStorage(
|
|
41
|
-
debugModeSettings
|
|
41
|
+
(debugModeSettings == null ? void 0 : debugModeSettings.localStorageKey) || DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT,
|
|
42
42
|
"off"
|
|
43
43
|
);
|
|
44
44
|
const contextValue = useMemo(
|
|
45
45
|
() => ({
|
|
46
46
|
// set debugMode to disabled when debugModeSettings.disable is true
|
|
47
47
|
// otherwise use current debug mode from localStorage
|
|
48
|
-
debugMode: debugModeSettings
|
|
48
|
+
debugMode: (debugModeSettings == null ? void 0 : debugModeSettings.disable) ? "disabled" : debugMode,
|
|
49
49
|
preventSubmit: (prevent) => {
|
|
50
50
|
setPreventSubmit(prevent);
|
|
51
51
|
},
|
|
@@ -53,41 +53,39 @@ var FormProvider = ({
|
|
|
53
53
|
validation
|
|
54
54
|
}),
|
|
55
55
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
56
|
-
[debugMode, debugModeSettings
|
|
56
|
+
[debugMode, debugModeSettings == null ? void 0 : debugModeSettings.disable]
|
|
57
57
|
);
|
|
58
|
-
const methods = useForm({
|
|
59
|
-
defaultValues: initialValues
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
const handleSubmit = async (e) => {
|
|
58
|
+
const methods = useForm(__spreadValues({
|
|
59
|
+
defaultValues: initialValues
|
|
60
|
+
}, validation ? {
|
|
61
|
+
// set rhf mode
|
|
62
|
+
// see: https://react-hook-form.com/docs/useform#mode
|
|
63
|
+
mode: validationTrigger,
|
|
64
|
+
resolver: (values) => __async(void 0, null, function* () {
|
|
65
|
+
const _a = yield validation.validateAsync(
|
|
66
|
+
toValidationFormat(values)
|
|
67
|
+
), { data, errors } = _a, rest = __objRest(_a, ["data", "errors"]);
|
|
68
|
+
return __spreadValues({ values: data || {}, errors: errors || {} }, rest);
|
|
69
|
+
})
|
|
70
|
+
} : {}));
|
|
71
|
+
const handleSubmit = (e) => __async(void 0, null, function* () {
|
|
74
72
|
if (methods.formState.isValid && preventSubmit) {
|
|
75
73
|
console.warn(
|
|
76
74
|
"[FormProvider] form submit was prevented because preventSubmit is true..."
|
|
77
75
|
);
|
|
78
|
-
e
|
|
76
|
+
e == null ? void 0 : e.preventDefault();
|
|
79
77
|
return Promise.resolve();
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
return /* @__PURE__ */ jsx(UniformContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(HookFormProvider, {
|
|
79
|
+
yield methods.handleSubmit(onSubmit)(e);
|
|
80
|
+
});
|
|
81
|
+
return /* @__PURE__ */ jsx(UniformContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(HookFormProvider, __spreadProps(__spreadValues({}, methods), { children: children({ handleSubmit }) })) });
|
|
84
82
|
};
|
|
85
83
|
var FormContext_default = FormProvider;
|
|
86
84
|
|
|
87
85
|
// src/hooks/useFormContext/useFormContext.ts
|
|
88
86
|
var checkFieldIsRequired = (validation, path) => {
|
|
89
87
|
const checkRequired = (schema) => {
|
|
90
|
-
if (schema.type === "array" && schema
|
|
88
|
+
if (schema.type === "array" && (schema == null ? void 0 : schema.minLength)) {
|
|
91
89
|
return true;
|
|
92
90
|
}
|
|
93
91
|
return !schema.isOptional && !schema.isNullable;
|
|
@@ -95,39 +93,41 @@ var checkFieldIsRequired = (validation, path) => {
|
|
|
95
93
|
return validation.checkSchemaPath(checkRequired, path);
|
|
96
94
|
};
|
|
97
95
|
var useFormContext = () => {
|
|
98
|
-
const {
|
|
96
|
+
const _a = useHookFormContext(), {
|
|
99
97
|
formState,
|
|
98
|
+
getFieldState: getFieldStateOrig
|
|
99
|
+
} = _a, otherMethods = __objRest(_a, [
|
|
100
|
+
"formState",
|
|
100
101
|
// https://react-hook-form.com/docs/useform/getfieldstate
|
|
101
102
|
// for getFieldState a subscription to formState properties is needed!
|
|
102
|
-
getFieldState
|
|
103
|
-
|
|
104
|
-
} = useHookFormContext();
|
|
103
|
+
"getFieldState"
|
|
104
|
+
]);
|
|
105
105
|
const uniformContext = useContext(UniformContext);
|
|
106
106
|
const getFieldState = (name, testId) => {
|
|
107
107
|
const fieldPath = typeof name === "string" ? name.replace(/\[\d+\]/g, "").split(".") : name;
|
|
108
|
-
const required = uniformContext
|
|
109
|
-
const { error,
|
|
110
|
-
return {
|
|
111
|
-
...rest,
|
|
108
|
+
const required = (uniformContext == null ? void 0 : uniformContext.validation) ? checkFieldIsRequired(uniformContext.validation, fieldPath) : false;
|
|
109
|
+
const _a2 = getFieldStateOrig(name, formState), { error } = _a2, rest = __objRest(_a2, ["error"]);
|
|
110
|
+
return __spreadProps(__spreadValues({}, rest), {
|
|
112
111
|
error,
|
|
113
112
|
// Ensure correct type for error
|
|
114
113
|
required,
|
|
115
114
|
testId: slugify(testId || name)
|
|
116
|
-
};
|
|
115
|
+
});
|
|
117
116
|
};
|
|
118
|
-
return {
|
|
119
|
-
...otherMethods,
|
|
120
|
-
...uniformContext,
|
|
117
|
+
return __spreadProps(__spreadValues(__spreadValues({}, otherMethods), uniformContext), {
|
|
121
118
|
getFieldState,
|
|
122
119
|
formState
|
|
123
|
-
};
|
|
120
|
+
});
|
|
124
121
|
};
|
|
125
122
|
|
|
123
|
+
// src/hooks/useInput/useInput.ts
|
|
124
|
+
import { useInput } from "@heroui/input";
|
|
125
|
+
|
|
126
126
|
export {
|
|
127
127
|
useFieldArray,
|
|
128
|
-
removeNullishFields,
|
|
129
128
|
FormContext_default,
|
|
130
129
|
checkFieldIsRequired,
|
|
131
|
-
useFormContext
|
|
130
|
+
useFormContext,
|
|
131
|
+
useInput
|
|
132
132
|
};
|
|
133
|
-
//# sourceMappingURL=chunk-
|
|
133
|
+
//# sourceMappingURL=chunk-T4N6TMUL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useFieldArray/useFieldArray.ts","../src/hooks/useFormContext/useFormContext.ts","../src/Form/subcomponents/FormContext.tsx","../src/hooks/useInput/useInput.ts"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\n\n/** @see https://react-hook-form.com/docs/usefieldarray */\nexport { useFieldArray } from 'react-hook-form';\n","import type { VetoInstance } from '@fuf-stack/veto';\nimport type { FieldError } from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useFormContext as useHookFormContext } from 'react-hook-form';\n\nimport { slugify } from '@fuf-stack/pixel-utils';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\n\n/** Schema check whether a field is required or optional */\nexport const checkFieldIsRequired = (\n validation: VetoInstance,\n path: string[],\n): boolean => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const checkRequired = (schema: any) => {\n // arrays with minLength are required\n if (schema.type === 'array' && schema?.minLength) {\n return true;\n }\n // all other fields are required if they are\n // not optional and not nullable\n return !schema.isOptional && !schema.isNullable;\n };\n\n return validation.checkSchemaPath(checkRequired, path);\n};\n\n/**\n * Custom hook that extends react-hook-form's useFormContext to add validation and state management.\n */\nexport const useFormContext = () => {\n const {\n formState,\n // https://react-hook-form.com/docs/useform/getfieldstate\n // for getFieldState a subscription to formState properties is needed!\n getFieldState: getFieldStateOrig,\n ...otherMethods\n } = useHookFormContext();\n\n const uniformContext = useContext(UniformContext);\n\n /**\n * Updated getFieldState method which returns:\n * - Whether the field is required by checking the validation schema\n * - Existing field state information (errors, etc.)\n */\n const getFieldState = (name: string, testId?: string) => {\n const fieldPath =\n typeof name === 'string' ? name.replace(/\\[\\d+\\]/g, '').split('.') : name;\n\n // Check if the field is required using the validation schema\n const required = uniformContext?.validation\n ? checkFieldIsRequired(uniformContext.validation, fieldPath)\n : false;\n\n // Get the original field state (errors, etc.) from react-hook-form\n const { error, ...rest } = getFieldStateOrig(name, formState);\n\n return {\n ...rest,\n error: error as FieldError[] | undefined, // Ensure correct type for error\n required,\n testId: slugify(testId || name),\n };\n };\n\n return {\n ...otherMethods,\n ...uniformContext,\n getFieldState,\n formState,\n };\n};\n","import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\n\nimport React, { useMemo, useState } from 'react';\nimport { FormProvider as HookFormProvider, useForm } from 'react-hook-form';\n\nimport { useLocalStorage } from '@fuf-stack/pixels';\n\nimport { toValidationFormat } from '../../helpers';\n\ntype DebugMode = 'debug' | 'debug-testids' | 'off' | 'disabled';\n\nexport type DebugModeSettings = {\n /** disable form debug completely */\n disable?: boolean;\n /** custom localStorage key to save debug mode state */\n localStorageKey?: string;\n};\n\nconst DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = 'uniform:debug-mode';\n\n/**\n * The `UniformContext` provides control over the form's submission behavior and may optionally include\n * a Veto validation schema for form validation.\n *\n * Specifically, this context offers:\n * 1. **Form Submission Control**: The `preventSubmit` function allows components to enable or disable\n * form submissions.\n * 2. **Optional Validation Schema**: The `validation` property may hold a Veto validation schema instance\n * that can be used to validate form fields and handle validation logic.\n *\n * This context is useful for components that need to interact with or control the form submission state,\n * or access the validation schema for managing form validation logic.\n */\nexport const UniformContext = React.createContext<{\n /** Form debug mode enabled or not */\n debugMode: DebugMode;\n /** settings for from debug mode */\n debugModeSettings?: DebugModeSettings;\n /** Function to update if the form can currently be submitted */\n preventSubmit: (prevent: boolean) => void;\n /** Setter to enable or disable form debug mode */\n setDebugMode: (debugMode: DebugMode) => void;\n /** Optional Veto validation schema instance for form validation */\n validation?: VetoInstance;\n}>({\n debugMode: 'off',\n preventSubmit: () => undefined,\n setDebugMode: () => undefined,\n validation: undefined,\n});\n\n// Define props for the FormProvider component, extending HookForm's props\ninterface FormProviderProps {\n /** children form render function */\n children: (childProps: {\n handleSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;\n }) => ReactNode;\n /** settings for from debug mode */\n debugModeSettings?: DebugModeSettings;\n /** initial form values */\n initialValues?: FieldValues;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** Veto validation schema instance */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';\n}\n\n/**\n * FormProvider component provides:\n * - The veto validation schema context\n * - Submit handler creation and submission control with preventSubmit\n * - Form Debug Mode state\n * - React Hook Form context\n */\nconst FormProvider: React.FC<FormProviderProps> = ({\n children,\n debugModeSettings = undefined,\n initialValues = undefined,\n onSubmit,\n validation = undefined,\n validationTrigger,\n}) => {\n // Control if the form can currently be submitted\n const [preventSubmit, setPreventSubmit] = useState(false);\n\n // Form Debug mode state is handled in the form context\n const [debugMode, setDebugMode] = useLocalStorage<DebugMode>(\n debugModeSettings?.localStorageKey || DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT,\n 'off',\n );\n\n // Memoize the context value to prevent re-renders\n const contextValue = useMemo(\n () => ({\n // set debugMode to disabled when debugModeSettings.disable is true\n // otherwise use current debug mode from localStorage\n debugMode: debugModeSettings?.disable ? 'disabled' : debugMode,\n preventSubmit: (prevent: boolean) => {\n setPreventSubmit(prevent);\n },\n setDebugMode,\n validation,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [debugMode, debugModeSettings?.disable],\n );\n\n // Initialize react hook form\n const methods = useForm({\n defaultValues: initialValues,\n // add validation config when validation schema provided\n ...(validation\n ? {\n // set rhf mode\n // see: https://react-hook-form.com/docs/useform#mode\n mode: validationTrigger,\n resolver: async (values) => {\n const { data, errors, ...rest } = await validation.validateAsync(\n toValidationFormat(values),\n );\n // https://github.com/react-hook-form/resolvers/blob/master/zod/src/zod.ts\n return { values: data || {}, errors: errors || {}, ...rest };\n },\n }\n : {}),\n });\n\n // Create submit handler\n // eslint-disable-next-line consistent-return\n const handleSubmit = async (e?: React.BaseSyntheticEvent) => {\n // only prevent submit when form state is valid, because otherwise\n // submit will only trigger validation and add errors / focus invalid fields\n if (methods.formState.isValid && preventSubmit) {\n console.warn(\n '[FormProvider] form submit was prevented because preventSubmit is true...',\n );\n e?.preventDefault();\n return Promise.resolve();\n }\n await methods.handleSubmit(onSubmit)(e);\n };\n\n return (\n <UniformContext.Provider value={contextValue}>\n {/* Spread all hook form props into HookFormProvider */}\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <HookFormProvider {...methods}>\n {children({ handleSubmit })}\n </HookFormProvider>\n </UniformContext.Provider>\n );\n};\n\nexport default FormProvider;\n","/* eslint-disable import/prefer-default-export */\nexport { useInput } from '@heroui/input';\n"],"mappings":";;;;;;;;;;;AAGA,SAAS,qBAAqB;;;ACA9B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB,0BAA0B;AAErD,SAAS,eAAe;;;ACFxB,OAAO,SAAS,SAAS,gBAAgB;AACzC,SAAS,gBAAgB,kB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