trotl-table 1.0.12 → 1.0.14

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/index.cjs.js CHANGED
@@ -9696,7 +9696,8 @@ function TableInner({
9696
9696
  enableMultiSelect = false,
9697
9697
  enableExternalRowDrop = false,
9698
9698
  onExternalRowDrop = () => {},
9699
- useExternalDndContext = false
9699
+ useExternalDndContext = false,
9700
+ customColumns = []
9700
9701
  }) {
9701
9702
  // Local selection & sorting state (removed TableContext dependency)
9702
9703
  const [selectedRows, setSelectedRows] = React.useState([]);
@@ -10150,6 +10151,20 @@ function TableInner({
10150
10151
  }
10151
10152
  const row = item.row;
10152
10153
  const visualIndex = tableDataFlat.slice(0, index).filter(i => i.type === "row").length + 1;
10154
+
10155
+ // Compose columns + custom columns
10156
+ const allColumns = [...columns];
10157
+ // Insert custom columns at specified places
10158
+ if (Array.isArray(customColumns)) {
10159
+ customColumns.forEach(col => {
10160
+ if (typeof col.place === 'number') {
10161
+ allColumns.splice(col.place, 0, {
10162
+ ...col,
10163
+ isCustom: true
10164
+ });
10165
+ }
10166
+ });
10167
+ }
10153
10168
  const content = /*#__PURE__*/React.createElement("div", {
10154
10169
  key: key,
10155
10170
  style: style,
@@ -10162,10 +10177,22 @@ function TableInner({
10162
10177
  onChange: () => toggleRowSelection(row.id)
10163
10178
  })), showKey && /*#__PURE__*/React.createElement("div", {
10164
10179
  className: "table-cell key-cell"
10165
- }, visualIndex), columns.map((col, i) => /*#__PURE__*/React.createElement("div", {
10166
- key: i,
10167
- className: "table-cell"
10168
- }, renderCell(row[col.accessor], col.accessor))), showActions && /*#__PURE__*/React.createElement("div", {
10180
+ }, visualIndex), allColumns.map((col, i) => {
10181
+ let cellStyle = col.isCustom && col.style ? {
10182
+ ...col.style
10183
+ } : undefined;
10184
+ if (col.isCustom && col.style && col.style.width) {
10185
+ cellStyle = cellStyle || {};
10186
+ cellStyle.minWidth = col.style.width;
10187
+ cellStyle.maxWidth = col.style.width;
10188
+ cellStyle.width = col.style.width;
10189
+ }
10190
+ return /*#__PURE__*/React.createElement("div", {
10191
+ key: i,
10192
+ className: "table-cell",
10193
+ style: cellStyle
10194
+ }, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(row[col.accessor], col.accessor, row));
10195
+ }), showActions && /*#__PURE__*/React.createElement("div", {
10169
10196
  className: "table-cell action-cell"
10170
10197
  }, showView && /*#__PURE__*/React.createElement("button", {
10171
10198
  className: "action-btn-table",
@@ -10202,7 +10229,7 @@ function TableInner({
10202
10229
  }, content);
10203
10230
  }
10204
10231
  return content;
10205
- }, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, viewCallback, editCallback, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId]);
10232
+ }, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, viewCallback, editCallback, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId, customColumns]);
10206
10233
  const rowHeightGetter = ({
10207
10234
  index
10208
10235
  }) => tableDataFlat[index]?.type === "group" ? groupHeaderHeight : rowHeight;
@@ -10227,6 +10254,19 @@ function TableInner({
10227
10254
  externalDrop(node);
10228
10255
  }
10229
10256
  }, [useExternalDndContext, enableExternalRowDrop, externalDrop]);
