VariableTextArea

VariableTextArea 用来输入多行文本和变量表达式。变量会保留 {{ ... }} 字面,适合邮件正文、消息模板等长文本。

如果只需要单行输入,默认用 VariableInput

基本用法

import React from 'react';
import { Application, Plugin, VariableTextArea } from '@nocobase/client-v2';
import { Form } from 'antd';

function DemoPage() {
  return (
    <Form layout="vertical" style={{ maxWidth: 520 }}>
      <Form.Item name="content" label="Content">
        <VariableTextArea rows={5} namespaces={['$user', '$env']} />
      </Form.Item>
    </Form>
  );
}

class DemoPlugin extends Plugin {
  async load() {
    this.flowEngine.context.defineProperty('$user', {
      value: { name: 'Alice', email: 'alice@example.com' },
      meta: {
        title: 'Current user',
        type: 'object',
        properties: {
          name: { title: 'Name', type: 'string' },
          email: { title: 'Email', type: 'string' },
        },
      },
    });

    this.flowEngine.context.defineProperty('$env', {
      value: { SMTP_HOST: 'smtp.example.com' },
      meta: {
        title: 'Environment variables',
        type: 'object',
        properties: {
          SMTP_HOST: { title: 'SMTP_HOST', type: 'string' },
        },
      },
    });

    this.router.add('root', {
      path: '/',
      element: <DemoPage />,
    });
  }
}

const app = new Application({
  router: { type: 'memory', initialEntries: ['/'] },
  plugins: [DemoPlugin],
});

export default app.getRootComponent();
import { VariableTextArea } from '@nocobase/client-v2';

<Form.Item name="content" label={t('Content')}>
  <VariableTextArea namespaces={['$env', '$user']} rows={10} />
</Form.Item>;

API

参数类型说明
valuestring当前值
onChange(value: string) => void值变化回调
disabledboolean是否禁用
placeholderstring占位文字
namespacesstring[]限定可选的顶层命名空间
extraNodesMetaTreeNode[]追加局部变量节点
delimiters[string, string]变量分隔符,默认 ['{{', '}}']
classNamestring自定义 class
styleReact.CSSProperties自定义样式
rowsnumber固定行数
maxRowsnumber最大行数

相关链接