@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.
- package/component-catalog.json +1066 -0
- package/package.json +5 -1
- package/src/components/Button.md +42 -19
- package/src/components/Button.svelte +49 -49
- package/src/components/Button.test.ts +38 -27
- package/src/components/Card.test.ts +1 -1
- package/src/components/CodeBlock.md +44 -9
- package/src/components/CodeBlock.svelte +155 -10
- package/src/components/CodeBlock.test.ts +21 -2
- package/src/components/ColorSchemeButton.md +50 -0
- package/src/components/ColorSchemeButton.svelte +144 -0
- package/src/components/ColorSchemeButton.test.ts +39 -0
- package/src/components/CopyButton.md +5 -1
- package/src/components/CopyButton.svelte +6 -2
- package/src/components/Dialog.test.ts +2 -2
- package/src/components/ExpandButton.md +5 -1
- package/src/components/ExpandButton.svelte +1 -0
- package/src/components/Form.test.ts +4 -4
- package/src/components/Image.test.ts +1 -1
- package/src/components/Input.md +15 -5
- package/src/components/Input.svelte +10 -1
- package/src/components/Input.test.ts +2 -2
- package/src/components/OverflowAction.md +41 -0
- package/src/components/OverflowAction.svelte +209 -0
- package/src/components/OverflowAction.test.ts +11 -0
- package/src/components/OverflowActions.md +95 -0
- package/src/components/OverflowActions.svelte +501 -0
- package/src/components/OverflowActions.test.ts +87 -0
- package/src/components/Pagination.md +2 -2
- package/src/components/Pagination.svelte +2 -2
- package/src/components/Pagination.test.ts +2 -2
- package/src/components/SearchInput.md +14 -1
- package/src/components/SearchInput.svelte +104 -2
- package/src/components/SearchInput.test.ts +16 -1
- package/src/components/SelectButton.md +1 -1
- package/src/components/StyleButton.md +58 -0
- package/src/components/StyleButton.svelte +144 -0
- package/src/components/StyleButton.test.ts +39 -0
- package/src/components/Table.md +2 -2
- package/src/components/Table.svelte +4 -1
- package/src/components/TableCell.svelte +32 -5
- package/src/components/TableCell.test.ts +2 -2
- package/src/components/TableHead.svelte +20 -4
- package/src/components/TableToolbar.svelte +12 -5
- package/src/components/Text.svelte +2 -0
- package/src/components/Tooltip.md +27 -8
- package/src/components/Tooltip.svelte +101 -29
- package/src/components/Tooltip.test.ts +28 -2
- package/src/i18n/messages.ts +12 -0
- package/src/index.ts +17 -0
- package/src/internal/StyleButtonLogo.svelte +49 -0
- package/src/lib/table-context.svelte.ts +25 -0
- package/src/lib/tooltip-delay.md +7 -1
- package/src/lib/tooltip-motion-dismiss.md +16 -1
- package/src/lib/tooltip-motion-dismiss.ts +19 -7
- package/src/lib/tooltip-overlay.md +21 -3
- package/src/lib/tooltip-overlay.ts +4 -2
- package/src/logic/frame-inline-style.svelte.ts +2 -2
- package/src/logic/overflow-actions.svelte.ts +33 -0
- package/src/motion/presets/README.md +5 -2
- package/src/motion/presets/tooltip.md +40 -2
- package/src/motion/presets/tooltip.ts +0 -2
- package/src/motion/tokens.md +7 -4
- package/src/motion/tokens.ts +2 -1
- package/src/styles/auto-layout.css +10 -1
- package/src/styles/components.css +29 -20
- package/src/styles/tokens.css +33 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowui-design-system/components",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"./logic/*": "./src/logic/*.ts",
|
|
21
21
|
"./motion/*.css": "./src/motion/*.css",
|
|
22
22
|
"./motion/*": "./src/motion/*.ts",
|
|
23
|
+
"./component-catalog.json": "./component-catalog.json",
|
|
23
24
|
"./styles": "./src/styles/index.css",
|
|
24
25
|
"./styles/*": "./src/styles/*"
|
|
25
26
|
},
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"!src/demo",
|
|
29
30
|
"!src/playground",
|
|
30
31
|
"!src/test",
|
|
32
|
+
"component-catalog.json",
|
|
31
33
|
"README.md"
|
|
32
34
|
],
|
|
33
35
|
"peerDependencies": {
|
|
@@ -56,6 +58,8 @@
|
|
|
56
58
|
"check:standards": "node ../scripts/check-standards.js",
|
|
57
59
|
"fix:standards": "node ../scripts/check-standards.js --fix",
|
|
58
60
|
"check:oss": "node scripts/check-oss-deps.mjs",
|
|
61
|
+
"catalog:generate": "node scripts/generate-component-catalog.mjs",
|
|
62
|
+
"catalog:check": "node scripts/generate-component-catalog.mjs --check",
|
|
59
63
|
"verify:styles": "node scripts/verify-styles.mjs"
|
|
60
64
|
}
|
|
61
65
|
}
|
package/src/components/Button.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Button.svelte 文档
|
|
2
2
|
|
|
3
|
-
> **版本**: v2.
|
|
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
|
-
|
|
|
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
|
-
|
|
|
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
|
|
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`
|
|
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
|
|
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
|
-
-
|
|
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.
|
|
287
|
-
> 3. `bare`
|
|
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
|
-
| 最小热区 |
|
|
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
|
-
|
|
|
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**
|
|
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`
|
|
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
|
+
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
|
/**
|
|
@@ -65,7 +69,9 @@
|
|
|
65
69
|
let {
|
|
66
70
|
variant = undefined,
|
|
67
71
|
size = undefined,
|
|
72
|
+
iconOnly = false,
|
|
68
73
|
bare = false,
|
|
74
|
+
emphasis = "normal",
|
|
69
75
|
backgroundBlur = false,
|
|
70
76
|
toggle = false,
|
|
71
77
|
href = undefined,
|
|
@@ -134,9 +140,8 @@
|
|
|
134
140
|
return "sm";
|
|
135
141
|
});
|
|
136
142
|
|
|
137
|
-
// 响应式的单个图标状态
|
|
138
|
-
let isIconOnly = $state(false);
|
|
139
143
|
let buttonElement = $state<HTMLElement | undefined>(undefined);
|
|
144
|
+
let hasWarnedMissingIconOnlyName = false;
|
|
140
145
|
|
|
141
146
|
const defaultButtonIconSize = $derived.by(() => {
|
|
142
147
|
if (resolvedSize === "lg") return 20;
|
|
@@ -146,8 +151,8 @@
|
|
|
146
151
|
|
|
147
152
|
// 传递给 Frame Context 的尺寸(供 Icon/Avatar 等子组件继承)
|
|
148
153
|
const contextPixelSize = $derived.by(() => {
|
|
149
|
-
if (bare &&
|
|
150
|
-
if (
|
|
154
|
+
if (bare && iconOnly) return defaultButtonIconSize;
|
|
155
|
+
if (iconOnly) {
|
|
151
156
|
if (resolvedSize === "lg") return 24;
|
|
152
157
|
if (resolvedSize === "md") return 20;
|
|
153
158
|
return 16;
|
|
@@ -158,7 +163,7 @@
|
|
|
158
163
|
}
|
|
159
164
|
});
|
|
160
165
|
const buttonRenderHints = $derived.by(() => {
|
|
161
|
-
if (bare &&
|
|
166
|
+
if (bare && iconOnly) {
|
|
162
167
|
return {
|
|
163
168
|
variant: userRenderHints?.variant ?? "circle",
|
|
164
169
|
width: userRenderHints?.width ?? `${defaultButtonIconSize}px`,
|
|
@@ -202,6 +207,29 @@
|
|
|
202
207
|
},
|
|
203
208
|
});
|
|
204
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
|
+
|
|
205
233
|
// 上下文感知 (用于 as="more" 逻辑)
|
|
206
234
|
const textCtx = getText();
|
|
207
235
|
const imageCtx = getImage();
|
|
@@ -476,46 +504,6 @@
|
|
|
476
504
|
clearHoldSuppressResetTimer();
|
|
477
505
|
}
|
|
478
506
|
|
|
479
|
-
// 精确识别“仅 1 个图标且无文本节点”的场景,避免 icon + text 误判
|
|
480
|
-
function detectIconOnly(node: HTMLElement) {
|
|
481
|
-
const iconSelector =
|
|
482
|
-
".snowui-icon-wrapper, .snowui-icon, .snowui-avatar, svg, img";
|
|
483
|
-
|
|
484
|
-
const update = () => {
|
|
485
|
-
const elementChildren = Array.from(node.children).filter(
|
|
486
|
-
(child) => !child.classList.contains("snowui-tooltip-placeholder"),
|
|
487
|
-
);
|
|
488
|
-
const hasSingleIconElement =
|
|
489
|
-
elementChildren.length === 1 &&
|
|
490
|
-
elementChildren[0]?.matches?.(iconSelector);
|
|
491
|
-
const hasTextNode = Array.from(node.childNodes).some(
|
|
492
|
-
(child) =>
|
|
493
|
-
child.nodeType === Node.TEXT_NODE && !!child.textContent?.trim(),
|
|
494
|
-
);
|
|
495
|
-
|
|
496
|
-
node.classList.toggle(
|
|
497
|
-
"snowui-button-icon-only",
|
|
498
|
-
hasSingleIconElement && !hasTextNode,
|
|
499
|
-
);
|
|
500
|
-
isIconOnly = hasSingleIconElement && !hasTextNode;
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
update();
|
|
504
|
-
|
|
505
|
-
const observer = new MutationObserver(update);
|
|
506
|
-
observer.observe(node, {
|
|
507
|
-
childList: true,
|
|
508
|
-
subtree: true,
|
|
509
|
-
characterData: true,
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
return {
|
|
513
|
-
destroy() {
|
|
514
|
-
observer.disconnect();
|
|
515
|
-
},
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
|
|
519
507
|
onDestroy(() => {
|
|
520
508
|
clearHoldTimers();
|
|
521
509
|
clearHoldSuppressResetTimer();
|
|
@@ -538,6 +526,8 @@
|
|
|
538
526
|
{target}
|
|
539
527
|
{rel}
|
|
540
528
|
data-variant={bare ? undefined : resolvedVariant}
|
|
529
|
+
data-icon-only={iconOnly ? "true" : undefined}
|
|
530
|
+
data-emphasis={bare ? emphasis : undefined}
|
|
541
531
|
data-embedded={isButtonGroupEmbedded ? "button-group" : undefined}
|
|
542
532
|
data-leading={as === "leading" ? "true" : undefined}
|
|
543
533
|
data-trailing={as === "trailing" ? "true" : undefined}
|
|
@@ -558,7 +548,8 @@
|
|
|
558
548
|
bare ? "snowui-button-bare" : "",
|
|
559
549
|
backgroundBlur ? "snowui-button-background-blur" : "",
|
|
560
550
|
isButtonGroupEmbedded ? "snowui-button-embedded-button-group" : "",
|
|
561
|
-
|
|
551
|
+
iconOnly ? "snowui-button-icon-only" : "",
|
|
552
|
+
bare && iconOnly
|
|
562
553
|
? "snowui-button-bare-icon-only"
|
|
563
554
|
: "",
|
|
564
555
|
className,
|
|
@@ -575,7 +566,6 @@
|
|
|
575
566
|
{...toggleDefaults}
|
|
576
567
|
{...clickProps}
|
|
577
568
|
{...frameRestProps}
|
|
578
|
-
use={[detectIconOnly]}
|
|
579
569
|
children={normalizeFrameSnippet(buttonChildren)}
|
|
580
570
|
/>
|
|
581
571
|
|
|
@@ -800,12 +790,22 @@
|
|
|
800
790
|
:global(:where(.snowui-button).snowui-button-bare) {
|
|
801
791
|
--snowui-button-background: transparent;
|
|
802
792
|
--snowui-button-border-color: transparent;
|
|
803
|
-
--snowui-button-
|
|
793
|
+
--snowui-button-bare-idle-opacity: 1;
|
|
794
|
+
--snowui-button-opacity: var(
|
|
795
|
+
--snowui-state-opacity,
|
|
796
|
+
var(--snowui-button-bare-idle-opacity)
|
|
797
|
+
);
|
|
804
798
|
background-image: none;
|
|
805
799
|
transition:
|
|
806
800
|
opacity var(--snowui-frame-color-motion-duration, 0.15s) var(--snowui-frame-color-motion-easing, ease-out);
|
|
807
801
|
}
|
|
808
802
|
|
|
803
|
+
:global(
|
|
804
|
+
:where(.snowui-button).snowui-button-bare[data-emphasis="muted"]
|
|
805
|
+
) {
|
|
806
|
+
--snowui-button-bare-idle-opacity: 0.4;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
809
|
:global(:where(.snowui-button).snowui-button-bare) {
|
|
810
810
|
--snowui-button-padding: 0;
|
|
811
811
|
--snowui-button-icon-only-padding: 0;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Button.test.ts
|
|
3
|
-
* v1.
|
|
3
|
+
* v1.6.0
|
|
4
|
+
* 变更记录 (2026-08-11): icon-only 改为显式 iconOnly=true;未声明等同于 false。
|
|
5
|
+
* 变更记录 (2026-08-09): bare 默认 100% 不透明,新增 emphasis="muted" 示例覆盖 40% → hover 100%。
|
|
4
6
|
* 变更记录 (2026-07-05): 新增 backgroundBlur 开启状态示例。
|
|
5
7
|
* 变更记录 (2026-05-18): 新增 B6 复制按钮示例,覆盖 P0.2 瞬时反馈模式:副作用挂 onclick,状态切换与内容回弹由 Frame 接管。
|
|
6
8
|
* 变更记录 (2026-03-15): 修复 B3 图标按钮示例运行时错误,示例下拉图标改为 test 沙箱已注入的 `ArrowLineDown`。
|
|
@@ -25,7 +27,7 @@ export const examples = [
|
|
|
25
27
|
<Button variant="outline">Outline</Button>
|
|
26
28
|
<Button variant="borderless">Borderless</Button>
|
|
27
29
|
<Button bare>Bare</Button>
|
|
28
|
-
<Button bare aria-label="减少"><Minus /></Button>`,
|
|
30
|
+
<Button bare iconOnly aria-label="减少"><Minus /></Button>`,
|
|
29
31
|
|
|
30
32
|
logic: ["Style"],
|
|
31
33
|
},
|
|
@@ -64,14 +66,15 @@ export const examples = [
|
|
|
64
66
|
code: `A4
|
|
65
67
|
<div class="flex-row gap-12 items-center">
|
|
66
68
|
<Button bare>All</Button>
|
|
67
|
-
<Button bare><FourLeafClover size={24} /></Button>
|
|
69
|
+
<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={24} /></Button>
|
|
70
|
+
<Button bare emphasis="muted">Muted</Button>
|
|
68
71
|
<Button bare disabled>Disabled</Button>
|
|
69
72
|
</div>`,
|
|
70
73
|
|
|
71
74
|
expected: {
|
|
72
|
-
render: "无外壳按钮可包含文字或 Icon,无 padding
|
|
75
|
+
render: "无外壳按钮可包含文字或 Icon,无 padding、圆角、背景和边框;默认保持 100% 不透明,muted 为 40%。",
|
|
73
76
|
layout: "按钮尺寸由内部内容自然撑开。",
|
|
74
|
-
interaction: "
|
|
77
|
+
interaction: "默认按钮 hover 时透明度不变;muted hover 时由 40% 提升到 100%,禁用按钮不响应 hover。",
|
|
75
78
|
performance: "仅通过 Button class 与 CSS 变量切换视觉。",
|
|
76
79
|
responsive: "字号与行高继续跟随 Button size。",
|
|
77
80
|
},
|
|
@@ -120,16 +123,24 @@ export const examples = [
|
|
|
120
123
|
{
|
|
121
124
|
name: "B2: 纯图标按钮 (Icon Only)",
|
|
122
125
|
code: `B2
|
|
123
|
-
<Button
|
|
126
|
+
<Button aria-label="未声明 iconOnly">
|
|
124
127
|
<FourLeafClover />
|
|
125
128
|
</Button>
|
|
126
|
-
<Button size="
|
|
129
|
+
<Button iconOnly size="sm" aria-label="四叶草">
|
|
127
130
|
<FourLeafClover />
|
|
128
131
|
</Button>
|
|
129
|
-
<Button size="
|
|
132
|
+
<Button iconOnly size="md" aria-label="四叶草">
|
|
133
|
+
<FourLeafClover />
|
|
134
|
+
</Button>
|
|
135
|
+
<Button iconOnly size="lg" aria-label="四叶草">
|
|
130
136
|
<FourLeafClover />
|
|
131
137
|
</Button>`,
|
|
132
138
|
|
|
139
|
+
expected: {
|
|
140
|
+
render: "未声明 iconOnly 的 Button 使用普通内容布局;后三个显式 iconOnly Button 使用对应尺寸的对称 padding。",
|
|
141
|
+
layout: "iconOnly=false 不根据单个 SVG 自动改变布局;iconOnly=true 的 sm/md/lg 使用 4/8/12px 四边 padding。",
|
|
142
|
+
interaction: "所有按钮保持普通 Button 交互;纯图标按钮通过 aria-label 提供可访问名称。",
|
|
143
|
+
},
|
|
133
144
|
logic: ["Composition"],
|
|
134
145
|
},
|
|
135
146
|
{
|
|
@@ -137,25 +148,25 @@ export const examples = [
|
|
|
137
148
|
code: `B3
|
|
138
149
|
<div class="flex-col gap-12">
|
|
139
150
|
<div class="flex-row gap-8 items-center">
|
|
140
|
-
<Button bare aria-label="减少">
|
|
151
|
+
<Button bare iconOnly aria-label="减少">
|
|
141
152
|
<Minus size={12} />
|
|
142
153
|
</Button>
|
|
143
|
-
<Button bare aria-label="筛选">
|
|
154
|
+
<Button bare iconOnly aria-label="筛选">
|
|
144
155
|
<FourLeafClover size={16} />
|
|
145
156
|
</Button>
|
|
146
|
-
<Button bare size="lg" variant="filled" aria-label="展开">
|
|
157
|
+
<Button bare iconOnly size="lg" variant="filled" aria-label="展开">
|
|
147
158
|
<ArrowLineDown />
|
|
148
159
|
</Button>
|
|
149
|
-
<Button bare aria-label="增加">
|
|
160
|
+
<Button bare iconOnly aria-label="增加">
|
|
150
161
|
<Plus size={24} />
|
|
151
162
|
</Button>
|
|
152
163
|
</div>
|
|
153
164
|
<div class="flex-row gap-8 items-center p-8 rounded-12 bg-surface-1">
|
|
154
165
|
<Input placeholder="搜索内容" />
|
|
155
|
-
<Button bare size="md" variant="outline" aria-label="展开筛选">
|
|
166
|
+
<Button bare iconOnly size="md" variant="outline" aria-label="展开筛选">
|
|
156
167
|
<ArrowLineDown />
|
|
157
168
|
</Button>
|
|
158
|
-
<Button bare aria-label="清空输入">
|
|
169
|
+
<Button bare iconOnly aria-label="清空输入">
|
|
159
170
|
<Minus size={16} />
|
|
160
171
|
</Button>
|
|
161
172
|
</div>
|
|
@@ -169,7 +180,7 @@ export const examples = [
|
|
|
169
180
|
</Button>
|
|
170
181
|
</div>
|
|
171
182
|
<div class="text-12 text-black-40">
|
|
172
|
-
说明:bare 忽略 filled/outline 等 variant
|
|
183
|
+
说明:bare 忽略 filled/outline 等 variant 的视觉结果。显式 iconOnly 的单视觉内容继承当前 size 档位的 12/16/20px 尺寸上下文,并获得至少 16×16px 的透明点击热区;未声明 iconOnly 等同于 false。精确尺寸直接声明在子 Icon 上,Icon + 文字继续保留普通 Button 的内容 gap。
|
|
173
184
|
</div>
|
|
174
185
|
</div>`,
|
|
175
186
|
|
|
@@ -361,7 +372,7 @@ export const examples = [
|
|
|
361
372
|
>
|
|
362
373
|
{#snippet children({ currentState })}
|
|
363
374
|
<div class="flex-row gap-16 items-center bg-background-1 p-16 rounded-12 border-black-10 w-hug">
|
|
364
|
-
<Button variant="gray" size="lg">
|
|
375
|
+
<Button iconOnly variant="gray" size="lg" aria-label="减少">
|
|
365
376
|
<Minus />
|
|
366
377
|
</Button>
|
|
367
378
|
<div class="text-24 font-semibold min-w-48" style="text-align: center;">
|
|
@@ -370,7 +381,7 @@ export const examples = [
|
|
|
370
381
|
duration={500}
|
|
371
382
|
/>
|
|
372
383
|
</div>
|
|
373
|
-
<Button variant="gray" size="lg">
|
|
384
|
+
<Button iconOnly variant="gray" size="lg" aria-label="增加">
|
|
374
385
|
<Plus />
|
|
375
386
|
</Button>
|
|
376
387
|
</div>
|
|
@@ -606,17 +617,17 @@ export const examples = [
|
|
|
606
617
|
<FourLeafClover />
|
|
607
618
|
</Icon>Gray</Button
|
|
608
619
|
>
|
|
609
|
-
<Button variant="filled" size="lg"
|
|
620
|
+
<Button iconOnly aria-label="四叶草" variant="filled" size="lg"
|
|
610
621
|
><Icon>
|
|
611
622
|
<FourLeafClover />
|
|
612
623
|
</Icon>Filled</Button
|
|
613
624
|
>
|
|
614
|
-
<Button variant="outline" size="lg"
|
|
625
|
+
<Button iconOnly aria-label="四叶草" variant="outline" size="lg"
|
|
615
626
|
><Icon>
|
|
616
627
|
<FourLeafClover />
|
|
617
628
|
</Icon>Outline</Button
|
|
618
629
|
>
|
|
619
|
-
<Button variant="borderless" size="lg"
|
|
630
|
+
<Button iconOnly aria-label="四叶草" variant="borderless" size="lg"
|
|
620
631
|
><Icon>
|
|
621
632
|
<FourLeafClover />
|
|
622
633
|
</Icon>Borderless</Button
|
|
@@ -708,13 +719,13 @@ export const examples = [
|
|
|
708
719
|
},
|
|
709
720
|
{
|
|
710
721
|
name: "Custom 23-00-59",
|
|
711
|
-
code: `<Button bare><FourLeafClover size={16} /></Button>
|
|
712
|
-
<Button bare><FourLeafClover size={20} /></Button>
|
|
713
|
-
<Button bare><FourLeafClover size={24} /></Button>
|
|
714
|
-
<Button bare><FourLeafClover size={32} /></Button>
|
|
715
|
-
<Button bare><FourLeafClover size={40} /></Button>
|
|
716
|
-
<Button bare><FourLeafClover size={48} /></Button>
|
|
717
|
-
<Button bare><FourLeafClover size={80} /></Button>
|
|
722
|
+
code: `<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={16} /></Button>
|
|
723
|
+
<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={20} /></Button>
|
|
724
|
+
<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={24} /></Button>
|
|
725
|
+
<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={32} /></Button>
|
|
726
|
+
<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={40} /></Button>
|
|
727
|
+
<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={48} /></Button>
|
|
728
|
+
<Button bare iconOnly aria-label="四叶草"><FourLeafClover size={80} /></Button>
|
|
718
729
|
<Button bare>文字</Button>`,
|
|
719
730
|
logic: ["UserCreated"],
|
|
720
731
|
},] as const;
|
|
@@ -108,7 +108,7 @@ export const examples = [
|
|
|
108
108
|
<Frame row>
|
|
109
109
|
<Icon as="leading" size={16}><Paperclip /></Icon>
|
|
110
110
|
<Text>Attachment.pdf</Text>
|
|
111
|
-
<Button as="trailing" bare variant="borderless">
|
|
111
|
+
<Button as="trailing" bare iconOnly emphasis="muted" variant="borderless" aria-label="下载">
|
|
112
112
|
<Icon size={16}><ArrowLineDown /></Icon>
|
|
113
113
|
</Button>
|
|
114
114
|
</Frame>
|