forked from nicedouble/StreamlitAntdComponentsDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
114 lines (107 loc) · 3.47 KB
/
app.py
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
#!/usr/bin/env python
# _*_coding:utf-8_*_
"""
@Time : 2023/5/26 22:14
@Author : ji hao ran
@File : app.py
@Project : StreamlitAntdComponents
@Software : PyCharm
"""
from demo.demo import DEMO
from demo.overview import overview
from demo.callback import callback_usage
from demo.session_state import session_usage
from demo.utils import *
st.set_page_config(layout='wide', page_title='streamlit-antd-components')
st.markdown(f'''
<style>
.stApp .main .block-container{{
padding-top:30px
}}
.stApp [data-testid='stSidebar']>div:nth-child(1)>div:nth-child(2){{
padding-top:50px
}}
iframe{{
display:block;
}}
</style>
''', unsafe_allow_html=True)
if 'index' not in st.session_state:
st.session_state['index'] = 0
with st.sidebar.container():
# tag
modified = sac.Tag('Modified', color='blue', bordered=False)
new = sac.Tag('New', color='green', bordered=False)
deprecated = sac.Tag('Deprecated', color='orange', bordered=False)
redesign = sac.Tag('Redesign', color='purple', bordered=False)
# title
st.subheader(f'Streamlit-antd-components')
# menu
menu = sac.menu(
items=[
sac.MenuItem('overview'),
sac.MenuItem('general', type='group', children=[sac.MenuItem('buttons')]),
sac.MenuItem('layout', type='group', children=[sac.MenuItem('divider', tag=redesign)]),
sac.MenuItem(
label='navigation', type='group', children=[
sac.MenuItem('menu'),
sac.MenuItem('pagination'),
'steps'
]
),
sac.MenuItem(
label='data entry', type='group',
children=[
sac.MenuItem('cascader'),
sac.MenuItem('checkbox'),
sac.MenuItem('chip'),
'rate', 'switch',
sac.MenuItem('transfer', tag=modified)
]
),
sac.MenuItem(
label='data display', type='group',
children=[
sac.MenuItem('segmented'),
'tabs',
sac.MenuItem('tree'),
sac.MenuItem('tags'),
],
),
sac.MenuItem(
label='feedback', type='group', children=[
sac.MenuItem('alert'),
sac.MenuItem('result')
]
),
sac.MenuItem(type='divider'),
sac.MenuItem('session state usage'),
sac.MenuItem('callback usage'),
],
index=st.session_state['index'],
open_all=True,
size='small',
format_func='title',
)
with st.container():
if menu == 'overview':
overview()
elif menu == 'callback usage':
callback_usage()
elif menu == 'session state usage':
session_usage()
else:
com_ = DEMO.get(menu)
# component introduce
st.subheader(menu.title(), anchor=False)
st.write(com_.get('doc'))
# component demo and api
tabs = sac.tabs([sac.TabsItem('Demo', icon='easel'), sac.TabsItem('Api', icon='cursor')], align='start')
if tabs == 'Demo':
col = st.columns([3, 1])
with col[-1].expander(f"{menu} params", True):
kw = com_.get('params')()
with col[0]:
com_.get('main')(kw)
else:
com_.get('api')()