import React from "react";
import NextImage from "next/image";
import type { ComponentProps, CssProperties, Asset } from "@webiny/website-builder-react";
import {
getAssetUrl,
getImageDimensions,
getImageSrcSet,
normalizeToAsset
} from "@webiny/website-builder-react";
type ImageProps = ComponentProps<{
title: string;
altText: string;
highPriority: boolean;
// Accepts the unified asset shape or a legacy value (existing pages).
image: Asset;
}>;
export const ImageComponent = (props: ImageProps) => {
const { title = "", altText, image, highPriority } = props.inputs;
const asset = normalizeToAsset(image);
if (!asset?.src) {
return when dimensions are
// unknown (next/image requires width + height unless `fill`).
const { width, height } = getImageDimensions(asset);
const style: CssProperties = { maxWidth: "100%", height: "auto", ...props.styles };
if (!width || !height) {
// No intrinsic size to lay out with — fall back to a plain
, still
// responsive via the SDK's framework-agnostic srcSet (crop/format baked in).
const { src, srcSet } = getImageSrcSet(asset, {
format: "auto",
cssWidth: props.styles?.width
});
// eslint-disable-next-line @next/next/no-img-element
return (
);
}
return (