@fibrae/semi-ui-svelte 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/components/auto-complete/auto-complete.svelte +12 -21
  2. package/dist/components/auto-complete/interface.d.ts +3 -2
  3. package/dist/components/badge/badge.svelte +4 -4
  4. package/dist/components/badge/interface.d.ts +4 -3
  5. package/dist/components/button/button.svelte +3 -2
  6. package/dist/components/button/interface.d.ts +4 -2
  7. package/dist/components/card/card.svelte +9 -10
  8. package/dist/components/card/interface.d.ts +4 -4
  9. package/dist/components/cascader/cascader.svelte +11 -18
  10. package/dist/components/cascader/interface.d.ts +3 -2
  11. package/dist/components/cascader/item.svelte +1 -1
  12. package/dist/components/color-picker/color-picker.svelte +16 -1
  13. package/dist/components/cropper/cropper.svelte +4 -4
  14. package/dist/components/cropper/interface.d.ts +4 -3
  15. package/dist/components/date-picker/date-input.svelte +3 -1
  16. package/dist/components/date-picker/date-picker.svelte +9 -10
  17. package/dist/components/date-picker/interface.d.ts +5 -4
  18. package/dist/components/date-picker/internal.d.ts +2 -0
  19. package/dist/components/descriptions/descriptions.svelte +2 -2
  20. package/dist/components/descriptions/interface.d.ts +4 -2
  21. package/dist/components/dropdown/dropdown-popup.svelte +2 -1
  22. package/dist/components/dropdown/dropdown-popup.svelte.d.ts +2 -1
  23. package/dist/components/dropdown/dropdown.svelte +4 -5
  24. package/dist/components/dropdown/interface.d.ts +6 -4
  25. package/dist/components/empty/empty.svelte +2 -2
  26. package/dist/components/empty/interface.d.ts +4 -3
  27. package/dist/components/feedback/feedback.svelte +6 -0
  28. package/dist/components/feedback/interface.d.ts +5 -0
  29. package/dist/components/form/form.svelte +3 -1
  30. package/dist/components/form/index.d.ts +4 -2
  31. package/dist/components/form/index.js +3 -1
  32. package/dist/components/form/interface.d.ts +57 -10
  33. package/dist/components/form/label.svelte +37 -13
  34. package/dist/components/form/schema-form/schema-field.svelte +4 -6
  35. package/dist/components/form/schema-form/schema-form.svelte +2 -2
  36. package/dist/components/form/schema-form/schema-node.svelte +73 -91
  37. package/dist/components/form/schema-form/schema-node.svelte.d.ts +2 -3
  38. package/dist/components/form/schema-form/semi-array.svelte +47 -0
  39. package/dist/components/form/schema-form/semi-array.svelte.d.ts +7 -0
  40. package/dist/components/form/schema-form/semi-field.svelte +42 -0
  41. package/dist/components/form/schema-form/semi-field.svelte.d.ts +8 -0
  42. package/dist/components/form/schema-form/semi-renderers.svelte +24 -0
  43. package/dist/components/form/schema-form/semi-renderers.svelte.d.ts +24 -0
  44. package/dist/components/form/schema-form/semi-section.svelte +22 -0
  45. package/dist/components/form/schema-form/semi-section.svelte.d.ts +10 -0
  46. package/dist/components/form/section.svelte +8 -2
  47. package/dist/components/highlight/highlight.svelte +6 -7
  48. package/dist/components/highlight/interface.d.ts +4 -3
  49. package/dist/components/icon-button/icon-button.svelte +4 -3
  50. package/dist/components/image/image.svelte +4 -4
  51. package/dist/components/image/interface.d.ts +6 -5
  52. package/dist/components/image/preview/preview-image.svelte +1 -1
  53. package/dist/components/image/preview/preview-inner.svelte +10 -18
  54. package/dist/components/image/preview/preview.svelte +4 -4
  55. package/dist/components/input/input.svelte +4 -2
  56. package/dist/components/input/interface.d.ts +6 -5
  57. package/dist/components/input/textarea.svelte +6 -6
  58. package/dist/components/input-number/input-number.svelte +4 -2
  59. package/dist/components/input-number/interface.d.ts +5 -1
  60. package/dist/components/modal/interface.d.ts +5 -3
  61. package/dist/components/modal/modal-content.svelte +26 -32
  62. package/dist/components/modal/modal-content.svelte.d.ts +5 -4
  63. package/dist/components/modal/modal.svelte +4 -4
  64. package/dist/components/navigation/interface.d.ts +8 -4
  65. package/dist/components/navigation/nav-items.svelte +1 -1
  66. package/dist/components/navigation/nav.svelte +3 -2
  67. package/dist/components/navigation/sub-nav.svelte +5 -4
  68. package/dist/components/overflow-list/interface.d.ts +4 -3
  69. package/dist/components/overflow-list/overflow-list.svelte +3 -3
  70. package/dist/components/pagination/interface.d.ts +1 -1
  71. package/dist/components/pagination/pagination.svelte +63 -61
  72. package/dist/components/popconfirm/interface.d.ts +3 -0
  73. package/dist/components/popconfirm/popconfirm.svelte +4 -4
  74. package/dist/components/popover/arrow.svelte +2 -2
  75. package/dist/components/popover/interface.d.ts +8 -3
  76. package/dist/components/popover/popover.svelte +4 -4
  77. package/dist/components/radio/interface.d.ts +6 -5
  78. package/dist/components/radio/radio-group.svelte +2 -2
  79. package/dist/components/radio/radio.svelte +4 -4
  80. package/dist/components/select/interface.d.ts +3 -2
  81. package/dist/components/select/option.svelte +1 -1
  82. package/dist/components/select/select.svelte +9 -14
  83. package/dist/components/side-sheet/interface.d.ts +6 -5
  84. package/dist/components/side-sheet/side-sheet.svelte +31 -29
  85. package/dist/components/slider/interface.d.ts +4 -2
  86. package/dist/components/slider/slider.svelte +3 -2
  87. package/dist/components/spin/icon.svelte +1 -1
  88. package/dist/components/spin/interface.d.ts +4 -3
  89. package/dist/components/spin/spin.svelte +2 -3
  90. package/dist/components/switch/switch.svelte +1 -1
  91. package/dist/components/table/body/body.svelte +21 -8
  92. package/dist/components/table/context.d.ts +2 -1
  93. package/dist/components/table/interface.d.ts +4 -3
  94. package/dist/components/table/table-header/table-header-row.svelte +15 -3
  95. package/dist/components/table/table.svelte +38 -8
  96. package/dist/components/tabs/interface.d.ts +8 -7
  97. package/dist/components/tabs/tab-bar.svelte +12 -2
  98. package/dist/components/tabs/tabs.svelte +7 -8
  99. package/dist/components/time-picker/interface.d.ts +4 -4
  100. package/dist/components/time-picker/time-input.svelte +2 -2
  101. package/dist/components/time-picker/time-picker.svelte +10 -11
  102. package/dist/components/tooltip/interface.d.ts +5 -2
  103. package/dist/components/tooltip/tooltip.svelte +13 -38
  104. package/dist/components/tree/interface.d.ts +4 -3
  105. package/dist/components/tree/node-arrow.svelte +1 -1
  106. package/dist/components/tree/tree-node.svelte +1 -1
  107. package/dist/components/tree/tree.svelte +23 -74
  108. package/dist/components/tree-select/interface.d.ts +4 -5
  109. package/dist/components/tree-select/tree-select.svelte +28 -67
  110. package/dist/components/typography/base.svelte +1 -1
  111. package/dist/components/upload/file-card.svelte +1 -1
  112. package/dist/components/upload/interface.d.ts +5 -3
  113. package/dist/components/upload/upload.svelte +6 -4
  114. package/dist/components/user-guide/user-guide.svelte +15 -1
  115. package/dist/hooks/index.d.ts +1 -0
  116. package/dist/hooks/index.js +1 -0
  117. package/dist/hooks/use-overlay-resources.svelte.d.ts +13 -0
  118. package/dist/hooks/use-overlay-resources.svelte.js +20 -0
  119. package/dist/internal/virtual-list.svelte +11 -1
  120. package/dist/internal/virtual-list.svelte.d.ts +7 -0
  121. package/dist/styles.css +1 -1
  122. package/package.json +3 -3
  123. package/dist/components/tree/use-tree-keyboard.svelte.d.ts +0 -29
  124. package/dist/components/tree/use-tree-keyboard.svelte.js +0 -61
