@soyfri/shared-library 2.0.0-beta.5 → 2.0.0-beta.6
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.
|
@@ -96,6 +96,7 @@ function Drawer({
|
|
|
96
96
|
collapsedWidth = 72,
|
|
97
97
|
showCollapseButton,
|
|
98
98
|
header,
|
|
99
|
+
logo,
|
|
99
100
|
footer,
|
|
100
101
|
preset,
|
|
101
102
|
sx,
|
|
@@ -133,20 +134,22 @@ function Drawer({
|
|
|
133
134
|
sx: paperSx
|
|
134
135
|
},
|
|
135
136
|
children: [
|
|
136
|
-
|
|
137
|
+
(logo || shouldShowToggle) && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
137
138
|
material.Box,
|
|
138
139
|
{
|
|
139
140
|
sx: {
|
|
140
141
|
display: "flex",
|
|
142
|
+
flexDirection: contextValue.collapsed ? "column" : "row",
|
|
141
143
|
alignItems: "center",
|
|
142
|
-
justifyContent: contextValue.collapsed ? "center" : "space-between",
|
|
144
|
+
justifyContent: contextValue.collapsed ? "center" : logo ? "space-between" : "flex-end",
|
|
145
|
+
gap: contextValue.collapsed ? 0.5 : 0,
|
|
143
146
|
px: contextValue.collapsed ? 1 : 2,
|
|
144
|
-
py: 1
|
|
147
|
+
py: 1,
|
|
145
148
|
minHeight: 64,
|
|
146
149
|
flexShrink: 0
|
|
147
150
|
},
|
|
148
151
|
children: [
|
|
149
|
-
|
|
152
|
+
logo && /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { display: "flex", alignItems: "center", minWidth: 0 }, children: logo }),
|
|
150
153
|
shouldShowToggle && /* @__PURE__ */ jsxRuntime.jsx(
|
|
151
154
|
material.IconButton,
|
|
152
155
|
{
|
|
@@ -159,24 +162,18 @@ function Drawer({
|
|
|
159
162
|
]
|
|
160
163
|
}
|
|
161
164
|
),
|
|
162
|
-
|
|
165
|
+
header && !contextValue.collapsed && /* @__PURE__ */ jsxRuntime.jsx(
|
|
163
166
|
material.Box,
|
|
164
167
|
{
|
|
165
168
|
sx: {
|
|
166
169
|
display: "flex",
|
|
167
|
-
|
|
168
|
-
px:
|
|
169
|
-
py: 1
|
|
170
|
+
alignItems: "center",
|
|
171
|
+
px: 2,
|
|
172
|
+
py: 1.5,
|
|
173
|
+
minHeight: 56,
|
|
174
|
+
flexShrink: 0
|
|
170
175
|
},
|
|
171
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
172
|
-
material.IconButton,
|
|
173
|
-
{
|
|
174
|
-
size: "small",
|
|
175
|
-
onClick: onToggleCollapse,
|
|
176
|
-
"aria-label": collapsed ? "Expandir menú" : "Colapsar menú",
|
|
177
|
-
children: collapsed ? /* @__PURE__ */ jsxRuntime.jsx(ChevronRightIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(ChevronLeftIcon, {})
|
|
178
|
-
}
|
|
179
|
-
)
|
|
176
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { flex: 1, minWidth: 0 }, children: header })
|
|
180
177
|
}
|
|
181
178
|
),
|
|
182
179
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.cjs","sources":["../../../src/components/Drawer/DrawerContext.ts","../../../src/components/Drawer/Drawer.sx.ts","../../../src/components/Drawer/Drawer.tsx","../../../src/components/Drawer/DrawerItem.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\n/**\n * Context interno del Drawer. Permite que los sub-componentes (DrawerItem,\n * DrawerSection, etc.) reaccionen al estado `collapsed` sin necesidad de\n * recibirlo por props explícitas.\n */\nexport interface DrawerContextValue {\n /** Si el drawer está en modo mini (solo iconos). */\n collapsed: boolean;\n /** Ancho actual del drawer (útil para sub-componentes que necesiten layout). */\n width: number;\n}\n\nexport const DrawerContext = createContext<DrawerContextValue | null>(null);\n\n/**\n * Hook para leer el estado del drawer desde cualquier sub-componente. Si se\n * llama fuera de un `<Drawer>`, devuelve valores por defecto (collapsed=false)\n * para que los items renderizados sueltos no exploten.\n */\nexport function useDrawerContext(): DrawerContextValue {\n const ctx = useContext(DrawerContext);\n if (ctx) return ctx;\n return { collapsed: false, width: 260 };\n}\n","import type { SxProps, Theme } from '@mui/material/styles';\n\nexport interface BuildDrawerSxArgs {\n /** Ancho actual del drawer (expanded o collapsed). */\n width: number;\n /** Duración de la transición de ancho en ms. */\n transitionDuration?: number;\n}\n\n/**\n * sx aplicado al root del MuiDrawer. Controla el ancho animado y el paper\n * interno. Los estilos visuales del paper (background, border) se dejan en\n * manos del theme / preset.\n */\nexport function buildDrawerSx({\n width,\n transitionDuration = 200,\n}: BuildDrawerSxArgs): SxProps<Theme> {\n return {\n width,\n flexShrink: 0,\n whiteSpace: 'nowrap',\n boxSizing: 'border-box',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n '& .MuiDrawer-paper': {\n width,\n boxSizing: 'border-box',\n overflowX: 'hidden',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n },\n };\n}\n\nexport interface BuildDrawerItemSxArgs {\n collapsed: boolean;\n active?: boolean;\n danger?: boolean;\n}\n\n/**\n * sx para un item del drawer. Centra el icono cuando está colapsado y\n * tiñe el fondo cuando el item está activo.\n */\nexport function buildDrawerItemSx({\n collapsed,\n active,\n danger,\n}: BuildDrawerItemSxArgs): SxProps<Theme> {\n return (theme) => ({\n minHeight: 44,\n px: collapsed ? 1 : 2,\n py: 1,\n mx: 1,\n my: 0.25,\n borderRadius: 1,\n display: 'flex',\n alignItems: 'center',\n justifyContent: collapsed ? 'center' : 'flex-start',\n gap: collapsed ? 0 : 1.5,\n cursor: 'pointer',\n color: danger\n ? theme.palette.error.main\n : active\n ? theme.palette.primary.main\n : theme.palette.text.primary,\n backgroundColor: active\n ? theme.palette.action.selected\n : 'transparent',\n transition: theme.transitions.create(\n ['background-color', 'color', 'padding'],\n { duration: 150 },\n ),\n '&:hover': {\n backgroundColor: danger\n ? theme.palette.error.light + '22'\n : theme.palette.action.hover,\n },\n '& .drawer-item__icon': {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n flexShrink: 0,\n minWidth: 24,\n },\n '& .drawer-item__label': {\n flex: 1,\n minWidth: 0,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n opacity: collapsed ? 0 : 1,\n width: collapsed ? 0 : 'auto',\n transition: theme.transitions.create(['opacity', 'width'], {\n duration: collapsed ? 100 : 200,\n }),\n },\n });\n}\n","import React, { useMemo, type ReactNode } from 'react';\nimport {\n Drawer as MuiDrawer,\n IconButton,\n Box,\n type DrawerProps as MuiDrawerProps,\n} from '@mui/material';\nimport {\n useTheme,\n type SxProps,\n type Theme,\n} from '@mui/material/styles';\nimport ChevronLeftIcon from '@mui/icons-material/ChevronLeft';\nimport ChevronRightIcon from '@mui/icons-material/ChevronRight';\n\nimport { DrawerContext } from './DrawerContext';\nimport { buildDrawerSx } from './Drawer.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\n\n// ── Tipos públicos ──────────────────────────────────────────────────────\nexport type DrawerVariant = 'permanent' | 'persistent' | 'temporary';\nexport type DrawerAnchor = 'left' | 'right' | 'top' | 'bottom';\n\nexport interface DrawerProps {\n /** Contenido del drawer (típicamente `<DrawerItem>`s). */\n children?: ReactNode;\n /**\n * Variante del drawer:\n * - `permanent` (default): siempre visible en desktop, soporta collapsed (mini).\n * - `persistent`: se oculta/muestra, empuja el contenido principal.\n * - `temporary`: flotante con backdrop (típico móvil).\n */\n variant?: DrawerVariant;\n /** Lado del viewport. Default: `'left'`. */\n anchor?: DrawerAnchor;\n /**\n * Estado mini (solo iconos). Solo se aplica con `variant=\"permanent\"` o\n * `\"persistent\"`. Si no se provee, el drawer está siempre expandido.\n */\n collapsed?: boolean;\n /** Callback del botón de toggle (chevron). */\n onToggleCollapse?: () => void;\n /** Estado abierto/cerrado (aplica a `temporary` y `persistent`). */\n open?: boolean;\n /** Callback de cierre (backdrop o ESC en temporary). */\n onClose?: MuiDrawerProps['onClose'];\n /** Ancho en estado expandido. Default: 260. */\n expandedWidth?: number;\n /** Ancho en estado colapsado (solo iconos). Default: 72. */\n collapsedWidth?: number;\n /** Muestra el botón chevron para toggle collapsed. Default: true si `onToggleCollapse` está definido. */\n showCollapseButton?: boolean;\n /** Contenido del header (por encima de los items). Típicamente logo/brand. */\n header?: ReactNode;\n /** Contenido del footer (por debajo de los items). Típicamente user profile. */\n footer?: ReactNode;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Drawer`.\n * - `\"default\"` (o ausente) = estilo built-in del paquete.\n */\n preset?: string;\n /** sx aplicado al Drawer (root). Se mergea después del preset. */\n sx?: SxProps<Theme>;\n /** sx aplicado al Paper interno. */\n paperSx?: SxProps<Theme>;\n className?: string;\n}\n\nexport function Drawer({\n children,\n variant = 'permanent',\n anchor = 'left',\n collapsed = false,\n onToggleCollapse,\n open,\n onClose,\n expandedWidth = 260,\n collapsedWidth = 72,\n showCollapseButton,\n header,\n footer,\n preset,\n sx,\n paperSx,\n className,\n}: DrawerProps) {\n const theme = useTheme();\n const presetSx = resolvePreset('Drawer', preset, theme);\n\n // El mini-variant solo tiene sentido en permanent / persistent.\n const supportsCollapsed = variant !== 'temporary';\n const effectiveWidth =\n supportsCollapsed && collapsed ? collapsedWidth : expandedWidth;\n\n const contextValue = useMemo(\n () => ({\n collapsed: supportsCollapsed && collapsed,\n width: effectiveWidth,\n }),\n [supportsCollapsed, collapsed, effectiveWidth],\n );\n\n const rootSx: SxProps<Theme> = [\n buildDrawerSx({ width: effectiveWidth }),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ];\n\n const shouldShowToggle =\n showCollapseButton ?? (supportsCollapsed && !!onToggleCollapse);\n\n const openProp =\n variant === 'permanent'\n ? true\n : open !== undefined\n ? open\n : false;\n\n return (\n <DrawerContext.Provider value={contextValue}>\n <MuiDrawer\n variant={variant}\n anchor={anchor}\n open={openProp}\n onClose={onClose}\n className={className}\n sx={rootSx}\n PaperProps={{\n sx: paperSx,\n }}\n >\n {header && (\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'space-between',\n px: contextValue.collapsed ? 1 : 2,\n py: 1.5,\n minHeight: 64,\n flexShrink: 0,\n }}\n >\n {!contextValue.collapsed && (\n <Box sx={{ flex: 1, minWidth: 0 }}>{header}</Box>\n )}\n {shouldShowToggle && (\n <IconButton\n size=\"small\"\n onClick={onToggleCollapse}\n aria-label={collapsed ? 'Expandir menú' : 'Colapsar menú'}\n >\n {collapsed ? <ChevronRightIcon /> : <ChevronLeftIcon />}\n </IconButton>\n )}\n </Box>\n )}\n\n {!header && shouldShowToggle && (\n <Box\n sx={{\n display: 'flex',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'flex-end',\n px: 1,\n py: 1,\n }}\n >\n <IconButton\n size=\"small\"\n onClick={onToggleCollapse}\n aria-label={collapsed ? 'Expandir menú' : 'Colapsar menú'}\n >\n {collapsed ? <ChevronRightIcon /> : <ChevronLeftIcon />}\n </IconButton>\n </Box>\n )}\n\n <Box\n component=\"nav\"\n sx={{\n flex: 1,\n overflowY: 'auto',\n overflowX: 'hidden',\n py: 1,\n }}\n >\n {children}\n </Box>\n\n {footer && (\n <Box\n sx={{\n flexShrink: 0,\n borderTop: (t) => `1px solid ${t.palette.divider}`,\n p: contextValue.collapsed ? 1 : 1.5,\n display: 'flex',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'flex-start',\n }}\n >\n {footer}\n </Box>\n )}\n </MuiDrawer>\n </DrawerContext.Provider>\n );\n}\n\nexport default Drawer;\n","import React, { type ReactNode, type MouseEvent } from 'react';\nimport { Box, Tooltip, Typography } from '@mui/material';\nimport type { SxProps, Theme } from '@mui/material/styles';\n\nimport { useDrawerContext } from './DrawerContext';\nimport { buildDrawerItemSx } from './Drawer.sx';\n\nexport interface DrawerItemProps {\n /** Icono del item. Se muestra siempre (expanded y collapsed). */\n icon?: ReactNode;\n /** Texto del item. Se oculta cuando el drawer está colapsado (muestra tooltip). */\n label: ReactNode;\n /** Handler de click. */\n onClick?: (event: MouseEvent<HTMLDivElement>) => void;\n /** Marca el item como activo (destaca color y fondo). */\n active?: boolean;\n /** Marca el item como \"destructivo\" (p.ej. cerrar sesión): color error. */\n danger?: boolean;\n /** Deshabilita click + bajo opacidad. */\n disabled?: boolean;\n /** Contenido adicional a la derecha del label (badge, count, chevron). */\n endAdornment?: ReactNode;\n /** sx override del consumer, se mergea al final. */\n sx?: SxProps<Theme>;\n className?: string;\n}\n\n/**\n * Item de un Drawer de shared-library. Lee el estado `collapsed` del\n * DrawerContext para adaptar layout y mostrar tooltip en modo mini.\n *\n * Uso típico:\n * ```tsx\n * <Drawer collapsed={collapsed} onToggleCollapse={toggle}>\n * <DrawerItem icon={<HomeIcon />} label=\"Inicio\" active />\n * <DrawerItem icon={<UserIcon />} label=\"Perfil\" />\n * </Drawer>\n * ```\n */\nexport function DrawerItem({\n icon,\n label,\n onClick,\n active = false,\n danger = false,\n disabled = false,\n endAdornment,\n sx,\n className,\n}: DrawerItemProps) {\n const { collapsed } = useDrawerContext();\n\n const baseSx = buildDrawerItemSx({ collapsed, active, danger });\n\n const mergedSx: SxProps<Theme> = [\n baseSx,\n disabled && { pointerEvents: 'none', opacity: 0.5 },\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ].filter(Boolean) as SxProps<Theme>;\n\n const content = (\n <Box\n role=\"button\"\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled}\n onClick={disabled ? undefined : onClick}\n onKeyDown={(event) => {\n if (disabled) return;\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onClick?.(event as unknown as MouseEvent<HTMLDivElement>);\n }\n }}\n className={className}\n sx={mergedSx}\n >\n {icon !== undefined && (\n <Box className=\"drawer-item__icon\" component=\"span\">\n {icon}\n </Box>\n )}\n <Typography\n component=\"span\"\n variant=\"body2\"\n className=\"drawer-item__label\"\n sx={{ fontWeight: active ? 600 : 400 }}\n >\n {label}\n </Typography>\n {!collapsed && endAdornment && (\n <Box component=\"span\" sx={{ flexShrink: 0, ml: 'auto' }}>\n {endAdornment}\n </Box>\n )}\n </Box>\n );\n\n // Cuando está colapsado, envolvemos en tooltip para revelar el label al hover.\n if (collapsed && typeof label === 'string') {\n return (\n <Tooltip title={label} placement=\"right\" arrow>\n {content}\n </Tooltip>\n );\n }\n\n return content;\n}\n\nexport default DrawerItem;\n"],"names":["createContext","useContext","useTheme","resolvePreset","useMemo","jsx","jsxs","MuiDrawer","Box","IconButton","Typography","Tooltip"],"mappings":";;;;;;;;;AAcO,MAAM,gBAAgBA,MAAAA,cAAyC,IAAI;AAOnE,SAAS,mBAAuC;AACrD,QAAM,MAAMC,MAAAA,WAAW,aAAa;AACpC,MAAI,IAAK,QAAO;AAChB,SAAO,EAAE,WAAW,OAAO,OAAO,IAAA;AACpC;ACXO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA,qBAAqB;AACvB,GAAsC;AACpC,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,YAAY,CAAC,UACX,MAAM,YAAY,OAAO,SAAS;AAAA,MAChC,QAAQ,MAAM,YAAY,OAAO;AAAA,MACjC,UAAU;AAAA,IAAA,CACX;AAAA,IACH,sBAAsB;AAAA,MACpB;AAAA,MACA,WAAW;AAAA,MACX,WAAW;AAAA,MACX,YAAY,CAAC,UACX,MAAM,YAAY,OAAO,SAAS;AAAA,QAChC,QAAQ,MAAM,YAAY,OAAO;AAAA,QACjC,UAAU;AAAA,MAAA,CACX;AAAA,IAAA;AAAA,EACL;AAEJ;AAYO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAA0C;AACxC,SAAO,CAAC,WAAW;AAAA,IACjB,WAAW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U,QAAO,IAAI,EAAE,YAAY,GAAG,IAAI,OAAA,GAC5C,UAAA,aAAA,CACH;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAMN,MAAI,aAAa,OAAO,UAAU,UAAU;AAC1C,WACEH,+BAACM,SAAAA,WAAQ,OAAO,OAAO,WAAU,SAAQ,OAAK,MAC3C,UAAA,QAAA,CACH;AAAA,EAEJ;AAEA,SAAO;AACT;;;;;"}
|
|
1
|
+
{"version":3,"file":"Drawer.cjs","sources":["../../../src/components/Drawer/DrawerContext.ts","../../../src/components/Drawer/Drawer.sx.ts","../../../src/components/Drawer/Drawer.tsx","../../../src/components/Drawer/DrawerItem.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\n/**\n * Context interno del Drawer. Permite que los sub-componentes (DrawerItem,\n * DrawerSection, etc.) reaccionen al estado `collapsed` sin necesidad de\n * recibirlo por props explícitas.\n */\nexport interface DrawerContextValue {\n /** Si el drawer está en modo mini (solo iconos). */\n collapsed: boolean;\n /** Ancho actual del drawer (útil para sub-componentes que necesiten layout). */\n width: number;\n}\n\nexport const DrawerContext = createContext<DrawerContextValue | null>(null);\n\n/**\n * Hook para leer el estado del drawer desde cualquier sub-componente. Si se\n * llama fuera de un `<Drawer>`, devuelve valores por defecto (collapsed=false)\n * para que los items renderizados sueltos no exploten.\n */\nexport function useDrawerContext(): DrawerContextValue {\n const ctx = useContext(DrawerContext);\n if (ctx) return ctx;\n return { collapsed: false, width: 260 };\n}\n","import type { SxProps, Theme } from '@mui/material/styles';\n\nexport interface BuildDrawerSxArgs {\n /** Ancho actual del drawer (expanded o collapsed). */\n width: number;\n /** Duración de la transición de ancho en ms. */\n transitionDuration?: number;\n}\n\n/**\n * sx aplicado al root del MuiDrawer. Controla el ancho animado y el paper\n * interno. Los estilos visuales del paper (background, border) se dejan en\n * manos del theme / preset.\n */\nexport function buildDrawerSx({\n width,\n transitionDuration = 200,\n}: BuildDrawerSxArgs): SxProps<Theme> {\n return {\n width,\n flexShrink: 0,\n whiteSpace: 'nowrap',\n boxSizing: 'border-box',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n '& .MuiDrawer-paper': {\n width,\n boxSizing: 'border-box',\n overflowX: 'hidden',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n },\n };\n}\n\nexport interface BuildDrawerItemSxArgs {\n collapsed: boolean;\n active?: boolean;\n danger?: boolean;\n}\n\n/**\n * sx para un item del drawer. Centra el icono cuando está colapsado y\n * tiñe el fondo cuando el item está activo.\n */\nexport function buildDrawerItemSx({\n collapsed,\n active,\n danger,\n}: BuildDrawerItemSxArgs): SxProps<Theme> {\n return (theme) => ({\n minHeight: 44,\n px: collapsed ? 1 : 2,\n py: 1,\n mx: 1,\n my: 0.25,\n borderRadius: 1,\n display: 'flex',\n alignItems: 'center',\n justifyContent: collapsed ? 'center' : 'flex-start',\n gap: collapsed ? 0 : 1.5,\n cursor: 'pointer',\n color: danger\n ? theme.palette.error.main\n : active\n ? theme.palette.primary.main\n : theme.palette.text.primary,\n backgroundColor: active\n ? theme.palette.action.selected\n : 'transparent',\n transition: theme.transitions.create(\n ['background-color', 'color', 'padding'],\n { duration: 150 },\n ),\n '&:hover': {\n backgroundColor: danger\n ? theme.palette.error.light + '22'\n : theme.palette.action.hover,\n },\n '& .drawer-item__icon': {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n flexShrink: 0,\n minWidth: 24,\n },\n '& .drawer-item__label': {\n flex: 1,\n minWidth: 0,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n opacity: collapsed ? 0 : 1,\n width: collapsed ? 0 : 'auto',\n transition: theme.transitions.create(['opacity', 'width'], {\n duration: collapsed ? 100 : 200,\n }),\n },\n });\n}\n","import React, { useMemo, type ReactNode } from 'react';\nimport {\n Drawer as MuiDrawer,\n IconButton,\n Box,\n type DrawerProps as MuiDrawerProps,\n} from '@mui/material';\nimport {\n useTheme,\n type SxProps,\n type Theme,\n} from '@mui/material/styles';\nimport ChevronLeftIcon from '@mui/icons-material/ChevronLeft';\nimport ChevronRightIcon from '@mui/icons-material/ChevronRight';\n\nimport { DrawerContext } from './DrawerContext';\nimport { buildDrawerSx } from './Drawer.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\n\n// ── Tipos públicos ──────────────────────────────────────────────────────\nexport type DrawerVariant = 'permanent' | 'persistent' | 'temporary';\nexport type DrawerAnchor = 'left' | 'right' | 'top' | 'bottom';\n\nexport interface DrawerProps {\n /** Contenido del drawer (típicamente `<DrawerItem>`s). */\n children?: ReactNode;\n /**\n * Variante del drawer:\n * - `permanent` (default): siempre visible en desktop, soporta collapsed (mini).\n * - `persistent`: se oculta/muestra, empuja el contenido principal.\n * - `temporary`: flotante con backdrop (típico móvil).\n */\n variant?: DrawerVariant;\n /** Lado del viewport. Default: `'left'`. */\n anchor?: DrawerAnchor;\n /**\n * Estado mini (solo iconos). Solo se aplica con `variant=\"permanent\"` o\n * `\"persistent\"`. Si no se provee, el drawer está siempre expandido.\n */\n collapsed?: boolean;\n /** Callback del botón de toggle (chevron). */\n onToggleCollapse?: () => void;\n /** Estado abierto/cerrado (aplica a `temporary` y `persistent`). */\n open?: boolean;\n /** Callback de cierre (backdrop o ESC en temporary). */\n onClose?: MuiDrawerProps['onClose'];\n /** Ancho en estado expandido. Default: 260. */\n expandedWidth?: number;\n /** Ancho en estado colapsado (solo iconos). Default: 72. */\n collapsedWidth?: number;\n /** Muestra el botón chevron para toggle collapsed. Default: true si `onToggleCollapse` está definido. */\n showCollapseButton?: boolean;\n /** Contenido del header (por encima de los items). Típicamente logo/brand. */\n header?: ReactNode;\n /**\n * Logo/brand que se muestra junto al botón de toggle.\n * - Expandido: logo a la izquierda, toggle a la derecha en la misma fila.\n * - Colapsado: logo arriba centrado, toggle debajo centrado (stack vertical).\n * Siempre visible (a diferencia de `header`, que se oculta al colapsar).\n */\n logo?: ReactNode;\n /** Contenido del footer (por debajo de los items). Típicamente user profile. */\n footer?: ReactNode;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Drawer`.\n * - `\"default\"` (o ausente) = estilo built-in del paquete.\n */\n preset?: string;\n /** sx aplicado al Drawer (root). Se mergea después del preset. */\n sx?: SxProps<Theme>;\n /** sx aplicado al Paper interno. */\n paperSx?: SxProps<Theme>;\n className?: string;\n}\n\nexport function Drawer({\n children,\n variant = 'permanent',\n anchor = 'left',\n collapsed = false,\n onToggleCollapse,\n open,\n onClose,\n expandedWidth = 260,\n collapsedWidth = 72,\n showCollapseButton,\n header,\n logo,\n footer,\n preset,\n sx,\n paperSx,\n className,\n}: DrawerProps) {\n const theme = useTheme();\n const presetSx = resolvePreset('Drawer', preset, theme);\n\n // El mini-variant solo tiene sentido en permanent / persistent.\n const supportsCollapsed = variant !== 'temporary';\n const effectiveWidth =\n supportsCollapsed && collapsed ? collapsedWidth : expandedWidth;\n\n const contextValue = useMemo(\n () => ({\n collapsed: supportsCollapsed && collapsed,\n width: effectiveWidth,\n }),\n [supportsCollapsed, collapsed, effectiveWidth],\n );\n\n const rootSx: SxProps<Theme> = [\n buildDrawerSx({ width: effectiveWidth }),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ];\n\n const shouldShowToggle =\n showCollapseButton ?? (supportsCollapsed && !!onToggleCollapse);\n\n const openProp =\n variant === 'permanent'\n ? true\n : open !== undefined\n ? open\n : false;\n\n return (\n <DrawerContext.Provider value={contextValue}>\n <MuiDrawer\n variant={variant}\n anchor={anchor}\n open={openProp}\n onClose={onClose}\n className={className}\n sx={rootSx}\n PaperProps={{\n sx: paperSx,\n }}\n >\n {(logo || shouldShowToggle) && (\n <Box\n sx={{\n display: 'flex',\n flexDirection: contextValue.collapsed ? 'column' : 'row',\n alignItems: 'center',\n justifyContent: contextValue.collapsed\n ? 'center'\n : logo\n ? 'space-between'\n : 'flex-end',\n gap: contextValue.collapsed ? 0.5 : 0,\n px: contextValue.collapsed ? 1 : 2,\n py: 1,\n minHeight: 64,\n flexShrink: 0,\n }}\n >\n {logo && (\n <Box sx={{ display: 'flex', alignItems: 'center', minWidth: 0 }}>\n {logo}\n </Box>\n )}\n {shouldShowToggle && (\n <IconButton\n size=\"small\"\n onClick={onToggleCollapse}\n aria-label={collapsed ? 'Expandir menú' : 'Colapsar menú'}\n >\n {collapsed ? <ChevronRightIcon /> : <ChevronLeftIcon />}\n </IconButton>\n )}\n </Box>\n )}\n\n {header && !contextValue.collapsed && (\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n px: 2,\n py: 1.5,\n minHeight: 56,\n flexShrink: 0,\n }}\n >\n <Box sx={{ flex: 1, minWidth: 0 }}>{header}</Box>\n </Box>\n )}\n\n <Box\n component=\"nav\"\n sx={{\n flex: 1,\n overflowY: 'auto',\n overflowX: 'hidden',\n py: 1,\n }}\n >\n {children}\n </Box>\n\n {footer && (\n <Box\n sx={{\n flexShrink: 0,\n borderTop: (t) => `1px solid ${t.palette.divider}`,\n p: contextValue.collapsed ? 1 : 1.5,\n display: 'flex',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'flex-start',\n }}\n >\n {footer}\n </Box>\n )}\n </MuiDrawer>\n </DrawerContext.Provider>\n );\n}\n\nexport default Drawer;\n","import React, { type ReactNode, type MouseEvent } from 'react';\nimport { Box, Tooltip, Typography } from '@mui/material';\nimport type { SxProps, Theme } from '@mui/material/styles';\n\nimport { useDrawerContext } from './DrawerContext';\nimport { buildDrawerItemSx } from './Drawer.sx';\n\nexport interface DrawerItemProps {\n /** Icono del item. Se muestra siempre (expanded y collapsed). */\n icon?: ReactNode;\n /** Texto del item. Se oculta cuando el drawer está colapsado (muestra tooltip). */\n label: ReactNode;\n /** Handler de click. */\n onClick?: (event: MouseEvent<HTMLDivElement>) => void;\n /** Marca el item como activo (destaca color y fondo). */\n active?: boolean;\n /** Marca el item como \"destructivo\" (p.ej. cerrar sesión): color error. */\n danger?: boolean;\n /** Deshabilita click + bajo opacidad. */\n disabled?: boolean;\n /** Contenido adicional a la derecha del label (badge, count, chevron). */\n endAdornment?: ReactNode;\n /** sx override del consumer, se mergea al final. */\n sx?: SxProps<Theme>;\n className?: string;\n}\n\n/**\n * Item de un Drawer de shared-library. Lee el estado `collapsed` del\n * DrawerContext para adaptar layout y mostrar tooltip en modo mini.\n *\n * Uso típico:\n * ```tsx\n * <Drawer collapsed={collapsed} onToggleCollapse={toggle}>\n * <DrawerItem icon={<HomeIcon />} label=\"Inicio\" active />\n * <DrawerItem icon={<UserIcon />} label=\"Perfil\" />\n * </Drawer>\n * ```\n */\nexport function DrawerItem({\n icon,\n label,\n onClick,\n active = false,\n danger = false,\n disabled = false,\n endAdornment,\n sx,\n className,\n}: DrawerItemProps) {\n const { collapsed } = useDrawerContext();\n\n const baseSx = buildDrawerItemSx({ collapsed, active, danger });\n\n const mergedSx: SxProps<Theme> = [\n baseSx,\n disabled && { pointerEvents: 'none', opacity: 0.5 },\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ].filter(Boolean) as SxProps<Theme>;\n\n const content = (\n <Box\n role=\"button\"\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled}\n onClick={disabled ? undefined : onClick}\n onKeyDown={(event) => {\n if (disabled) return;\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onClick?.(event as unknown as MouseEvent<HTMLDivElement>);\n }\n }}\n className={className}\n sx={mergedSx}\n >\n {icon !== undefined && (\n <Box className=\"drawer-item__icon\" component=\"span\">\n {icon}\n </Box>\n )}\n <Typography\n component=\"span\"\n variant=\"body2\"\n className=\"drawer-item__label\"\n sx={{ fontWeight: active ? 600 : 400 }}\n >\n {label}\n </Typography>\n {!collapsed && endAdornment && (\n <Box component=\"span\" sx={{ flexShrink: 0, ml: 'auto' }}>\n {endAdornment}\n </Box>\n )}\n </Box>\n );\n\n // Cuando está colapsado, envolvemos en tooltip para revelar el label al hover.\n if (collapsed && typeof label === 'string') {\n return (\n <Tooltip title={label} placement=\"right\" arrow>\n {content}\n </Tooltip>\n );\n }\n\n return content;\n}\n\nexport default DrawerItem;\n"],"names":["createContext","useContext","useTheme","resolvePreset","useMemo","jsx","jsxs","MuiDrawer","Box","IconButton","Typography","Tooltip"],"mappings":";;;;;;;;;AAcO,MAAM,gBAAgBA,MAAAA,cAAyC,IAAI;AAOnE,SAAS,mBAAuC;AACrD,QAAM,MAAMC,MAAAA,WAAW,aAAa;AACpC,MAAI,IAAK,QAAO;AAChB,SAAO,EAAE,WAAW,OAAO,OAAO,IAAA;AACpC;ACXO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA,qBAAqB;AACvB,GAAsC;AACpC,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,YAAY,CAAC,UACX,MAAM,YAAY,OAAO,SAAS;AAAA,MAChC,QAAQ,MAAM,YAAY,OAAO;AAAA,MACjC,UAAU;AAAA,IAAA,CACX;AAAA,IACH,sBAAsB;AAAA,MACpB;AAAA,MACA,WAAW;AAAA,MACX,WAAW;AAAA,MACX,YAAY,CAAC,UACX,MAAM,YAAY,OAAO,SAAS;AAAA,QAChC,QAAQ,MAAM,YAAY,OAAO;AAAA,QACjC,UAAU;AAAA,MAAA,CACX;AAAA,IAAA;AAAA,EACL;AAEJ;AAYO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAA0C;AACxC,SAAO,CAAC,WAAW;AAAA,IACjB,WAAW;AAAA,IACX,IAAI,YAAY,IAAI;AAAA,IACpB,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,cAAc;AAAA,IACd,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB,YAAY,WAAW;AAAA,IACvC,KAAK,YAAY,IAAI;AAAA,IACrB,QAAQ;AAAA,IACR,OAAO,SACH,MAAM,QAAQ,MAAM,O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,6 +34,13 @@ export interface DrawerProps {
|
|
|
34
34
|
showCollapseButton?: boolean;
|
|
35
35
|
/** Contenido del header (por encima de los items). Típicamente logo/brand. */
|
|
36
36
|
header?: ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Logo/brand que se muestra junto al botón de toggle.
|
|
39
|
+
* - Expandido: logo a la izquierda, toggle a la derecha en la misma fila.
|
|
40
|
+
* - Colapsado: logo arriba centrado, toggle debajo centrado (stack vertical).
|
|
41
|
+
* Siempre visible (a diferencia de `header`, que se oculta al colapsar).
|
|
42
|
+
*/
|
|
43
|
+
logo?: ReactNode;
|
|
37
44
|
/** Contenido del footer (por debajo de los items). Típicamente user profile. */
|
|
38
45
|
footer?: ReactNode;
|
|
39
46
|
/**
|
|
@@ -47,5 +54,5 @@ export interface DrawerProps {
|
|
|
47
54
|
paperSx?: SxProps<Theme>;
|
|
48
55
|
className?: string;
|
|
49
56
|
}
|
|
50
|
-
export declare function Drawer({ children, variant, anchor, collapsed, onToggleCollapse, open, onClose, expandedWidth, collapsedWidth, showCollapseButton, header, footer, preset, sx, paperSx, className, }: DrawerProps): import("react/jsx-runtime").JSX.Element;
|
|
57
|
+
export declare function Drawer({ children, variant, anchor, collapsed, onToggleCollapse, open, onClose, expandedWidth, collapsedWidth, showCollapseButton, header, logo, footer, preset, sx, paperSx, className, }: DrawerProps): import("react/jsx-runtime").JSX.Element;
|
|
51
58
|
export default Drawer;
|
|
@@ -94,6 +94,7 @@ function Drawer({
|
|
|
94
94
|
collapsedWidth = 72,
|
|
95
95
|
showCollapseButton,
|
|
96
96
|
header,
|
|
97
|
+
logo,
|
|
97
98
|
footer,
|
|
98
99
|
preset,
|
|
99
100
|
sx,
|
|
@@ -131,20 +132,22 @@ function Drawer({
|
|
|
131
132
|
sx: paperSx
|
|
132
133
|
},
|
|
133
134
|
children: [
|
|
134
|
-
|
|
135
|
+
(logo || shouldShowToggle) && /* @__PURE__ */ jsxs(
|
|
135
136
|
Box,
|
|
136
137
|
{
|
|
137
138
|
sx: {
|
|
138
139
|
display: "flex",
|
|
140
|
+
flexDirection: contextValue.collapsed ? "column" : "row",
|
|
139
141
|
alignItems: "center",
|
|
140
|
-
justifyContent: contextValue.collapsed ? "center" : "space-between",
|
|
142
|
+
justifyContent: contextValue.collapsed ? "center" : logo ? "space-between" : "flex-end",
|
|
143
|
+
gap: contextValue.collapsed ? 0.5 : 0,
|
|
141
144
|
px: contextValue.collapsed ? 1 : 2,
|
|
142
|
-
py: 1
|
|
145
|
+
py: 1,
|
|
143
146
|
minHeight: 64,
|
|
144
147
|
flexShrink: 0
|
|
145
148
|
},
|
|
146
149
|
children: [
|
|
147
|
-
|
|
150
|
+
logo && /* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "center", minWidth: 0 }, children: logo }),
|
|
148
151
|
shouldShowToggle && /* @__PURE__ */ jsx(
|
|
149
152
|
IconButton,
|
|
150
153
|
{
|
|
@@ -157,24 +160,18 @@ function Drawer({
|
|
|
157
160
|
]
|
|
158
161
|
}
|
|
159
162
|
),
|
|
160
|
-
|
|
163
|
+
header && !contextValue.collapsed && /* @__PURE__ */ jsx(
|
|
161
164
|
Box,
|
|
162
165
|
{
|
|
163
166
|
sx: {
|
|
164
167
|
display: "flex",
|
|
165
|
-
|
|
166
|
-
px:
|
|
167
|
-
py: 1
|
|
168
|
+
alignItems: "center",
|
|
169
|
+
px: 2,
|
|
170
|
+
py: 1.5,
|
|
171
|
+
minHeight: 56,
|
|
172
|
+
flexShrink: 0
|
|
168
173
|
},
|
|
169
|
-
children: /* @__PURE__ */ jsx(
|
|
170
|
-
IconButton,
|
|
171
|
-
{
|
|
172
|
-
size: "small",
|
|
173
|
-
onClick: onToggleCollapse,
|
|
174
|
-
"aria-label": collapsed ? "Expandir menú" : "Colapsar menú",
|
|
175
|
-
children: collapsed ? /* @__PURE__ */ jsx(ChevronRightIcon, {}) : /* @__PURE__ */ jsx(ChevronLeftIcon, {})
|
|
176
|
-
}
|
|
177
|
-
)
|
|
174
|
+
children: /* @__PURE__ */ jsx(Box, { sx: { flex: 1, minWidth: 0 }, children: header })
|
|
178
175
|
}
|
|
179
176
|
),
|
|
180
177
|
/* @__PURE__ */ jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.js","sources":["../../../src/components/Drawer/DrawerContext.ts","../../../src/components/Drawer/Drawer.sx.ts","../../../src/components/Drawer/Drawer.tsx","../../../src/components/Drawer/DrawerItem.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\n/**\n * Context interno del Drawer. Permite que los sub-componentes (DrawerItem,\n * DrawerSection, etc.) reaccionen al estado `collapsed` sin necesidad de\n * recibirlo por props explícitas.\n */\nexport interface DrawerContextValue {\n /** Si el drawer está en modo mini (solo iconos). */\n collapsed: boolean;\n /** Ancho actual del drawer (útil para sub-componentes que necesiten layout). */\n width: number;\n}\n\nexport const DrawerContext = createContext<DrawerContextValue | null>(null);\n\n/**\n * Hook para leer el estado del drawer desde cualquier sub-componente. Si se\n * llama fuera de un `<Drawer>`, devuelve valores por defecto (collapsed=false)\n * para que los items renderizados sueltos no exploten.\n */\nexport function useDrawerContext(): DrawerContextValue {\n const ctx = useContext(DrawerContext);\n if (ctx) return ctx;\n return { collapsed: false, width: 260 };\n}\n","import type { SxProps, Theme } from '@mui/material/styles';\n\nexport interface BuildDrawerSxArgs {\n /** Ancho actual del drawer (expanded o collapsed). */\n width: number;\n /** Duración de la transición de ancho en ms. */\n transitionDuration?: number;\n}\n\n/**\n * sx aplicado al root del MuiDrawer. Controla el ancho animado y el paper\n * interno. Los estilos visuales del paper (background, border) se dejan en\n * manos del theme / preset.\n */\nexport function buildDrawerSx({\n width,\n transitionDuration = 200,\n}: BuildDrawerSxArgs): SxProps<Theme> {\n return {\n width,\n flexShrink: 0,\n whiteSpace: 'nowrap',\n boxSizing: 'border-box',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n '& .MuiDrawer-paper': {\n width,\n boxSizing: 'border-box',\n overflowX: 'hidden',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n },\n };\n}\n\nexport interface BuildDrawerItemSxArgs {\n collapsed: boolean;\n active?: boolean;\n danger?: boolean;\n}\n\n/**\n * sx para un item del drawer. Centra el icono cuando está colapsado y\n * tiñe el fondo cuando el item está activo.\n */\nexport function buildDrawerItemSx({\n collapsed,\n active,\n danger,\n}: BuildDrawerItemSxArgs): SxProps<Theme> {\n return (theme) => ({\n minHeight: 44,\n px: collapsed ? 1 : 2,\n py: 1,\n mx: 1,\n my: 0.25,\n borderRadius: 1,\n display: 'flex',\n alignItems: 'center',\n justifyContent: collapsed ? 'center' : 'flex-start',\n gap: collapsed ? 0 : 1.5,\n cursor: 'pointer',\n color: danger\n ? theme.palette.error.main\n : active\n ? theme.palette.primary.main\n : theme.palette.text.primary,\n backgroundColor: active\n ? theme.palette.action.selected\n : 'transparent',\n transition: theme.transitions.create(\n ['background-color', 'color', 'padding'],\n { duration: 150 },\n ),\n '&:hover': {\n backgroundColor: danger\n ? theme.palette.error.light + '22'\n : theme.palette.action.hover,\n },\n '& .drawer-item__icon': {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n flexShrink: 0,\n minWidth: 24,\n },\n '& .drawer-item__label': {\n flex: 1,\n minWidth: 0,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n opacity: collapsed ? 0 : 1,\n width: collapsed ? 0 : 'auto',\n transition: theme.transitions.create(['opacity', 'width'], {\n duration: collapsed ? 100 : 200,\n }),\n },\n });\n}\n","import React, { useMemo, type ReactNode } from 'react';\nimport {\n Drawer as MuiDrawer,\n IconButton,\n Box,\n type DrawerProps as MuiDrawerProps,\n} from '@mui/material';\nimport {\n useTheme,\n type SxProps,\n type Theme,\n} from '@mui/material/styles';\nimport ChevronLeftIcon from '@mui/icons-material/ChevronLeft';\nimport ChevronRightIcon from '@mui/icons-material/ChevronRight';\n\nimport { DrawerContext } from './DrawerContext';\nimport { buildDrawerSx } from './Drawer.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\n\n// ── Tipos públicos ──────────────────────────────────────────────────────\nexport type DrawerVariant = 'permanent' | 'persistent' | 'temporary';\nexport type DrawerAnchor = 'left' | 'right' | 'top' | 'bottom';\n\nexport interface DrawerProps {\n /** Contenido del drawer (típicamente `<DrawerItem>`s). */\n children?: ReactNode;\n /**\n * Variante del drawer:\n * - `permanent` (default): siempre visible en desktop, soporta collapsed (mini).\n * - `persistent`: se oculta/muestra, empuja el contenido principal.\n * - `temporary`: flotante con backdrop (típico móvil).\n */\n variant?: DrawerVariant;\n /** Lado del viewport. Default: `'left'`. */\n anchor?: DrawerAnchor;\n /**\n * Estado mini (solo iconos). Solo se aplica con `variant=\"permanent\"` o\n * `\"persistent\"`. Si no se provee, el drawer está siempre expandido.\n */\n collapsed?: boolean;\n /** Callback del botón de toggle (chevron). */\n onToggleCollapse?: () => void;\n /** Estado abierto/cerrado (aplica a `temporary` y `persistent`). */\n open?: boolean;\n /** Callback de cierre (backdrop o ESC en temporary). */\n onClose?: MuiDrawerProps['onClose'];\n /** Ancho en estado expandido. Default: 260. */\n expandedWidth?: number;\n /** Ancho en estado colapsado (solo iconos). Default: 72. */\n collapsedWidth?: number;\n /** Muestra el botón chevron para toggle collapsed. Default: true si `onToggleCollapse` está definido. */\n showCollapseButton?: boolean;\n /** Contenido del header (por encima de los items). Típicamente logo/brand. */\n header?: ReactNode;\n /** Contenido del footer (por debajo de los items). Típicamente user profile. */\n footer?: ReactNode;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Drawer`.\n * - `\"default\"` (o ausente) = estilo built-in del paquete.\n */\n preset?: string;\n /** sx aplicado al Drawer (root). Se mergea después del preset. */\n sx?: SxProps<Theme>;\n /** sx aplicado al Paper interno. */\n paperSx?: SxProps<Theme>;\n className?: string;\n}\n\nexport function Drawer({\n children,\n variant = 'permanent',\n anchor = 'left',\n collapsed = false,\n onToggleCollapse,\n open,\n onClose,\n expandedWidth = 260,\n collapsedWidth = 72,\n showCollapseButton,\n header,\n footer,\n preset,\n sx,\n paperSx,\n className,\n}: DrawerProps) {\n const theme = useTheme();\n const presetSx = resolvePreset('Drawer', preset, theme);\n\n // El mini-variant solo tiene sentido en permanent / persistent.\n const supportsCollapsed = variant !== 'temporary';\n const effectiveWidth =\n supportsCollapsed && collapsed ? collapsedWidth : expandedWidth;\n\n const contextValue = useMemo(\n () => ({\n collapsed: supportsCollapsed && collapsed,\n width: effectiveWidth,\n }),\n [supportsCollapsed, collapsed, effectiveWidth],\n );\n\n const rootSx: SxProps<Theme> = [\n buildDrawerSx({ width: effectiveWidth }),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ];\n\n const shouldShowToggle =\n showCollapseButton ?? (supportsCollapsed && !!onToggleCollapse);\n\n const openProp =\n variant === 'permanent'\n ? true\n : open !== undefined\n ? open\n : false;\n\n return (\n <DrawerContext.Provider value={contextValue}>\n <MuiDrawer\n variant={variant}\n anchor={anchor}\n open={openProp}\n onClose={onClose}\n className={className}\n sx={rootSx}\n PaperProps={{\n sx: paperSx,\n }}\n >\n {header && (\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'space-between',\n px: contextValue.collapsed ? 1 : 2,\n py: 1.5,\n minHeight: 64,\n flexShrink: 0,\n }}\n >\n {!contextValue.collapsed && (\n <Box sx={{ flex: 1, minWidth: 0 }}>{header}</Box>\n )}\n {shouldShowToggle && (\n <IconButton\n size=\"small\"\n onClick={onToggleCollapse}\n aria-label={collapsed ? 'Expandir menú' : 'Colapsar menú'}\n >\n {collapsed ? <ChevronRightIcon /> : <ChevronLeftIcon />}\n </IconButton>\n )}\n </Box>\n )}\n\n {!header && shouldShowToggle && (\n <Box\n sx={{\n display: 'flex',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'flex-end',\n px: 1,\n py: 1,\n }}\n >\n <IconButton\n size=\"small\"\n onClick={onToggleCollapse}\n aria-label={collapsed ? 'Expandir menú' : 'Colapsar menú'}\n >\n {collapsed ? <ChevronRightIcon /> : <ChevronLeftIcon />}\n </IconButton>\n </Box>\n )}\n\n <Box\n component=\"nav\"\n sx={{\n flex: 1,\n overflowY: 'auto',\n overflowX: 'hidden',\n py: 1,\n }}\n >\n {children}\n </Box>\n\n {footer && (\n <Box\n sx={{\n flexShrink: 0,\n borderTop: (t) => `1px solid ${t.palette.divider}`,\n p: contextValue.collapsed ? 1 : 1.5,\n display: 'flex',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'flex-start',\n }}\n >\n {footer}\n </Box>\n )}\n </MuiDrawer>\n </DrawerContext.Provider>\n );\n}\n\nexport default Drawer;\n","import React, { type ReactNode, type MouseEvent } from 'react';\nimport { Box, Tooltip, Typography } from '@mui/material';\nimport type { SxProps, Theme } from '@mui/material/styles';\n\nimport { useDrawerContext } from './DrawerContext';\nimport { buildDrawerItemSx } from './Drawer.sx';\n\nexport interface DrawerItemProps {\n /** Icono del item. Se muestra siempre (expanded y collapsed). */\n icon?: ReactNode;\n /** Texto del item. Se oculta cuando el drawer está colapsado (muestra tooltip). */\n label: ReactNode;\n /** Handler de click. */\n onClick?: (event: MouseEvent<HTMLDivElement>) => void;\n /** Marca el item como activo (destaca color y fondo). */\n active?: boolean;\n /** Marca el item como \"destructivo\" (p.ej. cerrar sesión): color error. */\n danger?: boolean;\n /** Deshabilita click + bajo opacidad. */\n disabled?: boolean;\n /** Contenido adicional a la derecha del label (badge, count, chevron). */\n endAdornment?: ReactNode;\n /** sx override del consumer, se mergea al final. */\n sx?: SxProps<Theme>;\n className?: string;\n}\n\n/**\n * Item de un Drawer de shared-library. Lee el estado `collapsed` del\n * DrawerContext para adaptar layout y mostrar tooltip en modo mini.\n *\n * Uso típico:\n * ```tsx\n * <Drawer collapsed={collapsed} onToggleCollapse={toggle}>\n * <DrawerItem icon={<HomeIcon />} label=\"Inicio\" active />\n * <DrawerItem icon={<UserIcon />} label=\"Perfil\" />\n * </Drawer>\n * ```\n */\nexport function DrawerItem({\n icon,\n label,\n onClick,\n active = false,\n danger = false,\n disabled = false,\n endAdornment,\n sx,\n className,\n}: DrawerItemProps) {\n const { collapsed } = useDrawerContext();\n\n const baseSx = buildDrawerItemSx({ collapsed, active, danger });\n\n const mergedSx: SxProps<Theme> = [\n baseSx,\n disabled && { pointerEvents: 'none', opacity: 0.5 },\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ].filter(Boolean) as SxProps<Theme>;\n\n const content = (\n <Box\n role=\"button\"\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled}\n onClick={disabled ? undefined : onClick}\n onKeyDown={(event) => {\n if (disabled) return;\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onClick?.(event as unknown as MouseEvent<HTMLDivElement>);\n }\n }}\n className={className}\n sx={mergedSx}\n >\n {icon !== undefined && (\n <Box className=\"drawer-item__icon\" component=\"span\">\n {icon}\n </Box>\n )}\n <Typography\n component=\"span\"\n variant=\"body2\"\n className=\"drawer-item__label\"\n sx={{ fontWeight: active ? 600 : 400 }}\n >\n {label}\n </Typography>\n {!collapsed && endAdornment && (\n <Box component=\"span\" sx={{ flexShrink: 0, ml: 'auto' }}>\n {endAdornment}\n </Box>\n )}\n </Box>\n );\n\n // Cuando está colapsado, envolvemos en tooltip para revelar el label al hover.\n if (collapsed && typeof label === 'string') {\n return (\n <Tooltip title={label} placement=\"right\" arrow>\n {content}\n </Tooltip>\n );\n }\n\n return content;\n}\n\nexport default DrawerItem;\n"],"names":["MuiDrawer"],"mappings":";;;;;;;AAcO,MAAM,gBAAgB,cAAyC,IAAI;AAOnE,SAAS,mBAAuC;AACrD,QAAM,MAAM,WAAW,aAAa;AACpC,MAAI,IAAK,QAAO;AAChB,SAAO,EAAE,WAAW,OAAO,OAAO,IAAA;AACpC;ACXO,SAAS,cAA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A,MAEH,UAAA;AAAA,QAAA,SAAS,UACR,oBAAC,KAAA,EAAI,WAAU,qBAAoB,WAAU,QAC1C,UAAA,KAAA,CACH;AAAA,QAEF;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAU;AAAA,YACV,SAAQ;AAAA,YACR,WAAU;AAAA,YACV,IAAI,EAAE,YAAY,SAAS,MAAM,IAAA;AAAA,YAEhC,UAAA;AAAA,UAAA;AAAA,QAAA;AAAA,QAEF,CAAC,aAAa,gBACb,oBAAC,OAAI,WAAU,QAAO,IAAI,EAAE,YAAY,GAAG,IAAI,OAAA,GAC5C,UAAA,aAAA,CACH;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAMN,MAAI,aAAa,OAAO,UAAU,UAAU;AAC1C,WACE,oBAAC,WAAQ,OAAO,OAAO,WAAU,SAAQ,OAAK,MAC3C,UAAA,QAAA,CACH;AAAA,EAEJ;AAEA,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"Drawer.js","sources":["../../../src/components/Drawer/DrawerContext.ts","../../../src/components/Drawer/Drawer.sx.ts","../../../src/components/Drawer/Drawer.tsx","../../../src/components/Drawer/DrawerItem.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\n/**\n * Context interno del Drawer. Permite que los sub-componentes (DrawerItem,\n * DrawerSection, etc.) reaccionen al estado `collapsed` sin necesidad de\n * recibirlo por props explícitas.\n */\nexport interface DrawerContextValue {\n /** Si el drawer está en modo mini (solo iconos). */\n collapsed: boolean;\n /** Ancho actual del drawer (útil para sub-componentes que necesiten layout). */\n width: number;\n}\n\nexport const DrawerContext = createContext<DrawerContextValue | null>(null);\n\n/**\n * Hook para leer el estado del drawer desde cualquier sub-componente. Si se\n * llama fuera de un `<Drawer>`, devuelve valores por defecto (collapsed=false)\n * para que los items renderizados sueltos no exploten.\n */\nexport function useDrawerContext(): DrawerContextValue {\n const ctx = useContext(DrawerContext);\n if (ctx) return ctx;\n return { collapsed: false, width: 260 };\n}\n","import type { SxProps, Theme } from '@mui/material/styles';\n\nexport interface BuildDrawerSxArgs {\n /** Ancho actual del drawer (expanded o collapsed). */\n width: number;\n /** Duración de la transición de ancho en ms. */\n transitionDuration?: number;\n}\n\n/**\n * sx aplicado al root del MuiDrawer. Controla el ancho animado y el paper\n * interno. Los estilos visuales del paper (background, border) se dejan en\n * manos del theme / preset.\n */\nexport function buildDrawerSx({\n width,\n transitionDuration = 200,\n}: BuildDrawerSxArgs): SxProps<Theme> {\n return {\n width,\n flexShrink: 0,\n whiteSpace: 'nowrap',\n boxSizing: 'border-box',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n '& .MuiDrawer-paper': {\n width,\n boxSizing: 'border-box',\n overflowX: 'hidden',\n transition: (theme) =>\n theme.transitions.create('width', {\n easing: theme.transitions.easing.sharp,\n duration: transitionDuration,\n }),\n },\n };\n}\n\nexport interface BuildDrawerItemSxArgs {\n collapsed: boolean;\n active?: boolean;\n danger?: boolean;\n}\n\n/**\n * sx para un item del drawer. Centra el icono cuando está colapsado y\n * tiñe el fondo cuando el item está activo.\n */\nexport function buildDrawerItemSx({\n collapsed,\n active,\n danger,\n}: BuildDrawerItemSxArgs): SxProps<Theme> {\n return (theme) => ({\n minHeight: 44,\n px: collapsed ? 1 : 2,\n py: 1,\n mx: 1,\n my: 0.25,\n borderRadius: 1,\n display: 'flex',\n alignItems: 'center',\n justifyContent: collapsed ? 'center' : 'flex-start',\n gap: collapsed ? 0 : 1.5,\n cursor: 'pointer',\n color: danger\n ? theme.palette.error.main\n : active\n ? theme.palette.primary.main\n : theme.palette.text.primary,\n backgroundColor: active\n ? theme.palette.action.selected\n : 'transparent',\n transition: theme.transitions.create(\n ['background-color', 'color', 'padding'],\n { duration: 150 },\n ),\n '&:hover': {\n backgroundColor: danger\n ? theme.palette.error.light + '22'\n : theme.palette.action.hover,\n },\n '& .drawer-item__icon': {\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n flexShrink: 0,\n minWidth: 24,\n },\n '& .drawer-item__label': {\n flex: 1,\n minWidth: 0,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n opacity: collapsed ? 0 : 1,\n width: collapsed ? 0 : 'auto',\n transition: theme.transitions.create(['opacity', 'width'], {\n duration: collapsed ? 100 : 200,\n }),\n },\n });\n}\n","import React, { useMemo, type ReactNode } from 'react';\nimport {\n Drawer as MuiDrawer,\n IconButton,\n Box,\n type DrawerProps as MuiDrawerProps,\n} from '@mui/material';\nimport {\n useTheme,\n type SxProps,\n type Theme,\n} from '@mui/material/styles';\nimport ChevronLeftIcon from '@mui/icons-material/ChevronLeft';\nimport ChevronRightIcon from '@mui/icons-material/ChevronRight';\n\nimport { DrawerContext } from './DrawerContext';\nimport { buildDrawerSx } from './Drawer.sx';\nimport { resolvePreset } from '../_shared/resolvePreset';\n\n// ── Tipos públicos ──────────────────────────────────────────────────────\nexport type DrawerVariant = 'permanent' | 'persistent' | 'temporary';\nexport type DrawerAnchor = 'left' | 'right' | 'top' | 'bottom';\n\nexport interface DrawerProps {\n /** Contenido del drawer (típicamente `<DrawerItem>`s). */\n children?: ReactNode;\n /**\n * Variante del drawer:\n * - `permanent` (default): siempre visible en desktop, soporta collapsed (mini).\n * - `persistent`: se oculta/muestra, empuja el contenido principal.\n * - `temporary`: flotante con backdrop (típico móvil).\n */\n variant?: DrawerVariant;\n /** Lado del viewport. Default: `'left'`. */\n anchor?: DrawerAnchor;\n /**\n * Estado mini (solo iconos). Solo se aplica con `variant=\"permanent\"` o\n * `\"persistent\"`. Si no se provee, el drawer está siempre expandido.\n */\n collapsed?: boolean;\n /** Callback del botón de toggle (chevron). */\n onToggleCollapse?: () => void;\n /** Estado abierto/cerrado (aplica a `temporary` y `persistent`). */\n open?: boolean;\n /** Callback de cierre (backdrop o ESC en temporary). */\n onClose?: MuiDrawerProps['onClose'];\n /** Ancho en estado expandido. Default: 260. */\n expandedWidth?: number;\n /** Ancho en estado colapsado (solo iconos). Default: 72. */\n collapsedWidth?: number;\n /** Muestra el botón chevron para toggle collapsed. Default: true si `onToggleCollapse` está definido. */\n showCollapseButton?: boolean;\n /** Contenido del header (por encima de los items). Típicamente logo/brand. */\n header?: ReactNode;\n /**\n * Logo/brand que se muestra junto al botón de toggle.\n * - Expandido: logo a la izquierda, toggle a la derecha en la misma fila.\n * - Colapsado: logo arriba centrado, toggle debajo centrado (stack vertical).\n * Siempre visible (a diferencia de `header`, que se oculta al colapsar).\n */\n logo?: ReactNode;\n /** Contenido del footer (por debajo de los items). Típicamente user profile. */\n footer?: ReactNode;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Drawer`.\n * - `\"default\"` (o ausente) = estilo built-in del paquete.\n */\n preset?: string;\n /** sx aplicado al Drawer (root). Se mergea después del preset. */\n sx?: SxProps<Theme>;\n /** sx aplicado al Paper interno. */\n paperSx?: SxProps<Theme>;\n className?: string;\n}\n\nexport function Drawer({\n children,\n variant = 'permanent',\n anchor = 'left',\n collapsed = false,\n onToggleCollapse,\n open,\n onClose,\n expandedWidth = 260,\n collapsedWidth = 72,\n showCollapseButton,\n header,\n logo,\n footer,\n preset,\n sx,\n paperSx,\n className,\n}: DrawerProps) {\n const theme = useTheme();\n const presetSx = resolvePreset('Drawer', preset, theme);\n\n // El mini-variant solo tiene sentido en permanent / persistent.\n const supportsCollapsed = variant !== 'temporary';\n const effectiveWidth =\n supportsCollapsed && collapsed ? collapsedWidth : expandedWidth;\n\n const contextValue = useMemo(\n () => ({\n collapsed: supportsCollapsed && collapsed,\n width: effectiveWidth,\n }),\n [supportsCollapsed, collapsed, effectiveWidth],\n );\n\n const rootSx: SxProps<Theme> = [\n buildDrawerSx({ width: effectiveWidth }),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ];\n\n const shouldShowToggle =\n showCollapseButton ?? (supportsCollapsed && !!onToggleCollapse);\n\n const openProp =\n variant === 'permanent'\n ? true\n : open !== undefined\n ? open\n : false;\n\n return (\n <DrawerContext.Provider value={contextValue}>\n <MuiDrawer\n variant={variant}\n anchor={anchor}\n open={openProp}\n onClose={onClose}\n className={className}\n sx={rootSx}\n PaperProps={{\n sx: paperSx,\n }}\n >\n {(logo || shouldShowToggle) && (\n <Box\n sx={{\n display: 'flex',\n flexDirection: contextValue.collapsed ? 'column' : 'row',\n alignItems: 'center',\n justifyContent: contextValue.collapsed\n ? 'center'\n : logo\n ? 'space-between'\n : 'flex-end',\n gap: contextValue.collapsed ? 0.5 : 0,\n px: contextValue.collapsed ? 1 : 2,\n py: 1,\n minHeight: 64,\n flexShrink: 0,\n }}\n >\n {logo && (\n <Box sx={{ display: 'flex', alignItems: 'center', minWidth: 0 }}>\n {logo}\n </Box>\n )}\n {shouldShowToggle && (\n <IconButton\n size=\"small\"\n onClick={onToggleCollapse}\n aria-label={collapsed ? 'Expandir menú' : 'Colapsar menú'}\n >\n {collapsed ? <ChevronRightIcon /> : <ChevronLeftIcon />}\n </IconButton>\n )}\n </Box>\n )}\n\n {header && !contextValue.collapsed && (\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n px: 2,\n py: 1.5,\n minHeight: 56,\n flexShrink: 0,\n }}\n >\n <Box sx={{ flex: 1, minWidth: 0 }}>{header}</Box>\n </Box>\n )}\n\n <Box\n component=\"nav\"\n sx={{\n flex: 1,\n overflowY: 'auto',\n overflowX: 'hidden',\n py: 1,\n }}\n >\n {children}\n </Box>\n\n {footer && (\n <Box\n sx={{\n flexShrink: 0,\n borderTop: (t) => `1px solid ${t.palette.divider}`,\n p: contextValue.collapsed ? 1 : 1.5,\n display: 'flex',\n justifyContent: contextValue.collapsed\n ? 'center'\n : 'flex-start',\n }}\n >\n {footer}\n </Box>\n )}\n </MuiDrawer>\n </DrawerContext.Provider>\n );\n}\n\nexport default Drawer;\n","import React, { type ReactNode, type MouseEvent } from 'react';\nimport { Box, Tooltip, Typography } from '@mui/material';\nimport type { SxProps, Theme } from '@mui/material/styles';\n\nimport { useDrawerContext } from './DrawerContext';\nimport { buildDrawerItemSx } from './Drawer.sx';\n\nexport interface DrawerItemProps {\n /** Icono del item. Se muestra siempre (expanded y collapsed). */\n icon?: ReactNode;\n /** Texto del item. Se oculta cuando el drawer está colapsado (muestra tooltip). */\n label: ReactNode;\n /** Handler de click. */\n onClick?: (event: MouseEvent<HTMLDivElement>) => void;\n /** Marca el item como activo (destaca color y fondo). */\n active?: boolean;\n /** Marca el item como \"destructivo\" (p.ej. cerrar sesión): color error. */\n danger?: boolean;\n /** Deshabilita click + bajo opacidad. */\n disabled?: boolean;\n /** Contenido adicional a la derecha del label (badge, count, chevron). */\n endAdornment?: ReactNode;\n /** sx override del consumer, se mergea al final. */\n sx?: SxProps<Theme>;\n className?: string;\n}\n\n/**\n * Item de un Drawer de shared-library. Lee el estado `collapsed` del\n * DrawerContext para adaptar layout y mostrar tooltip en modo mini.\n *\n * Uso típico:\n * ```tsx\n * <Drawer collapsed={collapsed} onToggleCollapse={toggle}>\n * <DrawerItem icon={<HomeIcon />} label=\"Inicio\" active />\n * <DrawerItem icon={<UserIcon />} label=\"Perfil\" />\n * </Drawer>\n * ```\n */\nexport function DrawerItem({\n icon,\n label,\n onClick,\n active = false,\n danger = false,\n disabled = false,\n endAdornment,\n sx,\n className,\n}: DrawerItemProps) {\n const { collapsed } = useDrawerContext();\n\n const baseSx = buildDrawerItemSx({ collapsed, active, danger });\n\n const mergedSx: SxProps<Theme> = [\n baseSx,\n disabled && { pointerEvents: 'none', opacity: 0.5 },\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ].filter(Boolean) as SxProps<Theme>;\n\n const content = (\n <Box\n role=\"button\"\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled}\n onClick={disabled ? undefined : onClick}\n onKeyDown={(event) => {\n if (disabled) return;\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault();\n onClick?.(event as unknown as MouseEvent<HTMLDivElement>);\n }\n }}\n className={className}\n sx={mergedSx}\n >\n {icon !== undefined && (\n <Box className=\"drawer-item__icon\" component=\"span\">\n {icon}\n </Box>\n )}\n <Typography\n component=\"span\"\n variant=\"body2\"\n className=\"drawer-item__label\"\n sx={{ fontWeight: active ? 600 : 400 }}\n >\n {label}\n </Typography>\n {!collapsed && endAdornment && (\n <Box component=\"span\" sx={{ flexShrink: 0, ml: 'auto' }}>\n {endAdornment}\n </Box>\n )}\n </Box>\n );\n\n // Cuando está colapsado, envolvemos en tooltip para revelar el label al hover.\n if (collapsed && typeof label === 'string') {\n return (\n <Tooltip title={label} placement=\"right\" arrow>\n {content}\n </Tooltip>\n );\n }\n\n return content;\n}\n\nexport default DrawerItem;\n"],"names":["MuiDrawer"],"mappings":";;;;;;;AAcO,MAAM,gBAAgB,cAAyC,IAAI;AAOnE,SAAS,mBAAuC;AACrD,QAAM,MAAM,WAAW,aAAa;AACpC,MAAI,IAAK,QAAO;AAChB,SAAO,EAAE,WAAW,OAAO,OAAO,IAAA;AACpC;ACXO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA,qBAAqB;AACvB,GAAsC;AACpC,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,YAAY,CAAC,UACX,MAAM,YAAY,OAAO,SAAS;AAAA,MAChC,QAAQ,MAAM,YAAY,OAAO;AAAA,MACjC,UAAU;AAAA,IAAA,CACX;AAAA,IACH,sBAAsB;AAAA,MACpB;AAAA,MACA,WAAW;AAAA,MACX,WAAW;AAAA,MACX,YAAY,CAAC,UACX,MAAM,YAAY,OAAO,SAAS;AAAA,QAChC,QAAQ,MAAM,YAAY,OAAO;AAAA,QACjC,UAAU;AAAA,MAAA,CACX;AAAA,IAAA;AAAA,EACL;AAEJ;AAYO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAA0C;AACxC,SAAO,CAAC,WAAW;AAAA,IACjB,WAAW;AAAA,IACX,IAAI,YAAY,IAAI;A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