Skip to content

Instantly share code, notes, and snippets.

@phroggyy
Created November 29, 2018 11:49
Show Gist options
  • Save phroggyy/73c1fe6128225f371639306c802130bb to your computer and use it in GitHub Desktop.
Save phroggyy/73c1fe6128225f371639306c802130bb to your computer and use it in GitHub Desktop.
@Directive({
selector: '[hsThemed]',
})
export class ThemedDirective implements OnInit {
@Input() lightClass = '';
@Input() darkClass = '';
constructor(private el: ElementRef, private themingService: ThemingService) {
}
ngOnInit() {
if (this.themingService.isDarkTheme() && this.darkClass && this.darkClass.length) {
(this.el.nativeElement as HTMLElement).classList.add(...this.darkClass.split(' '));
}
if (this.themingService.isLightTheme() && this.lightClass && this.lightClass.length) {
(this.el.nativeElement as HTMLElement).classList.add(...this.lightClass.split(' '));
}
(this.el.nativeElement as HTMLElement).classList.add(`theme--${this.themingService.currentTheme}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment