overlay.registerOnCanOpen
Registers a callback that runs when the canOpen state of an overlay target changes.
Usage
Register overlay handler
import { overlay } from "@canva/design";overlay.registerOnCanOpen({target: 'image_selection',onCanOpen: async (event) => {if (event.canOpen) {// Can open overlay for selected image}}});
Open image editing overlay
import { overlay } from "@canva/design";overlay.registerOnCanOpen({target: 'image_selection',onCanOpen: async (event) => {if (event.canOpen) {const processId = await event.open({launchParameters: {mode: 'edit'}});// Overlay process started, with `processId`}}});
Open overlay with filters
import { overlay } from "@canva/design";overlay.registerOnCanOpen({target: 'image_selection',onCanOpen: async (event) => {if (event.canOpen) {await event.open({launchParameters: {mode: 'edit',filters: ['brightness', 'contrast', 'saturation']}});}}});
Handle overlay unavailability
import { overlay } from "@canva/design";overlay.registerOnCanOpen({target: 'image_selection',onCanOpen: async (event) => {if (!event.canOpen) {// Cannot open overlay, handle specific reasonsswitch (event.reason) {case 'no_selection':// No image is selectedbreak;case 'invalid_selection':// Selected content cannot be editedbreak;}}}});
Parameters
optsobjectOptions for configuring the callback.
targetTargetThe target to check the canOpen state of.
The only valid value is "image_selection".
onCanOpenfunctionA callback that runs when the canOpen state of the specified target changes.
This callback fires immediately.
Parameters
eventOverlayOpenableEvent<Target>Information about whether or not an overlay can be opened for the specified target.
Information about an overlay that can't be opened for the specified target.
canOpenbooleanIndicates that the overlay can't be opened for the specified target.
The only valid value is false.
reasonstringIndicates the reason the overlay can't be opened for the specified target.
canOpenbooleanIndicates that the overlay can be opened for the selected image.
The only valid value is true.
openfunctionRead-onlyOpens an overlay for the selected image.
Parameters
optionsobjectlaunchParametersunknownParameters to pass to the overlay when it opens.
This can be any type of structured data.
Returns
A unique identifier that references an app runtime process.
Promise<AppProcessId>
Returns
void
Returns
() => void