@soyfri/shared-library 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/components/Select/Select.cjs +1 -1
- package/cjs/components/Table/Table.cjs +1 -1
- package/esm/components/Select/Select.d.ts +6 -3
- package/esm/components/Select/Select.definitions.d.ts +1 -0
- package/esm/components/Select/Select.js +1 -1
- package/esm/components/Select/Select.stories.d.ts +1 -0
- package/esm/components/Table/Table.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/jsx-runtime.cjs"),t=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/jsx-runtime.cjs"),t=require("react"),s=require("@mui/material"),r=require("../../node_modules/@mui/icons-material/esm/Clear.cjs");function n(e){return null}function l({label:n,options:l=[],value:i,defaultValue:o,onChange:a,size:u="medium",multiple:p=!1,filterable:x=!1,placeholder:d,children:c,maxHeight:m=300,maxWidth:h,maxChipsToShow:j=3,renderChipLabel:f,chipVariant:g="outlined",loadOptions:b,loadingMessage:y="Cargando opciones...",noOptionsMessage:E="No hay opciones",debounceTimeout:v=300}){const R=t.useMemo((()=>{var e;if(1===t.Children.count(c)){const s=t.Children.only(c);if(t.isValidElement(s)&&"Option"===(null===(e=s.type)||void 0===e?void 0:e.displayName))return s.props.children}return null}),[c]),[C,_]=t.useState(""),[M,O]=t.useState([]),[S,I]=t.useState(!1),P=t.useRef(null),T=t.useRef(null),k="function"==typeof b,w=k?M:l;t.useEffect((()=>{k&&(P.current&&clearTimeout(P.current),C?(I(!0),P.current=window.setTimeout((()=>{b(C).then((e=>{O(e)})).finally((()=>{I(!1),T.current&&T.current.focus()}))}),v)):(O([]),I(!1),T.current&&T.current.focus()))}),[C,k,b,v]);const L=t.useMemo((()=>k?w:x&&C?w.filter((e=>e.label.toLowerCase().includes(C.toLowerCase()))):w),[C,x,w,k]),z=t.useMemo((()=>{const e={};return L.forEach((t=>{const s=t.group||"__default";e[s]||(e[s]=[]),e[s].push(t)})),e}),[L]),V=t.useMemo((()=>{const t=[];return(x||k)&&t.push(e.jsxRuntimeExports.jsx(s.ListSubheader,{sx:{px:2,pt:1,pb:1,backgroundColor:"background.paper",zIndex:1,position:"sticky",top:0},children:e.jsxRuntimeExports.jsx(s.TextField,{inputRef:T,placeholder:"Buscar...",variant:"standard",size:"small",fullWidth:!0,value:C,onChange:e=>_(e.target.value),inputProps:{autoFocus:!0},onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation()})},"search-header")),S?t.push(e.jsxRuntimeExports.jsx(s.MenuItem,{disabled:!0,children:e.jsxRuntimeExports.jsxs(s.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsxRuntimeExports.jsx(s.CircularProgress,{size:20}),e.jsxRuntimeExports.jsx(s.Typography,{children:y})]})},"loading-message")):0===Object.keys(z).length||1===Object.keys(z).length&&z.__default&&0===z.__default.length?t.push(e.jsxRuntimeExports.jsx(s.MenuItem,{disabled:!0,children:e.jsxRuntimeExports.jsx(s.Typography,{children:E})},"no-options-message")):Object.entries(z).forEach((([r,n])=>{"__default"!==r&&t.push(e.jsxRuntimeExports.jsx(s.ListSubheader,{disableSticky:!0,children:r},r)),n.forEach((r=>{t.push(e.jsxRuntimeExports.jsx(s.MenuItem,{value:r.value,disabled:r.disabled,children:R?R(r):r.label},r.value))}))})),t}),[z,R,x,k,C,S,y,E]);return e.jsxRuntimeExports.jsxs(s.FormControl,{fullWidth:!0,size:u,children:[n&&e.jsxRuntimeExports.jsx(s.InputLabel,{children:n}),e.jsxRuntimeExports.jsx(s.Select,{label:n,value:null!=i?i:p?[]:"",defaultValue:o,multiple:p,onChange:e=>{a(e.target.value)},renderValue:t=>{var n;if(!t||Array.isArray(t)&&0===t.length)return e.jsxRuntimeExports.jsx(s.Typography,{sx:{color:"text.disabled"},children:d||""});if(!p){const e=w.find((e=>e.value===t));return f&&e?f(e):null!==(n=null==e?void 0:e.label)&&void 0!==n?n:String(t)}const l=t,o=l.slice(0,j),u=l.length-j;return e.jsxRuntimeExports.jsxs(s.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:[o.map((t=>{const n=w.find((e=>e.value===t));if(!n)return null;return e.jsxRuntimeExports.jsx(s.Chip,{variant:g,color:"primary",label:f?f(n):n.label,avatar:n.img?e.jsxRuntimeExports.jsx(s.Avatar,{src:n.img}):void 0,onDelete:()=>(e=>{const t=i.filter((t=>t!==e));a(t)})(t),deleteIcon:e.jsxRuntimeExports.jsx(r,{})},t)})),u>0&&e.jsxRuntimeExports.jsx(s.Chip,{label:`+${u} más`,variant:g})]})},displayEmpty:!0,input:e.jsxRuntimeExports.jsx(s.OutlinedInput,{label:n}),MenuProps:{PaperProps:{style:{maxHeight:m,maxWidth:h}}},children:V})]})}n.displayName="Option",exports.Option=n,exports.Select=l,exports.default=l;
|
|
2
2
|
//# sourceMappingURL=Select.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/jsx-runtime.cjs"),t=require("react"),s=require("@mui/material"),r=require("../../node_modules/@mui/icons-material/esm/DownloadOutlined.cjs"),o=require("../../node_modules/@mui/icons-material/esm/FirstPage.cjs"),n=require("../../node_modules/@mui/icons-material/esm/LastPage.cjs"),i=require("../../node_modules/@mui/icons-material/esm/KeyboardArrowLeft.cjs"),l=require("../../node_modules/@mui/icons-material/esm/KeyboardArrowRight.cjs"),a=require("./exportsUtils.cjs"),x=require("../../node_modules/@mui/material/esm/Alert/Alert.cjs");const c=t.forwardRef((function(t,s){return e.jsxRuntimeExports.jsx(x,Object.assign({elevation:6,ref:s,variant:"filled"},t))}));function u({data:x,children:u,currentPage:p,pageSize:m,totalPages:d,previousPage:h,nextPage:j,pageSizeSelectorValue:b=10,onPageChange:E,onPageSizeChange:g,visiblePageNumbers:f=5,enableCSVExport:R=!1,csvExportFileName:y="data.csv",csvExportButtonText:C="Exportar CSV",csvExportColumns:S,enableExcelExport:v=!1,excelExportFileName:w="data.xlsx",excelExportButtonText:k="Exportar Excel",excelExportColumns:T,enableRowSelection:z=!1,rowIdentifier:I,onSelectionChange:B}){const P=t.Children.toArray(u).filter((e=>t.isValidElement(e)&&"Column"===e.type.displayName)),[q,M]=t.useState(!1),[_,A]=t.useState(""),[N,O]=t.useState("info"),[V,W]=t.useState([]);t.useEffect((()=>{W([])}),[x,p,m]),t.useEffect((()=>{null==B||B(V)}),[V,B]);const F=(e,t)=>{"clickaway"!==t&&M(!1)},D="function"==typeof E&&"number"==typeof p,[H,K]=t.useState(1),[L,G]=t.useState(b),U=D?p:H,$=D?m:L,J=(U-1)*$,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/jsx-runtime.cjs"),t=require("react"),s=require("@mui/material"),r=require("../../node_modules/@mui/icons-material/esm/DownloadOutlined.cjs"),o=require("../../node_modules/@mui/icons-material/esm/FirstPage.cjs"),n=require("../../node_modules/@mui/icons-material/esm/LastPage.cjs"),i=require("../../node_modules/@mui/icons-material/esm/KeyboardArrowLeft.cjs"),l=require("../../node_modules/@mui/icons-material/esm/KeyboardArrowRight.cjs"),a=require("./exportsUtils.cjs"),x=require("../../node_modules/@mui/material/esm/Alert/Alert.cjs");const c=t.forwardRef((function(t,s){return e.jsxRuntimeExports.jsx(x,Object.assign({elevation:6,ref:s,variant:"filled"},t))}));function u({data:x,children:u,currentPage:p,pageSize:m,totalPages:d,previousPage:h,nextPage:j,pageSizeSelectorValue:b=10,onPageChange:E,onPageSizeChange:g,visiblePageNumbers:f=5,enableCSVExport:R=!1,csvExportFileName:y="data.csv",csvExportButtonText:C="Exportar CSV",csvExportColumns:S,enableExcelExport:v=!1,excelExportFileName:w="data.xlsx",excelExportButtonText:k="Exportar Excel",excelExportColumns:T,enableRowSelection:z=!1,rowIdentifier:I,onSelectionChange:B}){const P=t.Children.toArray(u).filter((e=>t.isValidElement(e)&&"Column"===e.type.displayName)),[q,M]=t.useState(!1),[_,A]=t.useState(""),[N,O]=t.useState("info"),[V,W]=t.useState([]);t.useEffect((()=>{W([])}),[x,p,m]),t.useEffect((()=>{null==B||B(V)}),[V,B]);const F=(e,t)=>{"clickaway"!==t&&M(!1)},D="function"==typeof E&&"number"==typeof p,[H,K]=t.useState(1),[L,G]=t.useState(b),U=D?p:H,$=D?m:L,J=D?x:x.slice((U-1)*$,U*$),Q=D?d:Math.ceil(x.length/$),X=e=>{e<1||e>Q||(D?null==E||E(e):K(e))},Y=(()=>{const e=[],t=Q,s=U,r=Math.floor(f/2);let o=Math.max(1,s-r),n=Math.min(t,s+r);n-o+1<f&&(1===o?n=Math.min(t,o+f-1):n===t&&(o=Math.max(1,t-f+1)));for(let t=o;t<=n;t++)e.push(t);return e})(),Z=e=>!!I&&V.some((t=>t[I]===e[I])),ee=J.filter(Z).length,te=J.length>0&&ee===J.length,se=ee>0&&ee<J.length;return e.jsxRuntimeExports.jsxs(s.TableContainer,{component:s.Paper,sx:{borderRadius:2,overflow:"hidden"},children:[e.jsxRuntimeExports.jsxs(s.Table,{sx:{minWidth:650},"aria-label":"custom table",children:[e.jsxRuntimeExports.jsx(s.TableHead,{sx:{backgroundColor:e=>e.palette.grey[100]},children:e.jsxRuntimeExports.jsxs(s.TableRow,{children:[z&&e.jsxRuntimeExports.jsxs(s.TableCell,{padding:"checkbox",sx:{width:"50px"},children:[" ",e.jsxRuntimeExports.jsx(s.Checkbox,{color:"primary",indeterminate:se,checked:te,onChange:e=>{if(I)if(e.target.checked){const e=[...V];J.forEach((t=>{const s=t[I];e.some((e=>e[I]===s))||e.push(t)})),W(e)}else{const e=V.filter((e=>!J.some((t=>t[I]===e[I]))));W(e)}else console.warn("`rowIdentifier` prop is required for row selection.")},inputProps:{"aria-label":"select all desserts"}})]}),P.map(((t,r)=>e.jsxRuntimeExports.jsx(s.TableCell,{sx:{fontWeight:"bold",color:e=>e.palette.text.secondary,width:t.props.width||"auto",whiteSpace:"nowrap"},children:e.jsxRuntimeExports.jsx(s.Typography,{variant:"subtitle2",fontWeight:"bold",children:t.props.name})},r)))]})}),e.jsxRuntimeExports.jsxs(s.TableBody,{children:[J.map(((t,r)=>{const o=z&&Z(t);return e.jsxRuntimeExports.jsxs(s.TableRow,{sx:{"&:last-child td, &:last-child th":{border:0},"&:hover":{backgroundColor:e=>e.palette.action.hover}},selected:o,children:[z&&e.jsxRuntimeExports.jsxs(s.TableCell,{padding:"checkbox",sx:{width:"50px"},children:[" ",e.jsxRuntimeExports.jsx(s.Checkbox,{color:"primary",checked:o,onClick:e=>((e,t)=>{if(!I)return void console.warn("`rowIdentifier` prop is required for row selection.");const s=t[I],r=V.findIndex((e=>e[I]===s));let o=[];-1===r?o=o.concat(V,t):0===r?o=o.concat(V.slice(1)):r===V.length-1?o=o.concat(V.slice(0,-1)):r>0&&(o=o.concat(V.slice(0,r),V.slice(r+1))),W(o)})(0,t),inputProps:{"aria-labelledby":`table-checkbox-${r}`}})]}),P.map(((r,o)=>{const{field:n,children:i}=r.props;let l;return l=Array.isArray(n)?n.reduce(((e,s)=>(e[s]=t[s],e)),{}):{[n]:t[n]},e.jsxRuntimeExports.jsx(s.TableCell,{sx:{width:r.props.width||"auto",whiteSpace:"nowrap"},children:i(l)},o)}))]},r)})),0===J.length&&e.jsxRuntimeExports.jsx(s.TableRow,{children:e.jsxRuntimeExports.jsx(s.TableCell,{colSpan:P.length+(z?1:0),sx:{textAlign:"center",py:4},children:e.jsxRuntimeExports.jsx(s.Typography,{variant:"body2",color:"text.secondary",children:"No hay datos disponibles para mostrar."})})})]})]}),(Q>0||R||v||z&&V.length>0)&&e.jsxRuntimeExports.jsxs(s.Box,{display:"flex",justifyContent:"space-between",alignItems:"center",p:2,children:[Q>0&&e.jsxRuntimeExports.jsx(s.Select,{size:"small",value:$,onChange:e=>{return t=Number(e.target.value),void(D?(null==g||g(t),null==E||E(1)):(G(t),K(1)));var t},children:[1,2,3,5,10,20,50,100].map((t=>e.jsxRuntimeExports.jsxs(s.MenuItem,{value:t,children:["Mostrar ",t]},t)))}),Q>0&&e.jsxRuntimeExports.jsxs(s.Box,{display:"flex",alignItems:"center",gap:.5,sx:{flexGrow:1,justifyContent:"center"},children:[e.jsxRuntimeExports.jsx(s.IconButton,{onClick:()=>X(1),disabled:U<=1,size:"small",color:"primary",children:e.jsxRuntimeExports.jsx(o,{fontSize:"small"})}),e.jsxRuntimeExports.jsx(s.IconButton,{onClick:()=>X(U-1),disabled:U<=1,size:"small",color:"primary",children:e.jsxRuntimeExports.jsx(i,{fontSize:"small"})}),Y.map((t=>e.jsxRuntimeExports.jsx(s.Button,{onClick:()=>X(t),variant:U===t?"contained":"text",size:"small",sx:{minWidth:"32px",height:"32px"},children:t},t))),e.jsxRuntimeExports.jsx(s.IconButton,{onClick:()=>X(U+1),disabled:U>=Q,size:"small",color:"primary",children:e.jsxRuntimeExports.jsx(l,{fontSize:"small"})}),e.jsxRuntimeExports.jsx(s.IconButton,{onClick:()=>X(Q),disabled:U>=Q,size:"small",color:"primary",children:e.jsxRuntimeExports.jsx(n,{fontSize:"small"})})]}),z&&V.length>0&&e.jsxRuntimeExports.jsxs(s.Typography,{variant:"subtitle2",sx:{mr:2},children:[V.length," seleccionados"]}),(R||v)&&e.jsxRuntimeExports.jsxs(s.Box,{display:"flex",alignItems:"center",gap:1,children:[R&&e.jsxRuntimeExports.jsx(s.Button,{variant:"text",color:"primary",onClick:()=>a.exportToCSV({data:x,columns:P,fileName:y,exportColumns:S,setSnackbarOpen:M,setSnackbarMessage:A,setSnackbarSeverity:O}),size:"small",startIcon:e.jsxRuntimeExports.jsx(r,{}),children:C}),v&&e.jsxRuntimeExports.jsx(s.Button,{variant:"text",color:"primary",onClick:()=>a.exportToExcel({data:x,columns:P,fileName:w,exportColumns:T,setSnackbarOpen:M,setSnackbarMessage:A,setSnackbarSeverity:O}),size:"small",startIcon:e.jsxRuntimeExports.jsx(r,{}),children:k})]})]}),e.jsxRuntimeExports.jsx(s.Snackbar,{open:q,autoHideDuration:3e3,onClose:F,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:e.jsxRuntimeExports.jsx(c,{onClose:F,severity:N,sx:{width:"100%"},children:_})})]})}exports.Table=u,exports.default=u;
|
|
2
2
|
//# sourceMappingURL=Table.cjs.map
|
|
@@ -11,7 +11,7 @@ type RenderOptionItem = (item: SelectOption) => React.ReactNode;
|
|
|
11
11
|
type RenderChipLabel = (item: SelectOption) => React.ReactNode;
|
|
12
12
|
export interface SelectProps<TValue extends SelectOption['value'] = SelectOption['value']> {
|
|
13
13
|
label?: string;
|
|
14
|
-
options
|
|
14
|
+
options?: SelectOption[];
|
|
15
15
|
value?: TValue | TValue[];
|
|
16
16
|
defaultValue?: TValue | TValue[];
|
|
17
17
|
onChange: (val: TValue | TValue[]) => void;
|
|
@@ -27,6 +27,10 @@ export interface SelectProps<TValue extends SelectOption['value'] = SelectOption
|
|
|
27
27
|
maxChipsToShow?: number;
|
|
28
28
|
renderChipLabel?: RenderChipLabel;
|
|
29
29
|
chipVariant?: 'outlined' | 'filled';
|
|
30
|
+
loadOptions?: (inputValue: string) => Promise<SelectOption[]>;
|
|
31
|
+
loadingMessage?: React.ReactNode;
|
|
32
|
+
noOptionsMessage?: React.ReactNode;
|
|
33
|
+
debounceTimeout?: number;
|
|
30
34
|
}
|
|
31
35
|
export interface OptionProps {
|
|
32
36
|
children: RenderOptionItem;
|
|
@@ -35,6 +39,5 @@ export declare function Option(_props: OptionProps): null;
|
|
|
35
39
|
export declare namespace Option {
|
|
36
40
|
var displayName: string;
|
|
37
41
|
}
|
|
38
|
-
export declare function Select<TValue extends SelectOption['value'] = SelectOption['value']>({ label, options, value, defaultValue, onChange, size, multiple, filterable, placeholder, children, maxHeight, maxWidth, maxChipsToShow,
|
|
39
|
-
renderChipLabel, chipVariant, }: SelectProps<TValue>): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
export declare function Select<TValue extends SelectOption['value'] = SelectOption['value']>({ label, options, value, defaultValue, onChange, size, multiple, filterable, placeholder, children, maxHeight, maxWidth, maxChipsToShow, renderChipLabel, chipVariant, loadOptions, loadingMessage, noOptionsMessage, debounceTimeout, }: SelectProps<TValue>): import("react/jsx-runtime").JSX.Element;
|
|
40
43
|
export default Select;
|
|
@@ -11,3 +11,4 @@ export declare const ConstrainedWidthDefinition = "\nimport React, { useState }
|
|
|
11
11
|
export declare const AllFeaturesCombinedDefinition = "\nimport React, { useState } from 'react';\nimport { Select, Option } from './Select'; // Asumiendo que Select.tsx est\u00E1 en el mismo directorio\nimport { Avatar, Box, Typography, Chip } from '@mui/material';\n\nconst allOptions = [\n { value: 'gt', label: 'Guatemala', group: 'Centroam\u00E9rica' },\n { value: 'admin', label: 'Administrador', img: 'https://placehold.co/40x40?text=A' },\n { value: 'PENDING', label: 'Pendiente' },\n { value: 'ca', label: 'Canad\u00E1', group: 'Norteam\u00E9rica' },\n { value: 'user', label: 'Usuario', img: 'https://placehold.co/40x40?text=U' },\n { value: 'COMPLETED', label: 'Completado' },\n];\n\nexport const AllFeaturesCombinedExample = () => {\n const [value, setValue] = useState<string[]>(['gt', 'admin', 'PENDING', 'ca', 'user', 'COMPLETED']);\n return (\n <Box sx={{ width: 500 }}>\n <Select\n label=\"Selecci\u00F3n Completa\"\n multiple\n filterable\n maxChipsToShow={3}\n maxHeight={250}\n maxWidth=\"400px\"\n options={allOptions}\n value={value}\n onChange={(val) => setValue(val as string[])}\n placeholder=\"Busca y selecciona todo tipo de elementos\"\n renderChipLabel={(item) => (\n <Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>\n {item.img && <Avatar src={item.img} sx={{ width: 16, height: 16 }} />}\n <Typography variant=\"caption\" sx={{ fontWeight: 'bold' }}>\n {item.label.length > 10 ? item.label.substring(0, 7) + '...' : item.label}\n </Typography>\n </Box>\n )}\n >\n <Option>\n {(item) => (\n <Box sx={{ display: 'flex', alignItems: 'center', gap: 1, my: 0.5 }}>\n {item.img && <Avatar src={item.img} sx={{ width: 28, height: 28 }} />}\n <Box>\n <Typography variant=\"body2\" fontWeight=\"medium\">{item.label}</Typography>\n {item.group && (\n <Typography variant=\"caption\" color=\"text.secondary\">\n Grupo: {item.group}\n </Typography>\n )}\n {item.disabled && <Chip label=\"No disponible\" size=\"small\" color=\"warning\" sx={{ ml: 1 }} />}\n </Box>\n </Box>\n )}\n </Option>\n </Select>\n <Typography sx={{ mt: 2 }}>Valor seleccionado: {JSON.stringify(value)}</Typography>\n </Box>\n );\n};\n";
|
|
12
12
|
export declare const EmptyOptionsDefinition = "\nimport React, { useState } from 'react';\nimport { Select } from './Select'; // Asumiendo que Select.tsx est\u00E1 en el mismo directorio\nimport { Box, Typography } from '@mui/material';\n\nexport const EmptyOptionsExample = () => {\n const [value, setValue] = useState(null);\n return (\n <Box sx={{ width: 300 }}>\n <Select\n label=\"Seleccionar (Vac\u00EDo)\"\n options={[]}\n value={value}\n onChange={setValue}\n placeholder=\"No hay opciones disponibles\"\n />\n <Typography sx={{ mt: 2 }}>Valor seleccionado: {value || 'Ninguno'}</Typography>\n </Box>\n );\n};\n";
|
|
13
13
|
export declare const SelectWithManyOptionsDefinition = "\nimport React, { useState } from 'react';\nimport { Select } from './Select'; // Asumiendo que Select.tsx est\u00E1 en el mismo directorio\nimport { Box, Typography } from '@mui/material';\n\nconst manyOptions = Array.from({ length: 50 }, (_, i) => ({\n value: `option-${i}`,\n label: `Opci\u00F3n ${i + 1}`,\n group: i < 25 ? 'Grupo A' : 'Grupo B',\n}));\n\nexport const SelectWithManyOptionsExample = () => {\n const [value, setValue] = useState('');\n return (\n <Box sx={{ width: 300 }}>\n <Select\n label=\"Muchas Opciones\"\n options={manyOptions}\n value={value}\n onChange={(val) => setValue(val as string)}\n filterable\n maxHeight={200}\n />\n <Typography sx={{ mt: 2 }}>Valor seleccionado: {value}</Typography>\n </Box>\n );\n};\n";
|
|
14
|
+
export declare const AsyncSelectDefinition = "\nimport React, { useState } from 'react';\nimport { Select } from './Select';\nimport { Box, Typography } from '@mui/material';\n\nconst mockAsyncOptions = [\n { value: 'apple', label: 'Apple' },\n { value: 'banana', label: 'Banana' },\n { value: 'orange', label: 'Orange' },\n { value: 'grape', label: 'Grape' },\n { value: 'strawberry', label: 'Strawberry' },\n { value: 'blueberry', label: 'Blueberry' },\n { value: 'pineapple', label: 'Pineapple' },\n];\n\n// Simulate an API call\nconst simulatedLoadOptions = (inputValue: string): Promise<any[]> => {\n return new Promise((resolve) => {\n setTimeout(() => {\n const filtered = mockAsyncOptions.filter(option =>\n option.label.toLowerCase().includes(inputValue.toLowerCase())\n );\n resolve(filtered);\n }, 800); // Simulate network delay\n });\n};\n\nexport const AsyncSelectExample = () => {\n const [value, setValue] = useState('');\n return (\n <Box sx={{ width: 300 }}>\n <Select\n label=\"Buscar Frutas\"\n loadOptions={simulatedLoadOptions}\n value={value}\n onChange={(val) => setValue(val as string)}\n placeholder=\"Escribe para buscar...\"\n loadingMessage=\"Buscando frutas...\"\n noOptionsMessage=\"No se encontraron frutas.\"\n />\n <Typography sx={{ mt: 2 }}>Valor seleccionado: {value}</Typography>\n </Box>\n );\n};\n";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e}from"../../_virtual/jsx-runtime.js";import l,{useMemo as
|
|
1
|
+
import{j as e}from"../../_virtual/jsx-runtime.js";import l,{useMemo as n,isValidElement as r,useState as a,useRef as t,useEffect as i}from"react";import{ListSubheader as s,TextField as o,MenuItem as u,Box as d,CircularProgress as c,Typography as p,FormControl as h,InputLabel as m,Select as f,OutlinedInput as x,Chip as g,Avatar as j}from"@mui/material";import b from"../../node_modules/@mui/icons-material/esm/Clear.js";function v(e){return null}function y({label:v,options:y=[],value:C,defaultValue:_,onChange:k,size:w="medium",multiple:O=!1,filterable:P=!1,placeholder:z,children:W,maxHeight:E=300,maxWidth:S,maxChipsToShow:T=3,renderChipLabel:V,chipVariant:I="outlined",loadOptions:L,loadingMessage:M="Cargando opciones...",noOptionsMessage:N="No hay opciones",debounceTimeout:A=300}){const D=n((()=>{var e;if(1===l.Children.count(W)){const n=l.Children.only(W);if(r(n)&&"Option"===(null===(e=n.type)||void 0===e?void 0:e.displayName))return n.props.children}return null}),[W]),[H,B]=a(""),[F,K]=a([]),[R,$]=a(!1),q=t(null),G=t(null),J="function"==typeof L,Q=J?F:y;i((()=>{J&&(q.current&&clearTimeout(q.current),H?($(!0),q.current=window.setTimeout((()=>{L(H).then((e=>{K(e)})).finally((()=>{$(!1),G.current&&G.current.focus()}))}),A)):(K([]),$(!1),G.current&&G.current.focus()))}),[H,J,L,A]);const U=n((()=>J?Q:P&&H?Q.filter((e=>e.label.toLowerCase().includes(H.toLowerCase()))):Q),[H,P,Q,J]),X=n((()=>{const e={};return U.forEach((l=>{const n=l.group||"__default";e[n]||(e[n]=[]),e[n].push(l)})),e}),[U]),Y=n((()=>{const l=[];return(P||J)&&l.push(e.jsx(s,{sx:{px:2,pt:1,pb:1,backgroundColor:"background.paper",zIndex:1,position:"sticky",top:0},children:e.jsx(o,{inputRef:G,placeholder:"Buscar...",variant:"standard",size:"small",fullWidth:!0,value:H,onChange:e=>B(e.target.value),inputProps:{autoFocus:!0},onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation()})},"search-header")),R?l.push(e.jsx(u,{disabled:!0,children:e.jsxs(d,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(c,{size:20}),e.jsx(p,{children:M})]})},"loading-message")):0===Object.keys(X).length||1===Object.keys(X).length&&X.__default&&0===X.__default.length?l.push(e.jsx(u,{disabled:!0,children:e.jsx(p,{children:N})},"no-options-message")):Object.entries(X).forEach((([n,r])=>{"__default"!==n&&l.push(e.jsx(s,{disableSticky:!0,children:n},n)),r.forEach((n=>{l.push(e.jsx(u,{value:n.value,disabled:n.disabled,children:D?D(n):n.label},n.value))}))})),l}),[X,D,P,J,H,R,M,N]);return e.jsxs(h,{fullWidth:!0,size:w,children:[v&&e.jsx(m,{children:v}),e.jsx(f,{label:v,value:null!=C?C:O?[]:"",defaultValue:_,multiple:O,onChange:e=>{k(e.target.value)},renderValue:l=>{var n;if(!l||Array.isArray(l)&&0===l.length)return e.jsx(p,{sx:{color:"text.disabled"},children:z||""});if(!O){const e=Q.find((e=>e.value===l));return V&&e?V(e):null!==(n=null==e?void 0:e.label)&&void 0!==n?n:String(l)}const r=l,a=r.slice(0,T),t=r.length-T;return e.jsxs(d,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:[a.map((l=>{const n=Q.find((e=>e.value===l));if(!n)return null;return e.jsx(g,{variant:I,color:"primary",label:V?V(n):n.label,avatar:n.img?e.jsx(j,{src:n.img}):void 0,onDelete:()=>(e=>{const l=C.filter((l=>l!==e));k(l)})(l),deleteIcon:e.jsx(b,{})},l)})),t>0&&e.jsx(g,{label:`+${t} más`,variant:I})]})},displayEmpty:!0,input:e.jsx(x,{label:v}),MenuProps:{PaperProps:{style:{maxHeight:E,maxWidth:S}}},children:Y})]})}v.displayName="Option";export{v as Option,y as Select,y as default};
|
|
2
2
|
//# sourceMappingURL=Select.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e}from"../../_virtual/jsx-runtime.js";import r,{Children as t,isValidElement as o,useState as l,useEffect as s}from"react";import{TableContainer as i,Paper as a,Table as n,TableHead as c,TableRow as d,TableCell as m,Checkbox as x,Typography as p,TableBody as h,Box as u,Select as f,MenuItem as j,IconButton as g,Button as b,Snackbar as y}from"@mui/material";import v from"../../node_modules/@mui/icons-material/esm/DownloadOutlined.js";import w from"../../node_modules/@mui/icons-material/esm/FirstPage.js";import C from"../../node_modules/@mui/icons-material/esm/LastPage.js";import k from"../../node_modules/@mui/icons-material/esm/KeyboardArrowLeft.js";import S from"../../node_modules/@mui/icons-material/esm/KeyboardArrowRight.js";import{exportToCSV as z,exportToExcel as E}from"./exportsUtils.js";import P from"../../node_modules/@mui/material/esm/Alert/Alert.js";const I=r.forwardRef((function(r,t){return e.jsx(P,Object.assign({elevation:6,ref:t,variant:"filled"},r))}));function M({data:r,children:P,currentPage:M,pageSize:A,totalPages:N,previousPage:_,nextPage:O,pageSizeSelectorValue:R=10,onPageChange:W,onPageSizeChange:F,visiblePageNumbers:T=5,enableCSVExport:V=!1,csvExportFileName:q="data.csv",csvExportButtonText:B="Exportar CSV",csvExportColumns:D,enableExcelExport:K=!1,excelExportFileName:L="data.xlsx",excelExportButtonText:G="Exportar Excel",excelExportColumns:H,enableRowSelection:U=!1,rowIdentifier:$,onSelectionChange:J}){const Q=t.toArray(P).filter((e=>o(e)&&"Column"===e.type.displayName)),[X,Y]=l(!1),[Z,ee]=l(""),[re,te]=l("info"),[oe,le]=l([]);s((()=>{le([])}),[r,M,A]),s((()=>{null==J||J(oe)}),[oe,J]);const se=(e,r)=>{"clickaway"!==r&&Y(!1)},ie="function"==typeof W&&"number"==typeof M,[ae,ne]=l(1),[ce,de]=l(R),me=ie?M:ae,xe=ie?A:ce,pe=(me-1)*xe,
|
|
1
|
+
import{j as e}from"../../_virtual/jsx-runtime.js";import r,{Children as t,isValidElement as o,useState as l,useEffect as s}from"react";import{TableContainer as i,Paper as a,Table as n,TableHead as c,TableRow as d,TableCell as m,Checkbox as x,Typography as p,TableBody as h,Box as u,Select as f,MenuItem as j,IconButton as g,Button as b,Snackbar as y}from"@mui/material";import v from"../../node_modules/@mui/icons-material/esm/DownloadOutlined.js";import w from"../../node_modules/@mui/icons-material/esm/FirstPage.js";import C from"../../node_modules/@mui/icons-material/esm/LastPage.js";import k from"../../node_modules/@mui/icons-material/esm/KeyboardArrowLeft.js";import S from"../../node_modules/@mui/icons-material/esm/KeyboardArrowRight.js";import{exportToCSV as z,exportToExcel as E}from"./exportsUtils.js";import P from"../../node_modules/@mui/material/esm/Alert/Alert.js";const I=r.forwardRef((function(r,t){return e.jsx(P,Object.assign({elevation:6,ref:t,variant:"filled"},r))}));function M({data:r,children:P,currentPage:M,pageSize:A,totalPages:N,previousPage:_,nextPage:O,pageSizeSelectorValue:R=10,onPageChange:W,onPageSizeChange:F,visiblePageNumbers:T=5,enableCSVExport:V=!1,csvExportFileName:q="data.csv",csvExportButtonText:B="Exportar CSV",csvExportColumns:D,enableExcelExport:K=!1,excelExportFileName:L="data.xlsx",excelExportButtonText:G="Exportar Excel",excelExportColumns:H,enableRowSelection:U=!1,rowIdentifier:$,onSelectionChange:J}){const Q=t.toArray(P).filter((e=>o(e)&&"Column"===e.type.displayName)),[X,Y]=l(!1),[Z,ee]=l(""),[re,te]=l("info"),[oe,le]=l([]);s((()=>{le([])}),[r,M,A]),s((()=>{null==J||J(oe)}),[oe,J]);const se=(e,r)=>{"clickaway"!==r&&Y(!1)},ie="function"==typeof W&&"number"==typeof M,[ae,ne]=l(1),[ce,de]=l(R),me=ie?M:ae,xe=ie?A:ce,pe=ie?r:r.slice((me-1)*xe,me*xe),he=ie?N:Math.ceil(r.length/xe),ue=e=>{e<1||e>he||(ie?null==W||W(e):ne(e))},fe=(()=>{const e=[],r=he,t=me,o=Math.floor(T/2);let l=Math.max(1,t-o),s=Math.min(r,t+o);s-l+1<T&&(1===l?s=Math.min(r,l+T-1):s===r&&(l=Math.max(1,r-T+1)));for(let r=l;r<=s;r++)e.push(r);return e})(),je=e=>!!$&&oe.some((r=>r[$]===e[$])),ge=pe.filter(je).length,be=pe.length>0&&ge===pe.length,ye=ge>0&&ge<pe.length;return e.jsxs(i,{component:a,sx:{borderRadius:2,overflow:"hidden"},children:[e.jsxs(n,{sx:{minWidth:650},"aria-label":"custom table",children:[e.jsx(c,{sx:{backgroundColor:e=>e.palette.grey[100]},children:e.jsxs(d,{children:[U&&e.jsxs(m,{padding:"checkbox",sx:{width:"50px"},children:[" ",e.jsx(x,{color:"primary",indeterminate:ye,checked:be,onChange:e=>{if($)if(e.target.checked){const e=[...oe];pe.forEach((r=>{const t=r[$];e.some((e=>e[$]===t))||e.push(r)})),le(e)}else{const e=oe.filter((e=>!pe.some((r=>r[$]===e[$]))));le(e)}else console.warn("`rowIdentifier` prop is required for row selection.")},inputProps:{"aria-label":"select all desserts"}})]}),Q.map(((r,t)=>e.jsx(m,{sx:{fontWeight:"bold",color:e=>e.palette.text.secondary,width:r.props.width||"auto",whiteSpace:"nowrap"},children:e.jsx(p,{variant:"subtitle2",fontWeight:"bold",children:r.props.name})},t)))]})}),e.jsxs(h,{children:[pe.map(((r,t)=>{const o=U&&je(r);return e.jsxs(d,{sx:{"&:last-child td, &:last-child th":{border:0},"&:hover":{backgroundColor:e=>e.palette.action.hover}},selected:o,children:[U&&e.jsxs(m,{padding:"checkbox",sx:{width:"50px"},children:[" ",e.jsx(x,{color:"primary",checked:o,onClick:e=>((e,r)=>{if(!$)return void console.warn("`rowIdentifier` prop is required for row selection.");const t=r[$],o=oe.findIndex((e=>e[$]===t));let l=[];-1===o?l=l.concat(oe,r):0===o?l=l.concat(oe.slice(1)):o===oe.length-1?l=l.concat(oe.slice(0,-1)):o>0&&(l=l.concat(oe.slice(0,o),oe.slice(o+1))),le(l)})(0,r),inputProps:{"aria-labelledby":`table-checkbox-${t}`}})]}),Q.map(((t,o)=>{const{field:l,children:s}=t.props;let i;return i=Array.isArray(l)?l.reduce(((e,t)=>(e[t]=r[t],e)),{}):{[l]:r[l]},e.jsx(m,{sx:{width:t.props.width||"auto",whiteSpace:"nowrap"},children:s(i)},o)}))]},t)})),0===pe.length&&e.jsx(d,{children:e.jsx(m,{colSpan:Q.length+(U?1:0),sx:{textAlign:"center",py:4},children:e.jsx(p,{variant:"body2",color:"text.secondary",children:"No hay datos disponibles para mostrar."})})})]})]}),(he>0||V||K||U&&oe.length>0)&&e.jsxs(u,{display:"flex",justifyContent:"space-between",alignItems:"center",p:2,children:[he>0&&e.jsx(f,{size:"small",value:xe,onChange:e=>{return r=Number(e.target.value),void(ie?(null==F||F(r),null==W||W(1)):(de(r),ne(1)));var r},children:[1,2,3,5,10,20,50,100].map((r=>e.jsxs(j,{value:r,children:["Mostrar ",r]},r)))}),he>0&&e.jsxs(u,{display:"flex",alignItems:"center",gap:.5,sx:{flexGrow:1,justifyContent:"center"},children:[e.jsx(g,{onClick:()=>ue(1),disabled:me<=1,size:"small",color:"primary",children:e.jsx(w,{fontSize:"small"})}),e.jsx(g,{onClick:()=>ue(me-1),disabled:me<=1,size:"small",color:"primary",children:e.jsx(k,{fontSize:"small"})}),fe.map((r=>e.jsx(b,{onClick:()=>ue(r),variant:me===r?"contained":"text",size:"small",sx:{minWidth:"32px",height:"32px"},children:r},r))),e.jsx(g,{onClick:()=>ue(me+1),disabled:me>=he,size:"small",color:"primary",children:e.jsx(S,{fontSize:"small"})}),e.jsx(g,{onClick:()=>ue(he),disabled:me>=he,size:"small",color:"primary",children:e.jsx(C,{fontSize:"small"})})]}),U&&oe.length>0&&e.jsxs(p,{variant:"subtitle2",sx:{mr:2},children:[oe.length," seleccionados"]}),(V||K)&&e.jsxs(u,{display:"flex",alignItems:"center",gap:1,children:[V&&e.jsx(b,{variant:"text",color:"primary",onClick:()=>z({data:r,columns:Q,fileName:q,exportColumns:D,setSnackbarOpen:Y,setSnackbarMessage:ee,setSnackbarSeverity:te}),size:"small",startIcon:e.jsx(v,{}),children:B}),K&&e.jsx(b,{variant:"text",color:"primary",onClick:()=>E({data:r,columns:Q,fileName:L,exportColumns:H,setSnackbarOpen:Y,setSnackbarMessage:ee,setSnackbarSeverity:te}),size:"small",startIcon:e.jsx(v,{}),children:G})]})]}),e.jsx(y,{open:X,autoHideDuration:3e3,onClose:se,anchorOrigin:{vertical:"bottom",horizontal:"center"},children:e.jsx(I,{onClose:se,severity:re,sx:{width:"100%"},children:Z})})]})}export{M as Table,M as default};
|
|
2
2
|
//# sourceMappingURL=Table.js.map
|