@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
@@ -1,6 +1,6 @@
1
1
  # Badge.svelte 文档
2
2
 
3
- > **版本**: v1.2.8
3
+ > **版本**: v1.3.1
4
4
  > **职责**: 徽标组件,用于显示数字或状态指示。
5
5
 
6
6
  **继承**: 复用 Frame.svelte 的所有通用能力 (交互、动效、响应式)。
@@ -10,6 +10,7 @@
10
10
 
11
11
  | 属性 | 类型 | 默认值 | 描述 |
12
12
  | :--- | :--- | :--- | :--- |
13
+ | variant | `"filled" \| "border"` | `"filled"` | 视觉变体。`border` 与 Kbd 默认 `border` 视觉一致:透明背景、内描边、继承文字色、0×4px padding 与 6px 圆角 |
13
14
  | count | number \| string | undefined | 显示的数字或文本。默认 count 模式仅在值大于等于 1 时出现,`0` 不显示 |
14
15
  | stateCount | `StateValueMap<number \| string>` | undefined | 根据最近父级 Frame 状态映射 `count`,用于声明式控制 Badge 显隐 |
15
16
  | dot | boolean | false | 是否显示为小圆点模式 |
@@ -48,12 +49,26 @@ Badge 的根节点是 inline-level 定位外壳,内容整体 Hug:
48
49
  | `--snowui-badge-dot-size` | `calc(var(--size-4) * 1.5 / 4)` | 点模式尺寸 |
49
50
  | `--snowui-badge-background` | `resolveSnowUIColor(color)` | 数字和 Dot 模式的填充色 |
50
51
 
52
+ `variant="border"` 复用 Kbd 默认描边视觉的同一组 Token 值,但仍保持 Badge 的状态标签语义与 `<span>`/Frame 外壳:
53
+
54
+ | 属性 | `border` 值 |
55
+ | :--- | :--- |
56
+ | Padding | `var(--padding-0) var(--padding-1)`(0px 4px) |
57
+ | Radius | `calc(var(--radius-1) * 1.5)`(6px) |
58
+ | Font / Line height | `var(--text-12)` / `var(--leading-12)` |
59
+ | Background / Color | `transparent` / `inherit` |
60
+ | Border | `inset 0 0 0 var(--border-1) var(--black-10)` |
61
+
62
+ `border` 只作用于文本内容模式;`dot` 继续使用 Dot 视觉。作为 Button、SidebarItem 等宿主的后代时,`border` 保持文本 Hug,不继承宿主的固定方形尺寸上下文。
63
+ `border` 的内部 morph 文字层继承 `var(--leading-12)`,不使用 filled Badge 的紧凑 `line-height: 1`;因此可见高度与 Kbd 默认 border 一致。
64
+
51
65
  `color` 使用 SnowUI 公共语意色协议,严格区分大小写:
52
66
 
53
67
  ```svelte
54
68
  <Badge count={1} color="Blue" />
55
69
  <Badge count={2} color="Red" />
56
70
  <Badge dot color="Green" />
71
+ <Badge count="PRO" variant="border" />
57
72
  ```
58
73
 
59
74
  ## 角色化组合
@@ -125,6 +140,10 @@ Badge 的显示 / 隐藏使用两条并行动效,与 transitions.dev Notificat
125
140
  | **Min Width** | `1.125rem` | 18px |
126
141
  | **Z-Index** | `10` | 确保在父元素上方 |
127
142
 
143
+ ### 1.1 描边样式 (`variant="border"`)
144
+
145
+ 描边样式与 Kbd 默认 `border` 视觉保持一致,但 Badge 继续表达状态/分类,不输出 `<kbd>` 语义。背景透明、文字继承父级颜色,并使用 1px inset shadow 表达不占布局空间的边框。
146
+
128
147
  ### 2. 点模式 (Dot Mode)
129
148
 
130
149
  当 `dot` 属性启用时,Badge 切换为小圆点模式:
@@ -142,7 +161,7 @@ Badge 的显示 / 隐藏使用两条并行动效,与 transitions.dev Notificat
142
161
  组件内部使用 `Grid Stacking` (Morph Container) 确保布局稳定性:
143
162
 
144
163
  - **Container**: `display: grid; width: 100%; height: 100%;`
145
- - **Item**: `display: flex; align-items: center; justify-content: center; line-height: 1;`
164
+ - **Item**: `display: flex; align-items: center; justify-content: center;`;filled / dot 使用 `line-height: 1`,border 继承 surface 的 `var(--leading-12)`
146
165
 
147
166
  ---
148
167
 
@@ -162,6 +181,16 @@ Badge 的显示 / 隐藏使用两条并行动效,与 transitions.dev Notificat
162
181
 
163
182
  ## 更新日志 (Changelog)
164
183
 
