dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
22 lines (21 loc) • 4.29 kB
JavaScript
"use strict";const e=require("./jsx-runtime-DUiatUiq.cjs"),R=require("./radio-group-CqPTye2U-CXc2TUFE.cjs"),a=require("./button-Bp2lHjov-D9UnCnYX.cjs"),b=require("./useTranslation-CZf20ucv.cjs"),i=require("./createLucideIcon-BnAj0RnC.cjs"),o=require("react"),_=require("./lodash-C5w_OPmE.cjs"),h=require("./popover-HTqpqYpJ-Bx11rWT_.cjs"),I=require("./MyInput-yriz78UG.cjs"),L=require("./MySelect-DtdzVlXP.cjs"),$=require("./useFilter-CiORTEHP.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 z=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],T=i.createLucideIcon("chevron-down",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 F=[["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=i.createLucideIcon("list-filter-plus",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 D=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M10 18h4",key:"1ulq68"}]],O=i.createLucideIcon("list-filter",D);/**
* @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"}]],H=i.createLucideIcon("search",A),P=({name:u="search",defaultValue:n,onSearchChange:r})=>{const{t}=b.useTranslation(),c=l=>{const x=new FormData(l.currentTarget);r(x.get(u)||void 0),l.preventDefault()};return e.jsxRuntimeExports.jsxs("form",{className:"relative w-full max-w-64 min-w-40",onSubmit:c,children:[e.jsxRuntimeExports.jsx(R.yl,{className:"h-8 rounded-lg",name:u,placeholder:t("Search..."),defaultValue:n?`${n}`:""}),e.jsxRuntimeExports.jsx(a.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(H,{})})]})},W=o.memo(function({filters:n,params:r,onFilter:t,onChange:c,onCancel:l,...x}){const{t:p}=b.useTranslation(),[k,q]=o.useState(!1),[v,d]=o.useState(!1),{form:j}=$.useFilter({params:r}),{watch:M,getValues:N,handleSubmit:f,control:y,reset:E}=j;o.useEffect(()=>{let s=!1;n.map(g=>{const m=_.lodashExports.get(r,`${g.name}`);(Array.isArray(m)?m.length>0:m)&&(s=!0),q(s)})},[n,r]),o.useEffect(()=>{c==null||c(N())},[M()]);const S=o.useCallback((s={})=>{t==null||t(s),d(!1)},[t]),w=o.useCallback(()=>{E(),t&&r&&t({...r,...Object.fromEntries(n.map(s=>[s.name,void 0]))}),d(!1)},[t,E,r,n]);return e.jsxRuntimeExports.jsxs(h.Oe,{open:v,onOpenChange:d,children:[e.jsxRuntimeExports.jsx(h._e,{children:e.jsxRuntimeExports.jsx(a.u,{asChild:!0,size:"sm",variant:"secondary",className:"ml-auto px-3",...x,children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[k?e.jsxRuntimeExports.jsx(C,{size:20}):e.jsxRuntimeExports.jsx(O,{size:20})," ",e.jsxRuntimeExports.jsx("span",{className:"hidden lg:!inline",children:p("Filter")}),e.jsxRuntimeExports.jsx(T,{})]})})}),e.jsxRuntimeExports.jsx(h.ue,{side:"bottom",align:"end",className:"",children:e.jsxRuntimeExports.jsx(R.Ph,{...j,children:e.jsxRuntimeExports.jsxs("form",{onSubmit:f(S),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:y,name:s.name,placeholder:s.placeholder,isMulti:s.isMulti,options:s.options,label:s.label},s.name):e.jsxRuntimeExports.jsx(I.MyInput,{control:y,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(a.u,{variant:"destructive",type:"reset",size:"sm",onClick:w,children:p("Reset")}),e.jsxRuntimeExports.jsx(a.u,{type:"submit",size:"sm",children:p("Apply")})]})]})})})]})});exports.FilterWrapper=W;exports.Search=P;