Riverside Loft(河畔阁楼)
住宿卡片组合房源照片、位置、入住人数和评分。预订按钮用动作载荷传递房源标识。
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": "Image",
"$key": "image",
"src": "https://images.unsplash.com/photo-1522708323590-d24dbb6b0267?w=640&q=80",
"alt": "带开放式厨房和红色扶手椅的阁楼内景"
},
{
"$type": "Row",
"$key": "meta",
"justify": "between",
"align": "center",
"children": [
{
"$type": "Caption",
"$key": "details",
"value": "阿尔法玛 · 2 位房客 · 1 张床"
},
{
"$type": "Badge",
"$key": "rating",
"value": "4.9",
"variant": "success"
}
]
},
{
"$type": "Button",
"$key": "book",
"label": "预订,每晚 142 美元",
"buttonStyle": "primary",
"block": true,
"$action": {
"type": "book_stay",
"stayId": "riverside-loft"
}
}
]
}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
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