184
+ ### v1.3.1 (2026-07-30)
185
+
186
+ #### 修复
187
+ - Border 变体内部文字层改为继承 16px 行高,避免通用 morph-item 将实际高度压缩到 12px;PRO 标签现在与 Kbd 默认 border 高度一致。
188
+
189
+ ### v1.3.0 (2026-07-30)
190
+
191
+ #### 新功能
192
+ - 新增 `variant="border"`,复用 Kbd 默认描边视觉的 Token、padding、圆角、字号与行高,用于 PRO、updated 等状态/分类标签;默认 `filled` 行为不变。
193
+
165
194
  - **Badge-Motion.2026-06-18** 按 transitions.dev Notification badge 的双层结构还原默认动效:Frame 根层执行左下偏移进场,完整视觉 surface 执行中心 scale / opacity / blur;退场时 surface 整体缩小,而不是只缩放数字内容。
166
195
  - **Badge-Motion.2026-06-30** 统一 `while*` 完整视觉通道语义:显式对象不再浅合并 Badge 默认 x / y / scale / opacity,只继承默认时序 / 动力学参数。
167
196
 
@@ -1,5 +1,5 @@
1
1
  <!--
2
- Badge 组件:徽标组件 v1.2.8
2
+ Badge 组件:徽标组件 v1.3.1
3
3
 
4
4
  继承 Frame.svelte 的通用能力 (交互、动效、响应式)。
5
5
  详见:Badge.md
@@ -74,6 +74,7 @@
74
74
  }
75
75
 
76
76
  interface Props extends FrameProps {
77
+ variant?: "filled" | "border";
77
78
  count?: number | string;
78
79
  stateCount?: StateValueMap<number | string>;
79
80
  dot?: boolean;
@@ -86,6 +87,7 @@
86
87
  }
87
88
 
88
89
  let {
90
+ variant = "filled",
89
91
  count = undefined,
90
92
  stateCount = undefined,
91
93
  dot = undefined,
@@ -349,6 +351,7 @@
349
351
  });
350
352
 
351
353
  const badgeFixedSizeToken = $derived.by(() => {
354
+ if (variant === "border") return undefined;
352
355
  // Resolve Size:
353
356
  // If it's a badge role (inside Avatar/Icon), we don't want the parent Group's size as our FIXED size
354
357
  // unless it's explicitly passed as a prop.
@@ -389,7 +392,9 @@
389
392
  : "",
390
393
  dimStyle,
391
394
  fontInheritStyle,
392
- `--snowui-badge-background: ${resolveSnowUIColor(color)}`,
395
+ variant !== "border" || effectiveDot
396
+ ? `--snowui-badge-background: ${resolveSnowUIColor(color)}`
397
+ : "",
393
398
  userStyle,
394
399
  ]
395
400
  .filter(Boolean)
@@ -400,6 +405,13 @@
400
405
  );
