@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.
@@ -243,8 +243,18 @@ class BadgeColumn extends BaseColumn {
243
243
  this.config.variants = variants;
244
244
  return this;
245
245
  }
246
+ // Dynamische Variante basierend auf Row-Daten
247
+ variantFn(fn) {
248
+ this.config.variantFn = fn;
249
+ return this;
250
+ }
251
+ // Dynamische className basierend auf Row-Daten
252
+ classNameFn(fn) {
253
+ this.config.classNameFn = fn;
254
+ return this;
255
+ }
246
256
  build() {
247
- const { accessor, label, sortable, variants } = this.config;
257
+ const { accessor, label, sortable, variants, variantFn, classNameFn } = this.config;
248
258
  return {
249
259
  accessorKey: accessor,
250
260
  header: ({ column }) => {
@@ -254,18 +264,31 @@ class BadgeColumn extends BaseColumn {
254
264
  }
255
265
  return (jsxRuntime.jsxs(button.Button, { variant: "table_header", size: "table_header", onClick: () => column.toggleSorting(column.getIsSorted() === "asc"), className: utils.cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: [displayLabel, jsxRuntime.jsx(lucideReact.ArrowUpDown, { className: "ml-2 h-4 w-4" })] }));
256
266
  },
257
- cell: ({ getValue }) => {
258
- const value = String(getValue());
259
- const variantConfig = variants?.[value];
260
- if (!variantConfig) {
261
- return (jsxRuntime.jsx(badge.Badge, { variant: "outline", className: this.config.cellClassName, children: value }));
267
+ cell: ({ getValue, row }) => {
268
+ const value = getValue();
269
+ const stringValue = String(value);
270
+ // Priority 1: Dynamic variantFn (highest priority)
271
+ if (variantFn) {
272
+ const dynamicConfig = variantFn(value, row.original);
273
+ return (jsxRuntime.jsxs(badge.Badge, { variant: dynamicConfig.variant === "success" ||
274
+ dynamicConfig.variant === "warning" ||
275
+ dynamicConfig.variant === "info" ||
276
+ dynamicConfig.variant === "muted"
277
+ ? "default"
278
+ : dynamicConfig.variant || "default", className: utils.cn(dynamicConfig.className, classNameFn?.(value, row.original), this.config.cellClassName), children: [dynamicConfig.icon, dynamicConfig.label || stringValue] }));
279
+ }
280
+ // Priority 2: Static variants lookup
281
+ const variantConfig = variants?.[stringValue];
282
+ if (variantConfig) {
283
+ return (jsxRuntime.jsxs(badge.Badge, { variant: variantConfig.variant === "success" ||
284
+ variantConfig.variant === "warning" ||
285
+ variantConfig.variant === "info" ||
286
+ variantConfig.variant === "muted"
287
+ ? "default"
288
+ : variantConfig.variant || "default", className: utils.cn(variantConfig.className, classNameFn?.(value, row.original), this.config.cellClassName), children: [variantConfig.icon, variantConfig.label || stringValue] }));
262
289
  }
263
- return (jsxRuntime.jsxs(badge.Badge, { variant: variantConfig.variant === "success" ||
264
- variantConfig.variant === "warning" ||
265
- variantConfig.variant === "info" ||
266
- variantConfig.variant === "muted"
267
- ? "default"
268
- : variantConfig.variant || "default", className: utils.cn(variantConfig.className, this.config.cellClassName), children: [variantConfig.icon, variantConfig.label || value] }));
290
+ // Priority 3: Default badge with optional dynamic className
291
+ return (jsxRuntime.jsx(badge.Badge, { variant: "outline", className: utils.cn(classNameFn?.(value, row.original), this.config.cellClassName), children: stringValue }));
269
292
  },
270
293
  };
271
294
  }