@ltht-react/table 2.0.190 → 2.0.192
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/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 +111 -111
- package/src/molecules/table-component.tsx +123 -123
- package/src/molecules/table-header.tsx +38 -38
- 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 -351
- package/src/organisms/questionnaire-table.tsx +56 -56
package/src/molecules/table.tsx
CHANGED
|
@@ -1,166 +1,166 @@
|
|
|
1
|
-
import { FC, HTMLAttributes, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
getCoreRowModel,
|
|
4
|
-
useReactTable,
|
|
5
|
-
getExpandedRowModel,
|
|
6
|
-
getSortedRowModel,
|
|
7
|
-
ExpandedState,
|
|
8
|
-
SortingState,
|
|
9
|
-
PaginationState,
|
|
10
|
-
ColumnDef,
|
|
11
|
-
SortingFn,
|
|
12
|
-
} from '@tanstack/react-table'
|
|
13
|
-
import { Axis } from '@ltht-react/types'
|
|
14
|
-
import { ScrollableContainer } from './table-styled-components'
|
|
15
|
-
import useScrollRef from './useScrollRef'
|
|
16
|
-
import { handleDataUpdate, handleDataUpdateForManualPagination, handleScrollEvent } from './table-methods'
|
|
17
|
-
import TableComponent, { TableNavigationButton, TableSpinner } from './table-component'
|
|
18
|
-
import { CellProps } from './table-cell'
|
|
19
|
-
|
|
20
|
-
const Table: FC<IProps> = ({
|
|
21
|
-
tableData,
|
|
22
|
-
staticColumns = 0,
|
|
23
|
-
currentPage = 1,
|
|
24
|
-
pageSize: pageSizeParam = 10,
|
|
25
|
-
headerAxis = 'x',
|
|
26
|
-
manualPagination = false,
|
|
27
|
-
infiniteScrollEnabled = false,
|
|
28
|
-
getCanNextPage = () => false,
|
|
29
|
-
nextPage = () => null,
|
|
30
|
-
isFetching = false,
|
|
31
|
-
keepPreviousData = false,
|
|
32
|
-
maxHeight,
|
|
33
|
-
maxWidth,
|
|
34
|
-
isFlex = false,
|
|
35
|
-
enableSorting = true,
|
|
36
|
-
sortingFunctions = undefined,
|
|
37
|
-
...rest
|
|
38
|
-
}) => {
|
|
39
|
-
const scrollableDivElement = useRef<HTMLDivElement>(null)
|
|
40
|
-
const scrollState = useScrollRef(scrollableDivElement)
|
|
41
|
-
|
|
42
|
-
const [expanded, setExpanded] = useState<ExpandedState>({})
|
|
43
|
-
const [sorting, setSorting] = useState<SortingState>([])
|
|
44
|
-
const [{ pageIndex, pageSize }, setPagination] = useState<PaginationState>({
|
|
45
|
-
pageIndex: currentPage - 1,
|
|
46
|
-
pageSize: pageSizeParam,
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const pagination = useMemo(() => ({ pageIndex, pageSize }), [pageIndex, pageSize])
|
|
50
|
-
const [data, setData] = useState<DataEntity[]>([])
|
|
51
|
-
const [columns, setColumns] = useState<ColumnDef<DataEntity>[]>([])
|
|
52
|
-
const [pageCount, setPageCount] = useState<number>(-1)
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (!manualPagination) {
|
|
56
|
-
handleDataUpdate(tableData, pageIndex, pageSize, headerAxis, setColumns, setData, setPageCount)
|
|
57
|
-
}
|
|
58
|
-
}, [pageIndex, pageSize, headerAxis, tableData, manualPagination])
|
|
59
|
-
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (manualPagination) {
|
|
62
|
-
handleDataUpdateForManualPagination(tableData, headerAxis, keepPreviousData, setColumns, setData)
|
|
63
|
-
}
|
|
64
|
-
}, [headerAxis, tableData, manualPagination, keepPreviousData])
|
|
65
|
-
|
|
66
|
-
const table = useReactTable({
|
|
67
|
-
data,
|
|
68
|
-
columns,
|
|
69
|
-
...(!manualPagination ? { pageCount } : {}),
|
|
70
|
-
state: {
|
|
71
|
-
expanded,
|
|
72
|
-
sorting,
|
|
73
|
-
...(!manualPagination ? { pagination } : {}),
|
|
74
|
-
},
|
|
75
|
-
manualPagination: true,
|
|
76
|
-
onExpandedChange: setExpanded,
|
|
77
|
-
onSortingChange: setSorting,
|
|
78
|
-
enableSorting,
|
|
79
|
-
sortingFns: sortingFunctions,
|
|
80
|
-
getSubRows: (row) => row.subRows,
|
|
81
|
-
getCoreRowModel: getCoreRowModel(),
|
|
82
|
-
getExpandedRowModel: getExpandedRowModel(),
|
|
83
|
-
getSortedRowModel: getSortedRowModel(),
|
|
84
|
-
...(!manualPagination ? { onPaginationChange: setPagination } : {}),
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const getNextPage = () => (manualPagination ? nextPage() : table.nextPage())
|
|
88
|
-
const hasNextPage = () => (manualPagination ? getCanNextPage() : table.getCanNextPage())
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (!scrollState || !infiniteScrollEnabled || isFetching) {
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
handleScrollEvent({ getCanNextPage: hasNextPage, nextPage: getNextPage }, headerAxis, scrollState)
|
|
96
|
-
|
|
97
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
98
|
-
}, [scrollState])
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<ScrollableContainer
|
|
102
|
-
ref={scrollableDivElement}
|
|
103
|
-
tableHeaderAxis={headerAxis}
|
|
104
|
-
{...{ maxHeight, maxWidth }}
|
|
105
|
-
isFlex={isFlex}
|
|
106
|
-
>
|
|
107
|
-
<TableComponent table={table} staticColumns={staticColumns} headerAxis={headerAxis} {...rest} />
|
|
108
|
-
{manualPagination ? (
|
|
109
|
-
<TableSpinner position={headerAxis === 'x' ? 'bottom' : 'right'} hidden={!isFetching} />
|
|
110
|
-
) : null}
|
|
111
|
-
<TableNavigationButton
|
|
112
|
-
position={headerAxis === 'x' ? 'bottom' : 'right'}
|
|
113
|
-
hidden={isFetching || (manualPagination ? !getCanNextPage() : !table.getCanNextPage())}
|
|
114
|
-
clickHandler={getNextPage}
|
|
115
|
-
/>
|
|
116
|
-
</ScrollableContainer>
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
interface IProps extends ITableConfig, IPaginationProps, ITableDimensionProps, HTMLAttributes<HTMLTableElement> {
|
|
121
|
-
tableData: TableData
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface ITableConfig {
|
|
125
|
-
staticColumns?: 0 | 1 | 2
|
|
126
|
-
headerAxis?: Axis
|
|
127
|
-
enableSorting?: boolean
|
|
128
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
-
sortingFunctions?: Record<string, SortingFn<any>> | undefined
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export interface IPaginationProps {
|
|
133
|
-
currentPage?: number
|
|
134
|
-
pageSize?: number
|
|
135
|
-
manualPagination?: boolean
|
|
136
|
-
infiniteScrollEnabled?: boolean
|
|
137
|
-
nextPage?: () => void
|
|
138
|
-
getCanNextPage?: () => boolean
|
|
139
|
-
isFetching?: boolean
|
|
140
|
-
keepPreviousData?: boolean
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface ITableDimensionProps {
|
|
144
|
-
maxWidth?: string
|
|
145
|
-
maxHeight?: string
|
|
146
|
-
isFlex?: boolean
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
type DataEntity = Record<string, CellProps | DataEntity[]> & {
|
|
150
|
-
subRows?: DataEntity[]
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
interface Header {
|
|
154
|
-
type: 'accessor' | 'group' | 'display'
|
|
155
|
-
id: string
|
|
156
|
-
cellProps: CellProps
|
|
157
|
-
subHeaders?: Header[]
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
interface TableData {
|
|
161
|
-
headers: Header[]
|
|
162
|
-
rows: DataEntity[]
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export default Table
|
|
166
|
-
export { DataEntity, CellProps, Header, TableData }
|
|
1
|
+
import { FC, HTMLAttributes, useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
getCoreRowModel,
|
|
4
|
+
useReactTable,
|
|
5
|
+
getExpandedRowModel,
|
|
6
|
+
getSortedRowModel,
|
|
7
|
+
ExpandedState,
|
|
8
|
+
SortingState,
|
|
9
|
+
PaginationState,
|
|
10
|
+
ColumnDef,
|
|
11
|
+
SortingFn,
|
|
12
|
+
} from '@tanstack/react-table'
|
|
13
|
+
import { Axis } from '@ltht-react/types'
|
|
14
|
+
import { ScrollableContainer } from './table-styled-components'
|
|
15
|
+
import useScrollRef from './useScrollRef'
|
|
16
|
+
import { handleDataUpdate, handleDataUpdateForManualPagination, handleScrollEvent } from './table-methods'
|
|
17
|
+
import TableComponent, { TableNavigationButton, TableSpinner } from './table-component'
|
|
18
|
+
import { CellProps } from './table-cell'
|
|
19
|
+
|
|
20
|
+
const Table: FC<IProps> = ({
|
|
21
|
+
tableData,
|
|
22
|
+
staticColumns = 0,
|
|
23
|
+
currentPage = 1,
|
|
24
|
+
pageSize: pageSizeParam = 10,
|
|
25
|
+
headerAxis = 'x',
|
|
26
|
+
manualPagination = false,
|
|
27
|
+
infiniteScrollEnabled = false,
|
|
28
|
+
getCanNextPage = () => false,
|
|
29
|
+
nextPage = () => null,
|
|
30
|
+
isFetching = false,
|
|
31
|
+
keepPreviousData = false,
|
|
32
|
+
maxHeight,
|
|
33
|
+
maxWidth,
|
|
34
|
+
isFlex = false,
|
|
35
|
+
enableSorting = true,
|
|
36
|
+
sortingFunctions = undefined,
|
|
37
|
+
...rest
|
|
38
|
+
}) => {
|
|
39
|
+
const scrollableDivElement = useRef<HTMLDivElement>(null)
|
|
40
|
+
const scrollState = useScrollRef(scrollableDivElement)
|
|
41
|
+
|
|
42
|
+
const [expanded, setExpanded] = useState<ExpandedState>({})
|
|
43
|
+
const [sorting, setSorting] = useState<SortingState>([])
|
|
44
|
+
const [{ pageIndex, pageSize }, setPagination] = useState<PaginationState>({
|
|
45
|
+
pageIndex: currentPage - 1,
|
|
46
|
+
pageSize: pageSizeParam,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const pagination = useMemo(() => ({ pageIndex, pageSize }), [pageIndex, pageSize])
|
|
50
|
+
const [data, setData] = useState<DataEntity[]>([])
|
|
51
|
+
const [columns, setColumns] = useState<ColumnDef<DataEntity>[]>([])
|
|
52
|
+
const [pageCount, setPageCount] = useState<number>(-1)
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!manualPagination) {
|
|
56
|
+
handleDataUpdate(tableData, pageIndex, pageSize, headerAxis, setColumns, setData, setPageCount)
|
|
57
|
+
}
|
|
58
|
+
}, [pageIndex, pageSize, headerAxis, tableData, manualPagination])
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (manualPagination) {
|
|
62
|
+
handleDataUpdateForManualPagination(tableData, headerAxis, keepPreviousData, setColumns, setData)
|
|
63
|
+
}
|
|
64
|
+
}, [headerAxis, tableData, manualPagination, keepPreviousData])
|
|
65
|
+
|
|
66
|
+
const table = useReactTable({
|
|
67
|
+
data,
|
|
68
|
+
columns,
|
|
69
|
+
...(!manualPagination ? { pageCount } : {}),
|
|
70
|
+
state: {
|
|
71
|
+
expanded,
|
|
72
|
+
sorting,
|
|
73
|
+
...(!manualPagination ? { pagination } : {}),
|
|
74
|
+
},
|
|
75
|
+
manualPagination: true,
|
|
76
|
+
onExpandedChange: setExpanded,
|
|
77
|
+
onSortingChange: setSorting,
|
|
78
|
+
enableSorting,
|
|
79
|
+
sortingFns: sortingFunctions,
|
|
80
|
+
getSubRows: (row) => row.subRows,
|
|
81
|
+
getCoreRowModel: getCoreRowModel(),
|
|
82
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
83
|
+
getSortedRowModel: getSortedRowModel(),
|
|
84
|
+
...(!manualPagination ? { onPaginationChange: setPagination } : {}),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const getNextPage = () => (manualPagination ? nextPage() : table.nextPage())
|
|
88
|
+
const hasNextPage = () => (manualPagination ? getCanNextPage() : table.getCanNextPage())
|
|
89
|
+
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (!scrollState || !infiniteScrollEnabled || isFetching) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
handleScrollEvent({ getCanNextPage: hasNextPage, nextPage: getNextPage }, headerAxis, scrollState)
|
|
96
|
+
|
|
97
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
98
|
+
}, [scrollState])
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<ScrollableContainer
|
|
102
|
+
ref={scrollableDivElement}
|
|
103
|
+
tableHeaderAxis={headerAxis}
|
|
104
|
+
{...{ maxHeight, maxWidth }}
|
|
105
|
+
isFlex={isFlex}
|
|
106
|
+
>
|
|
107
|
+
<TableComponent table={table} staticColumns={staticColumns} headerAxis={headerAxis} {...rest} />
|
|
108
|
+
{manualPagination ? (
|
|
109
|
+
<TableSpinner position={headerAxis === 'x' ? 'bottom' : 'right'} hidden={!isFetching} />
|
|
110
|
+
) : null}
|
|
111
|
+
<TableNavigationButton
|
|
112
|
+
position={headerAxis === 'x' ? 'bottom' : 'right'}
|
|
113
|
+
hidden={isFetching || (manualPagination ? !getCanNextPage() : !table.getCanNextPage())}
|
|
114
|
+
clickHandler={getNextPage}
|
|
115
|
+
/>
|
|
116
|
+
</ScrollableContainer>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface IProps extends ITableConfig, IPaginationProps, ITableDimensionProps, HTMLAttributes<HTMLTableElement> {
|
|
121
|
+
tableData: TableData
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface ITableConfig {
|
|
125
|
+
staticColumns?: 0 | 1 | 2
|
|
126
|
+
headerAxis?: Axis
|
|
127
|
+
enableSorting?: boolean
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
+
sortingFunctions?: Record<string, SortingFn<any>> | undefined
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface IPaginationProps {
|
|
133
|
+
currentPage?: number
|
|
134
|
+
pageSize?: number
|
|
135
|
+
manualPagination?: boolean
|
|
136
|
+
infiniteScrollEnabled?: boolean
|
|
137
|
+
nextPage?: () => void
|
|
138
|
+
getCanNextPage?: () => boolean
|
|
139
|
+
isFetching?: boolean
|
|
140
|
+
keepPreviousData?: boolean
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface ITableDimensionProps {
|
|
144
|
+
maxWidth?: string
|
|
145
|
+
maxHeight?: string
|
|
146
|
+
isFlex?: boolean
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type DataEntity = Record<string, CellProps | DataEntity[]> & {
|
|
150
|
+
subRows?: DataEntity[]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface Header {
|
|
154
|
+
type: 'accessor' | 'group' | 'display'
|
|
155
|
+
id: string
|
|
156
|
+
cellProps: CellProps
|
|
157
|
+
subHeaders?: Header[]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface TableData {
|
|
161
|
+
headers: Header[]
|
|
162
|
+
rows: DataEntity[]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default Table
|
|
166
|
+
export { DataEntity, CellProps, Header, TableData }
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
const useDimensionsRef = (elementRef: React.RefObject<HTMLElement>, parentElementRef: React.RefObject<HTMLElement>) => {
|
|
4
|
-
const [dimensions, setDimensions] = useState({
|
|
5
|
-
width: 0,
|
|
6
|
-
height: 0,
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
const getDimensions = () => ({
|
|
11
|
-
width: (elementRef && elementRef.current && elementRef.current.offsetWidth) || 0,
|
|
12
|
-
height: (elementRef && elementRef.current && elementRef.current.offsetHeight) || 0,
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const handleResize = () => {
|
|
16
|
-
setDimensions(getDimensions())
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (elementRef.current) {
|
|
20
|
-
setDimensions(getDimensions())
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const parentElementResizeObserver = new ResizeObserver((_e: ResizeObserverEntry[]) => handleResize())
|
|
24
|
-
|
|
25
|
-
if (parentElementRef?.current) {
|
|
26
|
-
parentElementResizeObserver.observe(parentElementRef.current)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return () => {
|
|
30
|
-
parentElementResizeObserver?.disconnect()
|
|
31
|
-
}
|
|
32
|
-
}, [elementRef, parentElementRef])
|
|
33
|
-
|
|
34
|
-
return dimensions
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default useDimensionsRef
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const useDimensionsRef = (elementRef: React.RefObject<HTMLElement>, parentElementRef: React.RefObject<HTMLElement>) => {
|
|
4
|
+
const [dimensions, setDimensions] = useState({
|
|
5
|
+
width: 0,
|
|
6
|
+
height: 0,
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const getDimensions = () => ({
|
|
11
|
+
width: (elementRef && elementRef.current && elementRef.current.offsetWidth) || 0,
|
|
12
|
+
height: (elementRef && elementRef.current && elementRef.current.offsetHeight) || 0,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const handleResize = () => {
|
|
16
|
+
setDimensions(getDimensions())
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (elementRef.current) {
|
|
20
|
+
setDimensions(getDimensions())
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const parentElementResizeObserver = new ResizeObserver((_e: ResizeObserverEntry[]) => handleResize())
|
|
24
|
+
|
|
25
|
+
if (parentElementRef?.current) {
|
|
26
|
+
parentElementResizeObserver.observe(parentElementRef.current)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return () => {
|
|
30
|
+
parentElementResizeObserver?.disconnect()
|
|
31
|
+
}
|
|
32
|
+
}, [elementRef, parentElementRef])
|
|
33
|
+
|
|
34
|
+
return dimensions
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default useDimensionsRef
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
const useScrollRef = (elementRef: React.RefObject<HTMLElement>) => {
|
|
4
|
-
const [scrollState, setScrollState] = useState<ScrollState>()
|
|
5
|
-
|
|
6
|
-
const handleScroll = (e: HTMLElement) => {
|
|
7
|
-
if (!e) return
|
|
8
|
-
|
|
9
|
-
setScrollState({
|
|
10
|
-
scrollWidth: e.scrollWidth ?? 0,
|
|
11
|
-
scrollHeight: e.scrollHeight ?? 0,
|
|
12
|
-
currentXScroll: (e.scrollLeft ?? 0) + (e.clientWidth ?? 0),
|
|
13
|
-
currentYScroll: (e.scrollTop ?? 0) + (e.clientHeight ?? 0),
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const element = elementRef?.current
|
|
19
|
-
|
|
20
|
-
if (element) {
|
|
21
|
-
handleScroll(element) // Set initial scroll state
|
|
22
|
-
element.addEventListener('scroll', () => handleScroll(element))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return () => {
|
|
26
|
-
element?.removeEventListener('scroll', () => handleScroll(element))
|
|
27
|
-
}
|
|
28
|
-
}, [elementRef])
|
|
29
|
-
|
|
30
|
-
return scrollState
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface ScrollState {
|
|
34
|
-
scrollWidth: number
|
|
35
|
-
scrollHeight: number
|
|
36
|
-
currentXScroll: number
|
|
37
|
-
currentYScroll: number
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default useScrollRef
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const useScrollRef = (elementRef: React.RefObject<HTMLElement>) => {
|
|
4
|
+
const [scrollState, setScrollState] = useState<ScrollState>()
|
|
5
|
+
|
|
6
|
+
const handleScroll = (e: HTMLElement) => {
|
|
7
|
+
if (!e) return
|
|
8
|
+
|
|
9
|
+
setScrollState({
|
|
10
|
+
scrollWidth: e.scrollWidth ?? 0,
|
|
11
|
+
scrollHeight: e.scrollHeight ?? 0,
|
|
12
|
+
currentXScroll: (e.scrollLeft ?? 0) + (e.clientWidth ?? 0),
|
|
13
|
+
currentYScroll: (e.scrollTop ?? 0) + (e.clientHeight ?? 0),
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const element = elementRef?.current
|
|
19
|
+
|
|
20
|
+
if (element) {
|
|
21
|
+
handleScroll(element) // Set initial scroll state
|
|
22
|
+
element.addEventListener('scroll', () => handleScroll(element))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return () => {
|
|
26
|
+
element?.removeEventListener('scroll', () => handleScroll(element))
|
|
27
|
+
}
|
|
28
|
+
}, [elementRef])
|
|
29
|
+
|
|
30
|
+
return scrollState
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ScrollState {
|
|
34
|
+
scrollWidth: number
|
|
35
|
+
scrollHeight: number
|
|
36
|
+
currentXScroll: number
|
|
37
|
+
currentYScroll: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default useScrollRef
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import Table, { IPaginationProps, ITableDimensionProps, ITableConfig, TableData } from '../molecules/table'
|
|
2
|
-
|
|
3
|
-
const GenericTable = <TColumn, TRow>({
|
|
4
|
-
columnData,
|
|
5
|
-
rowData,
|
|
6
|
-
mapToTableData,
|
|
7
|
-
headerAxis = 'x',
|
|
8
|
-
pageSize = 10,
|
|
9
|
-
currentPage = 1,
|
|
10
|
-
keepPreviousData = true,
|
|
11
|
-
...props
|
|
12
|
-
}: IProps<TColumn, TRow>) => {
|
|
13
|
-
const tableData = mapToTableData(columnData, rowData)
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<Table
|
|
17
|
-
tableData={tableData}
|
|
18
|
-
headerAxis={headerAxis}
|
|
19
|
-
pageSize={pageSize}
|
|
20
|
-
currentPage={currentPage}
|
|
21
|
-
keepPreviousData={keepPreviousData}
|
|
22
|
-
{...props}
|
|
23
|
-
/>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface IProps<TColumn, TRow> extends ITableConfig, IPaginationProps, ITableDimensionProps {
|
|
28
|
-
id?: string
|
|
29
|
-
columnData: TColumn
|
|
30
|
-
rowData: TRow
|
|
31
|
-
mapToTableData: (colData: TColumn, rowData: TRow) => TableData
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default GenericTable
|
|
1
|
+
import Table, { IPaginationProps, ITableDimensionProps, ITableConfig, TableData } from '../molecules/table'
|
|
2
|
+
|
|
3
|
+
const GenericTable = <TColumn, TRow>({
|
|
4
|
+
columnData,
|
|
5
|
+
rowData,
|
|
6
|
+
mapToTableData,
|
|
7
|
+
headerAxis = 'x',
|
|
8
|
+
pageSize = 10,
|
|
9
|
+
currentPage = 1,
|
|
10
|
+
keepPreviousData = true,
|
|
11
|
+
...props
|
|
12
|
+
}: IProps<TColumn, TRow>) => {
|
|
13
|
+
const tableData = mapToTableData(columnData, rowData)
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Table
|
|
17
|
+
tableData={tableData}
|
|
18
|
+
headerAxis={headerAxis}
|
|
19
|
+
pageSize={pageSize}
|
|
20
|
+
currentPage={currentPage}
|
|
21
|
+
keepPreviousData={keepPreviousData}
|
|
22
|
+
{...props}
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface IProps<TColumn, TRow> extends ITableConfig, IPaginationProps, ITableDimensionProps {
|
|
28
|
+
id?: string
|
|
29
|
+
columnData: TColumn
|
|
30
|
+
rowData: TRow
|
|
31
|
+
mapToTableData: (colData: TColumn, rowData: TRow) => TableData
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default GenericTable
|