Skip to content

Commit

Permalink
fix: move Table to components
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Dec 4, 2023
1 parent 85504ac commit 306be94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/Table.tsx → src/components/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useCallback, useEffect } from "react";
import { Container } from "./components/Container";
import { useExpandable } from "./hooks/useExpandable";
import { useSelectable } from "./hooks/useSelectable";
import { useSortable } from "./hooks/useSortable";
import { TableProps } from "./types";
import { Headers } from "./components/Headers";
import { Rows } from "./components/Rows";
import { useShiftSelected } from "./hooks/useShiftSelect";
import React, { useCallback, useEffect } from "react";
import { useExpandable } from "../hooks/useExpandable";
import { useSelectable } from "../hooks/useSelectable";
import { useShiftSelected } from "../hooks/useShiftSelect";
import { useSortable } from "../hooks/useSortable";
import { TableProps } from "../types";
import { Container } from "./Container";
import { Headers } from "./Headers";
import { Rows } from "./Rows";

export const Table = (props: TableProps) => {
const {
Expand Down Expand Up @@ -38,7 +38,7 @@ export const Table = (props: TableProps) => {

const onChange = useShiftSelected(
dataSource.map((el) => el.id),
changeSelected
changeSelected,
);
const { localSorter, getColumnSorter, handleColumnClick } =
useSortable(sorter);
Expand All @@ -58,10 +58,12 @@ export const Table = (props: TableProps) => {

useEffect(() => {
onRowSelectionChange?.(selectedRowKeys);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedRowKeys]);

useEffect(() => {
onChangeSort?.(localSorter);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [localSorter]);

const allRowsAreSelected = useCallback(() => {
Expand All @@ -73,7 +75,8 @@ export const Table = (props: TableProps) => {
return dataSource.length === selectedRowKeys.length;
}
return getAllVisibleKeys().length === selectedRowKeys.length;
}, [dataSource, selectedRowKeys]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dataSource.length, expandableOpts, selectedRowKeys.length]);

const onToggleAllRowsSelected = useCallback(() => {
toggleAllRowsSelected(getAllVisibleKeys());
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { Table } from "./Table";
export { Table } from "./components/Table";
export * from "./types";

0 comments on commit 306be94

Please sign in to comment.