@soyfri/shared-library 2.0.0-beta.9 → 2.0.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.
Files changed (232) hide show
  1. package/Button-C17mExpd.cjs.map +1 -1
  2. package/Button-UkkP-bNw.js.map +1 -1
  3. package/README.md +182 -150
  4. package/components/ActionMenu/ActionMenu.cjs +52 -52
  5. package/components/ActionMenu/ActionMenu.cjs.map +1 -1
  6. package/components/ActionMenu/ActionMenu.d.ts +20 -36
  7. package/components/ActionMenu/ActionMenu.js +55 -55
  8. package/components/ActionMenu/ActionMenu.js.map +1 -1
  9. package/components/ActionMenu/index.d.ts +2 -2
  10. package/components/AppBar/AppBar.cjs +2 -219
  11. package/components/AppBar/AppBar.cjs.map +1 -1
  12. package/components/AppBar/AppBar.d.ts +6 -6
  13. package/components/AppBar/AppBar.js +5 -222
  14. package/components/AppBar/AppBar.js.map +1 -1
  15. package/components/AppBar/index.d.ts +0 -6
  16. package/components/Autocomplete/Autocomplete.cjs +93 -94
  17. package/components/Autocomplete/Autocomplete.cjs.map +1 -1
  18. package/components/Autocomplete/Autocomplete.d.ts +29 -26
  19. package/components/Autocomplete/Autocomplete.definitions.d.ts +2 -1
  20. package/components/Autocomplete/Autocomplete.helpers.d.ts +12 -8
  21. package/components/Autocomplete/Autocomplete.js +94 -95
  22. package/components/Autocomplete/Autocomplete.js.map +1 -1
  23. package/components/Autocomplete/_parts/AutocompleteChips.d.ts +7 -6
  24. package/components/Autocomplete/_parts/AutocompleteOption.d.ts +10 -13
  25. package/components/Autocomplete/index.d.ts +1 -1
  26. package/components/Avatar/Avatar.cjs +17 -18
  27. package/components/Avatar/Avatar.cjs.map +1 -1
  28. package/components/Avatar/Avatar.js +17 -18
  29. package/components/Avatar/Avatar.js.map +1 -1
  30. package/components/Avatar/index.d.ts +1 -0
  31. package/components/Button/Button.d.ts +5 -5
  32. package/components/Button/index.d.ts +1 -0
  33. package/components/Card/Card.cjs +3 -92
  34. package/components/Card/Card.cjs.map +1 -1
  35. package/components/Card/Card.d.ts +3 -50
  36. package/components/Card/Card.js +5 -94
  37. package/components/Card/Card.js.map +1 -1
  38. package/components/Card/Card.sx.d.ts +3 -6
  39. package/components/Card/index.d.ts +1 -1
  40. package/components/Checkbox/Checkbox.cjs +189 -0
  41. package/components/Checkbox/Checkbox.cjs.map +1 -0
  42. package/components/Checkbox/Checkbox.d.ts +55 -0
  43. package/components/Checkbox/Checkbox.js +189 -0
  44. package/components/Checkbox/Checkbox.js.map +1 -0
  45. package/components/Checkbox/Checkbox.sx.d.ts +13 -0
  46. package/components/Checkbox/index.d.ts +2 -0
  47. package/components/Checkbox.d.ts +6 -0
  48. package/components/Chip/Chip.cjs +2 -1
  49. package/components/Chip/Chip.cjs.map +1 -1
  50. package/components/Chip/Chip.js +2 -1
  51. package/components/Chip/Chip.js.map +1 -1
  52. package/components/Chip/index.d.ts +2 -1
  53. package/components/Chip.d.ts +4 -0
  54. package/components/DatePicker/DatePicker.cjs +40 -63
  55. package/components/DatePicker/DatePicker.cjs.map +1 -1
  56. package/components/DatePicker/DatePicker.d.ts +1 -13
  57. package/components/DatePicker/DatePicker.js +36 -59
  58. package/components/DatePicker/DatePicker.js.map +1 -1
  59. package/components/DatePicker/index.d.ts +1 -1
  60. package/components/DateTimePicker/DateTimePicker.cjs +58 -82
  61. package/components/DateTimePicker/DateTimePicker.cjs.map +1 -1
  62. package/components/DateTimePicker/DateTimePicker.d.ts +9 -17
  63. package/components/DateTimePicker/DateTimePicker.definitions.d.ts +2 -0
  64. package/components/DateTimePicker/DateTimePicker.helpers.d.ts +4 -2
  65. package/components/DateTimePicker/DateTimePicker.js +54 -78
  66. package/components/DateTimePicker/DateTimePicker.js.map +1 -1
  67. package/components/DateTimePicker/index.d.ts +1 -1
  68. package/components/Drawer/Drawer.cjs +12 -6
  69. package/components/Drawer/Drawer.cjs.map +1 -1
  70. package/components/Drawer/Drawer.d.ts +3 -1
  71. package/components/Drawer/Drawer.js +13 -7
  72. package/components/Drawer/Drawer.js.map +1 -1
  73. package/components/Drawer/DrawerItem.d.ts +6 -1
  74. package/components/Gallery/Gallery.cjs +154 -79
  75. package/components/Gallery/Gallery.cjs.map +1 -1
  76. package/components/Gallery/Gallery.d.ts +25 -9
  77. package/components/Gallery/Gallery.js +154 -79
  78. package/components/Gallery/Gallery.js.map +1 -1
  79. package/components/Gallery/GalleryLightbox.d.ts +6 -10
  80. package/components/Gallery/GalleryMain.d.ts +3 -7
  81. package/components/Gallery/GalleryThumbnails.d.ts +7 -11
  82. package/components/Gallery/index.d.ts +2 -1
  83. package/components/Gallery.d.ts +4 -0
  84. package/components/Icon/Icon.cjs +6 -8
  85. package/components/Icon/Icon.cjs.map +1 -1
  86. package/components/Icon/Icon.d.ts +11 -17
  87. package/components/Icon/Icon.js +6 -8
  88. package/components/Icon/Icon.js.map +1 -1
  89. package/components/Icon/index.d.ts +2 -1
  90. package/components/Icon.d.ts +4 -0
  91. package/components/Input/Input.cjs +26 -13
  92. package/components/Input/Input.cjs.map +1 -1
  93. package/components/Input/Input.d.ts +9 -2
  94. package/components/Input/Input.helpers.d.ts +3 -3
  95. package/components/Input/Input.js +23 -10
  96. package/components/Input/Input.js.map +1 -1
  97. package/components/Input/index.d.ts +1 -1
  98. package/components/InputGroup/InputGroup.cjs +23 -22
  99. package/components/InputGroup/InputGroup.cjs.map +1 -1
  100. package/components/InputGroup/InputGroup.d.ts +4 -4
  101. package/components/InputGroup/InputGroup.js +22 -21
  102. package/components/InputGroup/InputGroup.js.map +1 -1
  103. package/components/InputGroup/index.d.ts +2 -1
  104. package/components/InputGroup.d.ts +4 -0
  105. package/components/Modal/Modal.cjs +127 -98
  106. package/components/Modal/Modal.cjs.map +1 -1
  107. package/components/Modal/Modal.d.ts +20 -5
  108. package/components/Modal/Modal.js +130 -101
  109. package/components/Modal/Modal.js.map +1 -1
  110. package/components/Modal/ModalBody.d.ts +6 -1
  111. package/components/Modal/ModalFooter.d.ts +4 -4
  112. package/components/Modal/ModalHeader.d.ts +6 -1
  113. package/components/Modal/index.d.ts +4 -2
  114. package/components/Modal.d.ts +4 -0
  115. package/components/RadioGroup/RadioGroup.cjs +9 -7
  116. package/components/RadioGroup/RadioGroup.cjs.map +1 -1
  117. package/components/RadioGroup/RadioGroup.d.ts +9 -3
  118. package/components/RadioGroup/RadioGroup.js +9 -7
  119. package/components/RadioGroup/RadioGroup.js.map +1 -1
  120. package/components/RadioGroup/index.d.ts +1 -1
  121. package/components/Select/Select.cjs +129 -264
  122. package/components/Select/Select.cjs.map +1 -1
  123. package/components/Select/Select.d.ts +35 -20
  124. package/components/Select/Select.helpers.d.ts +6 -19
  125. package/components/Select/Select.js +134 -269
  126. package/components/Select/Select.js.map +1 -1
  127. package/components/Select/index.d.ts +1 -1
  128. package/components/Stat/Stat.cjs +2 -2
  129. package/components/Stat/Stat.cjs.map +1 -1
  130. package/components/Stat/Stat.js +2 -2
  131. package/components/Stat/Stat.js.map +1 -1
  132. package/components/Stat/index.d.ts +2 -1
  133. package/components/Stat.d.ts +4 -0
  134. package/components/StatusMessage/StatusMessage.cjs +84 -55
  135. package/components/StatusMessage/StatusMessage.cjs.map +1 -1
  136. package/components/StatusMessage/StatusMessage.d.ts +20 -36
  137. package/components/StatusMessage/StatusMessage.js +86 -57
  138. package/components/StatusMessage/StatusMessage.js.map +1 -1
  139. package/components/StatusMessage/StatusMessageContext.d.ts +16 -0
  140. package/components/StatusMessage/index.d.ts +4 -1
  141. package/components/StatusMessage.d.ts +4 -0
  142. package/components/Stepper/Stepper.cjs +289 -55
  143. package/components/Stepper/Stepper.cjs.map +1 -1
  144. package/components/Stepper/Stepper.d.ts +9 -20
  145. package/components/Stepper/Stepper.js +291 -57
  146. package/components/Stepper/Stepper.js.map +1 -1
  147. package/{hooks/Wizard/WizardContext.d.ts → components/Stepper/StepperContext.d.ts} +29 -23
  148. package/components/Stepper/_hooks/useHorizontalScroll.d.ts +19 -0
  149. package/components/Stepper/_parts/StepperScrollArrow.d.ts +19 -0
  150. package/components/Stepper/index.d.ts +6 -2
  151. package/components/Stepper.d.ts +4 -0
  152. package/components/Switch/Switch.cjs +5 -2
  153. package/components/Switch/Switch.cjs.map +1 -1
  154. package/components/Switch/Switch.d.ts +7 -2
  155. package/components/Switch/Switch.js +5 -2
  156. package/components/Switch/Switch.js.map +1 -1
  157. package/components/Tabs/Tabs.cjs +45 -29
  158. package/components/Tabs/Tabs.cjs.map +1 -1
  159. package/components/Tabs/Tabs.d.ts +21 -16
  160. package/components/Tabs/Tabs.js +46 -30
  161. package/components/Tabs/Tabs.js.map +1 -1
  162. package/components/Tabs/index.d.ts +4 -2
  163. package/components/Tabs.d.ts +4 -0
  164. package/components/Timeline/Timeline.cjs +3 -2
  165. package/components/Timeline/Timeline.cjs.map +1 -1
  166. package/components/Timeline/Timeline.d.ts +4 -8
  167. package/components/Timeline/Timeline.js +3 -2
  168. package/components/Timeline/Timeline.js.map +1 -1
  169. package/components/Timeline/index.d.ts +4 -2
  170. package/components/Timeline.d.ts +4 -0
  171. package/components/_shared/mergeSx.d.ts +7 -0
  172. package/{formField.sx-DfVbMe0V.js → formField.sx-8_QRnKxv.js} +2 -11
  173. package/formField.sx-8_QRnKxv.js.map +1 -0
  174. package/{formField.sx-CQ1mbk9M.cjs → formField.sx-BAX7KwMR.cjs} +10 -19
  175. package/formField.sx-BAX7KwMR.cjs.map +1 -0
  176. package/index.cjs +31 -2
  177. package/index.cjs.map +1 -1
  178. package/index.d.ts +1 -0
  179. package/index.js +16 -2
  180. package/index.js.map +1 -1
  181. package/mergeSx-BXoNZjB_.js +10 -0
  182. package/mergeSx-BXoNZjB_.js.map +1 -0
  183. package/mergeSx-Dbccoo_H.cjs +9 -0
  184. package/mergeSx-Dbccoo_H.cjs.map +1 -0
  185. package/mui.d.ts +3 -2
  186. package/package.json +6 -16
  187. package/theme/componentStyles.d.ts +1 -1
  188. package/tokens-BRrcP_p_.js +21 -0
  189. package/tokens-BRrcP_p_.js.map +1 -0
  190. package/tokens-jaWWNk39.cjs +20 -0
  191. package/tokens-jaWWNk39.cjs.map +1 -0
  192. package/utils/index.d.ts +2 -0
  193. package/{components/ScrollTopButton → utils}/scrollToTop.d.ts +6 -7
  194. package/components/AppBar/AppBarBrand.d.ts +0 -31
  195. package/components/AppBar/AppBarUserMenu.d.ts +0 -65
  196. package/components/Autocomplete/Autocomplete.types.d.ts +0 -1
  197. package/components/DatePicker/DatePicker.types.d.ts +0 -1
  198. package/components/DateTimePicker/DateTimePicker.types.d.ts +0 -1
  199. package/components/Input/Input.types.d.ts +0 -1
  200. package/components/PageLoader/PageLoader.cjs +0 -61
  201. package/components/PageLoader/PageLoader.cjs.map +0 -1
  202. package/components/PageLoader/PageLoader.d.ts +0 -38
  203. package/components/PageLoader/PageLoader.js +0 -61
  204. package/components/PageLoader/PageLoader.js.map +0 -1
  205. package/components/PageLoader/index.d.ts +0 -2
  206. package/components/PageLoader.d.ts +0 -6
  207. package/components/RadioGroup/RadioGroup.types.d.ts +0 -1
  208. package/components/ScrollTopButton/ScrollTopButton.cjs +0 -79
  209. package/components/ScrollTopButton/ScrollTopButton.cjs.map +0 -1
  210. package/components/ScrollTopButton/ScrollTopButton.d.ts +0 -48
  211. package/components/ScrollTopButton/ScrollTopButton.js +0 -79
  212. package/components/ScrollTopButton/ScrollTopButton.js.map +0 -1
  213. package/components/ScrollTopButton/index.d.ts +0 -4
  214. package/components/ScrollTopButton.d.ts +0 -6
  215. package/components/Select/Select.definitions.d.ts +0 -17
  216. package/components/Select/Select.types.d.ts +0 -1
  217. package/components/Select/_parts/SelectSearchHeader.d.ts +0 -15
  218. package/components/Select/_parts/SelectValue.d.ts +0 -22
  219. package/formField.sx-CQ1mbk9M.cjs.map +0 -1
  220. package/formField.sx-DfVbMe0V.js.map +0 -1
  221. package/hooks/Wizard/Wizard.cjs +0 -7
  222. package/hooks/Wizard/Wizard.cjs.map +0 -1
  223. package/hooks/Wizard/Wizard.js +0 -7
  224. package/hooks/Wizard/Wizard.js.map +0 -1
  225. package/hooks/Wizard/index.d.ts +0 -3
  226. package/hooks/Wizard/useWizard.d.ts +0 -9
  227. package/hooks/Wizard.d.ts +0 -2
  228. package/useWizard-CWdIxZzX.cjs +0 -94
  229. package/useWizard-CWdIxZzX.cjs.map +0 -1
  230. package/useWizard-CWq--C3o.js +0 -95
  231. package/useWizard-CWq--C3o.js.map +0 -1
  232. /package/{styles.css → index.css} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
