-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(column-resize): Experimental column resize for mat-table #16114
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d44d73
feat(column-resize): Experimental column resize for mat-table
kseamon ffd4079
Attempt to fix CI failure.
kseamon 01f9ba0
seeing what happens if we remove tsconfig-build
kseamon 48dee64
also for cdk
kseamon 1d173f3
Add a lot of JSDoc
kseamon d5894bb
Move takeUntil to the end of pipe chains
kseamon a150302
review
kseamon 1d71ac2
review
kseamon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ng_module") | ||
|
||
ng_module( | ||
name = "column-resize", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
module_name = "@angular/cdk-experimental/column-resize", | ||
deps = [ | ||
"//src/cdk-experimental/popover-edit", | ||
"//src/cdk/bidi", | ||
"//src/cdk/coercion", | ||
"//src/cdk/keycodes", | ||
"//src/cdk/overlay", | ||
"//src/cdk/portal", | ||
"//src/cdk/table", | ||
"@npm//@angular/common", | ||
"@npm//@angular/core", | ||
"@npm//rxjs", | ||
], | ||
) |
39 changes: 39 additions & 0 deletions
39
src/cdk-experimental/column-resize/column-resize-directives/column-resize-flex.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Explicitly enables column resizing for a flexbox-based cdk-table. | ||
* Individual columns must be annotated specifically. | ||
*/ | ||
@Directive({ | ||
selector: 'cdk-table[columnResize]', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...FLEX_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkColumnResizeFlex}, | ||
], | ||
}) | ||
export class CdkColumnResizeFlex extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/cdk-experimental/column-resize/column-resize-directives/column-resize.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Explicitly enables column resizing for a table-based cdk-table. | ||
* Individual columns must be annotated specifically. | ||
*/ | ||
@Directive({ | ||
selector: 'table[cdk-table][columnResize]', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...TABLE_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkColumnResize}, | ||
], | ||
}) | ||
export class CdkColumnResize extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/cdk-experimental/column-resize/column-resize-directives/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Provider} from '@angular/core'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import { | ||
TABLE_LAYOUT_FIXED_RESIZE_STRATEGY_PROVIDER, | ||
FLEX_RESIZE_STRATEGY_PROVIDER, | ||
} from '../resize-strategy'; | ||
|
||
const PROVIDERS: Provider[] = [ | ||
ColumnResizeNotifier, | ||
HeaderRowEventDispatcher, | ||
ColumnResizeNotifierSource, | ||
]; | ||
|
||
export const TABLE_PROVIDERS: Provider[] = [ | ||
...PROVIDERS, | ||
TABLE_LAYOUT_FIXED_RESIZE_STRATEGY_PROVIDER, | ||
]; | ||
export const FLEX_PROVIDERS: Provider[] = [...PROVIDERS, FLEX_RESIZE_STRATEGY_PROVIDER]; | ||
export const HOST_BINDINGS = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels like overkill to have to maintain this in a separate constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll punt this one up to @jelbourn for adjudication - I like the DRYness of it. |
||
'[class.cdk-column-resize-rtl]': 'directionality.value === "rtl"', | ||
}; |
39 changes: 39 additions & 0 deletions
39
...experimental/column-resize/column-resize-directives/default-enabled-column-resize-flex.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, FLEX_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Implicitly enables column resizing for a flex cdk-table. | ||
* Individual columns will be resizable unless opted out. | ||
*/ | ||
@Directive({ | ||
selector: 'cdk-table', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...FLEX_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkDefaultEnabledColumnResizeFlex}, | ||
], | ||
}) | ||
export class CdkDefaultEnabledColumnResizeFlex extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/cdk-experimental/column-resize/column-resize-directives/default-enabled-column-resize.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Directive, ElementRef, NgZone} from '@angular/core'; | ||
import {Directionality} from '@angular/cdk/bidi'; | ||
|
||
import {ColumnResize} from '../column-resize'; | ||
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from '../column-resize-notifier'; | ||
import {HeaderRowEventDispatcher} from '../event-dispatcher'; | ||
import {HOST_BINDINGS, TABLE_PROVIDERS} from './constants'; | ||
|
||
/** | ||
* Implicitly enables column resizing for a table-based cdk-table. | ||
* Individual columns will be resizable unless opted out. | ||
*/ | ||
@Directive({ | ||
selector: 'table[cdk-table]', | ||
host: HOST_BINDINGS, | ||
providers: [ | ||
...TABLE_PROVIDERS, | ||
{provide: ColumnResize, useExisting: CdkDefaultEnabledColumnResize}, | ||
], | ||
}) | ||
export class CdkDefaultEnabledColumnResize extends ColumnResize { | ||
constructor( | ||
readonly columnResizeNotifier: ColumnResizeNotifier, | ||
readonly directionality: Directionality, | ||
protected readonly elementRef: ElementRef, | ||
protected readonly eventDispatcher: HeaderRowEventDispatcher, | ||
protected readonly ngZone: NgZone, | ||
protected readonly notifier: ColumnResizeNotifierSource) { | ||
super(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/cdk-experimental/column-resize/column-resize-module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {NgModule} from '@angular/core'; | ||
|
||
import {CdkColumnResize} from './column-resize-directives/column-resize'; | ||
import {CdkColumnResizeFlex} from './column-resize-directives/column-resize-flex'; | ||
import { | ||
CdkDefaultEnabledColumnResize | ||
} from './column-resize-directives/default-enabled-column-resize'; | ||
import { | ||
CdkDefaultEnabledColumnResizeFlex | ||
} from './column-resize-directives/default-enabled-column-resize-flex'; | ||
|
||
/** | ||
* One of two NgModules for use with CdkColumnResize. | ||
* When using this module, columns are resizable by default. | ||
*/ | ||
@NgModule({ | ||
declarations: [CdkDefaultEnabledColumnResize, CdkDefaultEnabledColumnResizeFlex], | ||
exports: [CdkDefaultEnabledColumnResize, CdkDefaultEnabledColumnResizeFlex], | ||
}) | ||
export class CdkColumnResizeDefaultEnabledModule {} | ||
|
||
/** | ||
* One of two NgModules for use with CdkColumnResize. | ||
* When using this module, columns are not resizable by default. | ||
*/ | ||
@NgModule({ | ||
declarations: [CdkColumnResize, CdkColumnResizeFlex], | ||
exports: [CdkColumnResize, CdkColumnResizeFlex], | ||
}) | ||
export class CdkColumnResizeModule {} |
56 changes: 56 additions & 0 deletions
56
src/cdk-experimental/column-resize/column-resize-notifier.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Injectable} from '@angular/core'; | ||
import {Observable, Subject} from 'rxjs'; | ||
|
||
/** Indicates the width of a column. */ | ||
export interface ColumnSize { | ||
kseamon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** The ID/name of the column, as defined in CdkColumnDef. */ | ||
readonly columnId: string; | ||
|
||
/** The width in pixels of the column. */ | ||
readonly size: number; | ||
} | ||
|
||
/** Interface describing column size changes. */ | ||
export interface ColumnSizeAction extends ColumnSize { | ||
/** | ||
* Whether the resize action should be applied instantaneously. False for events triggered during | ||
* a UI-triggered resize (such as with the mouse) until the mouse button is released. True | ||
* for all programatically triggered resizes. | ||
*/ | ||
readonly completeImmediately?: boolean; | ||
} | ||
|
||
/** Originating source of column resize events within a table. */ | ||
@Injectable() | ||
export class ColumnResizeNotifierSource { | ||
/** Emits when an in-progress resize is canceled. */ | ||
readonly resizeCanceled = new Subject<ColumnSizeAction>(); | ||
|
||
/** Emits when a resize is applied. */ | ||
readonly resizeCompleted = new Subject<ColumnSize>(); | ||
|
||
/** Triggers a resize action. */ | ||
readonly triggerResize = new Subject<ColumnSizeAction>(); | ||
} | ||
|
||
/** Service for triggering column resizes imperatively or being notified of them. */ | ||
@Injectable() | ||
export class ColumnResizeNotifier { | ||
/** Emits whenever a column is resized. */ | ||
readonly resizeCompleted: Observable<ColumnSize> = this._source.resizeCompleted.asObservable(); | ||
|
||
constructor(private readonly _source: ColumnResizeNotifierSource) {} | ||
|
||
/** Instantly resizes the specified column. */ | ||
resize(columnId: string, size: number): void { | ||
this._source.triggerResize.next({columnId, size, completeImmediately: true}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.