Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(directives): add state to the full screen directive #794

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<span class="separator"></span>

<button mat-icon-button (click)="fullScreen.toggle()">
<mat-icon>fullscreen</mat-icon>
@if (fullScreen.enabled$()) {
<mat-icon>close_fullscreen</mat-icon>
} @else {
<mat-icon>open_in_full</mat-icon>
}
</button>

<app-table-column-settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ interface IStyleConfiguration {
bottom: string;
}

/**
* Full screen directive.
*/
/** Full screen directive. */
@Directive({
selector: '[appFullScreen]',
exportAs: 'fullScreen',
})
export class AppFullScreenDirective {
/** Original styles of the component. */
private readonly originalStyles = signal<IStyleConfiguration | null>(null);

/** Full screen state. */
public readonly enabled$ = signal<boolean>(false);

/**
* @param el Element reference.
*/
constructor(private readonly el: ElementRef<HTMLElement>) {}

/**
* Create a copy of the original styles.
* @param el HTML element.
*/
private backUpStyles(el: HTMLElement) {
const styles: IStyleConfiguration = {
width: el.style.width,
Expand All @@ -31,6 +40,10 @@ export class AppFullScreenDirective {
this.originalStyles.set(styles);
}

/**
* Restore original styles from a copy.
* @param el HTML element.
*/
private restoreStyles(el: HTMLElement) {
const styles = this.originalStyles();
if (styles !== null) {
Expand All @@ -43,6 +56,10 @@ export class AppFullScreenDirective {
}
}

/**
* Set element styles.
* @param el HTML element.
*/
private setStyles(el: HTMLElement) {
el.style.width = '100vw';
el.style.height = '100vw';
Expand All @@ -51,6 +68,7 @@ export class AppFullScreenDirective {
el.style.bottom = '0';
}

/** Toggle full screen. */
public toggle(): void {
const fullScreen = this.originalStyles();
switch (fullScreen) {
Expand All @@ -63,18 +81,22 @@ export class AppFullScreenDirective {
}
}

/** Enable full screen mode. */
public maximize(): void {
const el = this.el.nativeElement;
if (typeof el !== 'undefined') {
this.backUpStyles(el);
this.setStyles(el);
this.enabled$.set(true);
}
}

/** Disable full screen mode. */
public minimize(): void {
const el = this.el.nativeElement;
if (typeof el !== 'undefined') {
this.restoreStyles(el);
this.enabled$.set(false);
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@app/nx-ng-starter",
"version": "7.6.6",
"version": "7.6.7",
"private": true,
"description": "Monorepo starter: Nx, Angular, Angular Elements, Electron, NodeJS, NestJS, Firebase.",
"license": "MIT",
Expand Down