@angular/material
Version:
Angular Material
16 lines • 13.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("@angular/cdk/a11y"),require("@angular/cdk/coercion"),require("@angular/cdk/collections"),require("@angular/core"),require("@angular/forms"),require("@angular/material/core")):"function"==typeof define&&define.amd?define("@angular/material/button-toggle",["exports","tslib","@angular/cdk/a11y","@angular/cdk/coercion","@angular/cdk/collections","@angular/core","@angular/forms","@angular/material/core"],e):e(((t=t||self).ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.buttonToggle={}),t.tslib,t.ng.cdk.a11y,t.ng.cdk.coercion,t.ng.cdk.collections,t.ng.core,t.ng.forms,t.ng.material.core)}(this,(function(t,e,o,n,a,i,r,l){"use strict";
/**
* @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
*/var u=new i.InjectionToken("MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS"),c={provide:r.NG_VALUE_ACCESSOR,useExisting:i.forwardRef((function(){return d})),multi:!0},s=function s(){},g=0,p=function p(t,e){this.source=t,this.value=e},d=function(){function t(t,e){this._changeDetector=t,this._vertical=!1,this._multiple=!1,this._disabled=!1,this._controlValueAccessorChangeFn=function(){},this._onTouched=function(){},this._name="mat-button-toggle-group-"+g++,this.valueChange=new i.EventEmitter,this.change=new i.EventEmitter,this.appearance=e&&e.appearance?e.appearance:"standard"}return Object.defineProperty(t.prototype,"name",{get:function(){return this._name},set:function(t){var e=this;this._name=t,this._buttonToggles&&this._buttonToggles.forEach((function(t){t.name=e._name,t._markForCheck()}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"vertical",{get:function(){return this._vertical},set:function(t){this._vertical=n.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){var t=this._selectionModel?this._selectionModel.selected:[];return this.multiple?t.map((function(t){return t.value})):t[0]?t[0].value:void 0},set:function(t){this._setSelectionByValue(t),this.valueChange.emit(this.value)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"selected",{get:function(){var t=this._selectionModel?this._selectionModel.selected:[];return this.multiple?t:t[0]||null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"multiple",{get:function(){return this._multiple},set:function(t){this._multiple=n.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"disabled",{get:function(){return this._disabled},set:function(t){this._disabled=n.coerceBooleanProperty(t),this._buttonToggles&&this._buttonToggles.forEach((function(t){return t._markForCheck()}))},enumerable:!0,configurable:!0}),t.prototype.ngOnInit=function(){this._selectionModel=new a.SelectionModel(this.multiple,void 0,!1)},t.prototype.ngAfterContentInit=function(){var t;(t=this._selectionModel).select.apply(t,e.__spread(this._buttonToggles.filter((function(t){return t.checked}))))},t.prototype.writeValue=function(t){this.value=t,this._changeDetector.markForCheck()},t.prototype.registerOnChange=function(t){this._controlValueAccessorChangeFn=t},t.prototype.registerOnTouched=function(t){this._onTouched=t},t.prototype.setDisabledState=function(t){this.disabled=t},t.prototype._emitChangeEvent=function(){var t=this.selected,e=Array.isArray(t)?t[t.length-1]:t,o=new p(e,this.value);this._controlValueAccessorChangeFn(o.value),this.change.emit(o)},t.prototype._syncButtonToggle=function(t,e,o,n){var a=this;void 0===o&&(o=!1),void 0===n&&(n=!1),this.multiple||!this.selected||t.checked||(this.selected.checked=!1),this._selectionModel?e?this._selectionModel.select(t):this._selectionModel.deselect(t):n=!0,n?Promise.resolve((function(){return a._updateModelValue(o)})):this._updateModelValue(o)},t.prototype._isSelected=function(t){return this._selectionModel&&this._selectionModel.isSelected(t)},t.prototype._isPrechecked=function(t){return void 0!==this._rawValue&&(this.multiple&&Array.isArray(this._rawValue)?this._rawValue.some((function(e){return null!=t.value&&e===t.value})):t.value===this._rawValue)},t.prototype._setSelectionByValue=function(t){var e=this;if(this._rawValue=t,this._buttonToggles)if(this.multiple&&t){if(!Array.isArray(t))throw Error("Value must be an array in multiple-selection mode.");this._clearSelection(),t.forEach((function(t){return e._selectValue(t)}))}else this._clearSelection(),this._selectValue(t)},t.prototype._clearSelection=function(){this._selectionModel.clear(),this._buttonToggles.forEach((function(t){return t.checked=!1}))},t.prototype._selectValue=function(t){var e=this._buttonToggles.find((function(e){return null!=e.value&&e.value===t}));e&&(e.checked=!0,this._selectionModel.select(e))},t.prototype._updateModelValue=function(t){t&&this._emitChangeEvent(),this.valueChange.emit(this.value)},t.decorators=[{type:i.Directive,args:[{selector:"mat-button-toggle-group",providers:[c,{provide:s,useExisting:t}],host:{role:"group",class:"mat-button-toggle-group","[attr.aria-disabled]":"disabled","[class.mat-button-toggle-vertical]":"vertical","[class.mat-button-toggle-group-appearance-standard]":'appearance === "standard"'},exportAs:"matButtonToggleGroup"}]}],t.ctorParameters=function(){return[{type:i.ChangeDetectorRef},{type:void 0,decorators:[{type:i.Optional},{type:i.Inject,args:[u]}]}]},t.propDecorators={_buttonToggles:[{type:i.ContentChildren,args:[i.forwardRef((function(){return h})),{descendants:!0}]}],appearance:[{type:i.Input}],name:[{type:i.Input}],vertical:[{type:i.Input}],value:[{type:i.Input}],valueChange:[{type:i.Output}],multiple:[{type:i.Input}],disabled:[{type:i.Input}],change:[{type:i.Output}]},t}(),h=function(t){function a(e,o,n,a,r,l){var u=t.call(this)||this;u._changeDetectorRef=o,u._elementRef=n,u._focusMonitor=a,u._isSingleSelector=!1,u._checked=!1,u.ariaLabelledby=null,u._disabled=!1,u.change=new i.EventEmitter;var c=Number(r);return u.tabIndex=c||0===c?c:null,u.buttonToggleGroup=e,u.appearance=l&&l.appearance?l.appearance:"standard",u}return e.__extends(a,t),Object.defineProperty(a.prototype,"buttonId",{get:function(){return this.id+"-button"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"appearance",{get:function(){return this.buttonToggleGroup?this.buttonToggleGroup.appearance:this._appearance},set:function(t){this._appearance=t},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"checked",{get:function(){return this.buttonToggleGroup?this.buttonToggleGroup._isSelected(this):this._checked},set:function(t){var e=n.coerceBooleanProperty(t);e!==this._checked&&(this._checked=e,this.buttonToggleGroup&&this.buttonToggleGroup._syncButtonToggle(this,this._checked),this._changeDetectorRef.markForCheck())},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"disabled",{get:function(){return this._disabled||this.buttonToggleGroup&&this.buttonToggleGroup.disabled},set:function(t){this._disabled=n.coerceBooleanProperty(t)},enumerable:!0,configurable:!0}),a.prototype.ngOnInit=function(){this._isSingleSelector=this.buttonToggleGroup&&!this.buttonToggleGroup.multiple,this._type=this._isSingleSelector?"radio":"checkbox",this.id=this.id||"mat-button-toggle-"+g++,this._isSingleSelector&&(this.name=this.buttonToggleGroup.name),this.buttonToggleGroup&&this.buttonToggleGroup._isPrechecked(this)&&(this.checked=!0),this._focusMonitor.monitor(this._elementRef,!0)},a.prototype.ngOnDestroy=function(){var t=this.buttonToggleGroup;this._focusMonitor.stopMonitoring(this._elementRef),t&&t._isSelected(this)&&t._syncButtonToggle(this,!1,!1,!0)},a.prototype.focus=function(t){this._buttonElement.nativeElement.focus(t)},a.prototype._onButtonClick=function(){var t=!!this._isSingleSelector||!this._checked;t!==this._checked&&(this._checked=t,this.buttonToggleGroup&&(this.buttonToggleGroup._syncButtonToggle(this,this._checked,!0),this.buttonToggleGroup._onTouched())),this.change.emit(new p(this,this.value))},a.prototype._markForCheck=function(){this._changeDetectorRef.markForCheck()},a.decorators=[{type:i.Component,args:[{selector:"mat-button-toggle",template:'<button #button class="mat-button-toggle-button"\n type="button"\n [id]="buttonId"\n [attr.tabindex]="disabled ? -1 : tabIndex"\n [attr.aria-pressed]="checked"\n [disabled]="disabled || null"\n [attr.name]="name || null"\n [attr.aria-label]="ariaLabel"\n [attr.aria-labelledby]="ariaLabelledby"\n (click)="_onButtonClick()">\n <div class="mat-button-toggle-label-content">\n <ng-content></ng-content>\n </div>\n</button>\n\n<div class="mat-button-toggle-focus-overlay"></div>\n<div class="mat-button-toggle-ripple" matRipple\n [matRippleTrigger]="button"\n [matRippleDisabled]="this.disableRipple || this.disabled">\n</div>\n',encapsulation:i.ViewEncapsulation.None,exportAs:"matButtonToggle",changeDetection:i.ChangeDetectionStrategy.OnPush,inputs:["disableRipple"],host:{"[class.mat-button-toggle-standalone]":"!buttonToggleGroup","[class.mat-button-toggle-checked]":"checked","[class.mat-button-toggle-disabled]":"disabled","[class.mat-button-toggle-appearance-standard]":'appearance === "standard"',class:"mat-button-toggle","[attr.tabindex]":"-1","[attr.id]":"id","[attr.name]":"null","(focus)":"focus()"},styles:[".mat-button-toggle-standalone,.mat-button-toggle-group{position:relative;display:inline-flex;flex-direction:row;white-space:nowrap;overflow:hidden;border-radius:2px;-webkit-tap-highlight-color:transparent}.cdk-high-contrast-active .mat-button-toggle-standalone,.cdk-high-contrast-active .mat-button-toggle-group{outline:solid 1px}.mat-button-toggle-standalone.mat-button-toggle-appearance-standard,.mat-button-toggle-group-appearance-standard{border-radius:4px}.cdk-high-contrast-active .mat-button-toggle-standalone.mat-button-toggle-appearance-standard,.cdk-high-contrast-active .mat-button-toggle-group-appearance-standard{outline:0}.mat-button-toggle-vertical{flex-direction:column}.mat-button-toggle-vertical .mat-button-toggle-label-content{display:block}.mat-button-toggle{white-space:nowrap;position:relative}.mat-button-toggle .mat-icon svg{vertical-align:top}.mat-button-toggle.cdk-keyboard-focused .mat-button-toggle-focus-overlay{opacity:1}.cdk-high-contrast-active .mat-button-toggle.cdk-keyboard-focused .mat-button-toggle-focus-overlay{opacity:.5}.mat-button-toggle-appearance-standard:not(.mat-button-toggle-disabled):hover .mat-button-toggle-focus-overlay{opacity:.04}.mat-button-toggle-appearance-standard.cdk-keyboard-focused:not(.mat-button-toggle-disabled) .mat-button-toggle-focus-overlay{opacity:.12}.cdk-high-contrast-active .mat-button-toggle-appearance-standard.cdk-keyboard-focused:not(.mat-button-toggle-disabled) .mat-button-toggle-focus-overlay{opacity:.5}@media(hover: none){.mat-button-toggle-appearance-standard:not(.mat-button-toggle-disabled):hover .mat-button-toggle-focus-overlay{display:none}}.mat-button-toggle-label-content{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:inline-block;line-height:36px;padding:0 16px;position:relative}.mat-button-toggle-appearance-standard .mat-button-toggle-label-content{line-height:48px;padding:0 12px}.mat-button-toggle-label-content>*{vertical-align:middle}.mat-button-toggle-focus-overlay{border-radius:inherit;pointer-events:none;opacity:0;top:0;left:0;right:0;bottom:0;position:absolute}.mat-button-toggle-checked .mat-button-toggle-focus-overlay{border-bottom:solid 36px}.cdk-high-contrast-active .mat-button-toggle-checked .mat-button-toggle-focus-overlay{opacity:.5;height:0}.cdk-high-contrast-active .mat-button-toggle-checked.mat-button-toggle-appearance-standard .mat-button-toggle-focus-overlay{border-bottom:solid 48px}.mat-button-toggle .mat-button-toggle-ripple{top:0;left:0;right:0;bottom:0;position:absolute;pointer-events:none}.mat-button-toggle-button{border:0;background:none;color:inherit;padding:0;margin:0;font:inherit;outline:none;width:100%;cursor:pointer}.mat-button-toggle-disabled .mat-button-toggle-button{cursor:default}.mat-button-toggle-button::-moz-focus-inner{border:0}\n"]}]}],a.ctorParameters=function(){return[{type:d,decorators:[{type:i.Optional}]},{type:i.ChangeDetectorRef},{type:i.ElementRef},{type:o.FocusMonitor},{type:String,decorators:[{type:i.Attribute,args:["tabindex"]}]},{type:void 0,decorators:[{type:i.Optional},{type:i.Inject,args:[u]}]}]},a.propDecorators={ariaLabel:[{type:i.Input,args:["aria-label"]}],ariaLabelledby:[{type:i.Input,args:["aria-labelledby"]}],_buttonElement:[{type:i.ViewChild,args:["button"]}],id:[{type:i.Input}],name:[{type:i.Input}],value:[{type:i.Input}],tabIndex:[{type:i.Input}],appearance:[{type:i.Input}],checked:[{type:i.Input}],disabled:[{type:i.Input}],change:[{type:i.Output}]},a}(l.mixinDisableRipple((function b(){}))),m=function(){function t(){}return t.decorators=[{type:i.NgModule,args:[{imports:[l.MatCommonModule,l.MatRippleModule],exports:[l.MatCommonModule,d,h],declarations:[d,h]}]}],t}();
/**
* @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
*/
t.MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS=u,t.MAT_BUTTON_TOGGLE_GROUP_VALUE_ACCESSOR=c,t.MatButtonToggle=h,t.MatButtonToggleChange=p,t.MatButtonToggleGroup=d,t.MatButtonToggleGroupMultiple=s,t.MatButtonToggleModule=m,Object.defineProperty(t,"__esModule",{value:!0})}));