|
8 | 8 |
|
9 | 9 | import {SpecificEventListener, EventType} from '@material/base';
|
10 | 10 | import {MDCSliderAdapter, Thumb, TickMark} from '@material/slider';
|
| 11 | +import {MatSlider} from './slider'; |
11 | 12 |
|
12 | 13 | export class SliderAdapter implements MDCSliderAdapter {
|
13 |
| - hasClass(className: string): boolean { |
14 |
| - throw Error('Method not implemented.'); |
| 14 | + constructor(private readonly _delegate: MatSlider) {} |
| 15 | + hasClass = (className: string): boolean => { |
| 16 | + return this._delegate._hostElement.classList.contains(className); |
15 | 17 | }
|
16 |
| - addClass(className: string): void { |
17 |
| - throw Error('Method not implemented.'); |
| 18 | + addClass = (className: string): void => { |
| 19 | + this._delegate._hostElement.classList.add(className); |
18 | 20 | }
|
19 |
| - removeClass(className: string): void { |
20 |
| - throw Error('Method not implemented.'); |
| 21 | + removeClass = (className: string): void => { |
| 22 | + this._delegate._hostElement.classList.remove(className); |
21 | 23 | }
|
22 |
| - getAttribute(attribute: string): string | null { |
23 |
| - throw Error('Method not implemented.'); |
| 24 | + getAttribute = (attribute: string): string | null => { |
| 25 | + return this._delegate._hostElement.getAttribute(attribute); |
24 | 26 | }
|
25 |
| - addThumbClass(className: string, thumb: Thumb): void { |
26 |
| - throw Error('Method not implemented.'); |
| 27 | + addThumbClass = (className: string, thumb: Thumb): void => { |
| 28 | + this._delegate._getThumbElement(thumb).classList.add(className); |
27 | 29 | }
|
28 |
| - removeThumbClass(className: string, thumb: Thumb): void { |
29 |
| - throw Error('Method not implemented.'); |
| 30 | + removeThumbClass = (className: string, thumb: Thumb): void => { |
| 31 | + this._delegate._getThumbElement(thumb).classList.remove(className); |
30 | 32 | }
|
31 |
| - getInputValue(thumb: Thumb): string { |
32 |
| - throw Error('Method not implemented.'); |
| 33 | + getInputValue = (thumb: Thumb): string => { |
| 34 | + return this._delegate._getInputElement(thumb).value; |
33 | 35 | }
|
34 |
| - setInputValue(value: string, thumb: Thumb): void { |
35 |
| - throw Error('Method not implemented.'); |
| 36 | + setInputValue = (value: string, thumb: Thumb): void => { |
| 37 | + this._delegate._getInputElement(thumb).value = value; |
36 | 38 | }
|
37 |
| - getInputAttribute(attribute: string, thumb: Thumb): string | null { |
38 |
| - throw Error('Method not implemented.'); |
| 39 | + getInputAttribute = (attribute: string, thumb: Thumb): string | null => { |
| 40 | + return this._delegate._getInputElement(thumb).getAttribute(attribute); |
39 | 41 | }
|
40 |
| - setInputAttribute(attribute: string, value: string, thumb: Thumb): void { |
41 |
| - throw Error('Method not implemented.'); |
| 42 | + setInputAttribute = (attribute: string, value: string, thumb: Thumb): void => { |
| 43 | + this._delegate._getInputElement(thumb).setAttribute(attribute, value); |
42 | 44 | }
|
43 |
| - removeInputAttribute(attribute: string, thumb: Thumb): void { |
44 |
| - throw Error('Method not implemented.'); |
| 45 | + removeInputAttribute = (attribute: string, thumb: Thumb): void => { |
| 46 | + this._delegate._getInputElement(thumb).removeAttribute(attribute); |
45 | 47 | }
|
46 |
| - focusInput(thumb: Thumb): void { |
47 |
| - throw Error('Method not implemented.'); |
| 48 | + focusInput = (thumb: Thumb): void => { |
| 49 | + this._delegate._getInputElement(thumb).focus(); |
48 | 50 | }
|
49 |
| - isInputFocused(thumb: Thumb): boolean { |
50 |
| - throw Error('Method not implemented.'); |
| 51 | + isInputFocused = (thumb: Thumb): boolean => { |
| 52 | + return this._delegate._getInput(thumb)._isFocused(); |
51 | 53 | }
|
52 |
| - getThumbKnobWidth(thumb: Thumb): number { |
53 |
| - throw Error('Method not implemented.'); |
| 54 | + getThumbKnobWidth = (thumb: Thumb): number => { |
| 55 | + return this._delegate._getKnobElement(thumb).getBoundingClientRect().width; |
54 | 56 | }
|
55 |
| - getThumbBoundingClientRect(thumb: Thumb): ClientRect { |
56 |
| - throw Error('Method not implemented.'); |
| 57 | + getThumbBoundingClientRect = (thumb: Thumb): ClientRect => { |
| 58 | + return this._delegate._getThumbElement(thumb).getBoundingClientRect(); |
57 | 59 | }
|
58 |
| - getBoundingClientRect(): ClientRect { |
59 |
| - throw Error('Method not implemented.'); |
| 60 | + getBoundingClientRect = (): ClientRect => { |
| 61 | + return this._delegate._hostElement.getBoundingClientRect(); |
60 | 62 | }
|
61 |
| - isRTL(): boolean { |
62 |
| - throw Error('Method not implemented.'); |
| 63 | + isRTL = (): boolean => { |
| 64 | + // TODO(wagnermaciel): Actually implementing this. |
| 65 | + // throw Error('Method not implemented.'); |
| 66 | + return false; |
63 | 67 | }
|
64 |
| - setThumbStyleProperty(propertyName: string, value: string, thumb: Thumb): void { |
65 |
| - throw Error('Method not implemented.'); |
| 68 | + setThumbStyleProperty = (propertyName: string, value: string, thumb: Thumb): void => { |
| 69 | + this._delegate._getThumbElement(thumb).style.setProperty(propertyName, value); |
66 | 70 | }
|
67 |
| - removeThumbStyleProperty(propertyName: string, thumb: Thumb): void { |
68 |
| - throw Error('Method not implemented.'); |
| 71 | + removeThumbStyleProperty = (propertyName: string, thumb: Thumb): void => { |
| 72 | + this._delegate._getThumbElement(thumb).style.removeProperty(propertyName); |
69 | 73 | }
|
70 |
| - setTrackActiveStyleProperty(propertyName: string, value: string): void { |
71 |
| - throw Error('Method not implemented.'); |
| 74 | + setTrackActiveStyleProperty = (propertyName: string, value: string): void => { |
| 75 | + this._delegate._trackActive.nativeElement.style.setProperty(propertyName, value); |
72 | 76 | }
|
73 |
| - removeTrackActiveStyleProperty(propertyName: string): void { |
74 |
| - throw Error('Method not implemented.'); |
| 77 | + removeTrackActiveStyleProperty = (propertyName: string): void => { |
| 78 | + this._delegate._trackActive.nativeElement.style.removeProperty(propertyName); |
75 | 79 | }
|
76 |
| - setValueIndicatorText(value: number, thumb: Thumb): void { |
77 |
| - throw Error('Method not implemented.'); |
| 80 | + setValueIndicatorText = (value: number, thumb: Thumb): void => { |
| 81 | + this._delegate._setValueIndicatorText(value, thumb); |
78 | 82 | }
|
79 |
| - getValueToAriaValueTextFn(): ((value: number) => string) | null { |
80 |
| - throw Error('Method not implemented.'); |
| 83 | + getValueToAriaValueTextFn = (): ((value: number) => string) | null => { |
| 84 | + return this._delegate.displayWith; |
81 | 85 | }
|
82 |
| - updateTickMarks(tickMarks: TickMark[]): void { |
83 |
| - throw Error('Method not implemented.'); |
| 86 | + updateTickMarks = (tickMarks: TickMark[]): void => { |
| 87 | + this._delegate._tickMarks = tickMarks; |
| 88 | + this._delegate._cdr.markForCheck(); |
84 | 89 | }
|
85 |
| - setPointerCapture(pointerId: number): void { |
86 |
| - throw Error('Method not implemented.'); |
| 90 | + setPointerCapture = (pointerId: number): void => { |
| 91 | + this._delegate._hostElement.setPointerCapture(pointerId); |
87 | 92 | }
|
88 |
| - emitChangeEvent(value: number, thumb: Thumb): void { |
89 |
| - throw Error('Method not implemented.'); |
| 93 | + emitChangeEvent = (value: number, thumb: Thumb): void => {}; |
| 94 | + emitInputEvent = (value: number, thumb: Thumb): void => {}; |
| 95 | + emitDragStartEvent = (value: number, thumb: Thumb): void => { |
| 96 | + const input = this._delegate._getInput(thumb); |
| 97 | + input.dragStart.emit({ |
| 98 | + source: input, |
| 99 | + parent: this._delegate, |
| 100 | + value, |
| 101 | + thumb, |
| 102 | + }); |
90 | 103 | }
|
91 |
| - emitInputEvent(value: number, thumb: Thumb): void { |
92 |
| - throw Error('Method not implemented.'); |
| 104 | + emitDragEndEvent = (value: number, thumb: Thumb): void => { |
| 105 | + const input = this._delegate._getInput(thumb); |
| 106 | + input.dragEnd.emit({ |
| 107 | + source: input, |
| 108 | + parent: this._delegate, |
| 109 | + value, |
| 110 | + thumb, |
| 111 | + }); |
93 | 112 | }
|
94 |
| - emitDragStartEvent(value: number, thumb: Thumb): void { |
95 |
| - throw Error('Method not implemented.'); |
| 113 | + registerEventHandler = |
| 114 | + <K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => { |
| 115 | + this._delegate._hostElement.addEventListener(evtType, handler); |
96 | 116 | }
|
97 |
| - emitDragEndEvent(value: number, thumb: Thumb): void { |
98 |
| - throw Error('Method not implemented.'); |
| 117 | + deregisterEventHandler = |
| 118 | + <K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => { |
| 119 | + this._delegate._hostElement.removeEventListener(evtType, handler); |
99 | 120 | }
|
100 |
| - registerEventHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void { |
101 |
| - throw Error('Method not implemented.'); |
| 121 | + registerThumbEventHandler = |
| 122 | + <K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => { |
| 123 | + this._delegate._getThumbElement(thumb).addEventListener(evtType, handler); |
102 | 124 | }
|
103 |
| - deregisterEventHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void { |
104 |
| - throw Error('Method not implemented.'); |
| 125 | + deregisterThumbEventHandler = |
| 126 | + <K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => { |
| 127 | + this._delegate._getThumbElement(thumb).removeEventListener(evtType, handler); |
105 | 128 | }
|
106 |
| - registerThumbEventHandler<K extends EventType> |
107 |
| - (thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void { |
108 |
| - throw Error('Method not implemented.'); |
| 129 | + registerInputEventHandler = |
| 130 | + <K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => { |
| 131 | + this._delegate._getInputElement(thumb).addEventListener(evtType, handler); |
109 | 132 | }
|
110 |
| - deregisterThumbEventHandler<K extends EventType> |
111 |
| - (thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void { |
112 |
| - throw Error('Method not implemented.'); |
| 133 | + deregisterInputEventHandler = |
| 134 | + <K extends EventType>(thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void => { |
| 135 | + this._delegate._getInputElement(thumb).removeEventListener(evtType, handler); |
113 | 136 | }
|
114 |
| - registerInputEventHandler<K extends EventType> |
115 |
| - (thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void { |
116 |
| - throw Error('Method not implemented.'); |
| 137 | + registerBodyEventHandler = |
| 138 | + <K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => { |
| 139 | + this._delegate._document.body.addEventListener(evtType, handler); |
117 | 140 | }
|
118 |
| - deregisterInputEventHandler<K extends EventType> |
119 |
| - (thumb: Thumb, evtType: K, handler: SpecificEventListener<K>): void { |
120 |
| - throw Error('Method not implemented.'); |
| 141 | + deregisterBodyEventHandler = |
| 142 | + <K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => { |
| 143 | + this._delegate._document.body.removeEventListener(evtType, handler); |
121 | 144 | }
|
122 |
| - registerBodyEventHandler<K extends EventType> |
123 |
| - (evtType: K, handler: SpecificEventListener<K>): void { |
124 |
| - throw Error('Method not implemented.'); |
125 |
| - } |
126 |
| - deregisterBodyEventHandler<K extends EventType> |
127 |
| - (evtType: K, handler: SpecificEventListener<K>): void { |
128 |
| - throw Error('Method not implemented.'); |
129 |
| - } |
130 |
| - registerWindowEventHandler<K extends EventType> |
131 |
| - (evtType: K, handler: SpecificEventListener<K>): void { |
132 |
| - throw Error('Method not implemented.'); |
133 |
| - } |
134 |
| - deregisterWindowEventHandler<K extends EventType> |
135 |
| - (evtType: K, handler: SpecificEventListener<K>): void { |
136 |
| - throw Error('Method not implemented.'); |
| 145 | + registerWindowEventHandler = |
| 146 | + <K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => { |
| 147 | + this._delegate._window.addEventListener(evtType, handler); |
| 148 | + } |
| 149 | + deregisterWindowEventHandler = |
| 150 | + <K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void => { |
| 151 | + this._delegate._window.removeEventListener(evtType, handler); |
137 | 152 | }
|
138 | 153 | }
|
0 commit comments