@verifiedinc-public/shared-ui-elements 11.1.0 → 11.1.1
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 +1 @@
|
|
|
1
|
-
"use strict";import{useState as Y,useRef as x,useMemo as _,useEffect as
|
|
1
|
+
"use strict";import{useState as Y,useRef as x,useMemo as _,useEffect as Xe}from"react";import{useReactTable as en,getPaginationRowModel as nn,getSortedRowModel as on,getCoreRowModel as tn}from"@tanstack/react-table";import{useVirtualizer as an}from"@tanstack/react-virtual";import{Box as ln,TableContainer as rn,Table as sn}from"@mui/material";import{useBidirectionalScroll as dn}from"../../hooks/useBidirectionalScroll.mjs";import{DataTableProvider as un}from"./DataTable.context.mjs";import{useControllableState as u,useHeaderRowTops as gn,useStickyHeaderHeight as mn,usePinnedOffsets as fn}from"./DataTable.hooks.mjs";import{applySearch as hn,applyFilters as cn,EMPTY_FILTERS as pn}from"./DataTable.filters.mjs";import{inferColumns as bn,applyMetaWidthsToSizes as Cn,getColumnMeta as q,measureRowGroup as Rn}from"./DataTable.utils.mjs";import{DataTableBody as wn}from"./DataTableBody.mjs";import{DataTableFooter as Sn}from"./DataTableFooter.mjs";import{DataTableHead as Pn}from"./DataTableHead.mjs";import{DataTablePanels as vn}from"./DataTablePanels.mjs";import{DataTableToolbar as yn}from"./DataTableToolbar.mjs";import{jsx as r,jsxs as A}from"react/jsx-runtime";const xn=25,Ln=[10,25,50,100],zn=53,Mn={},Tn={left:[],right:[]},J=()=>{};function Hn({data:a,columns:L,getRowId:z,renderRow:U,initialSorting:Z=[],sorting:Q,onSortingChange:X,manualSorting:M=!1,initialPageSize:ee=xn,pageSizeOptions:ne=Ln,pagination:oe,onPaginationChange:te,manualPagination:g=!1,rowCount:c,disableSorting:p=!1,disablePagination:b=!1,bidirectionalScroll:o,enableColumnResizing:s=!1,enableColumnMenu:ie=!1,enableColumnPinning:m=!1,showToolbar:ae=!1,enableExport:le=!1,exportFilename:re="data",initialFilters:se=pn,filters:de,onFiltersChange:ue,manualFiltering:T=!1,initialSearch:ge="",search:me,onSearchChange:fe,initialColumnVisibility:H={},columnVisibility:he,onColumnVisibilityChange:ce,initialColumnPinning:pe=Tn,columnPinning:be,onColumnPinningChange:Ce,footerLeft:Re,estimateRowHeight:we=zn,minWidth:Se=650,maxHeight:Pe=800,tableLayout:C="auto",icons:ve=Mn,emptyMessage:ye="No data to display.",isLoading:xe=!1,renderLoading:Le}){const[ze,Me]=u(Z,Q,X),[Te,He]=u({pageIndex:0,pageSize:ee},oe,te),[R,Oe]=u(se,de,ue),[w,Ve]=u(ge,me,fe),[Fe,Ee]=u(H,he,ce),[Ie,Be]=u(pe,be,Ce),[S,De]=Y({}),O=s&&Object.keys(S).length>0,[Ne,f]=Y(null),ke=()=>{f(null)},V=x(null),F=x(null),E=(e,n)=>{if(n){const d=n.getBoundingClientRect();return{anchorPosition:{top:d.bottom,left:d.right},transformHorizontal:"right"}}const t=e.getBoundingClientRect();return{anchorPosition:{top:t.bottom,left:t.left},transformHorizontal:"left"}},$e=(e,n)=>{f({type:"filter",columnId:e,...E(n,V.current)})},We=e=>{f({type:"manageColumns",...E(e,F.current)})},P=x(null),l=_(()=>{const e=L??bn(a);return s?Cn(e):e},[L,a,s]),je=_(()=>T?a:hn(cn(a,R,l),w,l),[a,R,w,T,l]),i=en({data:je,columns:l,state:{...p?{}:{sorting:ze},...b?{}:{pagination:Te},...m?{columnPinning:Ie}:{},columnVisibility:Fe,columnSizing:S},initialState:{columnVisibility:H},onSortingChange:Me,onPaginationChange:He,onColumnVisibilityChange:Ee,onColumnPinningChange:Be,onColumnSizingChange:De,enableColumnPinning:m,columnResizeMode:"onChange",enableColumnResizing:s,getCoreRowModel:tn(),defaultColumn:{enableSorting:!1},enableSorting:!p,manualSorting:M,...p||M?{}:{getSortedRowModel:on()},manualPagination:g,...g&&c!==void 0?{rowCount:c}:{},getRowCanExpand:()=>!0,...b||g?{}:{getPaginationRowModel:nn()},...z?{getRowId:z}:{}}),v=i.getRowModel().rows,Ge=g?c??a.length:i.getPrePaginationRowModel().rows.length,Ke=i.getVisibleLeafColumns().length||1,Ye=s&&i.getVisibleLeafColumns().some(e=>{var n;return typeof((n=q(e.columnDef.meta))==null?void 0:n.width)=="number"}),_e=O||Ye,y=m?i.getLeftVisibleLeafColumns().map(e=>e.id):[],I=m?i.getRightVisibleLeafColumns().map(e=>e.id):[],B=i.getHeaderGroups().length,{headerRowRefs:D,headerRowTops:qe}=gn(B,l),N=o!==void 0,Ae=mn(N,D,B,l),{headerCellRefs:k,pinnedOffsets:$}=fn(y,I,l),Je=(e,n)=>{var t;for(const d of i.getVisibleLeafColumns())if(S[d.id]===void 0){const K=(t=k.current[d.id])==null?void 0:t.getBoundingClientRect().width;K&&(d.columnDef.size=Math.round(K))}e.getResizeHandler()(n)},W=(e,n)=>e==="left"?y[y.length-1]===n:I[0]===n,j=(e,n)=>{if(e==="left")return{left:$.left[n]??0};if(e==="right")return{right:$.right[n]??0}},G=C==="fixed"?{overflow:"hidden",textOverflow:"ellipsis"}:void 0,Ue=(e,n)=>e?t=>({...G,position:"sticky",zIndex:1,bgcolor:"background.paper",".MuiTableRow-hover:hover > &":{backgroundImage:`linear-gradient(${t.palette.action.hover}, ${t.palette.action.hover})`},...W(e,n)?{boxShadow:`inset ${e==="left"?-1:1}px 0 0 ${t.palette.divider}`}:{}}):G,Ze=e=>{var n;const t=e.column.getIsPinned();return{align:(n=q(e.column.columnDef.meta))==null?void 0:n.align,style:j(t,e.column.id),sx:Ue(t,e.column.id)}},h=an({count:v.length,getScrollElement:()=>P.current,estimateSize:()=>we,overscan:5,measureElement:Rn});dn({enabled:N,scrollContainerRef:P,virtualizer:h,rowCount:v.length,hasNewer:o?.hasNewer,hasOlder:o?.hasOlder,isLoadingNewer:o?.isLoadingNewer,isLoadingOlder:o?.isLoadingOlder,onLoadNewer:o?.onLoadNewer??J,onLoadOlder:o?.onLoadOlder??J,resetKey:o?.resetKey});const{pageIndex:Qe}=i.getState().pagination;return Xe(()=>{h.scrollToOffset(0)},[Qe,h]),r(un,{value:{table:i,data:a,rows:v,totalRowCount:Ge,columnCount:Ke,icons:ve,isLoading:xe,emptyMessage:ye,tableLayout:C,enableColumnResizing:s,enableColumnMenu:ie,enableExport:le,exportFilename:re,disablePagination:b,pageSizeOptions:ne,footerLeft:Re,bidirectionalScroll:o,renderLoading:Le,renderRow:U,filters:R,onFiltersChange:Oe,search:w,onSearchChange:Ve,columnPanel:Ne,setColumnPanel:f,closeColumnPanel:ke,openFilterPanel:$e,openManageColumnsPanel:We,toolbarFilterButtonRef:V,toolbarManageColumnsButtonRef:F,headerRowRefs:D,headerCellRefs:k,headerRowTops:qe,headerHeight:Ae,isPinnedEdge:W,getPinnedOffsetStyle:j,getCellProps:Ze,hasResizedColumns:O,startColumnResize:Je,virtualizer:h},children:A(ln,{sx:{width:"100%"},children:[ae&&r(yn,{}),r(rn,{ref:P,sx:{maxHeight:Pe,width:0,minWidth:"100%"},children:A(sn,{stickyHeader:!0,sx:{minWidth:Se,tableLayout:C},style:_e?{width:`max(${i.getTotalSize()}px, 100%)`}:void 0,"aria-label":"data table",children:[r(Pn,{}),r(wn,{})]})}),r(vn,{}),r(Sn,{})]})})}export{Hn as DataTable};
|
|
@@ -60,6 +60,12 @@ export interface DataTableColumnMeta {
|
|
|
60
60
|
* Column width — any CSS width value: a number for px (e.g. 140) or a
|
|
61
61
|
* string for percentage fill (e.g. '40%'). Applied to the header cell,
|
|
62
62
|
* which sizes the whole column.
|
|
63
|
+
*
|
|
64
|
+
* With `enableColumnResizing`, a numeric (px) width behaves like a
|
|
65
|
+
* drag-resize: the table grows to the sum of the column widths and
|
|
66
|
+
* scrolls horizontally rather than shrinking the other columns to fit,
|
|
67
|
+
* so a large width never reflows its neighbors. Percentage widths still
|
|
68
|
+
* split the available space.
|
|
63
69
|
*/
|
|
64
70
|
width?: number | string;
|
|
65
71
|
/**
|
|
@@ -69,6 +75,13 @@ export interface DataTableColumnMeta {
|
|
|
69
75
|
* current page, so supply the full set here.
|
|
70
76
|
*/
|
|
71
77
|
filterOptions?: string[];
|
|
78
|
+
/**
|
|
79
|
+
* Hides the hover kebab (column menu) on this column even when the table
|
|
80
|
+
* has `enableColumnMenu`. Use for utility columns with nothing to act on
|
|
81
|
+
* (e.g. an expand/select column) so they don't show a menu offering only
|
|
82
|
+
* the global "Manage columns" action.
|
|
83
|
+
*/
|
|
84
|
+
disableColumnMenu?: boolean;
|
|
72
85
|
}
|
|
73
86
|
/**
|
|
74
87
|
* Replacement component for one of the table's built-in MUI icons. Slots
|
|
@@ -347,7 +360,8 @@ export interface DataTableProps<TData extends DataTableData> {
|
|
|
347
360
|
*
|
|
348
361
|
* Every accessor column is filterable through the operator-based filter
|
|
349
362
|
* panel by default — opt a column out with `enableColumnFilter: false`
|
|
350
|
-
* on its def.
|
|
363
|
+
* on its def. Hide the kebab on a specific column (e.g. a utility
|
|
364
|
+
* expand/select column) with `meta.disableColumnMenu`.
|
|
351
365
|
*/
|
|
352
366
|
enableColumnMenu?: boolean;
|
|
353
367
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{flexRender as W}from"@tanstack/react-table";import{Typography as q,TableSortLabel as G,TableCell as J,Box as
|
|
1
|
+
"use strict";import{flexRender as W}from"@tanstack/react-table";import{Typography as q,TableSortLabel as G,TableCell as J,Box as C,Tooltip as w,IconButton as v}from"@mui/material";import{FilterAlt as K,MoreVert as Q}from"@mui/icons-material";import{useDataTableContext as U}from"./DataTable.context.mjs";import{isFilterRowActive as X}from"./DataTable.filters.mjs";import{getColumnMeta as Y,getColumnLabel as y}from"./DataTable.utils.mjs";import{jsx as o,jsxs as S}from"react/jsx-runtime";const _={left:"flex-start",center:"center",right:"flex-end"};function Z({header:l,rowIndex:s,headerRowCount:T}){const{icons:f,isLoading:z,filters:D,tableLayout:I,enableColumnResizing:p,enableColumnMenu:M,hasResizedColumns:R,columnPanel:c,setColumnPanel:B,openFilterPanel:P,startColumnResize:h,getPinnedOffsetStyle:$,isPinnedEdge:k,headerRowTops:j,headerCellRefs:L}=U(),{columnMenu:A=Q,filter:F=K}=f,{column:e}=l,n=Y(e.columnDef.meta),a=e.columns.length>0,g=a?1:T-s,d=n?.align??(a?"center":"left"),E=e.getCanSort(),i=e.getIsSorted(),H=p&&!a&&e.getCanResize(),N=e.getIsResizing(),r=a?!1:e.getIsPinned(),u=M&&!a&&!(n!=null&&n.disableColumnMenu),O=c?.type==="menu"&&c.columnId===e.id,m=u?D.rows.filter(t=>t.columnId===e.id&&X(t)).length:0,V=m>0,b=o(q,{component:"span",variant:"subtitle2",sx:{textTransform:"uppercase",fontSize:12,fontWeight:900},children:W(e.columnDef.header,l.getContext())}),x=E?o(G,{active:i!==!1,direction:i===!1?"asc":i,disabled:z,onClick:e.getToggleSortingHandler(),IconComponent:f.sort,children:b}):b;return S(J,{ref:t=>{a||(L.current[e.id]=t)},align:d,colSpan:l.colSpan>1?l.colSpan:void 0,rowSpan:g>1?g:void 0,sortDirection:i,style:{...R||p&&typeof n?.width=="number"?{width:l.getSize()}:{},...$(r,e.id)},sx:{width:n?.width,...I==="fixed"?{overflow:"hidden",textOverflow:"ellipsis"}:{},...a?{borderBottom:"none"}:{},...s>0?{top:j[s]??0}:{},...r?{zIndex:3,...k(r,e.id)?{boxShadow:t=>`inset ${r==="left"?-1:1}px 0 0 ${t.palette.divider}`}:{}}:{},...u?{"& .DataTable-columnMenuButton":{opacity:O?1:0,transition:"opacity .2s"},"&:hover .DataTable-columnMenuButton, &:focus-within .DataTable-columnMenuButton":{opacity:1}}:{}},children:[u?S(C,{sx:{display:"flex",alignItems:"center",gap:.5,justifyContent:_[d]},children:[x,V&&o(w,{title:`${m} active ${m===1?"filter":"filters"}`,placement:"bottom",arrow:!0,children:o(v,{size:"small","aria-label":`${y(e)} filter`,onClick:t=>P(e.id,t.currentTarget),children:o(F,{sx:{fontSize:16}})})}),o(w,{title:"Menu",placement:"bottom",arrow:!0,children:o(v,{size:"small",className:"DataTable-columnMenuButton","aria-label":`${y(e)} column menu`,onClick:t=>B({type:"menu",columnId:e.id,anchorEl:t.currentTarget}),sx:d!=="right"?{ml:"auto"}:void 0,children:o(A,{fontSize:"small"})})})]}):x,H&&o(C,{className:"DataTable-columnResizer","aria-hidden":!0,onMouseDown:t=>h(l,t),onTouchStart:t=>h(l,t),onDoubleClick:()=>e.resetSize(),sx:{position:"absolute",top:0,bottom:0,right:0,width:9,cursor:"col-resize",touchAction:"none",userSelect:"none",display:"flex",alignItems:"center",justifyContent:"center","&::after":{content:'""',transition:"background-color .2s",width:"1px",height:"50%",bgcolor:"divider"},"&:hover::after":{width:"4px",bgcolor:"primary.main"},...N?{"&::after, &:hover::after":{width:"4px",bgcolor:"primary.main"}}:{}}})]})}export{Z as DataTableHeaderCell};
|