legacy-slide-toggle.mjs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import * as i3 from '@angular/cdk/observers';
  2. import { ObserversModule } from '@angular/cdk/observers';
  3. import * as i0 from '@angular/core';
  4. import { InjectionToken, forwardRef, Component, ViewEncapsulation, ChangeDetectionStrategy, Attribute, Inject, Optional, ViewChild, NgModule } from '@angular/core';
  5. import * as i2 from '@angular/material/core';
  6. import { MatRippleModule, MatCommonModule } from '@angular/material/core';
  7. import * as i1 from '@angular/cdk/a11y';
  8. import { NG_VALUE_ACCESSOR } from '@angular/forms';
  9. import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
  10. import { _MatSlideToggleBase, _MatSlideToggleRequiredValidatorModule } from '@angular/material/slide-toggle';
  11. export { MAT_SLIDE_TOGGLE_REQUIRED_VALIDATOR as MAT_LEGACY_SLIDE_TOGGLE_REQUIRED_VALIDATOR, MatSlideToggleRequiredValidator as MatLegacySlideToggleRequiredValidator, _MatSlideToggleBase as _MatLegacySlideToggleBase, _MatSlideToggleRequiredValidatorModule as _MatLegacySlideToggleRequiredValidatorModule } from '@angular/material/slide-toggle';
  12. /**
  13. * Injection token to be used to override the default options for `mat-slide-toggle`
  14. * @deprecated Use `MAT_SLIDE_TOGGLE_DEFAULT_OPTIONS` from `@angular/material/slide-toggle` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  15. * @breaking-change 17.0.0
  16. */
  17. const MAT_LEGACY_SLIDE_TOGGLE_DEFAULT_OPTIONS = new InjectionToken('mat-slide-toggle-default-options', {
  18. providedIn: 'root',
  19. factory: () => ({ disableToggleValue: false }),
  20. });
  21. /**
  22. * @docs-private
  23. * @deprecated Use `MAT_SLIDE_TOGGLE_VALUE_ACCESSOR` from `@angular/material/slide-toggle` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  24. * @breaking-change 17.0.0
  25. */
  26. const MAT_LEGACY_SLIDE_TOGGLE_VALUE_ACCESSOR = {
  27. provide: NG_VALUE_ACCESSOR,
  28. useExisting: forwardRef(() => MatLegacySlideToggle),
  29. multi: true,
  30. };
  31. /**
  32. * Change event object emitted by a slide toggle.
  33. * @deprecated Use `MatSlideToggleChange` from `@angular/material/slide-toggle` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  34. * @breaking-change 17.0.0
  35. */
  36. class MatLegacySlideToggleChange {
  37. constructor(
  38. /** The source slide toggle of the event. */
  39. source,
  40. /** The new `checked` value of the slide toggle. */
  41. checked) {
  42. this.source = source;
  43. this.checked = checked;
  44. }
  45. }
  46. /**
  47. * Represents a slidable "switch" toggle that can be moved between on and off.
  48. * @deprecated Use `MatSlideToggle` from `@angular/material/slide-toggle` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  49. * @breaking-change 17.0.0
  50. */
  51. class MatLegacySlideToggle extends _MatSlideToggleBase {
  52. constructor(elementRef, focusMonitor, changeDetectorRef, tabIndex, defaults, animationMode) {
  53. super(elementRef, focusMonitor, changeDetectorRef, tabIndex, defaults, animationMode, 'mat-slide-toggle-');
  54. }
  55. _createChangeEvent(isChecked) {
  56. return new MatLegacySlideToggleChange(this, isChecked);
  57. }
  58. /** Method being called whenever the underlying input emits a change event. */
  59. _onChangeEvent(event) {
  60. // We always have to stop propagation on the change event.
  61. // Otherwise the change event, from the input element, will bubble up and
  62. // emit its event object to the component's `change` output.
  63. event.stopPropagation();
  64. this.toggleChange.emit();
  65. // When the slide toggle's config disables toggle change event by setting
  66. // `disableToggleValue: true`, the slide toggle's value does not change, and the
  67. // checked state of the underlying input needs to be changed back.
  68. if (this.defaults.disableToggleValue) {
  69. this._inputElement.nativeElement.checked = this.checked;
  70. return;
  71. }
  72. // Sync the value from the underlying input element with the component instance.
  73. this.checked = this._inputElement.nativeElement.checked;
  74. // Emit our custom change event only if the underlying input emitted one. This ensures that
  75. // there is no change event, when the checked state changes programmatically.
  76. this._emitChangeEvent();
  77. }
  78. /** Method being called whenever the slide-toggle has been clicked. */
  79. _onInputClick(event) {
  80. // We have to stop propagation for click events on the visual hidden input element.
  81. // By default, when a user clicks on a label element, a generated click event will be
  82. // dispatched on the associated input element. Since we are using a label element as our
  83. // root container, the click event on the `slide-toggle` will be executed twice.
  84. // The real click event will bubble up, and the generated click event also tries to bubble up.
  85. // This will lead to multiple click events.
  86. // Preventing bubbling for the second event will solve that issue.
  87. event.stopPropagation();
  88. }
  89. /** Focuses the slide-toggle. */
  90. focus(options, origin) {
  91. if (origin) {
  92. this._focusMonitor.focusVia(this._inputElement, origin, options);
  93. }
  94. else {
  95. this._inputElement.nativeElement.focus(options);
  96. }
  97. }
  98. /** Method being called whenever the label text changes. */
  99. _onLabelTextChange() {
  100. // Since the event of the `cdkObserveContent` directive runs outside of the zone, the
  101. // slide-toggle component will be only marked for check, but no actual change detection runs
  102. // automatically. Instead of going back into the zone in order to trigger a change detection
  103. // which causes *all* components to be checked (if explicitly marked or not using OnPush),
  104. // we only trigger an explicit change detection for the slide-toggle view and its children.
  105. this._changeDetectorRef.detectChanges();
  106. }
  107. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlideToggle, deps: [{ token: i0.ElementRef }, { token: i1.FocusMonitor }, { token: i0.ChangeDetectorRef }, { token: 'tabindex', attribute: true }, { token: MAT_LEGACY_SLIDE_TOGGLE_DEFAULT_OPTIONS }, { token: ANIMATION_MODULE_TYPE, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
  108. static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.0", type: MatLegacySlideToggle, selector: "mat-slide-toggle", inputs: { disabled: "disabled", disableRipple: "disableRipple", color: "color", tabIndex: "tabIndex" }, host: { properties: { "id": "id", "attr.tabindex": "null", "attr.aria-label": "null", "attr.aria-labelledby": "null", "attr.name": "null", "class.mat-checked": "checked", "class.mat-disabled": "disabled", "class.mat-slide-toggle-label-before": "labelPosition == \"before\"", "class._mat-animation-noopable": "_noopAnimations" }, classAttribute: "mat-slide-toggle" }, providers: [MAT_LEGACY_SLIDE_TOGGLE_VALUE_ACCESSOR], viewQueries: [{ propertyName: "_inputElement", first: true, predicate: ["input"], descendants: true }], exportAs: ["matSlideToggle"], usesInheritance: true, ngImport: i0, template: "<label [attr.for]=\"inputId\" class=\"mat-slide-toggle-label\" #label>\n <span 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\"\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 <span class=\"mat-slide-toggle-thumb-container\">\n <span class=\"mat-slide-toggle-thumb\"></span>\n <span 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 <span class=\"mat-ripple-element mat-slide-toggle-persistent-ripple\"></span>\n </span>\n </span>\n\n </span>\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", styles: [".mat-slide-toggle{display:inline-block;height:24px;max-width:100%;line-height:24px;white-space:nowrap;outline:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.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;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%;display:block}.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}}.mat-slide-toggle-input:focus~.mat-slide-toggle-thumb-container .mat-focus-indicator::before{content:\"\"}.cdk-high-contrast-active .mat-slide-toggle-thumb,.cdk-high-contrast-active .mat-slide-toggle-bar{border:1px solid}"], dependencies: [{ kind: "directive", type: i2.MatRipple, selector: "[mat-ripple], [matRipple]", inputs: ["matRippleColor", "matRippleUnbounded", "matRippleCentered", "matRippleRadius", "matRippleAnimation", "matRippleDisabled", "matRippleTrigger"], exportAs: ["matRipple"] }, { kind: "directive", type: i3.CdkObserveContent, selector: "[cdkObserveContent]", inputs: ["cdkObserveContentDisabled", "debounce"], outputs: ["cdkObserveContent"], exportAs: ["cdkObserveContent"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
  109. }
  110. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlideToggle, decorators: [{
  111. type: Component,
  112. args: [{ selector: 'mat-slide-toggle', exportAs: 'matSlideToggle', host: {
  113. 'class': 'mat-slide-toggle',
  114. '[id]': 'id',
  115. // Needs to be removed since it causes some a11y issues (see #21266).
  116. '[attr.tabindex]': 'null',
  117. '[attr.aria-label]': 'null',
  118. '[attr.aria-labelledby]': 'null',
  119. '[attr.name]': 'null',
  120. '[class.mat-checked]': 'checked',
  121. '[class.mat-disabled]': 'disabled',
  122. '[class.mat-slide-toggle-label-before]': 'labelPosition == "before"',
  123. '[class._mat-animation-noopable]': '_noopAnimations',
  124. }, providers: [MAT_LEGACY_SLIDE_TOGGLE_VALUE_ACCESSOR], inputs: ['disabled', 'disableRipple', 'color', 'tabIndex'], encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, template: "<label [attr.for]=\"inputId\" class=\"mat-slide-toggle-label\" #label>\n <span 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\"\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 <span class=\"mat-slide-toggle-thumb-container\">\n <span class=\"mat-slide-toggle-thumb\"></span>\n <span 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 <span class=\"mat-ripple-element mat-slide-toggle-persistent-ripple\"></span>\n </span>\n </span>\n\n </span>\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", styles: [".mat-slide-toggle{display:inline-block;height:24px;max-width:100%;line-height:24px;white-space:nowrap;outline:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}.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;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%;display:block}.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}}.mat-slide-toggle-input:focus~.mat-slide-toggle-thumb-container .mat-focus-indicator::before{content:\"\"}.cdk-high-contrast-active .mat-slide-toggle-thumb,.cdk-high-contrast-active .mat-slide-toggle-bar{border:1px solid}"] }]
  125. }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.FocusMonitor }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
  126. type: Attribute,
  127. args: ['tabindex']
  128. }] }, { type: undefined, decorators: [{
  129. type: Inject,
  130. args: [MAT_LEGACY_SLIDE_TOGGLE_DEFAULT_OPTIONS]
  131. }] }, { type: undefined, decorators: [{
  132. type: Optional
  133. }, {
  134. type: Inject,
  135. args: [ANIMATION_MODULE_TYPE]
  136. }] }]; }, propDecorators: { _inputElement: [{
  137. type: ViewChild,
  138. args: ['input']
  139. }] } });
  140. /**
  141. * @deprecated Use `MatSlideToggleModule` from `@angular/material/slide-toggle` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.
  142. * @breaking-change 17.0.0
  143. */
  144. class MatLegacySlideToggleModule {
  145. static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlideToggleModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
  146. static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlideToggleModule, declarations: [MatLegacySlideToggle], imports: [_MatSlideToggleRequiredValidatorModule,
  147. MatRippleModule,
  148. MatCommonModule,
  149. ObserversModule], exports: [_MatSlideToggleRequiredValidatorModule, MatLegacySlideToggle, MatCommonModule] }); }
  150. static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlideToggleModule, imports: [_MatSlideToggleRequiredValidatorModule,
  151. MatRippleModule,
  152. MatCommonModule,
  153. ObserversModule, _MatSlideToggleRequiredValidatorModule, MatCommonModule] }); }
  154. }
  155. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MatLegacySlideToggleModule, decorators: [{
  156. type: NgModule,
  157. args: [{
  158. imports: [
  159. _MatSlideToggleRequiredValidatorModule,
  160. MatRippleModule,
  161. MatCommonModule,
  162. ObserversModule,
  163. ],
  164. exports: [_MatSlideToggleRequiredValidatorModule, MatLegacySlideToggle, MatCommonModule],
  165. declarations: [MatLegacySlideToggle],
  166. }]
  167. }] });
  168. /**
  169. * Generated bundle index. Do not edit.
  170. */
  171. export { MAT_LEGACY_SLIDE_TOGGLE_DEFAULT_OPTIONS, MAT_LEGACY_SLIDE_TOGGLE_VALUE_ACCESSOR, MatLegacySlideToggle, MatLegacySlideToggleChange, MatLegacySlideToggleModule };
  172. //# sourceMappingURL=legacy-slide-toggle.mjs.map