@@ -1,12 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { onMount, tick, untrack } from 'svelte';
3
+ import { isNil, omitBy } from 'es-toolkit';
3
4
  import { cssClasses } from '@fibrae/semi-foundation/components/side-sheet/constants';
4
5
  import SideSheetFoundation, { type SideSheetAdapter, type SideSheetProps as SideSheetBaseProps, type SideSheetState } from '@fibrae/semi-foundation/components/side-sheet/side-sheet-foundation';
5
- import { warnIfDialogUnnamed, toCssLength } from '@fibrae/semi-foundation/utils';
6
+ import { toCssLength } from '@fibrae/semi-foundation/utils';
6
7
  import '@fibrae/semi-foundation/components/side-sheet/side-sheet.css';
7
8
  import { IconClose } from '@fibrae/semi-icons-svelte';
8
9
  import { useDefaultProps, useFoundation } from '../../base/index.js';
9
- import { watch } from '../../hooks/index.js';
10
+ import { useOverlayResources, watch } from '../../hooks/index.js';
10
11
  import { Portal } from '../../internal/index.js';
11
12
  import { isAriaKey, splitControlAttrs } from '../../utils/index.js';
12
13
  import { getConfigContext } from '../config-provider/context.js';
@@ -22,25 +23,24 @@
22
23
  // No fallback on `visible`: a bound `undefined` would throw with one, and undefined means closed
23
24
  let {
24
25
  afterVisibleChange,
25
- bodyStyle = defaults('bodyStyle'),
26
26
  canVerticalSetWidth = defaults('canVerticalSetWidth'),
27
+ classNames = defaults('classNames'),
27
28
  closable = defaults('closable', true),
28
29
  closeIcon = defaults('closeIcon'),
29
30
  closeOnEsc = defaults('closeOnEsc', false),
30
31
  disableScroll = defaults('disableScroll', true),
31
32
  footer = defaults('footer'),
32
33
  getPopupContainer = defaults('getPopupContainer'),
33
- headerStyle = defaults('headerStyle'),
34
34
  height = defaults('height'),
35
35
  keepDOM = defaults('keepDOM', false),
36
36
  mask = defaults('mask', true),
37
37
  maskClosable = defaults('maskClosable', true),
38
- maskStyle = defaults('maskStyle'),
39
38
  motion = defaults('motion', true),
40
39
  onCancel,
41
40
  placement = defaults('placement', 'right'),
42
41
  size = defaults('size', 'small'),
43
42
  style = defaults('style'),
43
+ styles = defaults('styles'),
44
44
  title = defaults('title'),
45
45
  visible = $bindable(),
46
46
  width = defaults('width'),
@@ -64,7 +64,7 @@
64
64
  const shouldRender = $derived(Boolean(visible) || keepDOM || (motion && !hidden));
65
65
  const hasTitle = $derived(typeof title === 'string' ? title !== '' : Boolean(title));
66
66
  const sheetSize = $derived(SideSheetFoundation.getSheetSize({ placement, canVerticalSetWidth, width, height, mask }));
67
- const attrs = $derived(splitControlAttrs(rest, isAriaKey));
67
+ const attrs = $derived(splitControlAttrs(omitBy(rest, isNil), isAriaKey));
68
68
  const horizontal = $derived(placement === 'top' || placement === 'bottom');
69
69
  const maskAnimation = $derived(animating ? `${prefix}-animation-mask_${animating}` : undefined);
70
70
  const dialogAnimation = $derived(animating ? `${prefix}-animation-content_${animating}_${placement}` : undefined);
@@ -103,7 +103,7 @@
103
103
  );
