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

Commit 8bc5c8c

Browse files
committed
feat(theme-picker): provide a visual preview of the theme colors via an SVG
1 parent 4f031fc commit 8bc5c8c

File tree

4 files changed

+105
-7
lines changed

4 files changed

+105
-7
lines changed

src/app/shared/theme-picker/theme-picker.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
<mat-icon>format_color_fill</mat-icon>
44
</button>
55

6-
<mat-menu #themeMenu="matMenu" x-position="before">
6+
<mat-menu #themeMenu="matMenu" xPosition="before" class="theme-picker-menu">
77
<button mat-menu-item *ngFor="let theme of themes" (click)="onThemeSelection(theme.name)">
88
<mat-icon [ngClass]="{'docs-theme-selected-icon': currentTheme === theme}"
99
[color]="currentTheme === theme ? 'accent' : undefined">
1010
{{currentTheme === theme ? 'radio_button_checked' : 'radio_button_unchecked'}}
1111
</mat-icon>
1212
<span>{{theme.displayName}}</span>
13+
<mat-icon [class]="'theme-example-icon ' + theme.name" svgIcon="theme-example"></mat-icon>
1314
</button>
1415
</mat-menu>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.theme-picker-menu {
2+
.mat-menu-item {
3+
.mat-icon.theme-example-icon {
4+
margin-right: 0;
5+
margin-left: 8px;
6+
float: right;
7+
8+
svg {
9+
vertical-align: middle;
10+
}
11+
12+
// The below colors need to align with the themes defined in ThemePicker
13+
&.deeppurple-amber svg {
14+
.theme-icon-background {
15+
fill: #fafafa;
16+
}
17+
.theme-icon-button {
18+
fill: #FFC107;
19+
}
20+
.theme-icon-toolbar {
21+
fill: #673AB7;
22+
}
23+
}
24+
25+
&.indigo-pink svg {
26+
.theme-icon-background {
27+
fill: #fafafa;
28+
}
29+
.theme-icon-button {
30+
fill: #E91E63;
31+
}
32+
.theme-icon-toolbar {
33+
fill: #3F51B5;
34+
}
35+
}
36+
37+
&.pink-bluegrey svg {
38+
.theme-icon-background {
39+
fill: #303030;
40+
}
41+
.theme-icon-button {
42+
fill: #607D8B;
43+
}
44+
.theme-icon-toolbar {
45+
fill: #E91E63;
46+
}
47+
}
48+
49+
&.purple-green svg {
50+
.theme-icon-background {
51+
fill: #303030;
52+
}
53+
.theme-icon-button {
54+
fill: #4CAF50;
55+
}
56+
.theme-icon-toolbar {
57+
fill: #9C27B0;
58+
}
59+
}
60+
}
61+
}
62+
}

src/app/shared/theme-picker/theme-picker.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,33 @@ import {
44
NgModule,
55
OnDestroy,
66
OnInit,
7+
ViewEncapsulation,
78
} from '@angular/core';
89
import {StyleManager} from '../style-manager';
910
import {DocsSiteTheme, ThemeStorage} from './theme-storage/theme-storage';
1011
import {MatButtonModule} from '@angular/material/button';
1112
import {MatGridListModule} from '@angular/material/grid-list';
12-
import {MatIconModule} from '@angular/material/icon';
13+
import {MatIconModule, MatIconRegistry} from '@angular/material/icon';
1314
import {MatMenuModule} from '@angular/material/menu';
1415
import {MatTooltipModule} from '@angular/material/tooltip';
1516
import {CommonModule} from '@angular/common';
1617
import {ActivatedRoute, ParamMap} from '@angular/router';
1718
import {Subscription} from 'rxjs';
1819
import {map} from 'rxjs/operators';
20+
import {DomSanitizer} from '@angular/platform-browser';
1921

2022
@Component({
2123
selector: 'theme-picker',
2224
templateUrl: 'theme-picker.html',
2325
styleUrls: ['theme-picker.scss'],
24-
changeDetection: ChangeDetectionStrategy.OnPush
26+
changeDetection: ChangeDetectionStrategy.OnPush,
27+
encapsulation: ViewEncapsulation.None
2528
})
2629
export class ThemePicker implements OnInit, OnDestroy {
2730
private _queryParamSubscription = Subscription.EMPTY;
2831
currentTheme: DocsSiteTheme;
2932

33+
// The below colors need to align with the themes defined in theme-picker.scss
3034
themes: DocsSiteTheme[] = [
3135
{
3236
primary: '#673AB7',
@@ -59,10 +63,13 @@ export class ThemePicker implements OnInit, OnDestroy {
5963
},
6064
];
6165

62-
constructor(
63-
public styleManager: StyleManager,
64-
private _themeStorage: ThemeStorage,
65-
private _activatedRoute: ActivatedRoute) {
66+
constructor(public styleManager: StyleManager,
67+
private _themeStorage: ThemeStorage,
68+
private _activatedRoute: ActivatedRoute,
69+
iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
70+
iconRegistry.addSvgIcon('theme-example',
71+
sanitizer.bypassSecurityTrustResourceUrl(
72+
'assets/img/theme-demo-icon.svg'));
6673
const themeName = this._themeStorage.getStoredThemeName();
6774
if (themeName) {
6875
this.onThemeSelection(themeName);

src/assets/img/theme-demo-icon.svg

Lines changed: 28 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)