@propellerads/table 5.1.1 → 6.0.0
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/dist/index.d.ts +114 -22
- package/dist/index.js +495 -6
- package/dist/index.js.map +1 -0
- package/package.json +31 -27
- package/dist/propsGetter.d.ts +0 -9
- package/dist/style.d.ts +0 -22
- package/dist/table.cjs.development.js +0 -650
- package/dist/table.cjs.development.js.map +0 -1
- package/dist/table.cjs.production.min.js +0 -2
- package/dist/table.cjs.production.min.js.map +0 -1
- package/dist/table.esm.js +0 -641
- package/dist/table.esm.js.map +0 -1
- package/dist/types.d.ts +0 -114
- package/dist/useLoadingState.d.ts +0 -5
- package/dist/useTableShadow.d.ts +0 -2
- package/src/index.tsx +0 -544
- package/src/propsGetter.tsx +0 -93
- package/src/style.tsx +0 -215
- package/src/types.tsx +0 -173
- package/src/useLoadingState.tsx +0 -52
- package/src/useTableShadow.tsx +0 -68
package/src/style.tsx
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/* eslint max-len: off */
|
|
2
|
-
import styled, {keyframes, css, CSSObject} from 'styled-components';
|
|
3
|
-
import {fontNormal, white, black, spacing, gray80, gray95} from '@propellerads/stylevariables';
|
|
4
|
-
|
|
5
|
-
const loadingAnimation = keyframes`
|
|
6
|
-
from {
|
|
7
|
-
background-position-x: 0;
|
|
8
|
-
}
|
|
9
|
-
50% {
|
|
10
|
-
background-position-x: 100%;
|
|
11
|
-
}
|
|
12
|
-
100% {
|
|
13
|
-
background-position-x: 0;
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
export const TableLoading = styled.div`
|
|
18
|
-
display: block;
|
|
19
|
-
position: absolute;
|
|
20
|
-
left: 0;
|
|
21
|
-
right: 0;
|
|
22
|
-
top: 0;
|
|
23
|
-
bottom: 0;
|
|
24
|
-
background: rgba(255, 255, 255, 0.8);
|
|
25
|
-
transition: all 0.3s ease;
|
|
26
|
-
z-index: -1;
|
|
27
|
-
opacity: 0;
|
|
28
|
-
pointer-events: none;
|
|
29
|
-
|
|
30
|
-
${(props: {isLoading: boolean}) =>
|
|
31
|
-
props.isLoading &&
|
|
32
|
-
css`
|
|
33
|
-
opacity: 1;
|
|
34
|
-
z-index: 2;
|
|
35
|
-
pointer-events: all;
|
|
36
|
-
`}
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
export const TableLoadingInner = styled.div`
|
|
40
|
-
position: absolute;
|
|
41
|
-
display: block;
|
|
42
|
-
text-align: center;
|
|
43
|
-
width: 100%;
|
|
44
|
-
top: 50%;
|
|
45
|
-
left: 0;
|
|
46
|
-
color: rgba(0, 0, 0, 0.6);
|
|
47
|
-
transform: translateY(-52%);
|
|
48
|
-
transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
49
|
-
`;
|
|
50
|
-
|
|
51
|
-
export const TableWrapper = styled.div`
|
|
52
|
-
position: relative;
|
|
53
|
-
overflow: hidden;
|
|
54
|
-
|
|
55
|
-
&::before {
|
|
56
|
-
bottom: 10px;
|
|
57
|
-
content: '';
|
|
58
|
-
opacity: 0;
|
|
59
|
-
pointer-events: none;
|
|
60
|
-
position: absolute;
|
|
61
|
-
width: 10px;
|
|
62
|
-
height: 100%;
|
|
63
|
-
top: 0;
|
|
64
|
-
left: -10px;
|
|
65
|
-
box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.2);
|
|
66
|
-
transition: 0.3s opacity;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
&::after {
|
|
70
|
-
bottom: 10px;
|
|
71
|
-
content: '';
|
|
72
|
-
opacity: 0;
|
|
73
|
-
pointer-events: none;
|
|
74
|
-
width: 10px;
|
|
75
|
-
height: 100%;
|
|
76
|
-
position: absolute;
|
|
77
|
-
top: 0;
|
|
78
|
-
right: -10px;
|
|
79
|
-
box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.2);
|
|
80
|
-
transition: 0.3s opacity;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
&.shadow_left {
|
|
84
|
-
&::before {
|
|
85
|
-
opacity: 1 !important;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
&.shadow_right {
|
|
90
|
-
&::after {
|
|
91
|
-
opacity: 1 !important;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
`;
|
|
95
|
-
|
|
96
|
-
export const TableRoot = styled.div`
|
|
97
|
-
font-size: ${fontNormal}px;
|
|
98
|
-
position: relative;
|
|
99
|
-
display: flex;
|
|
100
|
-
flex-direction: column;
|
|
101
|
-
border: 0;
|
|
102
|
-
`;
|
|
103
|
-
|
|
104
|
-
export const TableContent = styled.div`
|
|
105
|
-
display: block;
|
|
106
|
-
max-width: 100%;
|
|
107
|
-
overflow-x: scroll;
|
|
108
|
-
overflow-y: hidden;
|
|
109
|
-
`;
|
|
110
|
-
|
|
111
|
-
export const TableCore = styled.div`
|
|
112
|
-
flex: auto 1;
|
|
113
|
-
display: flex;
|
|
114
|
-
flex-direction: column;
|
|
115
|
-
align-items: stretch;
|
|
116
|
-
border-collapse: collapse;
|
|
117
|
-
`;
|
|
118
|
-
|
|
119
|
-
export const HeadCell = styled.div`
|
|
120
|
-
display: inline-flex;
|
|
121
|
-
`;
|
|
122
|
-
|
|
123
|
-
export const TD = styled.div`
|
|
124
|
-
white-space: nowrap;
|
|
125
|
-
text-overflow: ellipsis;
|
|
126
|
-
line-height: 1.3rem;
|
|
127
|
-
padding: 7px 4px;
|
|
128
|
-
overflow: hidden;
|
|
129
|
-
transition: width 0.3s ease 0s, min-width, padding, opacity;
|
|
130
|
-
|
|
131
|
-
${({align}: {align?: CSSObject; colSpan?: number}) =>
|
|
132
|
-
align &&
|
|
133
|
-
css`
|
|
134
|
-
text-align: ${align};
|
|
135
|
-
`}
|
|
136
|
-
`;
|
|
137
|
-
|
|
138
|
-
export const EmptyStateCell = styled.div`
|
|
139
|
-
width: 100%;
|
|
140
|
-
height: ${spacing * 4}px;
|
|
141
|
-
background: linear-gradient(to left, ${gray95}, ${white}, ${gray95});
|
|
142
|
-
background-size: 200% 200%;
|
|
143
|
-
animation: ${loadingAnimation} 1.6s linear infinite;
|
|
144
|
-
`;
|
|
145
|
-
|
|
146
|
-
export const TH = styled.div`
|
|
147
|
-
padding: 0 4px;
|
|
148
|
-
line-height: normal;
|
|
149
|
-
position: relative;
|
|
150
|
-
transition: box-shadow 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0s;
|
|
151
|
-
color: rgb(0, 0, 0);
|
|
152
|
-
font-weight: 500;
|
|
153
|
-
outline: none;
|
|
154
|
-
`;
|
|
155
|
-
|
|
156
|
-
export const THead = styled.div`
|
|
157
|
-
flex: 1 0 auto;
|
|
158
|
-
display: flex;
|
|
159
|
-
flex-direction: column;
|
|
160
|
-
user-select: none;
|
|
161
|
-
|
|
162
|
-
${TH}, ${TD} {
|
|
163
|
-
padding: 0 4px;
|
|
164
|
-
line-height: normal;
|
|
165
|
-
position: relative;
|
|
166
|
-
transition: box-shadow 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
167
|
-
color: ${black};
|
|
168
|
-
font-weight: 500;
|
|
169
|
-
outline: none;
|
|
170
|
-
}
|
|
171
|
-
`;
|
|
172
|
-
|
|
173
|
-
export const TRGroup = styled.div`
|
|
174
|
-
display: flex;
|
|
175
|
-
flex: 1 0 auto;
|
|
176
|
-
box-shadow: inset 0 -1px 0 0 ${gray95};
|
|
177
|
-
min-width: 100%;
|
|
178
|
-
width: max-content;
|
|
179
|
-
`;
|
|
180
|
-
|
|
181
|
-
export const TR = styled.div`
|
|
182
|
-
padding: 0;
|
|
183
|
-
-webkit-box-align: center;
|
|
184
|
-
align-items: center;
|
|
185
|
-
`;
|
|
186
|
-
|
|
187
|
-
export const TBody = styled.div`
|
|
188
|
-
border-top: 1px solid ${gray80};
|
|
189
|
-
margin-top: ${spacing * 2}px;
|
|
190
|
-
min-width: 100%;
|
|
191
|
-
width: max-content;
|
|
192
|
-
`;
|
|
193
|
-
|
|
194
|
-
export const TFoot = styled.div`
|
|
195
|
-
background: ${gray95};
|
|
196
|
-
flex: 1 0 auto;
|
|
197
|
-
display: flex;
|
|
198
|
-
flex-direction: column;
|
|
199
|
-
`;
|
|
200
|
-
|
|
201
|
-
export const TResizer = styled.div`
|
|
202
|
-
display: inline-block;
|
|
203
|
-
position: absolute;
|
|
204
|
-
right: 5px;
|
|
205
|
-
top: 0;
|
|
206
|
-
z-index: 1;
|
|
207
|
-
touch-action: none;
|
|
208
|
-
|
|
209
|
-
&:after {
|
|
210
|
-
content: '↔';
|
|
211
|
-
position: absolute;
|
|
212
|
-
right: 0;
|
|
213
|
-
top: 0;
|
|
214
|
-
}
|
|
215
|
-
`;
|
package/src/types.tsx
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import React, {FunctionComponent, ReactElement, ReactNode} from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Cell,
|
|
4
|
-
CellPropGetter,
|
|
5
|
-
Column,
|
|
6
|
-
FooterGroupPropGetter,
|
|
7
|
-
FooterPropGetter,
|
|
8
|
-
HeaderGroup,
|
|
9
|
-
HeaderGroupPropGetter,
|
|
10
|
-
Hooks,
|
|
11
|
-
Meta,
|
|
12
|
-
Row,
|
|
13
|
-
RowPropGetter,
|
|
14
|
-
TableBodyPropGetter,
|
|
15
|
-
TablePropGetter,
|
|
16
|
-
TableState,
|
|
17
|
-
UsePaginationInstanceProps,
|
|
18
|
-
UsePaginationOptions,
|
|
19
|
-
UsePaginationState,
|
|
20
|
-
UseRowSelectInstanceProps,
|
|
21
|
-
UseRowSelectState,
|
|
22
|
-
UseSortByColumnProps,
|
|
23
|
-
UseRowSelectRowProps,
|
|
24
|
-
UseSortByInstanceProps,
|
|
25
|
-
UseSortByOptions,
|
|
26
|
-
UseTableOptions,
|
|
27
|
-
HeaderPropGetter,
|
|
28
|
-
} from 'react-table';
|
|
29
|
-
|
|
30
|
-
export type DefaultObject = Record<string, string | number | unknown>;
|
|
31
|
-
|
|
32
|
-
export type LoadingState = {
|
|
33
|
-
loadingColumns?: Column[];
|
|
34
|
-
loadingData: any[];
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export enum FOOTER_PLACEMENT {
|
|
38
|
-
TOP = 'top',
|
|
39
|
-
BOTTOM = 'bottom',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type PaginationProps = {
|
|
43
|
-
paginationAmount?: string | ReactNode | ReactElement;
|
|
44
|
-
parentElementId: string;
|
|
45
|
-
labelPerPage?: string;
|
|
46
|
-
pageSizes?: Array<string | number>;
|
|
47
|
-
pageIndex: number;
|
|
48
|
-
perPage: number;
|
|
49
|
-
totalPages: number;
|
|
50
|
-
totalItems: number;
|
|
51
|
-
canNextPage: boolean;
|
|
52
|
-
canPreviousPage: boolean;
|
|
53
|
-
nextPageHandler: () => void;
|
|
54
|
-
previousPageHandler: () => void;
|
|
55
|
-
setPageSize: (size: number) => void;
|
|
56
|
-
gotoPage: (page: number) => void;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type ControlledPagination = {
|
|
60
|
-
paginationAmount?: string | ReactNode | ReactElement;
|
|
61
|
-
pageSize: number;
|
|
62
|
-
pageIndex: number;
|
|
63
|
-
pageCount: number;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type TableProps = {
|
|
67
|
-
columns: Array<Column<DefaultObject>>;
|
|
68
|
-
data: [];
|
|
69
|
-
totalItems?: number;
|
|
70
|
-
PaginationComponent: React.FunctionComponent<PaginationProps>;
|
|
71
|
-
initialState: Partial<TableState<DefaultObject>>;
|
|
72
|
-
fetchData?: (params: {pageIndex: number; pageSize: number}) => void;
|
|
73
|
-
onSortedChange?: (id: string, isDesc: boolean) => void;
|
|
74
|
-
isLoading?: boolean;
|
|
75
|
-
footerPlacement?: Array<FOOTER_PLACEMENT>;
|
|
76
|
-
hasDefaultPagination?: boolean;
|
|
77
|
-
onSelectRowsChange?: (rows: Array<DefaultObject>) => void;
|
|
78
|
-
controlledPagination?: ControlledPagination;
|
|
79
|
-
loadingMessage?: string;
|
|
80
|
-
labelPerPage?: string;
|
|
81
|
-
parentElementId?: string;
|
|
82
|
-
tableContentId?: string;
|
|
83
|
-
getRowPreProps?: (row: Row) => DefaultObject;
|
|
84
|
-
getTableProps?: TableGetter;
|
|
85
|
-
getHeaderGroupProps?: ElementGetter;
|
|
86
|
-
getHeaderProps?: ElementGetter;
|
|
87
|
-
getRowProps?: ElementGetter;
|
|
88
|
-
getCellProps?: ElementGetter;
|
|
89
|
-
getFooterProps?: ElementGetter;
|
|
90
|
-
getFooterGroupProps?: ElementGetter;
|
|
91
|
-
showLoadingState?: boolean;
|
|
92
|
-
LoadingCellComponent?: FunctionComponent<DefaultObject>;
|
|
93
|
-
noDataMessage?: string | ReactElement;
|
|
94
|
-
rowSubComponent?: (row: StandardRow) => ReactElement;
|
|
95
|
-
isEnableRowSelect?: (original: DefaultObject) => boolean;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type TableOptions = {
|
|
99
|
-
columns: Array<Column<DefaultObject>>;
|
|
100
|
-
data: Array<DefaultObject>;
|
|
101
|
-
initialState: {
|
|
102
|
-
pageIndex?: number;
|
|
103
|
-
pageSize?: number;
|
|
104
|
-
};
|
|
105
|
-
disableSortRemove: boolean;
|
|
106
|
-
disableMultiSort: boolean;
|
|
107
|
-
disableMultiRemove: boolean;
|
|
108
|
-
manualSortBy?: boolean;
|
|
109
|
-
autoResetPage?: boolean;
|
|
110
|
-
manualPagination?: boolean;
|
|
111
|
-
pageCount?: number;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export type MetaProps = {
|
|
115
|
-
column?: HeaderGroup<DefaultObject>;
|
|
116
|
-
cell?: Cell;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export type BaseMeta = Meta<DefaultObject, MetaProps>;
|
|
120
|
-
|
|
121
|
-
export type TableGetter = (props: DefaultObject) => DefaultObject;
|
|
122
|
-
|
|
123
|
-
export type ElementGetter = (props: DefaultObject, meta: BaseMeta) => DefaultObject;
|
|
124
|
-
|
|
125
|
-
export type ElementCellPropGetter = CellPropGetter<DefaultObject>;
|
|
126
|
-
|
|
127
|
-
export type ElementRowPropGetter = RowPropGetter<DefaultObject>;
|
|
128
|
-
|
|
129
|
-
export type ElementHeaderFooterPropGetter =
|
|
130
|
-
| FooterGroupPropGetter<DefaultObject>
|
|
131
|
-
| HeaderGroupPropGetter<DefaultObject>
|
|
132
|
-
| FooterPropGetter<DefaultObject>;
|
|
133
|
-
|
|
134
|
-
export type GetTableContainerPropsGetter = (
|
|
135
|
-
userGetter?: TableGetter,
|
|
136
|
-
getter?: TableGetter,
|
|
137
|
-
) => TablePropGetter<DefaultObject> | TableBodyPropGetter<DefaultObject>;
|
|
138
|
-
|
|
139
|
-
export type GetTableElementPropsGetter<T> = (userGetter?: ElementGetter, getter?: ElementGetter) => T;
|
|
140
|
-
|
|
141
|
-
export type GetTableElementInternalPropsGetter = (
|
|
142
|
-
internalProps: DefaultObject,
|
|
143
|
-
userGetter?: ElementGetter,
|
|
144
|
-
getter?: ElementGetter,
|
|
145
|
-
) => HeaderPropGetter<DefaultObject>;
|
|
146
|
-
|
|
147
|
-
export type ColumnWithSort = HeaderGroup<DefaultObject> & Partial<UseSortByColumnProps<DefaultObject>>;
|
|
148
|
-
|
|
149
|
-
export type StandardColumn = Column<DefaultObject>;
|
|
150
|
-
|
|
151
|
-
export type StandardRow = Row<DefaultObject> & {isExpanded?: boolean};
|
|
152
|
-
|
|
153
|
-
export type SelectableRow = Row<{id: string}> & UseRowSelectRowProps<DefaultObject>;
|
|
154
|
-
|
|
155
|
-
export type StandardCell = Cell<DefaultObject>;
|
|
156
|
-
|
|
157
|
-
export type SelectableRowInstanceProps = UseRowSelectInstanceProps<DefaultObject>;
|
|
158
|
-
|
|
159
|
-
export type StandardHooks = Hooks<DefaultObject>;
|
|
160
|
-
|
|
161
|
-
export type TableHooksInstanceProps = UseSortByInstanceProps<DefaultObject> &
|
|
162
|
-
UsePaginationInstanceProps<DefaultObject> &
|
|
163
|
-
UseRowSelectInstanceProps<DefaultObject> & {
|
|
164
|
-
state: UseRowSelectState<DefaultObject> & UsePaginationState<DefaultObject>;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
export type TableOptionsProps = UseTableOptions<DefaultObject> &
|
|
168
|
-
UseSortByOptions<DefaultObject> &
|
|
169
|
-
UsePaginationOptions<DefaultObject> & {
|
|
170
|
-
initialState: Partial<TableState<DefaultObject>> & Partial<UsePaginationState<DefaultObject>>;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
export class Table extends React.Component<Partial<TableProps>> {}
|
package/src/useLoadingState.tsx
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React, {FunctionComponent, useMemo} from 'react';
|
|
2
|
-
import {Column} from 'react-table';
|
|
3
|
-
import {DefaultObject, LoadingState} from './types';
|
|
4
|
-
|
|
5
|
-
const useLoadingState = (
|
|
6
|
-
showLoadingState: boolean,
|
|
7
|
-
loading: boolean,
|
|
8
|
-
pageSize: number,
|
|
9
|
-
columns: Column<DefaultObject>[],
|
|
10
|
-
LoadingCellComponent: FunctionComponent<DefaultObject>,
|
|
11
|
-
): LoadingState => {
|
|
12
|
-
const loadingColumns: Column<DefaultObject>[] | undefined = useMemo(
|
|
13
|
-
() =>
|
|
14
|
-
showLoadingState && loading
|
|
15
|
-
? columns.map((column: Column<DefaultObject>) => {
|
|
16
|
-
const loadingColumn: Column<DefaultObject> = {
|
|
17
|
-
...column,
|
|
18
|
-
Cell: () => <LoadingCellComponent />,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return loadingColumn;
|
|
22
|
-
})
|
|
23
|
-
: [],
|
|
24
|
-
[columns, loading, showLoadingState],
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const loadingData = useMemo(() => {
|
|
28
|
-
if (showLoadingState && loading && columns && columns.length > 0) {
|
|
29
|
-
const dataObject: DefaultObject = {};
|
|
30
|
-
const dataArray: DefaultObject[] = [];
|
|
31
|
-
|
|
32
|
-
for (let i = 0; i < columns.length; i += 1) {
|
|
33
|
-
dataObject[`empty_${i}`] = '';
|
|
34
|
-
}
|
|
35
|
-
for (let i = 0; i < pageSize; i += 1) {
|
|
36
|
-
dataArray.push(dataObject);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return dataArray;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return [];
|
|
43
|
-
}, [columns, loading, pageSize, showLoadingState]);
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
loadingColumns,
|
|
48
|
-
loadingData,
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export default useLoadingState;
|
package/src/useTableShadow.tsx
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
import {useEffect} from 'react';
|
|
3
|
-
|
|
4
|
-
const TABLE_SHADOW_CLASS_NAME = {
|
|
5
|
-
LEFT: 'shadow_left',
|
|
6
|
-
RIGHT: 'shadow_right',
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function changeClassName(tableWrapperNode: Element, newClassNameList: string[]) {
|
|
10
|
-
const {classList} = tableWrapperNode;
|
|
11
|
-
|
|
12
|
-
classList.remove(TABLE_SHADOW_CLASS_NAME.LEFT, TABLE_SHADOW_CLASS_NAME.RIGHT);
|
|
13
|
-
classList.add(...newClassNameList);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function calculateNewClassNames(tableNode, tableWrapperNode) {
|
|
17
|
-
if (!tableNode || !tableWrapperNode) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const tableRect = tableNode.getBoundingClientRect();
|
|
22
|
-
const tableWrapperRect = tableWrapperNode.getBoundingClientRect();
|
|
23
|
-
const newClassName = [];
|
|
24
|
-
|
|
25
|
-
const tableRectLeft = Math.floor(tableRect.left);
|
|
26
|
-
const tableRectRight = Math.floor(tableRect.right);
|
|
27
|
-
const tableWrapperRectLeft = Math.floor(tableWrapperRect.left);
|
|
28
|
-
const tableWrapperRectRight = Math.floor(tableWrapperRect.right);
|
|
29
|
-
|
|
30
|
-
if (tableRectLeft < tableWrapperRectLeft) {
|
|
31
|
-
newClassName.push(TABLE_SHADOW_CLASS_NAME.LEFT);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (tableRectRight > tableWrapperRectRight) {
|
|
35
|
-
newClassName.push(TABLE_SHADOW_CLASS_NAME.RIGHT);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
changeClassName(tableWrapperNode, newClassName);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default (tableRef, tableWrapperRef) => {
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
let ticking = false;
|
|
44
|
-
|
|
45
|
-
function onMousewheel() {
|
|
46
|
-
if (ticking) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
window.requestAnimationFrame(() => {
|
|
51
|
-
calculateNewClassNames(tableRef.current, tableWrapperRef.current);
|
|
52
|
-
ticking = false;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
ticking = true;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
calculateNewClassNames(tableRef.current, tableWrapperRef.current);
|
|
59
|
-
|
|
60
|
-
tableRef?.current?.addEventListener('mousewheel', onMousewheel);
|
|
61
|
-
window.addEventListener('resize', onMousewheel);
|
|
62
|
-
|
|
63
|
-
return () => {
|
|
64
|
-
tableRef?.current?.removeEventListener('mousewheel', onMousewheel);
|
|
65
|
-
window.removeEventListener('resize', onMousewheel);
|
|
66
|
-
};
|
|
67
|
-
}, [tableRef.current, tableWrapperRef.current]);
|
|
68
|
-
};
|