File

src/tag/tag-selectable.component.ts

Metadata

Index

Properties
Methods
Inputs
Outputs
HostBindings
HostListeners
Accessors

Inputs

class
Type : string
Default value : ""
disabled
Type : boolean
Default value : false
selected
Type : boolean
Default value : false
size
Type : "sm" | "md" | "lg"
Default value : "md"
skeleton
Type : boolean
Default value : false

Outputs

selectedChange
Type : EventEmitter

HostBindings

attr.aria-pressed
Type : boolean
attr.class
Type : string
attr.role
Type : string
Default value : "button"
attr.tabindex
Type : number
Default value : 0
attr.type
Type : string
Default value : "button"

HostListeners

click
click()

Methods

onClick
onClick()
Decorators :
@HostListener('click')
Returns : void

Properties

buttonType
Type : string
Default value : "button"
Decorators :
@HostBinding('attr.type')
role
Type : string
Default value : "button"
Decorators :
@HostBinding('attr.role')
tabIndex
Type : number
Default value : 0
Decorators :
@HostBinding('attr.tabindex')

Accessors

ariaPressed
getariaPressed()
attrClass
getattrClass()

Remove cds--tag--${this.size} in v7

import {
	ChangeDetectionStrategy,
	Component,
	EventEmitter,
	HostBinding,
	HostListener,
	Input,
	Output
} from "@angular/core";

@Component({
	selector: "cds-tag-selectable, ibm-tag-selectable",
	template: `
		<ng-container *ngIf="!skeleton">
			<ng-content select="[cdsTagIcon],[ibmTagIcon]"></ng-content>
			<span class="cds--tag__label">
				<ng-content></ng-content>
			</span>
		</ng-container>
	`,
	changeDetection: ChangeDetectionStrategy.OnPush
})
export class TagSelectableComponent {
	@HostBinding("attr.role") role = "button";
	@HostBinding("attr.type") buttonType = "button";
	@HostBinding("attr.tabindex") tabIndex = 0;
	@HostBinding("attr.aria-pressed") get ariaPressed() {
		return this.selected;
	}

	@Input() size: "sm" | "md" | "lg" = "md";
	@Input() skeleton = false;
	@Input() disabled = false;
	@Input() class = "";
	@Input() selected = false;

	@Output() selectedChange = new EventEmitter<boolean>();

	@HostListener("click")
	onClick() {
		this.selected = !this.selected;
		this.selectedChange.emit(this.selected);
	}

	/**
	 * @todo
	 * Remove `cds--tag--${this.size}` in v7
	 */
	@HostBinding("attr.class") get attrClass() {
		const disabledClass = this.disabled ? "cds--tag--disabled" : "";
		const sizeClass = `cds--tag--${this.size} cds--layout--size-${this.size}`;
		const skeletonClass = this.skeleton ? "cds--skeleton" : "";
		const selectedClass = this.selected ? "cds--tag--selectable-selected" : "";

		return `cds--tag cds--tag--selectable ${selectedClass} ${disabledClass} ${sizeClass} ${skeletonClass} ${this.class}`;
	}
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""