blob: 07b90dafcde32fa4dfad199c83786d801763eb72 [file] [log] [blame]
{"version":3,"file":"button.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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;ACmCA,MAAM,0BAA0B,GAAG,QAAQ,CAA3C;;;;;;AAMA,MAAM,sBAAsB,GAAG;IAC7B,YAAY;IACZ,iBAAiB;IACjB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,cAAc;IACd,SAAS;CACV,CAAD;;;;;AAIA,MAAM,aAAa,CAAnB;;;;IACE,WAAF,CAAqB,WAAuB,EAA5C;QA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