src/ui-shell/header/hamburger.component.ts
A toggle for the side navigation
selector | cds-hamburger, ibm-hamburger |
template |
|
Properties |
|
Methods |
|
Inputs |
Outputs |
constructor(i18n: I18n)
|
||||||
Parameters :
|
active | |
Type : boolean
|
|
Default value : false
|
|
Controls the active/selected state for the |
activeTitle | |
Type : any
|
|
Default value : this.i18n.get().UI_SHELL.HEADER.CLOSE_MENU
|
|
Set the title text when the hamburger is active |
inactiveTitle | |
Type : any
|
|
Default value : this.i18n.get().UI_SHELL.HEADER.OPEN_MENU
|
|
Set the title text when the hamburger is inactive |
selected | |
Type : EventEmitter<Object>
|
|
|
Public doClick |
doClick()
|
Emit the Hamburger click event upwards.
Returns :
void
|
Public i18n |
Type : I18n
|
import {
Component,
Output,
EventEmitter,
Input
} from "@angular/core";
import { I18n } from "carbon-components-angular/i18n";
/**
* A toggle for the side navigation
*/
@Component({
selector: "cds-hamburger, ibm-hamburger",
template: `
<button
type="button"
(click)="doClick()"
[ngClass]="{'cds--header__action--active': active}"
class="cds--header__menu-trigger cds--header__action cds--header__menu-toggle"
[attr.aria-label]="active ? activeTitle : inactiveTitle"
[attr.title]="active ? activeTitle : inactiveTitle">
<svg *ngIf="!active" cdsIcon="menu" size="20"></svg>
<svg *ngIf="active" cdsIcon="close" size="20"></svg>
</button>
`
})
export class Hamburger {
/**
* Controls the active/selected state for the `Hamburger` menu.
*/
@Input() active = false;
/**
* Set the title text when the hamburger is active
*/
@Input() activeTitle = this.i18n.get().UI_SHELL.HEADER.CLOSE_MENU;
/**
* Set the title text when the hamburger is inactive
*/
@Input() inactiveTitle = this.i18n.get().UI_SHELL.HEADER.OPEN_MENU;
/**
* `EventEmitter` to notify parent components of menu click events.
*/
@Output() selected: EventEmitter<Object> = new EventEmitter<Object>();
constructor(public i18n: I18n) {}
/**
* Emit the Hamburger click event upwards.
*/
public doClick() {
this.selected.emit(this.active);
}
}