Skip to content

Commit 320c74f

Browse files
committed
update
1 parent b47c5f4 commit 320c74f

File tree

4 files changed

+128
-3
lines changed

4 files changed

+128
-3
lines changed

examples/src/pages/tests/horizontal-layout/example.page.tsx

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
InfiniteTable,
66
InfiniteTableColumn,
77
InfiniteTablePropColumns,
8+
useInfiniteColumnCell,
89
} from '@infinite-table/infinite-react';
910
import { DataSource } from '@infinite-table/infinite-react';
1011

@@ -45,15 +46,113 @@ const style: InfiniteTableColumn<any>['style'] = (
4546

4647
const header: InfiniteTableColumn<Developer>['header'] = ({
4748
horizontalLayoutPageIndex,
49+
4850
column,
4951
}) => {
5052
return (
5153
<b>
52-
{column.field} - {horizontalLayoutPageIndex}
54+
{column.field} - {horizontalLayoutPageIndex}{' '}
55+
{column.computedSortedAsc
56+
? '📈'
57+
: column.computedSortedDesc
58+
? '📉'
59+
: '👀'}
5360
</b>
5461
);
5562
};
5663

64+
// const FlashingColumnCell = React.forwardRef(
65+
// (props: React.HTMLProps<HTMLDivElement>, ref: React.Ref<HTMLDivElement>) => {
66+
// const { domRef, value, column, rowInfo } =
67+
// useInfiniteColumnCell<Developer>();
68+
69+
// const flashBackground = 'blue';
70+
// const [flash, setFlash] = React.useState(false);
71+
72+
// const rowId = rowInfo.id;
73+
// const columnId = column.id;
74+
// const prevValueRef = React.useRef({
75+
// columnId,
76+
// rowId,
77+
// value,
78+
// });
79+
80+
// console.log(
81+
// 'render',
82+
// // props.children?.props?.children?[1].props?.children.props.children[3]
83+
// );
84+
85+
// React.useEffect(() => {
86+
// const prev = prevValueRef.current;
87+
// if (
88+
// prev.value !== value &&
89+
// prev.rowId === rowId &&
90+
// prev.columnId === columnId
91+
// ) {
92+
// console.log('value changed', value, 'prev', prev.value);
93+
// setFlash(true);
94+
// setTimeout(() => {
95+
// setFlash(false);
96+
// }, 500);
97+
// }
98+
99+
// console.log('value', value);
100+
// prevValueRef.current = {
101+
// columnId: column.id,
102+
// rowId: rowInfo.id,
103+
// value,
104+
// };
105+
// }, [value, columnId, rowId]);
106+
107+
// React.useEffect(() => {
108+
// console.log('mount');
109+
// }, []);
110+
111+
// return (
112+
// <div
113+
// ref={domRef}
114+
// {...props}
115+
// style={{
116+
// ...props.style,
117+
// background: flash ? flashBackground : props.style?.background,
118+
// }}
119+
// >
120+
// {props.children}
121+
// </div>
122+
// );
123+
// },
124+
// );
125+
126+
// const Flashing = (props: { value: any }) => {
127+
// const value = props.value;
128+
129+
// const prevValueRef = React.useRef(value);
130+
// const { htmlElementRef } = useInfiniteColumnCell();
131+
// const flash = () => {
132+
// if (!htmlElementRef.current) {
133+
// return;
134+
// }
135+
136+
// htmlElementRef.current!.style.backgroundColor = 'red';
137+
// setTimeout(() => {
138+
// htmlElementRef.current!.style.backgroundColor = '';
139+
// }, 500);
140+
// };
141+
142+
// React.useEffect(() => {
143+
// if (prevValueRef.current !== value) {
144+
// flash();
145+
// }
146+
// prevValueRef.current = value;
147+
// }, [value]);
148+
149+
// React.useEffect(() => {
150+
// flash();
151+
// }, []);
152+
153+
// return <div>{props.value}</div>;
154+
// };
155+
57156
const columns: InfiniteTablePropColumns<Developer> = {
58157
id: {
59158
field: 'id',
@@ -75,6 +174,15 @@ const columns: InfiniteTablePropColumns<Developer> = {
75174
columnGroup: 'colgroup',
76175
style,
77176
header,
177+
// renderValue: ({ value }) => {
178+
// console.log('renderValue', value);
179+
// return value;
180+
// // return <Flashing value={value} />;
181+
// },
182+
components: {
183+
// ColumnCell: FlashingColumnCell,
184+
// ColumnCell: FlashingColumnCell,
185+
},
78186
},
79187
firstName: {
80188
field: 'firstName',
@@ -149,6 +257,7 @@ export default () => {
149257
return fetch(process.env.NEXT_PUBLIC_BASE_URL + '/developers1k')
150258
.then((r) => r.json())
151259
.then((data) => {
260+
// data.length = 2;
152261
return data;
153262
// return new Promise((resolve) => {
154263
// setTimeout(() => {

source/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableColumnCell.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,22 @@ function InfiniteTableColumnCellFn<T>(props: InfiniteTableColumnCellProps<T>) {
162162

163163
fieldsToColumn,
164164

165-
domRef,
165+
domRef: initialDomRef,
166166
hidden,
167167
showZebraRows,
168168
} = props;
169169

170+
const htmlElementRef = React.useRef<HTMLElement | null>(null);
171+
const domRef = useCallback(
172+
(node: HTMLElement | null) => {
173+
htmlElementRef.current = node;
174+
if (initialDomRef) {
175+
initialDomRef(node);
176+
}
177+
},
178+
[initialDomRef],
179+
);
180+
170181
if (!column) {
171182
return <div ref={domRef}>no column</div>;
172183
}
@@ -271,6 +282,7 @@ function InfiniteTableColumnCellFn<T>(props: InfiniteTableColumnCellProps<T>) {
271282
const cellSelected = renderParam.cellSelected;
272283

273284
renderParam.domRef = domRef;
285+
renderParam.htmlElementRef = htmlElementRef;
274286

275287
renderParam.selectCell = useCallback(renderParam.selectCell, [rowInfo]);
276288
renderParam.deselectCell = useCallback(renderParam.deselectCell, [rowInfo]);

source/src/components/InfiniteTable/components/InfiniteTableRow/columnRendering.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,10 @@ export function getColumnRenderParam<T>(options: {
293293
const cellSelected =
294294
cellSelection?.isCellSelected(rowInfo.id, column.id) ?? false;
295295

296-
const renderParam: Omit<InfiniteTableColumnCellContextType<T>, 'domRef'> = {
296+
const renderParam: Omit<
297+
InfiniteTableColumnCellContextType<T>,
298+
'domRef' | 'htmlElementRef'
299+
> = {
297300
column,
298301
columnsMap,
299302
fieldsToColumn,

source/src/components/InfiniteTable/types/InfiniteTableColumn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export type InfiniteTableColumnRenderParamBase<
9292
COL_TYPE = InfiniteTableComputedColumn<DATA_TYPE>,
9393
> = {
9494
domRef: InfiniteTableCellProps<DATA_TYPE>['domRef'];
95+
htmlElementRef: React.MutableRefObject<HTMLElement | null>;
9596

9697
rowIndexInHorizontalLayoutPage: null | number;
9798
horizontalLayoutPageIndex: null | number;

0 commit comments

Comments
 (0)