首页 > 其他分享 >【Dash】feffery_antd_componenet 中的 AntdSpace

【Dash】feffery_antd_componenet 中的 AntdSpace

时间:2024-09-03 15:51:35浏览次数:6  
标签:feffery componenet space align Dash re AntdSpace fac size

一、feffery_antd_componenet 中的 AntdSpace

feffery_antd_components(简称fac)中的AntdSpace组件是一个基于Ant Design的Dash第三方组件,它用于在水平或垂直方向上放置多个元素,并提供元素之间的间距。以下是AntdSpace组件的一些主要功能:

1、设置间距:

可以通过size属性来设置元素之间的间距,支持预设的small、middle、large三种尺寸,也可以自定义间距。

2、对齐方式:

可以设置子元素的对齐方式,通过align属性,可以设置为start、end、center、baseline。

3、自动换行:

通过wrap属性,可以设置是否自动换行,仅在水平方向上有效。

4、分隔符:

可以使用split属性来设置分隔符,例如在链接之间添加垂直分隔线。

5、紧凑模式:

AntdSpace.Compact用于表单组件之间紧凑连接且合并边框,支持的组件包括Button、AutoComplete、Cascader、DatePicker、Input、InputNumber、Select、TimePicker等。

6、垂直方向:

AntdSpace组件默认是水平方向的,但也可以设置为垂直方向,通过direction属性设置为vertical。

7、自定义尺寸:

可以通过传递一个数字给size属性来自定义间距大小。

8、预设间距:

AntdSpace组件提供了预设的间距大小,也可以通过CSS来进一步自定义样式。

二、代码

import dash
from dash import html
import feffery_antd_components as fac
from dash.dependencies import Output, Input, State

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        fac.AntdSpace(
            [
                fac.AntdDivider('AntdSpace 的应用', innerTextOrientation='center'),
                fac.AntdSpace(
                    [
                        fac.AntdText(
                            '对齐方向: '
                        ),
                        fac.AntdRadioGroup(
                            id='space-align-input',
                            options=['start', 'end', 'center', 'baseline'],
                            value='start',
                        ),  # 单选按钮
                    ],
                    size='large',
                )
            ],
            direction='vertical',
            size='large',
            style={
                'width': '100%',
            },
        ),
        fac.AntdSpace(
            [
                fac.AntdText(
                    '间距大小: '
                ),
                fac.AntdRadioGroup(
                    id='space-size-input',
                    options=['small', 'middle', 'large', '48'],
                    value='small',  # 子容器改写默认值为 small
                ),
            ],
            size='large',   # AntdSpace设置size 默认值为 large
            style={
                'width': '100%',
            }
        ),
        fac.AntdSpace(
            fac.AntdButton('添加 addSplitLIne 分割线', id='space-add-split-line', type='primary'),
            style={
                'padding': '5px',
            }

        ),
        fac.AntdSpace(
            fac.AntdButton('添加自定义分割线', id='space-add-line', type='primary'),
            style={
                'padding': '5px',
            }
        ),
        fac.AntdParagraph(),
        fac.AntdSpace(
            fac.AntdButton('设置元素超宽后自动换行(wrap=True)', id='space-wrap', type='primary'),
            style={
                'padding': '5px'
            }
        ),
        fac.AntdSpace(
            [
                fac.AntdSpace(
                    [
                        fac.AntdButton(button_type, type=button_type, danger=danger)
                        for button_type, danger in [['primary', False], ['default', False], ['dashed', False], ['text', False], ['link', False]] * 5
                    ],
                    wrap=False,
                    addSplitLine=True,
                    id='space-button1',
                ),
                fac.AntdSpace(
                    [
                        fac.AntdButton(button_type, type=button_type, danger=danger)
                        for button_type, danger in [['primary', True], ['default', True], ['dashed', True], ['text', True], ['link', True]] * 5
                    ],
                    wrap=False,
                    addSplitLine=True,
                    id='space-button2',
                    # customSplit=html.Div(
                    #     style={'height': 30, 'borderRight': '1px dashed #8c8c8c'}
                    # )

                ),
            ],
            direction='vertical',
            # id='space-button',
        ),
        fac.AntdParagraph(),
        # 横向拓展
        fac.AntdSpace(
            [
                html.Div(
                    style={
                        'backgroundColor': 'rgba(255, 255, 207, 1)',
                        'height': '20px',
                        'width': '50px',
                    }
                ),
                html.Div(
                    style={
                        'backgroundColor': 'rgba(250, 240, 155, 1)',
                        'height': '40px',
                        'width': '50px',
                    }
                ),
                html.Div(
                    style={
                        'backgroundColor': 'rgba(244, 234, 98, 1)',
                        'height': '60px',
                        'width': '50px',
                    }
                ),
                html.Div(
                    style={
                        'backgroundColor': 'orange',
                        'height': '80px',
                        'width': '50px',
                    }
                )
            ] * 2,
            id='space-align-output1',
            align='start',  # 系统默认值也是 start
            size='large',
            style={
                'backgroundColor': 'rgba(241, 241, 241, 0.8)',
                'padding': '10px',
            },
            addSplitLine=True,
        ),
        # 纵向拓展
        fac.AntdDivider(),
        fac.AntdSpace(
            [
                html.Div(
                    style={
                        'backgroundColor': 'rgba(243, 230, 195, 1)',
                        'height': '50px',
                        'width': '20px',
                    }
                ),
                html.Div(
                    style={
                        'backgroundColor': 'rgba(217, 188, 154, 1)',
                        'height': '50px',
                        'width': '40px',
                    },
                ),
                html.Div(
                    style={
                        'backgroundColor': 'rgba(218, 158, 106, 1)',
                        'height': '50px',
                        'width': '60px',
                    }
                ),
            ],
            id='space-align-output2',
            align='start',  # 系统默认值也是 start
            direction='vertical',
            size='large',
            style={
                'backgroundColor': 'rgba(241, 241, 241, 0.8)',
                'padding': '12px',
            },
        ),
    ]
)


