UNPKG

dgz-ui-shared

Version:

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

22 lines (21 loc) 9.57 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../jsx-runtime-DUiatUiq.cjs"),J=require("../../button-Bp2lHjov-D9UnCnYX.cjs"),R=require("../../dropdown-menu-BPBcxHRB-towSSPIs.cjs"),M=require("../../MyLimitSelect-BFWr_fUn.cjs"),F=require("../../index-Vhq7CMrm.cjs"),a=require("react"),u=require("../../lodash-C5w_OPmE.cjs"),m=require("../../index-DqTIeHVj-DlSOwhuZ.cjs"),n=require("../../utils-B6fNqzRf-BNysSCt9.cjs"),z=require("../../useSortable-ByFhUHQb.cjs"),$=require("../../radio-group-CqPTye2U-CXc2TUFE.cjs"),B=require("../../SortOrder-81BrXp3i.cjs"),Q=require("../../Empty--unTFnpg.cjs"),L=require("../../createLucideIcon-BnAj0RnC.cjs"),H=require("../../FilterWrapper-CVM-n8tz.cjs"),X=require("../../Loader-bUUShWXh.cjs"),Y=require("../../Actions-CkCdw8LQ.cjs"),Z=require("../../useTranslation-CZf20ucv.cjs"),U=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("table",{ref:i,className:n.mo("w-full caption-bottom text-sm",s),...r}));U.displayName="Table";const S=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("thead",{ref:i,className:n.mo("[&_tr]:border-b",s),...r}));S.displayName="TableHeader";const V=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("tbody",{ref:i,className:n.mo("[&_tr:last-child]:border-0",s),...r}));V.displayName="TableBody";const K=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("tfoot",{ref:i,className:n.mo("bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",s),...r}));K.displayName="TableFooter";const q=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("tr",{ref:i,className:n.mo("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",s),...r}));q.displayName="TableRow";const T=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("th",{ref:i,className:n.mo("text-muted-foreground h-12 px-4 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0",s),...r}));T.displayName="TableHead";const k=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("td",{ref:i,className:n.mo("p-4 align-middle [&:has([role=checkbox])]:pr-0",s),...r}));k.displayName="TableCell";const C=a.forwardRef(({className:s,...r},i)=>m.ae.jsx("caption",{ref:i,className:n.mo("text-muted-foreground mt-4 text-sm",s),...r}));C.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 P=[["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"}]],ee=L.createLucideIcon("arrow-down-wide-narrow",P);/** * @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 se=[["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"}]],te=L.createLucideIcon("arrow-up-down",se);/** * @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 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"}]],ie=L.createLucideIcon("arrow-up-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:"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"}]],xe=L.createLucideIcon("refresh-cw",le),W=({rows:s=[],columns:r,onRowClick:i,rowKey:j,params:c={page:1,limit:M.DEFAULT_LIMIT},hasNumbers:h=!1,hasCheckbox:E=!1,selectedItems:I,onSelectedItemsChange:g,onSortOrderChange:l,isStickyHeader:_})=>{const{sortObject:d,handleSort:N}=z.useSortable({sortField:c==null?void 0:c.sortField,sortOrder:c==null?void 0:c.sortField,onSortOrderChange:l}),{selectedRows:f,isRowSelected:y,isAllRowsSelected:b,handleSelectAllRows:p,handleSelectRow:v}=z.useDataTable({rows:s,defaultSelectedRows:I});return a.useEffect(()=>{g&&g(f)},[f]),e.jsxRuntimeExports.jsxs(U,{className:"relative",children:[e.jsxRuntimeExports.jsx(S,{className:n.mo("bg-bg",_&&"sticky top-0 z-10"),children:e.jsxRuntimeExports.jsxs(q,{children:[E&&e.jsxRuntimeExports.jsx(T,{className:"w-12 p-3",children:e.jsxRuntimeExports.jsx($.Tl,{className:"mt-1",checked:b(j),onCheckedChange:t=>p(j,!!t),"aria-label":"Select all"})}),h&&e.jsxRuntimeExports.jsx(T,{className:"w-12 p-2",children:"#"}),r.filter(t=>!t.hidden).map(t=>e.jsxRuntimeExports.jsx(T,{style:t.styles,className:n.mo("p-2",t.sortable&&"cursor-pointer"),onClick:()=>t.sortable&&N(t.dataIndex),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[t.name," ",t.sortable&&((d==null?void 0:d.sortField)===t.key?e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[(d==null?void 0:d.sortOrder)===B.SortOrder.DESC&&e.jsxRuntimeExports.jsx(ee,{size:15}),(d==null?void 0:d.sortOrder)===B.SortOrder.ASC&&e.jsxRuntimeExports.jsx(ie,{size:15})]}):e.jsxRuntimeExports.jsx(te,{size:15}))]})},t.key))]})}),e.jsxRuntimeExports.jsx(V,{className:"[&>tr:nth-child(even)]:bg-bg-secondary",children:s.length?s.map((t,w)=>e.jsxRuntimeExports.jsxs(q,{onClick:()=>i==null?void 0:i(t),className:n.mo(i&&"cursor-pointer"),"data-state":y(t[j])&&"selected",children:[E&&e.jsxRuntimeExports.jsx(k,{className:"w-12 p-3",onClick:o=>o.stopPropagation(),children:e.jsxRuntimeExports.jsx($.Tl,{className:"mt-1",checked:y(t[j]),onCheckedChange:o=>v(t[j],!!o),"aria-label":"Select row"})}),h&&e.jsxRuntimeExports.jsx(k,{className:"w-12 p-2",children:(c.page-1)*(c.limit||M.DEFAULT_LIMIT)+w+1}),r.filter(o=>!o.hidden).map(o=>e.jsxRuntimeExports.jsx(k,{className:"text-body-xs-medium max-w-xs p-2",style:o.styles,children:o.render?o.render(u.lodashExports.get(t,o.dataIndex),t):u.lodashExports.get(t,o.dataIndex,"")},`${w}-${o.key}`))]},`${t[j]}`)):e.jsxRuntimeExports.jsx(q,{children:e.jsxRuntimeExports.jsx(k,{colSpan:h?E?r.length+2:r.length+1:r.length,children:e.jsxRuntimeExports.jsx(Q.Empty,{})})})})]})},oe=({dataSource:s,columns:r,onRowClick:i,rowKey:j,hasNumbers:c,hasSearch:h,hasCheckbox:E,hasPagination:I,isStickyHeader:g,onParamChange:l,dataKey:_="docs",loading:d,tableKey:N,filters:f=[],actions:y=[],handleFilterChange:b,params:p,hasColumnsVisibilityDropdown:v})=>{const{t}=Z.useTranslation(),[w,o]=a.useState([]),{formattedColumns:D,handleColumnsChange:O,resetColumns:G}=z.useColumns({key:N,columns:r});return e.jsxRuntimeExports.jsxs("div",{className:"border-border-alpha-light flex grow flex-col overflow-auto rounded-xl border shadow-xs",children:[(h||v&&N||!u.lodashExports.isEmpty(f))&&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:h&&e.jsxRuntimeExports.jsx(H.Search,{defaultValue:u.lodashExports.get(p,"search",""),onSearchChange:x=>l==null?void 0:l({...p,search:x,page:1})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-3",children:[v&&N&&e.jsxRuntimeExports.jsxs(R.Nt,{children:[e.jsxRuntimeExports.jsx(R.jt,{asChild:!0,children:e.jsxRuntimeExports.jsxs(J.u,{variant:"secondary",size:"sm",className:"ml-auto rounded-lg px-3",children:[e.jsxRuntimeExports.jsx(F.yn,{})," ",e.jsxRuntimeExports.jsx("span",{className:"hidden lg:!inline",children:t("Customize columns")}),e.jsxRuntimeExports.jsx(F.f1,{})]})}),e.jsxRuntimeExports.jsxs(R.ut,{align:"end",children:[e.jsxRuntimeExports.jsxs(R.it,{className:"capitalize",onClick:G,children:[e.jsxRuntimeExports.jsx(xe,{})," ",t("Reset columns")]}),e.jsxRuntimeExports.jsx(R.ft,{}),D.map(x=>e.jsxRuntimeExports.jsx(R.dt,{className:"capitalize",checked:!x.hidden,onCheckedChange:A=>O(x,!A),children:x.name},x.key))]})]}),!u.lodashExports.isEmpty(y)&&e.jsxRuntimeExports.jsx(Y.Actions,{actions:y}),!u.lodashExports.isEmpty(f)&&e.jsxRuntimeExports.jsx(H.FilterWrapper,{filters:f,onFilter:x=>{l==null||l({...p,...x,page:1}),b==null||b(x)}})]})]}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col overflow-auto border-y",children:d?e.jsxRuntimeExports.jsx(X.Loader,{}):e.jsxRuntimeExports.jsx(W,{params:p,rows:u.lodashExports.get(s,_,[]),rowKey:j,selectedItems:w,isStickyHeader:g,columns:D,hasCheckbox:E,hasNumbers:c,onRowClick:i,onSelectedItemsChange:o,onSortOrderChange:({sortField:x,sortOrder:A})=>{l==null||l({...p,sortField:x,sortOrder:A})}})}),I&&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(M.MyLimitSelect,{onLimitChange:x=>l==null?void 0:l({...p,limit:x,page:1}),defaultValue:s==null?void 0:s.limit})}),e.jsxRuntimeExports.jsxs("div",{className:"text-muted-foreground text-sm",children:[w.length," of ",(s==null?void 0:s.total)||0," row(s) selected."]}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsx(M.MyPagination,{onPageChange:x=>l==null?void 0:l({...p,page:x}),currentPage:s==null?void 0:s.page,totalPages:s==null?void 0:s.totalPages})})]})]})};exports.DataTable=oe;exports.MyTable=W;