EnvVariableInput

EnvVariableInput は、$env 環境変数だけを選択できるようにするためのコンポーネントです。

基本的な使い方

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

function DemoPage() {
  return (
    <Form
      layout="vertical"
      style={{ maxWidth: 420 }}
      initialValues={{ accessKeySecret: '{{ $env.ACCESS_KEY_SECRET }}' }}
    >
      <Form.Item name="accessKeySecret" label="Access Key Secret">
        <EnvVariableInput
          password
          placeholder="Input secret or select env variable"
        />
      </Form.Item>
    </Form>
  );
}

class DemoPlugin extends Plugin {
  async load() {
    this.flowEngine.context.defineProperty('$env', {
      value: { ACCESS_KEY_SECRET: 'secret' },
      meta: {
        title: 'Environment variables',
        type: 'object',
        properties: {
          ACCESS_KEY_SECRET: { title: 'ACCESS_KEY_SECRET', type: 'string' },
        },
      },
    });

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

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

export default app.getRootComponent();

API

パラメータ説明
valuestring現在の値
onChange(value: string) => void値変更時のコールバック
addonBeforeReact.ReactNode入力欄の前に表示する内容
disabledboolean無効化するかどうか
passwordboolean変数ではない通常値をマスクする
placeholderstringプレースホルダー文字列

関連リンク