source: trip-planner-front/node_modules/@angular/material/fesm2015/slide-toggle.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 19.1 KB
Line 
1import { ObserversModule } from '@angular/cdk/observers';
2import { InjectionToken, forwardRef, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, ElementRef, ChangeDetectorRef, Attribute, Inject, Optional, ViewChild, Input, Output, Directive, NgModule } from '@angular/core';
3import { mixinTabIndex, mixinColor, mixinDisableRipple, mixinDisabled, MatRippleModule, MatCommonModule } from '@angular/material/core';
4import { FocusMonitor } from '@angular/cdk/a11y';
5import { coerceBooleanProperty } from '@angular/cdk/coercion';
6import { NG_VALUE_ACCESSOR, NG_VALIDATORS, CheckboxRequiredValidator } from '@angular/forms';
7import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
8
9/**
10 * @license
11 * Copyright Google LLC All Rights Reserved.
12 *
13 * Use of this source code is governed by an MIT-style license that can be
14 * found in the LICENSE file at https://angular.io/license
15 */
16/** Injection token to be used to override the default options for `mat-slide-toggle`. */
17const MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS = new InjectionToken('mat-slide-toggle-default-options', {
18 providedIn: 'root',
19 factory: () => ({ disableToggleValue: false })
20});
21
22/**
23 * @license
24 * Copyright Google LLC All Rights Reserved.
25 *
26 * Use of this source code is governed by an MIT-style license that can be
27 * found in the LICENSE file at https://angular.io/license
28 */
29// Increasing integer for generating unique ids for slide-toggle components.
30let nextUniqueId = 0;
31/** @docs-private */
32const MAT_SLIDE_TOGGLE_VALUE_ACCESSOR = {
33 provide: NG_VALUE_ACCESSOR,
34 useExisting: forwardRef(() => MatSlideToggle),
35 multi: true
36};
37/** Change event object emitted by a MatSlideToggle. */
38class MatSlideToggleChange {
39 constructor(
40 /** The source MatSlideToggle of the event. */
41 source,
42 /** The new `checked` value of the MatSlideToggle. */
43 checked) {
44 this.source = source;
45 this.checked = checked;
46 }
47}
48// Boilerplate for applying mixins to MatSlideToggle.
49/** @docs-private */
50const _MatSlideToggleBase = mixinTabIndex(mixinColor(mixinDisableRipple(mixinDisabled(class {
51 constructor(_elementRef) {
52 this._elementRef = _elementRef;
53 }
54}))));
55/** Represents a slidable "switch" toggle that can be moved between on and off. */
56class MatSlideToggle extends _MatSlideToggleBase {
57 constructor(elementRef, _focusMonitor, _changeDetectorRef, tabIndex, defaults, animationMode) {
58 super(elementRef);
59 this._focusMonitor = _focusMonitor;
60 this._changeDetectorRef = _changeDetectorRef;
61 this.defaults = defaults;
62 this._onChange = (_) => { };
63 this._onTouched = () => { };
64 this._uniqueId = `mat-slide-toggle-${++nextUniqueId}`;
65 this._required = false;
66 this._checked = false;
67 /** Name value will be applied to the input element if present. */
68 this.name = null;
69 /** A unique id for the slide-toggle input. If none is supplied, it will be auto-generated. */
70 this.id = this._uniqueId;
71 /** Whether the label should appear after or before the slide-toggle. Defaults to 'after'. */
72 this.labelPosition = 'after';
73 /** Used to set the aria-label attribute on the underlying input element. */
74 this.ariaLabel = null;
75 /** Used to set the aria-labelledby attribute on the underlying input element. */
76 this.ariaLabelledby = null;
77 /** An event will be dispatched each time the slide-toggle changes its value. */
78 this.change = new EventEmitter();
79 /**
80 * An event will be dispatched each time the slide-toggle input is toggled.
81 * This event is always emitted when the user toggles the slide toggle, but this does not mean
82 * the slide toggle's value has changed.
83 */
84 this.toggleChange = new EventEmitter();
85 this.tabIndex = parseInt(tabIndex) || 0;
86 this.color = this.defaultColor = defaults.color || 'accent';
87 this._noopAnimations = animationMode === 'NoopAnimations';
88 }
89 /** Whether the slide-toggle is required. */
90 get required() { return this._required; }
91 set required(value) { this._required = coerceBooleanProperty(value); }
92 /** Whether the slide-toggle element is checked or not. */
93 get checked() { return this._checked; }
94 set checked(value) {
95 this._checked = coerceBooleanProperty(value);
96 this._changeDetectorRef.markForCheck();
97 }
98 /** Returns the unique id for the visual hidden input. */
99 get inputId() { return `${this.id || this._uniqueId}-input`; }
100 ngAfterContentInit() {
101 this._focusMonitor
102 .monitor(this._elementRef, true)
103 .subscribe(focusOrigin => {
104 // Only forward focus manually when it was received programmatically or through the
105 // keyboard. We should not do this for mouse/touch focus for two reasons:
106 // 1. It can prevent clicks from landing in Chrome (see #18269).
107 // 2. They're already handled by the wrapping `label` element.
108 if (focusOrigin === 'keyboard' || focusOrigin === 'program') {
109 this._inputElement.nativeElement.focus();
110 }
111 else if (!focusOrigin) {
112 // When a focused element becomes disabled, the browser *immediately* fires a blur event.
113 // Angular does not expect events to be raised during change detection, so any state
114 // change (such as a form control's 'ng-touched') will cause a changed-after-checked
115 // error. See https://github.com/angular/angular/issues/17793. To work around this,
116 // we defer telling the form control it has been touched until the next tick.
117 Promise.resolve().then(() => this._onTouched());
118 }
119 });
120 }
121 ngOnDestroy() {
122 this._focusMonitor.stopMonitoring(this._elementRef);
123 }
124 /** Method being called whenever the underlying input emits a change event. */
125 _onChangeEvent(event) {
126 // We always have to stop propagation on the change event.
127 // Otherwise the change event, from the input element, will bubble up and
128 // emit its event object to the component's `change` output.
129 event.stopPropagation();
130 this.toggleChange.emit();
131 // When the slide toggle's config disables toggle change event by setting
132 // `disableToggleValue: true`, the slide toggle's value does not change, and the
133 // checked state of the underlying input needs to be changed back.
134 if (this.defaults.disableToggleValue) {
135 this._inputElement.nativeElement.checked = this.checked;
136 return;
137 }
138 // Sync the value from the underlying input element with the component instance.
139 this.checked = this._inputElement.nativeElement.checked;
140 // Emit our custom change event only if the underlying input emitted one. This ensures that
141 // there is no change event, when the checked state changes programmatically.
142 this._emitChangeEvent();
143 }
144 /** Method being called whenever the slide-toggle has been clicked. */
145 _onInputClick(event) {
146 // We have to stop propagation for click events on the visual hidden input element.
147 // By default, when a user clicks on a label element, a generated click event will be
148 // dispatched on the associated input element. Since we are using a label element as our
149 // root container, the click event on the `slide-toggle` will be executed twice.
150 // The real click event will bubble up, and the generated click event also tries to bubble up.
151 // This will lead to multiple click events.
152 // Preventing bubbling for the second event will solve that issue.
153 event.stopPropagation();
154 }
155 /** Implemented as part of ControlValueAccessor. */
156 writeValue(value) {
157 this.checked = !!value;
158 }
159 /** Implemented as part of ControlValueAccessor. */
160 registerOnChange(fn) {
161 this._onChange = fn;
162 }
163 /** Implemented as part of ControlValueAccessor. */
164 registerOnTouched(fn) {
165 this._onTouched = fn;
166 }
167 /** Implemented as a part of ControlValueAccessor. */
168 setDisabledState(isDisabled) {
169 this.disabled = isDisabled;
170 this._changeDetectorRef.markForCheck();
171 }
172 /** Focuses the slide-toggle. */
173 focus(options, origin) {
174 if (origin) {
175 this._focusMonitor.focusVia(this._inputElement, origin, options);
176 }
177 else {
178 this._inputElement.nativeElement.focus(options);
179 }
180 }
181 /** Toggles the checked state of the slide-toggle. */
182 toggle() {
183 this.checked = !this.checked;
184 this._onChange(this.checked);
185 }
186 /**
187 * Emits a change event on the `change` output. Also notifies the FormControl about the change.
188 */
189 _emitChangeEvent() {
190 this._onChange(this.checked);
191 this.change.emit(new MatSlideToggleChange(this, this.checked));
192 }
193 /** Method being called whenever the label text changes. */
194 _onLabelTextChange() {
195 // Since the event of the `cdkObserveContent` directive runs outside of the zone, the
196 // slide-toggle component will be only marked for check, but no actual change detection runs
197 // automatically. Instead of going back into the zone in order to trigger a change detection
198 // which causes *all* components to be checked (if explicitly marked or not using OnPush),
199 // we only trigger an explicit change detection for the slide-toggle view and its children.
200 this._changeDetectorRef.detectChanges();
201 }
202}
203MatSlideToggle.decorators = [
204 { type: Component, args: [{
205 selector: 'mat-slide-toggle',
206 exportAs: 'matSlideToggle',
207 host: {
208 'class': 'mat-slide-toggle',
209 '[id]': 'id',
210 // Needs to be `-1` so it can still receive programmatic focus.
211 '[attr.tabindex]': 'disabled ? null : -1',
212 '[attr.aria-label]': 'null',
213 '[attr.aria-labelledby]': 'null',
214 '[class.mat-checked]': 'checked',
215 '[class.mat-disabled]': 'disabled',
216 '[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',
217 '[class._mat-animation-noopable]': '_noopAnimations',
218 },
219 template: "<label [attr.for]=\"inputId\" class=\"mat-slide-toggle-label\" #label>\n <div #toggleBar class=\"mat-slide-toggle-bar\"\n [class.mat-slide-toggle-bar-no-side-margin]=\"!labelContent.textContent || !labelContent.textContent.trim()\">\n\n <input #input class=\"mat-slide-toggle-input cdk-visually-hidden\" type=\"checkbox\"\n role=\"switch\"\n [id]=\"inputId\"\n [required]=\"required\"\n [tabIndex]=\"tabIndex\"\n [checked]=\"checked\"\n [disabled]=\"disabled\"\n [attr.name]=\"name\"\n [attr.aria-checked]=\"checked.toString()\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n [attr.aria-describedby]=\"ariaDescribedby\"\n (change)=\"_onChangeEvent($event)\"\n (click)=\"_onInputClick($event)\">\n\n <div class=\"mat-slide-toggle-thumb-container\" #thumbContainer>\n <div class=\"mat-slide-toggle-thumb\"></div>\n <div class=\"mat-slide-toggle-ripple mat-focus-indicator\" mat-ripple\n [matRippleTrigger]=\"label\"\n [matRippleDisabled]=\"disableRipple || disabled\"\n [matRippleCentered]=\"true\"\n [matRippleRadius]=\"20\"\n [matRippleAnimation]=\"{enterDuration: _noopAnimations ? 0 : 150}\">\n\n <div class=\"mat-ripple-element mat-slide-toggle-persistent-ripple\"></div>\n </div>\n </div>\n\n </div>\n\n <span class=\"mat-slide-toggle-content\" #labelContent (cdkObserveContent)=\"_onLabelTextChange()\">\n <!-- Add an invisible span so JAWS can read the label -->\n <span style=\"display:none\">&nbsp;</span>\n <ng-content></ng-content>\n </span>\n</label>\n",
220 providers: [MAT_SLIDE_TOGGLE_VALUE_ACCESSOR],
221 inputs: ['disabled', 'disableRipple', 'color', 'tabIndex'],
222 encapsulation: ViewEncapsulation.None,
223 changeDetection: ChangeDetectionStrategy.OnPush,
224 styles: [".mat-slide-toggle{display:inline-block;height:24px;max-width:100%;line-height:24px;white-space:nowrap;outline:none;-webkit-tap-highlight-color:transparent}.mat-slide-toggle.mat-checked .mat-slide-toggle-thumb-container{transform:translate3d(16px, 0, 0)}[dir=rtl] .mat-slide-toggle.mat-checked .mat-slide-toggle-thumb-container{transform:translate3d(-16px, 0, 0)}.mat-slide-toggle.mat-disabled{opacity:.38}.mat-slide-toggle.mat-disabled .mat-slide-toggle-label,.mat-slide-toggle.mat-disabled .mat-slide-toggle-thumb-container{cursor:default}.mat-slide-toggle-label{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:flex;flex:1;flex-direction:row;align-items:center;height:inherit;cursor:pointer}.mat-slide-toggle-content{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.mat-slide-toggle-label-before .mat-slide-toggle-label{order:1}.mat-slide-toggle-label-before .mat-slide-toggle-bar{order:2}[dir=rtl] .mat-slide-toggle-label-before .mat-slide-toggle-bar,.mat-slide-toggle-bar{margin-right:8px;margin-left:0}[dir=rtl] .mat-slide-toggle-bar,.mat-slide-toggle-label-before .mat-slide-toggle-bar{margin-left:8px;margin-right:0}.mat-slide-toggle-bar-no-side-margin{margin-left:0;margin-right:0}.mat-slide-toggle-thumb-container{position:absolute;z-index:1;width:20px;height:20px;top:-3px;left:0;transform:translate3d(0, 0, 0);transition:all 80ms linear;transition-property:transform}._mat-animation-noopable .mat-slide-toggle-thumb-container{transition:none}[dir=rtl] .mat-slide-toggle-thumb-container{left:auto;right:0}.mat-slide-toggle-thumb{height:20px;width:20px;border-radius:50%}.mat-slide-toggle-bar{position:relative;width:36px;height:14px;flex-shrink:0;border-radius:8px}.mat-slide-toggle-input{bottom:0;left:10px}[dir=rtl] .mat-slide-toggle-input{left:auto;right:10px}.mat-slide-toggle-bar,.mat-slide-toggle-thumb{transition:all 80ms linear;transition-property:background-color;transition-delay:50ms}._mat-animation-noopable .mat-slide-toggle-bar,._mat-animation-noopable .mat-slide-toggle-thumb{transition:none}.mat-slide-toggle .mat-slide-toggle-ripple{position:absolute;top:calc(50% - 20px);left:calc(50% - 20px);height:40px;width:40px;z-index:1;pointer-events:none}.mat-slide-toggle .mat-slide-toggle-ripple .mat-ripple-element:not(.mat-slide-toggle-persistent-ripple){opacity:.12}.mat-slide-toggle-persistent-ripple{width:100%;height:100%;transform:none}.mat-slide-toggle-bar:hover .mat-slide-toggle-persistent-ripple{opacity:.04}.mat-slide-toggle:not(.mat-disabled).cdk-keyboard-focused .mat-slide-toggle-persistent-ripple{opacity:.12}.mat-slide-toggle-persistent-ripple,.mat-slide-toggle.mat-disabled .mat-slide-toggle-bar:hover .mat-slide-toggle-persistent-ripple{opacity:0}@media(hover: none){.mat-slide-toggle-bar:hover .mat-slide-toggle-persistent-ripple{display:none}}.cdk-high-contrast-active .mat-slide-toggle-thumb,.cdk-high-contrast-active .mat-slide-toggle-bar{border:1px solid}.cdk-high-contrast-active .mat-slide-toggle.cdk-keyboard-focused .mat-slide-toggle-bar{outline:2px dotted;outline-offset:5px}\n"]
225 },] }
226];
227MatSlideToggle.ctorParameters = () => [
228 { type: ElementRef },
229 { type: FocusMonitor },
230 { type: ChangeDetectorRef },
231 { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] },
232 { type: undefined, decorators: [{ type: Inject, args: [MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS,] }] },
233 { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] }
234];
235MatSlideToggle.propDecorators = {
236 _thumbEl: [{ type: ViewChild, args: ['thumbContainer',] }],
237 _thumbBarEl: [{ type: ViewChild, args: ['toggleBar',] }],
238 name: [{ type: Input }],
239 id: [{ type: Input }],
240 labelPosition: [{ type: Input }],
241 ariaLabel: [{ type: Input, args: ['aria-label',] }],
242 ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
243 ariaDescribedby: [{ type: Input, args: ['aria-describedby',] }],
244 required: [{ type: Input }],
245 checked: [{ type: Input }],
246 change: [{ type: Output }],
247 toggleChange: [{ type: Output }],
248 _inputElement: [{ type: ViewChild, args: ['input',] }]
249};
250
251/**
252 * @license
253 * Copyright Google LLC All Rights Reserved.
254 *
255 * Use of this source code is governed by an MIT-style license that can be
256 * found in the LICENSE file at https://angular.io/license
257 */
258const MAT_SLIDE_TOGGLE_REQUIRED_VALIDATOR = {
259 provide: NG_VALIDATORS,
260 useExisting: forwardRef(() => MatSlideToggleRequiredValidator),
261 multi: true
262};
263/**
264 * Validator for Material slide-toggle components with the required attribute in a
265 * template-driven form. The default validator for required form controls asserts
266 * that the control value is not undefined but that is not appropriate for a slide-toggle
267 * where the value is always defined.
268 *
269 * Required slide-toggle form controls are valid when checked.
270 */
271class MatSlideToggleRequiredValidator extends CheckboxRequiredValidator {
272}
273MatSlideToggleRequiredValidator.decorators = [
274 { type: Directive, args: [{
275 selector: `mat-slide-toggle[required][formControlName],
276 mat-slide-toggle[required][formControl], mat-slide-toggle[required][ngModel]`,
277 providers: [MAT_SLIDE_TOGGLE_REQUIRED_VALIDATOR],
278 },] }
279];
280
281/**
282 * @license
283 * Copyright Google LLC All Rights Reserved.
284 *
285 * Use of this source code is governed by an MIT-style license that can be
286 * found in the LICENSE file at https://angular.io/license
287 */
288/** This module is used by both original and MDC-based slide-toggle implementations. */
289class _MatSlideToggleRequiredValidatorModule {
290}
291_MatSlideToggleRequiredValidatorModule.decorators = [
292 { type: NgModule, args: [{
293 exports: [MatSlideToggleRequiredValidator],
294 declarations: [MatSlideToggleRequiredValidator],
295 },] }
296];
297class MatSlideToggleModule {
298}
299MatSlideToggleModule.decorators = [
300 { type: NgModule, args: [{
301 imports: [
302 _MatSlideToggleRequiredValidatorModule,
303 MatRippleModule,
304 MatCommonModule,
305 ObserversModule,
306 ],
307 exports: [
308 _MatSlideToggleRequiredValidatorModule,
309 MatSlideToggle,
310 MatCommonModule
311 ],
312 declarations: [MatSlideToggle],
313 },] }
314];
315
316/**
317 * @license
318 * Copyright Google LLC All Rights Reserved.
319 *
320 * Use of this source code is governed by an MIT-style license that can be
321 * found in the LICENSE file at https://angular.io/license
322 */
323
324/**
325 * Generated bundle index. Do not edit.
326 */
327
328export { MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS, MAT_SLIDE_TOGGLE_REQUIRED_VALIDATOR, MAT_SLIDE_TOGGLE_VALUE_ACCESSOR, MatSlideToggle, MatSlideToggleChange, MatSlideToggleModule, MatSlideToggleRequiredValidator, _MatSlideToggleRequiredValidatorModule };
329//# sourceMappingURL=slide-toggle.js.map
Note: See TracBrowser for help on using the repository browser.