@snowui-design-system/components 0.2.0-alpha.8 → 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 (67) hide show
  1. package/component-catalog.json +1066 -0
  2. package/package.json +5 -1
  3. package/src/components/Button.md +42 -19
  4. package/src/components/Button.svelte +49 -49
  5. package/src/components/Button.test.ts +38 -27
  6. package/src/components/Card.test.ts +1 -1
  7. package/src/components/CodeBlock.md +44 -9
  8. package/src/components/CodeBlock.svelte +155 -10
  9. package/src/components/CodeBlock.test.ts +21 -2
  10. package/src/components/ColorSchemeButton.md +50 -0
  11. package/src/components/ColorSchemeButton.svelte +144 -0
  12. package/src/components/ColorSchemeButton.test.ts +39 -0
  13. package/src/components/CopyButton.md +5 -1
  14. package/src/components/CopyButton.svelte +6 -2
  15. package/src/components/Dialog.test.ts +2 -2
  16. package/src/components/ExpandButton.md +5 -1
  17. package/src/components/ExpandButton.svelte +1 -0
  18. package/src/components/Form.test.ts +4 -4
  19. package/src/components/Image.test.ts +1 -1
  20. package/src/components/Input.md +15 -5
  21. package/src/components/Input.svelte +10 -1
  22. package/src/components/Input.test.ts +2 -2
  23. package/src/components/OverflowAction.md +41 -0
  24. package/src/components/OverflowAction.svelte +209 -0
  25. package/src/components/OverflowAction.test.ts +11 -0
  26. package/src/components/OverflowActions.md +95 -0
  27. package/src/components/OverflowActions.svelte +501 -0
  28. package/src/components/OverflowActions.test.ts +87 -0
  29. package/src/components/Pagination.md +2 -2
  30. package/src/components/Pagination.svelte +2 -2
  31. package/src/components/Pagination.test.ts +2 -2
  32. package/src/components/SearchInput.md +14 -1
  33. package/src/components/SearchInput.svelte +104 -2
  34. package/src/components/SearchInput.test.ts +16 -1
  35. package/src/components/SelectButton.md +1 -1
  36. package/src/components/StyleButton.md +58 -0
  37. package/src/components/StyleButton.svelte +144 -0
  38. package/src/components/StyleButton.test.ts +39 -0
  39. package/src/components/Table.md +2 -2
  40. package/src/components/Table.svelte +4 -1
  41. package/src/components/TableCell.svelte +32 -5
  42. package/src/components/TableCell.test.ts +2 -2
  43. package/src/components/TableHead.svelte +20 -4
  44. package/src/components/TableToolbar.svelte +12 -5
  45. package/src/components/Text.svelte +2 -0
  46. package/src/components/Tooltip.md +27 -8
  47. package/src/components/Tooltip.svelte +101 -29
  48. package/src/components/Tooltip.test.ts +28 -2
  49. package/src/i18n/messages.ts +12 -0
  50. package/src/index.ts +17 -0
  51. package/src/internal/StyleButtonLogo.svelte +49 -0
  52. package/src/lib/table-context.svelte.ts +25 -0
  53. package/src/lib/tooltip-delay.md +7 -1
  54. package/src/lib/tooltip-motion-dismiss.md +16 -1
  55. package/src/lib/tooltip-motion-dismiss.ts +19 -7
  56. package/src/lib/tooltip-overlay.md +21 -3
  57. package/src/lib/tooltip-overlay.ts +4 -2
  58. package/src/logic/frame-inline-style.svelte.ts +2 -2
  59. package/src/logic/overflow-actions.svelte.ts +33 -0
  60. package/src/motion/presets/README.md +5 -2
  61. package/src/motion/presets/tooltip.md +40 -2
  62. package/src/motion/presets/tooltip.ts +0 -2
  63. package/src/motion/tokens.md +7 -4
  64. package/src/motion/tokens.ts +2 -1
  65. package/src/styles/auto-layout.css +10 -1
  66. package/src/styles/components.css +29 -20
  67. package/src/styles/tokens.css +33 -33
@@ -0,0 +1,39 @@
1
+ export const examples = [
2
+ {
3
+ name: "CSB-01: Button 全部变体与尺寸",
4
+ code: `CSB-01
5
+ <ColorSchemeButton variant="gray" size="sm" />
6
+ <ColorSchemeButton variant="filled" size="md" />
7
+ <ColorSchemeButton variant="outline" size="lg" />
8
+ <ColorSchemeButton variant="borderless" size="sm" />
9
+ <ColorSchemeButton bare size="sm" />`,
10
+ expected: {
11
+ interaction: "每个按钮点击后立即在亮色与暗色之间切换;图标同步切换且没有替换动效",
12
+ render: "内置图标跟随 Button 尺寸:sm / md / lg 分别为 16 / 20 / 24px",
13
+ },
14
+ logic: ["HostSpecialization", "Variant", "Size", "ColorScheme"],
15
+ },
16
+ {
17
+ name: "CSB-02: 默认方案与禁用状态",
18
+ code: `CSB-02
19
+ <ColorSchemeButton defaultScheme="dark" variant="gray" />
20
+ <ColorSchemeButton variant="outline" disabled />`,
21
+ expected: {
22
+ interaction: "页面从暗色开始;两个按钮同步显示当前方案,禁用按钮不改变方案",
23
+ },
24
+ logic: ["defaultScheme", "Disabled", "AriaPressed"],
25
+ },
26
+ {
27
+ name: "CSB-03: Locale 与受控宿主",
28
+ code: `CSB-03
29
+ <LocaleProvider locale="en-US">
30
+ <ColorSchemeButton scheme="light" applyToDocument={false} bare>
31
+ <Text>Appearance</Text>
32
+ </ColorSchemeButton>
33
+ </LocaleProvider>`,
34
+ expected: {
35
+ render: "按钮使用英文切换名称和可见内容;显式状态不修改 document",
36
+ },
37
+ logic: ["LocaleProvider", "ExplicitScheme", "children"],
38
+ },
39
+ ] as const;
@@ -1,6 +1,6 @@
1
1
  # CopyButton
2
2
 
3
- > **版本**: v1.0.0
3
+ > **版本**: v1.0.1
4
4
  > **职责**: 以真实 Button 为宿主的剪贴板复制与瞬时反馈按钮。
5
5
 
6
6
  ## 使用
@@ -36,6 +36,10 @@
36
36
 
37
37
  ## 更新日志 (Changelog)
38
38
 
39
+ ### v1.0.1 (2026-08-11)
40
+
41
+ - `showText=false` 时主动向 Button 声明 `iconOnly=true`,保持纯图标复制按钮的尺寸与命中区域。
42
+
39
43
  ### v1.0.0 (2026-07-03)
40
44
 
41
45
  - 首次实现异步复制、成功/失败事件和反馈复位。
@@ -112,6 +112,7 @@
112
112
 
113
113
  <Button
114
114
  {...rest}
115
+ iconOnly={!showText}
115
116
  {disabled}
116
117
  data-copy-button
117
118
  data-copy-status={status}
@@ -146,7 +147,7 @@
146
147
 
147
148
  <style>
148
149
  /* CopyButton 自己管理 bare 状态的透明度与交互光标。反馈期内即使仍被
149
- hover,也保持常态透明度,避免复制成功时按钮突然闪亮。 */
150
+ hover,也保持当前 emphasis 的常态透明度,避免复制成功时按钮突然闪亮。 */
150
151
  :global(:where(.snowui-button)[data-copy-button]) {
151
152
  cursor: pointer;
152
153
  }
@@ -158,7 +159,10 @@
158
159
  ) {
159
160
  opacity: var(
160
161
  --snowui-copy-button-feedback-opacity,
161
- var(--snowui-state-opacity, 0.4)
162
+ var(
163
+ --snowui-state-opacity,
164
+ var(--snowui-button-bare-idle-opacity, 1)
165
+ )
162
166
  );
163
167
  }
164
168
  </style>
