Skip to content

Commit dbec3d6

Browse files
committed
fix: dropdown profile menu animation
when switching from authentication route to main route, profile menu animation appears even if property is false fix #11
1 parent d9391ee commit dbec3d6

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

src/app/app.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ThemeService } from './core/services/theme.service';
33
import { RouterOutlet } from '@angular/router';
44
import { NgClass } from '@angular/common';
55
import { ResponsiveHelperComponent } from './shared/components/responsive-helper/responsive-helper.component';
6-
76
@Component({
87
selector: 'app-root',
98
templateUrl: './app.component.html',

src/app/modules/layout/components/navbar/profile-menu/profile-menu.component.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
<span class="sr-only">Open user menu</span>
55
<img
66
clickOutside
7-
(clickOutside)="isMenuOpen = false"
7+
(clickOutside)="isOpen = false"
88
class="h-9 w-9 rounded-md"
99
src="https://avatars.githubusercontent.com/u/12519008?v=4"
1010
alt="" />
1111
</button>
1212
<!-- Dropdown -->
1313
<div
14-
[ngClass]="
15-
isMenuOpen
16-
? 'pointer-events-auto scale-100 animate-fade-in-up opacity-100 duration-200'
17-
: 'pointer-events-none scale-95 opacity-0 duration-100 ease-in'
18-
"
14+
[@openClose]="isOpen ? 'open' : 'closed'"
1915
class="absolute right-0 mt-2 w-60 origin-top-right transform rounded-md bg-background py-4 shadow-custom ring-1 ring-transparent ring-opacity-5 transition focus:outline-none">
2016
<div class="flext-row flex items-center px-4 pb-4">
2117
<div class="w-10 shrink-0">

src/app/modules/layout/components/navbar/profile-menu/profile-menu.component.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,39 @@ import { NgClass } from '@angular/common';
44
import { ClickOutsideDirective } from '../../../../../shared/directives/click-outside.directive';
55
import { AngularSvgIconModule } from 'angular-svg-icon';
66
import { ThemeService } from '../../../../../core/services/theme.service';
7+
import { trigger, state, style, animate, transition } from '@angular/animations';
78

89
@Component({
910
selector: 'app-profile-menu',
1011
templateUrl: './profile-menu.component.html',
1112
styleUrls: ['./profile-menu.component.scss'],
1213
standalone: true,
1314
imports: [ClickOutsideDirective, NgClass, RouterLink, AngularSvgIconModule],
15+
animations: [
16+
trigger('openClose', [
17+
state(
18+
'open',
19+
style({
20+
opacity: 1,
21+
transform: 'translateY(0)',
22+
visibility: 'visible',
23+
}),
24+
),
25+
state(
26+
'closed',
27+
style({
28+
opacity: 0,
29+
transform: 'translateY(-20px)',
30+
visibility: 'hidden',
31+
}),
32+
),
33+
transition('open => closed', [animate('0.2s')]),
34+
transition('closed => open', [animate('0.2s')]),
35+
]),
36+
],
1437
})
1538
export class ProfileMenuComponent implements OnInit {
16-
public isMenuOpen = false;
39+
public isOpen = false;
1740
public profileMenu = [
1841
{
1942
title: 'Your Profile',
@@ -70,7 +93,7 @@ export class ProfileMenuComponent implements OnInit {
7093
ngOnInit(): void {}
7194

7295
public toggleMenu(): void {
73-
this.isMenuOpen = !this.isMenuOpen;
96+
this.isOpen = !this.isOpen;
7497
}
7598

7699
toggleThemeMode() {

src/main.ts

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
import { enableProdMode, importProvidersFrom } from '@angular/core'
2-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
1+
import { enableProdMode, importProvidersFrom } from '@angular/core';
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
33

4-
5-
import { environment } from './environments/environment'
4+
import { environment } from './environments/environment';
65
import { AppComponent } from './app/app.component';
76
import { AppRoutingModule } from './app/app-routing.module';
87
import { BrowserModule, bootstrapApplication } from '@angular/platform-browser';
8+
import { provideAnimations } from '@angular/platform-browser/animations';
99

1010
if (environment.production) {
11-
enableProdMode()
12-
//show this warning only on prod mode
13-
if (window) {
14-
selfXSSWarning();
15-
}
11+
enableProdMode();
12+
//show this warning only on prod mode
13+
if (window) {
14+
selfXSSWarning();
15+
}
1616
}
1717

1818
bootstrapApplication(AppComponent, {
19-
providers: [importProvidersFrom(BrowserModule, AppRoutingModule)]
20-
})
21-
.catch((err) => console.error(err))
19+
providers: [importProvidersFrom(BrowserModule, AppRoutingModule), provideAnimations()],
20+
}).catch((err) => console.error(err));
2221

2322
function selfXSSWarning() {
24-
setTimeout(() => {
25-
console.log('%c** STOP **', 'font-weight:bold; font: 2.5em Arial; color: white; background-color: #e11d48; padding-left: 15px; padding-right: 15px; border-radius: 25px; padding-top: 5px; padding-bottom: 5px;');
26-
console.log(
27-
`\n%cThis is a browser feature intended for developers. Using this console may allow attackers to impersonate you and steal your information sing an attack called Self-XSS. Do not enter or paste code that you do not understand.`, 'font-weight:bold; font: 2em Arial; color: #e11d48;'
28-
);
29-
});
23+
setTimeout(() => {
24+
console.log(
25+
'%c** STOP **',
26+
'font-weight:bold; font: 2.5em Arial; color: white; background-color: #e11d48; padding-left: 15px; padding-right: 15px; border-radius: 25px; padding-top: 5px; padding-bottom: 5px;',
27+
);
28+
console.log(
29+
`\n%cThis is a browser feature intended for developers. Using this console may allow attackers to impersonate you and steal your information sing an attack called Self-XSS. Do not enter or paste code that you do not understand.`,
30+
'font-weight:bold; font: 2em Arial; color: #e11d48;',
31+
);
32+
});
3033
}

0 commit comments

Comments
 (0)