@soyfri/shared-library 2.0.0-beta.7 → 2.0.0-beta.9

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.
@@ -1,4 +1,23 @@
1
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));
2
21
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
22
  const jsxRuntime = require("react/jsx-runtime");
4
23
  const material = require("@mui/material");
@@ -7,36 +26,60 @@ const Stepper = ({
7
26
  children,
8
27
  orientation = "horizontal",
9
28
  alternateLabel = false,
29
+ responsive = true,
30
+ mobileBreakpoint = "sm",
10
31
  sx,
11
32
  currentStep: currentStepProp
12
33
  }) => {
34
+ const theme = material.useTheme();
35
+ const isMobile = material.useMediaQuery(theme.breakpoints.down(mobileBreakpoint));
36
+ const mobileAdapt = responsive && isMobile && orientation === "horizontal";
37
+ const effectiveOrientation = mobileAdapt && children.length > 3 ? "vertical" : orientation;
38
+ const hideLabelsOnMobile = mobileAdapt && children.length <= 3;
39
+ const effectiveAlternateLabel = alternateLabel && effectiveOrientation === "horizontal";
13
40
  const wizard = useWizard.useWizard();
14
41
  const currentStep = currentStepProp !== void 0 ? currentStepProp : wizard.totalSteps > 0 ? wizard.currentStep : 0;
15
- return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx, children: [
16
- /* @__PURE__ */ jsxRuntime.jsx(material.Stepper, { activeStep: currentStep, orientation, alternativeLabel: alternateLabel, children: children.map((child, idx) => {
17
- const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;
18
- return /* @__PURE__ */ jsxRuntime.jsx(material.Step, { completed, disabled, className, sx: stepSx, children: /* @__PURE__ */ jsxRuntime.jsx(
19
- material.StepLabel,
20
- {
21
- sx: {
22
- pointerEvents: "none",
23
- "& .MuiStepIcon-root": {
24
- color: dotColor
25
- },
26
- "& .MuiStepIcon-active": {
27
- color: activeDotColor
28
- },
29
- "& .MuiStepIcon-completed": {
30
- color: completedDotColor
31
- },
32
- "& .MuiStepIcon-text": {
33
- fill: iconTextColor
42
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: __spreadValues({ width: "100%", overflowX: "hidden" }, sx), children: [
43
+ /* @__PURE__ */ jsxRuntime.jsx(
44
+ material.Stepper,
45
+ {
46
+ activeStep: currentStep,
47
+ orientation: effectiveOrientation,
48
+ alternativeLabel: effectiveAlternateLabel,
49
+ sx: __spreadValues({}, effectiveOrientation === "horizontal" && {
50
+ flexWrap: "wrap",
51
+ rowGap: 1,
52
+ "& .MuiStepLabel-label": { textAlign: "center" }
53
+ }),
54
+ children: children.map((child, idx) => {
55
+ const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;
56
+ return /* @__PURE__ */ jsxRuntime.jsx(material.Step, { completed, disabled, className, sx: stepSx, children: /* @__PURE__ */ jsxRuntime.jsx(
57
+ material.StepLabel,
58
+ {
59
+ sx: __spreadProps(__spreadValues({
60
+ pointerEvents: "none"
61
+ }, hideLabelsOnMobile && {
62
+ "& .MuiStepLabel-labelContainer": { display: "none" }
63
+ }), {
64
+ "& .MuiStepIcon-root": {
65
+ color: dotColor
66
+ },
67
+ "& .MuiStepIcon-active": {
68
+ color: activeDotColor
69
+ },
70
+ "& .MuiStepIcon-completed": {
71
+ color: completedDotColor
72
+ },
73
+ "& .MuiStepIcon-text": {
74
+ fill: iconTextColor
75
+ }
76
+ }),
77
+ children: label
34
78
  }
35
- },
36
- children: label
37
- }
38
- ) }, idx);
39
- }) }),
79
+ ) }, idx);
80
+ })
81
+ }
82
+ ),
40
83
  /* @__PURE__ */ jsxRuntime.jsx(material.Box, { mt: 2, children: children.map(
41
84
  (child, idx) => idx === currentStep ? /* @__PURE__ */ jsxRuntime.jsx(material.Box, { children: child.props.children }, idx) : null
42
85
  ) })
@@ -1 +1 @@
1
- {"version":3,"file":"Stepper.cjs","sources":["../../../src/components/Stepper/Stepper.tsx","../../../src/components/Stepper/Step.tsx"],"sourcesContent":["import React, { ReactElement } from \"react\";\nimport { Stepper as MuiStepper, Step as MuiStep, StepLabel as MuiStepLabel, Box } from \"@mui/material\";\nimport { StepProps } from \"./Step\";\nimport { useWizard } from \"../../hooks/Wizard\";\n\ninterface MyStepperProps {\n children: ReactElement<StepProps>[];\n orientation?: \"horizontal\" | \"vertical\";\n sx?: object;\n alternateLabel?: boolean;\n /**\n * Índice 0-based del paso activo. Si no se provee, el Stepper intenta\n * leerlo del `WizardContext` (si está dentro de un `<WizardProvider>`).\n * Si tampoco hay provider, el default es 0.\n */\n currentStep?: number;\n}\n\nexport const Stepper: React.FC<MyStepperProps> = ({\n children,\n orientation = \"horizontal\",\n alternateLabel = false,\n\n sx,\n currentStep: currentStepProp,\n}) => {\n // Lee el paso desde el WizardContext cuando el consumer no lo pasa como prop.\n // Si el Stepper NO está dentro de un WizardProvider, `useWizard()` devuelve\n // el valor default (currentStep=0, totalSteps=0), así que no rompe nada.\n const wizard = useWizard();\n const currentStep =\n currentStepProp !== undefined\n ? currentStepProp\n : wizard.totalSteps > 0\n ? wizard.currentStep\n : 0;\n\n return (\n <Box sx={sx}>\n <MuiStepper activeStep={currentStep} orientation={orientation} alternativeLabel={alternateLabel} >\n {children.map((child, idx) => {\n const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;\n return (\n <MuiStep key={idx} completed={completed} disabled={disabled} className={className} sx={stepSx}>\n <MuiStepLabel sx={{\n pointerEvents: 'none',\n \"& .MuiStepIcon-root\": {\n color: dotColor,\n },\n \"& .MuiStepIcon-active\": {\n color: activeDotColor,\n },\n \"& .MuiStepIcon-completed\": {\n color: completedDotColor,\n },\n \"& .MuiStepIcon-text\": {\n fill: iconTextColor,\n },\n }}\n >{label}\n </MuiStepLabel>\n </MuiStep>\n );\n })}\n </MuiStepper>\n <Box mt={2}>\n {children.map((child, idx) =>\n idx === currentStep ? <Box key={idx}>{child.props.children}</Box> : null\n )}\n </Box>\n </Box>\n );\n};\n\nexport default Stepper;","import React from \"react\";\nimport { StepProps as MuiStepProps } from \"@mui/material\";\n\ntype PickMuiStepProps = Pick<MuiStepProps, \"completed\" | \"disabled\" | \"sx\" | \"className\">;\n\nexport interface StepProps extends PickMuiStepProps {\n label: React.ReactNode;\n children?: React.ReactNode;\n disabled?: boolean;\n sx?: object;\n dotColor?: string; // dot base\n activeDotColor?: string; // dot activa\n completedDotColor?: string; // dot completada\n iconTextColor?: string; // número o check dentro\n}\n\nexport const Step = (_: StepProps): null => null;\n\nStep.displayName = \"Step\";\n\nexport default Step;"],"names":["useWizard","jsxs","Box","jsx","MuiStepper","MuiStep","MuiStepLabel"],"mappings":";;;;;AAkBO,MAAM,UAAoC,CAAC;AAAA,EAChD;AAAA,EACA,cAAc;AAAA,EACd,iBAAiB;AAAA,EAEjB;AAAA,EACA,aAAa;AACf,MAAM;AAIJ,QAAM,SAASA,UAAAA,UAAA;AACf,QAAM,cACJ,oBAAoB,SAChB,kBACA,OAAO,aAAa,IAClB,OAAO,cACP;AAER,SACEC,gCAACC,SAAAA,OAAI,IACH,UAAA;AAAA,IAAAC,2BAAAA,IAACC,SAAAA,SAAA,EAAW,YAAY,aAAa,aAA0B,kBAAkB,gBAC9E,UAAA,SAAS,IAAI,CAAC,OAAO,QAAQ;AAC5B,YAAM,EAAE,OAAO,WAAW,UAAU,WAAW,IAAI,QAAQ,UAAU,gBAAgB,mBAAmB,cAAA,IAAkB,MAAM;AAChI,4CACGC,eAAA,EAAkB,WAAsB,UAAoB,WAAsB,IAAI,QACrF,UAAAF,2BAAAA;AAAAA,QAACG,SAAAA;AAAAA,QAAA;AAAA,UAAa,IAAI;AAAA,YAChB,eAAe;AAAA,YACf,uBAAuB;AAAA,cACrB,OAAO;AAAA,YAAA;AAAA,YAET,yBAAyB;AAAA,cACvB,OAAO;AAAA,YAAA;AAAA,YAET,4BAA4B;AAAA,cAC1B,OAAO;AAAA,YAAA;AAAA,YAET,uBAAuB;AAAA,cACrB,MAAM;AAAA,YAAA;AAAA,UACR;AAAA,UAEA,UAAA;AAAA,QAAA;AAAA,MAAA,KAhBU,GAkBd;AAAA,IAEJ,CAAC,EAAA,CACH;AAAA,IACAH,2BAAAA,IAACD,SAAAA,KAAA,EAAI,IAAI,GACN,UAAA,SAAS;AAAA,MAAI,CAAC,OAAO,QACpB,QAAQ,cAAcC,2BAAAA,IAACD,SAAAA,KAAA,EAAe,UAAA,MAAM,MAAM,SAAA,GAAlB,GAA2B,IAAS;AAAA,IAAA,EACtE,CACF;AAAA,EAAA,GACF;AAEJ;ACxDO,MAAM,OAAO,CAAC,MAAuB;AAE5C,KAAK,cAAc;;;"}
1
+ {"version":3,"file":"Stepper.cjs","sources":["../../../src/components/Stepper/Stepper.tsx","../../../src/components/Stepper/Step.tsx"],"sourcesContent":["import React, { ReactElement } from \"react\";\nimport {\n Stepper as MuiStepper,\n Step as MuiStep,\n StepLabel as MuiStepLabel,\n Box,\n useMediaQuery,\n useTheme,\n Breakpoint,\n} from \"@mui/material\";\nimport { StepProps } from \"./Step\";\nimport { useWizard } from \"../../hooks/Wizard\";\n\ninterface MyStepperProps {\n children: ReactElement<StepProps>[];\n orientation?: \"horizontal\" | \"vertical\";\n sx?: object;\n alternateLabel?: boolean;\n /**\n * Índice 0-based del paso activo. Si no se provee, el Stepper intenta\n * leerlo del `WizardContext` (si está dentro de un `<WizardProvider>`).\n * Si tampoco hay provider, el default es 0.\n */\n currentStep?: number;\n /**\n * Cuando es true (default), en pantallas más angostas que `mobileBreakpoint`\n * el stepper horizontal automáticamente:\n * - cambia a orientación vertical si hay >3 steps, o\n * - oculta los labels (solo dots) si hay ≤3 steps,\n * para evitar que se desborde del contenedor.\n * Si pasas `orientation=\"vertical\"` explícito, no se altera.\n */\n responsive?: boolean;\n /** Breakpoint debajo del cual aplica el modo mobile. Default: \"sm\". */\n mobileBreakpoint?: Breakpoint;\n}\n\nexport const Stepper: React.FC<MyStepperProps> = ({\n children,\n orientation = \"horizontal\",\n alternateLabel = false,\n responsive = true,\n mobileBreakpoint = \"sm\",\n sx,\n currentStep: currentStepProp,\n}) => {\n const theme = useTheme();\n const isMobile = useMediaQuery(theme.breakpoints.down(mobileBreakpoint));\n\n // Solo aplicamos adaptación mobile si el consumer pidió orientación horizontal.\n const mobileAdapt = responsive && isMobile && orientation === \"horizontal\";\n // Con muchos steps no caben aunque ocultes labels → mejor vertical.\n const effectiveOrientation: \"horizontal\" | \"vertical\" =\n mobileAdapt && children.length > 3 ? \"vertical\" : orientation;\n // Con pocos steps conservamos horizontal pero ocultamos labels para no desbordar.\n const hideLabelsOnMobile = mobileAdapt && children.length <= 3;\n const effectiveAlternateLabel =\n alternateLabel && effectiveOrientation === \"horizontal\";\n // Lee el paso desde el WizardContext cuando el consumer no lo pasa como prop.\n // Si el Stepper NO está dentro de un WizardProvider, `useWizard()` devuelve\n // el valor default (currentStep=0, totalSteps=0), así que no rompe nada.\n const wizard = useWizard();\n const currentStep =\n currentStepProp !== undefined\n ? currentStepProp\n : wizard.totalSteps > 0\n ? wizard.currentStep\n : 0;\n\n return (\n <Box sx={{ width: \"100%\", overflowX: \"hidden\", ...sx }}>\n <MuiStepper\n activeStep={currentStep}\n orientation={effectiveOrientation}\n alternativeLabel={effectiveAlternateLabel}\n sx={{\n // En horizontal con muchos labels + poco ancho, permitimos que\n // los labels hagan wrap en lugar de forzar overflow.\n ...(effectiveOrientation === \"horizontal\" && {\n flexWrap: \"wrap\",\n rowGap: 1,\n \"& .MuiStepLabel-label\": { textAlign: \"center\" },\n }),\n }}\n >\n {children.map((child, idx) => {\n const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;\n return (\n <MuiStep key={idx} completed={completed} disabled={disabled} className={className} sx={stepSx}>\n <MuiStepLabel sx={{\n pointerEvents: 'none',\n // Ocultamos la parte de texto en mobile cuando aplicamos\n // reducción a dots-only. El icono se mantiene visible.\n ...(hideLabelsOnMobile && {\n \"& .MuiStepLabel-labelContainer\": { display: \"none\" },\n }),\n \"& .MuiStepIcon-root\": {\n color: dotColor,\n },\n \"& .MuiStepIcon-active\": {\n color: activeDotColor,\n },\n \"& .MuiStepIcon-completed\": {\n color: completedDotColor,\n },\n \"& .MuiStepIcon-text\": {\n fill: iconTextColor,\n },\n }}\n >{label}\n </MuiStepLabel>\n </MuiStep>\n );\n })}\n </MuiStepper>\n <Box mt={2}>\n {children.map((child, idx) =>\n idx === currentStep ? <Box key={idx}>{child.props.children}</Box> : null\n )}\n </Box>\n </Box>\n );\n};\n\nexport default Stepper;","import React from \"react\";\nimport { StepProps as MuiStepProps } from \"@mui/material\";\n\ntype PickMuiStepProps = Pick<MuiStepProps, \"completed\" | \"disabled\" | \"sx\" | \"className\">;\n\nexport interface StepProps extends PickMuiStepProps {\n label: React.ReactNode;\n children?: React.ReactNode;\n disabled?: boolean;\n sx?: object;\n dotColor?: string; // dot base\n activeDotColor?: string; // dot activa\n completedDotColor?: string; // dot completada\n iconTextColor?: string; // número o check dentro\n}\n\nexport const Step = (_: StepProps): null => null;\n\nStep.displayName = \"Step\";\n\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AAAA,gBAChB,eAAe;AAAA,iBAGX,sBAAsB;AAAA,gBACxB,kCAAkC,EAAE,SAAS,OAAA;AAAA,cAAO,IALtC;AAAA,gBAOhB,uBAAuB;AAAA,kBACrB,OAAO;AAAA,gBAAA;AAAA,gBAET,yBAAyB;AAAA,kBACvB,OAAO;AAAA,gBAAA;AAAA,gBAET,4BAA4B;AAAA,kBAC1B,OAAO;AAAA,gBAAA;AAAA,gBAET,uBAAuB;AAAA,kBACrB,MAAM;AAAA,gBAAA;AAAA,cACR;AAAA,cAEA,UAAA;AAAA,YAAA;AAAA,UAAA,KArBU,GAuBd;AAAA,QAEJ,CAAC;AAAA,MAAA;AAAA,IAAA;AAAA,IAEHH,2BAAAA,IAACD,SAAAA,KAAA,EAAI,IAAI,GACN,UAAA,SAAS;AAAA,MAAI,CAAC,OAAO,QACpB,QAAQ,cAAcC,2BAAAA,IAACD,SAAAA,KAAA,EAAe,UAAA,MAAM,MAAM,SAAA,GAAlB,GAA2B,IAAS;AAAA,IAAA,EACtE,CACF;AAAA,EAAA,GACF;AAEJ;AC1GO,MAAM,OAAO,CAAC,MAAuB;AAE5C,KAAK,cAAc;;;"}
@@ -1,4 +1,5 @@
1
1
  import { default as React, ReactElement } from 'react';
2
+ import { Breakpoint } from '@mui/material';
2
3
  import { StepProps } from './Step';
3
4
  interface MyStepperProps {
4
5
  children: ReactElement<StepProps>[];
@@ -11,6 +12,17 @@ interface MyStepperProps {
11
12
  * Si tampoco hay provider, el default es 0.
12
13
  */
13
14
  currentStep?: number;
15
+ /**
16
+ * Cuando es true (default), en pantallas más angostas que `mobileBreakpoint`
17
+ * el stepper horizontal automáticamente:
18
+ * - cambia a orientación vertical si hay >3 steps, o
19
+ * - oculta los labels (solo dots) si hay ≤3 steps,
20
+ * para evitar que se desborde del contenedor.
21
+ * Si pasas `orientation="vertical"` explícito, no se altera.
22
+ */
23
+ responsive?: boolean;
24
+ /** Breakpoint debajo del cual aplica el modo mobile. Default: "sm". */
25
+ mobileBreakpoint?: Breakpoint;
14
26
  }
15
27
  export declare const Stepper: React.FC<MyStepperProps>;
16
28
  export default Stepper;
@@ -1,40 +1,83 @@
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));
1
20
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { Box, Stepper as Stepper$1, Step as Step$1, StepLabel } from "@mui/material";
21
+ import { useTheme, useMediaQuery, Box, Stepper as Stepper$1, Step as Step$1, StepLabel } from "@mui/material";
3
22
  import { u as useWizard } from "../../useWizard-CWq--C3o.js";
4
23
  const Stepper = ({
5
24
  children,
6
25
  orientation = "horizontal",
7
26
  alternateLabel = false,
27
+ responsive = true,
28
+ mobileBreakpoint = "sm",
8
29
  sx,
9
30
  currentStep: currentStepProp
10
31
  }) => {
32
+ const theme = useTheme();
33
+ const isMobile = useMediaQuery(theme.breakpoints.down(mobileBreakpoint));
34
+ const mobileAdapt = responsive && isMobile && orientation === "horizontal";
35
+ const effectiveOrientation = mobileAdapt && children.length > 3 ? "vertical" : orientation;
36
+ const hideLabelsOnMobile = mobileAdapt && children.length <= 3;
37
+ const effectiveAlternateLabel = alternateLabel && effectiveOrientation === "horizontal";
11
38
  const wizard = useWizard();
12
39
  const currentStep = currentStepProp !== void 0 ? currentStepProp : wizard.totalSteps > 0 ? wizard.currentStep : 0;
13
- return /* @__PURE__ */ jsxs(Box, { sx, children: [
14
- /* @__PURE__ */ jsx(Stepper$1, { activeStep: currentStep, orientation, alternativeLabel: alternateLabel, children: children.map((child, idx) => {
15
- const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;
16
- return /* @__PURE__ */ jsx(Step$1, { completed, disabled, className, sx: stepSx, children: /* @__PURE__ */ jsx(
17
- StepLabel,
18
- {
19
- sx: {
20
- pointerEvents: "none",
21
- "& .MuiStepIcon-root": {
22
- color: dotColor
23
- },
24
- "& .MuiStepIcon-active": {
25
- color: activeDotColor
26
- },
27
- "& .MuiStepIcon-completed": {
28
- color: completedDotColor
29
- },
30
- "& .MuiStepIcon-text": {
31
- fill: iconTextColor
40
+ return /* @__PURE__ */ jsxs(Box, { sx: __spreadValues({ width: "100%", overflowX: "hidden" }, sx), children: [
41
+ /* @__PURE__ */ jsx(
42
+ Stepper$1,
43
+ {
44
+ activeStep: currentStep,
45
+ orientation: effectiveOrientation,
46
+ alternativeLabel: effectiveAlternateLabel,
47
+ sx: __spreadValues({}, effectiveOrientation === "horizontal" && {
48
+ flexWrap: "wrap",
49
+ rowGap: 1,
50
+ "& .MuiStepLabel-label": { textAlign: "center" }
51
+ }),
52
+ children: children.map((child, idx) => {
53
+ const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;
54
+ return /* @__PURE__ */ jsx(Step$1, { completed, disabled, className, sx: stepSx, children: /* @__PURE__ */ jsx(
55
+ StepLabel,
56
+ {
57
+ sx: __spreadProps(__spreadValues({
58
+ pointerEvents: "none"
59
+ }, hideLabelsOnMobile && {
60
+ "& .MuiStepLabel-labelContainer": { display: "none" }
61
+ }), {
62
+ "& .MuiStepIcon-root": {
63
+ color: dotColor
64
+ },
65
+ "& .MuiStepIcon-active": {
66
+ color: activeDotColor
67
+ },
68
+ "& .MuiStepIcon-completed": {
69
+ color: completedDotColor
70
+ },
71
+ "& .MuiStepIcon-text": {
72
+ fill: iconTextColor
73
+ }
74
+ }),
75
+ children: label
32
76
  }
33
- },
34
- children: label
35
- }
36
- ) }, idx);
37
- }) }),
77
+ ) }, idx);
78
+ })
79
+ }
80
+ ),
38
81
  /* @__PURE__ */ jsx(Box, { mt: 2, children: children.map(
39
82
  (child, idx) => idx === currentStep ? /* @__PURE__ */ jsx(Box, { children: child.props.children }, idx) : null
40
83
  ) })
@@ -1 +1 @@
1
- {"version":3,"file":"Stepper.js","sources":["../../../src/components/Stepper/Stepper.tsx","../../../src/components/Stepper/Step.tsx"],"sourcesContent":["import React, { ReactElement } from \"react\";\nimport { Stepper as MuiStepper, Step as MuiStep, StepLabel as MuiStepLabel, Box } from \"@mui/material\";\nimport { StepProps } from \"./Step\";\nimport { useWizard } from \"../../hooks/Wizard\";\n\ninterface MyStepperProps {\n children: ReactElement<StepProps>[];\n orientation?: \"horizontal\" | \"vertical\";\n sx?: object;\n alternateLabel?: boolean;\n /**\n * Índice 0-based del paso activo. Si no se provee, el Stepper intenta\n * leerlo del `WizardContext` (si está dentro de un `<WizardProvider>`).\n * Si tampoco hay provider, el default es 0.\n */\n currentStep?: number;\n}\n\nexport const Stepper: React.FC<MyStepperProps> = ({\n children,\n orientation = \"horizontal\",\n alternateLabel = false,\n\n sx,\n currentStep: currentStepProp,\n}) => {\n // Lee el paso desde el WizardContext cuando el consumer no lo pasa como prop.\n // Si el Stepper NO está dentro de un WizardProvider, `useWizard()` devuelve\n // el valor default (currentStep=0, totalSteps=0), así que no rompe nada.\n const wizard = useWizard();\n const currentStep =\n currentStepProp !== undefined\n ? currentStepProp\n : wizard.totalSteps > 0\n ? wizard.currentStep\n : 0;\n\n return (\n <Box sx={sx}>\n <MuiStepper activeStep={currentStep} orientation={orientation} alternativeLabel={alternateLabel} >\n {children.map((child, idx) => {\n const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;\n return (\n <MuiStep key={idx} completed={completed} disabled={disabled} className={className} sx={stepSx}>\n <MuiStepLabel sx={{\n pointerEvents: 'none',\n \"& .MuiStepIcon-root\": {\n color: dotColor,\n },\n \"& .MuiStepIcon-active\": {\n color: activeDotColor,\n },\n \"& .MuiStepIcon-completed\": {\n color: completedDotColor,\n },\n \"& .MuiStepIcon-text\": {\n fill: iconTextColor,\n },\n }}\n >{label}\n </MuiStepLabel>\n </MuiStep>\n );\n })}\n </MuiStepper>\n <Box mt={2}>\n {children.map((child, idx) =>\n idx === currentStep ? <Box key={idx}>{child.props.children}</Box> : null\n )}\n </Box>\n </Box>\n );\n};\n\nexport default Stepper;","import React from \"react\";\nimport { StepProps as MuiStepProps } from \"@mui/material\";\n\ntype PickMuiStepProps = Pick<MuiStepProps, \"completed\" | \"disabled\" | \"sx\" | \"className\">;\n\nexport interface StepProps extends PickMuiStepProps {\n label: React.ReactNode;\n children?: React.ReactNode;\n disabled?: boolean;\n sx?: object;\n dotColor?: string; // dot base\n activeDotColor?: string; // dot activa\n completedDotColor?: string; // dot completada\n iconTextColor?: string; // número o check dentro\n}\n\nexport const Step = (_: StepProps): null => null;\n\nStep.displayName = \"Step\";\n\nexport default Step;"],"names":["MuiStepper","MuiStep","MuiStepLabel"],"mappings":";;;AAkBO,MAAM,UAAoC,CAAC;AAAA,EAChD;AAAA,EACA,cAAc;AAAA,EACd,iBAAiB;AAAA,EAEjB;AAAA,EACA,aAAa;AACf,MAAM;AAIJ,QAAM,SAAS,UAAA;AACf,QAAM,cACJ,oBAAoB,SAChB,kBACA,OAAO,aAAa,IAClB,OAAO,cACP;AAER,SACE,qBAAC,OAAI,IACH,UAAA;AAAA,IAAA,oBAACA,WAAA,EAAW,YAAY,aAAa,aAA0B,kBAAkB,gBAC9E,UAAA,SAAS,IAAI,CAAC,OAAO,QAAQ;AAC5B,YAAM,EAAE,OAAO,WAAW,UAAU,WAAW,IAAI,QAAQ,UAAU,gBAAgB,mBAAmB,cAAA,IAAkB,MAAM;AAChI,iCACGC,QAAA,EAAkB,WAAsB,UAAoB,WAAsB,IAAI,QACrF,UAAA;AAAA,QAACC;AAAAA,QAAA;AAAA,UAAa,IAAI;AAAA,YAChB,eAAe;AAAA,YACf,uBAAuB;AAAA,cACrB,OAAO;AAAA,YAAA;AAAA,YAET,yBAAyB;AAAA,cACvB,OAAO;AAAA,YAAA;AAAA,YAET,4BAA4B;AAAA,cAC1B,OAAO;AAAA,YAAA;AAAA,YAET,uBAAuB;AAAA,cACrB,MAAM;AAAA,YAAA;AAAA,UACR;AAAA,UAEA,UAAA;AAAA,QAAA;AAAA,MAAA,KAhBU,GAkBd;AAAA,IAEJ,CAAC,EAAA,CACH;AAAA,IACA,oBAAC,KAAA,EAAI,IAAI,GACN,UAAA,SAAS;AAAA,MAAI,CAAC,OAAO,QACpB,QAAQ,cAAc,oBAAC,KAAA,EAAe,UAAA,MAAM,MAAM,SAAA,GAAlB,GAA2B,IAAS;AAAA,IAAA,EACtE,CACF;AAAA,EAAA,GACF;AAEJ;ACxDO,MAAM,OAAO,CAAC,MAAuB;AAE5C,KAAK,cAAc;"}
1
+ {"version":3,"file":"Stepper.js","sources":["../../../src/components/Stepper/Stepper.tsx","../../../src/components/Stepper/Step.tsx"],"sourcesContent":["import React, { ReactElement } from \"react\";\nimport {\n Stepper as MuiStepper,\n Step as MuiStep,\n StepLabel as MuiStepLabel,\n Box,\n useMediaQuery,\n useTheme,\n Breakpoint,\n} from \"@mui/material\";\nimport { StepProps } from \"./Step\";\nimport { useWizard } from \"../../hooks/Wizard\";\n\ninterface MyStepperProps {\n children: ReactElement<StepProps>[];\n orientation?: \"horizontal\" | \"vertical\";\n sx?: object;\n alternateLabel?: boolean;\n /**\n * Índice 0-based del paso activo. Si no se provee, el Stepper intenta\n * leerlo del `WizardContext` (si está dentro de un `<WizardProvider>`).\n * Si tampoco hay provider, el default es 0.\n */\n currentStep?: number;\n /**\n * Cuando es true (default), en pantallas más angostas que `mobileBreakpoint`\n * el stepper horizontal automáticamente:\n * - cambia a orientación vertical si hay >3 steps, o\n * - oculta los labels (solo dots) si hay ≤3 steps,\n * para evitar que se desborde del contenedor.\n * Si pasas `orientation=\"vertical\"` explícito, no se altera.\n */\n responsive?: boolean;\n /** Breakpoint debajo del cual aplica el modo mobile. Default: \"sm\". */\n mobileBreakpoint?: Breakpoint;\n}\n\nexport const Stepper: React.FC<MyStepperProps> = ({\n children,\n orientation = \"horizontal\",\n alternateLabel = false,\n responsive = true,\n mobileBreakpoint = \"sm\",\n sx,\n currentStep: currentStepProp,\n}) => {\n const theme = useTheme();\n const isMobile = useMediaQuery(theme.breakpoints.down(mobileBreakpoint));\n\n // Solo aplicamos adaptación mobile si el consumer pidió orientación horizontal.\n const mobileAdapt = responsive && isMobile && orientation === \"horizontal\";\n // Con muchos steps no caben aunque ocultes labels → mejor vertical.\n const effectiveOrientation: \"horizontal\" | \"vertical\" =\n mobileAdapt && children.length > 3 ? \"vertical\" : orientation;\n // Con pocos steps conservamos horizontal pero ocultamos labels para no desbordar.\n const hideLabelsOnMobile = mobileAdapt && children.length <= 3;\n const effectiveAlternateLabel =\n alternateLabel && effectiveOrientation === \"horizontal\";\n // Lee el paso desde el WizardContext cuando el consumer no lo pasa como prop.\n // Si el Stepper NO está dentro de un WizardProvider, `useWizard()` devuelve\n // el valor default (currentStep=0, totalSteps=0), así que no rompe nada.\n const wizard = useWizard();\n const currentStep =\n currentStepProp !== undefined\n ? currentStepProp\n : wizard.totalSteps > 0\n ? wizard.currentStep\n : 0;\n\n return (\n <Box sx={{ width: \"100%\", overflowX: \"hidden\", ...sx }}>\n <MuiStepper\n activeStep={currentStep}\n orientation={effectiveOrientation}\n alternativeLabel={effectiveAlternateLabel}\n sx={{\n // En horizontal con muchos labels + poco ancho, permitimos que\n // los labels hagan wrap en lugar de forzar overflow.\n ...(effectiveOrientation === \"horizontal\" && {\n flexWrap: \"wrap\",\n rowGap: 1,\n \"& .MuiStepLabel-label\": { textAlign: \"center\" },\n }),\n }}\n >\n {children.map((child, idx) => {\n const { label, completed, disabled, className, sx: stepSx, dotColor, activeDotColor, completedDotColor, iconTextColor } = child.props;\n return (\n <MuiStep key={idx} completed={completed} disabled={disabled} className={className} sx={stepSx}>\n <MuiStepLabel sx={{\n pointerEvents: 'none',\n // Ocultamos la parte de texto en mobile cuando aplicamos\n // reducción a dots-only. El icono se mantiene visible.\n ...(hideLabelsOnMobile && {\n \"& .MuiStepLabel-labelContainer\": { display: \"none\" },\n }),\n \"& .MuiStepIcon-root\": {\n color: dotColor,\n },\n \"& .MuiStepIcon-active\": {\n color: activeDotColor,\n },\n \"& .MuiStepIcon-completed\": {\n color: completedDotColor,\n },\n \"& .MuiStepIcon-text\": {\n fill: iconTextColor,\n },\n }}\n >{label}\n </MuiStepLabel>\n </MuiStep>\n );\n })}\n </MuiStepper>\n <Box mt={2}>\n {children.map((child, idx) =>\n idx === currentStep ? <Box key={idx}>{child.props.children}</Box> : null\n )}\n </Box>\n </Box>\n );\n};\n\nexport default Stepper;","import React from \"react\";\nimport { StepProps as MuiStepProps } from \"@mui/material\";\n\ntype PickMuiStepProps = Pick<MuiStepProps, \"completed\" | \"disabled\" | \"sx\" | \"className\">;\n\nexport interface StepProps extends PickMuiStepProps {\n label: React.ReactNode;\n children?: React.ReactNode;\n disabled?: boolean;\n sx?: object;\n dotColor?: string; // dot base\n activeDotColor?: string; // dot activa\n completedDotColor?: string; // dot completada\n iconTextColor?: string; // número o check dentro\n}\n\nexport const Step = (_: StepProps): null => null;\n\nStep.displayName = \"Step\";\n\nexport default Step;"],"names":["MuiStepper","MuiStep","MuiStepLabel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqCO,MAAM,UAAoC,CAAC;AAAA,EAChD;AAAA,EACA,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB;AAAA,EACA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AAA,cACR;AAAA,cAEA,UAAA;AAAA,YAAA;AAAA,UAAA,KArBU,GAuBd;AAAA,QAEJ,CAAC;AAAA,MAAA;AAAA,IAAA;AAAA,IAEH,oBAAC,KAAA,EAAI,IAAI,GACN,UAAA,SAAS;AAAA,MAAI,CAAC,OAAO,QACpB,QAAQ,cAAc,oBAAC,KAAA,EAAe,UAAA,MAAM,MAAM,SAAA,GAAlB,GAA2B,IAAS;AAAA,IAAA,EACtE,CACF;AAAA,EAAA,GACF;AAEJ;AC1GO,MAAM,OAAO,CAAC,MAAuB;AAE5C,KAAK,cAAc;"}
@@ -0,0 +1,181 @@
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 } = 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) => field.onChange(next),
162
+ field.onBlur,
163
+ field.ref
164
+ ),
165
+ finalHelperText && /* @__PURE__ */ jsxRuntime.jsx(material.FormHelperText, { children: finalHelperText })
166
+ ]
167
+ }
168
+ );
169
+ }
170
+ }
171
+ );
172
+ }
173
+ const { checked, onChange } = props;
174
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.FormControl, { error, disabled, sx: buildSx(error), children: [
175
+ renderSwitch(checked, onChange),
176
+ helperText && /* @__PURE__ */ jsxRuntime.jsx(material.FormHelperText, { children: helperText })
177
+ ] });
178
+ };
179
+ exports.Switch = Switch;
180
+ exports.default = Switch;
181
+ //# 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 control: Control<any>;\n validation?: RegisterOptions;\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 } = 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) => field.onChange(next),\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,WAAW,CAAC,iBAChB,OAAO,iBAAiB,WAAW,GAAG,YAAY,OAAO;AAK3D,MAAM,mBACJ;AAiBK,MAAM,gBAAgB,CAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA4C;AAC1C,QAAM,SAAS,SAAS,YAAY;AAEpC,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,MACL,6BAA6B,EAAE,YAAY,EAAA;AAAA,IAAE;AAAA,EAEjD;AAEA,SAAO,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YAAA;AAAA,UAAA;AAAA,QAG3D;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AAGA,QAAM,EAAE,SAAS,SAAA,IAAa;AAC9B,yCACGD,sBAAA,EAAY,OAAc,UAAoB,IAAI,QAAQ,KAAK,GAC7D,UAAA;AAAA,IAAA,aAAa,SAAS,QAAQ;AAAA,IAC9B,cAAcN,2BAAAA,IAACO,SAAAA,gBAAA,EAAgB,UAAA,WAAA,CAAW;AAAA,EAAA,GAC7C;AAEJ;;;"}
@@ -0,0 +1,43 @@
1
+ import { SwitchProps as MuiSwitchProps, SxProps, Theme } from '@mui/material';
2
+ import { Control, 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: Control<any>;
30
+ validation?: RegisterOptions;
31
+ checked?: never;
32
+ onChange?: never;
33
+ }
34
+ export interface ControlledSwitchProps extends BaseSwitchProps {
35
+ name?: string;
36
+ control?: never;
37
+ validation?: never;
38
+ checked: boolean;
39
+ onChange: (checked: boolean) => void;
40
+ }
41
+ export type SwitchProps = RHFSwitchProps | ControlledSwitchProps;
42
+ export declare const Switch: React.FC<SwitchProps>;
43
+ 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";