logoAnt Design X

设计研发组件X MarkdownX SDKX CardX Skill演示国内镜像
  • 介绍
  • A2UI v0.8
  • A2UI v0.9

A2UI v0.8

API

通用属性参考:通用属性

BoxProps

Box 组件作为容器,用于管理 Card 实例和命令分发。

属性说明类型默认值版本
children子元素React.ReactNode--
components自定义组件映射,组件名称必须以大写字母开头Record<string, React.ComponentType<any>>--
commandsA2UI 命令对象A2UICommand_v0_9 | XAgentCommand_v0_8--
onActionCard 内部组件触发 action 时的回调函数(payload: ActionPayload) => void--

CardProps

Card 组件用于渲染单个 Surface。

属性说明类型默认值版本
idSurface ID,对应命令中的 surfaceIdstring--

ActionPayload

action 事件的数据结构。

属性说明类型默认值版本
name事件名称string--
surfaceId触发该 action 的 surfaceIdstring--
context当前 surface 的完整 dataModel 快照Record<string, any>--

XAgentCommand_v0_8

v0.8 版本的命令类型,支持以下命令:

SurfaceUpdateCommand

更新 Surface 上的组件。

属性说明类型默认值版本
surfaceUpdate.surfaceIdSurface IDstring--
surfaceUpdate.components组件列表ComponentWrapper_v0_8[]--

ComponentWrapper_v0_8

v0.8 版本的组件包装结构。

typescript
interface ComponentWrapper_v0_8 {
id: string;
component: {
[componentType: string]: {
child?: string;
children?: string[] | ExplicitList;
[key: string]: any | PathValue | LiteralStringValue;
};
};
}

ExplicitList

typescript
interface ExplicitList {
explicitList: string[];
}

DataModelUpdateCommand

更新数据模型(v0.8 格式)。

属性说明类型默认值版本
dataModelUpdate.surfaceIdSurface IDstring--
dataModelUpdate.contents数据内容列表Array<{ key: string; valueMap: Array<{ key: string; valueString: string }> }>--

BeginRenderingCommand

开始渲染。

属性说明类型默认值版本
beginRendering.surfaceIdSurface IDstring--
beginRendering.root根组件 IDstring--

DeleteSurfaceCommand

删除 Surface。

属性说明类型默认值版本
deleteSurface.surfaceIdSurface IDstring--

PathValue

数据绑定路径对象。

typescript
interface PathValue {
path: string;
}

LiteralStringValue

字面字符串值对象(v0.8 特有)。

typescript
interface LiteralStringValue {
literalString: string;
}
基础

使用 XCard 实现 A2UI v0.8 协议的基础示例。演示了如何使用 XAgentCommand_v0_8 命令来创建咖啡预订场景的交互卡片。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
渐进式

使用 XCard 实现 A2UI v0.8 协议的渐进式加载示例。演示了如何分批次加载产品数据,并通过 surfaceUpdate 命令渐进式更新组件,实现流畅的加载动画效果。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
流式渲染

使用 XCard 实现 A2UI v0.8 协议的流式内容与实时更新示例。演示了 AI 推荐结果的流式展示、组件逐步加载动画和加载进度指示。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
嵌套交互

使用 XCard 实现 A2UI v0.8 协议的复杂交互与嵌套组件示例。演示了可展开的详情卡片、树形文件浏览器和手风琴折叠面板。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
多卡片同步

使用 XCard 实现 A2UI v0.8 协议的多卡片协同与状态同步示例。演示了购物车场景中多个 Surface 之间的数据共享、跨卡片通信和实时价格计算。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
筛选搜索

使用 XCard 实现 A2UI v0.8 协议的动态数据筛选与搜索示例。演示了如何使用 antd 组件实现实时搜索、多条件筛选和结果动态更新。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
表单验证

使用 XCard 实现 A2UI v0.8 协议的表单验证与错误处理示例。演示了如何使用 antd Form 组件实现实时验证、错误状态管理和多步骤表单流程。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code