src/theme/theme.directive.ts
Applies theme styles to the div container it is applied to. Get started with importing the module:
Example :import { ThemeModule } from 'carbon-components-angular';
AfterContentChecked
Selector | [cdsTheme], [ibmTheme] |
exportAs | theme |
Properties |
Methods |
Inputs |
HostBindings |
Accessors |
cdsTheme | |
Type : ThemeType | string
|
|
Default value : "white"
|
|
Defined in src/theme/theme.directive.ts:39
|
|
Sets the theme for the content
Accepts |
ibmTheme | |
Type : ThemeType | string
|
|
Defined in src/theme/theme.directive.ts:30
|
class.cds--g10 |
Type : boolean
|
Defined in src/theme/theme.directive.ts:51
|
class.cds--g100 |
Type : boolean
|
Defined in src/theme/theme.directive.ts:59
|
class.cds--g90 |
Type : boolean
|
Defined in src/theme/theme.directive.ts:55
|
class.cds--layer-one |
Type : boolean
|
Default value : true
|
Defined in src/theme/theme.directive.ts:63
|
class.cds--white |
Type : boolean
|
Defined in src/theme/theme.directive.ts:47
|
Using host bindings with classes to ensure we do not overwrite user added classes |
ngAfterContentChecked |
ngAfterContentChecked()
|
Defined in src/theme/theme.directive.ts:65
|
Returns :
void
|
layerChildren |
Type : QueryList<LayerDirective>
|
Decorators :
@ContentChildren(LayerDirective, {descendants: false})
|
Defined in src/theme/theme.directive.ts:41
|
layerClass |
Default value : true
|
Decorators :
@HostBinding('class.cds--layer-one')
|
Defined in src/theme/theme.directive.ts:63
|
ibmTheme | ||||||
setibmTheme(type: ThemeType | string)
|
||||||
Defined in src/theme/theme.directive.ts:30
|
||||||
Parameters :
Returns :
void
|
whiteThemeClass |
getwhiteThemeClass()
|
Defined in src/theme/theme.directive.ts:47
|
Using host bindings with classes to ensure we do not overwrite user added classes |
g10ThemeClass |
getg10ThemeClass()
|
Defined in src/theme/theme.directive.ts:51
|
g90ThemeClass |
getg90ThemeClass()
|
Defined in src/theme/theme.directive.ts:55
|
g100ThemeClass |
getg100ThemeClass()
|
Defined in src/theme/theme.directive.ts:59
|
import {
AfterContentChecked,
ContentChildren,
Directive,
HostBinding,
Input,
QueryList
} from "@angular/core";
import { LayerDirective } from "carbon-components-angular/layer";
export type ThemeType = "white" | "g10" | "g90" | "g100";
/**
* Applies theme styles to the div container it is applied to. Get started with importing the module:
*
* ```typescript
* import { ThemeModule } from 'carbon-components-angular';
* ```
*
* [See demo](../../?path=/story/components-theme--basic)
*/
@Directive({
selector: "[cdsTheme], [ibmTheme]",
exportAs: "theme"
})
export class ThemeDirective implements AfterContentChecked {
/**
* @deprecated as of v5 - Use `cdsTheme` input property instead
*/
@Input() set ibmTheme(type: ThemeType | "") {
this.cdsTheme = type;
}
/**
* Sets the theme for the content
* Accepts `ThemeType` or nothing (empty string which is equivalent to "white")
* Empty string has been added as an option for Angular 16+ to resolve type errors
*/
@Input() cdsTheme: ThemeType | "" = "white";
@ContentChildren(LayerDirective, { descendants: false }) layerChildren: QueryList<LayerDirective>;
/**
* Using host bindings with classes to ensure we do not
* overwrite user added classes
*/
@HostBinding("class.cds--white") get whiteThemeClass() {
return this.cdsTheme === "white" || !this.cdsTheme;
}
@HostBinding("class.cds--g10") get g10ThemeClass() {
return this.cdsTheme === "g10";
}
@HostBinding("class.cds--g90") get g90ThemeClass() {
return this.cdsTheme === "g90";
}
@HostBinding("class.cds--g100") get g100ThemeClass() {
return this.cdsTheme === "g100";
}
@HostBinding("class.cds--layer-one") layerClass = true;
ngAfterContentChecked(): void {
/**
* Resets next layer level in theme
* If not found, the layer will be 1 by default
*/
this.layerChildren.toArray().forEach(layer => {
if (typeof layer.cdsLayer !== "number") {
layer.cdsLayer = 1;
}
});
}
}