2
  import { SelectProps as MuiSelectProps } from '@mui/material';
3
- import { Control, RegisterOptions } from 'react-hook-form';
3
+ import { RegisterOptions } from 'react-hook-form';
4
4
  export interface SelectOption {
5
5
  value: string | number;
6
6
  label: string;
@@ -10,7 +10,6 @@ export interface SelectOption {
10
10
  [key: string]: any;
11
11
  }
12
12
  export type LabelPosition = 'outside' | 'floating';
13
- export type ChipVariant = 'outlined' | 'filled';
14
13
  export type SelectSize = 'small' | 'medium';
15
14
  export type RenderOptionItem = (item: SelectOption) => ReactNode;
16
15
  export type RenderChipLabel = (item: SelectOption) => ReactNode;
@@ -22,21 +21,12 @@ export interface BaseSelectProps<TValue extends SelectOption['value'] = SelectOp
22
21
  options?: SelectOption[];
23
22
  defaultValue?: TValue | TValue[];
24
23
  size?: SelectSize;
25
- multiple?: boolean;
26
- filterable?: boolean;
27
24
  placeholder?: string;
28
25
  children?: ReactElement<{
29
26
  children: RenderOptionItem;
30
27
  }>;
31
28
  maxHeight?: number | string;
32
29
  maxWidth?: number | string;
33
- maxChipsToShow?: number;
34
- renderChipLabel?: RenderChipLabel;
35
- chipVariant?: ChipVariant;
36
- loadOptions?: (inputValue: string) => Promise<SelectOption[]>;
37
- loadingMessage?: ReactNode;
38
- noOptionsMessage?: ReactNode;
39
- debounceTimeout?: number;
40
30
  disabled?: boolean;
41
31
  error?: boolean;
42
32
  helperText?: string;
@@ -56,20 +46,45 @@ export interface BaseSelectProps<TValue extends SelectOption['value'] = SelectOp
56
46
  preset?: string;
57
47
  sx?: MuiSelectProps['sx'];
58
48
  className?: string;
49
+ /** Cantidad máxima de chips visibles antes de colapsar al "+N más". Default: 3. */
50
+ maxChipsToShow?: number;
51
+ /** Custom render del label de cada chip. Si no se pasa, usa `option.label`. */
52
+ renderChipLabel?: RenderChipLabel;
53
+ /** Variant de los chips. Default: 'outlined'. */
54
+ chipVariant?: 'outlined' | 'filled';
59
55
  }
60
- export interface RHFSelectProps<TValue extends SelectOption['value'] = SelectOption['value']> extends BaseSelectProps<TValue> {
61
- name: string;
62
- control: Control<any>;
63
- validation?: RegisterOptions;
64
- value?: TValue | TValue[];
65
- onChange?: (val: TValue | TValue[]) => void;
56
+ export interface SingleStandardSelectProps<TValue extends SelectOption['value'] = SelectOption['value']> extends BaseSelectProps<TValue> {
57
+ multiple?: false;
58
+ name?: string;
59
+ control?: never;
60
+ validation?: never;
61
+ value: TValue;
62
+ onChange: (val: TValue) => void;
66
63
  }
67
- export interface StandardSelectProps<TValue extends SelectOption['value'] = SelectOption['value']> extends BaseSelectProps<TValue> {
64
+ export interface MultipleStandardSelectProps<TValue extends SelectOption['value'] = SelectOption['value']> extends BaseSelectProps<TValue> {
65
+ multiple: true;
68
66
  name?: string;
69
67
  control?: never;
70
68
  validation?: never;
71
- value: TValue | TValue[];
72
- onChange: (val: TValue | TValue[]) => void;
69
+ value: TValue[];
70
+ onChange: (val: TValue[]) => void;
71
+ }
72
+ export type StandardSelectProps<TValue extends SelectOption['value'] = SelectOption['value']> = SingleStandardSelectProps<TValue> | MultipleStandardSelectProps<TValue>;
73
+ export interface RHFSelectProps<TValue extends SelectOption['value'] = SelectOption['value']> extends BaseSelectProps<TValue> {
74
+ /** En RHF se acepta como boolean dinámico — `field.value` se trata según
75
+ * esto: array si `multiple`, valor único si no. */
76
+ multiple?: boolean;
77
+ name: string;
78
+ control: any;
79
+ validation?: RegisterOptions;
80
+ /**
81
+ * Side-effect que corre después de que RHF actualiza el form state.
82
+ * Útil para cascadas entre campos (ej. reset de municipio al cambiar
83
+ * departamento). NO reemplaza al handler de RHF.
84
+ */
85
+ onValueChange?: (value: TValue | TValue[]) => void;
86
+ value?: never;
87
+ onChange?: never;
73
88
  }
74
89
  export type SelectProps<TValue extends SelectOption['value'] = SelectOption['value']> = RHFSelectProps<TValue> | StandardSelectProps<TValue>;
75
90
  export declare function Option(_props: OptionProps): null;
@@ -1,9 +1,4 @@
1
1
  import { SelectOption } from './Select';
2
- /**
3
- * Filtra opciones por `label` (case-insensitive). Si `search` es vacío,
4
- * devuelve el array completo. Solo se usa en modo no-async.
5
- */
6
- export declare const filterOptionsByLabel: (options: SelectOption[], search: string) => SelectOption[];
7
2
  /**
8
3
  * Agrupa opciones por la propiedad `group`. Las opciones sin group caen
9
4
  * bajo la key especial `__default`. Devuelve un Record para iterar en orden
@@ -11,18 +6,10 @@ export declare const filterOptionsByLabel: (options: SelectOption[], search: str
11
6
  */
12
7
  export declare const groupOptions: (options: SelectOption[]) => Record<string, SelectOption[]>;
13
8
  /**
14
- * Determina si un conjunto de grupos está efectivamente vacío
15
- * (no hay grupos o solo existe `__default` sin items).
16
- */
17
- export declare const isGroupedOptionsEmpty: (groups: Record<string, SelectOption[]>) => boolean;
18
- /**
19
- * Normaliza el valor actual al shape que espera el MUI Select:
20
- * - multiple: siempre array (aunque esté vacío).
21
- * - single: string vacío si null/undefined.
22
- */
23
- export declare const normalizeSelectValue: <T>(value: T | T[] | null | undefined, multiple: boolean) => T | T[] | "";
24
- /**
25
- * Evalúa si el valor actual está vacío (para decidir shrink del label
26
- * y visibilidad del placeholder).
9
+ * Normaliza el valor single al shape que espera MUI Select: string vacío si
10
+ * el valor es `null`/`undefined`.
27
11
  */
28
- export declare const isSelectValueEmpty: (normalizedValue: unknown, multiple: boolean) => boolean;
12
+ export declare const normalizeSelectValue: <T>(value: T | null | undefined) => T | "";
13
+ /** `true` si el valor está vacío (para shrink del label + placeholder). En
14
+ * multi se considera vacío cuando el array no tiene elementos. */
15
+ export declare const isSelectValueEmpty: (normalizedValue: unknown) => boolean;
@@ -29,21 +29,15 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
33
- import React__default, { useMemo, isValidElement, useState, useRef, useEffect } from "react";
34
- import { ListSubheader, TextField, Typography, Box, Chip, Avatar, MenuItem, ListItemIcon, CircularProgress, FormControl, InputLabel, Select as Select$1, FormHelperText, OutlinedInput } from "@mui/material";
32
+ import { jsxs, jsx } from "react/jsx-runtime";
33
+ import { useMemo, Children, isValidElement, useState } from "react";
34
+ import { MenuItem, ListItemIcon, FormControl, InputLabel, Select as Select$1, FormHelperText, ListSubheader, OutlinedInput, Typography, Box, Chip, Avatar } from "@mui/material";
35
35
  import { useTheme } from "@mui/material/styles";
36
36
  import { Controller } from "react-hook-form";
37
- import { b as buildFormFieldSx } from "../../formField.sx-DfVbMe0V.js";
37
+ import { b as buildFormFieldSx } from "../../formField.sx-8_QRnKxv.js";
38
38
  import { r as resolvePreset } from "../../resolvePreset-B-IB0ehH.js";
39
- import ClearIcon from "@mui/icons-material/Clear";
40
39
  import CheckIcon from "@mui/icons-material/Check";
41
40
  const buildSelectSx = (borderRadius, labelPosition) => buildFormFieldSx({ borderRadius, labelPosition });
42
- const filterOptionsByLabel = (options, search) => {
43
- if (!search) return options;
44
- const needle = search.toLowerCase();
45
- return options.filter((opt) => opt.label.toLowerCase().includes(needle));
46
- };
47
41
  const groupOptions = (options) => {
48
42
  const groups = {};
49
43
  options.forEach((opt) => {
@@ -53,108 +47,11 @@ const groupOptions = (options) => {
53
47
  });
54
48
  return groups;
55
49
  };
56
- const isGroupedOptionsEmpty = (groups) => {
57
- const keys = Object.keys(groups);
58
- if (keys.length === 0) return true;
59
- if (keys.length === 1 && groups["__default"] && groups["__default"].length === 0) {
60
- return true;
61
- }
62
- return false;
63
- };
64
- const normalizeSelectValue = (value, multiple) => {
65
- if (multiple) return value != null ? value : [];
66
- return value != null ? value : "";
67
- };
68
- const isSelectValueEmpty = (normalizedValue, multiple) => {
69
- if (multiple) return Array.isArray(normalizedValue) && normalizedValue.length === 0;
50
+ const normalizeSelectValue = (value) => value != null ? value : "";
51
+ const isSelectValueEmpty = (normalizedValue) => {
52
+ if (Array.isArray(normalizedValue)) return normalizedValue.length === 0;
70
53
  return normalizedValue === "" || normalizedValue === null || normalizedValue === void 0;
71
54
  };
72
- const SelectSearchHeader = ({
73
- value,
74
- onChange,
75
- placeholder = "Buscar...",
76
- inputRef
77
- }) => {
78
- return /* @__PURE__ */ jsx(
79
- ListSubheader,
80
- {
81
- sx: {
82
- px: 2,
83
- pt: 1,
84
- pb: 1,
85
- backgroundColor: "background.paper",
86
- zIndex: 1,
87
- position: "sticky",
88
- top: 0
89
- },
90
- children: /* @__PURE__ */ jsx(
91
- TextField,
92
- {
93
- inputRef,
94
- placeholder,
95
- variant: "standard",
96
- size: "small",
97
- fullWidth: true,
98
- value,
99
- onChange: (e) => onChange(e.target.value),
100
- slotProps: { htmlInput: { autoFocus: true } },
101
- onClick: (e) => e.stopPropagation(),
102
- onKeyDown: (e) => e.stopPropagation()
103
- }
104
- )
105
- }
106
- );
107
- };
108
- function SelectValue(props) {
109
- var _a;
110
- const {
111
- selected,
112
- options,
113
- multiple,
114
- placeholder,
115
- maxChipsToShow,
116
- chipVariant,
117
- renderChipLabel,
118
- onDeleteChip,
119
- currentValues
120
- } = props;
121
- const isEmpty = !selected || Array.isArray(selected) && selected.length === 0;
122
- if (isEmpty) {
123
- return /* @__PURE__ */ jsx(Typography, { sx: { color: "text.disabled" }, children: placeholder || "" });
124
- }
125
- if (!multiple) {
126
- const item = options.find((opt) => opt.value === selected);
127
- if (renderChipLabel && item) return /* @__PURE__ */ jsx(Fragment, { children: renderChipLabel(item) });
128
- return /* @__PURE__ */ jsx(Fragment, { children: (_a = item == null ? void 0 : item.label) != null ? _a : String(selected) });
129
- }
130
- const selectedValuesArray = selected;
131
- const displayedChips = selectedValuesArray.slice(0, maxChipsToShow);
132
- const hiddenChipsCount = selectedValuesArray.length - maxChipsToShow;
133
- const handleDelete = (chipValue) => {
134
- if (!onDeleteChip || !currentValues) return;
135
- onDeleteChip(currentValues.filter((v) => v !== chipValue));
136
- };
137
- return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: [
138
- displayedChips.map((val) => {
139
- const item = options.find((o) => o.value === val);
140
- if (!item) return null;
141
- return /* @__PURE__ */ jsx(
142
- Chip,
143
- {
144
- variant: chipVariant,
145
- color: "primary",
146
- size: "small",
147
- label: renderChipLabel ? renderChipLabel(item) : item.label,
148
- avatar: item.img ? /* @__PURE__ */ jsx(Avatar, { src: item.img }) : void 0,
149
- onDelete: () => handleDelete(val),
150
- deleteIcon: /* @__PURE__ */ jsx(ClearIcon, { fontSize: "small" })
151
- },
152
- String(val)
153
- );
154
- }),
155
- hiddenChipsCount > 0 && /* @__PURE__ */ jsx(Chip, { size: "small", variant: chipVariant, label: `+${hiddenChipsCount} más` })
156
- ] });
157
- }
158
55
  const renderSelectMenuItem = ({
159
56
  option,
160
57
  selected,
@@ -180,23 +77,12 @@ function Select(props) {
180
77
  const _a = props, {
181
78
  label,
182
79
  options = [],
183
- value,
184
- onChange,
185
80
  defaultValue,
186
81
  size = "small",
187
- multiple = false,
188
- filterable = false,
189
82
  placeholder,
190
83
  children,
191
84
  maxHeight = 300,
192
85
  maxWidth,
193
- maxChipsToShow = 3,
194
- renderChipLabel,
195
- chipVariant = "outlined",
196
- loadOptions,
197
- loadingMessage = "Cargando opciones...",
198
- noOptionsMessage = "No hay opciones",
199
- debounceTimeout = 300,
200
86
  disabled = false,
201
87
  error = false,
202
88
  helperText,
@@ -204,27 +90,26 @@ function Select(props) {
204
90
  labelPosition = "outside",
205
91
  preset,
206
92
  sx,
207
- className
93
+ className,
94
+ multiple = false,
95
+ maxChipsToShow = 3,
96
+ renderChipLabel,
97
+ chipVariant = "outlined",
98
+ name: _nameIgnored,
99
+ control: _controlIgnored,
100
+ validation: _validationIgnored,
101
+ value: _valueIgnored,
102
+ onChange: _onChangeIgnored,
103
+ onValueChange: _onValueChangeIgnored
208
104
  } = _a, rest = __objRest(_a, [
209
105
  "label",
210
106
  "options",
211
- "value",
212
- "onChange",
213
107
  "defaultValue",
214
108
  "size",
215
- "multiple",
216
- "filterable",
217
109
  "placeholder",
218
110
  "children",
219
111
  "maxHeight",
220
112
  "maxWidth",
221
- "maxChipsToShow",
222
- "renderChipLabel",
223
- "chipVariant",
224
- "loadOptions",
225
- "loadingMessage",
226
- "noOptionsMessage",
227
- "debounceTimeout",
228
113
  "disabled",
229
114
  "error",
230
115
  "helperText",
@@ -232,136 +117,119 @@ function Select(props) {
232
117
  "labelPosition",
233
118
  "preset",
234
119
  "sx",
235
- "className"
120
+ "className",
121
+ "multiple",
122
+ "maxChipsToShow",
123
+ "renderChipLabel",
124
+ "chipVariant",
125
+ // Separamos estos aunque no se usen directamente acá — evita que lleguen
126
+ // al DOM del MuiSelect via `{...rest}` y generen warnings de React.
127
+ "name",
128
+ "control",
129
+ "validation",
130
+ "value",
131
+ "onChange",
132
+ "onValueChange"
236
133
  ]);
237
134
  const theme = useTheme();
238
135
  const presetSx = resolvePreset("Select", preset, theme);
239
- const isRHFMode = "control" in rest && rest.control !== void 0;
136
+ const isRHFMode = "control" in props && props.control !== void 0;
240
137
  const customRender = useMemo(() => {
241
138
  var _a2;
242
- if (React__default.Children.count(children) === 1) {
243
- const child = React__default.Children.only(children);
139
+ if (Children.count(children) === 1) {
140
+ const child = Children.only(children);
244
141
  if (isValidElement(child) && ((_a2 = child.type) == null ? void 0 : _a2.displayName) === "Option") {
245
142
  return child.props.children;
246
143
  }
247
144
  }
248
145
  return null;
249
146
  }, [children]);
250
- const [search, setSearch] = useState("");
251
- const [asyncOptions, setAsyncOptions] = useState([]);
252
- const [loading, setLoading] = useState(false);
253
- const debounceTimerRef = useRef(null);
254
- const searchInputRef = useRef(null);
255
147
  const [isOpen, setIsOpen] = useState(false);
256
148
  const [isFocused, setIsFocused] = useState(false);
257
- const isAsync = typeof loadOptions === "function";
258
- const currentOptions = isAsync ? asyncOptions : options;
259
- useEffect(() => {
260
- var _a2;
261
- if (!isAsync) return;
262
- if (debounceTimerRef.current) clearTimeout(debounceTimerRef.current);
263
- if (search) {
264
- setLoading(true);
265
- debounceTimerRef.current = window.setTimeout(() => {
266
- loadOptions(search).then(setAsyncOptions).finally(() => {
267
- var _a3;
268
- setLoading(false);
269
- (_a3 = searchInputRef.current) == null ? void 0 : _a3.focus();
270
- });
271
- }, debounceTimeout);
272
- } else {
273
- setAsyncOptions([]);
274
- setLoading(false);
275
- (_a2 = searchInputRef.current) == null ? void 0 : _a2.focus();
276
- }
277
- }, [search, isAsync, loadOptions, debounceTimeout]);
278
- const filteredOptions = useMemo(() => {
279
- if (isAsync) return currentOptions;
280
- if (!filterable) return currentOptions;
281
- return filterOptionsByLabel(currentOptions, search);
282
- }, [search, filterable, currentOptions, isAsync]);
283
- const groupedOptions = useMemo(() => groupOptions(filteredOptions), [filteredOptions]);
284
- const menuItems = useMemo(() => {
149
+ const groupedOptions = useMemo(() => groupOptions(options), [options]);
150
+ const isSelected = (currentValue, val) => {
151
+ if (Array.isArray(currentValue)) return currentValue.includes(val);
152
+ return currentValue === val;
153
+ };
154
+ const buildMenuItems = (currentValue) => {
285
155
  const items = [];
286
- if (filterable || isAsync) {
287
- items.push(
288
- /* @__PURE__ */ jsx(
289
- SelectSearchHeader,
290
- {
291
- value: search,
292
- onChange: setSearch,
293
- inputRef: searchInputRef
294
- },
295
- "search-header"
296
- )
297
- );
298
- }
299
- const noOptions = isGroupedOptionsEmpty(groupedOptions);
300
- if (loading) {
301
- items.push(
302
- /* @__PURE__ */ jsx(MenuItem, { disabled: true, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
303
- /* @__PURE__ */ jsx(CircularProgress, { size: 20 }),
304
- /* @__PURE__ */ jsx(Typography, { children: loadingMessage })
305
- ] }) }, "loading-message")
306
- );
307
- } else if (noOptions) {
308
- items.push(
309
- /* @__PURE__ */ jsx(MenuItem, { disabled: true, children: /* @__PURE__ */ jsx(Typography, { children: noOptionsMessage }) }, "no-options-message")
310
- );
311
- } else {
312
- Object.entries(groupedOptions).forEach(([group, opts]) => {
313
- if (group !== "__default") {
314
- items.push(
315
- /* @__PURE__ */ jsx(ListSubheader, { disableSticky: true, children: group }, group)
316
- );
317
- }
318
- opts.forEach((opt) => {
319
- var _a2;
320
- const isSelected = multiple ? (_a2 = value == null ? void 0 : value.includes(opt.value)) != null ? _a2 : false : value === opt.value;
321
- items.push(
322
- renderSelectMenuItem({
323
- option: opt,
324
- selected: isSelected,
325
- customRender
326
- })
327
- );
328
- });
156
+ Object.entries(groupedOptions).forEach(([group, opts]) => {
157
+ if (group !== "__default") {
158
+ items.push(
159
+ /* @__PURE__ */ jsx(ListSubheader, { disableSticky: true, children: group }, group)
160
+ );
161
+ }
162
+ opts.forEach((opt) => {
163
+ items.push(
164
+ renderSelectMenuItem({
165
+ option: opt,
166
+ selected: isSelected(currentValue, opt.value),
167
+ customRender
168
+ })
169
+ );
329
170
  });
330
- }
171
+ });
331
172
  return items;
332
- }, [
333
- groupedOptions,
334
- customRender,
335
- filterable,
336
- isAsync,
337
- search,
338
- loading,
339
- loadingMessage,
340
- noOptionsMessage,
341
- multiple,
342
- value
343
- ]);
344
- const handleChangeInternal = (event, rhfOnChange) => {
345
- const newValue = event.target.value;
346
- if (isRHFMode) {
347
- rhfOnChange == null ? void 0 : rhfOnChange(newValue);
348
- } else {
349
- onChange == null ? void 0 : onChange(newValue);
350
- }
351
173
  };
352
174
  const mergedSx = [
353
175
  buildSelectSx(borderRadius, labelPosition),
354
176
  ...presetSx ? [presetSx] : [],
355
- ...Array.isArray(sx) ? sx : [sx]
177
+ ...Array.isArray(sx) ? sx : sx ? [sx] : []
356
178
  ];
357
- const renderSelect = (selectValue, selectOnChange, onBlur, inputRef, rhfError, rhfHelperText) => {
358
- const finalError = rhfError != null ? rhfError : error;
179
+ const renderSelect = (selectValue, commitValue, onBlur, inputRef, rhfError, rhfHelperText) => {
180
+ const finalError = !!rhfError || !!error;
359
181
  const finalHelperText = rhfHelperText != null ? rhfHelperText : helperText;
360
182
  const inputElement = labelPosition === "floating" ? /* @__PURE__ */ jsx(OutlinedInput, { label }) : /* @__PURE__ */ jsx(OutlinedInput, {});
361
- const normalizedValue = normalizeSelectValue(selectValue, multiple);
362
- const isEmpty = isSelectValueEmpty(normalizedValue, multiple);
183
+ const normalizedValue = multiple ? selectValue != null ? selectValue : [] : normalizeSelectValue(selectValue);
184
+ const isEmpty = isSelectValueEmpty(normalizedValue);
363
185
  const shouldShrink = !isEmpty || isFocused || isOpen;
364
186
  const shouldDisplayPlaceholder = isEmpty && (isFocused || isOpen) && !!placeholder;
187
+ const renderValueFn = (selected) => {
188
+ var _a2;
189
+ if (multiple) {
190
+ const arr = selected != null ? selected : [];
191
+ if (arr.length === 0) {
192
+ return /* @__PURE__ */ jsx(Typography, { sx: { color: "text.disabled" }, children: placeholder != null ? placeholder : "" });
193
+ }
194
+ const visible = arr.slice(0, maxChipsToShow);
195
+ const hidden = arr.length - visible.length;
196
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: [
197
+ visible.map((val) => {
198
+ const item2 = options.find((o) => o.value === val);
199
+ if (!item2) return null;
200
+ return /* @__PURE__ */ jsx(
201
+ Chip,
202
+ {
203
+ variant: chipVariant,
204
+ color: "primary",
205
+ size,
206
+ label: renderChipLabel ? renderChipLabel(item2) : item2.label,
207
+ avatar: item2.img ? /* @__PURE__ */ jsx(Avatar, { src: item2.img }) : void 0,
208
+ onMouseDown: (e) => e.stopPropagation(),
209
+ onDelete: () => {
210
+ commitValue(arr.filter((v) => v !== val));
211
+ }
212
+ },
213
+ String(val)
214
+ );
215
+ }),
216
+ hidden > 0 && /* @__PURE__ */ jsx(
217
+ Chip,
218
+ {
219
+ variant: chipVariant,
220
+ size,
221
+ label: `+${hidden} más`,
222
+ onMouseDown: (e) => e.stopPropagation()
223
+ }
224
+ )
225
+ ] });
226
+ }
227
+ if (isSelectValueEmpty(selected)) {
228
+ return /* @__PURE__ */ jsx(Typography, { sx: { color: "text.disabled" }, children: placeholder != null ? placeholder : "" });
229
+ }
230
+ const item = options.find((opt) => opt.value === selected);
231
+ return (_a2 = item == null ? void 0 : item.label) != null ? _a2 : String(selected);
232
+ };
365
233
  return /* @__PURE__ */ jsxs(
366
234
  FormControl,
367
235
  {
@@ -376,10 +244,9 @@ function Select(props) {
376
244
  /* @__PURE__ */ jsx(
377
245
  Select$1,
378
246
  __spreadProps(__spreadValues({
379
- value: normalizedValue,
380
- defaultValue,
381
247
  multiple,
382
- onChange: selectOnChange,
248
+ value: normalizedValue,
249
+ onChange: (e) => commitValue(e.target.value),
383
250
  onBlur: (e) => {
384
251
  setIsFocused(false);
385
252
  onBlur == null ? void 0 : onBlur(e);
@@ -387,20 +254,7 @@ function Select(props) {
387
254
  onFocus: () => setIsFocused(true),
388
255
  onOpen: () => setIsOpen(true),
389
256
  onClose: () => setIsOpen(false),
390
- renderValue: (selected) => /* @__PURE__ */ jsx(
391
- SelectValue,
392
- {
393
- selected,
394
- options: currentOptions,
395
- multiple,
396
- placeholder,
397
- maxChipsToShow,
398
- chipVariant,
399
- renderChipLabel,
400
- currentValues: value != null ? value : [],
401
- onDeleteChip: (next) => onChange == null ? void 0 : onChange(next)
402
- }
403
- ),
257
+ renderValue: renderValueFn,
404
258
  displayEmpty: shouldDisplayPlaceholder,
405
259
  input: inputElement,
406
260
  disabled,
@@ -411,7 +265,7 @@ function Select(props) {
411
265
  },
412
266
  inputRef
413
267
  }, rest), {
414
- children: menuItems
268
+ children: buildMenuItems(normalizedValue)
415
269
  })
416
270
  ),
417
271
  finalHelperText && /* @__PURE__ */ jsx(FormHelperText, { children: finalHelperText })
@@ -420,25 +274,36 @@ function Select(props) {
420
274
  );
421
275
  };
422
276
  if (isRHFMode) {
423
- const rhfProps = rest;
277
+ const { name, control, validation, onValueChange } = props;
424
278
  return /* @__PURE__ */ jsx(
425
279
  Controller,
426
280
  {
427
- name: rhfProps.name,
428
- control: rhfProps.control,
429
- rules: rhfProps.validation,
430
- render: ({ field, fieldState: { error: fieldError } }) => renderSelect(
431
- field.value,
432
- (e) => handleChangeInternal(e, field.onChange),
433
- field.onBlur,
434
- field.ref,
435
- !!fieldError,
436
- fieldError == null ? void 0 : fieldError.message
437
- )
281
+ name,
282
+ control,
283
+ rules: validation,
284
+ defaultValue,
285
+ render: ({ field, fieldState: { error: fieldError } }) => {
286
+ var _a2;
287
+ return renderSelect(
288
+ (_a2 = field.value) != null ? _a2 : multiple ? [] : null,
289
+ (next) => {
290
+ field.onChange(next);
291
+ onValueChange == null ? void 0 : onValueChange(next);
292
+ },
293
+ field.onBlur,
294
+ field.ref,
295
+ !!fieldError,
296
+ fieldError == null ? void 0 : fieldError.message
297
+ );
298
+ }
438
299
  }
439
300
  );
440
301
  }
441
- return renderSelect(value, (e) => handleChangeInternal(e));
302
+ const standardProps = props;
303
+ return renderSelect(
304
+ standardProps.value,
305
+ (next) => standardProps.onChange(next)
306
+ );
442
307
  }
443
308
  export {
444
309
  Option,