@patterninc/pattern-ui 0.0.0-main.202610080449.ea0e8cb183ed → 0.0.0-main.202610080515.7e6f1e06a552

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 (43) hide show
  1. package/dist/components/DataGrid/DataGrid.js +76 -19
  2. package/dist/components/DataGrid/DataGridCell.js +3 -3
  3. package/dist/components/DataGrid/DataGridCellValue.js +435 -234
  4. package/dist/components/DataGrid/DataGridDatePickerCell.js +3 -3
  5. package/dist/components/DataGrid/DataGridPickerCell.js +3 -3
  6. package/dist/components/DataGrid/DataGridRow.js +1 -1
  7. package/dist/components/DataGrid/DataGridRowHeader.js +233 -91
  8. package/dist/components/DataGrid/dataGridTypes.js +12 -0
  9. package/dist/components/DataGrid/hooks/useDataGridLayout.js +38 -7
  10. package/dist/components/DataGrid/hooks/useDataGridTree.js +8 -6
  11. package/dist/components/DataGrid/hooks/useRowResize.js +132 -0
  12. package/dist/components/DataGrid/hooks/useStickyColumns.js +4 -4
  13. package/dist/locales/en/messages.js +1 -1
  14. package/dist/locales/es/messages.js +1 -1
  15. package/dist/locales/fr/messages.js +1 -1
  16. package/dist/locales/pl/messages.js +1 -1
  17. package/dist/locales/pseudo-LOCALE/messages.js +1 -1
  18. package/dist/locales/zh/messages.js +1 -1
  19. package/package.json +1 -1
  20. package/src/components/DataGrid/DataGrid.tsx +139 -44
  21. package/src/components/DataGrid/DataGridCell.tsx +9 -4
  22. package/src/components/DataGrid/DataGridCellValue.tsx +168 -17
  23. package/src/components/DataGrid/DataGridDatePickerCell.tsx +5 -2
  24. package/src/components/DataGrid/DataGridPickerCell.tsx +5 -2
  25. package/src/components/DataGrid/DataGridRow.tsx +1 -1
  26. package/src/components/DataGrid/DataGridRowHeader.tsx +121 -4
  27. package/src/components/DataGrid/dataGridTypes.ts +16 -1
  28. package/src/components/DataGrid/hooks/useDataGridLayout.ts +49 -10
  29. package/src/components/DataGrid/hooks/useDataGridTree.ts +8 -4
  30. package/src/components/DataGrid/hooks/useRowResize.ts +177 -0
  31. package/src/components/DataGrid/hooks/useStickyColumns.ts +7 -4
  32. package/src/locales/en/messages.po +6 -0
  33. package/src/locales/en/messages.ts +1 -1
  34. package/src/locales/es/messages.po +6 -0
  35. package/src/locales/es/messages.ts +1 -1
  36. package/src/locales/fr/messages.po +6 -0
  37. package/src/locales/fr/messages.ts +1 -1
  38. package/src/locales/pl/messages.po +6 -0
  39. package/src/locales/pl/messages.ts +1 -1
  40. package/src/locales/pseudo-LOCALE/messages.po +6 -0
  41. package/src/locales/pseudo-LOCALE/messages.ts +1 -1
  42. package/src/locales/zh/messages.po +6 -0
  43. package/src/locales/zh/messages.ts +1 -1
@@ -20,11 +20,13 @@ import { DataGridPickerCell } from "./DataGridPickerCell.js";
20
20
  import { DataGridRow } from "./DataGridRow.js";
21
21
  import { DataGridRowHeader } from "./DataGridRowHeader.js";
22
22
  import { DataGridHeader, partitionDataGridChildren } from "./dataGridSlots.js";
23
+ import { DATA_GRID_ROW_HEIGHT_PX } from "./dataGridTypes.js";
23
24
  import { useCellRangeSelection } from "./hooks/useCellRangeSelection.js";
24
25
  import { useColumnResize } from "./hooks/useColumnResize.js";
25
26
  import { useDataGridFind } from "./hooks/useDataGridFind.js";
