@nccirtu/tablefy 0.8.2 → 0.8.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/dist/columns/badge-column.d.ts +7 -0
- package/dist/columns/columns/badge-column.d.ts +7 -0
- package/dist/columns/columns/types.d.ts +7 -0
- package/dist/columns/index.d.ts +3 -0
- package/dist/columns/index.esm.js +35 -12
- package/dist/columns/index.esm.js.map +1 -1
- package/dist/columns/index.js +35 -12
- package/dist/columns/index.js.map +1 -1
- package/dist/columns/types.d.ts +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +195 -14
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +197 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/columns/types.d.ts
CHANGED
|
@@ -27,6 +27,13 @@ export interface BadgeColumnConfig<TData> extends BaseColumnConfig<TData> {
|
|
|
27
27
|
className?: string;
|
|
28
28
|
icon?: ReactNode;
|
|
29
29
|
}>;
|
|
30
|
+
variantFn?: (value: unknown, row: TData) => {
|
|
31
|
+
label?: string;
|
|
32
|
+
variant?: "default" | "secondary" | "destructive" | "outline" | "success" | "warning" | "info" | "muted";
|
|
33
|
+
className?: string;
|
|
34
|
+
icon?: ReactNode;
|
|
35
|
+
};
|
|
36
|
+
classNameFn?: (value: unknown, row: TData) => string;
|
|
30
37
|
}
|
|
31
38
|
export interface ActionConfig<TData> {
|
|
32
39
|
label: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export { InputColumn, InputColumn as inputColumn, } from "./columns/input-column
|
|
|
13
13
|
export { LinkColumn } from "./columns/link-column";
|
|
14
14
|
export { NumberColumn } from "./columns/number-column";
|
|
15
15
|
export { ProgressColumn, SelectColumn } from "./columns";
|
|
16
|
+
export { ActionsColumn, ActionsColumn as actionsColumn, } from "./columns/actions-column";
|
|
17
|
+
export type { ActionItem } from "./columns/actions-column";
|
|
18
|
+
export { TextColumn, TextColumn as textColumn } from "./columns/text-column";
|
|
16
19
|
export { EnumColumn, EnumColumn as enumColumn } from "./columns/enum-column";
|
|
17
20
|
export type { EnumOption } from "./columns/enum-column";
|
|
18
21
|
export { ConfirmProvider, confirm } from "./confirm";
|
package/dist/index.esm.js
CHANGED
|
@@ -6,7 +6,7 @@ import { cn } from '@/lib/utils';
|
|
|
6
6
|
import { Button } from '@/components/ui/button';
|
|
7
7
|
import { Input } from '@/components/ui/input';
|
|
8
8
|
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuCheckboxItem, DropdownMenuItem } from '@/components/ui/dropdown-menu';
|
|
9
|
-
import { Search, X, Columns, ChevronDown, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, ArrowUpDown, Calendar, ExternalLink } from 'lucide-react';
|
|
9
|
+
import { Search, X, Columns, ChevronDown, ChevronsLeft, ChevronLeft, ChevronRight, ChevronsRight, ArrowUpDown, Calendar, ExternalLink, MoreHorizontal } from 'lucide-react';
|
|
10
10
|
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '@/components/ui/select';
|
|
11
11
|
import { Badge } from '@/components/ui/badge';
|
|
12
12
|
import { Checkbox } from '@/components/ui/checkbox';
|
|
@@ -599,8 +599,18 @@ class BadgeColumn extends BaseColumn {
|
|
|
599
599
|
this.config.variants = variants;
|
|
600
600
|
return this;
|
|
601
601
|
}
|
|
602
|
+
// Dynamische Variante basierend auf Row-Daten
|
|
603
|
+
variantFn(fn) {
|
|
604
|
+
this.config.variantFn = fn;
|
|
605
|
+
return this;
|
|
606
|
+
}
|
|
607
|
+
// Dynamische className basierend auf Row-Daten
|
|
608
|
+
classNameFn(fn) {
|
|
609
|
+
this.config.classNameFn = fn;
|
|
610
|
+
return this;
|
|
611
|
+
}
|
|
602
612
|
build() {
|
|
603
|
-
const { accessor, label, sortable, variants } = this.config;
|
|
613
|
+
const { accessor, label, sortable, variants, variantFn, classNameFn } = this.config;
|
|
604
614
|
return {
|
|
605
615
|
accessorKey: accessor,
|
|
606
616
|
header: ({ column }) => {
|
|
@@ -610,18 +620,31 @@ class BadgeColumn extends BaseColumn {
|
|
|
610
620
|
}
|
|
611
621
|
return (jsxs(Button, { variant: "table_header", size: "table_header", onClick: () => column.toggleSorting(column.getIsSorted() === "asc"), className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: [displayLabel, jsx(ArrowUpDown, { className: "ml-2 h-4 w-4" })] }));
|
|
612
622
|
},
|
|
613
|
-
cell: ({ getValue }) => {
|
|
614
|
-
const value =
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
623
|
+
cell: ({ getValue, row }) => {
|
|
624
|
+
const value = getValue();
|
|
625
|
+
const stringValue = String(value);
|
|
626
|
+
// Priority 1: Dynamic variantFn (highest priority)
|
|
627
|
+
if (variantFn) {
|
|
628
|
+
const dynamicConfig = variantFn(value, row.original);
|
|
629
|
+
return (jsxs(Badge, { variant: dynamicConfig.variant === "success" ||
|
|
630
|
+
dynamicConfig.variant === "warning" ||
|
|
631
|
+
dynamicConfig.variant === "info" ||
|
|
632
|
+
dynamicConfig.variant === "muted"
|
|
633
|
+
? "default"
|
|
634
|
+
: dynamicConfig.variant || "default", className: cn(dynamicConfig.className, classNameFn?.(value, row.original), this.config.cellClassName), children: [dynamicConfig.icon, dynamicConfig.label || stringValue] }));
|
|
635
|
+
}
|
|
636
|
+
// Priority 2: Static variants lookup
|
|
637
|
+
const variantConfig = variants?.[stringValue];
|
|
638
|
+
if (variantConfig) {
|
|
639
|
+
return (jsxs(Badge, { variant: variantConfig.variant === "success" ||
|
|
640
|
+
variantConfig.variant === "warning" ||
|
|
641
|
+
variantConfig.variant === "info" ||
|
|
642
|
+
variantConfig.variant === "muted"
|
|
643
|
+
? "default"
|
|
644
|
+
: variantConfig.variant || "default", className: cn(variantConfig.className, classNameFn?.(value, row.original), this.config.cellClassName), children: [variantConfig.icon, variantConfig.label || stringValue] }));
|
|
618
645
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
variantConfig.variant === "info" ||
|
|
622
|
-
variantConfig.variant === "muted"
|
|
623
|
-
? "default"
|
|
624
|
-
: variantConfig.variant || "default", className: cn(variantConfig.className, this.config.cellClassName), children: [variantConfig.icon, variantConfig.label || value] }));
|
|
646
|
+
// Priority 3: Default badge with optional dynamic className
|
|
647
|
+
return (jsx(Badge, { variant: "outline", className: cn(classNameFn?.(value, row.original), this.config.cellClassName), children: stringValue }));
|
|
625
648
|
},
|
|
626
649
|
};
|
|
627
650
|
}
|
|
@@ -1542,6 +1565,164 @@ class SelectColumn extends BaseColumn {
|
|
|
1542
1565
|
}
|
|
1543
1566
|
}
|
|
1544
1567
|
|
|
1568
|
+
class TextColumn extends BaseColumn {
|
|
1569
|
+
static make(accessor) {
|
|
1570
|
+
return new TextColumn(accessor);
|
|
1571
|
+
}
|
|
1572
|
+
formatter(fn) {
|
|
1573
|
+
this.config.formatter = fn;
|
|
1574
|
+
return this;
|
|
1575
|
+
}
|
|
1576
|
+
prefix(prefix) {
|
|
1577
|
+
this.config.prefix = prefix;
|
|
1578
|
+
return this;
|
|
1579
|
+
}
|
|
1580
|
+
suffix(suffix) {
|
|
1581
|
+
this.config.suffix = suffix;
|
|
1582
|
+
return this;
|
|
1583
|
+
}
|
|
1584
|
+
placeholder(placeholder) {
|
|
1585
|
+
this.config.placeholder = placeholder;
|
|
1586
|
+
return this;
|
|
1587
|
+
}
|
|
1588
|
+
// Shortcuts für gängige Formatierungen
|
|
1589
|
+
uppercase() {
|
|
1590
|
+
const existingFormatter = this.config.formatter;
|
|
1591
|
+
this.config.formatter = (value, row) => {
|
|
1592
|
+
const result = existingFormatter ? existingFormatter(value, row) : value;
|
|
1593
|
+
return typeof result === "string"
|
|
1594
|
+
? result.toUpperCase()
|
|
1595
|
+
: result;
|
|
1596
|
+
};
|
|
1597
|
+
return this;
|
|
1598
|
+
}
|
|
1599
|
+
lowercase() {
|
|
1600
|
+
const existingFormatter = this.config.formatter;
|
|
1601
|
+
this.config.formatter = (value, row) => {
|
|
1602
|
+
const result = existingFormatter ? existingFormatter(value, row) : value;
|
|
1603
|
+
return typeof result === "string"
|
|
1604
|
+
? result.toLowerCase()
|
|
1605
|
+
: result;
|
|
1606
|
+
};
|
|
1607
|
+
return this;
|
|
1608
|
+
}
|
|
1609
|
+
limit(chars) {
|
|
1610
|
+
const existingFormatter = this.config.formatter;
|
|
1611
|
+
this.config.formatter = (value, row) => {
|
|
1612
|
+
const result = existingFormatter ? existingFormatter(value, row) : value;
|
|
1613
|
+
if (typeof result === "string" && result.length > chars) {
|
|
1614
|
+
return result.slice(0, chars) + "...";
|
|
1615
|
+
}
|
|
1616
|
+
return result;
|
|
1617
|
+
};
|
|
1618
|
+
return this;
|
|
1619
|
+
}
|
|
1620
|
+
build() {
|
|
1621
|
+
const { accessor, label, sortable, prefix, suffix, placeholder, formatter, visibleByDefault, visibilityLabel, } = this.config;
|
|
1622
|
+
return {
|
|
1623
|
+
accessorKey: accessor,
|
|
1624
|
+
meta: {
|
|
1625
|
+
visibleByDefault,
|
|
1626
|
+
visibilityLabel: visibilityLabel || label || String(accessor),
|
|
1627
|
+
},
|
|
1628
|
+
header: ({ column }) => {
|
|
1629
|
+
const displayLabel = label || String(accessor);
|
|
1630
|
+
if (!sortable) {
|
|
1631
|
+
return (jsx("span", { className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: displayLabel }));
|
|
1632
|
+
}
|
|
1633
|
+
return (jsxs(Button, { variant: "table_header", size: "table_header", onClick: () => column.toggleSorting(column.getIsSorted() === "asc"), className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: [displayLabel, jsx(ArrowUpDown, { className: "ml-2 h-4 w-4" })] }));
|
|
1634
|
+
},
|
|
1635
|
+
cell: ({ row, getValue }) => {
|
|
1636
|
+
let value = getValue();
|
|
1637
|
+
// Custom Formatter anwenden
|
|
1638
|
+
if (formatter) {
|
|
1639
|
+
value = formatter(value, row);
|
|
1640
|
+
}
|
|
1641
|
+
// Placeholder wenn leer
|
|
1642
|
+
if (value === null || value === undefined || value === "") {
|
|
1643
|
+
return (jsx("span", { className: cn("text-muted-foreground", this.getAlignmentClass(), this.config.cellClassName), children: placeholder || "—" }));
|
|
1644
|
+
}
|
|
1645
|
+
// Prefix/Suffix hinzufügen
|
|
1646
|
+
const displayValue = `${prefix || ""}${value}${suffix || ""}`;
|
|
1647
|
+
return (jsx("span", { className: cn(this.getAlignmentClass(), this.config.cellClassName), children: displayValue }));
|
|
1648
|
+
},
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
class ActionsColumn {
|
|
1654
|
+
config = {
|
|
1655
|
+
actions: [],
|
|
1656
|
+
label: "Aktionen",
|
|
1657
|
+
};
|
|
1658
|
+
static make() {
|
|
1659
|
+
return new ActionsColumn();
|
|
1660
|
+
}
|
|
1661
|
+
label(label) {
|
|
1662
|
+
this.config.label = label;
|
|
1663
|
+
return this;
|
|
1664
|
+
}
|
|
1665
|
+
triggerIcon(icon) {
|
|
1666
|
+
this.config.triggerIcon = icon;
|
|
1667
|
+
return this;
|
|
1668
|
+
}
|
|
1669
|
+
// Action hinzufügen
|
|
1670
|
+
action(action) {
|
|
1671
|
+
this.config.actions.push(action);
|
|
1672
|
+
return this;
|
|
1673
|
+
}
|
|
1674
|
+
// Shortcuts für gängige Actions
|
|
1675
|
+
view(onClick) {
|
|
1676
|
+
return this.action({ label: "Anzeigen", onClick });
|
|
1677
|
+
}
|
|
1678
|
+
edit(onClick) {
|
|
1679
|
+
return this.action({ label: "Bearbeiten", onClick });
|
|
1680
|
+
}
|
|
1681
|
+
delete(onClick) {
|
|
1682
|
+
return this.action({
|
|
1683
|
+
label: "Löschen",
|
|
1684
|
+
onClick,
|
|
1685
|
+
variant: "destructive",
|
|
1686
|
+
separator: true,
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
link(label, href) {
|
|
1690
|
+
return this.action({ label, href });
|
|
1691
|
+
}
|
|
1692
|
+
separator() {
|
|
1693
|
+
if (this.config.actions.length > 0) {
|
|
1694
|
+
this.config.actions[this.config.actions.length - 1].separator = true;
|
|
1695
|
+
}
|
|
1696
|
+
return this;
|
|
1697
|
+
}
|
|
1698
|
+
build() {
|
|
1699
|
+
const { actions, label, triggerIcon } = this.config;
|
|
1700
|
+
return {
|
|
1701
|
+
id: "actions",
|
|
1702
|
+
header: () => jsx("span", { className: "sr-only", children: label }),
|
|
1703
|
+
cell: ({ row }) => {
|
|
1704
|
+
const data = row.original;
|
|
1705
|
+
const visibleActions = actions.filter((action) => !action.hidden || !action.hidden(data));
|
|
1706
|
+
if (visibleActions.length === 0)
|
|
1707
|
+
return null;
|
|
1708
|
+
return (jsxs(DropdownMenu, { children: [jsx(DropdownMenuTrigger, { asChild: true, children: jsxs(Button, { variant: "ghost", className: "h-10 w-10 p-0", children: [jsx("span", { className: "sr-only", children: label }), triggerIcon || jsx(MoreHorizontal, { className: "h-8 w-8" })] }) }), jsx(DropdownMenuContent, { align: "end", children: visibleActions.map((action, index) => (jsxs("div", { children: [action.render ? (
|
|
1709
|
+
// Custom render function takes priority
|
|
1710
|
+
action.render(data)) : (
|
|
1711
|
+
// Standard menu item
|
|
1712
|
+
jsxs(DropdownMenuItem, { disabled: action.disabled?.(data), className: cn(action.variant === "destructive" &&
|
|
1713
|
+
"text-destructive focus:text-destructive"), onClick: () => {
|
|
1714
|
+
if (action.href) {
|
|
1715
|
+
window.location.href = action.href(data);
|
|
1716
|
+
}
|
|
1717
|
+
else if (action.onClick) {
|
|
1718
|
+
action.onClick(data);
|
|
1719
|
+
}
|
|
1720
|
+
}, children: [action.icon && (jsx("span", { className: "mr-2", children: action.icon })), action.label] })), action.separator && index < visibleActions.length - 1 && (jsx(DropdownMenuSeparator, {}))] }, index))) })] }));
|
|
1721
|
+
},
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1545
1726
|
class EnumColumn extends BaseColumn {
|
|
1546
1727
|
constructor(accessor) {
|
|
1547
1728
|
super(accessor);
|
|
@@ -1676,5 +1857,5 @@ function ConfirmProvider({ children }) {
|
|
|
1676
1857
|
return (jsxs(Fragment, { children: [children, jsx(AlertDialog, { open: !!currentRequest, onOpenChange: (open) => !open && handleCancel(), children: jsxs(AlertDialogContent, { className: "max-w-md", children: [jsxs(AlertDialogHeader, { children: [jsx(AlertDialogTitle, { className: "text-center", children: title || "Bestätigung erforderlich" }), description && (jsx(AlertDialogDescription, { className: "text-center", children: description }))] }), image && (jsx("div", { className: "flex justify-center py-4", children: jsx("img", { src: image, alt: "Confirmation", className: "h-24 w-24 object-contain" }) })), icon && !image && (jsx("div", { className: "flex justify-center py-4 text-6xl", children: icon })), jsxs(AlertDialogFooter, { className: "flex flex-row !justify-between w-full", children: [jsx(AlertDialogCancel, { onClick: handleCancel, className: "mt-0", children: cancelLabel || "Abbrechen" }), jsx(AlertDialogAction, { onClick: handleConfirm, variant: variant === "destructive" ? "destructive" : "default", children: confirmLabel || "Bestätigen" })] })] }) })] }));
|
|
1677
1858
|
}
|
|
1678
1859
|
|
|
1679
|
-
export { AvatarGroupColumn, BadgeColumn, ButtonColumn, CheckboxColumn, ConfirmProvider, DataTable, DataTableSchema, DateColumn, DropdownColumn, EmptyStateBuilder, EnumColumn, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, SelectColumn, TableSchema, AvatarGroupColumn as avatarGroupColumn, BadgeColumn as badgeColumn, ButtonColumn as buttonColumn, CheckboxColumn as checkboxColumn, confirm, DateColumn as dateColumn, DropdownColumn as dropdownColumn, EnumColumn as enumColumn, IconColumn as iconColumn, InputColumn as inputColumn };
|
|
1860
|
+
export { ActionsColumn, AvatarGroupColumn, BadgeColumn, ButtonColumn, CheckboxColumn, ConfirmProvider, DataTable, DataTableSchema, DateColumn, DropdownColumn, EmptyStateBuilder, EnumColumn, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, SelectColumn, TableSchema, TextColumn, ActionsColumn as actionsColumn, AvatarGroupColumn as avatarGroupColumn, BadgeColumn as badgeColumn, ButtonColumn as buttonColumn, CheckboxColumn as checkboxColumn, confirm, DateColumn as dateColumn, DropdownColumn as dropdownColumn, EnumColumn as enumColumn, IconColumn as iconColumn, InputColumn as inputColumn, TextColumn as textColumn };
|
|
1680
1861
|
//# sourceMappingURL=index.esm.js.map
|