@@ -13,7 +13,7 @@ export const examples = [
13
13
  name: "DL-01:模版模式基础对话框",
14
14
  code: `DL-01
15
15
  <Dialog template id="dialog-basic">
16
- <Button as="pin-top-right" variant="borderless" bare data-dialog-close aria-label="关闭">
16
+ <Button as="pin-top-right" variant="borderless" bare iconOnly emphasis="muted" data-dialog-close aria-label="关闭">
17
17
  <XCircle size={16} />
18
18
  </Button>
19
19
  <Text class="text-18 text-black-100">编辑资料</Text>
@@ -130,7 +130,7 @@ export const examples = [
130
130
  <Button>
131
131
  快速设置
132
132
  <Dialog as="dialog" size="sm">
133
- <Button as="pin-top-right" variant="borderless" bare data-dialog-close aria-label="关闭">
133
+ <Button as="pin-top-right" variant="borderless" bare emphasis="muted" data-dialog-close aria-label="关闭">
134
134
  <XCircle size={16} />
135
135
  </Button>
136
136
  <Text class="text-18 text-black-100">快速设置</Text>
@@ -1,6 +1,6 @@
1
1
  # ExpandButton
2
2
 
3
- > **版本**: v1.0.0
3
+ > **版本**: v1.0.1
4
4
  > **职责**: 以真实 Button 为宿主的展开 / 收起二态按钮。
5
5
 
6
6
  ## 使用
@@ -36,6 +36,10 @@
36
36
 
37
37
  ## 更新日志 (Changelog)
38
38
 
39
+ ### v1.0.1 (2026-08-11)
40
+
41
+ - 无额外 children 时主动向 Button 声明 `iconOnly=true`,保持默认展开图标按钮布局。
42
+
39
43
  ### v1.0.0 (2026-07-03)
40
44
 
41
45
  - 首次实现 Button 宿主特化、展开语义与图标替换动效。
@@ -64,6 +64,7 @@
64
64
 
65
65
  <Button
66
66
  {...rest}
67
+ iconOnly={!children}
67
68
  {disabled}
68
69
  aria-expanded={resolvedExpanded}
69
70
  aria-label={resolvedExpanded ? collapseAriaLabel : ariaLabel}
@@ -119,7 +119,7 @@ export const examples = [
119
119
  <Text as="label" style="color: var(--black-40, rgba(0, 0, 0, 0.4));">Due Date</Text>
120
120
  <Icon as="leading" style="color: var(--black-40, rgba(0, 0, 0, 0.4));"><CalendarBlank /></Icon>
121
121
  <Input type="date" name="dueDate" defaultValue="2026-02-01" />
122
- <Button as="trailing" type="button" variant="borderless" bare aria-label="打开日期选择" style="color: var(--black-40, rgba(0, 0, 0, 0.4));">
122
+ <Button as="trailing" type="button" variant="borderless" bare iconOnly emphasis="muted" aria-label="打开日期选择">
123
123
  <Icon size={16}><ArrowLineUpDown /></Icon>
124
124
  </Button>
125
125
  </Field>`,
@@ -231,14 +231,14 @@ export const examples = [
231
231
  </Text>
232
232
  <Frame as="row" row style="align-items: center; justify-content: space-between;">
233
233
  <Frame as="row" row style="gap: var(--gap-1);">
234
- <Button type="button" variant="borderless" bare aria-label="添加附件">
234
+ <Button type="button" variant="borderless" bare iconOnly emphasis="muted" aria-label="添加附件">
235
235
  <Paperclip size={16} />
236
236
  </Button>
237
- <Button type="button" variant="borderless" bare aria-label="附加第二操作">
237
+ <Button type="button" variant="borderless" bare iconOnly emphasis="muted" aria-label="附加第二操作">
238
238
  <CalendarBlank size={16} />
239
239
  </Button>
240
240
  </Frame>
241
- <Button type="button" variant="borderless" bare aria-label="发送">
241
+ <Button type="button" variant="borderless" bare iconOnly emphasis="muted" aria-label="发送">
242
242
  <PaperPlaneRight size={16} />
243
243
  </Button>
244
244
  </Frame>
@@ -23,7 +23,7 @@ export const examples = [
23
23
  <Radio as="badge" checked />
24
24
  </Image>
25
25
  <Image src={Image01} size={40}>
26
- <Button as="icon" variant="gray">
26
+ <Button as="icon" variant="gray" iconOnly aria-label="选择">
27
27
  <Icon>
28
28
  <Check />
29
29
  </Icon>
@@ -1,6 +1,6 @@
1
1
  # Input.svelte 文档
2
2
 
3
- > **版本**: v1.1.1
3
+ > **版本**: v1.1.3
4
4
  > **职责**: 基础单行输入宿主;`text` 使用原生可见 `<input>`,`date` / `color` 使用自定义可见展示层,其余类型继续承接原生 `<input>` 能力与 Frame 通用能力。
5
5
 
6
6
  **2026-04-27 补充**: 内建清除 X 恢复为焦点态交互:只有输入内容非空且 `Input` 处于 `focus-within` 时显示;失焦后隐藏且不为隐藏 X 预留额外 gap。
@@ -11,7 +11,7 @@
11
11
 
12
12
  **2026-04-09 图标规则补充**: `Input` 内建 error trailing icon,以及放在 `Input` 里的前置 / 后置 icon,位置优先由 `Input` 自身控制。默认要求是 icon 到最近可见内边界保持 `16px`;进入 `Field` 后仍沿用这条规则。若 `Input as="segment"` 处于连续字段表面中,icon 到最近边框或分割线的距离仍保持 `16px`,不因为 `Field` 组合而改成新的偏移规则。
13
13
  **2026-04-09 补充**: 根据需求文档中 F-01 的期望 HTML,`type="text"` 已回收为可见原生 `<input>`,不再额外渲染自定义 editor / placeholder 覆盖层;`Field > Input` 的结构收敛为 `div > input`,placeholder 与输入内容共同走浏览器原生单行输入排版。
14
- **2026-07-05 补充**: `Input` 单独使用时默认 padding 调整为 `12 / 12`;进入 `Field` 后仍由 Field 的既有 `12 / 16` 规则接管。
14
+ **2026-08-12 更正**: `Input` 单独使用时的源码默认 padding 为 `12 / 16`;此前文档中的 `12 / 12` 为记录错误。进入 `Field` 后仍由 Field 的既有 `12 / 16` 规则接管。
15
15
  **2026-03-29 补充**: 当 `type="text"` 同时声明 `list` 时,`Input` 会回退为可见原生 `<input>`,以保留浏览器原生 `datalist` 建议项。
16
16
  **2026-03-29 补充**: `type="file"` 已从 `Input` 组件支持范围中移除;传入该类型时会回退为普通 `text` 输入,不再透传浏览器原生文件上传器。
17
17
  **2026-03-28 补充**: `type="range"` 已从 `Input` 组件支持范围中移除;传入该类型时会回退为普通 `text` 输入,不再直接透传浏览器原生滑杆。
@@ -25,7 +25,7 @@
25
25
  ## 2026-04-04 表单样式规则
26
26
 
27
27
  - 基础节奏统一:`Field` 默认 `padding = 12 / 16`,`gap = 8`
28
- - `Input` 单独使用时:组件自身带 `12 / 12` padding 和 `8` gap
28
+ - `Input` 单独使用时:组件自身带 `12 / 16` padding 和 `8` gap
29
29
  - icon 位置由 `Input` 自己控制:leading / trailing icon 到最近可见内边界默认都是 `16px`
30
30
  - 错误态内建 warning icon 也走同一条 trailing icon 规则,不额外使用 overlay 偏移
31
31
  - 放进 `Field` 后,先看有没有 `as="segment"`
@@ -81,6 +81,7 @@
81
81
  | :--- | :--- | :--- | :--- |
82
82
  | type | `string` | `"text"` | 原生输入类型,如 `text` / `email` / `password` / `number`;`range` / `file` 不再支持,会回退为 `text` |
83
83
  | value | `string \| number` | - | 当前值,支持 `bind:value` |
84
+ | element | `HTMLElement` | - | 外层真实 Frame 根元素引用,支持 `bind:element`;用于宿主特化组件复用根尺寸与焦点能力 |
84
85
  | defaultValue | `string \| number` | - | 初始值;未绑定 `value` 时作为初始展示值 |
85
86
  | disabled | `boolean` | `false` | 禁用输入 |
86
87
  | readonly | `boolean` | `false` | 只读输入;保留聚焦与选中文本能力,但不可直接编辑 |
@@ -244,7 +245,7 @@ Input 的根布局固定按 Leading / Control / Trailing 三段组织:
244
245
  <!-- 日期输入 + 自定义 trailing 触发器(简单场景自动推断) -->
245
246
  <Field>
246
247
  <Input type="date" />
247
- <Button bare as="trailing">
248
+ <Button bare iconOnly as="trailing" aria-label="打开日期选择">
248
249
  <ArrowLineDown size={16} />
249
250
  </Button>
250
251
  </Field>
@@ -253,7 +254,7 @@ Input 的根布局固定按 Leading / Control / Trailing 三段组织:
253
254
  <Field>
254
255
  <Frame as="row" row>
255
256
  <Input type="date" />
256
- <Button bare as="trailing">
257
+ <Button bare iconOnly as="trailing" aria-label="打开日期选择">
257
258
  <ArrowLineDown size={16} />
258
259
  </Button>
259
260
  </Frame>
@@ -530,6 +531,15 @@ invalid=true + !hasCustomTrailing
530
531
  - **Input-Motion.2026-06-18** 新增默认错误反馈 shake:独立 `Input invalid / aria-invalid` 自动播放,嵌入 `Field` 时由 `Field` 汇总播放,消费方无需手动传类名或状态。
531
532
  - **Input-Docs.2026-05-25** 源码顶部历史变更记录已归档;后续新增变更统一写入本文档 Changelog,源码顶部只保留职责、当前关键架构与文档路径。
532
533
 
534
+ ### v1.1.3 (2026-08-12)
535
+
536
+ - 更正独立 Input 标准态 padding 记录为源码实际值 `12px / 16px`;组件行为未改变。
537
+
538
+ ### v1.1.2 (2026-08-10)
539
+
540
+ - 补齐从 Frame 继承的 `bind:element` 根宿主引用,使 SearchInput 等宿主特化组件无需 wrapper 或私有 DOM 查询即可复用根尺寸能力。
541
+ - 普通 Input 的 clear + leading 稳定宽度规则在 SearchInput 空值图标态时退出,避免隐藏 clear 的历史 gap 继续占据 Icon 右侧;聚焦或已有值后仍恢复原布局。
542
+
533
543
  ### v1.1.1 (2026-07-05)
534
544
 
535
545
  #### 修复
@@ -1,6 +1,6 @@
1
1
  <!--
2
2
  Input 组件:基础单行输入框
3
- v1.1.1
3
+ v1.1.3
4
4
 
5
5
  文档: ./Input.md
6
6
  -->
@@ -55,6 +55,7 @@
55
55
  type DateDraft = Record<TemporalSegmentKey, string>;
56
56
 
57
57
  interface Props extends Omit<FrameProps, "tag"> {
58
+ element?: HTMLElement;
58
59
  type?: HTMLInputAttributes["type"];
59
60
  value?: InputValue;
60
61
  defaultValue?: InputValue;
@@ -110,6 +111,7 @@
110
111
  const inheritedInputPart = useComponentPart<Props>("Input");
111
112
  let {
112
113
  value = $bindable(),
114
+ element = $bindable(),
113
115
  ...explicitProps
114
116
  }: Props = $props();
115
117
  let {
@@ -263,6 +265,9 @@
263
265
  isEmbedded && !isCustomColorType && !isCustomTemporalType,
264
266
  );
265
267
  let hostElement = $state<HTMLElement | undefined>(undefined);
268
+ $effect(() => {
269
+ element = hostElement;
270
+ });
266
271
  // as="search" 时自动移入浮层 header 区域(固定置顶,不随内容滚动)
267
272
  $effect(() => {
268
273
  if (!isOverlaySearchHeader || !listboxHeaderPortal?.el || !hostElement) return;
@@ -2737,6 +2742,10 @@
2737
2742
  .snowui-input:not(.snowui-search-input-borderless)[data-has-root-accessory="true"]:has(
2738
2743
  > .snowui-input-clear-btn
2739
2744
  ):has(> [data-as="leading"]):not(
2745
+ .snowui-search-input-responsive-icon:not(
2746
+ :focus-within
2747
+ ):not(.snowui-search-input-has-value)
2748
+ ):not(
2740
2749
  :has(
2741
2750
  > [data-as="trailing"]:not(
2742
2751
  .snowui-input-clear-btn
@@ -140,7 +140,7 @@ export const examples = [
140
140
  code: `I-14b
141
141
  <Field style="width: 20rem;">
142
142
  <Input type="date" />
143
- <Button as="trailing" type="button" variant="borderless" bare aria-label="打开日期选择器">
143
+ <Button as="trailing" type="button" variant="borderless" bare iconOnly emphasis="muted" aria-label="打开日期选择器">
144
144
  <CalendarBlank size={16} />
145
145
  </Button>
146
146
  </Field>`,
@@ -166,7 +166,7 @@ export const examples = [
166
166
  code: `I-15b
167
167
  <Field style="width: 20rem;">
168
168
  <Input type="time" />
169
- <Button as="trailing" type="button" variant="borderless" bare aria-label="打开时间选择器">
169
+ <Button as="trailing" type="button" variant="borderless" bare iconOnly emphasis="muted" aria-label="打开时间选择器">
170
170
  <Clock size={16} />
171
171
  </Button>
172
172
  </Field>`,
@@ -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 默认样式。