For AI agents: the complete documentation index is available at https://a3s-lab.github.io/UI/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/UI/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/UI/templates.md.
  • 简体中文
  • next
  • 模板

    A3S UI 为具有较大 HTML 结构的组件提供了可选的 Nunjucks 和 Jinja 宏。它们生成组件文档中显示的相同语义 A3S UI 标记,同时使重复的服务器渲染标记更易于维护。

    这些模板使用 @a3s-lab/ui 进行版本控制,因此生成的标记与您安装的 CSS 和 JavaScript 文件相匹配。

    某些宏文件包含内部递归助手,例如 render_select_items()。这些助手是实现细节,不属于公共 API 的一部分。

    用途

    安装模板

    @a3s-lab/ui 复制模板引擎的模板文件夹。模板应归应用程序所有,因此您可以在复制后对其进行编辑。

    Nunjucks
    cp -R node_modules/@a3s-lab/ui/templates/nunjucks ./templates/a3s-ui
    Jinja
    cp -R node_modules/@a3s-lab/ui/templates/jinja ./templates/a3s-ui

    如果您不需要完整的模板文件夹,则仅复制您使用的文件。

    也可以直接从 GitHub 复制 Nunjucks templatesJinja templates

    使用宏

    从复制的模板文件导入宏,然后使用该组件的 props 调用它。

    Nunjucks
    {% from "a3s-ui/select.njk" import select %}
    {{ select(
      name="fruit",
      items=[
        { value: "apple", label: "Apple" },
        { value: "banana", label: "Banana" },
        { value: "blueberry", label: "Blueberry" }
      ]
    ) }}
    Jinja
    {% from "a3s-ui/select.html.jinja" import select %}
    {{ select(
      name="fruit",
      items=[
        { "value": "apple", "label": "Apple" },
        { "value": "banana", "label": "Banana" },
        { "value": "blueberry", "label": "Blueberry" }
      ]
    ) }}

    宏参考

    combobox()

    道具类型默认描述
    idstring生成的唯一的组合框 ID。
    selected`字符串\数组\对象`
    namestringNone / none隐藏输入名称。
    multiplebooleanfalse启用基于芯片的多重选择。
    placeholderstringNone / none可见的输入占位符。
    close_on_selectbooleanfalse在多模式下选择每个选项后关闭弹出窗口。
    clearbooleanfalse在单选模式下显示清除按钮。
    auto_highlightbooleanfalse过滤时突出显示第一个匹配选项。
    format`“值”\“对象”`"value"
    main_attrsobject{}.combobox 根的额外属性。
    input_attrsobject{}可见输入或芯片输入包装器的额外属性。
    popover_attrsobject{}弹出框元素的额外属性。
    listbox_attrsobject{}列表框的额外属性。
    hidden_input_attrsobject{}隐藏输入的额外属性。

    command()

    道具类型默认描述
    idstring生成的唯一的命令 ID。
    itemsarrayNone / none可选的结构化项目数据。省略时使用调用者内容。
    placeholderstring"Type a command or search..."搜索输入占位符。
    empty_textstring"No results found."空状态文本。
    main_attrsobject{}.command 根的额外属性。
    input_attrsobject{}搜索输入的额外属性。
    menu_attrsobject{}命令菜单的额外属性。

    command_dialog()

    道具类型默认描述
    idstring生成的唯一的命令对话框 ID。
    itemsarrayNone / none可选的结构化项目数据。省略时使用调用者内容。
    placeholderstring"Type a command or search..."搜索输入占位符。
    empty_textstring"No results found."空状态文本。
    dialog_attrsobject{}原生对话框的额外属性。
    input_attrsobject{}搜索输入的额外属性。
    menu_attrsobject{}命令菜单的额外属性。
    openbooleanfalse默认情况下呈现打开的对话框。

    dialog()

    道具类型默认描述
    idstring生成的唯一的对话框 ID。
    triggerstringNone / none生成的触发按钮的文本或 HTML。
    titlestringNone / none对话框标题。
    descriptionstringNone / none对话框描述。
    footerstringNone / none对话框页脚的 HTML。
    dialog_attrsobject{}原生对话框的额外属性。
    trigger_attrsobject{}生成的触发按钮的额外属性。
    header_attrsobject{}对话框标题的额外属性。
    body_attrsobject{}对话框主体部分的额外属性。
    footer_attrsobject{}对话框页脚的额外属性。
    openbooleanfalse默认情况下呈现打开的对话框。
    close_buttonbooleantrue包括生成的关闭按钮。
    close_on_overlay_clickbooleantrue添加背景单击关闭行为。
    道具类型默认描述
    triggerstring必填触发按钮的 HTML。
    idstring生成的唯一的下拉菜单 ID。
    itemsarrayNone / none可选的结构化菜单项数据。省略时使用调用者内容。
    main_attrsobject{}.dropdown-menu 根的额外属性。
    trigger_attrsobject{}触发按钮的额外属性。
    popover_attrsobject{}弹出框元素的额外属性。
    menu_attrsobject{}菜单元素的额外属性。

    popover()

    道具类型默认描述
    triggerstring必填触发按钮的 HTML。
    idstring生成的唯一的弹出窗口 ID。
    main_attrsobject{}.popover 根的额外属性。
    trigger_attrsobject{}触发按钮的额外属性。
    popover_attrsobject{}弹出框元素的额外属性。

    select()

    道具类型默认描述
    idstring生成的唯一的选择 ID。
    selected`字符串\数组`None / none
    namestringid 生成隐藏输入名称。
    itemsarrayNone / none可选的结构化项目数据。省略时使用调用者内容。
    multiplebooleanfalse启用多项选择。
    placeholderstringNone / none多种模式的占位符文本,无需选择。
    close_on_selectbooleanfalse在多模式下选择每个选项后关闭弹出窗口。
    format`“值”\“对象”`"value"
    main_attrsobject{}.select 根的额外属性。
    trigger_attrsobject{}触发按钮的额外属性。
    popover_attrsobject{}弹出框元素的额外属性。
    listbox_attrsobject{}列表框的额外属性。
    input_attrsobject{}隐藏输入的额外属性。
    道具类型默认描述
    idstringNone / none可选侧边栏 ID。当存在多个侧边栏时使用一个。
    labelstring"Sidebar navigation"导航地标标签。
    openbooleantrue初始打开状态。
    side`“左”\“对”`"left"
    headerstringNone / none侧边栏标题的 HTML。
    footerstringNone / none侧边栏页脚的 HTML。
    menuarrayNone / none可选的结构化菜单数据。省略时使用调用者内容。
    main_attrsobject{}.sidebar 根的额外属性。
    header_attrsobject{}标题的额外属性。
    content_attrsobject{}可滚动内容部分的额外属性。
    footer_attrsobject{}页脚的额外属性。

    tabs()

    道具类型默认描述
    idstring生成的唯一的选项卡 ID。
    tabsetsarray[]选项卡定义。每个项目可包括 tabpaneltab_attrspanel_attrs
    main_attrsobject{}.tabs 根的额外属性。
    tablist_attrsobject{}选项卡列表的额外属性。此处使用 aria-orientation="vertical"data-variant="line"
    default_tab_indexnumber1最初选择的选项卡的基于一的索引。

    toaster()

    道具类型默认描述
    idstring"toaster"烤面包机容器 ID。
    toastsarray[]烤面包机内渲染的初始烤面包对象。
    attrsobject{}.toaster 容器的额外属性。

    toast()

    道具类型默认描述
    category`“成功”\“错误”\“信息”\
    titlestring""Toast标题。
    descriptionstring""Toast描述。
    durationnumber默认超时超时(以毫秒为单位)。使用 -1 使 toast 保持打开状态。
    iconstring类别图标自定义图标 HTML。
    actionobjectNone / none操作按钮/链接配置。支持labelonclickhref
    cancelobjectNone / none取消按钮/链接配置。支持labelonclickhref
    attrsobject{}.toast 元素的额外属性。