/** * @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 { InjectionToken, Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, forwardRef, Input, Output, ViewChild, ViewEncapsulation, NgZone, Optional, Inject, Directive, NgModule } from '@angular/core'; import { FocusMonitor } from '@angular/cdk/a11y'; import { Directionality } from '@angular/cdk/bidi'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { NG_VALUE_ACCESSOR, CheckboxRequiredValidator, NG_VALIDATORS } from '@angular/forms'; import { mixinColor, mixinDisabled, mixinDisableRipple, mixinTabIndex, GestureConfig, MatCommonModule, MatRippleModule } from '@angular/material/core'; import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations'; import { ObserversModule } from '@angular/cdk/observers'; import { HAMMER_GESTURE_CONFIG } from '@angular/platform-browser'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Injection token to be used to override the default options for `mat-slide-toggle`. * @type {?} */ const MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS = new InjectionToken('mat-slide-toggle-default-options', { providedIn: 'root', factory: (/** * @return {?} */ () => ({ disableToggleValue: false, disableDragValue: false })) }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // Increasing integer for generating unique ids for slide-toggle components. /** @type {?} */ let nextUniqueId = 0; /** * \@docs-private * @type {?} */ const MAT_SLIDE_TOGGLE_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/** * @return {?} */ () => MatSlideToggle)), multi: true }; /** * Change event object emitted by a MatSlideToggle. */ class MatSlideToggleChange { /** * @param {?} source * @param {?} checked */ constructor(source, checked) { this.source = source; this.checked = checked; } } // Boilerplate for applying mixins to MatSlideToggle. /** * \@docs-private */ class MatSlideToggleBase { /** * @param {?} _elementRef */ constructor(_elementRef) { this._elementRef = _elementRef; } } /** @type {?} */ const _MatSlideToggleMixinBase = mixinTabIndex(mixinColor(mixinDisableRipple(mixinDisabled(MatSlideToggleBase)), 'accent')); /** * Represents a slidable "switch" toggle that can be moved between on and off. */ class MatSlideToggle extends _MatSlideToggleMixinBase { /** * @param {?} elementRef * @param {?} _focusMonitor * @param {?} _changeDetectorRef * @param {?} tabIndex * @param {?} _ngZone * @param {?} defaults * @param {?=} _animationMode * @param {?=} _dir */ constructor(elementRef, _focusMonitor, _changeDetectorRef, tabIndex, _ngZone, defaults, _animationMode, _dir) { super(elementRef); this._focusMonitor = _focusMonitor; this._changeDetectorRef = _changeDetectorRef; this._ngZone = _ngZone; this.defaults = defaults; this._animationMode = _animationMode; this._dir = _dir; this._onChange = (/** * @param {?} _ * @return {?} */ (_) => { }); this._onTouched = (/** * @return {?} */ () => { }); this._uniqueId = `mat-slide-toggle-${++nextUniqueId}`; this._required = false; this._checked = false; /** * Whether the thumb is currently being dragged. */ this._dragging = false; /** * Name value will be applied to the input element if present. */ this.name = null; /** * A unique id for the slide-toggle input. If none is supplied, it will be auto-generated. */ this.id = this._uniqueId; /** * Whether the label should appear after or before the slide-toggle. Defaults to 'after'. */ this.labelPosition = 'after'; /** * Used to set the aria-label attribute on the underlying input element. */ this.ariaLabel = null; /** * Used to set the aria-labelledby attribute on the underlying input element. */ this.ariaLabelledby = null; /** * An event will be dispatched each time the slide-toggle changes its value. */ this.change = new EventEmitter(); /** * An event will be dispatched each time the slide-toggle input is toggled. * This event is always emitted when the user toggles the slide toggle, but this does not mean * the slide toggle's value has changed. The event does not fire when the user drags to change * the slide toggle value. */ this.toggleChange = new EventEmitter(); /** * An event will be dispatched each time the slide-toggle is dragged. * This event is always emitted when the user drags the slide toggle to make a change greater * than 50%. It does not mean the slide toggle's value is changed. The event is not emitted when * the user toggles the slide toggle to change its value. */ this.dragChange = new EventEmitter(); this.tabIndex = parseInt(tabIndex) || 0; } /** * Whether the slide-toggle is required. * @return {?} */ get required() { return this._required; } /** * @param {?} value * @return {?} */ set required(value) { this._required = coerceBooleanProperty(value); } /** * Whether the slide-toggle element is checked or not. * @return {?} */ get checked() { return this._checked; } /** * @param {?} value * @return {?} */ set checked(value) { this._checked = coerceBooleanProperty(value); this._changeDetectorRef.markForCheck(); } /** * Returns the unique id for the visual hidden input. * @return {?} */ get inputId() { return `${this.id || this._uniqueId}-input`; } /** * @return {?} */ ngAfterContentInit() { this._focusMonitor .monitor(this._elementRef, true) .subscribe((/** * @param {?} focusOrigin * @return {?} */ focusOrigin => { if (!focusOrigin) { // When a focused element becomes disabled, the browser *immediately* fires a blur event. // Angular does not expect events to be raised during change detection, so any state // change (such as a form control's 'ng-touched') will cause a changed-after-checked // error. See https://github.com/angular/angular/issues/17793. To work around this, // we defer telling the form control it has been touched until the next tick. Promise.resolve().then((/** * @return {?} */ () => this._onTouched())); } })); } /** * @return {?} */ ngOnDestroy() { this._focusMonitor.stopMonitoring(this._elementRef); } /** * Method being called whenever the underlying input emits a change event. * @param {?} event * @return {?} */ _onChangeEvent(event) { // We always have to stop propagation on the change event. // Otherwise the change event, from the input element, will bubble up and // emit its event object to the component's `change` output. event.stopPropagation(); if (!this._dragging) { this.toggleChange.emit(); } // Releasing the pointer over the `