定价

SidebarItem 使用手册

v1.7.0 · @snowui-design-system/components

许可阅读:首次阅读组件文档、源码或 npm 使用流程,先读完整 LICENSE;同任务同版本去重。公开 API 配置与内部实现修改分别按许可处理;全部组件使用统一运行包,源码权益以许可为准。

组件介绍

在 Sidebar 中呈现导航入口,支持激活状态、图标、层级与状态提示,帮助识别当前位置。

使用选择

用于 Sidebar 导航入口,提供稳定身份、图标、文本和目标地址。激活状态不等于自动完成业务路由。

  • 提供稳定 id 与 label;href 表示导航地址,onSelect 处理选择通知。

  • disabled 禁止导航;actions 配置条目附加操作,parts 配置内置徽标和操作按钮。

  • 内置updated圆点的名称随LocaleProvider更新;label、tags及actions仍属调用方内容。折叠态的装饰与可访问树结构保持原有契约。

快速开始

以下示例展示推荐的基本组合。更多场景与组合限制见后文。

<script lang="ts">	import { SidebarItem } from '@snowui-design-system/components';	let opened = $state('');</script> <div style="width: min(100%, 12rem);"><SidebarItem id="components" label="Components" icon="squares-four" iconCollection="phosphor" onSelect={() => opened = 'Components'} /></div>

API

关键字 类型 默认值 描述
id string 必填 稳定导航标识
label string 必填 文字与折叠态可访问名称
icon string | Snippet — ResourceIcon 名称或自定义 leading 内容
iconCollection string — icon 的 ResourceIcon collection;存在同名 SnowUI 图标时传入 "snowui"
depth 0 | 1 0 导航层级;1 表示二级 Item,由组件在 leading 槽绘制 L 形层级连接线并替换普通 Icon
href string — 存在时主操作渲染 Link,否则渲染 Button
updated boolean false 内置 Badge dot;展开态位于外部 tags 之后,折叠态跟随 leading icon
tags Snippet — label 后、updated 前的自定义状态/分类标签;推荐使用 Badge variant="border"
disabled boolean false 禁用主操作
actions SidebarActionData[] | Snippet [] 0~多个末尾操作;数组生成 Button bare
onSelect (id: string) => void — 本项选择回调
parts ComponentPartsOf<{ Badge: typeof Badge; Button: typeof Button }> — 配置内置 Badge 与数据生成的 Button

未重新声明的继承能力请查所属基础组件文档;本表只列本组件源码具名公开属性。

使用边界与详细说明

API 参考

主操作与标签/updated 之间的有效间距至少为 4 CSS px,缩小根字号或 gap scale 时仍保留;较大首选间距保持不变。长文字先缩略,Link 与 Button 都遵守可用宽度;末尾操作独立预留空间,不覆盖状态标签。leading 槽不小于内置图标既有的 12px 下限,默认 20px 与层级连接线对齐保持不变。

提供 href 时导航内容使用链接,否则使用按钮。附属 actions 与主导航操作独立;tags 显示在 label 与 updated 提示之间。折叠后保留图标,内置 Tooltip 提供完整标签。组件负责折叠过渡、标签布局与操作位置,页面只需提供数据和业务回调。

depth={1} 表示二级 Item。组件在既有 20px leading 槽内通过伪元素绘制等长双臂的 L 形点线:由密集的 1px Black/40% 点组成,弯曲圆角为 4px;默认视觉线长为 9px × 9px。竖线中心与同列一级 Item 的 Icon 中心对齐,横线中心与二级 Item 文字中心对齐。该图形只表达层级关系,没有独立交互或无障碍语义,不进入图标资源解析,也不随 IconProvider 切换。二级 Item 不同时显示普通 icon;调用方在 Sidebar 折叠时仍应隐藏二级 Item。


SidebarItem 样式覆盖

先阅读 完整 LICENSE;同任务、同版本、同范围去重。

优先用组件公开 Props 匹配合适样式,尽可能保留原有视觉。确需改写时按 样式选择与改写顺序 使用自己的 class(含项目已有 Tailwind)或实例 style。以下名称来自源码实际消费的公开 override;先核对目标作用域,不修改私有 DOM。采用 SnowUI Token 时选择正确类别,外部应用不被要求安装一方 utilities。

变量 用途与默认参考
--snowui-button-opacity-override 不透明度(默认值见组件源码)
--snowui-link-gap-override 内部内容与 leading / trailing 间距(首选 var(--gap-1),有效值至少 4 CSS px)
--snowui-sidebar-item-background-override hover / active 背景(默认 var(--black-4))
--snowui-sidebar-item-font-size-override 导航文字字号(默认 var(--text-14))
--snowui-sidebar-item-gap-override 导航项内部间距(首选 var(--gap-2),有效值至少 4 CSS px)
--snowui-sidebar-item-line-height-override 导航文字行高(默认 var(--leading-14))
--snowui-sidebar-item-padding-x-override 导航项横向 padding(默认 var(--padding-2))
--snowui-sidebar-item-padding-y-override 导航项纵向 padding(默认 var(--padding-2))
--snowui-sidebar-item-radius-override 导航项圆角(默认 var(--radius-3))

设计指南 · Token · 组合边界

SidebarItem 类型与状态

必填属性:id、label。

可双向绑定:本组件未声明具名双向绑定属性;状态更新通过公开回调或所属宿主处理。

继承声明:Omit<FrameProps, "children" | "id">。继承能力以基类公开文档为准;Omit 中的字段已排除,不能按基类原样使用。

共享 Frame API · 返回 API

以下为公开属性实际引用的类型声明,来自源码;Svelte Snippet 表示内容片段,ComponentProps 表示对应组件的 Props。

SidebarActionData

来源:components/src/blocks/sidebar-context.svelte.ts

export interface SidebarActionData {    id: string;    icon: string;    iconCollection?: string;    label: string;    disabled?: boolean;    onSelect?: (ownerId: string) => void;}

ComponentPartsOf

来源:components/src/logic/component-parts.svelte.ts

export type ComponentPartsOf<    T extends Record<string, Component<any>>,> = {    [K in keyof T]?: ConfigurableComponentPartProps<T[K]>;};

ConfigurableComponentPartProps

来源:components/src/logic/component-parts.svelte.ts

export type ConfigurableComponentPartProps<C extends Component<any>> = Partial<    Omit<ComponentProps<C>, ComponentPartControlledKey>>;

ComponentPartControlledKey

来源:components/src/logic/component-parts.svelte.ts

export type ComponentPartControlledKey =    | "children"    | "as"    | "value"    | "defaultValue"    | "open"    | "selected"    | "checked"    | "disabled"    | "readonly"    | "id"    | `on${string}`    | `aria-${string}`;