Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 08ee4b1

Browse files
committed
feat: add version and version picker
1 parent 31ea36e commit 08ee4b1

File tree

9 files changed

+74
-13
lines changed

9 files changed

+74
-13
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
"private": true,
2121
"dependencies": {
2222
"@angular/animations": "^5.2.1",
23-
"@angular/cdk": "^5.2.1",
23+
"@angular/cdk": "^5.2.4",
2424
"@angular/common": "^5.2.1",
2525
"@angular/compiler": "^5.2.1",
2626
"@angular/core": "^5.2.1",
2727
"@angular/forms": "^5.2.1",
2828
"@angular/http": "^5.2.1",
29-
"@angular/material": "^5.2.1",
30-
"@angular/material-moment-adapter": "^5.2.1",
29+
"@angular/material": "^5.2.4",
30+
"@angular/material-moment-adapter": "^5.2.4",
3131
"@angular/platform-browser": "^5.2.1",
3232
"@angular/platform-browser-dynamic": "^5.2.1",
3333
"@angular/router": "^5.2.1",

src/app/shared/footer/footer.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import {Component, NgModule} from '@angular/core';
2-
import {VERSION} from '@angular/material';
2+
import {materialVersion} from '../version/version'
33

44
@Component({
55
selector: 'app-footer',
66
templateUrl: './footer.html',
77
styleUrls: ['./footer.scss']
88
})
99
export class Footer {
10-
get version() {
11-
const version = VERSION.full.match(/\d+\.\d+\.\d+/);
12-
if (version) {
13-
return version[0];
14-
}
15-
return '';
16-
}
10+
version = materialVersion;
1711
}
1812

1913

src/app/shared/navbar/navbar.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
[routerLink]="key">{{sections[key]}}</a>
1212
<a mat-button class="docs-navbar-hide-small docs-button" routerLink="guides">Guides</a>
1313
<div class="flex-spacer"></div>
14+
<!-- TODO(tinayuangao): Uncomment this when we are ready for v6
15+
<version-picker></version-picker>
16+
-->
1417
<theme-picker></theme-picker>
1518
<a mat-button class="docs-button docs-navbar-hide-small" href="https://github.com/angular/material2"
1619
aria-label="GitHub Repository">

src/app/shared/navbar/navbar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {CommonModule} from '@angular/common';
33
import {MatButtonModule, MatMenuModule} from '@angular/material';
44
import {RouterModule} from '@angular/router';
55
import {ThemePickerModule} from '../theme-picker/theme-picker';
6+
import {VersionPickerModule} from '../version-picker';
67
import {SECTIONS} from '../documentation-items/documentation-items';
78

89
const SECTIONS_KEYS = Object.keys(SECTIONS);
@@ -23,7 +24,7 @@ export class NavBar {
2324
}
2425

2526
@NgModule({
26-
imports: [MatButtonModule, MatMenuModule, RouterModule, ThemePickerModule, CommonModule],
27+
imports: [MatButtonModule, MatMenuModule, RouterModule, ThemePickerModule, VersionPickerModule, CommonModule],
2728
exports: [NavBar],
2829
declarations: [NavBar],
2930
})

src/app/shared/stackblitz/stackblitz-writer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {Http} from '@angular/http';
33
import {ExampleData} from '@angular/material-examples';
44
import {VERSION} from '@angular/material';
55

6+
import {materialVersion} from '../version/version';
7+
68
const STACKBLITZ_URL = 'https://run.stackblitz.com/api/angular/v1';
79

810
const COPYRIGHT =
@@ -21,7 +23,6 @@ const TEMPLATE_FILES = [
2123

2224
const TAGS: string[] = ['angular', 'material', 'example'];
2325
const angularVersion = '^5.0.0';
24-
const materialVersion = '5.2.1';
2526

2627
const dependencies = {
2728
'@angular/cdk': materialVersion,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './version-picker';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<button mat-button [matMenuTriggerFor]="versionPicker">
2+
{{materialVersion}}
3+
</button>
4+
<mat-menu #versionPicker="matMenu">
5+
<button mat-menu-item *ngFor="let version of docVersions"
6+
(click)="onVersionChanged(version)">
7+
{{version.title}}
8+
</button>
9+
</mat-menu>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {Component, NgModule} from '@angular/core';
2+
import {CommonModule} from '@angular/common';
3+
import {MatButtonModule, MatMenuModule} from '@angular/material';
4+
import {docVersions, materialVersion, VersionInfo} from '../version/version'
5+
6+
@Component({
7+
selector: 'version-picker',
8+
templateUrl: './version-picker.html'
9+
})
10+
export class VersionPicker {
11+
docVersions = docVersions;
12+
13+
materialVersion = materialVersion;
14+
15+
displayVersion = materialVersion.match(/\d+.\d+.\d+/)[0];
16+
17+
onVersionChanged(version: VersionInfo) {
18+
if (version.title.match(/\d+.\d+.\d+/)[0] !== this.displayVersion) {
19+
window.location.assign(version.url);
20+
}
21+
}
22+
}
23+
24+
@NgModule({
25+
imports: [MatButtonModule, MatMenuModule, CommonModule],
26+
exports: [VersionPicker],
27+
declarations: [VersionPicker]
28+
})
29+
export class VersionPickerModule {}

src/app/shared/version/version.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {VERSION} from '@angular/material';
2+
3+
/** This material version will be used in footer and stackblitz. */
4+
export const materialVersion = VERSION.full;
5+
6+
/** Version information with title and redirect url */
7+
export interface VersionInfo {
8+
url: string;
9+
title: string;
10+
}
11+
12+
/** Doc site versions. We update the urls and titles manually */
13+
// TODO(tinayuangao): Update the url with material.angular.io domain
14+
export const docVersions: VersionInfo[] = [
15+
{
16+
url: 'https://material2-docs-5.firebaseapp.com/',
17+
title: '5.2.4'
18+
},
19+
{
20+
url: `http://material2-docs-dev.firebaseapp.com`,
21+
title: '6.0.0-beta.4'
22+
}
23+
];

0 commit comments

Comments
 (0)