UNPKG

ivt

Version:

Ivt Components Library

3 lines (2 loc) 17.4 kB
import*as e from"react";import t,{forwardRef as a,createElement as l}from"react";import{c as n}from"../chunks/utils-C-nkZ_Ir.mjs";import{C as r}from"../chunks/chevron-down-CxCeX9iY.mjs";import{C as s}from"../chunks/check-PTeDoR8O.mjs";import{P as m,a as c,b as o}from"../chunks/popover-DLVlIkos.mjs";import{B as i}from"../chunks/button-CWf6NSDH.mjs";import{C as u,b as d,c as g,d as p,e as h,f,S as E}from"../chunks/command-uwBExuyh.mjs";import{I as w}from"../chunks/input-DEBRXIRa.mjs";import{S as x,h as N,i as b,a as y,c as k}from"../chunks/select-BKDPXdmT.mjs";import{C as v}from"../chunks/chevron-left-uN3-P_oe.mjs";import{C}from"../chunks/chevron-right-2gS0EXq0.mjs";import{c as S,f as j}from"../chunks/pagination-BaeImhHS.mjs";import{S as z}from"../chunks/skeleton-CkxzXYw_.mjs";import{e as M,f as P,T as A,a as F,d as I,b as L}from"../chunks/table-70kXrlUN.mjs";import{c as R}from"../chunks/createLucideIcon-D1jKv6AP.mjs";import{S as V,b as $}from"../chunks/sortable-DQWkBD0j.mjs";import"../chunks/bundle-mjs-DHbvkKp4.mjs";import"../chunks/index-DVnblQ-a.mjs";import"../chunks/index-C-j8pU3U.mjs";import"../chunks/index-Dr5ObK3L.mjs";import"react/jsx-runtime";import"../chunks/index-C_Mk3Jfk.mjs";import"../chunks/index-DiPp8h7C.mjs";import"react-dom";import"@radix-ui/react-slot";import"../chunks/index-DSUHCtxx.mjs";import"../chunks/index-0-u0cdz8.mjs";import"../chunks/index-lVEpnR8T.mjs";import"../chunks/tslib.es6-Bvey-QDo.mjs";import"../chunks/index-UQBMY2z8.mjs";import"../chunks/index-DtZD7YmJ.mjs";import"../chunks/index-CnLJ482V.mjs";import"../chunks/index-1xuBLrml.mjs";import"../chunks/index-BOUg6o32.mjs";import"class-variance-authority";import"../chunks/index-D1EuiH1M.mjs";import"../chunks/dialog-Dxotsves.mjs";import"../chunks/x-COocN1ks.mjs";import"@radix-ui/react-select";const O=R("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),_=R("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);function D({table:t,transformColumnName:a}){const l=e.useRef(null);return e.createElement(m,{modal:!0},e.createElement(c,{asChild:!0},e.createElement(i,{ref:l,"aria-label":"Toggle columns",variant:"outline",className:"text-muted-foreground hover:text-muted-foreground w-full max-w-[12.5rem] items-center justify-between bg-inherit px-3 py-2 hover:bg-inherit"},"Colunas",e.createElement(r,{className:"h-4 w-4"}))),e.createElement(o,{align:"end",className:"w-44 p-0",onCloseAutoFocus:()=>l.current?.focus()},e.createElement(u,null,e.createElement(d,{placeholder:"Pesquisar colunas..."}),e.createElement(g,null,e.createElement(p,null,"Nenhuma coluna encontrada."),e.createElement(h,null,t.getAllColumns().filter(e=>void 0!==e.accessorFn&&e.getCanHide()).map(t=>e.createElement(f,{key:t.id,onSelect:()=>t.toggleVisibility(!t.getIsVisible())},e.createElement("span",{className:"truncate"},a?a(t.id):t.id),e.createElement(s,{className:n("ml-auto size-4 shrink-0",t.getIsVisible()?"opacity-100":"opacity-0")}))))))))}function H({table:e,keySearch:t,placeholder:a}){return React.createElement("div",{className:"relative w-full max-w-sm"},React.createElement(E,{className:"text-muted-foreground absolute top-3 left-3 h-4 w-4"}),React.createElement(w,{placeholder:a,value:e.getColumn(t)?.getFilterValue()??"",onChange:a=>e.getColumn(t)?.setFilterValue(a.target.value),className:"w-full pl-8 xl:w-80"}))}var T=["color"],B=a(function(e,t){var a=e.color,n=void 0===a?"currentColor":a,r=function(e,t){if(null==e)return{};var a,l,n={},r=Object.keys(e);for(l=0;l<r.length;l++)a=r[l],t.indexOf(a)>=0||(n[a]=e[a]);return n}(e,T);return l("svg",Object.assign({width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg"},r,{ref:t}),l("path",{d:"M4.93179 5.43179C4.75605 5.60753 4.75605 5.89245 4.93179 6.06819C5.10753 6.24392 5.39245 6.24392 5.56819 6.06819L7.49999 4.13638L9.43179 6.06819C9.60753 6.24392 9.89245 6.24392 10.0682 6.06819C10.2439 5.89245 10.2439 5.60753 10.0682 5.43179L7.81819 3.18179C7.73379 3.0974 7.61933 3.04999 7.49999 3.04999C7.38064 3.04999 7.26618 3.0974 7.18179 3.18179L4.93179 5.43179ZM10.0682 9.56819C10.2439 9.39245 10.2439 9.10753 10.0682 8.93179C9.89245 8.75606 9.60753 8.75606 9.43179 8.93179L7.49999 10.8636L5.56819 8.93179C5.39245 8.75606 5.10753 8.75606 4.93179 8.93179C4.75605 9.10753 4.75605 9.39245 4.93179 9.56819L7.18179 11.8182C7.35753 11.9939 7.64245 11.9939 7.81819 11.8182L10.0682 9.56819Z",fill:n,fillRule:"evenodd",clipRule:"evenodd"}))});function q(t,a){return t?function(e){return"function"==typeof e&&(()=>{const t=Object.getPrototypeOf(e);return t.prototype&&t.prototype.isReactComponent})()}(l=t)||"function"==typeof l||function(e){return"object"==typeof e&&"symbol"==typeof e.$$typeof&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}(l)?e.createElement(t,a):t:null;var l}function W({table:e,pageSizeOptions:a=[20,30,50,100,200],dataLabel:l="Fundos"}){const n=a[0],r=e.getState().pagination.pageIndex+1,s=e.getRowCount(),m=Math.ceil(s/e.getState().pagination.pageSize);return t.createElement("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2"},t.createElement("div",{className:"text-muted-foreground flex gap-1 text-sm"},t.createElement("p",{className:"ml-2"},"Mostrando ",e.getRowModel().rows.length.toLocaleString()," de ",s," ",l,".")),t.createElement("div",{className:"flex flex-wrap items-center justify-between gap-2 gap-y-4"},t.createElement(x,{value:String(e.getState().pagination.pageSize)||String(n),onValueChange:t=>e.setPageSize(Number(t))},t.createElement(N,{className:"w-fit"},t.createElement(b,{placeholder:`Mostrar ${e.getState().pagination.pageSize||n}`})),t.createElement(y,null,s&&(0===s||s<n)?t.createElement(k,{value:String(n)},"Mostrar ",n):t.createElement(t.Fragment,null,a.map(e=>t.createElement(k,{key:e,value:String(e)},"Mostrar ",e))))),t.createElement("div",{className:"flex flex-wrap gap-2 gap-y-4"},t.createElement(i,{variant:"ghost",onClick:()=>e.previousPage(),disabled:!e.getCanPreviousPage(),"aria-label":"Ir para página anterior",className:"gap-1"},t.createElement(v,{className:"size-4"}),"Anterior"),t.createElement("div",{className:"flex gap-2"},(()=>{const a=[];if(m<=3)for(let l=1;l<=m;l++)a.push(t.createElement(i,{variant:r===l?"outline":"ghost",key:l,onClick:()=>e.setPageIndex(l-1),className:"size-9"},l));else{a.push(t.createElement(i,{variant:1===r?"outline":"ghost",key:1,onClick:()=>e.setPageIndex(0),className:"size-9"},"1"));const l=Math.max(2,Math.min(r,m-2)),n=Math.min(m-1,l+3-2);l>2&&a.push(t.createElement(S,{key:"ellipsis-start",className:"list-none"},t.createElement(j,null)));for(let s=l;s<=n;s++)a.push(t.createElement(i,{variant:r===s?"outline":"ghost",key:s,onClick:()=>e.setPageIndex(s-1),className:"size-9"},s));n<m-1&&a.push(t.createElement(S,{key:"ellipsis-end",className:"list-none"},t.createElement(j,null))),a.push(t.createElement(i,{variant:r===m?"outline":"ghost",key:m,onClick:()=>e.setPageIndex(m-1)},m))}return a})()),t.createElement(i,{variant:"ghost",onClick:()=>e.nextPage(),disabled:!e.getCanNextPage(),"aria-label":"Ir para próxima página",className:"gap-1"},"Próximo",t.createElement(C,{className:"size-4"})))))}const Z=({className:e})=>t.createElement("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2"},t.createElement(z,{className:n("h-5 w-40",e)}),t.createElement("div",{className:"flex flex-wrap items-center justify-between gap-2 gap-y-4"},t.createElement(z,{className:n("h-10 w-28",e)}),t.createElement(z,{className:n("h-9 w-[16rem]",e)})));function K(e){const{columnCount:a,rowCount:l=8,cellWidths:n=["auto"],shrinkZero:r=!1}=e;return t.createElement(t.Fragment,null,Array.from({length:l}).map((e,l)=>t.createElement(M,{key:`row-${String(l)}`,className:"hover:bg-transparent"},Array.from({length:a}).map((e,a)=>t.createElement(P,{key:`cell-${String(l)}-${a}`,style:{width:n[a],minWidth:r?n[a]:"auto"}},t.createElement(z,{className:"h-6 w-full"}))))))}const G=({table:e,columns:a,isLoadingTable:l,loadingContent:r,setQueryParams:s,dataLabel:m,actionColumns:c=[],messageEmpty:o=t.createElement(t.Fragment,null,"Sem resultados"),dividingColumnKey:i,pageSizeOptions:u,className:d,scrollMaxHeightClass:g="sm:max-h-[calc(100vh-300px)]",isScrollable:p=!1,fixedHeader:h=!1,showPagination:f=!0})=>{const E=Number(e.getState().pagination.pageIndex).toString(),w=Number(e.getState().pagination.pageSize).toString(),x=e.getState().sorting;t.useEffect(()=>{if(!s)return;const e={sortingBy:"",order:""};x.length>0&&(e.sortingBy=x[0].id,e.order=x[0].desc?"DESC":"ASC"),s(t=>({...t,pageSize:w,page:E,...e}))},[E,w,s,x]);const N=e.getRowModel().rows.length>1||l;return t.createElement(t.Fragment,null,t.createElement("div",{className:n("bg-background mx-1 h-full w-full rounded-md border whitespace-nowrap",d)},t.createElement("div",{className:n("relative w-full overflow-auto",N&&"force-min-height",p&&g&&g)},t.createElement(A,null,t.createElement(F,{className:n(h&&"bg-background sticky top-0 z-10 shadow-[0_1px_0_hsl(240_6%_90%)]")},e.getHeaderGroups().map(e=>t.createElement(M,{key:e.id},e.headers.map(e=>{const{column:{id:a}}=e,l=["actions",...c].includes(a);return t.createElement(I,{className:n(i?.includes(a)?"border-r":"","static"),key:e.id},e.isPlaceholder?null:t.createElement(t.Fragment,null,t.createElement("div",{className:!l&&e.column.getCanSort()?"flex w-fit items-center justify-start cursor-pointer gap-1 font-medium":"",onClick:l?void 0:e.column.getToggleSortingHandler()},q(e.column.columnDef.header,e.getContext()),(!l&&e.column.getCanSort()&&{asc:t.createElement(O,{className:"h-3.5 w-3.5"}),desc:t.createElement(_,{className:"h-3.5 w-3.5"}),false:t.createElement(B,{className:"h-4 w-4"})}[e.column.getIsSorted()])??t.createElement(O,{className:"h-3.5 w-3.5"}))))})))),t.createElement(L,null,l&&!r?t.createElement(K,{columnCount:e.getAllColumns().length}):l&&r?t.createElement(P,{colSpan:a.length,className:"h-24 text-center"},r):0===e.getRowModel().rows.length?t.createElement(M,null,t.createElement(P,{colSpan:a.length,className:"h-24 text-center"},t.createElement("span",{className:"inline-block max-w-[30rem] text-wrap break-words"},o))):e.getRowModel().rows.map((e,a)=>{const l=e.id??String(a);return t.createElement(M,{key:l,"data-state":e.getIsSelected()&&"selected",className:"even:bg-body/50"},e.getVisibleCells().map(e=>t.createElement(P,{key:e.id,className:n("p-2 py-1",i?.includes(e.column.id)&&"border-r")},q(e.column.columnDef.cell,e.getContext()))))}))))),p||!f?null:l?t.createElement(Z,null):t.createElement(W,{table:e,dataLabel:m,pageSizeOptions:u}))};function Q(e){const{columnCount:a,rowCount:l=10,searchableColumnCount:r=0,filterableColumnCount:s=0,showViewOptions:m=!0,cellWidths:c=["auto"],withPagination:o=!0,shrinkZero:i=!1,className:u,...d}=e;return t.createElement("div",{className:n("w-full space-y-2.5 overflow-auto",u),...d},t.createElement("div",{className:"flex w-full items-center justify-between space-x-2 overflow-auto p-1"},t.createElement("div",{className:"flex flex-1 items-center space-x-2"},r>0?Array.from({length:r}).map((e,a)=>t.createElement(z,{key:`${String(a)}`,className:"h-7 w-40 lg:w-60"})):null,s>0?Array.from({length:s}).map((e,a)=>t.createElement(z,{key:`${String(a)}`,className:"h-7 w-[4.5rem] border-dashed"})):null),m?t.createElement(z,{className:"ml-auto hidden h-7 w-[4.5rem] lg:flex"}):null),t.createElement("div",{className:"rounded-md border"},t.createElement(A,null,t.createElement(F,null,Array.from({length:1}).map((e,l)=>t.createElement(M,{key:`${String(l)}`,className:"hover:bg-transparent"},Array.from({length:a}).map((e,a)=>t.createElement(I,{key:`${String(a)}`,style:{width:c[a],minWidth:i?c[a]:"auto"}},t.createElement(z,{className:"h-6 w-full"})))))),t.createElement(L,null,Array.from({length:l}).map((e,l)=>t.createElement(M,{key:`${String(l)}`,className:"hover:bg-transparent"},Array.from({length:a}).map((e,a)=>t.createElement(P,{key:`${String(a)}`,style:{width:c[a],minWidth:i?c[a]:"auto"}},t.createElement(z,{className:"h-6 w-full"})))))))),o?t.createElement("div",{className:"flex w-full items-center justify-between gap-4 overflow-auto p-1 sm:gap-8"},t.createElement(z,{className:"h-7 w-40 shrink-0"}),t.createElement("div",{className:"flex items-center gap-4 sm:gap-6 lg:gap-8"},t.createElement("div",{className:"flex items-center space-x-2"},t.createElement(z,{className:"h-7 w-24"}),t.createElement(z,{className:"h-7 w-[4.5rem]"})),t.createElement("div",{className:"flex items-center justify-center text-sm font-medium"},t.createElement(z,{className:"h-7 w-20"})),t.createElement("div",{className:"flex items-center space-x-2"},t.createElement(z,{className:"hidden size-7 lg:block"}),t.createElement(z,{className:"size-7"}),t.createElement(z,{className:"size-7"}),t.createElement(z,{className:"hidden size-7 lg:block"})))):null)}function U({table:e,uniqueStatusValues:a,renderStatusMessage:l,className:s}){const h=t.useRef(null),E=e.getColumn("status")?.getFilterValue();return t.createElement(m,{modal:!0},t.createElement(c,{asChild:!0},t.createElement(i,{ref:h,"aria-label":"Filtre por status",variant:"outline",className:n("border-input text-muted-foreground ring-offset-background placeholder:text-muted-foreground hover:text-muted-foreground focus:ring-ring flex h-10 w-full max-w-60 items-center justify-between rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-sm hover:bg-inherit focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",s)},E?l(E):"Todos os status",t.createElement(r,{className:"h-4 w-4"}))),t.createElement(o,{align:"end",className:"w-44 p-0",onCloseAutoFocus:()=>h.current?.focus()},t.createElement(u,null,t.createElement(d,{placeholder:"Pesquisar status..."}),t.createElement(g,null,t.createElement(p,null,"Nenhum status encontrado."),t.createElement(f,{key:"all",onSelect:()=>e.getColumn("status")?.setFilterValue(void 0)},t.createElement("span",{className:"truncate"},"Todos os status")),a.map(a=>{if(!a)return null;const n=l(a);return t.createElement(f,{key:`${String(a)}`,onSelect:()=>e.getColumn("status")?.setFilterValue(a)},t.createElement("span",{className:"truncate"},n))})))))}const J=(e,t)=>{if("function"==typeof t)return t(e);if(Array.isArray(t)){for(const a of t)if(void 0!==e[a]&&null!==e[a])return e[a];return""}return e[t]},X=({table:e,columns:a,isLoadingTable:l,loadingContent:r,setQueryParams:s,dataLabel:m,actionColumns:c=[],data:o,messageEmpty:i=t.createElement(t.Fragment,null,"Sem resultados"),onDataChange:u,rowKey:d,dividingColumnKey:g,pageSizeOptions:p,className:h,scrollMaxHeightClass:f="sm:max-h-[calc(100vh-300px)]",isScrollable:E=!1,fixedHeader:w=!1,showPagination:x=!0})=>{const N=Number(e.getState().pagination.pageIndex).toString(),b=Number(e.getState().pagination.pageSize).toString(),y=e.getState().sorting,[k,v]=t.useState(o);t.useEffect(()=>{v(o)},[o]),t.useEffect(()=>{if(!s)return;const e={sortingBy:"",order:""};y.length>0&&(e.sortingBy=y[0].id,e.order=y[0].desc?"DESC":"ASC"),s(t=>({...t,pageSize:b,page:N,...e}))},[N,b,s,y]);const C=e.getRowModel().rows.length>1||l;return t.createElement(t.Fragment,null,t.createElement("div",{className:n("bg-background mx-1 h-full w-full rounded-md border whitespace-nowrap",h)},t.createElement("div",{className:n("relative w-full overflow-auto",C&&"force-min-height",E&&f&&f)},t.createElement(A,null,t.createElement(F,{className:n(w&&"bg-background sticky top-0 z-10 shadow-[0_1px_0_hsl(240_6%_90%)]")},e.getHeaderGroups().map(e=>t.createElement(M,{key:e.id},e.headers.map(e=>{const{column:{id:a}}=e,l=["actions",...c].includes(a);return t.createElement(I,{className:g?.includes(a)?"border-r":"",key:e.id},e.isPlaceholder?null:t.createElement(t.Fragment,null,t.createElement("div",{className:!l&&e.column.getCanSort()?"flex w-fit items-center justify-start cursor-pointer gap-1 font-medium":"",onClick:l?void 0:e.column.getToggleSortingHandler()},q(e.column.columnDef.header,e.getContext()),(!l&&e.column.getCanSort()&&{asc:t.createElement(O,{className:"h-3.5 w-3.5"}),desc:t.createElement(_,{className:"h-3.5 w-3.5"}),false:t.createElement(B,{className:"h-4 w-4"})}[e.column.getIsSorted()])??t.createElement(O,{className:"h-3.5 w-3.5"}))))})))),t.createElement(L,null,t.createElement(V,{value:k.map(e=>({...e,id:J(e,d)})),onValueChange:e=>{v(e),u?.(e)}},l&&!r?t.createElement(K,{columnCount:e.getAllColumns().length}):l&&r?t.createElement(P,{colSpan:a.length,className:"h-24 text-center"},r):0===e.getRowModel().rows.length?t.createElement(M,null,t.createElement(P,{colSpan:a.length,className:"h-24 text-center"},t.createElement("span",{className:"inline-block max-w-[30rem] text-wrap break-words"},i))):e.getRowModel().rows.map(e=>{const a=e.original,l=J(a,d);return t.createElement($,{key:e.id,value:l,asChild:!0},t.createElement(M,{"data-state":e.getIsSelected()&&"selected",className:"even:bg-body/50"},e.getVisibleCells().map(e=>t.createElement(P,{key:e.id,className:n("p-2 py-1",g?.includes(e.column.id)&&"border-r")},q(e.column.columnDef.cell,e.getContext())))))})))))),E||!x?null:l?t.createElement(Z,null):t.createElement(W,{table:e,dataLabel:m,pageSizeOptions:p}))};export{G as DataTableMainFrame,X as DataTableMainFrameSortable,W as DataTablePagination,Z as DataTablePaginationSkeleton,K as DataTableRowSkeleton,H as DataTableSearch,Q as DataTableSkeleton,U as DataTableStatus,D as DataTableViewOptions}; //# sourceMappingURL=index.mjs.map