@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
@@ -8,7 +8,7 @@
8
8
  - 组件无额外 wrapper,真实 `Input` 仍是根宿主;事件只由该宿主触发一次。
9
9
  - `Input` 自身隐藏生成的错误 `Text` 仍可通过平铺后的 `parts.Text` 配置。
10
10
 
11
- > **版本**: v1.2.1
11
+ > **版本**: v1.3.0
12
12
  > **职责**: 提供与 `Input` 一致的 OSS 搜索输入框,默认内置 `Search`。
13
13
 
14
14
  `SearchInput` 是 `Input` 的搜索场景变体。除默认 `type="search"` 和默认 leading 图标为 `Search` 外,其颜色、hover/focus、清除 X、三槽位布局、Frame 能力与 `Input` 保持一致。
@@ -18,6 +18,7 @@
18
18
  - 默认使用 `Search` 作为 leading 图标,图标来自 `@snowui-design-system/resource-svelte`
19
19
  - 内置默认 `Search` 静止态为 Black/20,输入激活态为 Black/40;该颜色规则只属于 `SearchInput`
20
20
  - 支持外置 leading 替换默认图标
21
+ - 可通过 `collapseBelow` 在自身宽度不足时退化为仅搜索图标;最小宽度由左右实际 padding + leading Icon 固有宽度组成,空值且未聚焦时折叠,聚焦或已有值时恢复输入内容
21
22
  - 清除 X、hover、focus、disabled、readonly、invalid 与默认错误 shake 等行为继承 `Input`
22
23
  - 根能力通过内部 `Input` 接通 OSS `Frame`
23
24
 
@@ -34,6 +35,7 @@
34
35
  | defaultValue | `string \| number` | — | 初始值 |
35
36
  | placeholder | `string` | — | 占位文本 |
36
37
  | showSearchIcon | `boolean` | `true` | 是否渲染默认搜索图标 |
38
+ | collapseBelow | `number` | — | 当组件自身宽度小于或等于该 px 阈值时,在空值且未聚焦状态退化为仅搜索图标;未传时不启用 |
37
39
  | variant | `"default" \| "borderless"` | `"default"` | 外观变体;`borderless` 移除自身边框、背景、圆角、padding 和 focus ring,在 Flex / Block 宿主中填满可用空间,并在 shrink-to-fit 宿主中保持稳定固有宽度,适合嵌入已有表面的工具栏或面板 |
38
40
  | as | `"search" \| string` | `"search"` | 角色关键字;默认透传给内部 `Input`,使 SearchInput 放入 `<Popover>` / `<Listbox>` 时自动移入固定 header,行为与 `<Input as="search">` 一致。可显式覆盖。 |
39
41
  | children | `Snippet` | — | 外置 leading / trailing / 其他 Input 子内容 |
@@ -49,6 +51,11 @@
49
51
  <SearchInput placeholder="Search" />
50
52
  ```
51
53
 
54
+ ```svelte
55
+ <!-- 容器收窄到 80px 以下时只保留搜索图标;点击或键盘聚焦后恢复输入 -->
56
+ <SearchInput collapseBelow={80} placeholder="Search" />
57
+ ```
58
+
52
59
  ```svelte
53
60
  <!-- 外层容器已经提供完整表面时,显式使用无边框版本 -->
54
61
  <SearchInput variant="borderless" placeholder="Search" />
@@ -97,6 +104,7 @@
97
104
  | 关键字 | 处理方式 | 说明 |
98
105
  | :--- | :--- | :--- |
99
106
  | showSearchIcon | 条件渲染 | `false` 时不渲染默认 Search |
107
+ | collapseBelow | 共享尺寸观察 | 复用 `resizeManager` 监听真实根宿主;只写入 `data-responsive-collapse="icon"`,空值且未聚焦时由 SearchInput 自己收敛布局,不改变 Input 的通用布局协议 |
100
108
  | variant | 根 class | `borderless` 由 SearchInput 自己移除边框、背景、圆角、padding 和 focus ring;以 `flex: 1 1 0; width: auto; max-width: 100%` 填满确定容器的可用空间,并避免 shrink-to-fit 宿主因输入状态重算百分比宽度;父容器不得通过后代选择器改写这些视觉或布局 |
101
109
  | children | 透传到 Input | 用于外置 leading/trailing 或其他组合内容 |
102
110
 
@@ -109,6 +117,11 @@
109
117
 
110
118
  ## 更新日志 (Changelog)
111
119
 
120
+ ### v1.3.0 (2026-08-10)
121
+
122
+ - 新增 `collapseBelow` 响应式退化能力;空值且未聚焦时使用明确的单列布局收敛为仅搜索图标,隐藏清除按钮的历史槽位与 gap 不再参与宽度;最小宽度等于左右实际 padding + leading Icon 固有宽度,聚焦或已有值时恢复真实输入内容与交互。
123
+ - 尺寸监听复用全局 `resizeManager`,不创建组件私有 `ResizeObserver`。
124
+
112
125
  ### v1.2.1 (2026-07-05)
