Skip to content

Commit ca3cb5b

Browse files
committed
main - 6b02256 refactor: migrate example inputs to signal inputs (#29789)
1 parent c47695d commit ca3cb5b

File tree

15 files changed

+45
-47
lines changed

15 files changed

+45
-47
lines changed

cdk/scrolling/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CollectionViewer } from '@angular/cdk/collections';
22
import { DataSource } from '@angular/cdk/collections';
33
import * as i0 from '@angular/core';
4+
import { InputSignal } from '@angular/core';
45
import { Observable } from 'rxjs';
56

67
/** @title Virtual scroll with view recycling disabled. */
@@ -78,10 +79,10 @@ export declare class CdkVirtualScrollTemplateCacheExample {
7879

7980
/** @title Virtual scrolling window */
8081
export declare class CdkVirtualScrollWindowScrollingExample {
81-
shouldRun: boolean;
82+
readonly shouldRun: InputSignal<boolean>;
8283
items: string[];
8384
static ɵfac: i0.ɵɵFactoryDeclaration<CdkVirtualScrollWindowScrollingExample, never>;
84-
static ɵcmp: i0.ɵɵComponentDeclaration<CdkVirtualScrollWindowScrollingExample, "cdk-virtual-scroll-window-scrolling-example", never, { "shouldRun": { "alias": "shouldRun"; "required": false; }; }, {}, never, never, true, never>;
85+
static ɵcmp: i0.ɵɵComponentDeclaration<CdkVirtualScrollWindowScrollingExample, "cdk-virtual-scroll-window-scrolling-example", never, { "shouldRun": { "alias": "shouldRun"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
8586
}
8687

8788
declare class MyDataSource extends DataSource<string | undefined> {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
@if (shouldRun) {
1+
@if (shouldRun()) {
22
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-header&quot;</span>&gt;</span>Content before<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
33
<span class="hljs-tag">&lt;<span class="hljs-name">cdk-virtual-scroll-viewport</span> <span class="hljs-attr">scrollWindow</span> <span class="hljs-attr">itemSize</span>=<span class="hljs-string">&quot;50&quot;</span>&gt;</span>
44
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> *<span class="hljs-attr">cdkVirtualFor</span>=<span class="hljs-string">&quot;let item of items&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-item&quot;</span>&gt;</span>{{item}}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
55
<span class="hljs-tag">&lt;/<span class="hljs-name">cdk-virtual-scroll-viewport</span>&gt;</span>
66
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;example-footer&quot;</span>&gt;</span>Content after<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
77
}
88

9-
@if (!shouldRun) {
9+
@if (!shouldRun()) {
1010
<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Please open on StackBlitz to see result<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
1111
}

docs-content/examples-highlighted/cdk/scrolling/cdk-virtual-scroll-window-scrolling/cdk-virtual-scroll-window-scrolling-example-ts.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<span class="hljs-keyword">import</span> {ChangeDetectionStrategy, Component, Input} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/core&#x27;</span>;
1+
<span class="hljs-keyword">import</span> {ChangeDetectionStrategy, Component, input} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/core&#x27;</span>;
22
<span class="hljs-keyword">import</span> {ScrollingModule} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/cdk/scrolling&#x27;</span>;
33

44
<span class="hljs-comment">/** <span class="hljs-doctag">@title </span>Virtual scrolling window */</span>
@@ -11,7 +11,7 @@
1111
<span class="hljs-attr">imports</span>: [ScrollingModule],
1212
})
1313
<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CdkVirtualScrollWindowScrollingExample</span> </span>{
14-
<span class="hljs-meta">@Input</span>() shouldRun = <span class="hljs-regexp">/(^|.)(stackblitz|webcontainer).(io|com)$/</span>.test(<span class="hljs-built_in">window</span>.location.host);
14+
<span class="hljs-keyword">readonly</span> shouldRun = input(<span class="hljs-regexp">/(^|.)(stackblitz|webcontainer).(io|com)$/</span>.test(<span class="hljs-built_in">window</span>.location.host));
1515

1616
items = <span class="hljs-built_in">Array</span>.from({<span class="hljs-attr">length</span>: <span class="hljs-number">100000</span>}).map(<span class="hljs-function">(<span class="hljs-params">_, i</span>) =&gt;</span> <span class="hljs-string">`Item #<span class="hljs-subst">${i}</span>`</span>);
1717
}

docs-content/examples-highlighted/material/table/table-wrapped/table-wrapped-example-ts.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
AfterContentInit,
44
Component,
55
ContentChildren,
6-
Input,
76
AfterViewInit,
87
QueryList,
98
ViewChild,
109
ContentChild,
1110
forwardRef,
11+
input,
1212
} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/core&#x27;</span>;
1313
<span class="hljs-keyword">import</span> {MatSort, MatSortModule} <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@angular/material/sort&#x27;</span>;
1414
<span class="hljs-keyword">import</span> {
@@ -94,9 +94,8 @@
9494

9595
<span class="hljs-meta">@ViewChild</span>(MatTable, {<span class="hljs-attr">static</span>: <span class="hljs-literal">true</span>}) table: MatTable&lt;T&gt;;
9696

97-
<span class="hljs-meta">@Input</span>() columns: <span class="hljs-built_in">string</span>[];
98-
99-
<span class="hljs-meta">@Input</span>() dataSource: DataSource&lt;T&gt;;
97+
<span class="hljs-keyword">readonly</span> columns = input.required&lt;<span class="hljs-built_in">string</span>[]&gt;();
98+
<span class="hljs-keyword">readonly</span> dataSource = input.required&lt;DataSource&lt;T&gt;&gt;();
10099

101100
<span class="hljs-function"><span class="hljs-title">ngAfterContentInit</span>(<span class="hljs-params"></span>)</span> {
102101
<span class="hljs-built_in">this</span>.columnDefs.forEach(<span class="hljs-function"><span class="hljs-params">columnDef</span> =&gt;</span> <span class="hljs-built_in">this</span>.table.addColumnDef(columnDef));

docs-content/examples-highlighted/material/table/table-wrapped/wrapper-table-html.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">mat-table</span> [<span class="hljs-attr">dataSource</span>]=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;mat-elevation-z8&quot;</span>&gt;</span>
1+
<span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">mat-table</span> [<span class="hljs-attr">dataSource</span>]=<span class="hljs-string">&quot;dataSource()&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;mat-elevation-z8&quot;</span>&gt;</span>
22
<span class="hljs-tag">&lt;<span class="hljs-name">ng-content</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ng-content</span>&gt;</span>
33

44
<span class="hljs-comment">&lt;!-- Position Column --&gt;</span>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
@if (shouldRun) {
1+
@if (shouldRun()) {
22
<div class="example-header">Content before</div>
33
<cdk-virtual-scroll-viewport scrollWindow itemSize="50">
44
<div *cdkVirtualFor="let item of items" class="example-item">{{item}}</div>
55
</cdk-virtual-scroll-viewport>
66
<div class="example-footer">Content after</div>
77
}
88

9-
@if (!shouldRun) {
9+
@if (!shouldRun()) {
1010
<div>Please open on StackBlitz to see result</div>
1111
}

docs-content/examples-source/cdk/scrolling/cdk-virtual-scroll-window-scrolling/cdk-virtual-scroll-window-scrolling-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ChangeDetectionStrategy, Component, Input} from '@angular/core';
1+
import {ChangeDetectionStrategy, Component, input} from '@angular/core';
22
import {ScrollingModule} from '@angular/cdk/scrolling';
33

44
/** @title Virtual scrolling window */
@@ -11,7 +11,7 @@ import {ScrollingModule} from '@angular/cdk/scrolling';
1111
imports: [ScrollingModule],
1212
})
1313
export class CdkVirtualScrollWindowScrollingExample {
14-
@Input() shouldRun = /(^|.)(stackblitz|webcontainer).(io|com)$/.test(window.location.host);
14+
readonly shouldRun = input(/(^|.)(stackblitz|webcontainer).(io|com)$/.test(window.location.host));
1515

1616
items = Array.from({length: 100000}).map((_, i) => `Item #${i}`);
1717
}

docs-content/examples-source/material/table/table-wrapped/table-wrapped-example.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {
33
AfterContentInit,
44
Component,
55
ContentChildren,
6-
Input,
76
AfterViewInit,
87
QueryList,
98
ViewChild,
109
ContentChild,
1110
forwardRef,
11+
input,
1212
} from '@angular/core';
1313
import {MatSort, MatSortModule} from '@angular/material/sort';
1414
import {
@@ -94,9 +94,8 @@ export class WrapperTable<T> implements AfterContentInit {
9494

9595
@ViewChild(MatTable, {static: true}) table: MatTable<T>;
9696

97-
@Input() columns: string[];
98-
99-
@Input() dataSource: DataSource<T>;
97+
readonly columns = input.required<string[]>();
98+
readonly dataSource = input.required<DataSource<T>>();
10099

101100
ngAfterContentInit() {
102101
this.columnDefs.forEach(columnDef => this.table.addColumnDef(columnDef));

docs-content/examples-source/material/table/table-wrapped/wrapper-table.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
1+
<table mat-table [dataSource]="dataSource()" class="mat-elevation-z8">
22
<ng-content></ng-content>
33

44
<!-- Position Column -->

fesm2022/cdk/scrolling.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as i0 from '@angular/core';
2-
import { Component, ChangeDetectionStrategy, ViewEncapsulation, Input } from '@angular/core';
2+
import { Component, ChangeDetectionStrategy, ViewEncapsulation, input } from '@angular/core';
33
import * as i1 from '@angular/cdk/scrolling';
44
import { ScrollingModule, FixedSizeVirtualScrollStrategy, VIRTUAL_SCROLL_STRATEGY } from '@angular/cdk/scrolling';
55
import { DataSource } from '@angular/cdk/collections';
@@ -232,18 +232,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0-next.3",
232232
/** @title Virtual scrolling window */
233233
class CdkVirtualScrollWindowScrollingExample {
234234
constructor() {
235-
this.shouldRun = /(^|.)(stackblitz|webcontainer).(io|com)$/.test(window.location.host);
235+
this.shouldRun = input(/(^|.)(stackblitz|webcontainer).(io|com)$/.test(window.location.host));
236236
this.items = Array.from({ length: 100000 }).map((_, i) => `Item #${i}`);
237237
}
238238
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0-next.3", ngImport: i0, type: CdkVirtualScrollWindowScrollingExample, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
239-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.0-next.3", type: CdkVirtualScrollWindowScrollingExample, isStandalone: true, selector: "cdk-virtual-scroll-window-scrolling-example", inputs: { shouldRun: "shouldRun" }, ngImport: i0, template: "@if (shouldRun) {\n <div class=\"example-header\">Content before</div>\n <cdk-virtual-scroll-viewport scrollWindow itemSize=\"50\">\n <div *cdkVirtualFor=\"let item of items\" class=\"example-item\">{{item}}</div>\n </cdk-virtual-scroll-viewport>\n <div class=\"example-footer\">Content after</div>\n}\n\n@if (!shouldRun) {\n <div>Please open on StackBlitz to see result</div>\n}\n", styles: [".example-item {\n height: 50px;\n}\n\n.example-header,\n.example-footer {\n height: 100px;\n background: lightgray;\n}\n"], dependencies: [{ kind: "ngmodule", type: ScrollingModule }, { kind: "directive", type: i1.CdkFixedSizeVirtualScroll, selector: "cdk-virtual-scroll-viewport[itemSize]", inputs: ["itemSize", "minBufferPx", "maxBufferPx"] }, { kind: "directive", type: i1.CdkVirtualForOf, selector: "[cdkVirtualFor][cdkVirtualForOf]", inputs: ["cdkVirtualForOf", "cdkVirtualForTrackBy", "cdkVirtualForTemplate", "cdkVirtualForTemplateCacheSize"] }, { kind: "component", type: i1.CdkVirtualScrollViewport, selector: "cdk-virtual-scroll-viewport", inputs: ["orientation", "appendOnly"], outputs: ["scrolledIndexChange"] }, { kind: "directive", type: i1.CdkVirtualScrollableWindow, selector: "cdk-virtual-scroll-viewport[scrollWindow]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
239+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.0-next.3", type: CdkVirtualScrollWindowScrollingExample, isStandalone: true, selector: "cdk-virtual-scroll-window-scrolling-example", inputs: { shouldRun: { classPropertyName: "shouldRun", publicName: "shouldRun", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "@if (shouldRun()) {\n <div class=\"example-header\">Content before</div>\n <cdk-virtual-scroll-viewport scrollWindow itemSize=\"50\">\n <div *cdkVirtualFor=\"let item of items\" class=\"example-item\">{{item}}</div>\n </cdk-virtual-scroll-viewport>\n <div class=\"example-footer\">Content after</div>\n}\n\n@if (!shouldRun()) {\n <div>Please open on StackBlitz to see result</div>\n}\n", styles: [".example-item {\n height: 50px;\n}\n\n.example-header,\n.example-footer {\n height: 100px;\n background: lightgray;\n}\n"], dependencies: [{ kind: "ngmodule", type: ScrollingModule }, { kind: "directive", type: i1.CdkFixedSizeVirtualScroll, selector: "cdk-virtual-scroll-viewport[itemSize]", inputs: ["itemSize", "minBufferPx", "maxBufferPx"] }, { kind: "directive", type: i1.CdkVirtualForOf, selector: "[cdkVirtualFor][cdkVirtualForOf]", inputs: ["cdkVirtualForOf", "cdkVirtualForTrackBy", "cdkVirtualForTemplate", "cdkVirtualForTemplateCacheSize"] }, { kind: "component", type: i1.CdkVirtualScrollViewport, selector: "cdk-virtual-scroll-viewport", inputs: ["orientation", "appendOnly"], outputs: ["scrolledIndexChange"] }, { kind: "directive", type: i1.CdkVirtualScrollableWindow, selector: "cdk-virtual-scroll-viewport[scrollWindow]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
240240
}
241241
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0-next.3", ngImport: i0, type: CdkVirtualScrollWindowScrollingExample, decorators: [{
242242
type: Component,
243-
args: [{ selector: 'cdk-virtual-scroll-window-scrolling-example', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [ScrollingModule], template: "@if (shouldRun) {\n <div class=\"example-header\">Content before</div>\n <cdk-virtual-scroll-viewport scrollWindow itemSize=\"50\">\n <div *cdkVirtualFor=\"let item of items\" class=\"example-item\">{{item}}</div>\n </cdk-virtual-scroll-viewport>\n <div class=\"example-footer\">Content after</div>\n}\n\n@if (!shouldRun) {\n <div>Please open on StackBlitz to see result</div>\n}\n", styles: [".example-item {\n height: 50px;\n}\n\n.example-header,\n.example-footer {\n height: 100px;\n background: lightgray;\n}\n"] }]
244-
}], propDecorators: { shouldRun: [{
245-
type: Input
246-
}] } });
243+
args: [{ selector: 'cdk-virtual-scroll-window-scrolling-example', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [ScrollingModule], template: "@if (shouldRun()) {\n <div class=\"example-header\">Content before</div>\n <cdk-virtual-scroll-viewport scrollWindow itemSize=\"50\">\n <div *cdkVirtualFor=\"let item of items\" class=\"example-item\">{{item}}</div>\n </cdk-virtual-scroll-viewport>\n <div class=\"example-footer\">Content after</div>\n}\n\n@if (!shouldRun()) {\n <div>Please open on StackBlitz to see result</div>\n}\n", styles: [".example-item {\n height: 50px;\n}\n\n.example-header,\n.example-footer {\n height: 100px;\n background: lightgray;\n}\n"] }]
244+
}] });
247245

248246
/**
249247
* Generated bundle index. Do not edit.

0 commit comments

Comments
 (0)