@nccirtu/tablefy 0.7.2 → 0.7.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.
@@ -7,6 +7,8 @@ export declare abstract class BaseColumn<TData, TConfig extends BaseColumnConfig
7
7
  sortable(sortable?: boolean): this;
8
8
  searchable(searchable?: boolean): this;
9
9
  hidden(hidden?: boolean): this;
10
+ visibleByDefault(visible?: boolean): this;
11
+ visibilityLabel(label: string): this;
10
12
  alignLeft(): this;
11
13
  alignCenter(): this;
12
14
  alignRight(): this;
@@ -7,6 +7,8 @@ export declare abstract class BaseColumn<TData, TConfig extends BaseColumnConfig
7
7
  sortable(sortable?: boolean): this;
8
8
  searchable(searchable?: boolean): this;
9
9
  hidden(hidden?: boolean): this;
10
+ visibleByDefault(visible?: boolean): this;
11
+ visibilityLabel(label: string): this;
10
12
  alignLeft(): this;
11
13
  alignCenter(): this;
12
14
  alignRight(): this;
@@ -0,0 +1,52 @@
1
+ import { ColumnDef } from "@tanstack/react-table";
2
+ import { LucideIcon } from "lucide-react";
3
+ import { BaseColumn } from "./base-column";
4
+ import { BaseColumnConfig } from "./types";
5
+ export interface EnumOption<T = string | number> {
6
+ value: T;
7
+ label: string;
8
+ icon?: LucideIcon;
9
+ color?: "default" | "secondary" | "destructive" | "outline" | "success" | "warning" | "info";
10
+ className?: string;
11
+ }
12
+ interface EnumColumnConfig<TData> extends BaseColumnConfig<TData> {
13
+ options: EnumOption[];
14
+ asBadge?: boolean;
15
+ showIcon?: boolean;
16
+ iconPosition?: "left" | "right";
17
+ placeholder?: string;
18
+ }
19
+ export declare class EnumColumn<TData> extends BaseColumn<TData, EnumColumnConfig<TData>> {
20
+ constructor(accessor: keyof TData | string);
21
+ static make<TData>(accessor: keyof TData | string): EnumColumn<TData>;
22
+ /**
23
+ * Define the enum options with labels, icons, and colors
24
+ */
25
+ options(options: EnumOption[]): this;
26
+ /**
27
+ * Display as plain text instead of badge
28
+ */
29
+ asText(): this;
30
+ /**
31
+ * Display as badge (default)
32
+ */
33
+ asBadge(): this;
34
+ /**
35
+ * Hide icons
36
+ */
37
+ hideIcon(): this;
38
+ /**
39
+ * Show icons (default)
40
+ */
41
+ showIcon(): this;
42
+ /**
43
+ * Set icon position
44
+ */
45
+ iconPosition(position: "left" | "right"): this;
46
+ /**
47
+ * Placeholder for unknown values
48
+ */
49
+ placeholder(placeholder: string): this;
50
+ build(): ColumnDef<TData, unknown>;
51
+ }
52
+ export {};
@@ -13,4 +13,6 @@ export { ProgressColumn } from "./progress-column";
13
13
  export { SelectColumn } from "./select-column";
14
14
  export { TextColumn } from "./text-column";
15
15
  export { ActionsColumn } from "./actions-column";
16
+ export { EnumColumn } from "./enum-column";
17
+ export type { EnumOption } from "./enum-column";
16
18
  export type * from "./types";
