From e415ecc415aa02267131b8bbfd5ea8e5255753ae Mon Sep 17 00:00:00 2001 From: akastijn Date: Sat, 8 Nov 2025 22:09:35 +0100 Subject: [PATCH] Implement dynamic container height adjustment in `NickGeneratorComponent` based on header and footer dimensions. Refactor HTML structure for improved dark mode styling and accessibility. Optimize component lifecycle by adding `AfterViewInit` and `OnDestroy` handling with a `ResizeObserver`. --- .../nick-generator.component.html | 161 +++++++++--------- .../nick-generator.component.scss | 8 +- .../nickgenerator/nick-generator.component.ts | 62 ++++++- 3 files changed, 141 insertions(+), 90 deletions(-) diff --git a/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.html b/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.html index 87a1b25..8713313 100644 --- a/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.html +++ b/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.html @@ -12,96 +12,97 @@
-
-
+
+
+
- @for (part of parts; track $index; let i = $index) { -
-
- - Text - - {{ part.text.length }} / 16 - + @for (part of parts; track $index; let i = $index) { +
+
+ + Text + + {{ part.text.length }} / 16 + - Gradient - + Gradient + - - Color A - - + + Color A + + - - Color B - - + + Color B + + - Continuation - + Continuation + +
+ + @if (part.invalid) { +
(min 1 – max 16 chars{{ part.gradient ? '' : ' for non-empty text' }})
+ } +
+ } - @if (part.invalid) { -
(min 1 – max 16 chars{{ part.gradient ? '' : ' for non-empty text' }})
- } - +
+ +
- } -
- - + @if (showCommands) { +
+
+
{{ tryCmd }}
+ +
+
+
{{ requestCmd }}
+ +
+
+ } + + @if (showPreview) { +
+ }
- - @if (showCommands) { -
-
-
{{ tryCmd }}
- -
-
-
{{ requestCmd }}
- -
-
- } - - @if (showPreview) { -
- }
diff --git a/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.scss b/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.scss index bf3c716..0899f33 100644 --- a/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.scss +++ b/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.scss @@ -1,9 +1,7 @@ -/* nick-generator.component.css */ .containerNick { - background-color: #292828; - padding: 40px 5%; max-width: 1220px; margin: 0 auto; + height: 100%; } .controls { @@ -59,8 +57,6 @@ } .command { - background: #1e1e1e; - color: #ffffff; padding: 10px 12px; border-radius: 6px; font-family: monospace; @@ -68,10 +64,8 @@ } .preview { - background: #1e1e1e; padding: 14px 12px; border-radius: 6px; - color: #ffffff; font-family: 'minecraft-text', monospace; white-space: pre-wrap; } diff --git a/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.ts b/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.ts index 55ee893..2a7a916 100644 --- a/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.ts +++ b/frontend/src/app/pages/reference/nickgenerator/nick-generator.component.ts @@ -1,4 +1,4 @@ -import {Component} from '@angular/core'; +import {AfterViewInit, Component, ElementRef, OnDestroy, Renderer2} from '@angular/core'; import {DomSanitizer, SafeHtml} from '@angular/platform-browser'; import {MatFormFieldModule} from '@angular/material/form-field'; import {MatInputModule} from '@angular/material/input'; @@ -31,7 +31,7 @@ interface Part { MatButtonModule, ] }) -export class NickGeneratorComponent { +export class NickGeneratorComponent implements AfterViewInit, OnDestroy { parts: Part[] = [ {text: '', gradient: false, colorA: '#ffffff', colorB: '#ffffff', continuation: false} ]; @@ -41,8 +41,33 @@ export class NickGeneratorComponent { previewHtml: SafeHtml = ''; showPreview = false; showCommands = false; + private handleResize: any; + private boundHandleResize: any; + private resizeObserver: ResizeObserver | null = null; - constructor(private sanitizer: DomSanitizer) { + + constructor(private sanitizer: DomSanitizer, + private elementRef: ElementRef, + private renderer: Renderer2 + ) { + } + + ngOnDestroy() { + if (this.resizeObserver) { + this.resizeObserver.disconnect(); + this.resizeObserver = null; + } + + if (this.boundHandleResize) { + window.removeEventListener('resize', this.boundHandleResize); + } + } + + ngAfterViewInit(): void { + this.setupResizeObserver(); + window.addEventListener('resize', this.boundHandleResize); + this.boundHandleResize = this.handleResize.bind(this); + setTimeout(() => this.updateContainerHeight(), 0); } addPart(): void { @@ -223,4 +248,35 @@ export class NickGeneratorComponent { .replace(//g, '>'); } + + private updateContainerHeight() { + const headerElement = document.querySelector('app-header'); + const footerElement = document.querySelector('footer'); + + const container = this.elementRef.nativeElement.querySelector('.containerNick'); + + if (headerElement && footerElement && container) { + const headerHeight = headerElement.getBoundingClientRect().height; + const footerHeight = footerElement.getBoundingClientRect().height; + + const calculatedHeight = `calc(100vh - ${headerHeight}px - ${footerHeight}px)`; + this.renderer.setStyle(container, 'min-height', calculatedHeight); + } + } + + private setupResizeObserver() { + this.resizeObserver = new ResizeObserver(() => { + this.updateContainerHeight(); + }); + + const headerElement = document.querySelector('app-header'); + if (headerElement) { + this.resizeObserver.observe(headerElement); + } + + const footerElement = document.querySelector('footer'); + if (footerElement) { + this.resizeObserver.observe(footerElement); + } + } }