@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
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
- `parts.Indicator`:配置内置 resize Indicator。
|
|
6
6
|
- 需要替换手柄结构时使用文档既有 Indicator `as` 职责;外置显式 Props 高于 part。
|
|
7
7
|
|
|
8
|
-
> **版本**: v1.
|
|
9
|
-
> **更新**: 2026-
|
|
10
|
-
> **布局模型**:
|
|
8
|
+
> **版本**: v1.6.1
|
|
9
|
+
> **更新**: 2026-08-12
|
|
10
|
+
> **布局模型**: 默认态为复合管理布局;`singleLine` 为槽位宿主布局
|
|
11
11
|
> **文档**: ./CodeBlock.md
|
|
12
12
|
|
|
13
13
|
代码块组件,支持语法显示、基础语法着色、行号、复制到剪贴板与全屏放大。全屏放大/缩小使用共享元素转场的 `layout` 策略:实际过渡位置与尺寸,不缩放代码字形;图标切换动效使用 `REPLACEMENT_APPEAR_MOTION`,避免继承浮层类动效语义。
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
|:---|:---|
|
|
24
24
|
| **内容** | `code`, `language`, `children` |
|
|
25
25
|
| **功能开关** | `showLanguage`, `showLineNumbers`, `showCopyButton`, `showExpandButton` |
|
|
26
|
-
| **布局** | `visibleLines`,
|
|
26
|
+
| **布局** | `variant="default|singleLine"`, `visibleLines`, 默认态拖拽高度 |
|
|
27
27
|
| **行为** | `copyTimeout`;复制能力由默认内置 CopyButton 承担 |
|
|
28
28
|
| **默认内置组件** | `parts.CopyButton` 配置内置 bare CopyButton;`parts.ExpandButton` 配置内置 bare ExpandButton;`parts.Indicator` 配置缩放手柄 |
|
|
29
|
-
|
|
|
29
|
+
| **外置配件槽位** | `singleLine` 支持 `as="leading"`;全部变体支持 `as="trailing"`;兼容 `data-as="copy-icon"`, `data-as="copied-icon"`, `data-as="expand-icon"`, `data-as="collapse-icon"`,前两者映射到 CopyButton icon/successIcon |
|
|
30
30
|
| **Frame 透传** | `class`, `style`, `...rest` |
|
|
31
31
|
|
|
32
32
|
---
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
|
|
36
36
|
| 关键字 | 类型 | 默认值 | 描述 |
|
|
37
37
|
|:---|:---|:---|:---|
|
|
38
|
+
| `variant` | `"default" \| "singleLine"` | `"default"` | `singleLine` 使用 Input 同类 Leading / Content / Trailing 三槽布局;固定为单行展示,不生成高度拖拽、语言、行号、全屏或纵向滚动结构 |
|
|
38
39
|
| `code` | `string` | `""` | 要显示的代码字符串 |
|
|
39
40
|
| `language` | `string` | — | 语言标识,显示在工具栏(如 `"tsx"`, `"css"`) |
|
|
40
41
|
| `showLanguage` | `boolean` | `true` | 是否显示语言标识 |
|
|
@@ -48,6 +49,37 @@
|
|
|
48
49
|
|
|
49
50
|
---
|
|
50
51
|
|
|
52
|
+
## `singleLine` 单行变体
|
|
53
|
+
|
|
54
|
+
`variant="singleLine"` 面向 import、install command、短配置值等独占一行的只读代码条。它仍使用 `<pre><code>`、内置轻量语法着色和 CopyButton,不改用 Input,也不引入表单语义。
|
|
55
|
+
|
|
56
|
+
布局参考 Input 的三槽协议:
|
|
57
|
+
|
|
58
|
+
| 槽位 | 尺寸 | 内容 |
|
|
59
|
+
|:---|:---|:---|
|
|
60
|
+
| Leading | Hug | 可选外置 `as="leading"` 配件 |
|
|
61
|
+
| Content | Fill / `min-width: 0` | 单行高亮代码;超宽时仅横向滚动 |
|
|
62
|
+
| Trailing | Hug | 外置 `as="trailing"`,否则为默认内置 CopyButton |
|
|
63
|
+
|
|
64
|
+
单行态固定隐藏语言、行号和全屏按钮;`visibleLines`、`showLanguage`、`showLineNumbers`、`showExpandButton` 在该变体中不产生对应结构。根层不生成 Indicator,不接受拖拽高度,也不创建纵向 scrollbar / fade。默认 padding 与 Input 标准态一致:上下 `--padding-3`(12px)、左右 `--padding-4`(16px);gap 为 `--gap-2`(8px),圆角为 `--radius-4`(16px)。
|
|
65
|
+
|
|
66
|
+
```svelte
|
|
67
|
+
<CodeBlock
|
|
68
|
+
variant="singleLine"
|
|
69
|
+
code="import { Button } from '@snowui-design-system/components';"
|
|
70
|
+
/>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
需要 Leading 配件时:
|
|
74
|
+
|
|
75
|
+
```svelte
|
|
76
|
+
<CodeBlock variant="singleLine" code="pnpm add @snowui-design-system/components">
|
|
77
|
+
<Icon as="leading"><Package /></Icon>
|
|
78
|
+
</CodeBlock>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
51
83
|
## 语法着色
|
|
52
84
|
|
|
53
85
|
当使用 `code` prop 时,组件内置轻量语法着色规则,覆盖 JS / TS / JSON / HTML / CSS 常见 token。规则来自参考仓库中 `shiki` / `rehype-pretty-code` 的高亮分层思路,但当前实现不新增依赖。
|
|
@@ -61,7 +93,7 @@
|
|
|
61
93
|
| 行号 | `--black-20` |
|
|
62
94
|
| 注释 / 灰色代码 | `--black-40` |
|
|
63
95
|
| 语言标识 | `--black-40` |
|
|
64
|
-
| 按钮区 |
|
|
96
|
+
| 按钮区 | 内置操作显式使用 `Button bare emphasis="muted"`:`--black-100` × `opacity: 0.4`(视觉等同 `--black-40`) |
|
|
65
97
|
| 关键字 / 数字 / literal | `#ff32c6` |
|
|
66
98
|
| 函数 / 调用对象 | `#ffac60` |
|
|
67
99
|
| 属性 / 方法 | `#1ac69c` |
|
|
@@ -70,7 +102,7 @@
|
|
|
70
102
|
|
|
71
103
|
代码块根容器默认设置 `font-size: var(--text-12)` 与 `line-height: var(--leading-12)`;内部行号、`pre`、`code`、代码行全部继承根容器排版。`font-family` 默认继承外部上下文,不设置具体字体族,忽略设计稿中的字体设置。
|
|
72
104
|
|
|
73
|
-
按钮 hover 对齐 Button `bare` 模式:关闭背景叠加,默认 `opacity: 0.4`,hover 提升到 `1`,并使用 Frame color motion 变量过渡。
|
|
105
|
+
按钮 hover 对齐 Button 的 `bare emphasis="muted"` 模式:关闭背景叠加,默认 `opacity: 0.4`,hover 提升到 `1`,并使用 Frame color motion 变量过渡。
|
|
74
106
|
|
|
75
107
|
工具栏使用内部 Pin 布局固定到 `pin-top-right`,偏移为 `var(--padding-2)`;右下角尺寸手柄复用 `Indicator axis="height" appearance="corner"`,宿主 hover 时以 1px / Black/20% 显示,自身 hover、focus 或 dragging 时变为 2px / Black/40%。
|
|
76
108
|
|
|
@@ -149,7 +181,7 @@ CodeBlock 只声明轨道定位,滚动条尺寸、显隐、hover 形态与鼠
|
|
|
149
181
|
|
|
150
182
|
| Frame 能力 | 接入层 | 说明 |
|
|
151
183
|
|:---|:---|:---|
|
|
152
|
-
| 普通 Frame | 根 Frame | 容器不触发默认 hover
|
|
184
|
+
| 普通 Frame | 根 Frame | 容器不触发默认 hover 动效;`singleLine` 固定启用 row + Auto Layout 三槽协议 |
|
|
153
185
|
| `enableResponsive` | 根 Frame | 默认 `false`(代码块本身不需要容器断点响应) |
|
|
154
186
|
| `enableContext` | 根 Frame | 默认 `false` |
|
|
155
187
|
| `enableScaleObserver` | 根 Frame | 默认 `false` |
|
|
@@ -222,7 +254,7 @@ pnpm build`}
|
|
|
222
254
|
|
|
223
255
|
## 布局模型
|
|
224
256
|
|
|
225
|
-
|
|
257
|
+
默认态主布局模型:**复合管理布局**(参见 [LayoutProtocol.md §12.6](../../../specs/LayoutProtocol.md))。`singleLine` 改用**槽位宿主布局**,根层直接管理 Leading / Content / Trailing,且不生成下列默认态的滚动、全屏与 resize 子树。
|
|
226
258
|
|
|
227
259
|
组件内部包含:
|
|
228
260
|
- 工具栏区域(固定在顶部,不随代码滚动)
|
|
@@ -235,6 +267,9 @@ pnpm build`}
|
|
|
235
267
|
|
|
236
268
|
| 日期 | 版本 | 说明 |
|
|
237
269
|
|:---|:---|:---|
|
|
270
|
+
| 2026-08-12 | v1.6.1 | `singleLine` 的 padding、gap 与圆角对齐 Input 标准态:上下 12px、左右 16px、gap 8px、圆角 16px |
|
|
271
|
+
| 2026-08-12 | v1.6.0 | 新增 `variant="singleLine"`;参考 Input 实现 Leading / Content / Trailing 三槽布局,保留高亮与复制,移除语言、行号、全屏、纵向滚动及高度拖拽结构 |
|
|
272
|
+
| 2026-08-09 | v1.5.1 | Button bare 默认改为 100% 后,内置复制 / 放大操作显式使用 `emphasis="muted"` 保留原 40% → hover 100% 的次级操作视觉 |
|
|
238
273
|
| 2026-07-30 | v1.5.0 | 全屏展开/收起改用共享元素 `layout` 策略,实际过渡位置与尺寸,代码字形不参与缩放;普通态与全屏态统一遵循 `showLineNumbers`,消除退出末帧横向突变 |
|
|
239
274
|
| 2026-07-08 | v1.4.7 | 顶部操作按钮容器的 `pin-top-right` 偏移从 `--padding-2`(8px)调整为 `--padding-3`(12px),普通态与全屏态保持一致 |
|
|
240
275
|
| 2026-07-08 | v1.4.6 | 顶部复制 / 放大操作按钮统一使用 Button bare 默认 16×16 尺寸;移除 CodeBlock 私有按钮外壳尺寸,按钮组间距改为 `--gap-2`(8px)并接入 `--snowui-code-block-gap-override` |
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
CodeBlock 组件:代码块显示,支持行号、复制、全屏放大
|
|
3
|
-
v1.
|
|
3
|
+
v1.6.1
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
布局模型:默认态为复合管理布局;singleLine 变体为槽位宿主布局
|
|
6
6
|
|
|
7
7
|
Frame 能力接入:
|
|
8
8
|
- 根层:enableDefaultMotion=true
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
退出:applyFlipExit 将全屏层缩回卡片位置后卸载
|
|
14
14
|
|
|
15
15
|
外置 Icon 替换(ComponentGuidelines §2.7.1):
|
|
16
|
+
- singleLine 支持 as="leading" / data-as="leading" 前置配件
|
|
16
17
|
- as="trailing" / data-as="trailing" 替换默认右侧动作区
|
|
17
18
|
- data-as="copy-icon" / "copied-icon" / "expand-icon" / "collapse-icon" 保留为精确图标替换兼容入口
|
|
18
19
|
|
|
@@ -117,6 +118,8 @@
|
|
|
117
118
|
]);
|
|
118
119
|
|
|
119
120
|
interface Props extends Partial<FrameProps> {
|
|
121
|
+
/** 视觉与布局变体;singleLine 使用三槽单行代码条 */
|
|
122
|
+
variant?: "default" | "singleLine";
|
|
120
123
|
/** 要显示的代码字符串 */
|
|
121
124
|
code?: string;
|
|
122
125
|
/** 语言标识,显示在工具栏 */
|
|
@@ -149,6 +152,7 @@
|
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
let {
|
|
155
|
+
variant = "default",
|
|
152
156
|
code = "",
|
|
153
157
|
language = "",
|
|
154
158
|
showLanguage = true,
|
|
@@ -187,16 +191,19 @@
|
|
|
187
191
|
let hasCustomCopiedIcon = $state(false);
|
|
188
192
|
let hasCustomExpandIcon = $state(false);
|
|
189
193
|
let hasCustomCollapseIcon = $state(false);
|
|
194
|
+
let hasCustomLeading = $state(false);
|
|
190
195
|
let hasCustomTrailing = $state(false);
|
|
191
196
|
let customCopyIconHtml = $state("");
|
|
192
197
|
let customCopiedIconHtml = $state("");
|
|
193
198
|
let customExpandIconHtml = $state("");
|
|
194
199
|
let customCollapseIconHtml = $state("");
|
|
200
|
+
let customLeadingHtml = $state("");
|
|
195
201
|
let customTrailingHtml = $state("");
|
|
196
202
|
let childCode = $state("");
|
|
197
203
|
let hostElement: HTMLElement | undefined = $state(undefined);
|
|
198
204
|
|
|
199
205
|
/* ─── 计算属性 ─── */
|
|
206
|
+
const isSingleLine = $derived(variant === "singleLine");
|
|
200
207
|
const resolvedCode = $derived(code || childCode);
|
|
201
208
|
const lines = $derived(resolvedCode ? resolvedCode.split("\n") : []);
|
|
202
209
|
const resolvedVisibleLines = $derived(Math.max(1, visibleLines || 15));
|
|
@@ -204,11 +211,14 @@
|
|
|
204
211
|
Math.min(Math.max(lines.length || 1, 1), resolvedVisibleLines),
|
|
205
212
|
);
|
|
206
213
|
const highlightedLines = $derived(lines.map(highlightLine));
|
|
214
|
+
const highlightedSingleLine = $derived(highlightLine(resolvedCode));
|
|
207
215
|
const rootStyle = $derived(
|
|
208
216
|
[
|
|
209
217
|
`--snowui-code-block-visible-lines: ${autoVisibleLines};`,
|
|
210
218
|
userStyle,
|
|
211
|
-
resizeHeight !== undefined
|
|
219
|
+
!isSingleLine && resizeHeight !== undefined
|
|
220
|
+
? `height:${resizeHeight}px;`
|
|
221
|
+
: "",
|
|
212
222
|
]
|
|
213
223
|
.filter(Boolean)
|
|
214
224
|
.join(" "),
|
|
@@ -408,6 +418,9 @@
|
|
|
408
418
|
const childPre = hostElement!.querySelector(
|
|
409
419
|
".snowui-code-block-accessories pre",
|
|
410
420
|
) as HTMLElement | null;
|
|
421
|
+
const leading = hostElement!.querySelector(
|
|
422
|
+
'.snowui-code-block-accessories [data-as="leading"], .snowui-code-block-accessories .snowui-role-leading',
|
|
423
|
+
) as HTMLElement | null;
|
|
411
424
|
const trailing = hostElement!.querySelector(
|
|
412
425
|
'.snowui-code-block-accessories [data-as="trailing"], .snowui-code-block-accessories .snowui-role-trailing',
|
|
413
426
|
) as HTMLElement | null;
|
|
@@ -427,11 +440,13 @@
|
|
|
427
440
|
hasCustomCopiedIcon = !!copiedIcon;
|
|
428
441
|
hasCustomExpandIcon = !!expandIcon;
|
|
429
442
|
hasCustomCollapseIcon = !!collapseIcon;
|
|
443
|
+
hasCustomLeading = !!leading;
|
|
430
444
|
hasCustomTrailing = !!trailing;
|
|
431
445
|
customCopyIconHtml = copyIcon?.innerHTML ?? "";
|
|
432
446
|
customCopiedIconHtml = copiedIcon?.innerHTML ?? "";
|
|
433
447
|
customExpandIconHtml = expandIcon?.innerHTML ?? "";
|
|
434
448
|
customCollapseIconHtml = collapseIcon?.innerHTML ?? "";
|
|
449
|
+
customLeadingHtml = leading?.innerHTML ?? "";
|
|
435
450
|
customTrailingHtml = trailing?.innerHTML ?? "";
|
|
436
451
|
childCode =
|
|
437
452
|
childPre?.textContent ??
|
|
@@ -447,9 +462,17 @@
|
|
|
447
462
|
|
|
448
463
|
$effect(() => {
|
|
449
464
|
highlightedLines;
|
|
465
|
+
highlightedSingleLine;
|
|
450
466
|
updateScrollFade();
|
|
451
467
|
});
|
|
452
468
|
|
|
469
|
+
$effect(() => {
|
|
470
|
+
if (!isSingleLine) return;
|
|
471
|
+
resizeHeight = undefined;
|
|
472
|
+
isFullscreen = false;
|
|
473
|
+
isExitingFullscreen = false;
|
|
474
|
+
});
|
|
475
|
+
|
|
453
476
|
$effect(() => {
|
|
454
477
|
const element = fullscreenElement;
|
|
455
478
|
if (!element || !isFullscreen || isExitingFullscreen) return;
|
|
@@ -533,13 +556,21 @@
|
|
|
533
556
|
|
|
534
557
|
<!-- 根容器:bind:element 用于 MutationObserver 和 FLIP captureFlipRect 起点记录 -->
|
|
535
558
|
<Frame
|
|
559
|
+
{...rest}
|
|
536
560
|
enableResponsive={enableResponsive}
|
|
537
561
|
enableContext={enableContext}
|
|
538
562
|
enableScaleObserver={enableScaleObserver}
|
|
539
563
|
enableDefaultMotion={true}
|
|
564
|
+
enableAutoLayout={isSingleLine}
|
|
565
|
+
row={isSingleLine}
|
|
540
566
|
bind:element={hostElement}
|
|
541
|
-
class={[
|
|
542
|
-
|
|
567
|
+
class={[
|
|
568
|
+
"snowui-code-block",
|
|
569
|
+
!isSingleLine && "snowui-overlay-scrollbar-host",
|
|
570
|
+
className,
|
|
571
|
+
].filter(Boolean).join(" ")}
|
|
572
|
+
data-variant={variant}
|
|
573
|
+
data-resized={!isSingleLine && resizeHeight !== undefined ? "true" : undefined}
|
|
543
574
|
style={rootStyle}
|
|
544
575
|
renderHints={{
|
|
545
576
|
variant: "rect",
|
|
@@ -548,8 +579,54 @@
|
|
|
548
579
|
radius: "var(--radius-4)",
|
|
549
580
|
}}
|
|
550
581
|
componentParts={parts}
|
|
551
|
-
{...rest}
|
|
552
582
|
>
|
|
583
|
+
{#if isSingleLine}
|
|
584
|
+
{#if hasCustomLeading}
|
|
585
|
+
<span
|
|
586
|
+
class="snowui-code-block-single-line-leading"
|
|
587
|
+
data-as="leading">{@html customLeadingHtml}</span
|
|
588
|
+
>
|
|
589
|
+
{/if}
|
|
590
|
+
|
|
591
|
+
<div class="snowui-code-block-single-line-content">
|
|
592
|
+
<pre class="snowui-code-block-pre"><code
|
|
593
|
+
class="snowui-code-block-code"
|
|
594
|
+
>{#each highlightedSingleLine as token}<span
|
|
595
|
+
class={`snowui-code-block-token snowui-code-block-token-${token.kind}`}
|
|
596
|
+
>{token.text}</span
|
|
597
|
+
>{/each}</code
|
|
598
|
+
></pre
|
|
599
|
+
>
|
|
600
|
+
</div>
|
|
601
|
+
|
|
602
|
+
{#if hasCustomTrailing}
|
|
603
|
+
<span
|
|
604
|
+
class="snowui-code-block-trailing-custom"
|
|
605
|
+
data-as="trailing">{@html customTrailingHtml}</span
|
|
606
|
+
>
|
|
607
|
+
{:else if showCopyButton}
|
|
608
|
+
<div
|
|
609
|
+
class="snowui-code-block-actions snowui-code-block-single-line-trailing"
|
|
610
|
+
data-as="trailing"
|
|
611
|
+
>
|
|
612
|
+
<CopyButton
|
|
613
|
+
text={resolvedCode}
|
|
614
|
+
bare
|
|
615
|
+
emphasis={parts?.CopyButton?.emphasis ?? "muted"}
|
|
616
|
+
showText={false}
|
|
617
|
+
feedbackDuration={copyTimeout}
|
|
618
|
+
icon={hasCustomCopyIcon
|
|
619
|
+
? normalizeActionSnippet(copyIconSnippet)
|
|
620
|
+
: undefined}
|
|
621
|
+
successIcon={hasCustomCopiedIcon
|
|
622
|
+
? normalizeActionSnippet(copiedIconSnippet)
|
|
623
|
+
: undefined}
|
|
624
|
+
class="snowui-code-block-btn snowui-hoverable"
|
|
625
|
+
ariaLabel="复制代码"
|
|
626
|
+
/>
|
|
627
|
+
</div>
|
|
628
|
+
{/if}
|
|
629
|
+
{:else}
|
|
553
630
|
<!-- 工具栏 -->
|
|
554
631
|
<div
|
|
555
632
|
class="snowui-code-block-toolbar snowui-code-block-default-pin-top-right"
|
|
@@ -572,6 +649,7 @@
|
|
|
572
649
|
<CopyButton
|
|
573
650
|
text={resolvedCode}
|
|
574
651
|
bare
|
|
652
|
+
emphasis={parts?.CopyButton?.emphasis ?? "muted"}
|
|
575
653
|
showText={false}
|
|
576
654
|
feedbackDuration={copyTimeout}
|
|
577
655
|
icon={hasCustomCopyIcon
|
|
@@ -590,6 +668,7 @@
|
|
|
590
668
|
<ExpandButton
|
|
591
669
|
expanded={isFullscreen}
|
|
592
670
|
bare
|
|
671
|
+
emphasis={parts?.ExpandButton?.emphasis ?? "muted"}
|
|
593
672
|
class="snowui-code-block-btn"
|
|
594
673
|
ariaLabel="全屏查看"
|
|
595
674
|
collapseAriaLabel="退出全屏"
|
|
@@ -658,6 +737,7 @@
|
|
|
658
737
|
ariaLabel="调整代码块高度"
|
|
659
738
|
onSizeChange={handleResizeHeight}
|
|
660
739
|
/>
|
|
740
|
+
{/if}
|
|
661
741
|
{#if children}
|
|
662
742
|
<div class="snowui-code-block-accessories" aria-hidden="true">
|
|
663
743
|
{@render children()}
|
|
@@ -666,7 +746,7 @@
|
|
|
666
746
|
</Frame>
|
|
667
747
|
|
|
668
748
|
<!-- 全屏覆盖层:手动使用 layout 策略进出,代码字形不参与 scale -->
|
|
669
|
-
{#if isFullscreen || isExitingFullscreen}
|
|
749
|
+
{#if !isSingleLine && (isFullscreen || isExitingFullscreen)}
|
|
670
750
|
<Frame
|
|
671
751
|
bind:element={fullscreenElement}
|
|
672
752
|
tag="div"
|
|
@@ -698,6 +778,7 @@
|
|
|
698
778
|
<CopyButton
|
|
699
779
|
text={resolvedCode}
|
|
700
780
|
bare
|
|
781
|
+
emphasis={parts?.CopyButton?.emphasis ?? "muted"}
|
|
701
782
|
showText={false}
|
|
702
783
|
feedbackDuration={copyTimeout}
|
|
703
784
|
icon={hasCustomCopyIcon
|
|
@@ -715,6 +796,7 @@
|
|
|
715
796
|
<ExpandButton
|
|
716
797
|
expanded
|
|
717
798
|
bare
|
|
799
|
+
emphasis={parts?.ExpandButton?.emphasis ?? "muted"}
|
|
718
800
|
class="snowui-code-block-btn"
|
|
719
801
|
ariaLabel="全屏查看"
|
|
720
802
|
collapseAriaLabel="退出全屏"
|
|
@@ -803,9 +885,6 @@
|
|
|
803
885
|
var(--snowui-code-block-visible-lines) * 1lh
|
|
804
886
|
);
|
|
805
887
|
|
|
806
|
-
display: flex;
|
|
807
|
-
flex-direction: column;
|
|
808
|
-
gap: var(--gap-2);
|
|
809
888
|
background-color: var(
|
|
810
889
|
--snowui-code-block-bg-override,
|
|
811
890
|
var(--snowui-code-block-bg)
|
|
@@ -837,6 +916,54 @@
|
|
|
837
916
|
width: 100%;
|
|
838
917
|
}
|
|
839
918
|
|
|
919
|
+
:global(:where(.snowui-code-block[data-variant="default"])) {
|
|
920
|
+
display: flex;
|
|
921
|
+
flex-direction: column;
|
|
922
|
+
gap: var(--gap-2);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/* singleLine:沿用 Input 的 Leading / Content / Trailing 三槽结构。 */
|
|
926
|
+
:global(:where(.snowui-code-block[data-variant="singleLine"])) {
|
|
927
|
+
--snowui-code-block-padding-x: var(--padding-4);
|
|
928
|
+
--snowui-code-block-padding-y: var(--padding-3);
|
|
929
|
+
|
|
930
|
+
gap: var(
|
|
931
|
+
--snowui-code-block-gap-override,
|
|
932
|
+
var(--snowui-code-block-gap)
|
|
933
|
+
);
|
|
934
|
+
box-sizing: border-box;
|
|
935
|
+
height: auto;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
:global(:where(.snowui-code-block-single-line-content)) {
|
|
939
|
+
grid-row: 1;
|
|
940
|
+
min-width: 0;
|
|
941
|
+
overflow-x: auto;
|
|
942
|
+
overflow-y: hidden;
|
|
943
|
+
white-space: nowrap;
|
|
944
|
+
scrollbar-width: none;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
:global(:where(.snowui-code-block-single-line-content::-webkit-scrollbar)) {
|
|
948
|
+
display: none;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
:global(
|
|
952
|
+
:where(
|
|
953
|
+
.snowui-code-block[data-variant="singleLine"]
|
|
954
|
+
> [data-as="leading"],
|
|
955
|
+
.snowui-code-block[data-variant="singleLine"]
|
|
956
|
+
> [data-as="trailing"]
|
|
957
|
+
)
|
|
958
|
+
) {
|
|
959
|
+
display: inline-flex;
|
|
960
|
+
align-items: center;
|
|
961
|
+
justify-content: center;
|
|
962
|
+
min-width: 0;
|
|
963
|
+
white-space: nowrap;
|
|
964
|
+
line-height: inherit;
|
|
965
|
+
}
|
|
966
|
+
|
|
840
967
|
:global(:where(.snowui-code-block-fullscreen)) {
|
|
841
968
|
--snowui-code-block-bg: var(--background-2, #f9f9fa);
|
|
842
969
|
--snowui-code-block-fg: var(--black-100, #000000ff);
|
|
@@ -979,6 +1106,24 @@
|
|
|
979
1106
|
padding: 0;
|
|
980
1107
|
}
|
|
981
1108
|
|
|
1109
|
+
:global(
|
|
1110
|
+
:where(
|
|
1111
|
+
.snowui-code-block[data-variant="singleLine"]
|
|
1112
|
+
.snowui-code-block-pre
|
|
1113
|
+
)
|
|
1114
|
+
) {
|
|
1115
|
+
white-space: nowrap;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
:global(
|
|
1119
|
+
:where(
|
|
1120
|
+
.snowui-code-block[data-variant="singleLine"]
|
|
1121
|
+
.snowui-code-block-code
|
|
1122
|
+
)
|
|
1123
|
+
) {
|
|
1124
|
+
display: inline;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
982
1127
|
:global(:where(.snowui-code-block-line)) {
|
|
983
1128
|
display: block;
|
|
984
1129
|
line-height: inherit;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CodeBlock.test.ts
|
|
3
|
-
* v1.
|
|
4
|
-
* 变更记录 (2026-
|
|
3
|
+
* v1.3.0
|
|
4
|
+
* 变更记录 (2026-08-12): 增加 singleLine 三槽布局回归示例,验证单行内容、Leading 与默认复制 Trailing。
|
|
5
5
|
*/
|
|
6
6
|
export const examples = [
|
|
7
7
|
{
|
|
@@ -128,6 +128,25 @@ function resizeViewport(width: number) {
|
|
|
128
128
|
],
|
|
129
129
|
},
|
|
130
130
|
|
|
131
|
+
{
|
|
132
|
+
name: "CB-07:单行三槽代码条",
|
|
133
|
+
code: `CB-07
|
|
134
|
+
<CodeBlock
|
|
135
|
+
variant="singleLine"
|
|
136
|
+
code="import { Button } from '@snowui-design-system/components';"
|
|
137
|
+
style="width: 38rem;"
|
|
138
|
+
>
|
|
139
|
+
<Icon as="leading"><Bell /></Icon>
|
|
140
|
+
</CodeBlock>`,
|
|
141
|
+
logic: [
|
|
142
|
+
"variant",
|
|
143
|
+
"singleLine",
|
|
144
|
+
"leading",
|
|
145
|
+
"content",
|
|
146
|
+
"trailing",
|
|
147
|
+
"showCopyButton",
|
|
148
|
+
],
|
|
149
|
+
},
|
|
131
150
|
{
|
|
132
151
|
name: "Custom 04-13-42",
|
|
133
152
|
code: `CB-01
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# ColorSchemeButton
|
|
2
|
+
|
|
3
|
+
> **版本**: v1.0.1
|
|
4
|
+
> **职责**: 以真实 Button 为宿主,在页面亮色与暗色方案之间切换。
|
|
5
|
+
|
|
6
|
+
## 使用
|
|
7
|
+
|
|
8
|
+
```svelte
|
|
9
|
+
<ColorSchemeButton bare />
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
ColorSchemeButton 平铺 Button 的兼容 Props,支持全部变体与尺寸。默认读取 `document.documentElement`:`theme="dark"` 为暗色,移除该属性为亮色。无额外 children 时,组件主动向 Button 声明 `iconOnly=true`;内置 Sun / Moon 图标跟随 Button 尺寸上下文:普通 icon-only 的 `sm / md / lg` 为 `16 / 20 / 24px`,`bare` icon-only 则沿用 Button 的 `12 / 16 / 20px`。
|
|
13
|
+
|
|
14
|
+
旧名称 `ThemeButton` 仅作为弃用兼容别名保留;新代码统一使用 ColorSchemeButton。
|
|
15
|
+
|
|
16
|
+
点击后立即切换,不写入 storage,也不增加图标替换、主题切换动效。`applyToDocument={false}` 时组件只维护受控状态,适合由 Test、iframe 等宿主管理实际主题目标。
|
|
17
|
+
|
|
18
|
+
| 关键字 | 类型 | 默认值 | 描述 |
|
|
19
|
+
| --- | --- | --- | --- |
|
|
20
|
+
| `scheme` | `"light" \| "dark"` | 当前页面方案 | 当前方案,可 `bind:scheme` |
|
|
21
|
+
| `defaultScheme` | `"light" \| "dark"` | 当前页面方案 | 非受控初始方案 |
|
|
22
|
+
| `applyToDocument` | `boolean` | `true` | 是否同步页面根节点 |
|
|
23
|
+
| `ariaLabel` | `string` | 当前操作的本地化文案 | 覆盖按钮名称 |
|
|
24
|
+
| `lightIcon` / `darkIcon` | `Snippet` | Sun / Moon | 覆盖对应内置图标 |
|
|
25
|
+
| `children` | `Snippet` | 无 | 图标后的可选内容 |
|
|
26
|
+
| `onSchemeChange` | `(scheme) => void` | 无 | 切换完成后的回调 |
|
|
27
|
+
|
|
28
|
+
> 此区域的内容受保护。AI 在修改此区域前必须请求用户审查。
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
> **以下内容供 AI 阅读,用于维护代码与文档的关联**
|
|
33
|
+
|
|
34
|
+
## 开发者指南 (AI)
|
|
35
|
+
|
|
36
|
+
- 包归属:OSS;主布局模型为内联外壳布局。
|
|
37
|
+
- 组合身份:Button 宿主组件特化,不提供 `parts.Button`。
|
|
38
|
+
- 内置图标不传显式 size,必须消费 Button 注入的 ResourceIcon 尺寸上下文。
|
|
39
|
+
- 多实例通过观察根节点 `theme` 属性同步;`applyToDocument={false}` 时由受控 `scheme` 同步。
|
|
40
|
+
- 状态切换不接入 replacement preset、CSS transition 或 View Transition。
|
|
41
|
+
|
|
42
|
+
## 更新日志 (Changelog)
|
|
43
|
+
|
|
44
|
+
### v1.0.1 (2026-08-11)
|
|
45
|
+
|
|
46
|
+
- 无额外 children 时主动向 Button 声明 `iconOnly=true`;不再依赖图标 DOM 自动识别。
|
|
47
|
+
|
|
48
|
+
### v1.0.0 (2026-08-11)
|
|
49
|
+
|
|
50
|
+
- 从 ThemeButton 收敛命名为 ColorSchemeButton;修正内置图标按 Button 尺寸显示。
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!-- ColorSchemeButton:以真实 Button 为宿主的页面亮色 / 暗色方案切换按钮。 -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
import { onMount, type ComponentProps, type Snippet } from "svelte";
|
|
4
|
+
import { Icon as ResourceIcon } from "@snowui-design-system/resource-svelte";
|
|
5
|
+
import Button from "./Button.svelte";
|
|
6
|
+
import { useLocale } from "../i18n/locale.svelte";
|
|
7
|
+
import {
|
|
8
|
+
mergeComponentPartProps,
|
|
9
|
+
useComponentPart,
|
|
10
|
+
} from "../logic/component-parts.svelte";
|
|
11
|
+
|
|
12
|
+
export type ColorScheme = "light" | "dark";
|
|
13
|
+
|
|
14
|
+
type ButtonProps = ComponentProps<typeof Button>;
|
|
15
|
+
interface Props extends Omit<
|
|
16
|
+
ButtonProps,
|
|
17
|
+
"children" | "onclick" | "disabled" | "aria-pressed"
|
|
18
|
+
> {
|
|
19
|
+
scheme?: ColorScheme;
|
|
20
|
+
defaultScheme?: ColorScheme;
|
|
21
|
+
applyToDocument?: boolean;
|
|
22
|
+
ariaLabel?: string;
|
|
23
|
+
lightIcon?: Snippet;
|
|
24
|
+
darkIcon?: Snippet;
|
|
25
|
+
children?: Snippet;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
onSchemeChange?: (scheme: ColorScheme) => void;
|
|
28
|
+
onclick?: (event: MouseEvent) => void;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const locale = useLocale();
|
|
33
|
+
const inheritedPart = useComponentPart<Props>("ColorSchemeButton");
|
|
34
|
+
let { scheme = $bindable(), ...explicitProps }: Props = $props();
|
|
35
|
+
let {
|
|
36
|
+
defaultScheme = undefined,
|
|
37
|
+
applyToDocument = true,
|
|
38
|
+
ariaLabel = undefined,
|
|
39
|
+
lightIcon,
|
|
40
|
+
darkIcon,
|
|
41
|
+
children,
|
|
42
|
+
disabled = false,
|
|
43
|
+
onSchemeChange,
|
|
44
|
+
onclick,
|
|
45
|
+
...rest
|
|
46
|
+
}: Props = $derived(
|
|
47
|
+
mergeComponentPartProps(inheritedPart.current, explicitProps),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
let internalScheme = $state<ColorScheme>("light");
|
|
51
|
+
let mounted = $state(false);
|
|
52
|
+
const resolvedScheme = $derived(scheme ?? internalScheme);
|
|
53
|
+
const resolvedAriaLabel = $derived(
|
|
54
|
+
ariaLabel
|
|
55
|
+
?? locale.t(
|
|
56
|
+
resolvedScheme === "dark"
|
|
57
|
+
? "colorSchemeButton.toLight"
|
|
58
|
+
: "colorSchemeButton.toDark",
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
function readDocumentScheme(): ColorScheme {
|
|
63
|
+
return document.documentElement.getAttribute("theme") === "dark"
|
|
64
|
+
? "dark"
|
|
65
|
+
: "light";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function applyDocumentScheme(nextScheme: ColorScheme) {
|
|
69
|
+
if (!applyToDocument) return;
|
|
70
|
+
if (nextScheme === "dark") {
|
|
71
|
+
document.documentElement.setAttribute("theme", "dark");
|
|
72
|
+
} else {
|
|
73
|
+
document.documentElement.removeAttribute("theme");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onMount(() => {
|
|
78
|
+
const initialScheme = scheme
|
|
79
|
+
?? defaultScheme
|
|
80
|
+
?? (applyToDocument ? readDocumentScheme() : "light");
|
|
81
|
+
internalScheme = initialScheme;
|
|
82
|
+
scheme = initialScheme;
|
|
83
|
+
applyDocumentScheme(initialScheme);
|
|
84
|
+
|
|
85
|
+
if (!applyToDocument) {
|
|
86
|
+
mounted = true;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const observer = new MutationObserver(() => {
|
|
91
|
+
const nextScheme = readDocumentScheme();
|
|
92
|
+
internalScheme = nextScheme;
|
|
93
|
+
if (scheme !== nextScheme) scheme = nextScheme;
|
|
94
|
+
});
|
|
95
|
+
observer.observe(document.documentElement, {
|
|
96
|
+
attributes: true,
|
|
97
|
+
attributeFilter: ["theme"],
|
|
98
|
+
});
|
|
99
|
+
mounted = true;
|
|
100
|
+
return () => observer.disconnect();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
$effect(() => {
|
|
104
|
+
if (!mounted || scheme === undefined) return;
|
|
105
|
+
internalScheme = scheme;
|
|
106
|
+
applyDocumentScheme(scheme);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
function handleClick(event: MouseEvent) {
|
|
110
|
+
if (disabled) return;
|
|
111
|
+
onclick?.(event);
|
|
112
|
+
const nextScheme = resolvedScheme === "dark" ? "light" : "dark";
|
|
113
|
+
internalScheme = nextScheme;
|
|
114
|
+
scheme = nextScheme;
|
|
115
|
+
applyDocumentScheme(nextScheme);
|
|
116
|
+
onSchemeChange?.(nextScheme);
|
|
117
|
+
}
|
|
118
|
+
</script>
|
|
119
|
+
|
|
120
|
+
<Button
|
|
121
|
+
{...rest}
|
|
122
|
+
iconOnly={!children}
|
|
123
|
+
{disabled}
|
|
124
|
+
data-color-scheme-button
|
|
125
|
+
data-scheme={resolvedScheme}
|
|
126
|
+
aria-label={resolvedAriaLabel}
|
|
127
|
+
aria-pressed={resolvedScheme === "dark"}
|
|
128
|
+
onclick={handleClick}
|
|
129
|
+
>
|
|
130
|
+
{#if resolvedScheme === "dark"}
|
|
131
|
+
{#if darkIcon}
|
|
132
|
+
{@render darkIcon()}
|
|
133
|
+
{:else}
|
|
134
|
+
<ResourceIcon name="moon" aria-hidden="true" />
|
|
135
|
+
{/if}
|
|
136
|
+
{:else}
|
|
137
|
+
{#if lightIcon}
|
|
138
|
+
{@render lightIcon()}
|
|
139
|
+
{:else}
|
|
140
|
+
<ResourceIcon name="sun" aria-hidden="true" />
|
|
141
|
+
{/if}
|
|
142
|
+
{/if}
|
|
143
|
+
{@render children?.()}
|
|
144
|
+
</Button>
|