Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion src/components/Card/Card.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export const CardWrapper = styled.div`
justify-content: center;
padding: 0.5rem;
`}
${(props) =>
props.$fitContainer &&
!props.$listView &&
`
padding: 2rem;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
`}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

.gatsby-image-wrapper,
.old-gatsby-image-wrapper {
Expand Down Expand Up @@ -123,7 +133,7 @@ export const CardWrapper = styled.div`
`
@media screen and (max-width: 1200px) and (min-width: 992px) {
.post-thumb-block {
height: auto;
height: ${(props) => (props.$fitContainer ? "10rem" : "auto")};
min-height: 10rem;
}
.post-content-block {
Expand Down
12 changes: 9 additions & 3 deletions src/components/Card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ const Card = ({
loading = "lazy",
fetchpriority = "auto",
listView = false,
fitContainer = false,
}) => {
const { isDark } = useStyledDarkMode();
return (
<CardWrapper fixed={!!frontmatter.abstract} $listView={listView}>
<CardWrapper
fixed={!!frontmatter.abstract}
$listView={listView}
$fitContainer={fitContainer}
>
<div className="post-block">
<div className="post-thumb-block">
<Image
Expand All @@ -25,7 +30,8 @@ const Card = ({
frontmatter.thumbnail.publicURL
? frontmatter.darkthumbnail
: frontmatter.thumbnail)}
imgStyle={{ objectFit: "cover" }}
fitContainer={fitContainer}
imgStyle={!fitContainer ? { objectFit: "cover" } : {}}
loading={loading}
fetchpriority={fetchpriority}
alt={frontmatter.title}
Expand Down Expand Up @@ -98,4 +104,4 @@ const Card = ({
);
};

export default Card;
export default Card;
58 changes: 41 additions & 17 deletions src/components/image.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
import React from "react";
import { GatsbyImage } from "gatsby-plugin-image";

const Image = ({ childImageSharp, extension, publicURL, alt, imgStyle, ...rest }) => {
const Image = ({
childImageSharp,
extension,
publicURL,
alt,
imgStyle,
fitContainer,
...rest
}) => {
/**
* Rendering Mode: fitContainer
* By default, GatsbyImage and SVGs scale to their intrinsic aspect ratios.
* Passing `fitContainer={true}` forces the image wrapper to 100% width and height,
* and uses `object-fit: contain` to scale the image losslessly inside that bounds.
*
* Note: This rendering mode guarantees full visibility with no cropping,
* but mathematically CANNOT guarantee identical pixel area (visual weight) across
* arbitrary aspect ratios, as that limitation belongs to standard CSS constraints.
*/
const computedWrapperStyle = fitContainer
? { width: "100%", height: "100%" }
: { width: "100%", height: "auto" };

const computedImgStyle = {
objectFit: fitContainer ? "contain" : imgStyle?.objectFit || "cover",
...(fitContainer && { width: "100%", height: "100%" }),
...imgStyle,
};

if (!childImageSharp && extension === "svg") {
return (
<div className="old-gatsby-image-wrapper" style={{ width: "100%", height: "auto" }}>
<div className="old-gatsby-image-wrapper" style={computedWrapperStyle}>
<img
src={publicURL}
alt={alt || "Blog image"}
width="100%"
height="auto"
style={{
objectFit: imgStyle?.objectFit || "cover",
...imgStyle
}}
height={fitContainer ? "100%" : "auto"}
style={computedImgStyle}
/>
</div>
);
}

return <GatsbyImage
key={publicURL}
image={childImageSharp?.gatsbyImageData}
alt={alt || "Blog image"}
imgStyle={{
objectFit: imgStyle?.objectFit || "cover",
...imgStyle
}}
{...rest}
/>;
return (
<GatsbyImage
key={publicURL}
image={childImageSharp?.gatsbyImageData}
alt={alt || "Blog image"}
style={fitContainer ? computedWrapperStyle : undefined}
imgStyle={computedImgStyle}
{...rest}
/>
);
};

export default Image;
1 change: 1 addition & 0 deletions src/sections/Resources/Resources-grid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const ResourceGrid = (props) => {
<Card
frontmatter={frontmatter}
fields={fields}
fitContainer={frontmatter.type === "Article"}
/>
</Col>
))}
Expand Down