@soyfri/shared-library 1.5.0 → 2.0.0-beta.0
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/dist/components/ActionMenu/ActionMenu.cjs +107 -0
- package/dist/components/ActionMenu/ActionMenu.cjs.map +1 -0
- package/dist/components/ActionMenu/ActionMenu.d.ts +60 -0
- package/dist/components/ActionMenu/ActionMenu.js +107 -0
- package/dist/components/ActionMenu/ActionMenu.js.map +1 -0
- package/dist/components/ActionMenu/index.d.ts +2 -0
- package/dist/components/ActionMenu.d.ts +6 -0
- package/dist/components/AppBar/AppBar.cjs +346 -0
- package/dist/components/AppBar/AppBar.cjs.map +1 -0
- package/dist/components/AppBar/AppBar.d.ts +55 -0
- package/dist/components/AppBar/AppBar.js +346 -0
- package/dist/components/AppBar/AppBar.js.map +1 -0
- package/dist/components/AppBar/AppBar.sx.d.ts +12 -0
- package/dist/components/AppBar/AppBarBrand.d.ts +31 -0
- package/dist/components/AppBar/AppBarContext.d.ts +18 -0
- package/dist/components/AppBar/AppBarMenuToggle.d.ts +39 -0
- package/dist/components/AppBar/AppBarUserMenu.d.ts +65 -0
- package/dist/components/AppBar/index.d.ts +12 -0
- package/dist/components/AppBar.d.ts +6 -0
- package/dist/components/Autocomplete/Autocomplete.cjs +259 -54
- package/dist/components/Autocomplete/Autocomplete.cjs.map +1 -1
- package/dist/components/Autocomplete/Autocomplete.d.ts +64 -9
- package/dist/components/Autocomplete/Autocomplete.definitions.d.ts +6 -0
- package/dist/components/Autocomplete/Autocomplete.helpers.d.ts +18 -0
- package/dist/components/Autocomplete/Autocomplete.js +261 -56
- package/dist/components/Autocomplete/Autocomplete.js.map +1 -1
- package/dist/components/Autocomplete/Autocomplete.sx.d.ts +7 -0
- package/dist/components/Autocomplete/Autocomplete.types.d.ts +1 -0
- package/dist/components/Autocomplete/_parts/AutocompleteChips.d.ts +19 -0
- package/dist/components/Autocomplete/_parts/AutocompleteLoader.d.ts +9 -0
- package/dist/components/Autocomplete/_parts/AutocompleteOption.d.ts +19 -0
- package/dist/components/Autocomplete/index.d.ts +2 -1
- package/dist/components/Autocomplete.d.ts +4 -0
- package/dist/components/Avatar/Avatar.cjs +116 -79
- package/dist/components/Avatar/Avatar.cjs.map +1 -1
- package/dist/components/Avatar/Avatar.d.ts +16 -2
- package/dist/components/Avatar/Avatar.definitions.d.ts +11 -0
- package/dist/components/Avatar/Avatar.js +117 -80
- package/dist/components/Avatar/Avatar.js.map +1 -1
- package/dist/components/Card/Card.cjs +168 -9
- package/dist/components/Card/Card.cjs.map +1 -1
- package/dist/components/Card/Card.d.ts +78 -8
- package/dist/components/Card/Card.js +170 -11
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Card/Card.sx.d.ts +17 -0
- package/dist/components/Card/index.d.ts +4 -1
- package/dist/components/Card.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.cjs +201 -3
- package/dist/components/DatePicker/DatePicker.cjs.map +1 -1
- package/dist/components/DatePicker/DatePicker.d.ts +47 -9
- package/dist/components/DatePicker/DatePicker.definitions.d.ts +1 -0
- package/dist/components/DatePicker/DatePicker.helpers.d.ts +7 -0
- package/dist/components/DatePicker/DatePicker.js +200 -2
- package/dist/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/components/DatePicker/DatePicker.sx.d.ts +9 -0
- package/dist/components/DatePicker/DatePicker.types.d.ts +1 -0
- package/dist/components/DatePicker/index.d.ts +2 -1
- package/dist/components/DatePicker.d.ts +4 -0
- package/dist/components/DateTimePicker/DateTimePicker.cjs +152 -138
- package/dist/components/DateTimePicker/DateTimePicker.cjs.map +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.d.ts +46 -9
- package/dist/components/DateTimePicker/DateTimePicker.definitions.d.ts +1 -0
- package/dist/components/DateTimePicker/DateTimePicker.helpers.d.ts +11 -0
- package/dist/components/DateTimePicker/DateTimePicker.js +152 -138
- package/dist/components/DateTimePicker/DateTimePicker.js.map +1 -1
- package/dist/components/DateTimePicker/DateTimePicker.sx.d.ts +7 -0
- package/dist/components/DateTimePicker/DateTimePicker.types.d.ts +1 -0
- package/dist/components/DateTimePicker/index.d.ts +2 -1
- package/dist/components/DateTimePicker.d.ts +4 -0
- package/dist/components/Drawer/Drawer.cjs +271 -0
- package/dist/components/Drawer/Drawer.cjs.map +1 -0
- package/dist/components/Drawer/Drawer.d.ts +51 -0
- package/dist/components/Drawer/Drawer.js +271 -0
- package/dist/components/Drawer/Drawer.js.map +1 -0
- package/dist/components/Drawer/Drawer.sx.d.ts +23 -0
- package/dist/components/Drawer/DrawerContext.d.ts +18 -0
- package/dist/components/Drawer/DrawerItem.d.ts +35 -0
- package/dist/components/Drawer/index.d.ts +6 -0
- package/dist/components/Drawer.d.ts +6 -0
- package/dist/components/Icon/Icon.cjs +44 -3
- package/dist/components/Icon/Icon.cjs.map +1 -1
- package/dist/components/Icon/Icon.d.ts +34 -1
- package/dist/components/Icon/Icon.js +44 -3
- package/dist/components/Icon/Icon.js.map +1 -1
- package/dist/components/Input/Input.cjs +173 -3
- package/dist/components/Input/Input.cjs.map +1 -1
- package/dist/components/Input/Input.d.ts +20 -15
- package/dist/components/Input/Input.definitions.d.ts +5 -2
- package/dist/components/Input/Input.helpers.d.ts +14 -0
- package/dist/components/Input/Input.js +172 -2
- package/dist/components/Input/Input.js.map +1 -1
- package/dist/components/Input/Input.sx.d.ts +8 -0
- package/dist/components/Input/Input.types.d.ts +1 -0
- package/dist/components/Input/index.d.ts +2 -1
- package/dist/components/Input.d.ts +4 -0
- package/dist/components/InputGroup/InputGroup.cjs +104 -91
- package/dist/components/InputGroup/InputGroup.cjs.map +1 -1
- package/dist/components/InputGroup/InputGroup.d.ts +37 -1
- package/dist/components/InputGroup/InputGroup.definitions.d.ts +6 -0
- package/dist/components/InputGroup/InputGroup.js +106 -93
- package/dist/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/components/Modal/Modal.cjs +226 -116
- package/dist/components/Modal/Modal.cjs.map +1 -1
- package/dist/components/Modal/Modal.d.ts +38 -2
- package/dist/components/Modal/Modal.js +227 -117
- package/dist/components/Modal/Modal.js.map +1 -1
- package/dist/components/Modal/ModalFooter.d.ts +9 -1
- package/dist/components/Modal/index.d.ts +5 -0
- package/dist/components/PageLoader/PageLoader.cjs +61 -0
- package/dist/components/PageLoader/PageLoader.cjs.map +1 -0
- package/dist/components/PageLoader/PageLoader.d.ts +38 -0
- package/dist/components/PageLoader/PageLoader.js +61 -0
- package/dist/components/PageLoader/PageLoader.js.map +1 -0
- package/dist/components/PageLoader/index.d.ts +2 -0
- package/dist/components/PageLoader.d.ts +6 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.cjs +79 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.cjs.map +1 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.d.ts +48 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.js +79 -0
- package/dist/components/ScrollTopButton/ScrollTopButton.js.map +1 -0
- package/dist/components/ScrollTopButton/index.d.ts +4 -0
- package/dist/components/ScrollTopButton/scrollToTop.d.ts +29 -0
- package/dist/components/ScrollTopButton.d.ts +6 -0
- package/dist/components/Select/Select.cjs +446 -4
- package/dist/components/Select/Select.cjs.map +1 -1
- package/dist/components/Select/Select.d.ts +33 -13
- package/dist/components/Select/Select.definitions.d.ts +3 -0
- package/dist/components/Select/Select.helpers.d.ts +28 -0
- package/dist/components/Select/Select.js +445 -3
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/Select.sx.d.ts +7 -0
- package/dist/components/Select/Select.types.d.ts +1 -0
- package/dist/components/Select/_parts/SelectMenuItem.d.ts +20 -0
- package/dist/components/Select/_parts/SelectSearchHeader.d.ts +15 -0
- package/dist/components/Select/_parts/SelectValue.d.ts +22 -0
- package/dist/components/Select/index.d.ts +2 -1
- package/dist/components/Select.d.ts +4 -0
- package/dist/components/Stat/Stat.cjs +1 -1
- package/dist/components/Stat/Stat.js +1 -1
- package/dist/components/Stepper/Stepper.cjs +4 -1
- package/dist/components/Stepper/Stepper.cjs.map +1 -1
- package/dist/components/Stepper/Stepper.d.ts +5 -0
- package/dist/components/Stepper/Stepper.js +4 -1
- package/dist/components/Stepper/Stepper.js.map +1 -1
- package/dist/components/_shared/formField.sx.d.ts +33 -0
- package/dist/components/_shared/resolvePreset.d.ts +18 -0
- package/dist/formField.sx-CQ1mbk9M.cjs +76 -0
- package/dist/formField.sx-CQ1mbk9M.cjs.map +1 -0
- package/dist/formField.sx-DfVbMe0V.js +77 -0
- package/dist/formField.sx-DfVbMe0V.js.map +1 -0
- package/dist/hooks/Wizard/Wizard.cjs +7 -0
- package/dist/hooks/Wizard/Wizard.cjs.map +1 -0
- package/dist/hooks/Wizard/Wizard.js +7 -0
- package/dist/hooks/Wizard/Wizard.js.map +1 -0
- package/dist/hooks/Wizard/WizardContext.d.ts +67 -0
- package/dist/hooks/Wizard/index.d.ts +3 -0
- package/dist/hooks/Wizard/useWizard.d.ts +9 -0
- package/dist/hooks/Wizard.d.ts +2 -0
- package/dist/index.cjs +99 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +31 -2
- package/dist/index.js.map +1 -1
- package/dist/mui.d.ts +5 -0
- package/dist/resolvePreset-B-IB0ehH.js +15 -0
- package/dist/resolvePreset-B-IB0ehH.js.map +1 -0
- package/dist/resolvePreset-CT3kU-K2.cjs +14 -0
- package/dist/resolvePreset-CT3kU-K2.cjs.map +1 -0
- package/dist/styles.css +3 -112
- package/dist/theme/componentStyles.d.ts +32 -0
- package/dist/theme/tokens.d.ts +28 -0
- package/dist/useWizard-CWdIxZzX.cjs +94 -0
- package/dist/useWizard-CWdIxZzX.cjs.map +1 -0
- package/dist/useWizard-CWq--C3o.js +95 -0
- package/dist/useWizard-CWq--C3o.js.map +1 -0
- package/package.json +1 -1
- package/src/components/ActionMenu/ActionMenu.stories.tsx +230 -0
- package/src/components/ActionMenu/ActionMenu.tsx +174 -0
- package/src/components/ActionMenu/index.ts +2 -0
- package/src/components/AppBar/AppBar.stories.tsx +272 -0
- package/src/components/AppBar/AppBar.sx.ts +32 -0
- package/src/components/AppBar/AppBar.tsx +123 -0
- package/src/components/AppBar/AppBarBrand.tsx +120 -0
- package/src/components/AppBar/AppBarContext.ts +25 -0
- package/src/components/AppBar/AppBarMenuToggle.tsx +90 -0
- package/src/components/AppBar/AppBarUserMenu.tsx +217 -0
- package/src/components/AppBar/index.ts +25 -0
- package/src/components/Autocomplete/Autocomplete.definitions.ts +223 -0
- package/src/components/Autocomplete/Autocomplete.helpers.ts +60 -0
- package/src/components/Autocomplete/Autocomplete.stories.tsx +363 -2
- package/src/components/Autocomplete/Autocomplete.sx.ts +30 -0
- package/src/components/Autocomplete/Autocomplete.tsx +312 -90
- package/src/components/Autocomplete/Autocomplete.types.ts +13 -0
- package/src/components/Autocomplete/_parts/AutocompleteChips.tsx +55 -0
- package/src/components/Autocomplete/_parts/AutocompleteLoader.tsx +17 -0
- package/src/components/Autocomplete/_parts/AutocompleteOption.tsx +31 -0
- package/src/components/Autocomplete/index.ts +12 -1
- package/src/components/Avatar/Avatar.definitions.ts +162 -0
- package/src/components/Avatar/Avatar.stories.tsx +205 -1
- package/src/components/Avatar/Avatar.tsx +166 -103
- package/src/components/Card/Card.stories.tsx +205 -16
- package/src/components/Card/Card.sx.ts +104 -0
- package/src/components/Card/Card.tsx +191 -35
- package/src/components/Card/index.ts +9 -1
- package/src/components/DatePicker/DatePicker.definitions.ts +24 -1
- package/src/components/DatePicker/DatePicker.helpers.ts +24 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +29 -2
- package/src/components/DatePicker/DatePicker.sx.ts +33 -0
- package/src/components/DatePicker/DatePicker.tsx +163 -139
- package/src/components/DatePicker/DatePicker.types.ts +10 -0
- package/src/components/DatePicker/index.ts +9 -1
- package/src/components/DateTimePicker/DateTimePicker.definitions.ts +24 -0
- package/src/components/DateTimePicker/DateTimePicker.helpers.ts +38 -0
- package/src/components/DateTimePicker/DateTimePicker.stories.tsx +29 -1
- package/src/components/DateTimePicker/DateTimePicker.sx.ts +30 -0
- package/src/components/DateTimePicker/DateTimePicker.tsx +200 -166
- package/src/components/DateTimePicker/DateTimePicker.types.ts +10 -0
- package/src/components/DateTimePicker/index.ts +9 -1
- package/src/components/Drawer/Drawer.stories.tsx +270 -0
- package/src/components/Drawer/Drawer.sx.ts +106 -0
- package/src/components/Drawer/Drawer.tsx +214 -0
- package/src/components/Drawer/DrawerContext.ts +26 -0
- package/src/components/Drawer/DrawerItem.tsx +110 -0
- package/src/components/Drawer/index.ts +10 -0
- package/src/components/Flyout/Flyout.stories.tsx +26 -18
- package/src/components/Icon/Icon.stories.tsx +68 -1
- package/src/components/Icon/Icon.tsx +87 -6
- package/src/components/Input/Input.definitions.ts +74 -2
- package/src/components/Input/Input.helpers.ts +49 -0
- package/src/components/Input/Input.stories.tsx +116 -4
- package/src/components/Input/Input.sx.ts +42 -0
- package/src/components/Input/Input.tsx +117 -162
- package/src/components/Input/Input.types.ts +10 -0
- package/src/components/Input/index.ts +9 -1
- package/src/components/InputGroup/InputGroup.definitions.ts +158 -0
- package/src/components/InputGroup/InputGroup.stories.tsx +159 -28
- package/src/components/InputGroup/InputGroup.tsx +159 -116
- package/src/components/Modal/Modal.stories.tsx +434 -6
- package/src/components/Modal/Modal.tsx +303 -121
- package/src/components/Modal/ModalFooter.tsx +22 -12
- package/src/components/Modal/index.ts +6 -1
- package/src/components/PageLoader/PageLoader.stories.tsx +217 -0
- package/src/components/PageLoader/PageLoader.tsx +96 -0
- package/src/components/PageLoader/index.ts +2 -0
- package/src/components/ScrollTopButton/ScrollTopButton.stories.tsx +158 -0
- package/src/components/ScrollTopButton/ScrollTopButton.tsx +135 -0
- package/src/components/ScrollTopButton/index.ts +8 -0
- package/src/components/ScrollTopButton/scrollToTop.ts +37 -0
- package/src/components/Select/Select.definitions.ts +114 -0
- package/src/components/Select/Select.helpers.ts +71 -0
- package/src/components/Select/Select.stories.tsx +126 -8
- package/src/components/Select/Select.sx.ts +14 -0
- package/src/components/Select/Select.tsx +246 -285
- package/src/components/Select/Select.types.ts +15 -0
- package/src/components/Select/_parts/SelectMenuItem.tsx +40 -0
- package/src/components/Select/_parts/SelectSearchHeader.tsx +51 -0
- package/src/components/Select/_parts/SelectValue.tsx +96 -0
- package/src/components/Select/index.ts +14 -1
- package/src/components/Stepper/Stepper.tsx +17 -1
- package/src/components/Tooltip/Tooltip.stories.tsx +15 -3
- package/src/components/_shared/formField.sx.ts +118 -0
- package/src/components/_shared/resolvePreset.ts +35 -0
- package/src/hooks/Wizard/Wizard.stories.tsx +301 -0
- package/src/hooks/Wizard/WizardContext.tsx +166 -0
- package/src/hooks/Wizard/index.ts +6 -0
- package/src/hooks/Wizard/useWizard.ts +13 -0
- package/src/index.ts +17 -1
- package/src/mui.ts +44 -0
- package/src/theme/componentStyles.ts +47 -0
- package/src/theme/tokens.ts +43 -0
- package/dist/DatePicker-BSNboVhN.js +0 -201
- package/dist/DatePicker-BSNboVhN.js.map +0 -1
- package/dist/DatePicker-BoqxWAhj.cjs +0 -200
- package/dist/DatePicker-BoqxWAhj.cjs.map +0 -1
- package/dist/Input-DFHs7cJ_.js +0 -171
- package/dist/Input-DFHs7cJ_.js.map +0 -1
- package/dist/Input-c8MwNNPg.cjs +0 -170
- package/dist/Input-c8MwNNPg.cjs.map +0 -1
- package/dist/Select-BO2N56sm.cjs +0 -411
- package/dist/Select-BO2N56sm.cjs.map +0 -1
- package/dist/Select-BcLkyHSE.js +0 -412
- package/dist/Select-BcLkyHSE.js.map +0 -1
- package/dist/index.css +0 -3
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React, {
|
|
2
|
+
useMemo,
|
|
3
|
+
useRef,
|
|
4
|
+
useState,
|
|
5
|
+
type ReactNode,
|
|
6
|
+
type SyntheticEvent,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import {
|
|
3
|
-
Autocomplete,
|
|
9
|
+
Autocomplete as MuiAutocomplete,
|
|
4
10
|
TextField,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
CircularProgress,
|
|
10
|
-
} from "@mui/material";
|
|
11
|
-
import ClearIcon from "@mui/icons-material/Clear";
|
|
11
|
+
type TextFieldProps,
|
|
12
|
+
} from '@mui/material';
|
|
13
|
+
import { useTheme, type SxProps, type Theme } from '@mui/material/styles';
|
|
14
|
+
import { Controller, type Control, type RegisterOptions } from 'react-hook-form';
|
|
12
15
|
|
|
16
|
+
import { buildAutocompleteSx } from './Autocomplete.sx';
|
|
17
|
+
import {
|
|
18
|
+
areResolvedValuesEqual,
|
|
19
|
+
isResolvedValueEmpty,
|
|
20
|
+
resolveMultipleValue,
|
|
21
|
+
resolveSingleValue,
|
|
22
|
+
} from './Autocomplete.helpers';
|
|
23
|
+
import { resolvePreset } from '../_shared/resolvePreset';
|
|
24
|
+
import { AutocompleteOption } from './_parts/AutocompleteOption';
|
|
25
|
+
import { AutocompleteChips } from './_parts/AutocompleteChips';
|
|
26
|
+
import { AutocompleteLoader } from './_parts/AutocompleteLoader';
|
|
27
|
+
|
|
28
|
+
// ── Tipos de dominio ─────────────────────────────────────────────────────
|
|
13
29
|
export interface SelectOption {
|
|
14
30
|
value: string | number;
|
|
15
31
|
label: string;
|
|
@@ -19,121 +35,327 @@ export interface SelectOption {
|
|
|
19
35
|
[key: string]: any;
|
|
20
36
|
}
|
|
21
37
|
|
|
22
|
-
type
|
|
23
|
-
type
|
|
38
|
+
export type LabelPosition = 'outside' | 'floating';
|
|
39
|
+
export type AutocompleteSize = 'small' | 'medium';
|
|
40
|
+
|
|
41
|
+
// ── Render slots ─────────────────────────────────────────────────────────
|
|
42
|
+
export type RenderOptionItem = (item: SelectOption) => ReactNode;
|
|
43
|
+
export type RenderChipLabel = (item: SelectOption) => ReactNode;
|
|
24
44
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
45
|
+
// ── Props base ───────────────────────────────────────────────────────────
|
|
46
|
+
export type BaseAutocompleteProps<
|
|
47
|
+
_TValue extends SelectOption['value'] = SelectOption['value'],
|
|
48
|
+
> = {
|
|
28
49
|
label?: string;
|
|
29
|
-
|
|
30
|
-
onChange: (val: TValue | TValue[]) => void;
|
|
31
|
-
options?: SelectOption[];
|
|
50
|
+
options: SelectOption[];
|
|
32
51
|
placeholder?: string;
|
|
33
52
|
multiple?: boolean;
|
|
34
53
|
disabled?: boolean;
|
|
54
|
+
readOnly?: boolean;
|
|
35
55
|
loading?: boolean;
|
|
36
56
|
error?: boolean;
|
|
37
57
|
helperText?: string;
|
|
38
58
|
maxChipsToShow?: number;
|
|
39
59
|
renderOptionItem?: RenderOptionItem;
|
|
40
60
|
renderChipLabel?: RenderChipLabel;
|
|
61
|
+
/** Border radius del input. Default: 10. */
|
|
62
|
+
borderRadius?: number | string;
|
|
63
|
+
/** "outside" (default) = label arriba del input; "floating" = comportamiento nativo MUI. */
|
|
64
|
+
labelPosition?: LabelPosition;
|
|
65
|
+
/** Tamaño del TextField. Default: 'small'. */
|
|
66
|
+
size?: AutocompleteSize;
|
|
67
|
+
/** Texto cuando no hay coincidencias. */
|
|
68
|
+
noOptionsText?: ReactNode;
|
|
69
|
+
/** Texto cuando está cargando. */
|
|
70
|
+
loadingText?: ReactNode;
|
|
71
|
+
sx?: SxProps<Theme>;
|
|
72
|
+
className?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Nombre del preset de estilo registrado en `theme.styles.Autocomplete`.
|
|
75
|
+
* - `"default"` (o ausente) = estilo built-in del paquete.
|
|
76
|
+
* - Cualquier otro string = mergea el preset encima del estilo built-in.
|
|
77
|
+
*/
|
|
78
|
+
preset?: string;
|
|
79
|
+
/** Props para el TextField subyacente. */
|
|
80
|
+
textFieldProps?: Partial<TextFieldProps>;
|
|
81
|
+
|
|
82
|
+
// ── Búsqueda asíncrona / remota ──────────────────────────────────────
|
|
83
|
+
/** Se dispara cada vez que el usuario escribe. Útil para llamadas a servicios
|
|
84
|
+
* (debounce recomendado en el consumer). */
|
|
85
|
+
onInputChange?: (
|
|
86
|
+
event: SyntheticEvent,
|
|
87
|
+
value: string,
|
|
88
|
+
reason: 'input' | 'reset' | 'clear' | 'blur' | 'selectOption' | 'removeOption',
|
|
89
|
+
) => void;
|
|
90
|
+
/** Valor controlado del texto de búsqueda. */
|
|
91
|
+
inputValue?: string;
|
|
92
|
+
/** Filtro custom. Para búsqueda remota pasar `(x) => x` y confiar sólo en el servicio. */
|
|
93
|
+
filterOptions?: (options: SelectOption[], state: any) => SelectOption[];
|
|
94
|
+
/** Permite valores arbitrarios (no solo de la lista). */
|
|
95
|
+
freeSolo?: boolean;
|
|
96
|
+
open?: boolean;
|
|
97
|
+
onOpen?: (event: SyntheticEvent) => void;
|
|
98
|
+
onClose?: (event: SyntheticEvent, reason: string) => void;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// ── Variantes discriminadas (RHF vs controlado) ──────────────────────────
|
|
102
|
+
export interface ControlledAutocompleteProps<
|
|
103
|
+
TValue extends SelectOption['value'] = SelectOption['value'],
|
|
104
|
+
> extends BaseAutocompleteProps<TValue> {
|
|
105
|
+
value: TValue | TValue[] | null;
|
|
106
|
+
onChange: (val: TValue | TValue[] | null) => void;
|
|
107
|
+
name?: string;
|
|
108
|
+
control?: never;
|
|
109
|
+
validation?: never;
|
|
41
110
|
}
|
|
42
111
|
|
|
43
|
-
export
|
|
44
|
-
TValue extends SelectOption[
|
|
112
|
+
export interface RHFAutocompleteProps<
|
|
113
|
+
TValue extends SelectOption['value'] = SelectOption['value'],
|
|
114
|
+
> extends BaseAutocompleteProps<TValue> {
|
|
115
|
+
name: string;
|
|
116
|
+
control: Control<any>;
|
|
117
|
+
validation?: RegisterOptions;
|
|
118
|
+
value?: never;
|
|
119
|
+
onChange?: never;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ── API pública final ────────────────────────────────────────────────────
|
|
123
|
+
export type AutocompleteProps<
|
|
124
|
+
TValue extends SelectOption['value'] = SelectOption['value'],
|
|
125
|
+
> = ControlledAutocompleteProps<TValue> | RHFAutocompleteProps<TValue>;
|
|
126
|
+
|
|
127
|
+
export function Autocomplete<
|
|
128
|
+
TValue extends SelectOption['value'] = SelectOption['value'],
|
|
45
129
|
>(props: AutocompleteProps<TValue>) {
|
|
46
130
|
const {
|
|
47
131
|
label,
|
|
48
|
-
options
|
|
49
|
-
value,
|
|
50
|
-
onChange,
|
|
132
|
+
options,
|
|
51
133
|
placeholder,
|
|
52
134
|
multiple = false,
|
|
53
135
|
disabled = false,
|
|
136
|
+
readOnly = false,
|
|
54
137
|
loading = false,
|
|
55
|
-
error = false,
|
|
138
|
+
error: errorProp = false,
|
|
56
139
|
helperText,
|
|
140
|
+
maxChipsToShow = 3,
|
|
57
141
|
renderOptionItem,
|
|
58
142
|
renderChipLabel,
|
|
59
|
-
|
|
60
|
-
|
|
143
|
+
borderRadius = 10,
|
|
144
|
+
labelPosition = 'outside',
|
|
145
|
+
size = 'small',
|
|
146
|
+
noOptionsText = 'No hay opciones',
|
|
147
|
+
loadingText,
|
|
148
|
+
sx,
|
|
149
|
+
className,
|
|
150
|
+
preset,
|
|
151
|
+
textFieldProps,
|
|
152
|
+
onInputChange,
|
|
153
|
+
inputValue,
|
|
154
|
+
filterOptions,
|
|
155
|
+
freeSolo,
|
|
156
|
+
open,
|
|
157
|
+
onOpen,
|
|
158
|
+
onClose,
|
|
159
|
+
} = props as BaseAutocompleteProps<TValue>;
|
|
61
160
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const hidden = value.length - maxChipsToShow;
|
|
161
|
+
// Focus tracking para mostrar placeholder solo cuando el label sube.
|
|
162
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
65
163
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/>
|
|
76
|
-
))}
|
|
164
|
+
// Cache interno de opciones vistas (indexado por value). Crítico para async
|
|
165
|
+
// multiple: cuando `options` cambian por un nuevo search, los items ya
|
|
166
|
+
// seleccionados no desaparecen de los chips porque los recordamos acá.
|
|
167
|
+
const seenOptionsRef = useRef<Map<SelectOption['value'], SelectOption>>(
|
|
168
|
+
new Map(),
|
|
169
|
+
);
|
|
170
|
+
for (const opt of options) {
|
|
171
|
+
seenOptionsRef.current.set(opt.value, opt);
|
|
172
|
+
}
|
|
77
173
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
);
|
|
81
|
-
|
|
174
|
+
// Pool de opciones para resolver values (merge de options + vistas).
|
|
175
|
+
const resolvePool = useMemo<SelectOption[]>(() => {
|
|
176
|
+
const merged = new Map(seenOptionsRef.current);
|
|
177
|
+
for (const opt of options) merged.set(opt.value, opt);
|
|
178
|
+
return Array.from(merged.values());
|
|
179
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
180
|
+
}, [options]);
|
|
82
181
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
182
|
+
// Estabiliza la referencia del resolvedValue que pasamos a MUI Autocomplete.
|
|
183
|
+
// MUI compara value con `!==`: una referencia nueva con mismo contenido
|
|
184
|
+
// dispara resetInputValue() y borra el texto que el usuario está escribiendo.
|
|
185
|
+
const prevResolvedRef = useRef<SelectOption[] | SelectOption | null>(
|
|
186
|
+
multiple ? [] : null,
|
|
87
187
|
);
|
|
88
188
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
: (options.find((o) => o.value === value) ?? null)
|
|
99
|
-
}
|
|
100
|
-
disabled={disabled}
|
|
101
|
-
loading={loading}
|
|
102
|
-
getOptionLabel={(opt) => opt?.label ?? ""}
|
|
103
|
-
isOptionEqualToValue={(a, b) => a.value === b.value}
|
|
104
|
-
onChange={onChange}
|
|
105
|
-
renderOption={renderOption}
|
|
106
|
-
renderTags={multiple ? renderTags : undefined}
|
|
107
|
-
noOptionsText="No hay opciones"
|
|
108
|
-
loadingText={
|
|
109
|
-
<Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
|
|
110
|
-
<CircularProgress size={20} />
|
|
111
|
-
<Typography>Cargando...</Typography>
|
|
112
|
-
</Box>
|
|
113
|
-
}
|
|
114
|
-
renderInput={(params) => (
|
|
115
|
-
<TextField
|
|
116
|
-
{...params}
|
|
117
|
-
label={label}
|
|
118
|
-
placeholder={placeholder}
|
|
119
|
-
error={error}
|
|
120
|
-
helperText={helperText}
|
|
121
|
-
/>
|
|
122
|
-
)}
|
|
123
|
-
/>
|
|
124
|
-
);
|
|
189
|
+
const stabilizeResolved = (
|
|
190
|
+
newVal: SelectOption[] | SelectOption | null,
|
|
191
|
+
): any => {
|
|
192
|
+
if (areResolvedValuesEqual(prevResolvedRef.current, newVal, multiple)) {
|
|
193
|
+
return prevResolvedRef.current;
|
|
194
|
+
}
|
|
195
|
+
prevResolvedRef.current = newVal;
|
|
196
|
+
return newVal;
|
|
197
|
+
};
|
|
125
198
|
|
|
126
|
-
const
|
|
199
|
+
const theme = useTheme();
|
|
200
|
+
const presetSx = resolvePreset('Autocomplete', preset, theme);
|
|
201
|
+
|
|
202
|
+
const mergedSx = [
|
|
203
|
+
buildAutocompleteSx(borderRadius, labelPosition),
|
|
204
|
+
...(presetSx ? [presetSx] : []),
|
|
205
|
+
...(Array.isArray(sx) ? sx : sx ? [sx] : []),
|
|
206
|
+
];
|
|
207
|
+
|
|
208
|
+
const renderAutocomplete = (
|
|
209
|
+
resolvedValue: any,
|
|
210
|
+
handleChange: (event: any, newValue: any) => void,
|
|
211
|
+
onBlur?: () => void,
|
|
212
|
+
inputRef?: React.Ref<any>,
|
|
213
|
+
rhfError?: boolean,
|
|
214
|
+
rhfHelperText?: string,
|
|
215
|
+
) => {
|
|
216
|
+
const finalError = !!rhfError || !!errorProp;
|
|
217
|
+
const finalHelperText = rhfHelperText || helperText;
|
|
218
|
+
|
|
219
|
+
const isEmpty = isResolvedValueEmpty(resolvedValue, multiple);
|
|
220
|
+
const showPlaceholder = isEmpty && isFocused && !!placeholder;
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<MuiAutocomplete
|
|
224
|
+
multiple={multiple}
|
|
225
|
+
options={options}
|
|
226
|
+
value={resolvedValue}
|
|
227
|
+
disabled={disabled}
|
|
228
|
+
readOnly={readOnly}
|
|
229
|
+
loading={loading}
|
|
230
|
+
className={className}
|
|
231
|
+
sx={mergedSx}
|
|
232
|
+
freeSolo={freeSolo as any}
|
|
233
|
+
open={open}
|
|
234
|
+
onOpen={onOpen}
|
|
235
|
+
onClose={onClose}
|
|
236
|
+
inputValue={inputValue}
|
|
237
|
+
onInputChange={onInputChange}
|
|
238
|
+
filterOptions={filterOptions as any}
|
|
239
|
+
getOptionLabel={(opt) =>
|
|
240
|
+
typeof opt === 'string' ? opt : (opt?.label ?? '')
|
|
241
|
+
}
|
|
242
|
+
isOptionEqualToValue={(a, b) => a?.value === b?.value}
|
|
243
|
+
getOptionDisabled={(opt) => !!opt?.disabled}
|
|
244
|
+
onChange={handleChange}
|
|
245
|
+
onFocus={() => setIsFocused(true)}
|
|
246
|
+
onBlur={() => {
|
|
247
|
+
setIsFocused(false);
|
|
248
|
+
onBlur?.();
|
|
249
|
+
}}
|
|
250
|
+
renderOption={(liProps, option) => (
|
|
251
|
+
<AutocompleteOption
|
|
252
|
+
liProps={liProps as any}
|
|
253
|
+
option={option}
|
|
254
|
+
customRender={renderOptionItem}
|
|
255
|
+
/>
|
|
256
|
+
)}
|
|
257
|
+
renderTags={
|
|
258
|
+
multiple
|
|
259
|
+
? (value, getTagProps) => (
|
|
260
|
+
<AutocompleteChips
|
|
261
|
+
value={value}
|
|
262
|
+
getTagProps={getTagProps}
|
|
263
|
+
size={size}
|
|
264
|
+
maxChipsToShow={maxChipsToShow}
|
|
265
|
+
renderChipLabel={renderChipLabel}
|
|
266
|
+
/>
|
|
267
|
+
)
|
|
268
|
+
: undefined
|
|
269
|
+
}
|
|
270
|
+
noOptionsText={noOptionsText}
|
|
271
|
+
loadingText={loadingText ?? <AutocompleteLoader />}
|
|
272
|
+
renderInput={(params) => (
|
|
273
|
+
<TextField
|
|
274
|
+
{...params}
|
|
275
|
+
label={label}
|
|
276
|
+
size={size}
|
|
277
|
+
variant="outlined"
|
|
278
|
+
placeholder={showPlaceholder ? placeholder : undefined}
|
|
279
|
+
error={finalError}
|
|
280
|
+
helperText={finalHelperText}
|
|
281
|
+
inputRef={inputRef}
|
|
282
|
+
{...textFieldProps}
|
|
283
|
+
InputLabelProps={{
|
|
284
|
+
...(params.InputLabelProps as Record<string, any>),
|
|
285
|
+
...(textFieldProps?.InputLabelProps as Record<string, any> | undefined),
|
|
286
|
+
shrink:
|
|
287
|
+
labelPosition === 'outside'
|
|
288
|
+
? !isEmpty || isFocused
|
|
289
|
+
: (params.InputLabelProps as any)?.shrink,
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
)}
|
|
293
|
+
/>
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const handleControlledChange = (_event: any, newValue: any) => {
|
|
298
|
+
const onChange = (props as ControlledAutocompleteProps<TValue>).onChange;
|
|
127
299
|
if (multiple) {
|
|
128
|
-
const values = (newValue ?? []).map((opt:
|
|
129
|
-
|
|
300
|
+
const values = (newValue ?? []).map((opt: SelectOption) => opt.value as TValue);
|
|
301
|
+
onChange(values);
|
|
130
302
|
} else {
|
|
131
|
-
|
|
132
|
-
(onChange as (val: TValue) => void)?.(value);
|
|
303
|
+
onChange((newValue?.value ?? null) as TValue | null);
|
|
133
304
|
}
|
|
134
305
|
};
|
|
135
306
|
|
|
136
|
-
|
|
307
|
+
// --- RHF mode ---
|
|
308
|
+
if ('control' in props && props.control) {
|
|
309
|
+
const { name, control, validation } = props as RHFAutocompleteProps<TValue>;
|
|
310
|
+
return (
|
|
311
|
+
<Controller
|
|
312
|
+
name={name}
|
|
313
|
+
control={control}
|
|
314
|
+
rules={validation}
|
|
315
|
+
render={({ field, fieldState: { error: fieldError } }) => {
|
|
316
|
+
const resolvedValue = stabilizeResolved(
|
|
317
|
+
multiple
|
|
318
|
+
? resolveMultipleValue(resolvePool, field.value)
|
|
319
|
+
: resolveSingleValue(resolvePool, field.value),
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
const handleChange = (_event: any, newValue: any) => {
|
|
323
|
+
if (multiple) {
|
|
324
|
+
field.onChange(
|
|
325
|
+
(newValue ?? []).map((opt: SelectOption) => opt.value),
|
|
326
|
+
);
|
|
327
|
+
} else {
|
|
328
|
+
field.onChange(newValue?.value ?? null);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
return renderAutocomplete(
|
|
333
|
+
resolvedValue,
|
|
334
|
+
handleChange,
|
|
335
|
+
field.onBlur,
|
|
336
|
+
field.ref,
|
|
337
|
+
!!fieldError,
|
|
338
|
+
fieldError?.message,
|
|
339
|
+
);
|
|
340
|
+
}}
|
|
341
|
+
/>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// --- Controlled mode ---
|
|
346
|
+
const controlledValue = (props as ControlledAutocompleteProps<TValue>).value;
|
|
347
|
+
const resolvedValue = stabilizeResolved(
|
|
348
|
+
multiple
|
|
349
|
+
? resolveMultipleValue(resolvePool, controlledValue as SelectOption['value'][])
|
|
350
|
+
: resolveSingleValue(resolvePool, controlledValue as SelectOption['value']),
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
return renderAutocomplete(resolvedValue, handleControlledChange);
|
|
137
354
|
}
|
|
138
355
|
|
|
139
|
-
|
|
356
|
+
/**
|
|
357
|
+
* @deprecated Usar `Autocomplete` en su lugar. Alias mantenido para retro-compatibilidad.
|
|
358
|
+
*/
|
|
359
|
+
export const AutocompleteSelect = Autocomplete;
|
|
360
|
+
|
|
361
|
+
export default Autocomplete;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Re-export barrel para compatibilidad con imports antiguos.
|
|
2
|
+
// Los tipos ahora viven dentro de Autocomplete.tsx.
|
|
3
|
+
export type {
|
|
4
|
+
SelectOption,
|
|
5
|
+
LabelPosition,
|
|
6
|
+
AutocompleteSize,
|
|
7
|
+
RenderOptionItem,
|
|
8
|
+
RenderChipLabel,
|
|
9
|
+
BaseAutocompleteProps,
|
|
10
|
+
ControlledAutocompleteProps,
|
|
11
|
+
RHFAutocompleteProps,
|
|
12
|
+
AutocompleteProps,
|
|
13
|
+
} from './Autocomplete';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Avatar, Chip } from '@mui/material';
|
|
3
|
+
import ClearIcon from '@mui/icons-material/Clear';
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
SelectOption,
|
|
7
|
+
RenderChipLabel,
|
|
8
|
+
AutocompleteSize,
|
|
9
|
+
} from '../Autocomplete';
|
|
10
|
+
|
|
11
|
+
interface AutocompleteChipsProps {
|
|
12
|
+
value: SelectOption[];
|
|
13
|
+
getTagProps: (args: { index: number }) => Record<string, any>;
|
|
14
|
+
size: AutocompleteSize;
|
|
15
|
+
maxChipsToShow: number;
|
|
16
|
+
renderChipLabel?: RenderChipLabel;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Render de los chips del Autocomplete en modo multiple.
|
|
21
|
+
* Trunca después de `maxChipsToShow` con un chip "+N más".
|
|
22
|
+
* El `getTagProps({ index })` viene de MUI y contiene el handler de delete,
|
|
23
|
+
* la key, etc. — se spreadea tal cual al Chip.
|
|
24
|
+
*/
|
|
25
|
+
export const AutocompleteChips: React.FC<AutocompleteChipsProps> = ({
|
|
26
|
+
value,
|
|
27
|
+
getTagProps,
|
|
28
|
+
size,
|
|
29
|
+
maxChipsToShow,
|
|
30
|
+
renderChipLabel,
|
|
31
|
+
}) => {
|
|
32
|
+
const displayed = value.slice(0, maxChipsToShow);
|
|
33
|
+
const hidden = value.length - maxChipsToShow;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
{displayed.map((option, index) => {
|
|
38
|
+
const tagProps = getTagProps({ index });
|
|
39
|
+
return (
|
|
40
|
+
<Chip
|
|
41
|
+
{...tagProps}
|
|
42
|
+
key={option.value}
|
|
43
|
+
size={size}
|
|
44
|
+
label={renderChipLabel ? renderChipLabel(option) : option.label}
|
|
45
|
+
avatar={option.img ? <Avatar src={option.img} /> : undefined}
|
|
46
|
+
deleteIcon={<ClearIcon />}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
})}
|
|
50
|
+
{hidden > 0 && <Chip size={size} label={`+${hidden} más`} />}
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default AutocompleteChips;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, CircularProgress, Typography } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Loader por defecto para el `loadingText` del Autocomplete.
|
|
6
|
+
* El consumer puede sobrescribirlo pasando `loadingText` al componente padre.
|
|
7
|
+
*/
|
|
8
|
+
export const AutocompleteLoader: React.FC<{ text?: string }> = ({
|
|
9
|
+
text = 'Cargando...',
|
|
10
|
+
}) => (
|
|
11
|
+
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
|
12
|
+
<CircularProgress size={16} />
|
|
13
|
+
<Typography variant="body2">{text}</Typography>
|
|
14
|
+
</Box>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export default AutocompleteLoader;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SelectOption, RenderOptionItem } from '../Autocomplete';
|
|
3
|
+
|
|
4
|
+
interface AutocompleteOptionProps {
|
|
5
|
+
liProps: React.HTMLAttributes<HTMLLIElement> & { key?: React.Key };
|
|
6
|
+
option: SelectOption;
|
|
7
|
+
customRender?: RenderOptionItem;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Render por defecto de un <li> del dropdown del Autocomplete.
|
|
12
|
+
* Se expone como componente para testear y extender fácilmente, pero MUI
|
|
13
|
+
* lo llama desde `renderOption={(props, option) => ...}` en el padre.
|
|
14
|
+
*
|
|
15
|
+
* El `key` lo manejamos nosotros (no spreadeamos junto al resto) porque MUI
|
|
16
|
+
* lo inyecta como parte de `propsLi` y React exige que sea prop directo.
|
|
17
|
+
*/
|
|
18
|
+
export const AutocompleteOption: React.FC<AutocompleteOptionProps> = ({
|
|
19
|
+
liProps,
|
|
20
|
+
option,
|
|
21
|
+
customRender,
|
|
22
|
+
}) => {
|
|
23
|
+
const { key: _ignored, ...liRest } = liProps;
|
|
24
|
+
return (
|
|
25
|
+
<li key={option.value} {...liRest}>
|
|
26
|
+
{customRender ? customRender(option) : option.label}
|
|
27
|
+
</li>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default AutocompleteOption;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
export { default
|
|
1
|
+
export { Autocomplete, AutocompleteSelect, default } from './Autocomplete';
|
|
2
|
+
export type {
|
|
3
|
+
AutocompleteProps,
|
|
4
|
+
SelectOption,
|
|
5
|
+
BaseAutocompleteProps,
|
|
6
|
+
ControlledAutocompleteProps,
|
|
7
|
+
RHFAutocompleteProps,
|
|
8
|
+
RenderOptionItem,
|
|
9
|
+
RenderChipLabel,
|
|
10
|
+
LabelPosition,
|
|
11
|
+
AutocompleteSize,
|
|
12
|
+
} from './Autocomplete.types';
|