Draft email(邮件草稿)
邮件表单显示发件人,并收集收件人、主题和正文。发送按钮提交填写的数据。
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",
"title": "新邮件",
"children": {
"$type": "Form",
"$action": {
"type": "send_email"
},
"children": [
{
"$type": "Row",
"$key": "from-row",
"align": "center",
"children": [
{
"$type": "Caption",
"$key": "from-label",
"value": "发件人"
},
{
"$type": "Text",
"$key": "from-value",
"value": "[email protected]",
"size": "sm"
}
]
},
{
"$type": "Row",
"$key": "to-row",
"align": "center",
"children": [
{
"$type": "Caption",
"$key": "to-label",
"value": "收件人"
},
{
"$type": "Input",
"$key": "to-input",
"name": "to",
"placeholder": "[email protected]"
}
]
},
{
"$type": "Input",
"$key": "subject",
"name": "subject",
"label": "主题",
"placeholder": "主题"
},
{
"$type": "Input",
"$key": "body",
"name": "body",
"label": "正文",
"multiline": true,
"placeholder": "输入邮件内容…"
},
{
"$type": "Row",
"$key": "actions",
"justify": "end",
"children": [
{
"$type": "Button",
"$key": "discard",
"label": "舍弃",
"buttonStyle": "ghost",
"$action": {
"type": "discard_email"
}
},
{
"$type": "Button",
"$key": "send",
"label": "发送邮件",
"buttonStyle": "primary",
"submit": true
}
]
}
]
}
}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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86