[Updated] Looking better

This commit is contained in:
Ninjaws
2024-11-24 18:21:45 +01:00
parent 4c928a4220
commit 4328514e2c
2 changed files with 24 additions and 29 deletions
@@ -13,33 +13,28 @@
<span *ngFor="let technology of project.technologies" <span *ngFor="let technology of project.technologies"
class="bg-gray-800/55 text-white text-sm sm:text-md px-1 sm:px-2 py-1 rounded-md">{{technology}}</span> class="bg-gray-800/55 text-white text-sm sm:text-md px-1 sm:px-2 py-1 rounded-md">{{technology}}</span>
</div> </div>
<!-- max-h-60 -->
<!-- <p class="text-gray-300 mb-4 whitespace-pre-line overflow-hidden overflow-ellipsis max-h-60">
{{project.description}}</p> -->
<!-- [class.mb-2]="isTruncated || isExpanded" --> <div class="relative mb-2"
<div class="relative mb-2"> [class.mb-4]="project.links.length === 0"
<!-- [class.mb-2]="project.links.length === 0"> --> >
<!-- [class.max-h-[textHeight]="isExpanded" [class.max-h-52]="!isExpanded" --> <!-- [class.max-h-[textHeight]="isExpanded" [class.max-h-52]="!isExpanded" -->
<p #description <p #description
class="text-gray-300 mb-4 overflow-hidden xl:whitespace-pre-line transition-all duration-500 ease-in-out" class="text-gray-300 mb-4 overflow-hidden xl:whitespace-pre-line transition-all duration-500 ease-in-out"
[ngStyle]="{ maxHeight: isExpanded ? fullHeight : '13rem' }" [ngStyle]="{ maxHeight: isExpanded ? getTextHeight(): '13rem' }"
[class.whitespace-pre-line]="isTruncated || isExpanded"> [class.whitespace-pre-line]="isTruncated || isExpanded">
{{ project.description }} {{ project.description }}
</p> </p>
<button *ngIf="isTruncated && !isExpanded" (click)="toggleExpand()" <button *ngIf="isTruncated && !isExpanded" (click)="toggleExpand()"
class="text-teal-600 hover:text-teal-400"> class="text-teal-600 hover:text-teal-400">
Show More Show More
</button> </button>
<button *ngIf="isExpanded" (click)="toggleExpand()" class="text-teal-500 hover:text-teal-200"> <button *ngIf="isExpanded" (click)="toggleExpand()" class="text-teal-600 hover:text-teal-400">
Show Less Show Less
</button> </button>
</div> </div>
<div class="flex justify-end items-end gap-5 flex-1"> <div class="flex justify-end items-end gap-5 flex-1">
<a *ngFor="let link of project.links" href="{{link.address}}" target="_blank" class=""> <a *ngFor="let link of project.links" href="{{link.address}}" target="_blank" class="">
<!-- [ngClass]="link.type === 'link' ? 'border-2 border-gray-600 p-1 rounded-sm hover:bg-teal-400 hover:text-gray-700 hover:border-transparent' : ''"> -->
<p *ngIf="link.type === 'link'" <p *ngIf="link.type === 'link'"
class="text-base md:text-lg flex text-center items-center border-2 text-gray-400 border-gray-600 p-1 rounded-sm hover:bg-teal-400 hover:text-gray-700 hover:border-transparent transition-all duration-300 ease-in-out"> class="text-base md:text-lg flex text-center items-center border-2 text-gray-400 border-gray-600 p-1 rounded-sm hover:bg-teal-400 hover:text-gray-700 hover:border-transparent transition-all duration-300 ease-in-out">
Try it here! Try it here!
+17 -17
View File
@@ -1,5 +1,12 @@
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { ChangeDetectorRef, Component, ElementRef, Input, ViewChild } from '@angular/core'; import {
ChangeDetectorRef,
Component,
ElementRef,
HostListener,
Input,
ViewChild,
} from '@angular/core';
export interface Project { export interface Project {
title: string; title: string;
@@ -7,7 +14,7 @@ export interface Project {
description: string; description: string;
image: string; image: string;
technologies: string[]; technologies: string[];
links: {address: string, type: 'source' | 'demo' | 'link'}[]; links: { address: string; type: 'source' | 'demo' | 'link' }[];
// source?: string; // source?: string;
// demo?: string; // demo?: string;
// link?: string; // link?: string;
@@ -18,31 +25,30 @@ export interface Project {
standalone: true, standalone: true,
imports: [CommonModule], imports: [CommonModule],
templateUrl: './project-card.component.html', templateUrl: './project-card.component.html',
styles: `` styles: ``,
}) })
export class ProjectCardComponent { export class ProjectCardComponent {
@Input() project!: Project; @Input() project!: Project;
@ViewChild('description') descriptionElement!: ElementRef; @ViewChild('description') descriptionElement!: ElementRef;
isExpanded = false;
isTruncated = false; isTruncated = false;
isTextVisible = true; isExpanded = false;
fullHeight: string = '13rem';
constructor(private cdr: ChangeDetectorRef) {} constructor(private cdr: ChangeDetectorRef) {}
ngAfterViewInit() { ngAfterViewInit() {
this.checkIfTruncated(); this.checkIfTruncated();
this.cdr.detectChanges(); // Notify Angular of the changes after view initialization
} }
// Check if the description is being cut off
checkIfTruncated() { checkIfTruncated() {
const element = this.descriptionElement.nativeElement; const element = this.descriptionElement.nativeElement;
this.fullHeight = `${this.descriptionElement.nativeElement.scrollHeight}px`; // console.log(this.fullHeight);
console.log(this.fullHeight);
this.isTruncated = element.scrollHeight > element.offsetHeight; this.isTruncated = element.scrollHeight > element.offsetHeight;
// this.updateTextHeight();
}
getTextHeight() {
return `${this.descriptionElement.nativeElement.scrollHeight}px`;
} }
// Toggle expand/collapse // Toggle expand/collapse
@@ -50,15 +56,9 @@ export class ProjectCardComponent {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
if (this.isExpanded) { if (this.isExpanded) {
this.isTruncated = false; this.isTruncated = false;
this.isTextVisible = false;
setTimeout(() => {
this.isTextVisible = true;
}, 500)
} else { } else {
this.isTruncated = true; this.isTruncated = true;
} }
this.cdr.detectChanges(); // Notify Angular of the changes after toggling this.cdr.detectChanges(); // Notify Angular of the changes after toggling
} }
} }