Skip to content

Commit 745a0bd

Browse files
committed
feat: context-menu example
1 parent 19016f9 commit 745a0bd

9 files changed

+78
-8
lines changed

PLAYBOOK.md

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ ng g component containers/experimentsLayout --app=experiments --dry-run
243243
ng g component containers/experiments --app=experiments --dry-run
244244
ng g component components/hammerCard --app=experiments --dry-run
245245
ng g directive components/Hammertime/Hammertime --app=experiments --dry-run
246+
ng g component containers/ContextMenu --app=experiments --dry-run
246247

247248

248249

apps/default/src/app/core/menu-data.ts

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export const defaultMenu: MenuItem[] = [
4141
name: 'Upload',
4242
icon: 'directions',
4343
link: '/dashboard/experiments/file-upload'
44+
},
45+
{
46+
name: 'Context Menu',
47+
icon: 'web_aaset',
48+
link: '/dashboard/experiments/context-menu'
4449
}
4550
]
4651
},

libs/context-menu/src/context-menu-trigger.directive.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ export class ContextMenuTriggerDirective implements OnDestroy {
2828

2929
const positionStrategy = this._overlay
3030
.position()
31-
.connectedTo(this._elementRef, { originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' });
31+
.flexibleConnectedTo(this._elementRef)
32+
.withPositions([{
33+
overlayX: 'start',
34+
overlayY: 'top',
35+
originX: 'start',
36+
originY: 'bottom'
37+
}]);
3238

3339
const overlayRef = this._overlay.create({ positionStrategy });
3440
const templatePortal = new TemplatePortal(this.contextMenu, this._vcr);

libs/context-menu/src/context-menu.component.ts

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import { Component, ChangeDetectionStrategy, HostListener, HostBinding } from '@
44
selector: 'df-context-menu',
55
templateUrl: './context-menu.component.html',
66
styleUrls: ['./context-menu.component.scss'],
7-
// host: {
8-
// class: 'mat-elevation-z2'
9-
// },
107
changeDetection: ChangeDetectionStrategy.OnPush
118
})
129
export class ContextMenuComponent {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<mat-card>
2+
<mat-list role="list">
3+
<mat-list-item [contextMenu]="myContextMenu">Right click me to see the menu 1</mat-list-item>
4+
<mat-list-item [contextMenu]="myContextMenu">Right click me to see the menu 2</mat-list-item>
5+
<mat-list-item [contextMenu]="myContextMenu">Right click me to see the menu 3</mat-list-item>
6+
</mat-list>
7+
</mat-card>
8+
<ng-template #myContextMenu>
9+
<df-context-menu>
10+
<button mat-button>Select all</button>
11+
<button mat-button>Edit Row</button>
12+
<button mat-button>Quick tag</button>
13+
<button mat-button>Copy selected column</button>
14+
<button mat-button>Copy selected row</button>
15+
<button mat-button>Delete</button>
16+
</df-context-menu>
17+
</ng-template>

libs/experiments/src/containers/context-menu/context-menu.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ContextMenuComponent } from './context-menu.component';
4+
5+
describe('ContextMenuComponent', () => {
6+
let component: ContextMenuComponent;
7+
let fixture: ComponentFixture<ContextMenuComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ ContextMenuComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ContextMenuComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'context-menu',
5+
templateUrl: './context-menu.component.html',
6+
styleUrls: ['./context-menu.component.scss']
7+
})
8+
export class ContextMenuComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit() {
13+
}
14+
15+
}

libs/experiments/src/experiments.module.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { FilePondModule,registerPlugin } from '@xmlking/ngx-filepond';
66

77
import { SharedModule } from '@nx-starter-kit/shared';
88
import { UploadModule } from '@nx-starter-kit/upload';
9+
import {ContextMenuModule} from "@nx-starter-kit/context-menu";
910
import { AnimationsComponent } from './containers/animations/animations.component';
1011
import { FileUploadComponent } from './containers/file-upload/file-upload.component';
1112
import { HammertimeDirective } from './components/hammertime/hammertime.directive';
13+
import { ContextMenuComponent } from './containers/context-menu/context-menu.component';
1214

1315
export class MyHammerConfig extends HammerGestureConfig {
1416
overrides = <any>{
@@ -22,13 +24,15 @@ import * as FilePondPluginFileValidateType from 'filepond-plugin-file-validate-t
2224
import * as FilepondPluginFileValidateSize from 'filepond-plugin-file-validate-size';
2325
import * as FilepondPluginImagePreview from 'filepond-plugin-image-preview';
2426

27+
2528
registerPlugin(FilePondPluginFileValidateType, FilepondPluginFileValidateSize, FilepondPluginImagePreview);
2629

2730
@NgModule({
2831
imports: [
2932
SharedModule,
3033
UploadModule,
3134
FilePondModule,
35+
ContextMenuModule,
3236
RouterModule.forChild([
3337
/* {path: '', pathMatch: 'full', component: InsertYourComponentHere} */
3438
{ path: '', redirectTo: 'animations', pathMatch: 'full', data: { animation: 'experiments' } },
@@ -43,9 +47,9 @@ registerPlugin(FilePondPluginFileValidateType, FilepondPluginFileValidateSize, F
4347
data: { animation: 'file-upload' }
4448
},
4549
{
46-
path: 'experiment3',
47-
component: AnimationsComponent,
48-
data: { animation: 'experiment3' }
50+
path: 'context-menu',
51+
component: ContextMenuComponent,
52+
data: { animation: 'context-menu' }
4953
}
5054
])
5155
],
@@ -55,6 +59,6 @@ registerPlugin(FilePondPluginFileValidateType, FilepondPluginFileValidateSize, F
5559
useClass: MyHammerConfig
5660
}
5761
],
58-
declarations: [AnimationsComponent, FileUploadComponent, HammertimeDirective]
62+
declarations: [AnimationsComponent, FileUploadComponent, HammertimeDirective, ContextMenuComponent]
5963
})
6064
export class ExperimentsModule {}

0 commit comments

Comments
 (0)