@ltht-react/table 2.0.161 → 2.0.163
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.
- package/README.md +15 -15
- package/lib/molecules/table-cell.d.ts +1 -0
- package/lib/molecules/table-cell.js +5 -5
- package/lib/molecules/table-cell.js.map +1 -1
- package/lib/molecules/table-component.js +6 -5
- package/lib/molecules/table-component.js.map +1 -1
- package/lib/molecules/table-header.d.ts +2 -1
- package/lib/molecules/table-header.js +2 -2
- package/lib/molecules/table-header.js.map +1 -1
- package/lib/organisms/questionnaire-table-methods.js +2 -0
- package/lib/organisms/questionnaire-table-methods.js.map +1 -1
- package/package.json +8 -8
- package/src/atoms/questionnaire-withdrawn-table-cell.tsx +15 -15
- package/src/index.tsx +8 -8
- package/src/molecules/table-cell.tsx +96 -93
- package/src/molecules/table-component.tsx +123 -120
- package/src/molecules/table-header.tsx +38 -36
- package/src/molecules/table-methods.tsx +238 -238
- package/src/molecules/table-styled-components.tsx +249 -249
- package/src/molecules/table.tsx +166 -166
- package/src/molecules/useDimensionRef.tsx +37 -37
- package/src/molecules/useScrollRef.tsx +40 -40
- package/src/organisms/generic-table.tsx +34 -34
- package/src/organisms/questionnaire-table-methods.tsx +351 -349
- package/src/organisms/questionnaire-table.tsx +56 -56
|
@@ -1,120 +1,123 @@
|
|
|
1
|
-
import Icon from '@ltht-react/icon'
|
|
2
|
-
import { flexRender, Header as ReactTableHeader, Table } from '@tanstack/react-table'
|
|
3
|
-
import { HTMLAttributes, useMemo, useRef } from 'react'
|
|
4
|
-
import { calculateStaticColumnOffset } from './table-methods'
|
|
5
|
-
import {
|
|
6
|
-
StyledNextPageButtonContainer,
|
|
7
|
-
StyledSpinnerContainer,
|
|
8
|
-
StyledTable,
|
|
9
|
-
StyledTableRow,
|
|
10
|
-
StyledTableData,
|
|
11
|
-
StyledTHead,
|
|
12
|
-
} from './table-styled-components'
|
|
13
|
-
import useDimensionsRef from './useDimensionRef'
|
|
14
|
-
import { CellProps } from './table-cell'
|
|
15
|
-
import { ITableConfig } from './table'
|
|
16
|
-
import TableHeader from './table-header'
|
|
17
|
-
|
|
18
|
-
const TableComponent = <T,>({ table, staticColumns = 0, headerAxis, ...rest }: ITableHeadProps<T>): JSX.Element => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
case
|
|
46
|
-
return <TableHeader key={header.id} ref={
|
|
47
|
-
|
|
48
|
-
return <TableHeader key={header.id} {...headerProps} />
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
import Icon from '@ltht-react/icon'
|
|
2
|
+
import { flexRender, Header as ReactTableHeader, Table } from '@tanstack/react-table'
|
|
3
|
+
import { HTMLAttributes, useMemo, useRef } from 'react'
|
|
4
|
+
import { calculateStaticColumnOffset } from './table-methods'
|
|
5
|
+
import {
|
|
6
|
+
StyledNextPageButtonContainer,
|
|
7
|
+
StyledSpinnerContainer,
|
|
8
|
+
StyledTable,
|
|
9
|
+
StyledTableRow,
|
|
10
|
+
StyledTableData,
|
|
11
|
+
StyledTHead,
|
|
12
|
+
} from './table-styled-components'
|
|
13
|
+
import useDimensionsRef from './useDimensionRef'
|
|
14
|
+
import { CellProps } from './table-cell'
|
|
15
|
+
import { ITableConfig } from './table'
|
|
16
|
+
import TableHeader from './table-header'
|
|
17
|
+
|
|
18
|
+
const TableComponent = <T,>({ table, staticColumns = 0, headerAxis, ...rest }: ITableHeadProps<T>): JSX.Element => {
|
|
19
|
+
const tableIdPrefix = rest.id ? `${rest.id}-` : ''
|
|
20
|
+
|
|
21
|
+
const firstColumn = useRef(null)
|
|
22
|
+
const secondColumn = useRef(null)
|
|
23
|
+
const tableElement = useRef(null)
|
|
24
|
+
const { width: firstColumnWidth } = useDimensionsRef(firstColumn, tableElement)
|
|
25
|
+
const { width: secondColumnWidth } = useDimensionsRef(secondColumn, tableElement)
|
|
26
|
+
|
|
27
|
+
const usingExpanderColumn = table.getHeaderGroups().some((x) => x.headers.some((h) => h.column.id === 'expander'))
|
|
28
|
+
const totalStaticColumns = useMemo(
|
|
29
|
+
() => (usingExpanderColumn ? staticColumns + 1 : staticColumns),
|
|
30
|
+
[usingExpanderColumn, staticColumns]
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const getHeaderColumn = <TData, TValue>(header: ReactTableHeader<TData, TValue>, headerIndex: number) => {
|
|
34
|
+
const stickyWidth = calculateStaticColumnOffset(
|
|
35
|
+
headerIndex,
|
|
36
|
+
totalStaticColumns,
|
|
37
|
+
firstColumnWidth,
|
|
38
|
+
secondColumnWidth
|
|
39
|
+
)
|
|
40
|
+
const headerProps = {
|
|
41
|
+
header,
|
|
42
|
+
stickyWidth,
|
|
43
|
+
}
|
|
44
|
+
switch (headerIndex) {
|
|
45
|
+
case 0:
|
|
46
|
+
return <TableHeader key={header.id} tableId={tableIdPrefix} ref={firstColumn} {...headerProps} />
|
|
47
|
+
case 1:
|
|
48
|
+
return <TableHeader key={header.id} tableId={tableIdPrefix} ref={secondColumn} {...headerProps} />
|
|
49
|
+
default:
|
|
50
|
+
return <TableHeader key={header.id} tableId={tableIdPrefix} {...headerProps} />
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<StyledTable ref={tableElement} {...rest}>
|
|
56
|
+
<StyledTHead>
|
|
57
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
58
|
+
<tr key={headerGroup.id} id={`${tableIdPrefix}${headerGroup.id}`} role="row">
|
|
59
|
+
{headerGroup.headers.map((header, headerIndex) => getHeaderColumn(header, headerIndex))}
|
|
60
|
+
</tr>
|
|
61
|
+
))}
|
|
62
|
+
</StyledTHead>
|
|
63
|
+
<tbody>
|
|
64
|
+
{table.getRowModel().rows.map((row) => (
|
|
65
|
+
<StyledTableRow tableHeaderAxis={headerAxis} key={row.id} role="row">
|
|
66
|
+
{row.getVisibleCells().map((cell, cellIdx) => (
|
|
67
|
+
<StyledTableData
|
|
68
|
+
tableHeaderAxis={headerAxis}
|
|
69
|
+
stickyWidth={calculateStaticColumnOffset(
|
|
70
|
+
cellIdx,
|
|
71
|
+
totalStaticColumns,
|
|
72
|
+
firstColumnWidth,
|
|
73
|
+
secondColumnWidth
|
|
74
|
+
)}
|
|
75
|
+
key={cell.id}
|
|
76
|
+
id={`${tableIdPrefix}${cell.id}`}
|
|
77
|
+
role="cell"
|
|
78
|
+
style={(cell.getValue() as CellProps)?.parentStyle}
|
|
79
|
+
>
|
|
80
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
81
|
+
</StyledTableData>
|
|
82
|
+
))}
|
|
83
|
+
</StyledTableRow>
|
|
84
|
+
))}
|
|
85
|
+
</tbody>
|
|
86
|
+
</StyledTable>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const TableNavigationButton = ({ position, hidden, clickHandler }: ITableNavButtonProps) => (
|
|
91
|
+
<StyledNextPageButtonContainer
|
|
92
|
+
role="button"
|
|
93
|
+
elementPosition={position}
|
|
94
|
+
onClick={() => clickHandler()}
|
|
95
|
+
hidden={hidden}
|
|
96
|
+
>
|
|
97
|
+
<Icon type="chevron" direction={position === 'bottom' ? 'down' : 'right'} size="medium" />
|
|
98
|
+
</StyledNextPageButtonContainer>
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
const TableSpinner = ({ position, hidden }: ITableSpinnerProps) => (
|
|
102
|
+
<StyledSpinnerContainer elementPosition={position} hidden={hidden}>
|
|
103
|
+
<Icon type="spinner" size="medium" title="Loading..." />
|
|
104
|
+
</StyledSpinnerContainer>
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
interface ITableNavButtonProps {
|
|
108
|
+
position: 'bottom' | 'right'
|
|
109
|
+
hidden: boolean
|
|
110
|
+
clickHandler: () => void
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface ITableSpinnerProps {
|
|
114
|
+
position: 'bottom' | 'right'
|
|
115
|
+
hidden: boolean
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface ITableHeadProps<T> extends ITableConfig, HTMLAttributes<HTMLTableElement> {
|
|
119
|
+
table: Table<T>
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default TableComponent
|
|
123
|
+
export { TableNavigationButton, TableSpinner }
|
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
import { forwardRef, Ref } from 'react'
|
|
2
|
-
import { flexRender, Header as ReactTableHeader } from '@tanstack/react-table'
|
|
3
|
-
import { StyledTableHeader } from './table-styled-components'
|
|
4
|
-
|
|
5
|
-
interface TableHeaderProps<TData, TValue> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
import { forwardRef, Ref } from 'react'
|
|
2
|
+
import { flexRender, Header as ReactTableHeader } from '@tanstack/react-table'
|
|
3
|
+
import { StyledTableHeader } from './table-styled-components'
|
|
4
|
+
|
|
5
|
+
interface TableHeaderProps<TData, TValue> {
|
|
6
|
+
tableId?: string
|
|
7
|
+
header: ReactTableHeader<TData, TValue>
|
|
8
|
+
stickyWidth?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Wrapper = <TData, TValue>(
|
|
12
|
+
{ tableId, header, stickyWidth }: TableHeaderProps<TData, TValue>,
|
|
13
|
+
ref?: Ref<HTMLTableCellElement>
|
|
14
|
+
) => (
|
|
15
|
+
<StyledTableHeader
|
|
16
|
+
id={`${tableId}${header.id}`}
|
|
17
|
+
ref={ref}
|
|
18
|
+
stickyWidth={stickyWidth}
|
|
19
|
+
colSpan={header.colSpan}
|
|
20
|
+
role="columnheader"
|
|
21
|
+
{...(header.column.id !== 'expander'
|
|
22
|
+
? {
|
|
23
|
+
style: {
|
|
24
|
+
cursor: header.column.getCanSort() ? 'pointer' : '',
|
|
25
|
+
},
|
|
26
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
27
|
+
}
|
|
28
|
+
: {})}
|
|
29
|
+
>
|
|
30
|
+
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
|
|
31
|
+
</StyledTableHeader>
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
const TableHeader = forwardRef(Wrapper) as <TData, TValue>(
|
|
35
|
+
props: TableHeaderProps<TData, TValue> & { ref?: Ref<HTMLTableCellElement> }
|
|
36
|
+
) => ReturnType<typeof Wrapper>
|
|
37
|
+
|
|
38
|
+
export default TableHeader
|