Define properties

更新时间:
复制 MD 格式

This topic describes how to define properties for a component.

Example

  1. Define the properties in the component's specs.js file:
    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.

  2. Develop the render method in the index.tsx entry file:
    render(): JSX.Element {
        const { temperature } = this.props;
        return (
            <div>
                Current temperature is: {temperature}
            </div>
        );
    }
  3. Run the following commands to start the component's application:
    cd <project_name>
    # Install dependencies
    bnpm install
    # Start the application
    npm run start

    In the component entry file index.tsx, from this.props, you use the unique identifier identifier to obtain the tempature property value and display it on the page:

    The component preview canvas displays Current temperature is: 26. This confirms that the component successfully retrieved the property value from this.propstemperature and 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, or linkage, this value is passed as the props parameter.
  • Runtime value: The value a property receives from a configured data source. When using functions for options, visible, or linkage, this value is passed as the propValues parameter.

To pass options, visible, or linkage as a function, use the following format:

Note Here, 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:

  • props: The property's configured value.
  • propValues: The property's runtime value.
The function must return an object.
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 boolean:

  • true: Displays the property.
  • false: Hides the property.

If the value is a function, it receives two parameters:

  • props: The property's configured value.
  • propValuestruefalse: The property's runtime value.
The function must returnor.
linkage function No Used for property linkage. Receives the following parameters:
  • changedProps: The property that changed.
  • props: The configured value of all properties after the change.
  • propValues: The runtime value of all properties after the change.
  • prevProps: The configured value of all properties before the change.
  • prevPropValues: The runtime value of all properties before the change.

The function must return one of the following value types:

  • null: Clears the current property's value.
  • undefined: Keeps the current property's value unchanged.
  • Any other value: Sets the property to the new value.
validate function No Used for property validation. Receives two parameters:
  • props
  • propValues
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.
  • true: Displays the value.
  • false: Hides the value.
displayLinkage function No Used for property display linkage. Receives the following parameters:
  • changedProps: The property that changed.
  • props: The component's configured value.
  • propValues: The component's runtime value.
  • prevProps: The configured value of all properties before the change.
  • prevPropValues: The runtime value of all properties before the change.

The function must return one of the following value types:

  • null: Clears the current property's value.
  • undefined: Keeps the current property's value unchanged.
  • Any other value: Sets the property to the new value.