@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":[
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/SwitchBox/switchBoxVariants.ts","../../src/SwitchBox/SwitchBox.tsx"],"mappings":";;;qBAIa,qBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmElB,YAAY,mBAAmB;UC9D1B;;EAEf,YAAY;;EAEZ,cAAc;;EAEd;;EAEA,OAAO;;EAEP,QAAQ;;EAER;;EAEA;;EAEA;EAEA;;EAEA;;EAEA,YAAY;;;cAIR,cAAa,WAAA,aAAA,MAAA,MAAA,MAAA,cAAA,qBAQhB,mCAAc,IAAA"}
|
package/dist/SwitchBox/index.mjs
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
|
-
import { useUniformField } from "../
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { n as useUniformField, t as FieldLabel } from "../FieldLabel-DrNWJIVh.mjs";
|
|
2
|
+
import { n as getFieldControlProps, t as FieldDescription } from "../FieldDescription-X_0s1Lhu.mjs";
|
|
3
|
+
import { t as switchVariants } from "../switchVariants-D16b2VaT.mjs";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { tv } from "@fuf-stack/pixel-utils";
|
|
6
|
+
import { useStyling } from "@fuf-stack/pixels/StylingProvider";
|
|
7
|
+
import { useFocusRing } from "react-aria/useFocusRing";
|
|
8
|
+
import { useObjectRef } from "react-aria/useObjectRef";
|
|
9
|
+
import { useHover } from "react-aria/useHover";
|
|
10
|
+
import { mergeProps } from "react-aria/mergeProps";
|
|
11
|
+
import { useSwitch } from "react-aria/useSwitch";
|
|
12
|
+
import { VisuallyHidden } from "react-aria/VisuallyHidden";
|
|
13
|
+
import { useToggleState } from "react-stately/useToggleState";
|
|
14
|
+
// src/SwitchBox/switchBoxVariants.ts
|
|
8
15
|
const switchBoxVariants = tv({
|
|
9
16
|
slots: {
|
|
10
|
-
|
|
17
|
+
/** Selectable box containing the toggle and text */
|
|
18
|
+
box: ["group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default", "hover:bg-content2 data-[selected=true]:border-focus"],
|
|
19
|
+
/** Supporting text for the field */
|
|
11
20
|
description: "text-foreground opacity-70",
|
|
21
|
+
/** Container for validation messages */
|
|
22
|
+
errorMessage: "text-danger text-tiny",
|
|
23
|
+
/** Container below the switch for validation messages */
|
|
24
|
+
helperWrapper: "relative ml-0 block p-0",
|
|
25
|
+
/** Decorative icon beside the option text */
|
|
12
26
|
icon: "",
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
/** Visible field label */
|
|
28
|
+
label: "font-medium text-foreground",
|
|
29
|
+
/** Movable indicator showing the current value */
|
|
15
30
|
thumb: "",
|
|
16
|
-
|
|
31
|
+
/** Content inside the toggle thumb */
|
|
32
|
+
thumbIcon: "",
|
|
33
|
+
/** Container arranging the selectable content */
|
|
34
|
+
wrapper: ""
|
|
17
35
|
},
|
|
18
36
|
variants: {
|
|
19
37
|
disabled: { true: { box: "pointer-events-none opacity-disabled" } },
|
|
@@ -21,94 +39,116 @@ const switchBoxVariants = tv({
|
|
|
21
39
|
box: "!border-danger",
|
|
22
40
|
label: "!text-danger"
|
|
23
41
|
} },
|
|
24
|
-
readOnly: { true: { box: "
|
|
42
|
+
readOnly: { true: { box: "cursor-not-allowed opacity-disabled **:cursor-not-allowed hover:bg-transparent" } },
|
|
25
43
|
size: {
|
|
26
|
-
|
|
27
|
-
box: "gap-
|
|
28
|
-
description: "text-
|
|
29
|
-
label: "text-
|
|
44
|
+
lg: {
|
|
45
|
+
box: "gap-4 p-5",
|
|
46
|
+
description: "text-small",
|
|
47
|
+
label: "text-base"
|
|
30
48
|
},
|
|
31
49
|
md: {
|
|
32
50
|
box: "gap-4 p-4",
|
|
33
51
|
description: "text-small",
|
|
34
52
|
label: "text-sm"
|
|
35
53
|
},
|
|
36
|
-
|
|
37
|
-
box: "gap-
|
|
38
|
-
description: "text-
|
|
39
|
-
label: "text-
|
|
54
|
+
sm: {
|
|
55
|
+
box: "gap-2 p-3",
|
|
56
|
+
description: "text-xs",
|
|
57
|
+
label: "text-xs"
|
|
40
58
|
}
|
|
41
59
|
}
|
|
42
60
|
},
|
|
43
61
|
defaultVariants: { size: "md" }
|
|
44
62
|
});
|
|
63
|
+
// src/SwitchBox/subcomponents/SwitchBoxTrack.tsx
|
|
64
|
+
/** Visual toggle track and thumb, including the selection-aware icon callback */
|
|
65
|
+
const SwitchBoxTrack = ({ className: trackClassNames, selected, thumbIcon }) => {
|
|
66
|
+
return /* @__PURE__ */ jsx("span", {
|
|
67
|
+
"aria-hidden": true,
|
|
68
|
+
className: trackClassNames.wrapper,
|
|
69
|
+
"data-slot": "wrapper",
|
|
70
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
71
|
+
className: trackClassNames.thumb,
|
|
72
|
+
"data-slot": "thumb",
|
|
73
|
+
children: typeof thumbIcon === "function" ? thumbIcon({
|
|
74
|
+
isSelected: selected,
|
|
75
|
+
className: trackClassNames.thumbIcon,
|
|
76
|
+
width: "1em",
|
|
77
|
+
height: "1em",
|
|
78
|
+
"data-checked": String(selected)
|
|
79
|
+
}) : thumbIcon
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
// src/SwitchBox/subcomponents/SwitchBoxControl.tsx
|
|
45
84
|
/**
|
|
46
|
-
*
|
|
85
|
+
* Selectable switch box with label, description and validation messages
|
|
86
|
+
*
|
|
87
|
+
* @see https://react-aria.adobe.com/useSwitch
|
|
47
88
|
*/
|
|
48
|
-
const
|
|
49
|
-
const {
|
|
50
|
-
|
|
51
|
-
|
|
89
|
+
const SwitchBoxControl = ({ field, className, size, thumbIcon, icon }) => {
|
|
90
|
+
const { description, disabled, errorMessage, ids, ref: inputRef, invalid, label, name, onBlur, onChange: onValueChange, readOnly, required, testId, value } = field;
|
|
91
|
+
const controlProps = getFieldControlProps(field);
|
|
92
|
+
const styling = useStyling();
|
|
93
|
+
const controlRef = useObjectRef(inputRef);
|
|
94
|
+
const state = useToggleState({
|
|
95
|
+
isReadOnly: readOnly,
|
|
96
|
+
isSelected: !!value,
|
|
97
|
+
onChange: onValueChange
|
|
52
98
|
});
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
99
|
+
const { inputProps, labelProps, isPressed } = useSwitch({
|
|
100
|
+
...controlProps,
|
|
101
|
+
children: label,
|
|
56
102
|
isDisabled: disabled,
|
|
103
|
+
isInvalid: invalid,
|
|
57
104
|
isReadOnly: readOnly,
|
|
58
|
-
|
|
59
|
-
name
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
const
|
|
105
|
+
isRequired: required,
|
|
106
|
+
name,
|
|
107
|
+
onBlur,
|
|
108
|
+
validationBehavior: "aria"
|
|
109
|
+
}, state, controlRef);
|
|
110
|
+
const { focusProps, isFocused, isFocusVisible } = useFocusRing();
|
|
111
|
+
const { hoverProps, isHovered } = useHover({ isDisabled: disabled });
|
|
112
|
+
const variants = styling.resolve(switchBoxVariants, {
|
|
65
113
|
disabled,
|
|
66
114
|
invalid,
|
|
67
115
|
readOnly,
|
|
68
116
|
size
|
|
69
117
|
});
|
|
70
|
-
const classNames = variantsToClassNames(variants, className, "box");
|
|
71
|
-
|
|
72
|
-
|
|
118
|
+
const classNames = styling.variantsToClassNames(variants, className, "box");
|
|
119
|
+
const trackVariants = styling.resolve(switchVariants, { size });
|
|
120
|
+
const trackClassNames = styling.variantsToClassNames(trackVariants, {
|
|
121
|
+
wrapper: classNames.wrapper,
|
|
122
|
+
thumb: classNames.thumb,
|
|
123
|
+
thumbIcon: classNames.thumbIcon
|
|
124
|
+
});
|
|
125
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("label", {
|
|
126
|
+
...mergeProps(labelProps, hoverProps),
|
|
73
127
|
className: classNames.box,
|
|
128
|
+
"data-component": "switch-box",
|
|
129
|
+
"data-focus": isFocused || void 0,
|
|
130
|
+
"data-focus-visible": isFocusVisible || void 0,
|
|
131
|
+
"data-hover": isHovered || void 0,
|
|
74
132
|
"data-invalid": invalid,
|
|
133
|
+
"data-pressed": isPressed || void 0,
|
|
134
|
+
"data-readonly": readOnly || void 0,
|
|
75
135
|
"data-required": required,
|
|
136
|
+
"data-selected": state.isSelected || void 0,
|
|
76
137
|
"data-testid": testId,
|
|
138
|
+
htmlFor: ids.control,
|
|
77
139
|
children: [
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (!readOnly) onChange(e.target.checked);
|
|
85
|
-
},
|
|
86
|
-
onFocus: () => {
|
|
87
|
-
visualSwitchRef.current?.focus();
|
|
88
|
-
},
|
|
89
|
-
tabIndex: -1,
|
|
90
|
-
type: "checkbox"
|
|
91
|
-
}), /* @__PURE__ */ jsx("input", {
|
|
92
|
-
ref: visualSwitchRef,
|
|
93
|
-
...getInputProps(),
|
|
94
|
-
onBlur: (e) => {
|
|
95
|
-
getInputProps().onBlur?.(e);
|
|
96
|
-
onBlur();
|
|
97
|
-
}
|
|
98
|
-
})] }),
|
|
99
|
-
!icon ? /* @__PURE__ */ jsx("span", {
|
|
100
|
-
...getWrapperProps(),
|
|
101
|
-
className: cn(getWrapperProps().className, classNames.wrapper),
|
|
102
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
103
|
-
className: cn(slots.thumb({ class: classNames.thumb })),
|
|
104
|
-
children: thumbIcon && typeof thumbIcon === "function" ? thumbIcon({
|
|
105
|
-
isSelected: !!isSelected,
|
|
106
|
-
className: slots.thumbIcon({ class: classNames.thumbIcon }),
|
|
107
|
-
width: "1em",
|
|
108
|
-
height: "1em",
|
|
109
|
-
"data-checked": isSelected ? "true" : "false"
|
|
110
|
-
}) : thumbIcon
|
|
140
|
+
/* @__PURE__ */ jsx(VisuallyHidden, {
|
|
141
|
+
elementType: "span",
|
|
142
|
+
children: /* @__PURE__ */ jsx("input", {
|
|
143
|
+
...mergeProps(inputProps, focusProps, controlProps),
|
|
144
|
+
ref: controlRef,
|
|
145
|
+
"data-slot": "input"
|
|
111
146
|
})
|
|
147
|
+
}),
|
|
148
|
+
!icon ? /* @__PURE__ */ jsx(SwitchBoxTrack, {
|
|
149
|
+
className: trackClassNames,
|
|
150
|
+
selected: state.isSelected,
|
|
151
|
+
thumbIcon
|
|
112
152
|
}) : null,
|
|
113
153
|
icon ? /* @__PURE__ */ jsx("div", {
|
|
114
154
|
className: classNames.icon,
|
|
@@ -116,38 +156,52 @@ const SwitchBox = ({ className = void 0, description = void 0, icon = void 0, na
|
|
|
116
156
|
}) : null,
|
|
117
157
|
/* @__PURE__ */ jsxs("div", {
|
|
118
158
|
className: "grow",
|
|
119
|
-
children: [label ? /* @__PURE__ */ jsx(
|
|
159
|
+
children: [label ? /* @__PURE__ */ jsx(FieldLabel, {
|
|
160
|
+
as: "div",
|
|
120
161
|
className: classNames.label,
|
|
162
|
+
id: ids.label,
|
|
163
|
+
required,
|
|
121
164
|
children: label
|
|
122
|
-
}) : null, description ? /* @__PURE__ */ jsx(
|
|
165
|
+
}) : null, description ? /* @__PURE__ */ jsx(FieldDescription, {
|
|
123
166
|
className: classNames.description,
|
|
167
|
+
"data-slot": void 0,
|
|
168
|
+
id: ids.description,
|
|
124
169
|
children: description
|
|
125
170
|
}) : null]
|
|
126
171
|
}),
|
|
127
|
-
icon ? /* @__PURE__ */ jsx(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
className: cn(slots.thumb({ class: classNames.thumb })),
|
|
132
|
-
children: thumbIcon && typeof thumbIcon === "function" ? thumbIcon({
|
|
133
|
-
isSelected: !!isSelected,
|
|
134
|
-
className: slots.thumbIcon({ class: classNames.thumbIcon }),
|
|
135
|
-
width: "1em",
|
|
136
|
-
height: "1em",
|
|
137
|
-
"data-checked": isSelected ? "true" : "false"
|
|
138
|
-
}) : thumbIcon
|
|
139
|
-
})
|
|
172
|
+
icon ? /* @__PURE__ */ jsx(SwitchBoxTrack, {
|
|
173
|
+
className: trackClassNames,
|
|
174
|
+
selected: state.isSelected,
|
|
175
|
+
thumbIcon
|
|
140
176
|
}) : null
|
|
141
177
|
]
|
|
142
178
|
}), invalid ? /* @__PURE__ */ jsx("div", {
|
|
143
|
-
|
|
144
|
-
|
|
179
|
+
className: classNames.helperWrapper,
|
|
180
|
+
"data-slot": "helper-wrapper",
|
|
145
181
|
children: /* @__PURE__ */ jsx("div", {
|
|
146
|
-
|
|
182
|
+
className: classNames.errorMessage,
|
|
183
|
+
"data-slot": "error-message",
|
|
184
|
+
id: ids.error,
|
|
147
185
|
children: errorMessage
|
|
148
186
|
})
|
|
149
187
|
}) : null] });
|
|
150
188
|
};
|
|
189
|
+
// src/SwitchBox/SwitchBox.tsx
|
|
190
|
+
/** Form toggle field with a switch inside a selectable card */
|
|
191
|
+
const SwitchBox = ({ className = void 0, description = void 0, icon = void 0, name, size = void 0, thumbIcon = void 0, ...uniformFieldProps }) => {
|
|
192
|
+
const { field } = useUniformField({
|
|
193
|
+
...uniformFieldProps,
|
|
194
|
+
description,
|
|
195
|
+
name
|
|
196
|
+
});
|
|
197
|
+
return /* @__PURE__ */ jsx(SwitchBoxControl, {
|
|
198
|
+
className,
|
|
199
|
+
field,
|
|
200
|
+
icon,
|
|
201
|
+
size,
|
|
202
|
+
thumbIcon
|
|
203
|
+
});
|
|
204
|
+
};
|
|
151
205
|
// src/SwitchBox/index.ts
|
|
152
206
|
var SwitchBox_default = SwitchBox;
|
|
153
207
|
export { SwitchBox_default as default, switchBoxVariants };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/SwitchBox/SwitchBox.tsx","../../src/SwitchBox/index.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\nimport type { SwitchProps as HeroSwitchProps } from '@heroui/switch';\nimport type { ReactNode } from 'react';\n\nimport { useRef } from 'react';\n\nimport { useSwitch } from '@heroui/switch';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\n\nimport { cn, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../hooks/useUniformField';\n\nexport const switchBoxVariants = tv({\n slots: {\n box: 'group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default hover:bg-content2 data-[selected=true]:border-focus',\n description: 'text-foreground opacity-70',\n icon: '',\n label:\n 'font-medium text-foreground group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n wrapper: '',\n thumb: '',\n thumbIcon: '',\n },\n variants: {\n disabled: {\n true: {\n box: 'pointer-events-none opacity-disabled',\n },\n },\n invalid: {\n true: {\n box: '!border-danger',\n label: '!text-danger',\n },\n },\n readOnly: {\n true: {\n // Inner controls set their own cursors, so override every descendant.\n box: '**:cursor-not-allowed cursor-not-allowed opacity-disabled hover:bg-transparent',\n },\n },\n size: {\n sm: {\n box: 'gap-2 p-3',\n description: 'text-xs',\n label: 'text-xs',\n },\n md: {\n box: 'gap-4 p-4',\n description: 'text-small',\n label: 'text-sm',\n },\n lg: {\n box: 'gap-4 p-5',\n description: 'text-small',\n label: 'text-base',\n },\n },\n },\n defaultVariants: {\n size: 'md',\n },\n});\n\ntype ClassName = TVClassName<typeof switchBoxVariants>;\n\nexport interface SwitchBoxProps {\n /** CSS class name */\n className?: ClassName;\n /** Description text displayed below the label */\n description?: ReactNode;\n /** whether the switch should be disabled */\n disabled?: boolean;\n /** Icon to be displayed in the box */\n icon?: ReactNode;\n /** component displayed as the label */\n label?: ReactNode;\n /** name the field is registered under */\n name: string;\n /** Prevents changes while keeping the switch focusable and its value in validation and submission */\n readOnly?: boolean;\n /** whether the field is required */\n required?: boolean;\n /* Size of the switch */\n size?: 'sm' | 'md' | 'lg';\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** Icon to be displayed inside the thumb */\n thumbIcon?: HeroSwitchProps['thumbIcon'];\n}\n\n/**\n * SwitchBox component - A card-like box with a switch control\n */\nconst SwitchBox = ({\n className = undefined,\n description = undefined,\n icon = undefined,\n name,\n size = undefined,\n thumbIcon = undefined,\n ...uniformFieldProps\n}: SwitchBoxProps) => {\n const {\n defaultValue,\n disabled,\n errorMessage,\n field,\n getErrorMessageProps,\n getHelperWrapperProps,\n invalid,\n label,\n onBlur,\n onChange,\n readOnly,\n ref,\n required,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Ref for the visual switch to forward focus\n const visualSwitchRef = useRef<HTMLInputElement>(null);\n\n // Use the useSwitch hook to get access to all the necessary props\n const {\n Component,\n slots,\n isSelected,\n getBaseProps,\n getInputProps,\n getWrapperProps,\n } = useSwitch({\n defaultSelected: !!defaultValue,\n isDisabled: disabled,\n isReadOnly: readOnly,\n isSelected: !!field.value,\n name: `${name}_switch`,\n onValueChange: onChange,\n size,\n thumbIcon,\n });\n\n // classNames from slots\n const variants = switchBoxVariants({\n disabled,\n invalid,\n readOnly,\n size,\n });\n const classNames = variantsToClassNames(variants, className, 'box');\n\n return (\n <>\n <Component\n {...getBaseProps()}\n className={classNames.box}\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n >\n <VisuallyHidden>\n <input\n ref={ref}\n aria-label={typeof label === 'string' ? label : name}\n checked={!!field.value}\n name={name}\n onChange={(e) => {\n if (!readOnly) {\n onChange(e.target.checked);\n }\n }}\n onFocus={() => {\n // When RHF focuses this hidden input (e.g., on validation error),\n // forward focus to the visual switch to show focus ring\n visualSwitchRef.current?.focus();\n }}\n tabIndex={-1}\n type=\"checkbox\"\n />\n {/* Visual switch input for focus ring */}\n <input\n ref={visualSwitchRef}\n {...getInputProps()}\n onBlur={(e) => {\n // Call HeroUI's internal onBlur to clear focus state and remove focus ring\n getInputProps().onBlur?.(e);\n // Then call RHF's onBlur to mark field as touched\n onBlur();\n }}\n />\n </VisuallyHidden>\n {!icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n <div className=\"grow\">\n {label ? <div className={classNames.label}>{label}</div> : null}\n {description ? (\n <div className={classNames.description}>{description}</div>\n ) : null}\n </div>\n {icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n </Component>\n {invalid ? (\n <div\n {...getHelperWrapperProps()}\n className={cn(\n getHelperWrapperProps()?.className,\n // force helper to be visible (for some reason it's hidden by default) and remove margin\n 'ml-0 block',\n )}\n >\n <div {...getErrorMessageProps()}>{errorMessage}</div>\n </div>\n ) : null}\n </>\n );\n};\n\nexport default SwitchBox;\n","import SwitchBox from './SwitchBox';\n\nexport type { SwitchBoxProps } from './SwitchBox';\n\nexport { switchBoxVariants } from './SwitchBox';\n\nexport default SwitchBox;\n"],"mappings":";;;;;;;AAaA,MAAa,oBAAoB,GAAG;CAClC,OAAO;EACL,KAAK;EACL,aAAa;EACb,MAAM;EACN,OACE;EACF,SAAS;EACT,OAAO;EACP,WAAW;CACb;CACA,UAAU;EACR,UAAU,EACR,MAAM,EACJ,KAAK,uCACP,EACF;EACA,SAAS,EACP,MAAM;GACJ,KAAK;GACL,OAAO;EACT,EACF;EACA,UAAU,EACR,MAAM,EAEJ,KAAK,iFACP,EACF;EACA,MAAM;GACJ,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;EACF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IACH,IACJ,EAAA,CAAA;AAEN;;ACvPA,IAAA,oBAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/SwitchBox/switchBoxVariants.ts","../../src/SwitchBox/subcomponents/SwitchBoxTrack.tsx","../../src/SwitchBox/subcomponents/SwitchBoxControl.tsx","../../src/SwitchBox/SwitchBox.tsx","../../src/SwitchBox/index.ts"],"sourcesContent":["import type { TVClassName } from '@fuf-stack/pixel-utils';\n\nimport { tv } from '@fuf-stack/pixel-utils';\n\nexport const switchBoxVariants = tv({\n slots: {\n /** Selectable box containing the toggle and text */\n box: [\n // box layout and surface\n 'group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default',\n // hover and selection feedback\n 'hover:bg-content2 data-[selected=true]:border-focus',\n ],\n /** Supporting text for the field */\n description: 'text-foreground opacity-70',\n /** Container for validation messages */\n errorMessage: 'text-danger text-tiny',\n /** Container below the switch for validation messages */\n helperWrapper: 'relative ml-0 block p-0',\n /** Decorative icon beside the option text */\n icon: '',\n /** Visible field label */\n label: 'font-medium text-foreground',\n /** Movable indicator showing the current value */\n thumb: '',\n /** Content inside the toggle thumb */\n thumbIcon: '',\n /** Container arranging the selectable content */\n wrapper: '',\n },\n variants: {\n disabled: {\n true: {\n box: 'pointer-events-none opacity-disabled',\n },\n },\n invalid: {\n true: {\n box: '!border-danger',\n label: '!text-danger',\n },\n },\n readOnly: {\n true: {\n // inner controls set their own cursors, override every descendant\n box: 'cursor-not-allowed opacity-disabled **:cursor-not-allowed hover:bg-transparent',\n },\n },\n size: {\n lg: {\n box: 'gap-4 p-5',\n description: 'text-small',\n label: 'text-base',\n },\n md: {\n box: 'gap-4 p-4',\n description: 'text-small',\n label: 'text-sm',\n },\n sm: {\n box: 'gap-2 p-3',\n description: 'text-xs',\n label: 'text-xs',\n },\n },\n },\n defaultVariants: {\n size: 'md',\n },\n});\n\nexport type ClassName = TVClassName<typeof switchBoxVariants>;\n","import type { SwitchBoxProps } from '../SwitchBox';\n\ninterface SwitchBoxTrackProps extends Pick<SwitchBoxProps, 'thumbIcon'> {\n /** CSS class name */\n className: Record<'thumb' | 'thumbIcon' | 'wrapper', string>;\n /** Current toggle state supplied to the icon callback */\n selected: boolean;\n}\n\n/** Visual toggle track and thumb, including the selection-aware icon callback */\nconst SwitchBoxTrack = ({\n className: trackClassNames,\n selected,\n thumbIcon,\n}: SwitchBoxTrackProps) => {\n return (\n <span aria-hidden className={trackClassNames.wrapper} data-slot=\"wrapper\">\n <span className={trackClassNames.thumb} data-slot=\"thumb\">\n {typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: selected,\n className: trackClassNames.thumbIcon,\n width: '1em',\n height: '1em',\n 'data-checked': String(selected),\n })\n : thumbIcon}\n </span>\n </span>\n );\n};\n\nexport default SwitchBoxTrack;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { SwitchBoxProps } from '../SwitchBox';\n\nimport { mergeProps } from 'react-aria/mergeProps';\nimport { useFocusRing } from 'react-aria/useFocusRing';\nimport { useHover } from 'react-aria/useHover';\nimport { useObjectRef } from 'react-aria/useObjectRef';\nimport { useSwitch } from 'react-aria/useSwitch';\nimport { VisuallyHidden } from 'react-aria/VisuallyHidden';\nimport { useToggleState } from 'react-stately/useToggleState';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport { getFieldControlProps } from '../../helpers/fieldProps/fieldProps';\nimport FieldDescription from '../../partials/FieldDescription/FieldDescription';\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { switchVariants } from '../../Switch/switchVariants';\nimport { switchBoxVariants } from '../switchBoxVariants';\nimport SwitchBoxTrack from './SwitchBoxTrack';\n\ninterface SwitchBoxControlProps extends Pick<\n SwitchBoxProps,\n 'className' | 'icon' | 'size' | 'thumbIcon'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, boolean>;\n}\n\n/**\n * Selectable switch box with label, description and validation messages\n *\n * @see https://react-aria.adobe.com/useSwitch\n */\nconst SwitchBoxControl = ({\n field,\n className,\n size,\n thumbIcon,\n icon,\n}: SwitchBoxControlProps) => {\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 const controlRef = useObjectRef<HTMLInputElement>(inputRef);\n const state = useToggleState({\n isReadOnly: readOnly,\n isSelected: !!value,\n onChange: onValueChange,\n });\n const { inputProps, labelProps, isPressed } = useSwitch(\n {\n ...controlProps,\n children: label,\n isDisabled: disabled,\n isInvalid: invalid,\n isReadOnly: readOnly,\n isRequired: required,\n name,\n onBlur,\n validationBehavior: 'aria',\n },\n state,\n controlRef,\n );\n const { focusProps, isFocused, isFocusVisible } = useFocusRing();\n const { hoverProps, isHovered } = useHover({ isDisabled: disabled });\n\n // classNames from slots\n const variants = styling.resolve(switchBoxVariants, {\n disabled,\n invalid,\n readOnly,\n size,\n });\n const classNames = styling.variantsToClassNames(variants, className, 'box');\n\n const trackVariants = styling.resolve(switchVariants, { size });\n const trackClassNames = styling.variantsToClassNames(trackVariants, {\n wrapper: classNames.wrapper,\n thumb: classNames.thumb,\n thumbIcon: classNames.thumbIcon,\n });\n\n return (\n <>\n <label\n {...mergeProps(labelProps, hoverProps)}\n className={classNames.box}\n data-component=\"switch-box\"\n data-focus={isFocused || undefined}\n data-focus-visible={isFocusVisible || undefined}\n data-hover={isHovered || undefined}\n data-invalid={invalid}\n data-pressed={isPressed || undefined}\n data-readonly={readOnly || undefined}\n data-required={required}\n data-selected={state.isSelected || undefined}\n data-testid={testId}\n htmlFor={ids.control}\n >\n {/* native toggle for keyboard and assistive technology */}\n <VisuallyHidden elementType=\"span\">\n <input\n {...mergeProps(inputProps, focusProps, controlProps)}\n ref={controlRef}\n data-slot=\"input\"\n />\n </VisuallyHidden>\n {!icon ? (\n <SwitchBoxTrack\n className={trackClassNames}\n selected={state.isSelected}\n thumbIcon={thumbIcon}\n />\n ) : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n\n {/* label and supporting text */}\n <div className=\"grow\">\n {label ? (\n <FieldLabel\n as=\"div\"\n className={classNames.label}\n id={ids.label}\n required={required}\n >\n {label}\n </FieldLabel>\n ) : null}\n {description ? (\n <FieldDescription\n className={classNames.description}\n data-slot={undefined}\n id={ids.description}\n >\n {description}\n </FieldDescription>\n ) : null}\n </div>\n {icon ? (\n <SwitchBoxTrack\n className={trackClassNames}\n selected={state.isSelected}\n thumbIcon={thumbIcon}\n />\n ) : null}\n </label>\n\n {/* validation messages below the box */}\n {invalid ? (\n <div className={classNames.helperWrapper} data-slot=\"helper-wrapper\">\n <div\n className={classNames.errorMessage}\n data-slot=\"error-message\"\n id={ids.error}\n >\n {errorMessage}\n </div>\n </div>\n ) : null}\n </>\n );\n};\n\nexport default SwitchBoxControl;\n","import type { ReactNode } from 'react';\nimport type { SwitchProps } from '../Switch/Switch';\nimport type { ClassName } from './switchBoxVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport SwitchBoxControl from './subcomponents/SwitchBoxControl';\n\nexport { switchBoxVariants } from './switchBoxVariants';\n\nexport interface SwitchBoxProps {\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 /** Icon to be displayed in the box */\n icon?: ReactNode;\n /** Field label */\n label?: ReactNode;\n /** Field name */\n name: string;\n /** Prevents toggling while keeping the value in validation and submission */\n readOnly?: boolean;\n /** whether the field is required */\n required?: boolean;\n /* Size of the switch */\n size?: 'sm' | 'md' | 'lg';\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n /** Content or render callback inside the toggle thumb */\n thumbIcon?: SwitchProps['thumbIcon'];\n}\n\n/** Form toggle field with a switch inside a selectable card */\nconst SwitchBox = ({\n className = undefined,\n description = undefined,\n icon = undefined,\n name,\n size = undefined,\n thumbIcon = undefined,\n ...uniformFieldProps\n}: SwitchBoxProps) => {\n const { field } = useUniformField({\n ...uniformFieldProps,\n description,\n name,\n });\n\n return (\n <SwitchBoxControl\n className={className}\n field={field}\n icon={icon}\n size={size}\n thumbIcon={thumbIcon}\n />\n );\n};\n\nexport default SwitchBox;\n","import SwitchBox from './SwitchBox';\n\nexport type { SwitchBoxProps } from './SwitchBox';\n\nexport { switchBoxVariants } from './SwitchBox';\n\nexport default SwitchBox;\n"],"mappings":";;;;;;;;;;;;;;AAIA,MAAa,oBAAoB,GAAG;CAClC,OAAO;;EAEL,KAAK,CAEH,2GAEA,qDACF;;EAEA,aAAa;;EAEb,cAAc;;EAEd,eAAe;;EAEf,MAAM;;EAEN,OAAO;;EAEP,OAAO;;EAEP,WAAW;;EAEX,SAAS;CACX;CACA,UAAU;EACR,UAAU,EACR,MAAM,EACJ,KAAK,uCACP,EACF;EACA,SAAS,EACP,MAAM;GACJ,KAAK;GACL,OAAO;EACT,EACF;EACA,UAAU,EACR,MAAM,EAEJ,KAAK,iFACP,EACF;EACA,MAAM;GACJ,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;GACA,IAAI;IACF,KAAK;IACL,aAAa;IACb,OAAO;GACT;EACF;CACF;CACA,iBAAiB,EACf,MAAM,KACR;AACF,CAAC;;;AC3DD,MAAM,kBAAkB,EACtB,WAAW,iBACX,UACA,gBACyB;CACzB,OACE,oBAAC,QAAD;EAAM,eAAA;EAAY,WAAW,gBAAgB;EAAS,aAAU;EAC9D,UAAA,oBAAC,QAAD;GAAM,WAAW,gBAAgB;GAAO,aAAU;GAC/C,UAAA,OAAO,cAAc,aAClB,UAAU;IACR,YAAY;IACZ,WAAW,gBAAgB;IAC3B,OAAO;IACP,QAAQ;IACR,gBAAgB,OAAO,QAAQ;GACjC,CAAC,IACD;EACA,CAAA;CACF,CAAA;AAEV;;;;;;;ACGA,MAAM,oBAAoB,EACx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