Skip to content

Commit f57aa5e

Browse files
committed
add Image Preview in Content Editor
1 parent 7383a00 commit f57aa5e

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/app/features/spaces/contents/shared/asset-select/asset-select.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@if (asset.type.startsWith('image/')) {
2525
<img
2626
matListItemAvatar
27-
llImagePreview
27+
llImagePreview="3"
2828
class="border object-contain bg-stripes-gray !rounded"
2929
width="200"
3030
height="200"

src/app/features/spaces/contents/shared/assets-select/assets-select.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
@if (asset.type.startsWith('image/')) {
2424
<img
2525
matListItemAvatar
26+
llImagePreview="3"
2627
class="border object-contain bg-stripes-gray !rounded"
2728
width="200"
2829
height="200"
Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
import { Directive, ElementRef, HostListener } from '@angular/core';
1+
import { Directive, ElementRef, HostListener, input } from '@angular/core';
22

33
@Directive({
4-
selector: '[llImagePreview]',
4+
selector: 'img[llImagePreview]',
55
})
66
export class ImagePreviewDirective {
7-
constructor(private hostElement: ElementRef<HTMLImageElement>) {
8-
console.log('ImagePreviewDirective', hostElement.nativeElement);
7+
scale = input<number>(2, { alias: 'llImagePreview' });
8+
9+
constructor(private hostElement: ElementRef<HTMLImageElement>) {}
10+
11+
@HostListener('mouseover')
12+
public onMouseOver() {
13+
if (this.hostElement.nativeElement.parentElement) {
14+
this.hostElement.nativeElement.parentElement.style.overflow = 'visible';
15+
}
16+
this.hostElement.nativeElement.style.zIndex = '50';
17+
this.hostElement.nativeElement.style.transform = `scale(${this.scale() || 2})`;
18+
this.hostElement.nativeElement.style.transition = 'transform 0.3s ease-in-out';
919
}
1020

11-
@HostListener('mouseover', ['$event'])
12-
public onMouseOver(event: MouseEvent) {
13-
const img = event.target as HTMLImageElement;
14-
console.log('mouseover', event);
15-
console.log('mouseover', img.srcset);
21+
@HostListener('mouseout')
22+
public onMouseOut() {
23+
this.hostElement.nativeElement.style.transform = 'scale(1)';
24+
this.hostElement.nativeElement.style.zIndex = '';
25+
setTimeout(() => {
26+
if (this.hostElement.nativeElement.parentElement) {
27+
this.hostElement.nativeElement.style.transform = '';
28+
this.hostElement.nativeElement.style.transition = '';
29+
this.hostElement.nativeElement.parentElement.style.overflow = '';
30+
}
31+
}, 400);
1632
}
1733
}

0 commit comments

Comments
 (0)