|
| 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 | + |
| 9 | +import { |
| 10 | + ChangeDetectorRef, |
| 11 | + ElementRef, |
| 12 | + EventEmitter, |
| 13 | + InjectionToken, |
| 14 | + QueryList, |
| 15 | +} from '@angular/core'; |
| 16 | +import {Thumb, TickMark} from '@material/slider'; |
| 17 | + |
| 18 | +/** |
| 19 | + * Represents a drag event emitted by the MatSlider component. |
| 20 | + */ |
| 21 | +interface _MatSliderDragEventInterface { |
| 22 | + /** The MatSliderThumb that was interacted with. */ |
| 23 | + source: _MatSliderThumbInterface; |
| 24 | + |
| 25 | + /** The current value of the slider. */ |
| 26 | + value: number; |
| 27 | + |
| 28 | + /** The thumb that was interacted with. */ |
| 29 | + thumb: Thumb; |
| 30 | +} |
| 31 | + |
| 32 | +export interface _MatSliderThumbInterface { |
| 33 | + /** The current value of this slider input. */ |
| 34 | + value: number; |
| 35 | + |
| 36 | + /** Event emitted when the slider thumb starts being dragged. */ |
| 37 | + dragStart: EventEmitter<_MatSliderDragEventInterface>; |
| 38 | + |
| 39 | + /** Event emitted when the slider thumb stops being dragged. */ |
| 40 | + dragEnd: EventEmitter<_MatSliderDragEventInterface>; |
| 41 | + |
| 42 | + /** Event emitted every time the MatSliderThumb is blurred. */ |
| 43 | + _blur: EventEmitter<void>; |
| 44 | + |
| 45 | + /** Event emitted every time the MatSliderThumb is focused. */ |
| 46 | + _focus: EventEmitter<void>; |
| 47 | + |
| 48 | + /** Indicates which slider thumb this input corresponds to. */ |
| 49 | + thumb: Thumb; |
| 50 | + |
| 51 | + /** A reference to MatSliderThumbs root/host element. */ |
| 52 | + _elementRef: ElementRef<HTMLInputElement>; |
| 53 | + |
| 54 | + /** The injected document if available or fallback to the global document reference. */ |
| 55 | + _document: Document; |
| 56 | + |
| 57 | + /** Returns true if this slider input currently has focus. */ |
| 58 | + _isFocused: () => boolean; |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +/** |
| 63 | + * This is a dummy interface that just contains the properties and methods of MatSlider that are |
| 64 | + * used by MatSliderThumb. Rather than directly referencing MatSlider, we use this interface when |
| 65 | + * defining MAT_SLIDER to avoid a circular dependency between MatSlider and MatSliderThumb. |
| 66 | + */ |
| 67 | +export interface _MatSliderInterface { |
| 68 | + /** The slider thumb(s). */ |
| 69 | + _thumbs: QueryList<ElementRef<HTMLElement>>; |
| 70 | + |
| 71 | + /** The slider thumb knob(s) */ |
| 72 | + _knobs: QueryList<ElementRef<HTMLElement>>; |
| 73 | + |
| 74 | + /** The span containing the slider thumb value indicator text */ |
| 75 | + _valueIndicatorTextElements: QueryList<ElementRef<HTMLElement>>; |
| 76 | + |
| 77 | + /** The active section of the slider track. */ |
| 78 | + _trackActive: ElementRef<HTMLElement>; |
| 79 | + |
| 80 | + /** The sliders hidden range input(s). */ |
| 81 | + _inputs: QueryList<_MatSliderThumbInterface>; |
| 82 | + |
| 83 | + /** Whether the slider is disabled. */ |
| 84 | + disabled: boolean; |
| 85 | + |
| 86 | + /** Whether the slider displays a numeric value label upon pressing the thumb. */ |
| 87 | + discrete: boolean; |
| 88 | + |
| 89 | + /** Whether the slider displays tick marks along the slider track. */ |
| 90 | + showTickMarks: boolean; |
| 91 | + |
| 92 | + /** The minimum value that the slider can have. */ |
| 93 | + min: number; |
| 94 | + |
| 95 | + /** The maximum value that the slider can have. */ |
| 96 | + max: number; |
| 97 | + |
| 98 | + /** The values at which the thumb will snap. */ |
| 99 | + step: number; |
| 100 | + |
| 101 | + /** |
| 102 | + * Function that will be used to format the value before it is displayed |
| 103 | + * in the thumb label. Can be used to format very large number in order |
| 104 | + * for them to fit into the slider thumb. |
| 105 | + */ |
| 106 | + displayWith: ((value: number) => string) | null; |
| 107 | + |
| 108 | + /** Whether the foundation has been initialized. */ |
| 109 | + _initialized: boolean; |
| 110 | + |
| 111 | + /** The injected document if available or fallback to the global document reference. */ |
| 112 | + _document: Document; |
| 113 | + |
| 114 | + /** |
| 115 | + * The defaultView of the injected document if |
| 116 | + * available or fallback to global window reference. |
| 117 | + */ |
| 118 | + _window: Window; |
| 119 | + |
| 120 | + /** Used to keep track of & render the active & inactive tick marks on the slider track. */ |
| 121 | + _tickMarks: TickMark[]; |
| 122 | + |
| 123 | + /** The change detector ref. */ |
| 124 | + _cdr: ChangeDetectorRef; |
| 125 | + |
| 126 | + /** A reference to MatSliders root/host element. */ |
| 127 | + _elementRef: ElementRef<HTMLElement>; |
| 128 | + |
| 129 | + /** Sets the value of a slider thumb. */ |
| 130 | + _setValue: (value: number, thumb: Thumb) => void; |
| 131 | + |
| 132 | + /** Whether this is a ranged slider. */ |
| 133 | + _isRange: () => boolean; |
| 134 | + |
| 135 | + /** Gets the slider thumb input of the given thumb. */ |
| 136 | + _getInput: (thumb: Thumb) => _MatSliderThumbInterface; |
| 137 | + |
| 138 | + /** Gets the slider thumb HTML input element of the given thumb. */ |
| 139 | + _getInputElement: (thumb: Thumb) => HTMLInputElement; |
| 140 | + |
| 141 | + /** Gets the slider thumb HTML element of the given thumb. */ |
| 142 | + _getThumbElement: (thumb: Thumb) => HTMLElement; |
| 143 | + |
| 144 | + /** Gets the slider knob HTML element of the given thumb. */ |
| 145 | + _getKnobElement: (thumb: Thumb) => HTMLElement; |
| 146 | + |
| 147 | + /** |
| 148 | + * Sets the value indicator text of the given thumb using the given value. |
| 149 | + * |
| 150 | + * Uses the `displayWith` function if one has been provided. Otherwise, it just uses the |
| 151 | + * numeric value as a string. |
| 152 | + */ |
| 153 | + _setValueIndicatorText: (value: number, thumb: Thumb) => void; |
| 154 | + |
| 155 | + /** Determines the class name for a HTML element. */ |
| 156 | + _getTickMarkClass: (tickMark: TickMark) => string; |
| 157 | + |
| 158 | + /** Returns an array of the thumb types that exist on the current slider instance. */ |
| 159 | + _getThumbTypes: () => Thumb[]; |
| 160 | +} |
| 161 | + |
| 162 | +/** |
| 163 | + * Injection token that can be used to inject instances of MatSlider. |
| 164 | + */ |
| 165 | +export const MAT_SLIDER = new InjectionToken<_MatSliderInterface>('MatSlider'); |
0 commit comments