@xeplr/ui-table 1.1.2 → 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` |
@@ -263,6 +264,17 @@ CSS classes are namespaced `xeplr-table-*` (chrome) and `xeplr-r-*` (renderers).
263
264
 
264
265
  The `gold` / `blue` tag variants and `link` use fixed colours. The header is not sticky by default; add `position: sticky; top: 0` to `.xeplr-table-th` and the table offsets each grouped header row by the real height of the rows above it.
265
266
 
267
+ ### Touch screens and phones
268
+
269
+ - **Rows keep scrolling sideways** on a phone, inside the table's own box — a table of ten columns does not fit 360px, and turning rows into cards loses the grid. The page itself never widens.
270
+ - **The actions column is pinned to the right edge** below 640px, so a row's Edit or Delete is on screen without scrolling the table.
271
+ - **One tap opens a row** on a touch screen where a mouse needs a double-click (`childDisplay="popup"`). A tap on the row's own button or tick box does only that.
272
+ - **Thumb-sized targets** on any touch screen (`pointer: coarse`) and below 640px: row buttons 40px, filter and expand buttons 36px, tick boxes 22px, toolbar and paging buttons 36–40px.
273
+ - **The toolbar and the paging bar wrap** instead of clipping their last buttons; "Page 1 of 3" and the row count never break mid-phrase.
274
+ - **Popups fill the screen** below 640px, and the detail popup's fields go to one column.
275
+
276
+ Nothing above changes on a desktop with a mouse.
277
+
266
278
  ### Style layers for a host panel
267
279
 
268
280
  `tableStyles.js` is the vocabulary a host builds a style editor from — no React:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-table",
3
- "version": "1.1.2",
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",
@@ -32,6 +32,14 @@ var filterComponentMap = {
32
32
  */
33
33
  var CHILD_DISPLAY = { POPUP: 'popup', INNER: 'inner' };
34
34
 
35
+ // Was this click a finger? A click is a PointerEvent that says so; where the
36
+ // browser does not say, a screen with no hover is a touch screen.
37
+ function isTouch(e) {
38
+ var type = e.nativeEvent && e.nativeEvent.pointerType;
39
+ if (type) return type === 'touch' || type === 'pen';
40
+ return typeof window !== 'undefined' && !!window.matchMedia && window.matchMedia('(hover: none)').matches;
41
+ }
42
+
35
43
  /**
36
44
  * Main table component.
37
45
  *
@@ -356,6 +364,14 @@ export default function XeplrTable(props) {
356
364
  }
357
365
  }
358
366
 
367
+ // A finger has no double-click: on a touch screen one tap opens the row.
368
+ // Not when the tap was on something of the row's own (a button, a tick box).
369
+ function handleRowTap(e, original) {
370
+ if (!usePopup || !isTouch(e)) return;
371
+ if (e.target.closest && e.target.closest('button, input, select, textarea, a, label')) return;
372
+ actions.openDetail(original);
373
+ }
374
+
359
375
  // Resolved fresh each render: if the row has paged, sorted or filtered away,
360
376
  // there is nothing to find and the box simply isn't rendered.
361
377
  var zoomCell = null;
@@ -595,6 +611,7 @@ export default function XeplrTable(props) {
595
611
 
596
612
  rowElements.push(
597
613
  <tr key={row.id} className={rowClass}
614
+ onClick={function(e) { handleRowTap(e, original); }}
598
615
  onDoubleClick={function() { handleRowDoubleClick(original); }}>
599
616
  {showExpandCol && (
600
617
  <td className="xeplr-table-td xeplr-table-td-expand">
@@ -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,
@@ -24,6 +24,9 @@
24
24
  /* Centred so arbitrary host content in the leading slot sits on the same
25
25
  line as the buttons instead of stretching to the row's full height. */
26
26
  align-items: center;
27
+ /* Wraps rather than clipping: the container is overflow:hidden, so on a
28
+ narrow screen a toolbar that cannot wrap loses its last buttons. */
29
+ flex-wrap: wrap;
27
30
  gap: 8px;
28
31
  padding: 8px 12px;
29
32
  border-bottom: 1px solid var(--xeplr-border-primary, #2a2a4a);
@@ -448,6 +451,7 @@
448
451
  .xeplr-table-pagination {
449
452
  display: flex;
450
453
  align-items: center;
454
+ flex-wrap: wrap;
451
455
  gap: 8px;
452
456
  padding: 8px 12px;
453
457
  border-top: 1px solid var(--xeplr-border-primary, #2a2a4a);
@@ -476,6 +480,7 @@
476
480
 
477
481
  .xeplr-table-page-info {
478
482
  color: var(--xeplr-text-secondary, #a0a0c0);
483
+ white-space: nowrap;
479
484
  }
480
485
 
481
486
  .xeplr-table-page-size {
@@ -490,6 +495,7 @@
490
495
  .xeplr-table-row-count {
491
496
  color: var(--xeplr-text-muted, #666);
492
497
  margin-left: auto;
498
+ white-space: nowrap;
493
499
  }
494
500
 
495
501
  /* ── Scrollbar ── */
@@ -1082,3 +1088,39 @@
1082
1088
  border-left: none;
1083
1089
  border-right: none;
1084
1090
  }
1091
+
1092
+ /* ── Touch ──
1093
+ A finger is not a mouse pointer: every control a row or the toolbar offers
1094
+ gets a target a thumb can hit (about 40px), on any touch screen and on
1095
+ any phone-width one. */
1096
+ @media (pointer: coarse), (max-width: 640px) {
1097
+ .xeplr-table-action-btn { width: 40px; height: 40px; }
1098
+ .xeplr-table-action-label { width: auto; height: auto; min-height: 40px; padding: 8px 14px; font-size: 13px; }
1099
+ .xeplr-table-filter-trigger, .xeplr-table-expand-btn { width: 36px; height: 36px; }
1100
+ .xeplr-table-checkbox { width: 22px; height: 22px; }
1101
+ .xeplr-table-toolbar-btn { min-height: 36px; padding: 6px 14px; font-size: 13px; }
1102
+ .xeplr-table-pagination button { min-width: 40px; min-height: 40px; }
1103
+ .xeplr-table-page-size { min-height: 40px; font-size: 14px; }
1104
+ .xeplr-table-modal-close { min-width: 40px; min-height: 40px; }
1105
+ }
1106
+
1107
+ /* ── Phones ──
1108
+ The table keeps scrolling sideways — ten columns do not fit a phone and
1109
+ turning rows into cards loses the grid — but the row's own buttons stay
1110
+ pinned at the right edge, so Edit is never a scroll away. Popups fill the
1111
+ screen and their fields stack. */
1112
+ @media (max-width: 640px) {
1113
+ .xeplr-table-th-actions,
1114
+ .xeplr-table-td-actions {
1115
+ position: sticky;
1116
+ right: 0;
1117
+ z-index: 1;
1118
+ background: var(--xeplr-bg-tertiary, #1a1a2e);
1119
+ box-shadow: -6px 0 8px -6px rgba(0, 0, 0, 0.25);
1120
+ }
1121
+ .xeplr-table-th-actions { background: var(--xeplr-bg-secondary, #16162a); }
1122
+ .xeplr-table-modal,
1123
+ .xeplr-table-detail { width: 100%; max-width: none; height: 100%; max-height: none; border-radius: 0; }
1124
+ .xeplr-table-detail-fields { grid-template-columns: 1fr; }
1125
+ .xeplr-table-detail-body { padding: 16px; }
1126
+ }