@m4l/components 9.4.15 → 9.4.17-BE20260121-2
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/@types/types.d.ts +25 -17
- package/components/DaysOfWeekPicker/DaysOfWeekPicker.d.ts +33 -0
- package/components/DaysOfWeekPicker/DaysOfWeekPicker.js +81 -0
- package/components/DaysOfWeekPicker/DaysOfWeekPicker.styles.d.ts +2 -0
- package/components/DaysOfWeekPicker/DaysOfWeekPicker.styles.js +99 -0
- package/components/DaysOfWeekPicker/DaysOfWeekPicker.test.d.ts +1 -0
- package/components/DaysOfWeekPicker/constants.d.ts +12 -0
- package/components/DaysOfWeekPicker/constants.js +11 -0
- package/components/DaysOfWeekPicker/dictionary.d.ts +1 -0
- package/components/DaysOfWeekPicker/dictionary.js +6 -0
- package/components/DaysOfWeekPicker/helpers/getDaysOfWeekFromDictionary.d.ts +29 -0
- package/components/DaysOfWeekPicker/helpers/getDaysOfWeekFromDictionary.js +12 -0
- package/components/DaysOfWeekPicker/helpers/getDaysOfWeekFromDictionary.test.d.ts +1 -0
- package/components/DaysOfWeekPicker/helpers/index.d.ts +1 -0
- package/components/DaysOfWeekPicker/helpers/index.js +1 -0
- package/components/DaysOfWeekPicker/hooks/index.d.ts +2 -0
- package/components/DaysOfWeekPicker/hooks/types.d.ts +29 -0
- package/components/DaysOfWeekPicker/hooks/useDaysOfWeekPicker.d.ts +9 -0
- package/components/DaysOfWeekPicker/hooks/useDaysOfWeekPicker.js +71 -0
- package/components/DaysOfWeekPicker/hooks/useDaysOfWeekPicker.test.d.ts +1 -0
- package/components/DaysOfWeekPicker/index.d.ts +3 -0
- package/components/DaysOfWeekPicker/index.js +1 -0
- package/components/DaysOfWeekPicker/slots/DaysOfWeekPickerEnum.d.ts +5 -0
- package/components/DaysOfWeekPicker/slots/DaysOfWeekPickerEnum.js +9 -0
- package/components/DaysOfWeekPicker/slots/DaysOfWeekPickerSlots.d.ts +9 -0
- package/components/DaysOfWeekPicker/slots/DaysOfWeekPickerSlots.js +23 -0
- package/components/DaysOfWeekPicker/slots/index.d.ts +3 -0
- package/components/DaysOfWeekPicker/slots/index.js +1 -0
- package/components/DaysOfWeekPicker/types.d.ts +70 -0
- package/components/DynamicFilter/subcomponents/FieldTypes/BooleanFilter/helpers.js +10 -1
- package/components/DynamicFilter/types.d.ts +22 -0
- package/components/NumberInput/hooks/useNumberInput/useNumberInput.js +2 -0
- package/components/datagrids/views/TableView/hooks/useSortColumnsRows/useSortColumnsRows.js +2 -0
- package/components/hook-form/RHFAutocompleteAsync/reducer/RHFAutocompleteReducer.js +5 -0
- package/components/hook-form/RHFDaysOfWeekPicker/RHFDaysOfWeekPicker.d.ts +26 -0
- package/components/hook-form/RHFDaysOfWeekPicker/RHFDaysOfWeekPicker.js +6 -0
- package/components/hook-form/RHFDaysOfWeekPicker/index.d.ts +1 -0
- package/components/hook-form/RHFDaysOfWeekPicker/index.js +1 -0
- package/components/hook-form/index.d.ts +1 -0
- package/components/index.d.ts +1 -0
- package/hocs/index.d.ts +2 -0
- package/hocs/withRHFController/constants.d.ts +8 -0
- package/hocs/withRHFController/constants.js +8 -0
- package/hocs/withRHFController/index.d.ts +37 -0
- package/hocs/withRHFController/index.js +95 -0
- package/hocs/withRHFController/slots/WithRHFControllerEnum.d.ts +3 -0
- package/hocs/withRHFController/slots/WithRHFControllerEnum.js +7 -0
- package/hocs/withRHFController/slots/WithRHFControllerSlots.d.ts +5 -0
- package/hocs/withRHFController/slots/WithRHFControllerSlots.js +11 -0
- package/hocs/withRHFController/slots/index.d.ts +2 -0
- package/hocs/withRHFController/slots/index.js +1 -0
- package/hocs/withRHFController/types.d.ts +70 -0
- package/hocs/withRHFController/withRHFController.styles.d.ts +5 -0
- package/hocs/withRHFController/withRHFController.styles.js +14 -0
- package/hocs/withRHFController/withRHFController.test.d.ts +1 -0
- package/index.js +111 -105
- package/not_recognized/index.js +100 -25
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import * as Yup from "yup";
|
|
|
2
2
|
import { B as BOOLEAN_OPERATORS } from "../../../constants.js";
|
|
3
3
|
import { B as BooleanFilter } from "./index.js";
|
|
4
4
|
import { D as DYNAMIC_FILTER_DICTIONARY_ID, a as DICCTIONARY } from "../../../dictionary.js";
|
|
5
|
+
import { g as getFormatBoolean } from "../../../../formatters/BooleanFormatter/BooleanFormatter.js";
|
|
5
6
|
import { c as createValidationSchema, a as createValidationFullObject, b as createValidationPartialObject } from "../../../../hook-form/RHFormProvider/schema.js";
|
|
6
7
|
class BooleanFilterHelpers {
|
|
7
8
|
getComponent() {
|
|
@@ -67,7 +68,15 @@ class BooleanFilterHelpers {
|
|
|
67
68
|
* getLabel devuelve las etiquetas para el filtro booleano.
|
|
68
69
|
*/
|
|
69
70
|
getLabels(filter, getLabel, _formatters, _field) {
|
|
70
|
-
const
|
|
71
|
+
const presentationType = filter.field.presentationType;
|
|
72
|
+
const value = filter.operand1;
|
|
73
|
+
let labelOperands;
|
|
74
|
+
if (presentationType && typeof presentationType === "object" && "trueLabel" in presentationType) {
|
|
75
|
+
labelOperands = value ? presentationType.trueLabel : presentationType.falseLabel;
|
|
76
|
+
} else {
|
|
77
|
+
const preset = presentationType ?? "string_true_false";
|
|
78
|
+
labelOperands = getFormatBoolean(preset, value, getLabel);
|
|
79
|
+
}
|
|
71
80
|
return {
|
|
72
81
|
labelField: filter.field.label ?? getLabel(filter.field.dictionaryId),
|
|
73
82
|
labelOperator: getLabel(
|
|
@@ -5,6 +5,19 @@ import { M4LOverridesStyleRules } from '../../@types/augmentations';
|
|
|
5
5
|
import { RHFAutocompleteAsyncProps } from '../hook-form/RHFAutocompleteAsync/types';
|
|
6
6
|
import { RHFSelectProps } from '../hook-form/RHFSelect';
|
|
7
7
|
import { DynamicFilterSlots } from './slots';
|
|
8
|
+
import { PresentationType } from '../formatters/BooleanFormatter/types';
|
|
9
|
+
/**
|
|
10
|
+
* Labels personalizados para valores booleanos
|
|
11
|
+
*/
|
|
12
|
+
export interface BooleanCustomLabels {
|
|
13
|
+
trueLabel: string;
|
|
14
|
+
falseLabel: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Tipo de presentación para campos booleanos en DynamicFilter.
|
|
18
|
+
* Solo incluye las presentaciones de texto del BooleanFormatter más labels personalizados.
|
|
19
|
+
*/
|
|
20
|
+
export type BooleanPresentationType = Extract<PresentationType, 'string_true_false' | 'string_yes_no'> | BooleanCustomLabels;
|
|
8
21
|
export type FieldType = 'number' | 'string' | 'boolean' | 'datetime' | 'select' | 'selectAsync';
|
|
9
22
|
export type OperandType = number | string | boolean | Date | [] | object;
|
|
10
23
|
export type OperandInitialFilterType = number | string | boolean | [] | object;
|
|
@@ -47,6 +60,15 @@ export interface FieldBase<T extends FieldType = FieldType, TOption = any> {
|
|
|
47
60
|
selectOptions?: SelectOptions;
|
|
48
61
|
selectAsyncOptions?: SelectAsyncOptions<TOption>;
|
|
49
62
|
skipColumnValidation?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Tipo de presentación para campos booleanos.
|
|
65
|
+
* Solo aplica cuando type es 'boolean'.
|
|
66
|
+
* - 'string_true_false': "Verdadero" / "Falso" (default)
|
|
67
|
+
* - 'string_yes_no': "Sí" / "No"
|
|
68
|
+
* - { trueLabel: string, falseLabel: string }: Labels personalizados
|
|
69
|
+
* @default 'string_true_false'
|
|
70
|
+
*/
|
|
71
|
+
presentationType?: BooleanPresentationType;
|
|
50
72
|
}
|
|
51
73
|
export interface FieldWithSelectAsync<T extends 'selectAsync', TOption = any> extends FieldBase<T, TOption> {
|
|
52
74
|
selectAsyncOptions: SelectAsyncOptions<TOption>;
|
|
@@ -56,9 +56,11 @@ const useNumberInput = (parameters) => {
|
|
|
56
56
|
(event, field, fieldValue, reason) => {
|
|
57
57
|
if (field === "value" && typeof fieldValue !== "string") {
|
|
58
58
|
switch (reason) {
|
|
59
|
+
// only a blur event will dispatch `numberInput:clamp`
|
|
59
60
|
case "numberInput:inputChange":
|
|
60
61
|
onChange?.(event, fieldValue);
|
|
61
62
|
break;
|
|
63
|
+
// only a blur event will dispatch `numberInput:clamp`
|
|
62
64
|
case "numberInput:clamp":
|
|
63
65
|
onChange?.(event, fieldValue);
|
|
64
66
|
break;
|
|
@@ -20,6 +20,7 @@ function getComparator(columns, sortColumn) {
|
|
|
20
20
|
return column.customSort;
|
|
21
21
|
}
|
|
22
22
|
switch (typeOrder) {
|
|
23
|
+
//Si el tipo de dato de la columna es un numerico, retorna una función de ordenamiento numérica
|
|
23
24
|
case "number":
|
|
24
25
|
return (a, b) => {
|
|
25
26
|
try {
|
|
@@ -28,6 +29,7 @@ function getComparator(columns, sortColumn) {
|
|
|
28
29
|
return -1;
|
|
29
30
|
}
|
|
30
31
|
};
|
|
32
|
+
//Por defecto retorna una función de ordenamiento de string
|
|
31
33
|
default:
|
|
32
34
|
return (a, b) => {
|
|
33
35
|
try {
|
|
@@ -65,6 +65,11 @@ const RHFAutocompleteAsyncReducer = (onChangeFilterParms) => (state, action) =>
|
|
|
65
65
|
...state,
|
|
66
66
|
isOpen: false
|
|
67
67
|
};
|
|
68
|
+
// case actionsType.SET_SELECTED_OPTIONS_TO_AUTOCOMPLETE:
|
|
69
|
+
// return {
|
|
70
|
+
// ...state,
|
|
71
|
+
// selectedOptions: action.payload,
|
|
72
|
+
// };
|
|
68
73
|
default:
|
|
69
74
|
return state;
|
|
70
75
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Componente RHFDaysOfWeekPicker que integra DaysOfWeekPicker con react-hook-form.
|
|
3
|
+
*
|
|
4
|
+
* Este componente permite seleccionar días de la semana en un formulario controlado
|
|
5
|
+
* por react-hook-form, proporcionando validación automática y manejo de estados.
|
|
6
|
+
*
|
|
7
|
+
* ### Características:
|
|
8
|
+
* - **Integración con RHF**: Se integra automáticamente con react-hook-form mediante el HOC withRHFController
|
|
9
|
+
* - **Validación**: Soporta validación mediante esquemas de validación (Yup, Zod, etc.)
|
|
10
|
+
* - **Estados del formulario**: Se deshabilita automáticamente durante el envío del formulario
|
|
11
|
+
* - **Label y errores**: El HOC maneja automáticamente el Label y los mensajes de error
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const schema = Yup.object({
|
|
15
|
+
* days: Yup.array().min(1, 'Debe seleccionar al menos un día').required('Campo requerido'),
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* <RHFDaysOfWeekPicker
|
|
19
|
+
* name="days"
|
|
20
|
+
* label="Días de la semana"
|
|
21
|
+
* mandatory
|
|
22
|
+
* disabledDays={[6]} // Deshabilita domingo
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const RHFDaysOfWeekPicker: import('react').ForwardRefExoticComponent<Omit<import('../../DaysOfWeekPicker').DaysOfWeekPickerProps & import('react').RefAttributes<HTMLDivElement> & import('../../../hocs').BaseRHFProps<import('react-hook-form').FieldValues>, "ref"> & import('react').RefAttributes<any>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { w as withRHFController } from "../../../hocs/withRHFController/index.js";
|
|
2
|
+
import { D as DaysOfWeekPicker } from "../../DaysOfWeekPicker/DaysOfWeekPicker.js";
|
|
3
|
+
const RHFDaysOfWeekPicker = withRHFController(DaysOfWeekPicker);
|
|
4
|
+
export {
|
|
5
|
+
RHFDaysOfWeekPicker as R
|
|
6
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RHFDaysOfWeekPicker } from './RHFDaysOfWeekPicker';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -8,6 +8,7 @@ export * from './RHFCheckableList';
|
|
|
8
8
|
export { RHFDateTime } from './RHFDateTime';
|
|
9
9
|
export { RHFDateTimePicker } from './RHFDateTimePicker';
|
|
10
10
|
export { RHFDatePicker } from './RHFDatePicker';
|
|
11
|
+
export * from './RHFDaysOfWeekPicker';
|
|
11
12
|
export { RHFMultiCheckbox } from './RHFMultiCheckbox';
|
|
12
13
|
export { RHFSelect } from './RHFSelect';
|
|
13
14
|
export { RHFHelperError } from './RHFHelperError';
|
package/components/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './CommonActions/';
|
|
|
14
14
|
export * from './ContainerFlow';
|
|
15
15
|
export * from './CommonActions/dictionary';
|
|
16
16
|
export * from './datagrids';
|
|
17
|
+
export * from './DaysOfWeekPicker';
|
|
17
18
|
export * from './DragResizeWindowRND';
|
|
18
19
|
export * from './DynamicFilter';
|
|
19
20
|
export * from './DynamicSort';
|
package/hocs/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { g as getComponentClasses } from "../../utils/getComponentSlotRoot.js";
|
|
2
|
+
import { W as WithRHFControllerSlots } from "./slots/WithRHFControllerEnum.js";
|
|
3
|
+
const WITH_RHF_CONTROLLER_KEY = "withRHFController";
|
|
4
|
+
const WITH_RHF_CONTROLLER_CLASSES = getComponentClasses(WITH_RHF_CONTROLLER_KEY, WithRHFControllerSlots);
|
|
5
|
+
export {
|
|
6
|
+
WITH_RHF_CONTROLLER_CLASSES as W,
|
|
7
|
+
WITH_RHF_CONTROLLER_KEY as a
|
|
8
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FieldValues } from 'react-hook-form';
|
|
3
|
+
import { BaseRHFProps, ComponentWithRHFControllerProps } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* HOC que envuelve un componente con la funcionalidad de Controller de react-hook-form.
|
|
6
|
+
*
|
|
7
|
+
* Este HOC automatiza la integración con react-hook-form proporcionando:
|
|
8
|
+
* - Acceso automático al control del formulario mediante useFormContext
|
|
9
|
+
* - Wrapper con Controller que maneja el estado del campo
|
|
10
|
+
* - Props del field, fieldState y formState pasadas automáticamente al componente envuelto
|
|
11
|
+
* - Props estándar de RHF (value, onChange, onBlur, name, error) extraídas del field y fieldState para compatibilidad
|
|
12
|
+
* @template TComponentProps - Props del componente que será envuelto
|
|
13
|
+
* @template TFieldValues - Tipo de los valores del formulario
|
|
14
|
+
* @param Component - Componente a envolver
|
|
15
|
+
* @returns Componente envuelto con funcionalidad RHF
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* // Componente base sin RHF - puede usar field completo o props individuales
|
|
19
|
+
* const MyInput = ({ field, fieldState, value, onChange, ...props }) => (
|
|
20
|
+
* <input {...field} {...props} />
|
|
21
|
+
* );
|
|
22
|
+
*
|
|
23
|
+
* // O usar props estándar de RHF directamente
|
|
24
|
+
* const MyTextField = ({ value, onChange, onBlur, error, ...props }) => (
|
|
25
|
+
* <TextField value={value} onChange={onChange} onBlur={onBlur} error={error} {...props} />
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* // Componente envuelto con HOC
|
|
29
|
+
* const RHFMyInput = withRHFController(MyInput);
|
|
30
|
+
* const RHFMyTextField = withRHFController(MyTextField);
|
|
31
|
+
*
|
|
32
|
+
* // Uso en formulario
|
|
33
|
+
* <RHFMyInput name="email" label="Email" />
|
|
34
|
+
* <RHFMyTextField name="email" label="Email" />
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function withRHFController<TComponentProps extends Record<string, any> = {}, TFieldValues extends FieldValues = FieldValues>(Component: React.ComponentType<ComponentWithRHFControllerProps<TComponentProps, TFieldValues>>): React.ForwardRefExoticComponent<React.PropsWithoutRef<TComponentProps & BaseRHFProps<TFieldValues>> & React.RefAttributes<any>>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId } from "react";
|
|
3
|
+
import { useFormContext, Controller } from "react-hook-form";
|
|
4
|
+
import { W as WITH_RHF_CONTROLLER_CLASSES } from "./constants.js";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import { R as RootStyled } from "./slots/WithRHFControllerSlots.js";
|
|
7
|
+
import { L as Label } from "../../components/Label/Label.js";
|
|
8
|
+
import { H as HelperError } from "../../components/HelperError/HelperError.js";
|
|
9
|
+
function withRHFController(Component) {
|
|
10
|
+
const WrappedComponent = forwardRef((props, ref) => {
|
|
11
|
+
const {
|
|
12
|
+
name,
|
|
13
|
+
control: controlProp,
|
|
14
|
+
// Puede permitir que el componente se use fuera de un FormProvider
|
|
15
|
+
label,
|
|
16
|
+
mandatory,
|
|
17
|
+
mandatoryMessage,
|
|
18
|
+
helperMessage,
|
|
19
|
+
size = "medium",
|
|
20
|
+
disabled,
|
|
21
|
+
id,
|
|
22
|
+
htmlFor,
|
|
23
|
+
...componentProps
|
|
24
|
+
} = props;
|
|
25
|
+
const hookId = useId();
|
|
26
|
+
const htmlForId = id || htmlFor || hookId;
|
|
27
|
+
const contextControl = useFormContext()?.control;
|
|
28
|
+
const control = controlProp || contextControl;
|
|
29
|
+
if (!control) {
|
|
30
|
+
console.warn(
|
|
31
|
+
`withRHFController: No se encontró un control de formulario para el campo "${name}". Asegúrate de que el componente esté dentro de un FormProvider o proporciona el control como prop.`
|
|
32
|
+
);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
Controller,
|
|
37
|
+
{
|
|
38
|
+
name,
|
|
39
|
+
control,
|
|
40
|
+
render: ({ field, fieldState, formState }) => {
|
|
41
|
+
const { value, onChange, onBlur, name: fieldName } = field;
|
|
42
|
+
const isDisabled = disabled || formState.isSubmitting;
|
|
43
|
+
const controllerProps = {
|
|
44
|
+
...componentProps,
|
|
45
|
+
// Props estándar de RHF (value, onChange, onBlur, name, error)
|
|
46
|
+
// Útiles para componentes que prefieren props individuales explícitas
|
|
47
|
+
value,
|
|
48
|
+
onChange,
|
|
49
|
+
onBlur,
|
|
50
|
+
name: fieldName,
|
|
51
|
+
error: !!fieldState.error,
|
|
52
|
+
// Props del HOC que también deben pasarse al componente (size, disabled, id)
|
|
53
|
+
size,
|
|
54
|
+
disabled: isDisabled,
|
|
55
|
+
id: htmlForId,
|
|
56
|
+
// Props del Controller (field completo, fieldState, formState)
|
|
57
|
+
field,
|
|
58
|
+
fieldState,
|
|
59
|
+
formState
|
|
60
|
+
};
|
|
61
|
+
return /* @__PURE__ */ jsxs(RootStyled, { ref, className: clsx(WITH_RHF_CONTROLLER_CLASSES.root), children: [
|
|
62
|
+
label && /* @__PURE__ */ jsx(
|
|
63
|
+
Label,
|
|
64
|
+
{
|
|
65
|
+
size,
|
|
66
|
+
label,
|
|
67
|
+
htmlFor: htmlForId,
|
|
68
|
+
mandatory,
|
|
69
|
+
mandatoryMessage,
|
|
70
|
+
helperMessage,
|
|
71
|
+
disabled: isDisabled,
|
|
72
|
+
error: !!fieldState.error
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
/* @__PURE__ */ jsx(Component, { ...controllerProps, ref: field.ref, size, disabled: isDisabled }),
|
|
76
|
+
fieldState.error?.message && /* @__PURE__ */ jsx(
|
|
77
|
+
HelperError,
|
|
78
|
+
{
|
|
79
|
+
message: fieldState.error.message,
|
|
80
|
+
size,
|
|
81
|
+
htmlFor: htmlForId
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
] });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
const componentName = Component.displayName || Component.name || "Component";
|
|
90
|
+
WrappedComponent.displayName = `withRHFController(${componentName})`;
|
|
91
|
+
return WrappedComponent;
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
withRHFController as w
|
|
95
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elemento div de react construido a través de styled,
|
|
3
|
+
* sirve para agrupar el contenido del HOC `withRHFController`
|
|
4
|
+
*/
|
|
5
|
+
export declare const RootStyled: import('@emotion/styled').StyledComponent<import('@mui/system').MUIStyledCommonProps<import('@mui/material/styles').Theme> & Record<string, unknown>, Pick<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import('react').ClassAttributes<HTMLDivElement> | keyof import('react').HTMLAttributes<HTMLDivElement>>, {}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { styled } from "@mui/material/styles";
|
|
2
|
+
import { a as WITH_RHF_CONTROLLER_KEY } from "../constants.js";
|
|
3
|
+
import { W as WithRHFControllerSlots } from "./WithRHFControllerEnum.js";
|
|
4
|
+
import { w as withRHFControllerStyles } from "../withRHFController.styles.js";
|
|
5
|
+
const RootStyled = styled("div", {
|
|
6
|
+
name: WITH_RHF_CONTROLLER_KEY,
|
|
7
|
+
slot: WithRHFControllerSlots.root
|
|
8
|
+
})(withRHFControllerStyles?.root);
|
|
9
|
+
export {
|
|
10
|
+
RootStyled as R
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Control, FieldPath, FieldValues, ControllerRenderProps, ControllerFieldState, FormState } from 'react-hook-form';
|
|
2
|
+
import { Theme } from '@mui/material';
|
|
3
|
+
import { M4LOverridesStyleRules } from '../../@types/augmentations';
|
|
4
|
+
import { WithRHFControllerSlots } from './slots/WithRHFControllerEnum';
|
|
5
|
+
import { WITH_RHF_CONTROLLER_KEY } from './constants';
|
|
6
|
+
import { LabelPropsBase } from '../../components/Label/types';
|
|
7
|
+
import { Sizes } from '@m4l/styles';
|
|
8
|
+
/**
|
|
9
|
+
* Props que el componente envuelto recibirá del Controller de react-hook-form
|
|
10
|
+
*/
|
|
11
|
+
export interface RHFControllerRenderProps<TFieldValues extends FieldValues = FieldValues> {
|
|
12
|
+
/** Props del field del Controller */
|
|
13
|
+
field: ControllerRenderProps<TFieldValues, FieldPath<TFieldValues>>;
|
|
14
|
+
/** Estado del field (error, invalid, etc.) */
|
|
15
|
+
fieldState: ControllerFieldState;
|
|
16
|
+
/** Estado del formulario completo */
|
|
17
|
+
formState: FormState<TFieldValues>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Props base que todos los componentes RHF deben tener
|
|
21
|
+
*/
|
|
22
|
+
export interface BaseRHFProps<TFieldValues extends FieldValues = FieldValues> extends LabelPropsBase {
|
|
23
|
+
/** Nombre del campo en el formulario */
|
|
24
|
+
name: FieldPath<TFieldValues>;
|
|
25
|
+
/** Control del formulario (opcional, se obtiene automáticamente de useFormContext si no se proporciona) */
|
|
26
|
+
control?: Control<TFieldValues>;
|
|
27
|
+
/** Tamaño del componente */
|
|
28
|
+
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
29
|
+
/** Indica si el componente está deshabilitado */
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** Identificador único para el campo */
|
|
32
|
+
id?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Props que el HOC añade al componente envuelto
|
|
36
|
+
*/
|
|
37
|
+
export interface WithRHFControllerProps<TFieldValues extends FieldValues = FieldValues> extends BaseRHFProps<TFieldValues> {
|
|
38
|
+
/** Props del render del Controller */
|
|
39
|
+
renderProps?: RHFControllerRenderProps<TFieldValues>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Props adicionales que el HOC pasa al componente envuelto
|
|
43
|
+
*/
|
|
44
|
+
export interface WithRHFControllerAdditionalProps {
|
|
45
|
+
/** Valor del campo */
|
|
46
|
+
value?: any;
|
|
47
|
+
/** Función de cambio de valor */
|
|
48
|
+
onChange?: (...event: any[]) => void;
|
|
49
|
+
/** Función de blur (puede ser de diferentes tipos según el componente) */
|
|
50
|
+
onBlur?: (...args: any[]) => void;
|
|
51
|
+
/** Nombre del campo */
|
|
52
|
+
name?: string;
|
|
53
|
+
/** Indica si hay error */
|
|
54
|
+
error?: boolean;
|
|
55
|
+
/** Tamaño del componente */
|
|
56
|
+
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
57
|
+
/** Indica si el componente está deshabilitado */
|
|
58
|
+
disabled?: boolean;
|
|
59
|
+
/** Identificador único para el campo */
|
|
60
|
+
id?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Tipo para el componente que será envuelto por el HOC
|
|
64
|
+
*/
|
|
65
|
+
export type ComponentWithRHFControllerProps<TComponentProps extends Record<string, any> = {}, TFieldValues extends FieldValues = FieldValues> = TComponentProps & RHFControllerRenderProps<TFieldValues> & Partial<WithRHFControllerAdditionalProps>;
|
|
66
|
+
/**
|
|
67
|
+
* Define los estilos del HOC `withRHFController`. Permite la personalización parcial
|
|
68
|
+
* de las reglas de estilo mediante `M4LOverridesStyleRules`.
|
|
69
|
+
*/
|
|
70
|
+
export type WithRHFControllerStyles = M4LOverridesStyleRules<WithRHFControllerSlots, typeof WITH_RHF_CONTROLLER_KEY, Theme>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const withRHFControllerStyles = {
|
|
2
|
+
/**
|
|
3
|
+
* Estilos para el contenedor principal del componente.
|
|
4
|
+
*/
|
|
5
|
+
root: ({ theme }) => ({
|
|
6
|
+
display: "flex",
|
|
7
|
+
flexDirection: "column",
|
|
8
|
+
gap: theme.vars.size.baseSpacings.sp1,
|
|
9
|
+
width: "100%"
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
withRHFControllerStyles as w
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|