
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
angular-dark-mode
Advanced tools
angular-dark-mode is a zero-dependency library that helps you integrate dark mode into you Angular applications with ease!
Inspired by the awesome use-dark-mode library
To use angular-dark-mode in your project install it via npm:
npm i angular-dark-mode
or if you are using yarn:
yarn add angular-dark-mode
and add angular-dark-mode.js file to angular.json scripts section:
{
"scripts": ["./node_modules/angular-dark-mode/angular-dark-mode.js"]
}
if you are using custom configuration see angular-dark-mode.js
In order to use angular-dark-mode you need to inject the service somewhere in your applications - presumably where you hold the dark mode toggle, and get the dark mode value from the exported darkMode$ Observable:
// dark-mode-toggle.component.ts
@Component({
selector: 'app-dark-mode-toggle',
template: `<input
type="checkbox"
[checked]="darkMode$ | async"
(change)="onToggle()"
/>`,
})
export class DarkModeToggle {
darkMode$: Observable<boolean> = this.darkModeService.darkMode$;
constructor(private darkModeService: DarkModeService) {}
onToggle(): void {
this.darkModeService.toggle();
}
}
Next, include global styles and some text to reflect the mode:
/* styles.css */
body.dark-mode {
background-color: #2d3436;
color: #dfe6e9;
}
body.light-mode {
background-color: #dfe6e9;
color: #2d3436;
}
// app.component.ts
@Component({
selector: 'app-root',
template: `
<h1>angular-dark-mode</h1>
<p>Toggle to see magic happens!</p>
<app-dark-mode-toggle></app-dark-mode-toggle>
`,
})
export class AppComponent {}
You're all set!
Save and run your application, play with the toggle button to change between modes.
angular-dark-mode ships with the following options:
| Option | Description | Default Value |
|---|---|---|
| darkModeClass | dark mode css class name | 'dark-mode' |
| lightModeClass | light mode css class name | 'light-mode' |
| preloadingClass | css class name to flag that element is in preloading state | 'dark-mode-preloading' |
| storageKey | localStorage key to persist dark mode | 'dark-mode' |
| element | target HTMLElement to set given css classes | document.body |
All options are set to default and can be configured via the DARK_MODE_OPTIONS InjectionToken:
import { DARK_MODE_OPTIONS } from 'angular-dark-mode';
@NgModule({
...
providers: [
{
provide: DARK_MODE_OPTIONS,
useValue: {
darkModeClass: 'my-dark-mode',
lightModeClass: 'my-light-mode'
}
}
]
...
})
export class AppModule {}
This file has multiple purposes:
localStorage if empty falls back to (prefers-color-scheme: dark) media querypreloadingClass to document.body which can be used to prevent initial transitioningIf you are using the default configurations, adding the angular-dark-mode.js file bundled with this library is enough.
In any other case, copy angular-dark-mode.js locally, make the necessary changes and load it instead of the bundled one.
It is often useful to transition the changes between dark and light modes, and most of the time we would want to skip the initial transition, in order to achieve this use the preloadingClass option like so:
/* styles.css */
...
body:not(.dark-mode-preloading) {
transition: all 0.3s linear;
}
...
Thanks goes to these wonderful people emoji key:
Tal Ohana 💻 📖 🚧 | Guy Shemesh 🎨 |
FAQs
Add dark mode to your Angular applications with ease!
The npm package angular-dark-mode receives a total of 342 weekly downloads. As such, angular-dark-mode popularity was classified as not popular.
We found that angular-dark-mode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.