Skip to content

Commit

Permalink
feat(docs): storing theme and active color (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Margar1ta authored and pimenovoleg committed Oct 2, 2019
1 parent 1b6b017 commit f59f04a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/docs/src/app/components/anchors/anchors.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export class AnchorsComponent {
this.debounceTime = this.noSmoothScrollDebounce;
}
this.currentUrl = router.url.split('#')[0];
localStorage.setItem('PT_nextRoute', this.currentUrl);
this.container = '.anchors-menu';
this.pathName = this.router.url;
this.router.events.pipe(takeUntil(this.destroyed)).subscribe((event) => {
if (event instanceof NavigationEnd) {
const rootUrl = router.url.split('#')[0];

if (rootUrl !== this.currentUrl) {
localStorage.setItem('PT_nextRoute', rootUrl);
this.currentUrl = rootUrl;
this.pathName = this.router.url;
}
Expand Down
29 changes: 28 additions & 1 deletion packages/docs/src/app/components/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ export class NavbarComponent {
}
];
activeColor = this.colors[0];
private readonly themeProperty = 'PT_theme';
private readonly colorProperty = 'PT_color';

constructor(private renderer: Renderer2) {}
constructor(private renderer: Renderer2) {
this.initTheme();
this.initActiveColor();
}

setVersion(version) {
this.curVerIndex = version;
Expand All @@ -71,17 +76,39 @@ export class NavbarComponent {

setTheme(i) {
this.curTheme = this.themes[i];
localStorage.setItem(this.themeProperty, `${i}`);
this.changeThemeOnBody();
}

setColor(i) {
this.activeColor = this.colors[i];
localStorage.setItem(this.colorProperty, `${i}`);
this.changeColorOnBody();

this.colors.forEach((color) => { color.selected = false; });
this.colors[i].selected = true;
}

initTheme() {
const theme = localStorage.getItem(this.themeProperty);

if (theme) {
this.setTheme(theme);
} else {
localStorage.setItem(this.themeProperty, '0');
}
}

initActiveColor() {
const color = localStorage.getItem(this.colorProperty);

if (color) {
this.setColor(color);
} else {
localStorage.setItem(this.colorProperty, '0');
}
}

private changeThemeOnBody() {

if (this.curTheme) {
Expand Down
4 changes: 4 additions & 0 deletions packages/docs/src/app/components/navbar/navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ $doc-navbar-padding: 10px;
};
}

&_hidden {
visibility: hidden;
}

&__icon { color: inherit; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<div class="flex-spacer"></div>

<div class="docs-navbar-dropdown">
<div class="docs-navbar-dropdown docs-navbar-dropdown_hidden">
<button mc-button color="second" class="mc-button mc-button_transparent docs-navbar-dropdown__trigger"
[mcDropdownTriggerFor]="languageDropdown">
<span >{{curLanguage}}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
mcTooltip
mcTitle="Содержимое скопировано в буфер обмена"
mcTrigger="manual"
mcMouseEnterDelay = "20"
mcPlacement="bottom"></i>
</span>
<mc-tab-group mc-light-tabs (selectedTabChange)="setLineNumbers()">
Expand Down

0 comments on commit f59f04a

Please sign in to comment.