FixedBanner
A single linked banner image, with a smaller image for phones and an eager-loading option for a banner at the top.
import { FixedBanner } from '@salla.sa/twilight-theme-engine/components/home';In plain words
One wide picture that links somewhere, such as a sale banner. The block can carry a second, smaller picture for phones, which the browser picks below 768px.
Set priority for a banner at the very top of the page: the browser then loads it first instead of waiting.
Signature
const FixedBanner: React.MemoExoticComponent<(props: {
data: {
image: { url: string; alt?: string; small_url?: string };
url?: string; // '#'
title?: string; // alt text when image.alt is empty
[key: string]: unknown;
};
priority?: boolean; // false
}) => JSX.Element | null>Try it live
Loading the home page blocks…
import { FixedBanner } from '@salla.sa/twilight-theme-engine/components/home';
export function HeroBanner() {
return (
<FixedBanner
data={{
image: { url: '/banner.jpg', small_url: '/banner-mobile.jpg' },
url: '/offers',
title: 'Summer sale',
}}
/>
);
}
Example
import { FixedBanner } from '@salla.sa/twilight-theme-engine/components/home';
export function Hero() {
return (
<FixedBanner
priority
data={{
image: { url: '/banners/sale.webp', small_url: '/banners/sale-mobile.webp' },
url: '/offers',
title: 'End of season sale',
}}
/>
);
}
How it behaves
Markup:
.container> engineLink.banner.banner--fixed><picture>with a(max-width: 767px)source forsmall_url><img width="1200" height="300">withobject-fit: contain.prioritygivesloading="eager",fetchpriority="high"anddecoding="sync"; otherwiseloading="lazy"anddecoding="async".The alt text is
image.altwhen not blank, elsetitle, else "fixed banner".
Gotchas
priorityis a prop of its own here, butHomeComponentRendererpassespriorityinsidedata. A banner the home page renders is therefore always lazy, even at the top; render the first banner yourself, or register a small wrapper that passespriority={data.priority}.Without
image.urlit renders nothing.