@snowui-design-system/components 0.2.0-alpha.7 → 0.2.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +27 -22
  2. package/component-catalog.json +1066 -0
  3. package/package.json +12 -4
  4. package/src/assets/gradient-avatar/blue.svg +1 -0
  5. package/src/assets/gradient-avatar/cyan.svg +1 -0
  6. package/src/assets/gradient-avatar/green.svg +1 -0
  7. package/src/assets/gradient-avatar/orange.svg +1 -0
  8. package/src/assets/gradient-avatar/purple.svg +1 -0
  9. package/src/assets/gradient-avatar/red.svg +1 -0
  10. package/src/components/Accordion.md +1 -1
  11. package/src/components/Accordion.svelte +5 -1
  12. package/src/components/Avatar.md +95 -58
  13. package/src/components/Avatar.svelte +286 -92
  14. package/src/components/Avatar.test.ts +24 -3
  15. package/src/components/Badge.md +31 -2
  16. package/src/components/Badge.svelte +38 -3
  17. package/src/components/Badge.test.ts +14 -1
  18. package/src/components/Button.md +42 -19
  19. package/src/components/Button.svelte +56 -50
  20. package/src/components/Button.test.ts +38 -27
  21. package/src/components/Card.test.ts +1 -1
  22. package/src/components/CodeBlock.md +50 -14
  23. package/src/components/CodeBlock.svelte +213 -34
  24. package/src/components/CodeBlock.test.ts +43 -2
  25. package/src/components/ColorSchemeButton.md +50 -0
  26. package/src/components/ColorSchemeButton.svelte +144 -0
  27. package/src/components/ColorSchemeButton.test.ts +39 -0
  28. package/src/components/CopyButton.md +5 -1
  29. package/src/components/CopyButton.svelte +6 -2
  30. package/src/components/Dialog.svelte +1 -0
  31. package/src/components/Dialog.test.ts +2 -2
  32. package/src/components/ExpandButton.md +5 -1
  33. package/src/components/ExpandButton.svelte +1 -0
  34. package/src/components/Form.test.ts +4 -4
  35. package/src/components/Gradient.md +278 -0
  36. package/src/components/Gradient.svelte +1283 -0
  37. package/src/components/Gradient.test.ts +77 -0
  38. package/src/components/Icon.svelte +3 -1
  39. package/src/components/Image.svelte +11 -8
  40. package/src/components/Image.test.ts +1 -1
  41. package/src/components/Indicator.md +18 -4
  42. package/src/components/Indicator.svelte +151 -11
  43. package/src/components/Indicator.test.ts +25 -0
  44. package/src/components/Input.md +15 -5
  45. package/src/components/Input.svelte +10 -1
  46. package/src/components/Input.test.ts +2 -2
  47. package/src/components/Listbox.md +5 -0
  48. package/src/components/Listbox.svelte +26 -0
  49. package/src/components/Listbox.test.ts +14 -0
  50. package/src/components/MenuItem.md +5 -0
  51. package/src/components/MenuItem.svelte +6 -0
  52. package/src/components/OverflowAction.md +41 -0
  53. package/src/components/OverflowAction.svelte +209 -0
  54. package/src/components/OverflowAction.test.ts +11 -0
  55. package/src/components/OverflowActions.md +95 -0
  56. package/src/components/OverflowActions.svelte +501 -0
  57. package/src/components/OverflowActions.test.ts +87 -0
  58. package/src/components/Pagination.md +2 -2
  59. package/src/components/Pagination.svelte +2 -2
  60. package/src/components/Pagination.test.ts +2 -2
  61. package/src/components/Popover.md +5 -0
  62. package/src/components/Popover.svelte +25 -0
  63. package/src/components/Popover.test.ts +14 -0
  64. package/src/components/ScrollArea.md +7 -3
  65. package/src/components/ScrollArea.test.ts +3 -2
  66. package/src/components/SearchInput.md +14 -1
  67. package/src/components/SearchInput.svelte +104 -2
  68. package/src/components/SearchInput.test.ts +16 -1
  69. package/src/components/SelectButton.md +1 -1
  70. package/src/components/SelectButton.svelte +8 -2
  71. package/src/components/Skeleton.md +13 -1
  72. package/src/components/Skeleton.svelte +30 -2
  73. package/src/components/Slider.md +68 -6
  74. package/src/components/Slider.svelte +329 -21
  75. package/src/components/Slider.test.ts +65 -0
  76. package/src/components/SnowUILogo.md +210 -0
  77. package/src/components/SnowUILogo.svelte +478 -0
  78. package/src/components/SnowUILogo.test.ts +62 -0
  79. package/src/components/StyleButton.md +58 -0
  80. package/src/components/StyleButton.svelte +144 -0
  81. package/src/components/StyleButton.test.ts +39 -0
  82. package/src/components/Table.md +23 -7
  83. package/src/components/Table.svelte +22 -1
  84. package/src/components/TableBody.md +12 -1
  85. package/src/components/TableBody.svelte +26 -2
  86. package/src/components/TableBody.test.ts +3 -0
  87. package/src/components/TableCell.md +9 -3
  88. package/src/components/TableCell.svelte +139 -78
  89. package/src/components/TableCell.test.ts +4 -4
  90. package/src/components/TableHead.md +9 -3
  91. package/src/components/TableHead.svelte +56 -43
  92. package/src/components/TableHead.test.ts +5 -5
  93. package/src/components/TableRow.md +15 -5
  94. package/src/components/TableRow.svelte +47 -10
  95. package/src/components/TableRow.test.ts +2 -2
  96. package/src/components/TableToolbar.svelte +20 -8
  97. package/src/components/Text.md +7 -1
  98. package/src/components/Text.svelte +17 -7
  99. package/src/components/Tooltip.md +37 -9
  100. package/src/components/Tooltip.svelte +145 -35
  101. package/src/components/Tooltip.test.ts +54 -4
  102. package/src/i18n/messages.ts +12 -0
  103. package/src/index.ts +24 -0
  104. package/src/internal/StyleButtonLogo.svelte +49 -0
  105. package/src/lib/color.md +2 -2
  106. package/src/lib/edge-fade.md +1 -0
  107. package/src/lib/overlay-scrollbar.md +6 -1
  108. package/src/lib/table-context.svelte.ts +36 -0
  109. package/src/lib/table-role-blur.ts +46 -0
  110. package/src/lib/table-truncation.md +14 -0
  111. package/src/lib/table-truncation.ts +83 -0
  112. package/src/lib/tooltip-delay.md +7 -1
  113. package/src/lib/tooltip-motion-dismiss.md +33 -0
  114. package/src/lib/tooltip-motion-dismiss.ts +160 -0
  115. package/src/lib/tooltip-overlay.md +21 -3
  116. package/src/lib/tooltip-overlay.ts +13 -2
  117. package/src/logic/README.md +4 -1
  118. package/src/logic/continuous-hover.svelte.md +22 -0
  119. package/src/logic/continuous-hover.svelte.ts +436 -0
  120. package/src/logic/frame-inline-style.svelte.ts +2 -2
  121. package/src/logic/frame-truncation.md +9 -3
  122. package/src/logic/frame-truncation.svelte.ts +6 -0
  123. package/src/logic/layout-flip.ts +182 -5
  124. package/src/logic/overflow-actions.svelte.ts +33 -0
  125. package/src/motion/presets/README.md +6 -2
  126. package/src/motion/presets/continuous-hover.md +11 -0
  127. package/src/motion/presets/continuous-hover.ts +18 -0
  128. package/src/motion/presets/tooltip.md +40 -2
  129. package/src/motion/presets/tooltip.ts +0 -2
  130. package/src/motion/tokens.md +9 -4
  131. package/src/motion/tokens.ts +4 -1
  132. package/src/styles/README.md +16 -2
  133. package/src/styles/auto-layout.css +10 -1
  134. package/src/styles/components.css +920 -0
  135. package/src/styles/index.css +3 -1
  136. package/src/styles/layout.css +44 -0
  137. package/src/styles/scrollbar.css +27 -7
  138. package/src/styles/themes.css +146 -0
  139. package/src/styles/tokens.css +33 -33