113
126
 
114
127
  - 修复 `borderless` 在 shrink-to-fit 宿主中输入内容时宽度变化:以 `width: auto; max-width: 100%` 取代循环参与固有尺寸计算的百分比宽度,Flex / Block 宿主中的填充行为保持不变。
@@ -1,6 +1,6 @@
1
1
  <!--
2
2
  SearchInput 简单搜索输入框
3
- v1.2.1
3
+ v1.3.0
4
4
 
5
5
  文档: ./SearchInput.md
6
6
  -->
@@ -13,6 +13,7 @@
13
13
  mergeComponentPartProps,
14
14
  useComponentPart,
15
15
  } from "../logic/component-parts.svelte";
16
+ import { resizeManager } from "../logic/observer.svelte";
16
17
 
17
18
  type InputProps = ComponentProps<typeof Input>;
18
19
  type ControlledInputKeys =
@@ -21,13 +22,16 @@
21
22
  | "type"
22
23
  | "as"
23
24
  | "class"
25
+ | "element"
24
26
  | "children";
25
27
 
26
28
  interface Props extends Omit<InputProps, ControlledInputKeys> {
27
29
  type?: InputProps["type"];
28
30
  value?: string | number;
31
+ element?: HTMLElement;
29
32
  defaultValue?: string | number;
30
33
  showSearchIcon?: boolean;
34
+ collapseBelow?: number;
31
35
  variant?: "default" | "borderless";
32
36
  as?: InputProps["as"];
33
37
  class?: string;
@@ -38,12 +42,14 @@
38
42
  const inheritedSearchInputPart = useComponentPart<Props>("SearchInput");
39
43
  let {
40
44
  value = $bindable(),
45
+ element = $bindable(),
41
46
  ...explicitProps
42
47
  }: Props = $props();
43
48
  let {
44
49
  type = "search",
45
50
  defaultValue = undefined,
46
51
  showSearchIcon = true,
52
+ collapseBelow = undefined,
47
53
  variant = "default",
48
54
  as = "search",
49
55
  class: userClass = "",
@@ -55,14 +61,52 @@
55
61
  explicitProps,
56
62
  ),
57
63
  );
64
+
65
+ let responsiveIcon = $state(false);
66
+ const hasValue = $derived(
67
+ value !== undefined && value !== null && String(value) !== "" ||
68
+ value === undefined &&
69
+ defaultValue !== undefined &&
70
+ defaultValue !== null &&
71
+ String(defaultValue) !== "",
72
+ );
73
+
74
+ $effect(() => {
75
+ const node = element;
76
+ const threshold = collapseBelow;
77
+ if (!node) return;
78
+
79
+ const update = (width: number) => {
80
+ if (
81
+ typeof threshold === "number" &&
82
+ threshold > 0 &&
83
+ width <= threshold
84
+ ) {
85
+ responsiveIcon = true;
86
+ } else {
87
+ responsiveIcon = false;
88
+ }
89
+ };
90
+
91
+ update(node.getBoundingClientRect().width);
92
+ const unwatch = resizeManager.watch(node, (entry) =>
93
+ update(entry.contentRect.width),
94
+ );
95
+
96
+ return () => {
97
+ unwatch();
98
+ responsiveIcon = false;
99
+ };
100
+ });
58
101
  </script>
59
102
 
60
103
  <Input
61
104
  bind:value
105
+ bind:element
62
106
  {defaultValue}
63
107
  {type}
64
108
  {as}
65
- class={`snowui-search-input snowui-search-input-${variant}${userClass ? ` ${userClass}` : ""}`}
109
+ class={`snowui-search-input snowui-search-input-${variant}${responsiveIcon ? " snowui-search-input-responsive-icon" : ""}${hasValue ? " snowui-search-input-has-value" : ""}${userClass ? ` ${userClass}` : ""}`}
66
110
  {...rest}
67
111
  >