10257
+
10258
+ // Compose columns + custom columns for header
10259
+ const allColumns = [...columns];
10260
+ if (Array.isArray(customColumns)) {
10261
+ customColumns.forEach(col => {
10262
+ if (typeof col.place === 'number') {
10263
+ allColumns.splice(col.place, 0, {
10264
+ ...col,
10265
+ isCustom: true
10266
+ });
10267
+ }
10268
+ });
10269
+ }
10230
10270
  const tableMarkup = /*#__PURE__*/React.createElement("div", {
10231
10271
  className: "table-container",
10232
10272
  ref: setTableRef,
@@ -10260,14 +10300,29 @@ function TableInner({
10260
10300
  }
10261
10301
  })), showKey && /*#__PURE__*/React.createElement("div", {
10262
10302
  className: "table-cell key-cell"
10263
- }, "#"), columns.map((col, i) => /*#__PURE__*/React.createElement("div", {
10264
- key: i,
10265
- className: "table-cell",
10266
- onClick: () => setSort(col.accessor),
10267
- style: {
10268
- cursor: "pointer"
10303
+ }, "#"), allColumns.map((col, i) => {
10304
+ // For custom columns, apply width and textAlign to header cell
10305
+ let cellStyle = col.isCustom && col.style ? {
10306
+ ...col.style,
10307
+ cursor: undefined,
10308
+ display: 'flex',
10309
+ alignItems: 'center',
10310
+ justifyContent: col.style.textAlign === 'center' ? 'center' : col.style.textAlign === 'right' ? 'flex-end' : 'flex-start'
10311
+ } : {
10312
+ cursor: col.isCustom ? undefined : "pointer"
10313
+ };
10314
+ if (col.isCustom && col.style && col.style.width) {
10315
+ cellStyle.minWidth = col.style.width;
10316
+ cellStyle.maxWidth = col.style.width;
10317
+ cellStyle.width = col.style.width;
10269
10318
  }
10270
- }, col.header, sorting?.column === col.accessor && (sorting.direction === "asc" ? " ↑" : " ↓"))), showActions && /*#__PURE__*/React.createElement("div", {
10319
+ return /*#__PURE__*/React.createElement("div", {
10320
+ key: i,
10321
+ className: "table-cell",
10322
+ style: cellStyle,
10323
+ onClick: col.isCustom ? undefined : () => setSort(col.accessor)
10324
+ }, col.isCustom ? col.header ?? '' : col.header, !col.isCustom && sorting?.column === col.accessor && (sorting.direction === "asc" ? " ↑" : " ↓"));
10325
+ }), showActions && /*#__PURE__*/React.createElement("div", {
10271
10326
  className: "table-cell action-cell"
10272
10327
  }, "Action"))), /*#__PURE__*/React.createElement("div", {
10273
10328
  className: "main-table",
@@ -10309,9 +10364,51 @@ function Table(props) {
10309
10364
  }, /*#__PURE__*/React.createElement(TableInner, props));
10310
10365
  }
10311
10366
 
10367
+ function Switch({
10368
+ checked,
10369
+ onChange
10370
+ }) {
10371
+ return /*#__PURE__*/React.createElement("label", {
10372
+ style: {
10373
+ display: "inline-flex",
10374
+ alignItems: "center",
10375
+ cursor: "pointer"
10376
+ }
10377
+ }, /*#__PURE__*/React.createElement("input", {
10378
+ type: "checkbox",
10379
+ checked: checked,
10380
+ onChange: onChange,
10381
+ style: {
10382
+ display: "none"
10383
+ }
10384
+ }), /*#__PURE__*/React.createElement("span", {
10385
+ style: {
10386
+ width: 36,
10387
+ height: 20,
10388
+ background: checked ? "#4caf50" : "#ccc",
10389
+ borderRadius: 12,
10390
+ position: "relative",
10391
+ transition: "background 0.2s",
10392
+ display: "inline-block"
10393
+ }
10394
+ }, /*#__PURE__*/React.createElement("span", {
10395
+ style: {
10396
+ position: "absolute",
10397
+ left: checked ? 18 : 2,
10398
+ top: 2,
10399
+ width: 16,
10400
+ height: 16,
10401
+ background: "#fff",
10402
+ borderRadius: "50%",
10403
+ transition: "left 0.2s"
10404
+ }
10405
+ })));
10406
+ }
10407
+
10312
10408
  // src/index.js
10313
- // if you want named import
10409
+ // named exports for both
10314
10410
 
10411
+ exports.Switch = Switch;
10315
10412
  exports.Table = Table;
10316
10413
  exports.default = Table;
10317
10414
  //# sourceMappingURL=index.cjs.js.map