File

src/theme/theme.directive.ts

Description

Applies theme styles to the div container it is applied to. Get started with importing the module:

Example :
import { ThemeModule } from 'carbon-components-angular';

See demo

Implements

AfterContentChecked

Metadata

Index

Properties
Methods
Inputs
HostBindings
Accessors

Inputs

cdsTheme
Type : ThemeType | string
Default value : "white"

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

ibmTheme
Type : ThemeType | string

HostBindings

class.cds--g10
Type : boolean
class.cds--g100
Type : boolean
class.cds--g90
Type : boolean
class.cds--layer-one
Type : boolean
Default value : true
class.cds--white
Type : boolean

Using host bindings with classes to ensure we do not overwrite user added classes

Methods

ngAfterContentChecked
ngAfterContentChecked()
Returns : void

Properties

layerChildren
Type : QueryList<LayerDirective>
Decorators :
@ContentChildren(LayerDirective, {descendants: false})
layerClass
Default value : true
Decorators :
@HostBinding('class.cds--layer-one')

Accessors

ibmTheme
setibmTheme(type: ThemeType | string)
Parameters :
Name Type Optional
type ThemeType | string No
Returns : void
whiteThemeClass
getwhiteThemeClass()

Using host bindings with classes to ensure we do not overwrite user added classes

g10ThemeClass
getg10ThemeClass()
g90ThemeClass
getg90ThemeClass()
g100ThemeClass
getg100ThemeClass()
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;
			}
		});
	}
}

results matching ""

    No results matching ""