-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdc5f86
commit 99c2162
Showing
21 changed files
with
124 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
demo/src/app/components/collapse/demos/navbar/collapse-navbar.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { NgFor } from '@angular/common'; | ||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
interface Theme { | ||
id: string; | ||
name: string; | ||
icon: string; | ||
} | ||
|
||
@Component({ | ||
selector: 'ngbd-demo-theme', | ||
standalone: true, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [NgFor, NgbDropdownModule], | ||
template: ` | ||
<div class="nav-item" ngbDropdown> | ||
<a class="nav-link" ngbDropdownToggle id="demo-site-theme" role="button"> | ||
<span class="bi bi-{{ currentTheme.icon }}"></span> | ||
</a> | ||
<div ngbDropdownMenu aria-labelledby="demo-site-theme" class="dropdown-menu dropdown-menu-end"> | ||
<button | ||
ngbDropdownItem | ||
*ngFor="let theme of themes" | ||
[class.active]="theme.id === currentTheme.id" | ||
(click)="setTheme(theme)" | ||
> | ||
<span class="bi bi-{{ theme.icon }} me-2"></span>{{ theme.name }} | ||
</button> | ||
</div> | ||
</div> | ||
`, | ||
}) | ||
export class NgbdDemoThemeComponent { | ||
themes: Theme[] = [ | ||
{ id: 'auto', name: 'Auto', icon: 'circle-half' }, | ||
{ id: 'light', name: 'Light', icon: 'sun-fill' }, | ||
{ id: 'dark', name: 'Dark', icon: 'moon-stars-fill' }, | ||
]; | ||
currentTheme: Theme = { id: 'auto', name: 'auto', icon: 'circle-half' }; | ||
|
||
constructor() { | ||
const theme = this.themes.find((t) => t.id === localStorage.getItem('theme')); | ||
if (theme) { | ||
this.currentTheme = theme; | ||
} | ||
this.setTheme(this.getPreferredTheme()); | ||
|
||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { | ||
if (this.currentTheme.id !== 'light' || this.currentTheme.id !== ('dark' as any)) { | ||
this.setTheme(this.getPreferredTheme()); | ||
} | ||
}); | ||
} | ||
|
||
getPreferredTheme(): Theme { | ||
if (this.currentTheme) { | ||
return this.currentTheme; | ||
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
return this.themes.find((t) => t.id === 'dark')!; | ||
} else { | ||
return this.themes.find((t) => t.id === 'light')!; | ||
} | ||
} | ||
|
||
setTheme(theme: Theme): void { | ||
this.currentTheme = theme; | ||
localStorage.setItem('theme', theme.id); | ||
if (theme.id === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
document.documentElement.setAttribute('data-bs-theme', 'dark'); | ||
} else { | ||
document.documentElement.setAttribute('data-bs-theme', theme.id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.