Skip to content

Commit 2c23113

Browse files
committed
chore: update table demo page
1 parent f060c88 commit 2c23113

22 files changed

+163
-540
lines changed

src/demo-app/demo-app/routes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ import {TooltipDemo} from '../tooltip/tooltip-demo';
5050
import {TreeDemo} from '../tree/tree-demo';
5151
import {TypographyDemo} from '../typography/typography-demo';
5252
import {DemoApp, Home} from './demo-app';
53-
import {TableDemoPage} from '../table/table-demo-page';
54-
import {TABLE_DEMO_ROUTES} from '../table/routes';
5553
import {BadgeDemo} from '../badge/badge-demo';
5654
import {ConnectedOverlayDemo} from '../connected-overlay/connected-overlay-demo';
5755
import {PaginatorDemo} from '../paginator/paginator-demo';
5856

5957
import {ExamplesPage} from '../examples-page/examples-page';
58+
import {TableDemo} from '../table/table-demo';
6059

6160
export const DEMO_APP_ROUTES: Routes = [
6261
{path: '', component: DemoApp, children: [
@@ -96,7 +95,7 @@ export const DEMO_APP_ROUTES: Routes = [
9695
{path: 'slider', component: SliderDemo},
9796
{path: 'snack-bar', component: SnackBarDemo},
9897
{path: 'stepper', component: StepperDemo},
99-
{path: 'table', component: TableDemoPage, children: TABLE_DEMO_ROUTES},
98+
{path: 'table', component: TableDemo},
10099
{path: 'tabs', component: TabsDemo, children: TABS_DEMO_ROUTES},
101100
{path: 'toolbar', component: ToolbarDemo},
102101
{path: 'tooltip', component: TooltipDemo},

src/demo-app/example/example-list.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,46 @@
88

99
import {Component, Input} from '@angular/core';
1010
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
11+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
1112

1213
/** Displays a set of material examples in a mat-accordion. */
1314
@Component({
1415
selector: 'material-example-list',
1516
template: `
16-
<h2> {{type}} Examples </h2>
17-
<mat-accordion>
18-
<mat-expansion-panel *ngFor="let id of ids">
17+
<mat-accordion multi>
18+
<mat-expansion-panel *ngFor="let id of ids" [expanded]="expandAll">
1919
<mat-expansion-panel-header>
20-
{{id}}: {{exampleComponents[id].title}}
20+
<div class="header">
21+
<div class="title"> {{exampleComponents[id]?.title}} </div>
22+
<div class="id"> <{{id}}> </div>
23+
</div>
2124
</mat-expansion-panel-header>
25+
2226
<ng-template matExpansionPanelContent>
2327
<material-example [id]="id"></material-example>
2428
</ng-template>
2529
</mat-expansion-panel>
2630
</mat-accordion>
2731
`,
2832
styles: [`
29-
h2 {
30-
text-transform: capitalize;
33+
mat-expansion-panel {
34+
box-shadow: none !important;
35+
background: transparent;
36+
border-top: 1px solid #CCC;
37+
}
38+
39+
.header {
40+
display: flex;
41+
justify-content: space-between;
42+
width: 100%;
43+
padding-right: 24px;
44+
align-items: center;
45+
}
46+
47+
.id {
48+
font-family: monospace;
49+
color: #666;
50+
font-size: 12px;
3151
}
3252
`]
3353
})
@@ -38,5 +58,10 @@ export class ExampleList {
3858
/** IDs of the examples to display. */
3959
@Input() ids: string[];
4060

61+
@Input()
62+
set expandAll(v: boolean) { this._expandAll = coerceBooleanProperty(v); }
63+
get expandAll(): boolean { return this._expandAll; }
64+
_expandAll: boolean;
65+
4166
exampleComponents = EXAMPLE_COMPONENTS;
4267
}

src/demo-app/example/example.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,59 @@
77
*/
88

99
import {Component, ElementRef, Input} from '@angular/core';
10+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
11+
import {EXAMPLE_COMPONENTS} from '@angular/material-examples';
1012

1113
@Component({
1214
selector: 'material-example',
13-
template: '',
15+
template: `
16+
<div class="label" *ngIf="showLabel">
17+
<span class="title"> {{title}} </span>
18+
<span class="id"> <{{id}}> </span>
19+
</div>
20+
21+
<div *ngIf="!id">
22+
Could not find example {{id}}
23+
</div>
24+
`,
25+
styles: [`
26+
.label {
27+
display: flex;
28+
justify-content: space-between;
29+
align-items: flex-end;
30+
margin: 16px 0;
31+
}
32+
33+
.title {
34+
font-size: 20px;
35+
font-weight: 500;
36+
}
37+
38+
.id {
39+
font-size: 13px;
40+
font-family: monospace;
41+
color: #666;
42+
white-space: pre;
43+
}
44+
`]
1445
})
1546
export class Example {
1647
/** ID of the material example to display. */
1748
@Input() id: string;
1849

50+
@Input()
51+
set showLabel(v: boolean) { this._showLabel = coerceBooleanProperty(v); }
52+
get showLabel(): boolean { return this._showLabel; }
53+
_showLabel: boolean;
54+
55+
title: string;
56+
1957
constructor(private elementRef: ElementRef) { }
2058

2159
ngOnInit() {
2260
const element = document.createElement(this.id);
2361
this.elementRef.nativeElement.appendChild(element);
62+
63+
this.title = EXAMPLE_COMPONENTS[this.id] ? EXAMPLE_COMPONENTS[this.id].title : '';
2464
}
2565
}

src/demo-app/table/custom-table/custom-table.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88

99
import {Component, ViewChild} from '@angular/core';
1010
import {MatSort, MatTableDataSource} from '@angular/material';
11-
import {PeriodicElement, ELEMENT_DATA} from '../element-data';
11+
import {Element, ELEMENT_DATA} from '../element-data';
1212

1313

1414
@Component({
1515
moduleId: module.id,
16+
selector: 'custom-table-demo',
1617
templateUrl: 'custom-table.html',
1718
styleUrls: ['custom-table.css'],
1819
})
1920
export class CustomTableDemo {
2021
columnsToDisplay = ['name', 'weight', 'symbol', 'position'];
21-
simpleTableDataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
22-
wrapperTableDataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
23-
getWeight = (data: PeriodicElement) => '~' + data.weight;
22+
simpleTableDataSource = new MatTableDataSource<Element>(ELEMENT_DATA);
23+
wrapperTableDataSource = new MatTableDataSource<Element>(ELEMENT_DATA);
24+
getWeight = (data: Element) => '~' + data.weight;
2425

2526
@ViewChild('simpleTableSort') simpleTableSort: MatSort;
2627
@ViewChild('wrapperTableSort') wrapperTableSort: MatSort;

src/demo-app/table/data-input-table/data-input-table.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Component, ViewChild} from '@angular/core';
10-
import {PeriodicElement, ELEMENT_DATA} from '../element-data';
10+
import {Element, ELEMENT_DATA} from '../element-data';
1111
import {CdkTable} from '@angular/cdk/table';
1212
import {MatRadioChange, MatTable, MatTableDataSource} from '@angular/material';
1313
import {Observable} from 'rxjs';
@@ -17,6 +17,7 @@ export type TrackByStrategy = 'position' | 'reference' | 'index';
1717

1818
@Component({
1919
moduleId: module.id,
20+
selector: 'data-input-table-demo',
2021
templateUrl: 'data-input-table.html',
2122
styleUrls: ['data-input-table.css'],
2223
})
@@ -28,18 +29,18 @@ export class DataInputTableDemo {
2829
matTableDataSource = new MatTableDataSource(this.data);
2930

3031
trackByStrategy: TrackByStrategy = 'reference';
31-
trackBy = (index: number, item: PeriodicElement) => {
32+
trackBy = (index: number, item: Element) => {
3233
switch (this.trackByStrategy) {
3334
case 'position': return item.position;
3435
case 'reference': return item;
3536
case 'index': return index;
3637
}
3738
}
3839

39-
dataSource: DataSource<PeriodicElement> | Observable<PeriodicElement[]> | PeriodicElement[] | null = this.data;
40+
dataSource: DataSource<Element> | Observable<Element[]> | Element[] | null = this.data;
4041

41-
@ViewChild(CdkTable) cdkTable: CdkTable<PeriodicElement>;
42-
@ViewChild(MatTable) matTable: MatTable<PeriodicElement>;
42+
@ViewChild(CdkTable) cdkTable: CdkTable<Element>;
43+
@ViewChild(MatTable) matTable: MatTable<Element>;
4344

4445
changeInput(e: MatRadioChange) {
4546
this.inputType = e.value;

src/demo-app/table/dynamic-columns/dynamic-columns.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/demo-app/table/dynamic-columns/dynamic-columns.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/demo-app/table/element-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
export interface PeriodicElement {
9+
export interface Element {
1010
position: number;
1111
name: string;
1212
weight: number;
1313
symbol: string;
1414
}
1515

16-
export const ELEMENT_DATA: PeriodicElement[] = [
16+
export const ELEMENT_DATA: Element[] = [
1717
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
1818
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
1919
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},

src/demo-app/table/mat-table-data-source/mat-table-data-source.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/demo-app/table/mat-table-data-source/mat-table-data-source.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)