Skip to content

Commit

Permalink
fix(storefront): Add new isHalfSize optional prop to `BannerPicture…
Browse files Browse the repository at this point in the history
…s.astro`

Minor fix transform widths and srcset sizes
  • Loading branch information
leomp12 committed Oct 8, 2024
1 parent 5ecda74 commit d7fc29d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/storefront/src/lib/components/BannerPictures.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type Props = UseBannerProps & {
class?: string;
mobileWidths?: number[];
mobileClass?: string;
isHalfSize?: boolean;
};
const {
Expand All @@ -18,19 +19,24 @@ const {
subtitle,
buttonText,
index,
class: className = 'max-w-screen-sm sm:max-w-[828px] md:max-w-screen-2xl',
mobileClass = 'max-w-screen-sm sm:max-w-screen-lg',
mobileClass,
} = Astro.props as Props;
const hasHeader = title || subtitle || buttonText;
const hasHeader = Boolean(title || subtitle || buttonText);
const isHalfSize = Astro.props.isHalfSize || hasHeader;
let { widths, mobileWidths } = Astro.props;
let className = Astro.props.class;
if (!className) {
if (isHalfSize) {
className = 'max-w-screen-sm sm:max-w-[828px] lg:max-w-screen-xl';
} else {
className = 'max-w-screen-sm sm:max-w-[828px] md:max-w-screen-2xl 2xl:max-w-[1920px]';
}
}
if (!widths?.length) {
if (mobileImg) {
widths = [1536, 2048];
widths = isHalfSize ? [828, 1280] : [1536, 2048];
} else {
widths = [640, 828, 1536, 2048];
if (hasHeader) {
widths = widths.map((w) => (w / 2));
}
widths = isHalfSize ? [640, 828, 1280] : [640, 828, 1536, 2048];
}
}
if (!mobileWidths?.length) {
Expand All @@ -56,6 +62,7 @@ if (!mobileWidths?.length) {
widths={mobileWidths}
fetchpriority={index === 0 ? 'high' : 'low'}
loading={index === 0 ? 'eager' : 'lazy'}
class={`mx-auto text-sm text-opacity-70 md:hidden ${mobileClass}`}
class={`mx-auto text-sm text-opacity-70 md:hidden
${(mobileClass || 'max-w-screen-sm sm:max-w-screen-lg')}`}
/>
}

0 comments on commit d7fc29d

Please sign in to comment.