Front: add context menu UI
This commit is contained in:
1 parent
31d38d8da9
commit
bd65181da3
9 files changed
+173
-1
No files matched your search
@@ -0,0 +1,23 @@
|
||||
.context-menu {
|
||||
position: absolute;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
|
||||
z-index: 1000;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.context-menu ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.context-menu li {
|
||||
padding: 8px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.context-menu li:hover {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<div *ngIf="isVisible" [ngStyle]="{'top.px': position.y, 'left.px': position.x}" class="context-menu">
|
||||
<ul>
|
||||
<li *ngFor="let option of menuOptions" (click)="onAction(option)">
|
||||
{{ option }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DebugElement } from '@angular/core';
|
||||
|
||||
import { ContextMenuComponent } from './context-menu.component';
|
||||
|
||||
describe('ContextMenuComponent', () => {
|
||||
let component: ContextMenuComponent;
|
||||
let fixture: ComponentFixture<ContextMenuComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ContextMenuComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ContextMenuComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ContextMenuService } from '../../services/context-menu.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-context-menu',
|
||||
templateUrl: './context-menu.component.html',
|
||||
styleUrls: ['./context-menu.component.css'],
|
||||
})
|
||||
export class ContextMenuComponent implements OnInit {
|
||||
isVisible = false;
|
||||
position = { x: 0, y: 0 };
|
||||
menuOptions: any[] = [];
|
||||
|
||||
optionsDisplayText = {
|
||||
removeFromLib: 'Remove From Library',
|
||||
addToLib: 'Add To Library',
|
||||
addToCollection: 'Add To Collection',
|
||||
optopt: 'opt',
|
||||
};
|
||||
|
||||
constructor(private contextMenuService: ContextMenuService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.contextMenuService.contextMenuVisibility$.subscribe((visible) => {
|
||||
this.isVisible = visible;
|
||||
});
|
||||
|
||||
this.contextMenuService.contextMenuPosition$.subscribe((position) => {
|
||||
this.position = position;
|
||||
});
|
||||
|
||||
this.contextMenuService.menuOptions$.subscribe((options) => {
|
||||
this.menuOptions = options;
|
||||
});
|
||||
}
|
||||
|
||||
onAction(action: string) {
|
||||
this.contextMenuService.hideContextMenu();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user