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

chore(gd): Styles for SVG Icons thumbnails were broken #29278

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -26,6 +26,11 @@ dot-contentlet-icon {
background-size: cover;
background-position: center center;
background-repeat: no-repeat;

&.svg-thumbnail {
background-size: contain;
}

img {
width: 0px;
height: 0px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export class DotContentletThumbnail {
fieldVariable = '';

@State() renderImage: boolean;
@State() isSVG: boolean;

componentWillLoad() {
const { hasTitleImage, mimeType } = this.contentlet;
this.isSVG = mimeType === 'image/svg+xml';
// Some endpoints return this property as a boolean
if (typeof hasTitleImage === 'boolean' && hasTitleImage) {
this.renderImage = hasTitleImage;
Expand All @@ -54,6 +56,7 @@ export class DotContentletThumbnail {
const backgroundImageURL =
this.contentlet && this.backgroundImage ? `url(${this.getImageURL()})` : '';
const imgClass = this.backgroundImage ? 'background-image' : '';
const svgClass = this.isSVG ? ' svg-thumbnail' : '';

return (
<Host>
Expand All @@ -66,8 +69,10 @@ export class DotContentletThumbnail {
/>
) : this.renderImage ? (
<div
class={`thumbnail ${imgClass}`}
style={{ 'background-image': backgroundImageURL }}>
class={`thumbnail ${imgClass}${svgClass}`}
style={{
'background-image': backgroundImageURL
}}>
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
<img
src={this.getImageURL()}
alt={this.alt}
Expand All @@ -87,13 +92,16 @@ export class DotContentletThumbnail {
}

private getImageURL(): string {
return this.contentlet.mimeType === 'application/pdf'
? `/contentAsset/image/${this.contentlet.inode}/${
this.fieldVariable || this.contentlet.titleImage
}/pdf_page/1/resize_w/250/quality_q/45`
: `/dA/${this.contentlet.inode}/${this.fieldVariablePath()}500w/50q?r=${
this.contentlet.modDateMilis || this.contentlet.modDate
}`;
if (this.contentlet.mimeType === 'application/pdf')
return `/contentAsset/image/${this.contentlet.inode}/${
this.fieldVariable || this.contentlet.titleImage
}/pdf_page/1/resize_w/250/quality_q/45`;

if (this.isSVG) return `/contentAsset/image/${this.contentlet.inode}/asset`;

return `/dA/${this.contentlet.inode}/${this.fieldVariablePath()}500w/50q?r=${
this.contentlet.modDateMilis || this.contentlet.modDate
}`;
}

private fieldVariablePath(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
}

dot-contentlet-thumbnail::ng-deep {
.background-image:not(.svg-thumbnail) {
img {
object-fit: cover;
}
}

img {
object-fit: cover;
object-fit: contain;
}
}

Expand Down