Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive column sizing #1321

Merged
merged 57 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a0866af
Working changes.
atmgrifter00 Apr 12, 2023
ba081ee
Minor fixes.
atmgrifter00 Apr 12, 2023
bd11f9f
Refactor to manager class.
atmgrifter00 Apr 13, 2023
d058ad0
Merge branch 'main' into table-interactive-column-sizing
atmgrifter00 Apr 13, 2023
6284818
Removed unused method.
atmgrifter00 Apr 13, 2023
7fa5820
Not working well
atmgrifter00 Apr 14, 2023
0a97fa5
Mostly works.
atmgrifter00 Jun 2, 2023
1a45a8d
Merge from main
atmgrifter00 Jun 2, 2023
81c0cc4
Add double-click reset
atmgrifter00 Jun 2, 2023
c8e0367
Improve behavior.
atmgrifter00 Jun 2, 2023
9060860
Improved, but imperfect behavior.
atmgrifter00 Jun 20, 2023
f169b9e
Add columnResizeMode. Fix behaviors.
atmgrifter00 Jun 21, 2023
7a19622
Merge branch 'main' into table-column-sizing-cascade-and-grow
atmgrifter00 Jun 22, 2023
3b138a6
Remove whitespace in README.
atmgrifter00 Jun 22, 2023
4fae2b8
Merge branch 'main' into table-column-sizing-cascade-and-grow
atmgrifter00 Jun 22, 2023
298b323
Ready for draft.
atmgrifter00 Jun 23, 2023
e0739f1
Remove reduce implementations.
atmgrifter00 Jun 23, 2023
523f7a1
Method was incorrectly public.
atmgrifter00 Jun 23, 2023
aebf8f5
Whoops.
atmgrifter00 Jun 23, 2023
d910b36
Clean up.
atmgrifter00 Jun 23, 2023
1e1b382
Remove width factor et. al.
atmgrifter00 Jun 27, 2023
ebf5e5c
PR feedback et. at.
atmgrifter00 Jun 27, 2023
f25bd9e
Revert "PR feedback et. at."
atmgrifter00 Jun 27, 2023
6af868f
Revert "Revert "PR feedback et. at.""
atmgrifter00 Jun 27, 2023
d041c20
Fix style.
atmgrifter00 Jun 27, 2023
11f1887
Another style fix.
atmgrifter00 Jun 27, 2023
d535d30
Increase divider hit test area.
atmgrifter00 Jun 27, 2023
ee4516a
Fixes and adding tests.
atmgrifter00 Jun 28, 2023
748e757
Remove TableColumnResizeMode.
atmgrifter00 Jun 29, 2023
c4fc72d
Align cascade implementations.
atmgrifter00 Jun 29, 2023
baa565c
Adding tests.
atmgrifter00 Jun 29, 2023
e15f9fb
Formatting.
atmgrifter00 Jun 29, 2023
23727f0
Fix test intermittency.
atmgrifter00 Jun 30, 2023
80e08ff
Remove unused code.
atmgrifter00 Jun 30, 2023
80b25ab
Change files
atmgrifter00 Jun 30, 2023
618c1dd
Handle PR feedback.
atmgrifter00 Jun 30, 2023
61a5b12
Remove fedescribe
atmgrifter00 Jun 30, 2023
6caa932
Handle PR feedback.
atmgrifter00 Jun 30, 2023
72d4b54
Minor clean up.
atmgrifter00 Jul 10, 2023
c8096cf
Removing errant Math.floor.
atmgrifter00 Jul 13, 2023
ccf1672
Linting
atmgrifter00 Jul 13, 2023
4e5b905
Limit column sizing to using left mouse button.
atmgrifter00 Jul 13, 2023
de99e8f
Doc update.
atmgrifter00 Jul 13, 2023
dd4d643
Linting.
atmgrifter00 Jul 13, 2023
403d3fe
Handling PR feedback.
atmgrifter00 Jul 17, 2023
256da5d
Handling PR feedback.
atmgrifter00 Jul 18, 2023
f81266b
Style fix.
atmgrifter00 Jul 18, 2023
795d720
Merge branch 'main' into table-column-sizing-cascade-and-grow
atmgrifter00 Jul 18, 2023
d81f3db
Linting.
atmgrifter00 Jul 18, 2023
0b4e3c9
Merge branch 'main' into table-column-sizing-cascade-and-grow
atmgrifter00 Jul 18, 2023
e4e5b65
Merge branch 'main' into table-column-sizing-cascade-and-grow
atmgrifter00 Jul 18, 2023
4b979c1
Handling PR feedback.
atmgrifter00 Jul 18, 2023
a846600
Merge branch 'table-column-sizing-cascade-and-grow' of https://github…
atmgrifter00 Jul 18, 2023
223b70a
Merge branch 'main' into table-column-sizing-cascade-and-grow
jattasNI Jul 18, 2023
4ccc518
Handling PR feedback.
atmgrifter00 Jul 19, 2023
8a8a882
Merge branch 'table-column-sizing-cascade-and-grow' of https://github…
atmgrifter00 Jul 19, 2023
55a799b
Prettier.
atmgrifter00 Jul 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
atmgrifter00 marked this conversation as resolved.
Show resolved Hide resolved
atmgrifter00 marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
atmgrifter00 marked this conversation as resolved.
Show resolved Hide resolved
atmgrifter00 marked this conversation as resolved.
Show resolved Hide resolved
"comment": "Adding interactive column sizing",
"packageName": "@ni/nimble-components",
"email": "26874831+atmgrifter00@users.noreply.github.com",
"dependentChangeType": "patch"
}
atmgrifter00 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,11 @@ const fractionalWidthOptions = {
} as const;

