Skip to content

Commit 44454d5

Browse files
committed
feat: image cards now use NgOptimizedImage
1 parent cd92419 commit 44454d5

7 files changed

Lines changed: 15 additions & 38 deletions

File tree

public/images/mural.jpg

414 KB
Loading

src/app/pages/readme/readme.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="parallax">
22
<hgroup>
3-
<img class="mural" src="images/mural.png" alt="Mural" />
3+
<img class="mural" ngSrc="images/mural.jpg" alt="Mural" fill priority disableOptimizedSrcset />
44
<h1>
55
Welcome to the
66
<om-typewriter
@@ -15,7 +15,7 @@ <h1>
1515
<article class="content">
1616
<section id="intro" class="pres-container">
1717
<div class="pres-image-container">
18-
<img src="images/president.png" alt="President of the CSSS" />
18+
<img ngSrc="images/president.png" alt="President of the CSSS" height="480" width="320" />
1919
</div>
2020
<div class="pres-content">
2121
<h2>President's Address</h2>

src/app/pages/readme/readme.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ hgroup {
9898
place-items: center;
9999
height: 100%;
100100
width: 100%;
101-
gap: 1rem;
101+
gap: 2rem;
102102

103103
& > a {
104104
@include g.no-select;

src/app/pages/readme/readme.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NgOptimizedImage } from '@angular/common';
12
import { ChangeDetectionStrategy, Component } from '@angular/core';
23
import { RouterModule } from '@angular/router';
34
import { CardComponent } from '@csss-code/card/card.component';
@@ -15,7 +16,8 @@ import { RouteLinkComponent } from 'components/url/route-link/route-link.compone
1516
FontAwesomeModule,
1617
ExternalLinkComponent,
1718
RouteLinkComponent,
18-
NgxTypewriterComponent
19+
NgxTypewriterComponent,
20+
NgOptimizedImage
1921
],
2022
templateUrl: './readme.component.html',
2123
styleUrl: './readme.component.scss',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
<img [ngSrc]="bgImg()" alt="card" fill />
12
<ng-content></ng-content>

src/ui/csss-code/card/card.component.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
:host {
22
display: block;
33
position: relative;
4-
background-repeat: no-repeat;
5-
background-size: cover;
6-
background-position: center;
74

85
height: 100%;
96
width: 100%;
Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
1-
import {
2-
ChangeDetectionStrategy,
3-
Component,
4-
ElementRef,
5-
HostBinding,
6-
inject,
7-
input
8-
} from '@angular/core';
9-
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
10-
import { pathToCssUrl } from 'utils/string-utils';
1+
import { NgOptimizedImage } from '@angular/common';
2+
import { ChangeDetectionStrategy, Component, ElementRef, inject, input } from '@angular/core';
113

124
@Component({
135
selector: 'code-card',
6+
imports: [NgOptimizedImage],
147
templateUrl: './card.component.html',
158
styleUrl: './card.component.scss',
16-
changeDetection: ChangeDetectionStrategy.OnPush
9+
changeDetection: ChangeDetectionStrategy.OnPush,
10+
host: {
11+
'[class.hoverable]': 'isHoverOn()'
12+
}
1713
})
1814
export class CardComponent {
19-
/**
20-
* The CSS background image URL.
21-
*/
22-
@HostBinding('style.background-image') protected get backgroundImage(): SafeStyle {
23-
return this.sanitizer.bypassSecurityTrustStyle(pathToCssUrl(this.bgImg()));
24-
}
25-
26-
/**
27-
* The CSS class that enables this to be hoverable.
28-
*/
29-
@HostBinding('class.hoverable') get hoverable(): boolean {
30-
return this.isHoverOn();
31-
}
32-
33-
public elementRef = inject(ElementRef);
15+
elementRef = inject(ElementRef);
3416

3517
/**
3618
* URL of the image to use.
@@ -45,9 +27,4 @@ export class CardComponent {
4527
* false makes the card have no hover effects.
4628
*/
4729
public isHoverOn = input(true);
48-
49-
/**
50-
* Sanitizes inputs for Angular.
51-
*/
52-
private sanitizer = inject(DomSanitizer);
5330
}

0 commit comments

Comments
 (0)