For AI agents: the complete documentation index is available at https://a3s-lab.github.io/UI/v0.4.0/llms.txt, the full documentation bundle is available at https://a3s-lab.github.io/UI/v0.4.0/llms-full.txt, and this page is available as Markdown at https://a3s-lab.github.io/UI/v0.4.0/templates.md.

模板

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 templates 或 Jinja templates。

使用宏

从复制的模板文件导入宏,然后传入该组件所需的参数。

Nunjucks
{% from "a3s-ui/select.njk" import select %}
{{ select(
  name="fruit",
  label="水果",
  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",
  label="水果",
  items=[
    { "value": "apple", "label": "Apple" },
    { "value": "banana", "label": "Banana" },
    { "value": "blueberry", "label": "Blueberry" }
  ]
) }}

宏参考

combobox()

参数类型默认值描述
idstring生成的唯一的组合框 ID。
selectedstring | array | objectNone / none初始选择的一个或多个值。对象可以包括 value 和 label。
namestringNone / none隐藏输入名称。
multiplebooleanfalse启用基于芯片的多重选择。
placeholderstringNone / none可见的输入占位符。
close_on_selectbooleanfalse在多模式下选择每个选项后关闭弹出窗口。
clearbooleanfalse在单选模式下显示清除按钮。
auto_highlightbooleanfalse过滤时突出显示第一个匹配选项。
format"value" | "object""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添加背景单击关闭行为。

context_menu()

参数类型默认值描述
triggerstring必填右键或键盘菜单触发表面的 HTML。
labelstring"Context menu"菜单的可访问名称。
idstring生成的唯一的上下文菜单 ID。
main_attrsobject{}.context-menu 根的额外属性。
trigger_attrsobject{}触发表面的额外属性。
menu_attrsobject{}菜单元素的额外属性。
参数类型默认值描述
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。
selectedstring | arrayNone / none初始选择的一个或多个值。
namestring从 id 生成隐藏输入名称。
itemsarrayNone / none可选的结构化项目数据。省略时使用调用者内容。
multiplebooleanfalse启用多项选择。
placeholderstringNone / none多种模式的占位符文本,无需选择。
close_on_selectbooleanfalse在多模式下选择每个选项后关闭弹出窗口。
format"value" | "object""value"隐藏输入序列化格式。
main_attrsobject{}.select 根的额外属性。
trigger_attrsobject{}触发按钮的额外属性。
popover_attrsobject{}弹出框元素的额外属性。
listbox_attrsobject{}列表框的额外属性。
input_attrsobject{}隐藏输入的额外属性。
labelstringNone / none独立触发器的稳定无障碍名称;触发器已关联外部标签时省略。
参数类型默认值描述
idstringNone / none可选侧边栏 ID。当存在多个侧边栏时使用一个。
labelstring"Sidebar navigation"导航地标标签。
openbooleantrue初始打开状态。
side"left" | "right""left"侧边栏所在的视口一侧。
headerstringNone / none侧边栏标题的 HTML。
footerstringNone / none侧边栏页脚的 HTML。
menuarrayNone / none可选的结构化菜单数据。省略时使用调用者内容。
main_attrsobject{}.sidebar 根的额外属性。
header_attrsobject{}标题的额外属性。
content_attrsobject{}可滚动内容部分的额外属性。
footer_attrsobject{}页脚的额外属性。

tabs()

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

toaster()

参数类型默认值描述
idstring"toaster"通知容器 ID。
toastsarray[]通知容器内初始渲染的通知对象。
attrsobject{}.toaster 容器的额外属性。

toast()

参数类型默认值描述
category"success" | "error" | "info" | "warning""success"通知类型,用于控制图标和 ARIA 角色。
titlestring""通知标题。
descriptionstring""通知说明。
durationnumber默认超时超时(以毫秒为单位)。使用 -1 使 toast 保持打开状态。
iconstring类别图标自定义图标 HTML。
actionobjectNone / none操作按钮/链接配置。支持label、onclick和href。
cancelobjectNone / none取消按钮/链接配置。支持label、onclick和href。
attrsobject{}.toast 元素的额外属性。