@soyfri/shared-library 1.5.0-beta.4 → 1.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Button-C17mExpd.cjs.map +1 -1
- package/Button-UkkP-bNw.js.map +1 -1
- package/components/ActionMenu/ActionMenu.cjs +107 -0
- package/components/ActionMenu/ActionMenu.cjs.map +1 -0
- package/components/ActionMenu/ActionMenu.d.ts +44 -0
- package/components/ActionMenu/ActionMenu.js +107 -0
- package/components/ActionMenu/ActionMenu.js.map +1 -0
- package/components/ActionMenu/index.d.ts +2 -0
- package/components/ActionMenu.d.ts +6 -0
- package/components/AppBar/AppBar.cjs +129 -0
- package/components/AppBar/AppBar.cjs.map +1 -0
- package/components/AppBar/AppBar.d.ts +55 -0
- package/components/AppBar/AppBar.js +129 -0
- package/components/AppBar/AppBar.js.map +1 -0
- package/components/AppBar/AppBar.sx.d.ts +12 -0
- package/components/AppBar/AppBarContext.d.ts +18 -0
- package/components/AppBar/AppBarMenuToggle.d.ts +39 -0
- package/components/AppBar/index.d.ts +6 -0
- package/components/AppBar.d.ts +6 -0
- package/components/Autocomplete/Autocomplete.cjs +263 -82
- package/components/Autocomplete/Autocomplete.cjs.map +1 -1
- package/components/Autocomplete/Autocomplete.d.ts +71 -13
- package/components/Autocomplete/Autocomplete.definitions.d.ts +7 -0
- package/components/Autocomplete/Autocomplete.helpers.d.ts +22 -0
- package/components/Autocomplete/Autocomplete.js +264 -83
- package/components/Autocomplete/Autocomplete.js.map +1 -1
- package/components/Autocomplete/Autocomplete.sx.d.ts +7 -0
- package/components/Autocomplete/_parts/AutocompleteChips.d.ts +20 -0
- package/components/Autocomplete/_parts/AutocompleteLoader.d.ts +9 -0
- package/components/Autocomplete/_parts/AutocompleteOption.d.ts +16 -0
- package/components/Autocomplete/index.d.ts +2 -1
- package/components/Autocomplete.d.ts +4 -0
- package/components/Avatar/Avatar.cjs +117 -81
- package/components/Avatar/Avatar.cjs.map +1 -1
- package/components/Avatar/Avatar.d.ts +16 -2
- package/components/Avatar/Avatar.definitions.d.ts +11 -0
- package/components/Avatar/Avatar.js +118 -82
- package/components/Avatar/Avatar.js.map +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 +78 -7
- package/components/Card/Card.cjs.map +1 -1
- package/components/Card/Card.d.ts +31 -8
- package/components/Card/Card.js +79 -8
- package/components/Card/Card.js.map +1 -1
- package/components/Card/Card.sx.d.ts +14 -0
- package/components/Card/index.d.ts +4 -1
- package/components/Card.d.ts +4 -0
- package/components/Checkbox/Checkbox.cjs +189 -0
- package/components/Checkbox/Checkbox.cjs.map +1 -0
- package/components/Checkbox/Checkbox.d.ts +55 -0
- package/components/Checkbox/Checkbox.js +189 -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 +2 -1
- package/components/Chip/Chip.js.map +1 -1
- package/components/Chip/index.d.ts +2 -1
- package/components/Chip.d.ts +4 -0
- package/components/DatePicker/DatePicker.cjs +178 -3
- package/components/DatePicker/DatePicker.cjs.map +1 -1
- package/components/DatePicker/DatePicker.d.ts +35 -9
- package/components/DatePicker/DatePicker.definitions.d.ts +1 -0
- package/components/DatePicker/DatePicker.helpers.d.ts +7 -0
- package/components/DatePicker/DatePicker.js +177 -2
- package/components/DatePicker/DatePicker.js.map +1 -1
- package/components/DatePicker/DatePicker.sx.d.ts +9 -0
- package/components/DatePicker/index.d.ts +2 -1
- package/components/DatePicker.d.ts +4 -0
- package/components/DateTimePicker/DateTimePicker.cjs +121 -131
- package/components/DateTimePicker/DateTimePicker.cjs.map +1 -1
- package/components/DateTimePicker/DateTimePicker.d.ts +41 -12
- package/components/DateTimePicker/DateTimePicker.definitions.d.ts +3 -0
- package/components/DateTimePicker/DateTimePicker.helpers.d.ts +13 -0
- package/components/DateTimePicker/DateTimePicker.js +121 -131
- package/components/DateTimePicker/DateTimePicker.js.map +1 -1
- package/components/DateTimePicker/DateTimePicker.sx.d.ts +7 -0
- package/components/DateTimePicker/index.d.ts +2 -1
- package/components/DateTimePicker.d.ts +4 -0
- package/components/Drawer/Drawer.cjs +272 -0
- package/components/Drawer/Drawer.cjs.map +1 -0
- package/components/Drawer/Drawer.d.ts +58 -0
- package/components/Drawer/Drawer.js +272 -0
- package/components/Drawer/Drawer.js.map +1 -0
- package/components/Drawer/Drawer.sx.d.ts +23 -0
- package/components/Drawer/DrawerContext.d.ts +18 -0
- package/components/Drawer/DrawerItem.d.ts +40 -0
- package/components/Drawer/index.d.ts +6 -0
- package/components/Drawer.d.ts +6 -0
- 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 +49 -10
- package/components/Icon/Icon.cjs.map +1 -1
- package/components/Icon/Icon.d.ts +29 -2
- package/components/Icon/Icon.js +49 -10
- 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 +186 -3
- package/components/Input/Input.cjs.map +1 -1
- package/components/Input/Input.d.ts +29 -17
- package/components/Input/Input.definitions.d.ts +6 -2
- package/components/Input/Input.helpers.d.ts +14 -0
- package/components/Input/Input.js +185 -2
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.sx.d.ts +8 -0
- package/components/Input/index.d.ts +2 -1
- package/components/Input.d.ts +4 -0
- package/components/InputGroup/InputGroup.cjs +107 -93
- package/components/InputGroup/InputGroup.cjs.map +1 -1
- package/components/InputGroup/InputGroup.d.ts +38 -2
- package/components/InputGroup/InputGroup.definitions.d.ts +6 -0
- package/components/InputGroup/InputGroup.js +109 -95
- 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 +287 -148
- package/components/Modal/Modal.cjs.map +1 -1
- package/components/Modal/Modal.d.ts +57 -6
- package/components/Modal/Modal.js +289 -150
- package/components/Modal/Modal.js.map +1 -1
- package/components/Modal/ModalBody.d.ts +6 -1
- package/components/Modal/ModalFooter.d.ts +12 -4
- package/components/Modal/ModalHeader.d.ts +6 -1
- package/components/Modal/index.d.ts +8 -1
- package/components/Modal.d.ts +4 -0
- package/components/RadioGroup/RadioGroup.cjs +204 -0
- package/components/RadioGroup/RadioGroup.cjs.map +1 -0
- package/components/RadioGroup/RadioGroup.d.ts +59 -0
- package/components/RadioGroup/RadioGroup.definitions.d.ts +6 -0
- package/components/RadioGroup/RadioGroup.js +204 -0
- package/components/RadioGroup/RadioGroup.js.map +1 -0
- package/components/RadioGroup/RadioGroup.sx.d.ts +20 -0
- package/components/RadioGroup/index.d.ts +2 -0
- package/components/RadioGroup.d.ts +6 -0
- package/components/Select/Select.cjs +311 -4
- package/components/Select/Select.cjs.map +1 -1
- package/components/Select/Select.d.ts +62 -27
- package/components/Select/Select.helpers.d.ts +15 -0
- package/components/Select/Select.js +310 -3
- package/components/Select/Select.js.map +1 -1
- package/components/Select/Select.sx.d.ts +7 -0
- package/components/Select/_parts/SelectMenuItem.d.ts +20 -0
- package/components/Select/index.d.ts +2 -1
- package/components/Select.d.ts +4 -0
- package/components/Stat/Stat.cjs +2 -2
- package/components/Stat/Stat.cjs.map +1 -1
- package/components/Stat/Stat.js +2 -2
- 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 +66 -55
- package/components/StatusMessage/StatusMessage.cjs.map +1 -1
- package/components/StatusMessage/StatusMessage.d.ts +20 -36
- package/components/StatusMessage/StatusMessage.js +68 -57
- package/components/StatusMessage/StatusMessage.js.map +1 -1
- package/components/StatusMessage/index.d.ts +2 -1
- package/components/StatusMessage.d.ts +4 -0
- package/components/Stepper/Stepper.cjs +285 -29
- package/components/Stepper/Stepper.cjs.map +1 -1
- package/components/Stepper/Stepper.d.ts +13 -7
- package/components/Stepper/Stepper.js +287 -31
- package/components/Stepper/Stepper.js.map +1 -1
- package/components/Stepper/StepperContext.d.ts +73 -0
- 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 +184 -0
- package/components/Switch/Switch.cjs.map +1 -0
- package/components/Switch/Switch.d.ts +48 -0
- package/components/Switch/Switch.definitions.d.ts +7 -0
- package/components/Switch/Switch.js +184 -0
- package/components/Switch/Switch.js.map +1 -0
- package/components/Switch/Switch.sx.d.ts +22 -0
- package/components/Switch/Switch.types.d.ts +1 -0
- package/components/Switch/index.d.ts +2 -0
- package/components/Switch.d.ts +6 -0
- package/components/Tabs/Tabs.cjs +45 -29
- package/components/Tabs/Tabs.cjs.map +1 -1
- package/components/Tabs/Tabs.d.ts +21 -16
- package/components/Tabs/Tabs.js +46 -30
- package/components/Tabs/Tabs.js.map +1 -1
- 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/formField.sx.d.ts +33 -0
- package/components/_shared/mergeSx.d.ts +7 -0
- package/components/_shared/resolvePreset.d.ts +18 -0
- package/formField.sx-8_QRnKxv.js +68 -0
- package/formField.sx-8_QRnKxv.js.map +1 -0
- package/formField.sx-BAX7KwMR.cjs +67 -0
- package/formField.sx-BAX7KwMR.cjs.map +1 -0
- package/index.cjs +144 -1
- package/index.cjs.map +1 -1
- package/index.d.ts +4 -0
- package/index.js +49 -2
- 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 +7 -0
- package/package.json +31 -1
- package/resolvePreset-B-IB0ehH.js +15 -0
- package/resolvePreset-B-IB0ehH.js.map +1 -0
- package/resolvePreset-CT3kU-K2.cjs +14 -0
- package/resolvePreset-CT3kU-K2.cjs.map +1 -0
- package/theme/componentStyles.d.ts +32 -0
- package/theme/tokens.d.ts +28 -0
- 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/utils/scrollToTop.d.ts +28 -0
- package/DatePicker-BSNboVhN.js +0 -201
- package/DatePicker-BSNboVhN.js.map +0 -1
- package/DatePicker-BoqxWAhj.cjs +0 -200
- package/DatePicker-BoqxWAhj.cjs.map +0 -1
- package/Input-DFHs7cJ_.js +0 -171
- package/Input-DFHs7cJ_.js.map +0 -1
- package/Input-c8MwNNPg.cjs +0 -170
- package/Input-c8MwNNPg.cjs.map +0 -1
- package/Select-BO2N56sm.cjs +0 -411
- package/Select-BO2N56sm.cjs.map +0 -1
- package/Select-BcLkyHSE.js +0 -412
- package/Select-BcLkyHSE.js.map +0 -1
- package/components/Select/Select.definitions.d.ts +0 -14
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
34
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
35
|
+
const styles = require("@mui/material/styles");
|
|
36
|
+
const material = require("@mui/material");
|
|
37
|
+
const reactHookForm = require("react-hook-form");
|
|
38
|
+
const resolvePreset = require("../../resolvePreset-CT3kU-K2.cjs");
|
|
39
|
+
const toRadius = (borderRadius) => typeof borderRadius === "number" ? `${borderRadius}px` : borderRadius;
|
|
40
|
+
const FOCUS_TRANSITION = "border-color 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms, box-shadow 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms";
|
|
41
|
+
const buildSwitchSx = ({
|
|
42
|
+
bordered,
|
|
43
|
+
borderRadius,
|
|
44
|
+
hasLabel,
|
|
45
|
+
error
|
|
46
|
+
}) => {
|
|
47
|
+
const radius = toRadius(borderRadius);
|
|
48
|
+
if (!bordered) {
|
|
49
|
+
return {
|
|
50
|
+
"& .MuiFormHelperText-root": { marginLeft: 0 }
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return (theme) => ({
|
|
54
|
+
"& .MuiFormControlLabel-root": __spreadValues(__spreadProps(__spreadValues({
|
|
55
|
+
marginLeft: 0,
|
|
56
|
+
marginRight: 0,
|
|
57
|
+
paddingX: 1.5,
|
|
58
|
+
paddingY: 1.25,
|
|
59
|
+
border: `1px solid ${error ? theme.palette.error.main : theme.palette.divider}`,
|
|
60
|
+
borderRadius: radius,
|
|
61
|
+
transition: FOCUS_TRANSITION
|
|
62
|
+
}, error && {
|
|
63
|
+
boxShadow: `0 0 0 1px ${theme.palette.error.main}`
|
|
64
|
+
}), {
|
|
65
|
+
// Focus del usuario sobre el switch interno.
|
|
66
|
+
"&:focus-within": {
|
|
67
|
+
borderColor: error ? theme.palette.error.main : theme.palette.primary.main,
|
|
68
|
+
boxShadow: `0 0 0 1px ${error ? theme.palette.error.main : theme.palette.primary.main}`
|
|
69
|
+
}
|
|
70
|
+
}), hasLabel && {
|
|
71
|
+
width: "100%",
|
|
72
|
+
justifyContent: "space-between"
|
|
73
|
+
}),
|
|
74
|
+
"& .MuiFormHelperText-root": {
|
|
75
|
+
marginLeft: 0
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const Switch = (props) => {
|
|
80
|
+
const _a = props, {
|
|
81
|
+
label,
|
|
82
|
+
size = "medium",
|
|
83
|
+
labelPlacement = "end",
|
|
84
|
+
disabled = false,
|
|
85
|
+
error = false,
|
|
86
|
+
helperText,
|
|
87
|
+
bordered = false,
|
|
88
|
+
borderRadius = 10,
|
|
89
|
+
defaultChecked,
|
|
90
|
+
preset,
|
|
91
|
+
sx
|
|
92
|
+
} = _a, rest = __objRest(_a, [
|
|
93
|
+
"label",
|
|
94
|
+
"size",
|
|
95
|
+
"labelPlacement",
|
|
96
|
+
"disabled",
|
|
97
|
+
"error",
|
|
98
|
+
"helperText",
|
|
99
|
+
"bordered",
|
|
100
|
+
"borderRadius",
|
|
101
|
+
"defaultChecked",
|
|
102
|
+
"preset",
|
|
103
|
+
"sx"
|
|
104
|
+
]);
|
|
105
|
+
const theme = styles.useTheme();
|
|
106
|
+
const presetSx = resolvePreset.resolvePreset("Switch", preset, theme);
|
|
107
|
+
const buildSx = (effectiveError) => [
|
|
108
|
+
buildSwitchSx({
|
|
109
|
+
bordered,
|
|
110
|
+
borderRadius,
|
|
111
|
+
hasLabel: !!label,
|
|
112
|
+
error: effectiveError
|
|
113
|
+
}),
|
|
114
|
+
...presetSx ? [presetSx] : [],
|
|
115
|
+
...Array.isArray(sx) ? sx : [sx]
|
|
116
|
+
];
|
|
117
|
+
const renderSwitch = (checked2, onChange2, onBlur, inputRef) => {
|
|
118
|
+
const switchEl = /* @__PURE__ */ jsxRuntime.jsx(
|
|
119
|
+
material.Switch,
|
|
120
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
121
|
+
size,
|
|
122
|
+
checked: !!checked2,
|
|
123
|
+
onChange: (_e, next) => onChange2(next),
|
|
124
|
+
onBlur,
|
|
125
|
+
inputRef,
|
|
126
|
+
disabled
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
return label ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
130
|
+
material.FormControlLabel,
|
|
131
|
+
{
|
|
132
|
+
control: switchEl,
|
|
133
|
+
label,
|
|
134
|
+
labelPlacement,
|
|
135
|
+
disabled
|
|
136
|
+
}
|
|
137
|
+
) : switchEl;
|
|
138
|
+
};
|
|
139
|
+
if ("control" in props && props.control) {
|
|
140
|
+
const { name, control, validation, onValueChange } = props;
|
|
141
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
142
|
+
reactHookForm.Controller,
|
|
143
|
+
{
|
|
144
|
+
name,
|
|
145
|
+
control,
|
|
146
|
+
rules: validation,
|
|
147
|
+
defaultValue: defaultChecked,
|
|
148
|
+
render: ({ field, fieldState: { error: fieldError } }) => {
|
|
149
|
+
var _a2;
|
|
150
|
+
const finalError = !!fieldError || error;
|
|
151
|
+
const finalHelperText = (_a2 = fieldError == null ? void 0 : fieldError.message) != null ? _a2 : helperText;
|
|
152
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
153
|
+
material.FormControl,
|
|
154
|
+
{
|
|
155
|
+
error: finalError,
|
|
156
|
+
disabled,
|
|
157
|
+
sx: buildSx(finalError),
|
|
158
|
+
children: [
|
|
159
|
+
renderSwitch(
|
|
160
|
+
!!field.value,
|
|
161
|
+
(next) => {
|
|
162
|
+
field.onChange(next);
|
|
163
|
+
onValueChange == null ? void 0 : onValueChange(next);
|
|
164
|
+
},
|
|
165
|
+
field.onBlur,
|
|
166
|
+
field.ref
|
|
167
|
+
),
|
|
168
|
+
finalHelperText && /* @__PURE__ */ jsxRuntime.jsx(material.FormHelperText, { children: finalHelperText })
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const { checked, onChange } = props;
|
|
177
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(material.FormControl, { error, disabled, sx: buildSx(error), children: [
|
|
178
|
+
renderSwitch(checked, onChange),
|
|
179
|
+
helperText && /* @__PURE__ */ jsxRuntime.jsx(material.FormHelperText, { children: helperText })
|
|
180
|
+
] });
|
|
181
|
+
};
|
|
182
|
+
exports.Switch = Switch;
|
|
183
|
+
exports.default = Switch;
|
|
184
|
+
//# sourceMappingURL=Switch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Switch.cjs","sources":["../../../src/components/Switch/Switch.sx.ts","../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import type { SxProps, Theme } from '@mui/material/styles';\n\nexport interface BuildSwitchSxOptions {\n bordered: boolean;\n borderRadius: number | string;\n hasLabel: boolean;\n error: boolean;\n}\n\nconst toRadius = (borderRadius: number | string) =>\n typeof borderRadius === 'number' ? `${borderRadius}px` : borderRadius;\n\n/**\n * Transición compartida (matchea el InputGroup y el RadioGroup).\n */\nconst FOCUS_TRANSITION =\n 'border-color 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms, ' +\n 'box-shadow 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms';\n\n/**\n * Builder de sx para Switch. Reproduce el estilo del antiguo\n * `FormToggleInput` legacy cuando `bordered=true`: contenedor con borde,\n * label a la izquierda y switch a la derecha (vía justify-content: space-between).\n *\n * Cuando `bordered=true`, el contenedor gana:\n * - `:focus-within` → borde + shadow primario (mismo patrón que `InputGroup`).\n * - `error=true` → borde + shadow de error (palette.error.main).\n *\n * El shadow es de 1px, así que no hay shift de layout — sólo se intensifica\n * visualmente el borde sin empujar nada alrededor.\n *\n * Si `bordered=false`, sólo aplica un reset de margin del helper text.\n */\nexport const buildSwitchSx = ({\n bordered,\n borderRadius,\n hasLabel,\n error,\n}: BuildSwitchSxOptions): SxProps<Theme> => {\n const radius = toRadius(borderRadius);\n\n if (!bordered) {\n return {\n '& .MuiFormHelperText-root': { marginLeft: 0 },\n };\n }\n\n return (theme) => ({\n '& .MuiFormControlLabel-root': {\n marginLeft: 0,\n marginRight: 0,\n paddingX: 1.5,\n paddingY: 1.25,\n border: `1px solid ${\n error ? theme.palette.error.main : theme.palette.divider\n }`,\n borderRadius: radius,\n transition: FOCUS_TRANSITION,\n ...(error && {\n boxShadow: `0 0 0 1px ${theme.palette.error.main}`,\n }),\n // Focus del usuario sobre el switch interno.\n '&:focus-within': {\n borderColor: error\n ? theme.palette.error.main\n : theme.palette.primary.main,\n boxShadow: `0 0 0 1px ${\n error ? theme.palette.error.main : theme.palette.primary.main\n }`,\n },\n // Si hay label, separar el switch al borde opuesto.\n ...(hasLabel && {\n width: '100%',\n justifyContent: 'space-between',\n }),\n },\n '& .MuiFormHelperText-root': {\n marginLeft: 0,\n },\n });\n};\n","import { useTheme } from '@mui/material/styles';\nimport {\n FormControl,\n FormControlLabel,\n FormHelperText,\n Switch as MuiSwitch,\n type SwitchProps as MuiSwitchProps,\n type SxProps,\n type Theme,\n} from '@mui/material';\nimport { Controller, type Control, type RegisterOptions } from 'react-hook-form';\n\nimport { buildSwitchSx } from './Switch.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\n\n// ── Tipos de dominio ─────────────────────────────────────────────────────\nexport type SwitchSize = 'small' | 'medium';\nexport type SwitchLabelPlacement = 'start' | 'end' | 'top' | 'bottom';\n\n// ── Props base (todo lo común entre RHF y controlado) ────────────────────\nexport interface BaseSwitchProps\n extends Omit<MuiSwitchProps, 'value' | 'onChange' | 'checked' | 'defaultChecked' | 'size'> {\n /** Texto al lado del switch. Si está ausente, no se renderiza FormControlLabel. */\n label?: string;\n size?: SwitchSize;\n /** Posición del label. Default: 'end' (legacy `FormToggleInput` lo ponía a la izquierda con su flex-stack). */\n labelPlacement?: SwitchLabelPlacement;\n disabled?: boolean;\n error?: boolean;\n helperText?: string;\n /** Renderiza un contenedor con borde alrededor del switch + label. Default: false. */\n bordered?: boolean;\n /** Border radius del contenedor (cuando bordered). Default: 10. */\n borderRadius?: number | string;\n defaultChecked?: boolean;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Switch`.\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?: SxProps<Theme>;\n}\n\n// ── Variantes discriminadas (RHF vs controlado) ──────────────────────────\nexport interface RHFSwitchProps extends BaseSwitchProps {\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 o su uso involucra generics adicionales, TS se\n // confunde narroweando el discriminated union y `Control<any>` no logra\n // absorber `Control<MyForm>` en la comparación estructural profunda. El\n // `any` plano elimina ese ruido. RHF adentro sigue teniendo sus tipos\n // fuertes — solo degradamos la superficie del prop del componente.\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. NO reemplaza al handler de RHF.\n */\n onValueChange?: (checked: boolean) => void;\n checked?: never;\n onChange?: never;\n}\n\nexport interface ControlledSwitchProps extends BaseSwitchProps {\n name?: string;\n control?: never;\n validation?: never;\n checked: boolean;\n onChange: (checked: boolean) => void;\n}\n\n// ── API pública final ────────────────────────────────────────────────────\nexport type SwitchProps = RHFSwitchProps | ControlledSwitchProps;\n\nexport const Switch: React.FC<SwitchProps> = (props) => {\n const {\n label,\n size = 'medium',\n labelPlacement = 'end',\n disabled = false,\n error = false,\n helperText,\n bordered = false,\n borderRadius = 10,\n defaultChecked,\n preset,\n sx,\n ...rest\n } = props as ControlledSwitchProps & {\n control?: Control<any>;\n validation?: RegisterOptions;\n };\n\n const theme = useTheme();\n const presetSx = resolvePreset('Switch', preset, theme);\n\n // Construye el sx con el estado de error efectivo; se llama por rama\n // (RHF usa el error del Controller, controlado usa el prop `error`).\n const buildSx = (effectiveError: boolean) => [\n buildSwitchSx({\n bordered,\n borderRadius,\n hasLabel: !!label,\n error: effectiveError,\n }),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : [sx]),\n ];\n\n const renderSwitch = (\n checked: boolean,\n onChange: (next: boolean) => void,\n onBlur?: () => void,\n inputRef?: React.Ref<HTMLInputElement>,\n ) => {\n const switchEl = (\n <MuiSwitch\n {...rest}\n size={size}\n checked={!!checked}\n onChange={(_e, next) => onChange(next)}\n onBlur={onBlur}\n inputRef={inputRef}\n disabled={disabled}\n />\n );\n\n return label ? (\n <FormControlLabel\n control={switchEl}\n label={label}\n labelPlacement={labelPlacement}\n disabled={disabled}\n />\n ) : (\n switchEl\n );\n };\n\n // ── RHF mode ──────────────────────────────────────────────────────────\n if ('control' in props && props.control) {\n const { name, control, validation, onValueChange } = props as RHFSwitchProps;\n return (\n <Controller\n name={name}\n control={control}\n rules={validation}\n defaultValue={defaultChecked}\n render={({ field, fieldState: { error: fieldError } }) => {\n const finalError = !!fieldError || error;\n const finalHelperText = fieldError?.message ?? helperText;\n return (\n <FormControl\n error={finalError}\n disabled={disabled}\n sx={buildSx(finalError)}\n >\n {renderSwitch(\n !!field.value,\n (next) => {\n field.onChange(next);\n onValueChange?.(next);\n },\n field.onBlur,\n field.ref,\n )}\n {finalHelperText && <FormHelperText>{finalHelperText}</FormHelperText>}\n </FormControl>\n );\n }}\n />\n );\n }\n\n // ── Controlled mode ───────────────────────────────────────────────────\n const { checked, onChange } = props as ControlledSwitchProps;\n return (\n <FormControl error={error} disabled={disabled} sx={buildSx(error)}>\n {renderSwitch(checked, onChange)}\n {helperText && <FormHelperText>{helperText}</FormHelperText>}\n </FormControl>\n );\n};\n\nexport default Switch;\n"],"names":["useTheme","resolvePreset","checked","onChange","jsx","MuiSwitch","FormControlLabel","Controller","_a","jsxs","FormControl","FormHelperText"],"mappings":"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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SwitchProps as MuiSwitchProps, SxProps, Theme } from '@mui/material';
|
|
2
|
+
import { RegisterOptions } from 'react-hook-form';
|
|
3
|
+
export type SwitchSize = 'small' | 'medium';
|
|
4
|
+
export type SwitchLabelPlacement = 'start' | 'end' | 'top' | 'bottom';
|
|
5
|
+
export interface BaseSwitchProps extends Omit<MuiSwitchProps, 'value' | 'onChange' | 'checked' | 'defaultChecked' | 'size'> {
|
|
6
|
+
/** Texto al lado del switch. Si está ausente, no se renderiza FormControlLabel. */
|
|
7
|
+
label?: string;
|
|
8
|
+
size?: SwitchSize;
|
|
9
|
+
/** Posición del label. Default: 'end' (legacy `FormToggleInput` lo ponía a la izquierda con su flex-stack). */
|
|
10
|
+
labelPlacement?: SwitchLabelPlacement;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
helperText?: string;
|
|
14
|
+
/** Renderiza un contenedor con borde alrededor del switch + label. Default: false. */
|
|
15
|
+
bordered?: boolean;
|
|
16
|
+
/** Border radius del contenedor (cuando bordered). Default: 10. */
|
|
17
|
+
borderRadius?: number | string;
|
|
18
|
+
defaultChecked?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Nombre del preset de estilo registrado en `theme.styles.Switch`.
|
|
21
|
+
* - `"default"` (o ausente) = estilo built-in del paquete.
|
|
22
|
+
* - Cualquier otro string = mergea el preset encima del estilo built-in.
|
|
23
|
+
*/
|
|
24
|
+
preset?: string;
|
|
25
|
+
sx?: SxProps<Theme>;
|
|
26
|
+
}
|
|
27
|
+
export interface RHFSwitchProps extends BaseSwitchProps {
|
|
28
|
+
name: string;
|
|
29
|
+
control: any;
|
|
30
|
+
validation?: RegisterOptions;
|
|
31
|
+
/**
|
|
32
|
+
* Side-effect que corre después de que RHF actualiza el form state.
|
|
33
|
+
* Útil para cascadas entre campos. NO reemplaza al handler de RHF.
|
|
34
|
+
*/
|
|
35
|
+
onValueChange?: (checked: boolean) => void;
|
|
36
|
+
checked?: never;
|
|
37
|
+
onChange?: never;
|
|
38
|
+
}
|
|
39
|
+
export interface ControlledSwitchProps extends BaseSwitchProps {
|
|
40
|
+
name?: string;
|
|
41
|
+
control?: never;
|
|
42
|
+
validation?: never;
|
|
43
|
+
checked: boolean;
|
|
44
|
+
onChange: (checked: boolean) => void;
|
|
45
|
+
}
|
|
46
|
+
export type SwitchProps = RHFSwitchProps | ControlledSwitchProps;
|
|
47
|
+
export declare const Switch: React.FC<SwitchProps>;
|
|
48
|
+
export default Switch;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const BasicSwitchDefinition = "\nimport React, { useState } from 'react';\nimport { Switch } from './Switch';\nimport { Box, Typography } from '@mui/material';\n\nexport const BasicSwitchExample = () => {\n const [checked, setChecked] = useState(false);\n return (\n <Box sx={{ width: 280 }}>\n <Switch checked={checked} onChange={setChecked} />\n <Typography sx={{ mt: 2 }}>Estado: {checked ? 'ON' : 'OFF'}</Typography>\n </Box>\n );\n};\n";
|
|
2
|
+
export declare const SwitchWithLabelDefinition = "\nimport React, { useState } from 'react';\nimport { Switch } from './Switch';\nimport { Box } from '@mui/material';\n\nexport const SwitchWithLabelExample = () => {\n const [checked, setChecked] = useState(true);\n return (\n <Box sx={{ width: 280 }}>\n <Switch\n label=\"Notificaciones por email\"\n checked={checked}\n onChange={setChecked}\n />\n </Box>\n );\n};\n";
|
|
3
|
+
export declare const BorderedSwitchDefinition = "\nimport React, { useState } from 'react';\nimport { Switch } from './Switch';\nimport { Box } from '@mui/material';\n\nexport const BorderedSwitchExample = () => {\n const [checked, setChecked] = useState(true);\n return (\n <Box sx={{ width: 360 }}>\n <Switch\n label=\"Recibir reportes diarios\"\n checked={checked}\n onChange={setChecked}\n bordered\n />\n </Box>\n );\n};\n";
|
|
4
|
+
export declare const SwitchSizesDefinition = "\nimport React, { useState } from 'react';\nimport { Switch } from './Switch';\nimport { Box } from '@mui/material';\n\nexport const SwitchSizesExample = () => {\n const [a, setA] = useState(false);\n const [b, setB] = useState(true);\n return (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, width: 280 }}>\n <Switch label=\"Peque\u00F1o\" size=\"small\" checked={a} onChange={setA} />\n <Switch label=\"Mediano (default)\" size=\"medium\" checked={b} onChange={setB} />\n </Box>\n );\n};\n";
|
|
5
|
+
export declare const SwitchWithErrorDefinition = "\nimport React, { useState } from 'react';\nimport { Switch } from './Switch';\nimport { Box } from '@mui/material';\n\nexport const SwitchWithErrorExample = () => {\n const [checked, setChecked] = useState(false);\n const hasError = !checked;\n return (\n <Box sx={{ width: 320 }}>\n <Switch\n label=\"Aceptar t\u00E9rminos y condiciones\"\n checked={checked}\n onChange={setChecked}\n error={hasError}\n helperText={hasError ? 'Debes aceptar los t\u00E9rminos para continuar' : ''}\n />\n </Box>\n );\n};\n";
|
|
6
|
+
export declare const DisabledSwitchDefinition = "\nimport React from 'react';\nimport { Switch } from './Switch';\nimport { Box } from '@mui/material';\n\nexport const DisabledSwitchExample = () => (\n <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, width: 280 }}>\n <Switch label=\"Off bloqueado\" checked={false} onChange={() => {}} disabled />\n <Switch label=\"On bloqueado\" checked={true} onChange={() => {}} disabled />\n </Box>\n);\n";
|
|
7
|
+
export declare const RHFSwitchDefinition = "\nimport React from 'react';\nimport { useForm } from 'react-hook-form';\nimport { Switch } from './Switch';\nimport { Box, Button, Typography } from '@mui/material';\n\nexport const RHFSwitchExample = () => {\n const { control, handleSubmit, watch } = useForm({\n defaultValues: { darkMode: false },\n });\n const value = watch('darkMode');\n return (\n <Box sx={{ width: 320 }} component=\"form\" onSubmit={handleSubmit(console.log)}>\n <Switch\n label=\"Modo oscuro\"\n name=\"darkMode\"\n control={control}\n bordered\n />\n <Typography sx={{ mt: 2 }}>Valor en el form: {String(value)}</Typography>\n <Button type=\"submit\" sx={{ mt: 1 }}>Enviar</Button>\n </Box>\n );\n};\n";
|
|
@@ -0,0 +1,184 @@
|
|
|
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 { jsx, jsxs } from "react/jsx-runtime";
|
|
33
|
+
import { useTheme } from "@mui/material/styles";
|
|
34
|
+
import { FormControl, FormHelperText, Switch as Switch$1, FormControlLabel } from "@mui/material";
|
|
35
|
+
import { Controller } from "react-hook-form";
|
|
36
|
+
import { r as resolvePreset } from "../../resolvePreset-B-IB0ehH.js";
|
|
37
|
+
const toRadius = (borderRadius) => typeof borderRadius === "number" ? `${borderRadius}px` : borderRadius;
|
|
38
|
+
const FOCUS_TRANSITION = "border-color 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms, box-shadow 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms";
|
|
39
|
+
const buildSwitchSx = ({
|
|
40
|
+
bordered,
|
|
41
|
+
borderRadius,
|
|
42
|
+
hasLabel,
|
|
43
|
+
error
|
|
44
|
+
}) => {
|
|
45
|
+
const radius = toRadius(borderRadius);
|
|
46
|
+
if (!bordered) {
|
|
47
|
+
return {
|
|
48
|
+
"& .MuiFormHelperText-root": { marginLeft: 0 }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return (theme) => ({
|
|
52
|
+
"& .MuiFormControlLabel-root": __spreadValues(__spreadProps(__spreadValues({
|
|
53
|
+
marginLeft: 0,
|
|
54
|
+
marginRight: 0,
|
|
55
|
+
paddingX: 1.5,
|
|
56
|
+
paddingY: 1.25,
|
|
57
|
+
border: `1px solid ${error ? theme.palette.error.main : theme.palette.divider}`,
|
|
58
|
+
borderRadius: radius,
|
|
59
|
+
transition: FOCUS_TRANSITION
|
|
60
|
+
}, error && {
|
|
61
|
+
boxShadow: `0 0 0 1px ${theme.palette.error.main}`
|
|
62
|
+
}), {
|
|
63
|
+
// Focus del usuario sobre el switch interno.
|
|
64
|
+
"&:focus-within": {
|
|
65
|
+
borderColor: error ? theme.palette.error.main : theme.palette.primary.main,
|
|
66
|
+
boxShadow: `0 0 0 1px ${error ? theme.palette.error.main : theme.palette.primary.main}`
|
|
67
|
+
}
|
|
68
|
+
}), hasLabel && {
|
|
69
|
+
width: "100%",
|
|
70
|
+
justifyContent: "space-between"
|
|
71
|
+
}),
|
|
72
|
+
"& .MuiFormHelperText-root": {
|
|
73
|
+
marginLeft: 0
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const Switch = (props) => {
|
|
78
|
+
const _a = props, {
|
|
79
|
+
label,
|
|
80
|
+
size = "medium",
|
|
81
|
+
labelPlacement = "end",
|
|
82
|
+
disabled = false,
|
|
83
|
+
error = false,
|
|
84
|
+
helperText,
|
|
85
|
+
bordered = false,
|
|
86
|
+
borderRadius = 10,
|
|
87
|
+
defaultChecked,
|
|
88
|
+
preset,
|
|
89
|
+
sx
|
|
90
|
+
} = _a, rest = __objRest(_a, [
|
|
91
|
+
"label",
|
|
92
|
+
"size",
|
|
93
|
+
"labelPlacement",
|
|
94
|
+
"disabled",
|
|
95
|
+
"error",
|
|
96
|
+
"helperText",
|
|
97
|
+
"bordered",
|
|
98
|
+
"borderRadius",
|
|
99
|
+
"defaultChecked",
|
|
100
|
+
"preset",
|
|
101
|
+
"sx"
|
|
102
|
+
]);
|
|
103
|
+
const theme = useTheme();
|
|
104
|
+
const presetSx = resolvePreset("Switch", preset, theme);
|
|
105
|
+
const buildSx = (effectiveError) => [
|
|
106
|
+
buildSwitchSx({
|
|
107
|
+
bordered,
|
|
108
|
+
borderRadius,
|
|
109
|
+
hasLabel: !!label,
|
|
110
|
+
error: effectiveError
|
|
111
|
+
}),
|
|
112
|
+
...presetSx ? [presetSx] : [],
|
|
113
|
+
...Array.isArray(sx) ? sx : [sx]
|
|
114
|
+
];
|
|
115
|
+
const renderSwitch = (checked2, onChange2, onBlur, inputRef) => {
|
|
116
|
+
const switchEl = /* @__PURE__ */ jsx(
|
|
117
|
+
Switch$1,
|
|
118
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
119
|
+
size,
|
|
120
|
+
checked: !!checked2,
|
|
121
|
+
onChange: (_e, next) => onChange2(next),
|
|
122
|
+
onBlur,
|
|
123
|
+
inputRef,
|
|
124
|
+
disabled
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
return label ? /* @__PURE__ */ jsx(
|
|
128
|
+
FormControlLabel,
|
|
129
|
+
{
|
|
130
|
+
control: switchEl,
|
|
131
|
+
label,
|
|
132
|
+
labelPlacement,
|
|
133
|
+
disabled
|
|
134
|
+
}
|
|
135
|
+
) : switchEl;
|
|
136
|
+
};
|
|
137
|
+
if ("control" in props && props.control) {
|
|
138
|
+
const { name, control, validation, onValueChange } = props;
|
|
139
|
+
return /* @__PURE__ */ jsx(
|
|
140
|
+
Controller,
|
|
141
|
+
{
|
|
142
|
+
name,
|
|
143
|
+
control,
|
|
144
|
+
rules: validation,
|
|
145
|
+
defaultValue: defaultChecked,
|
|
146
|
+
render: ({ field, fieldState: { error: fieldError } }) => {
|
|
147
|
+
var _a2;
|
|
148
|
+
const finalError = !!fieldError || error;
|
|
149
|
+
const finalHelperText = (_a2 = fieldError == null ? void 0 : fieldError.message) != null ? _a2 : helperText;
|
|
150
|
+
return /* @__PURE__ */ jsxs(
|
|
151
|
+
FormControl,
|
|
152
|
+
{
|
|
153
|
+
error: finalError,
|
|
154
|
+
disabled,
|
|
155
|
+
sx: buildSx(finalError),
|
|
156
|
+
children: [
|
|
157
|
+
renderSwitch(
|
|
158
|
+
!!field.value,
|
|
159
|
+
(next) => {
|
|
160
|
+
field.onChange(next);
|
|
161
|
+
onValueChange == null ? void 0 : onValueChange(next);
|
|
162
|
+
},
|
|
163
|
+
field.onBlur,
|
|
164
|
+
field.ref
|
|
165
|
+
),
|
|
166
|
+
finalHelperText && /* @__PURE__ */ jsx(FormHelperText, { children: finalHelperText })
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
const { checked, onChange } = props;
|
|
175
|
+
return /* @__PURE__ */ jsxs(FormControl, { error, disabled, sx: buildSx(error), children: [
|
|
176
|
+
renderSwitch(checked, onChange),
|
|
177
|
+
helperText && /* @__PURE__ */ jsx(FormHelperText, { children: helperText })
|
|
178
|
+
] });
|
|
179
|
+
};
|
|
180
|
+
export {
|
|
181
|
+
Switch,
|
|
182
|
+
Switch as default
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=Switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Switch.js","sources":["../../../src/components/Switch/Switch.sx.ts","../../../src/components/Switch/Switch.tsx"],"sourcesContent":["import type { SxProps, Theme } from '@mui/material/styles';\n\nexport interface BuildSwitchSxOptions {\n bordered: boolean;\n borderRadius: number | string;\n hasLabel: boolean;\n error: boolean;\n}\n\nconst toRadius = (borderRadius: number | string) =>\n typeof borderRadius === 'number' ? `${borderRadius}px` : borderRadius;\n\n/**\n * Transición compartida (matchea el InputGroup y el RadioGroup).\n */\nconst FOCUS_TRANSITION =\n 'border-color 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms, ' +\n 'box-shadow 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms';\n\n/**\n * Builder de sx para Switch. Reproduce el estilo del antiguo\n * `FormToggleInput` legacy cuando `bordered=true`: contenedor con borde,\n * label a la izquierda y switch a la derecha (vía justify-content: space-between).\n *\n * Cuando `bordered=true`, el contenedor gana:\n * - `:focus-within` → borde + shadow primario (mismo patrón que `InputGroup`).\n * - `error=true` → borde + shadow de error (palette.error.main).\n *\n * El shadow es de 1px, así que no hay shift de layout — sólo se intensifica\n * visualmente el borde sin empujar nada alrededor.\n *\n * Si `bordered=false`, sólo aplica un reset de margin del helper text.\n */\nexport const buildSwitchSx = ({\n bordered,\n borderRadius,\n hasLabel,\n error,\n}: BuildSwitchSxOptions): SxProps<Theme> => {\n const radius = toRadius(borderRadius);\n\n if (!bordered) {\n return {\n '& .MuiFormHelperText-root': { marginLeft: 0 },\n };\n }\n\n return (theme) => ({\n '& .MuiFormControlLabel-root': {\n marginLeft: 0,\n marginRight: 0,\n paddingX: 1.5,\n paddingY: 1.25,\n border: `1px solid ${\n error ? theme.palette.error.main : theme.palette.divider\n }`,\n borderRadius: radius,\n transition: FOCUS_TRANSITION,\n ...(error && {\n boxShadow: `0 0 0 1px ${theme.palette.error.main}`,\n }),\n // Focus del usuario sobre el switch interno.\n '&:focus-within': {\n borderColor: error\n ? theme.palette.error.main\n : theme.palette.primary.main,\n boxShadow: `0 0 0 1px ${\n error ? theme.palette.error.main : theme.palette.primary.main\n }`,\n },\n // Si hay label, separar el switch al borde opuesto.\n ...(hasLabel && {\n width: '100%',\n justifyContent: 'space-between',\n }),\n },\n '& .MuiFormHelperText-root': {\n marginLeft: 0,\n },\n });\n};\n","import { useTheme } from '@mui/material/styles';\nimport {\n FormControl,\n FormControlLabel,\n FormHelperText,\n Switch as MuiSwitch,\n type SwitchProps as MuiSwitchProps,\n type SxProps,\n type Theme,\n} from '@mui/material';\nimport { Controller, type Control, type RegisterOptions } from 'react-hook-form';\n\nimport { buildSwitchSx } from './Switch.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\n\n// ── Tipos de dominio ─────────────────────────────────────────────────────\nexport type SwitchSize = 'small' | 'medium';\nexport type SwitchLabelPlacement = 'start' | 'end' | 'top' | 'bottom';\n\n// ── Props base (todo lo común entre RHF y controlado) ────────────────────\nexport interface BaseSwitchProps\n extends Omit<MuiSwitchProps, 'value' | 'onChange' | 'checked' | 'defaultChecked' | 'size'> {\n /** Texto al lado del switch. Si está ausente, no se renderiza FormControlLabel. */\n label?: string;\n size?: SwitchSize;\n /** Posición del label. Default: 'end' (legacy `FormToggleInput` lo ponía a la izquierda con su flex-stack). */\n labelPlacement?: SwitchLabelPlacement;\n disabled?: boolean;\n error?: boolean;\n helperText?: string;\n /** Renderiza un contenedor con borde alrededor del switch + label. Default: false. */\n bordered?: boolean;\n /** Border radius del contenedor (cuando bordered). Default: 10. */\n borderRadius?: number | string;\n defaultChecked?: boolean;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Switch`.\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?: SxProps<Theme>;\n}\n\n// ── Variantes discriminadas (RHF vs controlado) ──────────────────────────\nexport interface RHFSwitchProps extends BaseSwitchProps {\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 o su uso involucra generics adicionales, TS se\n // confunde narroweando el discriminated union y `Control<any>` no logra\n // absorber `Control<MyForm>` en la comparación estructural profunda. El\n // `any` plano elimina ese ruido. RHF adentro sigue teniendo sus tipos\n // fuertes — solo degradamos la superficie del prop del componente.\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. NO reemplaza al handler de RHF.\n */\n onValueChange?: (checked: boolean) => void;\n checked?: never;\n onChange?: never;\n}\n\nexport interface ControlledSwitchProps extends BaseSwitchProps {\n name?: string;\n control?: never;\n validation?: never;\n checked: boolean;\n onChange: (checked: boolean) => void;\n}\n\n// ── API pública final ────────────────────────────────────────────────────\nexport type SwitchProps = RHFSwitchProps | ControlledSwitchProps;\n\nexport const Switch: React.FC<SwitchProps> = (props) => {\n const {\n label,\n size = 'medium',\n labelPlacement = 'end',\n disabled = false,\n error = false,\n helperText,\n bordered = false,\n borderRadius = 10,\n defaultChecked,\n preset,\n sx,\n ...rest\n } = props as ControlledSwitchProps & {\n control?: Control<any>;\n validation?: RegisterOptions;\n };\n\n const theme = useTheme();\n const presetSx = resolvePreset('Switch', preset, theme);\n\n // Construye el sx con el estado de error efectivo; se llama por rama\n // (RHF usa el error del Controller, controlado usa el prop `error`).\n const buildSx = (effectiveError: boolean) => [\n buildSwitchSx({\n bordered,\n borderRadius,\n hasLabel: !!label,\n error: effectiveError,\n }),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : [sx]),\n ];\n\n const renderSwitch = (\n checked: boolean,\n onChange: (next: boolean) => void,\n onBlur?: () => void,\n inputRef?: React.Ref<HTMLInputElement>,\n ) => {\n const switchEl = (\n <MuiSwitch\n {...rest}\n size={size}\n checked={!!checked}\n onChange={(_e, next) => onChange(next)}\n onBlur={onBlur}\n inputRef={inputRef}\n disabled={disabled}\n />\n );\n\n return label ? (\n <FormControlLabel\n control={switchEl}\n label={label}\n labelPlacement={labelPlacement}\n disabled={disabled}\n />\n ) : (\n switchEl\n );\n };\n\n // ── RHF mode ──────────────────────────────────────────────────────────\n if ('control' in props && props.control) {\n const { name, control, validation, onValueChange } = props as RHFSwitchProps;\n return (\n <Controller\n name={name}\n control={control}\n rules={validation}\n defaultValue={defaultChecked}\n render={({ field, fieldState: { error: fieldError } }) => {\n const finalError = !!fieldError || error;\n const finalHelperText = fieldError?.message ?? helperText;\n return (\n <FormControl\n error={finalError}\n disabled={disabled}\n sx={buildSx(finalError)}\n >\n {renderSwitch(\n !!field.value,\n (next) => {\n field.onChange(next);\n onValueChange?.(next);\n },\n field.onBlur,\n field.ref,\n )}\n {finalHelperText && <FormHelperText>{finalHelperText}</FormHelperText>}\n </FormControl>\n );\n }}\n />\n );\n }\n\n // ── Controlled mode ───────────────────────────────────────────────────\n const { checked, onChange } = props as ControlledSwitchProps;\n return (\n <FormControl error={error} disabled={disabled} sx={buildSx(error)}>\n {renderSwitch(checked, onChange)}\n {helperText && <FormHelperText>{helperText}</FormHelperText>}\n </FormControl>\n );\n};\n\nexport default Switch;\n"],"names":["checked","onChange","MuiSwitch","_a"],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SxProps, Theme } from '@mui/material/styles';
|
|
2
|
+
export interface BuildSwitchSxOptions {
|
|
3
|
+
bordered: boolean;
|
|
4
|
+
borderRadius: number | string;
|
|
5
|
+
hasLabel: boolean;
|
|
6
|
+
error: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Builder de sx para Switch. Reproduce el estilo del antiguo
|
|
10
|
+
* `FormToggleInput` legacy cuando `bordered=true`: contenedor con borde,
|
|
11
|
+
* label a la izquierda y switch a la derecha (vía justify-content: space-between).
|
|
12
|
+
*
|
|
13
|
+
* Cuando `bordered=true`, el contenedor gana:
|
|
14
|
+
* - `:focus-within` → borde + shadow primario (mismo patrón que `InputGroup`).
|
|
15
|
+
* - `error=true` → borde + shadow de error (palette.error.main).
|
|
16
|
+
*
|
|
17
|
+
* El shadow es de 1px, así que no hay shift de layout — sólo se intensifica
|
|
18
|
+
* visualmente el borde sin empujar nada alrededor.
|
|
19
|
+
*
|
|
20
|
+
* Si `bordered=false`, sólo aplica un reset de margin del helper text.
|
|
21
|
+
*/
|
|
22
|
+
export declare const buildSwitchSx: ({ bordered, borderRadius, hasLabel, error, }: BuildSwitchSxOptions) => SxProps<Theme>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { SwitchSize, SwitchLabelPlacement, BaseSwitchProps, RHFSwitchProps, ControlledSwitchProps, SwitchProps, } from './Switch';
|
package/components/Tabs/Tabs.cjs
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __spreadValues = (a, b) => {
|
|
8
|
-
for (var prop in b || (b = {}))
|
|
9
|
-
if (__hasOwnProp.call(b, prop))
|
|
10
|
-
__defNormalProp(a, prop, b[prop]);
|
|
11
|
-
if (__getOwnPropSymbols)
|
|
12
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
-
if (__propIsEnum.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
}
|
|
16
|
-
return a;
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
19
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
20
4
|
const React = require("react");
|
|
21
5
|
const material = require("@mui/material");
|
|
6
|
+
const mergeSx = require("../../mergeSx-Dbccoo_H.cjs");
|
|
22
7
|
const TAB_DISPLAY_MAP = {
|
|
23
8
|
horizontal: { display: "flex", flexDirection: "column" },
|
|
24
9
|
vertical: { display: "flex", flexDirection: "row" }
|
|
@@ -26,7 +11,7 @@ const TAB_DISPLAY_MAP = {
|
|
|
26
11
|
const Tabs = ({
|
|
27
12
|
children,
|
|
28
13
|
defaultValue,
|
|
29
|
-
|
|
14
|
+
onChangeValue,
|
|
30
15
|
centered = true,
|
|
31
16
|
orientation = "horizontal",
|
|
32
17
|
scrollButtons = "auto",
|
|
@@ -34,21 +19,27 @@ const Tabs = ({
|
|
|
34
19
|
indicatorColor = "primary",
|
|
35
20
|
labelColor = "primary",
|
|
36
21
|
className,
|
|
37
|
-
onChangeValue,
|
|
38
22
|
allowScrollButtonsMobile = true,
|
|
23
|
+
keepMounted = false,
|
|
39
24
|
sx
|
|
40
25
|
}) => {
|
|
41
26
|
var _a, _b;
|
|
42
|
-
const
|
|
27
|
+
const tabs = React.Children.toArray(children).filter(
|
|
28
|
+
(child) => {
|
|
29
|
+
var _a2;
|
|
30
|
+
return React.isValidElement(child) && ((_a2 = child.type) == null ? void 0 : _a2.displayName) === "Tab";
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
const firstValue = (_a = tabs[0]) == null ? void 0 : _a.props.value;
|
|
43
34
|
const [currentValue, setCurrentValue] = React.useState(
|
|
44
35
|
(_b = defaultValue != null ? defaultValue : firstValue) != null ? _b : 0
|
|
45
36
|
);
|
|
46
|
-
const handleChange = (
|
|
37
|
+
const handleChange = (_event, newValue) => {
|
|
47
38
|
setCurrentValue(newValue);
|
|
48
|
-
onChange == null ? void 0 : onChange();
|
|
49
39
|
onChangeValue == null ? void 0 : onChangeValue(newValue);
|
|
50
40
|
};
|
|
51
|
-
|
|
41
|
+
const { display, flexDirection } = TAB_DISPLAY_MAP[orientation];
|
|
42
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: { display, flexDirection }, children: [
|
|
52
43
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
53
44
|
material.Tabs,
|
|
54
45
|
{
|
|
@@ -61,10 +52,19 @@ const Tabs = ({
|
|
|
61
52
|
variant,
|
|
62
53
|
className,
|
|
63
54
|
textColor: labelColor,
|
|
64
|
-
sx: __spreadValues({}, sx),
|
|
65
55
|
allowScrollButtonsMobile,
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
sx: mergeSx.mergeSx({}, sx),
|
|
57
|
+
children: tabs.map((tab, idx) => {
|
|
58
|
+
const {
|
|
59
|
+
label,
|
|
60
|
+
icon,
|
|
61
|
+
value = idx,
|
|
62
|
+
disabled,
|
|
63
|
+
wrapped,
|
|
64
|
+
iconPosition,
|
|
65
|
+
className: tabClassName,
|
|
66
|
+
sx: tabSx
|
|
67
|
+
} = tab.props;
|
|
68
68
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
69
69
|
material.Tab,
|
|
70
70
|
{
|
|
@@ -82,10 +82,25 @@ const Tabs = ({
|
|
|
82
82
|
})
|
|
83
83
|
}
|
|
84
84
|
),
|
|
85
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { m: 2,
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { m: 2, sx: { width: "100%" }, children: keepMounted ? tabs.map((tab, idx) => {
|
|
86
|
+
var _a2;
|
|
87
|
+
const value = (_a2 = tab.props.value) != null ? _a2 : idx;
|
|
88
|
+
const isActive = value === currentValue;
|
|
89
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
90
|
+
material.Box,
|
|
91
|
+
{
|
|
92
|
+
role: "tabpanel",
|
|
93
|
+
sx: { display: isActive ? "block" : "none" },
|
|
94
|
+
"aria-hidden": !isActive,
|
|
95
|
+
children: tab.props.children
|
|
96
|
+
},
|
|
97
|
+
value
|
|
98
|
+
);
|
|
99
|
+
}) : tabs.map((tab, idx) => {
|
|
86
100
|
var _a2;
|
|
87
|
-
const value = (_a2 =
|
|
88
|
-
|
|
101
|
+
const value = (_a2 = tab.props.value) != null ? _a2 : idx;
|
|
102
|
+
if (value !== currentValue) return null;
|
|
103
|
+
return /* @__PURE__ */ jsxRuntime.jsx(material.Box, { role: "tabpanel", children: tab.props.children }, value);
|
|
89
104
|
}) })
|
|
90
105
|
] });
|
|
91
106
|
};
|
|
@@ -93,4 +108,5 @@ const Tab = (_) => null;
|
|
|
93
108
|
Tab.displayName = "Tab";
|
|
94
109
|
exports.Tab = Tab;
|
|
95
110
|
exports.Tabs = Tabs;
|
|
111
|
+
exports.default = Tabs;
|
|
96
112
|
//# sourceMappingURL=Tabs.cjs.map
|