Create event(创建日程)
日程卡片汇总当天三项活动,供用户确认加入日历或舍弃。
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",
"confirm": {
"label": "加入日历",
"$action": {
"type": "add_to_calendar"
}
},
"cancel": {
"label": "舍弃"
},
"children": [
{
"$type": "Row",
"$key": "date-header",
"gap": 3,
"align": "center",
"children": [
{
"$type": "Text",
"$key": "day",
"value": "24",
"size": "3xl",
"weight": "bold"
},
{
"$type": "Col",
"$key": "date-meta",
"gap": 0,
"children": [
{
"$type": "Text",
"$key": "month",
"value": "7 月",
"weight": "semibold"
},
{
"$type": "Caption",
"$key": "weekday",
"value": "星期五"
}
]
}
]
},
{
"$type": "Divider",
"$key": "divider"
},
{
"$type": "Col",
"$key": "events",
"gap": 3,
"children": [
{
"$type": "Row",
"$key": "event-1",
"align": "center",
"gap": 3,
"children": [
{
"$type": "Box",
"$key": "accent",
"width": 3,
"height": 32,
"radius": "full",
"background": "var(--primary)"
},
{
"$type": "Col",
"$key": "info",
"gap": 0,
"children": [
{
"$type": "Text",
"$key": "title",
"value": "设计评审",
"weight": "medium"
},
{
"$type": "Caption",
"$key": "time",
"value": "09:00 至 09:30"
}
]
},
{
"$type": "Spacer",
"$key": "spacer"
},
{
"$type": "Badge",
"$key": "tag",
"value": "工作",
"variant": "info"
}
]
},
{
"$type": "Row",
"$key": "event-2",
"align": "center",
"gap": 3,
"children": [
{
"$type": "Box",
"$key": "accent",
"width": 3,
"height": 32,
"radius": "full",
"background": "var(--chart-4)"
},
{
"$type": "Col",
"$key": "info",
"gap": 0,
"children": [
{
"$type": "Text",
"$key": "title",
"value": "与小周午餐",
"weight": "medium"
},
{
"$type": "Caption",
"$key": "time",
"value": "12:30 至 13:30"
}
]
},
{
"$type": "Spacer",
"$key": "spacer"
},
{
"$type": "Badge",
"$key": "tag",
"value": "个人",
"variant": "warning"
}
]
},
{
"$type": "Row",
"$key": "event-3",
"align": "center",
"gap": 3,
"children": [
{
"$type": "Box",
"$key": "accent",
"width": 3,
"height": 32,
"radius": "full",
"background": "var(--chart-2)"
},
{
"$type": "Col",
"$key": "info",
"gap": 0,
"children": [
{
"$type": "Text",
"$key": "title",
"value": "飞往东京",
"weight": "medium"
},
{
"$type": "Caption",
"$key": "time",
"value": "18:45"
}
]
},
{
"$type": "Spacer",
"$key": "spacer"
},
{
"$type": "Badge",
"$key": "tag",
"value": "出行",
"variant": "success"
}
]
}
]
}
]
}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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190