UNPKG

@anoki/fse-ui

Version:

FSE UI components library

3 lines (2 loc) 3.09 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./components/ui/CommunicationSeach/CommunicationSearch.css');const s=require("./index.cjs237.js");;/* empty css */const a=require("./index.cjs239.js"),x=require("react"),w=require("./index.cjs226.js"),C=require("./index.cjs179.js"),y=require("./index.cjs61.js"),v=require("./index.cjs32.js"),S=({btnText:d,helperText:j="Cosa vuoi approfondire?",value:i,loading:p,items:t,emptyLabel:f="Nessun risultato disponibile",setValue:g,setSelectedElement:R})=>{const[u,c]=x.useState(!1),m=e=>{const n=e.target.value;g(n)},E=e=>{R(e),c(!1)},b=x.useCallback((e,n)=>{if(!n)return e;const r=e.toLowerCase().indexOf(n.toLowerCase());if(r===-1)return e;const o=e.slice(0,r),l=e.slice(r,r+n.length),N=e.slice(r+n.length);return s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[o,s.jsxRuntimeExports.jsx("span",{className:"text-primary fw-bold",children:l}),N]})},[]),h=x.useMemo(()=>u||i.length>=3&&(t==null?void 0:t.length)>0?!0:u,[u,t==null?void 0:t.length,i.length]);return s.jsxRuntimeExports.jsxs("div",{className:a.clsx("ui-communication-search","br-x4 bg-border-secondary w-full"),onBlur:()=>{setTimeout(()=>{c(!1)},150)},children:[s.jsxRuntimeExports.jsxs("div",{className:"position-relative w-full",children:[s.jsxRuntimeExports.jsx("input",{id:"search",type:"search",className:a.clsx("ui-communication-search-input","fs-6 md-fs-custom text-slate-20 br-x4 w-full pl-x24"),placeholder:j,"aria-label":"Barra di ricerca",value:i,onChange:m,onFocus:()=>c(!0)}),p&&s.jsxRuntimeExports.jsx(w.Spinner,{className:"ui-loading-spinner"}),i&&i.length>=3&&s.jsxRuntimeExports.jsx(C.Close,{className:"ui-clean-button",onClick:()=>{m({target:{value:""}})}})]}),s.jsxRuntimeExports.jsx("div",{className:a.clsx("ui-wrap-list-item-search shadow position-absolute",{"py-x24":h}),children:s.jsxRuntimeExports.jsx(y.Col,{gap:"x24",fw:"regular",text:"secondary",fs:"6",className:"ui-list-item-search overflow-y-auto",children:h&&s.jsxRuntimeExports.jsxs(s.jsxRuntimeExports.Fragment,{children:[t.map((e,n)=>{var r;return(r=e.items)!=null&&r.length?s.jsxRuntimeExports.jsx(x.Fragment,{children:s.jsxRuntimeExports.jsxs("div",{children:[s.jsxRuntimeExports.jsx("h1",{className:"category-title fw-semibold text-dark fs-6 mb-x8 px-x24",children:e.category}),s.jsxRuntimeExports.jsx("ul",{className:"list-unstyled",children:e.items.map(o=>s.jsxRuntimeExports.jsx("li",{onClick:l=>{l.stopPropagation(),l.preventDefault(),E(o)},className:"cursor-pointer py-x8 px-x24",children:b(o.name,i||"")},o.id))})]})},n):s.jsxRuntimeExports.jsx(s.jsxRuntimeExports.Fragment,{})}),!p&&t.every(e=>e.items.length===0)?s.jsxRuntimeExports.jsx("p",{className:" px-x24 fs-6",children:f}):""]})})}),s.jsxRuntimeExports.jsx("div",{className:a.clsx("ui-div-btn"),children:s.jsxRuntimeExports.jsx(v.Button,{className:a.clsx("ui-btn-search","bg-primary text-white fs-7 md-fs-6 fw-semibold br-x4"),onClick:()=>{m({target:{value:i}}),c(!0)},children:d})})]})};exports.CommunicationSearch=S; //# sourceMappingURL=index.cjs62.js.map