mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 21:20:57 +00:00
2 lines
6.0 KiB
JavaScript
2 lines
6.0 KiB
JavaScript
import{r as i,j as e,B as T,aS as b,v as o,aI as v,b8 as g,aP as w}from"./index-Db-xuq0b.js";import{S as _}from"./separator-BaOOgzZX.js";import{P as N,a as k,b as S}from"./popover-X-j_SRnG.js";import{C as F,a as V,b as G,c as W,d as C,e as u,f as X}from"./command-Cr0tMDDu.js";const P=l=>l.normalize("NFKC").toLocaleLowerCase().replace(/\s+/g," ").trim(),$=i.forwardRef(({options:l=[],onValueChange:m,variant:q,defaultValue:I=[],placeholder:E="Select options",animation:H=0,maxCount:d=3,modalPopover:D=!1,asChild:J=!1,className:A,value:x,...O},K)=>{const[a,c]=i.useState(x||I),[B,p]=i.useState(!1),[Q,U]=i.useState(!1),[M,h]=i.useState(!1);i.useEffect(()=>{x!==void 0&&c(x)},[x]);const z=s=>{if(s.key==="Enter")p(!0);else if(s.key==="Backspace"&&!s.currentTarget.value){const r=[...a];r.pop(),c(r),m(r)}},L=s=>{const r=a.includes(s)?a.filter(t=>t!==s):[...a,s];c(r),m(r)},j=(s,r)=>{r.stopPropagation();const t=a.filter(n=>n!==s);c(t),m(t)},y=s=>{s.stopPropagation(),c([]),m([])},R=()=>{if(a.length===l.length)y(new MouseEvent("click"));else{const s=l?.map(r=>r.value);c(s),m(s)}};return e.jsxs(N,{open:B,onOpenChange:p,modal:D,children:[e.jsx(k,{asChild:!0,children:e.jsx(T,{ref:K,...O,className:g("flex w-full p-2 rounded-md border min-h-10 h-auto items-center justify-between bg-background hover:bg-background/90 [&_svg]:pointer-events-auto",A),children:a.length>0?e.jsxs("div",{className:"flex justify-between items-center w-full",children:[e.jsxs("div",{className:"flex flex-wrap gap-1 items-center",children:[a.slice(0,d)?.map(s=>{const r=l.find(n=>n.value===s),t=r==null?void 0:r.icon;return e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-primary/10 text-primary border border-primary/20 dark:bg-primary/20 dark:text-primary-foreground dark:border-primary/40 rounded-md",children:[t&&e.jsx(t,{className:"h-3 w-3 mr-1"}),e.jsx("span",{className:"max-w-[150px] truncate text-sm",children:r==null?void 0:r.label}),e.jsx(b,{className:"h-3.5 w-3.5 cursor-pointer text-primary dark:text-primary-foreground hover:text-red-600 ml-1",onClick:n=>j(s,n)})]},s)}),a.length>d&&e.jsxs(N,{open:M,onOpenChange:h,modal:!0,children:[e.jsx(k,{asChild:!0,children:e.jsx("div",{role:"button",tabIndex:0,onPointerDown:s=>s.stopPropagation(),onClick:s=>{s.stopPropagation(),h(r=>!r)},onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),s.stopPropagation(),h(r=>!r))},className:"flex items-center gap-1 px-2 py-1 bg-gray-100 text-gray-700 border border-gray-200 rounded-md cursor-pointer hover:bg-gray-200 transition-colors dark:bg-gray-700 dark:text-gray-200 dark:border-gray-600 dark:hover:bg-gray-600",title:o("msg.selectAll"),children:e.jsx("span",{className:"text-sm",children:`+ ${a.length-d} more`})})}),e.jsxs(S,{align:"start",className:"w-72 p-0",onPointerDown:s=>s.stopPropagation(),onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[e.jsx("span",{className:"text-xs font-semibold text-slate-700 dark:text-slate-200",children:o("ApprovalPage.Selected","Selected")}),e.jsx("span",{className:"rounded-full bg-primary/15 px-2 py-0.5 text-xs font-medium text-primary dark:bg-primary/30 dark:text-primary-foreground",children:a.length})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto py-1",children:a.slice(d)?.map(s=>{const r=l.find(n=>n.value===s);if(!r)return null;const t=r.icon;return e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-1.5 hover:bg-slate-50 dark:hover:bg-slate-800",children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[t&&e.jsx(t,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-sm truncate",children:r.label})]}),e.jsx(b,{className:"h-3.5 w-3.5 cursor-pointer text-slate-500 dark:text-slate-400 hover:text-red-600 shrink-0",onClick:n=>j(s,n)})]},s)})})]})]})]}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(v,{className:"h-4 mx-2 cursor-pointer text-muted-foreground"})})]}):e.jsxs("div",{className:"flex items-center justify-between w-full mx-auto",children:[e.jsx("span",{className:"text-sm text-muted-foreground mx-3",children:E}),e.jsx(v,{className:"h-4 cursor-pointer text-muted-foreground mx-2"})]})})}),e.jsx(S,{className:"w-auto p-0 max-w-[400px] dark:bg-gray-800 dark:border-gray-700",align:"start",onEscapeKeyDown:()=>p(!1),onWheel:s=>{s.stopPropagation()},children:e.jsxs(F,{filter:(s,r,t=[])=>{const n=P(r);return n?[s,...t]?.map(f=>P(f)).filter(Boolean)?.some(f=>f.includes(n))?1:0:1},children:[e.jsx(V,{placeholder:o("ApprovalPage.Search"),onKeyDown:z}),e.jsxs(G,{className:"max-h-[200px] overflow-y-auto custom-scrollbar scroll-container",children:[e.jsx(W,{children:o("common.noResult")}),e.jsxs(C,{children:[e.jsxs(u,{onSelect:R,className:"cursor-pointer",children:[e.jsx("div",{className:g("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",a.length===l.length?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(w,{className:"h-4 w-4"})}),e.jsxs("span",{children:["(",o("msg.selectAll"),")"]})]},"all"),l?.map(s=>{const r=a.includes(s.value);return e.jsxs(u,{value:s.label,keywords:[s.value,s.label],onSelect:()=>L(s.value),className:"cursor-pointer",children:[e.jsx("div",{className:g("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",r?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible"),children:e.jsx(w,{className:"h-4 w-4"})}),s.icon&&e.jsx(s.icon,{className:"mr-2 h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:s.label})]},s.value)})]}),e.jsx(X,{}),e.jsx(C,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[a.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(u,{onClick:y,className:"flex-1 justify-center cursor-pointer",children:o("userIncoming.Clear")}),e.jsx(_,{orientation:"vertical",className:"flex min-h-6 h-full"})]}),e.jsx(u,{onSelect:()=>p(!1),className:"flex-1 justify-center cursor-pointer max-w-full",children:o("complaint.close")})]})})]})]})})]})});$.displayName="MultiSelect";export{$ as M};
|