@fuf-stack/uniform 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CheckboxGroup/index.cjs +3 -3
- package/dist/CheckboxGroup/index.d.cts +5 -2
- package/dist/CheckboxGroup/index.d.ts +5 -2
- package/dist/CheckboxGroup/index.js +2 -2
- package/dist/CheckboxGroup-o-qWkWe1.d.cts +130 -0
- package/dist/CheckboxGroup-o-qWkWe1.d.ts +130 -0
- package/dist/FieldArray/index.cjs +3 -3
- package/dist/FieldArray/index.js +2 -2
- package/dist/{FieldValidationError-BSXedjCA.d.cts → FieldValidationError-DAT12Ess.d.cts} +2 -1
- package/dist/{FieldValidationError-BSXedjCA.d.ts → FieldValidationError-DAT12Ess.d.ts} +2 -1
- package/dist/Input/index.cjs +3 -3
- package/dist/Input/index.js +2 -2
- package/dist/RadioGroup/index.cjs +3 -3
- package/dist/RadioGroup/index.d.cts +5 -2
- package/dist/RadioGroup/index.d.ts +5 -2
- package/dist/RadioGroup/index.js +2 -2
- package/dist/RadioGroup-D_kiBt0M.d.cts +162 -0
- package/dist/RadioGroup-D_kiBt0M.d.ts +162 -0
- package/dist/Select/index.cjs +3 -3
- package/dist/Select/index.d.cts +3 -3
- package/dist/Select/index.d.ts +3 -3
- package/dist/Select/index.js +2 -2
- package/dist/Select-BhS4z0Pj.d.cts +317 -0
- package/dist/Select-BhS4z0Pj.d.ts +317 -0
- package/dist/Switch/index.cjs +3 -3
- package/dist/Switch/index.d.cts +5 -2
- package/dist/Switch/index.d.ts +5 -2
- package/dist/Switch/index.js +2 -2
- package/dist/Switch-Fdldj8LV.d.cts +126 -0
- package/dist/Switch-Fdldj8LV.d.ts +126 -0
- package/dist/TextArea/index.cjs +3 -3
- package/dist/TextArea/index.js +2 -2
- package/dist/{chunk-OCR2UWG2.cjs → chunk-4RTJ5XR2.cjs} +3 -3
- package/dist/{chunk-OCR2UWG2.cjs.map → chunk-4RTJ5XR2.cjs.map} +1 -1
- package/dist/{chunk-YUAJN6HW.cjs → chunk-6HMMXOSV.cjs} +48 -15
- package/dist/chunk-6HMMXOSV.cjs.map +1 -0
- package/dist/{chunk-FMQNL3RT.js → chunk-F7GG67YU.js} +2 -2
- package/dist/{chunk-W24WP5YE.cjs → chunk-HFMFDBEV.cjs} +46 -14
- package/dist/chunk-HFMFDBEV.cjs.map +1 -0
- package/dist/{chunk-NHPQEYYN.js → chunk-HOCRJOEU.js} +2 -2
- package/dist/{chunk-TNELIBCV.cjs → chunk-JDRMKZ35.cjs} +4 -4
- package/dist/{chunk-TNELIBCV.cjs.map → chunk-JDRMKZ35.cjs.map} +1 -1
- package/dist/{chunk-4AHVJWTB.js → chunk-JG5VQZ4V.js} +46 -14
- package/dist/chunk-JG5VQZ4V.js.map +1 -0
- package/dist/{chunk-5UHHZ7KY.cjs → chunk-JRFKYVXY.cjs} +3 -3
- package/dist/{chunk-5UHHZ7KY.cjs.map → chunk-JRFKYVXY.cjs.map} +1 -1
- package/dist/chunk-LDW7K7LW.js +231 -0
- package/dist/chunk-LDW7K7LW.js.map +1 -0
- package/dist/{chunk-3XNW2VQ7.cjs → chunk-NQ4JZ7AK.cjs} +38 -16
- package/dist/chunk-NQ4JZ7AK.cjs.map +1 -0
- package/dist/{chunk-UHFAY5XK.cjs → chunk-NXTXKBTP.cjs} +105 -114
- package/dist/chunk-NXTXKBTP.cjs.map +1 -0
- package/dist/{chunk-QTL5FREE.cjs → chunk-OHJYXA6R.cjs} +7 -5
- package/dist/chunk-OHJYXA6R.cjs.map +1 -0
- package/dist/{chunk-ZOVKQ7MN.js → chunk-PFX4YRWI.js} +39 -17
- package/dist/chunk-PFX4YRWI.js.map +1 -0
- package/dist/{chunk-DTSX7YON.js → chunk-SCTH3FAO.js} +2 -2
- package/dist/{chunk-DBLODROX.js → chunk-WKM2D7LF.js} +7 -5
- package/dist/chunk-WKM2D7LF.js.map +1 -0
- package/dist/{chunk-ARUVDZFG.js → chunk-YSZW33OV.js} +48 -15
- package/dist/chunk-YSZW33OV.js.map +1 -0
- package/dist/index.cjs +12 -12
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +14 -14
- package/dist/partials/FieldValidationError/index.cjs +2 -2
- package/dist/partials/FieldValidationError/index.d.cts +2 -2
- package/dist/partials/FieldValidationError/index.d.ts +2 -2
- package/dist/partials/FieldValidationError/index.js +1 -1
- package/package.json +3 -3
- package/dist/CheckboxGroup-BYsQ0A0q.d.cts +0 -32
- package/dist/CheckboxGroup-BYsQ0A0q.d.ts +0 -32
- package/dist/RadioGroup-BU4K9cnS.d.cts +0 -40
- package/dist/RadioGroup-BU4K9cnS.d.ts +0 -40
- package/dist/Select-C08Oftdr.d.cts +0 -184
- package/dist/Select-C08Oftdr.d.ts +0 -184
- package/dist/Switch-DmjDKgKs.d.cts +0 -20
- package/dist/Switch-DmjDKgKs.d.ts +0 -20
- package/dist/chunk-3XNW2VQ7.cjs.map +0 -1
- package/dist/chunk-4AHVJWTB.js.map +0 -1
- package/dist/chunk-ARUVDZFG.js.map +0 -1
- package/dist/chunk-DBLODROX.js.map +0 -1
- package/dist/chunk-OCXF3U6L.js +0 -240
- package/dist/chunk-OCXF3U6L.js.map +0 -1
- package/dist/chunk-QTL5FREE.cjs.map +0 -1
- package/dist/chunk-UHFAY5XK.cjs.map +0 -1
- package/dist/chunk-W24WP5YE.cjs.map +0 -1
- package/dist/chunk-YUAJN6HW.cjs.map +0 -1
- package/dist/chunk-ZOVKQ7MN.js.map +0 -1
- /package/dist/{chunk-FMQNL3RT.js.map → chunk-F7GG67YU.js.map} +0 -0
- /package/dist/{chunk-NHPQEYYN.js.map → chunk-HOCRJOEU.js.map} +0 -0
- /package/dist/{chunk-DTSX7YON.js.map → chunk-SCTH3FAO.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-4RTJ5XR2.cjs","../src/TextArea/TextArea.tsx","../src/TextArea/index.ts"],"names":["TextArea_default"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACRA,gDAA2B;AAE3B,0CAAyC;AAEzC,oDAAmB;AAqDgB,+CAAA;AA3BnC,IAAM,SAAA,EAAW,CAAC;AAAA,EAChB,SAAA,EAAW,IAAA;AAAA,EACX,UAAA,EAAY,KAAA,CAAA;AAAA,EACZ,SAAA,EAAW,KAAA;AAAA,EACX,MAAA,EAAQ,KAAA,CAAA;AAAA,EACR,IAAA;AAAA,EACA,YAAA,EAAc,GAAA;AAAA,EACd,MAAA,EAAQ,QAAA,EAAU,KAAA;AACpB,CAAA,EAAA,GAAqB;AACnB,EAAA,MAAM,EAAE,OAAA,EAAS,cAAc,EAAA,EAAI,8CAAA,CAAe;AAClD,EAAA,MAAM,EAAE,KAAA,EAAO,OAAA,EAAS,QAAA,EAAU,OAAO,EAAA,EAAI,aAAA,CAAc,IAAA,EAAM,OAAO,CAAA;AAExE,EAAA,uBACE,6BAAA;AAAA,IAAC,yBAAA;AAAA,IAAA;AAAA,MACC,OAAA;AAAA,MACA,IAAA;AAAA,MACA,QAAA;AAAA,MACA,MAAA,EAAQ,CAAC;AAAA,QACP,KAAA,EAAO,EAAE,QAAA,EAAU,UAAA,EAAY,QAAA,EAAU,MAAA,EAAQ,KAAA,EAAO,IAAI;AAAA,MAC9D,CAAA,EAAA,GAAM;AACJ,QAAA,uBACE,6BAAA;AAAA,UAAC,eAAA;AAAA,UAAA;AAAA,YACC,SAAA,EAAW,4BAAA,SAAY,CAAA;AAAA,YACvB,UAAA,EAAY;AAAA,cACV,YAAA,EAAc;AAAA,YAChB,CAAA;AAAA,YACA,aAAA,EAAa,MAAA;AAAA,YACb,YAAA,EAAc,MAAA,mBAAS,6BAAA,8CAAC,EAAA,EAAqB,MAAA,CAAc,CAAA;AAAA,YAC3D,UAAA;AAAA,YACA,UAAA,EAAY,QAAA;AAAA,YACZ,SAAA,EAAW,OAAA;AAAA,YACX,KAAA,kBACE,8BAAA,oBAAA,EAAA,EACG,QAAA,EAAA;AAAA,cAAA,KAAA;AAAA,8BACD,6BAAA,+CAAC,EAAA,EAAsB,OAAA,CAAgB;AAAA,YAAA,EAAA,CACzC,CAAA;AAAA,YAEF,cAAA,EAAe,SAAA;AAAA,YACf,WAAA;AAAA,YACA,IAAA;AAAA,YACA,KAAA;AAAA,YACA,QAAA;AAAA,YACA,MAAA;AAAA,YACA,GAAA;AAAA,YACA,OAAA,EAAQ,UAAA;AAAA,YAEP;AAAA,UAAA;AAAA,QACH,CAAA;AAAA,MAEJ;AAAA,IAAA;AAAA,EACF,CAAA;AAEJ,CAAA;AAEA,IAAO,iBAAA,EAAQ,QAAA;ADnBf;AACA;AE9DA,IAAOA,kBAAAA,EAAQ,gBAAA;AFgEf;AACA;AACE;AACA;AACF,2FAAC","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-4RTJ5XR2.cjs","sourcesContent":[null,"import type { ReactNode } from 'react';\n\nimport { Controller } from 'react-hook-form';\n\nimport { Textarea as NextTextArea } from '@nextui-org/input';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport interface TextAreaProps {\n /** Child components. The content of the textarea. */\n children?: ReactNode;\n /** CSS class name */\n className?: string;\n /** Determines if the TextArea is disabled or not. */\n disabled?: boolean;\n /** Label displayed above the TextArea. */\n label?: ReactNode;\n /** Name the TextArea is registered at in HTML forms (react-hook-form). */\n name: string;\n /** placeholder for the textArea content. */\n placeholder?: string;\n /** Id to grab element in internal tests. */\n testId?: string;\n}\n\n/**\n * TextArea component based on [NextUI TextArea](https://nextui.org/docs/components/textarea)\n */\nconst TextArea = ({\n children = null,\n className = undefined,\n disabled = false,\n label = undefined,\n name,\n placeholder = ' ',\n testId: _testId = undefined,\n}: TextAreaProps) => {\n const { control, getFieldState } = useFormContext();\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n return (\n <Controller\n control={control}\n name={name}\n disabled={disabled}\n render={({\n field: { disabled: isDisabled, onChange, onBlur, value, ref },\n }) => {\n return (\n <NextTextArea\n className={cn(className)}\n classNames={{\n inputWrapper: 'group-data-[focus=true]:border-primary',\n }}\n data-testid={testId}\n errorMessage={error && <FieldValidationError error={error} />}\n isDisabled={isDisabled}\n isRequired={required}\n isInvalid={invalid}\n label={\n <>\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </>\n }\n labelPlacement=\"outside\"\n placeholder={placeholder}\n name={name}\n value={value}\n onChange={onChange}\n onBlur={onBlur}\n ref={ref}\n variant=\"bordered\"\n >\n {children}\n </NextTextArea>\n );\n }}\n />\n );\n};\n\nexport default TextArea;\n","import TextArea from './TextArea';\n\nexport type { TextAreaProps } from './TextArea';\n\nexport { TextArea };\n\nexport default TextArea;\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunkKMMS4G7Acjs = require('./chunk-KMMS4G7A.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkOHJYXA6Rcjs = require('./chunk-OHJYXA6R.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkLDCRR7FPcjs = require('./chunk-LDCRR7FP.cjs');
|
|
@@ -93,6 +93,25 @@ var RadioButton = ({
|
|
|
93
93
|
|
|
94
94
|
// src/RadioGroup/RadioGroup.tsx
|
|
95
95
|
|
|
96
|
+
var radioGroupVariants = _pixelutils.tv.call(void 0, {
|
|
97
|
+
slots: {
|
|
98
|
+
base: "group",
|
|
99
|
+
// Needs group for group-data condition
|
|
100
|
+
buttonGroup: "rounded-xl group-data-[invalid=true]:border group-data-[invalid=true]:border-danger",
|
|
101
|
+
// optional if a button group is used
|
|
102
|
+
itemBase: "",
|
|
103
|
+
itemBaseActive: "bg-opacity-50",
|
|
104
|
+
// optional if a button group is used
|
|
105
|
+
itemControl: "",
|
|
106
|
+
itemDescription: "",
|
|
107
|
+
itemLabel: "text-sm",
|
|
108
|
+
itemLabelWrapper: "",
|
|
109
|
+
itemWrapper: "",
|
|
110
|
+
// See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/select.ts
|
|
111
|
+
label: "text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger",
|
|
112
|
+
wrapper: ""
|
|
113
|
+
}
|
|
114
|
+
});
|
|
96
115
|
var RadioGroup = ({
|
|
97
116
|
className = void 0,
|
|
98
117
|
disabled = false,
|
|
@@ -105,6 +124,8 @@ var RadioGroup = ({
|
|
|
105
124
|
}) => {
|
|
106
125
|
const { control, getFieldState, getValues } = _chunkLDCRR7FPcjs.useFormContext.call(void 0, );
|
|
107
126
|
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
127
|
+
const variants = radioGroupVariants();
|
|
128
|
+
const classNames = _pixelutils.variantsToClassNames.call(void 0, variants, className, "base");
|
|
108
129
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
109
130
|
_reacthookform.Controller,
|
|
110
131
|
{
|
|
@@ -113,19 +134,28 @@ var RadioGroup = ({
|
|
|
113
134
|
name,
|
|
114
135
|
render: ({ field: { onChange, disabled: isDisabled, onBlur, ref } }) => {
|
|
115
136
|
let RadioComponents;
|
|
137
|
+
const itemClassNames = {
|
|
138
|
+
base: classNames.itemBase,
|
|
139
|
+
control: classNames.itemControl,
|
|
140
|
+
description: classNames.itemDescription,
|
|
141
|
+
label: classNames.itemLabel,
|
|
142
|
+
labelWrapper: classNames.itemLabelWrapper,
|
|
143
|
+
wrapper: classNames.itemWrapper
|
|
144
|
+
};
|
|
116
145
|
switch (variant) {
|
|
117
146
|
case "radioBox":
|
|
118
147
|
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
119
148
|
RadioBox,
|
|
120
149
|
{
|
|
150
|
+
classNames: itemClassNames,
|
|
121
151
|
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
122
152
|
`${testId}_option_${option.testId || option.value}`
|
|
123
153
|
),
|
|
124
|
-
isDisabled: isDisabled || option.disabled,
|
|
125
|
-
value: option.value,
|
|
126
|
-
onChange,
|
|
127
154
|
description: option.description,
|
|
128
155
|
icon: option.icon,
|
|
156
|
+
isDisabled: isDisabled || option.disabled,
|
|
157
|
+
onChange,
|
|
158
|
+
value: option.value,
|
|
129
159
|
children: option.label ? option.label : option.value
|
|
130
160
|
},
|
|
131
161
|
option.value
|
|
@@ -135,15 +165,15 @@ var RadioGroup = ({
|
|
|
135
165
|
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
136
166
|
RadioButton,
|
|
137
167
|
{
|
|
168
|
+
className: _pixelutils.cn.call(void 0, classNames.itemBase, {
|
|
169
|
+
[classNames.itemBaseActive]: getValues()[name] !== option.value
|
|
170
|
+
}),
|
|
138
171
|
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
139
172
|
`${testId}_option_${option.testId || option.value}`
|
|
140
173
|
),
|
|
141
174
|
isDisabled: isDisabled || option.disabled,
|
|
142
|
-
value: option.value,
|
|
143
175
|
onChange,
|
|
144
|
-
|
|
145
|
-
`${getValues()[name] !== option.value ? "bg-opacity-50" : ""}`
|
|
146
|
-
),
|
|
176
|
+
value: option.value,
|
|
147
177
|
children: option.label ? option.label : option.value
|
|
148
178
|
},
|
|
149
179
|
option.value
|
|
@@ -153,12 +183,13 @@ var RadioGroup = ({
|
|
|
153
183
|
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
154
184
|
_radio.Radio,
|
|
155
185
|
{
|
|
186
|
+
classNames: itemClassNames,
|
|
156
187
|
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
157
188
|
`${testId}_option_${option.testId || option.value}`
|
|
158
189
|
),
|
|
159
190
|
isDisabled: isDisabled || option.disabled,
|
|
160
|
-
value: option.value,
|
|
161
191
|
onChange,
|
|
192
|
+
value: option.value,
|
|
162
193
|
children: option.label ? option.label : option.value
|
|
163
194
|
},
|
|
164
195
|
option.value
|
|
@@ -167,25 +198,27 @@ var RadioGroup = ({
|
|
|
167
198
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
168
199
|
_radio.RadioGroup,
|
|
169
200
|
{
|
|
170
|
-
|
|
201
|
+
classNames,
|
|
202
|
+
"data-invalid": invalid,
|
|
203
|
+
"data-required": required,
|
|
171
204
|
"data-testid": testId,
|
|
172
|
-
errorMessage: error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
205
|
+
errorMessage: error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOHJYXA6Rcjs.FieldValidationError_default, { error }),
|
|
173
206
|
isDisabled,
|
|
174
207
|
isInvalid: invalid,
|
|
175
208
|
isRequired: required,
|
|
176
209
|
label: label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
177
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", {
|
|
210
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { children: [
|
|
178
211
|
label,
|
|
179
212
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKMMS4G7Acjs.FieldCopyTestIdButton_default, { testId })
|
|
180
213
|
] }),
|
|
214
|
+
name,
|
|
181
215
|
orientation: inline ? "horizontal" : "vertical",
|
|
182
216
|
onBlur,
|
|
183
217
|
onChange,
|
|
184
|
-
name,
|
|
185
218
|
ref,
|
|
186
219
|
children: variant === "radioButton" ? (
|
|
187
220
|
// 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 })
|
|
221
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _button.ButtonGroup, { className: classNames.buttonGroup, children: RadioComponents })
|
|
189
222
|
) : RadioComponents
|
|
190
223
|
}
|
|
191
224
|
);
|
|
@@ -202,4 +235,4 @@ var RadioGroup_default2 = RadioGroup_default;
|
|
|
202
235
|
|
|
203
236
|
|
|
204
237
|
exports.RadioGroup_default = RadioGroup_default; exports.RadioGroup_default2 = RadioGroup_default2;
|
|
205
|
-
//# sourceMappingURL=chunk-
|
|
238
|
+
//# sourceMappingURL=chunk-6HMMXOSV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-6HMMXOSV.cjs","../src/RadioGroup/RadioGroup.tsx","../src/RadioGroup/Variants/RadioBox.tsx","../src/RadioGroup/Variants/RadioButton.tsx","../src/RadioGroup/index.ts"],"names":["jsx","cn"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACVA,gDAA2B;AAE3B,4CAA+C;AAC/C,0CAAoD;AAEpD,oDAA6C;ADU7C;AACA;AEhBA;AACA,6DAA+B;AAE/B;AAmCQ,+CAAA;AA5BD,IAAM,SAAA,EAAW,CAAC,EAAE,KAAA,EAAO,KAAA,CAAA,EAAW,GAAG,MAAM,CAAA,EAAA,GAAkB;AACtE,EAAA,MAAM;AAAA,IACJ,QAAA;AAAA,IACA,SAAA;AAAA,IACA,WAAA;AAAA,IACA,YAAA;AAAA,IACA,eAAA;AAAA,IACA,aAAA;AAAA,IACA,aAAA;AAAA,IACA,oBAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,EACF,EAAA,EAAI,6BAAA,KAAc,CAAA;AAElB,EAAA,uBACE,8BAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAA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AA;AAAA,cAAA;AAL1B,YAAA;AAQhB,YAAA;AAAA,UAAA;AAEA,YAAA;AACE,cAAA;AAAC,cAAA;AAAA,gBAAA;AACa,gBAAA;AACC,kBAAA;AACsC,gBAAA;AACnD,gBAAA;AACiC,gBAAA;AAEjC,gBAAA;AACc,gBAAA;AAEwB,cAAA;AAAA,cAAA;AAJ1B,YAAA;AAMf,QAAA;AAGL,QAAA;AACE,UAAA;AAAC,UAAA;AAAA,YAAA;AAEC,YAAA;AAEc,YAAA;AACC,YAAA;AACF,YAAA;AAC8C,YAAA;AAC3D,YAAA;AACW,YAAA;AACC,YAAA;AAEV,4BAAA;AAGK,cAAA;AAAA,8BAAA;AACsC,YAAA;AACzC,YAAA;AAGJ,YAAA;AACqC,YAAA;AACrC,YAAA;AACA,YAAA;AACA,YAAA;AAEa;AAAA,8BAAA;AAIX,YAAA;AAEA,UAAA;AAAA,QAAA;AAEJ,MAAA;AAEJ,IAAA;AAAA,EAAA;AAGN;AAEA;ADqBA;AACA;AIhOA;AJkOA;AACA;AACA;AACA;AACA","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-6HMMXOSV.cjs","sourcesContent":[null,"import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport 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, tv, variantsToClassNames } 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 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: '',\n itemDescription: '',\n itemLabel: 'text-sm',\n itemLabelWrapper: '',\n itemWrapper: '',\n // See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/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 },\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 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: 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 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 };\n\n switch (variant) {\n case 'radioBox':\n RadioComponents = options.map((option) => (\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 break;\n case 'radioButton':\n RadioComponents = options.map((option) => (\n <RadioButton\n className={cn(classNames.itemBase, {\n [classNames.itemBaseActive]:\n getValues()[name] !== option.value,\n })}\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 // 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 break;\n default:\n RadioComponents = options.map((option) => (\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\n return (\n <NextRadioGroup\n // className={className}\n classNames={classNames}\n // See NextUI styles for group-data condition (data-invalid), e.g.: https://github.com/nextui-org/nextui/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 label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label>\n {label}\n <FieldCopyTestIdButton testId={testId} />\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 // TODO: NextButtonGroup uses ref to modify Button style, but we wrap it, so it does not work at the moment.\n <NextButtonGroup className={classNames.buttonGroup}>\n {RadioComponents}\n </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"]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-T3CCNJHK.js";
|
|
4
4
|
import {
|
|
5
5
|
FieldValidationError_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WKM2D7LF.js";
|
|
7
7
|
import {
|
|
8
8
|
useFormContext
|
|
9
9
|
} from "./chunk-HWDQZO7X.js";
|
|
@@ -284,4 +284,4 @@ export {
|
|
|
284
284
|
FieldArray_default,
|
|
285
285
|
FieldArray_default2
|
|
286
286
|
};
|
|
287
|
-
//# sourceMappingURL=chunk-
|
|
287
|
+
//# sourceMappingURL=chunk-F7GG67YU.js.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunkKMMS4G7Acjs = require('./chunk-KMMS4G7A.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkOHJYXA6Rcjs = require('./chunk-OHJYXA6R.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkLDCRR7FPcjs = require('./chunk-LDCRR7FP.cjs');
|
|
@@ -17,7 +17,22 @@ var _reacthookform = require('react-hook-form');
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
var _checkbox = require('@nextui-org/checkbox');
|
|
20
|
+
var _pixelutils = require('@fuf-stack/pixel-utils');
|
|
20
21
|
var _jsxruntime = require('react/jsx-runtime');
|
|
22
|
+
var checkboxGroupVariants = _pixelutils.tv.call(void 0, {
|
|
23
|
+
slots: {
|
|
24
|
+
base: "group",
|
|
25
|
+
// Needs group for group-data condition
|
|
26
|
+
errorMessage: "text-tiny",
|
|
27
|
+
itemBase: "",
|
|
28
|
+
itemIcon: "",
|
|
29
|
+
itemLabel: "text-sm",
|
|
30
|
+
itemWrapper: "",
|
|
31
|
+
// See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/select.ts
|
|
32
|
+
label: "text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger",
|
|
33
|
+
wrapper: ""
|
|
34
|
+
}
|
|
35
|
+
});
|
|
21
36
|
var CheckboxGroup = ({
|
|
22
37
|
className = void 0,
|
|
23
38
|
label = void 0,
|
|
@@ -28,6 +43,19 @@ var CheckboxGroup = ({
|
|
|
28
43
|
}) => {
|
|
29
44
|
const { getFieldState, control } = _chunkLDCRR7FPcjs.useFormContext.call(void 0, );
|
|
30
45
|
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
46
|
+
const variants = checkboxGroupVariants();
|
|
47
|
+
const classNames = _pixelutils.variantsToClassNames.call(void 0, variants, className, "base");
|
|
48
|
+
const itemClassName = {
|
|
49
|
+
base: classNames.itemBase,
|
|
50
|
+
wrapper: classNames.itemWrapper,
|
|
51
|
+
icon: classNames.itemIcon,
|
|
52
|
+
label: classNames.itemLabel
|
|
53
|
+
};
|
|
54
|
+
const itemGroupClassName = {
|
|
55
|
+
base: classNames.base,
|
|
56
|
+
wrapper: classNames.wrapper,
|
|
57
|
+
label: classNames.label
|
|
58
|
+
};
|
|
31
59
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
32
60
|
_reacthookform.Controller,
|
|
33
61
|
{
|
|
@@ -38,23 +66,25 @@ var CheckboxGroup = ({
|
|
|
38
66
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
39
67
|
_checkbox.CheckboxGroup,
|
|
40
68
|
{
|
|
41
|
-
|
|
69
|
+
name,
|
|
70
|
+
classNames: itemGroupClassName,
|
|
42
71
|
"data-testid": testId,
|
|
43
|
-
|
|
72
|
+
"data-invalid": invalid,
|
|
73
|
+
errorMessage: error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
74
|
+
_chunkOHJYXA6Rcjs.FieldValidationError_default,
|
|
75
|
+
{
|
|
76
|
+
error,
|
|
77
|
+
className: classNames.errorMessage
|
|
78
|
+
}
|
|
79
|
+
),
|
|
44
80
|
isDisabled: disabled,
|
|
45
81
|
isInvalid: invalid,
|
|
46
82
|
isRequired: required,
|
|
47
83
|
label: label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
48
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
children: [
|
|
53
|
-
label,
|
|
54
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKMMS4G7Acjs.FieldCopyTestIdButton_default, { testId })
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
),
|
|
84
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { children: [
|
|
85
|
+
label,
|
|
86
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKMMS4G7Acjs.FieldCopyTestIdButton_default, { testId })
|
|
87
|
+
] }),
|
|
58
88
|
...options.length === 1 ? {
|
|
59
89
|
value: [value].filter((v) => v !== void 0),
|
|
60
90
|
onChange: (newValue) => onChange(newValue && newValue[0])
|
|
@@ -68,6 +98,8 @@ var CheckboxGroup = ({
|
|
|
68
98
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
69
99
|
_checkbox.Checkbox,
|
|
70
100
|
{
|
|
101
|
+
"data-invalid": invalid,
|
|
102
|
+
classNames: itemClassName,
|
|
71
103
|
isDisabled: disabled || option.disabled,
|
|
72
104
|
value: _optionalChain([option, 'optionalAccess', _3 => _3.value]),
|
|
73
105
|
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
@@ -93,4 +125,4 @@ var CheckboxGroup_default2 = CheckboxGroup_default;
|
|
|
93
125
|
|
|
94
126
|
|
|
95
127
|
exports.CheckboxGroup_default = CheckboxGroup_default; exports.CheckboxGroup_default2 = CheckboxGroup_default2;
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
128
|
+
//# sourceMappingURL=chunk-HFMFDBEV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-HFMFDBEV.cjs","../src/CheckboxGroup/CheckboxGroup.tsx","../src/CheckboxGroup/index.ts"],"names":["CheckboxGroup_default"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACXA,gDAA2B;AAE3B;AACE;AACA;AAAiB,gDACZ;AAEP,oDAAyC;AA+FzB,+CAAA;AAxFT,IAAM,sBAAA,EAAwB,4BAAA;AAAG,EACtC,KAAA,EAAO;AAAA,IACL,IAAA,EAAM,OAAA;AAAA;AAAA,IACN,YAAA,EAAc,WAAA;AAAA,IACd,QAAA,EAAU,EAAA;AAAA,IACV,QAAA,EAAU,EAAA;AAAA,IACV,SAAA,EAAW,SAAA;AAAA,IACX,WAAA,EAAa,EAAA;AAAA;AAAA,IAEb,KAAA,EACE,qFAAA;AAAA,IACF,OAAA,EAAS;AAAA,EACX;AACF,CAAC,CAAA;AAkCD,IAAM,cAAA,EAAgB,CAAC;AAAA,EACrB,UAAA,EAAY,KAAA,CAAA;AAAA,EACZ,MAAA,E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UAAA;AACH,QAAA;AAEJ,MAAA;AAAA,IAAA;AACF,EAAA;AAEJ;AAEO;ADvCc;AACA;AElHdA;AFoHc;AACA;AACA;AACA;AACA","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-HFMFDBEV.cjs","sourcesContent":[null,"import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\n\nimport { Controller } from 'react-hook-form';\n\nimport {\n Checkbox,\n CheckboxGroup as NextCheckboxGroup,\n} from '@nextui-org/checkbox';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { slugify } from '../helpers';\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport const checkboxGroupVariants = tv({\n slots: {\n base: 'group', // Needs group for group-data condition\n errorMessage: 'text-tiny',\n itemBase: '',\n itemIcon: '',\n itemLabel: 'text-sm',\n itemWrapper: '',\n // See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/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 },\n});\n\ntype VariantProps = TVProps<typeof checkboxGroupVariants>;\ntype ClassName = TVClassName<typeof checkboxGroupVariants>;\n\nexport type CheckboxGroupOption = {\n /** option label */\n label?: React.ReactNode;\n /** option value */\n value: string;\n /** disables the option */\n disabled?: boolean;\n /** HTML data-testid attribute of the option */\n testId?: string;\n};\n\nexport interface CheckboxGroupProps extends VariantProps {\n /** CSS class name. ClassName: string | { buttons?: string | { base?: string; active?: string }; base?: string;} */\n className?: ClassName;\n /** label displayed above the Checkboxes */\n label?: React.ReactNode;\n /** Name the Field is registered on the form. */\n name: string;\n /** Checkboxes that should be displayed. */\n options: CheckboxGroupOption[];\n /** sets all buttons disabled */\n disabled?: boolean;\n /** id for internal testing. */\n testId?: string;\n}\n\n/**\n * CheckboxGroup component based on [NextUI CheckboxGroup](https://nextui.org/docs/components/checkbox-group)\n */\nconst CheckboxGroup = ({\n className = undefined,\n label = undefined,\n options,\n disabled = false,\n name,\n testId: _testId = undefined,\n}: CheckboxGroupProps) => {\n const { getFieldState, control } = useFormContext();\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n const variants = checkboxGroupVariants();\n const classNames = variantsToClassNames(variants, className, 'base');\n\n const itemClassName = {\n base: classNames.itemBase,\n wrapper: classNames.itemWrapper,\n icon: classNames.itemIcon,\n label: classNames.itemLabel,\n };\n const itemGroupClassName = {\n base: classNames.base,\n wrapper: classNames.wrapper,\n label: classNames.label,\n };\n\n return (\n <Controller\n control={control}\n name={name}\n disabled={disabled}\n render={({ field: { onChange, value, ref, onBlur } }) => {\n return (\n <NextCheckboxGroup\n name={name}\n classNames={itemGroupClassName}\n data-testid={testId}\n // See NextUI styles for group-data condition (data-invalid), e.g.: https://github.com/nextui-org/nextui/blob/main/packages/components/select/src/use-select.ts\n data-invalid={invalid}\n errorMessage={\n error && (\n <FieldValidationError\n error={error}\n className={classNames.errorMessage}\n />\n )\n }\n isDisabled={disabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label>\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </label>\n )\n }\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(options.length === 1\n ? {\n value: [value].filter((v) => v !== undefined),\n onChange: (newValue) => onChange(newValue && newValue[0]),\n }\n : {\n onChange,\n value,\n })}\n onBlur={onBlur}\n ref={ref}\n >\n {options?.map((option) => {\n return (\n <Checkbox\n data-invalid={invalid}\n classNames={itemClassName}\n key={`index_${option.value}`}\n isDisabled={disabled || option.disabled}\n value={option?.value}\n data-testid={slugify(\n `${testId}_option_${option?.testId || option?.value}`,\n )}\n >\n {option?.label}\n </Checkbox>\n );\n })}\n </NextCheckboxGroup>\n );\n }}\n />\n );\n};\n\nexport default CheckboxGroup;\n","import CheckboxGroup from './CheckboxGroup';\n\nexport type { CheckboxGroupProps, CheckboxGroupOption } from './CheckboxGroup';\n\nexport { CheckboxGroup };\n\nexport default CheckboxGroup;\n"]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-T3CCNJHK.js";
|
|
4
4
|
import {
|
|
5
5
|
FieldValidationError_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WKM2D7LF.js";
|
|
7
7
|
import {
|
|
8
8
|
useFormContext
|
|
9
9
|
} from "./chunk-HWDQZO7X.js";
|
|
@@ -73,4 +73,4 @@ export {
|
|
|
73
73
|
TextArea_default,
|
|
74
74
|
TextArea_default2
|
|
75
75
|
};
|
|
76
|
-
//# sourceMappingURL=chunk-
|
|
76
|
+
//# sourceMappingURL=chunk-HOCRJOEU.js.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunkKMMS4G7Acjs = require('./chunk-KMMS4G7A.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkOHJYXA6Rcjs = require('./chunk-OHJYXA6R.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkLDCRR7FPcjs = require('./chunk-LDCRR7FP.cjs');
|
|
@@ -150,7 +150,7 @@ var FieldArrayField = ({
|
|
|
150
150
|
error && typeof error[index] !== "undefined" && // @ts-expect-error rhf incompatibility
|
|
151
151
|
_optionalChain([error, 'access', _ => _[Number(index)], 'optionalAccess', _2 => _2._errors]) && // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)
|
|
152
152
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
153
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getErrorMessageProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
153
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getErrorMessageProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOHJYXA6Rcjs.FieldValidationError_default, { error: _optionalChain([error, 'access', _3 => _3[Number(index)], 'optionalAccess', _4 => _4._errors]) }) }) })
|
|
154
154
|
] });
|
|
155
155
|
};
|
|
156
156
|
var FieldArrayField_default = FieldArrayField;
|
|
@@ -268,7 +268,7 @@ var FieldArray = ({
|
|
|
268
268
|
}
|
|
269
269
|
),
|
|
270
270
|
_optionalChain([error, 'optionalAccess', _7 => _7._errors]) && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
271
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getErrorMessageProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
271
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ...getErrorMessageProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOHJYXA6Rcjs.FieldValidationError_default, { error: _optionalChain([error, 'optionalAccess', _8 => _8._errors]) }) }) })
|
|
272
272
|
] })
|
|
273
273
|
}
|
|
274
274
|
)
|
|
@@ -284,4 +284,4 @@ var FieldArray_default2 = FieldArray_default;
|
|
|
284
284
|
|
|
285
285
|
|
|
286
286
|
exports.FieldArray_default = FieldArray_default; exports.FieldArray_default2 = FieldArray_default2;
|
|
287
|
-
//# sourceMappingURL=chunk-
|
|
287
|
+
//# sourceMappingURL=chunk-JDRMKZ35.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-TNELIBCV.cjs","../src/FieldArray/FieldArray.tsx","../src/FieldArray/FieldArrayField.tsx","../src/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B;AACA;AG7Q7B;AH+Q6B;AACA;AACA;AACA;AACA","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-TNELIBCV.cjs","sourcesContent":[null,"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"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-JDRMKZ35.cjs","../src/FieldArray/FieldArray.tsx","../src/FieldArray/FieldArrayField.tsx","../src/FieldArray/index.ts"],"names":["jsx","Button"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACLA,8BAA0B;AAC1B,gDAA8B;AAE9B;AACE;AACA;AACA;AACA;AACA;AACA;AAAA,qCACK;AACP;AACE;AACA;AAAA,+CACK;AACP;AACE;AACA;AAAA,6CACK;AACP,0CAAyB;AAEzB,2CAAuB;ADKvB;AACA;AE3BA;AACA,oCAAoD;AAEpD;AACA,+CAAoB;AACpB;AAEA;AAwEI,+CAAA;AA9CJ,IAAM,gBAAA,EAAkB,CAAC;AAAA,EACvB,QAAA;AAAA,EACA,UAAA,EAAY,KAAA,CAAA;AAAA,EACZ,KAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA,EAAc,CAAC,CAAA;AAAA,EACf,EAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,iBAAA,EAAmB,IAAA;AAAA,EACnB,IAAA;AAAA,EACA,SAAA;AAAA,EACA,IAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA,EAAS,KAAA;AACX,CAAA,EAAA,GAA4B;AAC1B,EAAA,MAAM,EAAE,UAAA,EAAY,SAAA,EAAW,UAAA,EAAY,SAAA,EAAW,WAAW,EAAA,EAC/D,mCAAA,EAAc,GAAG,CAAC,CAAA;AAEpB,EAAA,MAAM,MAAA,EAAQ;AAAA,IACZ,SAAA,EAAW,cAAA,CAAI,SAAA,CAAU,QAAA,CAAS,SAAS,CAAA;AAAA,IAC3C;AAAA,EACF,CAAA;AA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A;AAEgC,YAAA;AAC9BC,cAAAA;AAAA,cAAA;AACkB,gBAAA;AACZ,gBAAA;AACmB,gBAAA;AACzB,gBAAA;AAAA,cAAA;AAED,YAAA;AAGM,4BAAA;AAEA,4BAAA;AAQV,UAAA;AAAA,QAAA;AACF,MAAA;AAAA,IAAA;AACF,EAAA;AAEJ;AAEe;ADiE6B;AACA;AG7Q7B;AH+Q6B;AACA;AACA;AACA;AACA","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-JDRMKZ35.cjs","sourcesContent":[null,"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"]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-T3CCNJHK.js";
|
|
4
4
|
import {
|
|
5
5
|
FieldValidationError_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WKM2D7LF.js";
|
|
7
7
|
import {
|
|
8
8
|
useFormContext
|
|
9
9
|
} from "./chunk-HWDQZO7X.js";
|
|
@@ -17,7 +17,22 @@ import {
|
|
|
17
17
|
Checkbox,
|
|
18
18
|
CheckboxGroup as NextCheckboxGroup
|
|
19
19
|
} from "@nextui-org/checkbox";
|
|
20
|
+
import { tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
20
21
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
22
|
+
var checkboxGroupVariants = tv({
|
|
23
|
+
slots: {
|
|
24
|
+
base: "group",
|
|
25
|
+
// Needs group for group-data condition
|
|
26
|
+
errorMessage: "text-tiny",
|
|
27
|
+
itemBase: "",
|
|
28
|
+
itemIcon: "",
|
|
29
|
+
itemLabel: "text-sm",
|
|
30
|
+
itemWrapper: "",
|
|
31
|
+
// See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/select.ts
|
|
32
|
+
label: "text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger",
|
|
33
|
+
wrapper: ""
|
|
34
|
+
}
|
|
35
|
+
});
|
|
21
36
|
var CheckboxGroup = ({
|
|
22
37
|
className = void 0,
|
|
23
38
|
label = void 0,
|
|
@@ -28,6 +43,19 @@ var CheckboxGroup = ({
|
|
|
28
43
|
}) => {
|
|
29
44
|
const { getFieldState, control } = useFormContext();
|
|
30
45
|
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
46
|
+
const variants = checkboxGroupVariants();
|
|
47
|
+
const classNames = variantsToClassNames(variants, className, "base");
|
|
48
|
+
const itemClassName = {
|
|
49
|
+
base: classNames.itemBase,
|
|
50
|
+
wrapper: classNames.itemWrapper,
|
|
51
|
+
icon: classNames.itemIcon,
|
|
52
|
+
label: classNames.itemLabel
|
|
53
|
+
};
|
|
54
|
+
const itemGroupClassName = {
|
|
55
|
+
base: classNames.base,
|
|
56
|
+
wrapper: classNames.wrapper,
|
|
57
|
+
label: classNames.label
|
|
58
|
+
};
|
|
31
59
|
return /* @__PURE__ */ jsx(
|
|
32
60
|
Controller,
|
|
33
61
|
{
|
|
@@ -38,23 +66,25 @@ var CheckboxGroup = ({
|
|
|
38
66
|
return /* @__PURE__ */ jsx(
|
|
39
67
|
NextCheckboxGroup,
|
|
40
68
|
{
|
|
41
|
-
|
|
69
|
+
name,
|
|
70
|
+
classNames: itemGroupClassName,
|
|
42
71
|
"data-testid": testId,
|
|
43
|
-
|
|
72
|
+
"data-invalid": invalid,
|
|
73
|
+
errorMessage: error && /* @__PURE__ */ jsx(
|
|
74
|
+
FieldValidationError_default,
|
|
75
|
+
{
|
|
76
|
+
error,
|
|
77
|
+
className: classNames.errorMessage
|
|
78
|
+
}
|
|
79
|
+
),
|
|
44
80
|
isDisabled: disabled,
|
|
45
81
|
isInvalid: invalid,
|
|
46
82
|
isRequired: required,
|
|
47
83
|
label: label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
48
|
-
/* @__PURE__ */ jsxs(
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
children: [
|
|
53
|
-
label,
|
|
54
|
-
/* @__PURE__ */ jsx(FieldCopyTestIdButton_default, { testId })
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
),
|
|
84
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
85
|
+
label,
|
|
86
|
+
/* @__PURE__ */ jsx(FieldCopyTestIdButton_default, { testId })
|
|
87
|
+
] }),
|
|
58
88
|
...options.length === 1 ? {
|
|
59
89
|
value: [value].filter((v) => v !== void 0),
|
|
60
90
|
onChange: (newValue) => onChange(newValue && newValue[0])
|
|
@@ -68,6 +98,8 @@ var CheckboxGroup = ({
|
|
|
68
98
|
return /* @__PURE__ */ jsx(
|
|
69
99
|
Checkbox,
|
|
70
100
|
{
|
|
101
|
+
"data-invalid": invalid,
|
|
102
|
+
classNames: itemClassName,
|
|
71
103
|
isDisabled: disabled || option.disabled,
|
|
72
104
|
value: option?.value,
|
|
73
105
|
"data-testid": slugify(
|
|
@@ -93,4 +125,4 @@ export {
|
|
|
93
125
|
CheckboxGroup_default,
|
|
94
126
|
CheckboxGroup_default2
|
|
95
127
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
128
|
+
//# sourceMappingURL=chunk-JG5VQZ4V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/CheckboxGroup/CheckboxGroup.tsx","../src/CheckboxGroup/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\n\nimport { Controller } from 'react-hook-form';\n\nimport {\n Checkbox,\n CheckboxGroup as NextCheckboxGroup,\n} from '@nextui-org/checkbox';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { slugify } from '../helpers';\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport const checkboxGroupVariants = tv({\n slots: {\n base: 'group', // Needs group for group-data condition\n errorMessage: 'text-tiny',\n itemBase: '',\n itemIcon: '',\n itemLabel: 'text-sm',\n itemWrapper: '',\n // See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/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 },\n});\n\ntype VariantProps = TVProps<typeof checkboxGroupVariants>;\ntype ClassName = TVClassName<typeof checkboxGroupVariants>;\n\nexport type CheckboxGroupOption = {\n /** option label */\n label?: React.ReactNode;\n /** option value */\n value: string;\n /** disables the option */\n disabled?: boolean;\n /** HTML data-testid attribute of the option */\n testId?: string;\n};\n\nexport interface CheckboxGroupProps extends VariantProps {\n /** CSS class name. ClassName: string | { buttons?: string | { base?: string; active?: string }; base?: string;} */\n className?: ClassName;\n /** label displayed above the Checkboxes */\n label?: React.ReactNode;\n /** Name the Field is registered on the form. */\n name: string;\n /** Checkboxes that should be displayed. */\n options: CheckboxGroupOption[];\n /** sets all buttons disabled */\n disabled?: boolean;\n /** id for internal testing. */\n testId?: string;\n}\n\n/**\n * CheckboxGroup component based on [NextUI CheckboxGroup](https://nextui.org/docs/components/checkbox-group)\n */\nconst CheckboxGroup = ({\n className = undefined,\n label = undefined,\n options,\n disabled = false,\n name,\n testId: _testId = undefined,\n}: CheckboxGroupProps) => {\n const { getFieldState, control } = useFormContext();\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n const variants = checkboxGroupVariants();\n const classNames = variantsToClassNames(variants, className, 'base');\n\n const itemClassName = {\n base: classNames.itemBase,\n wrapper: classNames.itemWrapper,\n icon: classNames.itemIcon,\n label: classNames.itemLabel,\n };\n const itemGroupClassName = {\n base: classNames.base,\n wrapper: classNames.wrapper,\n label: classNames.label,\n };\n\n return (\n <Controller\n control={control}\n name={name}\n disabled={disabled}\n render={({ field: { onChange, value, ref, onBlur } }) => {\n return (\n <NextCheckboxGroup\n name={name}\n classNames={itemGroupClassName}\n data-testid={testId}\n // See NextUI styles for group-data condition (data-invalid), e.g.: https://github.com/nextui-org/nextui/blob/main/packages/components/select/src/use-select.ts\n data-invalid={invalid}\n errorMessage={\n error && (\n <FieldValidationError\n error={error}\n className={classNames.errorMessage}\n />\n )\n }\n isDisabled={disabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label>\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </label>\n )\n }\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...(options.length === 1\n ? {\n value: [value].filter((v) => v !== undefined),\n onChange: (newValue) => onChange(newValue && newValue[0]),\n }\n : {\n onChange,\n value,\n })}\n onBlur={onBlur}\n ref={ref}\n >\n {options?.map((option) => {\n return (\n <Checkbox\n data-invalid={invalid}\n classNames={itemClassName}\n key={`index_${option.value}`}\n isDisabled={disabled || option.disabled}\n value={option?.value}\n data-testid={slugify(\n `${testId}_option_${option?.testId || option?.value}`,\n )}\n >\n {option?.label}\n </Checkbox>\n );\n })}\n </NextCheckboxGroup>\n );\n }}\n />\n );\n};\n\nexport default CheckboxGroup;\n","import CheckboxGroup from './CheckboxGroup';\n\nexport type { CheckboxGroupProps, CheckboxGroupOption } from './CheckboxGroup';\n\nexport { CheckboxGroup };\n\nexport default CheckboxGroup;\n"],"mappings":";;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAE3B;AAAA,EACE;AAAA,EACA,iBAAiB;AAAA,OACZ;AAEP,SAAS,IAAI,4BAA4B;AA+FzB,cAYA,YAZA;AAxFT,IAAM,wBAAwB,GAAG;AAAA,EACtC,OAAO;AAAA,IACL,MAAM;AAAA;AAAA,IACN,cAAc;AAAA,IACd,UAAU;AAAA,IACV,UAAU;AAAA,IACV,WAAW;AAAA,IACX,aAAa;AAAA;AAAA,IAEb,OACE;AAAA,IACF,SAAS;AAAA,EACX;AACF,CAAC;AAkCD,IAAM,gBAAgB,CAAC;AAAA,EACrB,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA,QAAQ,UAAU;AACpB,MAA0B;AACxB,QAAM,EAAE,eAAe,QAA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