104
104
 
105
105
  // aria-* go to the dialog (F12); the title names it unless the caller does, since a generated reference would
106
- // shadow aria-label
106
+ // shadow aria-label. `attrs` drops attributes bound to undefined, which count as unset and keep these defaults.
107
107
  const dialogAttrs = (inBody: boolean) => ({
108
108
  'aria-labelledby': !attrs.control['aria-label'] && hasTitle ? `${uid}-title` : undefined,
109
109
  'aria-modal': SideSheetFoundation.isModal({ mask, inBody }) ? true : undefined,
@@ -130,18 +130,17 @@
130
130
  displayNone = true;
131
131
  }
132
132
  animating = undefined;
133
+ foundation.handleAnimationEnd();
133
134
  };
134
135
 
135
- // Before the DOM updates, so the focus is recorded ahead of anything in the sheet taking it, and the classes of the
136
- // new run are in the first render. The initial run is the mount: shown with an enter animation, or hidden without
137
- // a leave one.
136
+ // Before the DOM updates, so the classes of the new run are in the first render. The initial run is the mount: shown
137
+ // with an enter animation, or hidden without a leave one.
138
138
  $effect.pre(() => {
139
139
  const open = visible;
140
140
  untrack(() => {
141
141
  if (open) {
142
142
  displayNone = false;
143
143
  animating = motion ? 'show' : undefined;
144
- foundation.recordFocus();
145
144
  } else if (started) {
146
145
  animating = motion ? 'hide' : undefined;
147
146
  }
@@ -166,19 +165,22 @@
166
165
  });
167
166
  });
168
167
 
169
- $effect(() => {
170
- const element = dialogEl;
171
- if (!visible || !element || !rootEl) {
172
- return;
173
- }
174
- untrack(() => {
175
- foundation.beforeShow();
176
- warnIfDialogUnnamed(element, 'SideSheet');
177
- });
178
- return foundation.afterHide;
179
- });
168
+ useOverlayResources(
169
+ foundation,
170
+ () => visible,
171
+ () => Boolean(dialogEl && !hidden && rootEl)
172
+ );
180
173
 
181
- watch(() => hidden, foundation.handleHiddenChange);
174
+ watch(
175
+ () => hidden,
176
+ (isHidden) => {
177
+ foundation.handleHiddenChange(isHidden);
178
+ // no animation ends a showing without motion
179
+ if (!motion) {
180
+ foundation.handleAnimationEnd();
181
+ }
182
+ }
183
+ );
182
184
 
183
185
  onMount(() => () => foundation.handleHiddenChange(true));
184
186
 
@@ -209,21 +211,21 @@
209
211
  >
