import CustomVcc from '@withkoji/custom-vcc-sdk';
const customVcc = new CustomVcc();
Implements a custom control for capturing user input in Koji apps.
Instantiates CustomVcc
.
import CustomVcc from '@withkoji/custom-vcc-sdk';
const customVcc = new CustomVcc();
Updates the value with the user-entered value.
newValue
– Any, Current value of the custom control.
customVcc.change(newValue);
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).
handler
– Function, Called when theme is available.
Receives the following property as input:
theme
– Theme, Represents the theme as an object.
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
});
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 .
|
handler
– Function, Handles changes to the custom value.
Receives the following property as input:
props
– Props, Properties of the custom control.
customVcc.onUpdate((props) => {
// props is an object containing the control's current state.
});
Indicates that the custom control has loaded and registers it to trigger the on events from the parent editor.
width
– (Optional) Any, Width of the custom control.
height
– (Optional) Any, Height of the custom control.
customVcc.register('300', '300');
Saves the JSON customization file in the consumer application.
customVcc.save();
Uploads a file blob to the Koji CDN.
file
– Blob, File blob data to be uploaded.
fileName
– String, Name of the file to be uploaded.
onComplete
– Function, Called when upload has completed.
Receives the following property as input:
url
– String, URL of the uploaded file.
customVcc.uploadFile(myBlob, myFileName, (url) => {
// url of the uploaded file
});
Represents the current state of a custom control. It is returned to the handler listening to onUpdate.
type
– String, Type signature for this VCC.
name
– String, Name of the control.
value
– Any, Current value of the control.
scope
– String, Name of the section where this VCC appears in the consumer application.
variableName
– String, Resolved variable name of this VCC (scope.key
).
options
– Object, Any options passed in typeOptions
.
collaborationDecoration
– Object, Any collaborators currently focused on this control.
_config
– Object, 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.
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.
name
– String, Name of the theme.
breakpoints
– Object, Responsive style breakpoints of the theme.
colors
– Object, Key-value pairs representing the theme’s named colors.
mixins
– Object, CSS mixins to style specific elements.
{
"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;",
...
}
}