benjamincharity
8/7/2017 - 3:30 PM

Create a base class that will set a theme class on the component.

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,
  ) {}

}