slide-toggle.d.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { FocusMonitor } from '@angular/cdk/a11y';
  9. import { Directionality } from '@angular/cdk/bidi';
  10. import { AfterContentInit, ChangeDetectorRef, ElementRef, EventEmitter, OnDestroy, NgZone } from '@angular/core';
  11. import { ControlValueAccessor } from '@angular/forms';
  12. import { CanColor, CanColorCtor, CanDisable, CanDisableCtor, CanDisableRipple, CanDisableRippleCtor, HammerInput, HasTabIndex, HasTabIndexCtor } from '@angular/material/core';
  13. import { MatSlideToggleDefaultOptions } from './slide-toggle-config';
  14. /** @docs-private */
  15. export declare const MAT_SLIDE_TOGGLE_VALUE_ACCESSOR: any;
  16. /** Change event object emitted by a MatSlideToggle. */
  17. export declare class MatSlideToggleChange {
  18. /** The source MatSlideToggle of the event. */
  19. source: MatSlideToggle;
  20. /** The new `checked` value of the MatSlideToggle. */
  21. checked: boolean;
  22. constructor(
  23. /** The source MatSlideToggle of the event. */
  24. source: MatSlideToggle,
  25. /** The new `checked` value of the MatSlideToggle. */
  26. checked: boolean);
  27. }
  28. /** @docs-private */
  29. declare class MatSlideToggleBase {
  30. _elementRef: ElementRef;
  31. constructor(_elementRef: ElementRef);
  32. }
  33. declare const _MatSlideToggleMixinBase: HasTabIndexCtor & CanColorCtor & CanDisableRippleCtor & CanDisableCtor & typeof MatSlideToggleBase;
  34. /** Represents a slidable "switch" toggle that can be moved between on and off. */
  35. export declare class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestroy, AfterContentInit, ControlValueAccessor, CanDisable, CanColor, HasTabIndex, CanDisableRipple {
  36. private _focusMonitor;
  37. private _changeDetectorRef;
  38. private _ngZone;
  39. defaults: MatSlideToggleDefaultOptions;
  40. _animationMode?: string | undefined;
  41. private _dir?;
  42. private _onChange;
  43. private _onTouched;
  44. private _uniqueId;
  45. private _required;
  46. private _checked;
  47. /** Whether the thumb is currently being dragged. */
  48. private _dragging;
  49. /** Previous checked state before drag started. */
  50. private _previousChecked;
  51. /** Width of the thumb bar of the slide-toggle. */
  52. private _thumbBarWidth;
  53. /** Percentage of the thumb while dragging. Percentage as fraction of 100. */
  54. private _dragPercentage;
  55. /** Reference to the thumb HTMLElement. */
  56. _thumbEl: ElementRef;
  57. /** Reference to the thumb bar HTMLElement. */
  58. _thumbBarEl: ElementRef;
  59. /** Name value will be applied to the input element if present. */
  60. name: string | null;
  61. /** A unique id for the slide-toggle input. If none is supplied, it will be auto-generated. */
  62. id: string;
  63. /** Whether the label should appear after or before the slide-toggle. Defaults to 'after'. */
  64. labelPosition: 'before' | 'after';
  65. /** Used to set the aria-label attribute on the underlying input element. */
  66. ariaLabel: string | null;
  67. /** Used to set the aria-labelledby attribute on the underlying input element. */
  68. ariaLabelledby: string | null;
  69. /** Whether the slide-toggle is required. */
  70. required: boolean;
  71. /** Whether the slide-toggle element is checked or not. */
  72. checked: boolean;
  73. /** An event will be dispatched each time the slide-toggle changes its value. */
  74. readonly change: EventEmitter<MatSlideToggleChange>;
  75. /**
  76. * An event will be dispatched each time the slide-toggle input is toggled.
  77. * This event is always emitted when the user toggles the slide toggle, but this does not mean
  78. * the slide toggle's value has changed. The event does not fire when the user drags to change
  79. * the slide toggle value.
  80. */
  81. readonly toggleChange: EventEmitter<void>;
  82. /**
  83. * An event will be dispatched each time the slide-toggle is dragged.
  84. * This event is always emitted when the user drags the slide toggle to make a change greater
  85. * than 50%. It does not mean the slide toggle's value is changed. The event is not emitted when
  86. * the user toggles the slide toggle to change its value.
  87. */
  88. readonly dragChange: EventEmitter<void>;
  89. /** Returns the unique id for the visual hidden input. */
  90. readonly inputId: string;
  91. /** Reference to the underlying input element. */
  92. _inputElement: ElementRef<HTMLInputElement>;
  93. constructor(elementRef: ElementRef, _focusMonitor: FocusMonitor, _changeDetectorRef: ChangeDetectorRef, tabIndex: string, _ngZone: NgZone, defaults: MatSlideToggleDefaultOptions, _animationMode?: string | undefined, _dir?: Directionality | undefined);
  94. ngAfterContentInit(): void;
  95. ngOnDestroy(): void;
  96. /** Method being called whenever the underlying input emits a change event. */
  97. _onChangeEvent(event: Event): void;
  98. /** Method being called whenever the slide-toggle has been clicked. */
  99. _onInputClick(event: Event): void;
  100. /** Implemented as part of ControlValueAccessor. */
  101. writeValue(value: any): void;
  102. /** Implemented as part of ControlValueAccessor. */
  103. registerOnChange(fn: any): void;
  104. /** Implemented as part of ControlValueAccessor. */
  105. registerOnTouched(fn: any): void;
  106. /** Implemented as a part of ControlValueAccessor. */
  107. setDisabledState(isDisabled: boolean): void;
  108. /** Focuses the slide-toggle. */
  109. focus(options?: FocusOptions): void;
  110. /** Toggles the checked state of the slide-toggle. */
  111. toggle(): void;
  112. /**
  113. * Emits a change event on the `change` output. Also notifies the FormControl about the change.
  114. */
  115. private _emitChangeEvent;
  116. /** Retrieves the percentage of thumb from the moved distance. Percentage as fraction of 100. */
  117. private _getDragPercentage;
  118. _onDragStart(): void;
  119. _onDrag(event: HammerInput): void;
  120. _onDragEnd(): void;
  121. /** Method being called whenever the label text changes. */
  122. _onLabelTextChange(): void;
  123. }
  124. export {};