From 330d99fa0ec4c67604e5bb9d4d1ee3892d7a769e Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Wed, 26 Sep 2018 17:03:45 -0700 Subject: [PATCH 1/2] docs(virtual-scroll): add embedded examples --- src/cdk/scrolling/scrolling.md | 53 +++------------- .../cdk-virtual-scroll-context-example.css | 13 ++++ .../cdk-virtual-scroll-context-example.html | 17 +++++ .../cdk-virtual-scroll-context-example.ts | 12 ++++ ...cdk-virtual-scroll-data-source-example.css | 9 +++ ...dk-virtual-scroll-data-source-example.html | 3 + .../cdk-virtual-scroll-data-source-example.ts | 57 +++++++++++++++++ .../cdk-virtual-scroll-dl-example.css | 14 +++++ .../cdk-virtual-scroll-dl-example.html | 8 +++ .../cdk-virtual-scroll-dl-example.ts | 63 +++++++++++++++++++ ...dk-virtual-scroll-fixed-buffer-example.css | 9 +++ ...k-virtual-scroll-fixed-buffer-example.html | 4 ++ ...cdk-virtual-scroll-fixed-buffer-example.ts | 12 ++++ .../cdk-virtual-scroll-horizontal-example.css | 16 +++++ ...cdk-virtual-scroll-horizontal-example.html | 5 ++ .../cdk-virtual-scroll-horizontal-example.ts | 13 ++++ .../cdk-virtual-scroll-overview-example.css | 9 +++ .../cdk-virtual-scroll-overview-example.html | 3 + .../cdk-virtual-scroll-overview-example.ts | 12 ++++ ...-virtual-scroll-template-cache-example.css | 9 +++ ...virtual-scroll-template-cache-example.html | 3 + ...k-virtual-scroll-template-cache-example.ts | 12 ++++ 22 files changed, 311 insertions(+), 45 deletions(-) create mode 100644 src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css create mode 100644 src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.html create mode 100644 src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.ts create mode 100644 src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.css create mode 100644 src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.html create mode 100644 src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.ts create mode 100644 src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.css create mode 100644 src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.html create mode 100644 src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.ts create mode 100644 src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.css create mode 100644 src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.html create mode 100644 src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.ts create mode 100644 src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.css create mode 100644 src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.html create mode 100644 src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.ts create mode 100644 src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.css create mode 100644 src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.html create mode 100644 src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.ts create mode 100644 src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.css create mode 100644 src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.html create mode 100644 src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.ts diff --git a/src/cdk/scrolling/scrolling.md b/src/cdk/scrolling/scrolling.md index eb875979e2ae..3729a76ec903 100644 --- a/src/cdk/scrolling/scrolling.md +++ b/src/cdk/scrolling/scrolling.md @@ -27,11 +27,7 @@ rest. same API as [`*ngFor`](https://angular.io/api/common/NgForOf). The simplest usage just specifies the list of items: -```html - -
{{item}}
-
-``` + `*cdkVirtualFor` makes the following context variables available to the template: @@ -47,15 +43,7 @@ list of items: All of these apply to the index of the item in the data source, not the index in the rendered portion of the data. -```html - -
- {{item}} ({{index}} of {{count}}) -
-
-``` + A `trackBy` function can be specified and works the same as the `*ngFor` `trackBy`. The `index` passed to the tracking function will be the index in the data source, not the index in the rendered @@ -68,11 +56,7 @@ is reused instead. The size of the view cache can be adjusted via the `templateC property; setting this size to `0` disables caching. If your templates are expensive in terms of memory you may wish to reduce this number to avoid spending too much memory on the template cache. -```html - -
{{item}}
-
-``` + ##### Specifying data `*cdkVirtualFor` accepts data from an `Array`, `Observable`, or `DataSource`. The @@ -83,17 +67,13 @@ data array that should be rendered. The viewport will call `disconnect` when the destroyed, which may be the right time to clean up any subscriptions that were registered during the connect process. + + #### Scrolling over fixed size items When all items are the same fixed size, you can use the `FixedSizeVirtualScrollStrategy`. This can be easily added to your viewport using the `itemSize` directive. The advantage of this constraint is that it allows for better performance, since items do not need to be measured as they are rendered. -```html - - ... - -``` - The fixed size strategy also supports setting a couple of buffer parameters that determine how much extra content is rendered beyond what is visible in the viewport. The first of these parameters is `minBufferPx`. The `minBufferPx` is the minimum amount of content buffer (in pixels) that the @@ -108,11 +88,7 @@ remaining. Since this is below `minBufferPx` the viewport must render more buffe least enough buffer to get back to `maxBufferPx`. In this case, it renders 4 items (an additional `200px`) to bring the total buffer size to `290px`, back above `maxBufferPx`. -```html - - ... - -``` + Other virtual scrolling strategies can be implemented by extending `VirtualScrollStrategy`. An autosize strategy that works on elements of differing sizes is currently being developed in @@ -125,11 +101,7 @@ out horizontally via CSS. To do this you may want to target CSS at `.cdk-virtual-scroll-content-wrapper` which is the wrapper element that contains the rendered content. -```html - - ... - -``` + ### Elements with parent tag requirements Some HTML elements such as `` and `
  • ` have limitations on the kinds of parent elements they @@ -138,13 +110,4 @@ their proper parent, and then wrap the whole thing in a `cdk-virtual-scroll-view that the parent does not introduce additional space (e.g. via `margin` or `padding`) as it will interfere with the scrolling. -```html - - - - - - -
    {{row.first}}{{row.second}}
    -
    -``` + diff --git a/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css new file mode 100644 index 000000000000..95c87d9fde21 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css @@ -0,0 +1,13 @@ +.example-viewport { + height: 200px; + width: 200px; + border: 1px solid black; +} + +.example-item-detail { + height: 18px; +} + +.example-alternate { + background: rgba(0, 0, 0, .2); +} diff --git a/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.html b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.html new file mode 100644 index 000000000000..d3e0f6d27fb1 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.html @@ -0,0 +1,17 @@ + +
    +
    Item: {{item}}
    +
    Index: {{index}}
    +
    Count: {{count}}
    +
    First: {{first ? 'Yes' : 'No'}}
    +
    Last: {{last ? 'Yes' : 'No'}}
    +
    Event: {{even ? 'Yes' : 'No'}}
    +
    Odd: {{odd ? 'Yes' : 'No'}}
    +
    +
    diff --git a/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.ts b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.ts new file mode 100644 index 000000000000..7b7d0a5af77a --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.ts @@ -0,0 +1,12 @@ +import {ChangeDetectionStrategy, Component} from '@angular/core'; + +/** @title Virtual scroll context variables */ +@Component({ + selector: 'cdk-virtual-scroll-context-example', + styleUrls: ['cdk-virtual-scroll-context-example.css'], + templateUrl: 'cdk-virtual-scroll-context-example.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CdkVirtualScrollContextExample { + items = Array.from({length: 100000}).map((_, i) => `Item #${i}`); +} diff --git a/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.css b/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.css new file mode 100644 index 000000000000..55eb0cd3c6e6 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.css @@ -0,0 +1,9 @@ +.example-viewport { + height: 200px; + width: 200px; + border: 1px solid black; +} + +.example-item { + height: 50px; +} diff --git a/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.html b/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.html new file mode 100644 index 000000000000..8c02441bde63 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.html @@ -0,0 +1,3 @@ + +
    {{item || 'Loading...'}}
    +
    diff --git a/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.ts b/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.ts new file mode 100644 index 000000000000..c610ad424e86 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-data-source/cdk-virtual-scroll-data-source-example.ts @@ -0,0 +1,57 @@ +import {CollectionViewer, DataSource} from '@angular/cdk/collections'; +import {ChangeDetectionStrategy, Component} from '@angular/core'; +import {BehaviorSubject, Observable, Subscription} from 'rxjs'; + +/** @title Virtual scroll with a custom data source */ +@Component({ + selector: 'cdk-virtual-scroll-data-source-example', + styleUrls: ['cdk-virtual-scroll-data-source-example.css'], + templateUrl: 'cdk-virtual-scroll-data-source-example.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CdkVirtualScrollDataSourceExample { + ds = new MyDataSource(); +} + +export class MyDataSource extends DataSource { + private length = 100000; + private pageSize = 100; + private cachedData = Array.from({length: this.length}); + private fetchedPages = new Set(); + private dataStream = new BehaviorSubject<(string | undefined)[]>(this.cachedData); + private subscription = new Subscription(); + + connect(collectionViewer: CollectionViewer): Observable<(string | undefined)[]> { + this.subscription.add(collectionViewer.viewChange.subscribe(range => { + const startPage = this.getPageForIndex(range.start); + const endPage = this.getPageForIndex(range.end - 1); + for (let i = startPage; i <= endPage; i++) { + this.fetchPage(i); + } + })); + return this.dataStream; + } + + disconnect(): void { + this.subscription.unsubscribe(); + } + + private getPageForIndex(index: number): number { + return Math.floor(index / this.pageSize); + } + + private fetchPage(page: number) { + if (this.fetchedPages.has(page)) { + return; + } + this.fetchedPages.add(page); + + // Use `setTimeout` to simulate fetching data from server. + setTimeout(() => { + this.cachedData.splice(page * this.pageSize, this.pageSize, + ...Array.from({length: this.pageSize}) + .map((_, i) => `Item #${page * this.pageSize + i}`)); + this.dataStream.next(this.cachedData); + }, Math.random() * 1000 + 200); + } +} diff --git a/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.css b/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.css new file mode 100644 index 000000000000..6eba86fecf45 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.css @@ -0,0 +1,14 @@ +.example-viewport { + height: 200px; + width: 200px; + border: 1px solid black; +} + +.example-dt { + height: 30px; + font-weight: bold; +} + +.example-dd { + height: 30px; +} diff --git a/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.html b/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.html new file mode 100644 index 000000000000..0fcd32247f30 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.html @@ -0,0 +1,8 @@ + +
    + +
    {{state.name}}
    +
    {{state.capital}}
    +
    +
    +
    diff --git a/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.ts b/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.ts new file mode 100644 index 000000000000..288576eeca93 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-dl/cdk-virtual-scroll-dl-example.ts @@ -0,0 +1,63 @@ +import {ChangeDetectionStrategy, Component} from '@angular/core'; + +/** @title Virtual scrolling `
    ` */ +@Component({ + selector: 'cdk-virtual-scroll-dl-example', + styleUrls: ['cdk-virtual-scroll-dl-example.css'], + templateUrl: 'cdk-virtual-scroll-dl-example.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CdkVirtualScrollDlExample { + states = [ + {name: 'Alabama', capital: 'Montgomery'}, + {name: 'Alaska', capital: 'Juneau'}, + {name: 'Arizona', capital: 'Phoenix'}, + {name: 'Arkansas', capital: 'Little Rock'}, + {name: 'California', capital: 'Sacramento'}, + {name: 'Colorado', capital: 'Denver'}, + {name: 'Connecticut', capital: 'Hartford'}, + {name: 'Delaware', capital: 'Dover'}, + {name: 'Florida', capital: 'Tallahassee'}, + {name: 'Georgia', capital: 'Atlanta'}, + {name: 'Hawaii', capital: 'Honolulu'}, + {name: 'Idaho', capital: 'Boise'}, + {name: 'Illinois', capital: 'Springfield'}, + {name: 'Indiana', capital: 'Indianapolis'}, + {name: 'Iowa', capital: 'Des Moines'}, + {name: 'Kansas', capital: 'Topeka'}, + {name: 'Kentucky', capital: 'Frankfort'}, + {name: 'Louisiana', capital: 'Baton Rouge'}, + {name: 'Maine', capital: 'Augusta'}, + {name: 'Maryland', capital: 'Annapolis'}, + {name: 'Massachusetts', capital: 'Boston'}, + {name: 'Michigan', capital: 'Lansing'}, + {name: 'Minnesota', capital: 'St. Paul'}, + {name: 'Mississippi', capital: 'Jackson'}, + {name: 'Missouri', capital: 'Jefferson City'}, + {name: 'Montana', capital: 'Helena'}, + {name: 'Nebraska', capital: 'Lincoln'}, + {name: 'Nevada', capital: 'Carson City'}, + {name: 'New Hampshire', capital: 'Concord'}, + {name: 'New Jersey', capital: 'Trenton'}, + {name: 'New Mexico', capital: 'Santa Fe'}, + {name: 'New York', capital: 'Albany'}, + {name: 'North Carolina', capital: 'Raleigh'}, + {name: 'North Dakota', capital: 'Bismarck'}, + {name: 'Ohio', capital: 'Columbus'}, + {name: 'Oklahoma', capital: 'Oklahoma City'}, + {name: 'Oregon', capital: 'Salem'}, + {name: 'Pennsylvania', capital: 'Harrisburg'}, + {name: 'Rhode Island', capital: 'Providence'}, + {name: 'South Carolina', capital: 'Columbia'}, + {name: 'South Dakota', capital: 'Pierre'}, + {name: 'Tennessee', capital: 'Nashville'}, + {name: 'Texas', capital: 'Austin'}, + {name: 'Utah', capital: 'Salt Lake City'}, + {name: 'Vermont', capital: 'Montpelier'}, + {name: 'Virginia', capital: 'Richmond'}, + {name: 'Washington', capital: 'Olympia'}, + {name: 'West Virginia', capital: 'Charleston'}, + {name: 'Wisconsin', capital: 'Madison'}, + {name: 'Wyoming', capital: 'Cheyenne'}, + ]; +} diff --git a/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.css b/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.css new file mode 100644 index 000000000000..55eb0cd3c6e6 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.css @@ -0,0 +1,9 @@ +.example-viewport { + height: 200px; + width: 200px; + border: 1px solid black; +} + +.example-item { + height: 50px; +} diff --git a/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.html b/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.html new file mode 100644 index 000000000000..49c4bc3ea57e --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.html @@ -0,0 +1,4 @@ + +
    {{item}}
    +
    diff --git a/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.ts b/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.ts new file mode 100644 index 000000000000..c257dd39e792 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-fixed-buffer/cdk-virtual-scroll-fixed-buffer-example.ts @@ -0,0 +1,12 @@ +import {ChangeDetectionStrategy, Component} from '@angular/core'; + +/** @title Fixed size virtual scroll with custom buffer parameters */ +@Component({ + selector: 'cdk-virtual-scroll-fixed-buffer-example', + styleUrls: ['cdk-virtual-scroll-fixed-buffer-example.css'], + templateUrl: 'cdk-virtual-scroll-fixed-buffer-example.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CdkVirtualScrollFixedBufferExample { + items = Array.from({length: 100000}).map((_, i) => `Item #${i}`); +} diff --git a/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.css b/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.css new file mode 100644 index 000000000000..ac76e171e676 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.css @@ -0,0 +1,16 @@ +.cdk-virtual-scroll-data-source-example .example-viewport { + height: 200px; + width: 200px; + border: 1px solid black; +} + +.cdk-virtual-scroll-data-source-example .example-viewport .cdk-virtual-scroll-content-wrapper { + display: flex; + flex-direction: row; +} + +.cdk-virtual-scroll-data-source-example .example-item { + width: 50px; + height: 100%; + writing-mode: vertical-lr; +} diff --git a/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.html b/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.html new file mode 100644 index 000000000000..96c03f9a2063 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.html @@ -0,0 +1,5 @@ +
    + +
    {{item}}
    +
    +
    diff --git a/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.ts b/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.ts new file mode 100644 index 000000000000..06070a2b007a --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-horizontal/cdk-virtual-scroll-horizontal-example.ts @@ -0,0 +1,13 @@ +import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core'; + +/** @title Horizontal virtual scroll */ +@Component({ + selector: 'cdk-virtual-scroll-horizontal-example', + styleUrls: ['cdk-virtual-scroll-horizontal-example.css'], + templateUrl: 'cdk-virtual-scroll-horizontal-example.html', + encapsulation: ViewEncapsulation.None, + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CdkVirtualScrollHorizontalExample { + items = Array.from({length: 100000}).map((_, i) => `Item #${i}`); +} diff --git a/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.css b/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.css new file mode 100644 index 000000000000..55eb0cd3c6e6 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.css @@ -0,0 +1,9 @@ +.example-viewport { + height: 200px; + width: 200px; + border: 1px solid black; +} + +.example-item { + height: 50px; +} diff --git a/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.html b/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.html new file mode 100644 index 000000000000..d44d9d9d7489 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.html @@ -0,0 +1,3 @@ + +
    {{item}}
    +
    diff --git a/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.ts b/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.ts new file mode 100644 index 000000000000..18c88ef664f6 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-overview/cdk-virtual-scroll-overview-example.ts @@ -0,0 +1,12 @@ +import {ChangeDetectionStrategy, Component} from '@angular/core'; + +/** @title Basic virtual scroll */ +@Component({ + selector: 'cdk-virtual-scroll-overview-example', + styleUrls: ['cdk-virtual-scroll-overview-example.css'], + templateUrl: 'cdk-virtual-scroll-overview-example.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CdkVirtualScrollOverviewExample { + items = Array.from({length: 100000}).map((_, i) => `Item #${i}`); +} diff --git a/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.css b/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.css new file mode 100644 index 000000000000..55eb0cd3c6e6 --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.css @@ -0,0 +1,9 @@ +.example-viewport { + height: 200px; + width: 200px; + border: 1px solid black; +} + +.example-item { + height: 50px; +} diff --git a/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.html b/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.html new file mode 100644 index 000000000000..268055f8c29d --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.html @@ -0,0 +1,3 @@ + +
    {{item}}
    +
    diff --git a/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.ts b/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.ts new file mode 100644 index 000000000000..10731fac8cfc --- /dev/null +++ b/src/material-examples/cdk-virtual-scroll-template-cache/cdk-virtual-scroll-template-cache-example.ts @@ -0,0 +1,12 @@ +import {ChangeDetectionStrategy, Component} from '@angular/core'; + +/** @title Virtual scroll with no template caching */ +@Component({ + selector: 'cdk-virtual-scroll-template-cache-example', + styleUrls: ['cdk-virtual-scroll-template-cache-example.css'], + templateUrl: 'cdk-virtual-scroll-template-cache-example.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CdkVirtualScrollTemplateCacheExample { + items = Array.from({length: 100000}).map((_, i) => `Item #${i}`); +} From a967af99f4b935203f071d96e5c898bb61f06128 Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Thu, 27 Sep 2018 09:59:57 -0700 Subject: [PATCH 2/2] use semi-transparent gray instead of black --- .../cdk-virtual-scroll-context-example.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css index 95c87d9fde21..f1a86b302a1e 100644 --- a/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css +++ b/src/material-examples/cdk-virtual-scroll-context/cdk-virtual-scroll-context-example.css @@ -9,5 +9,5 @@ } .example-alternate { - background: rgba(0, 0, 0, .2); + background: rgba(127, 127, 127, 0.3); }