@nccirtu/tablefy 0.7.1 → 0.7.3
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/columns/enum-column.d.ts +52 -0
- package/dist/columns/columns/index.d.ts +2 -0
- package/dist/columns/enum-column.d.ts +52 -0
- package/dist/columns/index.d.ts +3 -5
- package/dist/columns/index.esm.js +95 -1
- package/dist/columns/index.esm.js.map +1 -1
- package/dist/columns/index.js +95 -0
- package/dist/columns/index.js.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.esm.js +64 -125
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +63 -127
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/columns/index.js
CHANGED
|
@@ -1332,6 +1332,100 @@ class ActionsColumn {
|
|
|
1332
1332
|
}
|
|
1333
1333
|
}
|
|
1334
1334
|
|
|
1335
|
+
class EnumColumn extends BaseColumn {
|
|
1336
|
+
constructor(accessor) {
|
|
1337
|
+
super(accessor);
|
|
1338
|
+
this.config.asBadge = true;
|
|
1339
|
+
this.config.showIcon = true;
|
|
1340
|
+
this.config.iconPosition = "left";
|
|
1341
|
+
}
|
|
1342
|
+
static make(accessor) {
|
|
1343
|
+
return new EnumColumn(accessor);
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Define the enum options with labels, icons, and colors
|
|
1347
|
+
*/
|
|
1348
|
+
options(options) {
|
|
1349
|
+
this.config.options = options;
|
|
1350
|
+
return this;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Display as plain text instead of badge
|
|
1354
|
+
*/
|
|
1355
|
+
asText() {
|
|
1356
|
+
this.config.asBadge = false;
|
|
1357
|
+
return this;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Display as badge (default)
|
|
1361
|
+
*/
|
|
1362
|
+
asBadge() {
|
|
1363
|
+
this.config.asBadge = true;
|
|
1364
|
+
return this;
|
|
1365
|
+
}
|
|
1366
|
+
/**
|
|
1367
|
+
* Hide icons
|
|
1368
|
+
*/
|
|
1369
|
+
hideIcon() {
|
|
1370
|
+
this.config.showIcon = false;
|
|
1371
|
+
return this;
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Show icons (default)
|
|
1375
|
+
*/
|
|
1376
|
+
showIcon() {
|
|
1377
|
+
this.config.showIcon = true;
|
|
1378
|
+
return this;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Set icon position
|
|
1382
|
+
*/
|
|
1383
|
+
iconPosition(position) {
|
|
1384
|
+
this.config.iconPosition = position;
|
|
1385
|
+
return this;
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Placeholder for unknown values
|
|
1389
|
+
*/
|
|
1390
|
+
placeholder(placeholder) {
|
|
1391
|
+
this.config.placeholder = placeholder;
|
|
1392
|
+
return this;
|
|
1393
|
+
}
|
|
1394
|
+
build() {
|
|
1395
|
+
const { accessor, label, sortable, options, asBadge, showIcon, iconPosition, placeholder, } = this.config;
|
|
1396
|
+
if (!options || options.length === 0) {
|
|
1397
|
+
throw new Error(`EnumColumn "${String(accessor)}" requires options to be defined`);
|
|
1398
|
+
}
|
|
1399
|
+
return {
|
|
1400
|
+
accessorKey: accessor,
|
|
1401
|
+
header: ({ column }) => {
|
|
1402
|
+
const displayLabel = label || String(accessor);
|
|
1403
|
+
if (!sortable) {
|
|
1404
|
+
return (jsxRuntime.jsx("span", { className: utils.cn("text-muted-foreground font-medium", this.getAlignmentClass(), this.config.headerClassName), children: displayLabel }));
|
|
1405
|
+
}
|
|
1406
|
+
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" })] }));
|
|
1407
|
+
},
|
|
1408
|
+
cell: ({ getValue }) => {
|
|
1409
|
+
const value = getValue();
|
|
1410
|
+
// Find matching option
|
|
1411
|
+
const option = options.find((opt) => opt.value === value);
|
|
1412
|
+
// Handle unknown values
|
|
1413
|
+
if (!option) {
|
|
1414
|
+
return (jsxRuntime.jsx("span", { className: utils.cn("text-muted-foreground", this.getAlignmentClass(), this.config.cellClassName), children: placeholder || "—" }));
|
|
1415
|
+
}
|
|
1416
|
+
const Icon = option.icon;
|
|
1417
|
+
const iconElement = showIcon && Icon ? jsxRuntime.jsx(Icon, { className: "h-4 w-4" }) : null;
|
|
1418
|
+
// Render as Badge
|
|
1419
|
+
if (asBadge) {
|
|
1420
|
+
return (jsxRuntime.jsx("div", { className: utils.cn(this.getAlignmentClass(), this.config.cellClassName), children: jsxRuntime.jsxs(badge.Badge, { variant: option.color || "default", className: utils.cn("inline-flex items-center gap-1.5", option.className), children: [iconPosition === "left" && iconElement, option.label, iconPosition === "right" && iconElement] }) }));
|
|
1421
|
+
}
|
|
1422
|
+
// Render as plain text with icon
|
|
1423
|
+
return (jsxRuntime.jsxs("div", { className: utils.cn("inline-flex items-center gap-2", this.getAlignmentClass(), this.config.cellClassName, option.className), children: [iconPosition === "left" && iconElement, jsxRuntime.jsx("span", { children: option.label }), iconPosition === "right" && iconElement] }));
|
|
1424
|
+
},
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1335
1429
|
exports.ActionsColumn = ActionsColumn;
|
|
1336
1430
|
exports.AvatarGroupColumn = AvatarGroupColumn;
|
|
1337
1431
|
exports.BadgeColumn = BadgeColumn;
|
|
@@ -1339,6 +1433,7 @@ exports.ButtonColumn = ButtonColumn;
|
|
|
1339
1433
|
exports.CheckboxColumn = CheckboxColumn;
|
|
1340
1434
|
exports.DateColumn = DateColumn;
|
|
1341
1435
|
exports.DropdownColumn = DropdownColumn;
|
|
1436
|
+
exports.EnumColumn = EnumColumn;
|
|
1342
1437
|
exports.IconColumn = IconColumn;
|
|
1343
1438
|
exports.ImageColumn = ImageColumn;
|
|
1344
1439
|
exports.InputColumn = InputColumn;
|