-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathApp.tsx
More file actions
58 lines (54 loc) · 1.6 KB
/
Copy pathApp.tsx
File metadata and controls
58 lines (54 loc) · 1.6 KB
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
import { Flex, Radio } from 'antd';
import { useState } from 'react';
import { Composite } from './Composite';
import { ItemPreview } from './ItemPreview';
import { Playground } from './Playground';
import { Preview } from './Preview';
import { StreamPreview } from './StreamPreview';
export const App = () => {
const getInitialTab = () => {
const params = new URLSearchParams(window.location.search);
return params.get('tab') || 'composite';
};
const [tab, setTab] = useState(getInitialTab);
const handleTabChange = (value: string) => {
setTab(value);
const params = new URLSearchParams(window.location.search);
params.set('tab', value);
window.history.replaceState(
{},
'',
`${window.location.pathname}?${params}`,
);
};
return (
<Flex vertical style={{ height: '100%' }}>
<Radio.Group
options={[
{ label: '灵活组合', value: 'composite' },
{ label: '模版预览', value: 'preview' },
{ label: '数据项预览', value: 'item' },
{ label: '流式渲染', value: 'stream' },
{ label: '语法渲染', value: 'playground' },
]}
value={tab}
onChange={(e) => handleTabChange(e.target.value)}
block
optionType="button"
buttonStyle="solid"
style={{ padding: 16 }}
/>
{tab === 'composite' ? (
<Composite />
) : tab === 'preview' ? (
<Preview />
) : tab === 'stream' ? (
<StreamPreview />
) : tab === 'playground' ? (
<Playground />
) : (
<ItemPreview />
)}
</Flex>
);
};