UNPKG

@anoki/fse-ui

Version:

FSE UI components library

3 lines (2 loc) 3.13 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./components/ui/DelegateFilterDropDown/DelegateFilterDropDown.css');const t=require("./index.cjs278.js"),d=require("./index.cjs280.js"),r=require("react");;/* empty css */const L=require("./index.cjs80.js"),S=require("./index.cjs36.js"),D=require("./index.cjs82.js"),I=({size:h="large",items:j=[],className:w,selectedPerson:l,setSelectedPerson:m,placeholder:g="",btnText:E="Cerca"})=>{const[n,a]=r.useState(!1),[o,c]=r.useState(""),u=r.useRef(null),x=r.useRef(null),f=j.filter(e=>`${e.firstName} ${e.lastName} ${e.relationship}`.toLowerCase().includes(o.toLowerCase()));r.useEffect(()=>{const e=s=>{u.current&&!u.current.contains(s.target)&&a(!1)};return n?document.addEventListener("mousedown",e):document.removeEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[n]),r.useEffect(()=>{n&&(c(""),x.current&&x.current.focus())},[n]);const N=e=>{n&&c(e.target.value)},p=()=>{a(!n)},R=e=>{e.stopPropagation(),m(null),c("")},v=!n&&l?`${l.firstName} ${l.lastName} (${l.relationship})`:o,C=l!==null||o.length>0,b=(e,s)=>{if(!s||s.trim()==="")return t.jsxRuntimeExports.jsxs("span",{style:{color:"black",fontSize:"0.85rem"},children:[" ",e," "]});const i=e.toLowerCase().indexOf(s.toLowerCase());if(i===-1)return e;const $=e.slice(0,i),k=e.slice(i,i+s.length),y=e.slice(i+s.length);return t.jsxRuntimeExports.jsxs("span",{style:{color:"black",fontSize:"0.85rem"},children:[$,t.jsxRuntimeExports.jsx("span",{style:{fontSize:"0.85rem"},className:"text-primary fw-bold",children:k}),y]})};return t.jsxRuntimeExports.jsxs("div",{ref:u,className:d.clsx("ui-related-dropdown","br-x4 bg-border-secondary w-full",w),style:h==="large"?{maxWidth:"100%"}:{maxWidth:"553px"},children:[t.jsxRuntimeExports.jsxs("div",{className:"ui-input-container",children:[t.jsxRuntimeExports.jsx("input",{ref:x,className:d.clsx("ui-related-dropdown-input","bg-white fs-6 br-x4 w-full pl-x24",{active:n}),value:v,onChange:N,placeholder:g,onClick:p}),C&&t.jsxRuntimeExports.jsx("div",{className:"ui-close-button",onClick:R,children:t.jsxRuntimeExports.jsx(L.Close,{width:20})}),t.jsxRuntimeExports.jsx("div",{className:"ui-div-btn",children:t.jsxRuntimeExports.jsx(S.Button,{className:d.clsx("ui-btn-search","bg-primary text-white fs-7 fw-semibold br-x4"),onClick:p,children:E})})]}),n&&t.jsxRuntimeExports.jsx("div",{className:"ui-related-dropdown-options",children:t.jsxRuntimeExports.jsx("div",{className:"px-x24 shadow w-full",children:t.jsxRuntimeExports.jsx(D.Col,{gap:"x4",text:"primary",fs:"custom",fw:"regular",className:"ui-options-list fw-regular",children:f.length>0?f.map((e,s)=>{const i=`${e.firstName} ${e.lastName} (${e.relationship})`;return t.jsxRuntimeExports.jsx("div",{className:"ui-option-item",onClick:()=>{m(e),a(!1)},children:b(i,o)},e.fiscalCode||s)}):t.jsxRuntimeExports.jsx("div",{className:"ui-option-item no-results",children:t.jsxRuntimeExports.jsx("span",{style:{color:"gray"},children:"Nessun risultato trovato"})})})})})]})};exports.DelegateFilterDropDown=I; //# sourceMappingURL=index.cjs101.js.map