jattac.libs.web.responsive-table 0.2.3 → 0.2.4
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/README.md +152 -147
- package/dist/Data/IResponsiveTableColumnDefinition.d.ts +4 -0
- package/dist/Plugins/SortPlugin.d.ts +29 -0
- package/dist/UI/ResponsiveTable.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +118 -5
- package/dist/index.js.map +1 -1
- package/package.json +12 -6
- package/.eslintrc.json +0 -8
- package/.prettierrc +0 -5
- package/gemini/index.md +0 -1
- package/gemini/project_analysis.md +0 -41
- package/gemini/project_memos.md +0 -3
- package/gemini/release_git_steps.md +0 -80
- package/rollup.config.js +0 -23
- package/set-origin-urls.sh +0 -32
- package/src/Data/IFooterColumnDefinition.ts +0 -21
- package/src/Data/IFooterRowDefinition.ts +0 -5
- package/src/Data/IResponsiveTableColumnDefinition.tsx +0 -12
- package/src/Plugins/FilterPlugin.tsx +0 -71
- package/src/Plugins/IResponsiveTablePlugin.ts +0 -48
- package/src/Plugins/InfiniteScrollPlugin.tsx +0 -73
- package/src/Styles/ResponsiveTable.module.css +0 -260
- package/src/UI/ResponsiveTable.tsx +0 -552
- package/src/index.tsx +0 -10
- package/src/typings.d.ts +0 -14
- package/tsconfig.json +0 -22
- package/update-dependancies.sh +0 -4
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jattac.libs.web.responsive-table",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "A fully responsive, customizable, and lightweight React table component with a modern, mobile-first design and a powerful plugin system.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "rollup -c",
|
|
13
|
+
"watch": "rollup -c -w",
|
|
10
14
|
"lint": "eslint './{src,app}/**/*.{ts,tsx}'",
|
|
11
15
|
"size": "size-limit",
|
|
12
16
|
"prepare": "npm run build"
|
|
13
17
|
},
|
|
14
18
|
"keywords": [
|
|
15
19
|
"react",
|
|
16
|
-
"typescript"
|
|
20
|
+
"typescript",
|
|
21
|
+
"table",
|
|
22
|
+
"responsive",
|
|
23
|
+
"component"
|
|
17
24
|
],
|
|
18
25
|
"author": "Nyingi Maina",
|
|
19
26
|
"license": "MIT",
|
|
@@ -25,6 +32,7 @@
|
|
|
25
32
|
"devDependencies": {
|
|
26
33
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
27
34
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
35
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
28
36
|
"@rollup/plugin-typescript": "^11.1.5",
|
|
29
37
|
"@size-limit/preset-small-lib": "^10.0.1",
|
|
30
38
|
"@testing-library/react": "^14.0.0",
|
|
@@ -38,7 +46,6 @@
|
|
|
38
46
|
"eslint-plugin-prettier": "^5.0.1",
|
|
39
47
|
"eslint-plugin-react": "^7.33.2",
|
|
40
48
|
"identity-obj-proxy": "^3.0.0",
|
|
41
|
-
"npm": "^10.2.2",
|
|
42
49
|
"postcss": "^8.4.31",
|
|
43
50
|
"prettier": "^3.0.3",
|
|
44
51
|
"react": "^18.2.0",
|
|
@@ -53,8 +60,7 @@
|
|
|
53
60
|
"typescript": "^5.2.2"
|
|
54
61
|
},
|
|
55
62
|
"dependencies": {
|
|
56
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
57
63
|
"react-window": "^1.8.11",
|
|
58
64
|
"tslib": "^2.6.2"
|
|
59
65
|
}
|
|
60
|
-
}
|
|
66
|
+
}
|
package/.eslintrc.json
DELETED
package/.prettierrc
DELETED
package/gemini/index.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Please inspect this directory recursively to understand the project in depth. Analyze its purpose, technology stack, core features, and overall structure. Provide a comprehensive explanation based on your findings. Start by listing all relevant files and then read the contents of key files like `package.json`, `README.md`, and any other configuration or source files that seem important.
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
Based on the files, here's an in-depth understanding of the project:
|
|
3
|
-
|
|
4
|
-
**Project Goal:**
|
|
5
|
-
|
|
6
|
-
The project, `jattac.libs.web.responsive-table`, is a reusable **React component library** that provides a highly customizable and responsive table. The key feature is its ability to transform from a traditional tabular layout on larger screens to a more readable card-based layout on mobile devices.
|
|
7
|
-
|
|
8
|
-
**Core Functionality & Features:**
|
|
9
|
-
|
|
10
|
-
* **Responsiveness:** This is the primary selling point. It automatically adapts the table's presentation based on the screen width (`mobileBreakpoint` prop), ensuring a good user experience on both desktop and mobile.
|
|
11
|
-
* **Data-Driven:** The table is populated with data passed through the `data` prop. The structure of the table (columns) is defined by the `columnDefinitions` prop.
|
|
12
|
-
* **Customizable Rendering:** The `cellRenderer` function in the column definitions allows developers to render any React component within a cell, enabling rich content like buttons, links, formatted text, and more.
|
|
13
|
-
* **Dynamic Columns:** Column definitions can be functions, allowing for the dynamic creation of columns based on application state or data properties (e.g., showing an "Admin Actions" column only for admin users).
|
|
14
|
-
* **Interactivity:**
|
|
15
|
-
* **Row Clicks:** The `onRowClick` prop allows for handling clicks on entire table rows.
|
|
16
|
-
* **Header Clicks:** The `interactivity` property on a column definition enables click handlers for table headers, useful for sorting or filtering actions.
|
|
17
|
-
* **Loading and Empty States:**
|
|
18
|
-
* It provides a `isLoading` prop to display a skeleton loader while data is being fetched, improving the user experience.
|
|
19
|
-
* A customizable `noDataComponent` can be shown when there's no data to display.
|
|
20
|
-
* **Animations:** It supports optional staggered entrance animations for rows (`animateOnLoad` prop) to make the table feel more dynamic.
|
|
21
|
-
* **Table Footer:** The `footerRows` prop allows for adding a footer to the table, which is also responsive. This is useful for displaying summary information like totals.
|
|
22
|
-
* **Styling:** It uses CSS Modules (`ResponsiveTable.module.css`) for scoped styling, preventing style conflicts with other parts of an application. It also uses CSS variables for easy theming.
|
|
23
|
-
|
|
24
|
-
**Project Structure & Technology Stack:**
|
|
25
|
-
|
|
26
|
-
* **Language:** TypeScript (`.ts`, `.tsx`) and JavaScript for the build configuration.
|
|
27
|
-
* **Framework:** React.
|
|
28
|
-
* **Build Tool:** Rollup is used to bundle the library for distribution. The `rollup.config.js` file defines the build process, including plugins for handling TypeScript, PostCSS (for CSS Modules), and resolving dependencies.
|
|
29
|
-
* **Package Manager:** npm.
|
|
30
|
-
* **Linting & Formatting:** ESLint and Prettier are used to maintain code quality and consistency.
|
|
31
|
-
* **Testing:** While no test files are present, the `package.json` includes dependencies for `@testing-library/react`, indicating that testing is intended for this project.
|
|
32
|
-
* **Distribution:** The `dist` directory (ignored by Git) is the output for the bundled library, which is then published to npm. The `package.json` defines the entry points (`main`, `module`, `types`).
|
|
33
|
-
|
|
34
|
-
**Development & Maintenance:**
|
|
35
|
-
|
|
36
|
-
* The project includes shell scripts (`set-origin-urls.sh`, `update-dependancies.sh`) to help with development tasks like updating remote URLs and managing dependencies.
|
|
37
|
-
* The `README.md` is comprehensive, providing clear installation instructions, getting-started examples, and a detailed API reference. This is crucial for a library intended for other developers to use.
|
|
38
|
-
|
|
39
|
-
**Overall Impression:**
|
|
40
|
-
|
|
41
|
-
This is a well-structured and well-documented React component library. It solves a common problem (responsive tables) with a modern and flexible approach. The focus on customization, performance (debounced resize handling), and developer experience (clear documentation, helpful scripts) makes it a high-quality project. The use of TypeScript, CSS Modules, and a proper build process are all signs of a professional and maintainable codebase.
|
package/gemini/project_memos.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
## Release Git Steps
|
|
2
|
-
|
|
3
|
-
This document outlines the sequence of Git commands to perform at the end of every release cycle to ensure the `master` branch is up-to-date, tagged, and all changes are pushed to the remote repository.
|
|
4
|
-
|
|
5
|
-
**Prerequisites:**
|
|
6
|
-
- Ensure all development work for the release is complete and committed to the `develop` branch.
|
|
7
|
-
- Ensure you are on the `develop` branch (`git checkout develop`).
|
|
8
|
-
|
|
9
|
-
**Steps:**
|
|
10
|
-
|
|
11
|
-
1. **Stage all changes (if any uncommitted changes exist on `develop`):**
|
|
12
|
-
```bash
|
|
13
|
-
git add .
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
2. **Commit changes on `develop` (if not already done):**
|
|
17
|
-
```bash
|
|
18
|
-
git commit -m "feat(release): Release vX.Y.Z
|
|
19
|
-
|
|
20
|
-
Summarize the key changes, new features, bug fixes, and any breaking changes
|
|
21
|
-
introduced in this release. This message should provide a high-level overview
|
|
22
|
-
of what's new since the last release.
|
|
23
|
-
|
|
24
|
-
Example:
|
|
25
|
-
- Introduced extensible plugin system with Filter and Infinite Scroll plugins.
|
|
26
|
-
- Refactored animation props into a dedicated object.
|
|
27
|
-
- Added virtualized scrolling for large datasets.
|
|
28
|
-
- Updated dependencies."
|
|
29
|
-
# Or, if you have a multi-line message, use a temporary file:
|
|
30
|
-
# echo "Your detailed commit message" > commit_message.txt
|
|
31
|
-
# git commit -F commit_message.txt
|
|
32
|
-
```
|
|
33
|
-
*(Note: We assume the main feature/bugfix commits are already on `develop`.)*
|
|
34
|
-
|
|
35
|
-
3. **Switch to the `master` branch:**
|
|
36
|
-
```bash
|
|
37
|
-
git checkout master
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
4. **Merge `develop` into `master`:**
|
|
41
|
-
```bash
|
|
42
|
-
git merge develop
|
|
43
|
-
```
|
|
44
|
-
*This will bring all the latest changes from `develop` into `master`.*
|
|
45
|
-
|
|
46
|
-
5. **Get the current version from `package.json`:**
|
|
47
|
-
```bash
|
|
48
|
-
# Manually read the "version" field from package.json
|
|
49
|
-
# Example: "version": "1.0.0"
|
|
50
|
-
# Let's assume the version is X.Y.Z
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
6. **Create a new Git tag for the release:**
|
|
54
|
-
```bash
|
|
55
|
-
git tag vX.Y.Z
|
|
56
|
-
```
|
|
57
|
-
*Replace `X.Y.Z` with the actual version number obtained from `package.json`.*
|
|
58
|
-
|
|
59
|
-
7. **Push the `master` branch and all tags to the remote repository:**
|
|
60
|
-
```bash
|
|
61
|
-
git push origin master --tags
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
8. **Switch back to the `develop` branch:**
|
|
65
|
-
```bash
|
|
66
|
-
git checkout develop
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
9. **Push the `develop` branch to the remote repository (to ensure it's up-to-date after the merge):**
|
|
70
|
-
```bash
|
|
71
|
-
git push origin develop
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
This sequence ensures a clean release process, updating `master`, creating a version tag, and synchronizing both branches with the remote.
|
|
75
|
-
|
|
76
|
-
10. **Delete temporary files:**
|
|
77
|
-
```bash
|
|
78
|
-
del commit_message.txt
|
|
79
|
-
```
|
|
80
|
-
*Ensure to delete any temporary files created during the release process.*
|
package/rollup.config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const postcss = require('rollup-plugin-postcss');
|
|
2
|
-
const typescript = require('@rollup/plugin-typescript');
|
|
3
|
-
const peerDepsExternal = require('rollup-plugin-peer-deps-external');
|
|
4
|
-
const resolve = require('@rollup/plugin-node-resolve').default;
|
|
5
|
-
const commonjs = require('@rollup/plugin-commonjs');
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
input: 'src/index.tsx',
|
|
9
|
-
output: {
|
|
10
|
-
dir: 'dist',
|
|
11
|
-
format: 'cjs',
|
|
12
|
-
sourcemap: true,
|
|
13
|
-
},
|
|
14
|
-
plugins: [
|
|
15
|
-
peerDepsExternal(),
|
|
16
|
-
resolve(),
|
|
17
|
-
typescript(),
|
|
18
|
-
commonjs(),
|
|
19
|
-
postcss({
|
|
20
|
-
modules: true,
|
|
21
|
-
}),
|
|
22
|
-
],
|
|
23
|
-
};
|
package/set-origin-urls.sh
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
read -p "Enter your Personal Access Token (PAT): " pat
|
|
4
|
-
|
|
5
|
-
# Get the current remote URL
|
|
6
|
-
current_url=$(git remote get-url origin)
|
|
7
|
-
|
|
8
|
-
# Determine if the remote is GitHub or Azure DevOps
|
|
9
|
-
if [[ "$current_url" == *"github.com"* ]]; then
|
|
10
|
-
repo_url=$(echo "$current_url" | sed -E 's#https://([^@]+@)?github.com/#https://github.com/#')
|
|
11
|
-
new_url=$(echo "$repo_url" | sed -E "s#https://github.com/#https://$pat@github.com/#")
|
|
12
|
-
elif [[ "$current_url" == *"visualstudio.com"* || "$current_url" == *"dev.azure.com"* ]]; then
|
|
13
|
-
repo_url=$(echo "$current_url" | sed -E 's#https://([^@]+@)?([^/]+)/#https://\2/#')
|
|
14
|
-
new_url=$(echo "$repo_url" | sed -E "s#https://#https://$pat@#")
|
|
15
|
-
else
|
|
16
|
-
echo "Unsupported remote URL format."
|
|
17
|
-
exit 1
|
|
18
|
-
fi
|
|
19
|
-
|
|
20
|
-
echo "Current remote URL: $current_url"
|
|
21
|
-
echo "Constructed new remote URL: $new_url"
|
|
22
|
-
read -p "Do you want to proceed with updating the remote URL? (y/n): " confirm
|
|
23
|
-
if [[ "$confirm" != "y" ]]; then
|
|
24
|
-
echo "Operation canceled."
|
|
25
|
-
exit 1
|
|
26
|
-
fi
|
|
27
|
-
|
|
28
|
-
git remote set-url origin "$new_url"
|
|
29
|
-
|
|
30
|
-
echo "Updated remote URL to: $new_url"
|
|
31
|
-
|
|
32
|
-
git remote -v
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
export default interface IFooterColumnDefinition {
|
|
4
|
-
colSpan: number;
|
|
5
|
-
cellRenderer: () => ReactNode;
|
|
6
|
-
/**
|
|
7
|
-
* An optional, explicit label for the footer cell, especially for mobile view.
|
|
8
|
-
* If not provided, the table could try to infer it from the corresponding column.
|
|
9
|
-
*/
|
|
10
|
-
displayLabel?: ReactNode;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* An optional click handler for the footer cell.
|
|
14
|
-
*/
|
|
15
|
-
onCellClick?: () => void;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Optional class name for custom styling of the footer cell.
|
|
19
|
-
*/
|
|
20
|
-
className?: string;
|
|
21
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
export default interface IResponsiveTableColumnDefinition<TData> {
|
|
4
|
-
displayLabel: ReactNode;
|
|
5
|
-
cellRenderer: (data: TData) => ReactNode;
|
|
6
|
-
interactivity?: {
|
|
7
|
-
id: string;
|
|
8
|
-
onHeaderClick?: (id: string) => void;
|
|
9
|
-
className?: string;
|
|
10
|
-
};
|
|
11
|
-
getFilterableValue?: (data: TData) => string | number;
|
|
12
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { IResponsiveTablePlugin, IPluginAPI } from './IResponsiveTablePlugin';
|
|
3
|
-
import IResponsiveTableColumnDefinition from '../Data/IResponsiveTableColumnDefinition';
|
|
4
|
-
|
|
5
|
-
export class FilterPlugin<TData> implements IResponsiveTablePlugin<TData> {
|
|
6
|
-
public id = 'filter';
|
|
7
|
-
private filterText = '';
|
|
8
|
-
private api!: IPluginAPI<TData>;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public onPluginInit = (api: IPluginAPI<TData>) => {
|
|
14
|
-
this.api = api;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
public renderHeader = () => {
|
|
18
|
-
if (!this.api.filterProps?.showFilter) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
return (
|
|
22
|
-
<div style={{ float: 'right', marginBottom: '1rem' }}>
|
|
23
|
-
<input
|
|
24
|
-
type="text"
|
|
25
|
-
placeholder={this.api.filterProps.filterPlaceholder || "Search..."}
|
|
26
|
-
onChange={this.handleFilterChange}
|
|
27
|
-
style={{
|
|
28
|
-
padding: '0.5rem',
|
|
29
|
-
border: '1px solid #ccc',
|
|
30
|
-
borderRadius: '4px',
|
|
31
|
-
}}
|
|
32
|
-
/>
|
|
33
|
-
</div>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
public processData = (data: TData[]): TData[] => {
|
|
38
|
-
if (!this.filterText || !this.api.columnDefinitions) {
|
|
39
|
-
return data;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const lowercasedFilter = this.filterText.toLowerCase();
|
|
43
|
-
|
|
44
|
-
return data.filter((row) => {
|
|
45
|
-
return this.api.columnDefinitions!.some((colDef) => {
|
|
46
|
-
// If colDef is a function, it won't have getFilterableValue, so skip it.
|
|
47
|
-
if (typeof colDef === 'function') {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Now we know colDef is an object (IResponsiveTableColumnDefinition<TData>)
|
|
52
|
-
const typedColDef = colDef as IResponsiveTableColumnDefinition<TData>;
|
|
53
|
-
|
|
54
|
-
// Check if getFilterableValue exists and is a function
|
|
55
|
-
if (typedColDef.getFilterableValue && typeof typedColDef.getFilterableValue === 'function') {
|
|
56
|
-
const value = typedColDef.getFilterableValue(row);
|
|
57
|
-
return value?.toString().toLowerCase().includes(lowercasedFilter);
|
|
58
|
-
}
|
|
59
|
-
return false; // If getFilterableValue is not present or not a function
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
private handleFilterChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
65
|
-
// Debounce the filter change
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
this.filterText = e.target.value;
|
|
68
|
-
this.api.forceUpdate();
|
|
69
|
-
}, 300);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { ColumnDefinition } from '../UI/ResponsiveTable';
|
|
3
|
-
|
|
4
|
-
export interface IResponsiveTablePlugin<TData> {
|
|
5
|
-
// A unique identifier for the plugin
|
|
6
|
-
id: string;
|
|
7
|
-
|
|
8
|
-
// Optional: Renders a UI component above the table
|
|
9
|
-
renderHeader?: () => ReactNode;
|
|
10
|
-
|
|
11
|
-
// Optional: Renders a UI component below the table
|
|
12
|
-
renderFooter?: () => ReactNode;
|
|
13
|
-
|
|
14
|
-
// Optional: Processes the data before it's rendered
|
|
15
|
-
processData?: (data: TData[]) => TData[];
|
|
16
|
-
|
|
17
|
-
// Optional: A callback that the table can use to provide the plugin with its own API
|
|
18
|
-
onPluginInit?: (api: IPluginAPI<TData>) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface IPluginAPI<TData> {
|
|
22
|
-
// Function to get the current data from the table
|
|
23
|
-
getData: () => TData[];
|
|
24
|
-
|
|
25
|
-
// Function to force the table to re-render
|
|
26
|
-
forceUpdate: () => void;
|
|
27
|
-
|
|
28
|
-
// Function to get the column definitions from the table
|
|
29
|
-
columnDefinitions: ColumnDefinition<TData>[];
|
|
30
|
-
|
|
31
|
-
// Function to get the scrollable element of the table
|
|
32
|
-
getScrollableElement?: () => HTMLElement | null;
|
|
33
|
-
|
|
34
|
-
// Optional: Infinite scroll props from the ResponsiveTable component
|
|
35
|
-
infiniteScrollProps?: {
|
|
36
|
-
enableInfiniteScroll?: boolean;
|
|
37
|
-
onLoadMore?: (currentData: TData[]) => Promise<TData[] | null>;
|
|
38
|
-
hasMore?: boolean;
|
|
39
|
-
loadingMoreComponent?: ReactNode;
|
|
40
|
-
noMoreDataComponent?: ReactNode;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Optional: Filter props from the ResponsiveTable component
|
|
44
|
-
filterProps?: {
|
|
45
|
-
showFilter?: boolean;
|
|
46
|
-
filterPlaceholder?: string;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { IResponsiveTablePlugin, IPluginAPI } from './IResponsiveTablePlugin';
|
|
3
|
-
|
|
4
|
-
export class InfiniteScrollPlugin<TData> implements IResponsiveTablePlugin<TData> {
|
|
5
|
-
public id = 'infinite-scroll';
|
|
6
|
-
private api!: IPluginAPI<TData>;
|
|
7
|
-
private isLoadingMore = false;
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public onPluginInit = (api: IPluginAPI<TData>) => {
|
|
13
|
-
this.api = api;
|
|
14
|
-
this.attachScrollListener();
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
private attachScrollListener = () => {
|
|
18
|
-
const scrollableElement = this.api.getScrollableElement?.();
|
|
19
|
-
if (scrollableElement) {
|
|
20
|
-
scrollableElement.addEventListener('scroll', this.handleScroll);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
private handleScroll = async () => {
|
|
25
|
-
const scrollableElement = this.api.getScrollableElement?.();
|
|
26
|
-
if (!scrollableElement || !this.api.infiniteScrollProps?.enableInfiniteScroll) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const { scrollTop, scrollHeight, clientHeight } = scrollableElement;
|
|
31
|
-
|
|
32
|
-
const scrollThreshold = 200; // Load more data when 200px from the bottom
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
scrollHeight - scrollTop - clientHeight < scrollThreshold &&
|
|
36
|
-
this.api.infiniteScrollProps.hasMore &&
|
|
37
|
-
!this.isLoadingMore
|
|
38
|
-
) {
|
|
39
|
-
this.isLoadingMore = true;
|
|
40
|
-
this.api.forceUpdate(); // Trigger re-render to show loading component
|
|
41
|
-
|
|
42
|
-
const newData = await this.api.infiniteScrollProps.onLoadMore?.(this.api.getData());
|
|
43
|
-
|
|
44
|
-
if (newData) {
|
|
45
|
-
// The main component will handle appending data via processData
|
|
46
|
-
} else {
|
|
47
|
-
// No more data, update hasMore in parent if necessary
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.isLoadingMore = false;
|
|
51
|
-
this.api.forceUpdate(); // Trigger re-render to hide loading component
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
public processData = (data: TData[]): TData[] => {
|
|
56
|
-
// This plugin doesn't modify the data directly, but rather triggers loading more.
|
|
57
|
-
// The main component's data prop should be updated by the consumer of the table.
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
public renderFooter = () => {
|
|
62
|
-
if (!this.api.infiniteScrollProps) {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (this.isLoadingMore) {
|
|
67
|
-
return this.api.infiniteScrollProps.loadingMoreComponent || <div>Loading more...</div>;
|
|
68
|
-
} else if (!this.api.infiniteScrollProps.hasMore) {
|
|
69
|
-
return this.api.infiniteScrollProps.noMoreDataComponent || <div>No more data.</div>;
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
};
|
|
73
|
-
}
|