@fuf-stack/uniform 0.3.2 → 0.5.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/FieldArray/index.cjs +13 -0
- package/dist/FieldArray/index.cjs.map +1 -0
- package/dist/FieldArray/index.d.cts +8 -0
- package/dist/FieldArray/index.d.ts +8 -0
- package/dist/FieldArray/index.js +13 -0
- package/dist/FieldArray/index.js.map +1 -0
- package/dist/FieldArray-DUvn98Fe.d.cts +27 -0
- package/dist/FieldArray-DUvn98Fe.d.ts +27 -0
- package/dist/Form/index.cjs +2 -2
- package/dist/Form/index.js +1 -1
- package/dist/Grid/index.cjs +2 -2
- package/dist/Grid/index.js +1 -1
- package/dist/Input/index.cjs +3 -3
- package/dist/Input/index.d.cts +2 -2
- package/dist/Input/index.d.ts +2 -2
- package/dist/Input/index.js +2 -2
- package/dist/{Input-B_rP1h4X.d.cts → Input-B6dNQiiD.d.cts} +3 -1
- package/dist/{Input-B_rP1h4X.d.ts → Input-B6dNQiiD.d.ts} +3 -1
- package/dist/RadioGroup/index.cjs +13 -0
- package/dist/RadioGroup/index.cjs.map +1 -0
- package/dist/RadioGroup/index.d.cts +7 -0
- package/dist/RadioGroup/index.d.ts +7 -0
- package/dist/RadioGroup/index.js +13 -0
- package/dist/RadioGroup/index.js.map +1 -0
- package/dist/RadioGroup-BU4K9cnS.d.cts +40 -0
- package/dist/RadioGroup-BU4K9cnS.d.ts +40 -0
- package/dist/Select/index.cjs +13 -0
- package/dist/Select/index.cjs.map +1 -0
- package/dist/Select/index.d.cts +8 -0
- package/dist/Select/index.d.ts +8 -0
- package/dist/Select/index.js +13 -0
- package/dist/Select/index.js.map +1 -0
- package/dist/Select-Mp6Y00dT.d.cts +40 -0
- package/dist/Select-Mp6Y00dT.d.ts +40 -0
- package/dist/SubmitButton/index.cjs +2 -2
- package/dist/SubmitButton/index.js +1 -1
- package/dist/Switch/index.cjs +13 -0
- package/dist/Switch/index.cjs.map +1 -0
- package/dist/Switch/index.d.cts +7 -0
- package/dist/Switch/index.d.ts +7 -0
- package/dist/Switch/index.js +13 -0
- package/dist/Switch/index.js.map +1 -0
- package/dist/Switch-DmjDKgKs.d.cts +20 -0
- package/dist/Switch-DmjDKgKs.d.ts +20 -0
- package/dist/TextArea/index.cjs +13 -0
- package/dist/TextArea/index.cjs.map +1 -0
- package/dist/TextArea/index.d.cts +8 -0
- package/dist/TextArea/index.d.ts +8 -0
- package/dist/TextArea/index.js +13 -0
- package/dist/TextArea/index.js.map +1 -0
- package/dist/TextArea-B-sKvTkd.d.cts +25 -0
- package/dist/TextArea-B-sKvTkd.d.ts +25 -0
- package/dist/{chunk-3DMR7T4D.js → chunk-2Z3YMYNN.js} +8 -6
- package/dist/chunk-2Z3YMYNN.js.map +1 -0
- package/dist/chunk-4IT2WVQK.cjs +76 -0
- package/dist/chunk-4IT2WVQK.cjs.map +1 -0
- package/dist/{chunk-TEJGV6NC.js → chunk-5FMJUJ7H.js} +2 -2
- package/dist/chunk-5FMJUJ7H.js.map +1 -0
- package/dist/{chunk-ZPFKVKGV.cjs → chunk-6GN255GP.cjs} +4 -4
- package/dist/chunk-6GN255GP.cjs.map +1 -0
- package/dist/chunk-6NZVSPFX.js +76 -0
- package/dist/chunk-6NZVSPFX.js.map +1 -0
- package/dist/{chunk-XUKBLFTR.cjs → chunk-AGAYQTFD.cjs} +4 -4
- package/dist/chunk-AGAYQTFD.cjs.map +1 -0
- package/dist/chunk-BIJVBXOG.js +205 -0
- package/dist/chunk-BIJVBXOG.js.map +1 -0
- package/dist/{chunk-4BELEHDQ.cjs → chunk-BNTEIMNY.cjs} +5 -5
- package/dist/chunk-BNTEIMNY.cjs.map +1 -0
- package/dist/chunk-CRKMTDKU.js +239 -0
- package/dist/chunk-CRKMTDKU.js.map +1 -0
- package/dist/chunk-EXYTFHEJ.js +81 -0
- package/dist/chunk-EXYTFHEJ.js.map +1 -0
- package/dist/{chunk-22AA557I.cjs → chunk-HT3LKDHX.cjs} +4 -4
- package/dist/chunk-HT3LKDHX.cjs.map +1 -0
- package/dist/chunk-I22ICCUC.cjs +205 -0
- package/dist/chunk-I22ICCUC.cjs.map +1 -0
- package/dist/chunk-I26DVRVR.js +287 -0
- package/dist/chunk-I26DVRVR.js.map +1 -0
- package/dist/{chunk-6XKDXQ4A.js → chunk-KFRKKWZT.js} +3 -3
- package/dist/chunk-KFRKKWZT.js.map +1 -0
- package/dist/chunk-NVJKXQ5W.cjs +239 -0
- package/dist/chunk-NVJKXQ5W.cjs.map +1 -0
- package/dist/chunk-OS4SMYPO.cjs +287 -0
- package/dist/chunk-OS4SMYPO.cjs.map +1 -0
- package/dist/{chunk-FNVT6LS4.js → chunk-OV5RMSYD.js} +2 -2
- package/dist/{chunk-22AA557I.cjs.map → chunk-OV5RMSYD.js.map} +1 -1
- package/dist/{chunk-4MEKDDB2.js → chunk-PDCEKC3G.js} +2 -2
- package/dist/chunk-PDCEKC3G.js.map +1 -0
- package/dist/{chunk-2O53LMR3.cjs → chunk-VO7ZM3KY.cjs} +11 -9
- package/dist/chunk-VO7ZM3KY.cjs.map +1 -0
- package/dist/chunk-XY7ZZARS.cjs +81 -0
- package/dist/chunk-XY7ZZARS.cjs.map +1 -0
- package/dist/hooks/index.d.cts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/index.cjs +27 -7
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +29 -9
- package/dist/partials/FieldCopyTestIdButton/index.cjs +2 -2
- package/dist/partials/FieldCopyTestIdButton/index.js +1 -1
- package/package.json +41 -17
- package/dist/chunk-2O53LMR3.cjs.map +0 -1
- package/dist/chunk-3DMR7T4D.js.map +0 -1
- package/dist/chunk-4BELEHDQ.cjs.map +0 -1
- package/dist/chunk-4MEKDDB2.js.map +0 -1
- package/dist/chunk-6XKDXQ4A.js.map +0 -1
- package/dist/chunk-FNVT6LS4.js.map +0 -1
- package/dist/chunk-TEJGV6NC.js.map +0 -1
- package/dist/chunk-XUKBLFTR.cjs.map +0 -1
- package/dist/chunk-ZPFKVKGV.cjs.map +0 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkHT3LKDHXcjs = require('./chunk-HT3LKDHX.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkQTL5FREEcjs = require('./chunk-QTL5FREE.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkWQRM7G4Ccjs = require('./chunk-WQRM7G4C.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkBBB4FEY6cjs = require('./chunk-BBB4FEY6.cjs');
|
|
13
|
+
|
|
14
|
+
// src/RadioGroup/RadioGroup.tsx
|
|
15
|
+
var _reacthookform = require('react-hook-form');
|
|
16
|
+
var _button = require('@nextui-org/button');
|
|
17
|
+
var _radio = require('@nextui-org/radio');
|
|
18
|
+
var _pixelutils = require('@fuf-stack/pixel-utils');
|
|
19
|
+
|
|
20
|
+
// src/RadioGroup/Variants/RadioBox.tsx
|
|
21
|
+
|
|
22
|
+
var _visuallyhidden = require('@react-aria/visually-hidden');
|
|
23
|
+
|
|
24
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
25
|
+
var RadioBox = ({ icon = void 0, ...props }) => {
|
|
26
|
+
const {
|
|
27
|
+
children,
|
|
28
|
+
Component,
|
|
29
|
+
description,
|
|
30
|
+
getBaseProps,
|
|
31
|
+
getControlProps,
|
|
32
|
+
getInputProps,
|
|
33
|
+
getLabelProps,
|
|
34
|
+
getLabelWrapperProps,
|
|
35
|
+
getWrapperProps,
|
|
36
|
+
isDisabled
|
|
37
|
+
} = _radio.useRadio.call(void 0, props);
|
|
38
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
39
|
+
Component,
|
|
40
|
+
{
|
|
41
|
+
...getBaseProps(),
|
|
42
|
+
className: _pixelutils.cn.call(void 0,
|
|
43
|
+
"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-primary",
|
|
44
|
+
{
|
|
45
|
+
// disabled styles
|
|
46
|
+
"pointer-events-none opacity-disabled": isDisabled
|
|
47
|
+
}
|
|
48
|
+
),
|
|
49
|
+
children: [
|
|
50
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _visuallyhidden.VisuallyHidden, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "input", { ...getInputProps() }) }),
|
|
51
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...getWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...getControlProps() }) }),
|
|
52
|
+
icon,
|
|
53
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
54
|
+
"div",
|
|
55
|
+
{
|
|
56
|
+
...getLabelWrapperProps(),
|
|
57
|
+
className: _pixelutils.cn.call(void 0, getLabelWrapperProps().className, "grow"),
|
|
58
|
+
children: [
|
|
59
|
+
children && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...getLabelProps(), children }),
|
|
60
|
+
description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-small text-foreground opacity-70", children: description })
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/RadioGroup/Variants/RadioButton.tsx
|
|
70
|
+
|
|
71
|
+
var _pixels = require('@fuf-stack/pixels');
|
|
72
|
+
|
|
73
|
+
var RadioButton = ({
|
|
74
|
+
className = void 0,
|
|
75
|
+
value,
|
|
76
|
+
isDisabled = false,
|
|
77
|
+
onChange,
|
|
78
|
+
children
|
|
79
|
+
}) => {
|
|
80
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
81
|
+
_pixels.Button,
|
|
82
|
+
{
|
|
83
|
+
className: _pixelutils.cn.call(void 0, className),
|
|
84
|
+
disabled: isDisabled,
|
|
85
|
+
onClick: () => {
|
|
86
|
+
return onChange(value);
|
|
87
|
+
},
|
|
88
|
+
children
|
|
89
|
+
},
|
|
90
|
+
`index_${value}`
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/RadioGroup/RadioGroup.tsx
|
|
95
|
+
|
|
96
|
+
var RadioGroup = ({
|
|
97
|
+
className = void 0,
|
|
98
|
+
disabled = false,
|
|
99
|
+
inline = false,
|
|
100
|
+
label = void 0,
|
|
101
|
+
name,
|
|
102
|
+
options,
|
|
103
|
+
testId: _testId = void 0,
|
|
104
|
+
variant = "default"
|
|
105
|
+
}) => {
|
|
106
|
+
const { control, getFieldState, getValues } = _chunkWQRM7G4Ccjs.useFormContext.call(void 0, );
|
|
107
|
+
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
108
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
109
|
+
_reacthookform.Controller,
|
|
110
|
+
{
|
|
111
|
+
control,
|
|
112
|
+
disabled,
|
|
113
|
+
name,
|
|
114
|
+
render: ({ field: { onChange, disabled: isDisabled, onBlur, ref } }) => {
|
|
115
|
+
let RadioComponents;
|
|
116
|
+
switch (variant) {
|
|
117
|
+
case "radioBox":
|
|
118
|
+
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
119
|
+
RadioBox,
|
|
120
|
+
{
|
|
121
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
122
|
+
`${testId}_option_${option.testId || option.value}`
|
|
123
|
+
),
|
|
124
|
+
isDisabled: isDisabled || option.disabled,
|
|
125
|
+
value: option.value,
|
|
126
|
+
onChange,
|
|
127
|
+
description: option.description,
|
|
128
|
+
icon: option.icon,
|
|
129
|
+
children: option.label ? option.label : option.value
|
|
130
|
+
},
|
|
131
|
+
option.value
|
|
132
|
+
));
|
|
133
|
+
break;
|
|
134
|
+
case "radioButton":
|
|
135
|
+
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
136
|
+
RadioButton,
|
|
137
|
+
{
|
|
138
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
139
|
+
`${testId}_option_${option.testId || option.value}`
|
|
140
|
+
),
|
|
141
|
+
isDisabled: isDisabled || option.disabled,
|
|
142
|
+
value: option.value,
|
|
143
|
+
onChange,
|
|
144
|
+
className: _pixelutils.cn.call(void 0,
|
|
145
|
+
`${getValues()[name] !== option.value ? "bg-opacity-50" : ""}`
|
|
146
|
+
),
|
|
147
|
+
children: option.label ? option.label : option.value
|
|
148
|
+
},
|
|
149
|
+
option.value
|
|
150
|
+
));
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
154
|
+
_radio.Radio,
|
|
155
|
+
{
|
|
156
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
157
|
+
`${testId}_option_${option.testId || option.value}`
|
|
158
|
+
),
|
|
159
|
+
isDisabled: isDisabled || option.disabled,
|
|
160
|
+
value: option.value,
|
|
161
|
+
onChange,
|
|
162
|
+
children: option.label ? option.label : option.value
|
|
163
|
+
},
|
|
164
|
+
option.value
|
|
165
|
+
));
|
|
166
|
+
}
|
|
167
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
168
|
+
_radio.RadioGroup,
|
|
169
|
+
{
|
|
170
|
+
className,
|
|
171
|
+
"data-testid": testId,
|
|
172
|
+
errorMessage: error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQTL5FREEcjs.FieldValidationError_default, { error }),
|
|
173
|
+
isDisabled,
|
|
174
|
+
isInvalid: invalid,
|
|
175
|
+
isRequired: required,
|
|
176
|
+
label: label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
177
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { className: `${invalid ? "text-danger" : ""}`, children: [
|
|
178
|
+
label,
|
|
179
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkHT3LKDHXcjs.FieldCopyTestIdButton_default, { testId })
|
|
180
|
+
] }),
|
|
181
|
+
orientation: inline ? "horizontal" : "vertical",
|
|
182
|
+
onBlur,
|
|
183
|
+
onChange,
|
|
184
|
+
name,
|
|
185
|
+
ref,
|
|
186
|
+
children: variant === "radioButton" ? (
|
|
187
|
+
// TODO: NextButtonGroup uses ref to modify Button style, but we wrap it, so it does not work at the moment.
|
|
188
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _button.ButtonGroup, { children: RadioComponents })
|
|
189
|
+
) : RadioComponents
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
var RadioGroup_default = RadioGroup;
|
|
197
|
+
|
|
198
|
+
// src/RadioGroup/index.ts
|
|
199
|
+
var RadioGroup_default2 = RadioGroup_default;
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
exports.RadioGroup_default = RadioGroup_default; exports.RadioGroup_default2 = RadioGroup_default2;
|
|
205
|
+
//# sourceMappingURL=chunk-I22ICCUC.cjs.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"],"names":["cn","jsx","jsxs","RadioGroup_default"],"mappings":";;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAE3B,SAAS,eAAe,uBAAuB;AAC/C,SAAS,cAAc,gBAAgB,aAAa;AAEpD,SAAS,MAAAA,WAAU;;;ACJnB,SAAS,gBAAgB;A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A,gBAC9D;AAAA,gBAEC,iBAAO,QAAQ,OAAO,QAAQ,OAAO;AAAA;AAAA,cAZjC,OAAO;AAAA,YAad,CACD;AACD;AAAA,UACF;AACE,8BAAkB,QAAQ,IAAI,CAAC,WAC7B,gBAAAC;AAAA,cAAC;AAAA;AAAA,gBAEC,eAAa;AAAA,kBACX,GAAG,MAAM,WAAW,OAAO,UAAU,OAAO,KAAK;AAAA,gBACnD;AAAA,gBACA,YAAY,cAAc,OAAO;AAAA,gBACjC,OAAO,OAAO;AAAA,gBACd;AAAA,gBAEC,iBAAO,QAAQ,OAAO,QAAQ,OAAO;AAAA;AAAA,cARjC,OAAO;AAAA,YASd,CACD;AAAA,QACL;AAEA,eACE,gBAAAA;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA,eAAa;AAAA,YACb,cAAc,SAAS,gBAAAA,KAAC,gCAAqB,OAAc;AAAA,YAC3D;AAAA,YACA,WAAW;AAAA,YACX,YAAY;AAAA,YACZ,OACE;AAAA,YAEE,gBAAAC,MAAC,WAAM,WAAW,GAAG,UAAU,gBAAgB,EAAE,IAC9C;AAAA;AAAA,cACD,gBAAAD,KAAC,iCAAsB,QAAgB;AAAA,eACzC;AAAA,YAGJ,aAAa,SAAS,eAAe;AAAA,YACrC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YAEC,sBAAY;AAAA;AAAA,cAEX,gBAAAA,KAAC,mBAAiB,2BAAgB;AAAA,gBAElC;AAAA;AAAA,QAEJ;AAAA,MAEJ;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,qBAAQ;;;AG7Jf,IAAOE,sBAAQ","sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport { Controller } from 'react-hook-form';\n\nimport { ButtonGroup as NextButtonGroup } from '@nextui-org/button';\nimport { RadioGroup as NextRadioGroup, Radio } from '@nextui-org/radio';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { slugify } from '../helpers';\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 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 /** CSS class name */\n className?: string;\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: RadioGroupOption[];\n /** Id to grab element in internal tests. */\n testId?: string;\n /** How the RadioGroup should look like. */\n variant?: 'default' | 'radioBox' | 'radioButton';\n}\n\n/**\n * RadioGroup component based on [NextUI RadioGroup](https://nextui.org/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): ReactElement => {\n const { control, getFieldState, getValues } = useFormContext();\n\n const { error, invalid, required, testId } = getFieldState(name, _testId);\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 switch (variant) {\n case 'radioBox':\n RadioComponents = options.map((option) => (\n <RadioBox\n key={option.value}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n isDisabled={isDisabled || option.disabled}\n value={option.value}\n onChange={onChange}\n description={option.description}\n icon={option.icon}\n >\n {option.label ? option.label : option.value}\n </RadioBox>\n ));\n break;\n case 'radioButton':\n RadioComponents = options.map((option) => (\n <RadioButton\n key={option.value}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n isDisabled={isDisabled || option.disabled}\n value={option.value}\n onChange={onChange}\n // TODO: how to do the classNames properly (make selected option darker with same color)\n className={cn(\n `${getValues()[name] !== option.value ? 'bg-opacity-50' : ''}`,\n )}\n >\n {option.label ? option.label : option.value}\n </RadioButton>\n ));\n break;\n default:\n RadioComponents = options.map((option) => (\n <Radio\n key={option.value}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n isDisabled={isDisabled || option.disabled}\n value={option.value}\n onChange={onChange}\n >\n {option.label ? option.label : option.value}\n </Radio>\n ));\n }\n\n return (\n <NextRadioGroup\n className={className}\n data-testid={testId}\n errorMessage={error && <FieldValidationError error={error} />}\n isDisabled={isDisabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label className={`${invalid ? 'text-danger' : ''}`}>\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </label>\n )\n }\n orientation={inline ? 'horizontal' : 'vertical'}\n onBlur={onBlur}\n onChange={onChange}\n name={name}\n ref={ref}\n >\n {variant === 'radioButton' ? (\n // TODO: NextButtonGroup uses ref to modify Button style, but we wrap it, so it does not work at the moment.\n <NextButtonGroup>{RadioComponents}</NextButtonGroup>\n ) : (\n RadioComponents\n )}\n </NextRadioGroup>\n );\n }}\n />\n );\n};\n\nexport default RadioGroup;\n","import type { RadioProps as NextRadioProps } from '@nextui-org/radio';\nimport type { ReactNode } from 'react';\n\nimport { useRadio } from '@nextui-org/radio';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\ninterface RadioProps extends NextRadioProps {\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-primary',\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 /** 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 className = undefined,\n value,\n isDisabled = false,\n onChange,\n children,\n}: RadioButtonProps) => {\n return (\n <Button\n key={`index_${value}`}\n className={cn(className)}\n disabled={isDisabled}\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"]}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldCopyTestIdButton_default
|
|
3
|
+
} from "./chunk-OV5RMSYD.js";
|
|
4
|
+
import {
|
|
5
|
+
FieldValidationError_default
|
|
6
|
+
} from "./chunk-DBLODROX.js";
|
|
7
|
+
import {
|
|
8
|
+
useFormContext
|
|
9
|
+
} from "./chunk-BCMPSLSG.js";
|
|
10
|
+
import {
|
|
11
|
+
slugify
|
|
12
|
+
} from "./chunk-V46BHM2U.js";
|
|
13
|
+
|
|
14
|
+
// src/FieldArray/FieldArray.tsx
|
|
15
|
+
import { useEffect as useEffect2 } from "react";
|
|
16
|
+
import { useFieldArray } from "react-hook-form";
|
|
17
|
+
import {
|
|
18
|
+
closestCenter,
|
|
19
|
+
DndContext,
|
|
20
|
+
KeyboardSensor,
|
|
21
|
+
PointerSensor,
|
|
22
|
+
useSensor,
|
|
23
|
+
useSensors
|
|
24
|
+
} from "@dnd-kit/core";
|
|
25
|
+
import {
|
|
26
|
+
restrictToVerticalAxis,
|
|
27
|
+
restrictToWindowEdges
|
|
28
|
+
} from "@dnd-kit/modifiers";
|
|
29
|
+
import {
|
|
30
|
+
SortableContext,
|
|
31
|
+
verticalListSortingStrategy
|
|
32
|
+
} from "@dnd-kit/sortable";
|
|
33
|
+
import { useInput as useInput2 } from "@nextui-org/input";
|
|
34
|
+
import { Button as Button2 } from "@fuf-stack/pixels";
|
|
35
|
+
|
|
36
|
+
// src/FieldArray/FieldArrayField.tsx
|
|
37
|
+
import { useEffect } from "react";
|
|
38
|
+
import { FaAngleDown, FaAngleUp, FaGripLines } from "react-icons/fa";
|
|
39
|
+
import { useSortable } from "@dnd-kit/sortable";
|
|
40
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
41
|
+
import { useInput } from "@nextui-org/input";
|
|
42
|
+
import { Button } from "@fuf-stack/pixels";
|
|
43
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
44
|
+
var FieldArrayField = ({
|
|
45
|
+
children,
|
|
46
|
+
className = void 0,
|
|
47
|
+
field,
|
|
48
|
+
fields,
|
|
49
|
+
hideButtons = [],
|
|
50
|
+
id,
|
|
51
|
+
index,
|
|
52
|
+
insert,
|
|
53
|
+
lastNotDeletable = true,
|
|
54
|
+
move,
|
|
55
|
+
moveField,
|
|
56
|
+
name,
|
|
57
|
+
remove,
|
|
58
|
+
testId = void 0
|
|
59
|
+
}) => {
|
|
60
|
+
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
|
|
61
|
+
const style = {
|
|
62
|
+
transform: CSS.Translate.toString(transform),
|
|
63
|
+
transition
|
|
64
|
+
};
|
|
65
|
+
const { getFieldState, register, watch, trigger } = useFormContext();
|
|
66
|
+
const { error, invalid } = getFieldState(`${name}`, void 0);
|
|
67
|
+
const { getHelperWrapperProps, getErrorMessageProps } = useInput({
|
|
68
|
+
isInvalid: invalid,
|
|
69
|
+
errorMessage: JSON.stringify(error),
|
|
70
|
+
labelPlacement: "inside",
|
|
71
|
+
placeholder: " ",
|
|
72
|
+
classNames: { helperWrapper: "block" }
|
|
73
|
+
});
|
|
74
|
+
register(`${name}.${index}._errors`);
|
|
75
|
+
const formValues = watch();
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
trigger(`${name}.${index}._errors`);
|
|
78
|
+
}, [JSON.stringify(formValues)]);
|
|
79
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ jsxs("li", { ref: setNodeRef, style, className, children: [
|
|
81
|
+
!hideButtons.includes("move") && !hideButtons.includes("all") && /* @__PURE__ */ jsxs("div", { className: "mr-6 flex flex-row items-center", children: [
|
|
82
|
+
moveField.includes("drag-drop") && /* @__PURE__ */ jsx(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
className: "mr-2 text-base text-xl",
|
|
86
|
+
"data-testid": slugify(`${name}_${index}_movebutton`),
|
|
87
|
+
...attributes,
|
|
88
|
+
...listeners,
|
|
89
|
+
children: /* @__PURE__ */ jsx(FaGripLines, {})
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
moveField.includes("button") && /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
Button,
|
|
95
|
+
{
|
|
96
|
+
testId: `${name}.${index}.up`,
|
|
97
|
+
disabled: index === 0,
|
|
98
|
+
onClick: () => move(index, index - 1),
|
|
99
|
+
className: "flex rounded-b-none rounded-t-md border border-gray-300 px-2 py-2 shadow-sm",
|
|
100
|
+
children: /* @__PURE__ */ jsx(FaAngleUp, {})
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
/* @__PURE__ */ jsx(
|
|
104
|
+
Button,
|
|
105
|
+
{
|
|
106
|
+
testId: `${name}.${index}.down`,
|
|
107
|
+
disabled: index === fields.length - 1,
|
|
108
|
+
onClick: () => move(index, index + 1),
|
|
109
|
+
className: "flex rounded-b-md rounded-t-none border border-gray-300 px-2 py-2 shadow-sm",
|
|
110
|
+
children: /* @__PURE__ */ jsx(FaAngleDown, {})
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
] })
|
|
114
|
+
] }),
|
|
115
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full", children: [
|
|
116
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center", children: [
|
|
117
|
+
/* @__PURE__ */ jsx("div", { className: "flex-grow", "data-testid": testId, children }),
|
|
118
|
+
!hideButtons.includes("remove") && !hideButtons.includes("all") && (lastNotDeletable && fields.length === 1 ? null : /* @__PURE__ */ jsx(Button, { onClick: () => remove(index), className: "ml-1", children: /* @__PURE__ */ jsx(
|
|
119
|
+
"svg",
|
|
120
|
+
{
|
|
121
|
+
className: "h-4 w-4",
|
|
122
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
123
|
+
viewBox: "0 0 20 20",
|
|
124
|
+
fill: "currentColor",
|
|
125
|
+
"aria-hidden": "true",
|
|
126
|
+
children: /* @__PURE__ */ jsx(
|
|
127
|
+
"path",
|
|
128
|
+
{
|
|
129
|
+
fillRule: "evenodd",
|
|
130
|
+
d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
|
|
131
|
+
clipRule: "evenodd"
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
) }))
|
|
136
|
+
] }),
|
|
137
|
+
!hideButtons.includes("insert") && !hideButtons.includes("all") && index !== fields.length - 1 ? /* @__PURE__ */ jsx(
|
|
138
|
+
Button,
|
|
139
|
+
{
|
|
140
|
+
className: "text-xs font-medium",
|
|
141
|
+
testId: `add-harbor-button-${index}`,
|
|
142
|
+
onClick: () => {
|
|
143
|
+
insert(index + 1, {});
|
|
144
|
+
},
|
|
145
|
+
children: "insert"
|
|
146
|
+
}
|
|
147
|
+
) : null
|
|
148
|
+
] }, `rest-${field.id}`)
|
|
149
|
+
] }),
|
|
150
|
+
error && typeof error[index] !== "undefined" && // @ts-expect-error rhf incompatibility
|
|
151
|
+
error[Number(index)]?._errors && // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)
|
|
152
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
153
|
+
/* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx(FieldValidationError_default, { error: error[Number(index)]?._errors }) }) })
|
|
154
|
+
] });
|
|
155
|
+
};
|
|
156
|
+
var FieldArrayField_default = FieldArrayField;
|
|
157
|
+
|
|
158
|
+
// src/FieldArray/FieldArray.tsx
|
|
159
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
160
|
+
var FieldArray = ({
|
|
161
|
+
children,
|
|
162
|
+
hideButtons = [],
|
|
163
|
+
label: _label = void 0,
|
|
164
|
+
lastNotDeletable = true,
|
|
165
|
+
name,
|
|
166
|
+
testId: _testId = void 0,
|
|
167
|
+
moveField = ["button"]
|
|
168
|
+
}) => {
|
|
169
|
+
const { control, getValues, getFieldState, register, trigger, watch } = useFormContext();
|
|
170
|
+
const { fields, append, remove, insert, move } = useFieldArray({
|
|
171
|
+
control,
|
|
172
|
+
name
|
|
173
|
+
});
|
|
174
|
+
const { error, testId, invalid, required } = getFieldState(name, _testId);
|
|
175
|
+
register(`${name}._errors`);
|
|
176
|
+
const formValues = watch();
|
|
177
|
+
useEffect2(() => {
|
|
178
|
+
trigger(`${name}._errors`);
|
|
179
|
+
}, [JSON.stringify(formValues)]);
|
|
180
|
+
const { label, getLabelProps, getHelperWrapperProps, getErrorMessageProps } = useInput2({
|
|
181
|
+
isInvalid: invalid,
|
|
182
|
+
isRequired: required,
|
|
183
|
+
errorMessage: JSON.stringify(error),
|
|
184
|
+
label: _label,
|
|
185
|
+
labelPlacement: "inside",
|
|
186
|
+
placeholder: " ",
|
|
187
|
+
classNames: { helperWrapper: "block" }
|
|
188
|
+
});
|
|
189
|
+
if (lastNotDeletable && fields.length === 0) {
|
|
190
|
+
append({});
|
|
191
|
+
}
|
|
192
|
+
const sensors = useSensors(
|
|
193
|
+
useSensor(PointerSensor),
|
|
194
|
+
useSensor(KeyboardSensor)
|
|
195
|
+
);
|
|
196
|
+
const handleDragEnd = (event) => {
|
|
197
|
+
const { active, over } = event;
|
|
198
|
+
if (active.id !== over?.id) {
|
|
199
|
+
const oldIndex = fields.findIndex((field) => field.id === active.id);
|
|
200
|
+
const newIndex = fields.findIndex((field) => field.id === over?.id);
|
|
201
|
+
move(oldIndex, newIndex);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
return /* @__PURE__ */ jsx2(
|
|
205
|
+
DndContext,
|
|
206
|
+
{
|
|
207
|
+
sensors,
|
|
208
|
+
collisionDetection: closestCenter,
|
|
209
|
+
onDragEnd: handleDragEnd,
|
|
210
|
+
modifiers: [restrictToVerticalAxis, restrictToWindowEdges],
|
|
211
|
+
children: /* @__PURE__ */ jsx2(
|
|
212
|
+
SortableContext,
|
|
213
|
+
{
|
|
214
|
+
items: fields.map((field) => field.id),
|
|
215
|
+
strategy: verticalListSortingStrategy,
|
|
216
|
+
children: /* @__PURE__ */ jsxs2("ul", { "data-testid": testId, children: [
|
|
217
|
+
label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
218
|
+
/* @__PURE__ */ jsx2(
|
|
219
|
+
"label",
|
|
220
|
+
{
|
|
221
|
+
...getLabelProps(),
|
|
222
|
+
className: `${getLabelProps().className} !pointer-events-auto !static !z-0 -mb-1 ml-1 !inline-block`,
|
|
223
|
+
children: label
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ jsx2(FieldCopyTestIdButton_default, { testId }),
|
|
227
|
+
fields.map((field, index) => {
|
|
228
|
+
const duplicate = (i) => {
|
|
229
|
+
const values = getValues(name);
|
|
230
|
+
insert(i + 1, { ...values[i], id: null });
|
|
231
|
+
};
|
|
232
|
+
return /* @__PURE__ */ jsx2(
|
|
233
|
+
FieldArrayField_default,
|
|
234
|
+
{
|
|
235
|
+
id: field.id,
|
|
236
|
+
testId: `${testId}_${index}`,
|
|
237
|
+
className: "mb-3 mt-5 flex flex-row items-center",
|
|
238
|
+
field,
|
|
239
|
+
fields,
|
|
240
|
+
hideButtons,
|
|
241
|
+
index,
|
|
242
|
+
insert,
|
|
243
|
+
lastNotDeletable,
|
|
244
|
+
move,
|
|
245
|
+
moveField,
|
|
246
|
+
name,
|
|
247
|
+
remove,
|
|
248
|
+
children: children(
|
|
249
|
+
`${name}[${index}]`,
|
|
250
|
+
index,
|
|
251
|
+
fields.length,
|
|
252
|
+
move,
|
|
253
|
+
insert,
|
|
254
|
+
remove,
|
|
255
|
+
duplicate
|
|
256
|
+
)
|
|
257
|
+
},
|
|
258
|
+
field.id
|
|
259
|
+
);
|
|
260
|
+
}),
|
|
261
|
+
!hideButtons.includes("add") && !hideButtons.includes("all") && /* @__PURE__ */ jsx2(
|
|
262
|
+
Button2,
|
|
263
|
+
{
|
|
264
|
+
testId: `${testId}_append`,
|
|
265
|
+
size: "sm",
|
|
266
|
+
onClick: () => append({}),
|
|
267
|
+
children: "Add"
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
error?._errors && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
271
|
+
/* @__PURE__ */ jsx2("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx2("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx2(FieldValidationError_default, { error: error?._errors }) }) })
|
|
272
|
+
] })
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
var FieldArray_default = FieldArray;
|
|
279
|
+
|
|
280
|
+
// src/FieldArray/index.ts
|
|
281
|
+
var FieldArray_default2 = FieldArray_default;
|
|
282
|
+
|
|
283
|
+
export {
|
|
284
|
+
FieldArray_default,
|
|
285
|
+
FieldArray_default2
|
|
286
|
+
};
|
|
287
|
+
//# sourceMappingURL=chunk-I26DVRVR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/FieldArray/FieldArray.tsx","../src/FieldArray/FieldArrayField.tsx","../src/FieldArray/index.ts"],"sourcesContent":["import type { DragEndEvent } from '@dnd-kit/core';\nimport type {\n FieldValues,\n UseFieldArrayInsert,\n UseFieldArrayMove,\n UseFieldArrayRemove,\n} from 'react-hook-form';\n\nimport { useEffect } from 'react';\nimport { useFieldArray } from 'react-hook-form';\n\nimport {\n closestCenter,\n DndContext,\n KeyboardSensor,\n PointerSensor,\n useSensor,\n useSensors,\n} from '@dnd-kit/core';\nimport {\n restrictToVerticalAxis,\n restrictToWindowEdges,\n} from '@dnd-kit/modifiers';\nimport {\n SortableContext,\n verticalListSortingStrategy,\n} from '@dnd-kit/sortable';\nimport { useInput } from '@nextui-org/input';\n\nimport { Button } from '@fuf-stack/pixels';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\nimport FieldArrayField from './FieldArrayField';\n\nexport type FieldArrayHideOption = 'add' | 'remove' | 'move' | 'insert' | 'all';\nexport type FieldArrayFieldChildren = (\n name: string,\n index: number,\n length: number,\n move: UseFieldArrayMove,\n insert: UseFieldArrayInsert<FieldValues, string>,\n remove: UseFieldArrayRemove,\n duplicate: (i: number) => void,\n) => JSX.Element;\n\nexport type MoveField = 'drag-drop' | 'button';\n\nexport interface FieldArrayProps {\n /** function that renders the children with provided Properties. */\n children: FieldArrayFieldChildren;\n /** Hide a set of buttons. */\n hideButtons?: FieldArrayHideOption[];\n /** label of the FieldArray. */\n label?: React.ReactNode;\n /** stops user from deleting all items. */\n lastNotDeletable?: boolean;\n /** name the FieldArray is registered in RHF */\n name: string;\n /** ID for test purposes. */\n testId?: string;\n /* how the fields can be moved */\n moveField: MoveField[];\n}\n\n/**\n * FieldArray component using react-hook-form\n */\nconst FieldArray = ({\n children,\n hideButtons = [],\n label: _label = undefined,\n lastNotDeletable = true,\n name,\n testId: _testId = undefined,\n moveField = ['button'],\n}: FieldArrayProps) => {\n const { control, getValues, getFieldState, register, trigger, watch } =\n useFormContext();\n\n const { fields, append, remove, insert, move } = useFieldArray({\n control,\n name,\n });\n\n const { error, testId, invalid, required } = getFieldState(name, _testId);\n\n register(`${name}._errors`);\n\n const formValues = watch();\n\n useEffect(() => {\n trigger(`${name}._errors`);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(formValues)]);\n\n // TODO: what about input props?\n const { label, getLabelProps, getHelperWrapperProps, getErrorMessageProps } =\n useInput({\n isInvalid: invalid,\n isRequired: required,\n errorMessage: JSON.stringify(error),\n label: _label,\n labelPlacement: 'inside',\n placeholder: ' ',\n classNames: { helperWrapper: 'block' },\n });\n\n if (lastNotDeletable && fields.length === 0) {\n append({});\n }\n\n const sensors = useSensors(\n useSensor(PointerSensor),\n useSensor(KeyboardSensor),\n );\n\n const handleDragEnd = (event: DragEndEvent) => {\n const { active, over } = event;\n\n if (active.id !== over?.id) {\n const oldIndex = fields.findIndex((field) => field.id === active.id);\n const newIndex = fields.findIndex((field) => field.id === over?.id);\n move(oldIndex, newIndex);\n }\n };\n return (\n <DndContext\n sensors={sensors}\n collisionDetection={closestCenter}\n onDragEnd={handleDragEnd}\n modifiers={[restrictToVerticalAxis, restrictToWindowEdges]}\n >\n <SortableContext\n items={fields.map((field) => field.id)}\n strategy={verticalListSortingStrategy}\n >\n <ul data-testid={testId}>\n {label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getLabelProps()}\n className={`${getLabelProps().className} !pointer-events-auto !static !z-0 -mb-1 ml-1 !inline-block`}\n >\n {label}\n </label>\n )}\n <FieldCopyTestIdButton testId={testId} />\n\n {fields.map((field, index) => {\n const duplicate = (i: number) => {\n const values = getValues(name);\n insert(i + 1, { ...values[i], id: null });\n };\n\n return (\n <FieldArrayField\n id={field.id}\n key={field.id}\n testId={`${testId}_${index}`}\n className=\"mb-3 mt-5 flex flex-row items-center\"\n field={field}\n fields={fields}\n hideButtons={hideButtons}\n index={index}\n insert={insert}\n lastNotDeletable={lastNotDeletable}\n move={move}\n moveField={moveField}\n name={name}\n remove={remove}\n >\n {children(\n `${name}[${index}]`,\n index,\n fields.length,\n move,\n insert,\n remove,\n duplicate,\n )}\n </FieldArrayField>\n );\n })}\n\n {!hideButtons.includes('add') && !hideButtons.includes('all') && (\n <Button\n testId={`${testId}_append`}\n size=\"sm\"\n onClick={() => append({})}\n >\n Add\n </Button>\n )}\n {/* @ts-expect-error rhf incompatibility */}\n {error?._errors && (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div {...getHelperWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <div {...getErrorMessageProps()}>\n {/* @ts-expect-error rhf incompatibility */}\n <FieldValidationError error={error?._errors} />\n </div>\n </div>\n )}\n </ul>\n </SortableContext>\n </DndContext>\n );\n};\n\nexport default FieldArray;\n","import type {\n FieldValues,\n UseFieldArrayInsert,\n UseFieldArrayMove,\n UseFieldArrayRemove,\n} from 'react-hook-form';\nimport type { FieldArrayHideOption, MoveField } from './FieldArray';\n\nimport { useEffect } from 'react';\nimport { FaAngleDown, FaAngleUp, FaGripLines } from 'react-icons/fa';\n\nimport { useSortable } from '@dnd-kit/sortable';\nimport { CSS } from '@dnd-kit/utilities';\nimport { useInput } from '@nextui-org/input';\n\nimport { Button } from '@fuf-stack/pixels';\n\nimport { slugify } from '../helpers';\nimport { useFormContext } from '../hooks';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\ninterface FieldArrayFieldProps {\n children: React.ReactNode;\n className?: string;\n field: Record<'id', string>;\n fields: Record<'id', string>[];\n hideButtons?: FieldArrayHideOption[];\n id: string | number;\n index: number;\n insert: UseFieldArrayInsert<FieldValues, string>;\n lastNotDeletable?: boolean;\n move: UseFieldArrayMove;\n moveField: MoveField[];\n testId?: string;\n name: string;\n remove: UseFieldArrayRemove;\n}\n\n/**\n * FieldArrayField component using react-hook-form\n */\nconst FieldArrayField = ({\n children,\n className = undefined,\n field,\n fields,\n hideButtons = [],\n id,\n index,\n insert,\n lastNotDeletable = true,\n move,\n moveField,\n name,\n remove,\n testId = undefined,\n}: FieldArrayFieldProps) => {\n const { attributes, listeners, setNodeRef, transform, transition } =\n useSortable({ id });\n\n const style = {\n transform: CSS.Translate.toString(transform),\n transition,\n };\n\n const { getFieldState, register, watch, trigger } = useFormContext();\n const { error, invalid } = getFieldState(`${name}`, undefined);\n\n // TODO: what about input props? and label props? Do we need a label?\n const { getHelperWrapperProps, getErrorMessageProps } = useInput({\n isInvalid: invalid,\n errorMessage: JSON.stringify(error),\n labelPlacement: 'inside',\n placeholder: ' ',\n classNames: { helperWrapper: 'block' },\n });\n\n // TODO: Check if this is a current issue: _error gets kicked out of the formValidation if no other errors exist. validationError exists, but the structure changes.\n register(`${name}.${index}._errors`);\n\n const formValues = watch();\n useEffect(() => {\n trigger(`${name}.${index}._errors`);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(formValues)]);\n\n return (\n <>\n <li ref={setNodeRef} style={style} className={className}>\n {/** Start Button up/down */}\n {!hideButtons.includes('move') && !hideButtons.includes('all') && (\n <div className=\"mr-6 flex flex-row items-center\">\n {moveField.includes('drag-drop') && (\n <div\n className=\"mr-2 text-base text-xl\"\n data-testid={slugify(`${name}_${index}_movebutton`)}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...attributes}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...listeners}\n >\n <FaGripLines />\n </div>\n )}\n {moveField.includes('button') && (\n <div className=\"flex flex-col\">\n <Button\n testId={`${name}.${index}.up`}\n disabled={index === 0}\n onClick={() => move(index, index - 1)}\n className=\"flex rounded-b-none rounded-t-md border border-gray-300 px-2 py-2 shadow-sm\"\n >\n <FaAngleUp />\n </Button>\n <Button\n testId={`${name}.${index}.down`}\n disabled={index === fields.length - 1}\n onClick={() => move(index, index + 1)}\n className=\"flex rounded-b-md rounded-t-none border border-gray-300 px-2 py-2 shadow-sm\"\n >\n <FaAngleDown />\n </Button>\n </div>\n )}\n </div>\n )}\n {/** End Button up/down */}\n <div key={`rest-${field.id}`} className=\"w-full\">\n <div className=\"mb-2 flex items-center\">\n {/** RENDER CHILDREN */}\n <div className=\"flex-grow\" data-testid={testId}>\n {children}\n </div>\n {!hideButtons.includes('remove') &&\n !hideButtons.includes('all') &&\n (lastNotDeletable && fields.length === 1 ? null : (\n <Button onClick={() => remove(index)} className=\"ml-1\">\n <svg\n className=\"h-4 w-4\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 20 20\"\n fill=\"currentColor\"\n aria-hidden=\"true\"\n >\n <path\n fillRule=\"evenodd\"\n d=\"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z\"\n clipRule=\"evenodd\"\n />\n </svg>\n </Button>\n ))}\n </div>\n\n {!hideButtons.includes('insert') &&\n !hideButtons.includes('all') &&\n index !== fields.length - 1 ? (\n <Button\n className=\"text-xs font-medium\"\n testId={`add-harbor-button-${index}`}\n onClick={() => {\n insert(index + 1, {});\n }}\n >\n insert\n </Button>\n ) : null}\n </div>\n </li>\n {error &&\n typeof error[index] !== 'undefined' &&\n // @ts-expect-error rhf incompatibility\n error[Number(index)]?._errors && ( // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div {...getHelperWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <div {...getErrorMessageProps()}>\n {/* @ts-expect-error rhf incompatibility */}\n <FieldValidationError error={error[Number(index)]?._errors} />\n </div>\n </div>\n )}\n </>\n );\n};\nexport default FieldArrayField;\n","import FieldArray from './FieldArray';\n\nexport type {\n FieldArrayProps,\n FieldArrayHideOption,\n FieldArrayFieldChildren,\n} from './FieldArray';\n\nexport { FieldArray };\n\nexport default FieldArray;\n"],"mappings":";;;;;;;;;;;;;;AAQA,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAAC,iBAAgB;AAEzB,SAAS,UAAAC,eAAc;;;ACrBvB,SAAS,iBAAiB;AAC1B,SAAS,aAAa,WAAW,mBAAmB;AAEpD,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AACpB,SAAS,gBAAgB;AAEzB,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,gBAAC;AAAA;AAAA,kBACC,IAAI,MAAM;AAAA,kBAEV,QAAQ,GAAG,MAAM,IAAI,KAAK;AAAA,kBAC1B,WAAU;AAAA,kBACV;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBACA;AAAA,kBAEC;AAAA,oBACC,GAAG,IAAI,IAAI,KAAK;AAAA,oBAChB;AAAA,oBACA,OAAO;AAAA,oBACP;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA;AAAA,kBACF;AAAA;AAAA,gBAtBK,MAAM;AAAA,cAuBb;AAAA,YAEJ,CAAC;AAAA,YAEA,CAAC,YAAY,SAAS,KAAK,KAAK,CAAC,YAAY,SAAS,KAAK,KAC1D,gBAAAA;AAAA,cAACI;AAAA,cAAA;AAAA,gBACC,QAAQ,GAAG,MAAM;AAAA,gBACjB,MAAK;AAAA,gBACL,SAAS,MAAM,OAAO,CAAC,CAAC;AAAA,gBACzB;AAAA;AAAA,YAED;AAAA,YAGD,OAAO;AAAA,YAEN,gBAAAJ,KAAC,SAAK,GAAG,sBAAsB,GAE7B,0BAAAA,KAAC,SAAK,GAAG,qBAAqB,GAE5B,0BAAAA,KAAC,gCAAqB,OAAO,OAAO,SAAS,GAC/C,GACF;AAAA,aAEJ;AAAA;AAAA,MACF;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,qBAAQ;;;AE3Mf,IAAOK,sBAAQ;","names":["useEffect","useInput","Button","jsx","jsxs","useEffect","useInput","Button","FieldArray_default"]}
|
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
// src/Form/Form.tsx
|
|
10
10
|
import { useEffect as useEffect2 } from "react";
|
|
11
11
|
import { useForm } from "react-hook-form";
|
|
12
|
-
import cn2 from "
|
|
12
|
+
import { cn as cn2 } from "@fuf-stack/pixel-utils";
|
|
13
13
|
|
|
14
14
|
// src/Form/subcomponents/FormDebugViewer.tsx
|
|
15
15
|
import { useEffect, useState } from "react";
|
|
16
16
|
import { FaTimes } from "react-icons/fa";
|
|
17
17
|
import { FaBug } from "react-icons/fa6";
|
|
18
|
-
import cn from "
|
|
18
|
+
import { cn } from "@fuf-stack/pixel-utils";
|
|
19
19
|
import { Button, Card, Json, useLocalStorage } from "@fuf-stack/pixels";
|
|
20
20
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
21
|
var LOCALSTORAGE_DEBUG_KEY = "uniform:form-debug-enabled";
|
|
@@ -156,4 +156,4 @@ export {
|
|
|
156
156
|
Form_default,
|
|
157
157
|
Form_default2
|
|
158
158
|
};
|
|
159
|
-
//# sourceMappingURL=chunk-
|
|
159
|
+
//# sourceMappingURL=chunk-KFRKKWZT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Form/Form.tsx","../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/index.ts"],"sourcesContent":["import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\n\nimport { useEffect } from 'react';\nimport { useForm } from 'react-hook-form';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { slugify } from '../helpers';\nimport FormProvider from './subcomponents/FormContext';\nimport FormDebugViewer from './subcomponents/FormDebugViewer';\n\n/**\n * recursively removes all fields that are null or undefined before\n * the form data is passed to the veto validation function\n */\nexport const removeNullishFields = (obj: Record<string, unknown>) => {\n return JSON.parse(\n JSON.stringify(obj, (_key, value) => {\n return value === null ? undefined : value;\n }),\n );\n};\n\nexport interface FormProps {\n /** form children */\n children: ReactNode | ReactNode[];\n /** CSS class name */\n className?: string | string[];\n /** initial form values */\n initialValues?: FieldValues;\n /** name of the form */\n name?: string;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** veto validation schema */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger?:\n | 'onChange'\n | 'onBlur'\n | 'onSubmit'\n | 'onTouched'\n | 'all'\n | 'all-instant';\n}\n\n/**\n * Form component that has to wrap every uniform\n */\nconst Form = ({\n children,\n className = undefined,\n initialValues = undefined,\n name = undefined,\n onSubmit,\n testId = undefined,\n validation = undefined,\n validationTrigger = 'all',\n}: FormProps) => {\n const methods = useForm(\n validation\n ? {\n defaultValues: initialValues,\n resolver: async (values) => {\n const { data, errors, ...rest } = await validation.validateAsync(\n removeNullishFields(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 // set rhf mode\n // see: https://react-hook-form.com/docs/useform#mode\n mode: validationTrigger === 'all-instant' ? 'all' : validationTrigger,\n }\n : {\n defaultValues: initialValues,\n },\n );\n\n useEffect(\n () => {\n if (validationTrigger === 'all-instant') {\n methods.trigger();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [validationTrigger],\n );\n\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <FormProvider {...methods} validation={validation}>\n <div className=\"flex w-full flex-row justify-between gap-6\">\n <form\n className={cn('flex-grow', className)}\n data-testid={slugify(testId || name || '')}\n name={name}\n onSubmit={methods.handleSubmit(onSubmit)}\n >\n {children}\n </form>\n <FormDebugViewer className=\"w-96 flex-shrink\" />\n </div>\n </FormProvider>\n );\n};\n\nexport default Form;\n","import type { VetoError } from '@fuf-stack/veto';\n\nimport { useEffect, useState } from 'react';\nimport { FaTimes } from 'react-icons/fa';\nimport { FaBug } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button, Card, Json, useLocalStorage } from '@fuf-stack/pixels';\n\nimport { useFormContext } from '../../hooks';\n\ninterface FormDebugViewerProps {\n /** CSS class name */\n className?: string;\n}\n\nconst LOCALSTORAGE_DEBUG_KEY = 'uniform:form-debug-enabled';\n\n/** Renders a form debug panel with information about the current form state */\nconst FormDebugViewer = ({ className = undefined }: FormDebugViewerProps) => {\n const {\n watch,\n formState: { dirtyFields, isValid, isSubmitting },\n validation,\n } = useFormContext();\n\n const [debug, setDebug] = useLocalStorage(LOCALSTORAGE_DEBUG_KEY, false);\n\n const [validationErrors, setValidationErrors] = useState<\n VetoError['errors'] | null\n >(null);\n\n const formValues = watch();\n\n useEffect(\n () => {\n const updateValidationErrors = async () => {\n if (validation) {\n const validateResult = await validation?.validateAsync(formValues);\n setValidationErrors(validateResult?.errors);\n }\n };\n updateValidationErrors();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(formValues)],\n );\n\n if (!debug) {\n return (\n <Button\n ariaLabel=\"Enable form debug mode\"\n onClick={() => setDebug(!debug)}\n className=\"absolute bottom-2.5 right-2.5 w-5 text-default-400\"\n variant=\"light\"\n icon={<FaBug />}\n />\n );\n }\n\n return (\n <Card\n className={cn(className)}\n header={\n <div className=\"flex w-full flex-row justify-between\">\n <span className=\"text-lg\">Debug Mode</span>\n <Button\n icon={<FaTimes className=\"text-danger\" />}\n onClick={() => setDebug(false)}\n size=\"sm\"\n variant=\"flat\"\n />\n </div>\n }\n >\n <Json\n value={{\n values: formValues,\n errors: validationErrors,\n dirtyFields,\n isValid,\n isSubmitting,\n }}\n />\n </Card>\n );\n};\nexport default FormDebugViewer;\n","import Form from './Form';\n\nexport type { FormProps } from './Form';\n\nexport { Form };\n\nexport default Form;\n"],"mappings":";;;;;;;;;AAIA,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,eAAe;AAExB,SAAS,MAAAC,WAAU;;;ACLnB,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;AACxB,SAAS,aAAa;AAEtB,SAAS,UAAU;AACnB,SAAS,QAAQ,MAAM,MAAM,uBAAuB;AAgDtC,cASN,YATM;AAvCd,IAAM,yBAAyB;AAG/B,IAAM,kBAAkB,CAAC,EAAE,YAAY,OAAU,MAA4B;AAC3E,QAAM;AAAA,IACJ;AAAA,IACA,WAAW,EAAE,aAAa,SAAS,aAAa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