src/ui-shell/panel/switcher-list-item.component.ts
Represents an item in a switcher list.
| selector | cds-switcher-list-item, ibm-switcher-list-item |
| template | |
Properties |
Methods |
Inputs |
Outputs |
HostBindings |
Accessors |
constructor(domSanitizer: DomSanitizer, router: Router)
|
|||||||||
|
Parameters :
|
| active | |
Type : boolean
|
|
Default value : false
|
|
|
Enables the "active" state for an item. Commonly used to indicate the current page or selection. |
|
| href | |
Type : string
|
|
|
Optional link for the underlying anchor. |
|
| route | |
Type : any[]
|
|
|
Array of commands to send to the router when the link is activated See: https://angular.io/api/router/Router#navigate |
|
| routeExtras | |
Type : any
|
|
|
Router options. Used in conjunction with |
|
| target | |
Type : string
|
|
|
Optional target for the underlying anchor. |
|
| navigation | |
Type : EventEmitter
|
|
|
Emits the navigation status promise when the link is activated |
|
| attr.role |
Type : string
|
Default value : "listitem"
|
| class.cds--switcher__item |
Type : boolean
|
Default value : true
|
| navigate | ||||
navigate(event)
|
||||
|
Parameters :
Returns :
void
|
| Protected _href |
Type : string
|
Default value : "#"
|
| Protected _target |
Type : string
|
Default value : ""
|
| itemClass |
Default value : true
|
Decorators :
@HostBinding('class.cds--switcher__item')
|
| itemRole |
Type : string
|
Default value : "listitem"
|
Decorators :
@HostBinding('attr.role')
|
| href | ||||||
gethref()
|
||||||
sethref(value: string)
|
||||||
|
Optional link for the underlying anchor.
Parameters :
Returns :
void
|
| target | ||||||
gettarget()
|
||||||
settarget(value: string)
|
||||||
|
Optional target for the underlying anchor.
Parameters :
Returns :
void
|
import {
Component,
Input,
Output,
EventEmitter,
Optional,
HostBinding
} from "@angular/core";
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";
import { Router } from "@angular/router";
/**
* Represents an item in a switcher list.
*/
@Component({
selector: "cds-switcher-list-item, ibm-switcher-list-item",
template: `
<a
class="cds--switcher__item-link"
[ngClass]="{
'cds--switcher__item-link--selected': active
}"
[href]="href"
[target]="target"
(click)="navigate($event)">
<ng-content></ng-content>
</a>
`
})
export class SwitcherListItem {
/**
* Enables the "active" state for an item. Commonly used to indicate the current page or selection.
*/
@Input() active = false;
/**
* Array of commands to send to the router when the link is activated
* See: https://angular.io/api/router/Router#navigate
*/
@Input() route: any[];
/**
* Router options. Used in conjunction with `route`
* See: https://angular.io/api/router/Router#navigate
*/
@Input() routeExtras: any;
/**
* Optional link for the underlying anchor.
*/
@Input() set href(value: string) {
this._href = value;
}
/**
* Emits the navigation status promise when the link is activated
*/
@Output() navigation = new EventEmitter<Promise<boolean>>();
get href() {
return this.domSanitizer.bypassSecurityTrustUrl(this._href) as string;
}
/**
* Optional target for the underlying anchor.
*/
@Input() set target(value: string) {
this._target = value;
}
get target() {
return this._target;
}
@HostBinding("class.cds--switcher__item") itemClass = true;
@HostBinding("attr.role") itemRole = "listitem";
protected _href = "#";
protected _target = "";
constructor(protected domSanitizer: DomSanitizer, @Optional() protected router: Router) { }
navigate(event) {
if (this.router && this.route) {
event.preventDefault();
const status = this.router.navigate(this.route, this.routeExtras);
this.navigation.emit(status);
} else if (this._href === "#") {
event.preventDefault();
}
}
}