diff --git a/app.py b/app.py index 21fc87c..f76a80e 100644 --- a/app.py +++ b/app.py @@ -9,12 +9,13 @@ @Software : PyCharm """ -from demo.demo import DEMO -from demo.overview import overview +import streamlit as st +import streamlit_antd_components as sac + from demo.callback import callback_usage +from demo.display_method import display_method +from demo.overview import overview from demo.session_state import session_usage -from demo.icon import icon -from demo.utils import * st.set_page_config(layout='wide', page_title='streamlit-antd-components') @@ -43,8 +44,7 @@ redesign = sac.Tag('Redesign', color='purple', bordered=False) # title st.subheader(f'Streamlit-antd-components') - # menu - menu = sac.menu( + method = sac.menu( items=[ sac.MenuItem('overview'), sac.MenuItem('icon', tag=new), @@ -100,26 +100,17 @@ sac.Tag(f'streamlit-antd-components=={sac.__VERSION__}', size='xs', color='blue')]) with st.container(): - if menu == 'overview': + if 'icon' not in st.session_state: + st.session_state['icon'] = 'Bootstrap' + + if method == 'icon': + method = st.session_state['icon'] + + if method == 'overview': overview() - elif menu == 'callback': + elif method == 'callback': callback_usage() - elif menu == 'session state': + elif method == 'session state': session_usage() - elif menu == 'icon': - icon() 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')], size='sm') - if tabs == 'Demo': - col = st.columns([2.2, 1]) - with col[-1].expander(f"{menu} params", True): - kw = com_.get('params')(key=menu) - with col[0]: - com_.get('main')(kw) - else: - com_.get('api')() + display_method(method) diff --git a/demo/demo/__init__.py b/demo/demo/__init__.py deleted file mode 100644 index a761b8b..0000000 --- a/demo/demo/__init__.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/8/9 17:06 -@Author : ji hao ran -@File : __init__.py.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from .buttons import BUTTONS_DEMO -from .tabs import TABS_DEMO -from .menu import MENU_DEMO -from .tree import TREE_DEMO -from .switch import SWITCH_DEMO -from .divider import DIVIDER_DEMO -from .cascader import CASCADER_DEMO -from .transfer import TRANSFER_DEMO -from .segmented import SEGMENTED_DEMO -from .alert import ALERT_DEMO -from .steps import STEPS_DEMO -from .checkbox import CHECKBOX_DEMO -from .rate import RATE_DEMO -from .result import RESULT_DEMO -from .tags import TAGS_DEMO -from .pagination import PAGINATION_DEMO -from .chip import CHIP_DEMO - -DEMO = { - **BUTTONS_DEMO, - **TABS_DEMO, - **SEGMENTED_DEMO, - **MENU_DEMO, - **TREE_DEMO, - **CASCADER_DEMO, - **TRANSFER_DEMO, - **SWITCH_DEMO, - **DIVIDER_DEMO, - **ALERT_DEMO, - **STEPS_DEMO, - **RATE_DEMO, - **CHECKBOX_DEMO, - **RESULT_DEMO, - **TAGS_DEMO, - **PAGINATION_DEMO, - **CHIP_DEMO -} diff --git a/demo/demo/alert.py b/demo/demo/alert.py deleted file mode 100644 index a4451d3..0000000 --- a/demo/demo/alert.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/7/11 16:37 -@Author : ji hao ran -@File : alert.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" - -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], 'description', key=key) - size = show_size(key=key) - radius = show_radius(key=key) - variant = show_variant(['light', 'filled', 'outline', 'transparent', 'quote', 'quote-light'], key=key) - color = show_color(options=('info', 'success', 'warning', 'error', *MartineColor, '#4682b4'), key=key) - banner = show_radio( - label='banner', - options=[True, False, [True, False], [False, True], "sac.Banner(direction='right',speed=150)"], - key=f'{key}') - icon = st.radio('icon', [True, False, 'house', "sac.BsIcon('house',size=50)"], horizontal=True, key=f'{key}-icon') - closable = st.checkbox('closable', True, key=f'{key}-close') - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - if kw.get('banner') == "sac.Banner(direction='right',speed=150)": - kw.update(banner=sac.Banner(direction='right', speed=150)) - if kw.get('icon') == "sac.BsIcon('house',size=50)": - kw.update(icon=sac.BsIcon('house', size=50)) - - with st.expander('demo', True): - show_space() - sac.alert(**kw) - show_space() - show_code(f''' - sac.alert({code_kw(kw, sac.alert).replace('Banner', 'sac.Banner').replace('BsIcon', 'sac.BsIcon')}) - ''', open=True) - - -def api(): - st.help(sac.alert) - st.help(sac.Banner) - - -ALERT_DEMO = { - 'alert': { - 'doc': 'Alert component for feedback.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/buttons.py b/demo/demo/buttons.py deleted file mode 100644 index 3b4459c..0000000 --- a/demo/demo/buttons.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/5/29 10:17 -@Author : ji hao ran -@File : buttons.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - index = show_index(c[0], [0, 1, None], key=key) - format_func = show_format_func(c[1], key=key) - with c[0]: - align = show_align(key=key) - with c[1]: - direction = show_direction(key=key) - size = show_size(key=key) - radius = show_radius(key=key) - gap = show_radio('gap', ['xs', 'sm', 'md', 'lg', 'xl', 0], index=1, key=key) - variant = show_variant(['filled', 'outline', 'dashed', 'text', 'link'], index=1, key=key) - color = show_color(key=key) - c = st.columns(2) - use_container_width = show_checkbox('use_container_width', c[0], key=key) - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - - with st.expander('demo', True): - show_space() - btn = sac.buttons([ - sac.ButtonsItem(label='button'), - sac.ButtonsItem(icon='apple'), - sac.ButtonsItem(label='google', icon='google', color='#25C3B0'), - sac.ButtonsItem(label='wechat', icon='wechat'), - sac.ButtonsItem(label='disabled', disabled=True), - sac.ButtonsItem(label='link', icon='share-fill', href='https://ant.design/components/button'), - ], **kw) - show_space() - st.write(f'The selected button {"index" if return_index else "label"} is: {btn}') - show_code(f''' - sac.buttons([ - sac.ButtonsItem(label='button'), - sac.ButtonsItem(icon='apple'), - sac.ButtonsItem(label='google', icon='google', color='#25C3B0'), - sac.ButtonsItem(label='wechat', icon='wechat'), - sac.ButtonsItem(label='disabled', disabled=True), - sac.ButtonsItem(label='link', icon='share-fill', href='https://ant.design/components/button'), - ], {code_kw(kw, sac.buttons)}) - ''', True) - - -def api(): - st.help(sac.buttons) - st.help(sac.ButtonsItem) - - -BUTTONS_DEMO = { - 'buttons': { - 'doc': 'A group of buttons component.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/cascader.py b/demo/demo/cascader.py deleted file mode 100644 index 6f469fd..0000000 --- a/demo/demo/cascader.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/6/13 11:17 -@Author : ji hao ran -@File : sascader.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - index = show_index(c[0], [None, 0, [1, 3, 6, 7]], 1, key=key) - format_func = show_format_func(c[1], key=key) - placeholder = st.text_input('placeholder', 'Please choose') - color = show_color(key=key) - c = st.columns(2) - multiple = show_checkbox('multiple', c[0], True, key=key) - disabled = show_checkbox('disabled', c[1], key=key) - search = c[0].checkbox('search', True) - clear = c[1].checkbox('clear', True) - strict = c[0].checkbox('strict') - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - with st.expander('demo', True): - show_space() - item = sac.cascader(items=[ - sac.CasItem('home', icon='house'), - sac.CasItem('app', icon='app', children=[ - sac.CasItem('store', icon='bag-check'), - sac.CasItem('brand', icon='award', children=[ - sac.CasItem('github', icon='github'), - sac.CasItem('google', icon='google'), - sac.CasItem('apple', icon='apple', children=[ - sac.CasItem('admin', icon='person-circle'), - sac.CasItem('guest', icon='person'), - sac.CasItem('twitter' * 5, icon='twitter'), - ]), - ]), - ]), - sac.CasItem('disabled', icon='send', disabled=True), - sac.CasItem('other1'), - sac.CasItem('other2'), - ], **kw) - show_space() - st.write(f'The selected cascader item {"index" if return_index else "label"} : {item}') - show_code(f''' - sac.cascader(items=[ - sac.CasItem('home', icon='house'), - sac.CasItem('app', icon='app', children=[ - sac.CasItem('store', icon='bag-check'), - sac.CasItem('brand', icon='award', children=[ - sac.CasItem('github', icon='github'), - sac.CasItem('google', icon='google'), - sac.CasItem('apple', icon='apple', children=[ - sac.CasItem('admin', icon='person-circle'), - sac.CasItem('guest', icon='person'), - sac.CasItem('twitter' * 5, icon='twitter'), - ]), - ]), - ]), - sac.CasItem('disabled', icon='send', disabled=True), - sac.CasItem('other1'), - sac.CasItem('other2') - ], {code_kw(kw, sac.cascader)}) - ''', False) - - -def api(): - st.help(sac.cascader) - st.help(sac.CasItem) - - -CASCADER_DEMO = { - 'cascader': { - 'doc': 'Cascade selection box.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/checkbox.py b/demo/demo/checkbox.py deleted file mode 100644 index 1624211..0000000 --- a/demo/demo/checkbox.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/7/26 15:12 -@Author : ji hao ran -@File : checkbox.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - index = show_index(c[0], [None, 0, [0, 1]], 2, key=key) - format_func = show_format_func(c[1], key=key) - align = show_align(key=key) - size = show_size(key=key, index=1) - radius = show_radius(index=1) - color = show_color(key=key) - check_all = show_radio('check_all', [False, True, 'Select all'], key=key) - c = st.columns(2) - disabled = show_checkbox('disabled', c[0], key=key) - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - with st.expander('demo', True): - show_space() - c = sac.checkbox( - items=[ - 'item1', - 'item2', - 'item3', - sac.CheckboxItem('item4', disabled=True) - ], - **kw - ) - show_space() - - st.write(f'The selected checkbox {"index" if return_index else "label"} is: {c}') - show_code(f''' - sac.checkbox( - items=[ - 'item1', - 'item2', - 'item3', - sac.CheckboxItem('item4', disabled=True) - ], - {code_kw(kw, sac.checkbox)} - ) - ''', True) - - -def api(): - st.help(sac.checkbox) - st.help(sac.CheckboxItem) - - -CHECKBOX_DEMO = { - 'checkbox': { - 'doc': 'A group of checkbox.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/chip.py b/demo/demo/chip.py deleted file mode 100644 index 88213da..0000000 --- a/demo/demo/chip.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/9/15 16:16 -@Author : ji hao ran -@File : chip.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - index = show_index(c[0], [0, [0, 2], None], 1, key=key) - format_func = show_format_func(c[1], key=key) - with c[0]: - align = show_align(key=key) - with c[1]: - direction = show_direction(key=key) - size = show_size(key=key) - radius = show_radius(key=key) - variant = show_variant(['outline', 'light', 'filled'], 2, key=key) - color = show_color(key=key) - c = st.columns(2) - multiple = show_checkbox('multiple', c[0], True, key=key) - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - with st.expander('demo', True): - show_space() - seg = sac.chip( - items=[ - sac.ChipItem(label='apple'), - sac.ChipItem(icon='google'), - sac.ChipItem(label='github', icon='github'), - sac.ChipItem(label='twitter', icon='twitter'), - sac.ChipItem(label='disabled', disabled=True), - ], **kw - ) - show_space() - st.write(f'The selected chip {"index" if return_index else "label"} is: {seg}') - show_code(f''' - sac.chip( - items=[ - sac.ChipItem(label='apple'), - sac.ChipItem(icon='google'), - sac.ChipItem(label='github', icon='github'), - sac.ChipItem(label='twitter', icon='twitter'), - sac.ChipItem(label='disabled', disabled=True), - ], {code_kw(kw, sac.chip)} - ) - ''', True) - - -def api(): - st.help(sac.segmented) - st.help(sac.SegmentedItem) - - -CHIP_DEMO = { - 'chip': { - 'doc': 'Pick one or multiple values with inline controls.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/divider.py b/demo/demo/divider.py deleted file mode 100644 index 5f7b57d..0000000 --- a/demo/demo/divider.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/6/13 11:11 -@Author : ji hao ran -@File : divider.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - label = show_label(key=key) - icon = show_radio('icon', [None, 'house', 'sac.BsIcon("house",size=20)'], index=1, key=key) - align = show_align(key=key) - size = show_size(index=0, key=key) - variant = show_variant(['solid', 'dashed', 'dotted'], key=key) - color = show_color(none_color='lightgray', index=2, key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - if kw.get('icon') == 'sac.BsIcon("house",size=20)': - kw.update(icon=sac.BsIcon("house", size=20)) - with st.expander('demo', True): - show_space() - sac.divider(**kw) - show_space() - show_code(f''' - sac.divider({code_kw(kw, sac.divider).replace('BsIcon', 'sac.BsIcon').replace(', color=None', '')}) - ''', True) - - -def api(): - st.help(sac.divider) - - -DIVIDER_DEMO = { - 'divider': { - 'doc': 'A divider line separates different content.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/menu.py b/demo/demo/menu.py deleted file mode 100644 index 6d5c5ad..0000000 --- a/demo/demo/menu.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/5/29 11:19 -@Author : ji hao ran -@File : menu.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - index = show_index(c[0], [0, 2], key=key) - format_func = show_format_func(c[1], key=key) - size = show_size(key=key) - variant = show_variant(['light', 'filled', 'subtle', 'left-bar', 'right-bar'], key=key) - color = show_color(key=key) - indent = show_radio('indent(px)', [5, 10, 24, 30], index=2, key=key) - c = st.columns(2) - height = show_radio('height', [None, 300], c[0], key=key) - open_index = show_radio('open_index', [None, [1, ]], c[1], key=key) - open_all = show_checkbox('open_all', c[0], value=True, key=key) - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - - with st.expander('demo', True): - c = st.columns(3) - with c[1]: - item = sac.menu([ - sac.MenuItem('home', icon='house-fill', - tag=[sac.Tag('Tag1', color='green'), sac.Tag('Tag2', color='red')]), - sac.MenuItem('products', icon='box-fill', children=[ - sac.MenuItem('apple', icon='apple'), - sac.MenuItem('other', icon='git', description='other items', children=[ - sac.MenuItem('google', icon='google', description='item description'), - sac.MenuItem('gitlab', icon='gitlab'), - sac.MenuItem('wechat', icon='wechat'), - ]), - ]), - sac.MenuItem('disabled', disabled=True), - sac.MenuItem(type='divider'), - sac.MenuItem('link', type='group', children=[ - sac.MenuItem('antd-menu', icon='heart-fill', href='https://ant.design/components/menu#menu'), - sac.MenuItem('bootstrap-icon', icon='bootstrap-fill', href='https://icons.getbootstrap.com/'), - ]), - ], **kw) - st.write(f'The selected menu item {"index" if return_index else "label"} : {item}') - show_code(f''' - sac.menu([ - sac.MenuItem('home', icon='house-fill', tag=[sac.Tag('Tag1', color='green'), sac.Tag('Tag2', 'red')]), - sac.MenuItem('products', icon='box-fill', children=[ - sac.MenuItem('apple', icon='apple'), - sac.MenuItem('other', icon='git', description='other items', children=[ - sac.MenuItem('google', icon='google', description='item description'), - sac.MenuItem('gitlab', icon='gitlab'), - sac.MenuItem('wechat', icon='wechat'), - ]), - ]), - sac.MenuItem('disabled', disabled=True), - sac.MenuItem(type='divider'), - sac.MenuItem('link', type='group', children=[ - sac.MenuItem('antd-menu', icon='heart-fill', href='https://ant.design/components/menu#menu'), - sac.MenuItem('bootstrap-icon', icon='bootstrap-fill', href='https://icons.getbootstrap.com/'), - ]), - ], {code_kw(kw, sac.menu)}) - ''') - - -def api(): - st.help(sac.menu) - st.help(sac.MenuItem) - - -MENU_DEMO = { - 'menu': { - 'doc': 'A versatile menu for navigation.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/pagination.py b/demo/demo/pagination.py deleted file mode 100644 index 12f1598..0000000 --- a/demo/demo/pagination.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/8/9 15:22 -@Author : ji hao ran -@File : pagination.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(3) - total = c[0].number_input('total', 0, 200, 100, 50) - index = show_index(c[1], [1, 2], key=key) - page_size = c[2].number_input('page_size', 5, 20, 10, 5) - align = st.radio('align', ["start", "center", "end"], 1, horizontal=True, key=key) - size = show_size(key=key) - radius = show_radius(key=key) - variant = show_variant(['light', 'filled', 'outline'], index=2, key=key) - color = show_color(key=key) - c = st.columns(2) - previous = show_radio('previous', [None, 'Previous'], c[0]) - next = show_radio('next', [None, 'Next'], c[1]) - disabled = show_checkbox('disabled', c[0], key=key) - jump = c[1].checkbox('jump', True) - simple = c[0].checkbox('simple') - show_total = c[1].checkbox('show_total', True) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - with st.expander('demo', True): - show_space() - r = sac.pagination(**kw) - show_space() - st.write(f'The selected pagination number is: {r}') - show_code(f''' - sac.pagination({code_kw(kw, sac.pagination)}) - ''', True) - - -def api(): - st.help(sac.pagination) - - -PAGINATION_DEMO = { - 'pagination': { - 'doc': 'A long list can be divided into several pages.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/rate.py b/demo/demo/rate.py deleted file mode 100644 index 5737717..0000000 --- a/demo/demo/rate.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/7/26 15:12 -@Author : ji hao ran -@File : rate.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - container = st.container() - c1 = st.columns([1, 1, 1.5]) - half = show_checkbox('half', c1[0], key=key) - with container: - c = st.columns(2) - value = c[0].number_input('value', min_value=.0, max_value=5.0, value=2.0, step=0.5 if half else 1.0) - count = c[1].number_input('count', 5, 100, 5, 5) - symbol = show_radio('symbol', [None, 'A', 'sac.BsIcon("bell-fill")'], key=key) - align = show_align(key=key) - size = show_size(key=key) - color = show_color(key=key) - return update_kw(locals(), ['c', 'c1', 'container', 'key']) - - -def main(kw): - if kw.get('symbol') == 'sac.BsIcon("bell-fill")': - kw.update(symbol=sac.BsIcon("bell-fill")) - with st.expander('demo', True): - show_space() - r = sac.rate(**kw) - show_space() - st.write(f'The rate value is: {r}') - show_code(f''' - sac.rate({code_kw(kw, sac.rate).replace('BsIcon', 'sac.BsIcon').replace('name=', '')}) - ''', True) - - -def api(): - st.help(sac.rate) - - -RATE_DEMO = { - 'rate': { - 'doc': 'Rate component.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/result.py b/demo/demo/result.py deleted file mode 100644 index 56828c5..0000000 --- a/demo/demo/result.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/7/27 14:56 -@Author : ji hao ran -@File : result.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], value='description', key=key) - status = show_radio('status', ['info', 'success', 'warning', 'error', 'empty', 403, 404, 500], key=key) - icon = show_radio('icon', [None, 'house', "sac.BsIcon('house',size=30)"], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - if kw.get('icon') == "sac.BsIcon('house',size=30)": - kw.update(icon=sac.BsIcon('house', size=30)) - with st.expander('demo', True): - show_space() - sac.result(**kw) - show_space() - show_code(f''' - sac.result({code_kw(kw, sac.result).replace('BsIcon', 'sac.BsIcon')}) - ''', open=True) - - -def api(): - st.help(sac.result) - - -RESULT_DEMO = { - 'result': { - 'doc': 'Used to feed back the results of a series of operational tasks.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/segmented.py b/demo/demo/segmented.py deleted file mode 100644 index a7db35d..0000000 --- a/demo/demo/segmented.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/7/11 16:22 -@Author : ji hao ran -@File : segmented.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - index = show_index(c[0], [0, 1], key=key) - format_func = show_format_func(c[1], key=key) - c = st.columns(2) - with c[0]: - align = show_align(key=key) - with c[1]: - direction = show_direction(key=key) - size = show_size(key=key) - radius = show_radius(key=key) - c = st.columns(2) - with c[0]: - color = show_color(key=key) - with c[1]: - bg_color = show_color(label='bg_color', none_color='--secondary-background-color', - options=(None, *MartineColor, 'transparent'), key=f'{key}-bg') - c = st.columns(2) - divider = show_checkbox('divider', c[0], True, key=key) - use_container_width = show_checkbox('use_container_width', c[1], key=key) - disabled = show_checkbox('disabled', c[0], key=key) - readonly = show_checkbox('readonly', c[1], key=key) - return_index = show_checkbox('return_index', c[0], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - with st.expander('demo', True): - show_space() - seg = sac.segmented( - items=[ - sac.SegmentedItem(label='apple'), - sac.SegmentedItem(icon='google'), - sac.SegmentedItem(label='github', icon='github'), - sac.SegmentedItem(label='link', icon='share-fill', href='https://mantine.dev/core/segmented-control/'), - sac.SegmentedItem(label='disabled', disabled=True), - ], **kw - ) - show_space() - st.write(f'The selected segmented {"index" if return_index else "label"} is: {seg}') - show_code(f''' - sac.segmented( - items=[ - sac.SegmentedItem(label='apple'), - sac.SegmentedItem(icon='google'), - sac.SegmentedItem(label='github', icon='github'), - sac.SegmentedItem(label='link', icon='share-fill', href='https://mantine.dev/core/segmented-control/'), - sac.SegmentedItem(label='disabled', disabled=True), - ], {code_kw(kw, sac.segmented)} - ) - ''', True) - - -def api(): - st.help(sac.segmented) - st.help(sac.SegmentedItem) - - -SEGMENTED_DEMO = { - 'segmented': { - 'doc': 'A linear set of two or more segments.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/steps.py b/demo/demo/steps.py deleted file mode 100644 index d3cb51f..0000000 --- a/demo/demo/steps.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/7/26 14:36 -@Author : ji hao ran -@File : steps.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - index = show_index(c[0], [0, 1], key=key) - format_func = show_format_func(c[1], key=key) - size = show_size(key=key) - variant = show_variant(['default', 'navigation'], key=key) - color = show_color(key=key) - placement = st.radio('placement', ["horizontal", "vertical"], help='title placement', horizontal=True) - direction = show_direction(key=key) - c = st.columns(2) - dot = c[0].checkbox('dot') - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - - with st.expander('demo', True): - show_space() - step = sac.steps( - items=[ - sac.StepsItem(title='step 1', subtitle='extra msg', description='description text'), - sac.StepsItem(title='step 2'), - sac.StepsItem(title='step 3'), - sac.StepsItem(title='step 4', disabled=True), - ], **kw - ) - show_space() - st.write(f'The selected steps {"index" if return_index else "label"} is: {step}') - show_code(f''' - sac.steps( - items=[ - sac.StepsItem(title='step 1', subtitle='extra msg', description='description text'), - sac.StepsItem(title='step 2'), - sac.StepsItem(title='step 3'), - sac.StepsItem(title='step 4', disabled=True), - ], {code_kw(kw, sac.steps)} - ) - ''', True) - - -def api(): - st.help(sac.steps) - st.help(sac.StepsItem) - - -STEPS_DEMO = { - 'steps': { - 'doc': 'A navigation bar that guides users through the steps of a task.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/switch.py b/demo/demo/switch.py deleted file mode 100644 index 28d1a30..0000000 --- a/demo/demo/switch.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/6/13 10:43 -@Author : ji hao ran -@File : switch.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - on_label = c[0].selectbox('on_label', [None, 'On', 'sac.BsIcon("sun")']) - off_label = c[1].selectbox('off_label', [None, 'Off', 'sac.BsIcon("moon")']) - c = st.columns(2) - with c[0]: - align = show_align(key=key) - with c[1]: - position = show_radio('position', ["right", "left"], key=key) - size = show_size(include_int=False, key=key) - radius = show_radius(index=3, key=key) - c = st.columns(2) - with c[0]: - on_color = show_color(label='on_color', key=f'{key}-on') - with c[1]: - off_color = show_color(label='off_color', none_color='--secondary-background-color', key=f'{key}-off') - value = show_checkbox('value', c[0], key=key) - disabled = show_checkbox('disabled', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - if kw.get('on_label') == 'sac.BsIcon("sun")': - kw.update(on_label=sac.BsIcon("sun")) - if kw.get('off_label') == 'sac.BsIcon("moon")': - kw.update(off_label=sac.BsIcon("moon")) - - with st.expander('demo', True): - show_space() - s = sac.switch(**kw) - show_space() - st.write(f'switch return value: {s}') - - show_code(f''' - sac.switch({code_kw(kw, sac.switch).replace('BsIcon', 'sac.BsIcon').replace('name=', '')}) - ''', True) - - -def api(): - st.help(sac.switch) - st.help(sac.BsIcon) - - -SWITCH_DEMO = { - 'switch': { - 'doc': 'Switching between two states or on-off state.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/tabs.py b/demo/demo/tabs.py deleted file mode 100644 index 5e1bf7b..0000000 --- a/demo/demo/tabs.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/5/29 11:04 -@Author : ji hao ran -@File : tabs.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns([1, 1.5, 1]) - index = show_index(c[0], [0, 1], key=key) - format_func = show_format_func(c[1], key=key) - height = c[2].selectbox('height(px)', [None, 150], help='available when position="right" or "left"') - align = show_align(key=key) - position = show_radio('position', ["top", "right", "bottom", "left"], key=key) - size = show_size(key=key) - variant = show_variant(['default', 'outline'], key=key) - color = show_color(key=key) - c = st.columns(2) - use_container_width = show_checkbox('use_container_width', c[0], key=key) - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - - with st.expander('demo', True): - show_space() - tab = sac.tabs([ - sac.TabsItem(label='apple', tag="10"), - sac.TabsItem(icon='google'), - sac.TabsItem(label='github', icon='github'), - sac.TabsItem(label='disabled', disabled=True), - ], **kw) - show_space() - st.write(f'The selected tabs {"index" if return_index else "label"} is: {tab}') - show_code(f''' - sac.tabs([ - sac.TabsItem(label='apple', tag="10"), - sac.TabsItem(icon='google'), - sac.TabsItem(label='github', icon='github'), - sac.TabsItem(label='disabled', disabled=True), - ], {code_kw(kw, sac.tabs)}) - ''', True) - - -def api(): - st.help(sac.tabs) - st.help(sac.TabsItem) - - -TABS_DEMO = { - 'tabs': { - 'doc': 'A tabs component.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/tags.py b/demo/demo/tags.py deleted file mode 100644 index 2f23b6e..0000000 --- a/demo/demo/tags.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/8/2 16:55 -@Author : ji hao ran -@File : tag.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" - -from ..utils import * - - -def params(key): - format_func = show_format_func(key=key) - align = show_align(key=key) - direction = show_direction(key=key) - size = show_size(key=key, index=1) - radius = show_radius(key=key) - color = show_color(options=(None, *AntColor.keys(), '#4682b4'), none_color='--text-color', martine=False, key=key) - return update_kw(locals(), ['key']) - - -def main(kw): - with st.expander('demo', True): - show_space() - sac.tags([ - sac.Tag(label='tag'), - sac.Tag(label='no border', bordered=False), - sac.Tag(label='closable', closable=True), - sac.Tag(label='link', icon='send', link='https://ant.design/components/tag'), - ], **kw) - show_space() - show_code(f''' - sac.tags([ - sac.Tag(label='tag'), - sac.Tag(label='no border', bordered=False), - sac.Tag(label='closable', closable=True), - sac.Tag(label='link', icon='send', link='https://ant.design/components/tag'), - ], {code_kw(kw, sac.tags)})''', open=True) - - -def api(): - st.help(sac.tags) - st.help(sac.Tag) - - -TAGS_DEMO = { - 'tags': { - 'doc': 'Tag for categorizing or markup.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/transfer.py b/demo/demo/transfer.py deleted file mode 100644 index f358672..0000000 --- a/demo/demo/transfer.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/7/10 13:57 -@Author : ji hao ran -@File : transfer.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - index = show_index(c[0], [[0, 1], None], key=key) - format_func = show_format_func(c[1], key=key) - titles = c[0].selectbox('titles', [None, ['source', 'target'], ['source'], ['', 'target']], 1) - reload = c[1].selectbox('reload', [True, False, 'reload data']) - align = show_align(key=key) - color = show_color(key=key) - c = st.columns(2) - width = show_radio('width', [None, 200], c[0], key=key) - height = show_radio('height', [None, 400], c[1], key=key) - search = c[0].checkbox('search', True) - pagination = c[1].checkbox('pagination', True) - oneway = c[0].checkbox('oneway') - disabled = show_checkbox('disabled', c[1], key=key) - use_container_width = show_checkbox('use_container_width', c[0], key=key) - return_index = show_checkbox('return_index', c[1], key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - with st.expander('demo', True): - t = sac.transfer(items=[f'item{i}' for i in range(30)], **kw) - st.write(f'The transfer target item {"index" if return_index else "label"} : {t}') - show_code(f''' - sac.transfer(items=[f'item{{i}}' for i in range(30)], {code_kw(kw, sac.transfer)}) - ''') - - -def api(): - st.help(sac.transfer) - - -TRANSFER_DEMO = { - 'transfer': { - 'doc': 'Double column transfer choice box.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/demo/tree.py b/demo/demo/tree.py deleted file mode 100644 index d74bf5a..0000000 --- a/demo/demo/tree.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2023/5/29 11:20 -@Author : ji hao ran -@File : tree.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" -from ..utils import * - - -def params(key): - c = st.columns(2) - label = show_label(c[0], key=key) - description = show_description(c[1], key=key) - index = show_index(c[0], [None, 0, [2], [0, 2]], index=1, key=key) - format_func = show_format_func(c[1], key=key) - align = show_align(key=key) - size = show_size(key=key) - color = show_color(key=key) - c = st.columns(2) - width = show_radio('width(px)', [None, 350], c[0], key=key) - height = show_radio('height(px)', [None, 300], c[1], key=key) - icon = show_radio('icon', [None, 'table'], c[0], index=1, key=key) - open_index = show_radio('open_index', [None, [1, 3]], c[1], key=key) - open_all = c[0].checkbox('open_all', True) - checkbox = c[1].checkbox('checkbox', True) - show_line = c[0].checkbox('show_line', True) - checkbox_strict = c[1].checkbox('checkbox_strict') - return_index = show_checkbox('return_index', key=key) - return update_kw(locals(), ['c', 'key']) - - -def main(kw): - return_index = kw.get('return_index') - - with st.expander('demo', True): - item1 = sac.tree(items=[ - sac.TreeItem('item1', tag=[sac.Tag('Tag', color='red'), sac.Tag('Tag2', color='cyan')]), - sac.TreeItem('item2', icon='apple', description='item description', children=[ - sac.TreeItem('tooltip', icon='github', tooltip='item tooltip'), - sac.TreeItem('item2-2', children=[ - sac.TreeItem('item2-2-1'), - sac.TreeItem('item2-2-2'), - sac.TreeItem('item2-2-3'), - ]), - ]), - sac.TreeItem('disabled', disabled=True), - sac.TreeItem('item3', children=[ - sac.TreeItem('item3-1'), - sac.TreeItem('item3-2'), - ]), - ], **kw) - st.write(f'The selected tree item {"index" if return_index else "label"} : {item1}') - show_code(f''' - sac.tree(items=[ - sac.TreeItem('item1', tag=[sac.Tag('Tag', color='red'), sac.Tag('Tag2', color='cyan')]), - sac.TreeItem('item2', icon='apple', description='item description', children=[ - sac.TreeItem('tooltip', icon='github', tooltip='item tooltip'), - sac.TreeItem('item2-2', children=[ - sac.TreeItem('item2-2-1'), - sac.TreeItem('item2-2-2'), - sac.TreeItem('item2-2-3'), - ]), - ]), - sac.TreeItem('disabled', disabled=True), - sac.TreeItem('item3', children=[ - sac.TreeItem('item3-1'), - sac.TreeItem('item3-2'), - ]), - ], {code_kw(kw, sac.tree)})''') - - -def api(): - st.help(sac.tree) - st.help(sac.TreeItem) - - -TREE_DEMO = { - 'tree': { - 'doc': 'A hierarchical list structure component.', - 'params': params, - 'main': main, - 'api': api - } -} diff --git a/demo/display_method.py b/demo/display_method.py new file mode 100644 index 0000000..316a4ad --- /dev/null +++ b/demo/display_method.py @@ -0,0 +1,162 @@ +import inspect +from typing import get_origin, Union, Literal + +import streamlit as st +import streamlit_antd_components as sac + +from demo.method_code import methods_code +import webcolors + +def get_args_dict(func): + sig = inspect.signature(func) + out = [] + for param in sig.parameters.values(): + default = param.default + name = param.name + + if name == 'color' and default is None: + default = st.get_option('theme.primaryColor') or 'red' + elif name == 'background_color' and default is None: + default = st.get_option('theme.backgroundColor') or 'white' + elif name == 'font' and default is None: + default = st.get_option('theme.font') or 'arial' + elif name == 'size' and default is None: + default = 'md' + + if (default is inspect.Parameter.empty or default is None) and param.annotation is str: + default = name + + if name == 'symbol': + default = None + + if func.__name__ == 'BsIcon' and name == 'name': + default = 'house' + if func.__name__ == 'AntIcon' and name == 'name': + default = 'HomeOutlined' + + out.append({'name': name, + 'annotation': param.annotation, + 'default': default}) + # print(out) + return out + + +def get_demo(method, params): + params_str = {f"{k}={v!r}" for k, v in params.items()} + params_str = ", ".join(params_str) + code = methods_code[method].format(params_str=params_str) + code = code.strip() + # with st.tabs(['demo', 'api']): + with st.expander('demo', True): + out = eval(code) + st.markdown(f"The selected {method} item is: {out}") + + with st.expander('code', True): + code = f"import streamlit_antd_components as sac\n{code}" + st.code(code, line_numbers=True) + + +def get_api(func): + doc = inspect.getsource(func) + st.code(doc) + + +def selectbox_color(label, options, index, c1): + with c1: + sac.menu([ + sac.MenuItem('', tag=[sac.Tag(color, color=color)]) for color in options + ], index=index) + + + +def get_hex(color_name): + if color_name.startswith('#'): + return color_name + try: + rgb_tuple = webcolors.name_to_rgb(color_name) + hex_value = "#{:02x}{:02x}{:02x}".format(*rgb_tuple) + return hex_value + except ValueError: + return f"Color '{color_name}' not found" + + + +def get_params(func): + if func.__name__ in ['BsIcon', 'AntIcon']: + icon = sac.chip(['Bootstrap', 'Ant'], index=0, label='icon', size='sm') + if icon != st.session_state['icon']: + st.session_state['icon'] = icon + st.rerun() + args = get_args_dict(func) + params = {} + c1_ = st.columns(2) + n = 0 + for args_ in args: + name = args_['name'] + annotation = args_['annotation'] + default = args_['default'] + # print(f"{name=}") + if n > 1: + n = 0 + c1_ = st.columns(2) + if get_origin(annotation) is Union: + annotation_args = annotation.__args__ + annotation_args_literal = [v for v in annotation_args if get_origin(v) is Literal] + if len(annotation_args_literal) == 0: + annotation = annotation_args[0] + else: + annotation = annotation_args_literal[0] + + if annotation is str: + params[name] = c1_[n].text_input(name, default) + elif annotation is int or annotation is float: + params[name] = c1_[n].number_input(name, value=default) + elif annotation is bool: + params[name] = c1_[n].checkbox(name, default) + elif get_origin(annotation) is Literal: + if default in annotation.__args__: + index = annotation.__args__.index(default) + else: + index = 0 + if 'color' in name: + params[name] = c1_[n].color_picker(name, get_hex(default)) + else: + params[name] = c1_[n].selectbox(name, annotation.__args__, index) + else: + continue + n += 1 + return params + + +def get_doc_str(func): + doc = func.__doc__ + doc_ = doc.split(':param')[0].strip() + st.markdown(doc_) + + +def display_method(method): + if method == 'Bootstrap': + method = 'BsIcon' + elif method == 'Ant': + method = 'AntIcon' + + if method not in methods_code.keys(): + raise ValueError(f'unsupported method {method}') + + st.subheader(method.title(), anchor=False) + + func = getattr(sac, method) + get_doc_str(func) + + tab = sac.tabs(['Demo', 'Api'], size='sm') + + if tab == 'Demo': + c0, c1 = st.columns([2.2, 1]) + with c1.expander(f"{method} params", True): + params = get_params(func) + with c0: + get_demo(method, params) + elif tab == 'Api': + get_api(func) + else: + raise ValueError(f'unsupported tab {tab}') diff --git a/demo/icon.py b/demo/icon.py deleted file mode 100644 index 4ac55a1..0000000 --- a/demo/icon.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python -# _*_coding:utf-8_*_ - -""" -@Time : 2024/1/10 14:42 -@Author : ji hao ran -@File : icon.py -@Project : StreamlitAntdComponentsDemo -@Software : PyCharm -""" - -from .utils import * - - -def icon(): - st.subheader('Icon', anchor=False) - st.write(''' - The default setting of the icon parameter is **string** to display Boostrap icons, - but it can also be set to class **AntIcon** and class **BsIcon** to display ant icons and more style settings. - ''') - - tabs = sac.tabs([sac.TabsItem('Demo', icon='easel'), sac.TabsItem('Api', icon='cursor')], size='sm') - if tabs == 'Demo': - c = st.columns([2.2, 1]) - with c[1].expander('params', True): - icon_ = sac.chip(['Bootstrap', 'Ant'], index=0, label='icon', size='sm') - name = st.text_input(f'{icon_} icon name', 'house' if icon_ == 'Bootstrap' else 'HomeOutlined') - size = show_radio('size', [None, 'xs', 'sm', 'md', 'lg', 'xl', 50], index=6, key='bs-icon') - color = show_color(none_color='--text-color', key='bs-icon') - kw = {k: v for k, v in dict(name=name, size=size, color=color).items() if v is not None} - with c[0].expander('demo', True): - show_space(2) - sac.buttons([ - sac.ButtonsItem(icon=sac.BsIcon(**kw) if icon_ == 'Bootstrap' else sac.AntIcon(**kw)), - ], align='center', variant='text', index=None) - show_space(2) - with c[0]: - show_code(f''' - sac.buttons([sac.ButtonsItem(icon=sac.{"Bs" if icon_ == 'Bootstrap' else 'Ant'}Icon({code_kw(kw, sac.BsIcon)}))], align='center', variant='text', index=None) - ''', True) - else: - st.help(sac.BsIcon) - st.help(sac.AntIcon) diff --git a/demo/method_code.py b/demo/method_code.py new file mode 100644 index 0000000..a1c89f2 --- /dev/null +++ b/demo/method_code.py @@ -0,0 +1,159 @@ +methods_code = dict( + alert=""" +sac.alert({params_str}) +""", + buttons=""" +sac.buttons([ + sac.ButtonsItem(label='button'), + sac.ButtonsItem(icon='apple'), + sac.ButtonsItem(label='google', icon='google', color='#25C3B0'), + sac.ButtonsItem(label='wechat', icon='wechat'), + sac.ButtonsItem(label='disabled', disabled=True), + sac.ButtonsItem(label='link', icon='share-fill', href='https://ant.design/components/button'), +], {params_str}) +""", + cascader=""" +sac.cascader(items=[ + sac.CasItem('home', icon='house'), + sac.CasItem('app', icon='app', children=[ + sac.CasItem('store', icon='bag-check'), + sac.CasItem('brand', icon='award', children=[ + sac.CasItem('github', icon='github'), + sac.CasItem('google', icon='google'), + sac.CasItem('apple', icon='apple', children=[ + sac.CasItem('admin', icon='person-circle'), + sac.CasItem('guest', icon='person'), + sac.CasItem('twitter' * 5, icon='twitter'), + ]), + ]), + ]), + sac.CasItem('disabled', icon='send', disabled=True), + sac.CasItem('other1'), + sac.CasItem('other2') + ], {params_str}) +""", + BsIcon=""" +sac.buttons([sac.ButtonsItem(icon=sac.BsIcon({params_str}))], align='center', variant='text', index=None) +""", + AntIcon=""" +sac.buttons([sac.ButtonsItem(icon=sac.AntIcon({params_str}))], align='center', variant='text', index=None) +""", + checkbox=""" +sac.checkbox( + items=[ + 'item1', + 'item2', + 'item3', + sac.CheckboxItem('item4', disabled=True) + ], + {params_str} +) +""", + chip=""" +sac.chip( + items=[ + sac.ChipItem(label='apple'), + sac.ChipItem(icon='google'), + sac.ChipItem(label='github', icon='github'), + sac.ChipItem(label='twitter', icon='twitter'), + sac.ChipItem(label='disabled', disabled=True), + ], {params_str} +) +""", + divider=""" +sac.divider({params_str}) +""", + menu=""" +sac.menu([ + sac.MenuItem('home', icon='house-fill', tag=[sac.Tag('Tag1', color='green'), sac.Tag('Tag2', 'red')]), + sac.MenuItem('products', icon='box-fill', children=[ + sac.MenuItem('apple', icon='apple'), + sac.MenuItem('other', icon='git', description='other items', children=[ + sac.MenuItem('google', icon='google', description='item description'), + sac.MenuItem('gitlab', icon='gitlab'), + sac.MenuItem('wechat', icon='wechat'), + ]), + ]), + sac.MenuItem('disabled', disabled=True), + sac.MenuItem(type='divider'), + sac.MenuItem('link', type='group', children=[ + sac.MenuItem('antd-menu', icon='heart-fill', href='https://ant.design/components/menu#menu'), + sac.MenuItem('bootstrap-icon', icon='bootstrap-fill', href='https://icons.getbootstrap.com/'), + ]), +], {params_str}) +""", + pagination=""" +sac.pagination({params_str}) +""", + rate=""" +sac.rate({params_str}) +""", + result=""" +sac.result({params_str}) +""", + segmented=""" +sac.segmented( + items=[ + sac.SegmentedItem(label='apple'), + sac.SegmentedItem(icon='google'), + sac.SegmentedItem(label='github', icon='github'), + sac.SegmentedItem(label='link', icon='share-fill', href='https://mantine.dev/core/segmented-control/'), + sac.SegmentedItem(label='disabled', disabled=True), + ], {params_str} +) +""", + steps=""" +sac.steps( + items=[ + sac.StepsItem(title='step 1', subtitle='extra msg', description='description text'), + sac.StepsItem(title='step 2'), + sac.StepsItem(title='step 3'), + sac.StepsItem(title='step 4', disabled=True), + ], {params_str} +) +""", + switch=""" +sac.switch({params_str}) +""", + # tabs=""" + # sac.tabs([ + # sac.TabsItem(label='apple', tag="10"), + # sac.TabsItem(icon='google'), + # sac.TabsItem(label='github', icon='github'), + # sac.TabsItem(label='disabled', disabled=True), + # ], {params_str}) + # """, + tabs=""" +sac.tabs( + ['apple', 'google','github','disabled'], + {params_str}) +""", + tags=""" +sac.tags([ + sac.Tag(label='tag'), + sac.Tag(label='no border', bordered=False), + sac.Tag(label='closable', closable=True), + sac.Tag(label='link', icon='send', link='https://ant.design/components/tag'), +], {params_str})""", + transfer=""" +sac.transfer(items=[f'item{{i}}' for i in range(30)], {params_str}) +""", + tree=""" +sac.tree(items=[ + sac.TreeItem('item1', tag=[sac.Tag('Tag', color='red'), sac.Tag('Tag2', color='cyan')]), + sac.TreeItem('item2', icon='apple', description='item description', children=[ + sac.TreeItem('tooltip', icon='github', tooltip='item tooltip'), + sac.TreeItem('item2-2', children=[ + sac.TreeItem('item2-2-1'), + sac.TreeItem('item2-2-2'), + sac.TreeItem('item2-2-3'), + ]), + ]), + sac.TreeItem('disabled', disabled=True), + sac.TreeItem('item3', children=[ + sac.TreeItem('item3-1'), + sac.TreeItem('item3-2'), + ]), +], {params_str}) +""" +) diff --git a/demo/utils.py b/demo/utils.py index f492d2a..6acd659 100644 --- a/demo/utils.py +++ b/demo/utils.py @@ -14,15 +14,7 @@ import inspect FORMAT = [None, 'title', 'upper', "lambda x:f'A_{x}'"] -LABEL = [ - None, - 'label', - '**label**', - '**label** Info' -] -MartineColor = ['dark', 'gray', 'red', 'pink', 'grape', 'violet', 'indigo', 'blue', 'cyan', 'teal', 'green', 'lime', - 'yellow', 'orange'] -MartineSize = ['xs', 'sm', 'md', 'lg', 'xl'] + AntColor = { 'magenta': '#c41d7f', 'red': '#cf1322', @@ -37,39 +29,9 @@ 'purple': '#531dab' } -size_help = 'support mantine size and int in px' -md_help = 'support str and markdown str' - - -def show_label(container=None, value='label', key=None): - if container is not None: - with container: - return st.text_input('label', value, key=f'{key}-label', help=md_help) - return st.text_input('label', value, key=f'{key}-label', help=md_help) - - -def show_description(container=None, value='', key=None): - if container is not None: - with container: - return st.text_input('description', value, key=f'{key}-desc', help=md_help) - return st.text_input('description', value, key=f'{key}-desc', help=md_help) - - -def show_index(container=None, option=None, index=0, key=None): - if container is not None: - with container: - return st.selectbox('index', option, index=index, key=f'{key}-index') - return st.selectbox('index', option, index=index, key=f'{key}-index') - -def show_format_func(container=None, key=None): - if container is not None: - with container: - return st.selectbox('format_func', FORMAT, 0, key=f'{key}-format', help='item label format') - return st.selectbox('format_func', FORMAT, 0, key=f'{key}-format', help='item label format') - -def show_color(index=0, label='color', options=(None, *MartineColor, '#4682b4', 'rgb(20,80,90)'), +def show_color(index=0, label='color', options=(None, '#4682b4', 'rgb(20,80,90)'), none_color='--primary-color', key=None, martine=True): colors = {'info': 'rgb(0, 66, 128)', 'success': 'rgb(23, 114, 51)', 'warning': 'rgb(146, 108, 5)', 'error': 'rgb(125, 53, 59)', 'transparent': 'lightgray', None: none_color} @@ -84,34 +46,6 @@ def show_color(index=0, label='color', options=(None, *MartineColor, '#4682b4', return None if btn == 'None' else btn -def show_size(index=2, include_int=True, key=None): - return st.radio('size', options=MartineSize + [25] if include_int else MartineSize, index=index, horizontal=True, - key=f'{key}-size', help=size_help) - - -def show_radius(index=2, key=None): - return st.radio('radius', MartineSize + [20, 2], index=index, horizontal=True, key=f'{key}-radius', help=size_help) - - -def show_variant(options, index=0, key=None): - return st.radio('variant', options, index=index, horizontal=True, key=f'{key}-variant') - - -def show_align(index=1, key=None): - return st.radio('align', ['start', 'center', 'end'], index=index, horizontal=True, key=f'{key}-align') - - -def show_direction(index=0, key=None): - return st.radio('direction', ["horizontal", "vertical"], index=index, horizontal=True, key=f'{key}-direction') - - -def show_checkbox(label, container=None, value=False, key=None): - if container is not None: - with container: - return st.checkbox(label, value=value, key=f'{key}-{label}') - return st.checkbox(label, value=value, key=f'{key}-{label}') - - def show_radio(label=None, options=None, container=None, index=0, key=None): if container is not None: with container: diff --git a/requirements.txt b/requirements.txt index 051c0b8..487b138 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ streamlit==1.29.0 streamlit-antd-components==0.3.2 +webcolors \ No newline at end of file diff --git a/run_app.py b/run_app.py new file mode 100644 index 0000000..5198a15 --- /dev/null +++ b/run_app.py @@ -0,0 +1,30 @@ +"""Main module.""" +import os + +import fire +from streamlit import config as _config +from streamlit.web.bootstrap import run + + +def run_app(app_name: str = 'app'): + """robyn app.""" + print('run app') + print(vars()) + + _config.set_option("server.headless", True) + + app_name_ = f"{app_name}.py" + app_name_ = str(app_name_) + if not os.path.exists(app_name_): + raise FileNotFoundError(f"File {app_name_} not found") + run(app_name_, [], args=[], flag_options=[]) + + +def main(): + """Execute main program.""" + fire.Fire(run_app) + print('\x1b[6;30;42m', 'Success!', '\x1b[0m') + + +if __name__ == "__main__": + main()