UNPKG

dgz-ui-shared

Version:

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

22 lines (21 loc) 9.94 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../jsx-runtime-h4oGeKUK.cjs"),K=require("../../button-CdZDBhmr-3yMPCRDo.cjs"),y=require("../../dropdown-menu-TWRSm6RK-DQ03CnVw.cjs"),A=require("../../MyLimitSelect-BU1FClXt.cjs"),O=require("../../index-CGv7FLNy.cjs"),d=require("react"),b=require("../../lodash-C5w_OPmE.cjs"),u=require("../../index-BL59b1Bz-COeLljOH.cjs"),n=require("../../utils-B6fNqzRf-BNysSCt9.cjs"),B=require("../../useSortable-BvLbSWXW.cjs"),H=require("../../input-mask-DBLFIvhN-C_0RAR2l.cjs"),I=require("../../SortOrder-81BrXp3i.cjs"),S=require("../../Empty-C2sFuxBi.cjs"),D=require("../../createLucideIcon-BnAj0RnC.cjs"),V=require("../../FilterWrapper-DvNjUQih.cjs"),P=require("../../Loader-BsYF7B7O.cjs"),C=require("../../Actions-uGf1oq7E.cjs"),ee=require("../../ExportData-ApStkEWC.cjs"),se=require("../../useTranslation-CZf20ucv.cjs"),J=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("table",{ref:r,className:n.mo("w-full caption-bottom text-sm",s),...t}));J.displayName="Table";const Z=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("thead",{ref:r,className:n.mo("[&_tr]:border-b",s),...t}));Z.displayName="TableHeader";const G=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("tbody",{ref:r,className:n.mo("[&_tr:last-child]:border-0",s),...t}));G.displayName="TableBody";const te=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("tfoot",{ref:r,className:n.mo("bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",s),...t}));te.displayName="TableFooter";const L=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("tr",{ref:r,className:n.mo("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...t}));L.displayName="TableRow";const _=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("th",{ref:r,className:n.mo("text-muted-foreground h-12 px-4 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0",s),...t}));_.displayName="TableHead";const v=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("td",{ref:r,className:n.mo("p-4 align-middle [&:has([role=checkbox])]:pr-0",s),...t}));v.displayName="TableCell";const ie=d.forwardRef(({className:s,...t},r)=>u.ae.jsx("caption",{ref:r,className:n.mo("text-muted-foreground mt-4 text-sm",s),...t}));ie.displayName="TableCaption";/** * @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 re=[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M11 4h10",key:"1w87gc"}],["path",{d:"M11 8h7",key:"djye34"}],["path",{d:"M11 12h4",key:"q8tih4"}]],xe=D.createLucideIcon("arrow-down-wide-narrow",re);/** * @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 le=[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]],oe=D.createLucideIcon("arrow-up-down",le);/** * @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 de=[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 16h7",key:"uosisv"}],["path",{d:"M11 20h4",key:"1krc32"}]],ce=D.createLucideIcon("arrow-up-wide-narrow",de);/** * @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 ne=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],pe=D.createLucideIcon("refresh-cw",ne),Q=({rows:s=[],columns:t,onRowClick:r,rowKey:a,params:p={page:1,limit:A.DEFAULT_LIMIT},hasNumbers:E=!1,hasCheckbox:f=!1,selectedItems:w,onSelectedItemsChange:R,onSortOrderChange:z,isStickyHeader:x})=>{const{sortObject:c,handleSort:F}=B.useSortable({sortField:p==null?void 0:p.sortField,sortOrder:p==null?void 0:p.sortOrder,onSortOrderChange:z}),{selectedRows:m,isRowSelected:N,isAllRowsSelected:g,handleSelectAllRows:k,handleSelectRow:j}=B.useDataTable({rows:s,defaultSelectedRows:w});return d.useEffect(()=>{JSON.stringify(w)!==JSON.stringify(m)&&m&&(R==null||R(m))},[m,w,R]),e.jsxRuntimeExports.jsxs(J,{className:"relative",children:[e.jsxRuntimeExports.jsx(Z,{className:n.mo("bg-bg",x&&"sticky top-0 z-10"),children:e.jsxRuntimeExports.jsxs(L,{children:[f&&e.jsxRuntimeExports.jsx(_,{className:"w-12 p-3",children:e.jsxRuntimeExports.jsx(H.vp,{className:"mt-1",checked:g(a),onCheckedChange:i=>k(a,!!i),"aria-label":"Select all"})}),E&&e.jsxRuntimeExports.jsx(_,{className:"w-12 p-2",children:"#"}),t.filter(i=>!i.hidden).map(i=>e.jsxRuntimeExports.jsx(_,{style:i.styles,className:n.mo("p-2",i.sortable&&"cursor-pointer"),onClick:()=>i.sortable&&F(i.dataIndex),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[i.name," ",i.sortable&&((c==null?void 0:c.sortField)===i.key?e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[(c==null?void 0:c.sortOrder)===I.SortOrder.DESC&&e.jsxRuntimeExports.jsx(xe,{size:15}),(c==null?void 0:c.sortOrder)===I.SortOrder.ASC&&e.jsxRuntimeExports.jsx(ce,{size:15})]}):e.jsxRuntimeExports.jsx(oe,{size:15}))]})},i.key))]})}),e.jsxRuntimeExports.jsx(G,{className:"[&>tr:nth-child(even)]:bg-bg-secondary",children:s.length?s.map((i,h)=>e.jsxRuntimeExports.jsxs(L,{onClick:()=>r==null?void 0:r(i),className:n.mo(r&&"cursor-pointer"),"data-state":N(i[a])&&"selected",children:[f&&e.jsxRuntimeExports.jsx(v,{className:"w-12 p-3",onClick:l=>l.stopPropagation(),children:e.jsxRuntimeExports.jsx(H.vp,{className:"mt-1",checked:N(i[a]),onCheckedChange:l=>j(i[a],!!l),"aria-label":"Select row"})}),E&&e.jsxRuntimeExports.jsx(v,{className:"w-12 p-2",children:(p.page-1)*(p.limit||A.DEFAULT_LIMIT)+h+1}),t.filter(l=>!l.hidden).map(l=>e.jsxRuntimeExports.jsx(v,{className:"text-body-xs-medium max-w-xs p-2",style:l.styles,children:l.render?l.render(b.lodashExports.get(i,l.dataIndex),i):b.lodashExports.get(i,l.dataIndex,"")},`${h}-${l.key}`))]},`${i[a]}`)):e.jsxRuntimeExports.jsx(L,{children:e.jsxRuntimeExports.jsx(v,{colSpan:E?f?t.length+2:t.length+1:t.length,children:e.jsxRuntimeExports.jsx(S.Empty,{})})})})]})},je=({dataSource:s,columns:t,onRowClick:r,rowKey:a,hasNumbers:p,hasSearch:E,exportOptions:f,hasCheckbox:w,hasPagination:R,isStickyHeader:z,onParamChange:x,dataKey:c="docs",loading:F,tableKey:m,filters:N,actions:g,handleFilterChange:k,params:j,exportLoading:i=!1,onColumnsUpdate:h,hasColumnsVisibilityDropdown:l,onSelectedItemsChange:M})=>{const{t:W}=se.useTranslation(),[q,X]=d.useState([]),{formattedColumns:T,handleColumnsChange:Y,resetColumns:U}=B.useColumns({key:m,columns:t});return d.useEffect(()=>{h==null||h(T)},[T,h]),d.useEffect(()=>{M==null||M(q)},[q,M]),e.jsxRuntimeExports.jsxs("div",{className:"border-border-alpha-light flex grow flex-col overflow-auto rounded-xl border shadow-xs",children:[(E||l&&m||!b.lodashExports.isEmpty(f)||!b.lodashExports.isEmpty(N))&&e.jsxRuntimeExports.jsxs("div",{className:"flex shrink-0 flex-col items-center justify-between gap-3 p-4 lg:flex-row",children:[e.jsxRuntimeExports.jsx("div",{className:"w-full shrink",children:E&&e.jsxRuntimeExports.jsx(V.Search,{defaultValue:b.lodashExports.get(j,"search",""),onSearchChange:o=>x==null?void 0:x({...j,search:o,page:1})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-3",children:[f&&e.jsxRuntimeExports.jsx(ee.ExportData,{options:f,loading:i}),l&&m&&e.jsxRuntimeExports.jsxs(y.Tt,{children:[e.jsxRuntimeExports.jsx(y.At,{asChild:!0,children:e.jsxRuntimeExports.jsxs(K.u,{variant:"secondary",size:"sm",className:"ml-auto rounded-lg px-3",children:[e.jsxRuntimeExports.jsx(O.yn,{})," ",e.jsxRuntimeExports.jsx("span",{className:"hidden lg:!inline",children:W("Customize columns")}),e.jsxRuntimeExports.jsx(O.f1,{})]})}),e.jsxRuntimeExports.jsxs(y.it,{align:"end",children:[e.jsxRuntimeExports.jsxs(y.ut,{className:"capitalize",onClick:U,children:[e.jsxRuntimeExports.jsx(pe,{})," ",W("Reset columns")]}),e.jsxRuntimeExports.jsx(y.ft,{}),T.map(o=>e.jsxRuntimeExports.jsx(y.dt,{className:"capitalize",checked:!o.hidden,onCheckedChange:$=>Y(o,!$),children:o.name},o.key))]})]}),g&&e.jsxRuntimeExports.jsx(C.Actions,{actions:g}),N&&e.jsxRuntimeExports.jsx(V.FilterWrapper,{filters:N,params:j,onFilter:o=>{x==null||x({...j,...o,page:1}),k==null||k(o)}})]})]}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col overflow-auto border-y",children:F?e.jsxRuntimeExports.jsx(P.Loader,{}):e.jsxRuntimeExports.jsx(Q,{params:{page:(s==null?void 0:s.page)||1,limit:s==null?void 0:s.limit,...j},rows:b.lodashExports.get(s,c,[]),rowKey:a,selectedItems:q,isStickyHeader:z,columns:T,hasCheckbox:w,hasNumbers:p,onRowClick:r,onSelectedItemsChange:X,onSortOrderChange:({sortField:o,sortOrder:$})=>{x==null||x({...j,sortField:o,sortOrder:$})}})}),R&&e.jsxRuntimeExports.jsxs("div",{className:"flex shrink-0 flex-col items-center justify-between gap-3 p-4 lg:flex-row",children:[e.jsxRuntimeExports.jsx("div",{className:"text-sm",children:e.jsxRuntimeExports.jsx(A.MyLimitSelect,{onLimitChange:o=>x==null?void 0:x({...j,limit:o,page:1}),defaultValue:s==null?void 0:s.limit})}),e.jsxRuntimeExports.jsxs("div",{className:"text-muted-foreground text-sm",children:[q.length," of ",(s==null?void 0:s.total)||0," row(s) selected."]}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsx(A.MyPagination,{onPageChange:o=>x==null?void 0:x({...j,page:o}),currentPage:s==null?void 0:s.page,totalPages:s==null?void 0:s.totalPages})})]})]})};exports.DataTable=je;exports.MyTable=Q;