-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Expand file tree
/
Copy pathline-ripple.ts
More file actions
73 lines (61 loc) · 2.25 KB
/
line-ripple.ts
File metadata and controls
73 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Directive, ElementRef, NgZone, OnDestroy, Renderer2, inject} from '@angular/core';
/** Class added when the line ripple is active. */
const ACTIVATE_CLASS = 'mdc-line-ripple--active';
/** Class added when the line ripple is being deactivated. */
const DEACTIVATING_CLASS = 'mdc-line-ripple--deactivating';
/**
* Internal directive that creates an instance of the MDC line-ripple component. Using a
* directive allows us to conditionally render a line-ripple in the template without having
* to manually create and destroy the `MDCLineRipple` component whenever the condition changes.
*
* The directive sets up the styles for the line-ripple and provides an API for activating
* and deactivating the line-ripple.
*/
@Directive({
selector: 'div[matFormFieldLineRipple]',
host: {
'class': 'mdc-line-ripple',
'aria-hidden': 'true',
},
})
export class MatFormFieldLineRipple implements OnDestroy {
private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
private _cleanupTransitionEnd!: () => void;
constructor(...args: unknown[]);
constructor() {
const ngZone = inject(NgZone);
const renderer = inject(Renderer2);
ngZone.runOutsideAngular(() => {
this._cleanupTransitionEnd = renderer.listen(
this._elementRef.nativeElement,
'transitionend',
this._handleTransitionEnd,
);
});
}
activate() {
const classList = this._elementRef.nativeElement.classList;
classList.remove(DEACTIVATING_CLASS);
classList.add(ACTIVATE_CLASS);
}
deactivate() {
this._elementRef.nativeElement.classList.add(DEACTIVATING_CLASS);
}
private _handleTransitionEnd = (event: TransitionEvent) => {
const classList = this._elementRef.nativeElement.classList;
const isDeactivating = classList.contains(DEACTIVATING_CLASS);
if (event.propertyName === 'opacity' && isDeactivating) {
classList.remove(ACTIVATE_CLASS, DEACTIVATING_CLASS);
}
};
ngOnDestroy() {
this._cleanupTransitionEnd();
}
}