@angular-mdc/web
Version:
220 lines (216 loc) • 5.92 kB
JavaScript
/**
* @license
* Copyright (c) Dominic Carretto
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/trimox/angular-mdc-web/blob/master/LICENSE
*/
import { Directive, Component, ViewEncapsulation, ChangeDetectionStrategy, ElementRef, Input, ContentChild, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { MdcRipple } from '@angular-mdc/web/ripple';
import { MdcIcon } from '@angular-mdc/web/icon';
/**
* @fileoverview added by tsickle
* Generated from: button/button.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MdcButtonLabel {
}
MdcButtonLabel.decorators = [
{ type: Directive, args: [{
selector: 'mdc-button-label, [mdcButtonLabel]',
exportAs: 'mdcButtonLabel',
host: { 'class': 'mdc-button__label' }
},] },
];
class MdcButton {
/**
* @param {?} elementRef
* @param {?} _ripple
*/
constructor(elementRef, _ripple) {
this.elementRef = elementRef;
this._ripple = _ripple;
this._raised = false;
this._unelevated = false;
this._outlined = false;
this._touch = false;
this._disabled = false;
this._ripple = new MdcRipple(this.elementRef);
this._ripple.init();
}
/**
* @return {?}
*/
get raised() {
return this._raised;
}
/**
* @param {?} value
* @return {?}
*/
set raised(value) {
this._raised = coerceBooleanProperty(value);
}
/**
* @return {?}
*/
get unelevated() {
return this._unelevated;
}
/**
* @param {?} value
* @return {?}
*/
set unelevated(value) {
this._unelevated = coerceBooleanProperty(value);
}
/**
* @return {?}
*/
get outlined() {
return this._outlined;
}
/**
* @param {?} value
* @return {?}
*/
set outlined(value) {
this._outlined = coerceBooleanProperty(value);
}
/**
* @return {?}
*/
get touch() {
return this._touch;
}
/**
* @param {?} value
* @return {?}
*/
set touch(value) {
this._touch = coerceBooleanProperty(value);
}
/**
* @return {?}
*/
get disabled() {
return this._disabled;
}
/**
* @param {?} value
* @return {?}
*/
set disabled(value) {
this.setDisabled(value);
}
/**
* @return {?}
*/
ngOnInit() {
if (this._icon) {
this._icon.elementRef.nativeElement.classList.add('mdc-button__icon');
}
}
/**
* @return {?}
*/
ngOnDestroy() {
this._ripple.destroy();
}
/**
* @param {?} disabled
* @return {?}
*/
setDisabled(disabled) {
this._disabled = coerceBooleanProperty(disabled);
if (this._disabled) {
this.getHostElement().setAttribute('disabled', 'true');
this.getHostElement().setAttribute('aria-disabled', 'true');
}
else {
this.getHostElement().removeAttribute('disabled');
this.getHostElement().removeAttribute('aria-disabled');
}
}
/**
* Focuses the button.
* @return {?}
*/
focus() {
this.getHostElement().focus();
}
/**
* @return {?}
*/
getHostElement() {
return this.elementRef.nativeElement;
}
/**
* @param {?} event
* @return {?}
*/
onClick(event) {
// A disabled button shouldn't apply any actions
if (this.disabled) {
event.preventDefault();
event.stopImmediatePropagation();
}
}
}
MdcButton.decorators = [
{ type: Component, args: [{exportAs: 'mdcButton',
selector: 'button[mdc-button], a[mdc-button]',
host: {
'[tabIndex]': 'disabled ? -1 : 0',
'class': 'mdc-button',
'[class.mdc-button--raised]': 'raised',
'[class.mdc-button--unelevated]': 'unelevated',
'[class.mdc-button--outlined]': 'outlined',
'[class.mdc-button--touch]': 'touch',
'(click)': 'onClick($event)'
},
template: `
<div class="mdc-button__ripple"></div>
<mdc-button-label *ngIf="label">{{label}}</mdc-button-label>
<div class="mdc-button__touch" *ngIf="touch"></div>
<ng-content></ng-content>
`,
providers: [MdcRipple],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
},] },
];
/** @nocollapse */
MdcButton.ctorParameters = () => [
{ type: ElementRef },
{ type: MdcRipple }
];
MdcButton.propDecorators = {
raised: [{ type: Input }],
unelevated: [{ type: Input }],
outlined: [{ type: Input }],
touch: [{ type: Input }],
disabled: [{ type: Input }],
_icon: [{ type: ContentChild, args: [MdcIcon, { static: true },] }],
label: [{ type: Input }]
};
/**
* @fileoverview added by tsickle
* Generated from: button/module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MdcButtonModule {
}
MdcButtonModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
exports: [MdcButton, MdcButtonLabel],
declarations: [MdcButton, MdcButtonLabel]
},] },
];
export { MdcButton, MdcButtonLabel, MdcButtonModule };
//# sourceMappingURL=button.js.map