-
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.
Create actions menu column component to reduce code duplication
- Loading branch information
Showing
13 changed files
with
258 additions
and
191 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/app/common/table/actions-menu-column/actions-menu-column.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,20 @@ | ||
<ng-container cdkColumnDef="actionsMenu" [sticky]="sticky" [stickyEnd]="stickyEnd"> | ||
<th cdk-header-cell *cdkHeaderCellDef></th> | ||
<td cdk-cell *cdkCellDef="let item; let index = index"> | ||
<button | ||
class="btn dropdown-toggle dropdown-toggle-hide-caret shadow-none py-0 ps-3" | ||
type="button" | ||
[attr.aria-controls]="getMenuId(index)" | ||
[cdkMenuTriggerData]="{ | ||
item, | ||
index, | ||
triggerId: getTriggerId(index), | ||
menuId: getMenuId(index) | ||
}" | ||
[cdkMenuTriggerFor]="template()" | ||
[id]="getTriggerId(index)" | ||
> | ||
<span class="fa-solid fa-lg fa-ellipsis-v"></span> | ||
</button> | ||
</td> | ||
</ng-container> |
12 changes: 12 additions & 0 deletions
12
src/app/common/table/actions-menu-column/actions-menu-column.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,12 @@ | ||
.cdk-column-actionsMenu { | ||
width: 50px; | ||
|
||
button.dropdown-toggle { | ||
display: block; | ||
border: 0; | ||
|
||
&:hover { | ||
color: var(--bs-link-hover-color); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/app/common/table/actions-menu-column/actions-menu-column.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,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ActionsMenuColumnComponent } from './actions-menu-column.component'; | ||
|
||
describe('ActionsMenuColumnComponent', () => { | ||
let component: ActionsMenuColumnComponent; | ||
let fixture: ComponentFixture<ActionsMenuColumnComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ActionsMenuColumnComponent] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ActionsMenuColumnComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
src/app/common/table/actions-menu-column/actions-menu-column.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,41 @@ | ||
import { CdkMenu, CdkMenuTrigger } from '@angular/cdk/menu'; | ||
import { CdkTableModule } from '@angular/cdk/table'; | ||
import { NgTemplateOutlet } from '@angular/common'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Directive, | ||
HostAttributeToken, | ||
TemplateRef, | ||
contentChild, | ||
inject | ||
} from '@angular/core'; | ||
|
||
import { AsyAbstractColumnComponent } from '../columns/asy-abstract-column.component'; | ||
|
||
@Directive({ selector: '[actions-menu-tmp]', standalone: true }) | ||
export class ActionsMenuTemplateDirective { | ||
constructor(public template: TemplateRef<any>) {} | ||
} | ||
|
||
@Component({ | ||
selector: 'asy-actions-menu-column', | ||
standalone: true, | ||
imports: [CdkTableModule, CdkMenuTrigger, NgTemplateOutlet, CdkMenu], | ||
templateUrl: './actions-menu-column.component.html', | ||
styleUrl: './actions-menu-column.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class ActionsMenuColumnComponent<T> extends AsyAbstractColumnComponent<T> { | ||
readonly template = contentChild.required(ActionsMenuTemplateDirective, { read: TemplateRef }); | ||
|
||
#scope = inject(new HostAttributeToken('scope')); | ||
|
||
getTriggerId(index: number) { | ||
return `${this.#scope}-action-menu-btn-${index}`; | ||
} | ||
|
||
getMenuId(index: number) { | ||
return `${this.#scope}-action-menu-${index}`; | ||
} | ||
} |
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
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.