Skip to content

Commit 6d1d1b2

Browse files
authored
Merge pull request #50 from maxime1992/feat/optional-custom-template-above-the-hover-opacity
feat: add an optional custom template to display above the hover opacity
2 parents 011a86c + 280303f commit 6d1d1b2

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<div class="content" [class.is-full-height]="isFullHeight">
22
<ng-content></ng-content>
33

4-
<div class="hover" *ngIf="isHoverVisible"></div>
4+
<div class="hover" *ngIf="isHoverVisible">
5+
<ng-container *ngTemplateOutlet="hoverOpacityTpl ?? null"></ng-container>
6+
</div>
57
</div>

projects/ngx-hover-opacity/src/lib/ngx-hover-opacity.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
ContentChild,
5+
Directive,
6+
Input,
7+
TemplateRef,
8+
ViewEncapsulation,
9+
} from '@angular/core';
210
import { Nilable } from 'tsdef';
311

412
export interface INgxHoverOpacityComponentCustomStyle {
513
backgroundColor: string;
614
zIndex: number;
715
}
816

17+
@Directive({ selector: '[hoverOpacityTpl]' })
18+
export class HoverOpacityTplDirective {}
19+
920
@Component({
1021
selector: 'ngx-hover-opacity',
1122
templateUrl: './ngx-hover-opacity.component.html',
@@ -17,4 +28,7 @@ export class NgxHoverOpacityComponent {
1728
@Input() isHoverVisible: Nilable<boolean>;
1829
@Input() isFullHeight = true;
1930
@Input() style: Nilable<INgxHoverOpacityComponentCustomStyle>;
31+
32+
@ContentChild(HoverOpacityTplDirective, { static: true, read: TemplateRef })
33+
public hoverOpacityTpl?: TemplateRef<any>;
2034
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
3-
import { NgxHoverOpacityComponent } from './ngx-hover-opacity.component';
3+
import { HoverOpacityTplDirective, NgxHoverOpacityComponent } from './ngx-hover-opacity.component';
44

55
@NgModule({
66
imports: [CommonModule],
7-
declarations: [NgxHoverOpacityComponent],
8-
exports: [NgxHoverOpacityComponent],
7+
declarations: [NgxHoverOpacityComponent, HoverOpacityTplDirective],
8+
exports: [NgxHoverOpacityComponent, HoverOpacityTplDirective],
99
})
1010
export class NgxHoverOpacityModule {}

src/app/app.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
<!--use the ngx-hover-opacity component to wrap the element to hover -->
44
<ngx-hover-opacity [isHoverVisible]="isHoverVisible">
5+
<ng-template hoverOpacityTpl>
6+
<div class="wrapper">This is a template that can go above the hover!</div>
7+
</ng-template>
8+
59
<mat-card>
610
<mat-card-header>
711
<mat-card-title>Card Title</mat-card-title>

src/app/app.component.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ ngx-hover-opacity {
66
max-width: 500px;
77
display: block;
88
}
9+
10+
.wrapper {
11+
display: flex;
12+
width: 100%;
13+
height: 100%;
14+
align-items: center;
15+
justify-content: center;
16+
}

0 commit comments

Comments
 (0)