@@ -49,6 +49,8 @@
49
49
  type ComponentPartsOf,
50
50
  useComponentPart,
51
51
  } from "../logic/component-parts.svelte";
52
+ import { ContinuousHoverController } from "../logic/continuous-hover.svelte";
53
+ import { CONTINUOUS_HOVER_MOTION_STYLE } from "../motion/presets/continuous-hover";
52
54
 
53
55
  export interface ListboxItem {
54
56
  value: string;
@@ -82,6 +84,8 @@
82
84
  align?: "start" | "end";
83
85
  /** 是否为选中项预留并显示勾选图标。 */
84
86
  showCheck?: boolean;
87
+ /** 选项间是否使用容器级连续 hover 背景。 */
88
+ continuousHover?: boolean;
85
89
  [key: string]: any;
86
90
  }
87
91
 
@@ -101,6 +105,7 @@
101
105
  placementMode = "selected",
102
106
  align = "start",
103
107
  showCheck = false,
108
+ continuousHover = true,
104
109
  enableAutoLayout = true,
105
110
  enableResponsive = false,
106
111
  enableContext = true,
@@ -157,6 +162,20 @@
157
162
  let listboxEl = $state<HTMLDivElement | undefined>(undefined);
158
163
  let scrollListboxEl = $state<HTMLElement | undefined>(undefined);
