avatar
UI
Components
Changelog
LobeHub UI
Antd Components
Lucide Icons
CSSinJS
Ctrl
K
Chat
ChatInputArea
ChatItem
EditableMessage
Data Display
Card
ChatMarkdown
CollapseGroup
Descriptions
Highlighter
JsonViewer
LogViewer
ProCard
RichTextEditor
Status
Table
Tree
Data Entry
CodeEditor
Form
Mentions
MonacoEditor
SelectCard
SliderInput
Feedback
Alert
DragPanel
Drawer
Modal
Notification
General
Breadcrumb
Typography
WaveformIcon
Layout
Divider
Page
Navigation
ButtonGroup
Dropdown
Theme
ConfigProvider
Logo
TTS
useSpeechSynthes
Utils
FormHelper

Form

Based on antd form, add Form.CollapseList component.

import { Form } from '@yuntijs/ui';
NPM
UNPKG
BundlePhobia
PackagePhobia
Anvaka Graph
Source
Edit
Previous
CodeEditor
Next
Mentions

Resources

Lobe UI-AIGC Components
Lobe Icon-AI / LLM Icon Collection
Lobe Charts-Modern Charts
Lobe TTS-TTS / STT Library

Community

Report Bug
Request Feature

Help

GitHub
Changelog

More Products

🤯 Lobe Chat-AI / LLM Chat Framework
🧸 Lobe Vidol-Virtual Idols for EveryOne
🅰️ Lobe Theme-Stable Diffusion Extension
🌐 Lobe i18n-AI i18next CLI
Copyright © 2022-2026
Made with ☁️ by YuntiJS
LobeHub

Usage

Based on antd form, add Form.CollapseList component.

Form

see https://ant.design/components/form .

Form.CollapseList

Simple usage

TSX
import { Form, Input } from '@yuntijs/ui';
import { VariableIcon } from 'lucide-react';

const FormCollapseList = Form.CollapseList;
interface FieldType {
  outputs?: {
    key: string;
    value: string;
  }[];
}

export default () => {
  const outputs = [
    {
      key: 'class',
      value: 'claas1',
    },
    {
      key: 'namespace',
      value: 'ns1',
    },
  ];
  return (
    <Form
      onValuesChange={(_, values) => console.log('values =>', values)}
      style={{ width: '100%' }}
      variant="filled"
    >
      <FormCollapseList
        columns={[
          {
            label: '变量名',
            name: 'key',
            render: () => <Input maxLength={30} placeholder="输入变量名" showCount />,
          },
          {
            label: '变量值',
            name: 'value',
            render: () => <Input placeholder="输入变量值" style={{ width: 360 }} />,
            rules: [{ required: true, message: '请输入变量值' }],
          },
        ]}
        icon={VariableIcon}
        initialValue={outputs}
        name="outputs"
        title="输出变量"
        variant="block"
      />
    </Form>
  );
};

Tree input usage

支持树形展示和输入,当数据中有 children 字段时会自动展示为树形表格,如果不需要或配置为其他字段可以用 childrenColumnName 进行配置。在 column render 属性中返回了 operation,与 Form.List 的 operation 用法一致,可以用来添加、删除、排序叶子节点,另外在 operation 中增加了一个 update 方法,可用于手动更新视图。

可以通过设置 indentSize 以控制每一层的缩进宽度。

设置 defaultExpandAllRows 可控制初始时,是否展开所有行。

TSX
export const TreeList = () => {
  // 推荐使用 useMemo 来定义 columns,减少组件渲染次数,提升性能
  const columns: FormCollapseListColumn[] = useMemo(
    () => [
      // ...
      {
        render: (fieldName, index, operation, fieldPath) => {
          return (
            <Space size="small">
              <Button
                icon={<PlusOutlined />}
                // 添加叶子节点
                onClick={() => operation.add()}
                type="text"
              />
              <Button
                icon={<DeleteOutlined />}
                // 删除当前节点
                onClick={() => operation.remove(fieldName)}
                type="text"
              />
            </Space>
          );
        },
      },
    ],
    []
  );

  return <FormCollapseList columns={columns} />;
};

Playground

Form.CollapseList

APIs

Form

see https://ant.design/components/form#api

Form.CollapseList

NameDescriptionTypeDefault
Properties definition not found for FormCollapseList component
输出变量
变量名变量值testtest2
点击右上角 + 添加
Form value 值
json
{
  "outputs": [
    {
      "key": "class",
      "value": "claas1",
      "test": "test1"
    },
    {
      "key": "namespace",
      "value": "ns1",
      "test": "test2"
    }
  ]
}
输出变量
变量名变量值
点击右上角 + 添加
Form value 值
{
outputs: [
{
name: "class"
value: "claas1"
items: [
{
name: "c1"
value: "c1"
items: [
{
name: "c11"
value: "c11"
}
]
}
]
}
{
name: "namespace"
value: "ns1"
}
]
}
输出变量
变量名类型变量值
点击右上角 + 添加