-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serve alternative images for card viewmodes. DDFFORM-667
Card images are displayed in different aspect ratios, based on context. This is handled by object-fit centering, but generally speaking, we want different cropped images to be served. We get around this, by allowing to pass along alternative SRCs, that are presented as containers, set to display none and using background images. By doing it this way, and letting CSS decide when the display is allowed, the browser is smart enough only to load the image when necessary.
- Loading branch information
Showing
8 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { FC } from "react"; | ||
|
||
type ImageCreditedProps = { | ||
src: string; | ||
alternativeSrcs?: { name: string; src: string }[]; | ||
alt?: string; | ||
}; | ||
|
||
const ImageCredited: FC<ImageCreditedProps> = ({ | ||
src, | ||
alternativeSrcs, | ||
alt = "", | ||
}) => { | ||
// Card images are displayed in different aspect ratios, based on context. | ||
// This is handled by object-fit centering, but generally speaking, we want | ||
// different cropped images to be served. | ||
// We get around this, by allowing to pass along alternative SRCs, that are | ||
// presented as containers, set to display none and using background images. | ||
// By doing it this way, and letting CSS decide when the display is allowed, | ||
// the browser is smart enough only to load the image when necessary. | ||
return ( | ||
<figure className="image-credited"> | ||
{src ? ( | ||
<div className="image-credited__image"> | ||
{alternativeSrcs | ||
? alternativeSrcs.map((alternativeSrc) => ( | ||
<div | ||
className="card__override-images" | ||
style={{ | ||
display: "none", | ||
backgroundImage: `url(${alternativeSrc.src})`, | ||
}} | ||
data-card-style={alternativeSrc.name} | ||
/> | ||
)) | ||
: ""} | ||
|
||
<img src={src} alt={alt} loading="lazy" /> | ||
</div> | ||
) : ( | ||
<div className="image-credited__no-image" /> | ||
)} | ||
</figure> | ||
); | ||
}; | ||
|
||
export default ImageCredited; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters