@m4l/components 9.1.71 → 9.1.73
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 +9 -1
- package/components/Label/types.d.ts +2 -1
- package/components/hook-form/RHFSelect/RHFSelect.d.ts +23 -0
- package/components/hook-form/RHFSelect/RHFSelect.js +77 -0
- package/components/hook-form/RHFSelect/RHFSelect.styles.d.ts +5 -0
- package/components/hook-form/RHFSelect/RHFSelect.styles.js +25 -0
- package/components/hook-form/RHFSelect/constants.d.ts +8 -0
- package/components/hook-form/RHFSelect/constants.js +8 -0
- package/components/hook-form/RHFSelect/index.d.ts +2 -0
- package/components/hook-form/RHFSelect/index.js +1 -0
- package/components/hook-form/RHFSelect/slots/RHFSelectEnum.d.ts +6 -0
- package/components/hook-form/RHFSelect/slots/RHFSelectEnum.js +10 -0
- package/components/hook-form/RHFSelect/slots/RHFSlots.d.ts +20 -0
- package/components/hook-form/RHFSelect/slots/RHFSlots.js +29 -0
- package/components/hook-form/RHFSelect/slots/index.d.ts +0 -0
- package/components/hook-form/RHFSelect/test/RHFSelect.test.d.ts +1 -0
- package/components/hook-form/RHFSelect/types.d.ts +60 -0
- package/components/mui_extended/MenuItem/MenuItem.styles.js +7 -34
- package/components/mui_extended/Popover/Popover.js +1 -1
- package/components/mui_extended/Select/Select.js +23 -5
- package/index.js +1 -1
- package/package.json +1 -1
- package/components/hook-form/RHFSelect.d.ts +0 -10
- package/components/hook-form/RHFSelect.js +0 -29
package/@types/types.d.ts
CHANGED
|
@@ -141,6 +141,7 @@ import { RHFAutocompleteOwnerState, RHFAutocompleteSlotsType } from '../componen
|
|
|
141
141
|
import { PropagateLoaderSpinnerOwnerState, PropagateLoaderSpinnerType } from '../components/extended/React-Spinners/PropagateLoaderSpinner/types';
|
|
142
142
|
import { LinearProgressIndeterminateOwnerState, LinearProgressIndeterminateType } from '../components/LinearProgressIndeterminate/types';
|
|
143
143
|
import { MenuDividerOwnerState, MenuDividerSlotsType } from '../components/mui_extended/MenuDivider/types';
|
|
144
|
+
import { RHFSelectSlotsType, RHFSelectOwnerState } from '../components/hook-form/RHFSelect/types';
|
|
144
145
|
|
|
145
146
|
declare module '@mui/material/styles' {
|
|
146
147
|
// Define the slots in the theme
|
|
@@ -198,6 +199,7 @@ declare module '@mui/material/styles' {
|
|
|
198
199
|
M4LRHFTextFieldPassword: RHFTextFieldPasswordType;
|
|
199
200
|
M4LLinearProgressIndeterminate: LinearProgressIndeterminateType;
|
|
200
201
|
M4LMenuDivider: MenuDividerSlotsType;
|
|
202
|
+
M4LRHFSelect: RHFSelectSlotsType;
|
|
201
203
|
}
|
|
202
204
|
|
|
203
205
|
interface ComponentsPropsList {
|
|
@@ -255,6 +257,7 @@ declare module '@mui/material/styles' {
|
|
|
255
257
|
M4LRHFTextFieldPassword: Partial<RHFTextFieldPasswordOwnerState>;
|
|
256
258
|
M4LLinearProgressIndeterminate: Partial<LinearProgressIndeterminateOwnerState>;
|
|
257
259
|
M4LMenuDivider: Partial<MenuDividerOwnerState>;
|
|
260
|
+
M4LRHFSelect: Partial<RHFSelectOwnerState>;
|
|
258
261
|
}
|
|
259
262
|
|
|
260
263
|
interface Components {
|
|
@@ -522,6 +525,11 @@ declare module '@mui/material/styles' {
|
|
|
522
525
|
defaultProps?: ComponentsPropsList['M4LMenuDivider'];
|
|
523
526
|
styleOverrides?: ComponentsOverrides<Theme>['M4LMenuDivider'];
|
|
524
527
|
variants?: ComponentsVariants['M4LMenuDivider'];
|
|
525
|
-
|
|
528
|
+
};
|
|
529
|
+
M4LRHFSelect?: {
|
|
530
|
+
defaultProps?: ComponentsPropsList['M4LRHFSelect'];
|
|
531
|
+
styleOverrides?: ComponentsOverrides<Theme>['M4LRHFSelect'];
|
|
532
|
+
variants?: ComponentsVariants['M4LRHFSelect'];
|
|
533
|
+
};
|
|
526
534
|
}
|
|
527
535
|
}
|
|
@@ -3,8 +3,9 @@ import { OverridesStyleRules } from '@mui/material/styles/overrides';
|
|
|
3
3
|
import { Theme } from '@mui/material';
|
|
4
4
|
import { LABEL_KEY_COMPONENT } from './constants';
|
|
5
5
|
import { Sizes } from '@m4l/styles';
|
|
6
|
+
import { TypographyProps } from '../mui_extended/Typography/types';
|
|
6
7
|
export type LabelVariants = 'standard';
|
|
7
|
-
export interface LabelProps {
|
|
8
|
+
export interface LabelProps extends Pick<TypographyProps, 'skeletonWidth'> {
|
|
8
9
|
/** Mesanje de ayuda opcional que se visualiza cuando se interactua con el tooltip del Icono de informacion */
|
|
9
10
|
helperMessage?: string | undefined;
|
|
10
11
|
/** Es la etiqueta de texto principal del componente.*/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RHFSelectProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* RHFSelect is a custom select component integrated with React Hook Form.
|
|
4
|
+
* It renders a select input with optional label, helper text, and error message.
|
|
5
|
+
* @template T - The type of the options.
|
|
6
|
+
* @param {RHFSelectProps<T>} props - The properties for the RHFSelect component.
|
|
7
|
+
* @param {string} props.name - The name of the field.
|
|
8
|
+
* @param {Array} props.options - The options to be displayed in the select input.
|
|
9
|
+
* @param {string} [props.label] - The label for the select input.
|
|
10
|
+
* @param {number} [props.labelSkeletonWidth] - The width of the skeleton for the label.
|
|
11
|
+
* @param {number} [props.helperErrorSkeletonWidth] - The width of the skeleton for the helper error message.
|
|
12
|
+
* @param {string} [props.helperMessage] - The helper message to be displayed.
|
|
13
|
+
* @param {string} [props.helperText] - The helper text to be displayed.
|
|
14
|
+
* @param {boolean} [props.mandatory] - Whether the field is mandatory.
|
|
15
|
+
* @param {string} [props.mandatoryMessage] - The message to be displayed if the field is mandatory.
|
|
16
|
+
* @param {boolean} [props.disabled] - Whether the select input is disabled.
|
|
17
|
+
* @param {string} [props.size] - The size of the select input.
|
|
18
|
+
* @param {string} [props.variant] - The variant of the select input.
|
|
19
|
+
* @param {string} [props.className] - Additional class names for the root element.
|
|
20
|
+
* @param {string} [props.dataTestId] - The data test ID for the select input.
|
|
21
|
+
* @returns {JSX.Element} The rendered RHFSelect component.
|
|
22
|
+
*/
|
|
23
|
+
export declare const RHFSelect: <T>(props: RHFSelectProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { R as RHFSELECT_CLASSES, a as RHFSELECT_COMPONENT_KEY } from "./constants.js";
|
|
4
|
+
import { R as RHFSelectEnum } from "./slots/RHFSelectEnum.js";
|
|
5
|
+
import { R as RootStyled, L as LabelStyled, S as SelectStyled, H as HelperErrorStyled } from "./slots/RHFSlots.js";
|
|
6
|
+
import { useFormContext, Controller } from "react-hook-form";
|
|
7
|
+
import { g as getPropDataTestId } from "../../../test/getNameDataTestId.js";
|
|
8
|
+
import { u as useComponentSize } from "../../../hooks/useComponentSize/useComponentSize.js";
|
|
9
|
+
const RHFSelect = (props) => {
|
|
10
|
+
const {
|
|
11
|
+
name,
|
|
12
|
+
options,
|
|
13
|
+
label,
|
|
14
|
+
labelSkeletonWidth,
|
|
15
|
+
helperErrorSkeletonWidth,
|
|
16
|
+
helperMessage,
|
|
17
|
+
helperText,
|
|
18
|
+
mandatory,
|
|
19
|
+
mandatoryMessage,
|
|
20
|
+
placeholder,
|
|
21
|
+
disabled,
|
|
22
|
+
size = "medium",
|
|
23
|
+
variant = "outlined",
|
|
24
|
+
className,
|
|
25
|
+
dataTestId
|
|
26
|
+
} = props;
|
|
27
|
+
const { currentSize } = useComponentSize(size);
|
|
28
|
+
const adjustedSize = currentSize === "small" || currentSize === "medium" ? currentSize : "medium";
|
|
29
|
+
const { control } = useFormContext();
|
|
30
|
+
return /* @__PURE__ */ jsx(RootStyled, { ownerState: {}, className: clsx(RHFSELECT_CLASSES.root, className), children: /* @__PURE__ */ jsx(
|
|
31
|
+
Controller,
|
|
32
|
+
{
|
|
33
|
+
name,
|
|
34
|
+
control,
|
|
35
|
+
render: ({ field: { value, onChange, ref }, fieldState: { error } }) => {
|
|
36
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
37
|
+
label && /* @__PURE__ */ jsx(
|
|
38
|
+
LabelStyled,
|
|
39
|
+
{
|
|
40
|
+
htmlFor: name,
|
|
41
|
+
label,
|
|
42
|
+
mandatory,
|
|
43
|
+
mandatoryMessage,
|
|
44
|
+
helperMessage,
|
|
45
|
+
helperText,
|
|
46
|
+
size: adjustedSize,
|
|
47
|
+
skeletonWidth: labelSkeletonWidth,
|
|
48
|
+
error: Boolean(error),
|
|
49
|
+
disabled
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
SelectStyled,
|
|
54
|
+
{
|
|
55
|
+
ref,
|
|
56
|
+
options,
|
|
57
|
+
id: name,
|
|
58
|
+
size: adjustedSize,
|
|
59
|
+
variant,
|
|
60
|
+
value,
|
|
61
|
+
onChange: (opt) => onChange(opt.id),
|
|
62
|
+
disabled,
|
|
63
|
+
className: RHFSELECT_CLASSES.select,
|
|
64
|
+
error: Boolean(error),
|
|
65
|
+
placeholder,
|
|
66
|
+
...getPropDataTestId(RHFSELECT_COMPONENT_KEY, RHFSelectEnum.select, dataTestId)
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
error?.message && /* @__PURE__ */ jsx(HelperErrorStyled, { size: adjustedSize, message: error.message, skeletonWidth: helperErrorSkeletonWidth })
|
|
70
|
+
] });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
) });
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
RHFSelect as R
|
|
77
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const rhfSelectStyles = {
|
|
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
|
+
}),
|
|
10
|
+
/**
|
|
11
|
+
* Estilos del Label.
|
|
12
|
+
*/
|
|
13
|
+
label: {},
|
|
14
|
+
/**
|
|
15
|
+
* Estilos del Select.
|
|
16
|
+
*/
|
|
17
|
+
select: {},
|
|
18
|
+
/**
|
|
19
|
+
* Estilos del HelperError.
|
|
20
|
+
*/
|
|
21
|
+
helperError: {}
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
rhfSelectStyles as r
|
|
25
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key del componente RHFSelect usado para identificar el componente en el registro de componentes.
|
|
3
|
+
*/
|
|
4
|
+
export declare const RHFSELECT_COMPONENT_KEY = "RHFSelect";
|
|
5
|
+
/**
|
|
6
|
+
* Clases CSS generadas dinámicamente para el componente RHFSelect.
|
|
7
|
+
*/
|
|
8
|
+
export declare const RHFSELECT_CLASSES: Record<string, string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { g as getComponentClasses } from "../../../utils/getComponentSlotRoot.js";
|
|
2
|
+
import { R as RHFSelectEnum } from "./slots/RHFSelectEnum.js";
|
|
3
|
+
const RHFSELECT_COMPONENT_KEY = "RHFSelect";
|
|
4
|
+
const RHFSELECT_CLASSES = getComponentClasses(RHFSELECT_COMPONENT_KEY, RHFSelectEnum);
|
|
5
|
+
export {
|
|
6
|
+
RHFSELECT_CLASSES as R,
|
|
7
|
+
RHFSELECT_COMPONENT_KEY as a
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var RHFSelectEnum = /* @__PURE__ */ ((RHFSelectEnum2) => {
|
|
2
|
+
RHFSelectEnum2["root"] = "root";
|
|
3
|
+
RHFSelectEnum2["label"] = "label";
|
|
4
|
+
RHFSelectEnum2["select"] = "select";
|
|
5
|
+
RHFSelectEnum2["helperError"] = "helperError";
|
|
6
|
+
return RHFSelectEnum2;
|
|
7
|
+
})(RHFSelectEnum || {});
|
|
8
|
+
export {
|
|
9
|
+
RHFSelectEnum as R
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Elemento div de react construido a través de styled,
|
|
3
|
+
* sirve para agrupar el contenido del componente `RHFSelect`
|
|
4
|
+
*/
|
|
5
|
+
export declare const RootStyled: import('@emotion/styled').StyledComponent<import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme> & Record<string, unknown>, Pick<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import('react').HTMLAttributes<HTMLDivElement> | keyof import('react').ClassAttributes<HTMLDivElement>>, {}>;
|
|
6
|
+
/**
|
|
7
|
+
* Elemento Label construido a través de styled,
|
|
8
|
+
* sirve para mostrar el label del componente `RHFSelect`
|
|
9
|
+
*/
|
|
10
|
+
export declare const LabelStyled: import('@emotion/styled').StyledComponent<Pick<import('../../../Label').LabelProps, keyof import('../../../Label').LabelProps> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme> & Record<string, unknown>, {}, {}>;
|
|
11
|
+
/**
|
|
12
|
+
* Elemento HelperError construido a través de styled,
|
|
13
|
+
* sirve para mostrar el mensaje de error del componente `RHFSelect`
|
|
14
|
+
*/
|
|
15
|
+
export declare const SelectStyled: import('@emotion/styled').StyledComponent<Pick<Omit<import('../../../mui_extended/Select').SelectProps<any>, "ref"> & import('react').RefAttributes<HTMLDivElement>, "children" | "value" | "onClose" | "title" | "size" | "name" | "error" | "input" | "options" | "rows" | "id" | "type" | "components" | "hidden" | "content" | "style" | "open" | "multiple" | "disabled" | "variant" | "margin" | "translate" | "sx" | "classes" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "autoCapitalize" | "autoFocus" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "enterKeyHint" | "lang" | "nonce" | "slot" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "componentsProps" | "onOpen" | "slotProps" | "slots" | "label" | keyof import('react').RefAttributes<HTMLDivElement> | "autoComplete" | "placeholder" | "readOnly" | "required" | "dataTestId" | "maxRows" | "fullWidth" | "inputProps" | "inputRef" | "multiline" | "minRows" | "disableInjectingGlobalStyles" | "endAdornment" | "inputComponent" | "renderSuffix" | "startAdornment" | "disableUnderline" | "autoWidth" | "defaultOpen" | "displayEmpty" | "IconComponent" | "labelId" | "MenuProps" | "native" | "renderValue" | "SelectDisplayProps"> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme> & Record<string, unknown>, {}, {}>;
|
|
16
|
+
/**
|
|
17
|
+
* Elemento HelperError construido a través de styled,
|
|
18
|
+
* sirve para mostrar el mensaje de error del componente `RHFSelect`
|
|
19
|
+
*/
|
|
20
|
+
export declare const HelperErrorStyled: import('@emotion/styled').StyledComponent<Pick<import('../../../HelperError').HelperErrorProps, keyof import('../../../HelperError').HelperErrorProps> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme> & Record<string, unknown>, {}, {}>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { styled } from "@mui/material";
|
|
2
|
+
import { a as RHFSELECT_COMPONENT_KEY } from "../constants.js";
|
|
3
|
+
import { R as RHFSelectEnum } from "./RHFSelectEnum.js";
|
|
4
|
+
import { r as rhfSelectStyles } from "../RHFSelect.styles.js";
|
|
5
|
+
import { L as Label } from "../../../Label/Label.js";
|
|
6
|
+
import { S as Select } from "../../../mui_extended/Select/Select.js";
|
|
7
|
+
import { H as HelperError } from "../../../HelperError/HelperError.js";
|
|
8
|
+
const RootStyled = styled("div", {
|
|
9
|
+
name: RHFSELECT_COMPONENT_KEY,
|
|
10
|
+
slot: RHFSelectEnum.root
|
|
11
|
+
})(rhfSelectStyles?.root);
|
|
12
|
+
const LabelStyled = styled(Label, {
|
|
13
|
+
name: RHFSELECT_COMPONENT_KEY,
|
|
14
|
+
slot: RHFSelectEnum.label
|
|
15
|
+
})(rhfSelectStyles?.label);
|
|
16
|
+
const SelectStyled = styled(Select, {
|
|
17
|
+
name: RHFSELECT_COMPONENT_KEY,
|
|
18
|
+
slot: RHFSelectEnum.select
|
|
19
|
+
})(rhfSelectStyles?.select);
|
|
20
|
+
const HelperErrorStyled = styled(HelperError, {
|
|
21
|
+
name: RHFSELECT_COMPONENT_KEY,
|
|
22
|
+
slot: RHFSelectEnum.helperError
|
|
23
|
+
})(rhfSelectStyles?.helperError);
|
|
24
|
+
export {
|
|
25
|
+
HelperErrorStyled as H,
|
|
26
|
+
LabelStyled as L,
|
|
27
|
+
RootStyled as R,
|
|
28
|
+
SelectStyled as S
|
|
29
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { HelperErrorProps } from 'src/components/HelperError';
|
|
2
|
+
import { LabelProps } from '../../Label/types';
|
|
3
|
+
import { SelectProps } from '../../mui_extended/Select/types';
|
|
4
|
+
import { Sizes } from '@m4l/styles';
|
|
5
|
+
import { M4LOverridesStyleRules } from 'src/@types/augmentations';
|
|
6
|
+
import { RHFSelectEnum } from './slots/RHFSelectEnum';
|
|
7
|
+
import { RHFSELECT_COMPONENT_KEY } from './constants';
|
|
8
|
+
import { Theme } from '@mui/material';
|
|
9
|
+
/**
|
|
10
|
+
* Props para el componente RHFSelect, incluye las propedades esceciales del Select, Label,
|
|
11
|
+
* así como las propiedades requeridas por react hook form.
|
|
12
|
+
*/
|
|
13
|
+
export interface RHFSelectProps<T> extends Pick<SelectProps<T>, 'options' | 'placeholder' | 'variant'>, Omit<LabelProps, 'dataTestId' | 'error' | 'children' | 'id' | 'className' | 'disabled' | 'size' | 'skeletonWidth'> {
|
|
14
|
+
/**
|
|
15
|
+
* Identificador para el manejo de campos en react hook form.
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Tamaño del componente
|
|
20
|
+
*/
|
|
21
|
+
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
22
|
+
/**
|
|
23
|
+
* Propiedad que deshabilita la interacción del componente.
|
|
24
|
+
*/
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Nombre de clase CSS personalizada que se aplicará al componente.
|
|
28
|
+
*/
|
|
29
|
+
className?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Propiedad usada para facilitar la identificación del componente en las pruebas.
|
|
32
|
+
*/
|
|
33
|
+
dataTestId?: string;
|
|
34
|
+
/**
|
|
35
|
+
* medida de anchura para el esqueleto del label
|
|
36
|
+
*/
|
|
37
|
+
labelSkeletonWidth?: LabelProps['skeletonWidth'];
|
|
38
|
+
/**
|
|
39
|
+
* medida de anchura para el esqueleto del helperError
|
|
40
|
+
*/
|
|
41
|
+
helperErrorSkeletonWidth?: HelperErrorProps['skeletonWidth'];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Define el estado del componente `RHFSelect`.
|
|
45
|
+
*/
|
|
46
|
+
export interface RHFSelectOwnerState {
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Define las claves del objeto `RHFSelectSlotsType`, que se utilizan para
|
|
50
|
+
* hacer referencia a los diferentes slots disponibles para estilizar el componente
|
|
51
|
+
* `RHFSelect`.
|
|
52
|
+
*/
|
|
53
|
+
export type RHFNumberInputSlotsType = keyof typeof RHFSelectEnum;
|
|
54
|
+
/**
|
|
55
|
+
* Define los estilos del componente `RHFNumberInputStyles`. Permite la personalización parcial
|
|
56
|
+
* de las reglas de estilo mediante `OverridesStyleRules`.
|
|
57
|
+
*
|
|
58
|
+
* Puede ser parcial o estar indefinido.
|
|
59
|
+
*/
|
|
60
|
+
export type RHFSelectStyles = M4LOverridesStyleRules<RHFSelectEnum, typeof RHFSELECT_COMPONENT_KEY, Theme>;
|
|
@@ -2,49 +2,22 @@ import { g as getHeightSizeStyles } from "../../../utils/getHeightSizeStyles.js"
|
|
|
2
2
|
const menuItemStyles = {
|
|
3
3
|
/**
|
|
4
4
|
* Estilos para el contenedor de los items del menú
|
|
5
|
-
* <<<<<<< HEAD
|
|
6
5
|
* @updatedUser Andrés Quintero - automatic
|
|
7
6
|
* @updatedAt 2025-01-08 10:36:41 - automatic
|
|
8
7
|
* @createdAt 2025-01-08 10:36:40 - automatic
|
|
9
8
|
* @author Andrés Quintero - automatic
|
|
10
|
-
* @updatedUser Andrés Quintero - automatic
|
|
11
|
-
* @updatedAt 2025-01-08 10:36:41 - automatic
|
|
12
|
-
* @createdAt 2025-01-03 11:42:11 - automatic
|
|
13
|
-
* @author Andrés Quintero - automatic
|
|
14
|
-
* @updatedUser Andrés Quintero - automatic
|
|
15
|
-
* @updatedAt 2025-01-08 10:36:41 - automatic
|
|
16
|
-
* @createdAt 2024-12-31 11:23:51 - automatic
|
|
17
|
-
* @author Andrés Quintero - automatic
|
|
18
|
-
* @updatedUser Andrés Quintero - automatic
|
|
19
|
-
* @updatedAt 2025-01-08 10:36:41 - automatic
|
|
20
|
-
* @createdAt 2024-12-30 14:36:06 - automatic
|
|
21
|
-
* @author Andrés Quintero - automatic
|
|
22
|
-
* @updatedUser Andrés Quintero - automatic
|
|
23
|
-
* @updatedAt 2025-01-08 10:36:41 - automatic
|
|
24
|
-
* =======
|
|
25
|
-
* @updatedUser cesar - automatic
|
|
26
|
-
* @updatedAt 2025-01-10 16:51:28 - automatic
|
|
27
|
-
* @createdAt 2025-01-10 16:51:28 - automatic
|
|
28
|
-
* @author cesar - automatic
|
|
29
|
-
* @updatedUser cesar - automatic
|
|
30
|
-
* @updatedAt 2025-01-10 16:51:28 - automatic
|
|
31
|
-
* @createdAt 2024-12-31 11:23:51 - automatic
|
|
32
|
-
* @author Andrés Quintero - automatic
|
|
33
|
-
* @updatedUser cesar - automatic
|
|
34
|
-
* @updatedAt 2025-01-10 16:51:28 - automatic
|
|
35
|
-
* @createdAt 2024-12-30 14:36:06 - automatic
|
|
36
|
-
* @author Andrés Quintero - automatic
|
|
37
|
-
* @updatedUser cesar - automatic
|
|
38
|
-
* @updatedAt 2025-01-10 16:51:28 - automatic
|
|
39
|
-
* >>>>>>> c15c4888 (Add checkable prop to MenuItem and update checked icon visibility logic)
|
|
40
|
-
* @createdAt 2024-12-27 08:28:33 - automatic
|
|
41
|
-
* @author Andrés Quintero - automatic
|
|
42
9
|
*/
|
|
43
10
|
root: ({ theme, ownerState }) => ({
|
|
44
11
|
width: "100%",
|
|
45
12
|
gap: theme.vars.size.baseSpacings.sp3,
|
|
46
|
-
|
|
13
|
+
paddingTop: theme.vars.size.baseSpacings.sp1,
|
|
14
|
+
paddingBottom: theme.vars.size.baseSpacings.sp1,
|
|
15
|
+
paddingLeft: theme.vars.size.baseSpacings.sp4,
|
|
16
|
+
paddingRight: theme.vars.size.baseSpacings.sp4,
|
|
47
17
|
borderRadius: theme.vars.size.borderRadius.r0,
|
|
18
|
+
"& .M4LTypography-root": {
|
|
19
|
+
paddingLeft: theme.vars.size.baseSpacings.sp1
|
|
20
|
+
},
|
|
48
21
|
...ownerState.selected && {
|
|
49
22
|
borderLeft: theme.vars.size.borderStroke.container,
|
|
50
23
|
borderColor: ownerState.paletteColor?.main,
|
|
@@ -21,6 +21,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
21
21
|
placeholder,
|
|
22
22
|
className,
|
|
23
23
|
dataTestId,
|
|
24
|
+
id,
|
|
24
25
|
...otherProps
|
|
25
26
|
} = props;
|
|
26
27
|
const { currentSize } = useComponentSize(size);
|
|
@@ -47,7 +48,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
47
48
|
const newValue = event.target.value;
|
|
48
49
|
setSelectedValue(newValue);
|
|
49
50
|
setOpen(false);
|
|
50
|
-
const selectedOption = options.find((option) => option.id === newValue);
|
|
51
|
+
const selectedOption = options.find((option) => String(option.id) === String(newValue));
|
|
51
52
|
if (selectedOption && onChange) {
|
|
52
53
|
onChange(selectedOption);
|
|
53
54
|
}
|
|
@@ -87,11 +88,11 @@ const Select = forwardRef((props, ref) => {
|
|
|
87
88
|
);
|
|
88
89
|
}
|
|
89
90
|
};
|
|
90
|
-
const renderValue = (
|
|
91
|
-
if (!Boolean(
|
|
91
|
+
const renderValue = () => {
|
|
92
|
+
if (!Boolean(selectedValue)) {
|
|
92
93
|
return /* @__PURE__ */ jsx(LabelPlaceholerStyled, { variant: "body", color: "text.disabled", ownerState: {}, children: placeholder });
|
|
93
94
|
}
|
|
94
|
-
const selectedOption = options.find((option) => option.id ===
|
|
95
|
+
const selectedOption = options.find((option) => String(option.id) === String(selectedValue));
|
|
95
96
|
return selectedOption ? /* @__PURE__ */ jsxs(RenderValueContainerStyled, { ownerState: { ...ownerState }, className: SELECT_CLASSES.renderValueContainer, children: [
|
|
96
97
|
selectedOption.startAdornment && RenderIcon(selectedOption.startAdornment),
|
|
97
98
|
/* @__PURE__ */ jsx(RenderValueTypography, { variant: "body", color: "text.primary", ownerState: {}, size: adjustedSize, className: SELECT_CLASSES.renderValueTypography, children: selectedOption.label })
|
|
@@ -105,6 +106,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
105
106
|
{
|
|
106
107
|
...otherProps,
|
|
107
108
|
...getPropDataTestId(SELECT_KEY_COMPONENT, SelectSlots.root, dataTestId),
|
|
109
|
+
id,
|
|
108
110
|
ref,
|
|
109
111
|
className: clsx(SELECT_CLASSES.root, SELECT_CLASSES[variant], className),
|
|
110
112
|
ownerState: { ...ownerState },
|
|
@@ -114,13 +116,29 @@ const Select = forwardRef((props, ref) => {
|
|
|
114
116
|
fullWidth: true,
|
|
115
117
|
disabled,
|
|
116
118
|
error,
|
|
117
|
-
renderValue
|
|
119
|
+
renderValue,
|
|
118
120
|
size: adjustedSize,
|
|
119
121
|
open,
|
|
120
122
|
displayEmpty: true,
|
|
121
123
|
onClick: () => {
|
|
122
124
|
!disabled && setOpen(!open);
|
|
123
125
|
},
|
|
126
|
+
MenuProps: {
|
|
127
|
+
sx: {
|
|
128
|
+
"& .MuiPaper-root": {
|
|
129
|
+
paddingTop: theme.vars.size.baseSpacings.sp3,
|
|
130
|
+
paddingBottom: theme.vars.size.baseSpacings.sp3,
|
|
131
|
+
paddingLeft: 0,
|
|
132
|
+
paddingRight: 0,
|
|
133
|
+
"& .MuiList-root": {
|
|
134
|
+
padding: 0,
|
|
135
|
+
display: "flex",
|
|
136
|
+
flexDirection: "column",
|
|
137
|
+
gap: theme.vars.size.baseSpacings.sp1
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
124
142
|
children: options.length > 0 ? options.map((option) => /* @__PURE__ */ jsx(
|
|
125
143
|
MenuItemListStyled,
|
|
126
144
|
{
|
package/index.js
CHANGED
|
@@ -31,7 +31,7 @@ import { R as R2 } from "./components/hook-form/RHFAutocompleteAsync/RHFAutocomp
|
|
|
31
31
|
import { g as g5 } from "./components/hook-form/RHFAutocompleteAsync/dictionary.js";
|
|
32
32
|
import { R as R3 } from "./components/hook-form/RHFDateTime/RHFDateTime.js";
|
|
33
33
|
import { R as R4 } from "./components/hook-form/RHFMultiCheckbox/index.js";
|
|
34
|
-
import { R as R5 } from "./components/hook-form/RHFSelect.js";
|
|
34
|
+
import { R as R5 } from "./components/hook-form/RHFSelect/RHFSelect.js";
|
|
35
35
|
import { R as R6 } from "./components/hook-form/RHFHelperError/index.js";
|
|
36
36
|
import { R as R7 } from "./components/hook-form/RHFPeriod/RHFPeriod.js";
|
|
37
37
|
import { g as g6 } from "./components/Period/dictionary.js";
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TextFieldProps } from '@mui/material';
|
|
2
|
-
interface IProps {
|
|
3
|
-
name: string;
|
|
4
|
-
children: any;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* TODO: Documentar
|
|
8
|
-
*/
|
|
9
|
-
export declare function RHFSelect({ name, children, ...other }: IProps & TextFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useFormContext, Controller } from "react-hook-form";
|
|
3
|
-
import { TextField } from "@mui/material";
|
|
4
|
-
function RHFSelect({ name, children, ...other }) {
|
|
5
|
-
const { control } = useFormContext();
|
|
6
|
-
return /* @__PURE__ */ jsx(
|
|
7
|
-
Controller,
|
|
8
|
-
{
|
|
9
|
-
name,
|
|
10
|
-
control,
|
|
11
|
-
render: ({ field, fieldState: { error } }) => /* @__PURE__ */ jsx(
|
|
12
|
-
TextField,
|
|
13
|
-
{
|
|
14
|
-
...field,
|
|
15
|
-
select: true,
|
|
16
|
-
fullWidth: true,
|
|
17
|
-
SelectProps: { native: true },
|
|
18
|
-
error: !!error,
|
|
19
|
-
helperText: error?.message,
|
|
20
|
-
...other,
|
|
21
|
-
children
|
|
22
|
-
}
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
RHFSelect as R
|
|
29
|
-
};
|