@multiplatform.one/table 9.5.0 → 9.6.0

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.
Files changed (84) hide show
  1. package/dist/cjs/components/ChildTable/index.cjs +4 -2
  2. package/dist/cjs/components/ChildTable/index.native.js +4 -2
  3. package/dist/cjs/components/ChildTable/index.native.js.map +1 -1
  4. package/dist/cjs/components/DataTableCell/index.cjs +5 -0
  5. package/dist/cjs/components/DataTableCell/index.native.js +5 -0
  6. package/dist/cjs/components/DataTableCell/index.native.js.map +1 -1
  7. package/dist/cjs/components/TableInput/ChildRowList.cjs +262 -0
  8. package/dist/cjs/components/TableInput/ChildRowList.native.js +287 -0
  9. package/dist/cjs/components/TableInput/ChildRowList.native.js.map +1 -0
  10. package/dist/cjs/components/TableInput/RowDetailEditor.cjs +14 -3
  11. package/dist/cjs/components/TableInput/index.cjs +200 -13
  12. package/dist/cjs/components/TableInput/index.native.js +1 -0
  13. package/dist/cjs/components/TableInput/index.native.js.map +1 -1
  14. package/dist/cjs/components/TableInput/shared.cjs +37 -0
  15. package/dist/cjs/components/TableInput/shared.native.js +48 -0
  16. package/dist/cjs/components/TableInput/shared.native.js.map +1 -1
  17. package/dist/esm/components/ChildTable/index.mjs +4 -2
  18. package/dist/esm/components/ChildTable/index.mjs.map +1 -1
  19. package/dist/esm/components/ChildTable/index.native.js +4 -2
  20. package/dist/esm/components/ChildTable/index.native.js.map +1 -1
  21. package/dist/esm/components/DataTableCell/index.mjs +5 -0
  22. package/dist/esm/components/DataTableCell/index.mjs.map +1 -1
  23. package/dist/esm/components/DataTableCell/index.native.js +5 -0
  24. package/dist/esm/components/DataTableCell/index.native.js.map +1 -1
  25. package/dist/esm/components/TableInput/ChildRowList.mjs +235 -0
  26. package/dist/esm/components/TableInput/ChildRowList.mjs.map +1 -0
  27. package/dist/esm/components/TableInput/ChildRowList.native.js +257 -0
  28. package/dist/esm/components/TableInput/ChildRowList.native.js.map +1 -0
  29. package/dist/esm/components/TableInput/RowDetailEditor.mjs +15 -4
  30. package/dist/esm/components/TableInput/RowDetailEditor.mjs.map +1 -1
  31. package/dist/esm/components/TableInput/index.mjs +204 -17
  32. package/dist/esm/components/TableInput/index.mjs.map +1 -1
  33. package/dist/esm/components/TableInput/index.native.js +2 -1
  34. package/dist/esm/components/TableInput/index.native.js.map +1 -1
  35. package/dist/esm/components/TableInput/shared.mjs +35 -1
  36. package/dist/esm/components/TableInput/shared.mjs.map +1 -1
  37. package/dist/esm/components/TableInput/shared.native.js +46 -1
  38. package/dist/esm/components/TableInput/shared.native.js.map +1 -1
  39. package/dist/jsx/components/ChildTable/index.mjs +4 -2
  40. package/dist/jsx/components/ChildTable/index.mjs.map +1 -1
  41. package/dist/jsx/components/ChildTable/index.native.js +4 -2
  42. package/dist/jsx/components/ChildTable/index.native.js.map +1 -1
  43. package/dist/jsx/components/DataTableCell/index.mjs +5 -0
  44. package/dist/jsx/components/DataTableCell/index.mjs.map +1 -1
  45. package/dist/jsx/components/DataTableCell/index.native.js +5 -0
  46. package/dist/jsx/components/DataTableCell/index.native.js.map +1 -1
  47. package/dist/jsx/components/TableInput/ChildRowList.mjs +235 -0
  48. package/dist/jsx/components/TableInput/ChildRowList.mjs.map +1 -0
  49. package/dist/jsx/components/TableInput/ChildRowList.native.js +287 -0
  50. package/dist/jsx/components/TableInput/ChildRowList.native.js.map +1 -0
  51. package/dist/jsx/components/TableInput/RowDetailEditor.mjs +15 -4
  52. package/dist/jsx/components/TableInput/RowDetailEditor.mjs.map +1 -1
  53. package/dist/jsx/components/TableInput/index.mjs +204 -17
  54. package/dist/jsx/components/TableInput/index.mjs.map +1 -1
  55. package/dist/jsx/components/TableInput/index.native.js +1 -0
  56. package/dist/jsx/components/TableInput/index.native.js.map +1 -1
  57. package/dist/jsx/components/TableInput/shared.mjs +35 -1
  58. package/dist/jsx/components/TableInput/shared.mjs.map +1 -1
  59. package/dist/jsx/components/TableInput/shared.native.js +48 -0
  60. package/dist/jsx/components/TableInput/shared.native.js.map +1 -1
  61. package/package.json +12 -12
  62. package/src/components/ChildTable/ChildTable.stories.tsx +50 -0
  63. package/src/components/ChildTable/index.tsx +4 -0
  64. package/src/components/DataTableCell/index.tsx +3 -0
  65. package/src/components/TableInput/ChildRowList.tsx +290 -0
  66. package/src/components/TableInput/RowDetailEditor.tsx +15 -4
  67. package/src/components/TableInput/childRowList.spec.tsx +141 -0
  68. package/src/components/TableInput/index.native.tsx +13 -2
  69. package/src/components/TableInput/index.tsx +349 -115
  70. package/src/components/TableInput/shared.ts +51 -0
  71. package/src/components/TableInput/tableInput.fit.spec.tsx +157 -0
  72. package/src/components/TableInput/tableInput.phoneIndex.spec.tsx +61 -0
  73. package/types/components/ChildTable/index.d.ts +2 -0
  74. package/types/components/ChildTable/index.d.ts.map +1 -1
  75. package/types/components/DataTableCell/index.d.ts.map +1 -1
  76. package/types/components/TableInput/ChildRowList.d.ts +38 -0
  77. package/types/components/TableInput/ChildRowList.d.ts.map +1 -0
  78. package/types/components/TableInput/RowDetailEditor.d.ts +3 -1
  79. package/types/components/TableInput/RowDetailEditor.d.ts.map +1 -1
  80. package/types/components/TableInput/index.d.ts +8 -1
  81. package/types/components/TableInput/index.d.ts.map +1 -1
  82. package/types/components/TableInput/index.native.d.ts.map +1 -1
  83. package/types/components/TableInput/shared.d.ts +22 -0
  84. package/types/components/TableInput/shared.d.ts.map +1 -1