159
164
  let scrollbarEl = $state<HTMLDivElement | undefined>(undefined);
165
+ const continuousHoverController = new ContinuousHoverController();
166
+
167
+ $effect(() => {
168
+ if (!scrollListboxEl) return;
169
+ return continuousHoverController.attach(scrollListboxEl, {
170
+ selector: ":scope > .snowui-menu-item",
171
+ layerClass: "snowui-listbox-continuous-hover-layer",
172
+ axis: "y",
173
+ enabled: continuousHover,
174
+ followActive: true,
175
+ });
176
+ });
177
+
178
+ $effect(() => continuousHoverController.setEnabled(continuousHover));
160
179
 
161
180
  // ── 自定义浮层滚动条(通用 hook,内部使用 resizeManager) ──────────────
162
181
  const sb = useOverlayScrollbar(
@@ -423,6 +442,7 @@
423
442
  tag="div"
424
443
  column
425
444
  class={`snowui-listbox snowui-overlay-scrollbar-viewport${userClass ? ` ${userClass}` : ""}`}
445
+ style={CONTINUOUS_HOVER_MOTION_STYLE}
426
446
  id={owner?.listboxId}
427
447
  role="listbox"
428
448
  tabindex={-1}
@@ -530,9 +550,15 @@
530
550
  min-height: 0;
531
551
  }
532
552
  :global(:where(.snowui-listbox > [data-as="item"])) {
553
+ position: relative;
554
+ z-index: 1;
533
555
  width: 100%;
534
556
  white-space: nowrap;
535
557
  }
558
+ :global(:where(.snowui-listbox-continuous-hover-layer)) {
559
+ border-radius: var(--snowui-menu-item-radius-override, var(--radius-3, 0.75rem));
560
+ background: var(--black-4, #0000000a);
561
+ }
536
562
  /* 组件只声明轨道定位;视觉样式由 scrollbar.css 的 .snowui-overlay-scrollbar 承接。 */
537
563
  :global(:where(.snowui-listbox-scrollbar)) {
538
564
  top: 0;
@@ -179,4 +179,18 @@ export const examples = [
179
179
  },
180
180
  logic: ["BuiltInMode", "Parts", "Search", "MaxHeight", "Scroll"],
181
181
  },
182
+ {
183
+ name: "B14:连续 Hover 与关闭开关",
184
+ code: `B14
185
+ <Listbox items={[{ value: "one", label: "One" }, { value: "two", label: "Two" }]} />
186
+ <Listbox continuousHover={false} items={[{ value: "one", label: "One" }, { value: "two", label: "Two" }]} />`,
187
+ expected: {
188
+ render: "默认实例生成一个共享背景层,关闭实例使用 MenuItem 原有背景。",
189
+ layout: "背景匹配直接 MenuItem 的宽高和圆角。",
190
+ interaction: "指针跨过项间隙时背景连续移动;disabled / filtered 项被跳过。",
191
+ performance: "容器级 rAF 与共享 ResizeObserver。",
192
+ responsive: "滚动和尺寸变化时重新测量。",
193
+ },
194
+ logic: ["ContinuousHover", "OptOut"],
195
+ },
182
196
  ] as const;
