Generate experiences with Puck AI
Read docs
CloudAPI referenceplugin-assetsFieldsAsset Field

Asset Field

Puck Assets is in early access. Request access.

Render a field for picking an asset from Puck Assets. Extends Base.

const config = {
  components: {
    Example: {
      fields: {
        image: {
          type: "asset",
          accept: ["image/*"],
        },
      },
      render: ({ image }) => <img src={image?.src} alt={image?.alt} />,
    },
  },
};

The field needs the Assets plugin.

Params

ParamExampleTypeStatus
typetype: "asset"”asset”Required
acceptaccept: ["image/*"]String[]-
transformtransform: { width: 1200 }Object-
transformControlstransformControls: falseBoolean-

Required params

type

The type of the field. Must be "asset".

Optional params

accept

The media type patterns the field accepts, such as image/*. Defaults to all types.

transform

The changes to apply to images picked by this field. Defaults to no change.

transform.width

Set the image’s width in pixels. Defaults to the image’s original width.

transform.height

Set the image’s height in pixels. Defaults to the image’s original height.

transform.fit

Set how the image fits the width and height props. Defaults to "scale-down".

  • "scale-down": Shows the whole image in the area and keeps its aspect ratio. It never upscales.
  • "contain": Shows the whole image in the area and keeps its aspect ratio. It upscales or downscales as needed.
  • "cover": Fills the area and crops the parts that don’t fit. It upscales as needed.
  • "crop": Fills the area and crops the parts that don’t fit. It never upscales.

transform.quality

Set the image’s quality and compression for JPEG and WebP formats, from 1 (lowest quality, smallest file) to 100 (highest quality, largest file). Defaults to 85.

transform.focalPoint

Set the coordinates (0.0 to 1.0) for the point around which to resize the image when changing the width and height props. Defaults to {"x": 0.5, "y": 0.5} (center).

transform.rotate

Rotate the image by 0, 90, 180, or 270 degrees. Defaults to 0.

transform.flip

Flip the image horizontally with "h", vertically with "v", or both ways with "hv". Defaults to no flip.

transform.saturation

Set the image’s color saturation factor, from 0.0 (desaturated) to 2.0 (highly saturated). Defaults to 1, no change.

transform.brightness

Set the image’s brightness factor, from 0.0 (completely dark) to 2.0 (very bright). Defaults to 1, no change.

transform.contrast

Set the image’s contrast factor, from 0.0 (no contrast) to 2.0 (high contrast). Defaults to 1, no change.

transform.gamma

Set the image’s gamma factor, from 0.0 (no gamma correction) to 2.0 (high gamma correction). Defaults to 1, no change.

transform.blur

Set the blur radius, from 0 (no blur) to 250 (maximum blur). Defaults to 0.

transform.sharpen

Set the sharpening strength, from 0 (no sharpening) to 10 (maximum sharpening). Defaults to 0.

transformControls

Whether users can change the transform of a picked image from the field UI. Defaults to true.