@@ -20,7 +20,7 @@
20
20
  * `isCellHidden` blanks a cell per row, and the caller owns the rule.
21
21
  */
22
22
 
23
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
23
+ import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
24
24
  import {
25
25
  SortableHandle,
26
26
  SortableSessionProvider,
@@ -45,14 +45,21 @@ import {
45
45
  } from "@tanstack/react-table";
46
46
  import { TrashIcon, PlusIcon } from "@phosphor-icons/react";
47
47
  import { useTranslation } from "react-i18next";
48
- import { Table, getTableCellPadding } from "@multiplatform.one/table-primitives";
48
+ import {
49
+ Table,
50
+ getTableCellPadding,
51
+ tableZebraFill,
52
+ tableZebraStripe,
53
+ } from "@multiplatform.one/table-primitives";
49
54
  import {
50
55
  transitionProps,
51
56
  hairline,
52
57
  useResolvedKnobs,
53
58
  sizeTokenStop,
59
+ useLayoutSizeClass,
54
60
  } from "@multiplatform.one/theme";
55
- import { View, XStack, YStack, isWeb, useTheme } from "tamagui";
61
+ import { View, XStack, YStack, getTokenValue, isWeb, useMedia, useTheme } from "tamagui";
62
+ import { LinearGradient } from "tamagui/linear-gradient";
56
63
  import type {
57
64
  DataTableColumn,
58
65
  DataTableData,
@@ -61,11 +68,15 @@ import type {
61
68
  } from "../../types";
62
69
  import { DataTableCell } from "../DataTableCell";
63
70
  import { withInterp } from "../../utils/withInterp";
71
+ import { ChildRowList } from "./ChildRowList";
64
72
  import { RowDetailEditor } from "./RowDetailEditor";
65
73
  import {
66
74
  childRowAttrs,
67
75
  childTableKeyAction,
76
+ childColumnJustify,
77
+ childScrollEdges,
68
78
  columnKey,
79
+ fitChildColumns,
69
80
  generateRowId,
70
81
  isEmptyRows,
71
82
  SKELETON_ROW_COUNT,
@@ -82,6 +93,8 @@ interface GridMeta<TData extends DataTableData> {
82
93
  readOnly: boolean;
83
94
  canDelete: boolean;
84
95
  deleteColor: string;
96
+ mutedColor: string;
97
+ tuned: boolean;
85
98
  knobProps: ReturnType<typeof useResolvedKnobs>["knobProps"];
86
99
  sortable: ReturnType<typeof useSortableRows<TData>>;
87
100
  detailColumns: DataTableColumn<TData>[];
@@ -145,9 +158,10 @@ function DataCell<TData extends DataTableData>(props: GridCellProps<TData>) {
145
158
 
146
159
  function DetailCell<TData extends DataTableData>(props: GridCellProps<TData>) {
147
160
  const { row } = props;
148
- const { detailColumns, readOnly, isCellHidden, commitRowDetail } = gridMeta(props);
161
+ const { detailColumns, readOnly, isCellHidden, commitRowDetail, tuned } = gridMeta(props);
149
162
  return (
150
163
  <RowDetailEditor
164
+ glyphTrigger={tuned}
151
165
  row={row.original}
152
166
  rowIndex={row.index}
153
167
  columns={detailColumns}
@@ -160,7 +174,20 @@ function DetailCell<TData extends DataTableData>(props: GridCellProps<TData>) {
160
174
 
161
175
  function DeleteCell<TData extends DataTableData>(props: GridCellProps<TData>) {
162
176
  const { row } = props;
163
- const { canDelete, knobProps, deleteColor, deleteRow, t } = gridMeta(props);
177
+ const { canDelete, knobProps, deleteColor, mutedColor, tuned, deleteRow, t } = gridMeta(props);
178
+ const label = withInterp(t("Delete row {{row}}", { row: row.index + 1 }), {
179
+ row: row.index + 1,
180
+ });
181
+ if (tuned) {
182
+ return (
183
+ <IconButton
184
+ icon={<TrashIcon color={mutedColor} weight="regular" />}
185
+ onPress={() => deleteRow(row.index)}
186
+ disabled={!canDelete}
187
+ aria-label={label}
188
+ />
189
+ );
190
+ }
164
191
  return (
165
192
  <Button
166
193
  chromeless
@@ -171,7 +198,7 @@ function DeleteCell<TData extends DataTableData>(props: GridCellProps<TData>) {
171
198
  row: row.index + 1,
172
199
  })}
173
200
  >
174
- <TrashIcon size={16} color={deleteColor} />
201
+ <TrashIcon size={16} color={deleteColor} style={{ flexShrink: 0 }} />
175
202
  </Button>
176
203
  );
177
204
  }
@@ -224,6 +251,13 @@ export interface TableInputProps<TData extends DataTableData = DataTableData> {
224
251
  detailColumns?: DataTableColumn<TData>[];
225
252
  /** Hides one row's cell, in the grid and in the detail editor. */
226
253
  isCellHidden?: ChildCellHidden<TData>;
254
+ /**
255
+ * How the rows read on a phone (LC-298). `drill`, the default, lists the
256
+ * rows as a read-only inset group that opens each row in a sheet. `inline`
257
+ * opts out: every cell stays a field at the 44pt control height. Wider
258
+ * screens always show the grid of fields.
259
+ */
260
+ phoneRows?: "inline" | "drill";
227
261
  }
228
262
 
229
263
  export function TableInput<TData extends DataTableData = DataTableData>({
@@ -249,6 +283,7 @@ export function TableInput<TData extends DataTableData = DataTableData>({
249
283
  rowDetail = false,
250
284
  detailColumns,
251
285
  isCellHidden,
286
+ phoneRows = "drill",
252
287
  }: TableInputProps<TData>) {
253
288
  const { t } = useTranslation();
254
289
  const { resolvedForm } = useFormField({ form: formProp });
@@ -286,6 +321,7 @@ export function TableInput<TData extends DataTableData = DataTableData>({
286
321
  rowDetail,
287
322
  detailColumns: detailColumns ?? columns,
288
323
  isCellHidden,
324
+ phoneRows,
289
325
  t,
290
326
  };
291
327
 
@@ -342,6 +378,7 @@ interface TableInputInnerProps<TData extends DataTableData> {
342
378
  rowDetail: boolean;
343
379
  detailColumns: DataTableColumn<TData>[];
344
380
  isCellHidden?: ChildCellHidden<TData>;
381
+ phoneRows?: "inline" | "drill";
345
382
  t: (key: string, options?: Record<string, unknown>) => string;
346
383
  }
347
384
 
@@ -364,6 +401,7 @@ function TableInputInner<TData extends DataTableData>({
364
401
  rowDetail,
365
402
  detailColumns,
366
403
  isCellHidden,
404
+ phoneRows,
367
405
  t,
368
406
  }: TableInputInnerProps<TData>) {
369
407
  const theme = useTheme();
@@ -374,6 +412,13 @@ function TableInputInner<TData extends DataTableData>({
374
412
  const pendingFocusRef = useRef<string | null>(null);
375
413
  const gridRef = useRef<HTMLElement | null>(null);
376
414
  const reorderEnabled = enableReorder && !readOnly && !skeleton;
415
+ const media = useMedia();
416
+ const phone = media.sm === false;
417
+ const tuned = phoneRows === "inline" && phone;
418
+ // The house compact class is the same 640 line as the table package's sm;
419
+ // reading it keeps a width-less render (SSR, a spec) on the grid.
420
+ const compact = useLayoutSizeClass() === "compact";
421
+ const drill = phoneRows === "drill" && compact && !skeleton;
377
422
 
378
423
  const firstDataKey = useMemo(() => {
379
424
  const first = columns[0];
@@ -480,6 +525,15 @@ function TableInputInner<TData extends DataTableData>({
480
525
  }, []);
481
526
 
482
527
  const canAddRow = !maxRows || rows.length < maxRows;
528
+ const [boxWidth, setBoxWidth] = useState(0);
529
+ const scrollRef = useRef<HTMLElement | null>(null);
530
+ const [scrollEdges, setScrollEdges] = useState({ start: false, end: false });
531
+ const readScrollEdges = useCallback(() => {
532
+ const scroller = scrollRef.current;
533
+ if (!scroller) return;
534
+ const next = childScrollEdges(scroller);
535
+ setScrollEdges((prev) => (prev.start === next.start && prev.end === next.end ? prev : next));
536
+ }, []);
483
537
 
484
538
  const handleGridKeyDown = useCallback(
485
539
  (e: {
@@ -525,21 +579,42 @@ function TableInputInner<TData extends DataTableData>({
525
579
  const chrome = (id: string, header: string, size: number, cell: ColumnDef<TData>["cell"]) =>
526
580
  cols.push({ id, header, size, cell });
527
581
 
528
- if (reorderEnabled) chrome("_reorder", "", chromePx + 16, ReorderCell<TData>);
529
- if (showRowNumbers) chrome("_rowNumber", "#", Math.max(36, chromePx), RowNumberCell<TData>);
582
+ // A tuned phone row's glyph buttons keep their 44pt target inside the
583
+ // column, and the trailing one keeps the cell inset from the frame.
584
+ const glyphCol = tuned ? 44 : chromePx + 16;
585
+ if (reorderEnabled) chrome("_reorder", "", glyphCol, ReorderCell<TData>);
586
+ // responsive-parity: on a phone the drag handle in the row's leading cell shows its place.
587
+ if (showRowNumbers && !(reorderEnabled && media.sm === false)) {
588
+ chrome("_rowNumber", "#", Math.max(36, chromePx), RowNumberCell<TData>);
589
+ }
530
590
  for (const col of columns) {
531
591
  cols.push({ ...col, id: columnKey(col), cell: DataCell<TData> } as ColumnDef<TData, unknown>);
532
592
  }
533
- if (rowDetail) chrome("_detail", "", chromePx + 16, DetailCell<TData>);
534
- if (showDeleteRow && !readOnly) chrome("_actions", "", chromePx + 16, DeleteCell<TData>);
593
+ const trailingInset = tuned ? chromePx / 2 : 0;
594
+ const deletes = showDeleteRow && !readOnly;
595
+ if (rowDetail)
596
+ chrome("_detail", "", glyphCol + (deletes ? 0 : trailingInset), DetailCell<TData>);
597
+ if (deletes) chrome("_actions", "", glyphCol + trailingInset, DeleteCell<TData>);
535
598
 
536
599
  return cols;
537
- }, [columns, reorderEnabled, showRowNumbers, rowDetail, showDeleteRow, readOnly, chromePx]);
600
+ }, [
601
+ columns,
602
+ reorderEnabled,
603
+ showRowNumbers,
604
+ media.sm,
605
+ rowDetail,
606
+ showDeleteRow,
607
+ readOnly,
608
+ chromePx,
609
+ tuned,
610
+ ]);
538
611
 
539
612
  const meta: GridMeta<TData> = {
540
613
  readOnly,
541
614
  canDelete: !minRows || rows.length > minRows,
542
615
  deleteColor: theme.red10?.val ?? "currentColor",
616
+ mutedColor: theme.textMuted?.val ?? "currentColor",
617
+ tuned,
543
618
  knobProps,
544
619
  sortable,
545
620
  detailColumns,
@@ -560,6 +635,109 @@ function TableInputInner<TData extends DataTableData>({
560
635
  meta,
561
636
  });
562
637
 
638
+ // The fixed-layout table grows past 100% when its px widths add up to
639
+ // more, which clipped the delete column on a phone (FZ-7732). Chrome keeps
640
+ // its px and the data columns share what is left, a number or symbol
641
+ // column taking half a text column's share the way SimpleTable's fitter
642
+ // keeps numbers narrow while text flexes.
643
+ const dataJustify = new Map(columns.map((col) => [columnKey(col), childColumnJustify(col)]));
644
+ const shareOf = (id: string) => ((dataJustify.get(id) ?? "flex-start") === "flex-start" ? 2 : 1);
645
+ const chromePxTotal = table
646
+ .getAllLeafColumns()
647
+ .filter((column) => chromeColumnIds.has(column.id))
648
+ .reduce((sum, column) => sum + column.getSize(), 0);
649
+ const fit = fitChildColumns(
650
+ boxWidth,
651
+ chromePx,
652
+ chromePxTotal,
653
+ columns.map((col) => shareOf(columnKey(col))),
654
+ );
655
+ const fitWidth = new Map(columns.map((col, index) => [columnKey(col), fit.widths[index]]));
656
+ const scrolls = fit.scrolls;
657
+ const tableWidth =
658
+ chromePxTotal + fit.widths.reduce<number>((sum, width) => sum + (width ?? 0), 0);
659
+ // When the grid scrolls, edit and delete stay pinned at the trailing edge.
660
+ const pinnedIds = table
661
+ .getAllLeafColumns()
662
+ .filter((column) => column.id === "_detail" || column.id === "_actions");
663
+ // A header cell already paints its band; a body cell paints its row's fill
664
+ // so the data scrolling beneath stays hidden.
665
+ const pinnedProps = (id: string, row?: { index: number; active: boolean }) => {
666
+ const index = pinnedIds.findIndex((column) => column.id === id);
667
+ if (!scrolls || index < 0) return null;
668
+ const right = pinnedIds.slice(index + 1).reduce((sum, column) => sum + column.getSize(), 0);
669
+ const fill = !row
670
+ ? undefined
671
+ : row.active
672
+ ? "$color3"
673
+ : tableZebraStripe(knobProps.tableZebra, row.index) === "odd"
674
+ ? tableZebraFill(knobProps.surface.backgroundColor)
675
+ : knobProps.surface.backgroundColor;
676
+ return {
677
+ ...(fill ? { backgroundColor: fill } : null),
678
+ zIndex: 1,
679
+ style: { position: "sticky" as const, right },
680
+ };
681
+ };
682
+ // A fixed-layout table reads a calc() that mixes % and px as auto, so the
683
+ // widths come from the measured box.
684
+ const columnWidth = (id: string, size: number) =>
685
+ chromeColumnIds.has(id) ? size : fitWidth.get(id);
686
+
687
+ // The same edge fade OverflowRow draws marks the side with hidden columns.
688
+ // The trailing one sits just inside the pinned edit and delete columns.
689
+ const pinnedWidth = pinnedIds.reduce((sum, column) => sum + column.getSize(), 0);
690
+ const fadeWidth = Number(getTokenValue("$2" as Parameters<typeof getTokenValue>[0], "size")) || 0;
691
+ const fadeSurface =
692
+ theme[knobProps.surface.backgroundColor as string]?.val ??
693
+ String(knobProps.surface.backgroundColor);
694
+ const edgeFade = (side: "start" | "end") => (
695
+ <LinearGradient
696
+ testID={`child-scroll-${side}-fade`}
697
+ pointerEvents="none"
698
+ position="absolute"
699
+ top={0}
700
+ bottom={0}
701
+ zIndex={2}
702
+ width={fadeWidth}
703
+ {...(side === "start" ? { left: 0 } : { right: pinnedWidth })}
704
+ colors={side === "start" ? [fadeSurface, "transparent"] : ["transparent", fadeSurface]}
705
+ start={[0, 0]}
706
+ end={[1, 0]}
707
+ />
708
+ );
709
+ const wrapScroll = (grid: ReactNode) =>
710
+ scrolls ? (
711
+ <View position="relative">
712
+ <View
713
+ ref={scrollRef as never}
714
+ {...({
715
+ style: { overflowX: "auto" },
716
+ "data-child-scroll": "true",
717
+ onScroll: readScrollEdges,
718
+ } as Record<string, unknown>)}
719
+ >
720
+ {grid}
721
+ </View>
722
+ {scrollEdges.start ? edgeFade("start") : null}
723
+ {scrollEdges.end ? edgeFade("end") : null}
724
+ </View>
725
+ ) : (
726
+ grid
727
+ );
728
+
729
+ // A table cell ignores justifyContent, so its edge also goes on text-align.
730
+ const cellTextAlign = (id: string) => {
731
+ const justify = dataJustify.get(id);
732
+ if (!justify || justify === "flex-start") return undefined;
733
+ return { textAlign: justify === "flex-end" ? ("right" as const) : ("center" as const) };
734
+ };
735
+
736
+ useEffect(() => {
737
+ if (scrolls) readScrollEdges();
738
+ else setScrollEdges((prev) => (prev.start || prev.end ? { start: false, end: false } : prev));
739
+ }, [scrolls, boxWidth, readScrollEdges]);
740
+
563
741
  // Empty state flips to flex so a single auto-width cell fills the row
564
742
  // (colSpan is unreliable when displayMode is overridden).
565
743
  const isEmpty = !skeleton && rows.length === 0;
@@ -571,9 +749,14 @@ function TableInputInner<TData extends DataTableData>({
571
749
  <Skeleton variant="rounded" width={100} height={chromePx} />
572
750
  </XStack>
573
751
  ) : showAdd && !skeleton ? (
574
- <XStack {...hairline.top} {...cellPad}>
752
+ <XStack
753
+ {...hairline.top}
754
+ {...cellPad}
755
+ {...(tuned ? { borderColor: "$borderColor", paddingVertical: 0 } : null)}
756
+ >
575
757
  <IconButton
576
- icon={PlusIcon}
758
+ icon={tuned ? <PlusIcon weight="regular" /> : PlusIcon}
759
+ {...(tuned ? { edge: "start" as const } : null)}
577
760
  aria-label={t("Add Row")}
578
761
  onPress={handleAddRow}
579
762
  disabled={!canAddRow}
@@ -581,6 +764,28 @@ function TableInputInner<TData extends DataTableData>({
581
764
  </XStack>
582
765
  ) : null;
583
766
 
767
+ if (drill) {
768
+ return (
769
+ <ChildRowList<TData>
770
+ rows={rows}
771
+ columns={columns}
772
+ detailColumns={detailColumns}
773
+ readOnly={readOnly}
774
+ canAdd={canAddRow}
775
+ canDelete={meta.canDelete}
776
+ showAdd={showAddRow}
777
+ showDelete={showDeleteRow}
778
+ emptyMessage={emptyMessage}
779
+ ariaLabel={ariaLabel}
780
+ isCellHidden={isCellHidden}
781
+ t={t}
782
+ onAddRow={handleAddRow}
783
+ onDeleteRow={handleDeleteRow}
784
+ onCommitRow={handleRowDetailCommit}
785
+ />
786
+ );
787
+ }
788
+
584
789
  return (
585
790
  <SortableSessionProvider sourceId={sortable.session?.id ?? null}>
586
791
  <YStack
@@ -589,114 +794,143 @@ function TableInputInner<TData extends DataTableData>({
589
794
  {...knobProps.borderRadiusNested}
590
795
  elevation={knobProps.elevation}
591
796
  overflow="hidden"
797
+ onLayout={(event) => setBoxWidth(Math.floor(event.nativeEvent.layout.width))}
592
798
  {...(isWeb ? { onKeyDown: handleGridKeyDown as never } : null)}
593
799
  >
594
- <Table
595
- aria-label={ariaLabel}
596
- aria-busy={skeleton || undefined}
597
- borderWidth={0}
598
- borderRadius={0}
599
- elevation={undefined}
600
- {...(isEmpty ? { displayMode: "flex" as const } : null)}
601
- >
602
- <Table.Head>
603
- {table.getHeaderGroups().map((headerGroup) => (
604
- <Table.Row key={headerGroup.id}>
605
- {headerGroup.headers.map((header) => (
606
- <Table.HeaderCell
607
- key={header.id}
608
- style={{
609
- width: header.getSize(),
610
- ...(isEmpty && !chromeColumnIds.has(header.column.id)
611
- ? { flexGrow: 1 }
612
- : null),
613
- }}
614
- >
615
- {header.isPlaceholder
616
- ? null
617
- : flexRender(header.column.columnDef.header, header.getContext())}
618
- </Table.HeaderCell>
619
- ))}
620
- </Table.Row>
621
- ))}
622
- </Table.Head>
623
- <Table.Body>
624
- {skeleton ? (
625
- Array.from({ length: SKELETON_ROW_COUNT }, (_, rowIndex) => (
626
- <Table.Row key={`skeleton-${rowIndex}`}>
627
- {table.getAllLeafColumns().map((column) => (
628
- <Table.Cell key={column.id}>
629
- {column.id === "_actions" ||
630
- column.id === "_reorder" ||
631
- column.id === "_detail" ? null : (
632
- <Skeleton
633
- variant="rounded"
634
- width={column.id === "_rowNumber" ? 16 : "70%"}
635
- height={16}
636
- />
800
+ {wrapScroll(
801
+ <Table
802
+ aria-label={ariaLabel}
803
+ aria-busy={skeleton || undefined}
804
+ borderWidth={0}
805
+ borderRadius={0}
806
+ elevation={undefined}
807
+ {...(scrolls ? { style: { width: tableWidth, overflow: "visible" as const } } : null)}
808
+ {...(isEmpty ? { displayMode: "flex" as const } : null)}
809
+ >
810
+ <Table.Head>
811
+ {table.getHeaderGroups().map((headerGroup) => (
812
+ <Table.Row key={headerGroup.id}>
813
+ {headerGroup.headers.map((header) => (
814
+ <Table.HeaderCell
815
+ key={header.id}
816
+ {...(tuned
817
+ ? { backgroundColor: "transparent", paddingVertical: "$2" }
818
+ : null)}
819
+ {...(dataJustify.has(header.column.id)
820
+ ? { justifyContent: dataJustify.get(header.column.id) }
821
+ : null)}
822
+ {...pinnedProps(header.column.id)}
823
+ style={{
824
+ ...pinnedProps(header.column.id)?.style,
825
+ width: columnWidth(header.column.id, header.getSize()),
826
+ ...cellTextAlign(header.column.id),
827
+ ...(isEmpty && !chromeColumnIds.has(header.column.id)
828
+ ? { flexGrow: 1 }
829
+ : null),
830
+ }}
831
+ >
832
+ {header.isPlaceholder ? null : tuned &&
833
+ typeof header.column.columnDef.header === "string" ? (
834
+ <Text {...knobProps.textRole.label}>{header.column.columnDef.header}</Text>
835
+ ) : (
836
+ flexRender(header.column.columnDef.header, header.getContext())
637
837
  )}
638
- </Table.Cell>
838
+ </Table.HeaderCell>
639
839
  ))}
640
840
  </Table.Row>
641
- ))
642
- ) : isEmpty ? (
643
- <Table.Row>
644
- <Table.Cell cellWidth="auto" justifyContent="center">
645
- <Text color="$color10">{emptyMessage}</Text>
646
- </Table.Cell>
647
- </Table.Row>
648
- ) : (
649
- table.getRowModel().rows.map((row) => {
650
- const isActive = activeRowId === row.id;
651
- return (
652
- <Table.Row
653
- key={row.id}
654
- {...{ [childRowAttrs.row]: "true" }}
655
- {...{ [childRowAttrs.rowId]: row.id }}
656
- {...{ [childRowAttrs.rowIndex]: String(row.index) }}
657
- {...{ [childRowAttrs.active]: isActive ? "true" : undefined }}
658
- backgroundColor={isActive ? "$color3" : undefined}
659
- hoverStyle={{ backgroundColor: "$backgroundHover" }}
660
- {...transitionProps(knobProps.motion.control)}
661
- // onFocusCapture is a web-only capture-phase handler outside
662
- // ThemedRowProps; the bag forwards it to the DOM <tr> (house
663
- // Record cast). Tracks the active row as focus enters it.
664
- {...({ onFocusCapture: () => setActiveRowId(row.id) } as Record<
665
- string,
666
- unknown
667
- >)}
668
- >
669
- {row.getVisibleCells().map((cell) => {
670
- const isData = !chromeColumnIds.has(cell.column.id);
671
- const field = columns.find((col) => {
672
- const id =
673
- typeof col.accessorKey === "string"
674
- ? col.accessorKey
675
- : col.id || String(col.accessorKey);
676
- return id === cell.column.id;
677
- })?.field;
678
- return (
679
- <Table.Cell
680
- key={cell.id}
681
- {...(isData
682
- ? {
683
- [childRowAttrs.columnId]: cell.column.id,
684
- [childRowAttrs.field]: (field as string) || "input",
685
- [childRowAttrs.lastInput]:
686
- cell.column.id === lastDataColumnId ? "true" : undefined,
687
- }
688
- : null)}
689
- >
690
- {flexRender(cell.column.columnDef.cell, cell.getContext())}
691
- </Table.Cell>
692
- );
693
- })}
841
+ ))}
842
+ </Table.Head>
843
+ <Table.Body>
844
+ {skeleton ? (
845
+ Array.from({ length: SKELETON_ROW_COUNT }, (_, rowIndex) => (
846
+ <Table.Row key={`skeleton-${rowIndex}`}>
847
+ {table.getAllLeafColumns().map((column) => (
848
+ <Table.Cell key={column.id}>
849
+ {column.id === "_actions" ||
850
+ column.id === "_reorder" ||
851
+ column.id === "_detail" ? null : (
852
+ <Skeleton
853
+ variant="rounded"
854
+ width={column.id === "_rowNumber" ? 16 : "70%"}
855
+ height={16}
856
+ />
857
+ )}
858
+ </Table.Cell>
859
+ ))}
694
860
  </Table.Row>
695
- );
696
- })
697
- )}
698
- </Table.Body>
699
- </Table>
861
+ ))
862
+ ) : isEmpty ? (
863
+ <Table.Row>
864
+ <Table.Cell cellWidth="auto" justifyContent="center">
865
+ <Text color="$color10">{emptyMessage}</Text>
866
+ </Table.Cell>
867
+ </Table.Row>
868
+ ) : (
869
+ table.getRowModel().rows.map((row) => {
870
+ const isActive = activeRowId === row.id;
871
+ return (
872
+ <Table.Row
873
+ key={row.id}
874
+ {...{ [childRowAttrs.row]: "true" }}
875
+ {...{ [childRowAttrs.rowId]: row.id }}
876
+ {...{ [childRowAttrs.rowIndex]: String(row.index) }}
877
+ {...{ [childRowAttrs.active]: isActive ? "true" : undefined }}
878
+ backgroundColor={isActive ? "$color3" : undefined}
879
+ hoverStyle={{ backgroundColor: "$backgroundHover" }}
880
+ {...transitionProps(knobProps.motion.control)}
881
+ // onFocusCapture is a web-only capture-phase handler outside
882
+ // ThemedRowProps; the bag forwards it to the DOM <tr> (house
883
+ // Record cast). Tracks the active row as focus enters it.
884
+ {...({ onFocusCapture: () => setActiveRowId(row.id) } as Record<
885
+ string,
886
+ unknown
887
+ >)}
888
+ >
889
+ {row.getVisibleCells().map((cell) => {
890
+ const isData = !chromeColumnIds.has(cell.column.id);
891
+ const field = columns.find((col) => {
892
+ const id =
893
+ typeof col.accessorKey === "string"
894
+ ? col.accessorKey
895
+ : col.id || String(col.accessorKey);
896
+ return id === cell.column.id;
897
+ })?.field;
898
+ return (
899
+ <Table.Cell
900
+ key={cell.id}
901
+ {...(tuned
902
+ ? {
903
+ paddingVertical: 0,
904
+ ...(isData
905
+ ? null
906
+ : { paddingHorizontal: 0, alignItems: "flex-start" as const }),
907
+ }
908
+ : null)}
909
+ {...pinnedProps(cell.column.id, { index: row.index, active: isActive })}
910
+ style={{
911
+ ...pinnedProps(cell.column.id)?.style,
912
+ ...cellTextAlign(cell.column.id),
913
+ }}
914
+ {...(isData
915
+ ? {
916
+ [childRowAttrs.columnId]: cell.column.id,
917
+ [childRowAttrs.field]: (field as string) || "input",
918
+ [childRowAttrs.lastInput]:
919
+ cell.column.id === lastDataColumnId ? "true" : undefined,
920
+ }
921
+ : null)}
922
+ >
923
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
924
+ </Table.Cell>
925
+ );
926
+ })}
927
+ </Table.Row>
928
+ );
929
+ })
930
+ )}
931
+ </Table.Body>
932
+ </Table>,
933
+ )}
700
934
  {addRowControl}
701
935
  {reorderEnabled ? (
702
936
  <View