210
212
  {#if mask}
211
213
  <!-- Pointer-only surface: the keyboard closes the sheet with its close button and Escape -->
212
- <div aria-hidden="true" class={[`${prefix}-mask`, maskAnimation]} style={maskStyle} onclick={onMaskClick}></div>
214
+ <div aria-hidden="true" class={[`${prefix}-mask`, maskAnimation, classNames?.mask]} style={styles?.mask} onclick={onMaskClick}></div>
213
215
  {/if}
214
216
  <div
215
217
  {...dialogAttrs(inBody)}
216
218
  bind:this={dialogEl}
217
- class={[`${prefix}-inner`, `${prefix}-inner-wrap`, `${prefix}-size-${size}`, dialogAnimation]}
219
+ class={[`${prefix}-inner`, `${prefix}-inner-wrap`, `${prefix}-size-${size}`, dialogAnimation, classNames?.content]}
218
220
  role="dialog"
219
- {style}
221
+ style={[style, styles?.content].filter(Boolean).join('; ') || undefined}
220
222
  style:height={toCssLength(sheetSize.dialogHeight)}
221
223
  style:width={toCssLength(sheetSize.dialogWidth)}
222
224
  tabindex="-1"
223
225
  onanimationend={onAnimationEnd}
224
226
  >
225
227
  <div class={`${prefix}-content`}>
226
- <div class={`${prefix}-header`} style={headerStyle}>
228
+ <div class={[`${prefix}-header`, classNames?.header]} style={styles?.header}>
227
229
  {#if hasTitle}
228
230
  <div aria-level="2" class={`${prefix}-title`} id={`${uid}-title`} role="heading" x-semi-prop="title">
229
231
  {#if typeof title === 'string'}{title}{:else}{@render title?.()}{/if}
@@ -237,11 +239,11 @@
237
239
  </IconButton>
238
240
  {/if}
239
241
  </div>
240
- <div class={`${prefix}-body`} style={bodyStyle} x-semi-prop="children">
242
+ <div class={[`${prefix}-body`, classNames?.body]} style={styles?.body} x-semi-prop="children">
241
243
  {@render body?.()}
242
244
  </div>
243
245
  {#if footer}
244
- <div class={`${prefix}-footer`} x-semi-prop="footer">
246
+ <div class={[`${prefix}-footer`, classNames?.footer]} style={styles?.footer} x-semi-prop="footer">
245
247
  {@render footer()}
246
248
  </div>
247
249
  {/if}
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes, HTMLInputAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLAttributes, HTMLInputAttributes } from 'svelte/elements';
3
+ import type { SliderPart } from '@fibrae/semi-foundation/components/slider/constants';
3
4
  import type { HandleDot } from '@fibrae/semi-foundation/components/slider/foundation';
4
5
  export type { HandleDot, SliderState } from '@fibrae/semi-foundation/components/slider/foundation';
5
6
  export interface SliderMarkSnippetProps {
@@ -30,7 +31,8 @@ export interface SliderProps extends Omit<HTMLAttributes<HTMLDivElement>, Native
30
31
  showBoundary?: boolean;
31
32
  vertical?: boolean;
32
33
  verticalReverse?: boolean;
33
- railStyle?: string;
34
+ classNames?: Partial<Record<SliderPart, ClassValue>>;
35
+ styles?: Partial<Record<SliderPart, string>>;
34
36
  handleDot?: HandleDot | HandleDot[];
35
37
  /** Names the first handle's input, so a `<label for>` focuses the slider */
36
38
  id?: string;
@@ -44,7 +44,8 @@
44
44
  showBoundary = defaults('showBoundary', false),
45
45
  vertical = defaults('vertical', false),
46
46
  verticalReverse = defaults('verticalReverse', false),
47
- railStyle = defaults('railStyle'),
47
+ classNames = defaults('classNames'),
48
+ styles = defaults('styles'),
48
49
  handleDot = defaults('handleDot'),
49
50
  // no global default: a global id would repeat on every instance
50
51
  id,
@@ -299,7 +300,7 @@
299
300
  foundation.handleWrapperLeave();
300
301
  }}
301
302
  >
302
- <div class={`${prefix}-rail`} style={railStyle} onclick={foundation.handleWrapClick}></div>
303
+ <div class={[`${prefix}-rail`, classNames?.rail]} style={styles?.rail} onclick={foundation.handleWrapClick}></div>
303
304
  <div class={cssClasses.TRACK} style={trackStyle} onclick={foundation.handleWrapClick}></div>
304
305
  {#if markList.length}
305
306
  <div class={cssClasses.DOTS}>
@@ -4,7 +4,7 @@
4
4
  const gradientId = `linearGradient-${uid}`;
5
5
  </script>
6
6
 
7
- <svg aria-hidden="true" data-icon="spin" height="48" version="1.1" viewBox="0 0 36 36" width="48" xmlns="http://www.w3.org/2000/svg">
7
+ <svg aria-hidden="true" data-icon="spin" height="48" viewBox="0 0 36 36" width="48" xmlns="http://www.w3.org/2000/svg">
8
8
  <defs>
9
9
  <linearGradient id={gradientId} x1="0%" x2="100%" y1="100%" y2="100%">
10
10
  <stop offset="0%" stop-color="currentColor" stop-opacity="0" />
@@ -1,12 +1,13 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
+ import type { SpinPart } from '@fibrae/semi-foundation/components/spin/constants';
3
4
  export type SpinSize = 'small' | 'large' | 'middle';
4
5
  export interface SpinProps extends HTMLAttributes<HTMLDivElement> {
5
6
  size?: SpinSize;
6
7
  spinning?: boolean;
7
8
  delay?: number;
8
- wrapperClassName?: string;
9
- childStyle?: string;
9
+ classNames?: Partial<Record<SpinPart, ClassValue>>;
10
+ styles?: Partial<Record<SpinPart, string>>;
10
11
  indicator?: Snippet;
11
12
  tip?: Snippet;
12
13
  }
@@ -12,7 +12,7 @@
12
12
  type Adapter = SpinAdapter<SpinProps>;
13
13
 
14
14
  const defaults = useDefaultProps('Spin');
15
- let { size = defaults('size', 'middle'), spinning = defaults('spinning', true), delay = defaults('delay', 0), wrapperClassName = defaults('wrapperClassName'), childStyle = defaults('childStyle'), indicator = defaults('indicator'), tip = defaults('tip'), children, ...rest }: SpinProps = $props();
15
+ let { size = defaults('size', 'middle'), spinning = defaults('spinning', true), delay = defaults('delay', 0), classNames = defaults('classNames'), styles = defaults('styles'), indicator = defaults('indicator'), tip = defaults('tip'), children, ...rest }: SpinProps = $props();
16
16
 
17
17
  const locale = useLocale('Spin');
18
18
 
@@ -48,7 +48,6 @@
48
48
  aria-busy={blocked ? true : undefined}
49
49
  class={[
50
50
  prefixCls,
51
- wrapperClassName,
52
51
  rest.class,
53
52
  {
54
53
  [`${prefixCls}-${size}`]: size,
@@ -70,7 +69,7 @@
70
69
  {/if}
71
70
  </output>
72
71
  {/if}
73
- <div class={`${prefixCls}-children`} inert={blocked} style={childStyle} x-semi-prop="children">
72
+ <div class={[`${prefixCls}-children`, classNames?.child]} inert={blocked} style={styles?.child} x-semi-prop="children">
74
73
  {@render children?.()}
75
74
  </div>
76
75
  </div>
@@ -79,7 +79,7 @@
79
79
  style={[rest.style, tooltip?.pointerEventsNone && 'pointer-events: none'].filter(Boolean).join(';') || undefined}
80
80
  >
81
81
  {#if loading}
82
- <Spin size={size === 'default' ? 'middle' : size} wrapperClassName={cssClasses.LOADING_SPIN} />
82
+ <Spin class={cssClasses.LOADING_SPIN} size={size === 'default' ? 'middle' : size} />
83
83
  {:else}
84
84
  <div aria-hidden="true" class={cssClasses.KNOB}></div>
85
85
  {/if}
@@ -54,6 +54,8 @@
54
54
  let bodyElement = $state<HTMLDivElement>();
55
55
  let listElement = $state<HTMLElement>();
56
56
  let list = $state<ReturnType<typeof VirtualList>>();
57
+ let listHeader = $state<HTMLDivElement>();
58
+ let listHeaderHeight = $state(0);
57
59
  let hoveredRowKey = $state<BaseRowKeyType | null>(null);
58
60
 
59
61
  // whether the body overflows, so it takes keyboard focus to scroll; known after mount
@@ -98,13 +100,12 @@
98
100
  if (!table.virtualized) {
99
101
  return null;
100
102
  }
103
+ // the header measures the widths, so it renders before the rows have any
101
104
  const cellWidths = table.getCellWidths(columns);
102
- if (!cellWidths.length) {
103
- return null;
104
- }
105
+ const hasWidths = cellWidths.length > 0;
105
106
  const y = typeof table.scroll?.y === 'number' ? table.scroll.y : numbers.DEFAULT_VIRTUALIZED_BODY_HEIGHT;
106
- const rowWidth = arrayAdd(cellWidths, 0, columns.length);
107
- return { rowWidth, height: virtualizedData.length ? y : 0 };
107
+ const rowWidth = hasWidths ? arrayAdd(cellWidths, 0, columns.length) : 0;
108
+ return { rowWidth, itemCount: hasWidths ? virtualizedData.length : 0, height: virtualizedData.length ? y : 0 };
108
109
  });
109
110
 
110
111
  // a scrolling body must be keyboard reachable even without a focusable cell
@@ -185,10 +186,10 @@
185
186
  untrack(() => list?.measure());
186
187
  });
187
188
 
188
- // with scroll.y the header is a separate table that reserves the width of a vertical scrollbar the body shows
189
+ // a separate (sticky) header reserves the width of a vertical scrollbar the body shows (#1219)
189
190
  $effect(() => {
190
191
  const node = scrollElement();
191
- if (!table.scroll?.y || !node) {
192
+ if (!table.scroll?.y || includeHeader || !node) {
192
193
  return;
193
194
  }
194
195
  const observer = new ResizeObserver(() => {
@@ -232,15 +233,27 @@
232
233
  class="{table.prefixCls}-body"
233
234
  height={virtualBody.height}
234
235
  innerAttrs={{ class: `${table.prefixCls}-tbody`, role: 'rowgroup' }}
235
- itemCount={virtualizedData.length}
236
+ itemCount={virtualBody.itemCount}
236
237
  itemKey={virtualKey}
237
238
  {itemSize}
238
239
  overscan={table.virtualizedProps?.overscanCount}
240
+ scrollMargin={includeHeader ? listHeaderHeight : 0}
239
241
  style="direction: {table.direction}{virtualizedData.length ? '' : '; height: auto'}"
240
242
  tabindex={0}
241
243
  wrapperAttrs={{ class: [table.prefixCls, `${table.prefixCls}-fixed`], role: 'none', style: rowStyle }}
242
244
  onscroll={handleListScroll}
243
245
  >
246
+ {#snippet before()}
247
+ {#if includeHeader}
248
+ <!-- a hidden header stays for its column widths; inert keeps its controls out of the Tab order and the a11y tree; rendered in the list's scroller above the rows, so the browser moves it with them in the same frame -->
249
+ <div {@attach observeResize(() => (listHeaderHeight = listHeader?.offsetHeight ?? 0))} bind:this={listHeader} class="{table.prefixCls}-list-header" inert={!table.showHeader}>
250
+ <svelte:element this={table.components.header.outer} class={[table.prefixCls, `${table.prefixCls}-fixed`]} role="none" style={joinStyles(table.scroll?.x != null && `width: ${toCssLength(table.scroll.x)}`, minWidth !== undefined && `min-width: ${toCssLength(minWidth)}`)}>
251
+ <ColGroup {columns} prefixCls={table.prefixCls} />
252
+ <TableHeader {columns} hidden={!table.showHeader} />
253
+ </svelte:element>
254
+ </div>
255
+ {/if}
256
+ {/snippet}
244
257
  {#snippet children({ index, style })}
245
258
  {@const item = virtualItem(index)}
246
259
  {#if item.sectionRow}
@@ -34,7 +34,8 @@ export interface TableContextValue {
34
34
  readonly anyColumnFixed: boolean;
35
35
  readonly flattenedColumns: ColumnProps[];
36
36
  readonly headWidths: BaseHeadWidth[][];
37
- readonly headerStyle?: string;
37
+ readonly classNames?: TableProps['classNames'];
38
+ readonly styles?: TableProps['styles'];
38
39
  readonly rowSpanHover: boolean;
39
40
  /** The header and the body are separate elements, so their container is the table */
40
41
  readonly splitTable: boolean;
@@ -1,6 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes, HTMLTdAttributes, HTMLThAttributes } from 'svelte/elements';
3
- import type { strings } from '@fibrae/semi-foundation/components/table/constants';
2
+ import type { ClassValue, HTMLAttributes, HTMLTdAttributes, HTMLThAttributes } from 'svelte/elements';
3
+ import type { strings, TablePart } from '@fibrae/semi-foundation/components/table/constants';
4
4
  import type { BaseAlign, BaseChangeInfoFilter, BaseChangeInfoSorter, BaseEllipsis, BaseFixed, BaseIncludeGroupRecord, BasePageData, CheckRelation, OnChangeExtra } from '@fibrae/semi-foundation/components/table/foundation';
5
5
  import type { Locale } from '@fibrae/semi-foundation/locale';
6
6
  import type { CheckboxProps } from '../checkbox/interface.js';
@@ -262,6 +262,7 @@ export interface TableVirtualizedScrollArgs {
262
262
  export interface TableProps<R extends AnyRecord = AnyRecord> extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'onchange' | 'onscroll' | 'children'> {
263
263
  bordered?: boolean;
264
264
  childrenRecordName?: string;
265
+ classNames?: Partial<Record<TablePart, ClassValue>>;
265
266
  clickGroupedRowToExpand?: boolean;
266
267
  columns?: ColumnProps<R>[];
267
268
  components?: TableComponents;
@@ -286,7 +287,6 @@ export interface TableProps<R extends AnyRecord = AnyRecord> extends Omit<HTMLAt
286
287
  footer?: string | Snippet<[TableTitleSnippetProps<R>]>;
287
288
  groupBy?: TableGroupBy<R>;
288
289
  groupSectionColumn?: (groupKey: string | number, group: (string | number)[]) => Omit<ColumnProps<R>, 'title' | 'children' | 'dataIndex'>;
289
- headerStyle?: string;
290
290
  hideExpandedColumn?: boolean;
291
291
  indentSize?: number;
292
292
  keepDOM?: boolean;
@@ -303,6 +303,7 @@ export interface TableProps<R extends AnyRecord = AnyRecord> extends Omit<HTMLAt
303
303
  showHeader?: boolean;
304
304
  size?: TableSize;
305
305
  sticky?: TableSticky;
306
+ styles?: Partial<Record<TablePart, string>>;
306
307
  title?: string | Snippet<[TableTitleSnippetProps<R>]>;
307
308
  virtualized?: TableVirtualized;
308
309
  onChange?: (changeInfo: TableChangeInfo<R>) => void;
@@ -78,6 +78,7 @@
78
78
  rowspan,
79
79
  class: [
80
80
  `${table.prefixCls}-row-head`,
81
+ table.classNames?.header,
81
82
  column.class,
82
83
  customClass,
83
84
  {
@@ -91,7 +92,7 @@
91
92
  [`${table.prefixCls}-row-head-clickSort`]: flags.clickToSort,
92
93
  },
93
94
  ],
94
- style: joinStyles(table.headerStyle, customStyle as string | undefined, textAlign && `text-align: ${textAlign}`, stickyOffset && `position: sticky; ${stickyOffset.side}: ${toCssLength(stickyOffset.offset)}`),
95
+ style: joinStyles(table.styles?.header, customStyle as string | undefined, textAlign && `text-align: ${textAlign}`, stickyOffset && `position: sticky; ${stickyOffset.side}: ${toCssLength(stickyOffset.offset)}`),
95
96
  // a role="none" table no longer gives colspan and rowspan their table meaning
96
97
  'aria-colspan': table.splitTable && colspan && colspan > 1 ? colspan : undefined,
97
98
  'aria-rowspan': table.splitTable && rowspan && rowspan > 1 ? rowspan : undefined,
@@ -123,8 +124,9 @@
123
124
  return { ...custom, class: [customClass, `${table.prefixCls}-row`] };
124
125
  });
125
126
 
126
- // The measured widths give the sticky offsets of fixed columns; measured when the columns change, not on every
127
- // render, since reading layout after a DOM update forces a reflow
127
+ // The measured widths give the sticky offsets of fixed columns; measured when the columns change or the row resizes
128
+ // (a column without a number width follows the table's width), not on every render, since reading layout after a
129
+ // DOM update forces a reflow
128
130
  const measure = (node: HTMLElement) => {
129
131
  const levelColumns = getColumnsByLevel(columns, index) as ColumnProps[];
130
132
  const heads = node.querySelectorAll(`.${table.prefixCls}-row-head`);
@@ -171,6 +173,16 @@
171
173
  untrack(() => measure(row));
172
174
  }
173
175
  });
176
+
177
+ $effect(() => {
178
+ const row = rowElement;
179
+ if (!row) {
180
+ return;
181
+ }
182
+ const observer = new ResizeObserver(() => measure(row));
183
+ observer.observe(row);
184
+ return () => observer.disconnect();
185
+ });
174
186
  </script>
175
187
 
176
188
  <svelte:element this={table.components.header.row} bind:this={rowElement} {...rowAttrs} role="row">
@@ -32,6 +32,7 @@
32
32
  let {
33
33
  bordered = defaults('bordered', false),
34
34
  childrenRecordName = defaults('childrenRecordName', 'children'),
35
+ classNames = defaults('classNames'),
35
36
  clickGroupedRowToExpand = defaults('clickGroupedRowToExpand', false),
36
37
  columns = defaults('columns'),
37
38
  components = defaults('components'),
@@ -49,7 +50,6 @@
49
50
  footer = defaults('footer'),
50
51
  groupBy = defaults('groupBy'),
51
52
  groupSectionColumn = defaults('groupSectionColumn'),
52
- headerStyle = defaults('headerStyle'),
53
53
  hideExpandedColumn = defaults('hideExpandedColumn', true),
54
54
  indentSize = defaults('indentSize', 20),
55
55
  keepDOM = defaults('keepDOM', false),
@@ -65,6 +65,7 @@
65
65
  showHeader = defaults('showHeader', true),
66
66
  size = defaults('size', 'default'),
67
67
  sticky = defaults('sticky'),
68
+ styles = defaults('styles'),
68
69
  title = defaults('title'),
69
70
  virtualized = defaults('virtualized'),
70
71
  onChange,
@@ -165,7 +166,13 @@
165
166
  const showExpandIcon = $derived(expandIcon !== false);
166
167
  const fixedHeader = $derived(Boolean(scroll?.y) || Boolean(sticky));
167
168
  const isVirtualized = $derived(Boolean(virtualized));
168
- const splitTable = $derived(fixedHeader || isVirtualized);
169
+
170
+ /**
171
+ * Elsewhere the header sits in the body's scroller, so the compositor moves both in the same frame. A header stuck
172
+ * to the page would be trapped by the body's overflow, so it renders as a separate table above the body
173
+ */
174
+ const headerApart = $derived(Boolean(sticky));
175
+ const splitTable = $derived(headerApart || isVirtualized);
169
176
  const mergedComponents = $derived(mergeComponents(components, isVirtualized));
170
177
  const paginationPosition = $derived(paginationOptions?.position ?? 'bottom');
171
178
  const formatPageText = $derived(paginationOptions?.formatPageText);
@@ -342,8 +349,13 @@
342
349
  return;
343
350
  }
344
351
  const scroller = body?.element();
345
- if (target.scrollLeft !== lastScrollLeft) {
346
- if (target === scroller && head) {
352
+ if (target === head && scroller && foundation.headerFollowsInCss()) {
353
+ // focus scrolled the clipped header to reveal a cell; the body takes the distance, and the header's
354
+ // animation follows it
355
+ scroller.scrollLeft += target.scrollLeft;
356
+ target.scrollLeft = 0;
357
+ } else if (target.scrollLeft !== lastScrollLeft) {
358
+ if (target === scroller && head && !foundation.headerFollowsInCss()) {
347
359
  head.scrollLeft = target.scrollLeft;
348
360
  } else if (target === head && scroller) {
349
361
  scroller.scrollLeft = target.scrollLeft;
@@ -391,8 +403,11 @@
391
403
  get headWidths() {
392
404
  return view.headWidths ?? [];
393
405
  },
394
- get headerStyle() {
395
- return headerStyle;
406
+ get classNames() {
407
+ return classNames;
408
+ },
409
+ get styles() {
410
+ return styles;
396
411
  },
397
412
  get rowSpanHover() {
398
413
  return rowSpanHover;
@@ -587,6 +602,21 @@
587
602
  return () => observer.disconnect();
588
603
  });
589
604
 
605
+ // the content-box size changes with the body's scrollbar too; columns or rows that widen the table without
606
+ // resizing the body are caught after the update
607
+ $effect(() => {
608
+ void tableColumns;
609
+ void view.dataSource;
610
+ const node = body?.element();
611
+ if (!headerApart || !node) {
612
+ return;
613
+ }
614
+ untrack(foundation.syncHeaderScrollRange);
615
+ const observer = new ResizeObserver(foundation.syncHeaderScrollRange);
616
+ observer.observe(node);
617
+ return () => observer.disconnect();
618
+ });
619
+
590
620
  export function getCurrentPageData(): ReturnType<TableHandle['getCurrentPageData']> {
591
621
  return cloneDeep(foundation.getCurrentPageData());
592
622
  }
@@ -623,7 +653,7 @@
623
653
  </div>
624
654
  {/if}
625
655
  <div {...splitTable ? nameAttrs : {}} aria-rowcount={isVirtualized ? headerRowCount + virtualizedData.length : undefined} class="{prefixCls}-container" role={splitTable ? 'table' : undefined}>
626
- {#if fixedHeader}
656
+ {#if headerApart}
627
657
  <HeadTable bind:element={head} columns={tableColumns} />
628
658
  {/if}
629
659
  <Body
@@ -632,7 +662,7 @@
632
662
  dataSource={view.dataSource ?? []}
633
663
  expandedRowKeys={view.expandedRowKeys ?? []}
634
664
  groups={view.groups}
635
- includeHeader={!fixedHeader}
665
+ includeHeader={!headerApart}
636
666
  {onScroll}
637
667
  pageDisabledRowKeysSet={view.pageDisabledRowKeysSet ?? EMPTY_KEYS}
638
668
  tableAttrs={splitTable ? undefined : nameAttrs}
@@ -1,5 +1,6 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { ClassValue, HTMLAttributes } from 'svelte/elements';
3
+ import type { TabsPart } from '@fibrae/semi-foundation/components/tabs/constants';
3
4
  import type { DropdownProps } from '../dropdown/index.js';
4
5
  export type TabType = 'line' | 'card' | 'button' | 'slash';
5
6
  export type TabSize = 'small' | 'medium' | 'large';
@@ -41,9 +42,11 @@ export interface TabBarProps {
41
42
  showRestInDropdown: boolean;
42
43
  more?: number | TabsMore;
43
44
  arrowPosition: 'both' | 'start' | 'end';
44
- visibleTabsStyle?: string;
45
+ /** Only `visibleTabs` is read: the scroll wrapper that holds the visible tabs */
46
+ classNames?: Partial<Record<'visibleTabs', ClassValue>>;
47
+ styles?: Partial<Record<'visibleTabs', string>>;
45
48
  dropdownProps?: TabsDropdownProps;
46
- class?: string;
49
+ class?: ClassValue;
47
50
  style?: string;
48
51
  }
49
52
  export interface TabsTabBarSnippetProps {
@@ -64,7 +67,7 @@ export interface TabsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'childre
64
67
  activeKey?: string | null;
65
68
  arrowPosition?: 'both' | 'start' | 'end';
66
69
  collapsible?: boolean | 'auto';
67
- contentStyle?: string;
70
+ classNames?: Partial<Record<TabsPart, ClassValue>>;
68
71
  dropdownProps?: TabsDropdownProps;
69
72
  keepDOM?: boolean;
70
73
  lazyRender?: boolean;
@@ -72,13 +75,11 @@ export interface TabsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'childre
72
75
  preventScroll?: boolean;
73
76
  showRestInDropdown?: boolean;
74
77
  size?: TabSize;
75
- tabBarClassName?: string;
76
- tabBarStyle?: string;
78
+ styles?: Partial<Record<TabsPart, string>>;
77
79
  tabList?: PlainTab[];
78
80
  tabPaneMotion?: boolean;
79
81
  tabPosition?: TabPosition;
80
82
  type?: TabType;
81
- visibleTabsStyle?: string;
82
83
  onChange?: (activeKey: string) => void;
83
84
  onTabClick?: (activeKey: string, event: MouseEvent | KeyboardEvent) => void;
84
85
  onTabClose?: (tabKey: string) => void;
@@ -25,7 +25,7 @@
25
25
  onVisibleTabsChange?: (visibleState: Map<string, boolean>) => void;
26
26
  }
27
27
 
28
- let { activeKey, list, type, size, tabPosition, collapsible, showRestInDropdown, more, arrowPosition, visibleTabsStyle, dropdownProps, tablistAttrs, class: className, style, tab, icon, arrow, moreTrigger, moreContent, extra, onVisibleTabsChange }: Props = $props();
28
+ let { activeKey, list, type, size, tabPosition, collapsible, showRestInDropdown, more, arrowPosition, classNames, styles, dropdownProps, tablistAttrs, class: className, style, tab, icon, arrow, moreTrigger, moreContent, extra, onVisibleTabsChange }: Props = $props();
29
29
 
30
30
  const ctx = requireTabsContext('TabBar');
31
31
  const locale = useLocale('Tabs');
@@ -167,7 +167,17 @@
167
167
  {style}
168
168
  >
169
169
  {#if collapsed}
170
- <OverflowList class="{prefix}-overflow-list" itemKey="key" items={overflowItems} onVisibleStateChange={foundation.handleVisibleStateChange} overflowRenderDirection={arrowPosition} renderMode="scroll" wrapperProps={tablistProps} wrapperStyle={visibleTabsStyle}>
170
+ <OverflowList
171
+ class="{prefix}-overflow-list"
172
+ classNames={{ wrapper: classNames?.visibleTabs }}
173
+ itemKey="key"
174
+ items={overflowItems}
175
+ onVisibleStateChange={foundation.handleVisibleStateChange}
176
+ overflowRenderDirection={arrowPosition}
177
+ renderMode="scroll"
178
+ styles={{ wrapper: styles?.visibleTabs }}
179
+ wrapperProps={tablistProps}
180
+ >
171
181
  {#snippet item({ item: overflowItem, index })}
172
182
  {@render tabItem(list[index] ?? overflowItem, index)}
173
183
  {/snippet}
@@ -23,7 +23,7 @@
23
23
  activeKey = $bindable(),
24
24
  arrowPosition = defaults('arrowPosition', 'both'),
25
25
  collapsible = defaults('collapsible', false),
26
- contentStyle = defaults('contentStyle'),
26
+ classNames = defaults('classNames'),
27
27
  dropdownProps = defaults('dropdownProps'),
28
28
  keepDOM = defaults('keepDOM', true),
29
29
  lazyRender = defaults('lazyRender', false),
@@ -31,13 +31,11 @@
31
31
  preventScroll = defaults('preventScroll'),
32
32
  showRestInDropdown = defaults('showRestInDropdown', true),
33
33
  size = defaults('size', 'large'),
34
- tabBarClassName = defaults('tabBarClassName'),
35
- tabBarStyle = defaults('tabBarStyle'),
34
+ styles = defaults('styles'),
36
35
  tabList = defaults('tabList', []),
37
36
  tabPaneMotion = defaults('tabPaneMotion', true),
38
37
  tabPosition = defaults('tabPosition', 'top'),
39
38
  type = defaults('type', 'line'),
40
- visibleTabsStyle = defaults('visibleTabsStyle'),
41
39
  onChange,
42
40
  onTabClick,
43
41
  onTabClose,
@@ -136,10 +134,11 @@
136
134
  showRestInDropdown,
137
135
  more,
138
136
  arrowPosition,
139
- visibleTabsStyle,
137
+ classNames: { visibleTabs: classNames?.visibleTabs },
138
+ styles: { visibleTabs: styles?.visibleTabs },
140
139
  dropdownProps,
141
- class: tabBarClassName,
142
- style: tabBarStyle,
140
+ class: classNames?.tabBar,
141
+ style: styles?.tabBar,
143
142
  });
144
143
 
145
144
  // Without `panel` the content area is the single panel; without a matching tab it has nothing to be labelled by
@@ -178,7 +177,7 @@
178
177
  {:else}
179
178
  {@render defaultBar()}
180
179
  {/if}
181
- <div {...contentPanelAttrs} class={[cssClasses.TABS_CONTENT, `${cssClasses.TABS_CONTENT}-${tabPosition}`]} style={contentStyle}>
180
+ <div {...contentPanelAttrs} class={[cssClasses.TABS_CONTENT, `${cssClasses.TABS_CONTENT}-${tabPosition}`, classNames?.content]} style={styles?.content}>
182
181
  {#if panel}
183
182
  {#each tabList as item, index (item.itemKey)}
184
183
  {#if keepDOM || item.itemKey === current}