Skip to content

Commit bd1d2fc

Browse files
igauchfengtianze
authored andcommitted
feat: select and dropdown add animation
1 parent 6428896 commit bd1d2fc

8 files changed

+78
-37
lines changed

src/dropdown/dropdown.directive.ts

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export class DropdownDirective extends BaseTooltip implements OnInit {
7373
this.type = TooltipType.Plain;
7474
this.position = 'bottom end';
7575
this.trigger = TooltipTrigger.Click;
76+
this.disableAnimation = false;
77+
this.animationType = 'scaleY';
7678
}
7779

7880
ngOnInit() {

src/dropdown/submenu/submenu.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<button
22
[class]="className"
33
[auiTooltip]="menu.template"
4-
[auiDisableAnimation]="true"
4+
auiTooltipAnimationType="scaleY"
55
[auiTooltipDisabled]="disabled"
66
[auiTooltipTrigger]="trigger"
77
[auiTooltipHideOnClick]="true"

src/select/multi-select/multi-select.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#selectRef
44
#tooltipRef="auiTooltip"
55
[auiTooltip]="templateRef"
6-
[auiDisableAnimation]="true"
6+
auiTooltipAnimationType="scaleY"
77
[auiTooltipDisabled]="disabled"
88
auiTooltipTrigger="click"
99
auiTooltipPosition="bottom start"

src/select/select.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#selectRef
88
#tooltipRef="auiTooltip"
99
[auiTooltip]="templateRef"
10-
[auiDisableAnimation]="true"
10+
auiTooltipAnimationType="scaleY"
1111
[auiTooltipDisabled]="disabled"
1212
auiTooltipTrigger="click"
1313
auiTooltipPosition="bottom start"

src/tooltip/animations.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { animate, state, style, transition } from '@angular/animations';
2+
3+
export const scale = [
4+
state(
5+
'scale-show',
6+
style({
7+
opacity: 1,
8+
transform: 'scale(1)',
9+
}),
10+
),
11+
state(
12+
'scale-hide,void',
13+
style({
14+
opacity: 0,
15+
transform: 'scale(0)',
16+
}),
17+
),
18+
transition('scale-hide => scale-show, void => scale-show', [
19+
animate('160ms cubic-bezier(0, 0, 0.2, 1)'),
20+
]),
21+
transition('scale-show => scale-hide', [
22+
animate('160ms cubic-bezier(0.38, 0, 0.24, 1)'),
23+
]),
24+
];
25+
26+
export const scaleY = [
27+
state(
28+
'scaleY-show',
29+
style({
30+
opacity: 1,
31+
transform: 'scaleY(1)',
32+
}),
33+
),
34+
state(
35+
'scaleY-hide,void',
36+
style({
37+
opacity: 0,
38+
transform: 'scaleY(0)',
39+
}),
40+
),
41+
transition('scaleY-hide => scaleY-show, void => scaleY-show', [
42+
animate('160ms cubic-bezier(0, 0, 0.2, 1)'),
43+
]),
44+
transition('scaleY-show => scaleY-hide', [
45+
animate('160ms cubic-bezier(0.38, 0, 0.24, 1)'),
46+
]),
47+
];
48+
49+
export const animations = [...scale, ...scaleY];
50+
51+
export type AnimationType = 'scale' | 'scaleY';

src/tooltip/base-tooltip.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030

3131
import { sleep } from '../utils';
3232

33+
import { AnimationType } from './animations';
3334
import { TooltipComponent } from './tooltip.component';
3435
import { TooltipTrigger, TooltipType } from './tooltip.types';
3536
import { getOriginPosition, getOverlayPosition } from './utils';
@@ -134,6 +135,7 @@ export class BaseTooltip<T = any>
134135

135136
hideOnClick = false;
136137
disableAnimation = true;
138+
animationType: AnimationType = 'scale';
137139

138140
visibleChange = new EventEmitter<boolean>();
139141

@@ -254,6 +256,7 @@ export class BaseTooltip<T = any>
254256
inputPosition$: this.inputPosition$$.asObservable(),
255257
inputType$: this.inputType$$.asObservable(),
256258
disableAnimation: this.disableAnimation,
259+
animationType: this.animationType,
257260
});
258261
this.componentIns.hide$.pipe(takeUntil(this.destroy$)).subscribe(() => {
259262
this._disposeTooltip();
@@ -417,7 +420,7 @@ export class BaseTooltip<T = any>
417420
.position()
418421
.flexibleConnectedTo(this.elRef)
419422
.withGrowAfterOpen(true)
420-
.withTransformOriginOn('.aui-tooltip')
423+
.withTransformOriginOn('.aui-tooltip__transform-origin')
421424
.withPositions([
422425
{ ...originPosition.main, ...overlayPosition.main },
423426
{ ...originPosition.fallback, ...overlayPosition.fallback },

src/tooltip/tooltip.component.ts

+14-33
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import {
2-
style,
3-
transition,
42
trigger,
53
AnimationEvent,
6-
state,
7-
animate,
84
} from '@angular/animations';
95
import { NgIf, NgTemplateOutlet, AsyncPipe } from '@angular/common';
106
import {
@@ -27,6 +23,7 @@ import {
2723

2824
import { Bem, buildBem, publishRef } from '../utils';
2925

26+
import { animations, AnimationType } from './animations';
3027
import { TooltipType } from './tooltip.types';
3128

3229
@Component({
@@ -36,37 +33,17 @@ import { TooltipType } from './tooltip.types';
3633
encapsulation: ViewEncapsulation.None,
3734
changeDetection: ChangeDetectionStrategy.OnPush,
3835
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)],
6137
standalone: true,
6238
imports: [NgIf, NgTemplateOutlet, AsyncPipe],
6339
})
6440
export class TooltipComponent implements OnDestroy {
6541
text: string;
6642
template: TemplateRef<any>;
6743
bem: Bem = buildBem('aui-tooltip');
68-
showHide: 'show' | 'hide' = 'hide';
44+
showHide = 'scale-hide';
6945
disableAnimation = true;
46+
animationType: AnimationType;
7047

7148
inputContent$: Observable<string | TemplateRef<any>>;
7249
inputType$: Observable<TooltipType>;
@@ -103,6 +80,7 @@ export class TooltipComponent implements OnDestroy {
10380
inputClass$: Observable<string>;
10481
inputContext$: Observable<any>;
10582
disableAnimation?: boolean;
83+
animationType?: string;
10684
}) {
10785
Object.assign(this, inputs);
10886
this.text$ = this.inputContent$.pipe(
@@ -131,9 +109,12 @@ export class TooltipComponent implements OnDestroy {
131109
map(([inputPosition, inputType, inputClass]) => {
132110
const b = this.bem.block();
133111
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+
);
137118
}),
138119
publishRef(),
139120
);
@@ -143,20 +124,20 @@ export class TooltipComponent implements OnDestroy {
143124
onAnimation(event: AnimationEvent) {
144125
const { phaseName, toState } = event;
145126
this.animating$$.next(phaseName === 'start');
146-
if (toState === 'hide' && phaseName === 'done') {
127+
if (toState.endsWith('-hide') && phaseName === 'done') {
147128
this.hide$.next(true);
148129
}
149130
}
150131

151132
show() {
152133
this.beforeShow$.next(null);
153-
this.showHide = 'show';
134+
this.showHide = `${this.animationType}-show`;
154135
this.cdr.markForCheck();
155136
}
156137

157138
hide() {
158139
this.beforeHide$.next(null);
159-
this.showHide = 'hide';
140+
this.showHide = `${this.animationType}-hide`;
160141
this.cdr.markForCheck();
161142
}
162143
}

src/tooltip/tooltip.directive.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Directive, EventEmitter, Input, Output } from '@angular/core';
22

3+
import { AnimationType } from './animations';
34
import { BaseTooltip } from './base-tooltip';
45

56
@Directive({
@@ -29,4 +30,7 @@ export class TooltipDirective extends BaseTooltip {
2930

3031
@Input('auiDisableAnimation')
3132
override disableAnimation = false;
33+
34+
@Input('auiTooltipAnimationType')
35+
override animationType: AnimationType;
3236
}

0 commit comments

Comments
 (0)