@instincthub/react-ui 0.1.32 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regenerator as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as l,useRef as s,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import g from"@mui/icons-material/ExpandMoreOutlined";import v from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as P,API_HOST_URL as x}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var w=l(function(l,w){var k,C,S=l.token,E=l.columns,j=l.defaultData,R=l.endpointPath,O=l.initialParams,M=void 0===O?{}:O,A=l.searchParams,F=l.dataAdapter,H=l.title,L=l.emptyStateMessage,_=void 0===L?"No data available":L,D=l.emptyStateIcon,I=void 0===D?i(f,{}):D,T=l.actions,U=l.showSearch,B=void 0===U||U,G=l.searchPlaceholder,J=void 0===G?"Search...":G,V=l.searchDebounceMs,W=void 0===V?1e3:V,q=l.enableSorting,z=void 0===q||q,K=l.enableExport,Q=void 0!==K&&K,X=l.exportOptions,Y=void 0===X?{csv:!0}:X,Z=l.rowsPerPageOptions,$=void 0===Z?[10,25,50,100]:Z,ee=l.defaultRowsPerPage,te=void 0===ee?10:ee,ne=l.onRowClick,re=l.onFetchError,ae=l.expandable,ie=void 0!==ae&&ae,oe=l.renderExpandedRow,ce=l.keyExtractor,le=void 0===ce?function(e){return JSON.stringify(e)}:ce,se=l.stickyHeader,ue=void 0!==se&&se,de=l.maxHeight,he=l.hideHeaderOnMobile,pe=void 0!==he&&he,be=l.showRowNumbers,me=void 0!==be&&be,fe=l.rowNumberStartFrom,ge=void 0===fe?1:fe,ve=s(!0),Ne=s(null),Pe=u(j||[]),xe=e(Pe,2),ye=xe[0],we=xe[1],ke=u(!0),Ce=e(ke,2),Se=Ce[0],Ee=Ce[1],je=u(null),Re=e(je,2),Oe=Re[0],Me=Re[1],Ae=u({totalCount:0,currentPage:1,perPage:te,totalPages:0}),Fe=e(Ae,2),He=Fe[0],Le=Fe[1],_e=u(t({page:1,limit:te},M)),De=e(_e,2),Ie=De[0],Te=De[1],Ue=u([]),Be=e(Ue,2),Ge=Be[0],Je=Be[1],Ve=u(M.search||""),We=e(Ve,2),qe=We[0],ze=We[1],Ke=d(y.exports.debounce(function(e){Te(function(n){return t(t({},n),{},{search:e,page:1})})},W),[]),Qe={data:j||[],pagination:{totalCount:null===(k=j||[])||void 0===k?void 0:k.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},Xe=d(function(){var t=r(a().m(function t(n){var r,i,o,c,l,s,u;return a().w(function(t){for(;;)switch(t.p=t.n){case 0:if(Ee(!0),t.p=1,R){t.n=2;break}return t.a(2,Qe);case 2:return r=new URLSearchParams({limit:n.limit.toString(),offset:((n.page-1)*n.limit).toString()}),n.search&&r.append("search",n.search),n.sort&&(i="desc"===n.direction?"-":"",r.append("ordering","".concat(i).concat(n.sort))),A&&Object.entries(A).forEach(function(t){var n=e(t,2),a=n[0],i=n[1];null!=i&&""!==i&&r.append(a,String(i))}),o=P("GET",null,S),c="".concat(x).concat(R,"?").concat(r.toString()),t.n=3,fetch(c,o);case 3:return l=t.v,t.n=4,l.json();case 4:return s=t.v,t.a(2,{data:s.results,pagination:{totalCount:s.count,currentPage:Math.floor(parseInt(new URLSearchParams(s.next).get("offset")||"0")/n.limit),perPage:n.limit,totalPages:Math.ceil(s.count/n.limit)},links:{next:s.next,previous:s.previous}});case 5:throw t.p=5,u=t.v,console.error("Error fetching program courses:",u),u;case 6:return t.p=6,Ee(!1),t.f(6);case 7:return t.a(2)}},t,null,[[1,5,6,7]])}));return function(e){return t.apply(this,arguments)}}(),[A]),Ye=d(function(e){var t=e.target.value;ze(t),Ke(t)},[Ke]),Ze=d(function(e){Te(function(n){return t(t({},n),{},{page:e})})},[]),$e=d(function(e){Te(function(n){return t(t({},n),{},{page:1,limit:e})})},[]),et=d(function(e){if(z&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Te(function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})})}},[z]),tt=d(function(){Te(function(e){return t({},e)})},[]);h(w,function(){return{refresh:tt}},[tt]);var nt=d(function(){var e=r(a().m(function e(r){var i,o,c,l,s,u,d,h,p,b,m;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(Q){e.n=1;break}return e.a(2);case 1:return e.p=1,Ee(!0),i=t(t({},Ie),{},{page:1,limit:1e3,export:r}),e.n=2,Xe(i);case 2:(o=e.v)&&(c=F?F(o).data:o.data,l=Y.fileName||"table-export","csv"===r&&(s=[].concat(n(me?["#"]:[]),n(E.filter(function(e){return"string"==typeof e.accessor}).map(function(e){return e.header}))),u=c.map(function(e,t){return[].concat(n(me?[String(t+ge)]:[]),n(E.filter(function(e){return"string"==typeof e.accessor}).map(function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")}))).join(",")}),d=[s.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(l,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.n=4;break;case 3:e.p=3,m=e.v,console.error("Export error:",m),re&&re(m);case 4:return e.p=4,Ee(!1),e.f(4);case 5:return e.a(2)}},e,null,[[1,3,4,5]])}));return function(t){return e.apply(this,arguments)}}(),[E,Ie,Q,Y,F,re]),rt=d(function(e,t){t.stopPropagation(),Je(function(t){return t.includes(e)?t.filter(function(t){return t!==e}):[].concat(n(t),[e])})},[]);return p(function(){var e=!0,t=function(){var t=r(a().m(function t(){var n,r,i;return a().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,Ee(!0),t.n=1,Xe(Ie);case 1:n=t.v,e&&(F?(r=F(n),we(r.data),r.pagination&&Le(r.pagination)):n&&(we(n.data),n.pagination&&Le(n.pagination)),Me(null)),t.n=3;break;case 2:t.p=2,i=t.v,console.error("Error fetching data:",i),e&&(Me(i),re&&re(i));case 3:return t.p=3,e&&(Ee(!1),ve.current=!1),t.f(3);case 4:return t.a(2)}},t,null,[[0,2,3,4]])}));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}},[Ie,F,re]),p(function(){A&&!ve.current&&Te(function(e){return t({},e)})},[A]),Se&&ve.current?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):Oe&&!Se&&0===(ye||[]).length?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:tt,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:Ne,children:[(H||T||B||Q)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:H&&i("h2",{children:H})}),o("div",{className:"ihub-table-controls",children:[B&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:J,value:qe,onChange:Ye,className:"ihub-search-input"}),Se&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),Q&&o("div",{className:"ihub-export-buttons",children:[Y.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return nt("csv")},disabled:Se,children:[i(b,{}),"CSV"]}),Y.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return nt("excel")},disabled:Se,children:[i(b,{}),"Excel"]}),Y.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return nt("pdf")},disabled:Se,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:tt,disabled:Se,children:[i(m,{}),"Refresh"]}),T&&i("div",{className:"ihub-data-controls ihub-mb-0",children:T})]})]}),Se&&!ve.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(ue?"ihub-sticky-header":""),style:de?{maxHeight:de}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:pe?"ihub-hide-on-mobile":"",children:o("tr",{children:[me&&i("th",{style:{width:"60px",textAlign:"center"},children:"#"}),ie&&oe&&i("th",{style:{width:"40px"}}),E.map(function(e,t){return i("th",{className:"".concat(e.sortable&&z?"ihub-sortable-column":""," ").concat(Ie.sort===e.accessor?"ihub-sorted-".concat(Ie.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&z?et(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&z&&i("span",{className:"ihub-sort-icon",children:Ie.sort===e.accessor&&"asc"===Ie.direction?"▲":Ie.sort===e.accessor&&"desc"===Ie.direction?"▼":"⇅"})]})},t)})]})}),Se||0!==(ye||[]).length?i("tbody",{children:ye.map(function(e,t){var n=le(e),r=Ge.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return ne&&ne(e)},className:ne?"ihub-clickable-row":"",children:[me&&i("td",{style:{textAlign:"center",fontWeight:"500"},children:(He.currentPage-1)*He.perPage+t+ge}),ie&&oe&&i("td",{onClick:function(e){return rt(n,e)},children:i(r?v:g,{})}),E.map(function(t,n){return i("td",{"data-label":pe?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)})]}),ie&&oe&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(E||[]).length+1+(me?1:0),children:i("div",{className:"ihub-row-details",children:oe(e)})})})]},n)})}):""]}),Se||0!==(ye||[]).length?"":o("div",{className:"ihub-data-list-container",children:[T&&i("div",{className:"ihub-data-controls ihub-mb-0",children:T}),i("div",{className:"ihub-empty-state",children:o("div",{children:[I,i("p",{children:_})]})})]})]}),He&&He.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(He.currentPage-1)*He.perPage+1," to"," ",Math.min(He.currentPage*He.perPage,He.totalCount)," ","of ",He.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===He.currentPage||Se,onClick:function(){return Ze(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===He.currentPage||Se,onClick:function(){return Ze(He.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,He.totalPages)},function(e,t){var n;return n=He.totalPages<=5||He.currentPage<=3?t+1:He.currentPage>=He.totalPages-2?He.totalPages-4+t:He.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(He.currentPage===n?"ihub-active":""),onClick:function(){return Ze(Number(n))},disabled:Se,children:n},n)}),i("button",{className:"ihub-pagination-button",disabled:He.currentPage===He.totalPages||Se,onClick:function(){return Ze(He.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:He.currentPage===He.totalPages||Se,onClick:function(){return Ze(He.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:He.perPage,onChange:function(e){return $e(Number(e.target.value))},className:"ihub-rows-select",disabled:Se,children:$.map(function(e){return i("option",{value:e,children:e},e)})})]})]})]})});w.displayName="IHubTableServer";export{w as IHubTableServer,w as default};
1
+ import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regenerator as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as l,useRef as s,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import g from"@mui/icons-material/ExpandMoreOutlined";import v from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as P,API_HOST_URL as x}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var w=l(function(l,w){var k=l.token,C=l.columns,S=l.defaultData,E=l.endpointPath,j=l.initialParams,R=void 0===j?{}:j,O=l.searchParams,M=l.dataAdapter,A=l.title,F=l.emptyStateMessage,H=void 0===F?"No data available":F,L=l.emptyStateIcon,_=void 0===L?i(f,{}):L,D=l.actions,I=l.showSearch,T=void 0===I||I,U=l.searchPlaceholder,B=void 0===U?"Search...":U,G=l.searchDebounceMs,J=void 0===G?1e3:G,V=l.enableSorting,W=void 0===V||V,q=l.enableExport,z=void 0!==q&&q,K=l.exportOptions,Q=void 0===K?{csv:!0}:K,X=l.rowsPerPageOptions,Y=void 0===X?[10,25,50,100]:X,Z=l.defaultRowsPerPage,$=void 0===Z?10:Z,ee=l.onRowClick,te=l.onFetchError,ne=l.expandable,re=void 0!==ne&&ne,ae=l.renderExpandedRow,ie=l.keyExtractor,oe=void 0===ie?function(e){return JSON.stringify(e)}:ie,ce=l.stickyHeader,le=void 0!==ce&&ce,se=l.maxHeight,ue=l.hideHeaderOnMobile,de=void 0!==ue&&ue,he=l.showRowNumbers,pe=void 0!==he&&he,be=l.rowNumberStartFrom,me=void 0===be?1:be,fe=s(!0),ge=s(null),ve=u(S||[]),Ne=e(ve,2),Pe=Ne[0],xe=Ne[1],ye=u(!0),we=e(ye,2),ke=we[0],Ce=we[1],Se=u(null),Ee=e(Se,2),je=Ee[0],Re=Ee[1],Oe=u({totalCount:0,currentPage:1,perPage:$,totalPages:0}),Me=e(Oe,2),Ae=Me[0],Fe=Me[1],He=u(t({page:1,limit:$},R)),Le=e(He,2),_e=Le[0],De=Le[1],Ie=u([]),Te=e(Ie,2),Ue=Te[0],Be=Te[1],Ge=u(R.search||""),Je=e(Ge,2),Ve=Je[0],We=Je[1],qe=d(y.exports.debounce(function(e){De(function(n){return t(t({},n),{},{search:e,page:1})})},J),[]),ze=(S||[]).length,Ke={data:S||[],pagination:{totalCount:ze,currentPage:1,perPage:10,totalPages:Math.ceil(ze/10)||1},links:{next:null,previous:null}},Qe=d(function(){var t=r(a().m(function t(n){var r,i,o,c,l,s,u;return a().w(function(t){for(;;)switch(t.p=t.n){case 0:if(Ce(!0),t.p=1,E){t.n=2;break}return t.a(2,Ke);case 2:return r=new URLSearchParams({limit:n.limit.toString(),offset:((n.page-1)*n.limit).toString()}),n.search&&r.append("search",n.search),n.sort&&(i="desc"===n.direction?"-":"",r.append("ordering","".concat(i).concat(n.sort))),O&&Object.entries(O).forEach(function(t){var n=e(t,2),a=n[0],i=n[1];null!=i&&""!==i&&r.append(a,String(i))}),o=P("GET",null,k),c="".concat(x).concat(E,"?").concat(r.toString()),t.n=3,fetch(c,o);case 3:return l=t.v,t.n=4,l.json();case 4:return s=t.v,t.a(2,{data:s.results,pagination:{totalCount:s.count,currentPage:Math.floor(parseInt(new URLSearchParams(s.next).get("offset")||"0")/n.limit),perPage:n.limit,totalPages:Math.ceil(s.count/n.limit)},links:{next:s.next,previous:s.previous}});case 5:throw t.p=5,u=t.v,console.error("Error fetching program courses:",u),u;case 6:return t.p=6,Ce(!1),t.f(6);case 7:return t.a(2)}},t,null,[[1,5,6,7]])}));return function(e){return t.apply(this,arguments)}}(),[O]),Xe=d(function(e){var t=e.target.value;We(t),qe(t)},[qe]),Ye=d(function(e){De(function(n){return t(t({},n),{},{page:e})})},[]),Ze=d(function(e){De(function(n){return t(t({},n),{},{page:1,limit:e})})},[]),$e=d(function(e){if(W&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;De(function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})})}},[W]),et=d(function(){De(function(e){return t({},e)})},[]);h(w,function(){return{refresh:et}},[et]);var tt=d(function(){var e=r(a().m(function e(r){var i,o,c,l,s,u,d,h,p,b,m;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(z){e.n=1;break}return e.a(2);case 1:return e.p=1,Ce(!0),i=t(t({},_e),{},{page:1,limit:1e3,export:r}),e.n=2,Qe(i);case 2:(o=e.v)&&(c=M?M(o).data:o.data,l=Q.fileName||"table-export","csv"===r&&(s=[].concat(n(pe?["#"]:[]),n(C.filter(function(e){return"string"==typeof e.accessor}).map(function(e){return e.header}))),u=c.map(function(e,t){return[].concat(n(pe?[String(t+me)]:[]),n(C.filter(function(e){return"string"==typeof e.accessor}).map(function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")}))).join(",")}),d=[s.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(l,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.n=4;break;case 3:e.p=3,m=e.v,console.error("Export error:",m),te&&te(m);case 4:return e.p=4,Ce(!1),e.f(4);case 5:return e.a(2)}},e,null,[[1,3,4,5]])}));return function(t){return e.apply(this,arguments)}}(),[C,_e,z,Q,M,te]),nt=d(function(e,t){t.stopPropagation(),Be(function(t){return t.includes(e)?t.filter(function(t){return t!==e}):[].concat(n(t),[e])})},[]);return p(function(){var e=!0,t=function(){var t=r(a().m(function t(){var n,r,i;return a().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,Ce(!0),t.n=1,Qe(_e);case 1:n=t.v,e&&(M?(r=M(n),xe(r.data),r.pagination&&Fe(r.pagination)):n&&(xe(n.data),n.pagination&&Fe(n.pagination)),Re(null)),t.n=3;break;case 2:t.p=2,i=t.v,console.error("Error fetching data:",i),e&&(Re(i),te&&te(i));case 3:return t.p=3,e&&(Ce(!1),fe.current=!1),t.f(3);case 4:return t.a(2)}},t,null,[[0,2,3,4]])}));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}},[_e,M,te]),p(function(){O&&!fe.current&&De(function(e){return t({},e)})},[O]),ke&&fe.current?o("div",{className:"ihub-data-list-container",children:[A&&i("h2",{children:A}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):je&&!ke&&0===(Pe||[]).length?o("div",{className:"ihub-data-list-container",children:[A&&i("h2",{children:A}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:et,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:ge,children:[(A||D||T||z)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:A&&i("h2",{children:A})}),o("div",{className:"ihub-table-controls",children:[T&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:B,value:Ve,onChange:Xe,className:"ihub-search-input"}),ke&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),z&&o("div",{className:"ihub-export-buttons",children:[Q.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return tt("csv")},disabled:ke,children:[i(b,{}),"CSV"]}),Q.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return tt("excel")},disabled:ke,children:[i(b,{}),"Excel"]}),Q.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return tt("pdf")},disabled:ke,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:et,disabled:ke,children:[i(m,{}),"Refresh"]}),D&&i("div",{className:"ihub-data-controls ihub-mb-0",children:D})]})]}),ke&&!fe.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(le?"ihub-sticky-header":""),style:se?{maxHeight:se}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:de?"ihub-hide-on-mobile":"",children:o("tr",{children:[pe&&i("th",{style:{width:"60px",textAlign:"center"},children:"#"}),re&&ae&&i("th",{style:{width:"40px"}}),C.map(function(e,t){return i("th",{className:"".concat(e.sortable&&W?"ihub-sortable-column":""," ").concat(_e.sort===e.accessor?"ihub-sorted-".concat(_e.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&W?$e(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&W&&i("span",{className:"ihub-sort-icon",children:_e.sort===e.accessor&&"asc"===_e.direction?"▲":_e.sort===e.accessor&&"desc"===_e.direction?"▼":"⇅"})]})},t)})]})}),ke||0!==(Pe||[]).length?i("tbody",{children:Pe.map(function(e,t){var n=oe(e),r=Ue.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return ee&&ee(e)},className:ee?"ihub-clickable-row":"",children:[pe&&i("td",{style:{textAlign:"center",fontWeight:"500"},children:(Ae.currentPage-1)*Ae.perPage+t+me}),re&&ae&&i("td",{onClick:function(e){return nt(n,e)},children:i(r?v:g,{})}),C.map(function(t,n){return i("td",{"data-label":de?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)})]}),re&&ae&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(C||[]).length+1+(pe?1:0),children:i("div",{className:"ihub-row-details",children:ae(e)})})})]},n)})}):""]}),ke||0!==(Pe||[]).length?"":o("div",{className:"ihub-data-list-container",children:[D&&i("div",{className:"ihub-data-controls ihub-mb-0",children:D}),i("div",{className:"ihub-empty-state",children:o("div",{children:[_,i("p",{children:H})]})})]})]}),Ae&&Ae.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(Ae.currentPage-1)*Ae.perPage+1," to"," ",Math.min(Ae.currentPage*Ae.perPage,Ae.totalCount)," ","of ",Ae.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===Ae.currentPage||ke,onClick:function(){return Ye(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===Ae.currentPage||ke,onClick:function(){return Ye(Ae.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,Ae.totalPages)},function(e,t){var n;return n=Ae.totalPages<=5||Ae.currentPage<=3?t+1:Ae.currentPage>=Ae.totalPages-2?Ae.totalPages-4+t:Ae.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(Ae.currentPage===n?"ihub-active":""),onClick:function(){return Ye(Number(n))},disabled:ke,children:n},n)}),i("button",{className:"ihub-pagination-button",disabled:Ae.currentPage===Ae.totalPages||ke,onClick:function(){return Ye(Ae.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:Ae.currentPage===Ae.totalPages||ke,onClick:function(){return Ye(Ae.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:Ae.perPage,onChange:function(e){return Ze(Number(e.target.value))},className:"ihub-rows-select",disabled:ke,children:Y.map(function(e){return i("option",{value:e,children:e},e)})})]})]})]})});w.displayName="IHubTableServer";export{w as IHubTableServer,w as default};
2
2
  //# sourceMappingURL=IHubTableServer.js.map
@@ -8,7 +8,8 @@ interface IHubTableServerPropsType<T> {
8
8
  /** Token for authentication */
9
9
  token?: string | null;
10
10
  columns: TableColumnType<T>[];
11
- defaultData?: any[];
11
+ /** Default data to display before API fetch completes. Items should have an `id` field. */
12
+ defaultData?: T[];
12
13
  endpointPath: string;
13
14
  initialParams?: Partial<FetchParamsType>;
14
15
  /** External search parameters that trigger table refetch when changed */
@@ -89,7 +90,7 @@ interface IHubTableServerPropsType<T> {
89
90
  * ```
90
91
  * @prop {string} token - The token for authentication
91
92
  * @prop {TableColumnType<T>[]} columns - The columns of the table
92
- * @prop {any<T>[]} defaultData - The default data of the table
93
+ * @prop {T[]} defaultData - The default data to display before API fetch completes
93
94
  * @prop {string} endpointPath - The path to the API endpoint
94
95
  * @prop {Partial<FetchParamsType>} initialParams - The initial parameters for the API request
95
96
  * @prop {Record<string, any>} searchParams - External search parameters that trigger table refetch when changed
@@ -113,5 +114,11 @@ interface IHubTableServerPropsType<T> {
113
114
  *
114
115
  * @link https://github.com/instincthub/instincthub-react-ui/blob/main/src/__examples__/src/components/ui/TableServerExamples.tsx
115
116
  */
116
- export declare const IHubTableServer: React.ForwardRefExoticComponent<IHubTableServerPropsType<any> & React.RefAttributes<IHubTableServerRef>>;
117
+ interface IHubTableServerComponent {
118
+ <T extends object>(props: IHubTableServerPropsType<T> & {
119
+ ref?: React.Ref<IHubTableServerRef>;
120
+ }): React.ReactNode;
121
+ displayName?: string;
122
+ }
123
+ export declare const IHubTableServer: IHubTableServerComponent;
117
124
  export default IHubTableServer;
@@ -217,6 +217,36 @@ export interface DataResponseType {
217
217
  id: string;
218
218
  [key: string]: any;
219
219
  }
220
+ /**
221
+ * Type for IHubTableServer's defaultData prop.
222
+ * Use this to type your default data array items.
223
+ *
224
+ * @example
225
+ * ```tsx
226
+ * import type { IHubTableDefaultDataType } from "@instincthub/react-ui/types";
227
+ *
228
+ * interface Student extends IHubTableDefaultDataType {
229
+ * first_name: string;
230
+ * last_name: string;
231
+ * email: string;
232
+ * enrollment_date: string;
233
+ * }
234
+ *
235
+ * const defaultStudents: Student[] = [
236
+ * { id: "1", first_name: "Jane", last_name: "Doe", email: "jane@example.com", enrollment_date: "2024-01-15" },
237
+ * ];
238
+ *
239
+ * <IHubTableServer<Student>
240
+ * columns={columns}
241
+ * defaultData={defaultStudents}
242
+ * endpointPath="students/"
243
+ * />
244
+ * ```
245
+ */
246
+ export interface IHubTableDefaultDataType {
247
+ id: string | number;
248
+ [key: string]: any;
249
+ }
220
250
  export interface SubMenuItemType {
221
251
  title: string;
222
252
  href: string;