Skip to content

Commit a3b9f8d

Browse files
committed
update: add button to toggle theme in demo-app
* Adds a button to the demo-app toolbar that allows developers to quickly change between dark and light Material themes. This is very useful when building new components or just when confirming that all components work with dark themes.
1 parent f24832c commit a3b9f8d

File tree

6 files changed

+66
-45
lines changed

6 files changed

+66
-45
lines changed

src/demo-app/button/button-demo.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
section {
99
display: flex;
1010
align-items: center;
11-
background-color: #f7f7f7;
1211
margin: 8px;
1312
}
1413

src/demo-app/demo-app/demo-app.html

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
1-
<md-sidenav-container class="demo-root" fullscreen>
2-
<md-sidenav #start>
3-
<md-nav-list>
4-
<a *ngFor="let navItem of navItems"
5-
md-list-item
6-
(click)="start.close()"
7-
[routerLink]="[navItem.route]">
8-
{{navItem.name}}
9-
</a>
1+
<!-- Theme class needs to be applied above sidenav-container to style content background. -->
2+
<div [class.demo-dark-theme]="isDarkTheme">
3+
<md-sidenav-container class="demo-root" fullscreen>
4+
<md-sidenav #start>
5+
<md-nav-list>
6+
<a *ngFor="let navItem of navItems"
7+
md-list-item
8+
(click)="start.close()"
9+
[routerLink]="[navItem.route]">
10+
{{navItem.name}}
11+
</a>
1012

11-
<hr>
13+
<hr>
1214

13-
<a md-list-item
14-
(click)="start.close()"
15-
[routerLink]="['baseline']">
16-
Baseline
17-
</a>
18-
</md-nav-list>
19-
<button md-button (click)="start.close()">CLOSE</button>
20-
</md-sidenav>
21-
<div>
22-
<md-toolbar color="primary">
23-
<button md-icon-button (click)="start.open()">
24-
<md-icon class="md-24" >menu</md-icon>
25-
</button>
26-
<div class="demo-toolbar">
27-
<h1>Angular Material Demos</h1>
28-
<button md-button (click)="toggleFullscreen()" title="Toggle fullscreen">
29-
Fullscreen
15+
<a md-list-item
16+
(click)="start.close()"
17+
[routerLink]="['baseline']">
18+
Baseline
19+
</a>
20+
</md-nav-list>
21+
<button md-button (click)="start.close()">CLOSE</button>
22+
</md-sidenav>
23+
<div>
24+
<md-toolbar color="primary">
25+
<button md-icon-button (click)="start.open()">
26+
<md-icon class="md-24" >menu</md-icon>
3027
</button>
31-
<button md-button (click)="root.dir = (root.dir == 'rtl' ? 'ltr' : 'rtl')" title="Toggle between RTL and LTR">
32-
{{root.dir.toUpperCase()}}
33-
</button>
34-
</div>
35-
</md-toolbar>
28+
<div class="demo-toolbar">
29+
<h1>Angular Material Demos</h1>
30+
<span class="demo-flex-fill"></span>
31+
<button md-button (click)="isDarkTheme = !isDarkTheme">Toggle Theme</button>
32+
<button md-button (click)="toggleFullscreen()" title="Toggle fullscreen">
33+
Fullscreen
34+
</button>
35+
<button md-button (click)="root.dir = (root.dir == 'rtl' ? 'ltr' : 'rtl')" title="Toggle between RTL and LTR">
36+
{{root.dir.toUpperCase()}}
37+
</button>
38+
</div>
39+
</md-toolbar>
3640

37-
<div #root="$implicit" dir="ltr" class="demo-content">
38-
<router-outlet></router-outlet>
41+
<div #root="$implicit" dir="ltr" class="demo-content">
42+
<router-outlet></router-outlet>
43+
</div>
3944
</div>
40-
</div>
41-
</md-sidenav-container>
45+
</md-sidenav-container>
46+
</div>

src/demo-app/demo-app/demo-app.scss

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// The default indigo-pink theme will load through the index file. This makes the SCSS build faster
2+
// since Sass doesn't need to build a "prebuilt" theme again.
3+
@import '../../lib/core/theming/all-theme';
4+
5+
.demo-dark-theme {
6+
// Include core material styles.
7+
@include mat-core();
8+
9+
$primary: mat-palette($mat-indigo);
10+
$accent: mat-palette($mat-pink);
11+
$dark-theme: mat-dark-theme($primary, $accent);
12+
13+
// Include component styles with the given theme.
14+
@include angular-material-theme($dark-theme);
15+
}
16+
117
body {
218
font-family: Roboto, 'Helvetica Neue', sans-serif;
319

@@ -31,7 +47,6 @@ body {
3147

3248
.demo-toolbar {
3349
display: flex;
34-
justify-content: space-between;
3550
width: 100%;
3651
}
3752
}
@@ -41,6 +56,11 @@ body {
4156
}
4257
}
4358

59+
// Fills remaining flex space.
60+
.demo-flex-fill {
61+
flex: 1 1 auto;
62+
}
63+
4464
// stretch to screen size in fullscreen mode
4565
.demo-content {
4666
width: 100%;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export class Home {}
1919
encapsulation: ViewEncapsulation.None,
2020
})
2121
export class DemoApp {
22+
23+
/** Whether the demo-app should use a dark theme or not. */
24+
isDarkTheme: boolean = false;
25+
2226
navItems = [
2327
{name: 'Autocomplete', route: 'autocomplete'},
2428
{name: 'Button', route: 'button'},

src/demo-app/radio/radio-demo.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
}
55

66
.demo-section {
7-
background-color: #f7f7f7;
87
margin: 8px;
98
padding: 16px;
109

src/demo-app/tabs/tabs-demo.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
.demo-nav-bar {
22
border: 1px solid #e0e0e0;
33
margin-bottom: 40px;
4-
.mat-tab-nav-bar {
5-
background: #f9f9f9;
6-
}
74
sunny-routed-content,
85
rainy-routed-content,
96
foggy-routed-content {
@@ -15,9 +12,6 @@
1512
.demo-tab-group {
1613
border: 1px solid #e0e0e0;
1714
margin-bottom: 40px;
18-
.mat-tab-header {
19-
background: #f9f9f9;
20-
}
2115
.mat-tab-body-content {
2216
padding: 12px;
2317
}

0 commit comments

Comments
 (0)