dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
22 lines (21 loc) • 4.19 kB
JavaScript
"use strict";const e=require("./jsx-runtime-DUiatUiq.cjs"),a=require("./MyInput-3qarivly.cjs"),i=require("./check-DE-1lGDl-C_ZPlJ0c.cjs"),k=require("./useTranslation-CZf20ucv.cjs"),l=require("./createLucideIcon-BnAj0RnC.cjs"),o=require("react"),j=require("./popover-DDxpKohG-lwQEtZjs.cjs"),_=require("./MySelect-PTD5YCMn.cjs"),D=require("./useFilter-DVFoDmdH.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 F=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],I=l.createLucideIcon("chevron-down",F);/**
* @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 L=[["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"}]],$=l.createLucideIcon("list-filter-plus",L);/**
* @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 z=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M10 18h4",key:"1ulq68"}]],C=l.createLucideIcon("list-filter",z);/**
* @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:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],T=l.createLucideIcon("search",O),A=({name:u="search",defaultValue:t,onSearchChange:n})=>{const{t:r}=k.useTranslation(),c=x=>{const p=new FormData(x.currentTarget);n(p.get(u)),x.preventDefault()};return e.jsxRuntimeExports.jsxs("form",{className:"relative min-w-40 w-full max-w-64",onSubmit:c,children:[e.jsxRuntimeExports.jsx(a.yo,{className:"rounded-lg h-8",name:u,placeholder:r("Search..."),defaultValue:t?`${t}`:""}),e.jsxRuntimeExports.jsx(i.u,{type:"submit",variant:"ghost",className:"!bg-transparent absolute top-0 right-0 cursor-pointer rounded-md text-foreground",size:"sm",children:e.jsxRuntimeExports.jsx(T,{})})]})},W=o.memo(function({filters:t,params:n,onFilter:r,onChange:c,onCancel:x,...p}){const{t:d}=k.useTranslation(),[b,f]=o.useState(!1),[v,m]=o.useState(!1),{form:y}=D.useFilter({params:n}),{watch:M,getValues:N,handleSubmit:g,control:E,reset:R}=y;o.useEffect(()=>{let s=!1;t.map(w=>{const h=a.lodashExports.get(n,`${w.name}`);(Array.isArray(h)?h.length>0:h)&&(s=!0),f(s)})},[t,n]),o.useEffect(()=>{c&&c(N())},[M()]);const q=o.useCallback((s={})=>{r&&r(s),m(!1)},[r]),S=o.useCallback(()=>{R(),r&&n&&r({...n,...Object.fromEntries(t.map(s=>[s.name,void 0]))}),m(!1)},[r,R,n,t]);return e.jsxRuntimeExports.jsxs(j.Oe,{open:v,onOpenChange:m,children:[e.jsxRuntimeExports.jsx(j._e,{children:e.jsxRuntimeExports.jsx(i.u,{asChild:!0,size:"sm",variant:"secondary",className:"ml-auto px-3",...p,children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[b?e.jsxRuntimeExports.jsx($,{size:20}):e.jsxRuntimeExports.jsx(C,{size:20})," ",e.jsxRuntimeExports.jsx("span",{className:"hidden md:inline",children:d("Filter")}),e.jsxRuntimeExports.jsx(I,{})]})})}),e.jsxRuntimeExports.jsx(j.ue,{side:"bottom",align:"end",className:"",children:e.jsxRuntimeExports.jsx(a.Mf,{...y,children:e.jsxRuntimeExports.jsxs("form",{onSubmit:g(q),className:"space-y-2",children:[e.jsxRuntimeExports.jsx("div",{className:"h-full shrink p-1",children:t.map(s=>s.options?e.jsxRuntimeExports.jsx(_.MySelect,{control:E,name:s.name,placeholder:s.placeholder,isMulti:s.isMulti,options:s.options,label:s.label},s.name):e.jsxRuntimeExports.jsx(a.MyInput,{control:E,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(i.u,{variant:"destructive",type:"reset",size:"sm",onClick:S,children:d("Reset")}),e.jsxRuntimeExports.jsx(i.u,{type:"submit",size:"sm",children:d("Apply")})]})]})})})]})});exports.FilterWrapper=W;exports.Search=A;