@@ -196,3 +196,8 @@ MenuItem 的根布局固定按 Leading / Label / Trailing 三段组织:
196
196
  - 统一 `MenuItem` 与 `QuickActionItem` 为单一 `MenuItem` 组件
197
197
  - 自动感知 `ListboxOwnerContext`:有 context 时注册并派生状态,无 context 时使用 Props
198
198
  - Listbox 与 QuickAction 场景统一使用 8px padding
199
+ ## 连续 Hover 宿主
200
+
201
+ MenuItem 在支持连续 hover 的 Listbox / Popover 中由宿主的唯一背景层表达 hover。
202
+ 独立使用或宿主 `continuousHover={false}` 时仍使用自身即时背景。独立 `active`
203
+ 背景保持持久,hover 到 active 项时与宿主背景叠加并加深。
@@ -296,6 +296,9 @@
296
296
  :global(:where(.snowui-menu-item:hover)) {
297
297
  background-color: var(--black-4, #0000000a);
298
298
  }
299
+ :global(:where([data-continuous-hover-enabled="true"] > .snowui-menu-item:hover)) {
300
+ background-color: transparent;
301
+ }
299
302
 
300
303
  /* 选中态 */
301
304
  :global(:where(.snowui-menu-item[aria-selected="true"])) {
@@ -310,6 +313,9 @@
310
313
  :global(:where(.snowui-menu-item[data-active="true"])) {
311
314
  background-color: var(--black-4, #0000000a);
312
315
  }
316
+ :global(:where(.snowui-listbox[data-continuous-hover-enabled="true"] > .snowui-menu-item[data-active="true"])) {
317
+ background-color: transparent;
318
+ }
313
319
 
314
320
  /* 禁用态 */
315
321
  :global(:where(.snowui-menu-item[aria-disabled="true"])) {
@@ -0,0 +1,41 @@
1
+ # OverflowAction
2
+
3
+ > **版本**: v1.0.0
4
+ > **职责**: 为 OverflowActions 显式声明一个可测量、可转移到菜单的真实 Button 操作。
5
+
6
+ ## API
7
+
8
+ | 关键字 | 类型 | 默认值 | 描述 |
9
+ | --- | --- | --- | --- |
10
+ | `id` | `string` | 必填 | 组内稳定且唯一的操作标识 |
11
+ | `label` | `string` | 必填 | 按钮文字、菜单文字与 Icon-only 无障碍名称 |
12
+ | `icon` | `string \| Snippet` | 无 | 资源图标名或自定义图标;菜单复用同一内容 |
13
+ | `disabled` | `boolean` | `false` | 禁用可见按钮与对应 MenuItem |
14
+ | `href` | `string` | 无 | 可见状态渲染链接;菜单执行时导航到同一地址 |
15
+ | `onclick` | `(event?: MouseEvent) => void` | 无 | 可见按钮与菜单执行共享的操作函数 |
16
+ | `children` | `Snippet` | 自动 Icon + label | 覆盖可见按钮内容;注册到菜单的 label / icon 仍取显式 Props |
17
+ | `...rest` | `ButtonProps` | 无 | 透传到真实 Button |
18
+
19
+ OverflowAction 只能作为 `OverflowActions` 的直系子项使用。组件保留透明测量外壳,以便父级同时获得完整与 Icon-only 宽度;交互宿主始终是真实 Button,不创建第二套按钮状态机。
20
+
21
+ 父级 `OverflowActions buttonProps` 为 Button 提供组级默认值;当前 `OverflowAction` 直接声明的 Button 兼容 Props 优先,子项 `parts.Button` 位于两者之间。
22
+
23
+ > 此区域的内容受保护。AI 在修改此区域前必须请求用户审查。
24
+
25
+ ---
26
+ ---
27
+
28
+ > **以下内容供 AI 阅读,用于维护代码与文档的关联**
29
+
30
+ ## 开发者指南 (AI)
31
+
32
+ - 包归属:OSS;主布局模型为内联外壳布局。
33
+ - 组合身份:OverflowActions 的专用显式子项。
34
+ - `as="item"` 时向最近的 OverflowActions Context 注册;缺少父级时开发环境输出警告,但仍渲染普通 Button。
35
+ - 测量副本必须不可聚焦、不可命中、不可进入无障碍树。
36
+
37
+ ## 更新日志 (Changelog)
38
+
39
+ ### v1.0.0 (2026-08-12)
40
+
41
+ - 初始版本。
@@ -0,0 +1,209 @@
1
+ <!-- OverflowActions 的专用真实 Button 子项。文档:./OverflowAction.md -->
2
+ <script lang="ts">
3
+ import { onMount, type ComponentProps, type Snippet } from "svelte";
4
+ import { Icon as ResourceIcon } from "@snowui-design-system/resource-svelte";
5
+ import Frame from "./Frame.svelte";
6
+ import Button from "./Button.svelte";
7
+ import {
8
+ mergeComponentPartProps,
9
+ type ComponentPartsOf,
10
+ } from "../logic/component-parts.svelte";
11
+ import {
12
+ getOverflowActionsContext,
13
+ type OverflowActionIcon,
14
+ } from "../logic/overflow-actions.svelte";
15
+
16
+ type ButtonProps = ComponentProps<typeof Button>;
17
+ type ControlledButtonKeys =
18
+ | "children"
19
+ | "as"
20
+ | "iconOnly"
21
+ | "disabled"
22
+ | "href"
23
+ | "onclick"
24
+ | "aria-label"
25
+ | "title";
26
+
27
+ interface Props extends Omit<ButtonProps, ControlledButtonKeys> {
28
+ id: string;
29
+ label: string;
30
+ icon?: OverflowActionIcon;
31
+ disabled?: boolean;
32
+ href?: string;
33
+ onclick?: (event?: MouseEvent) => void;
34
+ children?: Snippet;
35
+ parts?: ComponentPartsOf<{ Button: typeof Button }>;
36
+ as?: string;
37
+ [key: string]: any;
38
+ }
39
+
40
+ let {
41
+ id,
42
+ label,
43
+ icon = undefined,
44
+ disabled = false,
45
+ href = undefined,
46
+ onclick = undefined,
47
+ children = undefined,
48
+ parts = undefined,
49
+ as = undefined,
50
+ ...rest
51
+ }: Props = $props();
52
+
53
+ const owner = getOverflowActionsContext();
54
+ const resolvedButtonProps = $derived(
55
+ mergeComponentPartProps(
56
+ mergeComponentPartProps(
57
+ owner?.buttonProps,
58
+ parts?.Button ?? {},
59
+ ),
60
+ rest,
61
+ ),
62
+ );
63
+ let rootElement = $state<HTMLElement | undefined>(undefined);
64
+ let fullMeasureElement = $state<HTMLElement | undefined>(undefined);
65
+ let compactMeasureElement = $state<HTMLElement | undefined>(undefined);
66
+ const mode = $derived(owner?.getMode(id) ?? "full");
67
+ const resolvedDisabled = $derived(disabled || owner?.disabled === true);
68
+ // Button 仍接收完整兼容 Props;透明测量外壳只同步公开 data-* 标记,
69
+ // 避免把 onclick / motion 等交互能力重复绑定到两层宿主。
70
+ const frameRestProps = $derived.by(() => Object.fromEntries(
71
+ Object.entries(rest).filter(([key]) => key.startsWith("data-")),
72
+ ));
73
+
74
+ function execute(event?: MouseEvent) {
75
+ if (resolvedDisabled) return;
76
+ if (owner) owner.invoke(id, event);
77
+ else onclick?.(event);
78
+ }
79
+
80
+ onMount(() => {
81
+ if (as !== "item" || !owner) {
82
+ if (import.meta.env.DEV && as === "item" && !owner) {
83
+ console.warn(
84
+ `[SnowUI OverflowAction] id="${id}" requires an OverflowActions parent.`,
85
+ );
86
+ }
87
+ return;
88
+ }
89
+
90
+ return owner.register({
91
+ get id() { return id; },
92
+ get label() { return label; },
93
+ get icon() { return icon; },
94
+ get disabled() { return disabled; },
95
+ get href() { return href; },
96
+ execute(event) { onclick?.(event); },
97
+ getElement: () => rootElement,
98
+ getFullMeasureElement: () => fullMeasureElement,
99
+ getCompactMeasureElement: () => compactMeasureElement,
100
+ });
101
+ });
102
+
103
+ $effect(() => {
104
+ id;
105
+ label;
106
+ icon;
107
+ disabled;
108
+ href;
109
+ resolvedButtonProps;
110
+ owner?.requestLayout();
111
+ });
112
+ </script>
113
+
114
+ {#snippet renderIcon()}
115
+ {#if typeof icon === "string"}
116
+ <ResourceIcon name={icon} aria-hidden="true" />
117
+ {:else if icon}
118
+ {@render icon()}
119
+ {/if}
120
+ {/snippet}
121
+
122
+ {#snippet renderFull()}
123
+ {#if children}
124
+ {@render children()}
125
+ {:else}
126
+ {@render renderIcon()}
127
+ {label}
128
+ {/if}
129
+ {/snippet}
130
+
131
+ <Frame
132
+ bind:element={rootElement}
133
+ tag="span"
134
+ class="snowui-overflow-action"
135
+ data-overflow-action-id={id}
136
+ data-overflow-mode={mode}
137
+ data-as={as}
138
+ enableAutoLayout={false}
139
+ enableResponsive={false}
140
+ enableContext={false}
141
+ enableScaleObserver={false}
142
+ enableDefaultMotion={false}
143
+ {...frameRestProps}
144
+ >
145
+ {#if mode === "compact"}
146
+ <Button
147
+ {...resolvedButtonProps}
148
+ iconOnly
149
+ aria-label={label}
150
+ title={label}
151
+ disabled={resolvedDisabled}
152
+ {href}
153
+ onclick={execute}
154
+ >
155
+ {@render renderIcon()}
156
+ </Button>
157
+ {:else}
158
+ <Button
159
+ {...resolvedButtonProps}
160
+ disabled={resolvedDisabled}
161
+ {href}
162
+ onclick={execute}
163
+ >
164
+ {@render renderFull()}
165
+ </Button>
166
+ {/if}
167
+
168
+ <span class="snowui-overflow-action-measure" aria-hidden="true" inert>
169
+ <span bind:this={fullMeasureElement}>
170
+ <Button {...resolvedButtonProps} tabindex={-1}>
171
+ {@render renderFull()}
172
+ </Button>
173
+ </span>
174
+ {#if icon}
175
+ <span bind:this={compactMeasureElement}>
176
+ <Button {...resolvedButtonProps} iconOnly tabindex={-1} aria-label={label}>
177
+ {@render renderIcon()}
178
+ </Button>
179
+ </span>
180
+ {/if}
181
+ </span>
182
+ </Frame>
183
+
184
+ <style>
185
+ :global(:where(.snowui-overflow-action)) {
186
+ position: relative;
187
+ display: inline-flex;
188
+ flex: 0 0 auto;
189
+ min-width: 0;
190
+ font-size: inherit;
191
+ line-height: inherit;
192
+ }
193
+
194
+ :global(:where(.snowui-overflow-action[data-overflow-mode="hidden"])) {
195
+ position: absolute;
196
+ visibility: hidden;
197
+ pointer-events: none;
198
+ }
199
+
200
+ :global(:where(.snowui-overflow-action-measure)) {
201
+ position: absolute;
202
+ inset: 0 auto auto 0;
203
+ display: inline-flex;
204
+ visibility: hidden;
205
+ pointer-events: none;
206
+ contain: layout style;
207
+ white-space: nowrap;
208
+ }
209
+ </style>
@@ -0,0 +1,11 @@
1
+ export const examples = [
2
+ {
3
+ name: "OAI-01:专用显式子项",
4
+ code: `OAI-01
5
+ <OverflowActions availableWidth={240}>
6
+ <OverflowAction as="item" id="edit" label="编辑" icon="pencil-simple" variant="outline" />
7
+ </OverflowActions>`,
8
+ expected: { render: "OverflowAction 渲染真实 outline Button。", layout: "透明测量外壳不占额外空间。", interaction: "可见按钮和菜单调用同一执行函数。", performance: "Context 只注册公开元数据和测量节点。", responsive: "父级可在 full、compact、hidden 间切换。" },
9
+ logic: ["ExplicitChild", "ButtonHost", "Context"],
10
+ },
11
+ ] as const;
@@ -0,0 +1,95 @@
1
+ # OverflowActions
2
+
3
+ > **版本**: v1.0.0
4
+ > **职责**: 在有限宽度内保留一组操作,并把容纳不下的操作转移到 More 菜单。
5
+
6
+ ## 使用
7
+
8
+ 默认内置模式通过稳定数据生成 Button、Separator、SelectButton、Listbox 与 MenuItem:
9
+
10
+ ```svelte
11
+ <OverflowActions
12
+ items={[
13
+ { type: "action", id: "edit", label: "编辑", icon: "pencil-simple" },
14
+ { type: "separator", id: "main-separator" },
15
+ { type: "action", id: "delete", label: "删除", icon: "trash" },
16
+ ]}
17
+ onAction={({ id }) => runAction(id)}
18
+ />
19
+ ```
20
+
21
+ 显式组合模式使用专用 `OverflowAction as="item"` 声明可响应操作,使用 `Separator as="separator" column` 声明结构项:
22
+
23
+ ```svelte
24
+ <OverflowActions overflow="progressive" overflowFrom="end">
25
+ <OverflowAction as="item" id="edit" label="编辑" icon="pencil-simple" onclick={edit} />
26
+ <Separator as="separator" column />
27
+ <OverflowAction as="item" id="delete" label="删除" icon="trash" onclick={remove} />
28
+ </OverflowActions>
29
+ ```
30
+
31
+ ## 响应式规则
32
+
33
+ 组件按以下顺序适应可用宽度:
34
+
35
+ 1. 完整显示 Icon + Text。
36
+ 2. `compact="auto"` 且每个 Action 都同时声明 icon 与 label 时,统一收起文字,只显示 Icon。
37
+ 3. 仍然放不下时显示 More 按钮,并根据 `overflow` 转移操作:
38
+ - `all`:全部操作转入菜单。
39
+ - `progressive`:按 `overflowFrom="start" | "end"` 从一侧逐个转入菜单。
40
+
41
+ 结构项不作为独立的溢出候选。Separator 仅在主操作区域两侧都仍有可见操作时保留;首尾 Separator、连续重复 Separator 自动隐藏。操作转入 More/Listbox 后只生成连续 MenuItem,即使来源结构中存在 Separator,菜单内也一律不显示分割线。Separator 的宽度仍计入主操作区域布局计算。
42
+
43
+ More 按钮使用 `SelectButton selectionMode="action"`,内部直接组合 `Listbox + MenuItem`,不引入 Popover。菜单展开期间冻结当前布局,避免触发器因列宽或容器宽度变化而消失。
44
+
45
+ ## API
46
+
47
+ | 关键字 | 类型 | 默认值 | 描述 |
48
+ | --- | --- | --- | --- |
49
+ | `items` | `OverflowActionsItem[]` | `[]` | 默认内置模式的数据;包含 action 与 separator |
50
+ | `compact` | `"auto" \| "none"` | `"auto"` | 是否在溢出前统一尝试 Icon-only |
51
+ | `overflow` | `"all" \| "progressive"` | `"all"` | 操作进入 More 菜单的方式 |
52
+ | `overflowFrom` | `"start" \| "end"` | `"end"` | progressive 模式的收起方向 |
53
+ | `availableWidth` | `number` | 容器实测宽度 | 外部提供的可用宽度;DataTable 用它避免每个单元格单独观察尺寸 |
54
+ | `moreLabel` | `string` | `"更多操作"` | More 按钮的无障碍名称 |
55
+ | `align` | `"start" \| "end"` | `"end"` | Listbox 水平对齐 |
56
+ | `disabled` | `boolean` | `false` | 禁用全部操作 |
57
+ | `buttonProps` | `Omit<ButtonProps, 受控行为字段>` | 无 | 所有 Action Button 与 More Button 的组级默认 Props;可配置 variant / size / bare / emphasis / class / style 等视觉能力 |
58
+ | `children` | `Snippet` | 无 | 显式组合模式内容 |
59
+ | `parts` | `ComponentPartsOf` | 无 | 配置内建 Button / SelectButton / Listbox / MenuItem / Separator |
60
+ | `onAction` | `(event: OverflowActionsActionEvent) => void` | 无 | 任一可见按钮或菜单项执行后的统一回调 |
61
+
62
+ `OverflowAction` 的 `icon` 支持资源图标名称或 Snippet;MenuItem 自动复用相同 icon。内置资源图标使用 MenuItem 的默认 16px,文字使用 MenuItem 的默认 14px / 20px,不继承 More 触发按钮的 Icon-only 尺寸;自定义 Snippet 保留自身视觉。当前不提供菜单项图标或文字尺寸接口。`href` Action 在可见状态使用链接,在菜单中执行时导航到同一地址。每个 Action 的 `id` 在组内必须唯一。
63
+
64
+ `buttonProps` 是组级 Button 默认值,并同时作用于完整 Action、Icon-only Action、隐藏测量副本与 More 触发按钮。优先级为 `buttonProps` → `parts.Button` / 子项 `parts.Button` → `OverflowAction` 直接 Props;越靠后优先级越高。More 默认只固定 `iconOnly` 等行为字段,未设置 `buttonProps` 时使用 Button 默认的 `variant="gray"` 与 `size="sm"`,不再默认使用 `bare`。
65
+
66
+ > 此区域的内容受保护。AI 在修改此区域前必须请求用户审查。
67
+
68
+ ---
69
+ ---
70
+
71
+ > **以下内容供 AI 阅读,用于维护代码与文档的关联**
72
+
73
+ ## 开发者指南 (AI)
74
+
75
+ - 包归属:OSS;主布局模型为复合管理布局。
76
+ - 组合模式:默认内置模式与显式组合模式并存;显式模式只识别直系 `OverflowAction as="item"` 与 `Separator as="separator"`。
77
+ - `OverflowAction` 通过专用 Context 注册 id / label / icon / disabled / href / 执行函数与测量节点;父组件不得读取任意 Button 内部结构推断语义。
78
+ - 自测量模式复用全局 `resizeManager`;传入 `availableWidth` 时不注册 ResizeObserver。
79
+ - 布局计算统一读取完整、Icon-only、Separator 与 More 的测量宽度;读写按单次调度分批完成。
80
+ - DataTable 应从列宽上下文传入 `availableWidth`,禁止为每个 actions 单元格新增 Observer。
81
+ - More 菜单由 SelectButton / Listbox / MenuItem 承担打开、Portal、焦点、键盘与关闭行为。
82
+
83
+ ## 模块索引
84
+
85
+ - [OverflowActions.svelte](./OverflowActions.svelte)
86
+ - [OverflowAction.svelte](./OverflowAction.svelte)
87
+ - [SelectButton.svelte](./SelectButton.svelte)
88
+ - [Listbox.svelte](./Listbox.svelte)
89
+ - [MenuItem.svelte](./MenuItem.svelte)
90
+
91
+ ## 更新日志 (Changelog)
92
+
93
+ ### v1.0.0 (2026-08-12)
94
+
95
+ - 初始版本:支持完整、Icon-only、全部溢出、双向逐个溢出、结构 Separator、组级 `buttonProps` 与 DataTable 外部宽度驱动;More 默认使用 Button 默认样式。