68
112
  {#if showSearchIcon}
@@ -78,6 +122,64 @@
78
122
  </Input>
79
123
 
80
124
  <style>
125
+ :global(
126
+ .snowui-frame.snowui-input.snowui-search-input.snowui-search-input-responsive-icon:not(
127
+ :focus-within
128
+ ):not(.snowui-search-input-has-value)
129
+ ) {
130
+ display: grid;
131
+ grid-template-columns: minmax(0, 1fr);
132
+ justify-items: center;
133
+ min-width: max-content;
134
+ gap: 0;
135
+ }
136
+
137
+ :global(
138
+ :where(
139
+ .snowui-input.snowui-search-input-responsive-icon:not(
140
+ :focus-within
141
+ ):not(.snowui-search-input-has-value)
142
+ > [data-as="leading"]
143
+ )
144
+ ) {
145
+ grid-column: 1;
146
+ grid-row: 1;
147
+ justify-self: center;
148
+ }
149
+
150
+ /* 原生 input 覆盖整个 icon-only 命中区:视觉收敛但仍可直接聚焦,
151
+ focus-within 后自动回到 Input 的标准三槽位布局。 */
152
+ :global(
153
+ :where(
154
+ .snowui-input.snowui-search-input-responsive-icon:not(
155
+ :focus-within
156
+ ):not(.snowui-search-input-has-value)
157
+ > .snowui-input-control
158
+ )
159
+ ) {
160
+ position: absolute;
161
+ inset: 0;
162
+ z-index: 1;
163
+ width: 100%;
164
+ height: 100%;
165
+ padding: 0;
166
+ opacity: 0;
167
+ cursor: text;
168
+ }
169
+
170
+ :global(
171
+ :where(
172
+ .snowui-input.snowui-search-input-responsive-icon:not(
173
+ :focus-within
174
+ ):not(.snowui-search-input-has-value)
175
+ > :not([data-as="leading"]):not(
176
+ .snowui-input-control
177
+ )
178
+ )
179
+ ) {
180
+ display: none;
181
+ }
182
+
81
183
  :global(:where(.snowui-input.snowui-search-input-borderless)) {
82
184
  --snowui-field-border-width: 0rem;
83
185
  --snowui-field-focus-ring-width: 0rem;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * SearchInput.test.ts
3
- * v1.2.0
3
+ * v1.3.0
4
4
  *
5
5
  * 测试覆盖:SearchInput.md 定义的默认 Search、外置 leading、清除 X、Input 宿主 Props 平铺。
6
6
  */
@@ -58,4 +58,19 @@ export const examples = [
58
58
  />`,
59
59
  logic: ["HostSpecialization", "InputProps", "PartsText"],
60
60
  },
61
+ {
62
+ name: "SI-07:窄宽度退化为搜索图标",
63
+ code: `SI-07
64
+ <SearchInput
65
+ collapseBelow={80}
66
+ placeholder="Search"
67
+ style="width: 1rem;"
68
+ />`,
69
+ expected: {
70
+ render: "空值且未聚焦时仅显示水平居中的 Search 图标,左右间距相等",
71
+ interaction: "点击或键盘聚焦后恢复真实输入控件;输入值存在时保持内容可见",
72
+ responsive: "组件自身宽度不大于 80px 时进入 icon 退化态;即使外部 width 更小,最小宽度仍为左右实际 padding + leading Icon",
73
+ },
74
+ logic: ["ResponsiveCollapse", "Search", "Focus"],
75
+ },
61
76
  ] as const;
@@ -20,7 +20,7 @@ Button 的兼容 Props 在根级平铺;Button 是宿主,不提供 `parts.But
20
20
 
21
21
  `selectionMode="persistent"` 是默认持续选择模式:trigger 显示当前选中项。`selectionMode="action"` 是命令执行模式:trigger 始终显示 placeholder,点击选项只触发 `onAction(value)`,不保存选中值。因此无需另设 MenuButton。
22
22
 
23
- SelectButton 默认不显示搜索框,使用 `search` 开启。其 Listbox 默认以最长选项决定固定宽度,其他选项全部 fill,并且不显示选中 check。搜索 placeholder、搜索时 160px 最小宽度和打开后锁宽由 Listbox 统一提供。`bare` 直接传给宿主 Button。
23
+ SelectButton 默认不显示搜索框,使用 `search` 开启。其 Listbox 默认以最长选项决定固定宽度,其他选项全部 fill,并且不显示选中 check。搜索 placeholder、搜索时 160px 最小宽度和打开后锁宽由 Listbox 统一提供。`bare` 与 `emphasis` 直接传给宿主 Button;因此 bare 默认 100%,需要次级触发器时显式使用 `emphasis="muted"`。
24
24
 
25
25
  > 此区域的内容受保护。AI 在修改此区域前必须请求用户审查。
26
26
 
@@ -0,0 +1,58 @@
1
+ # StyleButton
2
+
3
+ > **版本**: v1.0.3
4
+ > **职责**: 以真实 Button 为宿主,在 SnowUI 与 Apple 视觉风格之间切换。
5
+
6
+ ## 使用
7
+
8
+ ```svelte
9
+ <StyleButton bare />
10
+ ```
11
+
12
+ StyleButton 平铺 Button 的兼容 Props,支持全部变体与尺寸。默认读取 `document.documentElement`:`mode="ios"` 为 Apple 风格,移除该属性为 SnowUI 风格。当前 SnowUI 状态使用 `SnowUILogo variant="icon"`,Apple 状态使用 Apple 品牌 Logo 矢量,而不是图标库中的 Apple Icon;无额外 children 时,StyleButton 主动向 Button 声明 `iconOnly=true`,因此 `sm / md / lg` 的四边 padding 分别保持 Button 原生的 `4 / 8 / 12px`。
13
+
14
+ 点击后立即切换,不写入 storage,也不增加图标替换、风格切换动效。`applyToDocument={false}` 时只维护受控状态,适合由 Test、iframe 等宿主管理实际风格目标。
15
+
16
+ | 关键字 | 类型 | 默认值 | 描述 |
17
+ | --- | --- | --- | --- |
18
+ | `mode` | `"snowui" \| "apple"` | 当前页面风格 | 当前风格,可 `bind:mode` |
19
+ | `defaultMode` | `"snowui" \| "apple"` | 当前页面风格 | 非受控初始风格 |
20
+ | `applyToDocument` | `boolean` | `true` | 是否同步页面根节点 |
21
+ | `ariaLabel` | `string` | 当前操作的本地化文案 | 覆盖按钮名称 |
22
+ | `snowuiLogo` / `appleLogo` | `Snippet` | SnowUI Logo / Apple Logo | 覆盖对应内置 Logo |
23
+ | `children` | `Snippet` | 无 | 图标后的可选内容 |
24
+ | `onModeChange` | `(mode) => void` | 无 | 切换完成后的回调 |
25
+
26
+ > 此区域的内容受保护。AI 在修改此区域前必须请求用户审查。
27
+
28
+ ---
29
+
30
+ > **以下内容供 AI 阅读,用于维护代码与文档的关联**
31
+
32
+ ## 开发者指南 (AI)
33
+
34
+ - 包归属:OSS;主布局模型为内联外壳布局。
35
+ - 组合身份:Button 宿主组件特化,不提供 `parts.Button`。
36
+ - 内置 SnowUI Logo 必须使用 `SnowUILogo variant="icon"`,Apple 状态必须使用 Apple Logo。
37
+ - 两个 Logo 均消费 Button 图标尺寸上下文,不得固定为单一尺寸。
38
+ - 两个 Logo 的直接根节点保留 `snowui-style-button-logo` 视觉身份;icon-only 布局由 StyleButton 显式传给 Button,不依赖 Logo DOM 类型,也不得由 StyleButton 私自覆写 padding。
39
+ - 多实例通过观察根节点 `mode` 属性同步;`applyToDocument={false}` 时由受控 `mode` 同步。
40
+
41
+ ## 更新日志 (Changelog)
42
+
43
+ ### v1.0.3 (2026-08-11)
44
+
45
+ - 无额外 children 时主动向 Button 声明 `iconOnly=true`;不再依赖 Logo DOM 自动识别。
46
+
47
+ ### v1.0.2 (2026-08-11)
48
+
49
+ - Apple 状态改用 Apple 品牌 Logo 矢量,不再使用资源 Icon。
50
+ - 修复 SnowUI Logo 未被 Button 判定为 icon-only 导致两种状态左右 padding 不一致;两个状态现在统一使用 Button 原生 icon-only padding。
51
+
52
+ ### v1.0.1 (2026-08-11)
53
+
54
+ - SnowUI / Apple 两个状态恢复为品牌 Logo;Logo 继续跟随 Button 图标尺寸上下文。
55
+
56
+ ### v1.0.0 (2026-08-11)
57
+
58
+ - 首次实现 SnowUI / Apple 风格切换、SnowIcon / Apple Logo 内置图标及 Button 全变体兼容。
@@ -0,0 +1,144 @@
1
+ <!-- StyleButton:以真实 Button 为宿主的 SnowUI / Apple 风格切换按钮。 -->
2
+ <script lang="ts">
3
+ import { onMount, type ComponentProps, type Snippet } from "svelte";
4
+ import Button from "./Button.svelte";
5
+ import StyleButtonLogo from "../internal/StyleButtonLogo.svelte";
6
+ import { useLocale } from "../i18n/locale.svelte";
7
+ import {
8
+ mergeComponentPartProps,
9
+ useComponentPart,
10
+ } from "../logic/component-parts.svelte";
11
+
12
+ export type SnowUIStyleMode = "snowui" | "apple";
13
+
14
+ type ButtonProps = ComponentProps<typeof Button>;
15
+ interface Props extends Omit<
16
+ ButtonProps,
17
+ "children" | "onclick" | "disabled" | "aria-pressed"
18
+ > {
19
+ mode?: SnowUIStyleMode;
20
+ defaultMode?: SnowUIStyleMode;
21
+ applyToDocument?: boolean;
22
+ ariaLabel?: string;
23
+ snowuiLogo?: Snippet;
24
+ appleLogo?: Snippet;
25
+ children?: Snippet;
26
+ disabled?: boolean;
27
+ onModeChange?: (mode: SnowUIStyleMode) => void;
28
+ onclick?: (event: MouseEvent) => void;
29
+ [key: string]: any;
30
+ }
31
+
32
+ const locale = useLocale();
33
+ const inheritedPart = useComponentPart<Props>("StyleButton");
34
+ let { mode = $bindable(), ...explicitProps }: Props = $props();
35
+ let {
36
+ defaultMode = undefined,
37
+ applyToDocument = true,
38
+ ariaLabel = undefined,
39
+ snowuiLogo,
40
+ appleLogo,
41
+ children,
42
+ disabled = false,
43
+ onModeChange,
44
+ onclick,
45
+ ...rest
46
+ }: Props = $derived(
47
+ mergeComponentPartProps(inheritedPart.current, explicitProps),
48
+ );
49
+
50
+ let internalMode = $state<SnowUIStyleMode>("snowui");
51
+ let mounted = $state(false);
52
+ const resolvedMode = $derived(mode ?? internalMode);
53
+ const resolvedAriaLabel = $derived(
54
+ ariaLabel
55
+ ?? locale.t(
56
+ resolvedMode === "apple"
57
+ ? "styleButton.toSnowUI"
58
+ : "styleButton.toApple",
59
+ ),
60
+ );
61
+
62
+ function readDocumentMode(): SnowUIStyleMode {
63
+ return document.documentElement.getAttribute("mode") === "ios"
64
+ ? "apple"
65
+ : "snowui";
66
+ }
67
+
68
+ function applyDocumentMode(nextMode: SnowUIStyleMode) {
69
+ if (!applyToDocument) return;
70
+ if (nextMode === "apple") {
71
+ document.documentElement.setAttribute("mode", "ios");
72
+ } else {
73
+ document.documentElement.removeAttribute("mode");
74
+ }
75
+ }
76
+
77
+ onMount(() => {
78
+ const initialMode = mode
79
+ ?? defaultMode
80
+ ?? (applyToDocument ? readDocumentMode() : "snowui");
81
+ internalMode = initialMode;
82
+ mode = initialMode;
83
+ applyDocumentMode(initialMode);
84
+
85
+ if (!applyToDocument) {
86
+ mounted = true;
87
+ return;
88
+ }
89
+
90
+ const observer = new MutationObserver(() => {
91
+ const nextMode = readDocumentMode();
92
+ internalMode = nextMode;
93
+ if (mode !== nextMode) mode = nextMode;
94
+ });
95
+ observer.observe(document.documentElement, {
96
+ attributes: true,
97
+ attributeFilter: ["mode"],
98
+ });
99
+ mounted = true;
100
+ return () => observer.disconnect();
101
+ });
102
+
103
+ $effect(() => {
104
+ if (!mounted || mode === undefined) return;
105
+ internalMode = mode;
106
+ applyDocumentMode(mode);
107
+ });
108
+
109
+ function handleClick(event: MouseEvent) {
110
+ if (disabled) return;
111
+ onclick?.(event);
112
+ const nextMode = resolvedMode === "apple" ? "snowui" : "apple";
113
+ internalMode = nextMode;
114
+ mode = nextMode;
115
+ applyDocumentMode(nextMode);
116
+ onModeChange?.(nextMode);
117
+ }
118
+ </script>
119
+
120
+ <Button
121
+ {...rest}
122
+ iconOnly={!children}
123
+ {disabled}
124
+ data-style-button
125
+ data-mode={resolvedMode}
126
+ aria-label={resolvedAriaLabel}
127
+ aria-pressed={resolvedMode === "apple"}
128
+ onclick={handleClick}
129
+ >
130
+ {#if resolvedMode === "apple"}
131
+ {#if appleLogo}
132
+ {@render appleLogo()}
133
+ {:else}
134
+ <StyleButtonLogo mode="apple" />
135
+ {/if}
136
+ {:else}
137
+ {#if snowuiLogo}
138
+ {@render snowuiLogo()}
139
+ {:else}
140
+ <StyleButtonLogo mode="snowui" />
141
+ {/if}
142
+ {/if}
143
+ {@render children?.()}
144
+ </Button>
@@ -0,0 +1,39 @@
1
+ export const examples = [
2
+ {
3
+ name: "STB-01: Button 全部变体与尺寸",
4
+ code: `STB-01
5
+ <StyleButton variant="gray" size="sm" />
6
+ <StyleButton variant="filled" size="md" />
7
+ <StyleButton variant="outline" size="lg" />
8
+ <StyleButton variant="borderless" size="sm" />
9
+ <StyleButton bare size="sm" />`,
10
+ expected: {
11
+ interaction: "每个按钮点击后立即在 SnowUI 与 Apple 风格之间切换且没有替换动效",
12
+ render: "SnowUI 状态使用 SnowUI Logo,Apple 状态使用 Apple 品牌 Logo;两者跟随 Button 尺寸并统一使用 icon-only padding",
13
+ },
14
+ logic: ["HostSpecialization", "Variant", "Size", "StyleMode"],
15
+ },
16
+ {
17
+ name: "STB-02: 默认风格与禁用状态",
18
+ code: `STB-02
19
+ <StyleButton defaultMode="apple" variant="gray" />
20
+ <StyleButton variant="outline" disabled />`,
21
+ expected: {
22
+ interaction: "页面从 Apple 风格开始;两个按钮同步显示当前风格,禁用按钮不改变风格",
23
+ },
24
+ logic: ["defaultMode", "Disabled", "AriaPressed"],
25
+ },
26
+ {
27
+ name: "STB-03: Locale 与受控宿主",
28
+ code: `STB-03
29
+ <LocaleProvider locale="en-US">
30
+ <StyleButton mode="snowui" applyToDocument={false} bare>
31
+ <Text>Style</Text>
32
+ </StyleButton>
33
+ </LocaleProvider>`,
34
+ expected: {
35
+ render: "按钮使用英文切换名称和可见内容;显式状态不修改 document",
36
+ },
37
+ logic: ["LocaleProvider", "ExplicitMode", "children"],
38
+ },
39
+ ] as const;
@@ -182,7 +182,7 @@ TableCell 默认 `lines={1}`,原始文字不需要再包一层 Text。行 hove
182
182
 
183
183
  `roleLayout="overlay"` 适合宽表或需要边缘悬浮操作的场景。表头全选框只在 hover 数据行、hover 首个数据列表头(Date)、聚焦/直接 hover 全选框自身或存在选中态时显示(详见上文「选择归属」);行动按钮只在该行 hover 时显示,不因行被选中而保持显示。
184
184
 
185
- 行动按钮(actions 列)被包裹在 `.snowui-table-role-overlay-controls` 容器内:表格的显隐渐变作用在这个**包裹层**的 `opacity` 上,而不是直接作用在按钮元素上。因此按钮自身的 `opacity`(如 `Button bare` 常态 40%、hover 100%)得以保留并与包裹层的渐变相乘,避免表格的 `opacity:1` 覆盖掉按钮自身的状态透明度导致图标按钮失去 hover 反馈。
185
+ 行动按钮(actions 列)被包裹在 `.snowui-table-role-overlay-controls` 容器内:表格的显隐渐变作用在这个**包裹层**的 `opacity` 上,而不是直接作用在按钮元素上。因此按钮自身的 `opacity`(次级操作应使用 `Button bare emphasis="muted"`,常态 40%、hover 100%)得以保留并与包裹层的渐变相乘,避免表格的 `opacity:1` 覆盖掉按钮自身的状态透明度导致图标按钮失去 hover 反馈。
186
186
 
187
187
  ## Keyword
188
188
 
@@ -250,7 +250,7 @@ TableCell 默认 `lines={1}`,原始文字不需要再包一层 Text。行 hove
250
250
 
251
251
  - 2026-06-27:v1.4.4,让表头第一列标题(Date 列)的「hover 边缘渐进式透明」触发条件与表头全选 Checkbox 的出现条件完全对齐:仅在 hover 数据行 / hover 该列表头 / hover|聚焦全选浮层 / 存在选中态时渐隐;全选 Checkbox 未出现时表头不再渐隐(此前为「鼠标进入表格即渐隐」)。
252
252
 
253
- - 2026-06-27:v1.4.3,两项修复:(1) 进一步收敛表头全选 Checkbox 的出现规则——改为仅在 hover 任意数据行、hover 首个数据列表头(overlay 下的 Date 列)、直接 hover/聚焦全选框自身或存在选中态时显示;hover 其他表头列(Stores 等)不再显示。(2) 修复 overlay 行动按钮(actions 列)图标按钮失去 hover 反馈的问题:将按钮包进 `.snowui-table-role-overlay-controls` 包裹层,表格的显隐渐变作用于包裹层 `opacity` 而非按钮元素本身,使 `Button bare` 的常态 40% / hover 100% 透明度得以保留(两层 `opacity` 相乘而非在同一元素上冲突)。
253
+ - 2026-06-27:v1.4.3,两项修复:(1) 进一步收敛表头全选 Checkbox 的出现规则——改为仅在 hover 任意数据行、hover 首个数据列表头(overlay 下的 Date 列)、直接 hover/聚焦全选框自身或存在选中态时显示;hover 其他表头列(Stores 等)不再显示。(2) 修复 overlay 行动按钮(actions 列)图标按钮失去 hover 反馈的问题:将按钮包进 `.snowui-table-role-overlay-controls` 包裹层,表格的显隐渐变作用于包裹层 `opacity` 而非按钮元素本身,使弱化 bare 操作的常态 40% / hover 100% 透明度得以保留(两层 `opacity` 相乘而非在同一元素上冲突;2026-08-09 起需显式写 `emphasis="muted"`)。
254
254
 
255
255
  - 2026-06-27:v1.4.2,调整表头全选 Checkbox 的出现规则:由「鼠标进入表格视口(`.snowui-table-viewport:hover`)即显示」改为「hover 到任意表格行(`.snowui-table-viewport:has(.snowui-table-row:hover)`)、行内键盘聚焦或存在选中态时才显示」,与行内 Checkbox 的可见时机保持一致。因表头本身也是一行,触发条件天然涵盖表头行,从而保证指针从数据行上移到表头时全选框仍可见、可点击。
256
256
 
@@ -42,7 +42,10 @@
42
42
  const truncationManager = new TableTruncationManager();
43
43
 
44
44
  provideTableContext({
45
- getColumnWidth: (columnId) => columnWidths[columnId] ?? autoLockedColumnWidths[columnId],
45
+ getColumnWidth: (columnId) =>
46
+ columnWidths[columnId]
47
+ ?? autoLockedColumnWidths[columnId]
48
+ ?? parentTable.getColumnWidth(columnId),
46
49
  setColumnWidth: (columnId, width) => {
47
50
  columnWidths = { ...columnWidths, [columnId]: Math.round(width) };
48
51
  onColumnWidthsChange?.(columnWidths);
@@ -14,6 +14,7 @@
14
14
  import Tooltip from "./Tooltip.svelte";
15
15
  import Checkbox from "./Checkbox.svelte";
16
16
  import Skeleton from "./Skeleton.svelte";
17
+ import OverflowActions from "./OverflowActions.svelte";
17
18
  import { resizeManager } from "../logic/observer.svelte";
18
19
  import { getTableContext, type TableRoleLayout } from "../lib/table-context.svelte";
19
20
  import { getTableRowContext } from "../lib/table-row-context.svelte";
@@ -73,6 +74,12 @@
73
74
  table.isDataTable() && actionsEnabled && resolvedRoleLayout === "overlay",
74
75
  );
75
76
  const width = $derived(resolvedColumnId ? table.getColumnWidth(resolvedColumnId) : undefined);
77
+ const defaultActions = $derived(
78
+ isActionsRole && rowId !== undefined ? table.getRowActions(rowId) : [],
79
+ );
80
+ const actionsAvailableWidth = $derived(
81
+ Math.max(0, (width ?? table.getActionsColumnWidth()) - 24),
82
+ );
76
83
  const resolvedLines = $derived(skeleton || isSelectionRole || isActionsRole || lines === false ? undefined : lines);
77
84
  const contextRowAppearMotion = $derived(
78
85
  !skeleton && !isSelectionRole && !isActionsRole && rowId !== undefined
@@ -225,14 +232,19 @@
225
232
  reset();
226
233
  };
227
234
  });
228
- const finalStyle = $derived(`${width ? `--snowui-table-cell-width-runtime:${width}px;width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));min-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));max-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime))` : ""};text-align:${align};${userStyle}`);
235
+ const runtimeWidth = $derived(
236
+ (isSelectionRole || isActionsRole) && resolvedRoleLayout === "overlay"
237
+ ? undefined
238
+ : width,
239
+ );
240
+ const finalStyle = $derived(`${runtimeWidth ? `--snowui-table-cell-width-runtime:${runtimeWidth}px;width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));min-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));max-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime))` : ""};text-align:${align};${userStyle}`);
229
241
  // actions 的遮罩依赖每行实测后写入的宽度变量,必须在内容单元格自身计算。
