<AssetMedia>
Puck Assets is in early access. Request access.
Render the value of an asset field as an image or video.
import { AssetMedia } from "@puckeditor/plugin-assets";
const config = {
components: {
Hero: {
fields: { image: { type: "asset" } },
render: ({ image }) =>
image ? (
<AssetMedia
src={image.src}
alt={image.alt}
mediaType={image.mediaType}
/>
) : null,
},
},
};Props
| Param | Example | Type | Status |
|---|---|---|---|
src | src: image.src | String | Required |
alt | alt: image.alt | String | - |
aspectRatio | aspectRatio: "16x9" | "16x9" | "1x1" | Number | - |
className | className: "hero-image" | String | - |
loading | loading: "eager" | "lazy" | "eager" | - |
mediaType | mediaType: image.mediaType | String | - |
sizes | sizes: "50vw" | String | - |
Required props
src
The asset’s URL. Use the src property of the asset field value.
Optional props
alt
The accessible description for the asset. Use the alt property of the asset field value.
aspectRatio
The shape the asset fills ("16x9", "1x1", or a number). Defaults to the image’s own shape.
className
The element’s CSS class.
loading
When to load the asset. "lazy" waits until the asset is near the screen. Defaults to "lazy".
mediaType
The asset’s media type. Defines how the asset should be rendered. Must be a valid image or video MIME type string.
sizes
The image’s sizes attribute. Defaults to "100vw".