onPresetSelected
API reference for the "onPresetSelected" method.
Registers a callback that runs when the user selects a preset.
If a user opens an extension by selecting a preset, the onReady callback runs immediately before the onPresetSelected callback.

Usage

1
const { imageHelpers } = window.canva;
2
const canva = window.canva.init();
3
4
canva.onReady(async (opts) => {
5
// This callback must exist for the extension to load
6
});
7
8
canva.onPresetsRequest(async (opts) => {
9
return [
10
{
11
id: "myPreset",
12
label: "My Preset",
13
image: opts.image,
14
},
15
];
16
});
17
18
canva.onPresetSelected(async (opts) => {
19
console.log(opts);
20
});
Copied!

Parameters

Name
Type
Required
Description
handler
Yes
The callback that runs when the user selects a preset.

Returns

void

Types

PresetSelectedHandler

The callback that runs when the user selects a preset.
Signature
1
(opts) => void
Copied!
Parameters
Name
Type
Required
Description
opts
object
Yes
Information about the event.
opts.presetId
string
Yes
The id of the selected preset.
Returns
void