@soyfri/shared-library 2.0.0-beta.12 → 2.0.0-beta.15
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/{Autocomplete-C2x-lBvZ.cjs → Autocomplete-4i0dNDKr.cjs} +55 -33
- package/Autocomplete-4i0dNDKr.cjs.map +1 -0
- package/{Autocomplete-BA-cGASd.js → Autocomplete-i3-V38n1.js} +56 -34
- package/Autocomplete-i3-V38n1.js.map +1 -0
- package/{Avatar-BJTr-PBd.js → Avatar-CgT7955R.js} +18 -19
- package/Avatar-CgT7955R.js.map +1 -0
- package/{Avatar-9L7YMxya.cjs → Avatar-CuSrK8Wn.cjs} +18 -19
- package/Avatar-CuSrK8Wn.cjs.map +1 -0
- package/Button-C17mExpd.cjs.map +1 -1
- package/Button-UkkP-bNw.js.map +1 -1
- package/Card-B1wtavyl.js +98 -0
- package/Card-B1wtavyl.js.map +1 -0
- package/Card-DfdU610V.cjs +97 -0
- package/Card-DfdU610V.cjs.map +1 -0
- package/Checkbox-BCqMFWt4.cjs +187 -0
- package/Checkbox-BCqMFWt4.cjs.map +1 -0
- package/Checkbox-gB5YKkVo.js +188 -0
- package/Checkbox-gB5YKkVo.js.map +1 -0
- package/{DatePicker-DLSfkgGA.cjs → DatePicker-CtCFqXDw.cjs} +41 -64
- package/DatePicker-CtCFqXDw.cjs.map +1 -0
- package/{DatePicker-8f_9bwhS.js → DatePicker-D0Bz9Ryg.js} +37 -60
- package/DatePicker-D0Bz9Ryg.js.map +1 -0
- package/{DateTimePicker-D4L9GAod.js → DateTimePicker-77w-9TP5.js} +27 -17
- package/DateTimePicker-77w-9TP5.js.map +1 -0
- package/{DateTimePicker-CWNW09-O.cjs → DateTimePicker-CTnRQCZo.cjs} +31 -21
- package/DateTimePicker-CTnRQCZo.cjs.map +1 -0
- package/{Input-DI0jfq5X.cjs → Input-jYapjJYM.cjs} +27 -14
- package/Input-jYapjJYM.cjs.map +1 -0
- package/{Input-Cp911l23.js → Input-rVVhI_wk.js} +24 -11
- package/Input-rVVhI_wk.js.map +1 -0
- package/{Modal-Bm_HH9cv.cjs → Modal-BN5s-Tfk.cjs} +126 -98
- package/Modal-BN5s-Tfk.cjs.map +1 -0
- package/{Modal-Bnz6d9m9.js → Modal-BRZMPwDj.js} +134 -106
- package/Modal-BRZMPwDj.js.map +1 -0
- package/{RadioGroup-CxqDHap1.cjs → RadioGroup-Dd0rHXSX.cjs} +10 -8
- package/RadioGroup-Dd0rHXSX.cjs.map +1 -0
- package/{RadioGroup-DMi9FvMP.js → RadioGroup-bO-ahP9T.js} +10 -8
- package/RadioGroup-bO-ahP9T.js.map +1 -0
- package/Select-B6jE3WH_.cjs +253 -0
- package/Select-B6jE3WH_.cjs.map +1 -0
- package/Select-bSVQokFX.js +254 -0
- package/Select-bSVQokFX.js.map +1 -0
- package/StatusMessage-B3nXpuRl.cjs +88 -0
- package/StatusMessage-B3nXpuRl.cjs.map +1 -0
- package/StatusMessage-D0WgSBx7.js +89 -0
- package/StatusMessage-D0WgSBx7.js.map +1 -0
- package/Step-BArsou1V.js +301 -0
- package/Step-BArsou1V.js.map +1 -0
- package/Step-Nd7SJbRZ.cjs +300 -0
- package/Step-Nd7SJbRZ.cjs.map +1 -0
- package/{Switch-BIeobv6i.cjs → Switch-CQFOopYy.cjs} +6 -3
- package/Switch-CQFOopYy.cjs.map +1 -0
- package/{Switch-DQEOxM2R.js → Switch-D72dpkH2.js} +6 -3
- package/Switch-D72dpkH2.js.map +1 -0
- package/{Tab-Co31KY2k.cjs → Tab-BbP8jBcK.cjs} +43 -28
- package/Tab-BbP8jBcK.cjs.map +1 -0
- package/Tab-BxSxKJsP.js +111 -0
- package/Tab-BxSxKJsP.js.map +1 -0
- package/components/ActionMenu/ActionMenu.cjs +52 -52
- package/components/ActionMenu/ActionMenu.cjs.map +1 -1
- package/components/ActionMenu/ActionMenu.d.ts +20 -36
- package/components/ActionMenu/ActionMenu.js +55 -55
- package/components/ActionMenu/ActionMenu.js.map +1 -1
- package/components/ActionMenu/index.d.ts +2 -2
- package/components/AppBar/AppBar.cjs +2 -219
- package/components/AppBar/AppBar.cjs.map +1 -1
- package/components/AppBar/AppBar.d.ts +6 -6
- package/components/AppBar/AppBar.js +5 -222
- package/components/AppBar/AppBar.js.map +1 -1
- package/components/AppBar/index.d.ts +0 -6
- package/components/Autocomplete/Autocomplete.cjs +1 -1
- package/components/Autocomplete/Autocomplete.d.ts +8 -6
- package/components/Autocomplete/Autocomplete.helpers.d.ts +8 -4
- package/components/Autocomplete/Autocomplete.js +1 -1
- package/components/Autocomplete/_parts/AutocompleteOption.d.ts +5 -8
- package/components/Autocomplete/index.d.ts +1 -1
- package/components/Avatar/Avatar.cjs +1 -1
- package/components/Avatar/Avatar.js +1 -1
- package/components/Avatar/index.d.ts +1 -0
- package/components/Button/Button.d.ts +5 -5
- package/components/Button/index.d.ts +1 -0
- package/components/Card/Card.cjs +1 -4
- package/components/Card/Card.cjs.map +1 -1
- package/components/Card/Card.d.ts +3 -50
- package/components/Card/Card.js +1 -4
- package/components/Card/Card.sx.d.ts +3 -6
- package/components/Card/index.d.ts +1 -1
- package/components/Checkbox/Checkbox.cjs +6 -0
- package/components/Checkbox/Checkbox.cjs.map +1 -0
- package/components/Checkbox/Checkbox.d.ts +55 -0
- package/components/Checkbox/Checkbox.js +6 -0
- package/components/Checkbox/Checkbox.js.map +1 -0
- package/components/Checkbox/Checkbox.sx.d.ts +13 -0
- package/components/Checkbox/index.d.ts +2 -0
- package/components/Checkbox.d.ts +6 -0
- package/components/Chip/Chip.cjs +2 -1
- package/components/Chip/Chip.cjs.map +1 -1
- package/components/Chip/Chip.js +3 -2
- package/components/Chip/index.d.ts +2 -1
- package/components/Chip.d.ts +4 -0
- package/components/DatePicker/DatePicker.cjs +1 -1
- package/components/DatePicker/DatePicker.d.ts +1 -13
- package/components/DatePicker/DatePicker.js +1 -1
- package/components/DatePicker/index.d.ts +1 -1
- package/components/DateTimePicker/DateTimePicker.cjs +1 -1
- package/components/DateTimePicker/DateTimePicker.d.ts +10 -6
- package/components/DateTimePicker/DateTimePicker.definitions.d.ts +2 -0
- package/components/DateTimePicker/DateTimePicker.helpers.d.ts +4 -2
- package/components/DateTimePicker/DateTimePicker.js +1 -1
- package/components/DateTimePicker/index.d.ts +1 -1
- package/components/Drawer/Drawer.cjs +10 -6
- package/components/Drawer/Drawer.cjs.map +1 -1
- package/components/Drawer/Drawer.js +11 -7
- package/components/Drawer/Drawer.js.map +1 -1
- package/components/Drawer/DrawerItem.d.ts +6 -1
- package/components/Gallery/Gallery.cjs +154 -79
- package/components/Gallery/Gallery.cjs.map +1 -1
- package/components/Gallery/Gallery.d.ts +25 -9
- package/components/Gallery/Gallery.js +154 -79
- package/components/Gallery/Gallery.js.map +1 -1
- package/components/Gallery/GalleryLightbox.d.ts +6 -10
- package/components/Gallery/GalleryMain.d.ts +3 -7
- package/components/Gallery/GalleryThumbnails.d.ts +7 -11
- package/components/Gallery/index.d.ts +2 -1
- package/components/Gallery.d.ts +4 -0
- package/components/Icon/Icon.cjs +6 -8
- package/components/Icon/Icon.cjs.map +1 -1
- package/components/Icon/Icon.d.ts +11 -17
- package/components/Icon/Icon.js +6 -8
- package/components/Icon/Icon.js.map +1 -1
- package/components/Icon/index.d.ts +2 -1
- package/components/Icon.d.ts +4 -0
- package/components/Input/Input.cjs +1 -1
- package/components/Input/Input.d.ts +9 -2
- package/components/Input/Input.helpers.d.ts +3 -3
- package/components/Input/Input.js +1 -1
- package/components/Input/index.d.ts +1 -1
- package/components/InputGroup/InputGroup.cjs +23 -22
- package/components/InputGroup/InputGroup.cjs.map +1 -1
- package/components/InputGroup/InputGroup.d.ts +4 -4
- package/components/InputGroup/InputGroup.js +22 -21
- package/components/InputGroup/InputGroup.js.map +1 -1
- package/components/InputGroup/index.d.ts +2 -1
- package/components/InputGroup.d.ts +4 -0
- package/components/Modal/Modal.cjs +1 -1
- package/components/Modal/Modal.d.ts +20 -5
- package/components/Modal/Modal.js +6 -6
- package/components/Modal/ModalBody.d.ts +6 -1
- package/components/Modal/ModalFooter.d.ts +4 -4
- package/components/Modal/ModalHeader.d.ts +6 -1
- package/components/Modal/index.d.ts +2 -0
- package/components/RadioGroup/RadioGroup.cjs +1 -1
- package/components/RadioGroup/RadioGroup.d.ts +9 -3
- package/components/RadioGroup/RadioGroup.js +1 -1
- package/components/RadioGroup/index.d.ts +1 -1
- package/components/Select/Select.cjs +1 -1
- package/components/Select/Select.d.ts +13 -18
- package/components/Select/Select.helpers.d.ts +5 -19
- package/components/Select/Select.js +1 -1
- package/components/Select/index.d.ts +1 -1
- package/components/Stat/Stat.cjs +2 -2
- package/components/Stat/Stat.js +3 -3
- package/components/Stat/Stat.js.map +1 -1
- package/components/Stat/index.d.ts +2 -1
- package/components/Stat.d.ts +4 -0
- package/components/StatusMessage/StatusMessage.cjs +1 -1
- package/components/StatusMessage/StatusMessage.d.ts +20 -36
- package/components/StatusMessage/StatusMessage.js +1 -1
- package/components/Stepper/Stepper.cjs +6 -2
- package/components/Stepper/Stepper.cjs.map +1 -1
- package/components/Stepper/Stepper.d.ts +9 -8
- package/components/Stepper/Stepper.js +6 -2
- package/{hooks/Wizard/WizardContext.d.ts → components/Stepper/StepperContext.d.ts} +28 -22
- package/components/Stepper/_hooks/useHorizontalScroll.d.ts +19 -0
- package/components/Stepper/_parts/StepperScrollArrow.d.ts +19 -0
- package/components/Stepper/index.d.ts +6 -2
- package/components/Stepper.d.ts +4 -0
- package/components/Switch/Switch.cjs +1 -1
- package/components/Switch/Switch.d.ts +7 -2
- package/components/Switch/Switch.js +1 -1
- package/components/Tabs/Tabs.cjs +3 -2
- package/components/Tabs/Tabs.cjs.map +1 -1
- package/components/Tabs/Tabs.d.ts +21 -16
- package/components/Tabs/Tabs.js +3 -2
- package/components/Tabs/index.d.ts +4 -2
- package/components/Tabs.d.ts +4 -0
- package/components/Timeline/Timeline.cjs +3 -2
- package/components/Timeline/Timeline.cjs.map +1 -1
- package/components/Timeline/Timeline.d.ts +4 -8
- package/components/Timeline/Timeline.js +3 -2
- package/components/Timeline/Timeline.js.map +1 -1
- package/components/Timeline/index.d.ts +4 -2
- package/components/Timeline.d.ts +4 -0
- package/components/_shared/mergeSx.d.ts +7 -0
- package/{formField.sx-DfVbMe0V.js → formField.sx-8_QRnKxv.js} +2 -11
- package/formField.sx-8_QRnKxv.js.map +1 -0
- package/{formField.sx-CQ1mbk9M.cjs → formField.sx-BAX7KwMR.cjs} +10 -19
- package/formField.sx-BAX7KwMR.cjs.map +1 -0
- package/index.cjs +38 -15
- package/index.cjs.map +1 -1
- package/index.d.ts +3 -0
- package/index.js +33 -19
- package/index.js.map +1 -1
- package/mergeSx-BXoNZjB_.js +10 -0
- package/mergeSx-BXoNZjB_.js.map +1 -0
- package/mergeSx-Dbccoo_H.cjs +9 -0
- package/mergeSx-Dbccoo_H.cjs.map +1 -0
- package/mui.d.ts +2 -1
- package/package.json +62 -72
- package/theme/componentStyles.d.ts +1 -1
- package/tokens-BRrcP_p_.js +21 -0
- package/tokens-BRrcP_p_.js.map +1 -0
- package/tokens-jaWWNk39.cjs +20 -0
- package/tokens-jaWWNk39.cjs.map +1 -0
- package/utils/index.d.ts +2 -0
- package/{components/ScrollTopButton → utils}/scrollToTop.d.ts +6 -7
- package/Autocomplete-BA-cGASd.js.map +0 -1
- package/Autocomplete-C2x-lBvZ.cjs.map +0 -1
- package/Avatar-9L7YMxya.cjs.map +0 -1
- package/Avatar-BJTr-PBd.js.map +0 -1
- package/Card-DG_crfkK.cjs +0 -185
- package/Card-DG_crfkK.cjs.map +0 -1
- package/Card-Ug-ttVSh.js +0 -186
- package/Card-Ug-ttVSh.js.map +0 -1
- package/DatePicker-8f_9bwhS.js.map +0 -1
- package/DatePicker-DLSfkgGA.cjs.map +0 -1
- package/DateTimePicker-CWNW09-O.cjs.map +0 -1
- package/DateTimePicker-D4L9GAod.js.map +0 -1
- package/Input-Cp911l23.js.map +0 -1
- package/Input-DI0jfq5X.cjs.map +0 -1
- package/Modal-Bm_HH9cv.cjs.map +0 -1
- package/Modal-Bnz6d9m9.js.map +0 -1
- package/RadioGroup-CxqDHap1.cjs.map +0 -1
- package/RadioGroup-DMi9FvMP.js.map +0 -1
- package/Select-3CBOfM2H.js +0 -447
- package/Select-3CBOfM2H.js.map +0 -1
- package/Select-Bku4f4f8.cjs +0 -446
- package/Select-Bku4f4f8.cjs.map +0 -1
- package/StatusMessage-C5B6oGZ_.cjs +0 -78
- package/StatusMessage-C5B6oGZ_.cjs.map +0 -1
- package/StatusMessage-D1GlfQdz.js +0 -79
- package/StatusMessage-D1GlfQdz.js.map +0 -1
- package/Step-Dq0N72YB.js +0 -49
- package/Step-Dq0N72YB.js.map +0 -1
- package/Step-a8U8O-91.cjs +0 -48
- package/Step-a8U8O-91.cjs.map +0 -1
- package/Switch-BIeobv6i.cjs.map +0 -1
- package/Switch-DQEOxM2R.js.map +0 -1
- package/Tab-Co31KY2k.cjs.map +0 -1
- package/Tab-DiK62gRz.js +0 -96
- package/Tab-DiK62gRz.js.map +0 -1
- package/components/AppBar/AppBarBrand.d.ts +0 -31
- package/components/AppBar/AppBarUserMenu.d.ts +0 -65
- package/components/Autocomplete/Autocomplete.types.d.ts +0 -1
- package/components/DatePicker/DatePicker.types.d.ts +0 -1
- package/components/DateTimePicker/DateTimePicker.types.d.ts +0 -1
- package/components/Input/Input.types.d.ts +0 -1
- package/components/PageLoader/PageLoader.cjs +0 -61
- package/components/PageLoader/PageLoader.cjs.map +0 -1
- package/components/PageLoader/PageLoader.d.ts +0 -38
- package/components/PageLoader/PageLoader.js +0 -61
- package/components/PageLoader/PageLoader.js.map +0 -1
- package/components/PageLoader/index.d.ts +0 -2
- package/components/PageLoader.d.ts +0 -6
- package/components/RadioGroup/RadioGroup.types.d.ts +0 -1
- package/components/ScrollTopButton/ScrollTopButton.cjs +0 -79
- package/components/ScrollTopButton/ScrollTopButton.cjs.map +0 -1
- package/components/ScrollTopButton/ScrollTopButton.d.ts +0 -48
- package/components/ScrollTopButton/ScrollTopButton.js +0 -79
- package/components/ScrollTopButton/ScrollTopButton.js.map +0 -1
- package/components/ScrollTopButton/index.d.ts +0 -4
- package/components/ScrollTopButton.d.ts +0 -6
- package/components/Select/Select.definitions.d.ts +0 -17
- package/components/Select/Select.types.d.ts +0 -1
- package/components/Select/_parts/SelectSearchHeader.d.ts +0 -15
- package/formField.sx-CQ1mbk9M.cjs.map +0 -1
- package/formField.sx-DfVbMe0V.js.map +0 -1
- package/hooks/Wizard/Wizard.cjs +0 -7
- package/hooks/Wizard/Wizard.cjs.map +0 -1
- package/hooks/Wizard/Wizard.js +0 -7
- package/hooks/Wizard/Wizard.js.map +0 -1
- package/hooks/Wizard/index.d.ts +0 -3
- package/hooks/Wizard/useWizard.d.ts +0 -9
- package/hooks/Wizard.d.ts +0 -2
- package/useWizard-CWdIxZzX.cjs +0 -94
- package/useWizard-CWdIxZzX.cjs.map +0 -1
- package/useWizard-CWq--C3o.js +0 -95
- package/useWizard-CWq--C3o.js.map +0 -1
- /package/{styles.css → index.css} +0 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
34
|
+
const React = require("react");
|
|
35
|
+
const material = require("@mui/material");
|
|
36
|
+
const styles = require("@mui/material/styles");
|
|
37
|
+
const reactHookForm = require("react-hook-form");
|
|
38
|
+
const formField_sx = require("./formField.sx-BAX7KwMR.cjs");
|
|
39
|
+
const resolvePreset = require("./resolvePreset-CxTI6_Ln.cjs");
|
|
40
|
+
const CheckIcon = require("@mui/icons-material/Check");
|
|
41
|
+
const buildSelectSx = (borderRadius, labelPosition) => formField_sx.buildFormFieldSx({ borderRadius, labelPosition });
|
|
42
|
+
const groupOptions = (options) => {
|
|
43
|
+
const groups = {};
|
|
44
|
+
options.forEach((opt) => {
|
|
45
|
+
const group = opt.group || "__default";
|
|
46
|
+
if (!groups[group]) groups[group] = [];
|
|
47
|
+
groups[group].push(opt);
|
|
48
|
+
});
|
|
49
|
+
return groups;
|
|
50
|
+
};
|
|
51
|
+
const normalizeSelectValue = (value) => value != null ? value : "";
|
|
52
|
+
const isSelectValueEmpty = (normalizedValue) => normalizedValue === "" || normalizedValue === null || normalizedValue === void 0;
|
|
53
|
+
const renderSelectMenuItem = ({
|
|
54
|
+
option,
|
|
55
|
+
selected,
|
|
56
|
+
customRender
|
|
57
|
+
}) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
58
|
+
material.MenuItem,
|
|
59
|
+
{
|
|
60
|
+
value: option.value,
|
|
61
|
+
disabled: option.disabled,
|
|
62
|
+
selected,
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.ListItemIcon, { sx: { minWidth: 32 }, children: selected && /* @__PURE__ */ jsxRuntime.jsx(CheckIcon, { color: "success", fontSize: "small" }) }),
|
|
65
|
+
customRender ? customRender(option) : option.label
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
String(option.value)
|
|
69
|
+
);
|
|
70
|
+
function Option(_props) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
Option.displayName = "Option";
|
|
74
|
+
function Select(props) {
|
|
75
|
+
const _a = props, {
|
|
76
|
+
label,
|
|
77
|
+
options = [],
|
|
78
|
+
defaultValue,
|
|
79
|
+
size = "small",
|
|
80
|
+
placeholder,
|
|
81
|
+
children,
|
|
82
|
+
maxHeight = 300,
|
|
83
|
+
maxWidth,
|
|
84
|
+
disabled = false,
|
|
85
|
+
error = false,
|
|
86
|
+
helperText,
|
|
87
|
+
borderRadius = 10,
|
|
88
|
+
labelPosition = "outside",
|
|
89
|
+
preset,
|
|
90
|
+
sx,
|
|
91
|
+
className,
|
|
92
|
+
name: _nameIgnored,
|
|
93
|
+
control: _controlIgnored,
|
|
94
|
+
validation: _validationIgnored,
|
|
95
|
+
value: _valueIgnored,
|
|
96
|
+
onChange: _onChangeIgnored
|
|
97
|
+
} = _a, rest = __objRest(_a, [
|
|
98
|
+
"label",
|
|
99
|
+
"options",
|
|
100
|
+
"defaultValue",
|
|
101
|
+
"size",
|
|
102
|
+
"placeholder",
|
|
103
|
+
"children",
|
|
104
|
+
"maxHeight",
|
|
105
|
+
"maxWidth",
|
|
106
|
+
"disabled",
|
|
107
|
+
"error",
|
|
108
|
+
"helperText",
|
|
109
|
+
"borderRadius",
|
|
110
|
+
"labelPosition",
|
|
111
|
+
"preset",
|
|
112
|
+
"sx",
|
|
113
|
+
"className",
|
|
114
|
+
// Separamos estos aunque no se usen directamente acá — evita que lleguen
|
|
115
|
+
// al DOM del MuiSelect via `{...rest}` y generen warnings de React.
|
|
116
|
+
"name",
|
|
117
|
+
"control",
|
|
118
|
+
"validation",
|
|
119
|
+
"value",
|
|
120
|
+
"onChange"
|
|
121
|
+
]);
|
|
122
|
+
const theme = styles.useTheme();
|
|
123
|
+
const presetSx = resolvePreset.resolvePreset("Select", preset, theme);
|
|
124
|
+
const isRHFMode = "control" in props && props.control !== void 0;
|
|
125
|
+
const customRender = React.useMemo(() => {
|
|
126
|
+
var _a2;
|
|
127
|
+
if (React.Children.count(children) === 1) {
|
|
128
|
+
const child = React.Children.only(children);
|
|
129
|
+
if (React.isValidElement(child) && ((_a2 = child.type) == null ? void 0 : _a2.displayName) === "Option") {
|
|
130
|
+
return child.props.children;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}, [children]);
|
|
135
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
136
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
137
|
+
const groupedOptions = React.useMemo(() => groupOptions(options), [options]);
|
|
138
|
+
const buildMenuItems = (currentValue) => {
|
|
139
|
+
const items = [];
|
|
140
|
+
Object.entries(groupedOptions).forEach(([group, opts]) => {
|
|
141
|
+
if (group !== "__default") {
|
|
142
|
+
items.push(
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.ListSubheader, { disableSticky: true, children: group }, group)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
opts.forEach((opt) => {
|
|
147
|
+
const selected = currentValue === opt.value;
|
|
148
|
+
items.push(
|
|
149
|
+
renderSelectMenuItem({
|
|
150
|
+
option: opt,
|
|
151
|
+
selected,
|
|
152
|
+
customRender
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return items;
|
|
158
|
+
};
|
|
159
|
+
const mergedSx = [
|
|
160
|
+
buildSelectSx(borderRadius, labelPosition),
|
|
161
|
+
...presetSx ? [presetSx] : [],
|
|
162
|
+
...Array.isArray(sx) ? sx : sx ? [sx] : []
|
|
163
|
+
];
|
|
164
|
+
const renderSelect = (selectValue, selectOnChange, onBlur, inputRef, rhfError, rhfHelperText) => {
|
|
165
|
+
const finalError = !!rhfError || !!error;
|
|
166
|
+
const finalHelperText = rhfHelperText != null ? rhfHelperText : helperText;
|
|
167
|
+
const inputElement = labelPosition === "floating" ? /* @__PURE__ */ jsxRuntime.jsx(material.OutlinedInput, { label }) : /* @__PURE__ */ jsxRuntime.jsx(material.OutlinedInput, {});
|
|
168
|
+
const normalizedValue = normalizeSelectValue(selectValue);
|
|
169
|
+
const isEmpty = isSelectValueEmpty(normalizedValue);
|
|
170
|
+
const shouldShrink = !isEmpty || isFocused || isOpen;
|
|
171
|
+
const shouldDisplayPlaceholder = isEmpty && (isFocused || isOpen) && !!placeholder;
|
|
172
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
173
|
+
material.FormControl,
|
|
174
|
+
{
|
|
175
|
+
fullWidth: true,
|
|
176
|
+
size,
|
|
177
|
+
error: finalError,
|
|
178
|
+
disabled,
|
|
179
|
+
className,
|
|
180
|
+
sx: mergedSx,
|
|
181
|
+
children: [
|
|
182
|
+
label && /* @__PURE__ */ jsxRuntime.jsx(material.InputLabel, { shrink: shouldShrink, children: label }),
|
|
183
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
184
|
+
material.Select,
|
|
185
|
+
__spreadProps(__spreadValues({
|
|
186
|
+
value: normalizedValue,
|
|
187
|
+
onChange: selectOnChange,
|
|
188
|
+
onBlur: (e) => {
|
|
189
|
+
setIsFocused(false);
|
|
190
|
+
onBlur == null ? void 0 : onBlur(e);
|
|
191
|
+
},
|
|
192
|
+
onFocus: () => setIsFocused(true),
|
|
193
|
+
onOpen: () => setIsOpen(true),
|
|
194
|
+
onClose: () => setIsOpen(false),
|
|
195
|
+
renderValue: (selected) => {
|
|
196
|
+
var _a2;
|
|
197
|
+
if (isSelectValueEmpty(selected)) {
|
|
198
|
+
return /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { sx: { color: "text.disabled" }, children: placeholder != null ? placeholder : "" });
|
|
199
|
+
}
|
|
200
|
+
const item = options.find((opt) => opt.value === selected);
|
|
201
|
+
return (_a2 = item == null ? void 0 : item.label) != null ? _a2 : String(selected);
|
|
202
|
+
},
|
|
203
|
+
displayEmpty: shouldDisplayPlaceholder,
|
|
204
|
+
input: inputElement,
|
|
205
|
+
disabled,
|
|
206
|
+
MenuProps: {
|
|
207
|
+
PaperProps: {
|
|
208
|
+
style: { maxHeight, maxWidth }
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
inputRef
|
|
212
|
+
}, rest), {
|
|
213
|
+
children: buildMenuItems(normalizedValue)
|
|
214
|
+
})
|
|
215
|
+
),
|
|
216
|
+
finalHelperText && /* @__PURE__ */ jsxRuntime.jsx(material.FormHelperText, { children: finalHelperText })
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
};
|
|
221
|
+
if (isRHFMode) {
|
|
222
|
+
const { name, control, validation, onValueChange } = props;
|
|
223
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
224
|
+
reactHookForm.Controller,
|
|
225
|
+
{
|
|
226
|
+
name,
|
|
227
|
+
control,
|
|
228
|
+
rules: validation,
|
|
229
|
+
defaultValue,
|
|
230
|
+
render: ({ field, fieldState: { error: fieldError } }) => {
|
|
231
|
+
var _a2;
|
|
232
|
+
return renderSelect(
|
|
233
|
+
(_a2 = field.value) != null ? _a2 : null,
|
|
234
|
+
(e) => {
|
|
235
|
+
const next = e.target.value;
|
|
236
|
+
field.onChange(next);
|
|
237
|
+
onValueChange == null ? void 0 : onValueChange(next);
|
|
238
|
+
},
|
|
239
|
+
field.onBlur,
|
|
240
|
+
field.ref,
|
|
241
|
+
!!fieldError,
|
|
242
|
+
fieldError == null ? void 0 : fieldError.message
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
const { value, onChange } = props;
|
|
249
|
+
return renderSelect(value, (e) => onChange(e.target.value));
|
|
250
|
+
}
|
|
251
|
+
exports.Option = Option;
|
|
252
|
+
exports.Select = Select;
|
|
253
|
+
//# sourceMappingURL=Select-B6jE3WH_.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select-B6jE3WH_.cjs","sources":["../src/components/Select/Select.sx.ts","../src/components/Select/Select.helpers.ts","../src/components/Select/_parts/SelectMenuItem.tsx","../src/components/Select/Select.tsx"],"sourcesContent":["import type { SelectProps as MuiSelectProps } from '@mui/material';\n\nimport { buildFormFieldSx } from '../_shared/formField.sx';\nimport type { LabelPosition } from './Select';\n\n/**\n * Builder de sx para el Select. Usa el builder compartido\n * `buildFormFieldSx`. El Select no necesita overrides específicos.\n */\nexport const buildSelectSx = (\n borderRadius: number | string,\n labelPosition: LabelPosition,\n): MuiSelectProps['sx'] =>\n buildFormFieldSx({ borderRadius, labelPosition }) as MuiSelectProps['sx'];\n","import type { SelectOption } from './Select';\n\n/**\n * Agrupa opciones por la propiedad `group`. Las opciones sin group caen\n * bajo la key especial `__default`. Devuelve un Record para iterar en orden\n * de inserción con Object.entries.\n */\nexport const groupOptions = (\n options: SelectOption[],\n): Record<string, SelectOption[]> => {\n const groups: Record<string, SelectOption[]> = {};\n options.forEach((opt) => {\n const group = opt.group || '__default';\n if (!groups[group]) groups[group] = [];\n groups[group].push(opt);\n });\n return groups;\n};\n\n/**\n * Normaliza el valor single al shape que espera MUI Select: string vacío si\n * el valor es `null`/`undefined`.\n */\nexport const normalizeSelectValue = <T>(value: T | null | undefined): T | '' =>\n (value ?? '') as T | '';\n\n/** `true` si el valor está vacío (para shrink del label + placeholder). */\nexport const isSelectValueEmpty = (normalizedValue: unknown): boolean =>\n normalizedValue === '' ||\n normalizedValue === null ||\n normalizedValue === undefined;\n","import React from 'react';\nimport { ListItemIcon, MenuItem } from '@mui/material';\nimport CheckIcon from '@mui/icons-material/Check';\n\nimport type { SelectOption, RenderOptionItem } from '../Select';\n\ninterface RenderSelectMenuItemArgs {\n option: SelectOption;\n selected: boolean;\n customRender?: RenderOptionItem | null;\n}\n\n/**\n * Render helper (no componente) que devuelve un <MenuItem> listo para\n * colocarse como hijo directo del <MuiSelect>. Se implementa como función\n * y no como componente porque MUI Select inspecciona `props.value` de sus\n * children para resolver la selección, y envolverlo en un componente extra\n * rompe esa detección.\n *\n * Incluye el icono de check a la izquierda cuando `selected` es true. Si el\n * consumer pasó un `<Option>{(opt) => ...}</Option>`, usa ese render para el\n * contenido principal; de lo contrario muestra `option.label`.\n */\nexport const renderSelectMenuItem = ({\n option,\n selected,\n customRender,\n}: RenderSelectMenuItemArgs): React.ReactElement => (\n <MenuItem\n key={String(option.value)}\n value={option.value}\n disabled={option.disabled}\n selected={selected}\n >\n <ListItemIcon sx={{ minWidth: 32 }}>\n {selected && <CheckIcon color=\"success\" fontSize=\"small\" />}\n </ListItemIcon>\n {customRender ? customRender(option) : option.label}\n </MenuItem>\n);\n","import {\n Children,\n isValidElement,\n useMemo,\n useState,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n FormControl,\n FormHelperText,\n InputLabel,\n ListSubheader,\n OutlinedInput,\n Select as MuiSelect,\n Typography,\n type SelectChangeEvent,\n type SelectProps as MuiSelectProps,\n} from '@mui/material';\nimport { useTheme } from '@mui/material/styles';\nimport { Controller, type Control, type RegisterOptions } from 'react-hook-form';\n\nimport { buildSelectSx } from './Select.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\nimport {\n groupOptions,\n isSelectValueEmpty,\n normalizeSelectValue,\n} from './Select.helpers';\nimport { renderSelectMenuItem } from './_parts/SelectMenuItem';\n\n// ── Tipos de dominio ─────────────────────────────────────────────────────\nexport interface SelectOption {\n value: string | number;\n label: string;\n img?: string;\n disabled?: boolean;\n group?: string;\n [key: string]: any;\n}\n\nexport type LabelPosition = 'outside' | 'floating';\nexport type SelectSize = 'small' | 'medium';\n\n// ── Render slots ─────────────────────────────────────────────────────────\nexport type RenderOptionItem = (item: SelectOption) => ReactNode;\n\n// ── Sub-componente declarativo <Option> ──────────────────────────────────\nexport interface OptionProps {\n children: RenderOptionItem;\n}\n\n// ── Props base ───────────────────────────────────────────────────────────\nexport interface BaseSelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> {\n label?: string;\n options?: SelectOption[];\n defaultValue?: TValue;\n size?: SelectSize;\n placeholder?: string;\n children?: ReactElement<{ children: RenderOptionItem }>;\n maxHeight?: number | string;\n maxWidth?: number | string;\n disabled?: boolean;\n error?: boolean;\n helperText?: string;\n /** Border radius del input (px o string CSS). Default: 10 */\n borderRadius?: number | string;\n /**\n * Posición del label.\n * - \"outside\" (default): label arriba del input, sin animación.\n * - \"floating\": label clásico de MUI (flota dentro del notched outline).\n */\n labelPosition?: LabelPosition;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Select`.\n * - `\"default\"` (o ausente) = estilo built-in del paquete.\n * - Cualquier otro string = mergea el preset encima del estilo built-in.\n */\n preset?: string;\n sx?: MuiSelectProps['sx'];\n className?: string;\n}\n\n// ── Variantes discriminadas (RHF vs controlado) ──────────────────────────\nexport interface RHFSelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> extends BaseSelectProps<TValue> {\n name: string;\n // `any` plano (no `Control<any>`): RHF tipa `Control<T>` con generics en\n // posiciones tanto contravariantes como covariantes (ej. `_subjects.state`).\n // Cuando el componente tiene generics propios (como `TValue` acá), TS se\n // confunde narroweando el discriminated union y `Control<any>` no logra\n // absorber `Control<MyForm>` en la comparación estructural profunda.\n // El `any` plano elimina ese ruido. RHF adentro sigue teniendo sus tipos\n // fuertes — solo degradamos la superficie del prop del Select.\n control: any;\n validation?: RegisterOptions;\n /**\n * Side-effect que corre después de que RHF actualiza el form state.\n * Útil para cascadas entre campos (ej. reset de municipio al cambiar\n * departamento). NO reemplaza al handler de RHF.\n */\n onValueChange?: (value: TValue) => void;\n value?: never;\n onChange?: never;\n}\n\nexport interface StandardSelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> extends BaseSelectProps<TValue> {\n name?: string;\n control?: never;\n validation?: never;\n value: TValue;\n onChange: (val: TValue) => void;\n}\n\n// ── API pública final ────────────────────────────────────────────────────\nexport type SelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> = RHFSelectProps<TValue> | StandardSelectProps<TValue>;\n\n// ── Sub-componente declarativo <Option> ──────────────────────────────────\nexport function Option(_props: OptionProps) {\n return null;\n}\nOption.displayName = 'Option';\n\n// ── Componente ───────────────────────────────────────────────────────────\nexport function Select<\n TValue extends SelectOption['value'] = SelectOption['value'],\n>(props: SelectProps<TValue>) {\n const {\n label,\n options = [],\n defaultValue,\n size = 'small',\n placeholder,\n children,\n maxHeight = 300,\n maxWidth,\n disabled = false,\n error = false,\n helperText,\n borderRadius = 10,\n labelPosition = 'outside',\n preset,\n sx,\n className,\n // Separamos estos aunque no se usen directamente acá — evita que lleguen\n // al DOM del MuiSelect via `{...rest}` y generen warnings de React.\n name: _nameIgnored,\n control: _controlIgnored,\n validation: _validationIgnored,\n value: _valueIgnored,\n onChange: _onChangeIgnored,\n ...rest\n } = props as StandardSelectProps<TValue> & {\n name?: string;\n control?: Control<any>;\n validation?: RegisterOptions;\n };\n\n const theme = useTheme();\n const presetSx = resolvePreset('Select', preset, theme);\n\n const isRHFMode = 'control' in props && (props as RHFSelectProps<TValue>).control !== undefined;\n\n // Custom render opcional vía <Option>{item => ...}</Option>\n const customRender: RenderOptionItem | null = useMemo(() => {\n if (Children.count(children) === 1) {\n const child = Children.only(children);\n if (isValidElement(child) && (child.type as any)?.displayName === 'Option') {\n return (child.props as OptionProps).children;\n }\n }\n return null;\n }, [children]);\n\n // Focus/open tracking para el comportamiento del label \"outside\".\n const [isOpen, setIsOpen] = useState(false);\n const [isFocused, setIsFocused] = useState(false);\n\n const groupedOptions = useMemo(() => groupOptions(options), [options]);\n\n // Items del menú (grupos + opciones). Un solo memoizado — sin search/async.\n const buildMenuItems = (currentValue: TValue | '') => {\n const items: ReactNode[] = [];\n Object.entries(groupedOptions).forEach(([group, opts]) => {\n if (group !== '__default') {\n items.push(\n <ListSubheader key={group} disableSticky>\n {group}\n </ListSubheader>,\n );\n }\n opts.forEach((opt) => {\n const selected = currentValue === opt.value;\n items.push(\n renderSelectMenuItem({\n option: opt,\n selected,\n customRender,\n }),\n );\n });\n });\n return items;\n };\n\n const mergedSx = [\n buildSelectSx(borderRadius, labelPosition),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ];\n\n // Render base (común a RHF y controlled)\n const renderSelect = (\n selectValue: TValue | null | undefined,\n selectOnChange: (event: SelectChangeEvent<TValue>) => void,\n onBlur?: (event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void,\n inputRef?: React.Ref<HTMLInputElement>,\n rhfError?: boolean,\n rhfHelperText?: string,\n ) => {\n const finalError = !!rhfError || !!error;\n const finalHelperText = rhfHelperText ?? helperText;\n\n const inputElement =\n labelPosition === 'floating' ? (\n <OutlinedInput label={label} />\n ) : (\n <OutlinedInput />\n );\n\n const normalizedValue = normalizeSelectValue(selectValue);\n const isEmpty = isSelectValueEmpty(normalizedValue);\n\n // Shrink cuando hay valor, foco, o dropdown abierto.\n const shouldShrink = !isEmpty || isFocused || isOpen;\n // Placeholder solo cuando el label ya subió.\n const shouldDisplayPlaceholder =\n isEmpty && (isFocused || isOpen) && !!placeholder;\n\n return (\n <FormControl\n fullWidth\n size={size}\n error={finalError}\n disabled={disabled}\n className={className}\n sx={mergedSx}\n >\n {label && <InputLabel shrink={shouldShrink}>{label}</InputLabel>}\n <MuiSelect<TValue>\n value={normalizedValue as TValue}\n onChange={selectOnChange}\n onBlur={(e) => {\n setIsFocused(false);\n onBlur?.(e);\n }}\n onFocus={() => setIsFocused(true)}\n onOpen={() => setIsOpen(true)}\n onClose={() => setIsOpen(false)}\n renderValue={(selected) => {\n if (isSelectValueEmpty(selected)) {\n return (\n <Typography sx={{ color: 'text.disabled' }}>\n {placeholder ?? ''}\n </Typography>\n );\n }\n const item = options.find((opt) => opt.value === selected);\n return item?.label ?? String(selected);\n }}\n displayEmpty={shouldDisplayPlaceholder}\n input={inputElement}\n disabled={disabled}\n MenuProps={{\n PaperProps: {\n style: { maxHeight, maxWidth },\n },\n }}\n inputRef={inputRef}\n {...(rest as any)}\n >\n {buildMenuItems(normalizedValue as TValue | '')}\n </MuiSelect>\n {finalHelperText && <FormHelperText>{finalHelperText}</FormHelperText>}\n </FormControl>\n );\n };\n\n // ── RHF mode ──────────────────────────────────────────────────────────\n if (isRHFMode) {\n const { name, control, validation, onValueChange } = props as RHFSelectProps<TValue>;\n return (\n <Controller\n name={name}\n control={control}\n rules={validation}\n defaultValue={defaultValue}\n render={({ field, fieldState: { error: fieldError } }) =>\n renderSelect(\n field.value ?? null,\n (e) => {\n const next = e.target.value as TValue;\n field.onChange(next);\n onValueChange?.(next);\n },\n field.onBlur,\n field.ref,\n !!fieldError,\n fieldError?.message,\n )\n }\n />\n );\n }\n\n // ── Controlled mode ───────────────────────────────────────────────────\n const { value, onChange } = props as StandardSelectProps<TValue>;\n return renderSelect(value, (e) => onChange(e.target.value as TValue));\n}\n\nexport default Select;\n"],"names":["buildFormFieldSx","jsxs","MenuItem","jsx","ListItemIcon","useTheme","resolvePreset","useMemo","Children","isValidElement","_a","useState","ListSubheader","OutlinedInput","FormControl","InputLabel","MuiSelect","Typography","FormHelperText","Controller"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,MAAM,gBAAgB,CAC3B,cACA,kBAEAA,aAAAA,iBAAiB,EA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B,SAAO,aAAa,OAAO,CAAC,MAAM,SAAS,EAAE,OAAO,KAAe,CAAC;AACtE;;;"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
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, Typography, FormHelperText, ListSubheader, OutlinedInput } from "@mui/material";
|
|
35
|
+
import { useTheme } from "@mui/material/styles";
|
|
36
|
+
import { Controller } from "react-hook-form";
|
|
37
|
+
import { b as buildFormFieldSx } from "./formField.sx-8_QRnKxv.js";
|
|
38
|
+
import { r as resolvePreset } from "./resolvePreset-K6_BfWHD.js";
|
|
39
|
+
import CheckIcon from "@mui/icons-material/Check";
|
|
40
|
+
const buildSelectSx = (borderRadius, labelPosition) => buildFormFieldSx({ borderRadius, labelPosition });
|
|
41
|
+
const groupOptions = (options) => {
|
|
42
|
+
const groups = {};
|
|
43
|
+
options.forEach((opt) => {
|
|
44
|
+
const group = opt.group || "__default";
|
|
45
|
+
if (!groups[group]) groups[group] = [];
|
|
46
|
+
groups[group].push(opt);
|
|
47
|
+
});
|
|
48
|
+
return groups;
|
|
49
|
+
};
|
|
50
|
+
const normalizeSelectValue = (value) => value != null ? value : "";
|
|
51
|
+
const isSelectValueEmpty = (normalizedValue) => normalizedValue === "" || normalizedValue === null || normalizedValue === void 0;
|
|
52
|
+
const renderSelectMenuItem = ({
|
|
53
|
+
option,
|
|
54
|
+
selected,
|
|
55
|
+
customRender
|
|
56
|
+
}) => /* @__PURE__ */ jsxs(
|
|
57
|
+
MenuItem,
|
|
58
|
+
{
|
|
59
|
+
value: option.value,
|
|
60
|
+
disabled: option.disabled,
|
|
61
|
+
selected,
|
|
62
|
+
children: [
|
|
63
|
+
/* @__PURE__ */ jsx(ListItemIcon, { sx: { minWidth: 32 }, children: selected && /* @__PURE__ */ jsx(CheckIcon, { color: "success", fontSize: "small" }) }),
|
|
64
|
+
customRender ? customRender(option) : option.label
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
String(option.value)
|
|
68
|
+
);
|
|
69
|
+
function Option(_props) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
Option.displayName = "Option";
|
|
73
|
+
function Select(props) {
|
|
74
|
+
const _a = props, {
|
|
75
|
+
label,
|
|
76
|
+
options = [],
|
|
77
|
+
defaultValue,
|
|
78
|
+
size = "small",
|
|
79
|
+
placeholder,
|
|
80
|
+
children,
|
|
81
|
+
maxHeight = 300,
|
|
82
|
+
maxWidth,
|
|
83
|
+
disabled = false,
|
|
84
|
+
error = false,
|
|
85
|
+
helperText,
|
|
86
|
+
borderRadius = 10,
|
|
87
|
+
labelPosition = "outside",
|
|
88
|
+
preset,
|
|
89
|
+
sx,
|
|
90
|
+
className,
|
|
91
|
+
name: _nameIgnored,
|
|
92
|
+
control: _controlIgnored,
|
|
93
|
+
validation: _validationIgnored,
|
|
94
|
+
value: _valueIgnored,
|
|
95
|
+
onChange: _onChangeIgnored
|
|
96
|
+
} = _a, rest = __objRest(_a, [
|
|
97
|
+
"label",
|
|
98
|
+
"options",
|
|
99
|
+
"defaultValue",
|
|
100
|
+
"size",
|
|
101
|
+
"placeholder",
|
|
102
|
+
"children",
|
|
103
|
+
"maxHeight",
|
|
104
|
+
"maxWidth",
|
|
105
|
+
"disabled",
|
|
106
|
+
"error",
|
|
107
|
+
"helperText",
|
|
108
|
+
"borderRadius",
|
|
109
|
+
"labelPosition",
|
|
110
|
+
"preset",
|
|
111
|
+
"sx",
|
|
112
|
+
"className",
|
|
113
|
+
// Separamos estos aunque no se usen directamente acá — evita que lleguen
|
|
114
|
+
// al DOM del MuiSelect via `{...rest}` y generen warnings de React.
|
|
115
|
+
"name",
|
|
116
|
+
"control",
|
|
117
|
+
"validation",
|
|
118
|
+
"value",
|
|
119
|
+
"onChange"
|
|
120
|
+
]);
|
|
121
|
+
const theme = useTheme();
|
|
122
|
+
const presetSx = resolvePreset("Select", preset, theme);
|
|
123
|
+
const isRHFMode = "control" in props && props.control !== void 0;
|
|
124
|
+
const customRender = useMemo(() => {
|
|
125
|
+
var _a2;
|
|
126
|
+
if (Children.count(children) === 1) {
|
|
127
|
+
const child = Children.only(children);
|
|
128
|
+
if (isValidElement(child) && ((_a2 = child.type) == null ? void 0 : _a2.displayName) === "Option") {
|
|
129
|
+
return child.props.children;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}, [children]);
|
|
134
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
135
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
136
|
+
const groupedOptions = useMemo(() => groupOptions(options), [options]);
|
|
137
|
+
const buildMenuItems = (currentValue) => {
|
|
138
|
+
const items = [];
|
|
139
|
+
Object.entries(groupedOptions).forEach(([group, opts]) => {
|
|
140
|
+
if (group !== "__default") {
|
|
141
|
+
items.push(
|
|
142
|
+
/* @__PURE__ */ jsx(ListSubheader, { disableSticky: true, children: group }, group)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
opts.forEach((opt) => {
|
|
146
|
+
const selected = currentValue === opt.value;
|
|
147
|
+
items.push(
|
|
148
|
+
renderSelectMenuItem({
|
|
149
|
+
option: opt,
|
|
150
|
+
selected,
|
|
151
|
+
customRender
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
return items;
|
|
157
|
+
};
|
|
158
|
+
const mergedSx = [
|
|
159
|
+
buildSelectSx(borderRadius, labelPosition),
|
|
160
|
+
...presetSx ? [presetSx] : [],
|
|
161
|
+
...Array.isArray(sx) ? sx : sx ? [sx] : []
|
|
162
|
+
];
|
|
163
|
+
const renderSelect = (selectValue, selectOnChange, onBlur, inputRef, rhfError, rhfHelperText) => {
|
|
164
|
+
const finalError = !!rhfError || !!error;
|
|
165
|
+
const finalHelperText = rhfHelperText != null ? rhfHelperText : helperText;
|
|
166
|
+
const inputElement = labelPosition === "floating" ? /* @__PURE__ */ jsx(OutlinedInput, { label }) : /* @__PURE__ */ jsx(OutlinedInput, {});
|
|
167
|
+
const normalizedValue = normalizeSelectValue(selectValue);
|
|
168
|
+
const isEmpty = isSelectValueEmpty(normalizedValue);
|
|
169
|
+
const shouldShrink = !isEmpty || isFocused || isOpen;
|
|
170
|
+
const shouldDisplayPlaceholder = isEmpty && (isFocused || isOpen) && !!placeholder;
|
|
171
|
+
return /* @__PURE__ */ jsxs(
|
|
172
|
+
FormControl,
|
|
173
|
+
{
|
|
174
|
+
fullWidth: true,
|
|
175
|
+
size,
|
|
176
|
+
error: finalError,
|
|
177
|
+
disabled,
|
|
178
|
+
className,
|
|
179
|
+
sx: mergedSx,
|
|
180
|
+
children: [
|
|
181
|
+
label && /* @__PURE__ */ jsx(InputLabel, { shrink: shouldShrink, children: label }),
|
|
182
|
+
/* @__PURE__ */ jsx(
|
|
183
|
+
Select$1,
|
|
184
|
+
__spreadProps(__spreadValues({
|
|
185
|
+
value: normalizedValue,
|
|
186
|
+
onChange: selectOnChange,
|
|
187
|
+
onBlur: (e) => {
|
|
188
|
+
setIsFocused(false);
|
|
189
|
+
onBlur == null ? void 0 : onBlur(e);
|
|
190
|
+
},
|
|
191
|
+
onFocus: () => setIsFocused(true),
|
|
192
|
+
onOpen: () => setIsOpen(true),
|
|
193
|
+
onClose: () => setIsOpen(false),
|
|
194
|
+
renderValue: (selected) => {
|
|
195
|
+
var _a2;
|
|
196
|
+
if (isSelectValueEmpty(selected)) {
|
|
197
|
+
return /* @__PURE__ */ jsx(Typography, { sx: { color: "text.disabled" }, children: placeholder != null ? placeholder : "" });
|
|
198
|
+
}
|
|
199
|
+
const item = options.find((opt) => opt.value === selected);
|
|
200
|
+
return (_a2 = item == null ? void 0 : item.label) != null ? _a2 : String(selected);
|
|
201
|
+
},
|
|
202
|
+
displayEmpty: shouldDisplayPlaceholder,
|
|
203
|
+
input: inputElement,
|
|
204
|
+
disabled,
|
|
205
|
+
MenuProps: {
|
|
206
|
+
PaperProps: {
|
|
207
|
+
style: { maxHeight, maxWidth }
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
inputRef
|
|
211
|
+
}, rest), {
|
|
212
|
+
children: buildMenuItems(normalizedValue)
|
|
213
|
+
})
|
|
214
|
+
),
|
|
215
|
+
finalHelperText && /* @__PURE__ */ jsx(FormHelperText, { children: finalHelperText })
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
};
|
|
220
|
+
if (isRHFMode) {
|
|
221
|
+
const { name, control, validation, onValueChange } = props;
|
|
222
|
+
return /* @__PURE__ */ jsx(
|
|
223
|
+
Controller,
|
|
224
|
+
{
|
|
225
|
+
name,
|
|
226
|
+
control,
|
|
227
|
+
rules: validation,
|
|
228
|
+
defaultValue,
|
|
229
|
+
render: ({ field, fieldState: { error: fieldError } }) => {
|
|
230
|
+
var _a2;
|
|
231
|
+
return renderSelect(
|
|
232
|
+
(_a2 = field.value) != null ? _a2 : null,
|
|
233
|
+
(e) => {
|
|
234
|
+
const next = e.target.value;
|
|
235
|
+
field.onChange(next);
|
|
236
|
+
onValueChange == null ? void 0 : onValueChange(next);
|
|
237
|
+
},
|
|
238
|
+
field.onBlur,
|
|
239
|
+
field.ref,
|
|
240
|
+
!!fieldError,
|
|
241
|
+
fieldError == null ? void 0 : fieldError.message
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
const { value, onChange } = props;
|
|
248
|
+
return renderSelect(value, (e) => onChange(e.target.value));
|
|
249
|
+
}
|
|
250
|
+
export {
|
|
251
|
+
Option as O,
|
|
252
|
+
Select as S
|
|
253
|
+
};
|
|
254
|
+
//# sourceMappingURL=Select-bSVQokFX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Select-bSVQokFX.js","sources":["../src/components/Select/Select.sx.ts","../src/components/Select/Select.helpers.ts","../src/components/Select/_parts/SelectMenuItem.tsx","../src/components/Select/Select.tsx"],"sourcesContent":["import type { SelectProps as MuiSelectProps } from '@mui/material';\n\nimport { buildFormFieldSx } from '../_shared/formField.sx';\nimport type { LabelPosition } from './Select';\n\n/**\n * Builder de sx para el Select. Usa el builder compartido\n * `buildFormFieldSx`. El Select no necesita overrides específicos.\n */\nexport const buildSelectSx = (\n borderRadius: number | string,\n labelPosition: LabelPosition,\n): MuiSelectProps['sx'] =>\n buildFormFieldSx({ borderRadius, labelPosition }) as MuiSelectProps['sx'];\n","import type { SelectOption } from './Select';\n\n/**\n * Agrupa opciones por la propiedad `group`. Las opciones sin group caen\n * bajo la key especial `__default`. Devuelve un Record para iterar en orden\n * de inserción con Object.entries.\n */\nexport const groupOptions = (\n options: SelectOption[],\n): Record<string, SelectOption[]> => {\n const groups: Record<string, SelectOption[]> = {};\n options.forEach((opt) => {\n const group = opt.group || '__default';\n if (!groups[group]) groups[group] = [];\n groups[group].push(opt);\n });\n return groups;\n};\n\n/**\n * Normaliza el valor single al shape que espera MUI Select: string vacío si\n * el valor es `null`/`undefined`.\n */\nexport const normalizeSelectValue = <T>(value: T | null | undefined): T | '' =>\n (value ?? '') as T | '';\n\n/** `true` si el valor está vacío (para shrink del label + placeholder). */\nexport const isSelectValueEmpty = (normalizedValue: unknown): boolean =>\n normalizedValue === '' ||\n normalizedValue === null ||\n normalizedValue === undefined;\n","import React from 'react';\nimport { ListItemIcon, MenuItem } from '@mui/material';\nimport CheckIcon from '@mui/icons-material/Check';\n\nimport type { SelectOption, RenderOptionItem } from '../Select';\n\ninterface RenderSelectMenuItemArgs {\n option: SelectOption;\n selected: boolean;\n customRender?: RenderOptionItem | null;\n}\n\n/**\n * Render helper (no componente) que devuelve un <MenuItem> listo para\n * colocarse como hijo directo del <MuiSelect>. Se implementa como función\n * y no como componente porque MUI Select inspecciona `props.value` de sus\n * children para resolver la selección, y envolverlo en un componente extra\n * rompe esa detección.\n *\n * Incluye el icono de check a la izquierda cuando `selected` es true. Si el\n * consumer pasó un `<Option>{(opt) => ...}</Option>`, usa ese render para el\n * contenido principal; de lo contrario muestra `option.label`.\n */\nexport const renderSelectMenuItem = ({\n option,\n selected,\n customRender,\n}: RenderSelectMenuItemArgs): React.ReactElement => (\n <MenuItem\n key={String(option.value)}\n value={option.value}\n disabled={option.disabled}\n selected={selected}\n >\n <ListItemIcon sx={{ minWidth: 32 }}>\n {selected && <CheckIcon color=\"success\" fontSize=\"small\" />}\n </ListItemIcon>\n {customRender ? customRender(option) : option.label}\n </MenuItem>\n);\n","import {\n Children,\n isValidElement,\n useMemo,\n useState,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport {\n FormControl,\n FormHelperText,\n InputLabel,\n ListSubheader,\n OutlinedInput,\n Select as MuiSelect,\n Typography,\n type SelectChangeEvent,\n type SelectProps as MuiSelectProps,\n} from '@mui/material';\nimport { useTheme } from '@mui/material/styles';\nimport { Controller, type Control, type RegisterOptions } from 'react-hook-form';\n\nimport { buildSelectSx } from './Select.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\nimport {\n groupOptions,\n isSelectValueEmpty,\n normalizeSelectValue,\n} from './Select.helpers';\nimport { renderSelectMenuItem } from './_parts/SelectMenuItem';\n\n// ── Tipos de dominio ─────────────────────────────────────────────────────\nexport interface SelectOption {\n value: string | number;\n label: string;\n img?: string;\n disabled?: boolean;\n group?: string;\n [key: string]: any;\n}\n\nexport type LabelPosition = 'outside' | 'floating';\nexport type SelectSize = 'small' | 'medium';\n\n// ── Render slots ─────────────────────────────────────────────────────────\nexport type RenderOptionItem = (item: SelectOption) => ReactNode;\n\n// ── Sub-componente declarativo <Option> ──────────────────────────────────\nexport interface OptionProps {\n children: RenderOptionItem;\n}\n\n// ── Props base ───────────────────────────────────────────────────────────\nexport interface BaseSelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> {\n label?: string;\n options?: SelectOption[];\n defaultValue?: TValue;\n size?: SelectSize;\n placeholder?: string;\n children?: ReactElement<{ children: RenderOptionItem }>;\n maxHeight?: number | string;\n maxWidth?: number | string;\n disabled?: boolean;\n error?: boolean;\n helperText?: string;\n /** Border radius del input (px o string CSS). Default: 10 */\n borderRadius?: number | string;\n /**\n * Posición del label.\n * - \"outside\" (default): label arriba del input, sin animación.\n * - \"floating\": label clásico de MUI (flota dentro del notched outline).\n */\n labelPosition?: LabelPosition;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Select`.\n * - `\"default\"` (o ausente) = estilo built-in del paquete.\n * - Cualquier otro string = mergea el preset encima del estilo built-in.\n */\n preset?: string;\n sx?: MuiSelectProps['sx'];\n className?: string;\n}\n\n// ── Variantes discriminadas (RHF vs controlado) ──────────────────────────\nexport interface RHFSelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> extends BaseSelectProps<TValue> {\n name: string;\n // `any` plano (no `Control<any>`): RHF tipa `Control<T>` con generics en\n // posiciones tanto contravariantes como covariantes (ej. `_subjects.state`).\n // Cuando el componente tiene generics propios (como `TValue` acá), TS se\n // confunde narroweando el discriminated union y `Control<any>` no logra\n // absorber `Control<MyForm>` en la comparación estructural profunda.\n // El `any` plano elimina ese ruido. RHF adentro sigue teniendo sus tipos\n // fuertes — solo degradamos la superficie del prop del Select.\n control: any;\n validation?: RegisterOptions;\n /**\n * Side-effect que corre después de que RHF actualiza el form state.\n * Útil para cascadas entre campos (ej. reset de municipio al cambiar\n * departamento). NO reemplaza al handler de RHF.\n */\n onValueChange?: (value: TValue) => void;\n value?: never;\n onChange?: never;\n}\n\nexport interface StandardSelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> extends BaseSelectProps<TValue> {\n name?: string;\n control?: never;\n validation?: never;\n value: TValue;\n onChange: (val: TValue) => void;\n}\n\n// ── API pública final ────────────────────────────────────────────────────\nexport type SelectProps<\n TValue extends SelectOption['value'] = SelectOption['value'],\n> = RHFSelectProps<TValue> | StandardSelectProps<TValue>;\n\n// ── Sub-componente declarativo <Option> ──────────────────────────────────\nexport function Option(_props: OptionProps) {\n return null;\n}\nOption.displayName = 'Option';\n\n// ── Componente ───────────────────────────────────────────────────────────\nexport function Select<\n TValue extends SelectOption['value'] = SelectOption['value'],\n>(props: SelectProps<TValue>) {\n const {\n label,\n options = [],\n defaultValue,\n size = 'small',\n placeholder,\n children,\n maxHeight = 300,\n maxWidth,\n disabled = false,\n error = false,\n helperText,\n borderRadius = 10,\n labelPosition = 'outside',\n preset,\n sx,\n className,\n // Separamos estos aunque no se usen directamente acá — evita que lleguen\n // al DOM del MuiSelect via `{...rest}` y generen warnings de React.\n name: _nameIgnored,\n control: _controlIgnored,\n validation: _validationIgnored,\n value: _valueIgnored,\n onChange: _onChangeIgnored,\n ...rest\n } = props as StandardSelectProps<TValue> & {\n name?: string;\n control?: Control<any>;\n validation?: RegisterOptions;\n };\n\n const theme = useTheme();\n const presetSx = resolvePreset('Select', preset, theme);\n\n const isRHFMode = 'control' in props && (props as RHFSelectProps<TValue>).control !== undefined;\n\n // Custom render opcional vía <Option>{item => ...}</Option>\n const customRender: RenderOptionItem | null = useMemo(() => {\n if (Children.count(children) === 1) {\n const child = Children.only(children);\n if (isValidElement(child) && (child.type as any)?.displayName === 'Option') {\n return (child.props as OptionProps).children;\n }\n }\n return null;\n }, [children]);\n\n // Focus/open tracking para el comportamiento del label \"outside\".\n const [isOpen, setIsOpen] = useState(false);\n const [isFocused, setIsFocused] = useState(false);\n\n const groupedOptions = useMemo(() => groupOptions(options), [options]);\n\n // Items del menú (grupos + opciones). Un solo memoizado — sin search/async.\n const buildMenuItems = (currentValue: TValue | '') => {\n const items: ReactNode[] = [];\n Object.entries(groupedOptions).forEach(([group, opts]) => {\n if (group !== '__default') {\n items.push(\n <ListSubheader key={group} disableSticky>\n {group}\n </ListSubheader>,\n );\n }\n opts.forEach((opt) => {\n const selected = currentValue === opt.value;\n items.push(\n renderSelectMenuItem({\n option: opt,\n selected,\n customRender,\n }),\n );\n });\n });\n return items;\n };\n\n const mergedSx = [\n buildSelectSx(borderRadius, labelPosition),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ];\n\n // Render base (común a RHF y controlled)\n const renderSelect = (\n selectValue: TValue | null | undefined,\n selectOnChange: (event: SelectChangeEvent<TValue>) => void,\n onBlur?: (event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void,\n inputRef?: React.Ref<HTMLInputElement>,\n rhfError?: boolean,\n rhfHelperText?: string,\n ) => {\n const finalError = !!rhfError || !!error;\n const finalHelperText = rhfHelperText ?? helperText;\n\n const inputElement =\n labelPosition === 'floating' ? (\n <OutlinedInput label={label} />\n ) : (\n <OutlinedInput />\n );\n\n const normalizedValue = normalizeSelectValue(selectValue);\n const isEmpty = isSelectValueEmpty(normalizedValue);\n\n // Shrink cuando hay valor, foco, o dropdown abierto.\n const shouldShrink = !isEmpty || isFocused || isOpen;\n // Placeholder solo cuando el label ya subió.\n const shouldDisplayPlaceholder =\n isEmpty && (isFocused || isOpen) && !!placeholder;\n\n return (\n <FormControl\n fullWidth\n size={size}\n error={finalError}\n disabled={disabled}\n className={className}\n sx={mergedSx}\n >\n {label && <InputLabel shrink={shouldShrink}>{label}</InputLabel>}\n <MuiSelect<TValue>\n value={normalizedValue as TValue}\n onChange={selectOnChange}\n onBlur={(e) => {\n setIsFocused(false);\n onBlur?.(e);\n }}\n onFocus={() => setIsFocused(true)}\n onOpen={() => setIsOpen(true)}\n onClose={() => setIsOpen(false)}\n renderValue={(selected) => {\n if (isSelectValueEmpty(selected)) {\n return (\n <Typography sx={{ color: 'text.disabled' }}>\n {placeholder ?? ''}\n </Typography>\n );\n }\n const item = options.find((opt) => opt.value === selected);\n return item?.label ?? String(selected);\n }}\n displayEmpty={shouldDisplayPlaceholder}\n input={inputElement}\n disabled={disabled}\n MenuProps={{\n PaperProps: {\n style: { maxHeight, maxWidth },\n },\n }}\n inputRef={inputRef}\n {...(rest as any)}\n >\n {buildMenuItems(normalizedValue as TValue | '')}\n </MuiSelect>\n {finalHelperText && <FormHelperText>{finalHelperText}</FormHelperText>}\n </FormControl>\n );\n };\n\n // ── RHF mode ──────────────────────────────────────────────────────────\n if (isRHFMode) {\n const { name, control, validation, onValueChange } = props as RHFSelectProps<TValue>;\n return (\n <Controller\n name={name}\n control={control}\n rules={validation}\n defaultValue={defaultValue}\n render={({ field, fieldState: { error: fieldError } }) =>\n renderSelect(\n field.value ?? null,\n (e) => {\n const next = e.target.value as TValue;\n field.onChange(next);\n onValueChange?.(next);\n },\n field.onBlur,\n field.ref,\n !!fieldError,\n fieldError?.message,\n )\n }\n />\n );\n }\n\n // ── Controlled mode ───────────────────────────────────────────────────\n const { value, onChange } = props as StandardSelectProps<TValue>;\n return renderSelect(value, (e) => onChange(e.target.value as TValue));\n}\n\nexport default Select;\n"],"names":["_a","MuiSelect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,MAAM,gBAAgB,CAC3B,cACA,kBAEA,iBAAiB,EAAE,cAAc,eAAe;ACN3C,MAAM,eAAe,CAC1B,YACmC;AACnC,QAAM,SAAyC,CAAA;AAC/C,UAAQ,QAAQ,CAAC,QAAQ;AACvB,UAAM,QAAQ,IAAI,SAAS;AAC3B,QAAI,CAAC,OAAO,KAAK,EAAG,QAAO,KAAK,IAAI,CAAA;AACpC,WAAO,KAAK,EAAE,KAAK,GAAG;AAAA,EACxB,CAAC;AACD,SAAO;AACT;AAMO,MAAM,uBAAuB,CAAI,UACrC,wBAAS;AAGL,MAAM,qBAAqB,CAAC,oBACjC,oBAAoB,MACpB,oBAAoB,QACpB,oBAAoB;ACPf,MAAM,uBAAuB,CAAC;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,MACE;AAAA,EAAC;AAAA,EAAA;AAAA,IAEC,OAAO,OAAO;AAAA,IACd,UAAU,OAAO;AAAA,IACjB;AAAA,IAEA,UAAA;AAAA,MAAA,oBAAC,cAAA,EAAa,IAAI,EAAE,UAAU,GAAA,GAC3B,UAAA,YAAY,oBAAC,WAAA,EAAU,OAAM,WAAU,UAAS,SAAQ,GAC3D;AAAA,MACC,eAAe,aAAa,MAAM,IAAI,OAAO;AAAA,IAAA;AAAA,EAAA;AAAA,EARzC,OAAO,OAAO,KAAK;AAS1B;ACuFK,SAAS,OAA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