@soyfri/shared-library 1.1.16 → 1.1.17
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,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"),i=require("@mui/material"),n=require("../../node_modules/@mui/icons-material/esm/Clear.cjs"),s=require("../../node_modules/@mui/icons-material/esm/Check.cjs"),r=require("../../node_modules/@mui/system/esm/styled/styled.cjs");function l(e){return null}l.displayName="Option";const o=r(i.Select)((({theme:e})=>({"& .MuiInputBase-root":{maxHeight:"4px",padding:"8px 10px",borderRadius:"10px",display:"flex",alignItems:"center",fontSize:"14px"},"& .MuiSelect-select":{padding:"0 !important",height:"28px !important",display:"flex",alignItems:"center",marginLeft:"8px"},"& .MuiOutlinedInput-notchedOutline":{marginBottom:"-4px !important",borderRadius:"10px"},"& .MuiSelect-icon":{top:"50%",transform:"translateY(-50%)"},"& .MuiOutlinedInput-notchedOutline > legend":{display:"none"}}))),a=r(i.InputLabel)((({theme:e})=>({"&.MuiInputLabel-root":{top:"50%",transform:"translate(14px, -50%)"},"&.MuiInputLabel-shrink":{transform:"translate(1px, -200%) scale(0.75)",fontSize:"16px","> legend":{display:"none"}},"&.MuiInputLabel-animated":{"&.MuiInputLabel-shrink":{display:"block"}}}))),u=r(i.OutlinedInput)((({theme:e})=>({"& .MuiInputBase-root":{maxHeight:"34px",padding:"8px 10px",borderRadius:"10px",display:"flex",alignItems:"center",fontSize:"14px"," & > .MuiAvatar-img":{width:"14px",height:"14px"}},"& .MuiInputBase-input":{padding:"0 !important",height:"18px",display:"flex",alignItems:"center"},"& .MuiOutlinedInput-notchedOutline":{border:"0.7px solid",borderColor:"#e0e0e0"}})));function p({label:r,options:l=[],value:p,defaultValue:d,onChange:x,size:c="medium",multiple:m=!1,filterable:h=!1,placeholder:g,children:j,maxHeight:f=300,maxWidth:b,maxChipsToShow:y=3,renderChipLabel:v,chipVariant:E="outlined",loadOptions:R,loadingMessage:M="Cargando opciones...",noOptionsMessage:I="No hay opciones",debounceTimeout:C=300,disabled:O=!1}){const S=t.useMemo((()=>{var e;if(1===t.Children.count(j)){const i=t.Children.only(j);if(t.isValidElement(i)&&"Option"===(null===(e=i.type)||void 0===e?void 0:e.displayName))return i.props.children}return null}),[j]),[_,k]=t.useState(""),[L,T]=t.useState([]),[w,z]=t.useState(!1),B=t.useRef(null),P=t.useRef(null),q="function"==typeof R,W=q?L:l;t.useEffect((()=>{q&&(B.current&&clearTimeout(B.current),_?(z(!0),B.current=window.setTimeout((()=>{R(_).then((e=>{T(e)})).finally((()=>{z(!1),P.current&&P.current.focus()}))}),C)):(T([]),z(!1),P.current&&P.current.focus()))}),[_,q,R,C]);const A=t.useMemo((()=>q?W:h&&_?W.filter((e=>e.label.toLowerCase().includes(_.toLowerCase()))):W),[_,h,W,q]),V=t.useMemo((()=>{const e={};return A.forEach((t=>{const i=t.group||"__default";e[i]||(e[i]=[]),e[i].push(t)})),e}),[A]),H=t.useMemo((()=>{const t=[];return(h||q)&&t.push(e.jsxRuntimeExports.jsx(i.ListSubheader,{sx:{px:2,pt:1,pb:1,backgroundColor:"background.paper",zIndex:1,position:"sticky",top:0},children:e.jsxRuntimeExports.jsx(i.TextField,{inputRef:P,placeholder:"Buscar...",variant:"standard",size:"small",fullWidth:!0,value:_,onChange:e=>k(e.target.value),inputProps:{autoFocus:!0},onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation()})},"search-header")),w?t.push(e.jsxRuntimeExports.jsx(i.MenuItem,{disabled:!0,children:e.jsxRuntimeExports.jsxs(i.Box,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsxRuntimeExports.jsx(i.CircularProgress,{size:20}),e.jsxRuntimeExports.jsx(i.Typography,{children:M})]})},"loading-message")):0===Object.keys(V).length||1===Object.keys(V).length&&V.__default&&0===V.__default.length?t.push(e.jsxRuntimeExports.jsx(i.MenuItem,{disabled:!0,children:e.jsxRuntimeExports.jsx(i.Typography,{children:I})},"no-options-message")):Object.entries(V).forEach((([n,r])=>{"__default"!==n&&t.push(e.jsxRuntimeExports.jsx(i.ListSubheader,{disableSticky:!0,children:n},n)),r.forEach((n=>{const r=m?null==p?void 0:p.includes(n.value):p===n.value;t.push(e.jsxRuntimeExports.jsxs(i.MenuItem,{value:n.value,disabled:n.disabled,selected:r,children:[e.jsxRuntimeExports.jsx(i.ListItemIcon,{sx:{minWidth:32},children:r&&e.jsxRuntimeExports.jsx(s,{sx:{color:"green"}})}),S?S(n):n.label]},n.value))}))})),t}),[V,S,h,q,_,w,M,I,m,p]),F=r&&!g;return e.jsxRuntimeExports.jsxs(i.FormControl,{fullWidth:!0,size:c,children:[F&&e.jsxRuntimeExports.jsx(a,{children:r}),e.jsxRuntimeExports.jsx(i.Box,{sx:{width:"100%",display:"grid",marginBottom:"10px",marginTop:"10px"},children:e.jsxRuntimeExports.jsx(o,{label:r,value:null!=p?p:m?[]:"",defaultValue:d,multiple:m,onChange:e=>{x(e.target.value)},renderValue:t=>{var s;if(!t||Array.isArray(t)&&0===t.length)return e.jsxRuntimeExports.jsx(i.Typography,{sx:{color:"text.disabled"},children:g||""});if(!m){const e=W.find((e=>e.value===t));return v&&e?v(e):null!==(s=null==e?void 0:e.label)&&void 0!==s?s:String(t)}const r=t,l=r.slice(0,y),o=r.length-y;return e.jsxRuntimeExports.jsxs(i.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:[l.map((t=>{const s=W.find((e=>e.value===t));if(!s)return null;return e.jsxRuntimeExports.jsx(i.Chip,{variant:E,color:"primary",label:v?v(s):s.label,avatar:s.img?e.jsxRuntimeExports.jsx(i.Avatar,{sx:{"& > .MuiAvatar-root, .MuiChip-avatar":{backgroundColor:"red"}},src:s.img}):void 0,onDelete:()=>(e=>{const t=p.filter((t=>t!==e));x(t)})(t),deleteIcon:e.jsxRuntimeExports.jsx(n,{sx:{fontSize:"12px !important"}}),sx:{height:"27px",marginTop:"1px"}},t)})),o>0&&e.jsxRuntimeExports.jsx(i.Chip,{sx:{height:"27px",marginTop:"0px"},label:`+${o} más`,variant:E})]})},displayEmpty:!0,input:e.jsxRuntimeExports.jsx(u,{label:r}),disabled:O,sx:{"& .InputGroupChild > .MuiOutlinedInput-notchedOutline":{border:"none !important"}},MenuProps:{PaperProps:{style:{maxHeight:f,maxWidth:b}}},children:H})})]})}exports.Option=l,exports.Select=p,exports.default=p;
|
|
2
2
|
//# sourceMappingURL=Select.cjs.map
|
|
@@ -31,6 +31,7 @@ export interface SelectProps<TValue extends SelectOption['value'] = SelectOption
|
|
|
31
31
|
loadingMessage?: React.ReactNode;
|
|
32
32
|
noOptionsMessage?: React.ReactNode;
|
|
33
33
|
debounceTimeout?: number;
|
|
34
|
+
disabled?: boolean;
|
|
34
35
|
}
|
|
35
36
|
export interface OptionProps {
|
|
36
37
|
children: RenderOptionItem;
|
|
@@ -39,5 +40,5 @@ export declare function Option(_props: OptionProps): null;
|
|
|
39
40
|
export declare namespace Option {
|
|
40
41
|
var displayName: string;
|
|
41
42
|
}
|
|
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;
|
|
43
|
+
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, disabled, }: SelectProps<TValue>): import("react/jsx-runtime").JSX.Element;
|
|
43
44
|
export default Select;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as e}from"../../_virtual/jsx-runtime.js";import t,{useMemo as n,isValidElement as i,useState as l,useRef as a,useEffect as r}from"react";import{Select as o,InputLabel as s,OutlinedInput as u,ListSubheader as
|
|
1
|
+
import{j as e}from"../../_virtual/jsx-runtime.js";import t,{useMemo as n,isValidElement as i,useState as l,useRef as a,useEffect as r}from"react";import{Select as o,InputLabel as s,OutlinedInput as u,ListSubheader as d,TextField as p,MenuItem as c,Box as x,CircularProgress as m,Typography as h,ListItemIcon as g,FormControl as f,Chip as b,Avatar as j}from"@mui/material";import y from"../../node_modules/@mui/icons-material/esm/Clear.js";import v from"../../node_modules/@mui/icons-material/esm/Check.js";import I from"../../node_modules/@mui/system/esm/styled/styled.js";function M(e){return null}M.displayName="Option";const C=I(o)((({theme:e})=>({"& .MuiInputBase-root":{maxHeight:"4px",padding:"8px 10px",borderRadius:"10px",display:"flex",alignItems:"center",fontSize:"14px"},"& .MuiSelect-select":{padding:"0 !important",height:"28px !important",display:"flex",alignItems:"center",marginLeft:"8px"},"& .MuiOutlinedInput-notchedOutline":{marginBottom:"-4px !important",borderRadius:"10px"},"& .MuiSelect-icon":{top:"50%",transform:"translateY(-50%)"},"& .MuiOutlinedInput-notchedOutline > legend":{display:"none"}}))),O=I(s)((({theme:e})=>({"&.MuiInputLabel-root":{top:"50%",transform:"translate(14px, -50%)"},"&.MuiInputLabel-shrink":{transform:"translate(1px, -200%) scale(0.75)",fontSize:"16px","> legend":{display:"none"}},"&.MuiInputLabel-animated":{"&.MuiInputLabel-shrink":{display:"block"}}}))),k=I(u)((({theme:e})=>({"& .MuiInputBase-root":{maxHeight:"34px",padding:"8px 10px",borderRadius:"10px",display:"flex",alignItems:"center",fontSize:"14px"," & > .MuiAvatar-img":{width:"14px",height:"14px"}},"& .MuiInputBase-input":{padding:"0 !important",height:"18px",display:"flex",alignItems:"center"},"& .MuiOutlinedInput-notchedOutline":{border:"0.7px solid",borderColor:"#e0e0e0"}})));function _({label:o,options:s=[],value:u,defaultValue:I,onChange:M,size:_="medium",multiple:S=!1,filterable:w=!1,placeholder:z,children:L,maxHeight:T=300,maxWidth:B,maxChipsToShow:P=3,renderChipLabel:W,chipVariant:A="outlined",loadOptions:E,loadingMessage:H="Cargando opciones...",noOptionsMessage:R="No hay opciones",debounceTimeout:V=300,disabled:N=!1}){const D=n((()=>{var e;if(1===t.Children.count(L)){const n=t.Children.only(L);if(i(n)&&"Option"===(null===(e=n.type)||void 0===e?void 0:e.displayName))return n.props.children}return null}),[L]),[F,G]=l(""),[K,Y]=l([]),[$,q]=l(!1),J=a(null),Q=a(null),U="function"==typeof E,X=U?K:s;r((()=>{U&&(J.current&&clearTimeout(J.current),F?(q(!0),J.current=window.setTimeout((()=>{E(F).then((e=>{Y(e)})).finally((()=>{q(!1),Q.current&&Q.current.focus()}))}),V)):(Y([]),q(!1),Q.current&&Q.current.focus()))}),[F,U,E,V]);const Z=n((()=>U?X:w&&F?X.filter((e=>e.label.toLowerCase().includes(F.toLowerCase()))):X),[F,w,X,U]),ee=n((()=>{const e={};return Z.forEach((t=>{const n=t.group||"__default";e[n]||(e[n]=[]),e[n].push(t)})),e}),[Z]),te=n((()=>{const t=[];return(w||U)&&t.push(e.jsx(d,{sx:{px:2,pt:1,pb:1,backgroundColor:"background.paper",zIndex:1,position:"sticky",top:0},children:e.jsx(p,{inputRef:Q,placeholder:"Buscar...",variant:"standard",size:"small",fullWidth:!0,value:F,onChange:e=>G(e.target.value),inputProps:{autoFocus:!0},onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation()})},"search-header")),$?t.push(e.jsx(c,{disabled:!0,children:e.jsxs(x,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(m,{size:20}),e.jsx(h,{children:H})]})},"loading-message")):0===Object.keys(ee).length||1===Object.keys(ee).length&&ee.__default&&0===ee.__default.length?t.push(e.jsx(c,{disabled:!0,children:e.jsx(h,{children:R})},"no-options-message")):Object.entries(ee).forEach((([n,i])=>{"__default"!==n&&t.push(e.jsx(d,{disableSticky:!0,children:n},n)),i.forEach((n=>{const i=S?null==u?void 0:u.includes(n.value):u===n.value;t.push(e.jsxs(c,{value:n.value,disabled:n.disabled,selected:i,children:[e.jsx(g,{sx:{minWidth:32},children:i&&e.jsx(v,{sx:{color:"green"}})}),D?D(n):n.label]},n.value))}))})),t}),[ee,D,w,U,F,$,H,R,S,u]),ne=o&&!z;return e.jsxs(f,{fullWidth:!0,size:_,children:[ne&&e.jsx(O,{children:o}),e.jsx(x,{sx:{width:"100%",display:"grid",marginBottom:"10px",marginTop:"10px"},children:e.jsx(C,{label:o,value:null!=u?u:S?[]:"",defaultValue:I,multiple:S,onChange:e=>{M(e.target.value)},renderValue:t=>{var n;if(!t||Array.isArray(t)&&0===t.length)return e.jsx(h,{sx:{color:"text.disabled"},children:z||""});if(!S){const e=X.find((e=>e.value===t));return W&&e?W(e):null!==(n=null==e?void 0:e.label)&&void 0!==n?n:String(t)}const i=t,l=i.slice(0,P),a=i.length-P;return e.jsxs(x,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:[l.map((t=>{const n=X.find((e=>e.value===t));if(!n)return null;return e.jsx(b,{variant:A,color:"primary",label:W?W(n):n.label,avatar:n.img?e.jsx(j,{sx:{"& > .MuiAvatar-root, .MuiChip-avatar":{backgroundColor:"red"}},src:n.img}):void 0,onDelete:()=>(e=>{const t=u.filter((t=>t!==e));M(t)})(t),deleteIcon:e.jsx(y,{sx:{fontSize:"12px !important"}}),sx:{height:"27px",marginTop:"1px"}},t)})),a>0&&e.jsx(b,{sx:{height:"27px",marginTop:"0px"},label:`+${a} más`,variant:A})]})},displayEmpty:!0,input:e.jsx(k,{label:o}),disabled:N,sx:{"& .InputGroupChild > .MuiOutlinedInput-notchedOutline":{border:"none !important"}},MenuProps:{PaperProps:{style:{maxHeight:T,maxWidth:B}}},children:te})})]})}export{M as Option,_ as Select,_ as default};
|
|
2
2
|
//# sourceMappingURL=Select.js.map
|