@dxos/react-ui-table 0.4.10-next.71cec10 → 0.5.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/lib/browser/index.mjs +108 -71
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Table/Table.d.ts +17 -4
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableBody.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableRootContext.d.ts +17 -0
- package/dist/types/src/components/Table/TableRootContext.d.ts.map +1 -0
- package/dist/types/src/components/Table/index.d.ts +1 -0
- package/dist/types/src/components/Table/index.d.ts.map +1 -1
- package/dist/types/src/components/Table/props.d.ts +2 -3
- package/dist/types/src/components/Table/props.d.ts.map +1 -1
- package/dist/types/src/hooks/usePinLastRow.d.ts +1 -1
- package/dist/types/src/hooks/usePinLastRow.d.ts.map +1 -1
- package/dist/types/src/schema/SchemaToTable.stories.d.ts.map +1 -1
- package/package.json +17 -15
- package/src/components/Table/Table.stories.tsx +114 -103
- package/src/components/Table/Table.tsx +59 -50
- package/src/components/Table/TableBody.tsx +6 -1
- package/src/components/Table/TableRootContext.ts +39 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/Table/props.ts +17 -24
- package/src/hooks/usePinLastRow.ts +10 -10
- package/src/schema/SchemaToTable.stories.tsx +15 -16
|
@@ -5,21 +5,21 @@
|
|
|
5
5
|
import { type Row, type Table } from '@tanstack/react-table';
|
|
6
6
|
import { useCallback, useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
getScrollElement?: () => Element | null,
|
|
13
|
-
) => {
|
|
8
|
+
import { useTableRootContext } from '../components';
|
|
9
|
+
|
|
10
|
+
export const usePinLastRow = (pinLastRow: boolean | undefined, table: Table<any>, data: any[]) => {
|
|
11
|
+
const { scrollContextRef } = useTableRootContext();
|
|
14
12
|
const [pinnedRowKey, setPinnedRowKey] = useState<string>();
|
|
15
13
|
|
|
16
14
|
// Scrolls to the bottom of a scrollable element.
|
|
17
15
|
const scrollToBottom = useCallback(() => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const element = scrollContextRef.current;
|
|
17
|
+
const scrollHeight = element?.scrollHeight;
|
|
18
|
+
|
|
19
|
+
if (element && scrollHeight) {
|
|
20
|
+
requestAnimationFrame(() => element.scrollTo({ top: scrollHeight }));
|
|
21
21
|
}
|
|
22
|
-
}, [
|
|
22
|
+
}, []);
|
|
23
23
|
|
|
24
24
|
const pinRow = useCallback(
|
|
25
25
|
(rowToPin: Row<any>) => {
|
|
@@ -6,7 +6,7 @@ import '@dxosTheme';
|
|
|
6
6
|
|
|
7
7
|
import * as Arbitrary from '@effect/schema/Arbitrary';
|
|
8
8
|
import * as fc from 'fast-check';
|
|
9
|
-
import React
|
|
9
|
+
import React from 'react';
|
|
10
10
|
|
|
11
11
|
import { S } from '@dxos/echo-schema';
|
|
12
12
|
import { DensityProvider } from '@dxos/react-ui';
|
|
@@ -51,22 +51,21 @@ const items = fc.sample(exampleSchemaArbitrary, 10);
|
|
|
51
51
|
|
|
52
52
|
export const SchemaTable = {
|
|
53
53
|
render: () => {
|
|
54
|
-
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
55
|
-
|
|
56
54
|
return (
|
|
57
|
-
<
|
|
58
|
-
<Table
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
<Table.Root>
|
|
56
|
+
<Table.Viewport classNames='inset-0 fixed'>
|
|
57
|
+
<Table.Table<ExampleSchema>
|
|
58
|
+
role='grid'
|
|
59
|
+
rowsSelectable='multi'
|
|
60
|
+
keyAccessor={(row) => JSON.stringify(row)}
|
|
61
|
+
columns={columns}
|
|
62
|
+
data={items}
|
|
63
|
+
fullWidth
|
|
64
|
+
stickyHeader
|
|
65
|
+
border
|
|
66
|
+
/>
|
|
67
|
+
</Table.Viewport>
|
|
68
|
+
</Table.Root>
|
|
70
69
|
);
|
|
71
70
|
},
|
|
72
71
|
};
|