Skip to content

Commit 5e17394

Browse files
committed
add loading animation
1 parent c3b208e commit 5e17394

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/lib/ReactDataTable/ReactDataTable.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
33
import { Paging } from "@neolution-ch/react-pattern-ui";
44
import { flexRender } from "@tanstack/react-table";
5-
import { Spinner, Table as ReactStrapTable, Input } from "reactstrap";
5+
import { Table as ReactStrapTable, Input } from "reactstrap";
66
import { reactDataTableTranslations } from "../translations/translations";
77
import { ReactDataTableProps } from "./ReactDataTableProps";
88

@@ -26,14 +26,35 @@ const ReactDataTable = <TData,>(props: ReactDataTableProps<TData>) => {
2626

2727
const { pagination } = table.getState();
2828

29+
const loadingCss = `
30+
@-webkit-keyframes reloadingAnimation {
31+
0%{
32+
background-position-x: 200%
33+
}
34+
100%{
35+
background-position-x: 0%
36+
}
37+
}`;
38+
2939
return (
3040
<>
31-
{!isLoading && isFetching && (
32-
<Spinner color="primary" type="grow">
33-
Loading...
34-
</Spinner>
35-
)}
36-
<ReactStrapTable striped hover size="sm" className={tableClassName} style={tableStyle}>
41+
<style>{loadingCss}</style>
42+
<ReactStrapTable
43+
striped
44+
hover
45+
size="sm"
46+
className={tableClassName}
47+
style={
48+
!isLoading && isFetching
49+
? {
50+
...tableStyle,
51+
background: "linear-gradient(90deg, #E8E8E8, #ffffff, #E8E8E8)",
52+
backgroundSize: "200% 200%",
53+
animation: "reloadingAnimation 3s linear infinite",
54+
}
55+
: tableStyle
56+
}
57+
>
3758
<thead>
3859
{table.getHeaderGroups().map((headerGroup) => (
3960
<>

src/lib/useReactDataTable/useReactDataTable.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ const useReactDataTable = <TData,>(props: useReactDataTableProps<TData>): useRea
5151
}));
5252
const skeletonData = Array.from({ length: paginationInternal.pageSize }, () => ({} as TData));
5353

54-
// add this so we dont have local filtering
55-
columns.filter((x) => !x.filterFn).forEach((x) => (x.filterFn = () => true));
56-
5754
const table = useReactTable<TData>({
5855
data: isLoading ? skeletonData : data,
5956
columns: isLoading ? skeletonColumns : columns,

0 commit comments

Comments
 (0)