Skip to content

Instantly share code, notes, and snippets.

@benjamincharity
Created August 7, 2017 15:30
Show Gist options
  • Save benjamincharity/5bfbd2274c5b61e483f385454cee2621 to your computer and use it in GitHub Desktop.
Save benjamincharity/5bfbd2274c5b61e483f385454cee2621 to your computer and use it in GitHub Desktop.
Create a base class that will set a theme class on the component.
import {
Component,
Input,
ElementRef,
} from '@angular/core';
import { TsStyleThemeTypes } from './../types/style-theme.types';
/**
* A base class to set a class theme on a component
*/
@Component({
selector: 'ts-theme-base',
})
export class TsThemeBaseComponent {
/**
* Define the button style
*/
@Input() set theme(theme: TsStyleThemeTypes) {
if (!theme) {
return;
}
this.element.nativeElement.classList.add(`u-theme--${theme}`);
};
constructor(
protected element: ElementRef,
) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment