-
素材库
-
角色立绘
- 主角·常服.png
- 主角·礼服.png
- 背景音乐
- 未授权素材(禁用)
-
-
剧本(默认折叠)
- 第一章.txt
- 第二章.txt
<ul class="icen-tree"> <li> <div class="icen-tree-node" style="--depth:0"> <button class="icen-tree-toggle" type="button" aria-expanded="true" aria-label="折叠/展开"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M5.5 7.75 10 12.25l4.5-4.5"></path></svg></button> <span class="icen-tree-label">素材库</span> </div> <ul> <li> <div class="icen-tree-node" style="--depth:1"> <button class="icen-tree-toggle" type="button" aria-expanded="true" aria-label="折叠/展开"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M5.5 7.75 10 12.25l4.5-4.5"></path></svg></button> <span class="icen-tree-label">角色立绘</span> </div> <ul> <li><div class="icen-tree-node is-selected" style="--depth:2"><span class="icen-tree-toggle" aria-hidden="true"></span><span class="icen-tree-label">主角·常服.png</span></div></li> <li><div class="icen-tree-node" style="--depth:2"><span class="icen-tree-toggle" aria-hidden="true"></span><span class="icen-tree-label">主角·礼服.png</span></div></li> </ul> </li> <li><div class="icen-tree-node" style="--depth:1"><span class="icen-tree-toggle" aria-hidden="true"></span><span class="icen-tree-label">背景音乐</span></div></li> <li><div class="icen-tree-node is-disabled" style="--depth:1"><span class="icen-tree-toggle" aria-hidden="true"></span><span class="icen-tree-label">未授权素材(禁用)</span></div></li> </ul> </li> <li> <div class="icen-tree-node" style="--depth:0"> <button class="icen-tree-toggle is-collapsed" type="button" aria-expanded="false" aria-label="折叠/展开"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M5.5 7.75 10 12.25l4.5-4.5"></path></svg></button> <span class="icen-tree-label">剧本(默认折叠)</span> </div> <ul hidden> <li><div class="icen-tree-node" style="--depth:1"><span class="icen-tree-toggle" aria-hidden="true"></span><span class="icen-tree-label">第一章.txt</span></div></li> <li><div class="icen-tree-node" style="--depth:1"><span class="icen-tree-toggle" aria-hidden="true"></span><span class="icen-tree-label">第二章.txt</span></div></li> </ul> </li></ul>
特性
- 结构:
icen-tree-node节点,多层可折叠 + 叶子单选 - 状态:
is-disabled/aria-disabled禁用节点 - 配套:行为在
behaviors/tree
接口
- 初始化
initTree()(kit 一行入口可直接命名导入)- 导出
-
initTree - 事件
-
icen:tree-selecticen:tree-toggledetail 契约见IcenEventMap - 类型
dist/behaviors/tree.d.mts(随 npm 包发布,含全部 JSDoc 约束)
安装
bun add @icen.ai/ui pnpm add @icen.ai/ui npm install @icen.ai/ui yarn add @icen.ai/ui 一行引入该组件(CSS 与 behavior 自动带上,无需关心内部 CSS 文件名):
import { initTree } from '@icen.ai/ui/kit/tree';initTree();
也可以用脚手架直接打印引入行:
bunx --bun @icen.ai/ui add tree
Astro 项目注意:kit 入口里的 CSS import 在页面 <script> 里会被 Astro 的 client bundle 摇掉——请改在布局 frontmatter 里引 CSS(import '@icen.ai/ui/components/content.css';),JS 行为仍可走 kit。Vite SPA / webpack 项目无此问题。
用法
import { initTree } from '@icen.ai/ui/behaviors/tree';initTree();// toggle 折叠/展开子 ul;点击叶子节点单选(.is-selected)