const fractionalWidthDescription = `Configure each column's width relative to the other columns with the \`fractional-width\` property. For example, a column with a \`fractional-width\` set to 2 will be twice as wide as a column with a \`fractional-width\` set to 1.
The default value for \`fractional-width\` is 1, and columns that don't support \`fractional-width\` explicitly, or another API responsible for managing the width of the column, will also behave as if they have a \`fractional-width\` of 1.`;
The default value for \`fractional-width\` is 1, and columns that don't support \`fractional-width\` explicitly, or another API responsible for managing the width of the column, will also behave as if they have a \`fractional-width\` of 1. This value only serves
as an initial state for a column. Once a column has been manually resized the column will use a fractional width calculated by the table from the resize.`;

const minPixelWidthDescription = `Table columns that support having a \`fractional-width\` can also be configured to have a minimum width such that its width
will never shrink below the specified pixel width.`;
will never shrink below the specified pixel width. This applies to both when a table is resized as well as when a column is interactively resized.`;

export const fractionalWidthColumn: StoryObj<ColumnWidthTableArgs> = {
parameters: {
Expand Down
74 changes: 66 additions & 8 deletions packages/nimble-components/src/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import {
} from './types';
import { Virtualizer } from './models/virtualizer';
import { getTanStackSortingFunction } from './models/sort-operations';
import { TableLayoutManager } from './models/table-layout-manager';
import { TableUpdateTracker } from './models/table-update-tracker';
import { TableLayoutHelper } from './models/table-layout-helper';
import type { TableRow } from './components/row';
import { ColumnInternals } from '../table-column/base/models/column-internals';
import { InteractiveSelectionManager } from './models/interactive-selection-manager';
Expand Down Expand Up @@ -153,16 +153,31 @@ export class Table<
@observable
public showCollapseAll = false;

/**
* @internal
*/
public readonly headerRowActionContainer!: HTMLElement;

/**
* @internal
*/
public readonly rowContainer!: HTMLElement;

/**
* @internal
*/
public readonly columnHeadersContainer!: Element;

/**
* @internal
*/
public readonly virtualizer: Virtualizer<TData>;

/**
* @internal
*/
public readonly layoutManager: TableLayoutManager<TData>;

/**
* @internal
*/
Expand All @@ -173,6 +188,16 @@ export class Table<
* @internal
*/
@observable
public visibleColumns: TableColumn[] = [];

/**
* @internal
* This value determines the size of the viewport area when a user has created horizontal scrollable
* space through a column resize operation.
*/
@observable
public tableScrollableMinWidth = 0;

public documentShiftKeyDown = false;

private readonly table: TanStackTable<TData>;
Expand Down Expand Up @@ -217,6 +242,7 @@ export class Table<
};
this.table = tanStackCreateTable(this.options);
this.virtualizer = new Virtualizer(this, this.table);
this.layoutManager = new TableLayoutManager(this);
this.selectionManager = new InteractiveSelectionManager(
this.table,
this.selectionMode
Expand Down Expand Up @@ -394,6 +420,32 @@ export class Table<
this.table.toggleAllRowsExpanded(false);
}

/** @internal */
public onRightDividerMouseDown(
event: MouseEvent,
columnIndex: number
): void {
if (event.button === 0) {
this.layoutManager.beginColumnInteractiveSize(
event.clientX,
columnIndex * 2
);
}
}

/** @internal */
public onLeftDividerMouseDown(
event: MouseEvent,
columnIndex: number
): void {
if (event.button === 0) {
this.layoutManager.beginColumnInteractiveSize(
event.clientX,
columnIndex * 2 - 1
);
}
}

/** @internal */
public handleGroupRowExpanded(rowIndex: number, event: Event): void {
this.toggleGroupExpanded(rowIndex);
Expand Down Expand Up @@ -464,7 +516,10 @@ export class Table<
}

if (this.tableUpdateTracker.updateColumnWidths) {
this.updateRowGridColumns();
this.rowGridColumns = this.layoutManager.getGridTemplateColumns();
this.visibleColumns = this.columns.filter(
column => !column.columnHidden
);
}

if (this.tableUpdateTracker.updateGroupRows) {
Expand All @@ -483,6 +538,15 @@ export class Table<
}
}

/**
* @internal
*/
public getHeaderContainerElements(): NodeListOf<Element> {
return this.columnHeadersContainer.querySelectorAll(
'.header-container'
);
}

protected selectionModeChanged(
_prev: string | undefined,
_next: string | undefined
Expand Down Expand Up @@ -691,12 +755,6 @@ export class Table<
this.actionMenuSlots = Array.from(slots);
}

private updateRowGridColumns(): void {
this.rowGridColumns = TableLayoutHelper.getGridTemplateColumns(
this.columns
);
}

private validate(): void {
this.tableValidator.validateSelectionMode(
this.selectionMode,
Expand Down

This file was deleted.

Loading