From cad2f1d410332a47e2408c1df1717cc317dadbb3 Mon Sep 17 00:00:00 2001 From: hiyach28 Date: Mon, 3 Aug 2026 18:35:24 +0000 Subject: [PATCH] [UI] Add fitContainer rendering mode to normalize thumbnails Signed-off-by: hiyach28 --- src/components/Card/Card.style.js | 12 +++- src/components/Card/index.js | 12 +++- src/components/image.js | 58 +++++++++++++------ .../Resources/Resources-grid/index.js | 1 + 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/components/Card/Card.style.js b/src/components/Card/Card.style.js index 0c7820c012a20b..4fd26b2df6e299 100644 --- a/src/components/Card/Card.style.js +++ b/src/components/Card/Card.style.js @@ -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; + `} .gatsby-image-wrapper, .old-gatsby-image-wrapper { @@ -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 { diff --git a/src/components/Card/index.js b/src/components/Card/index.js index 22d44c26b39a7b..e7d3d4db64555d 100644 --- a/src/components/Card/index.js +++ b/src/components/Card/index.js @@ -12,10 +12,15 @@ const Card = ({ loading = "lazy", fetchpriority = "auto", listView = false, + fitContainer = false, }) => { const { isDark } = useStyledDarkMode(); return ( - +
{frontmatter.title} { +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 ( -
+
{alt
); } - return ; + return ( + + ); }; export default Image; diff --git a/src/sections/Resources/Resources-grid/index.js b/src/sections/Resources/Resources-grid/index.js index b015866da4eb57..8958290507c5cd 100644 --- a/src/sections/Resources/Resources-grid/index.js +++ b/src/sections/Resources/Resources-grid/index.js @@ -51,6 +51,7 @@ const ResourceGrid = (props) => { ))}