230
242
  // 若把这条表达式定义在 Table 根上,根节点无法读取后代行上的变量,整条 mask 会失效。
231
243
  const contentStyle = $derived(
232
244
  `${gap === undefined
233
245
  ? ""
234
246
  : `gap:${typeof gap === "number" ? `var(--gap-${gap}, calc(var(--gap-1) * ${gap}))` : gap};`}` +
235
- `${hasActionsOverlay ? `--snowui-table-cell-actions-fade-mask:${actionsFadeMask};` : ""}`,
247
+ `${hasActionsOverlay ? `--snowui-table-cell-actions-fade-mask:${actionsFadeMask};--snowui-table-role-overlay-width-override:${width ?? table.getActionsColumnWidth()}px;` : ""}`,
236
248
  );
237
249
  const selectionBlur = $derived(getTableRoleBlurStyles(table, "left-to-right"));
238
250
  const actionsBlur = $derived(getTableRoleBlurStyles(table, "right-to-left"));
@@ -290,7 +302,22 @@
290
302
  <span style={layer.style}></span>
291
303
  {/each}
292
304
  </span>
293
- <span class="snowui-table-role-overlay-controls">{#if children}{@render children()}{/if}</span>
305
+ <span class="snowui-table-role-overlay-controls">{#if children}
306
+ {@render children()}
307
+ {:else if rowId !== undefined && defaultActions.length > 0}
308
+ <OverflowActions
309
+ items={defaultActions}
310
+ compact={table.getActionsCompact()}
311
+ overflow={table.getActionsOverflow()}
312
+ overflowFrom={table.getActionsOverflowFrom()}
313
+ availableWidth={actionsAvailableWidth}
314
+ onAction={({ id, item }) => table.runRowAction({
315
+ rowId,
316
+ actionId: id,
317
+ item,
318
+ })}
319
+ />
320
+ {/if}</span>
294
321
  </span>
295
322
  {:else}<span use:registerTruncation={{ enabled: resolvedLines === 1, onChange: onTruncate }} class={`snowui-table-cell-content ${resolvedLines ? `snowui-line-clamp-${resolvedLines}` : ""}`} data-row={row ? "true" : undefined} data-nowrap={nowrap ? "true" : undefined} data-lines={resolvedLines} data-truncated={isTruncated ? "true" : "false"} style={contentStyle}>
296
323
  {#if children}{@render children()}{/if}
@@ -332,7 +359,7 @@
332
359
  :global(:where(.snowui-table-cell-content[data-actions="true"])) { opacity: 0; pointer-events: none; transition: opacity var(--snowui-frame-color-motion-duration, .15s) var(--snowui-frame-color-motion-easing, ease-out); }
333
360
  :global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(:focus-visible), .snowui-table-row[data-selected="true"]) .snowui-table-cell[data-as="selection"] .snowui-table-selection-control),
334
361
  :global(:where(.snowui-table-cell[data-as="selection"] .snowui-table-selection-control[data-selected="true"])) { opacity: 1; pointer-events: auto; }
335
- :global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"]) .snowui-table-cell:not([data-role-layout="overlay"]) .snowui-table-cell-content[data-actions="true"]) { opacity: 1; pointer-events: auto; }
362
+ :global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(.snowui-select-button-trigger[aria-expanded="true"])) .snowui-table-cell:not([data-role-layout="overlay"]) .snowui-table-cell-content[data-actions="true"]) { opacity: 1; pointer-events: auto; }
336
363
  :global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="selection"])),
