From 8e2379c0c1806083e12062e4e886c6cc7aeb2f45 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 13 Nov 2024 11:39:44 +0000 Subject: [PATCH] feat: add responsive support to picture component --- packages/astro/components/Image.astro | 25 +++--- packages/astro/components/Picture.astro | 79 +++++++++++++++++-- .../core-image-layout/src/pages/picture.astro | 35 ++++++++ 3 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 packages/astro/test/fixtures/core-image-layout/src/pages/picture.astro diff --git a/packages/astro/components/Image.astro b/packages/astro/components/Image.astro index 70cbc0f456..04d964d4ea 100644 --- a/packages/astro/components/Image.astro +++ b/packages/astro/components/Image.astro @@ -23,14 +23,16 @@ if (typeof props.height === 'string') { props.height = parseInt(props.height); } -const { experimentalResponsiveImages } = imageConfig; - const layoutClassMap = { fixed: 'aim-fi', responsive: 'aim-re', + 'full-width': '', }; -if (experimentalResponsiveImages) { +const layout = props.layout ?? imageConfig.experimentalLayout ?? 'none'; +const useResponsive = imageConfig.experimentalResponsiveImages && layout !== 'none'; + +if (useResponsive) { // Apply defaults from imageConfig if not provided props.layout ??= imageConfig.experimentalLayout; props.fit ??= imageConfig.experimentalObjectFit ?? 'cover'; @@ -56,12 +58,12 @@ const { style = '', class: className, ...attrs } = { ...additionalAttributes, .. --- { - experimentalResponsiveImages && props.layout ? ( + useResponsive ? ( ) : ( @@ -69,13 +71,12 @@ const { style = '', class: className, ...attrs } = { ...additionalAttributes, .. } diff --git a/packages/astro/test/fixtures/core-image-layout/src/pages/picture.astro b/packages/astro/test/fixtures/core-image-layout/src/pages/picture.astro new file mode 100644 index 0000000000..53cce01ce4 --- /dev/null +++ b/packages/astro/test/fixtures/core-image-layout/src/pages/picture.astro @@ -0,0 +1,35 @@ +--- +import { Picture } from "astro:assets"; +import myImage from "../assets/penguin.jpg"; +--- + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +