ipsos-components
Version:
Material Design components for Angular
182 lines (164 loc) • 5.28 kB
text/typescript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {animate, state, style, transition, trigger} from '@angular/animations';
import {FocusMonitor} from '@angular/cdk/a11y';
import {ENTER, SPACE} from '@angular/cdk/keycodes';
import {filter} from 'rxjs/operators/filter';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Directive,
ElementRef,
Host,
Input,
OnDestroy,
ViewEncapsulation,
} from '@angular/core';
import {merge} from 'rxjs/observable/merge';
import {Subscription} from 'rxjs/Subscription';
import {EXPANSION_PANEL_ANIMATION_TIMING, MatExpansionPanel} from './expansion-panel';
/**
* <mat-expansion-panel-header> component.
*
* This component corresponds to the header element of an <mat-expansion-panel>.
*
* Please refer to README.md for examples on how to use it.
*/
export class MatExpansionPanelHeader implements OnDestroy {
private _parentChangeSubscription = Subscription.EMPTY;
constructor(
public panel: MatExpansionPanel,
private _element: ElementRef,
private _focusMonitor: FocusMonitor,
private _changeDetectorRef: ChangeDetectorRef) {
// Since the toggle state depends on an @Input on the panel, we
// need to subscribe and trigger change detection manually.
this._parentChangeSubscription = merge(
panel.opened,
panel.closed,
panel._inputChanges.pipe(filter(changes => !!(changes.hideToggle || changes.disabled)))
)
.subscribe(() => this._changeDetectorRef.markForCheck());
_focusMonitor.monitor(_element.nativeElement, false);
}
/** Height of the header while the panel is expanded. */
expandedHeight: string;
/** Height of the header while the panel is collapsed. */
collapsedHeight: string;
/** Toggles the expanded state of the panel. */
_toggle(): void {
if (!this.panel.disabled) {
this.panel.toggle();
}
}
/** Gets whether the panel is expanded. */
_isExpanded(): boolean {
return this.panel.expanded;
}
/** Gets the expanded state string of the panel. */
_getExpandedState(): string {
return this.panel._getExpandedState();
}
/** Gets the panel id. */
_getPanelId(): string {
return this.panel.id;
}
/** Gets whether the expand indicator should be shown. */
_showToggle(): boolean {
return !this.panel.hideToggle && !this.panel.disabled;
}
/** Handle keyup event calling to toggle() if appropriate. */
_keyup(event: KeyboardEvent) {
switch (event.keyCode) {
// Toggle for space and enter keys.
case SPACE:
case ENTER:
event.preventDefault();
this._toggle();
break;
default:
return;
}
}
ngOnDestroy() {
this._parentChangeSubscription.unsubscribe();
this._focusMonitor.stopMonitoring(this._element.nativeElement);
}
}
/**
* <mat-panel-description> directive.
*
* This direction is to be used inside of the MatExpansionPanelHeader component.
*/
export class MatExpansionPanelDescription {}
/**
* <mat-panel-title> directive.
*
* This direction is to be used inside of the MatExpansionPanelHeader component.
*/
export class MatExpansionPanelTitle {}