@m4l/components 9.1.53 → 9.1.55
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 +10 -1
- package/components/Chip/Chip.js +108 -0
- package/components/Chip/ChipStyles.js +533 -0
- package/components/Chip/constants.d.ts +4 -0
- package/components/Chip/constants.js +8 -0
- package/components/Chip/slots/ChipEnum.d.ts +7 -7
- package/components/Chip/slots/ChipEnum.js +11 -0
- package/components/Chip/slots/ChipSlots.js +35 -0
- package/components/Chip/slots/index.js +1 -0
- package/components/Chip/types.d.ts +41 -11
- package/components/DynamicFilter/types.d.ts +2 -2
- package/components/Label/Label.styles.js +28 -8
- package/components/SideBar/subcomponents/ContentGroups/subcomponents/ContainerMenuItemsMain/styles.js +9 -21
- package/components/hook-form/RHFAutocomplete/RFHAutocompleteStyles.d.ts +2 -0
- package/components/hook-form/RHFAutocomplete/RFHAutocompleteStyles.js +24 -0
- package/components/hook-form/RHFAutocomplete/RHFAutocomplete.d.ts +3 -5
- package/components/hook-form/RHFAutocomplete/RHFAutocomplete.js +161 -4
- package/components/hook-form/RHFAutocomplete/RHFAutocomplete.test.d.ts +1 -0
- package/components/hook-form/RHFAutocomplete/constants.d.ts +9 -0
- package/components/hook-form/RHFAutocomplete/constants.js +4 -0
- package/components/hook-form/RHFAutocomplete/oldTypes.d.ts +43 -0
- package/components/hook-form/RHFAutocomplete/slots/RHFAutocompleteEnum.d.ts +4 -0
- package/components/hook-form/RHFAutocomplete/slots/RHFAutocompleteEnum.js +8 -0
- package/components/hook-form/RHFAutocomplete/slots/RHFAutocompleteSlots.d.ts +6 -0
- package/components/hook-form/RHFAutocomplete/slots/RHFAutocompleteSlots.js +17 -0
- package/components/hook-form/RHFAutocomplete/slots/index.d.ts +2 -0
- package/components/hook-form/RHFAutocomplete/slots/index.js +1 -0
- package/components/hook-form/RHFAutocomplete/types.d.ts +63 -25
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsync.d.ts +5 -8
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsync.js +105 -4
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsyncStyles.d.ts +2 -0
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsyncStyles.js +6 -0
- package/components/hook-form/RHFAutocompleteAsync/constants.d.ts +9 -0
- package/components/hook-form/RHFAutocompleteAsync/constants.js +4 -0
- package/components/hook-form/RHFAutocompleteAsync/slots/RHFAutocompleteEnumAsync.d.ts +3 -0
- package/components/hook-form/RHFAutocompleteAsync/slots/RHFAutocompleteEnumAsync.js +7 -0
- package/components/hook-form/RHFAutocompleteAsync/slots/RHFAutocompleteSlotsAsync.d.ts +1 -0
- package/components/hook-form/RHFAutocompleteAsync/slots/RHFAutocompleteSlotsAsync.js +12 -0
- package/components/hook-form/RHFAutocompleteAsync/slots/index.d.ts +2 -0
- package/components/hook-form/RHFAutocompleteAsync/slots/index.js +1 -0
- package/components/hook-form/RHFAutocompleteAsync/types.d.ts +19 -5
- package/components/mui_extended/Autocomplete/Autocomplete.d.ts +1 -1
- package/components/mui_extended/Autocomplete/Autocomplete.js +299 -0
- package/components/mui_extended/Autocomplete/AutocompleteStyles.js +136 -0
- package/components/mui_extended/Autocomplete/constants.js +4 -0
- package/components/mui_extended/Autocomplete/dictionary.d.ts +0 -2
- package/components/mui_extended/Autocomplete/index.js +1 -0
- package/components/mui_extended/Autocomplete/renderOptions/index.d.ts +3 -0
- package/components/mui_extended/Autocomplete/renderOptions/index.js +24 -0
- package/components/mui_extended/Autocomplete/slots /AutocompleteEnum.d.ts +2 -1
- package/components/mui_extended/Autocomplete/slots /AutocompleteEnum.js +19 -0
- package/components/mui_extended/Autocomplete/slots /AutocompleteSlots.d.ts +3 -0
- package/components/mui_extended/Autocomplete/slots /AutocompleteSlots.js +72 -0
- package/components/mui_extended/Autocomplete/slots /index.js +1 -0
- package/components/mui_extended/Autocomplete/types.d.ts +2 -2
- package/components/mui_extended/CircularProgress/CircularProgress.js +1 -1
- package/components/mui_extended/MenuItem/MenuItem.js +11 -12
- package/components/mui_extended/MenuItem/MenuItem.styles.js +56 -66
- package/components/mui_extended/MenuItem/constants.d.ts +4 -0
- package/components/mui_extended/MenuItem/constants.js +5 -1
- package/components/mui_extended/MenuItem/slots/MenuItemEnum.d.ts +1 -1
- package/components/mui_extended/MenuItem/slots/MenuItemEnum.js +1 -1
- package/components/mui_extended/MenuItem/slots/MenuItemSlots.js +3 -3
- package/components/mui_extended/MenuItem/types.d.ts +32 -11
- package/components/mui_extended/Pager/classes/index.d.ts +1 -1
- package/components/mui_extended/Popper/Popper.js +79 -0
- package/components/mui_extended/Popper/PopperStyles.js +265 -0
- package/components/mui_extended/Popper/constants.js +4 -0
- package/components/mui_extended/Popper/index.js +1 -0
- package/components/mui_extended/Popper/slots/PopperEnum.js +6 -0
- package/components/mui_extended/Popper/slots/PopperStlots.js +12 -0
- package/components/mui_extended/Popper/slots/index.js +1 -0
- package/components/mui_extended/Popper/types.js +1 -0
- package/components/mui_extended/Select/slots/SelectSlots.d.ts +1 -1
- package/components/mui_extended/Select/slots/SelectSlots.js +1 -1
- package/components/mui_extended/TextField/TextField.js +11 -11
- package/components/mui_extended/TextField/TextField.styles.js +108 -203
- package/components/mui_extended/TextField/constants.d.ts +10 -0
- package/components/mui_extended/TextField/constants.js +8 -3
- package/components/mui_extended/TextField/slots/TextFieldEnum.d.ts +4 -0
- package/components/mui_extended/TextField/slots/TextFieldEnum.js +7 -1
- package/components/mui_extended/TextField/slots/TextFieldSlots.js +1 -1
- package/components/mui_extended/TextField/types.d.ts +3 -4
- package/components/mui_extended/Typography/Typography.js +4 -3
- package/components/mui_extended/Typography/constants.d.ts +4 -0
- package/components/mui_extended/Typography/constants.js +5 -1
- package/components/mui_extended/Typography/slots/typographySlots.js +1 -1
- package/package.json +1 -1
- package/utils/getHeightSizeStyles.d.ts +12 -0
- package/utils/getHeightSizeStyles.js +13 -0
- package/components/hook-form/RHFAutocomplete/classes/constant.d.ts +0 -1
- package/components/hook-form/RHFAutocomplete/classes/constant.js +0 -4
- package/components/hook-form/RHFAutocomplete/classes/index.d.ts +0 -19
- package/components/hook-form/RHFAutocomplete/classes/index.js +0 -77
- package/components/hook-form/RHFAutocomplete/classes/types.d.ts +0 -26
- package/components/hook-form/RHFAutocomplete/styles.d.ts +0 -1
- package/components/hook-form/RHFAutocomplete/styles.js +0 -7
- package/components/hook-form/RHFAutocomplete/subcomponents/ComponentTypeImage/index.d.ts +0 -5
- package/components/hook-form/RHFAutocomplete/subcomponents/ComponentTypeImage/index.js +0 -293
- package/components/hook-form/RHFAutocomplete/subcomponents/ComponentTypeText/index.d.ts +0 -9
- package/components/hook-form/RHFAutocomplete/subcomponents/ComponentTypeText/index.js +0 -281
- package/components/hook-form/RHFAutocomplete/subcomponents/RenderOption/index.d.ts +0 -6
- package/components/hook-form/RHFAutocomplete/subcomponents/RenderOption/index.js +0 -25
- package/components/hook-form/RHFAutocomplete/subcomponents/RenderOption/styles.d.ts +0 -1
- package/components/hook-form/RHFAutocomplete/subcomponents/RenderOption/styles.js +0 -9
- package/components/hook-form/RHFAutocomplete/subcomponents/Skeleton/index.d.ts +0 -5
- package/components/hook-form/RHFAutocomplete/subcomponents/Skeleton/index.js +0 -28
- package/components/hook-form/RHFAutocomplete/subcomponents/Skeleton/types.d.ts +0 -6
- package/components/hook-form/RHFAutocomplete/test/constants.d.ts +0 -2
- package/components/hook-form/RHFAutocomplete/test/constants.js +0 -6
- package/components/hook-form/RHFAutocomplete/test/utils.d.ts +0 -2
- package/components/hook-form/RHFAutocomplete/test/utils.js +0 -7
- package/components/hook-form/RHFAutocompleteAsync/classes/constant.d.ts +0 -1
- package/components/hook-form/RHFAutocompleteAsync/classes/constant.js +0 -4
- package/components/hook-form/RHFAutocompleteAsync/classes/index.d.ts +0 -9
- package/components/hook-form/RHFAutocompleteAsync/classes/index.js +0 -26
- package/components/hook-form/RHFAutocompleteAsync/classes/types.d.ts +0 -4
- package/components/hook-form/RHFAutocompleteAsync/styles.d.ts +0 -4
- package/components/hook-form/RHFAutocompleteAsync/styles.js +0 -34
- package/components/hook-form/RHFAutocompleteAsync/subcomponents/ComponentTypeImage/index.d.ts +0 -10
- package/components/hook-form/RHFAutocompleteAsync/subcomponents/ComponentTypeImage/index.js +0 -103
- package/components/hook-form/RHFAutocompleteAsync/subcomponents/ComponentTypeText/index.d.ts +0 -9
- package/components/hook-form/RHFAutocompleteAsync/subcomponents/ComponentTypeText/index.js +0 -103
- package/components/hook-form/RHFAutocompleteAsync/tests/constants.d.ts +0 -1
- package/components/hook-form/RHFAutocompleteAsync/tests/constants.js +0 -4
- package/components/hook-form/RHFAutocompleteAsync/tests/utils.d.ts +0 -2
- package/components/hook-form/RHFAutocompleteAsync/tests/utils.js +0 -7
|
@@ -1,43 +1,81 @@
|
|
|
1
|
-
import { AutocompleteCloseReason, AutocompleteInputChangeReason,
|
|
1
|
+
import { AutocompleteChangeReason, AutocompleteCloseReason, AutocompleteFreeSoloValueMapping, AutocompleteInputChangeReason, AutocompleteValue, AutocompleteProps as MUIAutocompleteProps, Theme, PaletteColor, PopperProps } from '@mui/material';
|
|
2
|
+
import { ComponentPalletColor, Sizes } from '@m4l/styles';
|
|
3
|
+
import { ChangeEvent } from 'react';
|
|
4
|
+
import { TextFieldProps } from '../../mui_extended/TextField/types';
|
|
5
|
+
import { RFHAUTOCOMPLETE_KEY_COMPONENT } from './constants';
|
|
6
|
+
import { OverridesStyleRules } from '@mui/material/styles/overrides';
|
|
7
|
+
import { RFHAutocompleteSlots } from './slots';
|
|
2
8
|
import { LabelProps } from '../../Label/types';
|
|
3
9
|
export type GetOptionString<T> = (option: T | null) => string;
|
|
4
|
-
export type RHFAutocompleteVariants = '
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export interface RHFAutocompleteBaseProps<T> extends Omit<TextFieldProps, 'label' | 'variant'>, Omit<LabelProps, 'label'> {
|
|
10
|
+
export type RHFAutocompleteVariants = 'outlined' | 'text';
|
|
11
|
+
export type RHFAutocompleteType = 'text' | 'image';
|
|
12
|
+
/**
|
|
13
|
+
* Props for the unified Autocomplete component.
|
|
14
|
+
* Supports both single and multiple selection, and two types: `text` and `image`.
|
|
15
|
+
* @createdAt 2024-11-28 17:06:36 - automatic
|
|
16
|
+
*/
|
|
17
|
+
export interface RHFAutocompleteProps<T, Multiple extends boolean | undefined = true, DisableClearable extends boolean | undefined = true, FreeSolo extends boolean | undefined = false> extends Omit<MUIAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>, 'variant' | 'color' | 'size' | 'onChange' | 'value' | 'classes' | 'defaultValue' | 'onBlur' | 'onFocus' | 'autoComplete' | 'renderInput'>, Omit<TextFieldProps, 'label' | 'variant' | 'defaultValue' | 'classes' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'ref' | 'onChange'>, Omit<LabelProps, 'label'> {
|
|
13
18
|
name: string;
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The label for the autocomplete field.
|
|
21
|
+
*/
|
|
22
|
+
popperProps?: Omit<PopperProps, 'color'>;
|
|
23
|
+
onFocus?: (event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
24
|
+
autoComplete?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The value of the autocomplete, supports single or multiple selection.
|
|
27
|
+
* Extended to include `null` for controlled components.
|
|
28
|
+
* @createdAt 2024-11-28 17:06:36 - automatic
|
|
29
|
+
*/
|
|
30
|
+
value?: AutocompleteValue<T, Multiple, DisableClearable, FreeSolo> | null | undefined;
|
|
31
|
+
size?: Extract<Sizes, 'small' | 'medium'>;
|
|
32
|
+
variant?: RHFAutocompleteVariants;
|
|
33
|
+
color?: Extract<ComponentPalletColor, 'primary'>;
|
|
34
|
+
dataTestid?: string;
|
|
35
|
+
options: T[];
|
|
36
|
+
getOptionLabel: (option: T | AutocompleteFreeSoloValueMapping<FreeSolo>) => string;
|
|
16
37
|
isOptionEqualToValue: (option: T, value: T) => boolean;
|
|
17
38
|
skeletonWidth?: string | number;
|
|
18
|
-
skeletonHeight?: string | number;
|
|
19
39
|
loading?: boolean;
|
|
20
40
|
refresh?: () => void;
|
|
21
41
|
label?: string;
|
|
22
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Whether the controller detected an error on component.
|
|
44
|
+
*/
|
|
23
45
|
helperMessage?: string;
|
|
24
46
|
onOpen?: (event: React.SyntheticEvent) => void;
|
|
25
47
|
onClose?: (event: React.SyntheticEvent, reason: AutocompleteCloseReason) => void;
|
|
26
48
|
onChangeFilterParmsLocal?: (newValue: string, reason: AutocompleteInputChangeReason) => void;
|
|
27
|
-
multiple?:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
multiple?: Multiple;
|
|
50
|
+
type?: RHFAutocompleteType;
|
|
51
|
+
getOptionUrlImage?: (option: T) => string;
|
|
52
|
+
imageScale?: boolean;
|
|
53
|
+
imageRepeat?: boolean;
|
|
54
|
+
customError?: {
|
|
55
|
+
message: string;
|
|
56
|
+
};
|
|
57
|
+
onChange?: (event: ChangeEvent<{}> | undefined, value: T | T[] | null, reason: AutocompleteChangeReason) => void;
|
|
58
|
+
renderInput?: MUIAutocompleteProps<T, Multiple, DisableClearable, FreeSolo>['renderInput'];
|
|
35
59
|
}
|
|
36
|
-
|
|
37
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Represents the owner state of the Autocomplete component for styling purposes.
|
|
62
|
+
*/
|
|
63
|
+
export interface RHFAutocompleteOwnerState extends Pick<RHFAutocompleteProps<any>, 'size' | 'disabled' | 'variant'> {
|
|
64
|
+
autocompleteColor: RHFAutocompleteProps<any>['color'];
|
|
65
|
+
disabled?: boolean;
|
|
38
66
|
isFocus: boolean;
|
|
39
67
|
isTabSelected: boolean;
|
|
40
68
|
semantics: RHFAutocompleteVariants | 'error' | null;
|
|
41
|
-
variant?: 'withImage';
|
|
42
69
|
multiple: boolean;
|
|
70
|
+
imageScale?: boolean;
|
|
71
|
+
imageRepeat?: boolean;
|
|
72
|
+
paletteColor: PaletteColor;
|
|
43
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Defines the types of Slots available for the Autocomplete.
|
|
76
|
+
*/
|
|
77
|
+
export type RHFAutocompleteSlotsType = keyof typeof RFHAutocompleteSlots;
|
|
78
|
+
/**
|
|
79
|
+
* Styles applicable to the Autocomplete using themes and custom slots.
|
|
80
|
+
*/
|
|
81
|
+
export type RHFAutocompleteStyles = Partial<OverridesStyleRules<RHFAutocompleteSlotsType, typeof RFHAUTOCOMPLETE_KEY_COMPONENT, Theme>> | undefined;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RHFAutocompleteAsyncBaseProps } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param props
|
|
5
|
-
* @returns
|
|
3
|
+
* RHFAutocompleteProps is a component that handles asynchronous autocomplete functionality.
|
|
4
|
+
* @param props - The properties passed to the component.
|
|
5
|
+
* @returns A React component.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
* TODO: Documentar
|
|
9
|
-
*/
|
|
10
|
-
export declare function RHFAutocompleteAsync<T>(props: RHFAutocompleteAsyncProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function RHFAutocompleteAsync<T>(props: RHFAutocompleteAsyncBaseProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,8 +1,109 @@
|
|
|
1
|
-
import { jsx
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useNetwork, getPropertyByString } from "@m4l/core";
|
|
3
|
+
import debounce from "lodash-es/debounce";
|
|
4
|
+
import { useState, useCallback, useEffect } from "react";
|
|
5
|
+
import { R as RHFAutocompleteAsyncRootStyled } from "./slots/RHFAutocompleteSlotsAsync.js";
|
|
4
6
|
function RHFAutocompleteAsync(props) {
|
|
5
|
-
|
|
7
|
+
const {
|
|
8
|
+
name,
|
|
9
|
+
endPoint,
|
|
10
|
+
timeout = 5e3,
|
|
11
|
+
parms,
|
|
12
|
+
resultField = "data",
|
|
13
|
+
size,
|
|
14
|
+
isRemote = true,
|
|
15
|
+
isExternalUrl = false,
|
|
16
|
+
onChangeFilterParms,
|
|
17
|
+
onChange,
|
|
18
|
+
onOpen,
|
|
19
|
+
onClose,
|
|
20
|
+
getOptionLabel,
|
|
21
|
+
isOptionEqualToValue,
|
|
22
|
+
multiple,
|
|
23
|
+
disabled,
|
|
24
|
+
skeletonWidth,
|
|
25
|
+
open,
|
|
26
|
+
value
|
|
27
|
+
} = props;
|
|
28
|
+
const { networkOperation } = useNetwork();
|
|
29
|
+
const [options, setOptions] = useState([]);
|
|
30
|
+
const [firstOpen, setFirstOpen] = useState(0);
|
|
31
|
+
const [loading, setIsloading] = useState(false);
|
|
32
|
+
const [newRefresh, setNewRefresh] = useState(0);
|
|
33
|
+
const [canLoadOptions, setCanLoadOptions] = useState(true);
|
|
34
|
+
const [filterParms, setFilterParms] = useState({});
|
|
35
|
+
const refresh = () => {
|
|
36
|
+
setNewRefresh((current) => current + 1);
|
|
37
|
+
firstOpen === 0 && hanldeFirstOpen();
|
|
38
|
+
};
|
|
39
|
+
const debouncedFilter = useCallback(
|
|
40
|
+
debounce(
|
|
41
|
+
(newFilterParms) => {
|
|
42
|
+
setCanLoadOptions(true);
|
|
43
|
+
setFilterParms(newFilterParms);
|
|
44
|
+
},
|
|
45
|
+
300
|
|
46
|
+
),
|
|
47
|
+
[setCanLoadOptions, setFilterParms]
|
|
48
|
+
);
|
|
49
|
+
const onChangeFilterParmsLocal = (newValue) => {
|
|
50
|
+
if (onChangeFilterParms) {
|
|
51
|
+
debouncedFilter(onChangeFilterParms(newValue));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
setCanLoadOptions(true);
|
|
56
|
+
}, [parms, endPoint]);
|
|
57
|
+
const hanldeFirstOpen = () => {
|
|
58
|
+
if (firstOpen === 0) {
|
|
59
|
+
setFirstOpen(1);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (firstOpen === 1 && !loading && canLoadOptions) {
|
|
64
|
+
setIsloading(true);
|
|
65
|
+
setOptions([]);
|
|
66
|
+
setCanLoadOptions(false);
|
|
67
|
+
networkOperation({
|
|
68
|
+
method: "GET",
|
|
69
|
+
endPoint,
|
|
70
|
+
timeout,
|
|
71
|
+
isExternalUrl,
|
|
72
|
+
parms: { ...parms, ...filterParms },
|
|
73
|
+
isRemote
|
|
74
|
+
}).then((response) => {
|
|
75
|
+
const valueMaybeArray = getPropertyByString(response, resultField);
|
|
76
|
+
const newOptions = Array.isArray(valueMaybeArray) ? valueMaybeArray : [];
|
|
77
|
+
setOptions(newOptions);
|
|
78
|
+
}).finally(() => {
|
|
79
|
+
setIsloading(false);
|
|
80
|
+
setCanLoadOptions(true);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return () => {
|
|
84
|
+
};
|
|
85
|
+
}, [firstOpen, parms, filterParms, endPoint, newRefresh]);
|
|
86
|
+
return /* @__PURE__ */ jsx(
|
|
87
|
+
RHFAutocompleteAsyncRootStyled,
|
|
88
|
+
{
|
|
89
|
+
name,
|
|
90
|
+
loading,
|
|
91
|
+
options,
|
|
92
|
+
onChangeFilterParmsLocal: onChangeFilterParms ? onChangeFilterParmsLocal : void 0,
|
|
93
|
+
size,
|
|
94
|
+
refresh: () => refresh(),
|
|
95
|
+
onOpen,
|
|
96
|
+
onChange,
|
|
97
|
+
getOptionLabel,
|
|
98
|
+
isOptionEqualToValue,
|
|
99
|
+
multiple,
|
|
100
|
+
disabled,
|
|
101
|
+
onClose,
|
|
102
|
+
skeletonWidth,
|
|
103
|
+
open,
|
|
104
|
+
value
|
|
105
|
+
}
|
|
106
|
+
);
|
|
6
107
|
}
|
|
7
108
|
export {
|
|
8
109
|
RHFAutocompleteAsync as R
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clave de identificación del componente Autocomplete dentro del sistema.
|
|
3
|
+
*
|
|
4
|
+
* Esta constante se utiliza como identificador único para asociar y personalizar estilos y configuraciones
|
|
5
|
+
* relacionadas con el componente `RHFAutocompleteAsync` dentro del sistema de temas y estilos.
|
|
6
|
+
* @default 'RHFM4LAutocomplete'
|
|
7
|
+
*/
|
|
8
|
+
export declare const RFHAUTOCOMPLETEASYNC_KEY_COMPONENT = "RHFM4LAutocompleteAsync";
|
|
9
|
+
export declare const RFHAUTOCOMPLETEASYNC_CLASS_NAME_SPECIFY = "RHFM4LclasssAutocompleCssSpecificityAsync";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var RHFAutocompleteAsyncSlots = /* @__PURE__ */ ((RHFAutocompleteAsyncSlots2) => {
|
|
2
|
+
RHFAutocompleteAsyncSlots2["autocompleteAsyncRoot"] = "autocompleteAsyncRoot";
|
|
3
|
+
return RHFAutocompleteAsyncSlots2;
|
|
4
|
+
})(RHFAutocompleteAsyncSlots || {});
|
|
5
|
+
export {
|
|
6
|
+
RHFAutocompleteAsyncSlots as R
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RHFAutocompleteAsyncRootStyled: import('@emotion/styled').StyledComponent<Pick<import('../../RHFAutocomplete/types').RHFAutocompleteProps<unknown, true, true, false>, keyof import('../../RHFAutocomplete/types').RHFAutocompleteProps<unknown, true, true, false>> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme> & Record<string, unknown>, {}, {}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { styled } from "@mui/material";
|
|
2
|
+
import { r as rhfAutocompleteAsyncSyles } from "../RHFAutocompleteAsyncStyles.js";
|
|
3
|
+
import { R as RFHAUTOCOMPLETEASYNC_KEY_COMPONENT } from "../constants.js";
|
|
4
|
+
import { R as RHFAutocompleteAsyncSlots } from "./RHFAutocompleteEnumAsync.js";
|
|
5
|
+
import { R as RHFAutocomplete } from "../../RHFAutocomplete/RHFAutocomplete.js";
|
|
6
|
+
const RHFAutocompleteAsyncRootStyled = styled(RHFAutocomplete, {
|
|
7
|
+
name: RFHAUTOCOMPLETEASYNC_KEY_COMPONENT,
|
|
8
|
+
slot: RHFAutocompleteAsyncSlots.autocompleteAsyncRoot
|
|
9
|
+
})(rhfAutocompleteAsyncSyles?.autocompleteAsyncRoot);
|
|
10
|
+
export {
|
|
11
|
+
RHFAutocompleteAsyncRootStyled as R
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,12 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { AutocompleteChangeReason, Theme } from '@mui/material';
|
|
2
|
+
import { OverridesStyleRules } from '@mui/material/styles/overrides';
|
|
3
|
+
import { ChangeEvent } from 'react';
|
|
4
|
+
import { RHFAutocompleteProps } from '../RHFAutocomplete/types';
|
|
5
|
+
import { RFHAUTOCOMPLETEASYNC_KEY_COMPONENT } from './constants';
|
|
6
|
+
import { RHFAutocompleteAsyncSlots } from './slots';
|
|
7
|
+
export interface RHFAutocompleteAsyncBaseProps<T> extends Omit<RHFAutocompleteProps<T>, 'options' | 'onChangeSearchInput' | 'get' | 'onChange' | 'getOptionLabel' | 'isOptionEqualToValue'> {
|
|
3
8
|
endPoint: string;
|
|
4
9
|
timeout?: number;
|
|
5
10
|
parms?: Record<string, any>;
|
|
11
|
+
isExternalUrl?: boolean;
|
|
6
12
|
resultField?: string;
|
|
7
13
|
isRemote?: boolean;
|
|
14
|
+
onChange?: (event: ChangeEvent<{}> | undefined, value: unknown, reason: AutocompleteChangeReason) => void;
|
|
15
|
+
getOptionLabel: (option: unknown) => string;
|
|
16
|
+
isOptionEqualToValue: (option: unknown, value: unknown) => boolean;
|
|
8
17
|
onChangeFilterParms?: (newValue: string) => Record<string, any>;
|
|
9
18
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Defines the types of Slots available for the Autocomplete.
|
|
21
|
+
*/
|
|
22
|
+
export type RHFAutocompleteAsyncSlotsType = keyof typeof RHFAutocompleteAsyncSlots;
|
|
23
|
+
/**
|
|
24
|
+
* Styles applicable to the Autocomplete using themes and custom slots.
|
|
25
|
+
*/
|
|
26
|
+
export type RHFAutocompleteAyncStyles = Partial<OverridesStyleRules<RHFAutocompleteAsyncSlotsType, typeof RFHAUTOCOMPLETEASYNC_KEY_COMPONENT, Theme>> | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AutocompleteProps } from './types';
|
|
2
|
-
export declare const Autocomplete: import('react').ForwardRefExoticComponent<Omit<AutocompleteProps<unknown,
|
|
2
|
+
export declare const Autocomplete: import('react').ForwardRefExoticComponent<Omit<AutocompleteProps<unknown, true, true, false>, "ref"> & import('react').RefAttributes<HTMLInputElement | HTMLTextAreaElement>>;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useModuleDictionary, useModuleSkeleton, useEnvironment, getPropertyByString } from "@m4l/core";
|
|
3
|
+
import { useTheme } from "@mui/material";
|
|
4
|
+
import { forwardRef, useState, useMemo, useEffect, useCallback } from "react";
|
|
5
|
+
import { w as withRenderOption } from "./renderOptions/index.js";
|
|
6
|
+
import { u as useComponentSize } from "../../../hooks/useComponentSize/useComponentSize.js";
|
|
7
|
+
import { A as AutocompleteStyled, P as PopperComponentStyled, R as RenderInputStyled, C as ChipStyled, I as ImageStyled, a as CircularProgressStyled, b as IconButtonStyled } from "./slots /AutocompleteSlots.js";
|
|
8
|
+
import { T as Typography } from "../Typography/Typography.js";
|
|
9
|
+
const Autocomplete = forwardRef(function Autocomplete2(props, ref) {
|
|
10
|
+
const {
|
|
11
|
+
getOptionLabel,
|
|
12
|
+
isOptionEqualToValue,
|
|
13
|
+
skeletonWidth = 100,
|
|
14
|
+
options,
|
|
15
|
+
disabled,
|
|
16
|
+
onOpen,
|
|
17
|
+
onClose,
|
|
18
|
+
loading,
|
|
19
|
+
variant = "outlined",
|
|
20
|
+
helperMessage,
|
|
21
|
+
size = "medium",
|
|
22
|
+
onChangeFilterParmsLocal,
|
|
23
|
+
multiple,
|
|
24
|
+
imageScale = true,
|
|
25
|
+
//Diferencia
|
|
26
|
+
imageRepeat,
|
|
27
|
+
// Diferencia
|
|
28
|
+
getOptionUrlImage,
|
|
29
|
+
// Diferencia
|
|
30
|
+
type = "outlined",
|
|
31
|
+
color = "primary",
|
|
32
|
+
refresh,
|
|
33
|
+
error = false,
|
|
34
|
+
onChange,
|
|
35
|
+
value,
|
|
36
|
+
customError,
|
|
37
|
+
...other
|
|
38
|
+
} = props;
|
|
39
|
+
const { getLabel } = useModuleDictionary();
|
|
40
|
+
useModuleSkeleton();
|
|
41
|
+
const theme = useTheme();
|
|
42
|
+
const { host_static_assets, environment_assets } = useEnvironment();
|
|
43
|
+
const [open, setOpen] = useState(false);
|
|
44
|
+
const { currentSize } = useComponentSize(size);
|
|
45
|
+
const adjustedSize = currentSize === "small" || currentSize === "medium" ? currentSize : "medium";
|
|
46
|
+
useMemo(
|
|
47
|
+
() => getOptionUrlImage !== void 0,
|
|
48
|
+
[getOptionUrlImage]
|
|
49
|
+
);
|
|
50
|
+
const [selectedValue, setSelectedValue] = useState(
|
|
51
|
+
value || (multiple ? [] : null)
|
|
52
|
+
);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!multiple && value) {
|
|
55
|
+
setInputValue(getOptionLabel(value));
|
|
56
|
+
} else if (multiple && Array.isArray(value)) {
|
|
57
|
+
setInputValue("");
|
|
58
|
+
} else {
|
|
59
|
+
setInputValue("");
|
|
60
|
+
}
|
|
61
|
+
setSelectedValue(value || (multiple ? [] : null));
|
|
62
|
+
}, [value, multiple, getOptionLabel]);
|
|
63
|
+
const handleDelete = (optionToDelete) => {
|
|
64
|
+
if (Array.isArray(selectedValue)) {
|
|
65
|
+
const updatedValue = selectedValue.filter(
|
|
66
|
+
(val) => !isOptionEqualToValueLocal(val, optionToDelete)
|
|
67
|
+
);
|
|
68
|
+
setSelectedValue(updatedValue);
|
|
69
|
+
onChange?.(
|
|
70
|
+
{},
|
|
71
|
+
updatedValue,
|
|
72
|
+
"removeOption"
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const handleRefresh = () => {
|
|
77
|
+
refresh?.();
|
|
78
|
+
setOpen(true);
|
|
79
|
+
};
|
|
80
|
+
const handleChange = (event, newSelectedValue, reason) => {
|
|
81
|
+
const updatedValue = multiple ? Array.isArray(newSelectedValue) ? newSelectedValue : [] : newSelectedValue;
|
|
82
|
+
setSelectedValue(updatedValue);
|
|
83
|
+
setInputValue(
|
|
84
|
+
!multiple && updatedValue ? getOptionLabel(updatedValue) : ""
|
|
85
|
+
);
|
|
86
|
+
onChange?.(event, updatedValue, reason);
|
|
87
|
+
};
|
|
88
|
+
const handleInputChange = (_event, newValue, reason) => {
|
|
89
|
+
setInputValue(newValue);
|
|
90
|
+
if (reason === "input" && onChangeFilterParmsLocal) {
|
|
91
|
+
onChangeFilterParmsLocal(newValue, reason);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const isOptionEqualToValueLocal = useCallback(
|
|
95
|
+
(option, val) => {
|
|
96
|
+
if (val === null || val === void 0) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return isOptionEqualToValue(option, val);
|
|
100
|
+
},
|
|
101
|
+
[isOptionEqualToValue]
|
|
102
|
+
);
|
|
103
|
+
const onCloseLocal = (event, reason) => {
|
|
104
|
+
setOpen(false);
|
|
105
|
+
if (onClose) {
|
|
106
|
+
onClose(event, reason);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const onOpenLocal = (event) => {
|
|
110
|
+
setOpen((currentState) => !currentState);
|
|
111
|
+
if (onOpen) {
|
|
112
|
+
onOpen(event);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const getOptionLabelLocal = useCallback(
|
|
116
|
+
(option) => {
|
|
117
|
+
if (typeof option === "string") {
|
|
118
|
+
return option;
|
|
119
|
+
}
|
|
120
|
+
if (option === null || option === void 0) {
|
|
121
|
+
return "";
|
|
122
|
+
}
|
|
123
|
+
return getOptionLabel(option);
|
|
124
|
+
},
|
|
125
|
+
[getOptionLabel]
|
|
126
|
+
);
|
|
127
|
+
const getOptionUrlImageLocal = (option) => {
|
|
128
|
+
if (option === void 0 || option === null || getOptionUrlImage === void 0) {
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
return getOptionUrlImage(option);
|
|
132
|
+
};
|
|
133
|
+
const paletteColor = getPropertyByString(
|
|
134
|
+
theme.vars.palette,
|
|
135
|
+
disabled ? "default" : color || "default",
|
|
136
|
+
theme.vars.palette.default
|
|
137
|
+
);
|
|
138
|
+
const ownerState = {
|
|
139
|
+
size: adjustedSize,
|
|
140
|
+
variant,
|
|
141
|
+
disabled,
|
|
142
|
+
paletteColor,
|
|
143
|
+
autocompleteColor: color,
|
|
144
|
+
imageScale: Boolean(imageScale),
|
|
145
|
+
multiple: Boolean(multiple)
|
|
146
|
+
};
|
|
147
|
+
const [inputValue, setInputValue] = useState("");
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (!open && value === null && inputValue !== "") {
|
|
150
|
+
setInputValue("");
|
|
151
|
+
}
|
|
152
|
+
if (!open && value !== null && options && options.length === 0) {
|
|
153
|
+
onChangeFilterParmsLocal?.(
|
|
154
|
+
getOptionLabelLocal(Array.isArray(value) ? value[0] : value),
|
|
155
|
+
"reset"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}, [
|
|
159
|
+
value,
|
|
160
|
+
open,
|
|
161
|
+
inputValue,
|
|
162
|
+
onChangeFilterParmsLocal,
|
|
163
|
+
getOptionLabelLocal,
|
|
164
|
+
options
|
|
165
|
+
]);
|
|
166
|
+
const checkKeyDown = (e) => {
|
|
167
|
+
if (e.code === "Enter") {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
return /* @__PURE__ */ jsx(
|
|
172
|
+
AutocompleteStyled,
|
|
173
|
+
{
|
|
174
|
+
ownerState: { ...ownerState },
|
|
175
|
+
tabIndex: 0,
|
|
176
|
+
disableClearable: true,
|
|
177
|
+
multiple,
|
|
178
|
+
onKeyDown: checkKeyDown,
|
|
179
|
+
size: adjustedSize,
|
|
180
|
+
ref,
|
|
181
|
+
autoSelect: false,
|
|
182
|
+
options,
|
|
183
|
+
getOptionLabel: getOptionLabelLocal,
|
|
184
|
+
clearOnBlur: false,
|
|
185
|
+
PopperComponent: (popperProps) => {
|
|
186
|
+
const { color: popperColor, ...otherPopperProps } = popperProps;
|
|
187
|
+
return /* @__PURE__ */ jsx(
|
|
188
|
+
PopperComponentStyled,
|
|
189
|
+
{
|
|
190
|
+
...otherPopperProps,
|
|
191
|
+
size: adjustedSize,
|
|
192
|
+
placement: "bottom-start",
|
|
193
|
+
ownerState: { ...ownerState }
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
isOptionEqualToValue: isOptionEqualToValueLocal,
|
|
198
|
+
value: selectedValue,
|
|
199
|
+
inputValue,
|
|
200
|
+
onOpen: onOpenLocal,
|
|
201
|
+
onClose: onCloseLocal,
|
|
202
|
+
open,
|
|
203
|
+
onInputChange: handleInputChange,
|
|
204
|
+
onChange: handleChange,
|
|
205
|
+
filterOptions: onChangeFilterParmsLocal ? (x) => x : void 0,
|
|
206
|
+
loading,
|
|
207
|
+
loadingText: /* @__PURE__ */ jsx(Typography, { variant: "body", size: adjustedSize, children: getLabel("autocomplete.loading_options") }),
|
|
208
|
+
disabled,
|
|
209
|
+
noOptionsText: /* @__PURE__ */ jsx(Typography, { variant: "body", size: adjustedSize, children: getLabel("autocomplete.no_options") }),
|
|
210
|
+
renderOption: (renderProps, option) => {
|
|
211
|
+
const isSelected = multiple ? Array.isArray(selectedValue) && selectedValue.some((val) => isOptionEqualToValueLocal(option, val)) : isOptionEqualToValueLocal(option, selectedValue);
|
|
212
|
+
return withRenderOption(color)(renderProps, {
|
|
213
|
+
...typeof option === "object" && option !== null ? option : {},
|
|
214
|
+
label: getOptionLabelLocal(option),
|
|
215
|
+
selected: isSelected,
|
|
216
|
+
disabled,
|
|
217
|
+
size
|
|
218
|
+
});
|
|
219
|
+
},
|
|
220
|
+
renderInput: (params) => {
|
|
221
|
+
const selectedOption = options.find((option) => {
|
|
222
|
+
return isOptionEqualToValueLocal(option, selectedValue);
|
|
223
|
+
});
|
|
224
|
+
return /* @__PURE__ */ jsx(
|
|
225
|
+
RenderInputStyled,
|
|
226
|
+
{
|
|
227
|
+
ownerState: { ...ownerState },
|
|
228
|
+
...params,
|
|
229
|
+
color,
|
|
230
|
+
error,
|
|
231
|
+
size: adjustedSize,
|
|
232
|
+
variant,
|
|
233
|
+
InputLabelProps: {
|
|
234
|
+
...params.InputLabelProps,
|
|
235
|
+
shrink: true
|
|
236
|
+
},
|
|
237
|
+
fullWidth: true,
|
|
238
|
+
disabled,
|
|
239
|
+
SelectProps: { native: true },
|
|
240
|
+
InputProps: {
|
|
241
|
+
...params.InputProps,
|
|
242
|
+
autoComplete: "off",
|
|
243
|
+
// Asegura que sea string.
|
|
244
|
+
startAdornment: multiple ? Array.isArray(selectedValue) ? selectedValue.map((option, index) => /* @__PURE__ */ jsx(
|
|
245
|
+
ChipStyled,
|
|
246
|
+
{
|
|
247
|
+
size: adjustedSize,
|
|
248
|
+
label: getOptionLabelLocal(option),
|
|
249
|
+
opacity: true,
|
|
250
|
+
onDeleted: () => handleDelete(option),
|
|
251
|
+
ownerState: { ...ownerState }
|
|
252
|
+
},
|
|
253
|
+
index
|
|
254
|
+
)) : null : type === "image" && !multiple && selectedOption ? /* @__PURE__ */ jsx(
|
|
255
|
+
ImageStyled,
|
|
256
|
+
{
|
|
257
|
+
ownerState: { ...ownerState },
|
|
258
|
+
src: getOptionUrlImageLocal(selectedOption),
|
|
259
|
+
alt: getOptionLabelLocal(selectedOption)
|
|
260
|
+
}
|
|
261
|
+
) : params.InputProps.startAdornment,
|
|
262
|
+
endAdornment: loading ? /* @__PURE__ */ jsx(
|
|
263
|
+
CircularProgressStyled,
|
|
264
|
+
{
|
|
265
|
+
ownerState: { ...ownerState },
|
|
266
|
+
color,
|
|
267
|
+
size: adjustedSize
|
|
268
|
+
}
|
|
269
|
+
) : /* @__PURE__ */ jsx("div", { children: refresh ? /* @__PURE__ */ jsx(
|
|
270
|
+
IconButtonStyled,
|
|
271
|
+
{
|
|
272
|
+
ownerState: { ...ownerState },
|
|
273
|
+
src: `${host_static_assets}/${environment_assets}/frontend/components/RHFAutocompletarAsync/assets/icons/round_refresh.svg`,
|
|
274
|
+
onClick: handleRefresh,
|
|
275
|
+
disabled,
|
|
276
|
+
size: adjustedSize
|
|
277
|
+
}
|
|
278
|
+
) : /* @__PURE__ */ jsx(
|
|
279
|
+
IconButtonStyled,
|
|
280
|
+
{
|
|
281
|
+
ownerState: { ...ownerState },
|
|
282
|
+
src: `${host_static_assets}/${environment_assets}/frontend/components/RHFAutocompletarAsync/assets/icons/chevronDown.svg`,
|
|
283
|
+
onClick: (event) => onOpenLocal(event),
|
|
284
|
+
disabled,
|
|
285
|
+
size: adjustedSize
|
|
286
|
+
}
|
|
287
|
+
) })
|
|
288
|
+
},
|
|
289
|
+
...other,
|
|
290
|
+
ref: params.InputProps.ref
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
);
|
|
296
|
+
});
|
|
297
|
+
export {
|
|
298
|
+
Autocomplete as A
|
|
299
|
+
};
|