@nccirtu/tablefy 0.1.7 → 0.2.0
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/dist/columns/lib/builders/empty-state.d.ts +19 -0
- package/dist/columns/lib/builders/table-schema.d.ts +71 -2
- package/dist/index.esm.js +215 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +215 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/builders/empty-state.d.ts +19 -0
- package/dist/lib/builders/table-schema.d.ts +71 -2
- package/package.json +1 -1
|
@@ -24,4 +24,23 @@ export declare class EmptyStateBuilder {
|
|
|
24
24
|
}): this;
|
|
25
25
|
noData(): this;
|
|
26
26
|
build(): EmptyStateConfig;
|
|
27
|
+
static noData(config: {
|
|
28
|
+
title: string;
|
|
29
|
+
description: string;
|
|
30
|
+
createLabel?: string;
|
|
31
|
+
createHref?: string;
|
|
32
|
+
createOnClick?: () => void;
|
|
33
|
+
}): EmptyStateConfig;
|
|
34
|
+
static noSearchResults(config: {
|
|
35
|
+
title: string;
|
|
36
|
+
description: string;
|
|
37
|
+
clearLabel?: string;
|
|
38
|
+
onClear?: () => void;
|
|
39
|
+
}): EmptyStateConfig;
|
|
40
|
+
static noFilterResults(config: {
|
|
41
|
+
title: string;
|
|
42
|
+
description: string;
|
|
43
|
+
resetLabel?: string;
|
|
44
|
+
onReset?: () => void;
|
|
45
|
+
}): EmptyStateConfig;
|
|
27
46
|
}
|
|
@@ -1,15 +1,84 @@
|
|
|
1
1
|
import { ColumnDef } from "@tanstack/react-table";
|
|
2
|
+
import { DataTableConfig } from "../types/table";
|
|
3
|
+
import { HeaderAction } from "../types/actions";
|
|
4
|
+
import { EmptyStateConfig } from "../types/empty-state";
|
|
5
|
+
import React from "react";
|
|
2
6
|
type ColumnBuilder<TData> = {
|
|
3
7
|
build(): ColumnDef<TData, unknown>;
|
|
4
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Header Actions Builder
|
|
11
|
+
* Fluent API for building header actions
|
|
12
|
+
*/
|
|
13
|
+
declare class HeaderActionsBuilder<TData> {
|
|
14
|
+
private actions;
|
|
15
|
+
create(config: {
|
|
16
|
+
label: string;
|
|
17
|
+
href?: string;
|
|
18
|
+
onClick?: () => void;
|
|
19
|
+
icon?: React.ReactNode;
|
|
20
|
+
}): this;
|
|
21
|
+
export(config: {
|
|
22
|
+
label: string;
|
|
23
|
+
icon?: React.ReactNode;
|
|
24
|
+
formats?: Array<{
|
|
25
|
+
label: string;
|
|
26
|
+
onClick: () => void;
|
|
27
|
+
}>;
|
|
28
|
+
}): this;
|
|
29
|
+
import(config: {
|
|
30
|
+
label: string;
|
|
31
|
+
icon?: React.ReactNode;
|
|
32
|
+
onClick?: () => void;
|
|
33
|
+
}): this;
|
|
34
|
+
bulkExport(config: {
|
|
35
|
+
label: string;
|
|
36
|
+
icon?: React.ReactNode;
|
|
37
|
+
onExport: (rows: TData[]) => void;
|
|
38
|
+
}): this;
|
|
39
|
+
bulkDelete(config: {
|
|
40
|
+
label: string;
|
|
41
|
+
icon?: React.ReactNode;
|
|
42
|
+
onDelete: (rows: TData[]) => void;
|
|
43
|
+
}): this;
|
|
44
|
+
custom(action: HeaderAction<TData>): this;
|
|
45
|
+
build(): HeaderAction<TData>[];
|
|
46
|
+
}
|
|
5
47
|
/**
|
|
6
48
|
* Table Schema Builder
|
|
7
|
-
* Fluent API for building table
|
|
49
|
+
* Fluent API for building complete table configurations
|
|
8
50
|
*/
|
|
9
51
|
export declare class TableSchema<TData> {
|
|
10
52
|
private columnBuilders;
|
|
53
|
+
private config;
|
|
11
54
|
static make<TData>(): TableSchema<TData>;
|
|
55
|
+
description(text: string): this;
|
|
56
|
+
title(text: string): this;
|
|
57
|
+
headerActions(builder: (b: HeaderActionsBuilder<TData>) => HeaderActionsBuilder<TData>): this;
|
|
58
|
+
emptyState(config: EmptyStateConfig): this;
|
|
59
|
+
searchEmptyState(config: EmptyStateConfig): this;
|
|
60
|
+
filterEmptyState(config: EmptyStateConfig): this;
|
|
61
|
+
searchable(config?: {
|
|
62
|
+
placeholder?: string;
|
|
63
|
+
} | boolean): this;
|
|
64
|
+
paginated(config?: {
|
|
65
|
+
pageSize?: number;
|
|
66
|
+
pageSizeOptions?: number[];
|
|
67
|
+
} | boolean): this;
|
|
68
|
+
selectable(multiSelect?: boolean): this;
|
|
69
|
+
sortable(defaultSort?: {
|
|
70
|
+
id: string;
|
|
71
|
+
desc: boolean;
|
|
72
|
+
}): this;
|
|
73
|
+
columnVisibility(enabled?: boolean): this;
|
|
74
|
+
bordered(enabled?: boolean): this;
|
|
75
|
+
striped(enabled?: boolean): this;
|
|
76
|
+
hoverable(enabled?: boolean): this;
|
|
77
|
+
density(density: "compact" | "default" | "comfortable"): this;
|
|
12
78
|
columns(...builders: ColumnBuilder<TData>[]): this;
|
|
13
|
-
build():
|
|
79
|
+
build(): {
|
|
80
|
+
columns: ColumnDef<TData, unknown>[];
|
|
81
|
+
config: DataTableConfig<TData>;
|
|
82
|
+
};
|
|
14
83
|
}
|
|
15
84
|
export {};
|
package/dist/index.esm.js
CHANGED
|
@@ -7815,21 +7815,193 @@ function DataTablePagination({ table, config, className, }) {
|
|
|
7815
7815
|
return (jsxs("div", { className: cn("flex flex-col gap-4 px-4 py-4 sm:flex-row sm:items-center sm:justify-between", className), children: [jsx("div", { className: "text-sm text-muted-foreground", children: table.getFilteredSelectedRowModel().rows.length > 0 ? (jsxs("span", { children: [table.getFilteredSelectedRowModel().rows.length, " von", " ", table.getFilteredRowModel().rows.length, " Zeile(n) ausgew\u00E4hlt"] })) : showPageInfo ? (jsxs("span", { children: [table.getFilteredRowModel().rows.length, " Eintr\u00E4ge"] })) : null }), jsxs("div", { className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:gap-6", children: [showPageSizeSelector && (jsxs("div", { className: "flex items-center gap-2", children: [jsx("span", { className: "text-sm text-muted-foreground whitespace-nowrap", children: "Zeilen pro Seite" }), jsxs(Select, { value: `${table.getState().pagination.pageSize}`, onValueChange: (value) => table.setPageSize(Number(value)), children: [jsx(SelectTrigger, { className: "h-8 w-[70px]", children: jsx(SelectValue, { placeholder: table.getState().pagination.pageSize }) }), jsx(SelectContent, { side: "top", children: pageSizeOptions.map((pageSize) => (jsx(SelectItem, { value: `${pageSize}`, children: pageSize }, pageSize))) })] })] })), showPageInfo && (jsxs("div", { className: "text-sm text-muted-foreground whitespace-nowrap", children: ["Seite ", table.getState().pagination.pageIndex + 1, " von", " ", table.getPageCount()] })), jsxs("div", { className: "flex items-center gap-1", children: [jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(0), disabled: !table.getCanPreviousPage(), children: [jsx(ChevronsLeft, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Erste Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.previousPage(), disabled: !table.getCanPreviousPage(), children: [jsx(ChevronLeft, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Vorherige Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.nextPage(), disabled: !table.getCanNextPage(), children: [jsx(ChevronRight, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "N\u00E4chste Seite" })] }), jsxs(Button, { variant: "outline", size: "icon", className: "h-8 w-8", onClick: () => table.setPageIndex(table.getPageCount() - 1), disabled: !table.getCanNextPage(), children: [jsx(ChevronsRight, { className: "h-4 w-4" }), jsx("span", { className: "sr-only", children: "Letzte Seite" })] })] })] })] }));
|
|
7816
7816
|
}
|
|
7817
7817
|
|
|
7818
|
+
/**
|
|
7819
|
+
* Header Actions Builder
|
|
7820
|
+
* Fluent API for building header actions
|
|
7821
|
+
*/
|
|
7822
|
+
class HeaderActionsBuilder {
|
|
7823
|
+
actions = [];
|
|
7824
|
+
create(config) {
|
|
7825
|
+
this.actions.push({
|
|
7826
|
+
id: "create",
|
|
7827
|
+
label: config.label,
|
|
7828
|
+
href: config.href,
|
|
7829
|
+
onClick: config.onClick,
|
|
7830
|
+
icon: config.icon,
|
|
7831
|
+
variant: "default",
|
|
7832
|
+
});
|
|
7833
|
+
return this;
|
|
7834
|
+
}
|
|
7835
|
+
export(config) {
|
|
7836
|
+
if (config.formats && config.formats.length > 0) {
|
|
7837
|
+
this.actions.push({
|
|
7838
|
+
id: "export",
|
|
7839
|
+
label: config.label,
|
|
7840
|
+
icon: config.icon,
|
|
7841
|
+
variant: "outline",
|
|
7842
|
+
children: config.formats.map((format, index) => ({
|
|
7843
|
+
id: `export-${index}`,
|
|
7844
|
+
label: format.label,
|
|
7845
|
+
onClick: format.onClick,
|
|
7846
|
+
})),
|
|
7847
|
+
});
|
|
7848
|
+
}
|
|
7849
|
+
else {
|
|
7850
|
+
this.actions.push({
|
|
7851
|
+
id: "export",
|
|
7852
|
+
label: config.label,
|
|
7853
|
+
icon: config.icon,
|
|
7854
|
+
variant: "outline",
|
|
7855
|
+
});
|
|
7856
|
+
}
|
|
7857
|
+
return this;
|
|
7858
|
+
}
|
|
7859
|
+
import(config) {
|
|
7860
|
+
this.actions.push({
|
|
7861
|
+
id: "import",
|
|
7862
|
+
label: config.label,
|
|
7863
|
+
icon: config.icon,
|
|
7864
|
+
onClick: config.onClick,
|
|
7865
|
+
variant: "outline",
|
|
7866
|
+
});
|
|
7867
|
+
return this;
|
|
7868
|
+
}
|
|
7869
|
+
bulkExport(config) {
|
|
7870
|
+
this.actions.push({
|
|
7871
|
+
id: "bulk-export",
|
|
7872
|
+
label: config.label,
|
|
7873
|
+
icon: config.icon,
|
|
7874
|
+
bulk: true,
|
|
7875
|
+
bulkOnClick: config.onExport,
|
|
7876
|
+
variant: "outline",
|
|
7877
|
+
});
|
|
7878
|
+
return this;
|
|
7879
|
+
}
|
|
7880
|
+
bulkDelete(config) {
|
|
7881
|
+
this.actions.push({
|
|
7882
|
+
id: "bulk-delete",
|
|
7883
|
+
label: config.label,
|
|
7884
|
+
icon: config.icon,
|
|
7885
|
+
bulk: true,
|
|
7886
|
+
bulkOnClick: config.onDelete,
|
|
7887
|
+
variant: "destructive",
|
|
7888
|
+
});
|
|
7889
|
+
return this;
|
|
7890
|
+
}
|
|
7891
|
+
custom(action) {
|
|
7892
|
+
this.actions.push(action);
|
|
7893
|
+
return this;
|
|
7894
|
+
}
|
|
7895
|
+
build() {
|
|
7896
|
+
return this.actions;
|
|
7897
|
+
}
|
|
7898
|
+
}
|
|
7818
7899
|
/**
|
|
7819
7900
|
* Table Schema Builder
|
|
7820
|
-
* Fluent API for building table
|
|
7901
|
+
* Fluent API for building complete table configurations
|
|
7821
7902
|
*/
|
|
7822
7903
|
class TableSchema {
|
|
7823
7904
|
columnBuilders = [];
|
|
7905
|
+
config = {};
|
|
7824
7906
|
static make() {
|
|
7825
7907
|
return new TableSchema();
|
|
7826
7908
|
}
|
|
7909
|
+
// Configuration Methods
|
|
7910
|
+
description(text) {
|
|
7911
|
+
this.config.description = text;
|
|
7912
|
+
return this;
|
|
7913
|
+
}
|
|
7914
|
+
title(text) {
|
|
7915
|
+
this.config.title = text;
|
|
7916
|
+
return this;
|
|
7917
|
+
}
|
|
7918
|
+
headerActions(builder) {
|
|
7919
|
+
const actionsBuilder = new HeaderActionsBuilder();
|
|
7920
|
+
this.config.headerActions = builder(actionsBuilder).build();
|
|
7921
|
+
return this;
|
|
7922
|
+
}
|
|
7923
|
+
emptyState(config) {
|
|
7924
|
+
this.config.emptyState = config;
|
|
7925
|
+
return this;
|
|
7926
|
+
}
|
|
7927
|
+
searchEmptyState(config) {
|
|
7928
|
+
this.config.searchEmptyState = config;
|
|
7929
|
+
return this;
|
|
7930
|
+
}
|
|
7931
|
+
filterEmptyState(config) {
|
|
7932
|
+
this.config.filterEmptyState = config;
|
|
7933
|
+
return this;
|
|
7934
|
+
}
|
|
7935
|
+
// Feature Methods
|
|
7936
|
+
searchable(config) {
|
|
7937
|
+
if (typeof config === "boolean") {
|
|
7938
|
+
this.config.search = config ? { enabled: true } : { enabled: false };
|
|
7939
|
+
}
|
|
7940
|
+
else {
|
|
7941
|
+
this.config.search = {
|
|
7942
|
+
enabled: true,
|
|
7943
|
+
placeholder: config?.placeholder,
|
|
7944
|
+
};
|
|
7945
|
+
}
|
|
7946
|
+
return this;
|
|
7947
|
+
}
|
|
7948
|
+
paginated(config) {
|
|
7949
|
+
if (typeof config === "boolean") {
|
|
7950
|
+
this.config.pagination = { enabled: config };
|
|
7951
|
+
}
|
|
7952
|
+
else {
|
|
7953
|
+
this.config.pagination = {
|
|
7954
|
+
enabled: true,
|
|
7955
|
+
pageSize: config?.pageSize,
|
|
7956
|
+
pageSizeOptions: config?.pageSizeOptions,
|
|
7957
|
+
};
|
|
7958
|
+
}
|
|
7959
|
+
return this;
|
|
7960
|
+
}
|
|
7961
|
+
selectable(multiSelect = true) {
|
|
7962
|
+
this.config.enableRowSelection = true;
|
|
7963
|
+
this.config.enableMultiRowSelection = multiSelect;
|
|
7964
|
+
return this;
|
|
7965
|
+
}
|
|
7966
|
+
sortable(defaultSort) {
|
|
7967
|
+
this.config.enableSorting = true;
|
|
7968
|
+
if (defaultSort) {
|
|
7969
|
+
this.config.defaultSort = defaultSort;
|
|
7970
|
+
}
|
|
7971
|
+
return this;
|
|
7972
|
+
}
|
|
7973
|
+
columnVisibility(enabled = true) {
|
|
7974
|
+
this.config.enableColumnVisibility = enabled;
|
|
7975
|
+
return this;
|
|
7976
|
+
}
|
|
7977
|
+
// Styling Methods
|
|
7978
|
+
bordered(enabled = true) {
|
|
7979
|
+
this.config.bordered = enabled;
|
|
7980
|
+
return this;
|
|
7981
|
+
}
|
|
7982
|
+
striped(enabled = true) {
|
|
7983
|
+
this.config.striped = enabled;
|
|
7984
|
+
return this;
|
|
7985
|
+
}
|
|
7986
|
+
hoverable(enabled = true) {
|
|
7987
|
+
this.config.hoverable = enabled;
|
|
7988
|
+
return this;
|
|
7989
|
+
}
|
|
7990
|
+
density(density) {
|
|
7991
|
+
this.config.density = density;
|
|
7992
|
+
return this;
|
|
7993
|
+
}
|
|
7994
|
+
// Columns
|
|
7827
7995
|
columns(...builders) {
|
|
7828
7996
|
this.columnBuilders.push(...builders);
|
|
7829
7997
|
return this;
|
|
7830
7998
|
}
|
|
7999
|
+
// Build
|
|
7831
8000
|
build() {
|
|
7832
|
-
return
|
|
8001
|
+
return {
|
|
8002
|
+
columns: this.columnBuilders.map((builder) => builder.build()),
|
|
8003
|
+
config: this.config,
|
|
8004
|
+
};
|
|
7833
8005
|
}
|
|
7834
8006
|
}
|
|
7835
8007
|
|
|
@@ -7905,6 +8077,47 @@ class EmptyStateBuilder {
|
|
|
7905
8077
|
build() {
|
|
7906
8078
|
return this.config;
|
|
7907
8079
|
}
|
|
8080
|
+
// Static helper methods for quick configuration
|
|
8081
|
+
static noData(config) {
|
|
8082
|
+
return {
|
|
8083
|
+
variant: "default",
|
|
8084
|
+
title: config.title,
|
|
8085
|
+
description: config.description,
|
|
8086
|
+
action: config.createLabel
|
|
8087
|
+
? {
|
|
8088
|
+
label: config.createLabel,
|
|
8089
|
+
href: config.createHref,
|
|
8090
|
+
onClick: config.createOnClick,
|
|
8091
|
+
}
|
|
8092
|
+
: undefined,
|
|
8093
|
+
};
|
|
8094
|
+
}
|
|
8095
|
+
static noSearchResults(config) {
|
|
8096
|
+
return {
|
|
8097
|
+
variant: "search",
|
|
8098
|
+
title: config.title,
|
|
8099
|
+
description: config.description,
|
|
8100
|
+
action: config.clearLabel
|
|
8101
|
+
? {
|
|
8102
|
+
label: config.clearLabel,
|
|
8103
|
+
onClick: config.onClear,
|
|
8104
|
+
}
|
|
8105
|
+
: undefined,
|
|
8106
|
+
};
|
|
8107
|
+
}
|
|
8108
|
+
static noFilterResults(config) {
|
|
8109
|
+
return {
|
|
8110
|
+
variant: "filter",
|
|
8111
|
+
title: config.title,
|
|
8112
|
+
description: config.description,
|
|
8113
|
+
action: config.resetLabel
|
|
8114
|
+
? {
|
|
8115
|
+
label: config.resetLabel,
|
|
8116
|
+
onClick: config.onReset,
|
|
8117
|
+
}
|
|
8118
|
+
: undefined,
|
|
8119
|
+
};
|
|
8120
|
+
}
|
|
7908
8121
|
}
|
|
7909
8122
|
|
|
7910
8123
|
function DataTable({ columns, data, config = {}, className, isLoading = false, isError = false, onRetry, }) {
|