337
364
  :global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="actions"])) { position: sticky; width: 0; min-width: 0; max-width: 0; padding: 0; overflow: visible; background: transparent; z-index: 3; }
338
365
  :global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="selection"])) { left: 0; }
@@ -364,7 +391,7 @@
364
391
  :global(:where(.snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"]) > :not(.snowui-table-role-blur-layer)) { opacity: 0; pointer-events: none; transition: opacity var(--snowui-frame-color-motion-duration, .15s) var(--snowui-frame-color-motion-easing, ease-out); }
365
392
  :global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(:focus-visible), .snowui-table-row[data-selected="true"]) .snowui-table-cell[data-role-layout="overlay"][data-as="selection"] .snowui-table-selection-control > :not(.snowui-table-role-blur-layer)),
366
393
  :global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="selection"] .snowui-table-selection-control[data-selected="true"]) > :not(.snowui-table-role-blur-layer)),
367
- :global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"]) .snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"] > :not(.snowui-table-role-blur-layer)) { opacity: 1; pointer-events: auto; }
394
+ :global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(.snowui-select-button-trigger[aria-expanded="true"])) .snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"] > :not(.snowui-table-role-blur-layer)) { opacity: 1; pointer-events: auto; }
368
395
  :global(:where(.snowui-table-cell[data-table-variant="striped"])) { border-bottom-color: transparent; }