@app.callback(
    [Output('space-align-output1', 'align'),
     Output('space-align-output2', 'align'),
     Output('space-button1', 'size'),
     Output('space-button2', 'size'),
     Output('space-align-output1', 'size'),
     Output('space-align-output2', 'size'),
     Output('space-button1', 'addSplitLine'),
     Output('space-button2', 'addSplitLine'),
     Output('space-align-output1', 'addSplitLine'),
     Output('space-button1', 'customSplit'),
     Output('space-button2', 'customSplit'),
     Output('space-button1', 'wrap'),
     Output('space-button2', 'wrap'),
     ],
    [Input('space-align-input', 'value'),   # align 对齐方向
     Input('space-size-input', 'value'),    # size 间距大小
     Input('space-add-split-line', 'nClicks'),  # addSplitLine
     Input('space-add-line', 'nClicks'),
     Input('space-wrap', 'nClicks'),
     ]
)
def update_space(value_align, value_size, nclick_add_split_line, nclick_add_line, nclick_wrap):
    if value_align:
        re_align = value_align

    if value_size and value_size == '48':
        re_size = 48
    else:
        re_size = value_size

    if nclick_add_split_line and nclick_add_split_line % 2 == 1:
        re_app_split_line = True
    else:
        re_app_split_line = False

    if nclick_add_line and nclick_add_line % 2 == 1:
        re_add_line = html.Div(
            style={'height': 30, 'borderRight': '1px dashed #8c8c8c'}
        )
    else:
        re_add_line = None

    if nclick_wrap and nclick_wrap % 2 == 1:
        re_wrap = True
    else:
        re_wrap = False

    return [re_align, re_align,
            re_size, re_size, re_size, re_size,
            re_app_split_line, re_app_split_line, re_app_split_line,
            re_add_line, re_add_line,
            re_wrap, re_wrap]


if __name__ == '__main__':
    app.run_server(debug=True)

 

 

标签:feffery,componenet,space,align,Dash,re,AntdSpace,fac,size
From: https://blog.csdn.net/u010528690/article/details/141862907

