1
1
import {
2
- style ,
3
- transition ,
4
2
trigger ,
5
3
AnimationEvent ,
6
- state ,
7
- animate ,
8
4
} from '@angular/animations' ;
9
5
import { NgIf , NgTemplateOutlet , AsyncPipe } from '@angular/common' ;
10
6
import {
@@ -27,6 +23,7 @@ import {
27
23
28
24
import { Bem , buildBem , publishRef } from '../utils' ;
29
25
26
+ import { animations , AnimationType } from './animations' ;
30
27
import { TooltipType } from './tooltip.types' ;
31
28
32
29
@Component ( {
@@ -36,37 +33,17 @@ import { TooltipType } from './tooltip.types';
36
33
encapsulation : ViewEncapsulation . None ,
37
34
changeDetection : ChangeDetectionStrategy . OnPush ,
38
35
preserveWhitespaces : false ,
39
- animations : [
40
- trigger ( 'showHide' , [
41
- state (
42
- 'show' ,
43
- style ( {
44
- opacity : 1 ,
45
- transform : 'scale(1)' ,
46
- } ) ,
47
- ) ,
48
- state (
49
- 'hide,void' ,
50
- style ( {
51
- opacity : 0 ,
52
- transform : 'scale(0)' ,
53
- } ) ,
54
- ) ,
55
- transition ( '* => show' , [ animate ( '160ms cubic-bezier(0, 0, 0.2, 1)' ) ] ) ,
56
- transition ( '* => hide' , [
57
- animate ( '160ms cubic-bezier(0.38, 0, 0.24, 1)' ) ,
58
- ] ) ,
59
- ] ) ,
60
- ] ,
36
+ animations : [ trigger ( 'showHide' , animations ) ] ,
61
37
standalone : true ,
62
38
imports : [ NgIf , NgTemplateOutlet , AsyncPipe ] ,
63
39
} )
64
40
export class TooltipComponent implements OnDestroy {
65
41
text : string ;
66
42
template : TemplateRef < any > ;
67
43
bem : Bem = buildBem ( 'aui-tooltip' ) ;
68
- showHide : 'show' | 'hide' = 'hide' ;
44
+ showHide = 'scale- hide' ;
69
45
disableAnimation = true ;
46
+ animationType : AnimationType ;
70
47
71
48
inputContent$ : Observable < string | TemplateRef < any > > ;
72
49
inputType$ : Observable < TooltipType > ;
@@ -103,6 +80,7 @@ export class TooltipComponent implements OnDestroy {
103
80
inputClass$ : Observable < string > ;
104
81
inputContext$ : Observable < any > ;
105
82
disableAnimation ?: boolean ;
83
+ animationType ?: string ;
106
84
} ) {
107
85
Object . assign ( this , inputs ) ;
108
86
this . text$ = this . inputContent$ . pipe (
@@ -131,9 +109,12 @@ export class TooltipComponent implements OnDestroy {
131
109
map ( ( [ inputPosition , inputType , inputClass ] ) => {
132
110
const b = this . bem . block ( ) ;
133
111
const dir = inputPosition . split ( ' ' ) [ 0 ] ;
134
- return inputType === TooltipType . Plain
135
- ? `${ b } --${ dir } ${ inputClass } `
136
- : `${ b } ${ b } --${ inputType } ${ b } --${ dir } ${ inputClass } ` ;
112
+ return (
113
+ `${ b } --${ dir } ${ inputClass } ${ this . bem . element (
114
+ 'transform-origin' ,
115
+ ) } ` +
116
+ ( inputType === TooltipType . Plain ? '' : `${ b } ${ b } --${ inputType } ` )
117
+ ) ;
137
118
} ) ,
138
119
publishRef ( ) ,
139
120
) ;
@@ -143,20 +124,20 @@ export class TooltipComponent implements OnDestroy {
143
124
onAnimation ( event : AnimationEvent ) {
144
125
const { phaseName, toState } = event ;
145
126
this . animating$$ . next ( phaseName === 'start' ) ;
146
- if ( toState === ' hide' && phaseName === 'done' ) {
127
+ if ( toState . endsWith ( '- hide') && phaseName === 'done' ) {
147
128
this . hide$ . next ( true ) ;
148
129
}
149
130
}
150
131
151
132
show ( ) {
152
133
this . beforeShow$ . next ( null ) ;
153
- this . showHide = ' show' ;
134
+ this . showHide = ` ${ this . animationType } - show` ;
154
135
this . cdr . markForCheck ( ) ;
155
136
}
156
137
157
138
hide ( ) {
158
139
this . beforeHide$ . next ( null ) ;
159
- this . showHide = ' hide' ;
140
+ this . showHide = ` ${ this . animationType } - hide` ;
160
141
this . cdr . markForCheck ( ) ;
161
142
}
162
143
}
0 commit comments