addEvent UI
¶
addEvent API is used to register event listener callbacks against UI component’s events.
Syntax¶
addEvent(componentId: String | Number, eventName: String, ListenerCB: Function)
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import INKAPI from './inkapi.js'
INKAPI.ready(async () => {
const UI = INKAPI.ui;
const btnId = "btnId";
const sidebarObject = await UI.create({
type: "Sidebar",
sidebarTitle: "My Personal Sidebar",
icon: "./sample.svg",
id: "myUniqueSidebarId",
children:[
{
type: "Button",
text: "Click Me!",
id: btnId,
}
]
});
UI.addEvent(btnId, "click", clickHandler)
function clickHandler(){
console.log("Button Clicked!")
}
});
|
Parameters¶
Name |
Type |
Description |
---|---|---|
componentId |
|
Id of the UI Component whose event we need to listen to. |
eventName |
|
Name of the event. Every component can have different event that they emit like click, change, etc. |
ListenerCB |
|
Callback function to be called when the event occurs. |