Start typing to search...
Reference
Packages for Koji features
@withkoji/custom-vcc-sdk
Search

@withkoji/custom-vcc-sdk

The @withkoji/custom-vcc-sdk package enables you to implement custom Visual Customization Controls (VCCs) for your template.

The Koji platform includes VCCs for standard elements, such as images, text, and sounds. In addition, you can build custom VCCs to provide new types of customizations that match closely with the application you are developing. For example, some Koji templates provide tile map editors, sound enhancers, or custom avatar creators to enhance the interactivity for remixers.

Install

Install the package in your Koji project.

npm install --save @withkoji/custom-vcc-sdk

CustomVcc

new CustomVcc()

Instantiates CustomVcc.

Example

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

CustomVcc methods

.change(newValue)

Updates the VCC value with the user-entered value.

Parameters

  • newValueAny, current value of the VCC.

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 VCC 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:

    • themeObject, represents the theme as an object. See Theme.

Example

customVcc.onTheme((theme) => {
	// theme is a Koji editor theme
 	// save this value in order to style your VCC 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, handle changes to the custom value. Receives the following property as input:

    • propsObject, contains the properties of the VCC. See Props.

Example

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

.register(width, height)

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

Parameters

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

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

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
});

CustomVcc objects

Props

A props object represents the current state of a custom VCC. It is returned to the handler listening to onUpdate.

The props object includes the following properties.

{
	type: string;(1)
	name: string;(2)
	value: any;(3)
	scope: string;(4)
	variableName: string;(5)
	options: object;(6)
	collaborationDecoration: object;(7)
	_config: object;(8)
};
  1. type – Type signature for this VCC.

  2. name – Name of the VCC.

  3. value – Current value of the VCC.

  4. scope – Name of the section where this VCC appears in the consumer application.

  5. variableName – Resolved variable name of this VCC (scope.key).

  6. options – An object containing any options passed in typeOptions.

  7. collaborationDecoration – An object containing any collaborators currently focused on this control.

  8. _config – 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

A theme object allows you to use styles that match the colors and styles of the remixer’s active theme. It is returned to the handler listening to onTheme.

The theme object includes the following properties.

{
	name: string;(1)
	breakpoints: object;(2)
	colors: object;(3)
	mixins: object;(4)
};
  1. name – Name of the theme.

  2. breakpoints – An object containing responsive style breakpoints of the theme.

  3. colors – An object of key-value pairs representing the theme’s named colors.

  4. mixins – An object containing CSS mixins to style specific elements.

Here is an example of some of the properties of the theme object.

{
	"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;",
		...
	}
}