VendureImage
VendureImage
A component for displaying an image from a Vendure asset.
Supports the following features:
- Presets
- Cropping
- Resizing
- Formatting
- Quality
- Focal point
- Fallback
Example
<VendureImage
asset={asset}
preset="thumb"
className="w-full h-full object-contain"
/>
function VendureImage(props: VendureImageProps): void
Parameters
props
VendureImageProps
The props for the VendureImage component.
interface VendureImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
asset: AssetLike | null | undefined;
preset?: ImagePreset;
mode?: ImageMode;
width?: number;
height?: number;
format?: ImageFormat;
quality?: number;
useFocalPoint?: boolean;
fallback?: React.ReactNode;
ref?: React.Ref<HTMLImageElement>;
}
- Extends:
React.ImgHTMLAttributes<HTMLImageElement>
asset
AssetLike | null | undefinedThe asset to display.
preset
The preset to use for the image.
mode
The crop/resize mode to use for the image.
width
numberThe width of the image.
height
numberThe height of the image.
format
The format of the image.
quality
numberThe quality of the image.
useFocalPoint
booleanWhether to use the asset's focal point in crop mode.
fallback
React.ReactNodeThe fallback to show if no asset is provided. If no fallback is provided, a default placeholder will be shown.
ref
React.Ref<HTMLImageElement>The ref to the image element.
AssetLike
The type of object that can be used as an asset in the VendureImage component.
interface AssetLike {
id: string;
preview: string;
name?: string | null;
focalPoint?: { x: number; y: number } | null;
}
id
stringpreview
stringname
string | nullfocalPoint
{ x: number; y: number } | nullImagePreset
The presets that can be used for the VendureImage component.
type ImagePreset = 'tiny' | 'thumb' | 'small' | 'medium' | 'large' | 'full' | null
ImageFormat
The formats that can be used for the VendureImage component.
type ImageFormat = 'jpg' | 'jpeg' | 'png' | 'webp' | 'avif' | null
ImageMode
The modes that can be used for the VendureImage component.
type ImageMode = 'crop' | 'resize' | null