@xeplr/ui-table 1.1.3 → 1.1.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/README.md CHANGED
@@ -88,7 +88,8 @@ Level N+1's `key` is the array property on each level-N row. `header` titles a c
88
88
  | field | |
89
89
  |---|---|
90
90
  | `accessor` | row property — required on a leaf column |
91
- | `header` | title; defaults to `accessor` |
91
+ | `header` | title; defaults to `accessor`. May be an element or a function (rendered by `flexRender`, e.g. an icon before the label) |
92
+ | `headerText` | the header's text, for measuring the column's width when `header` is not text; else the accessor is measured |
92
93
  | `dataType` | `'string'`, `'number'`, `'date'` or `'boolean'` — skips detection |
93
94
  | `render` | `{ type, …config }`, or the renderer name as a string |
94
95
  | `cell` | TanStack cell function `(ctx) => node`; wins over `render` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-table",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Controlled TanStack Table wrapper with auto-detected column types and smart filters",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -107,6 +107,19 @@ function pinnedWidth(overrides, index) {
107
107
  * in the width of "York"; a 60-character URL cannot be narrowed at all, which
108
108
  * is why the caller caps this (see maxFloor).
109
109
  */
110
+ /**
111
+ * The text a column's header is measured by. A header may be an element or a
112
+ * function (drawn by flexRender: an icon before the label), which has no
113
+ * width of its own to measure — so `headerText` when the column gives it, else
114
+ * the header when it is text, else the accessor.
115
+ */
116
+ export function headerTextOf(column) {
117
+ if (!column) return '';
118
+ if (typeof column.headerText === 'string') return column.headerText;
119
+ if (typeof column.header === 'string' || typeof column.header === 'number') return String(column.header);
120
+ return column.accessor == null ? '' : String(column.accessor);
121
+ }
122
+
110
123
  export function longestToken(text) {
111
124
  if (!text) return '';
112
125
  var parts = String(text).split(/\s+/);
@@ -1,5 +1,5 @@
1
1
  import { useState, useRef, useLayoutEffect, useCallback } from 'react';
2
- import { measureColumnDemand, allocateColumnWidths, resolvePercentWidths } from './columnWidths.js';
2
+ import { measureColumnDemand, allocateColumnWidths, resolvePercentWidths, headerTextOf } from './columnWidths.js';
3
3
 
4
4
  /**
5
5
  * Content-based column widths — the DOM half. See columnWidths.js for the
@@ -250,7 +250,7 @@ export default function useColumnWidths(opts) {
250
250
  columns: columns,
251
251
  rows: rows,
252
252
  textOf: textOf,
253
- headerOf: function(column) { return column.header || column.accessor; },
253
+ headerOf: headerTextOf,
254
254
  keyOf: function(column) { return column.accessor; },
255
255
  measure: measureWidest,
256
256
  bodyFont: BODY_FONTS,