@fuf-stack/uniform 0.4.0 → 0.6.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.cjs.map +1 -1
- package/dist/Form/index.d.cts +2 -2
- package/dist/Form/index.d.ts +2 -2
- package/dist/Form/index.js +1 -1
- package/dist/{Form-Bv0R3QNk.d.cts → Form-nJbG1hNH.d.cts} +1 -1
- package/dist/{Form-Bv0R3QNk.d.ts → Form-nJbG1hNH.d.ts} +1 -1
- package/dist/Grid/index.cjs.map +1 -1
- package/dist/Input/index.cjs +3 -3
- package/dist/Input/index.cjs.map +1 -1
- package/dist/Input/index.js +2 -2
- 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.cjs.map +1 -1
- 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-3K4JQTPQ.js +205 -0
- package/dist/chunk-3K4JQTPQ.js.map +1 -0
- package/dist/chunk-3SSUEUB5.js +81 -0
- package/dist/chunk-3SSUEUB5.js.map +1 -0
- package/dist/chunk-53AGVLUG.cjs +287 -0
- package/dist/chunk-53AGVLUG.cjs.map +1 -0
- package/dist/chunk-57OFVPRD.js +287 -0
- package/dist/chunk-57OFVPRD.js.map +1 -0
- package/dist/chunk-6GN255GP.cjs.map +1 -1
- package/dist/chunk-BBB4FEY6.cjs.map +1 -1
- package/dist/{chunk-OYXZQOGU.js → chunk-BGSQU5EH.js} +4 -4
- package/dist/{chunk-2CKPLOCK.cjs → chunk-FASB7HG3.cjs} +5 -5
- package/dist/chunk-FASB7HG3.cjs.map +1 -0
- package/dist/{chunk-BNTEIMNY.cjs → chunk-JFCOC5TW.cjs} +32 -25
- package/dist/chunk-JFCOC5TW.cjs.map +1 -0
- package/dist/chunk-JR7MAHBR.cjs +81 -0
- package/dist/chunk-JR7MAHBR.cjs.map +1 -0
- package/dist/chunk-KC3PZFGE.js +76 -0
- package/dist/chunk-KC3PZFGE.js.map +1 -0
- package/dist/{chunk-HT3LKDHX.cjs → chunk-KMMS4G7A.cjs} +4 -2
- package/dist/chunk-KMMS4G7A.cjs.map +1 -0
- package/dist/chunk-OSEU4ZUE.cjs +205 -0
- package/dist/chunk-OSEU4ZUE.cjs.map +1 -0
- package/dist/{chunk-5FMJUJ7H.js → chunk-QD6IQL6U.js} +3 -3
- package/dist/{chunk-5FMJUJ7H.js.map → chunk-QD6IQL6U.js.map} +1 -1
- package/dist/chunk-QTL5FREE.cjs.map +1 -1
- package/dist/{chunk-OV5RMSYD.js → chunk-T3CCNJHK.js} +4 -2
- package/dist/chunk-T3CCNJHK.js.map +1 -0
- package/dist/chunk-WNESYY6E.cjs +239 -0
- package/dist/chunk-WNESYY6E.cjs.map +1 -0
- package/dist/chunk-WQRM7G4C.cjs.map +1 -1
- package/dist/chunk-WRYE2CF5.cjs +76 -0
- package/dist/chunk-WRYE2CF5.cjs.map +1 -0
- package/dist/{chunk-AGAYQTFD.cjs → chunk-XJ3JTLXZ.cjs} +3 -3
- package/dist/chunk-XJ3JTLXZ.cjs.map +1 -0
- package/dist/{chunk-KFRKKWZT.js → chunk-Y4CFVCUN.js} +32 -25
- package/dist/chunk-Y4CFVCUN.js.map +1 -0
- package/dist/chunk-YAVU7ZYD.js +239 -0
- package/dist/chunk-YAVU7ZYD.js.map +1 -0
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/index.cjs +25 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +26 -6
- package/dist/partials/FieldCopyTestIdButton/index.cjs +2 -2
- package/dist/partials/FieldCopyTestIdButton/index.cjs.map +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.js +1 -1
- package/dist/partials/FieldValidationError/index.cjs.map +1 -1
- package/package.json +44 -19
- package/dist/chunk-2CKPLOCK.cjs.map +0 -1
- package/dist/chunk-AGAYQTFD.cjs.map +0 -1
- package/dist/chunk-BNTEIMNY.cjs.map +0 -1
- package/dist/chunk-HT3LKDHX.cjs.map +0 -1
- package/dist/chunk-KFRKKWZT.js.map +0 -1
- package/dist/chunk-OV5RMSYD.js.map +0 -1
- /package/dist/{chunk-OYXZQOGU.js.map → chunk-BGSQU5EH.js.map} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkWRYE2CF5cjs = require('../chunk-WRYE2CF5.cjs');
|
|
5
|
+
require('../chunk-KMMS4G7A.cjs');
|
|
6
|
+
require('../chunk-QTL5FREE.cjs');
|
|
7
|
+
require('../chunk-WQRM7G4C.cjs');
|
|
8
|
+
require('../chunk-BBB4FEY6.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.TextArea = _chunkWRYE2CF5cjs.TextArea_default; exports.default = _chunkWRYE2CF5cjs.TextArea_default2;
|
|
13
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/TextArea/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,6GAAC","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/TextArea/index.cjs"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TextArea_default,
|
|
3
|
+
TextArea_default2
|
|
4
|
+
} from "../chunk-KC3PZFGE.js";
|
|
5
|
+
import "../chunk-T3CCNJHK.js";
|
|
6
|
+
import "../chunk-DBLODROX.js";
|
|
7
|
+
import "../chunk-BCMPSLSG.js";
|
|
8
|
+
import "../chunk-V46BHM2U.js";
|
|
9
|
+
export {
|
|
10
|
+
TextArea_default as TextArea,
|
|
11
|
+
TextArea_default2 as default
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface TextAreaProps {
|
|
5
|
+
/** Child components. The content of the textarea. */
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
/** CSS class name */
|
|
8
|
+
className?: string;
|
|
9
|
+
/** Determines if the TextArea is disabled or not. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Label displayed above the TextArea. */
|
|
12
|
+
label?: ReactNode;
|
|
13
|
+
/** Name the TextArea is registered at in HTML forms (react-hook-form). */
|
|
14
|
+
name: string;
|
|
15
|
+
/** placeholder for the textArea content. */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Id to grab element in internal tests. */
|
|
18
|
+
testId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* TextArea component based on [NextUI TextArea](https://nextui.org/docs/components/textarea)
|
|
22
|
+
*/
|
|
23
|
+
declare const TextArea: ({ children, className, disabled, label, name, placeholder, testId: _testId, }: TextAreaProps) => react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
25
|
+
export { TextArea as T, type TextAreaProps as a };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface TextAreaProps {
|
|
5
|
+
/** Child components. The content of the textarea. */
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
/** CSS class name */
|
|
8
|
+
className?: string;
|
|
9
|
+
/** Determines if the TextArea is disabled or not. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Label displayed above the TextArea. */
|
|
12
|
+
label?: ReactNode;
|
|
13
|
+
/** Name the TextArea is registered at in HTML forms (react-hook-form). */
|
|
14
|
+
name: string;
|
|
15
|
+
/** placeholder for the textArea content. */
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
/** Id to grab element in internal tests. */
|
|
18
|
+
testId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* TextArea component based on [NextUI TextArea](https://nextui.org/docs/components/textarea)
|
|
22
|
+
*/
|
|
23
|
+
declare const TextArea: ({ children, className, disabled, label, name, placeholder, testId: _testId, }: TextAreaProps) => react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
25
|
+
export { TextArea as T, type TextAreaProps as a };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldCopyTestIdButton_default
|
|
3
|
+
} from "./chunk-T3CCNJHK.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/RadioGroup/RadioGroup.tsx
|
|
15
|
+
import { Controller } from "react-hook-form";
|
|
16
|
+
import { ButtonGroup as NextButtonGroup } from "@nextui-org/button";
|
|
17
|
+
import { RadioGroup as NextRadioGroup, Radio } from "@nextui-org/radio";
|
|
18
|
+
import { cn as cn3 } from "@fuf-stack/pixel-utils";
|
|
19
|
+
|
|
20
|
+
// src/RadioGroup/Variants/RadioBox.tsx
|
|
21
|
+
import { useRadio } from "@nextui-org/radio";
|
|
22
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
23
|
+
import { cn } from "@fuf-stack/pixel-utils";
|
|
24
|
+
import { jsx, jsxs } from "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
|
+
} = useRadio(props);
|
|
38
|
+
return /* @__PURE__ */ jsxs(
|
|
39
|
+
Component,
|
|
40
|
+
{
|
|
41
|
+
...getBaseProps(),
|
|
42
|
+
className: cn(
|
|
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__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", { ...getInputProps() }) }),
|
|
51
|
+
/* @__PURE__ */ jsx("span", { ...getWrapperProps(), children: /* @__PURE__ */ jsx("span", { ...getControlProps() }) }),
|
|
52
|
+
icon,
|
|
53
|
+
/* @__PURE__ */ jsxs(
|
|
54
|
+
"div",
|
|
55
|
+
{
|
|
56
|
+
...getLabelWrapperProps(),
|
|
57
|
+
className: cn(getLabelWrapperProps().className, "grow"),
|
|
58
|
+
children: [
|
|
59
|
+
children && /* @__PURE__ */ jsx("span", { ...getLabelProps(), children }),
|
|
60
|
+
description && /* @__PURE__ */ jsx("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
|
+
import { cn as cn2 } from "@fuf-stack/pixel-utils";
|
|
71
|
+
import { Button } from "@fuf-stack/pixels";
|
|
72
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
73
|
+
var RadioButton = ({
|
|
74
|
+
className = void 0,
|
|
75
|
+
value,
|
|
76
|
+
isDisabled = false,
|
|
77
|
+
onChange,
|
|
78
|
+
children
|
|
79
|
+
}) => {
|
|
80
|
+
return /* @__PURE__ */ jsx2(
|
|
81
|
+
Button,
|
|
82
|
+
{
|
|
83
|
+
className: cn2(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
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
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 } = useFormContext();
|
|
107
|
+
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
108
|
+
return /* @__PURE__ */ jsx3(
|
|
109
|
+
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__ */ jsx3(
|
|
119
|
+
RadioBox,
|
|
120
|
+
{
|
|
121
|
+
"data-testid": slugify(
|
|
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__ */ jsx3(
|
|
136
|
+
RadioButton,
|
|
137
|
+
{
|
|
138
|
+
"data-testid": slugify(
|
|
139
|
+
`${testId}_option_${option.testId || option.value}`
|
|
140
|
+
),
|
|
141
|
+
isDisabled: isDisabled || option.disabled,
|
|
142
|
+
value: option.value,
|
|
143
|
+
onChange,
|
|
144
|
+
className: cn3(
|
|
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__ */ jsx3(
|
|
154
|
+
Radio,
|
|
155
|
+
{
|
|
156
|
+
"data-testid": slugify(
|
|
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__ */ jsx3(
|
|
168
|
+
NextRadioGroup,
|
|
169
|
+
{
|
|
170
|
+
className,
|
|
171
|
+
"data-testid": testId,
|
|
172
|
+
errorMessage: error && /* @__PURE__ */ jsx3(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__ */ jsxs2("label", { className: `${invalid ? "text-danger" : ""}`, children: [
|
|
178
|
+
label,
|
|
179
|
+
/* @__PURE__ */ jsx3(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__ */ jsx3(NextButtonGroup, { 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
|
+
export {
|
|
202
|
+
RadioGroup_default,
|
|
203
|
+
RadioGroup_default2
|
|
204
|
+
};
|
|
205
|
+
//# sourceMappingURL=chunk-3K4JQTPQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/RadioGroup/RadioGroup.tsx","../src/RadioGroup/Variants/RadioBox.tsx","../src/RadioGroup/Variants/RadioButton.tsx","../src/RadioGroup/index.ts"],"sourcesContent":["import type { 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"],"mappings":";;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAE3B,SAAS,eAAe,uBAAuB;AAC/C,SAAS,cAAc,gBA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
import {
|
|
5
|
+
FieldValidationError_default
|
|
6
|
+
} from "./chunk-DBLODROX.js";
|
|
7
|
+
import {
|
|
8
|
+
useFormContext
|
|
9
|
+
} from "./chunk-BCMPSLSG.js";
|
|
10
|
+
|
|
11
|
+
// src/Switch/Switch.tsx
|
|
12
|
+
import { Controller } from "react-hook-form";
|
|
13
|
+
import { useInput } from "@nextui-org/input";
|
|
14
|
+
import { Switch as NextSwitch } from "@nextui-org/switch";
|
|
15
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var Switch = ({
|
|
17
|
+
className,
|
|
18
|
+
disabled = false,
|
|
19
|
+
label: _label = void 0,
|
|
20
|
+
name,
|
|
21
|
+
testId: _testId = void 0
|
|
22
|
+
}) => {
|
|
23
|
+
const { control, getFieldState } = useFormContext();
|
|
24
|
+
const { error, required, testId, invalid } = getFieldState(name, _testId);
|
|
25
|
+
const { label, getInputProps, getHelperWrapperProps, getErrorMessageProps } = useInput({
|
|
26
|
+
errorMessage: JSON.stringify(error),
|
|
27
|
+
isInvalid: invalid,
|
|
28
|
+
isRequired: required,
|
|
29
|
+
label: _label,
|
|
30
|
+
labelPlacement: "outside",
|
|
31
|
+
placeholder: " "
|
|
32
|
+
});
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
Controller,
|
|
35
|
+
{
|
|
36
|
+
name,
|
|
37
|
+
control,
|
|
38
|
+
disabled,
|
|
39
|
+
render: ({
|
|
40
|
+
field: { disabled: isDisabled, value, ref, onBlur, onChange }
|
|
41
|
+
}) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
42
|
+
/* @__PURE__ */ jsxs(
|
|
43
|
+
NextSwitch,
|
|
44
|
+
{
|
|
45
|
+
"aria-describedby": getInputProps()["aria-describedby"],
|
|
46
|
+
required,
|
|
47
|
+
isSelected: !!value,
|
|
48
|
+
className,
|
|
49
|
+
classNames: {
|
|
50
|
+
label: `text-bold block text-ellipsis text-small ${invalid ? "text-danger" : ""}`
|
|
51
|
+
},
|
|
52
|
+
"data-testid": testId,
|
|
53
|
+
isDisabled,
|
|
54
|
+
value,
|
|
55
|
+
onChange,
|
|
56
|
+
onBlur,
|
|
57
|
+
name,
|
|
58
|
+
ref,
|
|
59
|
+
children: [
|
|
60
|
+
label,
|
|
61
|
+
!!required && !!_label && /* @__PURE__ */ jsx("span", { className: "!text-danger", children: " *" }),
|
|
62
|
+
/* @__PURE__ */ jsx(FieldCopyTestIdButton_default, { testId })
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
error && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
67
|
+
/* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx(FieldValidationError_default, { error }) }) })
|
|
68
|
+
] })
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
var Switch_default = Switch;
|
|
73
|
+
|
|
74
|
+
// src/Switch/index.ts
|
|
75
|
+
var Switch_default2 = Switch_default;
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
Switch_default,
|
|
79
|
+
Switch_default2
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=chunk-3SSUEUB5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Switch/Switch.tsx","../src/Switch/index.ts"],"sourcesContent":["import { Controller } from 'react-hook-form';\n\nimport { useInput } from '@nextui-org/input';\nimport { Switch as NextSwitch } from '@nextui-org/switch';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport interface SwitchProps {\n /** CSS class name */\n className: string;\n /** whether the select should be disabled */\n disabled?: boolean;\n /** component displayed next to the switch. */\n label: React.ReactNode;\n /** name the field is registered under */\n name: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * Switch component based on [NextUI Switch](https://nextui.org/docs/components/switch)\n */\nconst Switch = ({\n className,\n disabled = false,\n label: _label = undefined,\n name,\n testId: _testId = undefined,\n}: SwitchProps) => {\n const { control, getFieldState } = useFormContext();\n const { error, required, testId, invalid } = getFieldState(name, _testId);\n\n const { label, getInputProps, getHelperWrapperProps, getErrorMessageProps } =\n useInput({\n errorMessage: JSON.stringify(error),\n isInvalid: invalid,\n isRequired: required,\n label: _label,\n labelPlacement: 'outside',\n placeholder: ' ',\n });\n\n return (\n <Controller\n name={name}\n control={control}\n disabled={disabled}\n render={({\n field: { disabled: isDisabled, value, ref, onBlur, onChange },\n }) => (\n <>\n <NextSwitch\n aria-describedby={getInputProps()['aria-describedby']}\n required={required}\n isSelected={!!value}\n className={className}\n classNames={{\n label: `text-bold block text-ellipsis text-small ${invalid ? 'text-danger' : ''}`,\n }}\n data-testid={testId}\n isDisabled={isDisabled}\n value={value}\n onChange={onChange}\n onBlur={onBlur}\n name={name}\n ref={ref}\n >\n {label}\n {!!required && !!_label && (\n <span className=\"!text-danger\">{' \\u002A'}</span>\n )}\n <FieldCopyTestIdButton testId={testId} />\n </NextSwitch>\n {error && (\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 <FieldValidationError error={error} />\n </div>\n </div>\n )}\n </>\n )}\n />\n );\n};\n\nexport default Switch;\n","import Switch from './Switch';\n\nexport type { SwitchProps } from './Switch';\n\nexport { Switch };\n\nexport default Switch;\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,kBAAkB;AAE3B,SAAS,gBAAgB;AACzB,SAAS,UAAU,kBAAkB;AAkD7B,mBAmBM,KAlBJ,YADF;AA5BR,IAAM,SAAS,CAAC;AAAA,EACd;AAAA,EACA,WAAW;AAAA,EACX,OAAO,SAAS;AAAA,EAChB;AAAA,EACA,QAAQ,UAAU;AACpB,MAAm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