@@ -6,6 +6,8 @@ export interface BaseColumnConfig<TData> {
6
6
  sortable?: boolean;
7
7
  searchable?: boolean;
8
8
  hidden?: boolean;
9
+ visibleByDefault?: boolean;
10
+ visibilityLabel?: string;
9
11
  align?: "left" | "center" | "right";
10
12
  width?: string | number;
11
13
  className?: string;
@@ -0,0 +1,52 @@
1
+ import { ColumnDef } from "@tanstack/react-table";
2
+ import { LucideIcon } from "lucide-react";
3
+ import { BaseColumn } from "./base-column";
4
+ import { BaseColumnConfig } from "./types";
5
+ export interface EnumOption<T = string | number> {
6
+ value: T;
7
+ label: string;
8
+ icon?: LucideIcon;
9
+ color?: "default" | "secondary" | "destructive" | "outline" | "success" | "warning" | "info";
10
+ className?: string;
11
+ }
12
+ interface EnumColumnConfig<TData> extends BaseColumnConfig<TData> {
13
+ options: EnumOption[];
14
+ asBadge?: boolean;
15
+ showIcon?: boolean;
16
+ iconPosition?: "left" | "right";
17
+ placeholder?: string;
18
+ }
19
+ export declare class EnumColumn<TData> extends BaseColumn<TData, EnumColumnConfig<TData>> {
20
+ constructor(accessor: keyof TData | string);
21
+ static make<TData>(accessor: keyof TData | string): EnumColumn<TData>;
22
+ /**
23
+ * Define the enum options with labels, icons, and colors
24
+ */
25
+ options(options: EnumOption[]): this;
26
+ /**
27
+ * Display as plain text instead of badge
28
+ */
29
+ asText(): this;
30
+ /**
31
+ * Display as badge (default)
32
+ */
33
+ asBadge(): this;
34
+ /**
35
+ * Hide icons
36
+ */
37
+ hideIcon(): this;
38
+ /**
39
+ * Show icons (default)
40
+ */
41
+ showIcon(): this;
42
+ /**
43
+ * Set icon position
44
+ */
45
+ iconPosition(position: "left" | "right"): this;
46
+ /**
47
+ * Placeholder for unknown values
48
+ */
49
+ placeholder(placeholder: string): this;
50
+ build(): ColumnDef<TData, unknown>;
51
+ }
52
+ export {};
@@ -12,11 +12,9 @@ export { ImageColumn } from "./columns/image-column";
12
12
  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
- export { ProgressColumn, ProgressColumn as progressColumn, } from "./columns/progress-column";
16
- export { SelectColumn, SelectColumn as selectColumn, } from "./columns/select-column";
17
- export { TextColumn, TextColumn as textColumn } from "./columns/text-column";
18
- export { ActionsColumn } from "./columns/actions-column";
19
- export type { ActionItem } from "./columns/actions-column";
15
+ export { ProgressColumn, SelectColumn } from "./columns";
16
+ export { EnumColumn, EnumColumn as enumColumn } from "./columns/enum-column";
17
+ export type { EnumOption } from "./columns/enum-column";
20
18
  export { ConfirmProvider, confirm } from "./confirm";
21
19
  export type { ConfirmOptions } from "./confirm";
22
20
  export type { DataTableConfig, EmptyStateConfig, FilterConfig, HeaderAction, PaginationConfig, SearchConfig, } from "./types";
@@ -44,6 +44,14 @@ class BaseColumn {
44
44
  this.config.hidden = hidden;
45
45
  return this;
46
46
  }
47
+ visibleByDefault(visible = true) {
48
+ this.config.visibleByDefault = visible;
49
+ return this;
50
+ }
51
+ visibilityLabel(label) {
52
+ this.config.visibilityLabel = label;
53
+ return this;
54
+ }
47
55
  alignLeft() {
48
56
  this.config.align = "left";
49
57
  return this;
@@ -1229,9 +1237,13 @@ class TextColumn extends BaseColumn {
1229
1237
  return this;
1230
1238
  }
1231
1239
  build() {
1232
- const { accessor, label, sortable, prefix, suffix, placeholder, formatter, } = this.config;
1240
+ const { accessor, label, sortable, prefix, suffix, placeholder, formatter, visibleByDefault, visibilityLabel, } = this.config;
1233
1241
  return {
1234
1242
  accessorKey: accessor,
1243
+ meta: {
1244
+ visibleByDefault,
1245
+ visibilityLabel: visibilityLabel || label || String(accessor),
1246
+ },
1235
1247
  header: ({ column }) => {
1236
1248
  const displayLabel = label || String(accessor);
1237
1249
  if (!sortable) {
@@ -1330,5 +1342,99 @@ class ActionsColumn {
1330
1342
  }
1331
1343
  }
1332
1344
 
1333
- export { ActionsColumn, AvatarGroupColumn, BadgeColumn, ButtonColumn, CheckboxColumn, DateColumn, DropdownColumn, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, SelectColumn, TextColumn };
1345
+ class EnumColumn extends BaseColumn {
1346
+ constructor(accessor) {
1347
+ super(accessor);
1348
+ this.config.asBadge = true;
1349
+ this.config.showIcon = true;
1350
+ this.config.iconPosition = "left";
1351
+ }
1352
+ static make(accessor) {
1353
+ return new EnumColumn(accessor);
1354
+ }
1355
+ /**
1356
+ * Define the enum options with labels, icons, and colors
1357
+ */
1358
+ options(options) {
1359
+ this.config.options = options;
1360
+ return this;
1361
+ }
1362
+ /**
1363
+ * Display as plain text instead of badge
1364
+ */
1365
+ asText() {
1366
+ this.config.asBadge = false;
1367
+ return this;
1368
+ }
1369
+ /**
1370
+ * Display as badge (default)
1371
+ */
1372
+ asBadge() {
1373
+ this.config.asBadge = true;
1374
+ return this;
1375
+ }
1376
+ /**
1377
+ * Hide icons
1378
+ */
1379
+ hideIcon() {
1380
+ this.config.showIcon = false;
1381
+ return this;
1382
+ }
1383
+ /**
1384
+ * Show icons (default)
1385
+ */
1386
+ showIcon() {
1387
+ this.config.showIcon = true;
1388
+ return this;
1389
+ }
1390
+ /**
1391
+ * Set icon position
1392
+ */
1393
+ iconPosition(position) {
1394
+ this.config.iconPosition = position;
1395
+ return this;
1396
+ }
1397
+ /**
1398
+ * Placeholder for unknown values
1399
+ */
1400
+ placeholder(placeholder) {
1401
+ this.config.placeholder = placeholder;
1402
+ return this;
1403
+ }
1404
+ build() {
1405
+ const { accessor, label, sortable, options, asBadge, showIcon, iconPosition, placeholder, } = this.config;
1406
+ if (!options || options.length === 0) {
1407
+ throw new Error(`EnumColumn "${String(accessor)}" requires options to be defined`);
1408
+ }
1409
+ return {
1410
+ accessorKey: accessor,
1411
+ header: ({ column }) => {
1412
+ const displayLabel = label || String(accessor);
1413
+ if (!sortable) {
1414
+ return (jsx("span", { className: cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: displayLabel }));
1415
+ }
1416
+ 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" })] }));
1417
+ },
1418
+ cell: ({ getValue }) => {
1419
+ const value = getValue();
1420
+ // Find matching option
1421
+ const option = options.find((opt) => opt.value === value);
1422
+ // Handle unknown values
1423
+ if (!option) {
1424
+ return (jsx("span", { className: cn("text-muted-foreground", this.getAlignmentClass(), this.config.cellClassName), children: placeholder || "—" }));
1425
+ }
1426
+ const Icon = option.icon;
1427
+ const iconElement = showIcon && Icon ? jsx(Icon, { className: "h-4 w-4" }) : null;
1428
+ // Render as Badge
1429
+ if (asBadge) {
1430
+ return (jsx("div", { className: cn(this.getAlignmentClass(), this.config.cellClassName), children: jsxs(Badge, { variant: option.color || "default", className: cn("inline-flex items-center gap-1.5", option.className), children: [iconPosition === "left" && iconElement, option.label, iconPosition === "right" && iconElement] }) }));
1431
+ }
1432
+ // Render as plain text with icon
1433
+ return (jsxs("div", { className: cn("inline-flex items-center gap-2", this.getAlignmentClass(), this.config.cellClassName, option.className), children: [iconPosition === "left" && iconElement, jsx("span", { children: option.label }), iconPosition === "right" && iconElement] }));
1434
+ },
1435
+ };
1436
+ }
1437
+ }
1438
+
1439
+ export { ActionsColumn, AvatarGroupColumn, BadgeColumn, ButtonColumn, CheckboxColumn, DateColumn, DropdownColumn, EnumColumn, IconColumn, ImageColumn, InputColumn, LinkColumn, NumberColumn, ProgressColumn, SelectColumn, TextColumn };
1334
1440
  //# sourceMappingURL=index.esm.js.map