@m4l/components 9.3.17-JT25092025.beta.1 → 9.3.18
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/components/Stepper/Stepper.js +14 -7
- package/components/Stepper/Stepper.styles.js +14 -17
- package/components/Stepper/helpers/index.d.ts +0 -2
- package/components/Stepper/hooks/useStepperActions/index.js +3 -19
- package/components/Stepper/store/StepperStore/index.js +1 -20
- package/components/Stepper/subcomponents/ContentArea/index.js +14 -7
- package/components/Stepper/subcomponents/ContentArea/subcomponents/WrapperIcon/index.js +1 -1
- package/components/Stepper/subcomponents/StepArea/index.js +26 -41
- package/components/Stepper/subcomponents/StepArea/subcomponents/Inidicator/index.js +10 -18
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperCancelButton/index.js +6 -38
- package/components/Stepper/subcomponents/StepperButtons/StepperNextButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperNextButton/index.js +3 -5
- package/components/Stepper/subcomponents/StepperButtons/StepperPrevButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperPrevButton/index.js +3 -5
- package/components/Stepper/subcomponents/StepperButtons/StepperSubmitButton/index.d.ts +1 -2
- package/components/Stepper/subcomponents/StepperButtons/StepperSubmitButton/index.js +3 -5
- package/components/Stepper/subcomponents/StepperContent/subcomponents/Step/index.js +11 -30
- package/components/Stepper/subcomponents/StepperFooter/index.js +1 -1
- package/components/Stepper/subcomponents/StepperFooter/subcomponents/StepperFooterRightActions/index.js +10 -20
- package/components/Stepper/tests/Stepper.helpers.test.d.ts +1 -0
- package/components/Stepper/tests/Stepper.hooks.test.d.ts +1 -0
- package/components/Stepper/tests/Stepper.navigation.test.d.ts +1 -0
- package/components/Stepper/tests/Stepper.rendering.test.d.ts +1 -0
- package/components/Stepper/tests/Stepper.subcomponents.test.d.ts +1 -0
- package/components/Stepper/tests/Stepper.test.d.ts +1 -0
- package/components/Stepper/tests/constants.d.ts +3 -0
- package/components/Stepper/types.d.ts +0 -7
- package/components/hook-form/RHFormContext/index.d.ts +1 -1
- package/components/hook-form/RHFormContext/index.js +4 -29
- package/package.json +1 -1
- package/components/Stepper/helpers/getInitialFieldValues/index.d.ts +0 -12
- package/components/Stepper/helpers/getInitialFieldValues/index.js +0 -14
- package/components/Stepper/helpers/parseWatchedValues/index.d.ts +0 -17
- package/components/Stepper/helpers/parseWatchedValues/index.js +0 -12
- package/components/Stepper/hooks/useDynamicValidation/index.d.ts +0 -11
- package/components/Stepper/hooks/useDynamicValidation/index.js +0 -69
|
@@ -57,13 +57,20 @@ function Stepper(props) {
|
|
|
57
57
|
if (!hasPresentFlags) {
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
|
-
return /* @__PURE__ */ jsx(StepperProvider, { ...props, children: /* @__PURE__ */ jsxs(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
return /* @__PURE__ */ jsx(StepperProvider, { ...props, children: /* @__PURE__ */ jsxs(
|
|
61
|
+
StepperRootStyled,
|
|
62
|
+
{
|
|
63
|
+
className: clsx(classRoot, className),
|
|
64
|
+
"data-testid": "stepper-root",
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsxs(ContentSectionStyled, { ownerState, children: [
|
|
67
|
+
/* @__PURE__ */ jsx(StepArea, {}),
|
|
68
|
+
/* @__PURE__ */ jsx(ContentArea, { children: stepperContent })
|
|
69
|
+
] }),
|
|
70
|
+
stepperFooter
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
) });
|
|
67
74
|
}
|
|
68
75
|
export {
|
|
69
76
|
Stepper as S
|
|
@@ -24,13 +24,8 @@ const stepperStyles = {
|
|
|
24
24
|
flexDirection: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "column" : "row",
|
|
25
25
|
gap: theme.vars.size.baseSpacings.sp8
|
|
26
26
|
}),
|
|
27
|
-
/**
|
|
28
|
-
* Estilos para el contenido del paso dentro del Stepper.
|
|
29
|
-
*/
|
|
30
27
|
stepContent: ({ ownerState }) => ({
|
|
31
|
-
|
|
32
|
-
display: ownerState?.isStepVisible ? "flex" : "none",
|
|
33
|
-
flexDirection: "column"
|
|
28
|
+
display: ownerState?.isStepVisible ? "block" : "none"
|
|
34
29
|
}),
|
|
35
30
|
/**
|
|
36
31
|
* Estilos para la sección que contiene los botones de acción del Stepper.
|
|
@@ -76,7 +71,8 @@ const stepperStyles = {
|
|
|
76
71
|
const isLastStep = step === totalSteps - 1;
|
|
77
72
|
return {
|
|
78
73
|
cursor: "pointer",
|
|
79
|
-
display:
|
|
74
|
+
display: "flex",
|
|
75
|
+
visibility: ownerState?.isStepVisible ? "visible" : "hidden",
|
|
80
76
|
flexDirection: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "column" : "row",
|
|
81
77
|
alignItems: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "center" : "start",
|
|
82
78
|
justifyContent: ownerState?.visibleTitle ? "space-between" : "center",
|
|
@@ -130,7 +126,7 @@ const stepperStyles = {
|
|
|
130
126
|
whiteSpace: "normal",
|
|
131
127
|
order: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? 1 : 0,
|
|
132
128
|
"&.M4LTypography-root": {
|
|
133
|
-
color: ownerState?.
|
|
129
|
+
color: (ownerState?.currentStep ?? 0) > (ownerState?.step ?? 0) ? theme.vars.palette.primary.semanticText : (ownerState?.currentStep ?? 0) === (ownerState?.step ?? 0) ? theme.vars.palette.text.primary : theme.vars.palette.text.secondary,
|
|
134
130
|
textAlign: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? "center" : "right"
|
|
135
131
|
}
|
|
136
132
|
}),
|
|
@@ -138,12 +134,13 @@ const stepperStyles = {
|
|
|
138
134
|
* Estilos para el indicador numérico de cada paso del Stepper.
|
|
139
135
|
*/
|
|
140
136
|
indicator: ({ theme, ownerState }) => {
|
|
137
|
+
const currentStep = ownerState?.currentStep ?? 0;
|
|
141
138
|
const step = ownerState?.step ?? 0;
|
|
142
139
|
const totalSteps = ownerState?.totalSteps ?? 0;
|
|
143
|
-
const isCompleted =
|
|
144
|
-
const isCurrent =
|
|
145
|
-
const isValidStep = ownerState?.isValidStep ?? true;
|
|
140
|
+
const isCompleted = currentStep > step;
|
|
141
|
+
const isCurrent = currentStep === step;
|
|
146
142
|
const isLastStep = step === totalSteps - 1;
|
|
143
|
+
const isValidStep = ownerState?.stepValidationStatus?.[step] ?? true;
|
|
147
144
|
return {
|
|
148
145
|
...ownerState?.orientation === "horizontal" ? {
|
|
149
146
|
marginTop: theme.generalSettings.isMobile ? "6px" : theme.vars.size.baseSpacings.sp1
|
|
@@ -153,7 +150,7 @@ const stepperStyles = {
|
|
|
153
150
|
justifyContent: "center",
|
|
154
151
|
flexShrink: 0,
|
|
155
152
|
order: ownerState?.orientation === "vertical" || theme.generalSettings.isMobile ? 0 : 1,
|
|
156
|
-
background:
|
|
153
|
+
background: isCompleted ? ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : theme.vars.palette.primary.toneOpacity : !isValidStep ? theme.vars.palette.error.enabled : ownerState?.indicatorType === "dot" || theme.generalSettings.isMobile ? theme.vars.palette.background.default : isCurrent ? theme.vars.palette.primary.enabled : theme.vars.palette.default.enabled,
|
|
157
154
|
borderRadius: theme.vars.size.borderRadius.r2,
|
|
158
155
|
...ownerState?.indicatorType === "number" && !theme.generalSettings.isMobile && {
|
|
159
156
|
boxShadow: isCurrent ? "0 2px 8px 0 rgb(0, 100, 255, 0.16)" : "none"
|
|
@@ -181,13 +178,13 @@ const stepperStyles = {
|
|
|
181
178
|
* Estilos para el número de texto dentro del indicador numérico del Stepper.
|
|
182
179
|
*/
|
|
183
180
|
textNumber: ({ theme, ownerState }) => {
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const
|
|
181
|
+
const currentStep = ownerState?.currentStep ?? 0;
|
|
182
|
+
const step = ownerState?.step ?? 0;
|
|
183
|
+
const isCompleted = currentStep > step;
|
|
184
|
+
const isCurrent = currentStep === step;
|
|
188
185
|
return {
|
|
189
186
|
"&.M4LTypography-root": {
|
|
190
|
-
color:
|
|
187
|
+
color: isCompleted || isCurrent ? theme.vars.palette.primary.contrastText : theme.vars.palette.text.primary
|
|
191
188
|
}
|
|
192
189
|
};
|
|
193
190
|
},
|
|
@@ -2,5 +2,3 @@ export { evaluateVisibilityStepCondition } from './evaluateVisibilityStepConditi
|
|
|
2
2
|
export { findNextVisibleValidStep } from './findNextVisibleValidStep';
|
|
3
3
|
export { findPrevVisibleValidStep } from './findPrevVisibleValidStep';
|
|
4
4
|
export { isLastVisibleValidStep } from './isLastVisibleValidStep';
|
|
5
|
-
export { parseWatchedValues } from './parseWatchedValues';
|
|
6
|
-
export { getInitialFieldValues } from './getInitialFieldValues';
|
|
@@ -2,10 +2,8 @@ import { useCallback } from "react";
|
|
|
2
2
|
import { u as useStepper } from "../useStepper/index.js";
|
|
3
3
|
import { useFormContext } from "react-hook-form";
|
|
4
4
|
import { shallow } from "zustand/shallow";
|
|
5
|
-
import { u as useDynamicValidation } from "../useDynamicValidation/index.js";
|
|
6
5
|
function useStepperActions() {
|
|
7
6
|
const { trigger, clearErrors, getValues, reset } = useFormContext();
|
|
8
|
-
const { activateFieldsValidation, clearAllValidation } = useDynamicValidation();
|
|
9
7
|
const {
|
|
10
8
|
nextStep,
|
|
11
9
|
prevStep,
|
|
@@ -43,20 +41,9 @@ function useStepperActions() {
|
|
|
43
41
|
if (fieldsToValidate.length === 0) {
|
|
44
42
|
return true;
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
if (!result) {
|
|
48
|
-
activateFieldsValidation(fieldsToValidate);
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
44
|
+
return await trigger(fieldsToValidate);
|
|
51
45
|
};
|
|
52
46
|
const success = await nextStep(validateFn, formData);
|
|
53
|
-
if (success) {
|
|
54
|
-
const currentStepData = steps[currentStep - 1];
|
|
55
|
-
const fieldsJustValidated = currentStepData?.validationFields || [];
|
|
56
|
-
if (fieldsJustValidated.length > 0) {
|
|
57
|
-
clearAllValidation();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
47
|
if (success && futureFields.length > 0) {
|
|
61
48
|
clearErrors(futureFields);
|
|
62
49
|
setTimeout(() => {
|
|
@@ -75,16 +62,13 @@ function useStepperActions() {
|
|
|
75
62
|
steps,
|
|
76
63
|
currentStep,
|
|
77
64
|
trigger,
|
|
78
|
-
getValues
|
|
79
|
-
activateFieldsValidation,
|
|
80
|
-
clearAllValidation
|
|
65
|
+
getValues
|
|
81
66
|
]);
|
|
82
67
|
const cancelAction = useCallback(() => {
|
|
83
68
|
reset();
|
|
84
69
|
clearErrors();
|
|
85
|
-
clearAllValidation();
|
|
86
70
|
resetStepper();
|
|
87
|
-
}, [reset, clearErrors,
|
|
71
|
+
}, [reset, clearErrors, resetStepper]);
|
|
88
72
|
return { prevStepAction, nextStepAction, cancelAction };
|
|
89
73
|
}
|
|
90
74
|
export {
|
|
@@ -35,18 +35,6 @@ const createStepperStore = (initProps, storeDevtoolsEnabled = false) => {
|
|
|
35
35
|
if (!preserveStepValidationStatus) {
|
|
36
36
|
state.stepValidationStatus = {};
|
|
37
37
|
}
|
|
38
|
-
if (!preserveStepValidationStatus) {
|
|
39
|
-
const firstVisibleStepIndex = findNextVisibleValidStep(
|
|
40
|
-
-1,
|
|
41
|
-
// Comenzar desde -1 para encontrar el primer step visible
|
|
42
|
-
steps,
|
|
43
|
-
{},
|
|
44
|
-
state.visibilityData
|
|
45
|
-
);
|
|
46
|
-
if (firstVisibleStepIndex !== 0 && firstVisibleStepIndex < steps.length) {
|
|
47
|
-
state.currentStep = firstVisibleStepIndex;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
38
|
});
|
|
51
39
|
},
|
|
52
40
|
/**
|
|
@@ -126,16 +114,9 @@ const createStepperStore = (initProps, storeDevtoolsEnabled = false) => {
|
|
|
126
114
|
*/
|
|
127
115
|
resetStepper: () => {
|
|
128
116
|
set((state) => {
|
|
117
|
+
state.currentStep = 0;
|
|
129
118
|
state.stepValidationStatus = {};
|
|
130
119
|
state.isValidating = false;
|
|
131
|
-
const firstVisibleStepIndex = findNextVisibleValidStep(
|
|
132
|
-
-1,
|
|
133
|
-
// Comenzar desde -1 para encontrar el primer step visible
|
|
134
|
-
state.steps,
|
|
135
|
-
{},
|
|
136
|
-
state.visibilityData
|
|
137
|
-
);
|
|
138
|
-
state.currentStep = firstVisibleStepIndex < state.steps.length ? firstVisibleStepIndex : 0;
|
|
139
120
|
});
|
|
140
121
|
}
|
|
141
122
|
}
|
|
@@ -11,13 +11,20 @@ function ContentArea(props) {
|
|
|
11
11
|
const ownerState = {
|
|
12
12
|
orientation
|
|
13
13
|
};
|
|
14
|
-
return /* @__PURE__ */ jsxs(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
return /* @__PURE__ */ jsxs(
|
|
15
|
+
ContentAreaStyled,
|
|
16
|
+
{
|
|
17
|
+
ownerState,
|
|
18
|
+
"data-testid": "stepper-content-area",
|
|
19
|
+
children: [
|
|
20
|
+
/* @__PURE__ */ jsxs(ContentAreaHeaderStyled, { "data-testid": "stepper-content-area-header", children: [
|
|
21
|
+
/* @__PURE__ */ jsx(WrapperIcon, {}),
|
|
22
|
+
/* @__PURE__ */ jsx(WrapperTitle, {})
|
|
23
|
+
] }),
|
|
24
|
+
/* @__PURE__ */ jsx(ContentAreaBodyStyled, { "data-testid": "stepper-content-area-body", children })
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
);
|
|
21
28
|
}
|
|
22
29
|
export {
|
|
23
30
|
ContentArea as C
|
|
@@ -17,7 +17,7 @@ function WrapperIcon() {
|
|
|
17
17
|
IconStyled,
|
|
18
18
|
{
|
|
19
19
|
color: "primary.enabled",
|
|
20
|
-
src: currentStepConfig
|
|
20
|
+
src: currentStepConfig?.icon ? currentStepConfig.icon : `${host_static_assets}/${environment_assets}/${pathIcons.patronum}`
|
|
21
21
|
}
|
|
22
22
|
) });
|
|
23
23
|
}
|
|
@@ -5,12 +5,10 @@ import { u as useStepper } from "../../hooks/useStepper/index.js";
|
|
|
5
5
|
import { e as StepAreaStyled, f as StepStyled, g as StepNameStyled } from "../../slots/StepperSlot.js";
|
|
6
6
|
import { I as Indicator } from "./subcomponents/Inidicator/index.js";
|
|
7
7
|
import { shallow } from "zustand/shallow";
|
|
8
|
-
import { u as useDynamicValidation } from "../../hooks/useDynamicValidation/index.js";
|
|
9
8
|
import { e as evaluateVisibilityStepCondition } from "../../helpers/evaluateVisibilityStepCondition/index.js";
|
|
10
9
|
function StepArea() {
|
|
11
10
|
const { trigger, clearErrors } = useFormContext();
|
|
12
11
|
const formValues = useWatch();
|
|
13
|
-
const { activateFieldsValidation, startExternalValidation, endExternalValidation } = useDynamicValidation();
|
|
14
12
|
const {
|
|
15
13
|
currentStep,
|
|
16
14
|
steps,
|
|
@@ -34,19 +32,16 @@ function StepArea() {
|
|
|
34
32
|
}),
|
|
35
33
|
shallow
|
|
36
34
|
);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(step) => evaluateVisibilityStepCondition(step, formValues || {}, visibilityData)
|
|
41
|
-
);
|
|
42
|
-
}, [steps, formValues, visibilityData]);
|
|
35
|
+
const validSteps = useMemo(() => {
|
|
36
|
+
return steps;
|
|
37
|
+
}, [steps]);
|
|
43
38
|
const ownerState = {
|
|
44
39
|
visibleTitle,
|
|
45
40
|
orientation,
|
|
46
|
-
totalSteps:
|
|
41
|
+
totalSteps: validSteps.length
|
|
47
42
|
};
|
|
48
43
|
const handleStepClick = async (targetIndex) => {
|
|
49
|
-
const currentIndex =
|
|
44
|
+
const currentIndex = validSteps.findIndex(
|
|
50
45
|
(step) => step.key === steps[currentStep].key
|
|
51
46
|
);
|
|
52
47
|
if (targetIndex === currentIndex) {
|
|
@@ -54,7 +49,7 @@ function StepArea() {
|
|
|
54
49
|
}
|
|
55
50
|
const isNavigatingForward = targetIndex > currentIndex;
|
|
56
51
|
const targetOriginalIndex = steps.findIndex(
|
|
57
|
-
(s) => s.key ===
|
|
52
|
+
(s) => s.key === validSteps[targetIndex].key
|
|
58
53
|
);
|
|
59
54
|
if (!isNavigatingForward) {
|
|
60
55
|
setCurrentStep(targetOriginalIndex);
|
|
@@ -63,43 +58,37 @@ function StepArea() {
|
|
|
63
58
|
const isSkippingSteps = targetIndex > currentIndex + 1;
|
|
64
59
|
if (isSkippingSteps) {
|
|
65
60
|
for (let i = currentIndex; i < targetIndex; i++) {
|
|
66
|
-
const step =
|
|
61
|
+
const step = validSteps[i];
|
|
67
62
|
const stepOriginalIndex = steps.findIndex((s) => s.key === step.key);
|
|
68
|
-
startExternalValidation();
|
|
69
63
|
const isValid = await trigger(step.validationFields);
|
|
70
|
-
endExternalValidation();
|
|
71
64
|
if (!isValid) {
|
|
72
65
|
setCurrentStep(stepOriginalIndex);
|
|
73
66
|
setStepValidationStatus(stepOriginalIndex, false);
|
|
74
|
-
activateFieldsValidation(step.validationFields || []);
|
|
75
67
|
return;
|
|
76
68
|
}
|
|
77
69
|
setStepValidationStatus(stepOriginalIndex, true);
|
|
78
70
|
}
|
|
79
71
|
} else {
|
|
80
|
-
const currentStepData =
|
|
72
|
+
const currentStepData = validSteps[currentIndex];
|
|
81
73
|
const currentStepOriginalIndex = steps.findIndex(
|
|
82
74
|
(s) => s.key === currentStepData.key
|
|
83
75
|
);
|
|
84
|
-
startExternalValidation();
|
|
85
76
|
const isCurrentValid = await trigger(currentStepData.validationFields);
|
|
86
|
-
endExternalValidation();
|
|
87
77
|
if (!isCurrentValid) {
|
|
88
78
|
setStepValidationStatus(currentStepOriginalIndex, false);
|
|
89
|
-
activateFieldsValidation(currentStepData.validationFields || []);
|
|
90
79
|
return;
|
|
91
80
|
}
|
|
92
81
|
setStepValidationStatus(currentStepOriginalIndex, true);
|
|
93
82
|
}
|
|
94
83
|
setCurrentStep(targetOriginalIndex);
|
|
95
84
|
if (isNavigatingForward) {
|
|
96
|
-
const currentStepData =
|
|
85
|
+
const currentStepData = validSteps[currentIndex];
|
|
97
86
|
const currentStepOriginalIndex = steps.findIndex(
|
|
98
87
|
(s) => s.key === currentStepData.key
|
|
99
88
|
);
|
|
100
89
|
const isCurrentStepValid = stepValidationStatus[currentStepOriginalIndex] !== false;
|
|
101
90
|
if (isCurrentStepValid) {
|
|
102
|
-
const targetStep =
|
|
91
|
+
const targetStep = validSteps[targetIndex];
|
|
103
92
|
const targetStepFields = targetStep.validationFields || [];
|
|
104
93
|
if (targetStepFields.length > 0) {
|
|
105
94
|
clearErrors(targetStepFields);
|
|
@@ -111,37 +100,33 @@ function StepArea() {
|
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
102
|
};
|
|
114
|
-
return /* @__PURE__ */ jsx(StepAreaStyled, { ownerState, children:
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
formValues || {},
|
|
118
|
-
|
|
119
|
-
);
|
|
120
|
-
const visibleStepIndex = isStepVisible ? visibleSteps.findIndex((visStep) => visStep.key === step.key) : -1;
|
|
103
|
+
return /* @__PURE__ */ jsx(StepAreaStyled, { ownerState, "data-testid": "stepper-step-area", children: validSteps.map((step, validIndex) => {
|
|
104
|
+
const originalIndex = steps.findIndex((s) => s.key === step.key);
|
|
105
|
+
const totalVisibleSteps = validSteps.filter(
|
|
106
|
+
(s) => evaluateVisibilityStepCondition(s, formValues || {}, visibilityData)
|
|
107
|
+
).length;
|
|
121
108
|
return /* @__PURE__ */ jsxs(
|
|
122
109
|
StepStyled,
|
|
123
110
|
{
|
|
124
111
|
role: "button",
|
|
125
|
-
onClick: () =>
|
|
112
|
+
onClick: () => handleStepClick(validIndex),
|
|
126
113
|
ownerState: {
|
|
127
114
|
...ownerState,
|
|
128
115
|
currentStep,
|
|
129
|
-
step:
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
step: validIndex,
|
|
117
|
+
isStepVisible: evaluateVisibilityStepCondition(
|
|
118
|
+
step,
|
|
119
|
+
formValues || {},
|
|
120
|
+
visibilityData
|
|
121
|
+
)
|
|
132
122
|
},
|
|
123
|
+
"data-testid": `stepper-step-${step.key}`,
|
|
133
124
|
children: [
|
|
134
125
|
visibleTitle && /* @__PURE__ */ jsx(
|
|
135
126
|
StepNameStyled,
|
|
136
127
|
{
|
|
137
128
|
variant: "body",
|
|
138
|
-
ownerState: {
|
|
139
|
-
...ownerState,
|
|
140
|
-
currentStep,
|
|
141
|
-
step: visibleStepIndex,
|
|
142
|
-
originalStepIndex: originalIndex,
|
|
143
|
-
isStepVisible
|
|
144
|
-
},
|
|
129
|
+
ownerState: { ...ownerState, currentStep, step: validIndex },
|
|
145
130
|
children: step.title
|
|
146
131
|
}
|
|
147
132
|
),
|
|
@@ -149,8 +134,8 @@ function StepArea() {
|
|
|
149
134
|
Indicator,
|
|
150
135
|
{
|
|
151
136
|
currentStep,
|
|
152
|
-
step:
|
|
153
|
-
totalSteps:
|
|
137
|
+
step: validIndex,
|
|
138
|
+
totalSteps: totalVisibleSteps,
|
|
154
139
|
originalStepIndex: originalIndex
|
|
155
140
|
}
|
|
156
141
|
)
|
|
@@ -21,6 +21,15 @@ function Indicator(props) {
|
|
|
21
21
|
);
|
|
22
22
|
const { host_static_assets, environment_assets } = useEnvironment();
|
|
23
23
|
const { currentSize } = useComponentSize(size);
|
|
24
|
+
const ownerState = {
|
|
25
|
+
size: currentSize,
|
|
26
|
+
currentStep,
|
|
27
|
+
step,
|
|
28
|
+
totalSteps,
|
|
29
|
+
orientation,
|
|
30
|
+
indicatorType,
|
|
31
|
+
stepValidationStatus
|
|
32
|
+
};
|
|
24
33
|
const isMobile = useIsMobile();
|
|
25
34
|
const effectiveIndicatorType = useMemo(() => {
|
|
26
35
|
return isMobile ? "dot" : indicatorType;
|
|
@@ -36,20 +45,6 @@ function Indicator(props) {
|
|
|
36
45
|
hasBeenValidated: validated
|
|
37
46
|
};
|
|
38
47
|
}, [currentStep, originalStepIndex, stepValidationStatus]);
|
|
39
|
-
const ownerState = {
|
|
40
|
-
size: currentSize,
|
|
41
|
-
currentStep,
|
|
42
|
-
step,
|
|
43
|
-
totalSteps,
|
|
44
|
-
orientation,
|
|
45
|
-
indicatorType,
|
|
46
|
-
stepValidationStatus,
|
|
47
|
-
originalStepIndex,
|
|
48
|
-
isCompleted,
|
|
49
|
-
isCurrent: currentStep === originalStepIndex,
|
|
50
|
-
isValidStep,
|
|
51
|
-
hasBeenValidated
|
|
52
|
-
};
|
|
53
48
|
return /* @__PURE__ */ jsx(IndicatorStyled, { ownerState, children: hasBeenValidated && !isValidStep ? (
|
|
54
49
|
// Mostrar error solo si ha sido validado y es inválido
|
|
55
50
|
/* @__PURE__ */ jsx(
|
|
@@ -72,10 +67,7 @@ function Indicator(props) {
|
|
|
72
67
|
)
|
|
73
68
|
) : (
|
|
74
69
|
// Mostrar estado normal (número o dot) para pasos no validados o actuales
|
|
75
|
-
/* @__PURE__ */ jsx(TextNumberStyled, { variant: "body", ownerState, children: effectiveIndicatorType === "number" ? (
|
|
76
|
-
// Solo mostrar número si el step es visible (step >= 0)
|
|
77
|
-
step >= 0 ? step + 1 : ""
|
|
78
|
-
) : /* @__PURE__ */ jsx(
|
|
70
|
+
/* @__PURE__ */ jsx(TextNumberStyled, { variant: "body", ownerState: { currentStep, step }, children: effectiveIndicatorType === "number" ? step + 1 : /* @__PURE__ */ jsx(
|
|
79
71
|
Icon,
|
|
80
72
|
{
|
|
81
73
|
src: `${host_static_assets}/${environment_assets}/${currentStep === originalStepIndex ? pathIcons.dotSelected : pathIcons.dotOutline}`,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { StepperButtonProps } from '../../../types';
|
|
2
1
|
/**
|
|
3
2
|
* Botón modular para cancelar el proceso del Stepper
|
|
4
3
|
*/
|
|
5
|
-
export declare function StepperCancelButton(
|
|
4
|
+
export declare function StepperCancelButton(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,55 +1,23 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback } from "react";
|
|
3
|
-
import { useFormContext, useFormState } from "react-hook-form";
|
|
4
2
|
import { u as useStepperActions } from "../../../hooks/useStepperActions/index.js";
|
|
5
|
-
import { D as DICTIONARY
|
|
6
|
-
import { D as DICTIONARY } from "../../../../CommonActions/dictionary.js";
|
|
3
|
+
import { D as DICTIONARY } from "../../../dictionary.js";
|
|
7
4
|
import { useModuleDictionary } from "@m4l/core";
|
|
8
|
-
import { u as useModal } from "../../../../../hooks/useModal/index.js";
|
|
9
|
-
import { u as useWindowToolsMF } from "../../../../WindowBase/hooks/useWindowToolsMF/index.js";
|
|
10
|
-
import { W as WindowConfirm } from "../../../../WindowConfirm/WindowConfirm.js";
|
|
11
5
|
import { B as Button } from "../../../../mui_extended/Button/Button.js";
|
|
12
|
-
function StepperCancelButton(
|
|
13
|
-
const { label, ...rest } = props;
|
|
6
|
+
function StepperCancelButton() {
|
|
14
7
|
const { getLabel } = useModuleDictionary();
|
|
15
8
|
const { cancelAction } = useStepperActions();
|
|
16
|
-
const
|
|
17
|
-
const { close: closeWindow } = useWindowToolsMF();
|
|
18
|
-
const { control } = useFormContext();
|
|
19
|
-
const { isDirty } = useFormState({
|
|
20
|
-
control
|
|
21
|
-
});
|
|
22
|
-
const onConfirmQuit = useCallback(() => {
|
|
9
|
+
const handleCancel = () => {
|
|
23
10
|
cancelAction();
|
|
24
|
-
|
|
25
|
-
}, [cancelAction, closeWindow]);
|
|
26
|
-
const handleCancel = useCallback(() => {
|
|
27
|
-
if (isDirty) {
|
|
28
|
-
openModal({
|
|
29
|
-
window: /* @__PURE__ */ jsx(
|
|
30
|
-
WindowConfirm,
|
|
31
|
-
{
|
|
32
|
-
variant: "warning",
|
|
33
|
-
title: getLabel(DICTIONARY.CONFIRM_QUIT_TITLE),
|
|
34
|
-
msg: getLabel(DICTIONARY.CONFIRM_QUIT_MSG),
|
|
35
|
-
onClickIntro: onConfirmQuit
|
|
36
|
-
}
|
|
37
|
-
),
|
|
38
|
-
variant: "warning"
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
onConfirmQuit();
|
|
42
|
-
}
|
|
43
|
-
}, [getLabel, isDirty, openModal, onConfirmQuit]);
|
|
11
|
+
};
|
|
44
12
|
return /* @__PURE__ */ jsx(
|
|
45
13
|
Button,
|
|
46
14
|
{
|
|
47
15
|
type: "button",
|
|
48
|
-
label:
|
|
16
|
+
label: getLabel(DICTIONARY.LABEL_CANCEL_BUTTON),
|
|
49
17
|
variant: "outlined",
|
|
50
18
|
color: "default",
|
|
51
19
|
onClick: handleCancel,
|
|
52
|
-
|
|
20
|
+
"data-testid": "stepper-cancel-button"
|
|
53
21
|
}
|
|
54
22
|
);
|
|
55
23
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { StepperButtonProps } from '../../../types';
|
|
2
1
|
/**
|
|
3
2
|
* Botón modular para avanzar al siguiente step del Stepper
|
|
4
3
|
*/
|
|
5
|
-
export declare function StepperNextButton(
|
|
4
|
+
export declare function StepperNextButton(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -6,8 +6,7 @@ import { D as DICTIONARY } from "../../../dictionary.js";
|
|
|
6
6
|
import { useModuleDictionary, useEnvironment } from "@m4l/core";
|
|
7
7
|
import { I as IconButton } from "../../../../mui_extended/IconButton/IconButton.js";
|
|
8
8
|
import { B as Button } from "../../../../mui_extended/Button/Button.js";
|
|
9
|
-
function StepperNextButton(
|
|
10
|
-
const { label, ...rest } = props;
|
|
9
|
+
function StepperNextButton() {
|
|
11
10
|
const { nextStepAction } = useStepperActions();
|
|
12
11
|
const isMobile = useIsMobile();
|
|
13
12
|
const { getLabel } = useModuleDictionary();
|
|
@@ -29,13 +28,12 @@ function StepperNextButton(props) {
|
|
|
29
28
|
Button,
|
|
30
29
|
{
|
|
31
30
|
type: "button",
|
|
32
|
-
label:
|
|
31
|
+
label: getLabel(DICTIONARY.LABEL_NEXT_BUTTON),
|
|
33
32
|
variant: "contained",
|
|
34
33
|
color: "primary",
|
|
35
34
|
onClick: handleNext,
|
|
36
35
|
endIcon: `${host_static_assets}/${environment_assets}/${pathIcons.arrowRight}`,
|
|
37
|
-
"data-testid": "stepper-next-button"
|
|
38
|
-
...rest
|
|
36
|
+
"data-testid": "stepper-next-button"
|
|
39
37
|
}
|
|
40
38
|
);
|
|
41
39
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { StepperButtonProps } from '../../../types';
|
|
2
1
|
/**
|
|
3
2
|
* Botón modular para ir al step anterior del Stepper
|
|
4
3
|
*/
|
|
5
|
-
export declare function StepperPrevButton(
|
|
4
|
+
export declare function StepperPrevButton(): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -7,8 +7,7 @@ import { useIsMobile } from "@m4l/graphics";
|
|
|
7
7
|
import { D as DICTIONARY } from "../../../dictionary.js";
|
|
8
8
|
import { I as IconButton } from "../../../../mui_extended/IconButton/IconButton.js";
|
|
9
9
|
import { B as Button } from "../../../../mui_extended/Button/Button.js";
|
|
10
|
-
function StepperPrevButton(
|
|
11
|
-
const { label, ...rest } = props;
|
|
10
|
+
function StepperPrevButton() {
|
|
12
11
|
const { currentStep } = useStepper((state) => ({
|
|
13
12
|
currentStep: state.currentStep
|
|
14
13
|
}));
|
|
@@ -36,13 +35,12 @@ function StepperPrevButton(props) {
|
|
|
36
35
|
Button,
|
|
37
36
|
{
|
|
38
37
|
type: "button",
|
|
39
|
-
label:
|
|
38
|
+
label: !isMobile ? getLabel(DICTIONARY.LABEL_PREV_BUTTON) : "",
|
|
40
39
|
variant: "outlined",
|
|
41
40
|
color: "default",
|
|
42
41
|
onClick: handlePrev,
|
|
43
42
|
startIcon: `${host_static_assets}/${environment_assets}/${pathIcons.arrowLeft}`,
|
|
44
|
-
"data-testid": "stepper-prev-button"
|
|
45
|
-
...rest
|
|
43
|
+
"data-testid": "stepper-prev-button"
|
|
46
44
|
}
|
|
47
45
|
);
|
|
48
46
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { StepperButtonProps } from '../../../types';
|
|
2
1
|
/**
|
|
3
2
|
* Botón modular para finalizar el Stepper y ejecutar onFinalSubmit
|
|
4
3
|
*/
|
|
5
|
-
export declare function StepperSubmitButton(
|
|
4
|
+
export declare function StepperSubmitButton(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,18 +2,16 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { D as DICTIONARY } from "../../../dictionary.js";
|
|
3
3
|
import { useModuleDictionary } from "@m4l/core";
|
|
4
4
|
import { B as Button } from "../../../../mui_extended/Button/Button.js";
|
|
5
|
-
function StepperSubmitButton(
|
|
6
|
-
const { label, ...rest } = props;
|
|
5
|
+
function StepperSubmitButton() {
|
|
7
6
|
const { getLabel } = useModuleDictionary();
|
|
8
7
|
return /* @__PURE__ */ jsx(
|
|
9
8
|
Button,
|
|
10
9
|
{
|
|
11
10
|
type: "submit",
|
|
12
|
-
label:
|
|
11
|
+
label: getLabel(DICTIONARY.LABEL_SUBMIT_BUTTON),
|
|
13
12
|
variant: "contained",
|
|
14
13
|
color: "primary",
|
|
15
|
-
"data-testid": "stepper-submit-button"
|
|
16
|
-
...rest
|
|
14
|
+
"data-testid": "stepper-submit-button"
|
|
17
15
|
}
|
|
18
16
|
);
|
|
19
17
|
}
|
|
@@ -12,47 +12,28 @@ function Step(props) {
|
|
|
12
12
|
steps: state.steps,
|
|
13
13
|
visibilityData: state.visibilityData
|
|
14
14
|
}));
|
|
15
|
+
const currentStepConfig = useMemo(() => {
|
|
16
|
+
return steps[currentStep];
|
|
17
|
+
}, [steps, currentStep]);
|
|
15
18
|
const stepConfig = useMemo(() => {
|
|
16
19
|
return steps.find((step) => step.key === stepKey);
|
|
17
20
|
}, [steps, stepKey]);
|
|
18
21
|
const isStepVisible = useMemo(() => {
|
|
19
|
-
if (!
|
|
22
|
+
if (!currentStepConfig) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (stepKey !== currentStepConfig.key) {
|
|
20
26
|
return false;
|
|
21
27
|
}
|
|
22
|
-
|
|
28
|
+
if (stepConfig && !evaluateVisibilityStepCondition(
|
|
23
29
|
stepConfig,
|
|
24
30
|
formValues || {},
|
|
25
31
|
visibilityData
|
|
26
|
-
)
|
|
27
|
-
if (!meetsVisibilityCondition) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
const currentStepConfig = steps[currentStep];
|
|
31
|
-
if (!currentStepConfig) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (evaluateVisibilityStepCondition(currentStepConfig, formValues || {}, visibilityData)) {
|
|
35
|
-
return stepKey === currentStepConfig.key;
|
|
36
|
-
}
|
|
37
|
-
const visibleStepsUpToCurrent = [];
|
|
38
|
-
for (let i = 0; i <= currentStep; i++) {
|
|
39
|
-
const step = steps[i];
|
|
40
|
-
if (evaluateVisibilityStepCondition(step, formValues || {}, visibilityData)) {
|
|
41
|
-
visibleStepsUpToCurrent.push(step);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (visibleStepsUpToCurrent.length === 0) {
|
|
45
|
-
for (let i = currentStep + 1; i < steps.length; i++) {
|
|
46
|
-
const step = steps[i];
|
|
47
|
-
if (evaluateVisibilityStepCondition(step, formValues || {}, visibilityData)) {
|
|
48
|
-
return stepKey === step.key;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
32
|
+
)) {
|
|
51
33
|
return false;
|
|
52
34
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}, [currentStep, stepKey, stepConfig, steps, formValues, visibilityData]);
|
|
35
|
+
return true;
|
|
36
|
+
}, [currentStepConfig, stepKey, stepConfig, formValues, visibilityData]);
|
|
56
37
|
return /* @__PURE__ */ jsx(StepContentStyled, { ownerState: { isStepVisible }, children });
|
|
57
38
|
}
|
|
58
39
|
export {
|
|
@@ -38,7 +38,7 @@ function StepperFooter(props) {
|
|
|
38
38
|
stepperFooterRightActions: parsedRightActions
|
|
39
39
|
};
|
|
40
40
|
}, [children]);
|
|
41
|
-
return /* @__PURE__ */ jsxs(StepperFooterSectionStyled, { children: [
|
|
41
|
+
return /* @__PURE__ */ jsxs(StepperFooterSectionStyled, { "data-testid": "stepper-footer", children: [
|
|
42
42
|
stepperFooterLeftActions,
|
|
43
43
|
stepperFooterRightActions
|
|
44
44
|
] });
|
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
3
|
import { u as useIsLastVisibleValidStep } from "../../../../hooks/useIsLastVisibleValidStep/index.js";
|
|
4
4
|
import { m as StepperFooterRightActionsStyled } from "../../../../slots/StepperSlot.js";
|
|
5
|
-
import { S as StepperSubmitButton } from "../../../StepperButtons/StepperSubmitButton/index.js";
|
|
6
5
|
import { S as StepperNextButton } from "../../../StepperButtons/StepperNextButton/index.js";
|
|
6
|
+
import { S as StepperSubmitButton } from "../../../StepperButtons/StepperSubmitButton/index.js";
|
|
7
7
|
function StepperFooterRightActions(props) {
|
|
8
8
|
const { children } = props;
|
|
9
9
|
const isLastVisibleValidStep = useIsLastVisibleValidStep();
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return child.type === StepperSubmitButton;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
});
|
|
18
|
-
setHasCustomSubmitButton(hasCustomButton);
|
|
19
|
-
}, [children]);
|
|
20
|
-
const filteredChildren = useMemo(() => {
|
|
10
|
+
const childrenWithoutNextButton = useMemo(() => {
|
|
11
|
+
if (!isLastVisibleValidStep) {
|
|
12
|
+
return children;
|
|
13
|
+
}
|
|
21
14
|
return React.Children.toArray(children).filter((child) => {
|
|
22
15
|
if (React.isValidElement(child)) {
|
|
23
|
-
if (
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (isLastVisibleValidStep && child.type === StepperNextButton) {
|
|
16
|
+
if (child.type === StepperNextButton) {
|
|
27
17
|
return false;
|
|
28
18
|
}
|
|
29
19
|
}
|
|
@@ -31,10 +21,10 @@ function StepperFooterRightActions(props) {
|
|
|
31
21
|
});
|
|
32
22
|
}, [children, isLastVisibleValidStep]);
|
|
33
23
|
const submitButton = useMemo(() => {
|
|
34
|
-
return isLastVisibleValidStep
|
|
35
|
-
}, [isLastVisibleValidStep
|
|
24
|
+
return isLastVisibleValidStep ? /* @__PURE__ */ jsx(StepperSubmitButton, {}) : null;
|
|
25
|
+
}, [isLastVisibleValidStep]);
|
|
36
26
|
return /* @__PURE__ */ jsxs(StepperFooterRightActionsStyled, { children: [
|
|
37
|
-
|
|
27
|
+
childrenWithoutNextButton,
|
|
38
28
|
submitButton
|
|
39
29
|
] });
|
|
40
30
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,7 +5,6 @@ import { ContentAreaSlots, ContentSlots, StepperFooterSlots, StepperSlots } from
|
|
|
5
5
|
import { STEPPER_PREFIX_NAME } from './constants';
|
|
6
6
|
import { M4LOverridesStyleRules } from '../../@types/augmentations';
|
|
7
7
|
import { Step as StepComponent } from './subcomponents/StepperContent/subcomponents/Step';
|
|
8
|
-
import { ButtonProps } from '../mui_extended/Button';
|
|
9
8
|
export type Orientation = 'horizontal' | 'vertical';
|
|
10
9
|
export type IndicatorType = 'number' | 'dot';
|
|
11
10
|
export type FormData = Record<string, string | number | boolean | null | undefined>;
|
|
@@ -146,12 +145,6 @@ export interface StepperFooterProps {
|
|
|
146
145
|
export interface StepperFooterLeftActionsProps {
|
|
147
146
|
children?: ReactNode;
|
|
148
147
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Props para los botones del Stepper que extienden las props de Button de mui_extended
|
|
151
|
-
*/
|
|
152
|
-
export interface StepperButtonProps extends Omit<ButtonProps, 'label'> {
|
|
153
|
-
label?: string;
|
|
154
|
-
}
|
|
155
148
|
/**
|
|
156
149
|
* Props del StepperFooterRightActions
|
|
157
150
|
*/
|
|
@@ -3,7 +3,7 @@ import { CustomFormArguments, FormProviderCustomProps, FormProviderProps } from
|
|
|
3
3
|
/**
|
|
4
4
|
* TODO: Documentar
|
|
5
5
|
*/
|
|
6
|
-
export declare function useCustomForm({ validationSchema, values, statusLoad, mode
|
|
6
|
+
export declare function useCustomForm({ validationSchema, values, statusLoad, mode }: CustomFormArguments): import('react-hook-form').UseFormReturn<FieldValues, any, FieldValues>;
|
|
7
7
|
/**
|
|
8
8
|
* TODO: Documentar
|
|
9
9
|
*/
|
|
@@ -6,12 +6,7 @@ import { yupResolver } from "@hookform/resolvers/yup";
|
|
|
6
6
|
import { F as FormProviderRoot } from "./styles.js";
|
|
7
7
|
import { R as RHFormProviderUtilityClasses } from "./classes/index.js";
|
|
8
8
|
const classes = RHFormProviderUtilityClasses();
|
|
9
|
-
function useCustomForm({
|
|
10
|
-
validationSchema,
|
|
11
|
-
values,
|
|
12
|
-
statusLoad,
|
|
13
|
-
mode
|
|
14
|
-
}) {
|
|
9
|
+
function useCustomForm({ validationSchema, values, statusLoad, mode }) {
|
|
15
10
|
const formMethods = useForm({
|
|
16
11
|
resolver: yupResolver(validationSchema),
|
|
17
12
|
defaultValues: values,
|
|
@@ -44,31 +39,11 @@ function useCustomForm({
|
|
|
44
39
|
}
|
|
45
40
|
function FormProviderCustom(props) {
|
|
46
41
|
const { children, onSubmit, className, handleSubmit } = props;
|
|
47
|
-
return /* @__PURE__ */ jsx(FormProvider, { ...props, children: /* @__PURE__ */ jsx(
|
|
48
|
-
FormProviderRoot,
|
|
49
|
-
{
|
|
50
|
-
className: clsx(classes.root, className),
|
|
51
|
-
onSubmit: handleSubmit(onSubmit),
|
|
52
|
-
children
|
|
53
|
-
}
|
|
54
|
-
) });
|
|
42
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...props, children: /* @__PURE__ */ jsx(FormProviderRoot, { className: clsx(classes.root, className), onSubmit: handleSubmit(onSubmit), children }) });
|
|
55
43
|
}
|
|
56
44
|
function RHFormProvider(props) {
|
|
57
|
-
const {
|
|
58
|
-
|
|
59
|
-
onSubmit,
|
|
60
|
-
values,
|
|
61
|
-
validationSchema,
|
|
62
|
-
statusLoad = "ready",
|
|
63
|
-
className,
|
|
64
|
-
mode
|
|
65
|
-
} = props;
|
|
66
|
-
const formMethods = useCustomForm({
|
|
67
|
-
validationSchema,
|
|
68
|
-
statusLoad,
|
|
69
|
-
values,
|
|
70
|
-
mode
|
|
71
|
-
});
|
|
45
|
+
const { children, onSubmit, values, validationSchema, statusLoad = "ready", className, mode } = props;
|
|
46
|
+
const formMethods = useCustomForm({ validationSchema, statusLoad, values, mode });
|
|
72
47
|
return /* @__PURE__ */ jsx(
|
|
73
48
|
FormProviderCustom,
|
|
74
49
|
{
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Obtiene los valores iniciales de campos específicos del formulario.
|
|
3
|
-
* Se usa para inicializar el ref que trackea cambios en los campos.
|
|
4
|
-
* @param allValues - Todos los valores del formulario (de getValues())
|
|
5
|
-
* @param fields - Lista de nombres de campos de los que queremos obtener valores
|
|
6
|
-
* @returns Objeto con solo los valores de los campos especificados
|
|
7
|
-
* @example
|
|
8
|
-
* const formValues = { name: 'John', age: 25, city: 'NY', country: 'USA' };
|
|
9
|
-
* getInitialFieldValues(formValues, ['name', 'age'])
|
|
10
|
-
* // Retorna: { name: 'John', age: 25 }
|
|
11
|
-
*/
|
|
12
|
-
export declare function getInitialFieldValues(allValues: Record<string, any>, fields?: string[]): Record<string, any>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
function getInitialFieldValues(allValues, fields = []) {
|
|
2
|
-
if (fields.length === 0) {
|
|
3
|
-
return {};
|
|
4
|
-
}
|
|
5
|
-
return fields.reduce((acc, field) => {
|
|
6
|
-
if (field in allValues) {
|
|
7
|
-
acc[field] = allValues[field];
|
|
8
|
-
}
|
|
9
|
-
return acc;
|
|
10
|
-
}, {});
|
|
11
|
-
}
|
|
12
|
-
export {
|
|
13
|
-
getInitialFieldValues as g
|
|
14
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convierte los valores observados de useWatch en un objeto estructurado con los nombres de campos como keys.
|
|
3
|
-
*
|
|
4
|
-
* useWatch de react-hook-form retorna diferentes estructuras según la cantidad de campos observados:
|
|
5
|
-
* - Un solo campo: retorna el valor directamente
|
|
6
|
-
* - Múltiples campos: retorna un array con los valores en el mismo orden de los campos
|
|
7
|
-
* @param watchValues - Valores observados de useWatch (puede ser un valor único o un array)
|
|
8
|
-
* @param fields - Lista de nombres de campos que se están observando
|
|
9
|
-
* @returns Objeto con los valores actuales mapeados a sus respectivos nombres de campo
|
|
10
|
-
* @example
|
|
11
|
-
* // Para un solo campo
|
|
12
|
-
* parseWatchedValues('John', ['name']) // { name: 'John' }
|
|
13
|
-
*
|
|
14
|
-
* // Para múltiples campos
|
|
15
|
-
* parseWatchedValues(['John', 25], ['name', 'age']) // { name: 'John', age: 25 }
|
|
16
|
-
*/
|
|
17
|
-
export declare function parseWatchedValues(watchValues: any, fields: string[]): Record<string, any>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function parseWatchedValues(watchValues, fields) {
|
|
2
|
-
if (fields.length === 1) {
|
|
3
|
-
return { [fields[0]]: watchValues };
|
|
4
|
-
}
|
|
5
|
-
return fields.reduce((acc, field, index) => {
|
|
6
|
-
acc[field] = Array.isArray(watchValues) ? watchValues[index] : watchValues;
|
|
7
|
-
return acc;
|
|
8
|
-
}, {});
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
parseWatchedValues as p
|
|
12
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook que simula validación onChange de campos específicos del Stepper, manteniendo el formulario en modo onSubmit para preservar el rendimiento.
|
|
3
|
-
* @returns Objeto con funciones para manejar la validación dinámica
|
|
4
|
-
*/
|
|
5
|
-
export declare function useDynamicValidation(): {
|
|
6
|
-
activateFieldsValidation: (fields: string[], skipIfValidating?: boolean) => void;
|
|
7
|
-
clearAllValidation: () => void;
|
|
8
|
-
activeFields: string[];
|
|
9
|
-
startExternalValidation: () => void;
|
|
10
|
-
endExternalValidation: () => void;
|
|
11
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { useState, useRef, useEffect, useCallback } from "react";
|
|
2
|
-
import { useFormContext, useWatch } from "react-hook-form";
|
|
3
|
-
import { p as parseWatchedValues } from "../../helpers/parseWatchedValues/index.js";
|
|
4
|
-
import { g as getInitialFieldValues } from "../../helpers/getInitialFieldValues/index.js";
|
|
5
|
-
function useDynamicValidation() {
|
|
6
|
-
const { trigger, getValues } = useFormContext();
|
|
7
|
-
const [activeFields, setActiveFields] = useState([]);
|
|
8
|
-
const [isValidating, setIsValidating] = useState(false);
|
|
9
|
-
const statusLoad = useWatch({
|
|
10
|
-
name: "statusLoad"
|
|
11
|
-
});
|
|
12
|
-
const watchValues = useWatch({
|
|
13
|
-
name: activeFields.length > 0 ? activeFields : ["__dummy__"]
|
|
14
|
-
});
|
|
15
|
-
const lastValuesRef = useRef({});
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (activeFields.length === 0 || statusLoad !== "ready" || isValidating) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const currentValues = parseWatchedValues(watchValues, activeFields);
|
|
21
|
-
const changedFields = activeFields.filter((field) => {
|
|
22
|
-
const currentValue = currentValues[field];
|
|
23
|
-
const lastValue = lastValuesRef.current[field];
|
|
24
|
-
const hasChanged = JSON.stringify(currentValue) !== JSON.stringify(lastValue);
|
|
25
|
-
if (hasChanged) {
|
|
26
|
-
lastValuesRef.current[field] = currentValue;
|
|
27
|
-
}
|
|
28
|
-
return hasChanged;
|
|
29
|
-
});
|
|
30
|
-
if (changedFields.length > 0) {
|
|
31
|
-
const timeoutId = setTimeout(() => {
|
|
32
|
-
trigger(changedFields);
|
|
33
|
-
}, 100);
|
|
34
|
-
return () => clearTimeout(timeoutId);
|
|
35
|
-
}
|
|
36
|
-
}, [activeFields, trigger, watchValues, statusLoad, isValidating]);
|
|
37
|
-
const startExternalValidation = useCallback(() => {
|
|
38
|
-
setIsValidating(true);
|
|
39
|
-
}, []);
|
|
40
|
-
const endExternalValidation = useCallback(() => {
|
|
41
|
-
setIsValidating(false);
|
|
42
|
-
}, []);
|
|
43
|
-
const activateFieldsValidation = useCallback(
|
|
44
|
-
(fields, skipIfValidating = true) => {
|
|
45
|
-
if (skipIfValidating && isValidating) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const formValues = getValues();
|
|
49
|
-
setActiveFields(fields);
|
|
50
|
-
const initialValues = getInitialFieldValues(formValues, fields);
|
|
51
|
-
lastValuesRef.current = initialValues;
|
|
52
|
-
},
|
|
53
|
-
[getValues, isValidating]
|
|
54
|
-
);
|
|
55
|
-
const clearAllValidation = useCallback(() => {
|
|
56
|
-
setActiveFields([]);
|
|
57
|
-
lastValuesRef.current = {};
|
|
58
|
-
}, []);
|
|
59
|
-
return {
|
|
60
|
-
activateFieldsValidation,
|
|
61
|
-
clearAllValidation,
|
|
62
|
-
activeFields,
|
|
63
|
-
startExternalValidation,
|
|
64
|
-
endExternalValidation
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export {
|
|
68
|
-
useDynamicValidation as u
|
|
69
|
-
};
|