Skip to content

Commit

Permalink
feat: context-menu example
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed May 1, 2018
1 parent 19016f9 commit 745a0bd
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 8 deletions.
1 change: 1 addition & 0 deletions PLAYBOOK.md
Expand Up @@ -243,6 +243,7 @@ ng g component containers/experimentsLayout --app=experiments --dry-run
ng g component containers/experiments --app=experiments --dry-run
ng g component components/hammerCard --app=experiments --dry-run
ng g directive components/Hammertime/Hammertime --app=experiments --dry-run
ng g component containers/ContextMenu --app=experiments --dry-run



Expand Down
5 changes: 5 additions & 0 deletions apps/default/src/app/core/menu-data.ts
Expand Up @@ -41,6 +41,11 @@ export const defaultMenu: MenuItem[] = [
name: 'Upload',
icon: 'directions',
link: '/dashboard/experiments/file-upload'
},
{
name: 'Context Menu',
icon: 'web_aaset',
link: '/dashboard/experiments/context-menu'
}
]
},
Expand Down
8 changes: 7 additions & 1 deletion libs/context-menu/src/context-menu-trigger.directive.ts
Expand Up @@ -28,7 +28,13 @@ export class ContextMenuTriggerDirective implements OnDestroy {

const positionStrategy = this._overlay
.position()
.connectedTo(this._elementRef, { originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' });
.flexibleConnectedTo(this._elementRef)
.withPositions([{
overlayX: 'start',
overlayY: 'top',
originX: 'start',
originY: 'bottom'
}]);

const overlayRef = this._overlay.create({ positionStrategy });
const templatePortal = new TemplatePortal(this.contextMenu, this._vcr);
Expand Down
3 changes: 0 additions & 3 deletions libs/context-menu/src/context-menu.component.ts
Expand Up @@ -4,9 +4,6 @@ import { Component, ChangeDetectionStrategy, HostListener, HostBinding } from '@
selector: 'df-context-menu',
templateUrl: './context-menu.component.html',
styleUrls: ['./context-menu.component.scss'],
// host: {
// class: 'mat-elevation-z2'
// },
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ContextMenuComponent {
Expand Down
@@ -0,0 +1,17 @@
<mat-card>
<mat-list role="list">
<mat-list-item [contextMenu]="myContextMenu">Right click me to see the menu 1</mat-list-item>
<mat-list-item [contextMenu]="myContextMenu">Right click me to see the menu 2</mat-list-item>
<mat-list-item [contextMenu]="myContextMenu">Right click me to see the menu 3</mat-list-item>
</mat-list>
</mat-card>
<ng-template #myContextMenu>
<df-context-menu>
<button mat-button>Select all</button>
<button mat-button>Edit Row</button>
<button mat-button>Quick tag</button>
<button mat-button>Copy selected column</button>
<button mat-button>Copy selected row</button>
<button mat-button>Delete</button>
</df-context-menu>
</ng-template>
Empty file.
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

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,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'context-menu',
templateUrl: './context-menu.component.html',
styleUrls: ['./context-menu.component.scss']
})
export class ContextMenuComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
12 changes: 8 additions & 4 deletions libs/experiments/src/experiments.module.ts
Expand Up @@ -6,9 +6,11 @@ import { FilePondModule,registerPlugin } from '@xmlking/ngx-filepond';

import { SharedModule } from '@nx-starter-kit/shared';
import { UploadModule } from '@nx-starter-kit/upload';
import {ContextMenuModule} from "@nx-starter-kit/context-menu";
import { AnimationsComponent } from './containers/animations/animations.component';
import { FileUploadComponent } from './containers/file-upload/file-upload.component';
import { HammertimeDirective } from './components/hammertime/hammertime.directive';
import { ContextMenuComponent } from './containers/context-menu/context-menu.component';

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


registerPlugin(FilePondPluginFileValidateType, FilepondPluginFileValidateSize, FilepondPluginImagePreview);

@NgModule({
imports: [
SharedModule,
UploadModule,
FilePondModule,
ContextMenuModule,
RouterModule.forChild([
/* {path: '', pathMatch: 'full', component: InsertYourComponentHere} */
{ path: '', redirectTo: 'animations', pathMatch: 'full', data: { animation: 'experiments' } },
Expand All @@ -43,9 +47,9 @@ registerPlugin(FilePondPluginFileValidateType, FilepondPluginFileValidateSize, F
data: { animation: 'file-upload' }
},
{
path: 'experiment3',
component: AnimationsComponent,
data: { animation: 'experiment3' }
path: 'context-menu',
component: ContextMenuComponent,
data: { animation: 'context-menu' }
}
])
],
Expand All @@ -55,6 +59,6 @@ registerPlugin(FilePondPluginFileValidateType, FilepondPluginFileValidateSize, F
useClass: MyHammerConfig
}
],
declarations: [AnimationsComponent, FileUploadComponent, HammertimeDirective]
declarations: [AnimationsComponent, FileUploadComponent, HammertimeDirective, ContextMenuComponent]
})
export class ExperimentsModule {}

0 comments on commit 745a0bd

Please sign in to comment.