26
27
  import { useDataGridLayout } from "./hooks/useDataGridLayout.js";
27
28
  import { useDataGridSelection } from "./hooks/useDataGridSelection.js";
29
+ import { hugRowHeight, useRowResize } from "./hooks/useRowResize.js";
28
30
  import { useStickyColumns } from "./hooks/useStickyColumns.js";
29
31
  import { DataGridGroupHeader } from "./DataGridGroupHeader.js";
30
32
  import { DataGridTreeCell } from "./DataGridTreeCell.js";
@@ -43,6 +45,7 @@ import { cn } from "cn";
43
45
 
44
46
  //#region src/components/DataGrid/DataGrid.tsx
45
47
  const GUTTER_WIDTH = "48px";
48
+ const ROW_RESIZE_KEYBOARD_STEP_PX = 10;
46
49
  const DEFAULT_RESIZE_WIDTH = 150;
47
50
  const MIN_RESIZE_WIDTH = 64;
48
51
  const SKELETON_ROW_COUNT = 20;
@@ -113,19 +116,19 @@ function cellValueProps(type, value, options) {
113
116
  valueState: value == null || value === "" ? "empty" : "filled"
114
117
  };
115
118
  }
116
- function getGridTemplate(columns, selectable, widthFor) {
119
+ function getGridTemplate(columns, hasGutter, widthFor) {
117
120
  const tracks = columns.map((col) => {
118
121
  if (col.resizable || col.pinned) return `${widthFor(col)}px`;
119
122
  if (col.width == null) return "minmax(0, 1fr)";
120
123
  return typeof col.width === "number" ? `${col.width}px` : col.width;
121
124
  });
122
- return [selectable ? GUTTER_WIDTH : null, ...tracks].filter(Boolean).join(" ");
125
+ return [hasGutter ? GUTTER_WIDTH : null, ...tracks].filter(Boolean).join(" ");
123
126
  }
124
- function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse", layout: layoutProp, defaultLayout, onLayoutChange, selectable = false, selectedIds: selectedIdsProp, defaultSelectedIds, onSelectedIdsChange, cellSelectable = false, selectedRange, onSelectedRangeChange, sortedColumn, sortDirection, onSortChange, onCellEdit, onColumnResize, children, rowNumberStart = 1, findMatcher, isLoading = false, emptyState, getRowProps, renderBeforeRow, renderAfterRow, className, qaTestId = "data-grid", ...props }) {
127
+ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse", layout: layoutProp, defaultLayout, onLayoutChange, selectable = false, rowResize = false, selectedIds: selectedIdsProp, defaultSelectedIds, onSelectedIdsChange, cellSelectable = false, selectedRange, onSelectedRangeChange, sortedColumn, sortDirection, onSortChange, onCellEdit, onColumnResize, children, rowNumberStart = 1, findMatcher, isLoading = false, emptyState, getRowProps, renderBeforeRow, renderAfterRow, className, qaTestId = "data-grid", ...props }) {
125
128
  const { _: _t } = useLingui();
126
129
  const gridRef = React$1.useRef(null);
127
130
  const [editingCell, setEditingCell] = React$1.useState(null);
128
- const { columns: effectiveColumns, layout, setColumnPinned, setColumnHidden, setDensity } = useDataGridLayout({
131
+ const { columns: effectiveColumns, layout, setColumnPinned, setColumnHidden, setDensity, setRowHeight } = useDataGridLayout({
129
132
  columns,
130
133
  layout: layoutProp,
131
134
  defaultLayout,
@@ -156,15 +159,23 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
156
159
  minWidth: MIN_RESIZE_WIDTH,
157
160
  onColumnResize
158
161
  });
162
+ const minRowHeight = DATA_GRID_ROW_HEIGHT_PX[densityState];
163
+ const { heightFor: heightForRow, isResizing: isRowResizing, startResize: startRowResize, cancelResize: cancelRowResize } = useRowResize({
164
+ minHeight: minRowHeight,
165
+ heights: layout.rowHeights,
166
+ onRowResize: setRowHeight
167
+ });
168
+ const hasGutter = selectable || rowResize;
159
169
  const { orderedColumns, hasPinned, stickyGutter, getPinProps, surfaceBacking, scrollRef, onScroll } = useStickyColumns({
160
170
  columns: effectiveColumns,
161
171
  widthFor,
162
172
  selectable,
173
+ hasGutter,
163
174
  variant,
164
175
  gutterWidth: Number.parseInt(GUTTER_WIDTH, 10),
165
176
  rowCount: isLoading ? SKELETON_ROW_COUNT : data.length
166
177
  });
167
- const rowHeight = densityState === "medium" ? 56 : 40;
178
+ const rowHeight = minRowHeight;
168
179
  const find = useDataGridFind({
169
180
  rows: data,
170
181
  columnKeys: effectiveColumns.map((col) => col.key),
@@ -183,9 +194,16 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
183
194
  }, [find.open]);
184
195
  const hasFlexColumn = orderedColumns.some((col) => col.width == null && !col.resizable && col.pinned == null);
185
196
  const rowWidthClass = hasFlexColumn ? void 0 : "w-max min-w-full";
186
- const template = getGridTemplate(orderedColumns, selectable, widthFor);
197
+ const template = getGridTemplate(orderedColumns, hasGutter, widthFor);
187
198
  const isEmpty = !isLoading && data.length === 0;
188
199
  const rowgroupRef = React$1.useRef(null);
200
+ const fitRow = (index, rowId) => {
201
+ cancelRowResize();
202
+ const rowEl = rowgroupRef.current?.querySelector(`[data-row-index="${index}"]`);
203
+ if (rowEl == null) return;
204
+ const fit = hugRowHeight(rowEl, minRowHeight);
205
+ setRowHeight(rowId, Math.abs(heightForRow(rowId) - fit) <= 1 ? minRowHeight : fit);
206
+ };
189
207
  const [rowRects, setRowRects] = React$1.useState([]);
190
208
  const measureRows = () => {
191
209
  const rowgroup = rowgroupRef.current;
@@ -223,7 +241,7 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
223
241
  onRangeChange: onSelectedRangeChange
224
242
  });
225
243
  const rangeRect = cellRange.rect;
226
- const gutterOffset = selectable ? 1 : 0;
244
+ const gutterOffset = hasGutter ? 1 : 0;
227
245
  const isColumnReported = (index) => rangeRect != null && index >= rangeRect.colStart && index <= rangeRect.colEnd;
228
246
  const isRowReported = (index) => rangeRect != null && index >= rangeRect.rowStart && index <= rangeRect.rowEnd;
229
247
  const rowPropsList = data.map((row, index) => getRowProps?.(row, index));
@@ -269,6 +287,27 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
269
287
  const originRow = Number(cell.closest("[data-row-index]")?.dataset.rowIndex ?? -1);
270
288
  const originCol = orderedColumns.findIndex((entry) => entry.key === cell.dataset.colKey);
271
289
  if (originRow < 0 || originCol < 0) return;
290
+ if (rowResize && event.altKey) {
291
+ const targetRow = data[originRow];
292
+ if (targetRow) {
293
+ const id = String(targetRow.id);
294
+ if (event.key === "ArrowDown") {
295
+ event.preventDefault();
296
+ setRowHeight(id, heightForRow(id) + ROW_RESIZE_KEYBOARD_STEP_PX);
297
+ return;
298
+ }
299
+ if (event.key === "ArrowUp") {
300
+ event.preventDefault();
301
+ setRowHeight(id, Math.max(minRowHeight, heightForRow(id) - ROW_RESIZE_KEYBOARD_STEP_PX));
302
+ return;
303
+ }
304
+ if (event.key === "Home") {
305
+ event.preventDefault();
306
+ setRowHeight(id, minRowHeight);
307
+ return;
308
+ }
309
+ }
310
+ }
272
311
  const lastRow = data.length - 1;
273
312
  const lastCol = orderedColumns.length - 1;
274
313
  let { row, col } = {
@@ -416,11 +455,11 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
416
455
  "aria-rowindex": 1,
417
456
  className: cn("sticky top-0 z-40 grid", variant === "weak" ? "bg-base-weak" : "bg-base-inverse", rowWidthClass),
418
457
  style: { gridTemplateColumns: template },
419
- children: [selectable && /* @__PURE__ */ jsx("div", {
458
+ children: [hasGutter && /* @__PURE__ */ jsx("div", {
420
459
  role: "columnheader",
421
460
  "aria-colindex": 1,
422
- className: cn("flex h-10 items-center justify-center border-r border-b border-depth-black-4", "hover:[@media(hover:hover)]:bg-depth-black-4", stickyGutter && cn("sticky left-0 z-20", surfaceBacking)),
423
- children: /* @__PURE__ */ jsx(Checkbox, {
461
+ className: cn("flex h-10 items-center justify-center border-r border-b border-depth-black-4", selectable && "hover:[@media(hover:hover)]:bg-depth-black-4", stickyGutter && cn("sticky left-0 z-20", surfaceBacking)),
462
+ children: selectable && /* @__PURE__ */ jsx(Checkbox, {
424
463
  checked: allPageSelected,
425
464
  partialChecked: somePageSelected,
426
465
  "aria-label": _t(
@@ -476,9 +515,12 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
476
515
  state: "loading",
477
516
  "aria-hidden": true,
478
517
  "data-slot": "data-grid-skeleton-row",
479
- className: cn("relative z-10", rowWidthClass),
480
- style: { gridTemplateColumns: template },
481
- gutter: selectable ? /* @__PURE__ */ jsx(DataGridRowHeader, {
518
+ className: cn("relative", rowWidthClass),
519
+ style: {
520
+ gridTemplateColumns: template,
521
+ height: minRowHeight
522
+ },
523
+ gutter: hasGutter ? /* @__PURE__ */ jsx(DataGridRowHeader, {
482
524
  density: densityState,
483
525
  state: "default",
484
526
  rowNumber: index + 1,
@@ -516,26 +558,41 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
516
558
  const pinRowSurface = rowPinBackingClass(rowProps?.className);
517
559
  const before = renderBeforeRow?.(row, index);
518
560
  const after = renderAfterRow?.(row, index);
561
+ const prev = index > 0 ? data[index - 1] : void 0;
562
+ const prevId = prev != null ? String(prev.id) : void 0;
563
+ const rowPx = heightForRow(String(row.id));
519
564
  const rowElement = /* @__PURE__ */ jsx(DataGridRow, {
520
565
  "data-row-index": index,
521
566
  "aria-rowindex": rowNumberStart + index + 1,
522
567
  state: "default",
523
568
  "aria-selected": isSelected || void 0,
524
- className: cn("relative z-10", editingCell?.rowId === String(row.id) && "z-50", rowWidthClass, rowProps?.className),
569
+ className: cn("relative", editingCell?.rowId === String(row.id) && "z-50", rowWidthClass, rowProps?.className),
525
570
  style: {
526
571
  gridTemplateColumns: template,
527
- ...rowProps?.style
572
+ height: rowPx,
573
+ ...rowProps?.style,
574
+ ...typeof rowProps?.style?.maxHeight === "number" && rowProps.style.maxHeight > 0 ? { maxHeight: Math.max(rowProps.style.maxHeight, rowPx) } : {}
528
575
  },
529
- gutter: selectable ? /* @__PURE__ */ jsx(DataGridRowHeader, {
576
+ "data-expanded": rowPx > minRowHeight ? "" : void 0,
577
+ gutter: hasGutter ? /* @__PURE__ */ jsx(DataGridRowHeader, {
530
578
  role: "gridcell",
531
579
  "aria-colindex": 1,
532
580
  density: densityState,
533
581
  state: "default",
534
582
  rowNumber: rowNumberStart + index,
535
- hoverReveal: rowHasCheckbox && !rowProps?.checkboxDisabled,
583
+ hoverReveal: selectable && rowHasCheckbox && !rowProps?.checkboxDisabled,
536
584
  checked: isSelected,
537
585
  disabled: rowProps?.checkboxDisabled,
538
- onCheckedChange: rowCanToggle ? (checked) => toggleRow(row.id, checked) : void 0,
586
+ onCheckedChange: selectable && rowCanToggle ? (checked) => toggleRow(row.id, checked) : void 0,
587
+ onResizeStart: rowResize ? startRowResize(String(row.id), rowPx) : void 0,
588
+ onResizeFit: rowResize ? () => fitRow(index, String(row.id)) : void 0,
589
+ isResizing: rowResize ? isRowResizing(String(row.id)) : void 0,
590
+ resizeValue: rowResize ? rowPx : void 0,
591
+ resizeMin: rowResize ? minRowHeight : void 0,
592
+ above: rowResize && prevId != null ? {
593
+ onResizeStart: startRowResize(prevId, heightForRow(prevId)),
594
+ onResizeFit: () => fitRow(index - 1, prevId)
595
+ } : void 0,
539
596
  className: cn(isRowReported(index) && !isSelected && "bg-base-weak", stickyGutter && cn("sticky left-0 z-20", surfaceBacking, pinRowSurface))
540
597
  }) : void 0,
541
598
  children: orderedColumns.map((col, colIndex) => {
@@ -667,4 +724,4 @@ function DataGrid({ columns, data, rowCount: rowCountProp, variant = "inverse",
667
724
  }
668
725
 
669
726
  //#endregion
670
- export { DATA_GRID_TREE_MOTION_MS, DataGrid, DataGridCell, DataGridCellEditor, DataGridCellValue, DataGridColumnHeader, DataGridDatePickerCell, DataGridFind, DataGridGroupHeader, DataGridHeader, DataGridPickerCell, DataGridRow, DataGridRowHeader, DataGridSearchBar, DataGridSelectionBar, DataGridStatusBar, DataGridToolbar, DataGridTreeCell, dataGridTreeRowMotion, useCellRangeSelection, useColumnResize, useDataGridContext, useDataGridFind, useDataGridLayout, useDataGridPagination, useDataGridSelection, useDataGridSort, useDataGridTree, useOptionalDataGridContext, useStickyColumns };
727
+ export { DATA_GRID_ROW_HEIGHT_PX, DATA_GRID_TREE_MOTION_MS, DataGrid, DataGridCell, DataGridCellEditor, DataGridCellValue, DataGridColumnHeader, DataGridDatePickerCell, DataGridFind, DataGridGroupHeader, DataGridHeader, DataGridPickerCell, DataGridRow, DataGridRowHeader, DataGridSearchBar, DataGridSelectionBar, DataGridStatusBar, DataGridToolbar, DataGridTreeCell, dataGridTreeRowMotion, hugRowHeight, useCellRangeSelection, useColumnResize, useDataGridContext, useDataGridFind, useDataGridLayout, useDataGridPagination, useDataGridSelection, useDataGridSort, useDataGridTree, useOptionalDataGridContext, useRowResize, useStickyColumns };
@@ -5,11 +5,11 @@ import { cn } from "cn";
5
5
  import { cva } from "class-variance-authority";
6
6
 
7
7
  //#region src/components/DataGrid/DataGridCell.tsx
8
- const cellVariants = cva(cn("pui-text-label-medium-loose flex min-w-0 items-center bg-clip-padding", "focus-visible:relative focus-visible:z-20 focus-visible:outline-none focus-visible:shadow-outline-secondary"), {
8
+ const cellVariants = cva(cn("pui-text-label-medium-loose flex min-h-0 min-w-0 items-center overflow-hidden bg-clip-padding", "focus-visible:relative focus-visible:z-20 focus-visible:outline-none focus-visible:shadow-outline-secondary"), {
9
9
  variants: {
10
10
  density: {
11
- small: "h-10",
12
- medium: "h-14"
11
+ small: "h-full min-h-10",
12
+ medium: "h-full min-h-14"
13
13
  },
14
14
  padded: {
15
15
  true: "px-3",