@anoki/fse-ui
Version:
FSE UI components library
3 lines (2 loc) • 3.09 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./components/ui/DeclarantsSelect/DeclarantsSelect.css');const s=require("./index.cjs244.js"),j=require("./index.cjs246.js"),o=require("react");;/* empty css */const y=require("./index.cjs161.js"),L=require("./index.cjs158.js"),M=require("./index.cjs10.js"),$=({size:w="large",items:p=[],className:E,selectedItem:i,setSelectedItem:f,placeholder:g=""})=>{const[n,c]=o.useState(!1),[l,u]=o.useState(""),d=o.useRef(null),x=o.useRef(null),m=p.filter(e=>{var r;return`${(r=e.labels)==null?void 0:r.it}`.toLowerCase().includes(l.toLowerCase())});o.useEffect(()=>{const e=t=>{d.current&&!d.current.contains(t.target)&&c(!1)};return n?document.addEventListener("mousedown",e):document.removeEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[n]),o.useEffect(()=>{n&&(u(""),x.current&&x.current.focus())},[n]);const R=e=>{n&&u(e.target.value)},v=()=>{c(!n)},b=e=>{e.stopPropagation(),f(null),u("")},C=o.useMemo(()=>{var e;return!n&&i?((e=p.find(t=>t.code===i))==null?void 0:e.labels.it)||"":l},[n,i,l]),h=i!==null||l.length>0,N=(e,t)=>{if(!t||t.trim()==="")return s.jsxRuntimeExports.jsxs("span",{style:{color:"black",fontSize:"0.85rem"},children:[" ",e," "]});const r=e.toLowerCase().indexOf(t.toLowerCase());if(r===-1)return e;const a=e.slice(0,r),S=e.slice(r,r+t.length),k=e.slice(r+t.length);return s.jsxRuntimeExports.jsxs("span",{style:{color:"black",fontSize:"0.85rem"},children:[a,s.jsxRuntimeExports.jsx("span",{style:{fontSize:"0.85rem"},className:"text-primary fw-bold",children:S}),k]})};return s.jsxRuntimeExports.jsxs("div",{ref:d,className:j.clsx("ui-related-dropdown","br-x4 bg-border-secondary w-full",E),style:w==="large"?{maxWidth:"100%"}:{maxWidth:"553px"},children:[s.jsxRuntimeExports.jsxs("div",{className:"ui-input-container",children:[s.jsxRuntimeExports.jsx("input",{ref:x,className:j.clsx("ui-related-dropdown-input","bg-white fs-6 br-x4 w-full pl-x24",{active:n}),value:C,onChange:R,placeholder:g,onClick:v}),h&&s.jsxRuntimeExports.jsx("div",{className:"ui-close-button",onClick:b,children:s.jsxRuntimeExports.jsx(y.Close,{width:40})}),!h&&s.jsxRuntimeExports.jsx("div",{className:"ui-close-button",children:s.jsxRuntimeExports.jsx(L.ArrowDown,{width:40,height:40})})]}),n&&s.jsxRuntimeExports.jsx("div",{className:"ui-related-dropdown-options",children:s.jsxRuntimeExports.jsx("div",{className:"px-x24 shadow w-full",children:s.jsxRuntimeExports.jsx(M.Col,{gap:"x4",text:"primary",fs:"custom",fw:"regular",className:"ui-options-list fw-regular",children:m.length>0?m.map((e,t)=>{var a;const r=`${(a=e.labels)==null?void 0:a.it} `;return s.jsxRuntimeExports.jsx("div",{className:"ui-option-item",onClick:()=>{f((e==null?void 0:e.code)||""),c(!1)},children:N(r,l)},(e==null?void 0:e.code)||t)}):s.jsxRuntimeExports.jsx("div",{className:"ui-option-item no-results",children:s.jsxRuntimeExports.jsx("span",{style:{color:"gray"},children:"Nessun risultato trovato"})})})})})]})};exports.DeclarantsSelect=$;
//# sourceMappingURL=index.cjs126.js.map