onPresetsRequest

API reference for the "onPresetsRequest" method.

Registers a callback that runs when Canva requests presets from an editing extension.

You can't call the remoteProcess method from the onPresetsRequest callback.

Usage

const { imageHelpers } = window.canva;
const canva = window.canva.init();
canva.onReady(async (opts) => {
// This callback must exist for the extension to load
});
canva.onPresetsRequest(async (opts) => {
return [
{
id: "myPreset",
label: "My Preset",
image: opts.image,
},
];
});

Parameters

Name

Type

Required

Description

handler

PresetsRequestHandler

Yes

The callback that runs when Canva requests presets.

Returns

void

PresetsRequestHandler

The callback that runs when Canva requests presets.

Signature

(opts) => Promise<Preset[]> | Preset[]

Parameters

Name

Type

Required

Description

opts

object

Yes

Information about the event.

opts.image

CanvaImageBlob

Yes

The user's image.

opts.minDimensions

object

Yes

The minimum dimensions of a preset's thumbnail.

opts.minDimensions.height

number

Yes

The minimum height of a preset's thumbnail, in pixels.

opts.minDimensions.width

number

Yes

The minimum width of a preset's thumbnail, in pixels.

Returns

Types

Preset

Represents an individual preset.

Signature

export type Preset = {
id: string;
label: string;
image: CanvaImageBlob;
kind?: "customizable" | "simple";
categoryId?: string;
};

Properties

Name

Type

Required

Description

id

string

Yes

A unique ID for the preset.

image

CanvaImageBlob

Yes

A thumbnail for the preset.

label

string

Yes

A human readable label for the preset.

kind

"simple" | "customizable"

No

The type of preset. The default value is "customizable".

categoryId

string

No

The ID of a preset category.