Angular 9 Night Mode Library
A library for adding night-mode to your Angular 9 app.
Features
- Widget appears automatically
- Saving users choice
- Automatically shows Darkmode if the OS prefered theme is dark (if the browsers supports prefers-color-scheme)
- Can be used programmatically without widget
How to Use ngx-darkmode
?
Navigate to your project's folder and run the following command:
$ npm install --save ngx-darkmode
Next, import NgxNightmodeModule
and add it to the imports
array f your app:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NgxNightmodeModule } from 'ngx-nightmode';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgxNightmodeModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Use it
import { Component , OnInit } from '@angular/core';
import { NgxNightmodeService , WidgetOptions } from 'ngx-nightmode';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'demo';
constructor(public nightmodeService: NgxNightmodeService){
}
ngOnInit(): void {
var opts: WidgetOptions = {
bottom: '64px',
right: 'unset',
left: '32px',
time: '0.5s',
mixColor: '#fff',
backgroundColor: '#fff',
buttonColorDark: '#100f2c',
buttonColorLight: '#fff',
saveInCookies: false,
label: '🌓',
autoMatchOsTheme: true
}
this.nightmodeService.showWidget(opts);
}
}