UNPKG

dgz-ui-shared

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library

22 lines (21 loc) 4.41 kB
"use strict";const e=require("./jsx-runtime-h4oGeKUK.cjs"),b=require("./input-mask-DBLFIvhN-C_0RAR2l.cjs"),u=require("./button-CdZDBhmr-3yMPCRDo.cjs"),I=require("./utils-B6fNqzRf-BNysSCt9.cjs"),q=require("./useTranslation-CZf20ucv.cjs"),l=require("./createLucideIcon-BnAj0RnC.cjs"),o=require("react"),_=require("./lodash-C5w_OPmE.cjs"),j=require("./popover-OZcfKDD9-KUWOsIOs.cjs"),D=require("./MyInput-9MnlVZ4h.cjs"),L=require("./MySelect-DNK997Bi.cjs"),z=require("./useFilter-Cwz8oftI.cjs");/** * @license lucide-react v0.511.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const $=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],F=l.createLucideIcon("chevron-down",$);/** * @license lucide-react v0.511.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const B=[["path",{d:"M10 18h4",key:"1ulq68"}],["path",{d:"M11 6H3",key:"1u26ik"}],["path",{d:"M15 6h6",key:"1jlkvy"}],["path",{d:"M18 9V3",key:"xwwp7m"}],["path",{d:"M7 12h8",key:"7a1bxv"}]],C=l.createLucideIcon("list-filter-plus",B);/** * @license lucide-react v0.511.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const O=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M10 18h4",key:"1ulq68"}]],T=l.createLucideIcon("list-filter",O);/** * @license lucide-react v0.511.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const A=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],W=l.createLucideIcon("search",A),P=({name:x="search",defaultValue:n,onSearchChange:r,placeholder:t,className:c,...y})=>{const{t:p}=q.useTranslation(),i=a=>{const d=new FormData(a.currentTarget);r(d.get(x)||void 0),a.preventDefault(),a.stopPropagation()};return e.jsxRuntimeExports.jsxs("form",{className:I.mo("relative w-full max-w-64 min-w-40",c),onSubmit:i,children:[e.jsxRuntimeExports.jsx(b.yp,{...y,className:"h-8 rounded-lg",name:x,placeholder:t||p("Search..."),defaultValue:n?`${n}`:""}),e.jsxRuntimeExports.jsx(u.u,{type:"submit",variant:"ghost",className:"text-foreground absolute top-0 right-0 cursor-pointer rounded-md !bg-transparent",size:"sm",children:e.jsxRuntimeExports.jsx(W,{})})]})},V=o.memo(function({filters:n,params:r,onFilter:t,onChange:c,onCancel:y,...p}){const{t:i}=q.useTranslation(),[a,d]=o.useState(!1),[v,m]=o.useState(!1),{form:E}=z.useFilter({params:r}),{watch:N,getValues:f,handleSubmit:M,control:R,reset:k}=E;o.useEffect(()=>{let s=!1;n.map(g=>{const h=_.lodashExports.get(r,`${g.name}`);(Array.isArray(h)?h.length>0:h)&&(s=!0),d(s)})},[n,r]),o.useEffect(()=>{c==null||c(f())},[N()]);const w=o.useCallback((s={})=>{t==null||t(s),m(!1)},[t]),S=o.useCallback(()=>{k(),t&&r&&t({...r,...Object.fromEntries(n.map(s=>[s.name,void 0]))}),m(!1)},[t,k,r,n]);return e.jsxRuntimeExports.jsxs(j._e,{open:v,onOpenChange:m,children:[e.jsxRuntimeExports.jsx(j.we,{children:e.jsxRuntimeExports.jsx(u.u,{asChild:!0,size:"sm",variant:"secondary",className:"ml-auto px-3",...p,children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[a?e.jsxRuntimeExports.jsx(C,{size:20}):e.jsxRuntimeExports.jsx(T,{size:20})," ",e.jsxRuntimeExports.jsx("span",{className:"hidden lg:!inline",children:i("Filter")}),e.jsxRuntimeExports.jsx(F,{})]})})}),e.jsxRuntimeExports.jsx(j.ue,{side:"bottom",align:"end",className:"",children:e.jsxRuntimeExports.jsx(b.Gx,{...E,children:e.jsxRuntimeExports.jsxs("form",{onSubmit:M(w),className:"space-y-2",children:[e.jsxRuntimeExports.jsx("div",{className:"h-full shrink p-1",children:n.map(s=>s.options?e.jsxRuntimeExports.jsx(L.MySelect,{control:R,name:s.name,placeholder:s.placeholder,isMulti:s.isMulti,options:s.options,label:s.label},s.name):e.jsxRuntimeExports.jsx(D.MyInput,{control:R,placeholder:s.placeholder,name:s.name,label:s.label},s.name))}),e.jsxRuntimeExports.jsxs("div",{className:"flex shrink-0 justify-end gap-2",children:[e.jsxRuntimeExports.jsx(u.u,{variant:"destructive",type:"reset",size:"sm",onClick:S,children:i("Reset")}),e.jsxRuntimeExports.jsx(u.u,{type:"submit",size:"sm",children:i("Apply")})]})]})})})]})});exports.FilterWrapper=V;exports.Search=P;