Skip to content

Commit 465ad59

Browse files
chore: Refactoring the core headers folder to match the updated format with separation for create, base, types, and utils. Match file import ordering in index, and refactoring core table to separate types (#5647)
1 parent e922897 commit 465ad59

10 files changed

Lines changed: 617 additions & 578 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Column, Header, RowData, Table } from '../../types'
2+
import { Header_Core } from './Headers.types'
3+
4+
export function _createHeader<TData extends RowData, TValue>(
5+
table: Table<TData>,
6+
column: Column<TData, TValue>,
7+
options: {
8+
id?: string
9+
isPlaceholder?: boolean
10+
placeholderId?: string
11+
index: number
12+
depth: number
13+
}
14+
): Header<TData, TValue> {
15+
const id = options.id ?? column.id
16+
17+
let header: Header_Core<TData, TValue> = {
18+
id,
19+
column,
20+
index: options.index,
21+
isPlaceholder: !!options.isPlaceholder,
22+
placeholderId: options.placeholderId,
23+
depth: options.depth,
24+
subHeaders: [],
25+
colSpan: 0,
26+
rowSpan: 0,
27+
headerGroup: null!,
28+
getLeafHeaders: (): Header<TData, unknown>[] => {
29+
const leafHeaders: Header<TData, unknown>[] = []
30+
31+
const recurseHeader = (h: Header_Core<TData, any>) => {
32+
if (h.subHeaders && h.subHeaders.length) {
33+
h.subHeaders.map(recurseHeader)
34+
}
35+
leafHeaders.push(h as Header<TData, unknown>)
36+
}
37+
38+
recurseHeader(header)
39+
40+
return leafHeaders
41+
},
42+
getContext: () => ({
43+
table,
44+
header: header as Header<TData, TValue>,
45+
column,
46+
}),
47+
}
48+
49+
table._features.forEach(feature => {
50+
feature._createHeader?.(header as Header<TData, TValue>, table)
51+
})
52+
53+
return header as Header<TData, TValue>
54+
}

0 commit comments

Comments
 (0)