When you add a Blocks site widget extension in the CLI, an api.ts
file is generated for the extension. This file contains the declarations for your Widget API properties, events, and functions.
When you add a new blocks site widget to your project, you'll see the following code in api.ts
:
You can implement and use these properties, events, and functions in your widget.ts
file. They are exposed when your widget is installed on a site (in the Wix Editors) or when it's added inside another widget.
Declare widget properties as key-value pairs within the props
object. Property values can only be strings.
When a widget is added to a site, your app (and users) can interact with your widget properties using $widget.
This flow currently doesn’t support custom type properties.
Declare methods you want your widget to expose within the methods
object. You must return these methods from defineWidget()
in your widget.ts
file.
Declare events you want your widget to trigger within the events
object. You can trigger these events in defineWidget()
in your widget.ts
file.