相关文章

  • GDB dashboard
    GitHub上开源的Python调试工具:GDBdashboard,为PythonGDB提供了可视化界面,更清晰的显示了程序调试信息,使开发者能专注于Python控制流。GDB仪表板是一个使用PythonAPI编写的独立.gdbinit文件,它启用了一个模块化接口,显示正在调试的程序的相关信息。其主要目标是减少检查当......
  • lodash 之 _.isEmpty
    lodash.isEmpty()是Lodash库中的一个函数,用于检查给定值是否为空。它可以用于判断对象、数组、字符串等不同类型的值是否为空。const_=require('lodash');console.log(_.isEmpty(null));//输出:trueconsole.log(_.isEmpty(undefined));//输出:trueconsole.log......
  • 报表系统之Redash
    Redash是一个开源的数据可视化和仪表板工具,旨在帮助用户轻松地从多个数据源中提取、查询、可视化数据,并分享结果。它的设计目标是让数据分析变得更加便捷,即使是非技术用户也能通过简单的操作生成复杂的数据报告和仪表板。核心概念和功能查询编辑器:Redash提供了一个功能强......
  • Lodash 使用详解:提升 JavaScript 开发效率的利器
    引言在现代JavaScript开发中,处理数组、对象、字符串等数据类型的操作频繁且复杂。尽管JavaScript本身已经提供了一些内置方法,但它们有时不够直观,或者在处理复杂场景时显得笨拙。Lodash是一个功能丰富的JavaScript实用工具库,它提供了简洁、高效的API来处理这些常见......
  • 部署 K8s 图形化管理工具 Dashboard
    目录一、Dashboard概述二、GitHub地址三、Dashboard部署安装1、选择兼容版本2、下载配置文件3、添加Dashboard的Service类型4、应用部署5、查看kubernetes-dashboard命名空间下资源状态6、创建访问账户7、授权8、获取账号token9、1.24版本以后的需要创建一个Pod四、浏览器......
  • 登录 k8s-Dashboard 显示 Your connection is not private
    目录一、背景二、解决方案一、背景部署好kubernetes-Dashboard后使用master节点的ip+port登录Dashboard显示Yourconnectionisnotprivate无论是Edge还是GoogleChrome都是这样的情况二、解决方案点击网页空白处,英文输入法输入:thisisunsafe即可正常访问......
  • 如何优化 Vite 项目中的 Lodash 引入:从 Tree Shaking 到自动化测试
    文章目录前言问题背景解决方案概述思路1:使用Lodash-ES替代Lodash思路2:使用Babel插件babel-plugin-lodash思路3:大规模替换后的验证与测试Babel的工作流程回顾最终选择及实践经验自动化测试:使用Puppeteer验证替换后的代码结论前言在现......
  • apisix-dashboard上添加自定义插件
    参考:https://overstarry.vip/posts/apisix如何添加自定义插件/首先,我们需要向自定义的插件user-remote-auth添加到apisix中,对这块不清楚的同学,可以参考我这篇文章:【apisix~lua插件开发与插件注册】,添加成功之后,通过curlhttp://apisix-admin.apisix:9180/apisix/admin/plugins/us......
  • 测试人必会 K8S 操作之 Dashboard
    在云计算和微服务架构的时代,Kubernetes(K8S)已成为管理容器化应用的标准。然而,对于许多新手来说,K8S的操作和管理常常显得复杂而神秘。特别是,当你第一次接触 K8SDashboard 时,你是否也感到有些无所适从?K8SDashboard是Kubernetes提供的一种用户友好的图形界面工具......
  • 如何在回调中获取当前的dash ag-grid设置
    问题是,我有一个组数据,可以在破折号选项卡上展开。我想在离开选项卡时保持行/列状态、顺序、过滤器相同。我使用dcc.Store保存回调中的设置,然后在选项卡返回时将它们取回。然而,行状态、顺序、展开/折叠状态似乎在破折号网格中没有属性。具体来说,我想获取当前扩展节点并在刷新/......