Skip to content

feat(docs): storing theme and active color #274

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

на будущее: подумай, ты можешь эти два метода свернуть в один с аргументами.

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