@fuf-stack/uniform 1.27.0 → 2.0.0-next.1
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 +9 -0
- package/dist/Checkboxes/index.d.mts +192 -263
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +294 -90
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +1282 -500
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +403 -83
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.d.mts +105 -98
- package/dist/FieldArray/index.d.mts.map +1 -1
- package/dist/FieldArray/index.mjs +344 -195
- package/dist/FieldArray/index.mjs.map +1 -1
- package/dist/FieldCard/index.d.mts +37 -35
- package/dist/FieldCard/index.d.mts.map +1 -1
- package/dist/FieldCard/index.mjs +187 -128
- package/dist/FieldCard/index.mjs.map +1 -1
- package/dist/{FieldCopyTestIdButton-CRJBix9D.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +5 -3
- package/dist/FieldCopyTestIdButton-DV0tkdh2.mjs.map +1 -0
- package/dist/FieldDescription-C4l0HKGL.mjs +36 -0
- package/dist/FieldDescription-C4l0HKGL.mjs.map +1 -0
- package/dist/FieldLabel-DKzqkuY1.mjs +125 -0
- package/dist/FieldLabel-DKzqkuY1.mjs.map +1 -0
- package/dist/FieldLayout-BLW5S-Jm.mjs +46 -0
- package/dist/FieldLayout-BLW5S-Jm.mjs.map +1 -0
- package/dist/FieldValidationError-DgkCL3cC.mjs +77 -0
- package/dist/FieldValidationError-DgkCL3cC.mjs.map +1 -0
- package/dist/Form/index.d.mts +11 -11
- package/dist/Form/index.d.mts.map +1 -1
- package/dist/Form/index.mjs +14 -11
- package/dist/Form/index.mjs.map +1 -1
- package/dist/FormContext-CHctWFAP.mjs +520 -0
- package/dist/FormContext-CHctWFAP.mjs.map +1 -0
- package/dist/FormContext-CsFiNvuJ.d.mts.map +1 -1
- package/dist/Grid/index.mjs +1 -2
- package/dist/{Grid-CTs-Rb9G.mjs → Grid-DfcZeuib.mjs} +4 -2
- package/dist/Grid-DfcZeuib.mjs.map +1 -0
- package/dist/Input/index.d.mts +640 -392
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +421 -76
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +1583 -120
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +159 -114
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +300 -81
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +277 -86
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +1353 -108
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +105 -54
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +558 -3013
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +319 -177
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +414 -1326
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +276 -94
- 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 -1248
- package/dist/Switch/index.mjs +167 -68
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/Switch-CvPO8IF9.d.mts +601 -0
- package/dist/Switch-CvPO8IF9.d.mts.map +1 -0
- package/dist/SwitchBox/index.d.mts +139 -43
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +142 -87
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +295 -411
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +200 -48
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +1170 -601
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +162 -74
- 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 +31 -3
- package/dist/hooks/useController/index.d.mts.map +1 -0
- package/dist/hooks/useController/index.mjs +1 -2
- package/dist/hooks/useFormContext/index.d.mts +65 -3
- package/dist/hooks/useFormContext/index.d.mts.map +1 -0
- package/dist/hooks/useFormContext/index.mjs +1 -2
- package/dist/hooks/useInputValueDebounce/index.d.mts +11 -5
- 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 -2
- package/dist/hooks/useWatchFormReset/index.mjs +1 -1
- package/dist/hooks/useWatchUserChange/index.d.mts +2 -2
- package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs.map +1 -1
- package/dist/{useInputValueTransform-LOaEim7k.d.mts → index-BS8IoBOn.d.mts} +3 -3
- package/dist/index-BS8IoBOn.d.mts.map +1 -0
- package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -2
- 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 -2
- package/dist/radioControlVariants-Cm6WufWo.mjs +188 -0
- package/dist/radioControlVariants-Cm6WufWo.mjs.map +1 -0
- package/dist/switchVariants-BaQw2DA7.mjs +67 -0
- package/dist/switchVariants-BaQw2DA7.mjs.map +1 -0
- package/dist/timeVariants-B9HDfNYt.mjs +58 -0
- package/dist/timeVariants-B9HDfNYt.mjs.map +1 -0
- package/dist/{useController-CK39i6HI.mjs → useController-BCFeZbBZ.mjs} +2 -2
- package/dist/{useController-CK39i6HI.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
- package/dist/{useFormContext-fYWtlnpE.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
- package/dist/{useFormContext-fYWtlnpE.mjs.map → useFormContext-BPjJjNnM.mjs.map} +1 -1
- package/dist/{useInputValueTransform-DJ5zkqSy.mjs → useInputValueTransform-Mw8YEOXT.mjs} +2 -2
- package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-Mw8YEOXT.mjs.map} +1 -1
- package/package.json +17 -29
- package/dist/FieldCopyTestIdButton-CRJBix9D.mjs.map +0 -1
- package/dist/FieldValidationError-ByRoIxaM.mjs +0 -50
- package/dist/FieldValidationError-ByRoIxaM.mjs.map +0 -1
- package/dist/FormContext-gHSwOlcy.mjs +0 -278
- package/dist/FormContext-gHSwOlcy.mjs.map +0 -1
- package/dist/Grid-CTs-Rb9G.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 -7
- package/dist/hooks/useInput/index.mjs.map +0 -1
- package/dist/hooks/useUniformField/index.d.mts +0 -98
- package/dist/hooks/useUniformField/index.d.mts.map +0 -1
- package/dist/hooks/useUniformField/index.mjs +0 -137
- package/dist/hooks/useUniformField/index.mjs.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.d.mts +0 -73
- package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.mjs +0 -101
- package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
- package/dist/index-CAdGtKE_.d.mts +0 -1
- package/dist/index-CaxrMD1A.d.mts +0 -1
- package/dist/index-D5HVU2jP.d.mts +0 -1
- package/dist/useController-DcK2YHbw.d.mts +0 -32
- package/dist/useController-DcK2YHbw.d.mts.map +0 -1
- package/dist/useFormContext-B3QGVVaO.d.mts +0 -66
- package/dist/useFormContext-B3QGVVaO.d.mts.map +0 -1
- package/dist/useInput-C0aJaAGe.mjs +0 -2
- package/dist/useInput-ClpHDPdr.d.mts +0 -2
- package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/partials/FieldValidationError/FieldValidationError.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/partials/FieldValidationError/FieldValidationError.tsx"],"mappings":";;;cAWM,gCAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAa7B,YAAY,mBAAmB;UAEnB;;EAEf,YAAY;;EAEZ,QAAQ;;EAER;;EAEA;;;;;;;;cASI,yBAAwB,WAAA,OAAA,IAAA,UAK3B,8CAAyB,IAAA"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { FieldValidationError_default as default };
|
|
1
|
+
export { t as default } from "../../FieldValidationError-DgkCL3cC.mjs";
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { createContext, useContext, useId, useRef } from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { tv } from "@fuf-stack/pixel-utils";
|
|
4
|
+
import { RadioButton, RadioField, RadioGroup } from "react-aria-components";
|
|
5
|
+
//#region src/partials/RadioGroupField/RadioGroupDescriptionContext.ts
|
|
6
|
+
/** Supporting message IDs inherited by each option */
|
|
7
|
+
const RadioGroupDescriptionContext = createContext(void 0);
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/partials/RadioGroupField/RadioGroupField.tsx
|
|
10
|
+
/**
|
|
11
|
+
* React Aria radio-group engine with option focus routing and shared descriptions
|
|
12
|
+
*
|
|
13
|
+
* Receives bound values and callbacks, without registering a form field.
|
|
14
|
+
* Its children own the field layout and option presentation.
|
|
15
|
+
*
|
|
16
|
+
* @see https://react-aria.adobe.com/RadioGroup
|
|
17
|
+
*/
|
|
18
|
+
const RadioGroupField = ({ children, className = void 0, controlProps, dataComponent = void 0, disabled = void 0, inputRef, invalid, inline, name, onBlur, onChange, required, testId, value }) => {
|
|
19
|
+
const groupRef = useRef(null);
|
|
20
|
+
const handleFocus = () => {
|
|
21
|
+
(groupRef.current?.querySelector("input:checked:not(:disabled)") ?? groupRef.current?.querySelector("input:not(:disabled)"))?.focus();
|
|
22
|
+
};
|
|
23
|
+
const setControlRef = (node) => {
|
|
24
|
+
groupRef.current = node;
|
|
25
|
+
inputRef(node ? { focus: handleFocus } : null);
|
|
26
|
+
};
|
|
27
|
+
const renderGroup = (props) => {
|
|
28
|
+
return /* @__PURE__ */ jsx("div", {
|
|
29
|
+
...props,
|
|
30
|
+
"data-invalid": invalid,
|
|
31
|
+
"data-required": required,
|
|
32
|
+
children: props.children
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
return /* @__PURE__ */ jsx(RadioGroup, {
|
|
36
|
+
ref: setControlRef,
|
|
37
|
+
"aria-describedby": controlProps["aria-describedby"],
|
|
38
|
+
"aria-label": controlProps["aria-label"],
|
|
39
|
+
className,
|
|
40
|
+
"data-component": dataComponent,
|
|
41
|
+
"data-invalid": invalid,
|
|
42
|
+
"data-required": required,
|
|
43
|
+
"data-slot": "base",
|
|
44
|
+
"data-testid": testId,
|
|
45
|
+
id: controlProps.id,
|
|
46
|
+
isDisabled: disabled,
|
|
47
|
+
isInvalid: invalid,
|
|
48
|
+
isRequired: required,
|
|
49
|
+
name,
|
|
50
|
+
onBlur,
|
|
51
|
+
onChange,
|
|
52
|
+
orientation: inline ? "horizontal" : "vertical",
|
|
53
|
+
render: renderGroup,
|
|
54
|
+
validationBehavior: "aria",
|
|
55
|
+
value: value != null ? String(value) : "",
|
|
56
|
+
children: /* @__PURE__ */ jsx(RadioGroupDescriptionContext.Provider, {
|
|
57
|
+
value: controlProps["aria-describedby"],
|
|
58
|
+
children
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/partials/RadioGroupField/radioGroupFieldVariants.ts
|
|
64
|
+
const radioGroupFieldVariants = tv({ slots: {
|
|
65
|
+
/** Container grouping the label, options and hints */
|
|
66
|
+
base: "relative",
|
|
67
|
+
/** Supporting text below the options */
|
|
68
|
+
description: "text-foreground-400 text-tiny",
|
|
69
|
+
/** Container for validation messages */
|
|
70
|
+
errorMessage: "",
|
|
71
|
+
/** Label above the options */
|
|
72
|
+
label: "relative",
|
|
73
|
+
/** Container around the selectable options */
|
|
74
|
+
wrapper: ""
|
|
75
|
+
} });
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/Radios/subcomponents/RadioControl.tsx
|
|
78
|
+
/**
|
|
79
|
+
* React Aria radio option with an indicator, label and optional supporting text
|
|
80
|
+
*
|
|
81
|
+
* Inherits selection and disabled state from its RadioGroup, and supporting
|
|
82
|
+
* message IDs from RadioGroupField when composed inside that engine.
|
|
83
|
+
*
|
|
84
|
+
* @see https://react-aria.adobe.com/RadioGroup
|
|
85
|
+
*/
|
|
86
|
+
const RadioControl = ({ children, className: classNames, description = void 0, disabled = void 0, icon = void 0, invalid, testId = void 0, value }) => {
|
|
87
|
+
const id = useId();
|
|
88
|
+
const describedBy = [useContext(RadioGroupDescriptionContext), description ? `${id}-description` : void 0].filter(Boolean).join(" ") || void 0;
|
|
89
|
+
const control = /* @__PURE__ */ jsx("span", {
|
|
90
|
+
"aria-hidden": true,
|
|
91
|
+
className: classNames.wrapper,
|
|
92
|
+
"data-slot": "wrapper",
|
|
93
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
94
|
+
className: classNames.control,
|
|
95
|
+
"data-slot": "control"
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
const renderOption = (props, state) => {
|
|
99
|
+
return /* @__PURE__ */ jsx("label", {
|
|
100
|
+
...props,
|
|
101
|
+
"data-focus": state.isFocused || void 0,
|
|
102
|
+
"data-hover": state.isHovered || void 0,
|
|
103
|
+
"data-hover-unselected": state.isHovered && !state.isSelected || void 0,
|
|
104
|
+
htmlFor: `${id}-control`,
|
|
105
|
+
children: props.children
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
return /* @__PURE__ */ jsx(RadioField, {
|
|
109
|
+
"aria-describedby": describedBy,
|
|
110
|
+
"aria-labelledby": `${id}-label`,
|
|
111
|
+
className: classNames.field,
|
|
112
|
+
id: `${id}-control`,
|
|
113
|
+
isDisabled: disabled,
|
|
114
|
+
value,
|
|
115
|
+
children: /* @__PURE__ */ jsxs(RadioButton, {
|
|
116
|
+
className: classNames.base,
|
|
117
|
+
"data-invalid": invalid,
|
|
118
|
+
"data-slot": "base",
|
|
119
|
+
"data-testid": testId,
|
|
120
|
+
render: renderOption,
|
|
121
|
+
children: [
|
|
122
|
+
!icon ? control : null,
|
|
123
|
+
icon ? /* @__PURE__ */ jsx("div", {
|
|
124
|
+
className: classNames.icon,
|
|
125
|
+
children: icon
|
|
126
|
+
}) : null,
|
|
127
|
+
/* @__PURE__ */ jsxs("div", {
|
|
128
|
+
className: classNames.labelWrapper,
|
|
129
|
+
"data-slot": "label-wrapper",
|
|
130
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
131
|
+
className: classNames.label,
|
|
132
|
+
"data-slot": "label",
|
|
133
|
+
id: `${id}-label`,
|
|
134
|
+
children
|
|
135
|
+
}), description ? /* @__PURE__ */ jsx("div", {
|
|
136
|
+
className: classNames.description,
|
|
137
|
+
"data-slot": "description",
|
|
138
|
+
id: `${id}-description`,
|
|
139
|
+
children: description
|
|
140
|
+
}) : null]
|
|
141
|
+
}),
|
|
142
|
+
icon ? control : null
|
|
143
|
+
]
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/Radios/subcomponents/radioControlVariants.ts
|
|
149
|
+
const radioControlVariants = tv({
|
|
150
|
+
slots: {
|
|
151
|
+
/** Clickable option containing the indicator and label */
|
|
152
|
+
base: ["group relative -m-2 inline-flex max-w-fit cursor-pointer select-none items-center justify-start p-2 tap-highlight-transparent", "data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-disabled"],
|
|
153
|
+
/** Dot marking the selected option */
|
|
154
|
+
control: [
|
|
155
|
+
"z-10 h-2 w-2 origin-center scale-0 rounded-full bg-primary text-primary-foreground opacity-0 transition-transform-opacity",
|
|
156
|
+
"group-data-[selected=true]:scale-100 group-data-[invalid=true]:bg-danger group-data-[invalid=true]:text-danger-foreground group-data-[selected=true]:opacity-100",
|
|
157
|
+
"motion-reduce:transition-none"
|
|
158
|
+
],
|
|
159
|
+
/** Supporting text below the option label */
|
|
160
|
+
description: "relative text-foreground-400 transition-colors text-small motion-reduce:transition-none",
|
|
161
|
+
/** Option state boundary without an additional layout box */
|
|
162
|
+
field: "contents",
|
|
163
|
+
/** Container for a decorative option icon */
|
|
164
|
+
icon: "",
|
|
165
|
+
/** Primary option text */
|
|
166
|
+
label: "relative select-none text-foreground transition-colors text-medium motion-reduce:transition-none",
|
|
167
|
+
/** Container grouping the option label and description */
|
|
168
|
+
labelWrapper: "ml-1 ms-2 flex flex-col",
|
|
169
|
+
/** Circular outline around the selection indicator */
|
|
170
|
+
wrapper: [
|
|
171
|
+
"relative box-border inline-flex h-5 w-5 shrink-0 items-center justify-center overflow-hidden",
|
|
172
|
+
"rounded-full border-2 border-solid border-default transition-transform-colors",
|
|
173
|
+
"group-data-[pressed=true]:scale-95 group-data-[invalid=true]:border-danger group-data-[invalid=true]:group-data-[selected=true]:border-danger group-data-[selected=true]:border-primary group-data-[hover-unselected=true]:bg-default-100",
|
|
174
|
+
"group-data-[focus-visible=true]:ring-2 group-data-[focus-visible=true]:ring-focus group-data-[focus-visible=true]:ring-offset-2 group-data-[focus-visible=true]:ring-offset-background",
|
|
175
|
+
"motion-reduce:transition-none"
|
|
176
|
+
]
|
|
177
|
+
},
|
|
178
|
+
variants: { invalid: { true: {
|
|
179
|
+
control: "bg-danger text-danger-foreground",
|
|
180
|
+
description: "text-danger-300",
|
|
181
|
+
label: "text-danger",
|
|
182
|
+
wrapper: "border-danger group-data-[selected=true]:border-danger"
|
|
183
|
+
} } }
|
|
184
|
+
});
|
|
185
|
+
//#endregion
|
|
186
|
+
export { RadioGroupField as i, RadioControl as n, radioGroupFieldVariants as r, radioControlVariants as t };
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=radioControlVariants-Cm6WufWo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radioControlVariants-Cm6WufWo.mjs","names":[],"sources":["../src/partials/RadioGroupField/RadioGroupDescriptionContext.ts","../src/partials/RadioGroupField/RadioGroupField.tsx","../src/partials/RadioGroupField/radioGroupFieldVariants.ts","../src/Radios/subcomponents/RadioControl.tsx","../src/Radios/subcomponents/radioControlVariants.ts"],"sourcesContent":["import { createContext } from 'react';\n\n/** Supporting message IDs inherited by each option */\nconst RadioGroupDescriptionContext = createContext<string | undefined>(\n undefined,\n);\n\nexport default RadioGroupDescriptionContext;\n","import type { ReactNode } from 'react';\nimport type { RadioGroupProps } from 'react-aria-components';\nimport type { FieldControlProps } from '../types';\n\nimport { useRef } from 'react';\nimport { RadioGroup } from 'react-aria-components';\n\nimport RadioGroupDescriptionContext from './RadioGroupDescriptionContext';\n\ninterface RadioGroupFieldProps {\n /** Group content, including its label and options */\n children: ReactNode;\n /** CSS class name */\n className?: string;\n /** Control ID, explicit accessible name and supporting message IDs */\n controlProps: Pick<\n FieldControlProps,\n 'id' | 'aria-label' | 'aria-describedby'\n >;\n /** Identifies the public component owning the radio group */\n dataComponent?: string;\n /** Disables every option */\n disabled?: boolean;\n /** Arranges options horizontally */\n inline: boolean;\n /** Connects form focus requests to the selected or first enabled option */\n inputRef: (control: Pick<HTMLElement, 'focus'> | null) => void;\n /** Marks visible validation failure */\n invalid: boolean;\n /** Field name */\n name: string;\n /** Callback when focus leaves the group */\n onBlur: () => void;\n /** Callback with the selected option's string value */\n onChange: (value: string) => void;\n /** Marks the group as required */\n required: boolean;\n /** HTML data-testid attribute */\n testId: string;\n /** Selected value, nullish values become an empty selection */\n value: unknown;\n}\n\n/**\n * React Aria radio-group engine with option focus routing and shared descriptions\n *\n * Receives bound values and callbacks, without registering a form field.\n * Its children own the field layout and option presentation.\n *\n * @see https://react-aria.adobe.com/RadioGroup\n */\nconst RadioGroupField = ({\n children,\n className = undefined,\n controlProps,\n dataComponent = undefined,\n disabled = undefined,\n inputRef,\n invalid,\n inline,\n name,\n onBlur,\n onChange,\n required,\n testId,\n value,\n}: RadioGroupFieldProps) => {\n const groupRef = useRef<HTMLDivElement>(null);\n\n // focus the selected enabled option, otherwise the first enabled option\n const handleFocus = () => {\n const input =\n groupRef.current?.querySelector<HTMLInputElement>(\n 'input:checked:not(:disabled)',\n ) ??\n groupRef.current?.querySelector<HTMLInputElement>('input:not(:disabled)');\n input?.focus();\n };\n\n // expose option focus through the binding ref\n const setControlRef = (node: HTMLDivElement | null) => {\n groupRef.current = node;\n inputRef(node ? { focus: handleFocus } : null);\n };\n\n // preserve the group's existing state selectors on the actual root\n const renderGroup: NonNullable<RadioGroupProps['render']> = (props) => {\n return (\n <div {...props} data-invalid={invalid} data-required={required}>\n {props.children}\n </div>\n );\n };\n\n return (\n <RadioGroup\n ref={setControlRef}\n aria-describedby={controlProps['aria-describedby']}\n aria-label={controlProps['aria-label']}\n className={className}\n data-component={dataComponent}\n data-invalid={invalid}\n data-required={required}\n data-slot=\"base\"\n data-testid={testId}\n id={controlProps.id}\n isDisabled={disabled}\n isInvalid={invalid}\n isRequired={required}\n name={name}\n onBlur={onBlur}\n onChange={onChange}\n orientation={inline ? 'horizontal' : 'vertical'}\n render={renderGroup}\n validationBehavior=\"aria\"\n value={value != null ? String(value) : ''}\n >\n <RadioGroupDescriptionContext.Provider\n value={controlProps['aria-describedby']}\n >\n {children}\n </RadioGroupDescriptionContext.Provider>\n </RadioGroup>\n );\n};\n\nexport default RadioGroupField;\n","import { tv } from '@fuf-stack/pixel-utils';\n\nconst radioGroupFieldVariants = tv({\n slots: {\n /** Container grouping the label, options and hints */\n base: 'relative',\n /** Supporting text below the options */\n description: 'text-foreground-400 text-tiny',\n /** Container for validation messages */\n errorMessage: '',\n /** Label above the options */\n label: 'relative',\n /** Container around the selectable options */\n wrapper: '',\n },\n});\n\nexport default radioGroupFieldVariants;\n","import type { ReactNode } from 'react';\nimport type { RadioButtonProps } from 'react-aria-components';\nimport type { RadioControlClassNames } from './radioControlVariants';\n\nimport { useContext, useId } from 'react';\nimport { RadioButton, RadioField } from 'react-aria-components';\n\nimport RadioGroupDescriptionContext from '../../partials/RadioGroupField/RadioGroupDescriptionContext';\n\ninterface RadioControlProps {\n /** Option label */\n children: ReactNode;\n /** CSS class name */\n className: RadioControlClassNames;\n /** Help text associated with the field */\n description?: ReactNode;\n /** Disables the field */\n disabled?: boolean;\n /** Decorative option icon */\n icon?: ReactNode;\n /** Marks visible validation failure */\n invalid: boolean;\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n /** String value managed by the containing group */\n value: string;\n}\n\n/**\n * React Aria radio option with an indicator, label and optional supporting text\n *\n * Inherits selection and disabled state from its RadioGroup, and supporting\n * message IDs from RadioGroupField when composed inside that engine.\n *\n * @see https://react-aria.adobe.com/RadioGroup\n */\nconst RadioControl = ({\n children,\n className: classNames,\n description = undefined,\n disabled = undefined,\n icon = undefined,\n invalid,\n testId = undefined,\n value,\n}: RadioControlProps) => {\n const id = useId();\n const groupDescription = useContext(RadioGroupDescriptionContext);\n\n const describedBy =\n [groupDescription, description ? `${id}-description` : undefined]\n .filter(Boolean)\n .join(' ') || undefined;\n\n const control = (\n <span aria-hidden className={classNames.wrapper} data-slot=\"wrapper\">\n <span className={classNames.control} data-slot=\"control\" />\n </span>\n );\n\n // preserve option state selectors on the visible label\n const renderOption: NonNullable<RadioButtonProps['render']> = (\n props,\n state,\n ) => {\n return (\n <label\n {...props}\n data-focus={state.isFocused || undefined}\n data-hover={state.isHovered || undefined}\n data-hover-unselected={\n (state.isHovered && !state.isSelected) || undefined\n }\n htmlFor={`${id}-control`}\n >\n {props.children}\n </label>\n );\n };\n\n return (\n <RadioField\n aria-describedby={describedBy}\n aria-labelledby={`${id}-label`}\n className={classNames.field}\n id={`${id}-control`}\n isDisabled={disabled}\n value={value}\n >\n <RadioButton\n className={classNames.base}\n data-invalid={invalid}\n data-slot=\"base\"\n data-testid={testId}\n render={renderOption}\n >\n {!icon ? control : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n <div className={classNames.labelWrapper} data-slot=\"label-wrapper\">\n <span\n className={classNames.label}\n data-slot=\"label\"\n id={`${id}-label`}\n >\n {children}\n </span>\n {description ? (\n <div\n className={classNames.description}\n data-slot=\"description\"\n id={`${id}-description`}\n >\n {description}\n </div>\n ) : null}\n </div>\n {icon ? control : null}\n </RadioButton>\n </RadioField>\n );\n};\n\nexport default RadioControl;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nconst radioControlVariants = tv({\n slots: {\n /** Clickable option containing the indicator and label */\n base: [\n // option layout and pointer behavior\n 'group relative -m-2 inline-flex max-w-fit cursor-pointer select-none items-center justify-start p-2 tap-highlight-transparent',\n // disabled interaction and opacity\n 'data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-disabled',\n ],\n /** Dot marking the selected option */\n control: [\n // selection dot appearance and animation\n 'z-10 h-2 w-2 origin-center scale-0 rounded-full bg-primary text-primary-foreground opacity-0 transition-transform-opacity',\n // selection and validation states\n 'group-data-[selected=true]:scale-100 group-data-[invalid=true]:bg-danger group-data-[invalid=true]:text-danger-foreground group-data-[selected=true]:opacity-100',\n // reduced motion\n 'motion-reduce:transition-none',\n ],\n /** Supporting text below the option label */\n description:\n 'relative text-foreground-400 transition-colors text-small motion-reduce:transition-none',\n /** Option state boundary without an additional layout box */\n field: 'contents',\n /** Container for a decorative option icon */\n icon: '',\n /** Primary option text */\n label:\n 'relative select-none text-foreground transition-colors text-medium motion-reduce:transition-none',\n /** Container grouping the option label and description */\n labelWrapper: 'ml-1 ms-2 flex flex-col',\n /** Circular outline around the selection indicator */\n wrapper: [\n // indicator dimensions and layout\n 'relative box-border inline-flex h-5 w-5 shrink-0 items-center justify-center overflow-hidden',\n // circular border and transitions\n 'rounded-full border-2 border-solid border-default transition-transform-colors',\n // pressed, selected and invalid states\n 'group-data-[pressed=true]:scale-95 group-data-[invalid=true]:border-danger group-data-[invalid=true]:group-data-[selected=true]:border-danger group-data-[selected=true]:border-primary group-data-[hover-unselected=true]:bg-default-100',\n // keyboard focus ring\n 'group-data-[focus-visible=true]:ring-2 group-data-[focus-visible=true]:ring-focus group-data-[focus-visible=true]:ring-offset-2 group-data-[focus-visible=true]:ring-offset-background',\n // reduced motion\n 'motion-reduce:transition-none',\n ],\n },\n variants: {\n invalid: {\n true: {\n control: 'bg-danger text-danger-foreground',\n description: 'text-danger-300',\n label: 'text-danger',\n wrapper: 'border-danger group-data-[selected=true]:border-danger',\n },\n },\n },\n});\n\nexport type RadioControlClassNames = Partial<\n Record<keyof ReturnType<typeof radioControlVariants>, string>\n>;\n\nexport type ClassName = TVClassName<typeof radioControlVariants>;\n\nexport default radioControlVariants;\n"],"mappings":";;;;;;AAGA,MAAM,+BAA+B,cACnC,KAAA,CACF;;;;;;;;;;;AC8CA,MAAM,mBAAmB,EACvB,UACA,YAAY,KAAA,GACZ,cACA,gBAAgB,KAAA,GAChB,WAAW,KAAA,GACX,UACA,SACA,QACA,MACA,QACA,UACA,UACA,QACA,YAC0B;CAC1B,MAAM,WAAW,OAAuB,IAAI;CAG5C,MAAM,oBAAoB;EAMxB,CAJE,SAAS,SAAS,cAChB,8BACF,KACA,SAAS,SAAS,cAAgC,sBAAsB,EAAA,EACnE,MAAM;CACf;CAGA,MAAM,iBAAiB,SAAgC;EACrD,SAAS,UAAU;EACnB,SAAS,OAAO,EAAE,OAAO,YAAY,IAAI,IAAI;CAC/C;CAGA,MAAM,eAAuD,UAAU;EACrE,OACE,oBAAC,OAAD;GAAK,GAAI;GAAO,gBAAc;GAAS,iBAAe;GACnD,UAAA,MAAM;EACJ,CAAA;CAET;CAEA,OACE,oBAAC,YAAD;EACE,KAAK;EACL,oBAAkB,aAAa;EAC/B,cAAY,aAAa;EACd;EACX,kBAAgB;EAChB,gBAAc;EACd,iBAAe;EACf,aAAU;EACV,eAAa;EACb,IAAI,aAAa;EACjB,YAAY;EACZ,WAAW;EACX,YAAY;EACN;EACE;EACE;EACV,aAAa,SAAS,eAAe;EACrC,QAAQ;EACR,oBAAmB;EACnB,OAAO,SAAS,OAAO,OAAO,KAAK,IAAI;EAEvC,UAAA,oBAAC,6BAA6B,UAA9B;GACE,OAAO,aAAa;GAEnB;EACoC,CAAA;CAC7B,CAAA;AAEhB;;;AC1HA,MAAM,0BAA0B,GAAG,EACjC,OAAO;;CAEL,MAAM;;CAEN,aAAa;;CAEb,cAAc;;CAEd,OAAO;;CAEP,SAAS;AACX,EACF,CAAC;;;;;;;;;;;ACqBD,MAAM,gBAAgB,EACpB,UACA,WAAW,YACX,cAAc,KAAA,GACd,WAAW,KAAA,GACX,OAAO,KAAA,GACP,SACA,SAAS,KAAA,GACT,YACuB;CACvB,MAAM,KAAK,MAAM;CAGjB,MAAM,cACJ,CAHuB,WAAW,4BAGlB,GAAG,cAAc,GAAG,GAAG,gBAAgB,KAAA,CAAS,CAAC,CAC9D,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,KAAK,KAAA;CAElB,MAAM,UACJ,oBAAC,QAAD;EAAM,eAAA;EAAY,WAAW,WAAW;EAAS,aAAU;EACzD,UAAA,oBAAC,QAAD;GAAM,WAAW,WAAW;GAAS,aAAU;EAAW,CAAA;CACtD,CAAA;CAIR,MAAM,gBACJ,OACA,UACG;EACH,OACE,oBAAC,SAAD;GACE,GAAI;GACJ,cAAY,MAAM,aAAa,KAAA;GAC/B,cAAY,MAAM,aAAa,KAAA;GAC/B,yBACG,MAAM,aAAa,CAAC,MAAM,cAAe,KAAA;GAE5C,SAAS,GAAG,GAAG;GAEd,UAAA,MAAM;EACF,CAAA;CAEX;CAEA,OACE,oBAAC,YAAD;EACE,oBAAkB;EAClB,mBAAiB,GAAG,GAAG;EACvB,WAAW,WAAW;EACtB,IAAI,GAAG,GAAG;EACV,YAAY;EACL;EAEP,UAAA,qBAAC,aAAD;GACE,WAAW,WAAW;GACtB,gBAAc;GACd,aAAU;GACV,eAAa;GACb,QAAQ;GALV,UAAA;IAOG,CAAC,OAAO,UAAU;IAClB,OAAO,oBAAC,OAAD;KAAK,WAAW,WAAW;KAAO,UAAA;IAAU,CAAA,IAAI;IACxD,qBAAC,OAAD;KAAK,WAAW,WAAW;KAAc,aAAU;KAAnD,UAAA,CACE,oBAAC,QAAD;MACE,WAAW,WAAW;MACtB,aAAU;MACV,IAAI,GAAG,GAAG;MAET;KACG,CAAA,GACL,cACC,oBAAC,OAAD;MACE,WAAW,WAAW;MACtB,aAAU;MACV,IAAI,GAAG,GAAG;MAET,UAAA;KACE,CAAA,IACH,IACD;;IACJ,OAAO,UAAU;GACP;;CACH,CAAA;AAEhB;;;ACpHA,MAAM,uBAAuB,GAAG;CAC9B,OAAO;;EAEL,MAAM,CAEJ,iIAEA,gFACF;;EAEA,SAAS;GAEP;GAEA;GAEA;EACF;;EAEA,aACE;;EAEF,OAAO;;EAEP,MAAM;;EAEN,OACE;;EAEF,cAAc;;EAEd,SAAS;GAEP;GAEA;GAEA;GAEA;GAEA;EACF;CACF;CACA,UAAU,EACR,SAAS,EACP,MAAM;EACJ,SAAS;EACT,aAAa;EACb,OAAO;EACP,SAAS;CACX,EACF,EACF;AACF,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { tv } from "@fuf-stack/pixel-utils";
|
|
2
|
+
//#region src/Switch/switchVariants.ts
|
|
3
|
+
const switchVariants = tv({
|
|
4
|
+
slots: {
|
|
5
|
+
/** Container for the field control and supporting text */
|
|
6
|
+
base: "group relative inline-flex max-w-fit cursor-pointer touch-none select-none items-center justify-start tap-highlight-transparent",
|
|
7
|
+
/** Supporting text for the field */
|
|
8
|
+
description: "text-foreground-500 text-tiny",
|
|
9
|
+
/** Content at the end of the control */
|
|
10
|
+
endContent: [
|
|
11
|
+
"absolute end-1.5 z-0 text-default-600 opacity-100 transition-transform-opacity text-small",
|
|
12
|
+
"group-data-[selected=true]:translate-x-3 group-data-[selected=true]:opacity-0",
|
|
13
|
+
"motion-reduce:transition-none"
|
|
14
|
+
],
|
|
15
|
+
/** Container for validation messages */
|
|
16
|
+
errorMessage: "text-danger text-tiny",
|
|
17
|
+
/** Container for help text and validation messages */
|
|
18
|
+
helperWrapper: "relative ml-0 block p-0",
|
|
19
|
+
/** Visible field label */
|
|
20
|
+
label: "group-data-[invalid=true]:text-danger! relative ms-2 select-none text-sm text-foreground subpixel-antialiased",
|
|
21
|
+
/** Container grouping the toggle and field messages */
|
|
22
|
+
outerWrapper: "place-content-center",
|
|
23
|
+
/** Content at the start of the control */
|
|
24
|
+
startContent: [
|
|
25
|
+
"absolute start-1.5 z-0 scale-50 text-current opacity-0 transition-transform-opacity text-small",
|
|
26
|
+
"group-data-[selected=true]:scale-100 group-data-[selected=true]:opacity-100",
|
|
27
|
+
"motion-reduce:transition-none"
|
|
28
|
+
],
|
|
29
|
+
/** Movable indicator showing the current value */
|
|
30
|
+
thumb: [
|
|
31
|
+
"pointer-events-none z-10 flex h-5 w-5 origin-right items-center justify-center rounded-full bg-white shadow-small transition-all text-small",
|
|
32
|
+
"group-data-[selected=true]:group-data-[pressed=true]:ms-4 group-data-[selected=true]:ms-5 group-data-[pressed=true]:w-6",
|
|
33
|
+
"motion-reduce:transition-none"
|
|
34
|
+
],
|
|
35
|
+
/** Content inside the toggle thumb */
|
|
36
|
+
thumbIcon: "text-black",
|
|
37
|
+
/** Container arranging the selectable content */
|
|
38
|
+
wrapper: [
|
|
39
|
+
"relative inline-flex h-7 w-12 shrink-0 items-center justify-start overflow-hidden rounded-full bg-default-200 px-1 transition-background",
|
|
40
|
+
"group-data-[selected=true]:bg-primary group-data-[selected=true]:text-primary-foreground",
|
|
41
|
+
"group-data-[focus-visible=true]:ring-2 group-data-[focus-visible=true]:ring-focus group-data-[focus-visible=true]:ring-offset-2 group-data-[focus-visible=true]:ring-offset-background",
|
|
42
|
+
"motion-reduce:transition-none"
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
variants: {
|
|
46
|
+
size: {
|
|
47
|
+
lg: {
|
|
48
|
+
endContent: "text-medium",
|
|
49
|
+
startContent: "text-medium",
|
|
50
|
+
thumb: "h-6 w-6 text-medium group-data-[selected=true]:group-data-[pressed=true]:ms-5 group-data-[selected=true]:ms-6 group-data-[pressed=true]:w-7",
|
|
51
|
+
wrapper: "h-8 w-14"
|
|
52
|
+
},
|
|
53
|
+
md: {},
|
|
54
|
+
sm: {
|
|
55
|
+
endContent: "text-tiny",
|
|
56
|
+
startContent: "text-tiny",
|
|
57
|
+
thumb: "h-4 w-4 text-tiny group-data-[selected=true]:group-data-[pressed=true]:ms-3 group-data-[selected=true]:ms-4 group-data-[pressed=true]:w-5",
|
|
58
|
+
wrapper: "h-6 w-10"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
disabled: { true: { base: "pointer-events-none opacity-disabled" } }
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
//#endregion
|
|
65
|
+
export { switchVariants as t };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=switchVariants-BaQw2DA7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchVariants-BaQw2DA7.mjs","names":[],"sources":["../src/Switch/switchVariants.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nexport const switchVariants = tv({\n slots: {\n /** Container for the field control and supporting text */\n base: 'group relative inline-flex max-w-fit cursor-pointer touch-none select-none items-center justify-start tap-highlight-transparent',\n /** Supporting text for the field */\n description: 'text-foreground-500 text-tiny',\n /** Content at the end of the control */\n endContent: [\n // end icon position and fade transition\n 'absolute end-1.5 z-0 text-default-600 opacity-100 transition-transform-opacity text-small',\n // move and hide the selected end icon\n 'group-data-[selected=true]:translate-x-3 group-data-[selected=true]:opacity-0',\n // reduced motion\n 'motion-reduce:transition-none',\n ],\n /** Container for validation messages */\n errorMessage: 'text-danger text-tiny',\n /** Container for help text and validation messages */\n helperWrapper: 'relative ml-0 block p-0',\n /** Visible field label */\n label:\n 'group-data-[invalid=true]:text-danger! relative ms-2 select-none text-sm text-foreground subpixel-antialiased',\n /** Container grouping the toggle and field messages */\n outerWrapper: 'place-content-center',\n /** Content at the start of the control */\n startContent: [\n // start icon position and fade transition\n 'absolute start-1.5 z-0 scale-50 text-current opacity-0 transition-transform-opacity text-small',\n // reveal the selected start icon\n 'group-data-[selected=true]:scale-100 group-data-[selected=true]:opacity-100',\n // reduced motion\n 'motion-reduce:transition-none',\n ],\n /** Movable indicator showing the current value */\n thumb: [\n // thumb layout and surface\n 'pointer-events-none z-10 flex h-5 w-5 origin-right items-center justify-center rounded-full bg-white shadow-small transition-all text-small',\n // selected position and pressed width\n 'group-data-[selected=true]:group-data-[pressed=true]:ms-4 group-data-[selected=true]:ms-5 group-data-[pressed=true]:w-6',\n // reduced motion\n 'motion-reduce:transition-none',\n ],\n /** Content inside the toggle thumb */\n thumbIcon: 'text-black',\n /** Container arranging the selectable content */\n wrapper: [\n // switch track layout and surface\n 'relative inline-flex h-7 w-12 shrink-0 items-center justify-start overflow-hidden rounded-full bg-default-200 px-1 transition-background',\n // selected track colors\n 'group-data-[selected=true]:bg-primary group-data-[selected=true]:text-primary-foreground',\n // keyboard focus ring\n 'group-data-[focus-visible=true]:ring-2 group-data-[focus-visible=true]:ring-focus group-data-[focus-visible=true]:ring-offset-2 group-data-[focus-visible=true]:ring-offset-background',\n // reduced motion\n 'motion-reduce:transition-none',\n ],\n },\n variants: {\n size: {\n lg: {\n endContent: 'text-medium',\n startContent: 'text-medium',\n thumb:\n 'h-6 w-6 text-medium group-data-[selected=true]:group-data-[pressed=true]:ms-5 group-data-[selected=true]:ms-6 group-data-[pressed=true]:w-7',\n wrapper: 'h-8 w-14',\n },\n md: {},\n sm: {\n endContent: 'text-tiny',\n startContent: 'text-tiny',\n thumb:\n 'h-4 w-4 text-tiny group-data-[selected=true]:group-data-[pressed=true]:ms-3 group-data-[selected=true]:ms-4 group-data-[pressed=true]:w-5',\n wrapper: 'h-6 w-10',\n },\n },\n disabled: { true: { base: 'pointer-events-none opacity-disabled' } },\n },\n});\n\nexport type VariantProps = TVProps<typeof switchVariants>;\n\nexport type ClassName = TVClassName<typeof switchVariants>;\n"],"mappings":";;AAIA,MAAa,iBAAiB,GAAG;CAC/B,OAAO;;EAEL,MAAM;;EAEN,aAAa;;EAEb,YAAY;GAEV;GAEA;GAEA;EACF;;EAEA,cAAc;;EAEd,eAAe;;EAEf,OACE;;EAEF,cAAc;;EAEd,cAAc;GAEZ;GAEA;GAEA;EACF;;EAEA,OAAO;GAEL;GAEA;GAEA;EACF;;EAEA,WAAW;;EAEX,SAAS;GAEP;GAEA;GAEA;GAEA;EACF;CACF;CACA,UAAU;EACR,MAAM;GACJ,IAAI;IACF,YAAY;IACZ,cAAc;IACd,OACE;IACF,SAAS;GACX;GACA,IAAI,CAAC;GACL,IAAI;IACF,YAAY;IACZ,cAAc;IACd,OACE;IACF,SAAS;GACX;EACF;EACA,UAAU,EAAE,MAAM,EAAE,MAAM,uCAAuC,EAAE;CACrE;AACF,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { tv } from "@fuf-stack/pixel-utils";
|
|
2
|
+
//#region src/Time/timeVariants.ts
|
|
3
|
+
/** Shared segmented input defaults, also extended by DatePicker */
|
|
4
|
+
const segmentedInputVariants = tv({ slots: {
|
|
5
|
+
/** Field container with space for supporting text */
|
|
6
|
+
base: "group flex w-full flex-col gap-y-1.5 pb-5",
|
|
7
|
+
/** Field description text */
|
|
8
|
+
description: "text-foreground-500 text-tiny",
|
|
9
|
+
/** Validation message text */
|
|
10
|
+
errorMessage: "text-danger text-tiny",
|
|
11
|
+
/** Supporting text below the input surface */
|
|
12
|
+
helperWrapper: ["absolute start-0 top-[calc(100%_+_2px)] flex flex-col gap-1.5", "p-0"],
|
|
13
|
+
/** Row containing segments and optional controls */
|
|
14
|
+
innerWrapper: "flex h-6 w-full items-center gap-x-2 text-default-400",
|
|
15
|
+
/** Editable date or time segment group */
|
|
16
|
+
input: "flex h-full w-full gap-x-0.5 font-normal text-small",
|
|
17
|
+
/** Bordered surface around the editable segments */
|
|
18
|
+
inputWrapper: [
|
|
19
|
+
"shadow-xs relative inline-flex h-10 min-h-10 w-full cursor-text flex-row items-center gap-3",
|
|
20
|
+
"rounded-small border-2 border-default-200 px-3",
|
|
21
|
+
"transition-colors duration-150",
|
|
22
|
+
"hover:border-default-400 focus-within:hover:border-default-foreground",
|
|
23
|
+
"motion-reduce:transition-none",
|
|
24
|
+
"bg-content1 focus-within:border-focus"
|
|
25
|
+
],
|
|
26
|
+
/** Label above the segmented input */
|
|
27
|
+
label: ["block w-full text-foreground subpixel-antialiased text-small", "cursor-default"],
|
|
28
|
+
/** Individual editable value or separator */
|
|
29
|
+
segment: [
|
|
30
|
+
"outline-solid focus:shadow-xs",
|
|
31
|
+
"group my-auto box-content inline-block rounded-md px-0.5 text-start tabular-nums text-foreground-500 outline-transparent",
|
|
32
|
+
"transition-colors",
|
|
33
|
+
"first:-ml-0.5 focus:bg-default-400/50",
|
|
34
|
+
"data-[editable=true]:data-[placeholder=true]:text-foreground-500 data-[editable=true]:text-foreground data-[editable=true]:focus:text-default-foreground",
|
|
35
|
+
"motion-reduce:transition-none",
|
|
36
|
+
"[&:not(:first-child)]:-ml-1"
|
|
37
|
+
]
|
|
38
|
+
} });
|
|
39
|
+
const timeVariants = tv({
|
|
40
|
+
extend: segmentedInputVariants,
|
|
41
|
+
variants: {
|
|
42
|
+
disabled: { true: { base: "pointer-events-none opacity-disabled" } },
|
|
43
|
+
invalid: { true: {
|
|
44
|
+
innerWrapper: "text-danger",
|
|
45
|
+
inputWrapper: "border-danger focus-within:border-danger hover:border-danger focus-within:hover:border-danger",
|
|
46
|
+
label: "text-danger",
|
|
47
|
+
segment: [
|
|
48
|
+
"text-danger-300 focus:bg-danger-400/50",
|
|
49
|
+
"data-[editable=true]:data-[placeholder=true]:text-danger data-[editable=true]:text-danger data-[editable=true]:focus:text-danger",
|
|
50
|
+
"dark:focus:bg-danger-400/20"
|
|
51
|
+
]
|
|
52
|
+
} }
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
//#endregion
|
|
56
|
+
export { timeVariants as n, segmentedInputVariants as t };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=timeVariants-B9HDfNYt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeVariants-B9HDfNYt.mjs","names":[],"sources":["../src/Time/timeVariants.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\n/** Shared segmented input defaults, also extended by DatePicker */\nexport const segmentedInputVariants = tv({\n slots: {\n /** Field container with space for supporting text */\n base: 'group flex w-full flex-col gap-y-1.5 pb-5',\n /** Field description text */\n description: 'text-foreground-500 text-tiny',\n /** Validation message text */\n errorMessage: 'text-danger text-tiny',\n /** Supporting text below the input surface */\n helperWrapper: [\n 'absolute start-0 top-[calc(100%_+_2px)] flex flex-col gap-1.5',\n 'p-0',\n ],\n /** Row containing segments and optional controls */\n innerWrapper: 'flex h-6 w-full items-center gap-x-2 text-default-400',\n /** Editable date or time segment group */\n input: 'flex h-full w-full gap-x-0.5 font-normal text-small',\n /** Bordered surface around the editable segments */\n inputWrapper: [\n // segmented control frame and layout\n 'shadow-xs relative inline-flex h-10 min-h-10 w-full cursor-text flex-row items-center gap-3',\n // border and padding\n 'rounded-small border-2 border-default-200 px-3',\n // color transitions\n 'transition-colors duration-150',\n // hover and focus borders\n 'hover:border-default-400 focus-within:hover:border-default-foreground',\n // reduced motion\n 'motion-reduce:transition-none',\n // surface color and focused border\n 'bg-content1 focus-within:border-focus',\n ],\n /** Label above the segmented input */\n label: [\n 'block w-full text-foreground subpixel-antialiased text-small',\n 'cursor-default',\n ],\n /** Individual editable value or separator */\n segment: [\n // segment focus outline and shadow\n 'outline-solid focus:shadow-xs',\n // segment spacing and typography\n 'group my-auto box-content inline-block rounded-md px-0.5 text-start tabular-nums text-foreground-500 outline-transparent',\n // color transition\n 'transition-colors',\n // first segment alignment and focus background\n 'first:-ml-0.5 focus:bg-default-400/50',\n // editable values and empty placeholders\n 'data-[editable=true]:data-[placeholder=true]:text-foreground-500 data-[editable=true]:text-foreground data-[editable=true]:focus:text-default-foreground',\n // reduced motion\n 'motion-reduce:transition-none',\n // spacing between subsequent segments\n '[&:not(:first-child)]:-ml-1',\n ],\n },\n});\n\nexport const timeVariants = tv({\n extend: segmentedInputVariants,\n variants: {\n disabled: { true: { base: 'pointer-events-none opacity-disabled' } },\n invalid: {\n true: {\n innerWrapper: 'text-danger',\n inputWrapper:\n 'border-danger focus-within:border-danger hover:border-danger focus-within:hover:border-danger',\n label: 'text-danger',\n segment: [\n // invalid text and focus background\n 'text-danger-300 focus:bg-danger-400/50',\n // editable values and empty placeholders\n 'data-[editable=true]:data-[placeholder=true]:text-danger data-[editable=true]:text-danger data-[editable=true]:focus:text-danger',\n // dark theme focus background\n 'dark:focus:bg-danger-400/20',\n ],\n },\n },\n },\n});\n\nexport type VariantProps = TVProps<typeof timeVariants>;\n\nexport type ClassName = TVClassName<typeof timeVariants>;\n\n/** Resolved class names for the segmented time slots */\nexport type TimeClassNames = Record<\n keyof ReturnType<typeof timeVariants>,\n string\n>;\n"],"mappings":";;;AAKA,MAAa,yBAAyB,GAAG,EACvC,OAAO;;CAEL,MAAM;;CAEN,aAAa;;CAEb,cAAc;;CAEd,eAAe,CACb,iEACA,KACF;;CAEA,cAAc;;CAEd,OAAO;;CAEP,cAAc;EAEZ;EAEA;EAEA;EAEA;EAEA;EAEA;CACF;;CAEA,OAAO,CACL,gEACA,gBACF;;CAEA,SAAS;EAEP;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;CACF;AACF,EACF,CAAC;AAED,MAAa,eAAe,GAAG;CAC7B,QAAQ;CACR,UAAU;EACR,UAAU,EAAE,MAAM,EAAE,MAAM,uCAAuC,EAAE;EACnE,SAAS,EACP,MAAM;GACJ,cAAc;GACd,cACE;GACF,OAAO;GACP,SAAS;IAEP;IAEA;IAEA;GACF;EACF,EACF;CACF;AACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { n as UniformContext } from "./FormContext-CHctWFAP.mjs";
|
|
1
2
|
import { fromNullishString, toNullishString } from "./helpers/index.mjs";
|
|
2
|
-
import { n as UniformContext } from "./FormContext-gHSwOlcy.mjs";
|
|
3
3
|
import { useContext } from "react";
|
|
4
4
|
import { useController } from "react-hook-form";
|
|
5
5
|
//#region src/hooks/useController/useController.ts
|
|
@@ -42,4 +42,4 @@ const useController$1 = (props) => {
|
|
|
42
42
|
//#endregion
|
|
43
43
|
export { useController$1 as t };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=useController-
|
|
45
|
+
//# sourceMappingURL=useController-BCFeZbBZ.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useController-
|
|
1
|
+
{"version":3,"file":"useController-BCFeZbBZ.mjs","names":["useController","useRHFController"],"sources":["../src/hooks/useController/useController.ts"],"sourcesContent":["import type {\n ControllerFieldState,\n ControllerRenderProps,\n UseControllerProps as RHFUseControllerProps,\n UseFormStateReturn,\n} from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useController as useRHFController } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { fromNullishString, toNullishString } from '../../helpers';\n\nexport type UseControllerProps<TFieldValues extends object = object> =\n RHFUseControllerProps<TFieldValues>;\n\nexport interface UseControllerReturn<TFieldValues extends object = object> {\n field: Omit<ControllerRenderProps<TFieldValues>, 'onChange' | 'value'> & {\n // Using any[] to support both direct value changes and React synthetic events\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n value: string;\n };\n fieldState: ControllerFieldState;\n formState: UseFormStateReturn<TFieldValues>;\n}\n\n/**\n * A wrapper around react-hook-form's useController that transparently handles nullish string conversions.\n *\n * Key features:\n * 1. Empty strings ('') in the UI are stored as null in form state\n * 2. Null/undefined values in form state are displayed as empty strings in the UI\n * 3. Handles both direct value changes and React synthetic events\n * 4. Maintains the same API as react-hook-form's useController\n * 5. Notifies UniformContext's userChange listeners on field changes (enables useWatchUserChange hook)\n * 6. No-op when value unchanged: onChange is ignored if the new value equals the current value\n * (prevents unnecessary re-renders and spurious useWatchUserChange triggers)\n *\n * This enables consistent handling of empty/null values while keeping a clean API\n * for form inputs that expect string values.\n *\n * @see https://react-hook-form.com/docs/usecontroller\n */\nexport const useController = <TFieldValues extends object = object>(\n props: UseControllerProps<TFieldValues>,\n): UseControllerReturn<TFieldValues> => {\n const { field, formState, fieldState } = useRHFController(props);\n const { userChange } = useContext(UniformContext);\n\n return {\n field: {\n ...field,\n // Handles both direct values (onChange(\"value\")) and events (onChange(event))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => {\n const value = event[0]?.target?.value ?? event[0];\n const formattedValue = value === '' ? '' : toNullishString(value);\n\n // Skip if value hasn't changed (e.g., user re-selects same option)\n // We compare formattedValue (the new value after nullish conversion) with\n // field.value (the current stored value, also in nullish format)\n if (formattedValue === field.value) {\n return;\n }\n\n // Update form state first\n field.onChange(formattedValue);\n\n // Then notify userChange listeners (for useWatchUserChange hook)\n // This ensures getValues() in listeners returns the updated value\n // Guard against undefined userChange (when used outside FormProvider)\n // NOTE: We notify with the original value (not formattedValue) so that\n // listeners receive the actual value (false, 0, null) instead of marker\n // strings like '__FALSE__', '__ZERO__', '__NULL__'\n userChange?.notify(field.name, value);\n },\n // Convert null/undefined to empty string for UI display\n value: fromNullishString(field.value) as string,\n },\n formState,\n fieldState,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAaA,mBACX,UACsC;CACtC,MAAM,EAAE,OAAO,WAAW,eAAeC,cAAiB,KAAK;CAC/D,MAAM,EAAE,eAAe,WAAW,cAAc;CAEhD,OAAO;EACL,OAAO;GACL,GAAG;GAGH,WAAW,GAAG,UAAiB;IAC7B,MAAM,QAAQ,MAAM,EAAE,EAAE,QAAQ,SAAS,MAAM;IAC/C,MAAM,iBAAiB,UAAU,KAAK,KAAK,gBAAgB,KAAK;IAKhE,IAAI,mBAAmB,MAAM,OAC3B;IAIF,MAAM,SAAS,cAAc;IAQ7B,YAAY,OAAO,MAAM,MAAM,KAAK;GACtC;GAEA,OAAO,kBAAkB,MAAM,KAAK;EACtC;EACA;EACA;CACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { n as UniformContext } from "./FormContext-CHctWFAP.mjs";
|
|
1
2
|
import { flatArrayKey, nameToTestId, toValidationFormat } from "./helpers/index.mjs";
|
|
2
|
-
import { n as UniformContext } from "./FormContext-gHSwOlcy.mjs";
|
|
3
3
|
import { useContext } from "react";
|
|
4
4
|
import { useFormContext } from "react-hook-form";
|
|
5
5
|
//#region src/hooks/useFormContext/useFormContext.ts
|
|
@@ -134,4 +134,4 @@ const useFormContext$1 = () => {
|
|
|
134
134
|
//#endregion
|
|
135
135
|
export { useFormContext$1 as n, checkFieldIsRequired as t };
|
|
136
136
|
|
|
137
|
-
//# sourceMappingURL=useFormContext-
|
|
137
|
+
//# sourceMappingURL=useFormContext-BPjJjNnM.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormContext-
|
|
1
|
+
{"version":3,"file":"useFormContext-BPjJjNnM.mjs","names":["useFormContext","useHookFormContext"],"sources":["../src/hooks/useFormContext/useFormContext.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { VetoFormattedError, VetoInstance } from '@fuf-stack/veto';\nimport type { FieldError, FieldValues, Path } from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useFormContext as useHookFormContext } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { flatArrayKey, nameToTestId, toValidationFormat } from '../../helpers';\n\n/** Schema check whether a field is required or optional */\nexport const checkFieldIsRequired = (\n validation: VetoInstance,\n path: string[],\n): boolean => {\n // Handle flat array paths: strip the flatArrayKey to check the array element schema\n // e.g., ['arrayField', '0', '__FLAT__'] -> check schema at ['arrayField', '0']\n const checkPath =\n path[path.length - 1] === flatArrayKey ? path.slice(0, -1) : path;\n\n const checkRequired = (schema: any) => {\n // arrays ...\n if (schema.type === 'array') {\n // ... if array is optional or nullable it is not required\n if (schema.isOptional || schema.isNullable) {\n return false;\n }\n // ... otherwise arrays are required (display logic wise -> no asterisk in the label)\n return true;\n }\n\n // all other fields are required if they are\n // not optional and not nullable\n return !schema.isOptional && !schema.isNullable;\n };\n\n return validation.checkSchemaPath(checkRequired, checkPath);\n};\n\n/**\n * Resolve validation errors for a given field path.\n *\n * Traverses a nested `VetoFormattedError` structure using a dotted path\n * (for example: \"user.address.0.street\") and returns the matching\n * `FieldError[]` if present. If no error exists at the path, returns\n * `undefined`.\n *\n * @param errors - The formatted validation errors from Uniform's context\n * @param name - The dotted field path to resolve\n * @returns An array of `FieldError` entries for the field, or `undefined`\n */\nconst getValidationErrorsByName = (\n errors: VetoFormattedError,\n name: string,\n) => {\n // Traverse nested error structure; ignore flat array wrapper key\n const keys = name.split('.').filter((k) => {\n return k !== flatArrayKey;\n });\n let current: unknown = errors;\n keys.forEach((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n } else {\n current = undefined;\n }\n });\n return current as FieldError[] | undefined;\n};\n\n/**\n * Custom hook that extends react-hook-form's useFormContext to add validation and state management.\n *\n * Key features:\n * - Enhanced `getFieldState` that includes validation schema-based \"required\" status and testId generation\n * - Automatic conversion of form values via `getValues`, `watch`, and `subscribe`:\n * - Unwraps flat array wrappers (`{ __FLAT__: value }` → `value`)\n * - Converts nullish string markers (`__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`)\n * - Filters out empty/null values\n */\nexport const useFormContext = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>() => {\n const {\n formState,\n // some methods that will be enhanced below\n getFieldState: getFieldStateOrig,\n getValues: getValuesOrig,\n watch: watchOrig,\n subscribe: subscribeOrig,\n reset: resetOrig,\n // the rest of the methods pass through unchanged\n ...otherMethods\n } = useHookFormContext<TFieldValues, TContext, TTransformedValues>();\n\n const uniformContext = useContext(UniformContext);\n\n /**\n * Wrap react-hook-form's `reset` so the uniform context is notified about\n * programmatic resets. Field components (e.g. FieldArray) use this signal to\n * normalize their state on reset instead of inferring it from field contents.\n */\n const notifyReset = uniformContext?.formReset?.notify;\n const reset = ((...args: Parameters<typeof resetOrig>) => {\n resetOrig(...args);\n notifyReset?.();\n }) as typeof resetOrig;\n\n /**\n * Updated getFieldState method which returns:\n * - Whether the field is required by checking the validation schema\n * - Existing field state information (errors, etc.)\n * - A testId generated from the field name (with flat array keys removed and slugified)\n *\n * @param name - The field path (string or array)\n * @param testId - Optional explicit testId. If provided, will be slugified. If not provided, generated from name.\n */\n const getFieldState = (name: Path<TFieldValues>, testId?: string) => {\n const fieldPath =\n typeof name === 'string' ? name.replace(/\\[\\d+\\]/g, '').split('.') : name;\n\n // Use base validation instance for checking \"required\" status\n // Client validation often uses .nullish() which would incorrectly mark fields as optional\n const validationInstance =\n uniformContext?.validation.baseInstance ??\n uniformContext?.validation.instance;\n\n // Check if the field is required using the validation schema\n const required = validationInstance\n ? checkFieldIsRequired(validationInstance, fieldPath)\n : false;\n\n const error = getValidationErrorsByName(\n uniformContext?.validation.errors ?? {},\n name,\n );\n\n // Get everything but the error from the original field state\n const fieldState = getFieldStateOrig(name, formState);\n\n return {\n ...fieldState,\n error,\n invalid: !!error,\n required,\n testId: nameToTestId(testId ?? name),\n };\n };\n\n /**\n * Wrap form value accessor methods to automatically convert from internal storage format\n * to component-friendly format:\n *\n * - Unwrap flat array wrappers: `{ __FLAT__: value }` → `value`\n * - Convert nullish string markers: `__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`\n * - Filter out empty/null values: fields with converted null/empty values are removed entirely\n *\n * This ensures components receive clean, predictable data without needing to handle\n * the internal nullish string conversion system or flat array wrapping manually.\n */\n const getValues = ((...args: any[]) => {\n const result = (getValuesOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof getValuesOrig;\n\n const watch = ((...args: any[]) => {\n const result = (watchOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof watchOrig;\n\n const subscribe = ((...args: any[]) => {\n // For subscribe, we need to wrap the callback to convert the values property\n const [options] = args;\n if (options?.callback) {\n const originalCallback = options.callback;\n const wrappedOptions = {\n ...options,\n callback: (subscribeFormState: any) => {\n // Convert the values property if it exists\n const convertedFormState = {\n ...subscribeFormState,\n ...(subscribeFormState.values && {\n values: toValidationFormat(subscribeFormState.values),\n }),\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return originalCallback(convertedFormState);\n },\n };\n return subscribeOrig(wrappedOptions);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (subscribeOrig as any)(...args);\n }) as typeof subscribeOrig;\n\n return {\n ...otherMethods,\n ...uniformContext,\n formState,\n getFieldState,\n getValues,\n reset,\n subscribe,\n watch,\n };\n};\n"],"mappings":";;;;;;AAYA,MAAa,wBACX,YACA,SACY;CAGZ,MAAM,YACJ,KAAK,KAAK,SAAS,OAAA,aAAsB,KAAK,MAAM,GAAG,EAAE,IAAI;CAE/D,MAAM,iBAAiB,WAAgB;EAErC,IAAI,OAAO,SAAS,SAAS;GAE3B,IAAI,OAAO,cAAc,OAAO,YAC9B,OAAO;GAGT,OAAO;EACT;EAIA,OAAO,CAAC,OAAO,cAAc,CAAC,OAAO;CACvC;CAEA,OAAO,WAAW,gBAAgB,eAAe,SAAS;AAC5D;;;;;;;;;;;;;AAcA,MAAM,6BACJ,QACA,SACG;CAEH,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAQ,MAAM;EACzC,OAAO,MAAM;CACf,CAAC;CACD,IAAI,UAAmB;CACvB,KAAK,SAAS,QAAQ;EACpB,IAAI,WAAW,OAAO,YAAY,UAChC,UAAW,QAAoC;OAE/C,UAAU,KAAA;CAEd,CAAC;CACD,OAAO;AACT;;;;;;;;;;;AAYA,MAAaA,yBAIN;CACL,MAAM,EACJ,WAEA,eAAe,mBACf,WAAW,eACX,OAAO,WACP,WAAW,eACX,OAAO,WAEP,GAAG,iBACDC,eAA+D;CAEnE,MAAM,iBAAiB,WAAW,cAAc;;;;;;CAOhD,MAAM,cAAc,gBAAgB,WAAW;CAC/C,MAAM,UAAU,GAAG,SAAuC;EACxD,UAAU,GAAG,IAAI;EACjB,cAAc;CAChB;;;;;;;;;;CAWA,MAAM,iBAAiB,MAA0B,WAAoB;EACnE,MAAM,YACJ,OAAO,SAAS,WAAW,KAAK,QAAQ,YAAY,EAAE,CAAC,CAAC,MAAM,GAAG,IAAI;EAIvE,MAAM,qBACJ,gBAAgB,WAAW,gBAC3B,gBAAgB,WAAW;EAG7B,MAAM,WAAW,qBACb,qBAAqB,oBAAoB,SAAS,IAClD;EAEJ,MAAM,QAAQ,0BACZ,gBAAgB,WAAW,UAAU,CAAC,GACtC,IACF;EAKA,OAAO;GACL,GAHiB,kBAAkB,MAAM,SAG7B;GACZ;GACA,SAAS,CAAC,CAAC;GACX;GACA,QAAQ,aAAa,UAAU,IAAI;EACrC;CACF;;;;;;;;;;;;CAaA,MAAM,cAAc,GAAG,SAAgB;EACrC,MAAM,SAAU,cAAsB,GAAG,IAAI;EAC7C,OAAO,mBAAmB,MAAM;CAClC;CAEA,MAAM,UAAU,GAAG,SAAgB;EACjC,MAAM,SAAU,UAAkB,GAAG,IAAI;EACzC,OAAO,mBAAmB,MAAM;CAClC;CAEA,MAAM,cAAc,GAAG,SAAgB;EAErC,MAAM,CAAC,WAAW;EAClB,IAAI,SAAS,UAAU;GACrB,MAAM,mBAAmB,QAAQ;GACjC,MAAM,iBAAiB;IACrB,GAAG;IACH,WAAW,uBAA4B;KAErC,MAAM,qBAAqB;MACzB,GAAG;MACH,GAAI,mBAAmB,UAAU,EAC/B,QAAQ,mBAAmB,mBAAmB,MAAM,EACtD;KACF;KAEA,OAAO,iBAAiB,kBAAkB;IAC5C;GACF;GACA,OAAO,cAAc,cAAc;EACrC;EAEA,OAAQ,cAAsB,GAAG,IAAI;CACvC;CAEA,OAAO;EACL,GAAG;EACH,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -87,7 +87,7 @@ const useInputValueTransform = ({ type, transform }) => {
|
|
|
87
87
|
toDisplayValue: useCallback((formValue) => {
|
|
88
88
|
if (transform?.toDisplayValue) return transform.toDisplayValue(formValue);
|
|
89
89
|
if (type === "number") {
|
|
90
|
-
if (formValue === "") return "";
|
|
90
|
+
if (formValue === "" || formValue === null || formValue === void 0) return "";
|
|
91
91
|
const numValue = Number(formValue);
|
|
92
92
|
return Number.isNaN(numValue) ? formValue : numValue;
|
|
93
93
|
}
|
|
@@ -107,4 +107,4 @@ const useInputValueTransform = ({ type, transform }) => {
|
|
|
107
107
|
//#endregion
|
|
108
108
|
export { useInputValueTransform as t };
|
|
109
109
|
|
|
110
|
-
//# sourceMappingURL=useInputValueTransform-
|
|
110
|
+
//# sourceMappingURL=useInputValueTransform-Mw8YEOXT.mjs.map
|
package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-Mw8YEOXT.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInputValueTransform-
|
|
1
|
+
{"version":3,"file":"useInputValueTransform-Mw8YEOXT.mjs","names":[],"sources":["../src/hooks/useInputValueTransform/useInputValueTransform.ts"],"sourcesContent":["import { useCallback } from 'react';\n\nexport interface InputValueTransform<TDisplay = unknown> {\n /** Transforms the form value to display value (e.g., 1000 → \"$1,000\" or 'a' → ['a']) */\n toDisplayValue: (value: unknown) => TDisplay;\n /** Transforms the display value to form value (e.g., \"$1,000\" → 1000 or ['a'] → 'a') */\n toFormValue: (value: TDisplay) => unknown;\n}\n\nexport interface UseInputValueTransformOptions<TDisplay = unknown> {\n /** Value transformation functions */\n transform?: InputValueTransform<TDisplay>;\n /** Input type for special number handling */\n type?: 'text' | 'number' | 'password';\n}\n\nexport interface UseInputValueTransformReturn<TDisplay = unknown> {\n /** Converts any form value to display value */\n toDisplayValue: (formValue: unknown) => TDisplay;\n /** Converts any display value to form value */\n toFormValue: (displayValue: TDisplay) => unknown;\n}\n\n/**\n * Custom hook providing utility functions for value transformations between display and form values.\n *\n * This hook provides pure conversion functions without any state management. It's useful for:\n * - Currency formatting ($1,000 display vs 1000 stored)\n * - Number inputs with special handling\n * - Date formatting (MM/DD/YYYY display vs ISO date stored)\n * - Phone number formatting ((555) 123-4567 display vs 5551234567 stored)\n * - Array/Object transformations (single value ↔ array, nested structures)\n *\n * **Key Features:**\n * - Pure conversion functions (no state)\n * - Generic support for any data type (strings, numbers, arrays, objects)\n * - Special number input handling (empty string preservation)\n * - Bidirectional value transformations\n * - Memoized functions for performance\n *\n * @param options Configuration for value transformation\n * @returns Pure conversion utility functions\n *\n * @example\n * ```tsx\n * // Currency formatting\n * const currencyTransform = {\n * toDisplayValue: (val) => val ? `$${Number(val).toLocaleString()}` : '',\n * toFormValue: (val) => parseFloat(val.replace(/[$,]/g, '')) || 0\n * };\n *\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * transform: currencyTransform\n * });\n *\n * const displayVal = toDisplayValue(1000); // \"$1,000\"\n * const formVal = toFormValue(\"$1,500\"); // 1500\n * ```\n *\n * @example\n * ```tsx\n * // Number input (no transforms needed)\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * type: 'number'\n * });\n *\n * // Handles empty string → empty string (not NaN)\n * // Handles \"123\" → 123 (string to number conversion)\n * ```\n *\n * @example\n * ```tsx\n * // Array to single value (for single checkbox)\n * const singleValueTransform = {\n * toDisplayValue: (val: string[]) => val?.[0] || '',\n * toFormValue: (val: string) => val ? [val] : []\n * };\n *\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * transform: singleValueTransform\n * });\n *\n * const displayVal = toDisplayValue(['option1']); // \"option1\"\n * const formVal = toFormValue(\"option2\"); // [\"option2\"]\n * ```\n *\n * @example\n * ```tsx\n * // Integration with debouncing\n * const MyInput = ({ field, transform }) => {\n * const transform = useInputValueTransform({ transform });\n *\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * ...transform,\n * debounceDelay: 300,\n * name: 'fieldName',\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * value: field.value,\n * });\n *\n * return <input value={value} onChange={onChange} onBlur={onBlur} />;\n * };\n * ```\n */\nexport const useInputValueTransform = <TDisplay = unknown>({\n type,\n transform,\n}: UseInputValueTransformOptions<TDisplay>): UseInputValueTransformReturn<TDisplay> => {\n /**\n * Converts any form value to display value\n */\n const toDisplayValue = useCallback(\n (formValue: unknown): TDisplay => {\n if (transform?.toDisplayValue) {\n return transform.toDisplayValue(formValue);\n }\n\n // For number type, convert valid strings to numbers for display\n if (type === 'number') {\n if (formValue === '' || formValue === null || formValue === undefined) {\n return '' as TDisplay;\n }\n const numValue = Number(formValue);\n return (Number.isNaN(numValue) ? formValue : numValue) as TDisplay;\n }\n\n // Default: pass through (handles primitives, arrays, objects, etc.)\n return (formValue ?? '') as TDisplay;\n },\n [type, transform],\n );\n\n /**\n * Converts any display value to form value\n */\n const toFormValue = useCallback(\n (displayValue: TDisplay): unknown => {\n if (transform?.toFormValue) {\n return transform.toFormValue(displayValue);\n }\n\n // For number type, convert strings to numbers\n if (type === 'number') {\n if (displayValue === '') {\n return '';\n }\n const numValue = Number(displayValue);\n return Number.isNaN(numValue) ? displayValue : numValue;\n }\n\n // Default: pass through (handles primitives, arrays, objects, etc.)\n return displayValue;\n },\n [type, transform],\n );\n\n return {\n toDisplayValue,\n toFormValue,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,MAAa,0BAA8C,EACzD,MACA,gBACqF;CAiDrF,OAAO;EACL,gBA9CqB,aACpB,cAAiC;GAChC,IAAI,WAAW,gBACb,OAAO,UAAU,eAAe,SAAS;GAI3C,IAAI,SAAS,UAAU;IACrB,IAAI,cAAc,MAAM,cAAc,QAAQ,cAAc,KAAA,GAC1D,OAAO;IAET,MAAM,WAAW,OAAO,SAAS;IACjC,OAAQ,OAAO,MAAM,QAAQ,IAAI,YAAY;GAC/C;GAGA,OAAQ,aAAa;EACvB,GACA,CAAC,MAAM,SAAS,CA4BH;EACb,aAvBkB,aACjB,iBAAoC;GACnC,IAAI,WAAW,aACb,OAAO,UAAU,YAAY,YAAY;GAI3C,IAAI,SAAS,UAAU;IACrB,IAAI,iBAAiB,IACnB,OAAO;IAET,MAAM,WAAW,OAAO,YAAY;IACpC,OAAO,OAAO,MAAM,QAAQ,IAAI,eAAe;GACjD;GAGA,OAAO;EACT,GACA,CAAC,MAAM,SAAS,CAKN;CACZ;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fuf-stack/uniform",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.1",
|
|
4
4
|
"description": "fuf react form library",
|
|
5
5
|
"author": "Fröhlich ∧ Frei",
|
|
6
6
|
"homepage": "https://github.com/fuf-stack/pixels#readme",
|
|
@@ -18,11 +18,8 @@
|
|
|
18
18
|
"./hooks/useClientValidation": "./dist/hooks/useClientValidation/index.mjs",
|
|
19
19
|
"./hooks/useController": "./dist/hooks/useController/index.mjs",
|
|
20
20
|
"./hooks/useFormContext": "./dist/hooks/useFormContext/index.mjs",
|
|
21
|
-
"./hooks/useInput": "./dist/hooks/useInput/index.mjs",
|
|
22
21
|
"./hooks/useInputValueDebounce": "./dist/hooks/useInputValueDebounce/index.mjs",
|
|
23
22
|
"./hooks/useInputValueTransform": "./dist/hooks/useInputValueTransform/index.mjs",
|
|
24
|
-
"./hooks/useUniformField": "./dist/hooks/useUniformField/index.mjs",
|
|
25
|
-
"./hooks/useUniformFieldArray": "./dist/hooks/useUniformFieldArray/index.mjs",
|
|
26
23
|
"./hooks/useWatchFormReset": "./dist/hooks/useWatchFormReset/index.mjs",
|
|
27
24
|
"./hooks/useWatchUserChange": "./dist/hooks/useWatchUserChange/index.mjs",
|
|
28
25
|
"./Input": "./dist/Input/index.mjs",
|
|
@@ -57,7 +54,8 @@
|
|
|
57
54
|
"scripts": {
|
|
58
55
|
"build": "tsdown",
|
|
59
56
|
"prepack": "pnpm build",
|
|
60
|
-
"test": "vitest ./src"
|
|
57
|
+
"test": "vitest ./src",
|
|
58
|
+
"test:types": "tsc --project tsconfig.build.json --noEmit && tsc --project test/typecheck/tsconfig.json"
|
|
61
59
|
},
|
|
62
60
|
"peerDependencies": {
|
|
63
61
|
"react": ">=18",
|
|
@@ -68,36 +66,26 @@
|
|
|
68
66
|
"@dnd-kit/modifiers": "9.0.0",
|
|
69
67
|
"@dnd-kit/sortable": "10.0.0",
|
|
70
68
|
"@dnd-kit/utilities": "3.2.2",
|
|
71
|
-
"@fuf-stack/pixel-motion": "
|
|
72
|
-
"@fuf-stack/pixel-utils": "
|
|
73
|
-
"@fuf-stack/pixels": "
|
|
74
|
-
"@fuf-stack/veto": "
|
|
75
|
-
"@heroui/button": "2.2.32",
|
|
76
|
-
"@heroui/checkbox": "2.3.32",
|
|
77
|
-
"@heroui/date-input": "2.3.32",
|
|
78
|
-
"@heroui/date-picker": "2.3.33",
|
|
79
|
-
"@heroui/input": "2.4.33",
|
|
80
|
-
"@heroui/number-input": "2.0.23",
|
|
81
|
-
"@heroui/radio": "2.3.32",
|
|
82
|
-
"@heroui/select": "2.4.33",
|
|
83
|
-
"@heroui/slider": "2.4.29",
|
|
84
|
-
"@heroui/switch": "2.2.27",
|
|
85
|
-
"@heroui/system": "2.4.28",
|
|
86
|
-
"@heroui/theme": "2.4.26",
|
|
69
|
+
"@fuf-stack/pixel-motion": "2.0.0-next.1",
|
|
70
|
+
"@fuf-stack/pixel-utils": "2.0.0-next.1",
|
|
71
|
+
"@fuf-stack/pixels": "2.0.0-next.1",
|
|
72
|
+
"@fuf-stack/veto": "2.0.0-next.1",
|
|
87
73
|
"@internationalized/date": "3.12.4",
|
|
88
|
-
"@react-aria/visually-hidden": "3.9.1",
|
|
89
74
|
"debug": "4.4.3",
|
|
90
|
-
"
|
|
75
|
+
"react-aria": "3.50.0",
|
|
76
|
+
"react-aria-components": "1.19.0",
|
|
91
77
|
"react-hook-form": "7.81.0",
|
|
92
78
|
"react-icons": "5.7.0",
|
|
93
|
-
"react-select": "5.10.2"
|
|
79
|
+
"react-select": "5.10.2",
|
|
80
|
+
"react-stately": "3.48.0",
|
|
81
|
+
"react-textarea-autosize": "8.5.9"
|
|
94
82
|
},
|
|
95
83
|
"devDependencies": {
|
|
96
84
|
"@types/debug": "4.1.13",
|
|
97
|
-
"@types/react": "19.
|
|
98
|
-
"@types/react-dom": "19.
|
|
99
|
-
"react": "19.
|
|
100
|
-
"react-dom": "19.
|
|
85
|
+
"@types/react": "19.3.0",
|
|
86
|
+
"@types/react-dom": "19.3.0",
|
|
87
|
+
"react": "19.3.0",
|
|
88
|
+
"react-dom": "19.3.0"
|
|
101
89
|
},
|
|
102
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "ec69356cdafe4e2399405b7e5e1b970022bbbbc6"
|
|
103
91
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FieldCopyTestIdButton-CRJBix9D.mjs","names":[],"sources":["../src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx","../src/partials/FieldCopyTestIdButton/index.ts"],"sourcesContent":["import { FaBullseye } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button } from '@fuf-stack/pixels';\n\nexport interface FieldCopyTestIdButtonProps {\n /** CSS class name */\n className?: string;\n /** HTML data-testid attribute used in e2e tests */\n testId: string;\n}\n\nconst FieldCopyTestIdButton = ({\n className = undefined,\n testId,\n}: FieldCopyTestIdButtonProps) => {\n const copyToClipboard = () => {\n // This component runs in the browser; the Node compatibility rule cannot\n // distinguish the DOM Clipboard API from Node's global navigator.\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n navigator.clipboard.writeText(testId).catch((err) => {\n console.error('Error copying TestId to clipboard', err);\n });\n };\n\n return (\n <Button\n className={cn(className, 'pointer-events-auto')}\n icon={<FaBullseye />}\n onClick={copyToClipboard}\n size=\"sm\"\n variant=\"light\"\n />\n );\n};\nexport default FieldCopyTestIdButton;\n","import FieldCopyTestIdButton from './FieldCopyTestIdButton';\n\nexport type { FieldCopyTestIdButtonProps } from './FieldCopyTestIdButton';\n\nexport default FieldCopyTestIdButton;\n"],"mappings":";;;;;AAYA,MAAM,yBAAyB,EAC7B,YAAY,KAAA,GACZ,aACgC;CAChC,MAAM,wBAAwB;EAI5B,UAAU,UAAU,UAAU,MAAM,CAAC,CAAC,OAAO,QAAQ;GACnD,QAAQ,MAAM,qCAAqC,GAAG;EACxD,CAAC;CACH;CAEA,OACE,oBAAC,QAAD;EACE,WAAW,GAAG,WAAW,qBAAqB;EAC9C,MAAM,oBAAC,YAAD,CAAa,CAAA;EACnB,SAAS;EACT,MAAK;EACL,SAAQ;CACT,CAAA;AAEL;;;AC9BA,IAAA,gCAAe"}
|