@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.
@@ -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
- export const usePinLastRow = (
9
- pinLastRow: boolean | undefined,
10
- table: Table<any>,
11
- data: any[],
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 scrollElement = getScrollElement?.();
19
- if (scrollElement) {
20
- requestAnimationFrame(() => scrollElement.scrollTo({ top: scrollElement.scrollHeight }));
16
+ const element = scrollContextRef.current;
17
+ const scrollHeight = element?.scrollHeight;
18
+
19
+ if (element && scrollHeight) {
20
+ requestAnimationFrame(() => element.scrollTo({ top: scrollHeight }));
21
21
  }
22
- }, [getScrollElement]);
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, { useRef } from '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
- <div ref={containerRef} className='fixed inset-0 overflow-auto'>
58
- <Table<ExampleSchema>
59
- role='grid'
60
- rowsSelectable='multi'
61
- keyAccessor={(row) => JSON.stringify(row)}
62
- columns={columns}
63
- data={items}
64
- fullWidth
65
- stickyHeader
66
- border
67
- getScrollElement={() => containerRef.current}
68
- />
69
- </div>
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
  };