All blocks can have editable attributes, each of which store settings that can be changed by an app creator.
Attributes are defined in the data.attributes
object found in <your block folder>/index.js
:
module.exports = {
className: 'phonecall',
template: require('./index.html'),
data: {
name: 'Phone Call',
icon: '/images/blocks_phone.png',
attributes: {
number: {
label: 'Phone #',
type: 'string',
value: '+18005555555'
},
innerHTML: {
label: 'Label',
type: 'string',
value: 'Send SMS'
}
}
}
};
Each editable attribute is keyed on its id
, and should include three properties:
label
: The label which appears to the app creator in the block editortype
: The type of editor that should be generated in the block editorvalue
: A default/placeholder value that will be used when the block is first added to the app
Labels can be any string, but should be specific and descriptive of the function that the attribute plays in your block. You should define labels in English (US) and add a localization for it if you wish to make it available in other languages.
The default type (if not defined) is string
, which will generate a simple input field.
Some types have special functionality and custom editors:
innerHTML
: The innerHTML of your block container will automatically be set to the value of this attribute.color
: Thestyle.color
of your block container will automatically be set to the value of this attribute. You will also get a special color picker for an editor.
Types which are not special types will get the string
editor and have no special automatically functionality; you will have to apply them in your template/js for them to be useful.