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
opts
object
Options for configuring the callback.
target
Target
The target to check the canOpen
state of.
This must be "image_selection"
.
onCanOpen
function
A callback that runs when the canOpen
state of the specified target changes.
This callback fires immediately.
Parameters
event
OverlayOpenableEvent<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.
canOpen
boolean
Indicates that the overlay can't be opened for the specified target.
This must be false
.
reason
string
Indicates the reason the overlay can't be opened for the specified target.
canOpen
boolean
Indicates that the overlay can be opened for the selected image.
This must be true
.
open
function
Read-onlyOpens an overlay for the selected image.
Parameters
options
object
launchParameters
unknown
Parameters 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