nextuiq
Version:
NextUIQ is a modern, lightweight, and developer-friendly UI component library for React and Next.js. Built with TypeScript and Tailwind CSS, it offers customizable, accessible, and performance-optimized components with built-in dark mode, theme customizat
2 lines (1 loc) • 720 B
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react");exports.useTable=({data:t,itemsPerPage:a=5,searchFields:r=[]})=>{const[s,l]=e.useState(""),[o,i]=e.useState("all"),[n,u]=e.useState("all"),[c,g]=e.useState(1),d=e.useMemo((()=>t.filter((e=>r.some((t=>String(e[t]).toLowerCase().includes(s.toLowerCase())))&&("all"===o||e.status===o)&&("all"===n||e.role===n)))),[t,s,o,n,r]),S=Math.ceil(d.length/a),h=(c-1)*a,m=d.slice(h,h+a);return{searchTerm:s,setSearchTerm:l,statusFilter:o,setStatusFilter:i,roleFilter:n,setRoleFilter:u,currentPage:c,setCurrentPage:g,filteredData:d,paginatedData:m,totalPages:S,startIndex:h,endIndex:Math.min(h+a,d.length),totalItems:d.length}};
;