Skip to content

Commit

Permalink
[ACS-7380][ADF] Break Context Menu dependency on Material Module (#9487)
Browse files Browse the repository at this point in the history
* [ACS-7380] convert context menu to standalone

* [ACS-7380] convert context menu to standalone

* [ACS-7380] convert context menu to standalone
  • Loading branch information
tamaragruszka authored Apr 3, 2024
1 parent c73fb1b commit 91e1c47
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 40 deletions.
14 changes: 14 additions & 0 deletions lib/core/src/lib/context-menu/context-menu-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div mat-menu class="mat-menu-panel" @panelAnimation>
<div id="adf-context-menu-content" class="mat-menu-content">
<ng-container *ngFor="let link of links">
<button *ngIf="link.model?.visible"
[attr.data-automation-id]="'context-' + (link.title || link.model?.title | translate)"
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)">
<mat-icon *ngIf="link.model?.icon">{{ link.model.icon }}</mat-icon>
<span>{{ link.title || link.model?.title | translate }}</span>
</button>
</ng-container>
</div>
</div>
32 changes: 10 additions & 22 deletions lib/core/src/lib/context-menu/context-menu-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,28 @@
* limitations under the License.
*/

import { Component, ViewEncapsulation, HostListener, AfterViewInit, Optional, Inject, QueryList, ViewChildren } from '@angular/core';
import { trigger } from '@angular/animations';
import { DOWN_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
import { FocusKeyManager } from '@angular/cdk/a11y';
import { MatMenuItem } from '@angular/material/menu';
import { ContextMenuOverlayRef } from './context-menu-overlay';
import { DOWN_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
import { NgForOf, NgIf } from '@angular/common';
import { AfterViewInit, Component, HostListener, Inject, Optional, QueryList, ViewChildren, ViewEncapsulation } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuItem, MatMenuModule } from '@angular/material/menu';
import { TranslateModule } from '@ngx-translate/core';
import { contextMenuAnimation } from './animations';
import { ContextMenuOverlayRef } from './context-menu-overlay';
import { CONTEXT_MENU_DATA } from './context-menu.tokens';

@Component({
selector: 'adf-context-menu',
template: `
<div mat-menu class="mat-menu-panel" @panelAnimation>
<div id="adf-context-menu-content" class="mat-menu-content">
<ng-container *ngFor="let link of links">
<button
*ngIf="link.model?.visible"
[attr.data-automation-id]="'context-' + (link.title || link.model?.title | translate)"
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)"
>
<mat-icon *ngIf="link.model?.icon">{{ link.model.icon }}</mat-icon>
<span>{{ link.title || link.model?.title | translate }}</span>
</button>
</ng-container>
</div>
</div>
`,
standalone: true,
templateUrl: './context-menu-list.component.html',
host: {
role: 'menu',
class: 'adf-context-menu'
},
encapsulation: ViewEncapsulation.None,
imports: [MatIconModule, MatMenuModule, NgForOf, NgIf, TranslateModule],
animations: [trigger('panelAnimation', contextMenuAnimation)]
})
export class ContextMenuListComponent implements AfterViewInit {
Expand Down
3 changes: 2 additions & 1 deletion lib/core/src/lib/context-menu/context-menu.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { Directive, HostListener, Input } from '@angular/core';
import { ContextMenuOverlayService } from './context-menu-overlay.service';

@Directive({
selector: '[adf-context-menu]'
selector: '[adf-context-menu]',
standalone: true
})
export class ContextMenuDirective {
/** Items for the menu. */
Expand Down
18 changes: 2 additions & 16 deletions lib/core/src/lib/context-menu/context-menu.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,12 @@
* limitations under the License.
*/

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MaterialModule } from '../material.module';
import { TranslateModule } from '@ngx-translate/core';

import { ContextMenuDirective } from './context-menu.directive';
import { ContextMenuListComponent } from './context-menu-list.component';

@NgModule({
imports: [
CommonModule,
MaterialModule,
TranslateModule
],
declarations: [
ContextMenuDirective,
ContextMenuListComponent
],
exports: [
ContextMenuDirective
]
imports: [ContextMenuListComponent, ContextMenuDirective],
exports: [ContextMenuListComponent, ContextMenuDirective]
})
export class ContextMenuModule {}
2 changes: 1 addition & 1 deletion lib/core/src/lib/context-menu/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

export * from './context-menu-list.component';
export * from './context-menu.directive';
export * from './context-menu-overlay.service';

export * from './context-menu.module';

0 comments on commit 91e1c47

Please sign in to comment.