401
406
  const badgeRenderHints = $derived.by(() => {
402
407
  const base = (() => {
408
+ if (variant === "border") {
409
+ return {
410
+ variant: "line" as const,
411
+ height: "var(--leading-12)",
412
+ radius: "calc(var(--radius-1) * 1.5)",
413
+ };
414
+ }
403
415
  if (effectiveDot) {
404
416
  const dotSize = badgeFixedSizeToken ??
405
417
  "calc(var(--size-4) * 1.5 / 4)";
@@ -451,6 +463,9 @@
451
463
  className,
452
464
  isBadgeRole ? "snowui-badge-role" : "",
453
465
  effectiveDot ? "snowui-badge-dot" : "",
466
+ variant === "border" && !effectiveDot
467
+ ? "snowui-badge-border"
468
+ : "",
454
469
  "snowui-badge-motion",
455
470
  shouldBindBadgeFixedSize ? "snowui-badge-size-bound" : "",
456
471
  ]
@@ -507,6 +522,8 @@
507
522
  --snowui-badge-radius: var(--radius-full);
508
523
  --snowui-badge-font-size: var(--text-12);
509
524
  --snowui-badge-line-height: 1;
525
+ --snowui-badge-foreground: var(--static-white-100, #ffffffff);
526
+ --snowui-badge-shadow: none;
510
527
 
511
528
  }
512
529
 
@@ -519,7 +536,7 @@
519
536
  --snowui-badge-background,
520
537
  var(--secondary-indigo, #adadfbff)
521
538
  );
522
- color: var(--static-white-100, #ffffffff);
539
+ color: var(--snowui-badge-foreground);
523
540
  width: fit-content;
524
541
  height: auto;
525
542
  min-width: var(
@@ -542,9 +559,27 @@
542
559
  --snowui-badge-radius-override,
543
560
  var(--snowui-badge-radius)
544
561
  );
562
+ box-shadow: var(--snowui-badge-shadow);
545
563
  white-space: nowrap;
546
564
  }
547
565
 
566
+ /* Level 4: Border 变体确权(与 Kbd 默认 border 视觉一致,仅更新变量) */
567
+ :global(:where(.snowui-badge).snowui-badge-border) {
568
+ --snowui-badge-padding: var(--padding-0) var(--padding-1);
569
+ --snowui-badge-radius: calc(var(--radius-1) * 1.5);
570
+ --snowui-badge-font-size: var(--text-12);
571
+ --snowui-badge-line-height: var(--leading-12);
572
+ --snowui-badge-background: transparent;
573
+ --snowui-badge-foreground: inherit;
574
+ --snowui-badge-shadow: inset 0 0 0 var(--border-1)
575
+ var(--black-10, rgba(0, 0, 0, 0.1));
576
+ }
577
+
578
+ /* Border 文本层继承 16px 行高,避免通用 morph-item 的紧凑 line-height: 1 将高度压回 12px。 */
579
+ :global(:where(.snowui-badge-border) .snowui-morph-item) {
580
+ line-height: inherit;
581
+ }
582
+
548
583
  /* transitions.dev Notification badge:Frame 根层滑动,视觉 surface 整体 pop。 */
549
584
  :global(:where(.snowui-badge-motion > .snowui-badge-surface)) {
550
585
  transform-origin: center;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Badge.test.ts
3
- * v1.2.0
3
+ * v1.3.1
4
4
  *
5
5
  * 测试覆盖:Badge.md 定义的所有功能点
6
6
  */
@@ -62,6 +62,19 @@ export const examples = [
62
62
  },
63
63
  logic: ["Color", "SemanticColor", "Dot"],
64
64
  },
65
+ {
66
+ name: "A6: 描边状态标签 (Border)",
67
+ code: `A6
68
+ <div class="flex-row gap-8 items-center">
69
+ <Kbd>PRO</Kbd>
70
+ <Badge count="PRO" variant="border" />
71
+ <Badge count="updated" variant="border" />
72
+ </div>`,
73
+ expected: {
74
+ render: "Kbd 与两个 Badge 使用一致的 12/16px 排版、16px 可见高度、透明背景、内描边、继承文字色、0×4px padding 与 6px 圆角。",
75
+ },
76
+ logic: ["Variant", "Border", "Status"],
77
+ },
65
78
  // === C: 组合模式 ===
66
79
  {
67
80
  name: "C1: 在 Icon 中作为徽标",
@@ -1,6 +1,8 @@
1
1
  # Button.svelte 文档
2
2
 
3
- > **版本**: v2.3.2
3
+ > **版本**: v2.5.0
4
+ > **变更记录 (2026-08-11)**: 新增显式 `iconOnly` 布局声明,默认 `false`;移除基于 children DOM 的自动推断,并为缺少可访问名称的 icon-only Button 提供开发警告。
5
+ > **变更记录 (2026-08-09)**: `bare` 默认改为 100% 不透明;新增 `emphasis="muted"` 显式启用 40% → hover 100% 的弱化交互。
4
6
  > **变更记录 (2026-07-08)**: Button 默认最小宽度改为 `max-content`,保留“文字 + gap + padding”的自然下限,避免 fill 布局吞掉默认 padding。
5
7
  > **变更记录 (2026-07-08)**: 文字型 Button 默认 `white-space: nowrap`,避免在 Pagination 等压缩布局中被中文逐字换行。
6
8
  > **变更记录 (2026-06-01)**: 移除 `variant="link"`;文字链接统一迁移到独立 [Link.svelte](./Link.svelte)。
@@ -16,7 +18,9 @@
16
18
  | :--- | :--- | :--- | :--- |
17
19
  | variant | 'gray'\|'filled'\|'outline'\|'borderless' | 'gray' | 按钮变体样式 |
18
20
  | size | 'sm'\|'md'\|'lg' | 'sm' | 按钮尺寸 |
19
- | bare | `boolean` | `false` | 开启无外壳按钮模式,内容可包含文字、Icon 或其他元素。忽略 `variant`,移除 padding / radius / 背景 / 边框与 hover overlay,保留普通 Button 的内容 gap;前景色继承 `currentColor`,默认透明度 40%,hover 提升到 100%。单 Icon 时自动使用当前 `size` 档位的 12/16/20px Icon 尺寸上下文,并提供至少 16×16px 的透明点击热区。精确 Icon 尺寸由子 Icon 自己声明。放入 Tab 时由 Tab 的 Button opacity override 接管透明度,不发生叠乘。 |
21
+ | iconOnly | `boolean` | `false` | 明确启用单视觉内容布局。使用对称 icon-only padding 与放大一级的尺寸上下文;不检查 children 类型。缺少 `aria-label`、`aria-labelledby` 或 `title` 时开发环境警告。 |
22
+ | bare | `boolean` | `false` | 开启无外壳按钮模式,内容可包含文字、Icon 或其他元素。忽略 `variant`,移除 padding / radius / 背景 / 边框与 hover overlay,保留普通 Button 的内容 gap;前景色继承 `currentColor`,默认保持 100% 不透明。与 `iconOnly` 同时使用时采用当前 `size` 档位的 12/16/20px 视觉尺寸上下文,并提供至少 16×16px 的透明点击热区。精确尺寸由子视觉自己声明。放入 Tab 时由 Tab 的 Button opacity override 接管透明度,不发生叠乘。 |
23
+ | emphasis | `'normal'\|'muted'` | `'normal'` | bare 模式的视觉强调级别。`normal` 常态与 hover 均为 100%;`muted` 常态为 40%,hover 提升到 100%。非 bare 模式下不改变现有 variant 视觉。 |
20
24
  | backgroundBlur | `boolean` | `false` | 是否模糊按钮背后的内容。开启时使用与 BarChart 模糊浮层一致的 `backdrop-filter: blur(1.25rem)`。 |
21
25
  | toggle | boolean | `false` | Toggle 模式语法糖。内部自动注入 `Click={{ Idle: "Active", Active: "Idle" }}` 与 `whileClick=false`;Active 状态下由 Frame 自动暴露的 `data-state="Active"` 触发 Secondary/Indigo 配色(gray / outline / borderless 生效,filled 排除);`aria-pressed` 由 Frame 自动输出。消费方可继续传 `Click` / `whileClick` 显式覆盖。 |
22
26
  | href | string | undefined | 链接地址 (渲染为 a 标签) |
@@ -29,7 +33,9 @@
29
33
  | :--- | :--- | :--- | :--- |
30
34
  | variant | `'gray' \| 'filled' \| 'outline' \| 'borderless'` | `'gray'` | 按钮变体 |
31
35
  | size | `'sm' \| 'md' \| 'lg'` | `'sm'` | 按钮尺寸 |
32
- | bare | `boolean` | `false` | 无外壳按钮模式,不限制内容类型。忽略 `variant`,外壳 padding / radius 为 0,保留内容 gap;单 Icon 自动获得尺寸上下文与最小透明点击热区。颜色使用 `currentColor × opacity: 0.4 -> 1`。 |
36
+ | iconOnly | `boolean` | `false` | 显式选择单视觉内容布局;未声明时始终按普通内容按钮处理。 |
37
+ | bare | `boolean` | `false` | 无外壳按钮模式,不限制内容类型。忽略 `variant`,外壳 padding / radius 为 0,保留内容 gap;与 `iconOnly` 同时使用时获得对应尺寸上下文与最小透明点击热区。默认使用 `currentColor × opacity: 1`。 |
38
+ | emphasis | `'normal'\|'muted'` | `'normal'` | bare 的强调级别;`muted` 使用 `currentColor × opacity: 0.4 -> 1`。 |
33
39
  | backgroundBlur | `boolean` | `false` | 开启按钮背景模糊,默认强度为 `1.25rem`。 |
34
40
  | toggle | `boolean` | `false` | Toggle 模式语法糖。等价于显式声明 `Click={{ Idle: "Active", Active: "Idle" }} whileClick={false}`;Active 配色由 `data-state="Active"` 自动套 Indigo;`aria-pressed` 自动输出。 |
35
41
  | as | `'more' \| 'badge' \| 'icon' \| 'prev' \| 'next' \| 'close' \| 'item' \| 'current' \| 'page' \| 'leading' \| 'trailing'` | - | 角色化:作为 Text 展开按钮、Breadcrumb item、Pagination 模板,或接入 Image / ImageViewer / Field 宿主定位协议;进入 Image / ImageViewer 宿主时会翻译为对应 `pin-*` 方位 |
@@ -45,12 +51,13 @@ Button 的内部布局不接入三槽位模型:
45
51
  - 文字型 Button 默认 `white-space: nowrap`,保证按钮文案作为一个操作短语保持单行;特殊长文案可由使用方通过外部 style / class 显式覆盖。
46
52
  - 默认最小宽度为 `max-content`,即“内容 + gap + padding”的自然下限;外层 fill 布局可以把 Button 拉宽,但不能把 Button 压到吞掉默认 padding。
47
53
  - Button 自身负责 padding / gap / radius / font-size / line-height,并通过 `--snowui-button-*-override` 变量允许外部覆盖。
54
+ - `iconOnly` 是单视觉内容布局的唯一开关,默认 `false`;Button 不读取 children 的 DOM 类型推断该状态。内容可以是 Icon、Logo 或其他单一视觉原子。
48
55
  - `as="leading"` / `as="trailing"` 只表示 Button 作为 Field / Input 等外层槽位宿主的配件;不会改变 Button 内部布局模型。
49
56
  - `as="item"` 表示 Button 作为 Breadcrumb 的路径片段;当前页不可交互规则由 Breadcrumb 标记 `aria-current="page"` 后触发。Button 未显式写 `variant` 时可继承 Breadcrumb 的 `variant`,显式 Button `variant` 优先。
50
57
  - `as="current"` / `as="page"` / `as="prev"` / `as="next"` 放入 Pagination 时表示角色样式模板;真实页码、可点击性与边界状态由 Pagination 生成和管理。
51
- - `bare` 是不限制内容类型的无外壳特化:保持当前字号 / 行高与普通内容 gap,固定清零 padding / radius,并使用 `currentColor × opacity: 0.4 -> 1` 表达交互。
58
+ - `bare` 是不限制内容类型的无外壳特化:保持当前字号 / 行高与普通内容 gap,固定清零 padding / radius,并默认使用 `currentColor × opacity: 1`;仅 `emphasis="muted"` 使用 `0.4 -> 1` 表达次级操作。
52
59
  - `as="pageSize"` 可作为 Pagination 的每页条数视觉模板;Pagination 会注入当前数值和 `ArrowLineDown`,并用内置 Listbox 接管交互。Icon 作为 Button 普通内容,不使用 `as="trailing"`,间距由 Button 内容 gap 控制。
53
- - `bare` 内容为单 Icon 时自动注入当前档位的 12/16/20px Icon 尺寸上下文,并通过透明伪元素保证至少 16×16px 的点击热区;精确尺寸直接写在子 Icon 上。
60
+ - `bare iconOnly` 显式注入当前档位的 12/16/20px 尺寸上下文,并通过透明伪元素保证至少 16×16px 的点击热区;精确尺寸直接写在子视觉上。
54
61
  - 当 Button 作为 `ButtonGroup` 的直系子项时,自动进入嵌入态:保留独立点击、链接、状态与内容 gap,退掉自身背景、边框和圆角,并接收 ButtonGroup 分配的单元格 padding。
55
62
 
56
63
  布局变量链:
@@ -81,13 +88,15 @@ Button 的内部布局不接入三槽位模型:
81
88
  <!-- 无外壳按钮,可包含任意内容 -->
82
89
  <Button bare>Random</Button>
83
90
  <Button bare><Icon><Shuffle /></Icon>Random</Button>
84
- <Button bare aria-label="展开"><ArrowLineDown size={16} /></Button>
91
+ <Button iconOnly aria-label="展开"><ArrowLineDown /></Button>
92
+ <Button bare iconOnly aria-label="展开"><ArrowLineDown size={16} /></Button>
93
+ <Button bare iconOnly emphasis="muted" aria-label="次级操作"><ArrowLineDown size={16} /></Button>
85
94
  <Button backgroundBlur>背景模糊按钮</Button>
86
95
 
87
96
  <!-- 日期选择触发器 -->
88
97
  <Field>
89
98
  <Input type="date" />
90
- <Button bare as="trailing">
99
+ <Button bare iconOnly as="trailing" aria-label="打开日期选择">
91
100
  <ArrowLineDown size={16} />
92
101
  </Button>
93
102
  </Field>
@@ -120,7 +129,7 @@ Button 放入 ButtonGroup 后不需要写额外 prop:
120
129
  - 嵌入态会接收 ButtonGroup 分配的单元格 padding,让 hover / 点击响应覆盖完整单元格,而不是只覆盖内部图标和文字。
121
130
  - 单元格首尾位置由 ButtonGroup 自动标记,不需要在 Button 上手写 `as="first"` / `as="last"`。
122
131
  - 嵌入态仍保留 `href` / `target` / `rel`、状态机、动效与 `aria-*` 等 Button 既有能力。
123
- - 纯图标单元格仍可由 Button 的 icon-only 识别处理;ButtonGroup 嵌入态会覆盖 icon-only padding,确保图标单元格的点击和 hover 区域与普通单元格一致。
132
+ - 纯图标单元格必须在 Button 上显式声明 `iconOnly`;ButtonGroup 嵌入态会覆盖 icon-only padding,确保图标单元格的点击和 hover 区域与普通单元格一致。
124
133
 
125
134
  ## Toggle 与瞬时反馈 (声明式)
126
135
 
@@ -222,7 +231,7 @@ OSS Button **自动输出 `aria-pressed`**:
222
231
  <!-- 简单场景:自动推断 -->
223
232
  <Field>
224
233
  <Input type="date" />
225
- <Button bare as="trailing">
234
+ <Button bare iconOnly as="trailing" aria-label="打开日期选择">
226
235
  <ArrowLineDown size={16} />
227
236
  </Button>
228
237
  </Field>
@@ -231,7 +240,7 @@ OSS Button **自动输出 `aria-pressed`**:
231
240
  <Field>
232
241
  <Frame as="row" row>
233
242
  <Input type="date" />
234
- <Button bare as="trailing">
243
+ <Button bare iconOnly as="trailing" aria-label="打开日期选择">
235
244
  <ArrowLineDown size={16} />
236
245
  </Button>
237
246
  </Frame>
@@ -283,8 +292,8 @@ Button 放入 Pagination 时使用角色模板:
283
292
 
284
293
  > **备注**:
285
294
  > 1. 常规按钮包含文字时,挂载的 `Icon` 等资源尺寸会优先等比缩小一号(`sm: 12`, `md: 16`, `lg: 20`)以匹配文本字号。
286
- > 2. 当按钮为纯图标按钮 (`isIconOnly`) 时,内部挂载的资源图标会自动放大一级以撑满空间:`sm: 16`, `md: 20`, `lg: 24`。
287
- > 3. `bare` 单 Icon 内容使用当前 `size` 档位的常规 Icon 尺寸(`sm -> 12`,`md -> 16`,`lg -> 20`);子 Icon 显式声明 `size` 时优先使用自身尺寸。
295
+ > 2. 当按钮显式声明 `iconOnly=true` 时,内部挂载的视觉资源使用放大一级的上下文:`sm: 16`, `md: 20`, `lg: 24`。
296
+ > 3. `bare iconOnly` 使用当前 `size` 档位的常规视觉尺寸(`sm -> 12`,`md -> 16`,`lg -> 20`);子视觉显式声明尺寸时优先使用自身尺寸。
288
297
 
289
298
  ### 1.1 Bare 模式
290
299
 
@@ -296,11 +305,11 @@ Button 放入 Pagination 时使用角色模板:
296
305
  | 内容 | 可包含文字、Icon 或其他元素 |
297
306
  | Padding / Radius | `0` |
298
307
  | Gap | 保留当前 Button `size` 档位的普通内容 gap |
299
- | 最小热区 | 单图标内容时至少 `16x16`,通过透明点击热区扩展,不改变可见尺寸 |
300
- | 默认透明度 | `0.4` |
301
- | Hover 透明度 | `1` |
308
+ | 最小热区 | `iconOnly=true` 时至少 `16x16`,通过透明点击热区扩展,不改变可见尺寸 |
309
+ | 默认透明度 | `1`;`emphasis="muted"` 时为 `0.4` |
310
+ | Hover 透明度 | 默认保持 `1`;`emphasis="muted"` 时提升到 `1` |
302
311
  | Hover 背景图层 | 关闭 `Surface` 默认 hover 叠加 |
303
- | 单 Icon 尺寸 | 子 Icon 显式 `size` > 当前 Button 档位尺寸(`sm/md/lg -> 12/16/20`) |
312
+ | icon-only 视觉尺寸 | 子视觉显式尺寸 > 当前 Button 档位尺寸(`sm/md/lg -> 12/16/20`) |
304
313
 
305
314
  ### 2. Colors & Interaction (颜色与交互)
306
315
 
@@ -349,6 +358,20 @@ Button 放入 Pagination 时使用角色模板:
349
358
 
350
359
  - **Button-Docs.2026-05-25** 源码顶部历史变更记录已归档;后续新增变更统一写入本文档 Changelog,源码顶部只保留职责、当前关键架构与文档路径。
351
360
 
361
+ ### v2.5.0 (2026-08-11)
362
+
363
+ #### 破坏性变更
364
+ - **BTN-IconOnly.2** 新增显式 `iconOnly` Prop,默认 `false`;Button 不再根据 children DOM 自动推断单视觉内容布局。
365
+ - **BTN-IconOnly.3** `iconOnly=true` 输出 `data-icon-only="true"`,统一控制对称 padding、尺寸上下文、bare 最小命中区域与 render hints。
366
+ - **BTN-A11y.2** 开发环境下,icon-only Button 缺少 `aria-label`、`aria-labelledby` 或 `title` 时输出警告。
367
+ - **BTN-IconOnly.4** ColorSchemeButton、StyleButton、CopyButton、ExpandButton 及仓库内纯图标 Button 消费点改为主动声明 `iconOnly`。
368
+
369
+ ### v2.4.0 (2026-08-09)
370
+
371
+ #### 调整
372
+ - **BTN-Bare.2** `bare` 默认改为 `emphasis="normal"`,常态与 hover 均保持 100% 不透明;次级操作显式使用 `emphasis="muted"` 获得 40% → hover 100%。disabled 继续优先消费全局 `--snowui-state-opacity`。
373
+ - **BTN-Bare.3** CopyButton 反馈期继承宿主 Button 的 bare 静止强调级别,不再无条件回落到 40%。
374
+
352
375
  ### v2.3.2 (2026-07-08)
353
376
 
354
377
  #### 修复
@@ -374,7 +397,7 @@ Button 放入 Pagination 时使用角色模板:
374
397
  ### v2.1.0 (2026-06-22)
375
398
 
376
399
  #### 新功能
377
- - **BTN-Bare.1** 新增 `bare` 无外壳按钮模式:内容可包含文字、Icon 或其他元素;无 padding / radius / 背景 / 边框,使用 `currentColor × opacity: 0.4 -> 1` 交互规则。
400
+ - **BTN-Bare.1** 最初新增 `bare` 无外壳按钮模式:内容可包含文字、Icon 或其他元素;无 padding / radius / 背景 / 边框。当时使用 `currentColor × opacity: 0.4 -> 1`;2026-08-09 起该视觉改由 `emphasis="muted"` 显式启用,bare 默认 100%。
378
401
  - **BTN-Bare.2** `bare` 放入 Tab 时由 Tab 的 `--snowui-button-opacity-override` 接管透明度;两者作用于同一 Button 根节点,不发生透明度叠乘。
379
402
 
380
403
  ### v2.0.0 (2026-06-01)
@@ -432,7 +455,7 @@ Button 放入 Pagination 时使用角色模板:
432
455
  ### v1.3.5 (2026-02-25)
433
456
 
434
457
  #### 修复
435
- - **BTN-Fix.3** 注入 `RESOURCE_ICON_CONTEXT_KEY` 尺寸上下文:`<Button><ArrowLineDown /></Button>` 直放 `resource-svelte` 图标时,默认尺寸跟随按钮档位(sm/md/lg => 16/20/24),与 `<Icon><ArrowLineDown /></Icon>` 行为一致。
458
+ - **BTN-Fix.3** 注入 `RESOURCE_ICON_CONTEXT_KEY` 尺寸上下文;当时直放资源图标会由 DOM 自动识别并使用 sm/md/lg => 16/20/24,v2.5.0 起改为 `<Button iconOnly>` 显式启用。
436
459
 
437
460
  ### v1.3.4 (2026-02-25)
438
461
 
@@ -470,7 +493,7 @@ Button 放入 Pagination 时使用角色模板:
470
493
 
471
494
  #### 修复
472
495
  - **BT-Fix.5** 修复 `icon + text` 被误判为 `icon-only` 的问题
473
- - **BT-Fix.6** `icon-only` 识别改为运行时精确检测(单图标元素 + 无文本节点)
496
+ - **BT-Fix.6** 当时将 `icon-only` 识别改为运行时精确检测(单图标元素 + 无文本节点);该自动识别已由 v2.5.0 移除。
474
497
 
475
498
  ### v1.2.3 (2026-02-07)
476
499
 
@@ -1,6 +1,6 @@
1
1
  <!--
2
2
  Button 组件:基础交互按钮
3
- v2.3.2
3
+ v2.5.0
4
4
 
5
5
  1. 核心能力 (Capabilities):
6
6
  - 继承 Frame 组件的所有通用能力 (交互、动效、响应式等)
@@ -37,7 +37,11 @@
37
37
  interface Props extends Omit<FrameProps, "size"> {
38
38
  variant?: "gray" | "filled" | "outline" | "borderless";
39
39
  size?: "sm" | "md" | "lg";
40
+ /** 明确启用单视觉内容布局;默认 false,不根据 children 自动推断。 */
41
+ iconOnly?: boolean;
40
42
  bare?: boolean;
43
+ /** bare 模式的视觉强调级别;normal 默认始终 100%,muted 为 40% 并在 hover 时提升到 100%。 */
44
+ emphasis?: "normal" | "muted";
41
45
  /** 是否启用背景内容模糊;默认 false。 */
42
46
  backgroundBlur?: boolean;
43
47
  /**
@@ -54,12 +58,20 @@
54
58
  [key: string]: any;
55
59
  }
56
60
 
61
+ // 跨独立仓库源码检查时,Svelte 的 Snippet nominal symbol 可能来自不同物理安装。
62
+ // 此处只归一化传给 Frame 的类型身份,不改变 snippet 本身或运行时调用。
63
+ function normalizeFrameSnippet(snippet: unknown): Snippet<[any]> {
64
+ return snippet as Snippet<[any]>;
65
+ }
66
+
57
67
  const inheritedButtonPart = useComponentPart<Props>("Button");
58
68
  let explicitProps: Props = $props();
59
69
  let {
60
70
  variant = undefined,
61
71
  size = undefined,
72
+ iconOnly = false,
62
73
  bare = false,
74
+ emphasis = "normal",
63
75
  backgroundBlur = false,
64
76
  toggle = false,
65
77
  href = undefined,
@@ -128,9 +140,8 @@
128
140
  return "sm";
129
141
  });
130
142
 
131
- // 响应式的单个图标状态
132
- let isIconOnly = $state(false);
133
143
  let buttonElement = $state<HTMLElement | undefined>(undefined);
144
+ let hasWarnedMissingIconOnlyName = false;
134
145
 
135
146
  const defaultButtonIconSize = $derived.by(() => {
136
147
  if (resolvedSize === "lg") return 20;
@@ -140,8 +151,8 @@
140
151
 
141
152
  // 传递给 Frame Context 的尺寸(供 Icon/Avatar 等子组件继承)
142
153
  const contextPixelSize = $derived.by(() => {
143
- if (bare && isIconOnly) return defaultButtonIconSize;
144
- if (isIconOnly) {
154
+ if (bare && iconOnly) return defaultButtonIconSize;
155
+ if (iconOnly) {
145
156
  if (resolvedSize === "lg") return 24;
146
157
  if (resolvedSize === "md") return 20;
147
158
  return 16;
@@ -152,7 +163,7 @@
152
163
  }
153
164
  });
154
165
  const buttonRenderHints = $derived.by(() => {
155
- if (bare && isIconOnly) {
166
+ if (bare && iconOnly) {
156
167
  return {
157
168
  variant: userRenderHints?.variant ?? "circle",
158
169
  width: userRenderHints?.width ?? `${defaultButtonIconSize}px`,
@@ -196,6 +207,29 @@
196
207
  },
197
208
  });
198
209
 
210
+ $effect(() => {
211
+ if (
212
+ !import.meta.env.DEV ||
213
+ !iconOnly ||
214
+ !buttonElement ||
215
+ hasWarnedMissingIconOnlyName
216
+ ) return;
217
+
218
+ const node = buttonElement;
219
+ queueMicrotask(() => {
220
+ const hasAccessibleName =
221
+ !!node.getAttribute("aria-label")?.trim() ||
222
+ !!node.getAttribute("aria-labelledby")?.trim() ||
223
+ !!node.getAttribute("title")?.trim();
224
+ if (hasAccessibleName || hasWarnedMissingIconOnlyName) return;
225
+ hasWarnedMissingIconOnlyName = true;
226
+ console.warn(
227
+ "[SnowUI Button] iconOnly={true} requires aria-label, aria-labelledby, or title.",
228
+ node,
229
+ );
230
+ });
231
+ });
232
+
199
233
  // 上下文感知 (用于 as="more" 逻辑)
200
234
  const textCtx = getText();
201
235
  const imageCtx = getImage();
@@ -470,46 +504,6 @@
470
504
  clearHoldSuppressResetTimer();
471
505
  }
472
506
 
473
- // 精确识别“仅 1 个图标且无文本节点”的场景,避免 icon + text 误判
474
- function detectIconOnly(node: HTMLElement) {
475
- const iconSelector =
476
- ".snowui-icon-wrapper, .snowui-icon, .snowui-avatar, svg, img";
477
-
478
- const update = () => {
479
- const elementChildren = Array.from(node.children).filter(
480
- (child) => !child.classList.contains("snowui-tooltip-placeholder"),
481
- );
482
- const hasSingleIconElement =
483
- elementChildren.length === 1 &&
484
- elementChildren[0]?.matches?.(iconSelector);
485
- const hasTextNode = Array.from(node.childNodes).some(
486
- (child) =>
487
- child.nodeType === Node.TEXT_NODE && !!child.textContent?.trim(),
488
- );
489
-
490
- node.classList.toggle(
491
- "snowui-button-icon-only",
492
- hasSingleIconElement && !hasTextNode,
493
- );
494
- isIconOnly = hasSingleIconElement && !hasTextNode;
495
- };
496
-
497
- update();
498
-
499
- const observer = new MutationObserver(update);
500
- observer.observe(node, {
501
- childList: true,
502
- subtree: true,
503
- characterData: true,
504
- });
505
-
506
- return {
507
- destroy() {
508
- observer.disconnect();
509
- },
510
- };
511
- }
512
-
513
507
  onDestroy(() => {
514
508
  clearHoldTimers();
515
509
  clearHoldSuppressResetTimer();
@@ -532,6 +526,8 @@
532
526
  {target}
533
527
  {rel}
534
528
  data-variant={bare ? undefined : resolvedVariant}
529
+ data-icon-only={iconOnly ? "true" : undefined}
530
+ data-emphasis={bare ? emphasis : undefined}
535
531
  data-embedded={isButtonGroupEmbedded ? "button-group" : undefined}
536
532
  data-leading={as === "leading" ? "true" : undefined}
537
533
  data-trailing={as === "trailing" ? "true" : undefined}
@@ -552,7 +548,8 @@
552
548
  bare ? "snowui-button-bare" : "",
553
549
  backgroundBlur ? "snowui-button-background-blur" : "",
554
550
  isButtonGroupEmbedded ? "snowui-button-embedded-button-group" : "",
555
- bare && isIconOnly
551
+ iconOnly ? "snowui-button-icon-only" : "",
552
+ bare && iconOnly
556
553
  ? "snowui-button-bare-icon-only"
557
554
  : "",
558
555
  className,
@@ -569,8 +566,7 @@
569
566
  {...toggleDefaults}
570
567
  {...clickProps}
571
568
  {...frameRestProps}
572
- use={[detectIconOnly]}
573
- children={buttonChildren}
569
+ children={normalizeFrameSnippet(buttonChildren)}
574
570
  />
575
571
 
576
572
  <style>
@@ -794,12 +790,22 @@
794
790
  :global(:where(.snowui-button).snowui-button-bare) {
795
791
  --snowui-button-background: transparent;
796
792
  --snowui-button-border-color: transparent;
797
- --snowui-button-opacity: var(--snowui-state-opacity, 0.4);
793
+ --snowui-button-bare-idle-opacity: 1;
794
+ --snowui-button-opacity: var(
795
+ --snowui-state-opacity,
796
+ var(--snowui-button-bare-idle-opacity)
797
+ );
798
798
  background-image: none;
799
799
  transition:
800
800
  opacity var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out);
801
801
  }
802
802
 
803
+ :global(
804
+ :where(.snowui-button).snowui-button-bare[data-emphasis="muted"]
805
+ ) {
806
+ --snowui-button-bare-idle-opacity: 0.4;
807
+ }
808
+
803
809
  :global(:where(.snowui-button).snowui-button-bare) {
804
810
  --snowui-button-padding: 0;
805
811
  --snowui-button-icon-only-padding: 0;