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 | undefined
The asset to display.
preset
The preset to use for the image.
mode
The crop/resize mode to use for the image.
width
number
The width of the image.
height
number
The height of the image.
format
The format of the image.
quality
number
The quality of the image.
useFocalPoint
boolean
Whether to use the asset's focal point in crop mode.
fallback
React.ReactNode
The 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
string
preview
string
name
string | null
focalPoint
{ x: number; y: number } | null
ImagePreset
The presets that can be used for the VendureImage component.
type ImagePreset = 'tiny' | 'thumb' | 'small' | 'medium' | 'large' | 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