generated from open-template-hub/web-ui-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added dropdown menu component, edited top nav
- Loading branch information
1 parent
b2e85b6
commit 759fbe6
Showing
8 changed files
with
236 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/app/component/common/dropdown-menu/dropdown-menu.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="dropdown"> | ||
<div #toggleButton class="ng-content-area"> | ||
<ng-content (click)="toggleDropdown()"></ng-content> | ||
</div> | ||
<div *ngIf="isDropdownOpen" #dropdownContent class="dropdown-content"> | ||
<i class="material-icons">change_history</i> | ||
<a *ngFor="let option of options; last as isLast" class="dropdown-item" | ||
(mouseover)="option.hover = true" (mouseleave)="option.hover = false" | ||
[ngStyle]="option?.hover && { 'background-color': option.backgroundColor }" | ||
[style.margin-bottom]="!isLast ? '10px' : '0'" [href]="option.link"> | ||
<img [src]="option.brand.brandLogo" alt="logo" class="dropdown-item-logo" height="40"/> | ||
<div class="dropdown-item-content"> | ||
<span>{{ option.header }}</span> | ||
<p>{{ option.description }}</p> | ||
</div> | ||
</a> | ||
</div> | ||
</div> |
51 changes: 51 additions & 0 deletions
51
src/app/component/common/dropdown-menu/dropdown-menu.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.dropdown { | ||
position: relative; | ||
} | ||
|
||
.dropdown-content { | ||
display: block; | ||
position: absolute; | ||
background-color: var(--card); | ||
min-width: 160px; | ||
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); | ||
padding: 12px 16px; | ||
z-index: 10; | ||
top: 61px; | ||
} | ||
|
||
.dropdown-content i { | ||
position: absolute; | ||
top: -13px; | ||
left: 22px; | ||
font-size: 15px; | ||
color: var(--lighter-contrast); | ||
} | ||
|
||
.dropdown-item { | ||
display: flex; | ||
width: 300px; | ||
padding: 10px; | ||
cursor: pointer; | ||
} | ||
|
||
.dropdown-item-logo { | ||
margin-right: 20px; | ||
} | ||
|
||
.dropdown-item-content span { | ||
font-size: 14px; | ||
font-weight: 500; | ||
} | ||
|
||
.dropdown-item-content p { | ||
margin-top: 10px; | ||
} | ||
|
||
.ng-content-area { | ||
display: flex; | ||
align-items: center; | ||
cursor: pointer; | ||
} | ||
|
||
.dropdown:hover .dropdown-content { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/app/component/common/dropdown-menu/dropdown-menu.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DropdownMenuComponent } from './dropdown-menu.component'; | ||
|
||
describe('DropdownMenuComponent', () => { | ||
let component: DropdownMenuComponent; | ||
let fixture: ComponentFixture<DropdownMenuComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ DropdownMenuComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DropdownMenuComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
src/app/component/common/dropdown-menu/dropdown-menu.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Component, ElementRef, Input, OnChanges, Renderer2, ViewChild } from '@angular/core'; | ||
import { ThemeService } from '../../../service/theme/theme.service'; | ||
|
||
export interface DropdownMenuOption { | ||
backgroundColor: string, | ||
brand: { brandLogo: string }, | ||
header: string, | ||
description: string, | ||
link: string, | ||
hover?: boolean // this property only use on this class, do not set it from outside | ||
} | ||
|
||
@Component({ | ||
selector: 'app-dropdown-menu', | ||
templateUrl: './dropdown-menu.component.html', | ||
styleUrls: ['./dropdown-menu.component.scss'] | ||
}) | ||
export class DropdownMenuComponent { | ||
isDropdownOpen = false | ||
brand = { | ||
brandLogo: '', | ||
}; | ||
|
||
@Input() options: DropdownMenuOption[] = [ | ||
{ | ||
backgroundColor: 'rgba(255, 0, 0, 0.2)', | ||
brand: { brandLogo: '' }, | ||
header: 'Open Template Hub', | ||
description: 'Open Template Hub is an organization that develops open source micro servers as templates including authentication server, payment server and more..', | ||
link: '/' | ||
} | ||
] | ||
|
||
@ViewChild('toggleButton') toggleButton: ElementRef | ||
@ViewChild('dropdownContent') dropdownContent: ElementRef | ||
|
||
constructor( | ||
private themeService: ThemeService, | ||
private renderer: Renderer2 | ||
) { | ||
this.brand = this.themeService.brand | ||
|
||
this.renderer.listen('window', 'click', (e: Event) => { | ||
if( this.toggleButton.nativeElement.contains( e.target ) ) { | ||
this.toggleDropdown() | ||
} else if ( !this.dropdownContent?.nativeElement.contains( e.target ) ) { | ||
this.isDropdownOpen = false | ||
} | ||
} ) | ||
} | ||
|
||
toggleDropdown() { | ||
console.log('test') | ||
this.isDropdownOpen = !this.isDropdownOpen | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.