@human-kit/ui 1.2.1 → 1.3.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.
@@ -95,7 +95,7 @@ and `TableCheckboxIndicatorProps`.
95
95
 
96
96
  - Use `Table.Root` as the stateful container for focus, selection, and sorting state.
97
97
  - Use `keyboardNavigation` to choose how far the roving tab stop reaches into the body: `'grid'` (default) makes every body cell a focus target, `'row'` makes the row the only one, and `'none'` leaves the body inert. The cell navigation has a cost: one focus registration and one focus state for each cell. A virtualized table does this again for each row that it makes. Use `'row'` when the body is a list, and not a surface where the user works. Use `'none'` only when nothing in the body does an action. The header keeps its own navigation in every mode.
98
- - Use `selectionBehavior="toggle"` to let the user remove the selection of a selected row. Use `selectionBehavior="replace"` to keep a selected row selected when the user presses it again. Use `selectionBehavior="checkbox"` when a press on the row should only perform its action: then only the selection checkbox, `Space` or the select-all shortcut change the selection.
98
+ - Use `selectionBehavior="toggle"` to let the user remove the selection of a selected row. Use `selectionBehavior="replace"` to keep a selected row selected when the user presses it again. Use `selectionBehavior="checkbox"` when a press on the row must only do its action. Then only the selection checkbox, `Space` or the select-all shortcut change the selection.
99
99
  - `Table.Column` is a logical-only wrapper for column metadata; it does not render DOM by itself and should wrap a single `Table.ColumnHeaderCell`.
100
100
  - Wrap each header cell in `Table.Column` so the table can register stable column metadata.
101
101
  - Add `Table.ColumnResizer` inside `Table.ColumnHeaderCell` to make the owning `Table.Column` resizable.
@@ -182,6 +182,7 @@ Put the groups and their rows in one `items` array. In the `children` snippet of
182
182
  - A click, `Enter` or `Space` calls `onAction` of the section row. The table does not call `onRowAction` for a section row.
183
183
  - A mounted section row tells the table that it is a section row. With a virtualizer, also set `isSectionItem` on `Table.Body`, because the table does not know the section rows that are not mounted.
184
184
  - With a virtualizer, set `sectionRowHeight` when a section row has a different height from `rowHeight`. This also needs `isSectionItem`. Give the rows the same heights in CSS.
185
+ - When the section rows are not all the same height, pass `sectionRowHeight` as a function of the item. The table calls it only for the items that `isSectionItem` accepts.
185
186
  - The cell is not sticky. In a table with pinned columns, add `sticky left-0` (or a similar class) to the content of the section row to keep it in view.
186
187
 
187
188
  ## Composition contract
@@ -98,10 +98,13 @@
98
98
  if (!virtualizer || !virtualizerEnabled || !isSectionItem) return undefined;
99
99
  const { rowHeight, sectionRowHeight } = virtualizer;
100
100
  if (sectionRowHeight === undefined || sectionRowHeight === rowHeight) return undefined;
101
+ const sectionHeight =
102
+ typeof sectionRowHeight === 'function' ? sectionRowHeight : () => sectionRowHeight;
101
103
 
102
104
  const offsets = new Float64Array(itemList.length + 1);
103
105
  for (let index = 0; index < itemList.length; index += 1) {
104
- const height = isSectionItem(itemList[index]) ? sectionRowHeight : rowHeight;
106
+ const item = itemList[index];
107
+ const height = isSectionItem(item) ? sectionHeight(item) : rowHeight;
105
108
  offsets[index + 1] = offsets[index] + height;
106
109
  }
107
110
  return offsets;
@@ -57,13 +57,17 @@ export type TableHeaderProps = Omit<HTMLAttributes<HTMLTableSectionElement>, 'ch
57
57
  children?: Snippet;
58
58
  class?: string;
59
59
  };
60
- export type TableBodyVirtualizer = {
60
+ export type TableBodyVirtualizer<T extends TableRowItem = TableRowItem> = {
61
61
  rowHeight: number;
62
62
  /**
63
63
  * Height, in px, of a section row, when it differs from `rowHeight`. It needs `isSectionItem` on
64
64
  * `Table.Body` to know which items are section rows. Without it, each item is `rowHeight` high.
65
+ *
66
+ * A function sizes each section row on its own, for a body whose section rows are not all
67
+ * alike — a group's header beside the header of an open row's children, say. It is only
68
+ * called for the items `isSectionItem` accepts.
65
69
  */
66
- sectionRowHeight?: number;
70
+ sectionRowHeight?: number | ((item: T) => number);
67
71
  /**
68
72
  * Extra rows rendered above and below the viewport, defaulting to 18. It
69
73
  * buffers against row render cost: while the main thread builds rows, the
@@ -84,7 +88,7 @@ export type TableBodyManualProps = TableBodyBaseProps & {
84
88
  };
85
89
  export type TableBodyItemsProps<T extends TableRowItem = TableRowItem> = TableBodyBaseProps & {
86
90
  items: readonly T[];
87
- virtualizer?: TableBodyVirtualizer;
91
+ virtualizer?: TableBodyVirtualizer<T>;
88
92
  /**
89
93
  * Tells which items render a `Table.SectionRow`. A section row that is mounted declares itself,
90
94
  * so this is optional without a virtualizer. With one, pass it: it keeps the section rows that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@human-kit/ui",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Accessible, typed UI components for Svelte 5 — shipped as native ESM with per-component subpath exports so bundlers only include what you import.",
5
5
  "license": "MIT",
6
6
  "author": "Agustin Delgado <agustindariodelgado@gmail.com>",