@snowui-design-system/components 0.2.0-alpha.7 → 0.2.0-alpha.8
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/README.md +27 -22
- package/package.json +8 -4
- package/src/assets/gradient-avatar/blue.svg +1 -0
- package/src/assets/gradient-avatar/cyan.svg +1 -0
- package/src/assets/gradient-avatar/green.svg +1 -0
- package/src/assets/gradient-avatar/orange.svg +1 -0
- package/src/assets/gradient-avatar/purple.svg +1 -0
- package/src/assets/gradient-avatar/red.svg +1 -0
- package/src/components/Accordion.md +1 -1
- package/src/components/Accordion.svelte +5 -1
- package/src/components/Avatar.md +95 -58
- package/src/components/Avatar.svelte +286 -92
- package/src/components/Avatar.test.ts +24 -3
- package/src/components/Badge.md +31 -2
- package/src/components/Badge.svelte +38 -3
- package/src/components/Badge.test.ts +14 -1
- package/src/components/Button.svelte +7 -1
- package/src/components/CodeBlock.md +8 -7
- package/src/components/CodeBlock.svelte +59 -25
- package/src/components/CodeBlock.test.ts +24 -2
- package/src/components/Dialog.svelte +1 -0
- package/src/components/Gradient.md +278 -0
- package/src/components/Gradient.svelte +1283 -0
- package/src/components/Gradient.test.ts +77 -0
- package/src/components/Icon.svelte +3 -1
- package/src/components/Image.svelte +11 -8
- package/src/components/Indicator.md +18 -4
- package/src/components/Indicator.svelte +151 -11
- package/src/components/Indicator.test.ts +25 -0
- package/src/components/Listbox.md +5 -0
- package/src/components/Listbox.svelte +26 -0
- package/src/components/Listbox.test.ts +14 -0
- package/src/components/MenuItem.md +5 -0
- package/src/components/MenuItem.svelte +6 -0
- package/src/components/Popover.md +5 -0
- package/src/components/Popover.svelte +25 -0
- package/src/components/Popover.test.ts +14 -0
- package/src/components/ScrollArea.md +7 -3
- package/src/components/ScrollArea.test.ts +3 -2
- package/src/components/SelectButton.svelte +8 -2
- package/src/components/Skeleton.md +13 -1
- package/src/components/Skeleton.svelte +30 -2
- package/src/components/Slider.md +68 -6
- package/src/components/Slider.svelte +329 -21
- package/src/components/Slider.test.ts +65 -0
- package/src/components/SnowUILogo.md +210 -0
- package/src/components/SnowUILogo.svelte +478 -0
- package/src/components/SnowUILogo.test.ts +62 -0
- package/src/components/Table.md +21 -5
- package/src/components/Table.svelte +18 -0
- package/src/components/TableBody.md +12 -1
- package/src/components/TableBody.svelte +26 -2
- package/src/components/TableBody.test.ts +3 -0
- package/src/components/TableCell.md +9 -3
- package/src/components/TableCell.svelte +108 -74
- package/src/components/TableCell.test.ts +2 -2
- package/src/components/TableHead.md +9 -3
- package/src/components/TableHead.svelte +36 -39
- package/src/components/TableHead.test.ts +5 -5
- package/src/components/TableRow.md +15 -5
- package/src/components/TableRow.svelte +47 -10
- package/src/components/TableRow.test.ts +2 -2
- package/src/components/TableToolbar.svelte +8 -3
- package/src/components/Text.md +7 -1
- package/src/components/Text.svelte +15 -7
- package/src/components/Tooltip.md +13 -4
- package/src/components/Tooltip.svelte +45 -7
- package/src/components/Tooltip.test.ts +27 -3
- package/src/index.ts +7 -0
- package/src/lib/color.md +2 -2
- package/src/lib/edge-fade.md +1 -0
- package/src/lib/overlay-scrollbar.md +6 -1
- package/src/lib/table-context.svelte.ts +11 -0
- package/src/lib/table-role-blur.ts +46 -0
- package/src/lib/table-truncation.md +14 -0
- package/src/lib/table-truncation.ts +83 -0
- package/src/lib/tooltip-motion-dismiss.md +18 -0
- package/src/lib/tooltip-motion-dismiss.ts +148 -0
- package/src/lib/tooltip-overlay.ts +9 -0
- package/src/logic/README.md +4 -1
- package/src/logic/continuous-hover.svelte.md +22 -0
- package/src/logic/continuous-hover.svelte.ts +436 -0
- package/src/logic/frame-truncation.md +9 -3
- package/src/logic/frame-truncation.svelte.ts +6 -0
- package/src/logic/layout-flip.ts +182 -5
- package/src/motion/presets/README.md +1 -0
- package/src/motion/presets/continuous-hover.md +11 -0
- package/src/motion/presets/continuous-hover.ts +18 -0
- package/src/motion/tokens.md +3 -1
- package/src/motion/tokens.ts +2 -0
- package/src/styles/README.md +16 -2
- package/src/styles/components.css +911 -0
- package/src/styles/index.css +3 -1
- package/src/styles/layout.css +44 -0
- package/src/styles/scrollbar.css +27 -7
- package/src/styles/themes.css +146 -0
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
<!-- 默认单行截断、接受任意内容的表格单元格。文档: ./TableCell.md -->
|
|
2
|
+
<script module lang="ts">
|
|
3
|
+
import { createEdgeFadeMaskImage } from "../lib/edge-fade";
|
|
4
|
+
|
|
5
|
+
const actionsFadeMask = createEdgeFadeMaskImage({
|
|
6
|
+
direction: "to left",
|
|
7
|
+
fadeStart: "var(--snowui-table-cell-actions-fade-width)",
|
|
8
|
+
fadeEnd: "calc(var(--snowui-table-cell-actions-fade-width) * var(--snowui-table-actions-fade-feather-override, 3))",
|
|
9
|
+
});
|
|
10
|
+
</script>
|
|
2
11
|
<script lang="ts">
|
|
3
|
-
import type
|
|
12
|
+
import { getContext, type Snippet } from "svelte";
|
|
4
13
|
import Frame, { type FrameProps } from "./Frame.svelte";
|
|
5
14
|
import Tooltip from "./Tooltip.svelte";
|
|
6
15
|
import Checkbox from "./Checkbox.svelte";
|
|
7
16
|
import Skeleton from "./Skeleton.svelte";
|
|
8
|
-
import { TruncationController } from "../logic/frame-truncation.svelte";
|
|
9
17
|
import { resizeManager } from "../logic/observer.svelte";
|
|
10
18
|
import { getTableContext, type TableRoleLayout } from "../lib/table-context.svelte";
|
|
11
19
|
import { getTableRowContext } from "../lib/table-row-context.svelte";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
20
|
+
import { SKELETON_CONTEXT_KEY } from "../keys";
|
|
21
|
+
import { getTableRoleBlurStyles } from "../lib/table-role-blur";
|
|
14
22
|
import {
|
|
15
23
|
mergeComponentPartProps,
|
|
16
24
|
useComponentPart,
|
|
@@ -36,11 +44,11 @@
|
|
|
36
44
|
const inheritedTableCellPart = useComponentPart<Props>("TableCell");
|
|
37
45
|
let explicitProps: Props = $props();
|
|
38
46
|
let { columnId, as: role = undefined, lines = 1, tooltip = true, onTruncate = undefined, align = "start", roleLayout = undefined, row = false, gap = 2, nowrap = false, skeleton = false, children, parts = undefined, whileAppear: userWhileAppear = undefined, currentState: userCurrentState = undefined, class: userClass = "", style: userStyle = "", enableResponsive = false, enableContext = false, enableScaleObserver = false, ...rest }: Props = $derived(mergeComponentPartProps(inheritedTableCellPart.current, explicitProps));
|
|
39
|
-
let contentElement = $state<HTMLElement>();
|
|
40
47
|
let roleOverlayElement = $state<HTMLElement>();
|
|
41
48
|
let hasNestedTruncationOwner = $state(false);
|
|
42
49
|
const table = getTableContext();
|
|
43
50
|
const rowContext = getTableRowContext();
|
|
51
|
+
const parentSkeletonContext = getContext(SKELETON_CONTEXT_KEY);
|
|
44
52
|
const rowId = $derived(rowContext?.getRowId());
|
|
45
53
|
const selectionEnabled = $derived(table.isSelectionEnabled());
|
|
46
54
|
const actionsEnabled = $derived(table.isActionsEnabled());
|
|
@@ -61,6 +69,9 @@
|
|
|
61
69
|
const isSelected = $derived(rowId !== undefined && table.isRowSelected(rowId));
|
|
62
70
|
const tableVariant = $derived(table.getVariant());
|
|
63
71
|
const resolvedRoleLayout = $derived(roleLayout ?? table.getRoleLayout());
|
|
72
|
+
const hasActionsOverlay = $derived(
|
|
73
|
+
table.isDataTable() && actionsEnabled && resolvedRoleLayout === "overlay",
|
|
74
|
+
);
|
|
64
75
|
const width = $derived(resolvedColumnId ? table.getColumnWidth(resolvedColumnId) : undefined);
|
|
65
76
|
const resolvedLines = $derived(skeleton || isSelectionRole || isActionsRole || lines === false ? undefined : lines);
|
|
66
77
|
const contextRowAppearMotion = $derived(
|
|
@@ -72,28 +83,46 @@
|
|
|
72
83
|
const resolvedCurrentState = $derived(
|
|
73
84
|
userCurrentState ?? (resolvedWhileAppear === undefined ? undefined : "Appear"),
|
|
74
85
|
);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
let isTruncated = $state(false);
|
|
87
|
+
let fullText = $state("");
|
|
88
|
+
function registerTruncation(
|
|
89
|
+
node: HTMLElement,
|
|
90
|
+
initial: { enabled: boolean; onChange?: (isTruncated: boolean) => void },
|
|
91
|
+
) {
|
|
92
|
+
let options = initial;
|
|
93
|
+
const cleanup = table.registerTruncationTarget(node, {
|
|
94
|
+
isEnabled: () => options.enabled,
|
|
95
|
+
notify: (result) => {
|
|
96
|
+
if (result.isTruncated !== isTruncated) {
|
|
97
|
+
isTruncated = result.isTruncated;
|
|
98
|
+
options.onChange?.(result.isTruncated);
|
|
99
|
+
}
|
|
100
|
+
if (result.fullText !== fullText) fullText = result.fullText;
|
|
101
|
+
if (result.hasNestedOwner !== hasNestedTruncationOwner) {
|
|
102
|
+
hasNestedTruncationOwner = result.hasNestedOwner;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
update(next: typeof initial) {
|
|
108
|
+
const wasEnabled = options.enabled;
|
|
109
|
+
const previousOnChange = options.onChange;
|
|
110
|
+
options = next;
|
|
111
|
+
if (!next.enabled && wasEnabled) {
|
|
112
|
+
if (isTruncated) previousOnChange?.(false);
|
|
113
|
+
isTruncated = false;
|
|
114
|
+
fullText = "";
|
|
115
|
+
hasNestedTruncationOwner = false;
|
|
116
|
+
}
|
|
117
|
+
table.requestTruncationMeasure();
|
|
118
|
+
},
|
|
119
|
+
destroy: cleanup,
|
|
91
120
|
};
|
|
92
|
-
|
|
93
|
-
});
|
|
121
|
+
}
|
|
94
122
|
$effect(() => {
|
|
95
123
|
const node = roleOverlayElement;
|
|
96
124
|
if (!node || resolvedRoleLayout !== "overlay" || (!isSelectionRole && !isActionsRole)) return;
|
|
125
|
+
const selected = isSelected;
|
|
97
126
|
let frame = 0;
|
|
98
127
|
const rowElement = node.closest<HTMLElement>(".snowui-table-row");
|
|
99
128
|
const layoutElement = rowElement?.closest<HTMLElement>(".snowui-data-table")
|
|
@@ -155,8 +184,9 @@
|
|
|
155
184
|
};
|
|
156
185
|
const shouldStayActive = () =>
|
|
157
186
|
Boolean(
|
|
187
|
+
selected ||
|
|
158
188
|
rowElement?.matches(
|
|
159
|
-
':hover, [data-force-hover="true"]
|
|
189
|
+
':hover, [data-force-hover="true"]',
|
|
160
190
|
) || rowElement?.contains(document.activeElement),
|
|
161
191
|
);
|
|
162
192
|
const deactivate = () => {
|
|
@@ -178,18 +208,8 @@
|
|
|
178
208
|
rowElement?.addEventListener("pointerleave", scheduleDeactivate);
|
|
179
209
|
rowElement?.addEventListener("focusin", activate);
|
|
180
210
|
rowElement?.addEventListener("focusout", scheduleDeactivate);
|
|
181
|
-
const selectedObserver = rowElement
|
|
182
|
-
? new MutationObserver(() => {
|
|
183
|
-
if (shouldStayActive()) activate();
|
|
184
|
-
else scheduleDeactivate();
|
|
185
|
-
})
|
|
186
|
-
: undefined;
|
|
187
|
-
selectedObserver?.observe(rowElement!, {
|
|
188
|
-
attributes: true,
|
|
189
|
-
attributeFilter: ["data-selected"],
|
|
190
|
-
});
|
|
191
211
|
// 空闲行不做同步布局测量;hover / focus / selected / force-hover 时再激活。
|
|
192
|
-
//
|
|
212
|
+
// selected 直接消费 Svelte 派生状态,不再为每个角色单元格创建 MutationObserver。
|
|
193
213
|
// 激活后额外监听 DataTable/Table 容器尺寸,覆盖内置工具栏出现/消失导致的整表位移。
|
|
194
214
|
if (shouldStayActive()) activate();
|
|
195
215
|
return () => {
|
|
@@ -202,50 +222,41 @@
|
|
|
202
222
|
rowElement?.removeEventListener("pointerleave", scheduleDeactivate);
|
|
203
223
|
rowElement?.removeEventListener("focusin", activate);
|
|
204
224
|
rowElement?.removeEventListener("focusout", scheduleDeactivate);
|
|
205
|
-
selectedObserver?.disconnect();
|
|
206
225
|
reset();
|
|
207
226
|
};
|
|
208
227
|
});
|
|
209
228
|
const finalStyle = $derived(`${width ? `--snowui-table-cell-width-runtime:${width}px;width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));min-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));max-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime))` : ""};text-align:${align};${userStyle}`);
|
|
210
229
|
// actions 的遮罩依赖每行实测后写入的宽度变量,必须在内容单元格自身计算。
|
|
211
230
|
// 若把这条表达式定义在 Table 根上,根节点无法读取后代行上的变量,整条 mask 会失效。
|
|
212
|
-
const actionsFadeMask = createEdgeFadeMaskImage({
|
|
213
|
-
direction: "to left",
|
|
214
|
-
fadeStart: "var(--snowui-table-cell-actions-fade-width)",
|
|
215
|
-
fadeEnd: "calc(var(--snowui-table-cell-actions-fade-width) * var(--snowui-table-actions-fade-feather-override, 3))",
|
|
216
|
-
});
|
|
217
231
|
const contentStyle = $derived(
|
|
218
232
|
`${gap === undefined
|
|
219
233
|
? ""
|
|
220
234
|
: `gap:${typeof gap === "number" ? `var(--gap-${gap}, calc(var(--gap-1) * ${gap}))` : gap};`}` +
|
|
221
|
-
`--snowui-table-cell-actions-fade-mask:${actionsFadeMask}
|
|
235
|
+
`${hasActionsOverlay ? `--snowui-table-cell-actions-fade-mask:${actionsFadeMask};` : ""}`,
|
|
236
|
+
);
|
|
237
|
+
const selectionBlur = $derived(getTableRoleBlurStyles(table, "left-to-right"));
|
|
238
|
+
const actionsBlur = $derived(getTableRoleBlurStyles(table, "right-to-left"));
|
|
239
|
+
const selectionCheckboxSizeStyle = $derived(
|
|
240
|
+
parts?.Checkbox?.size === undefined
|
|
241
|
+
? "--snowui-checkbox-size-override: var(--snowui-table-selection-checkbox-size-override, calc(var(--size-4, 1rem) + 0.0625rem))"
|
|
242
|
+
: undefined,
|
|
243
|
+
);
|
|
244
|
+
const useSemanticFastPath = $derived(
|
|
245
|
+
!skeleton
|
|
246
|
+
&& !isSelectionRole
|
|
247
|
+
&& !isActionsRole
|
|
248
|
+
&& resolvedWhileAppear === undefined
|
|
249
|
+
&& userCurrentState === undefined
|
|
250
|
+
&& parts === undefined
|
|
251
|
+
&& parentSkeletonContext === undefined
|
|
252
|
+
&& !enableResponsive
|
|
253
|
+
&& !enableContext
|
|
254
|
+
&& !enableScaleObserver
|
|
255
|
+
&& Object.keys(rest).length === 0,
|
|
222
256
|
);
|
|
223
|
-
function buildRoleOverlayBlur(direction: ProgressiveBlurDirection) {
|
|
224
|
-
const options = {
|
|
225
|
-
direction,
|
|
226
|
-
layerCount: table.getRoleOverlayLayers(),
|
|
227
|
-
width: "var(--snowui-table-role-overlay-width-override, calc((var(--size-12, 3rem) + var(--size-14, 3.5rem)) / 3))",
|
|
228
|
-
sampleExtension: "var(--snowui-table-role-overlay-sample-extension-override, 4rem)",
|
|
229
|
-
maxBlur: "var(--snowui-table-role-overlay-blur-override, 0rem)",
|
|
230
|
-
minBlur: "0rem",
|
|
231
|
-
leadWidthRatio: 0.1,
|
|
232
|
-
endRatio: 0.72,
|
|
233
|
-
featherRatio: 2.8,
|
|
234
|
-
tailOpacity: 0,
|
|
235
|
-
edgeFeatherRatio: table.getRoleOverlayUniformFeather(),
|
|
236
|
-
tintColor: "#ffffff",
|
|
237
|
-
tintOpacity: "var(--snowui-table-role-overlay-tint-opacity-override, 0%)",
|
|
238
|
-
};
|
|
239
|
-
return table.getRoleOverlayBlurMode() === "uniform"
|
|
240
|
-
? createUniformBlurStyles(options)
|
|
241
|
-
: createProgressiveBlurStyles(options);
|
|
242
|
-
}
|
|
243
|
-
const selectionBlur = $derived(buildRoleOverlayBlur("left-to-right"));
|
|
244
|
-
const actionsBlur = $derived(buildRoleOverlayBlur("right-to-left"));
|
|
245
257
|
</script>
|
|
246
258
|
|
|
247
|
-
{#
|
|
248
|
-
<Frame tag="td" data-column-id={resolvedColumnId} data-table-variant={tableVariant} data-role-layout={isSelectionRole || isActionsRole ? resolvedRoleLayout : undefined} data-skeleton={skeleton ? "true" : undefined} as={isSelectionRole || isActionsRole ? role : undefined} class={`snowui-table-cell ${userClass}`} style={finalStyle} whileAppear={resolvedWhileAppear} currentState={resolvedCurrentState} enableAutoLayout={false} enableResponsive={enableResponsive} enableContext={enableContext} enableScaleObserver={enableScaleObserver} componentParts={parts} {...rest}>
|
|
259
|
+
{#snippet renderCellContent()}
|
|
249
260
|
{#if skeleton}
|
|
250
261
|
<span class="snowui-table-cell-content snowui-table-cell-skeleton" aria-hidden="true">
|
|
251
262
|
{#if !isSelectionRole && !isActionsRole}
|
|
@@ -257,6 +268,7 @@
|
|
|
257
268
|
bind:this={roleOverlayElement}
|
|
258
269
|
class="snowui-table-selection-control"
|
|
259
270
|
data-selected={isSelected ? "true" : undefined}
|
|
271
|
+
style={selectionCheckboxSizeStyle}
|
|
260
272
|
>
|
|
261
273
|
<span class="snowui-table-role-blur-layer" style={selectionBlur.containerStyle} aria-hidden="true">
|
|
262
274
|
{#each selectionBlur.layers as layer (layer.index)}
|
|
@@ -264,7 +276,6 @@
|
|
|
264
276
|
{/each}
|
|
265
277
|
</span>
|
|
266
278
|
<Checkbox
|
|
267
|
-
size={16}
|
|
268
279
|
checked={isSelected}
|
|
269
280
|
ariaLabel="选择当前行"
|
|
270
281
|
onclick={(event: MouseEvent) => event.stopPropagation()}
|
|
@@ -281,19 +292,38 @@
|
|
|
281
292
|
</span>
|
|
282
293
|
<span class="snowui-table-role-overlay-controls">{#if children}{@render children()}{/if}</span>
|
|
283
294
|
</span>
|
|
284
|
-
{:else}<span
|
|
295
|
+
{:else}<span use:registerTruncation={{ enabled: resolvedLines === 1, onChange: onTruncate }} class={`snowui-table-cell-content ${resolvedLines ? `snowui-line-clamp-${resolvedLines}` : ""}`} data-row={row ? "true" : undefined} data-nowrap={nowrap ? "true" : undefined} data-lines={resolvedLines} data-truncated={isTruncated ? "true" : "false"} style={contentStyle}>
|
|
285
296
|
{#if children}{@render children()}{/if}
|
|
286
|
-
{#if tooltip && !hasNestedTruncationOwner &&
|
|
297
|
+
{#if tooltip && !hasNestedTruncationOwner && isTruncated && fullText}
|
|
287
298
|
<Tooltip>
|
|
288
|
-
{#if typeof tooltip === "string"}{tooltip}{:else if typeof tooltip === "function"}{@render tooltip()}{:else}{
|
|
299
|
+
{#if typeof tooltip === "string"}{tooltip}{:else if typeof tooltip === "function"}{@render tooltip()}{:else}{fullText}{/if}
|
|
289
300
|
</Tooltip>
|
|
290
301
|
{/if}
|
|
291
302
|
</span>{/if}
|
|
303
|
+
{/snippet}
|
|
304
|
+
|
|
305
|
+
{#if !isRoleColumnHidden}
|
|
306
|
+
{#if useSemanticFastPath}
|
|
307
|
+
<td
|
|
308
|
+
data-column-id={resolvedColumnId}
|
|
309
|
+
data-table-variant={tableVariant}
|
|
310
|
+
class={`snowui-frame snowui-table-cell ${userClass}`}
|
|
311
|
+
data-snowui-frame="true"
|
|
312
|
+
data-content-width="hug"
|
|
313
|
+
data-state="Idle"
|
|
314
|
+
style={finalStyle}
|
|
315
|
+
>
|
|
316
|
+
{@render renderCellContent()}
|
|
317
|
+
</td>
|
|
318
|
+
{:else}
|
|
319
|
+
<Frame tag="td" data-column-id={resolvedColumnId} data-table-variant={tableVariant} data-role-layout={isSelectionRole || isActionsRole ? resolvedRoleLayout : undefined} data-skeleton={skeleton ? "true" : undefined} as={isSelectionRole || isActionsRole ? role : undefined} class={`snowui-table-cell ${userClass}`} style={finalStyle} whileAppear={resolvedWhileAppear} currentState={resolvedCurrentState} enableAutoLayout={false} enableResponsive={enableResponsive} enableContext={enableContext} enableScaleObserver={enableScaleObserver} componentParts={parts} {...rest}>
|
|
320
|
+
{@render renderCellContent()}
|
|
292
321
|
</Frame>
|
|
293
322
|
{/if}
|
|
323
|
+
{/if}
|
|
294
324
|
|
|
295
325
|
<style>
|
|
296
|
-
:global(:where(.snowui-table-cell)) { position: relative; box-sizing: border-box; height: var(--size-10, 2.5rem); padding: var(--snowui-table-cell-padding-override, var(--padding-2, .5rem) var(--padding-3, .75rem)); border-bottom: var(--border-1, .5px) solid var(--black-10, #0000001a); font-size: var(--text-12, .75rem); line-height: var(--leading-12, 1rem); vertical-align: middle; }
|
|
326
|
+
:global(:where(.snowui-table-cell)) { position: relative; box-sizing: border-box; height: var(--size-10, 2.5rem); padding: var(--snowui-table-cell-padding-override, var(--padding-2, .5rem) var(--padding-3, .75rem)); border-bottom: var(--border-1, .5px) solid var(--black-10, #0000001a); background: var(--snowui-table-row-active-background, transparent); font-size: var(--text-12, .75rem); line-height: var(--leading-12, 1rem); vertical-align: middle; }
|
|
297
327
|
:global(:where(.snowui-table-cell[data-as="selection"])) { width: var(--size-10); padding: var(--snowui-table-cell-selection-padding-override, var(--padding-2) var(--padding-3)); }
|
|
298
328
|
:global(:where(.snowui-table-cell[data-as="actions"])) { width: var(--size-10); padding: var(--snowui-table-cell-actions-padding-override, var(--padding-2) var(--padding-3)); }
|
|
299
329
|
:global(:where(.snowui-table-cell[data-skeleton="true"])) { pointer-events: none; }
|
|
@@ -309,6 +339,8 @@
|
|
|
309
339
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="actions"])) { right: 0; }
|
|
310
340
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"] .snowui-table-selection-control)) { position: absolute; inset-block: 0 calc(-1 * var(--border-1, .5px)); inset-inline-start: 0; box-sizing: border-box; display: flex; width: var(--size-10, 2.5rem); align-items: center; justify-content: center; overflow: visible; padding: var(--padding-2, 0.5rem) var(--padding-3, 0.75rem); border-radius: var(--snowui-table-row-radius-override, var(--radius-3, 0.75rem)); background: transparent; z-index: 2147483647; pointer-events: auto; }
|
|
311
341
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"])) { opacity: 1; pointer-events: none; transition: none; }
|
|
342
|
+
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell[data-role-layout="overlay"][data-as="selection"] + .snowui-table-cell) { border-radius: var(--snowui-table-row-active-leading-radius, 0); }
|
|
343
|
+
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell:has(+ .snowui-table-cell[data-role-layout="overlay"][data-as="actions"])) { border-radius: var(--snowui-table-row-active-trailing-radius, 0); }
|
|
312
344
|
:global(:where(.snowui-table-body .snowui-table-row:hover, .snowui-table-body .snowui-table-row[data-force-hover="true"]) > .snowui-table-cell[data-role-layout="overlay"][data-as="selection"] + .snowui-table-cell) { border-radius: var(--snowui-table-row-radius-override, var(--radius-3, 0.75rem)) 0 0 var(--snowui-table-row-radius-override, var(--radius-3, 0.75rem)); }
|
|
313
345
|
:global(:where(.snowui-table-body .snowui-table-row:hover, .snowui-table-body .snowui-table-row[data-force-hover="true"]) > .snowui-table-cell:has(+ .snowui-table-cell[data-role-layout="overlay"][data-as="actions"])) { border-radius: 0 var(--snowui-table-row-radius-override, var(--radius-3, 0.75rem)) var(--snowui-table-row-radius-override, var(--radius-3, 0.75rem)) 0; }
|
|
314
346
|
:global(:where(.snowui-table-body .snowui-table-row:last-child) > .snowui-table-cell) { border-bottom-color: transparent; }
|
|
@@ -334,13 +366,15 @@
|
|
|
334
366
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="selection"] .snowui-table-selection-control[data-selected="true"]) > :not(.snowui-table-role-blur-layer)),
|
|
335
367
|
:global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"]) .snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"] > :not(.snowui-table-role-blur-layer)) { opacity: 1; pointer-events: auto; }
|
|
336
368
|
:global(:where(.snowui-table-cell[data-table-variant="striped"])) { border-bottom-color: transparent; }
|
|
337
|
-
:global(:where(.snowui-table-body .snowui-table-row:nth-child(odd)) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--surface-3, #f7f7f7); }
|
|
338
|
-
:global(:where(.snowui-table-body .snowui-table-row:nth-child(even)) > .snowui-table-cell[data-table-variant="striped"]) { background: transparent; }
|
|
369
|
+
:global(:where(.snowui-table-body .snowui-table-row:nth-child(odd)) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--snowui-table-row-active-background, var(--surface-3, #f7f7f7)); }
|
|
370
|
+
:global(:where(.snowui-table-body .snowui-table-row:nth-child(even)) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--snowui-table-row-active-background, transparent); }
|
|
371
|
+
:global(:where(.snowui-table-body[data-continuous-hover-enabled="true"] .snowui-table-row:hover) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--snowui-table-row-active-background, transparent); }
|
|
372
|
+
:global(:where(.snowui-table-body .snowui-table-row[data-force-hover="true"]) > .snowui-table-cell:not([data-role-layout="overlay"])) { background: var(--snowui-table-row-hover-background-override, var(--black-4, #0000000a)); }
|
|
339
373
|
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell[data-table-variant="striped"]:first-child) { border-radius: var(--radius-3) 0 0 var(--radius-3); }
|
|
340
374
|
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell[data-table-variant="striped"]:last-child) { border-radius: 0 var(--radius-3) var(--radius-3) 0; }
|
|
341
375
|
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell[data-role-layout="overlay"][data-as="selection"] + .snowui-table-cell[data-table-variant="striped"]) { border-radius: var(--radius-3) 0 0 var(--radius-3); }
|
|
342
376
|
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell[data-table-variant="striped"]:has(+ .snowui-table-cell[data-role-layout="overlay"][data-as="actions"])) { border-radius: 0 var(--radius-3) var(--radius-3) 0; }
|
|
343
|
-
:global(:where(.snowui-table-body .snowui-table-row:not([data-skeleton="true"]):hover, .snowui-table-body .snowui-table-row:not([data-skeleton="true"])[data-force-hover="true"]) > .snowui-table-cell) {
|
|
377
|
+
:global(:where(.snowui-table-body .snowui-table-row:not([data-skeleton="true"]):hover, .snowui-table-body .snowui-table-row:not([data-skeleton="true"])[data-force-hover="true"]) > .snowui-table-cell) { border-bottom-color: transparent; }
|
|
344
378
|
:global(:where(.snowui-table-body .snowui-table-row:has(+ .snowui-table-row:not([data-skeleton="true"]):hover), .snowui-table-body .snowui-table-row:has(+ .snowui-table-row:not([data-skeleton="true"])[data-force-hover="true"])) > .snowui-table-cell) { border-bottom-color: transparent; }
|
|
345
379
|
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell[data-role-layout="overlay"]) { background: transparent; }
|
|
346
380
|
:global(:where(.snowui-table-body .snowui-table-row:hover) > .snowui-table-cell[data-role-layout="overlay"]) { background: transparent; }
|
|
@@ -24,14 +24,14 @@ export const examples = [
|
|
|
24
24
|
name: "A4: 选择与行动单元格角色",
|
|
25
25
|
code: `A4
|
|
26
26
|
<Table selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell as="actions"><Button bare>更多</Button></TableCell></TableRow></TableBody></Table>`,
|
|
27
|
-
expected: { render: "selection 内置行 Checkbox;actions 渲染调用方按钮。", layout: "actions 横向排列且 gap 8px。", interaction: "Checkbox 在 hover/focus/selected 时显示;actions 只在 hover 时显示。", performance: "无 DOM 身份猜测。", responsive: "角色列保持窄宽。" },
|
|
27
|
+
expected: { render: "selection 内置行 Checkbox;actions 渲染调用方按钮。", layout: "selection Checkbox 默认 17px,在奇数高度行内上下留白对称;actions 横向排列且 gap 8px。", interaction: "Checkbox 在 hover/focus/selected 时显示;actions 只在 hover 时显示。", performance: "无 DOM 身份猜测。", responsive: "角色列保持窄宽。" },
|
|
28
28
|
logic: ["Selection", "Actions"],
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
name: "A5: 覆盖式角色单元格",
|
|
32
32
|
code: `A5
|
|
33
33
|
<Table roleLayout="overlay" selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell>SnowUI</TableCell><TableCell as="actions"><Button bare>更多</Button></TableCell></TableRow></TableBody></Table>`,
|
|
34
|
-
expected: { render: "selection/actions 仍保持合法 td。", layout: "角色 td
|
|
34
|
+
expected: { render: "selection/actions 仍保持合法 td。", layout: "角色 td 宽度归零,17px Checkbox 在覆盖块内垂直居中,覆盖块 sticky 到行左右边缘并用透明模糊渐变柔化后方内容。", interaction: "已选行 Checkbox 保持显示,actions 仍只在行 hover 时显示。", performance: "选择状态直接来自 rowId + Table Context,不创建逐单元格 MutationObserver。", responsive: "不改变普通内容列宽。" },
|
|
35
35
|
logic: ["Selection", "Actions", "OverlayRoleLayout"],
|
|
36
36
|
},
|
|
37
37
|
{
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
- `parts.Checkbox`:配置 selection 表头的全选 Checkbox。
|
|
9
9
|
- 排序、选择和列宽事件属于 TableHead 受控协议,parts 不得覆盖。
|
|
10
10
|
|
|
11
|
-
> **版本**:
|
|
11
|
+
> **版本**: v2.1.0
|
|
12
12
|
> **职责**: `<th scope="col">`、排序触发器与列宽手柄宿主。
|
|
13
13
|
|
|
14
14
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
| defaultSortActive | `boolean` | `false` | 使 `defaultSort` 的默认方向也显示激活态和图标,并将交互循环扩展为可取消排序 |
|
|
22
22
|
| roleLayout | `column \| overlay` | Table context | 覆盖当前角色表头的角色列布局;普通表头忽略 |
|
|
23
23
|
| onSortChange | `(direction) => void` | - | 独立使用时的三态排序回调 |
|
|
24
|
-
| resizable | `boolean` | `
|
|
24
|
+
| resizable | `boolean` | `true` | 是否显示列宽手柄;普通列默认可拖动改宽,设为 `false` 时关闭 |
|
|
25
25
|
| minWidth / maxWidth | `number` | `64 / Infinity` | 拖动约束 |
|
|
26
26
|
|
|
27
27
|
排序状态同步到 `aria-sort`。**只有 DataTable `defaultSort` 命中列的默认方向不显示激活态或图标**(`defaultSortActive` 可覆写);其他已排序状态显示对应图标。图标遵循主流前端表格的“数值方向”语义:ascending(A→Z、0→9、早→晚)显示内置 `ArrowsUp`;descending(Z→A、9→0、晚→早)显示内置 `ArrowsDown`。图标尺寸为 16px,与文字间距为 0。
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
|
|
36
36
|
不需要 `sortable` prop。DataTable 根据同名原始字段或 `sorters[columnId]` 自动判断列是否可排序;独立 TableHead 在声明 `sortDirection` / `onSortChange` 时也自动启用交互。没有任何排序规则的列不渲染按钮。
|
|
37
37
|
|
|
38
|
+
普通数据列只要声明 `columnId`,默认就在列尾渲染 Indicator 并允许拖动修改宽度;不需要重复声明 `resizable`。`as="selection"` / `as="actions"` 角色列始终不参与列宽拖动。某一列需要固定宽度时,显式传入 `resizable={false}`。
|
|
39
|
+
|
|
38
40
|
未声明任何 `defaultSort` 时,TableHead 不会把第一列视为隐式默认排序列。当所有列均未激活排序时,DataTable 保留上层传入的 rows / filteredRows 顺序。
|
|
39
41
|
|
|
40
42
|
## 角色列
|
|
@@ -64,7 +66,7 @@ TableHead **不声明内容类别**,也不公开 `sortType="text | number | da
|
|
|
64
66
|
默认排序由对应列头直接声明:
|
|
65
67
|
|
|
66
68
|
```svelte
|
|
67
|
-
<TableHead columnId="createdAt" defaultSort="descending"
|
|
69
|
+
<TableHead columnId="createdAt" defaultSort="descending">Date</TableHead>
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
同一个 DataTable 只能有一个 TableHead 声明 `defaultSort`。该声明优先于 DataTable 旧的对象式 `defaultSort={{ columnId, direction }}`;DataTable 对象式入口仅作为兼容回退保留。
|
|
@@ -99,6 +101,10 @@ TableHead **不声明内容类别**,也不公开 `sortType="text | number | da
|
|
|
99
101
|
|
|
100
102
|
## Changelog
|
|
101
103
|
|
|
104
|
+
- 2026-08-06:v2.1.0,普通数据列的 `resizable` 默认值改为 `true`;声明 `columnId` 后即可拖动改宽,固定列可显式传入 `resizable={false}`;selection/actions 角色列保持不可拖动。
|
|
105
|
+
- 2026-08-03:v1.9.2,selection Checkbox 的 1px 增量改为固定 `0.0625rem` 特例,不再复用边框 Token。
|
|
106
|
+
- 2026-08-03:v1.9.1,selection 全选 Checkbox 与数据行统一使用 Token 计算的 17px Table 组合尺寸;独立 Checkbox 默认值不变。
|
|
107
|
+
|
|
102
108
|
- 2026-07-12:v2.0.1,适配 Indicator line 全高命中带;表头视觉恢复 1×16 贴右缘。
|
|
103
109
|
- 2026-07-01:v2.0.0,新增 `label` 并把可排序列元数据注册给 DataTable / TableToolbar。
|
|
104
110
|
- 2026-06-30:v1.9.0,overlay selection 标题渐隐改为固定约 14px → 26px,视觉对齐 Table Demo 表格一,不再随标题或列宽变化。
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import Indicator from "./Indicator.svelte";
|
|
7
7
|
import Checkbox from "./Checkbox.svelte";
|
|
8
8
|
import { getTableContext, type TableColumnRegistration, type TableRoleLayout } from "../lib/table-context.svelte";
|
|
9
|
-
import {
|
|
9
|
+
import { getTableRoleBlurStyles } from "../lib/table-role-blur";
|
|
10
10
|
import {
|
|
11
11
|
type ComponentPartsOf,
|
|
12
12
|
} from "../logic/component-parts.svelte";
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
}>;
|
|
33
33
|
[key: string]: any;
|
|
34
34
|
}
|
|
35
|
-
let { columnId = undefined, label = undefined, as: role = undefined, sortDirection = undefined, defaultSort = undefined, defaultSortActive = false, roleLayout = undefined, onSortChange = undefined, resizable: canResize =
|
|
35
|
+
let { columnId = undefined, label = undefined, as: role = undefined, sortDirection = undefined, defaultSort = undefined, defaultSortActive = false, roleLayout = undefined, onSortChange = undefined, resizable: canResize = true, minWidth = 64, maxWidth = Infinity, align = "start", children, parts = undefined, class: userClass = "", style: userStyle = "", use: userActions = [], enableResponsive = false, enableContext = false, enableScaleObserver = false, ...rest }: Props = $props();
|
|
36
36
|
const table = getTableContext();
|
|
37
37
|
const selectionEnabled = $derived(table.isSelectionEnabled());
|
|
38
38
|
const actionsEnabled = $derived(table.isActionsEnabled());
|
|
@@ -65,6 +65,12 @@
|
|
|
65
65
|
});
|
|
66
66
|
const tableVariant = $derived(table.getVariant());
|
|
67
67
|
const resolvedRoleLayout = $derived(roleLayout ?? table.getRoleLayout());
|
|
68
|
+
const hasSelectionOverlay = $derived(
|
|
69
|
+
table.isDataTable() && selectionEnabled && resolvedRoleLayout === "overlay",
|
|
70
|
+
);
|
|
71
|
+
const hasActionsOverlay = $derived(
|
|
72
|
+
table.isDataTable() && actionsEnabled && resolvedRoleLayout === "overlay",
|
|
73
|
+
);
|
|
68
74
|
const width = $derived(resolvedColumnId ? table.getColumnWidth(resolvedColumnId) : undefined);
|
|
69
75
|
const sort = $derived(table.getSort());
|
|
70
76
|
const selectionState = $derived(table.getSelectionState());
|
|
@@ -114,43 +120,30 @@
|
|
|
114
120
|
}
|
|
115
121
|
table.toggleSort(columnId);
|
|
116
122
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
endRatio: 0.72,
|
|
127
|
-
featherRatio: 2.8,
|
|
128
|
-
tailOpacity: 0,
|
|
129
|
-
edgeFeatherRatio: table.getRoleOverlayUniformFeather(),
|
|
130
|
-
tintColor: "#ffffff",
|
|
131
|
-
tintOpacity: "var(--snowui-table-role-overlay-tint-opacity-override, 0%)",
|
|
132
|
-
};
|
|
133
|
-
return table.getRoleOverlayBlurMode() === "uniform"
|
|
134
|
-
? createUniformBlurStyles(options)
|
|
135
|
-
: createProgressiveBlurStyles(options);
|
|
136
|
-
}
|
|
137
|
-
const selectionBlur = $derived(buildRoleOverlayBlur("left-to-right"));
|
|
138
|
-
const actionsBlur = $derived(buildRoleOverlayBlur("right-to-left"));
|
|
139
|
-
const selectionContentBlur = $derived(buildRoleOverlayBlur("left-to-right"));
|
|
140
|
-
const actionsContentBlur = $derived(buildRoleOverlayBlur("right-to-left"));
|
|
123
|
+
const selectionBlur = $derived(getTableRoleBlurStyles(table, "left-to-right"));
|
|
124
|
+
const actionsBlur = $derived(getTableRoleBlurStyles(table, "right-to-left"));
|
|
125
|
+
const selectionContentBlur = $derived(getTableRoleBlurStyles(table, "left-to-right"));
|
|
126
|
+
const actionsContentBlur = $derived(getTableRoleBlurStyles(table, "right-to-left"));
|
|
127
|
+
const selectionCheckboxSizeStyle = $derived(
|
|
128
|
+
parts?.Checkbox?.size === undefined
|
|
129
|
+
? "--snowui-checkbox-size-override: var(--snowui-table-selection-checkbox-size-override, calc(var(--size-4, 1rem) + 0.0625rem))"
|
|
130
|
+
: undefined,
|
|
131
|
+
);
|
|
141
132
|
</script>
|
|
142
133
|
|
|
143
134
|
{#if !isRoleColumnHidden}
|
|
144
135
|
<Frame tag="th" aria-sort={!isSelectionRole && !isActionsRole ? direction ?? (isSortable ? "none" : undefined) : undefined} data-column-id={resolvedColumnId} data-sort={direction} data-selected={selectionState.some || selectionState.all ? "true" : undefined} data-table-variant={tableVariant} data-role-layout={isSelectionRole || isActionsRole ? resolvedRoleLayout : undefined} as={isSelectionRole || isActionsRole ? role : undefined} class={`snowui-table-head ${userClass}`} style={finalStyle} use={finalUse} enableAutoLayout={false} enableResponsive={enableResponsive} enableContext={enableContext} enableScaleObserver={enableScaleObserver} componentParts={parts} {...rest}>
|
|
145
136
|
{#if isSelectionRole}
|
|
146
|
-
<span
|
|
137
|
+
<span
|
|
138
|
+
class="snowui-table-selection-control"
|
|
139
|
+
style={selectionCheckboxSizeStyle}
|
|
140
|
+
>
|
|
147
141
|
<span class="snowui-table-role-blur-layer" style={selectionBlur.containerStyle} aria-hidden="true">
|
|
148
142
|
{#each selectionBlur.layers as layer (layer.index)}
|
|
149
143
|
<span style={layer.style}></span>
|
|
150
144
|
{/each}
|
|
151
145
|
</span>
|
|
152
146
|
<Checkbox
|
|
153
|
-
size={16}
|
|
154
147
|
checked={selectionState.all}
|
|
155
148
|
indeterminate={selectionState.some}
|
|
156
149
|
ariaLabel="选择全部当前行"
|
|
@@ -179,16 +172,20 @@
|
|
|
179
172
|
<span class="snowui-table-head-content snowui-table-head-content-static">{#if children}{@render children()}{/if}</span>
|
|
180
173
|
{/if}
|
|
181
174
|
{#if !isSelectionRole && !isActionsRole}
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
|
|
175
|
+
{#if hasSelectionOverlay}
|
|
176
|
+
<span class="snowui-table-head-selection-blur-proxy" style={selectionContentBlur.containerStyle} aria-hidden="true">
|
|
177
|
+
{#each selectionContentBlur.layers as layer (layer.index)}
|
|
178
|
+
<span style={layer.style}></span>
|
|
179
|
+
{/each}
|
|
180
|
+
</span>
|
|
181
|
+
{/if}
|
|
182
|
+
{#if hasActionsOverlay}
|
|
183
|
+
<span class="snowui-table-head-actions-blur-proxy" style={actionsContentBlur.containerStyle} aria-hidden="true">
|
|
184
|
+
{#each actionsContentBlur.layers as layer (layer.index)}
|
|
185
|
+
<span style={layer.style}></span>
|
|
186
|
+
{/each}
|
|
187
|
+
</span>
|
|
188
|
+
{/if}
|
|
192
189
|
{/if}
|
|
193
190
|
{#if canResize && resolvedColumnId && !isSelectionRole && !isActionsRole}
|
|
194
191
|
<Indicator
|
|
@@ -265,7 +262,7 @@
|
|
|
265
262
|
width: calc(var(--size-3, 0.75rem) / 6);
|
|
266
263
|
}
|
|
267
264
|
:global(:where(.snowui-table-head[data-table-variant="striped"])) { border-bottom-color: transparent; }
|
|
268
|
-
:global(:where(.snowui-table-header:has(+ .snowui-table-body > .snowui-table-row:first-child:not([aria-hidden="true"]):hover), .snowui-table-header:has(+ .snowui-table-body > .snowui-table-row:first-child:not([aria-hidden="true"])[data-force-hover="true"])) .snowui-table-head:not([data-table-variant="striped"])) { border-bottom-color: transparent; }
|
|
265
|
+
:global(:where(.snowui-table-header:has(+ .snowui-table-body > .snowui-table-row:first-child:not([aria-hidden="true"]):hover), .snowui-table-header:has(+ .snowui-table-body > .snowui-table-row:first-child:not([aria-hidden="true"])[data-active="true"]), .snowui-table-header:has(+ .snowui-table-body > .snowui-table-row:first-child:not([aria-hidden="true"])[data-force-hover="true"])) .snowui-table-head:not([data-table-variant="striped"])) { border-bottom-color: transparent; }
|
|
269
266
|
/* 表头内容渐隐过渡(mask-image),触发条件见下方规则。 */
|
|
270
267
|
:global(:where(.snowui-table-head-content)) {
|
|
271
268
|
transition:
|
|
@@ -2,7 +2,7 @@ export const examples = [
|
|
|
2
2
|
{
|
|
3
3
|
name: "A1: DataTable 排序与列宽",
|
|
4
4
|
code: `A1
|
|
5
|
-
<Table><TableHeader><TableRow><TableHead columnId="price" defaultSort="descending" defaultSortActive
|
|
5
|
+
<Table><TableHeader><TableRow><TableHead columnId="price" defaultSort="descending" defaultSortActive minWidth={64}>价格</TableHead></TableRow></TableHeader></Table>`,
|
|
6
6
|
expected: { render: "渲染 th 与 aria-sort;defaultSortActive 使默认方向也显示激活态和图标;ascending 使用 ArrowsUp,descending 使用 ArrowsDown。", layout: "图标 16px、与文间距 0;右侧 Indicator 为 1px × 16px 居中。", interaction: "defaultSortActive 列按默认 → 反向 → none → 默认;其他列按 none → ascending → descending → none。", performance: "排序状态由上层 context 持有。", responsive: "受 min/max 限制。" },
|
|
7
7
|
logic: ["Sort", "Resize"],
|
|
8
8
|
},
|
|
@@ -14,17 +14,17 @@ export const examples = [
|
|
|
14
14
|
logic: ["ControlledSort"],
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
name: "A3:
|
|
17
|
+
name: "A3: 固定静态列头",
|
|
18
18
|
code: `A3
|
|
19
|
-
<Table><TableHeader><TableRow><TableHead columnId="note">备注</TableHead></TableRow></TableHeader></Table>`,
|
|
20
|
-
expected: { render: "渲染静态 th
|
|
19
|
+
<Table><TableHeader><TableRow><TableHead columnId="note" resizable={false}>备注</TableHead></TableRow></TableHeader></Table>`,
|
|
20
|
+
expected: { render: "渲染静态 th,不渲染排序按钮或改宽 Indicator。", layout: "保持表头文字排版。", interaction: "无 hover、点击、排序或改宽交互。", performance: "不注册排序交互。", responsive: "跟随 Table。" },
|
|
21
21
|
logic: ["Static"],
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
name: "A4: 选择与行动表头角色",
|
|
25
25
|
code: `A4
|
|
26
26
|
<Table><TableHeader><TableRow><TableHead as="selection" /><TableHead as="actions">操作</TableHead></TableRow></TableHeader></Table>`,
|
|
27
|
-
expected: { render: "selection 渲染内置全选 Checkbox;actions 可选渲染标题。", layout: "
|
|
27
|
+
expected: { render: "selection 渲染内置全选 Checkbox;actions 可选渲染标题。", layout: "全选 Checkbox 默认 17px,与行 Checkbox 一致;角色列使用各自定向 padding。", interaction: "全选仅在 Table hover/focus-within 时显示;两列均无排序态。", performance: "选择状态来自 Table Context。", responsive: "保持窄角色列。" },
|
|
28
28
|
logic: ["Selection", "Actions"],
|
|
29
29
|
},
|
|
30
30
|
{
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# TableRow
|
|
2
2
|
|
|
3
|
-
> **版本**: v1.
|
|
4
|
-
> **职责**: 表头或表体的 `<tr>`,统一整行 hover
|
|
3
|
+
> **版本**: v1.9.0
|
|
4
|
+
> **职责**: 表头或表体的 `<tr>`,统一整行 hover 几何与交互状态。
|
|
5
5
|
|
|
6
|
-
`rowId` 会映射为 `data-row-id
|
|
6
|
+
`rowId` 会映射为 `data-row-id`。仅当 DataTable 开启 selection 时,行才注册到当前渲染行集合,供全选和部分选中状态使用;只读表、排序表与行预览不维护无用的选择注册。`active` 是完全受外部控制的持久视觉状态:开启后输出 `data-active="true"`,使用 `var(--snowui-table-row-hover-background-override, var(--black-4))` 作为静态背景;真实 hover 到激活行时,TableBody 的连续 hover 移动层会再叠加一层同色背景。组件自身不通过点击、hover 或其他交互切换 `active`。
|
|
7
|
+
|
|
8
|
+
选中时只由 Table Context 输出 `data-selected="true"`,供 selection 角色列保持 Checkbox 可见;`active` 不会写入选中状态,也不会将 Checkbox 设为选中。默认 `divided` 变体的静态行两端无圆角;hover、active(含 `data-force-hover="true"` 静态预览)时首尾单元格形成 12px 外缘圆角,并隐藏该行上下相邻的分割线。普通 hover 背景只由 TableBody 的连续移动层绘制;active 与静态 hover 预览保留自己的持久背景。`striped` 所有数据行始终保持 12px 外缘圆角,active 时以 `--black-4` 激活背景覆盖条纹,hover 时连续移动层继续叠加。
|
|
7
9
|
|
|
8
10
|
位于 DataTable 的内部 `loadMore` 管线时,TableRow 只提供稳定 `rowId`;内部 opacity 渐显由普通 TableCell 消费,避免 selection/actions overlay 被整行透明度压暗。业务显式传给 TableRow 的 `whileAppear / currentState` 仍按正常 Frame 行级动效执行。
|
|
9
11
|
|
|
10
12
|
行内空白点击的全局语义由 Table Context 决定:当 DataTable 配置 `onRowPreview` 时,TableRow 将空白点击转发为行预览;未配置时空白点击不响应。选择行为只由 selection 角色列负责,不再由整行空白点击切换。
|
|
11
13
|
|
|
12
14
|
```svelte
|
|
13
|
-
<TableRow rowId={user.id}><TableCell>{user.name}</TableCell></TableRow>
|
|
15
|
+
<TableRow rowId={user.id} active={user.id === activeRowId}><TableCell>{user.name}</TableCell></TableRow>
|
|
14
16
|
```
|
|
15
17
|
|
|
16
18
|
## Keyword
|
|
@@ -19,12 +21,20 @@
|
|
|
19
21
|
| :--- | :--- |
|
|
20
22
|
| component | 当前组件公开契约 |
|
|
21
23
|
|
|
24
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
25
|
+
| :--- | :--- | :--- | :--- |
|
|
26
|
+
| active | `boolean` | `false` | 由使用方或外部条件写入的持久激活背景;不会触发行选中或 Checkbox 选中 |
|
|
27
|
+
|
|
22
28
|
> **以下内容供 AI 阅读,不展示在文档站点**
|
|
23
29
|
|
|
24
|
-
- Row
|
|
30
|
+
- Row 的 active 是外部受控视觉,selected 仍只来自 Table Context;两者不相互推导。
|
|
25
31
|
|
|
26
32
|
## Changelog
|
|
27
33
|
|
|
34
|
+
- 2026-08-06:v1.9.0,默认普通 Row 使用保持同一 DOM 状态、事件与语义的原生 tr 快路径;声明高级 Frame 能力时自动回退完整路径。
|
|
35
|
+
- 2026-08-06:v1.8.0,仅在 DataTable 开启 selection 时注册 `rowId`;只读、排序与行预览表不再维护无用的行选择集合。
|
|
36
|
+
- 2026-08-03:v1.7.0,新增外部受控 `active` 激活态;默认使用 `--black-4` 持久背景,允许与 TableBody 连续 hover 层叠加,且不会改变 Checkbox / selected 状态。
|
|
37
|
+
- 2026-08-03:v1.6.0,删除 TableRow 的单元格 hover 背景与背景过渡;颜色统一由 TableBody 的唯一连续移动层绘制。
|
|
28
38
|
- 2026-07-08:v1.5.0,行内空白点击改为可选行预览协议;未配置 DataTable `onRowPreview` 时不响应,选择只由 selection 角色列触发。
|
|
29
39
|
- 2026-06-30:v1.4.0,DataTable 内部新增行动效从 TableRow 迁移到普通 TableCell;TableRow 仅保留业务显式行级 whileAppear。
|
|
30
40
|
- 2026-06-30:v1.3.2,TableRow 在存在 `whileAppear` 时同步进入 Frame `Appear` 状态,修复只传动效配置但状态仍为 Idle、实际不执行渐显的问题。
|