blob: 05f6f58c987c622ed840e2fcbee81f80469a129b [file] [log] [blame]
{"version":3,"file":"button.es5.js","sources":["../../../src/material/button/button-module.ts","../../../src/material/button/button.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {CommonModule} from '@angular/common';\nimport {NgModule} from '@angular/core';\nimport {MatCommonModule, MatRippleModule} from '@angular/material/core';\nimport {MatAnchor, MatButton} from './button';\n\n\n@NgModule({\n imports: [\n CommonModule,\n MatRippleModule,\n MatCommonModule,\n ],\n exports: [\n MatButton,\n MatAnchor,\n MatCommonModule,\n ],\n declarations: [\n MatButton,\n MatAnchor,\n ],\n})\nexport class MatButtonModule {}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {FocusMonitor} from '@angular/cdk/a11y';\nimport {\n ChangeDetectionStrategy,\n Component,\n ElementRef,\n OnDestroy,\n ViewChild,\n ViewEncapsulation,\n Optional,\n Inject,\n Input,\n} from '@angular/core';\nimport {\n CanColor,\n CanDisable,\n CanDisableRipple,\n CanColorCtor,\n CanDisableCtor,\n CanDisableRippleCtor,\n MatRipple,\n mixinColor,\n mixinDisabled,\n mixinDisableRipple,\n} from '@angular/material/core';\nimport {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';\n\n/** Default color palette for round buttons (mat-fab and mat-mini-fab) */\nconst DEFAULT_ROUND_BUTTON_COLOR = 'accent';\n\n/**\n * List of classes to add to MatButton instances based on host attributes to\n * style as different variants.\n */\nconst BUTTON_HOST_ATTRIBUTES = [\n 'mat-button',\n 'mat-flat-button',\n 'mat-icon-button',\n 'mat-raised-button',\n 'mat-stroked-button',\n 'mat-mini-fab',\n 'mat-fab',\n];\n\n// Boilerplate for applying mixins to MatButton.\n/** @docs-private */\nclass MatButtonBase {\n constructor(public _elementRef: ElementRef) {}\n}\n\nconst _MatButtonMixinBase: CanDisableRippleCtor & CanDisableCtor & CanColorCtor &\n typeof MatButtonBase = mixinColor(mixinDisabled(mixinDisableRipple(MatButtonBase)));\n\n/**\n * Material design button.\n */\n@Component({\n moduleId: module.id,\n selector: `button[mat-button], button[mat-raised-button], button[mat-icon-button],\n button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],\n button[mat-flat-button]`,\n exportAs: 'matButton',\n host: {\n '[attr.disabled]': 'disabled || null',\n '[class._mat-animation-noopable]': '_animationMode === \"NoopAnimations\"',\n },\n templateUrl: 'button.html',\n styleUrls: ['button.css'],\n inputs: ['disabled', 'disableRipple', 'color'],\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class MatButton extends _MatButtonMixinBase\n implements OnDestroy, CanDisable, CanColor, CanDisableRipple {\n\n /** Whether the button is round. */\n readonly isRoundButton: boolean = this._hasHostAttributes('mat-fab', 'mat-mini-fab');\n\n /** Whether the button is icon button. */\n readonly isIconButton: boolean = this._hasHostAttributes('mat-icon-button');\n\n /** Reference to the MatRipple instance of the button. */\n @ViewChild(MatRipple, {static: false}) ripple: MatRipple;\n\n constructor(elementRef: ElementRef,\n private _focusMonitor: FocusMonitor,\n @Optional() @Inject(ANIMATION_MODULE_TYPE) public _animationMode: string) {\n super(elementRef);\n\n // For each of the variant selectors that is prevent in the button's host\n // attributes, add the correct corresponding class.\n for (const attr of BUTTON_HOST_ATTRIBUTES) {\n if (this._hasHostAttributes(attr)) {\n (this._getHostElement() as HTMLElement).classList.add(attr);\n }\n }\n\n this._focusMonitor.monitor(this._elementRef, true);\n\n if (this.isRoundButton) {\n this.color = DEFAULT_ROUND_BUTTON_COLOR;\n }\n }\n\n ngOnDestroy() {\n this._focusMonitor.stopMonitoring(this._elementRef);\n }\n\n /** Focuses the button. */\n focus(): void {\n this._getHostElement().focus();\n }\n\n _getHostElement() {\n return this._elementRef.nativeElement;\n }\n\n _isRippleDisabled() {\n return this.disableRipple || this.disabled;\n }\n\n /** Gets whether the button has one of the given attributes. */\n _hasHostAttributes(...attributes: string[]) {\n return attributes.some(attribute => this._getHostElement().hasAttribute(attribute));\n }\n}\n\n/**\n * Material design anchor button.\n */\n@Component({\n moduleId: module.id,\n selector: `a[mat-button], a[mat-raised-button], a[mat-icon-button], a[mat-fab],\n a[mat-mini-fab], a[mat-stroked-button], a[mat-flat-button]`,\n exportAs: 'matButton, matAnchor',\n host: {\n // Note that we ignore the user-specified tabindex when it's disabled for\n // consistency with the `mat-button` applied on native buttons where even\n // though they have an index, they're not tabbable.\n '[attr.tabindex]': 'disabled ? -1 : (tabIndex || 0)',\n '[attr.disabled]': 'disabled || null',\n '[attr.aria-disabled]': 'disabled.toString()',\n '(click)': '_haltDisabledEvents($event)',\n '[class._mat-animation-noopable]': '_animationMode === \"NoopAnimations\"',\n },\n inputs: ['disabled', 'disableRipple', 'color'],\n templateUrl: 'button.html',\n styleUrls: ['button.css'],\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class MatAnchor extends MatButton {\n /** Tabindex of the button. */\n @Input() tabIndex: number;\n\n constructor(\n focusMonitor: FocusMonitor,\n elementRef: ElementRef,\n @Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode: string) {\n super(elementRef, focusMonitor, animationMode);\n }\n\n _haltDisabledEvents(event: Event) {\n // A disabled button shouldn't apply any actions\n if (this.disabled) {\n event.preventDefault();\n event.stopImmediatePropagation();\n }\n }\n}\n"],"names":["tslib_1.__extends"],"mappings":";;;;;;;;;;;;;;;;;;;;;;ACmCA,IAAM,0BAA0B,GAAG,QAAQ,CAA3C;;;;;;AAMA,IAAM,sBAAsB,GAAG;IAC7B,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,cAAc;IACd,SAAS;CACV,CAAD;;;;;AAIA;;;;;;IACE,SAAF,aAAA,CAAqB,WAAuB,EAA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