Define properties
This topic describes how to define properties for a component.
Example
- Define the properties in the component's
specs.jsfile:export default { "properties": [{ "identifier": "temperature", "defaultValue": 26, "text": "Temperature", "type": "text", }], "services": [], "events": [] };A property where the type (type) is text, the Chinese name of the property (text) is Temperature, the default value (defaultValue) is
%26;, and the unique component identifier (identifier) is temperature. - Develop the
rendermethod in theindex.tsxentry file:render(): JSX.Element { const { temperature } = this.props; return ( <div> Current temperature is: {temperature} </div> ); } - Run the following commands to start the component's application:
cd <project_name> # Install dependencies bnpm install # Start the application npm run startIn the component entry file index.tsx, from
The component preview canvas displays Current temperature is: 26. This confirms that the component successfully retrieved the property value fromthis.props, you use the unique identifier identifier to obtain the tempature property value and display it on the page:this.propstemperatureand rendered it to the page. In the Style panel on the right, you can configure coordinates, size, angle, component name, visibility, opacity, and the Temperature parameter.
Key concepts
When property settings include the options, visible, or linkage fields, and these fields are passed as a function, the following two terms apply:
- Configured value: The value of a property in its input field when no data source is configured. When using functions for
options,visible, orlinkage, this value is passed as thepropsparameter. - Runtime value: The value a property receives from a configured data source. When using functions for
options,visible, orlinkage, this value is passed as thepropValuesparameter.
To pass options, visible, or linkage as a function, use the following format:
function can be options, visible, or linkage.function({ props, propValues }) {
...
}
For details about the parameters that each function supports, see Property list.
Property list
The properties setting,"properties": [{"props1":"","props12":"",...},{},...], is an array of objects. Each object, {"props1":"","props12":"",...}, defines a single property. The following table lists the configurable fields for each property object.
| Parameter | Type | Required | Description |
| identifier | string | Yes | The property identifier. In the component, you can use this.props[identifier] to retrieve the configured value. |
| text | string | Yes | The property name, displayed in the property editor of the web-based visualization workbench. |
| description | string | No | The property description. It appears as a question mark icon. Hover over the icon to view the description. |
| type | string | Yes | The interface type identifier. Set type to one of the following values: bool, text, number, color, enum, image, group, or pureDataSource. For more information, see Property types. |
| options | object/function | No | Specifies the interface configuration, which is passed to the component corresponding to the type. If the value is a function, it receives two parameters:
|
| defaultValue | any | No | The property's default value. |
| mock | any | No | A mock value for the property, used when its actual value is empty. Unlike defaultValue, this value is not displayed in the interface configuration. |
| visible | boolean/function | No | Specifies whether to display the property. If the value is a
If the value is a function, it receives two parameters:
|
| linkage | function | No | Used for property linkage. Receives the following parameters:
The function must return one of the following value types:
|
| validate | function | No | Used for property validation. Receives two parameters:
|
| displayIdentifier | string | No | Specifies the identifier of another property that controls whether the current property is enabled. The current property's interface component also receives the value of the controlling property. |
| displayDefaultValue | boolean | No | Specifies whether to display the default value.
|
| displayLinkage | function | No | Used for property display linkage. Receives the following parameters:
The function must return one of the following value types:
|