tanstack-table-header-rowspan
Version:
Rowspan for TanStack Table headers
1 lines • 3.5 kB
Source Map (JSON)
{"version":3,"file":"rowspan.cjs","sources":["../src/index.ts"],"sourcesContent":["import type { Header } from '@tanstack/react-table';\nimport { type CSSProperties } from 'react';\n\nfunction deepestHeader<D, V>(header: Header<D, V>): Header<D, V> | null {\n let last = header;\n while (true) {\n const next =\n last.isPlaceholder && last.colSpan === 1 && last.subHeaders.length === 1\n ? last.subHeaders[0]\n : null;\n if (next) {\n last = next;\n } else {\n return last === header ? null : last;\n }\n }\n}\n\nexport function tableHeaderRowSpan(header: Header<any, any>): number | null {\n const deepest = deepestHeader(header);\n const rowSpan = (deepest ? deepest.depth - header.depth : 0) + 1;\n const above = header.depth - header.column.depth;\n if (above > 1) {\n return null;\n }\n return rowSpan;\n}\nexport function tableFooterRowSpan(header: Header<any, any>): number | null {\n const deepest = deepestHeader(header);\n const below = (deepest ? deepest.depth - header.depth : 0) + 1;\n const above = header.depth - header.column.depth;\n if (below > 1) {\n return null;\n }\n return above;\n}\n\nexport function flexTableHeaderRowSpan(header: Header<any, any>) {\n const rowSpan = header.depth - header.column.depth;\n return {\n rowSpan,\n topBorderMightBeNeeded: header.column.depth === 0,\n styles: (cssRowHeight: CSSProperties['height']): CSSProperties => ({\n /** @ts-ignore */\n '--rowspan': rowSpan,\n height: `calc(var(--rowspan, 1) * ${cssRowHeight})`,\n marginTop: `calc(-1 * (var(--rowspan, 1) - 1) * ${cssRowHeight})`,\n visibility: header.isPlaceholder ? 'hidden' : undefined,\n }),\n };\n}\n\nexport function flexTableFooterRowSpan(header: Header<any, any>) {\n const rowSpan = header.depth - header.column.depth;\n return {\n rowSpan,\n bottomBorderMightBeNeeded: header.column.depth === 0,\n styles: (cssRowHeight: CSSProperties['height']): CSSProperties => ({\n /** @ts-ignore */\n '--rowspan': rowSpan,\n height: `calc(var(--rowspan, 1) * ${cssRowHeight})`,\n marginBottom: `calc(-1*(var(--rowspan, 1) - 1) * ${cssRowHeight})`,\n visibility: header.isPlaceholder ? 'hidden' : undefined,\n }),\n };\n}\n"],"names":["deepestHeader","header","last","next","isPlaceholder","colSpan","subHeaders","length","rowSpan","depth","column","bottomBorderMightBeNeeded","styles","cssRowHeight","height","marginBottom","visibility","undefined","topBorderMightBeNeeded","marginTop","deepest"],"mappings":"AAGA,SAASA,EAAoBC,GAE3B,IADA,IAAIC,EAAOD,IACE,CACX,IAAME,EACJD,EAAKE,eAAkC,IAAjBF,EAAKG,SAA4C,IAA3BH,EAAKI,WAAWC,OACxDL,EAAKI,WAAW,GAChB,KACN,IAAIH,EAGF,OAAOD,IAASD,EAAS,KAAOC,EAFhCA,EAAOC,CAIX,CACF,yCAoCuCF,GACrC,IAAMO,EAAUP,EAAOQ,MAAQR,EAAOS,OAAOD,MAC7C,MAAO,CACLD,QAAAA,EACAG,0BAAmD,IAAxBV,EAAOS,OAAOD,MACzCG,OAAQ,SAACC,GAAqC,MAAqB,CAEjE,YAAaL,EACbM,OAAoCD,4BAAAA,MACpCE,kDAAmDF,EAAY,IAC/DG,WAAYf,EAAOG,cAAgB,cAAWa,EAC/C,EAEL,0CA5BuChB,GACrC,IAAMO,EAAUP,EAAOQ,MAAQR,EAAOS,OAAOD,MAC7C,MAAO,CACLD,QAAAA,EACAU,uBAAgD,IAAxBjB,EAAOS,OAAOD,MACtCG,OAAQ,SAACC,GAAqC,MAAqB,CAEjE,YAAaL,EACbM,OAAoCD,4BAAAA,MACpCM,iDAAkDN,EAAY,IAC9DG,WAAYf,EAAOG,cAAgB,cAAWa,EAC/C,EAEL,6BAvBgB,SAAmBhB,GACjC,IAAMmB,EAAUpB,EAAcC,GAG9B,OAF6D,GAA9CmB,EAAUA,EAAQX,MAAQR,EAAOQ,MAAQ,GAE5C,EAEZ,KAHcR,EAAOQ,MAAQR,EAAOS,OAAOD,KAK7C,6BAjBgB,SAAmBR,GACjC,IAAMmB,EAAUpB,EAAcC,GAG9B,OADcA,EAAOQ,MAAQR,EAAOS,OAAOD,MAC/B,EACH,KAHsD,GAA9CW,EAAUA,EAAQX,MAAQR,EAAOQ,MAAQ,EAM5D"}