@snowui-design-system/components 0.2.0-alpha.7 → 0.2.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -22
- package/component-catalog.json +1066 -0
- package/package.json +12 -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.md +42 -19
- package/src/components/Button.svelte +56 -50
- package/src/components/Button.test.ts +38 -27
- package/src/components/Card.test.ts +1 -1
- package/src/components/CodeBlock.md +50 -14
- package/src/components/CodeBlock.svelte +213 -34
- package/src/components/CodeBlock.test.ts +43 -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.svelte +1 -0
- 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/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/Image.test.ts +1 -1
- 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/Input.md +15 -5
- package/src/components/Input.svelte +10 -1
- package/src/components/Input.test.ts +2 -2
- 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/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/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/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/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/StyleButton.md +58 -0
- package/src/components/StyleButton.svelte +144 -0
- package/src/components/StyleButton.test.ts +39 -0
- package/src/components/Table.md +23 -7
- package/src/components/Table.svelte +22 -1
- 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 +139 -78
- package/src/components/TableCell.test.ts +4 -4
- package/src/components/TableHead.md +9 -3
- package/src/components/TableHead.svelte +56 -43
- 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 +20 -8
- package/src/components/Text.md +7 -1
- package/src/components/Text.svelte +17 -7
- package/src/components/Tooltip.md +37 -9
- package/src/components/Tooltip.svelte +145 -35
- package/src/components/Tooltip.test.ts +54 -4
- package/src/i18n/messages.ts +12 -0
- package/src/index.ts +24 -0
- package/src/internal/StyleButtonLogo.svelte +49 -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 +36 -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-delay.md +7 -1
- package/src/lib/tooltip-motion-dismiss.md +33 -0
- package/src/lib/tooltip-motion-dismiss.ts +160 -0
- package/src/lib/tooltip-overlay.md +21 -3
- package/src/lib/tooltip-overlay.ts +13 -2
- 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-inline-style.svelte.ts +2 -2
- 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/logic/overflow-actions.svelte.ts +33 -0
- package/src/motion/presets/README.md +6 -2
- package/src/motion/presets/continuous-hover.md +11 -0
- package/src/motion/presets/continuous-hover.ts +18 -0
- package/src/motion/presets/tooltip.md +40 -2
- package/src/motion/presets/tooltip.ts +0 -2
- package/src/motion/tokens.md +9 -4
- package/src/motion/tokens.ts +4 -1
- package/src/styles/README.md +16 -2
- package/src/styles/auto-layout.css +10 -1
- package/src/styles/components.css +920 -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
- package/src/styles/tokens.css +33 -33
|
@@ -1,16 +1,25 @@
|
|
|
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
|
|
17
|
+
import OverflowActions from "./OverflowActions.svelte";
|
|
9
18
|
import { resizeManager } from "../logic/observer.svelte";
|
|
10
19
|
import { getTableContext, type TableRoleLayout } from "../lib/table-context.svelte";
|
|
11
20
|
import { getTableRowContext } from "../lib/table-row-context.svelte";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
21
|
+
import { SKELETON_CONTEXT_KEY } from "../keys";
|
|
22
|
+
import { getTableRoleBlurStyles } from "../lib/table-role-blur";
|
|
14
23
|
import {
|
|
15
24
|
mergeComponentPartProps,
|
|
16
25
|
useComponentPart,
|
|
@@ -36,11 +45,11 @@
|
|
|
36
45
|
const inheritedTableCellPart = useComponentPart<Props>("TableCell");
|
|
37
46
|
let explicitProps: Props = $props();
|
|
38
47
|
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
48
|
let roleOverlayElement = $state<HTMLElement>();
|
|
41
49
|
let hasNestedTruncationOwner = $state(false);
|
|
42
50
|
const table = getTableContext();
|
|
43
51
|
const rowContext = getTableRowContext();
|
|
52
|
+
const parentSkeletonContext = getContext(SKELETON_CONTEXT_KEY);
|
|
44
53
|
const rowId = $derived(rowContext?.getRowId());
|
|
45
54
|
const selectionEnabled = $derived(table.isSelectionEnabled());
|
|
46
55
|
const actionsEnabled = $derived(table.isActionsEnabled());
|
|
@@ -61,7 +70,16 @@
|
|
|
61
70
|
const isSelected = $derived(rowId !== undefined && table.isRowSelected(rowId));
|
|
62
71
|
const tableVariant = $derived(table.getVariant());
|
|
63
72
|
const resolvedRoleLayout = $derived(roleLayout ?? table.getRoleLayout());
|
|
73
|
+
const hasActionsOverlay = $derived(
|
|
74
|
+
table.isDataTable() && actionsEnabled && resolvedRoleLayout === "overlay",
|
|
75
|
+
);
|
|
64
76
|
const width = $derived(resolvedColumnId ? table.getColumnWidth(resolvedColumnId) : undefined);
|
|
77
|
+
const defaultActions = $derived(
|
|
78
|
+
isActionsRole && rowId !== undefined ? table.getRowActions(rowId) : [],
|
|
79
|
+
);
|
|
80
|
+
const actionsAvailableWidth = $derived(
|
|
81
|
+
Math.max(0, (width ?? table.getActionsColumnWidth()) - 24),
|
|
82
|
+
);
|
|
65
83
|
const resolvedLines = $derived(skeleton || isSelectionRole || isActionsRole || lines === false ? undefined : lines);
|
|
66
84
|
const contextRowAppearMotion = $derived(
|
|
67
85
|
!skeleton && !isSelectionRole && !isActionsRole && rowId !== undefined
|
|
@@ -72,28 +90,46 @@
|
|
|
72
90
|
const resolvedCurrentState = $derived(
|
|
73
91
|
userCurrentState ?? (resolvedWhileAppear === undefined ? undefined : "Appear"),
|
|
74
92
|
);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
let isTruncated = $state(false);
|
|
94
|
+
let fullText = $state("");
|
|
95
|
+
function registerTruncation(
|
|
96
|
+
node: HTMLElement,
|
|
97
|
+
initial: { enabled: boolean; onChange?: (isTruncated: boolean) => void },
|
|
98
|
+
) {
|
|
99
|
+
let options = initial;
|
|
100
|
+
const cleanup = table.registerTruncationTarget(node, {
|
|
101
|
+
isEnabled: () => options.enabled,
|
|
102
|
+
notify: (result) => {
|
|
103
|
+
if (result.isTruncated !== isTruncated) {
|
|
104
|
+
isTruncated = result.isTruncated;
|
|
105
|
+
options.onChange?.(result.isTruncated);
|
|
106
|
+
}
|
|
107
|
+
if (result.fullText !== fullText) fullText = result.fullText;
|
|
108
|
+
if (result.hasNestedOwner !== hasNestedTruncationOwner) {
|
|
109
|
+
hasNestedTruncationOwner = result.hasNestedOwner;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
update(next: typeof initial) {
|
|
115
|
+
const wasEnabled = options.enabled;
|
|
116
|
+
const previousOnChange = options.onChange;
|
|
117
|
+
options = next;
|
|
118
|
+
if (!next.enabled && wasEnabled) {
|
|
119
|
+
if (isTruncated) previousOnChange?.(false);
|
|
120
|
+
isTruncated = false;
|
|
121
|
+
fullText = "";
|
|
122
|
+
hasNestedTruncationOwner = false;
|
|
123
|
+
}
|
|
124
|
+
table.requestTruncationMeasure();
|
|
125
|
+
},
|
|
126
|
+
destroy: cleanup,
|
|
91
127
|
};
|
|
92
|
-
|
|
93
|
-
});
|
|
128
|
+
}
|
|
94
129
|
$effect(() => {
|
|
95
130
|
const node = roleOverlayElement;
|
|
96
131
|
if (!node || resolvedRoleLayout !== "overlay" || (!isSelectionRole && !isActionsRole)) return;
|
|
132
|
+
const selected = isSelected;
|
|
97
133
|
let frame = 0;
|
|
98
134
|
const rowElement = node.closest<HTMLElement>(".snowui-table-row");
|
|
99
135
|
const layoutElement = rowElement?.closest<HTMLElement>(".snowui-data-table")
|
|
@@ -155,8 +191,9 @@
|
|
|
155
191
|
};
|
|
156
192
|
const shouldStayActive = () =>
|
|
157
193
|
Boolean(
|
|
194
|
+
selected ||
|
|
158
195
|
rowElement?.matches(
|
|
159
|
-
':hover, [data-force-hover="true"]
|
|
196
|
+
':hover, [data-force-hover="true"]',
|
|
160
197
|
) || rowElement?.contains(document.activeElement),
|
|
161
198
|
);
|
|
162
199
|
const deactivate = () => {
|
|
@@ -178,18 +215,8 @@
|
|
|
178
215
|
rowElement?.addEventListener("pointerleave", scheduleDeactivate);
|
|
179
216
|
rowElement?.addEventListener("focusin", activate);
|
|
180
217
|
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
218
|
// 空闲行不做同步布局测量;hover / focus / selected / force-hover 时再激活。
|
|
192
|
-
//
|
|
219
|
+
// selected 直接消费 Svelte 派生状态,不再为每个角色单元格创建 MutationObserver。
|
|
193
220
|
// 激活后额外监听 DataTable/Table 容器尺寸,覆盖内置工具栏出现/消失导致的整表位移。
|
|
194
221
|
if (shouldStayActive()) activate();
|
|
195
222
|
return () => {
|
|
@@ -202,50 +229,46 @@
|
|
|
202
229
|
rowElement?.removeEventListener("pointerleave", scheduleDeactivate);
|
|
203
230
|
rowElement?.removeEventListener("focusin", activate);
|
|
204
231
|
rowElement?.removeEventListener("focusout", scheduleDeactivate);
|
|
205
|
-
selectedObserver?.disconnect();
|
|
206
232
|
reset();
|
|
207
233
|
};
|
|
208
234
|
});
|
|
209
|
-
const
|
|
235
|
+
const runtimeWidth = $derived(
|
|
236
|
+
(isSelectionRole || isActionsRole) && resolvedRoleLayout === "overlay"
|
|
237
|
+
? undefined
|
|
238
|
+
: width,
|
|
239
|
+
);
|
|
240
|
+
const finalStyle = $derived(`${runtimeWidth ? `--snowui-table-cell-width-runtime:${runtimeWidth}px;width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));min-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime));max-width:var(--snowui-table-cell-width-override,var(--snowui-table-cell-width-runtime))` : ""};text-align:${align};${userStyle}`);
|
|
210
241
|
// actions 的遮罩依赖每行实测后写入的宽度变量,必须在内容单元格自身计算。
|
|
211
242
|
// 若把这条表达式定义在 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
243
|
const contentStyle = $derived(
|
|
218
244
|
`${gap === undefined
|
|
219
245
|
? ""
|
|
220
246
|
: `gap:${typeof gap === "number" ? `var(--gap-${gap}, calc(var(--gap-1) * ${gap}))` : gap};`}` +
|
|
221
|
-
`--snowui-table-cell-actions-fade-mask:${actionsFadeMask}
|
|
247
|
+
`${hasActionsOverlay ? `--snowui-table-cell-actions-fade-mask:${actionsFadeMask};--snowui-table-role-overlay-width-override:${width ?? table.getActionsColumnWidth()}px;` : ""}`,
|
|
248
|
+
);
|
|
249
|
+
const selectionBlur = $derived(getTableRoleBlurStyles(table, "left-to-right"));
|
|
250
|
+
const actionsBlur = $derived(getTableRoleBlurStyles(table, "right-to-left"));
|
|
251
|
+
const selectionCheckboxSizeStyle = $derived(
|
|
252
|
+
parts?.Checkbox?.size === undefined
|
|
253
|
+
? "--snowui-checkbox-size-override: var(--snowui-table-selection-checkbox-size-override, calc(var(--size-4, 1rem) + 0.0625rem))"
|
|
254
|
+
: undefined,
|
|
255
|
+
);
|
|
256
|
+
const useSemanticFastPath = $derived(
|
|
257
|
+
!skeleton
|
|
258
|
+
&& !isSelectionRole
|
|
259
|
+
&& !isActionsRole
|
|
260
|
+
&& resolvedWhileAppear === undefined
|
|
261
|
+
&& userCurrentState === undefined
|
|
262
|
+
&& parts === undefined
|
|
263
|
+
&& parentSkeletonContext === undefined
|
|
264
|
+
&& !enableResponsive
|
|
265
|
+
&& !enableContext
|
|
266
|
+
&& !enableScaleObserver
|
|
267
|
+
&& Object.keys(rest).length === 0,
|
|
222
268
|
);
|
|
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
269
|
</script>
|
|
246
270
|
|
|
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}>
|
|
271
|
+
{#snippet renderCellContent()}
|
|
249
272
|
{#if skeleton}
|
|
250
273
|
<span class="snowui-table-cell-content snowui-table-cell-skeleton" aria-hidden="true">
|
|
251
274
|
{#if !isSelectionRole && !isActionsRole}
|
|
@@ -257,6 +280,7 @@
|
|
|
257
280
|
bind:this={roleOverlayElement}
|
|
258
281
|
class="snowui-table-selection-control"
|
|
259
282
|
data-selected={isSelected ? "true" : undefined}
|
|
283
|
+
style={selectionCheckboxSizeStyle}
|
|
260
284
|
>
|
|
261
285
|
<span class="snowui-table-role-blur-layer" style={selectionBlur.containerStyle} aria-hidden="true">
|
|
262
286
|
{#each selectionBlur.layers as layer (layer.index)}
|
|
@@ -264,7 +288,6 @@
|
|
|
264
288
|
{/each}
|
|
265
289
|
</span>
|
|
266
290
|
<Checkbox
|
|
267
|
-
size={16}
|
|
268
291
|
checked={isSelected}
|
|
269
292
|
ariaLabel="选择当前行"
|
|
270
293
|
onclick={(event: MouseEvent) => event.stopPropagation()}
|
|
@@ -279,21 +302,55 @@
|
|
|
279
302
|
<span style={layer.style}></span>
|
|
280
303
|
{/each}
|
|
281
304
|
</span>
|
|
282
|
-
<span class="snowui-table-role-overlay-controls">{#if children}
|
|
305
|
+
<span class="snowui-table-role-overlay-controls">{#if children}
|
|
306
|
+
{@render children()}
|
|
307
|
+
{:else if rowId !== undefined && defaultActions.length > 0}
|
|
308
|
+
<OverflowActions
|
|
309
|
+
items={defaultActions}
|
|
310
|
+
compact={table.getActionsCompact()}
|
|
311
|
+
overflow={table.getActionsOverflow()}
|
|
312
|
+
overflowFrom={table.getActionsOverflowFrom()}
|
|
313
|
+
availableWidth={actionsAvailableWidth}
|
|
314
|
+
onAction={({ id, item }) => table.runRowAction({
|
|
315
|
+
rowId,
|
|
316
|
+
actionId: id,
|
|
317
|
+
item,
|
|
318
|
+
})}
|
|
319
|
+
/>
|
|
320
|
+
{/if}</span>
|
|
283
321
|
</span>
|
|
284
|
-
{:else}<span
|
|
322
|
+
{:else}<span use:registerTruncation={{ enabled: resolvedLines === 1, onChange: onTruncate }} class={`snowui-table-cell-content ${resolvedLines ? `snowui-line-clamp-${resolvedLines}` : ""}`} data-row={row ? "true" : undefined} data-nowrap={nowrap ? "true" : undefined} data-lines={resolvedLines} data-truncated={isTruncated ? "true" : "false"} style={contentStyle}>
|
|
285
323
|
{#if children}{@render children()}{/if}
|
|
286
|
-
{#if tooltip && !hasNestedTruncationOwner &&
|
|
324
|
+
{#if tooltip && !hasNestedTruncationOwner && isTruncated && fullText}
|
|
287
325
|
<Tooltip>
|
|
288
|
-
{#if typeof tooltip === "string"}{tooltip}{:else if typeof tooltip === "function"}{@render tooltip()}{:else}{
|
|
326
|
+
{#if typeof tooltip === "string"}{tooltip}{:else if typeof tooltip === "function"}{@render tooltip()}{:else}{fullText}{/if}
|
|
289
327
|
</Tooltip>
|
|
290
328
|
{/if}
|
|
291
329
|
</span>{/if}
|
|
330
|
+
{/snippet}
|
|
331
|
+
|
|
332
|
+
{#if !isRoleColumnHidden}
|
|
333
|
+
{#if useSemanticFastPath}
|
|
334
|
+
<td
|
|
335
|
+
data-column-id={resolvedColumnId}
|
|
336
|
+
data-table-variant={tableVariant}
|
|
337
|
+
class={`snowui-frame snowui-table-cell ${userClass}`}
|
|
338
|
+
data-snowui-frame="true"
|
|
339
|
+
data-content-width="hug"
|
|
340
|
+
data-state="Idle"
|
|
341
|
+
style={finalStyle}
|
|
342
|
+
>
|
|
343
|
+
{@render renderCellContent()}
|
|
344
|
+
</td>
|
|
345
|
+
{:else}
|
|
346
|
+
<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}>
|
|
347
|
+
{@render renderCellContent()}
|
|
292
348
|
</Frame>
|
|
293
349
|
{/if}
|
|
350
|
+
{/if}
|
|
294
351
|
|
|
295
352
|
<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; }
|
|
353
|
+
: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
354
|
: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
355
|
: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
356
|
:global(:where(.snowui-table-cell[data-skeleton="true"])) { pointer-events: none; }
|
|
@@ -302,13 +359,15 @@
|
|
|
302
359
|
:global(:where(.snowui-table-cell-content[data-actions="true"])) { opacity: 0; pointer-events: none; transition: opacity var(--snowui-frame-color-motion-duration, .15s) var(--snowui-frame-color-motion-easing, ease-out); }
|
|
303
360
|
:global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(:focus-visible), .snowui-table-row[data-selected="true"]) .snowui-table-cell[data-as="selection"] .snowui-table-selection-control),
|
|
304
361
|
:global(:where(.snowui-table-cell[data-as="selection"] .snowui-table-selection-control[data-selected="true"])) { opacity: 1; pointer-events: auto; }
|
|
305
|
-
:global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"]) .snowui-table-cell:not([data-role-layout="overlay"]) .snowui-table-cell-content[data-actions="true"]) { opacity: 1; pointer-events: auto; }
|
|
362
|
+
:global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(.snowui-select-button-trigger[aria-expanded="true"])) .snowui-table-cell:not([data-role-layout="overlay"]) .snowui-table-cell-content[data-actions="true"]) { opacity: 1; pointer-events: auto; }
|
|
306
363
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="selection"])),
|
|
307
364
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="actions"])) { position: sticky; width: 0; min-width: 0; max-width: 0; padding: 0; overflow: visible; background: transparent; z-index: 3; }
|
|
308
365
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="selection"])) { left: 0; }
|
|
309
366
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="actions"])) { right: 0; }
|
|
310
367
|
: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
368
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"])) { opacity: 1; pointer-events: none; transition: none; }
|
|
369
|
+
: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); }
|
|
370
|
+
: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
371
|
: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
372
|
: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
373
|
:global(:where(.snowui-table-body .snowui-table-row:last-child) > .snowui-table-cell) { border-bottom-color: transparent; }
|
|
@@ -332,15 +391,17 @@
|
|
|
332
391
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"]) > :not(.snowui-table-role-blur-layer)) { opacity: 0; pointer-events: none; transition: opacity var(--snowui-frame-color-motion-duration, .15s) var(--snowui-frame-color-motion-easing, ease-out); }
|
|
333
392
|
:global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(:focus-visible), .snowui-table-row[data-selected="true"]) .snowui-table-cell[data-role-layout="overlay"][data-as="selection"] .snowui-table-selection-control > :not(.snowui-table-role-blur-layer)),
|
|
334
393
|
:global(:where(.snowui-table-cell[data-role-layout="overlay"][data-as="selection"] .snowui-table-selection-control[data-selected="true"]) > :not(.snowui-table-role-blur-layer)),
|
|
335
|
-
:global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"]) .snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"] > :not(.snowui-table-role-blur-layer)) { opacity: 1; pointer-events: auto; }
|
|
394
|
+
:global(:where(.snowui-table-row:hover, .snowui-table-row[data-force-hover="true"], .snowui-table-row:has(.snowui-select-button-trigger[aria-expanded="true"])) .snowui-table-cell[data-role-layout="overlay"] .snowui-table-cell-content[data-actions="true"] > :not(.snowui-table-role-blur-layer)) { opacity: 1; pointer-events: auto; }
|
|
336
395
|
: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; }
|
|
396
|
+
:global(:where(.snowui-table-body .snowui-table-row:nth-child(odd)) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--snowui-table-row-active-background, var(--surface-3, #f7f7f7)); }
|
|
397
|
+
:global(:where(.snowui-table-body .snowui-table-row:nth-child(even)) > .snowui-table-cell[data-table-variant="striped"]) { background: var(--snowui-table-row-active-background, transparent); }
|
|
398
|
+
: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); }
|
|
399
|
+
: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
400
|
: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
401
|
: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
402
|
: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
403
|
: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) {
|
|
404
|
+
: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
405
|
: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
406
|
:global(:where(.snowui-table-body .snowui-table-row) > .snowui-table-cell[data-role-layout="overlay"]) { background: transparent; }
|
|
346
407
|
:global(:where(.snowui-table-body .snowui-table-row:hover) > .snowui-table-cell[data-role-layout="overlay"]) { background: transparent; }
|
|
@@ -23,15 +23,15 @@ export const examples = [
|
|
|
23
23
|
{
|
|
24
24
|
name: "A4: 选择与行动单元格角色",
|
|
25
25
|
code: `A4
|
|
26
|
-
<Table selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell as="actions"><Button bare>更多</Button></TableCell></TableRow></TableBody></Table>`,
|
|
27
|
-
expected: { render: "selection 内置行 Checkbox;actions 渲染调用方按钮。", layout: "actions 横向排列且 gap 8px。", interaction: "Checkbox 在 hover/focus/selected 时显示;actions 只在 hover 时显示。", performance: "无 DOM 身份猜测。", responsive: "角色列保持窄宽。" },
|
|
26
|
+
<Table selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell as="actions"><Button bare emphasis="muted">更多</Button></TableCell></TableRow></TableBody></Table>`,
|
|
27
|
+
expected: { render: "selection 内置行 Checkbox;actions 渲染调用方按钮。", layout: "selection Checkbox 默认 17px,在奇数高度行内上下留白对称;actions 横向排列且 gap 8px。", interaction: "Checkbox 在 hover/focus/selected 时显示;actions 只在 hover 时显示。", performance: "无 DOM 身份猜测。", responsive: "角色列保持窄宽。" },
|
|
28
28
|
logic: ["Selection", "Actions"],
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
name: "A5: 覆盖式角色单元格",
|
|
32
32
|
code: `A5
|
|
33
|
-
<Table roleLayout="overlay" selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell>SnowUI</TableCell><TableCell as="actions"><Button bare>更多</Button></TableCell></TableRow></TableBody></Table>`,
|
|
34
|
-
expected: { render: "selection/actions 仍保持合法 td。", layout: "角色 td
|
|
33
|
+
<Table roleLayout="overlay" selectedRowIds={["one"]}><TableBody><TableRow rowId="one"><TableCell as="selection" /><TableCell>SnowUI</TableCell><TableCell as="actions"><Button bare emphasis="muted">更多</Button></TableCell></TableRow></TableBody></Table>`,
|
|
34
|
+
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,7 +65,24 @@
|
|
|
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);
|
|
75
|
+
const resolvedMinWidth = $derived(isActionsRole ? table.getActionsMinWidth() : minWidth);
|
|
76
|
+
const resolvedMaxWidth = $derived(isActionsRole ? table.getActionsMaxWidth() : maxWidth);
|
|
77
|
+
const isResizeEnabled = $derived(
|
|
78
|
+
canResize
|
|
79
|
+
&& !!resolvedColumnId
|
|
80
|
+
&& !isSelectionRole
|
|
81
|
+
&& (!isActionsRole || (
|
|
82
|
+
table.isActionsResizable()
|
|
83
|
+
&& resolvedRoleLayout === "column"
|
|
84
|
+
)),
|
|
85
|
+
);
|
|
69
86
|
const sort = $derived(table.getSort());
|
|
70
87
|
const selectionState = $derived(table.getSelectionState());
|
|
71
88
|
const contextDefaultSort = $derived(table.getDefaultSort());
|
|
@@ -92,7 +109,12 @@
|
|
|
92
109
|
...(Array.isArray(userActions) ? userActions : []),
|
|
93
110
|
columnScope,
|
|
94
111
|
]);
|
|
95
|
-
const
|
|
112
|
+
const runtimeWidth = $derived(
|
|
113
|
+
(isSelectionRole || isActionsRole) && resolvedRoleLayout === "overlay"
|
|
114
|
+
? undefined
|
|
115
|
+
: width,
|
|
116
|
+
);
|
|
117
|
+
const finalStyle = $derived(`${runtimeWidth ? `--snowui-table-head-width-runtime:${runtimeWidth}px;width:var(--snowui-table-head-width-override,var(--snowui-table-head-width-runtime));min-width:var(--snowui-table-head-width-override,var(--snowui-table-head-width-runtime));max-width:var(--snowui-table-head-width-override,var(--snowui-table-head-width-runtime))` : ""};${hasActionsOverlay ? `--snowui-table-role-overlay-width-override:${width ?? table.getActionsColumnWidth()}px;` : ""}text-align:${align};${userStyle}`);
|
|
96
118
|
$effect(() => {
|
|
97
119
|
const declaredDefaultSort = defaultSort;
|
|
98
120
|
const declaredColumnId = columnId;
|
|
@@ -114,43 +136,30 @@
|
|
|
114
136
|
}
|
|
115
137
|
table.toggleSort(columnId);
|
|
116
138
|
}
|
|
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"));
|
|
139
|
+
const selectionBlur = $derived(getTableRoleBlurStyles(table, "left-to-right"));
|
|
140
|
+
const actionsBlur = $derived(getTableRoleBlurStyles(table, "right-to-left"));
|
|
141
|
+
const selectionContentBlur = $derived(getTableRoleBlurStyles(table, "left-to-right"));
|
|
142
|
+
const actionsContentBlur = $derived(getTableRoleBlurStyles(table, "right-to-left"));
|
|
143
|
+
const selectionCheckboxSizeStyle = $derived(
|
|
144
|
+
parts?.Checkbox?.size === undefined
|
|
145
|
+
? "--snowui-checkbox-size-override: var(--snowui-table-selection-checkbox-size-override, calc(var(--size-4, 1rem) + 0.0625rem))"
|
|
146
|
+
: undefined,
|
|
147
|
+
);
|
|
141
148
|
</script>
|
|
142
149
|
|
|
143
150
|
{#if !isRoleColumnHidden}
|
|
144
151
|
<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
152
|
{#if isSelectionRole}
|
|
146
|
-
<span
|
|
153
|
+
<span
|
|
154
|
+
class="snowui-table-selection-control"
|
|
155
|
+
style={selectionCheckboxSizeStyle}
|
|
156
|
+
>
|
|
147
157
|
<span class="snowui-table-role-blur-layer" style={selectionBlur.containerStyle} aria-hidden="true">
|
|
148
158
|
{#each selectionBlur.layers as layer (layer.index)}
|
|
149
159
|
<span style={layer.style}></span>
|
|
150
160
|
{/each}
|
|
151
161
|
</span>
|
|
152
162
|
<Checkbox
|
|
153
|
-
size={16}
|
|
154
163
|
checked={selectionState.all}
|
|
155
164
|
indeterminate={selectionState.some}
|
|
156
165
|
ariaLabel="选择全部当前行"
|
|
@@ -179,24 +188,28 @@
|
|
|
179
188
|
<span class="snowui-table-head-content snowui-table-head-content-static">{#if children}{@render children()}{/if}</span>
|
|
180
189
|
{/if}
|
|
181
190
|
{#if !isSelectionRole && !isActionsRole}
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
|
|
191
|
+
{#if hasSelectionOverlay}
|
|
192
|
+
<span class="snowui-table-head-selection-blur-proxy" style={selectionContentBlur.containerStyle} aria-hidden="true">
|
|
193
|
+
{#each selectionContentBlur.layers as layer (layer.index)}
|
|
194
|
+
<span style={layer.style}></span>
|
|
195
|
+
{/each}
|
|
196
|
+
</span>
|
|
197
|
+
{/if}
|
|
198
|
+
{#if hasActionsOverlay}
|
|
199
|
+
<span class="snowui-table-head-actions-blur-proxy" style={actionsContentBlur.containerStyle} aria-hidden="true">
|
|
200
|
+
{#each actionsContentBlur.layers as layer (layer.index)}
|
|
201
|
+
<span style={layer.style}></span>
|
|
202
|
+
{/each}
|
|
203
|
+
</span>
|
|
204
|
+
{/if}
|
|
192
205
|
{/if}
|
|
193
|
-
{#if
|
|
206
|
+
{#if isResizeEnabled && resolvedColumnId}
|
|
194
207
|
<Indicator
|
|
195
208
|
class="snowui-table-head-indicator"
|
|
196
209
|
axis="width"
|
|
197
210
|
value={width}
|
|
198
|
-
minSize={
|
|
199
|
-
maxSize={
|
|
211
|
+
minSize={resolvedMinWidth}
|
|
212
|
+
maxSize={resolvedMaxWidth}
|
|
200
213
|
applySize={false}
|
|
201
214
|
ariaLabel={`调整 ${resolvedColumnId} 列宽`}
|
|
202
215
|
onSizeChange={(next) => table.setColumnWidth(resolvedColumnId, next)}
|
|
@@ -265,7 +278,7 @@
|
|
|
265
278
|
width: calc(var(--size-3, 0.75rem) / 6);
|
|
266
279
|
}
|
|
267
280
|
: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; }
|
|
281
|
+
: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
282
|
/* 表头内容渐隐过渡(mask-image),触发条件见下方规则。 */
|
|
270
283
|
:global(:where(.snowui-table-head-content)) {
|
|
271
284
|
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
|
{
|