Start typing to search...
API Reference
@withkoji/custom-vcc-sdk
CustomVcc
Search

CustomVcc

Implements a custom control for capturing user input in Koji apps.

Constructor

Instantiates CustomVcc.

Example

import CustomVcc from '@withkoji/custom-vcc-sdk';
const customVcc = new CustomVcc();

Methods

.change(newValue)

Updates the value with the user-entered value.

Parameters

  • newValueAny, Current value of the custom control.

Example

customVcc.change(newValue);

.onTheme(handler)

Listens to changes to the theme value, to retrieve values relating to the Koji display theme. The theme returned in the listener allows you to style the control to match the user’s current theme on Koji (dark or light).

Parameters

  • handlerFunction, Called when theme is available. Receives the following property as input:

    • themeTheme, Represents the theme as an object.

Example

customVcc.onTheme((theme) => {
	// theme is a Koji editor theme
 	// save this value in order to style your control to match the user's current theme
});

.onUpdate(handler)

Listens to changes in the custom value from the consumer application to enable updates to rendered values.

Tip
It is prefereable to update the rendered value only in response to onUpdate events. Calling change immediately fires an onUpdate.

Parameters

  • handlerFunction, Handles changes to the custom value. Receives the following property as input:

    • propsProps, Properties of the custom control.

Example

customVcc.onUpdate((props) => {
	// props is an object containing the control's current state.
});

.register(width, height)

Indicates that the custom control has loaded and registers it to trigger the on events from the parent editor.

Parameters

  • width – (Optional) Any, Width of the custom control.

  • height – (Optional) Any, Height of the custom control.

Example

customVcc.register('300', '300');

.save()

Saves the JSON customization file in the consumer application.

Example

customVcc.save();

.uploadFile(file, fileName, onComplete)

Uploads a file blob to the Koji CDN.

Parameters

  • fileBlob, File blob data to be uploaded.

  • fileNameString, Name of the file to be uploaded.

  • onCompleteFunction, Called when upload has completed. Receives the following property as input:

    • urlString, URL of the uploaded file.

Example

customVcc.uploadFile(myBlob, myFileName, (url) => {
  // url of the uploaded file
});

Interfaces

Props

Represents the current state of a custom control. It is returned to the handler listening to onUpdate.

Properties

  • typeString, Type signature for this VCC.

  • nameString, Name of the control.

  • valueAny, Current value of the control.

  • scopeString, Name of the section where this VCC appears in the consumer application.

  • variableNameString, Resolved variable name of this VCC (scope.key).

  • optionsObject, Any options passed in typeOptions.

  • collaborationDecorationObject, Any collaborators currently focused on this control.

  • _configObject, The full VCC configuration file. Most controls are isolated to a single value. However, this object can be useful when creating more complex custom controls, like map builders.

Theme

Allows you to use styles that match the colors and styles of the calling app’s active theme. It is returned to the handler listening to onTheme.

Properties

  • nameString, Name of the theme.

  • breakpointsObject, Responsive style breakpoints of the theme.

  • colorsObject, Key-value pairs representing the theme’s named colors.

  • mixinsObject, CSS mixins to style specific elements.

Example

{
	"name": "aspergillus",
	"breakpoints": {
		"default": "(min-width: 1025px)",
		"phone": "(max-width: 767px)",
		"tablet": "(max-width: 1024px)"
	},
	"colors": {
		"background.default": "#ffffff",
		"foreground.default": "#111111",
		"input.background": "#ffffff",
		"input.foreground": "#111111"
		...
	},
	"mixins": {
		"card.default": "box-shadow: 0 6px 24px 0 rgba(0,0,0,0.05); background-color: #fff;",
		"clickable": "cursor: pointer; user-select: none;",
		...
	}
}