Last active
July 31, 2017 15:48
-
-
Save benjamincharity/9581d4d5c5b7eb0c4a44bf513ed6b835 to your computer and use it in GitHub Desktop.
A method for theming components based off a set list of themes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global material overrides | |
::ng-deep .mat-calendar-body-selected { | |
background-color: color(primary); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global material overrides | |
::ng-deep .mat-focused .mat-input-placeholder { | |
color: color(primary); | |
} | |
::ng-deep .mat-input-ripple { | |
background-color: color(primary); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global material overrides | |
::ng-deep .mat-option.mat-selected.mat-primary, | |
::ng-deep .mat-primary .mat-option.mat-selected { | |
color: color(primary); | |
} | |
// sass-lint:disable force-pseudo-nesting | |
::ng-deep .mat-select:focus:not(.mat-select-disabled).mat-primary .mat-select-trigger { | |
color: color(primary); | |
} | |
::ng-deep .mat-primary .mat-pseudo-checkbox-checked, | |
::ng-deep .mat-primary .mat-pseudo-checkbox-indeterminate, | |
::ng-deep .mat-pseudo-checkbox-checked.mat-primary, | |
::ng-deep .mat-pseudo-checkbox-indeterminate.mat-primary { | |
background: color(primary); | |
} | |
// sass-lint:enable force-pseudo-nesting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
) {} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$theme-and-color: ( | |
'primary': $color__primary, | |
'accent': $color__accent, | |
'error': $color__error, | |
'warn': $color__warn, | |
'highlight': $color__highlight, | |
'pure': $color__pure--light, | |
'utility': $color__utility | |
); | |
/** | |
* Output conditional styles for the possible themes | |
* | |
* @mixin theme-color | |
* @section Functions | |
* @param $property | |
* The CSS property that should be colored. Default: 'background-color' | |
* @example | |
* @include theme-color; | |
* @include theme-color('color'); | |
*/ | |
@mixin theme-color($property: 'background-color') { | |
// Verify an allowed property was passed in | |
@if not(($property == background-color)) and not(($property == color)) { | |
@error 'The `theme__color` mixin only accepts `background-color` or `color`'; | |
} | |
@each $key, $value in $theme-and-color { | |
::ng-deep .u-theme--#{$key} & { | |
#{$property}: $value; | |
@if ($property == 'background-color') and (not(($key == 'pure')) and not(($key == 'highlight'))) { | |
color: $color__pure--light; | |
} | |
@if ($property == 'background-color') and ($key == 'highlight') { | |
color: $color__pure--dark; | |
} | |
&[disabled] { | |
background-color: color(utility, light); | |
color: color(utility); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment