Confirm dialog(确认对话框)
紧凑的确认卡片提示删除不可撤销,并提供确认和取消两项操作。
loading
安装
bash
npm install @assistant-ui/generative-ui zod1
用法
将下方规格传给渲染器。提供 dispatch 可接收按钮或表单的动作载荷。演示只在本地显示操作反馈。
tsx
import { defaultGenerativeUILibrary, renderGenerativeUI } from "@assistant-ui/generative-ui/react";
renderGenerativeUI(spec, defaultGenerativeUILibrary, {
status: "done",
dispatch: (action) => {
// 将用户操作交给应用。
console.log(action);
},
});1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
规格
tsx
const spec = {
"$type": "Card",
"children": [
{
"$type": "Header",
"$key": "title",
"text": "删除这个文件?",
"size": "md"
},
{
"$type": "Text",
"$key": "question",
"value": "此操作无法撤销。确认继续吗?",
"size": "sm",
"color": "secondary"
},
{
"$type": "Row",
"$key": "actions",
"justify": "end",
"children": [
{
"$type": "Button",
"$key": "no",
"label": "取消",
"buttonStyle": "outline",
"$action": {
"type": "cancel_delete"
}
},
{
"$type": "Button",
"$key": "yes",
"label": "确认",
"buttonStyle": "primary",
"$action": {
"type": "confirm_delete"
}
}
]
}
]
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43