|
9 | 9 | import {Injectable} from '@angular/core'; |
10 | 10 | import {Observable, Subject} from 'rxjs'; |
11 | 11 |
|
| 12 | +/** Indicates the width of a column. */ |
12 | 13 | export interface ColumnSize { |
| 14 | + /** The ID/name of the column, as defined in CdkColumnDef. */ |
13 | 15 | readonly columnId: string; |
| 16 | + |
| 17 | + /** The width in pixels of the column. */ |
14 | 18 | readonly size: number; |
15 | 19 | } |
16 | 20 |
|
| 21 | +/** Interface describing column size changes. */ |
17 | 22 | export interface ColumnSizeAction extends ColumnSize { |
| 23 | + /** |
| 24 | + * Whether the resize action should be applied instantaneously. False for events triggered during |
| 25 | + * a UI-triggered resize (such as with the mouse) until the mouse button is released. True |
| 26 | + * for all programatically triggered resizes. |
| 27 | + */ |
18 | 28 | readonly completeImmediately?: boolean; |
19 | 29 | } |
20 | 30 |
|
| 31 | +/** Conduit for resize-releated events within the table. */ |
21 | 32 | @Injectable() |
22 | 33 | export class ColumnResizeNotifierSource { |
| 34 | + /** Emits when an in-progress resize is canceled. */ |
23 | 35 | readonly resizeCanceled = new Subject<ColumnSizeAction>(); |
| 36 | + |
| 37 | + /** Emits when a resize is applied. */ |
24 | 38 | readonly resizeCompleted = new Subject<ColumnSize>(); |
| 39 | + |
| 40 | + /** Triggers a resize action. */ |
25 | 41 | readonly triggerResize = new Subject<ColumnSizeAction>(); |
26 | 42 | } |
27 | 43 |
|
28 | 44 | /** Service for triggering column resizes imperatively or being notified of them. */ |
29 | 45 | @Injectable() |
30 | 46 | export class ColumnResizeNotifier { |
| 47 | + /** Emits whenever a column is resized. */ |
31 | 48 | readonly resizeCompleted: Observable<ColumnSize> = this._source.resizeCompleted.asObservable(); |
32 | 49 |
|
33 | 50 | constructor(private readonly _source: ColumnResizeNotifierSource) {} |
34 | 51 |
|
| 52 | + /** Instantly resizes the specified column. */ |
35 | 53 | resize(columnId: string, size: number): void { |
36 | 54 | this._source.triggerResize.next({columnId, size, completeImmediately: true}); |
37 | 55 | } |
|
0 commit comments