@blenx-dev/datatable 0.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # @blenx-dev/datatable
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0439e3e: Use Icon generator and simplify components
8
+ - Updated dependencies [0439e3e]
9
+ - @blenx-dev/core@0.2.3
10
+ - @blenx-dev/theme@0.2.3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Prashanth Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@blenx-dev/datatable",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "dependencies": {
10
+ "@tanstack/react-table": "^8.21.3",
11
+ "@vanilla-extract/css": "^1.20.1",
12
+ "@vanilla-extract/recipes": "^0.5.7",
13
+ "@vanilla-extract/sprinkles": "^1.6.5",
14
+ "clsx": "^2.1.1",
15
+ "@blenx-dev/core": "0.2.3",
16
+ "@blenx-dev/theme": "0.2.3"
17
+ },
18
+ "devDependencies": {
19
+ "@types/react": "^19.2.15",
20
+ "@types/react-dom": "^19.2.3",
21
+ "changeset": "^0.2.6"
22
+ },
23
+ "peerDependencies": {
24
+ "react": "^19.2.6",
25
+ "react-dom": "^19.2.6",
26
+ "@blenx-dev/core": "0.2.3",
27
+ "@blenx-dev/theme": "0.2.3"
28
+ }
29
+ }
@@ -0,0 +1,54 @@
1
+ import type { Table } from "@tanstack/react-table";
2
+ import * as styles from "./data-table.css";
3
+ import { Button, Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from "@blenx-dev/core";
4
+ import { SquareCheckIcon, ListIcon } from "@blenx-dev/core/icons";
5
+
6
+ interface DataTableColumnToggleProps<TData> {
7
+ table: Table<TData>;
8
+ }
9
+
10
+ export function DataTableColumnToggle<TData>({ table }: DataTableColumnToggleProps<TData>) {
11
+ const columns = table.getAllLeafColumns().filter((column) => column.getCanHide());
12
+
13
+ if (columns.length === 0) return null;
14
+
15
+ const allVisible = columns.every((column) => column.getIsVisible());
16
+ const someVisible = columns.some((column) => column.getIsVisible());
17
+
18
+ return (
19
+ <Menu>
20
+ <MenuTrigger render={<Button variant="outline" size="sm" />}>
21
+ <ListIcon width={16} />
22
+ <span>Columns</span>
23
+ </MenuTrigger>
24
+ <MenuPopup align="end">
25
+ <MenuItem
26
+ onClick={() => {
27
+ for (const column of columns) {
28
+ column.toggleVisibility(allVisible);
29
+ }
30
+ }}
31
+ >
32
+ <span className={styles.deselectLabel}>{allVisible ? "Deselect all" : "Select all"}</span>
33
+ <span className={allVisible ? styles.checkboxChecked : styles.checkboxUnchecked}>
34
+ {allVisible && <SquareCheckIcon width={16} />}
35
+ {!allVisible && someVisible && <div className={styles.partial} />}
36
+ </span>
37
+ </MenuItem>
38
+ <MenuSeparator />
39
+ {columns.map((column) => {
40
+ const label = column.columnDef.header?.toString() ?? column.id;
41
+ const isVisible = column.getIsVisible();
42
+ return (
43
+ <MenuItem key={column.id} onClick={() => column.toggleVisibility(!isVisible)}>
44
+ <span className={styles.itemLabel}>{label}</span>
45
+ <span className={isVisible ? styles.checkboxChecked : styles.checkboxUnchecked}>
46
+ {isVisible && <SquareCheckIcon width={16} />}
47
+ </span>
48
+ </MenuItem>
49
+ );
50
+ })}
51
+ </MenuPopup>
52
+ </Menu>
53
+ );
54
+ }
@@ -0,0 +1,27 @@
1
+ import { FolderOpenIcon } from "@blenx-dev/core/icons";
2
+ import * as styles from "./data-table.css";
3
+
4
+ interface DataTableEmptyProps {
5
+ message?: string;
6
+ icon?: React.ReactNode;
7
+ action?: React.ReactNode;
8
+ }
9
+
10
+ export function DataTableEmpty({
11
+ message = "No results found",
12
+ icon,
13
+ action,
14
+ }: DataTableEmptyProps) {
15
+ return (
16
+ <output aria-label={message} className={styles.emptyContainer}>
17
+ {icon && <div className={styles.iconWrap}>{icon}</div>}
18
+ {!icon && (
19
+ <div className={styles.iconWrap}>
20
+ <FolderOpenIcon width={48} />
21
+ </div>
22
+ )}
23
+ <p className={styles.message}>{message}</p>
24
+ {action && <div className={styles.actionWrap}>{action}</div>}
25
+ </output>
26
+ );
27
+ }
@@ -0,0 +1,25 @@
1
+ import { CircleAlertIcon } from "@blenx-dev/core/icons";
2
+ import * as styles from "./data-table.css";
3
+ import { Button } from "@blenx-dev/core";
4
+
5
+ interface DataTableErrorProps {
6
+ message?: string;
7
+ onRetry?: () => void;
8
+ }
9
+
10
+ export function DataTableError({
11
+ message = "Something went wrong while loading data",
12
+ onRetry,
13
+ }: DataTableErrorProps) {
14
+ return (
15
+ <div role="alert" aria-label={message} className={styles.errorContainer}>
16
+ <CircleAlertIcon width={48} />
17
+ <p className={styles.errorMessage}>{message}</p>
18
+ {onRetry && (
19
+ <Button variant="outline" size="sm" onClick={onRetry}>
20
+ Retry
21
+ </Button>
22
+ )}
23
+ </div>
24
+ );
25
+ }
@@ -0,0 +1,73 @@
1
+ import { Button, Spinner } from "@blenx-dev/core";
2
+ import type { InfiniteScrollConfig } from "./types";
3
+ import { useInfiniteScroll } from "./use-infinite-scroll";
4
+ import * as styles from "./data-table.css";
5
+
6
+ interface DataTableInfiniteLoaderProps {
7
+ fetchNextPage: () => void;
8
+ hasNextPage: boolean;
9
+ isFetchingNextPage: boolean;
10
+ isFetching?: boolean;
11
+ config?: InfiniteScrollConfig;
12
+ }
13
+
14
+ export function DataTableInfiniteLoader({
15
+ fetchNextPage,
16
+ hasNextPage,
17
+ isFetchingNextPage,
18
+ isFetching,
19
+ config,
20
+ }: DataTableInfiniteLoaderProps) {
21
+ const isAuto = config?.mode === "auto";
22
+ const loadingText = config?.loadingText ?? "Loading...";
23
+ const noMoreText = config?.noMoreText ?? "No more results";
24
+
25
+ const { sentinelRef } = useInfiniteScroll({
26
+ hasNextPage,
27
+ isFetchingNextPage: isFetchingNextPage || Boolean(isFetching),
28
+ fetchNextPage,
29
+ rootMargin: config?.rootMargin,
30
+ threshold: config?.threshold,
31
+ enabled: isAuto,
32
+ });
33
+
34
+ if (isAuto) {
35
+ return (
36
+ <div
37
+ ref={sentinelRef}
38
+ aria-label={isFetchingNextPage ? loadingText : noMoreText}
39
+ className={styles.sentinel}
40
+ >
41
+ {isFetchingNextPage && (
42
+ <div className={styles.loadingInline}>
43
+ <Spinner />
44
+ <span className={styles.loaderLoadingText}>{loadingText}</span>
45
+ </div>
46
+ )}
47
+ {!hasNextPage && !isFetchingNextPage && <span className={styles.noMore}>{noMoreText}</span>}
48
+ </div>
49
+ );
50
+ }
51
+
52
+ if (!hasNextPage) {
53
+ return (
54
+ <div className={styles.center}>
55
+ <span className={styles.noMore}>{noMoreText}</span>
56
+ </div>
57
+ );
58
+ }
59
+
60
+ return (
61
+ <div className={styles.center}>
62
+ <Button
63
+ variant="outline"
64
+ onClick={fetchNextPage}
65
+ disabled={isFetchingNextPage}
66
+ loading={isFetchingNextPage}
67
+ aria-label={config?.loadMoreText ?? "Load more"}
68
+ >
69
+ {config?.loadMoreText ?? "Load more"}
70
+ </Button>
71
+ </div>
72
+ );
73
+ }
@@ -0,0 +1,67 @@
1
+ import { Spinner } from "@blenx-dev/core";
2
+ import type { TableSize } from "./types";
3
+ import * as styles from "./data-table.css";
4
+
5
+ interface DataTableLoadingProps {
6
+ rowCount?: number;
7
+ columnCount?: number;
8
+ size?: TableSize;
9
+ }
10
+
11
+ const ROW_HEIGHTS: Record<TableSize, number> = {
12
+ sm: 36,
13
+ md: 48,
14
+ lg: 60,
15
+ };
16
+
17
+ export function DataTableLoading({
18
+ rowCount = 5,
19
+ columnCount = 4,
20
+ size = "md",
21
+ }: DataTableLoadingProps) {
22
+ const rowHeight = ROW_HEIGHTS[size];
23
+
24
+ return (
25
+ <output className={styles.loadingWrapper} aria-label="Loading table data">
26
+ <table className={styles.loadingTable}>
27
+ <thead>
28
+ <tr>
29
+ {Array.from({ length: columnCount }).map((_, i) => (
30
+ <th key={`skeleton-header-${i.toString()}`} className={styles.headerCell}>
31
+ <div
32
+ className={styles.skeletonBar}
33
+ style={{ height: 14, width: `${60 + ((i * 10) % 40)}px` }}
34
+ />
35
+ </th>
36
+ ))}
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ {Array.from({ length: rowCount }).map((_unknown, rowIdx) => (
41
+ <tr key={`skeleton-row-${rowIdx.toString()}`}>
42
+ {Array.from({ length: columnCount }).map((_, colIdx) => (
43
+ <td
44
+ key={`skeleton-cell-${rowIdx.toString()}-${colIdx.toString()}`}
45
+ className={styles.cell}
46
+ style={{ height: rowHeight }}
47
+ >
48
+ <div
49
+ className={styles.skeletonBar}
50
+ style={{
51
+ height: 12,
52
+ width: `${80 + ((rowIdx * 7 + colIdx * 13) % 20)}%`,
53
+ }}
54
+ />
55
+ </td>
56
+ ))}
57
+ </tr>
58
+ ))}
59
+ </tbody>
60
+ </table>
61
+ <div className={styles.loadingFooter}>
62
+ <Spinner />
63
+ <span className={styles.loadingText}>Loading data...</span>
64
+ </div>
65
+ </output>
66
+ );
67
+ }
@@ -0,0 +1,80 @@
1
+ import { Button } from "@blenx-dev/core";
2
+ import type { Table } from "@tanstack/react-table";
3
+ import * as styles from "./data-table.css";
4
+ import { ChevronLeftIcon, ChevronRightIcon } from "@blenx-dev/core/icons";
5
+
6
+ interface DataTablePaginationProps<TData> {
7
+ table: Table<TData>;
8
+ }
9
+
10
+ export function DataTablePagination<TData>({ table }: DataTablePaginationProps<TData>) {
11
+ const { pageIndex } = table.getState().pagination;
12
+ const pageCount = table.getPageCount();
13
+ const totalRows = table.getPrePaginationRowModel().rows.length;
14
+ const { pageSize } = table.getState().pagination;
15
+ const startRow = pageIndex * pageSize + 1;
16
+ const endRow = Math.min((pageIndex + 1) * pageSize, totalRows);
17
+ const canPreviousPage = table.getCanPreviousPage();
18
+ const canNextPage = table.getCanNextPage();
19
+
20
+ return (
21
+ <nav aria-label="Pagination" className={styles.nav}>
22
+ <span className={styles.info}>{totalRows} results</span>
23
+ <div className={styles.controls}>
24
+ <span className={styles.range}>
25
+ {startRow}-{endRow} of {totalRows}
26
+ </span>
27
+ <div className={styles.buttonGroup}>
28
+ <Button
29
+ variant="outline"
30
+ size="sm"
31
+ disabled={!canPreviousPage}
32
+ onClick={() => table.previousPage()}
33
+ aria-label="Previous page"
34
+ >
35
+ <ChevronLeftIcon width={16} />
36
+ </Button>
37
+ {Array.from({ length: pageCount }, (_, i) => i + 1)
38
+ .filter((page) => {
39
+ const current = pageIndex + 1;
40
+ if (pageCount <= 7) return true;
41
+ if (page === 1 || page === pageCount) return true;
42
+ if (Math.abs(page - current) <= 1) return true;
43
+ return false;
44
+ })
45
+ .map((page, idx, filtered) => {
46
+ const pageIdx = page - 1;
47
+ const isActive = pageIdx === pageIndex;
48
+ const showGap = idx > 0 && page - filtered[idx - 1]! > 1;
49
+ return (
50
+ <div key={`page-${page.toString()}`} className={styles.pageWrap}>
51
+ {showGap && <span className={styles.ellipsis}>...</span>}
52
+ <Button
53
+ variant={isActive ? "solid" : "ghost"}
54
+ intent={isActive ? "primary" : undefined}
55
+ size="sm"
56
+ disabled={isActive}
57
+ onClick={() => table.setPageIndex(pageIdx)}
58
+ aria-label={`Page ${page.toString()}`}
59
+ aria-current={isActive ? "page" : undefined}
60
+ className={styles.pageButton}
61
+ >
62
+ {page.toString()}
63
+ </Button>
64
+ </div>
65
+ );
66
+ })}
67
+ <Button
68
+ variant="outline"
69
+ size="sm"
70
+ disabled={!canNextPage}
71
+ onClick={() => table.nextPage()}
72
+ aria-label="Next page"
73
+ >
74
+ <ChevronRightIcon width={16} />
75
+ </Button>
76
+ </div>
77
+ </div>
78
+ </nav>
79
+ );
80
+ }
@@ -0,0 +1,62 @@
1
+ import { Button, Input } from "@blenx-dev/core";
2
+ import type { Table } from "@tanstack/react-table";
3
+ import { DataTableColumnToggle } from "./data-table-column-toggle";
4
+ import type { BulkAction, TableFeatures } from "./types";
5
+ import * as styles from "./data-table.css";
6
+
7
+ interface DataTableToolbarProps<TData> {
8
+ table: Table<TData>;
9
+ features?: TableFeatures;
10
+ globalSearch?: string;
11
+ onGlobalSearchChange?: (value: string) => void;
12
+ customToolbar?: React.ReactNode;
13
+ bulkActions?: BulkAction<TData>[];
14
+ selectedRows: TData[];
15
+ }
16
+
17
+ export function DataTableToolbar<TData>({
18
+ table,
19
+ features,
20
+ globalSearch,
21
+ onGlobalSearchChange,
22
+ customToolbar,
23
+ bulkActions,
24
+ selectedRows,
25
+ }: DataTableToolbarProps<TData>) {
26
+ return (
27
+ <div className={styles.toolbarContainer}>
28
+ <div className={styles.leftGroup}>
29
+ {features?.globalSearch && (
30
+ <div className={styles.searchWrap}>
31
+ <Input
32
+ size="sm"
33
+ placeholder="Search..."
34
+ value={globalSearch ?? ""}
35
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
36
+ onGlobalSearchChange?.(e.target.value);
37
+ }}
38
+ />
39
+ </div>
40
+ )}
41
+ {selectedRows.length > 0 &&
42
+ bulkActions?.map((action, index) => (
43
+ <Button
44
+ key={`bulk-action-${index.toString()}`}
45
+ variant={action.variant === "destructive" ? "solid" : "outline"}
46
+ intent={action.variant === "destructive" ? "danger" : undefined}
47
+ size="sm"
48
+ disabled={action.disabled}
49
+ onClick={() => action.onClick(selectedRows)}
50
+ >
51
+ {action.icon && <span>{action.icon}</span>}
52
+ {action.label}
53
+ </Button>
54
+ ))}
55
+ </div>
56
+ <div className={styles.rightGroup}>
57
+ {customToolbar}
58
+ {features?.columnVisibility && <DataTableColumnToggle table={table} />}
59
+ </div>
60
+ </div>
61
+ );
62
+ }