@fuf-stack/uniform 1.30.0 → 2.0.0-next.3
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/README.md +0 -6
- package/dist/Checkboxes/index.d.mts +178 -274
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +294 -94
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +1963 -148
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +401 -82
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.d.mts +102 -97
- package/dist/FieldArray/index.d.mts.map +1 -1
- package/dist/FieldArray/index.mjs +340 -195
- package/dist/FieldArray/index.mjs.map +1 -1
- package/dist/FieldCard/index.d.mts +34 -34
- package/dist/FieldCard/index.d.mts.map +1 -1
- package/dist/FieldCard/index.mjs +181 -127
- package/dist/FieldCard/index.mjs.map +1 -1
- package/dist/{FieldCopyTestIdButton-Y9SfvaM9.mjs → FieldCopyTestIdButton-D3_jZYJ1.mjs} +4 -2
- package/dist/FieldCopyTestIdButton-D3_jZYJ1.mjs.map +1 -0
- package/dist/FieldDescription-X_0s1Lhu.mjs +35 -0
- package/dist/FieldDescription-X_0s1Lhu.mjs.map +1 -0
- package/dist/FieldLabel-DrNWJIVh.mjs +128 -0
- package/dist/FieldLabel-DrNWJIVh.mjs.map +1 -0
- package/dist/FieldLayout-DcvQU0zN.mjs +45 -0
- package/dist/FieldLayout-DcvQU0zN.mjs.map +1 -0
- package/dist/FieldReset/index.d.mts +17 -12
- package/dist/FieldReset/index.d.mts.map +1 -1
- package/dist/FieldReset/index.mjs +50 -33
- package/dist/FieldReset/index.mjs.map +1 -1
- package/dist/FieldValidationError-iAayfTEw.mjs +75 -0
- package/dist/FieldValidationError-iAayfTEw.mjs.map +1 -0
- package/dist/Form/index.d.mts +2 -2
- package/dist/Form/index.d.mts.map +1 -1
- package/dist/Form/index.mjs +9 -7
- package/dist/Form/index.mjs.map +1 -1
- package/dist/{FormContext-Dvt3MiKq.d.mts → FormContext-BnNJYZOo.d.mts} +3 -3
- package/dist/{FormContext-Dvt3MiKq.d.mts.map → FormContext-BnNJYZOo.d.mts.map} +1 -1
- package/dist/{FormContext-B8G_Xxd6.mjs → FormContext-PXkVlBdU.mjs} +6 -2
- package/dist/FormContext-PXkVlBdU.mjs.map +1 -0
- package/dist/Grid/index.mjs +1 -1
- package/dist/{Grid-Us2JFczS.mjs → Grid-DBL29Kwb.mjs} +4 -2
- package/dist/Grid-DBL29Kwb.mjs.map +1 -0
- package/dist/Input/index.d.mts +734 -47
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +411 -168
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +300 -98
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +156 -119
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +302 -76
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +274 -87
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +314 -78
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +90 -44
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +410 -142
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +284 -157
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +382 -63
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +269 -90
- package/dist/Slider/index.mjs.map +1 -1
- package/dist/SubmitButton/index.d.mts.map +1 -1
- package/dist/SubmitButton/index.mjs +4 -1
- package/dist/SubmitButton/index.mjs.map +1 -1
- package/dist/Switch/index.d.mts +2 -427
- package/dist/Switch/index.mjs +167 -72
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/Switch-Db2dpGz7.d.mts +648 -0
- package/dist/Switch-Db2dpGz7.d.mts.map +1 -0
- package/dist/SwitchBox/index.d.mts +191 -91
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +142 -88
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +347 -29
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +195 -47
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +1373 -139
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +160 -77
- package/dist/Time/index.mjs.map +1 -1
- package/dist/helpers/index.d.mts +1 -1
- package/dist/helpers/index.mjs +1 -1
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/hooks/useClientValidation/index.mjs +1 -1
- package/dist/hooks/useController/index.d.mts +29 -2
- package/dist/hooks/useController/index.d.mts.map +1 -0
- package/dist/hooks/useController/index.mjs +1 -1
- package/dist/hooks/useFormContext/index.d.mts +44 -2
- package/dist/hooks/useFormContext/index.d.mts.map +1 -0
- package/dist/hooks/useFormContext/index.mjs +1 -1
- package/dist/hooks/useInputValueDebounce/index.d.mts +9 -3
- package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
- package/dist/hooks/useInputValueDebounce/index.mjs +27 -5
- package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
- package/dist/hooks/useInputValueTransform/index.d.mts +1 -2
- package/dist/hooks/useInputValueTransform/index.mjs +1 -1
- package/dist/hooks/useWatchFormReset/index.mjs +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs +1 -1
- package/dist/{useInputValueTransform-cevZBrIN.d.mts → index-cevZBrIN.d.mts} +1 -1
- package/dist/index-cevZBrIN.d.mts.map +1 -0
- package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -1
- package/dist/partials/FieldValidationError/index.d.mts +637 -3
- package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
- package/dist/partials/FieldValidationError/index.mjs +1 -1
- package/dist/radioControlVariants-BYRfaD6y.mjs +187 -0
- package/dist/radioControlVariants-BYRfaD6y.mjs.map +1 -0
- package/dist/switchVariants-D16b2VaT.mjs +67 -0
- package/dist/switchVariants-D16b2VaT.mjs.map +1 -0
- package/dist/timeVariants-CtXyNKmW.mjs +58 -0
- package/dist/timeVariants-CtXyNKmW.mjs.map +1 -0
- package/dist/{useController-CJjMqXU5.mjs → useController-JtIeurpw.mjs} +2 -2
- package/dist/{useController-CJjMqXU5.mjs.map → useController-JtIeurpw.mjs.map} +1 -1
- package/dist/{useFormContext-BEjPBdzb.mjs → useFormContext-piqnN2L-.mjs} +2 -2
- package/dist/{useFormContext-BEjPBdzb.mjs.map → useFormContext-piqnN2L-.mjs.map} +1 -1
- package/dist/{useInputValueTransform-D44BLp1Z.mjs → useInputValueTransform-CXWWFhy_.mjs} +2 -2
- package/dist/{useInputValueTransform-D44BLp1Z.mjs.map → useInputValueTransform-CXWWFhy_.mjs.map} +1 -1
- package/package.json +13 -25
- package/dist/FieldCopyTestIdButton-Y9SfvaM9.mjs.map +0 -1
- package/dist/FieldValidationError-BcUV0r1I.mjs +0 -48
- package/dist/FieldValidationError-BcUV0r1I.mjs.map +0 -1
- package/dist/FormContext-B8G_Xxd6.mjs.map +0 -1
- package/dist/Grid-Us2JFczS.mjs.map +0 -1
- package/dist/Switch/index.d.mts.map +0 -1
- package/dist/hooks/useInput/index.d.mts +0 -2
- package/dist/hooks/useInput/index.mjs +0 -5
- package/dist/hooks/useInput/index.mjs.map +0 -1
- package/dist/hooks/useUniformField/index.d.mts +0 -2
- package/dist/hooks/useUniformField/index.mjs +0 -141
- package/dist/hooks/useUniformField/index.mjs.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.d.mts +0 -47
- package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.mjs +0 -99
- package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
- package/dist/index-CaxrMD1A.d.mts +0 -1
- package/dist/index-DsB0_365.d.mts +0 -106
- package/dist/index-DsB0_365.d.mts.map +0 -1
- package/dist/useController-CdFEp-Wa.d.mts +0 -30
- package/dist/useController-CdFEp-Wa.d.mts.map +0 -1
- package/dist/useFormContext-BSSUZ0Md.d.mts +0 -45
- package/dist/useFormContext-BSSUZ0Md.d.mts.map +0 -1
- package/dist/useInput-ClpHDPdr.d.mts +0 -2
- package/dist/useInput-NPbS4w_n.mjs +0 -1
- package/dist/useInputValueTransform-cevZBrIN.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/Radios/Radios.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/Radios/radiosVariants.ts","../../src/Radios/Radios.tsx"],"mappings":";;qBAMa,kBAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoCf,eAAe,eAAe;KAE9B,YAAY,mBAAmB;UCpC1B;;EAEf;;EAEA,OAAO;;EAEP,QAAQ;;EAER,OAAO;;EAEP;;EAEA;;UAGe;;EAEf,QAAQ;;EAER,OAAO;;EAEP;;IAEE;;IAEA;;IAEA;;;UAIa,oBAAoB;;EAEnC;;EAEA,YAAY,SAAS,0BAA0B;;EAE/C,YAAY;;EAEZ,cAAc;;EAEd;;EAEA;;EAEA,QAAQ;;EAER;;EAEA,SAAS;;EAET;;EAEA;;;cAII,WAAU,UAAA,WAAA,QAAA,MAAA,YAAA,qBAOb,gBAAc"}
|
package/dist/Radios/index.mjs
CHANGED
|
@@ -1,47 +1,64 @@
|
|
|
1
|
+
import { n as useUniformField } from "../FieldLabel-DrNWJIVh.mjs";
|
|
1
2
|
import { createOptionValueConverter } from "../helpers/index.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { n as getFieldControlProps } from "../FieldDescription-X_0s1Lhu.mjs";
|
|
4
|
+
import { t as FieldLayout } from "../FieldLayout-DcvQU0zN.mjs";
|
|
5
|
+
import { i as RadioGroupField, n as RadioControl, r as radioGroupFieldVariants, t as radioControlVariants } from "../radioControlVariants-BYRfaD6y.mjs";
|
|
4
6
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
+
import { slugify, tv } from "@fuf-stack/pixel-utils";
|
|
8
|
+
import { useStyling } from "@fuf-stack/pixels/StylingProvider";
|
|
9
|
+
import { Label } from "react-aria-components";
|
|
10
|
+
// src/Radios/radiosVariants.ts
|
|
7
11
|
const radiosVariants = tv({
|
|
12
|
+
extend: radioGroupFieldVariants,
|
|
8
13
|
slots: {
|
|
14
|
+
/** Container for the field control and supporting text */
|
|
9
15
|
base: [
|
|
10
16
|
"group",
|
|
11
17
|
"flex w-full flex-col",
|
|
12
18
|
"gap-y-1.5"
|
|
13
19
|
],
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
/** Container for validation messages */
|
|
21
|
+
errorMessage: "text-danger text-tiny",
|
|
22
|
+
/** Clickable radio option */
|
|
23
|
+
itemBase: "",
|
|
24
|
+
/** Indicator marking the selected option */
|
|
16
25
|
itemControl: "bg-focus group-data-[invalid=true]:bg-danger",
|
|
26
|
+
/** Supporting text below an option label */
|
|
17
27
|
itemDescription: "",
|
|
28
|
+
/** Primary option text */
|
|
18
29
|
itemLabel: "text-sm",
|
|
30
|
+
/** Container grouping option text */
|
|
19
31
|
itemLabelWrapper: "ml-2",
|
|
32
|
+
/** Outline around the selection indicator */
|
|
20
33
|
itemWrapper: "group-data-[invalid=true]:border-danger! [&:not(group-data-[invalid=\"true\"]):not(group-data-[selected=\"false\"])]:border-focus",
|
|
34
|
+
/** Visible field label */
|
|
21
35
|
label: "mb-2 inline-flex cursor-default text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:text-danger",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
/** Container arranging the selectable content */
|
|
37
|
+
wrapper: "flex flex-col flex-wrap gap-2 data-[orientation=horizontal]:flex-row"
|
|
38
|
+
}
|
|
25
39
|
});
|
|
40
|
+
// src/Radios/subcomponents/RadiosControl.tsx
|
|
26
41
|
/**
|
|
27
|
-
*
|
|
42
|
+
* Radio options and custom list composition
|
|
43
|
+
*
|
|
44
|
+
* @see https://react-aria.adobe.com/RadioGroup
|
|
28
45
|
*/
|
|
29
|
-
const
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
46
|
+
const RadiosControl = ({ field, children, className, inline = false, options }) => {
|
|
47
|
+
const { description, disabled, errorMessage, ids, ref: inputRef, invalid, label, name, onBlur, onChange: onValueChange, readOnly, required, testId, value } = field;
|
|
48
|
+
const controlProps = getFieldControlProps(field);
|
|
49
|
+
const styling = useStyling();
|
|
34
50
|
const { convertToOriginalType } = createOptionValueConverter(options);
|
|
35
|
-
const variants = radiosVariants
|
|
36
|
-
const classNames = variantsToClassNames(variants, className, "base");
|
|
37
|
-
const
|
|
51
|
+
const variants = styling.resolve(radiosVariants, { readOnly });
|
|
52
|
+
const classNames = styling.variantsToClassNames(variants, className, "base");
|
|
53
|
+
const optionVariants = styling.resolve(radioControlVariants, { invalid });
|
|
54
|
+
const itemClassNames = styling.variantsToClassNames(optionVariants, {
|
|
38
55
|
base: classNames.itemBase,
|
|
39
56
|
control: classNames.itemControl,
|
|
40
57
|
description: classNames.itemDescription,
|
|
41
58
|
label: classNames.itemLabel,
|
|
42
59
|
labelWrapper: classNames.itemLabelWrapper,
|
|
43
60
|
wrapper: classNames.itemWrapper
|
|
44
|
-
};
|
|
61
|
+
});
|
|
45
62
|
const selectedValue = value != null ? String(value) : "";
|
|
46
63
|
const renderedOptions = options.map((option) => {
|
|
47
64
|
const optionTestId = slugify(`${testId}_option_${option.testId ?? option.value}`, { replaceDots: true });
|
|
@@ -49,10 +66,11 @@ const Radios = ({ children = void 0, className = void 0, inline = false, name, o
|
|
|
49
66
|
const optionValue = String(option.value);
|
|
50
67
|
return {
|
|
51
68
|
option,
|
|
52
|
-
radio: /* @__PURE__ */ jsx(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
radio: /* @__PURE__ */ jsx(RadioControl, {
|
|
70
|
+
className: itemClassNames,
|
|
71
|
+
disabled: optionIsDisabled,
|
|
72
|
+
invalid,
|
|
73
|
+
testId: optionTestId,
|
|
56
74
|
value: optionValue,
|
|
57
75
|
children: option.label ?? option.value
|
|
58
76
|
}, optionValue),
|
|
@@ -63,31 +81,59 @@ const Radios = ({ children = void 0, className = void 0, inline = false, name, o
|
|
|
63
81
|
}
|
|
64
82
|
};
|
|
65
83
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
const handleChange = (nextValue) => {
|
|
85
|
+
onValueChange(convertToOriginalType(nextValue));
|
|
86
|
+
};
|
|
87
|
+
return /* @__PURE__ */ jsx(FieldLayout, {
|
|
88
|
+
baseAs: RadioGroupField,
|
|
89
|
+
baseProps: {
|
|
90
|
+
controlProps,
|
|
91
|
+
dataComponent: "radios",
|
|
92
|
+
disabled,
|
|
93
|
+
inline,
|
|
94
|
+
inputRef,
|
|
95
|
+
invalid,
|
|
96
|
+
name,
|
|
97
|
+
onBlur,
|
|
98
|
+
onChange: handleChange,
|
|
99
|
+
readOnly,
|
|
100
|
+
required,
|
|
101
|
+
testId,
|
|
102
|
+
value
|
|
83
103
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
className: classNames,
|
|
105
|
+
description,
|
|
106
|
+
errorMessage,
|
|
107
|
+
ids,
|
|
108
|
+
invalid,
|
|
109
|
+
label,
|
|
110
|
+
labelAs: Label,
|
|
111
|
+
required,
|
|
112
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
113
|
+
className: classNames.wrapper,
|
|
114
|
+
"data-orientation": inline ? "horizontal" : "vertical",
|
|
115
|
+
"data-slot": "wrapper",
|
|
116
|
+
children: children ? children(renderedOptions) : renderedOptions.map(({ radio }) => {
|
|
117
|
+
return radio;
|
|
118
|
+
})
|
|
88
119
|
})
|
|
89
120
|
});
|
|
90
121
|
};
|
|
122
|
+
// src/Radios/Radios.tsx
|
|
123
|
+
/** Form selection field for one radio option */
|
|
124
|
+
const Radios = ({ children = void 0, className = void 0, inline = false, name, options, ...uniformFieldProps }) => {
|
|
125
|
+
const { field } = useUniformField({
|
|
126
|
+
...uniformFieldProps,
|
|
127
|
+
name
|
|
128
|
+
});
|
|
129
|
+
return /* @__PURE__ */ jsx(RadiosControl, {
|
|
130
|
+
className,
|
|
131
|
+
field,
|
|
132
|
+
inline,
|
|
133
|
+
options,
|
|
134
|
+
children
|
|
135
|
+
});
|
|
136
|
+
};
|
|
91
137
|
// src/Radios/index.ts
|
|
92
138
|
var Radios_default = Radios;
|
|
93
139
|
export { Radios_default as default, radiosVariants };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["HeroRadio","HeroRadioGroup"],"sources":["../../src/Radios/Radios.tsx","../../src/Radios/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { ReactElement, ReactNode } from 'react';\n\nimport {\n Radio as HeroRadio,\n RadioGroup as HeroRadioGroup,\n} from '@heroui/radio';\n\nimport { slugify, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { createOptionValueConverter } from '../helpers';\nimport { useUniformField } from '../hooks/useUniformField';\n\nexport const radiosVariants = tv({\n slots: {\n base: [\n // Needs group for group-data condition.\n 'group',\n // Match shared field wrapper layout.\n 'flex w-full flex-col',\n // Keep spacing between label/group consistent.\n 'gap-y-1.5',\n ],\n errorMessage: '',\n itemBase: [\n // HeroUI disables pointer events on disabled options, which hides the\n // cursor; re-enable them (the disabled input still blocks changes).\n 'data-[disabled=true]:pointer-events-auto data-[disabled=true]:cursor-not-allowed',\n // The hidden native input covers the option and keeps the browser's\n // default cursor, so override every descendant too.\n 'data-[disabled=true]:**:cursor-not-allowed',\n ],\n itemControl: 'bg-focus group-data-[invalid=true]:bg-danger',\n itemDescription: '',\n itemLabel: 'text-sm',\n itemLabelWrapper: 'ml-2',\n itemWrapper:\n 'group-data-[invalid=true]:border-danger! [&:not(group-data-[invalid=\"true\"]):not(group-data-[selected=\"false\"])]:border-focus',\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/select.ts\n label:\n 'mb-2 inline-flex cursor-default text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:text-danger',\n wrapper: '',\n },\n variants: {\n readOnly: {\n true: {\n // Inner controls set their own cursors, so override every descendant.\n base: '**:cursor-not-allowed cursor-not-allowed opacity-disabled',\n },\n },\n },\n});\n\ntype VariantProps = TVProps<typeof radiosVariants>;\ntype ClassName = TVClassName<typeof radiosVariants>;\n\nexport interface RadioOption {\n /** disables the option */\n disabled?: boolean;\n /** option icon */\n icon?: ReactNode;\n /** option label */\n label?: ReactNode;\n /** Arbitrary option metadata for custom render logic. */\n meta?: Record<string, unknown>;\n /** HTML data-testid attribute of the option */\n testId?: string;\n /** option value */\n value: string | number;\n}\n\nexport interface RadioRenderedOption {\n /** Option data as provided in `options` */\n option: RadioOption;\n /** Prebuilt radio element so consumers don't need to recreate HeroRadio */\n radio: ReactNode;\n /** Render-state flags for this option */\n state: {\n /** Whether this option is currently selected */\n selected: boolean;\n /** Whether this option is disabled */\n disabled: boolean;\n /** Whether the radio group is invalid */\n invalid: boolean;\n };\n}\n\nexport interface RadiosProps extends VariantProps {\n /** Custom aria-label for accessibility. If not provided, falls back to field name when no visible label exists */\n ariaLabel?: string;\n /** Optional child render function for custom full-list layout rendering. */\n children?: (options: RadioRenderedOption[]) => ReactNode;\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: RadioOption[];\n /** Prevents changes while keeping the radios focusable and its value in validation and submission */\n readOnly?: boolean;\n /** Id to grab element in internal tests. */\n testId?: string;\n}\n\n/**\n * Radios component based on [HeroUI RadioGroup](https://www.heroui.com//docs/components/radio-group)\n */\nconst Radios = ({\n children = undefined,\n className = undefined,\n inline = false,\n name,\n options,\n ...uniformFieldProps\n}: RadiosProps): ReactElement => {\n const {\n ariaLabel,\n disabled,\n errorMessage,\n field: { onBlur, onChange, ref, value },\n invalid,\n label,\n readOnly,\n required,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Create converter to preserve number types for option values\n const { convertToOriginalType } = createOptionValueConverter(options);\n\n // classNames from slots\n const variants = radiosVariants({ readOnly });\n const classNames = variantsToClassNames(variants, className, 'base');\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 const selectedValue = value != null ? String(value) : '';\n\n // Build option descriptors once so default and custom layouts share the same radio nodes/state.\n const renderedOptions = options.map((option) => {\n const optionTestId = slugify(\n `${testId}_option_${option.testId ?? option.value}`,\n { replaceDots: true },\n );\n const optionIsDisabled = !!disabled || !!option.disabled;\n const optionValue = String(option.value);\n const radio = (\n <HeroRadio\n key={optionValue}\n classNames={itemClassNames}\n data-testid={optionTestId}\n isDisabled={optionIsDisabled}\n value={optionValue}\n >\n {option.label ?? option.value}\n </HeroRadio>\n );\n\n return {\n option,\n radio,\n state: {\n selected: selectedValue === optionValue,\n disabled: optionIsDisabled,\n invalid: !!invalid,\n },\n };\n });\n\n return (\n <HeroRadioGroup\n ref={ref}\n aria-label={ariaLabel}\n classNames={classNames}\n // see HeroUI styles for group-data condition (data-invalid),\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/components/select/src/use-select.ts\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n errorMessage={errorMessage}\n isDisabled={disabled}\n isInvalid={invalid}\n isReadOnly={readOnly}\n isRequired={required}\n label={label ? <legend>{label}</legend> : null}\n name={name}\n onBlur={onBlur}\n onValueChange={(newValue) => {\n onChange(convertToOriginalType(newValue));\n }}\n orientation={inline ? 'horizontal' : 'vertical'}\n value={selectedValue}\n >\n {/* Child render function can fully control list layout; fallback keeps default rendering. */}\n {children\n ? children(renderedOptions)\n : renderedOptions.map(({ radio }) => {\n return radio;\n })}\n </HeroRadioGroup>\n );\n};\n\nexport default Radios;\n","import Radios from './Radios';\n\nexport type { RadiosProps, RadioOption } from './Radios';\n\nexport { radiosVariants } from './Radios';\n\nexport default Radios;\n"],"mappings":";;;;;;AAaA,MAAa,iBAAiB,GAAG;CAC/B,OAAO;EACL,MAAM;GAEJ;GAEA;GAEA;EACF;EACA,cAAc;EACd,UAAU,CAGR,oFAGA,4CACF;EACA,aAAa;EACb,iBAAiB;EACjB,WAAW;EACX,kBAAkB;EAClB,aACE;EAEF,OACE;EACF,SAAS;CACX;CACA,UAAU,EACR,UAAU,EACR,MAAM,EAEJ,MAAM,4DACR,EACF,EACF;AACF,CAAC;;;;AA8DD,MAAM,UAAU,EACd,WAAW,KAAA,GACX,YAAY,KAAA,GACZ,SAAS,OACT,MACA,SACA,GAAG,wBAC4B;CAC/B,MAAM,EACJ,WACA,UACA,cACA,OAAO,EAAE,QAAQ,UAAU,KAAK,SAChC,SACA,OACA,UACA,UACA,WACE,gBAAgB;EAClB;EACA,GAAG;CACL,CAAC;CAGD,MAAM,EAAE,0BAA0B,2BAA2B,OAAO;CAGpE,MAAM,WAAW,eAAe,EAAE,SAAS,CAAC;CAC5C,MAAM,aAAa,qBAAqB,UAAU,WAAW,MAAM;CAEnE,MAAM,iBAAiB;EACrB,MAAM,WAAW;EACjB,SAAS,WAAW;EACpB,aAAa,WAAW;EACxB,OAAO,WAAW;EAClB,cAAc,WAAW;EACzB,SAAS,WAAW;CACtB;CAEA,MAAM,gBAAgB,SAAS,OAAO,OAAO,KAAK,IAAI;CAGtD,MAAM,kBAAkB,QAAQ,KAAK,WAAW;EAC9C,MAAM,eAAe,QACnB,GAAG,OAAO,UAAU,OAAO,UAAU,OAAO,SAC5C,EAAE,aAAa,KAAK,CACtB;EACA,MAAM,mBAAmB,CAAC,CAAC,YAAY,CAAC,CAAC,OAAO;EAChD,MAAM,cAAc,OAAO,OAAO,KAAK;EAavC,OAAO;GACL;GACA,OAAA,oBAbCA,OAAD;IAEE,YAAY;IACZ,eAAa;IACb,YAAY;IACZ,OAAO;IAEN,UAAA,OAAO,SAAS,OAAO;GACf,GAPJ,WAYH;GACJ,OAAO;IACL,UAAU,kBAAkB;IAC5B,UAAU;IACV,SAAS,CAAC,CAAC;GACb;EACF;CACF,CAAC;CAED,OACE,oBAACC,YAAD;EACO;EACL,cAAY;EACA;EAGZ,gBAAc;EACd,iBAAe;EACf,eAAa;EACC;EACd,YAAY;EACZ,WAAW;EACX,YAAY;EACZ,YAAY;EACZ,OAAO,QAAQ,oBAAC,UAAD,EAAA,UAAS,MAAc,CAAA,IAAI;EACpC;EACE;EACR,gBAAgB,aAAa;GAC3B,SAAS,sBAAsB,QAAQ,CAAC;EAC1C;EACA,aAAa,SAAS,eAAe;EACrC,OAAO;EAGN,UAAA,WACG,SAAS,eAAe,IACxB,gBAAgB,KAAK,EAAE,YAAY;GACjC,OAAO;EACT,CAAC;CACS,CAAA;AAEpB;;ACnNA,IAAA,iBAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/Radios/radiosVariants.ts","../../src/Radios/subcomponents/RadiosControl.tsx","../../src/Radios/Radios.tsx","../../src/Radios/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nimport radioGroupFieldVariants from '../partials/RadioGroupField/radioGroupFieldVariants';\n\nexport const radiosVariants = tv({\n extend: radioGroupFieldVariants,\n slots: {\n /** Container for the field control and supporting text */\n base: [\n // Needs group for group-data condition.\n 'group',\n // Match shared field wrapper layout.\n 'flex w-full flex-col',\n // Keep spacing between label/group consistent.\n 'gap-y-1.5',\n ],\n /** Container for validation messages */\n errorMessage: 'text-danger text-tiny',\n /** Clickable radio option */\n itemBase: '',\n /** Indicator marking the selected option */\n itemControl: 'bg-focus group-data-[invalid=true]:bg-danger',\n /** Supporting text below an option label */\n itemDescription: '',\n /** Primary option text */\n itemLabel: 'text-sm',\n /** Container grouping option text */\n itemLabelWrapper: 'ml-2',\n /** Outline around the selection indicator */\n itemWrapper:\n 'group-data-[invalid=true]:border-danger! [&:not(group-data-[invalid=\"true\"]):not(group-data-[selected=\"false\"])]:border-focus',\n /** Visible field label */\n label:\n 'mb-2 inline-flex cursor-default text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:text-danger',\n /** Container arranging the selectable content */\n wrapper:\n 'flex flex-col flex-wrap gap-2 data-[orientation=horizontal]:flex-row',\n },\n});\n\nexport type VariantProps = TVProps<typeof radiosVariants>;\n\nexport type ClassName = TVClassName<typeof radiosVariants>;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { RadiosProps } from '../Radios';\n\nimport { Label } from 'react-aria-components';\n\nimport { slugify } from '@fuf-stack/pixel-utils';\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport { createOptionValueConverter } from '../../helpers';\nimport { getFieldControlProps } from '../../helpers/fieldProps/fieldProps';\nimport FieldLayout from '../../partials/FieldLayout/FieldLayout';\nimport RadioGroupField from '../../partials/RadioGroupField/RadioGroupField';\nimport { radiosVariants } from '../radiosVariants';\nimport RadioControl from './RadioControl';\nimport radioControlVariants from './radioControlVariants';\n\ninterface RadiosControlProps extends Pick<\n RadiosProps,\n 'children' | 'className' | 'inline' | 'options'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, string | number | boolean>;\n}\n\n/**\n * Radio options and custom list composition\n *\n * @see https://react-aria.adobe.com/RadioGroup\n */\nconst RadiosControl = ({\n field,\n children,\n className,\n inline = false,\n options,\n}: RadiosControlProps) => {\n const {\n description,\n disabled,\n errorMessage,\n ids,\n ref: inputRef,\n invalid,\n label,\n name,\n onBlur,\n onChange: onValueChange,\n readOnly,\n required,\n testId,\n value,\n } = field;\n\n // associate the editable control with its label and messages\n const controlProps = getFieldControlProps(field);\n\n const styling = useStyling();\n\n const { convertToOriginalType } = createOptionValueConverter(options);\n\n // classNames from slots\n const variants = styling.resolve(radiosVariants, { readOnly });\n const classNames = styling.variantsToClassNames(variants, className, 'base');\n\n const optionVariants = styling.resolve(radioControlVariants, { invalid });\n const itemClassNames = styling.variantsToClassNames(optionVariants, {\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 const selectedValue = value != null ? String(value) : '';\n\n // share option elements between default and custom layouts\n const renderedOptions = options.map((option) => {\n const optionTestId = slugify(\n `${testId}_option_${option.testId ?? option.value}`,\n { replaceDots: true },\n );\n const optionIsDisabled = !!disabled || !!option.disabled;\n const optionValue = String(option.value);\n const radio = (\n <RadioControl\n key={optionValue}\n className={itemClassNames}\n disabled={optionIsDisabled}\n invalid={invalid}\n testId={optionTestId}\n value={optionValue}\n >\n {option.label ?? option.value}\n </RadioControl>\n );\n\n return {\n option,\n radio,\n state: {\n selected: selectedValue === optionValue,\n disabled: optionIsDisabled,\n invalid: !!invalid,\n },\n };\n });\n\n // restore the selected option's original value type\n const handleChange = (nextValue: string) => {\n onValueChange(convertToOriginalType(nextValue));\n };\n\n return (\n <FieldLayout\n baseAs={RadioGroupField}\n baseProps={{\n controlProps,\n dataComponent: 'radios',\n disabled,\n inline,\n inputRef,\n invalid,\n name,\n onBlur,\n onChange: handleChange,\n readOnly,\n required,\n testId,\n value,\n }}\n className={classNames}\n description={description}\n errorMessage={errorMessage}\n ids={ids}\n invalid={invalid}\n label={label}\n labelAs={Label}\n required={required}\n >\n <div\n className={classNames.wrapper}\n data-orientation={inline ? 'horizontal' : 'vertical'}\n data-slot=\"wrapper\"\n >\n {/* Child render function can fully control list layout; fallback keeps default rendering. */}\n {children\n ? children(renderedOptions)\n : renderedOptions.map(({ radio }) => {\n return radio;\n })}\n </div>\n </FieldLayout>\n );\n};\n\nexport default RadiosControl;\n","import type { ReactElement, ReactNode } from 'react';\nimport type { ClassName, VariantProps } from './radiosVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport RadiosControl from './subcomponents/RadiosControl';\n\nexport { radiosVariants } from './radiosVariants';\n\nexport interface RadioOption {\n /** Disables the field */\n disabled?: boolean;\n /** option icon */\n icon?: ReactNode;\n /** Field label */\n label?: ReactNode;\n /** Arbitrary option metadata for custom render logic. */\n meta?: Record<string, unknown>;\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n /** option value */\n value: string | number;\n}\n\nexport interface RadioRenderedOption {\n /** Option data as provided in `options` */\n option: RadioOption;\n /** Prebuilt radio element for custom option layouts */\n radio: ReactNode;\n /** Render-state flags for this option */\n state: {\n /** Whether this option is currently selected */\n selected: boolean;\n /** Disables the field */\n disabled: boolean;\n /** Whether the radio group is invalid */\n invalid: boolean;\n };\n}\n\nexport interface RadiosProps extends VariantProps {\n /** Custom accessible name */\n ariaLabel?: string;\n /** Optional child render function for custom full-list layout rendering. */\n children?: (options: RadioRenderedOption[]) => ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Help text associated with the field */\n description?: ReactNode;\n /** Disables the field */\n disabled?: boolean;\n /** Arranges options horizontally */\n inline?: boolean;\n /** Field label */\n label?: ReactNode;\n /** Field name */\n name: string;\n /** Available options */\n options: RadioOption[];\n /** Prevents changes while keeping the selection in validation and submission */\n readOnly?: boolean;\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n}\n\n/** Form selection field for one radio option */\nconst Radios = ({\n children = undefined,\n className = undefined,\n inline = false,\n name,\n options,\n ...uniformFieldProps\n}: RadiosProps): ReactElement => {\n const { field } = useUniformField({ ...uniformFieldProps, name });\n\n return (\n <RadiosControl\n className={className}\n field={field}\n inline={inline}\n options={options}\n >\n {children}\n </RadiosControl>\n );\n};\n\nexport default Radios;\n","import Radios from './Radios';\n\nexport type { RadiosProps, RadioOption } from './Radios';\n\nexport { radiosVariants } from './Radios';\n\nexport default Radios;\n"],"mappings":";;;;;;;;;;AAMA,MAAa,iBAAiB,GAAG;CAC/B,QAAQ;CACR,OAAO;;EAEL,MAAM;GAEJ;GAEA;GAEA;EACF;;EAEA,cAAc;;EAEd,UAAU;;EAEV,aAAa;;EAEb,iBAAiB;;EAEjB,WAAW;;EAEX,kBAAkB;;EAElB,aACE;;EAEF,OACE;;EAEF,SACE;CACJ;AACF,CAAC;;;;;;;ACXD,MAAM,iBAAiB,EACrB,OACA,UACA,WACA,SAAS,OACT,cACwB;CACxB,MAAM,EACJ,aACA,UACA,cACA,KACA,KAAK,UACL,SACA,OACA,MACA,QACA,UAAU,eACV,UACA,UACA,QACA,UACE;CAGJ,MAAM,eAAe,qBAAqB,KAAK;CAE/C,MAAM,UAAU,WAAW;CAE3B,MAAM,EAAE,0BAA0B,2BAA2B,OAAO;CAGpE,MAAM,WAAW,QAAQ,QAAQ,gBAAgB,EAAE,SAAS,CAAC;CAC7D,MAAM,aAAa,QAAQ,qBAAqB,UAAU,WAAW,MAAM;CAE3E,MAAM,iBAAiB,QAAQ,QAAQ,sBAAsB,EAAE,QAAQ,CAAC;CACxE,MAAM,iBAAiB,QAAQ,qBAAqB,gBAAgB;EAClE,MAAM,WAAW;EACjB,SAAS,WAAW;EACpB,aAAa,WAAW;EACxB,OAAO,WAAW;EAClB,cAAc,WAAW;EACzB,SAAS,WAAW;CACtB,CAAC;CAED,MAAM,gBAAgB,SAAS,OAAO,OAAO,KAAK,IAAI;CAGtD,MAAM,kBAAkB,QAAQ,KAAK,WAAW;EAC9C,MAAM,eAAe,QACnB,GAAG,OAAO,UAAU,OAAO,UAAU,OAAO,SAC5C,EAAE,aAAa,KAAK,CACtB;EACA,MAAM,mBAAmB,CAAC,CAAC,YAAY,CAAC,CAAC,OAAO;EAChD,MAAM,cAAc,OAAO,OAAO,KAAK;EAcvC,OAAO;GACL;GACA,OAAA,oBAdC,cAAD;IAEE,WAAW;IACX,UAAU;IACD;IACT,QAAQ;IACR,OAAO;IAEN,UAAA,OAAO,SAAS,OAAO;GACZ,GARP,WAaH;GACJ,OAAO;IACL,UAAU,kBAAkB;IAC5B,UAAU;IACV,SAAS,CAAC,CAAC;GACb;EACF;CACF,CAAC;CAGD,MAAM,gBAAgB,cAAsB;EAC1C,cAAc,sBAAsB,SAAS,CAAC;CAChD;CAEA,OACE,oBAAC,aAAD;EACE,QAAQ;EACR,WAAW;GACT;GACA,eAAe;GACf;GACA;GACA;GACA;GACA;GACA;GACA,UAAU;GACV;GACA;GACA;GACA;EACF;EACA,WAAW;EACE;EACC;EACT;EACI;EACF;EACP,SAAS;EACC;EAEV,UAAA,oBAAC,OAAD;GACE,WAAW,WAAW;GACtB,oBAAkB,SAAS,eAAe;GAC1C,aAAU;GAGT,UAAA,WACG,SAAS,eAAe,IACxB,gBAAgB,KAAK,EAAE,YAAY;IACjC,OAAO;GACT,CAAC;EACF,CAAA;CACM,CAAA;AAEjB;;;ACzFA,MAAM,UAAU,EACd,WAAW,KAAA,GACX,YAAY,KAAA,GACZ,SAAS,OACT,MACA,SACA,GAAG,wBAC4B;CAC/B,MAAM,EAAE,UAAU,gBAAgB;EAAE,GAAG;EAAmB;CAAK,CAAC;CAEhE,OACE,oBAAC,eAAD;EACa;EACJ;EACC;EACC;EAER;CACY,CAAA;AAEnB;;AC/EA,IAAA,iBAAe"}
|