addComponent UI

addComponent API is used to add UI component dynamically as a child of other components.

Syntax

addComponent(jsonObj: Object, parentId: String | Number)

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 sidebarId = "myUniqueSidebarId";

  const sidebarObject = await UI.create({
    type: "Sidebar",
    sidebarTitle: "My Personal Sidebar",
    icon: "./sample.svg",
    id: sidebarId,
  });

  /*
  .
  .
  .
  */

  // Adding Button Component to Sidebar dynamically
  UI.addComponent({
    type: "Button",
    text: "Send",
  }, sidebarId);

});

Parameters

Name

Type

Description

jsonObj

Object

JSON based configuration for creating custom UI components.

parentId

String | Number

Id of the custom UI component, where the component needs to be inserted.