Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
mckervinc committed Jun 19, 2024
1 parent 1a7323a commit 1dd91b5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## 0.6.2

_2024-06-19_

### Bugfix

- (Docs) updated types

## 0.6.1

_2024-06-17_
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-fluid-table",
"version": "0.6.1",
"version": "0.6.2",
"description": "A React table inspired by react-window",
"author": "Mckervin Ceme <[email protected]>",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ const Header = forwardRef(
} = useContext(TableContext);

// variables
const { scrollWidth, clientWidth } = ((ref as React.MutableRefObject<HTMLDivElement>).current ||
NO_NODE) as HTMLDivElement;
const { scrollWidth, clientWidth } =
(ref as React.MutableRefObject<HTMLDivElement>).current || NO_NODE;
const width = scrollWidth <= clientWidth ? "100%" : undefined;
const stickyStyle: React.CSSProperties = {
zIndex: columns.find(c => c.frozen) ? 2 : undefined
Expand Down
4 changes: 2 additions & 2 deletions src/NumberTree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface LeafProps {
type LeafProps = {
height: number;
index: number;
}
};

class Leaf {
index: number;
Expand Down
16 changes: 12 additions & 4 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ type ListProps<T> = Omit<TableProps<T>, "columns" | "borders"> & {
borders: boolean;
};

type ListRef<T = any> = VariableSizeList<T> & {
_instanceProps: {
itemMetadataMap: {
[x: number]: { size: number };
};
};
};

/**
* The main table component
*/
Expand All @@ -57,7 +65,7 @@ const ListComponent = forwardRef(function (
) {
// hooks
const timeoutRef = useRef(0);
const listRef = useRef<any>(null);
const listRef = useRef<ListRef>(null);
const prevWidthRef = useRef(width);
const [tree] = useState(new NumberTree());
const tableRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -101,7 +109,7 @@ const ListComponent = forwardRef(function (
const node = tableRef.current?.children[1].children[0] as HTMLElement;
const resetIndex = Number(node?.dataset.index || "0") + 1;
tree.clearFromIndex(resetIndex);
listRef.current.resetAfterIndex(resetIndex);
listRef.current!.resetAfterIndex(resetIndex);
}, timeout);
},
[]
Expand Down Expand Up @@ -233,9 +241,9 @@ const ListComponent = forwardRef(function (
/* misc */
// provide access to window functions
useImperativeHandle(ref, () => ({
scrollTo: (scrollOffset: number): void => listRef.current.scrollTo(scrollOffset),
scrollTo: (scrollOffset: number): void => listRef.current!.scrollTo(scrollOffset),
scrollToItem: (index: number, align: ScrollAlign = "auto"): void =>
listRef.current.scrollToItem(index, align)
listRef.current!.scrollToItem(index, align)
}));

return (
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DEFAULT_ROW_HEIGHT = 37;
export const DEFAULT_HEADER_HEIGHT = 37;
export const DEFAULT_FOOTER_HEIGHT = 37;
export const NO_NODE = { scrollWidth: 0, clientWidth: 0 };
export const NO_NODE = { scrollWidth: 0, clientWidth: 0 } as HTMLDivElement;

0 comments on commit 1dd91b5

Please sign in to comment.