369
396
  :global(:where(.snowui-table-body .snowui-table-row:nth-child(odd)) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--snowui-table-row-active-background, var(--surface-3, #f7f7f7)); }
370
397
  :global(:where(.snowui-table-body .snowui-table-row:nth-child(even)) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--snowui-table-row-active-background, transparent); }
@@ -23,14 +23,14 @@ export const examples = [
23
23
  {
24
24
  name: "A4: 选择与行动单元格角色",
25
25
  code: `A4
26
- <Table selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell as="actions"><Button bare>更多</Button></TableCell></TableRow></TableBody></Table>`,
26
+ <Table selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell as="actions"><Button bare emphasis="muted">更多</Button></TableCell></TableRow></TableBody></Table>`,
27
27
  expected: { render: "selection 内置行 Checkbox;actions 渲染调用方按钮。", layout: "selection Checkbox 默认 17px,在奇数高度行内上下留白对称;actions 横向排列且 gap 8px。", interaction: "Checkbox 在 hover/focus/selected 时显示;actions 只在 hover 时显示。", performance: "无 DOM 身份猜测。", responsive: "角色列保持窄宽。" },
28
28
  logic: ["Selection", "Actions"],
29
29
  },
30
30
  {
31
31
  name: "A5: 覆盖式角色单元格",
32
32
  code: `A5
33
- <Table roleLayout="overlay" selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell>SnowUI</TableCell><TableCell as="actions"><Button bare>更多</Button></TableCell></TableRow></TableBody></Table>`,
33
+ <Table roleLayout="overlay" selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell>SnowUI</TableCell><TableCell as="actions"><Button bare emphasis="muted">更多</Button></TableCell></TableRow></TableBody></Table>`,
34
34
  expected: { render: "selection/actions 仍保持合法 td。", layout: "角色 td 宽度归零,17px Checkbox 在覆盖块内垂直居中,覆盖块 sticky 到行左右边缘并用透明模糊渐变柔化后方内容。", interaction: "已选行 Checkbox 保持显示,actions 仍只在行 hover 时显示。", performance: "选择状态直接来自 rowId + Table Context,不创建逐单元格 MutationObserver。", responsive: "不改变普通内容列宽。" },
35
35
  logic: ["Selection", "Actions", "OverlayRoleLayout"],
36
36
  },