@fibrae/semi-ui-svelte 0.9.0 → 0.10.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 (169) hide show
  1. package/README.md +8 -4
  2. package/README.zh-CN.md +8 -4
  3. package/dist/components/anchor/interface.d.ts +14 -0
  4. package/dist/components/audio-player/interface.d.ts +5 -0
  5. package/dist/components/auto-complete/interface.d.ts +29 -0
  6. package/dist/components/avatar/interface.d.ts +24 -0
  7. package/dist/components/backtop/interface.d.ts +2 -0
  8. package/dist/components/badge/interface.d.ts +7 -0
  9. package/dist/components/banner/interface.d.ts +7 -0
  10. package/dist/components/breadcrumb/interface.d.ts +10 -0
  11. package/dist/components/button/interface.d.ts +18 -0
  12. package/dist/components/calendar/interface.d.ts +16 -0
  13. package/dist/components/card/interface.d.ts +18 -0
  14. package/dist/components/carousel/interface.d.ts +16 -0
  15. package/dist/components/cascader/cascader.svelte +1 -0
  16. package/dist/components/cascader/interface.d.ts +57 -0
  17. package/dist/components/checkbox/interface.d.ts +19 -0
  18. package/dist/components/code-highlight/interface.d.ts +3 -0
  19. package/dist/components/collapse/interface.d.ts +16 -0
  20. package/dist/components/collapsible/interface.d.ts +10 -0
  21. package/dist/components/color-picker/interface.d.ts +10 -0
  22. package/dist/components/config-provider/interface.d.ts +7 -0
  23. package/dist/components/cropper/interface.d.ts +11 -0
  24. package/dist/components/date-picker/interface.d.ts +47 -0
  25. package/dist/components/descriptions/interface.d.ts +6 -0
  26. package/dist/components/divider/interface.d.ts +4 -0
  27. package/dist/components/dropdown/interface.d.ts +8 -0
  28. package/dist/components/empty/interface.d.ts +7 -0
  29. package/dist/components/feedback/interface.d.ts +16 -0
  30. package/dist/components/float-button/interface.d.ts +14 -0
  31. package/dist/components/form/interface.d.ts +47 -0
  32. package/dist/components/form/label.svelte +2 -2
  33. package/dist/components/grid/interface.d.ts +13 -0
  34. package/dist/components/highlight/interface.d.ts +7 -0
  35. package/dist/components/hot-keys/interface.d.ts +3 -0
  36. package/dist/components/image/interface.d.ts +59 -0
  37. package/dist/components/input/interface.d.ts +67 -0
  38. package/dist/components/input-number/interface.d.ts +24 -0
  39. package/dist/components/json-viewer/interface.d.ts +7 -0
  40. package/dist/components/layout/interface.d.ts +3 -0
  41. package/dist/components/list/interface.d.ts +18 -0
  42. package/dist/components/locale/interface.d.ts +4 -0
  43. package/dist/components/lottie/interface.d.ts +2 -0
  44. package/dist/components/markdown-render/interface.d.ts +5 -0
  45. package/dist/components/modal/interface.d.ts +29 -0
  46. package/dist/components/navigation/interface.d.ts +47 -0
  47. package/dist/components/overflow-list/interface.d.ts +11 -0
  48. package/dist/components/pagination/interface.d.ts +12 -0
  49. package/dist/components/pincode/interface.d.ts +8 -0
  50. package/dist/components/popconfirm/interface.d.ts +12 -0
  51. package/dist/components/popover/interface.d.ts +30 -0
  52. package/dist/components/progress/interface.d.ts +13 -0
  53. package/dist/components/radio/interface.d.ts +22 -0
  54. package/dist/components/rating/interface.d.ts +12 -0
  55. package/dist/components/resizable/interface.d.ts +30 -0
  56. package/dist/components/scroll-list/interface.d.ts +6 -0
  57. package/dist/components/select/interface.d.ts +63 -0
  58. package/dist/components/side-sheet/interface.d.ts +19 -0
  59. package/dist/components/skeleton/interface.d.ts +7 -0
  60. package/dist/components/slider/interface.d.ts +23 -0
  61. package/dist/components/space/interface.d.ts +4 -0
  62. package/dist/components/spin/interface.d.ts +7 -0
  63. package/dist/components/steps/interface.d.ts +9 -0
  64. package/dist/components/switch/interface.d.ts +7 -0
  65. package/dist/components/table/interface.d.ts +48 -0
  66. package/dist/components/tabs/interface.d.ts +29 -0
  67. package/dist/components/tag/interface.d.ts +22 -0
  68. package/dist/components/tag-input/interface.d.ts +29 -0
  69. package/dist/components/time-picker/interface.d.ts +31 -0
  70. package/dist/components/timeline/interface.d.ts +5 -0
  71. package/dist/components/tooltip/interface.d.ts +20 -0
  72. package/dist/components/tooltip/tooltip.svelte +3 -0
  73. package/dist/components/transfer/interface.d.ts +18 -0
  74. package/dist/components/tree/interface.d.ts +45 -0
  75. package/dist/components/tree-select/interface.d.ts +55 -0
  76. package/dist/components/typography/interface.d.ts +33 -0
  77. package/dist/components/upload/interface.d.ts +64 -0
  78. package/dist/components/user-guide/interface.d.ts +15 -0
  79. package/dist/components/video-player/interface.d.ts +22 -0
  80. package/dist/styles.css +1 -1
  81. package/docs/advanced/dark-mode.md +288 -0
  82. package/docs/basic/button.md +605 -0
  83. package/docs/basic/divider.md +103 -0
  84. package/docs/basic/float-button.md +246 -0
  85. package/docs/basic/grid.md +427 -0
  86. package/docs/basic/layout.md +459 -0
  87. package/docs/basic/resizable.md +584 -0
  88. package/docs/basic/space.md +163 -0
  89. package/docs/basic/tokens.md +425 -0
  90. package/docs/basic/typography.md +615 -0
  91. package/docs/changes-from-semi.md +105 -0
  92. package/docs/ecosystem/tailwind.md +210 -0
  93. package/docs/experience/accessibility.md +82 -0
  94. package/docs/experience/content-guidelines.md +819 -0
  95. package/docs/experience/internationalization.md +7 -0
  96. package/docs/feedback/banner.md +198 -0
  97. package/docs/feedback/feedback.md +294 -0
  98. package/docs/feedback/notification.md +401 -0
  99. package/docs/feedback/popconfirm.md +243 -0
  100. package/docs/feedback/progress.md +389 -0
  101. package/docs/feedback/skeleton.md +388 -0
  102. package/docs/feedback/spin.md +172 -0
  103. package/docs/feedback/toast.md +393 -0
  104. package/docs/input/auto-complete.md +399 -0
  105. package/docs/input/cascader.md +1558 -0
  106. package/docs/input/checkbox.md +408 -0
  107. package/docs/input/color-picker.md +175 -0
  108. package/docs/input/date-picker.md +942 -0
  109. package/docs/input/form.md +2550 -0
  110. package/docs/input/input-number.md +451 -0
  111. package/docs/input/input.md +640 -0
  112. package/docs/input/pincode.md +191 -0
  113. package/docs/input/radio.md +337 -0
  114. package/docs/input/rating.md +214 -0
  115. package/docs/input/select.md +1230 -0
  116. package/docs/input/slider.md +347 -0
  117. package/docs/input/switch.md +206 -0
  118. package/docs/input/tag-input.md +465 -0
  119. package/docs/input/time-picker.md +358 -0
  120. package/docs/input/transfer.md +1061 -0
  121. package/docs/input/tree-select.md +1300 -0
  122. package/docs/input/upload.md +1811 -0
  123. package/docs/llms.txt +147 -0
  124. package/docs/navigation/anchor.md +377 -0
  125. package/docs/navigation/backtop.md +100 -0
  126. package/docs/navigation/breadcrumb.md +284 -0
  127. package/docs/navigation/navigation.md +851 -0
  128. package/docs/navigation/pagination.md +217 -0
  129. package/docs/navigation/steps.md +315 -0
  130. package/docs/navigation/tabs.md +754 -0
  131. package/docs/navigation/tree.md +1956 -0
  132. package/docs/other/config-provider.md +599 -0
  133. package/docs/other/locale.md +353 -0
  134. package/docs/plus/audio-player.md +155 -0
  135. package/docs/plus/code-highlight.md +150 -0
  136. package/docs/plus/drag-move.md +214 -0
  137. package/docs/plus/hot-keys.md +174 -0
  138. package/docs/plus/json-viewer.md +392 -0
  139. package/docs/plus/lottie.md +176 -0
  140. package/docs/plus/markdown-render.md +240 -0
  141. package/docs/plus/video-player.md +325 -0
  142. package/docs/show/avatar.md +475 -0
  143. package/docs/show/badge.md +276 -0
  144. package/docs/show/calendar.md +352 -0
  145. package/docs/show/card.md +485 -0
  146. package/docs/show/carousel.md +592 -0
  147. package/docs/show/collapse.md +289 -0
  148. package/docs/show/collapsible.md +216 -0
  149. package/docs/show/cropper.md +285 -0
  150. package/docs/show/descriptions.md +325 -0
  151. package/docs/show/dropdown.md +466 -0
  152. package/docs/show/empty.md +225 -0
  153. package/docs/show/highlight.md +144 -0
  154. package/docs/show/image.md +433 -0
  155. package/docs/show/list.md +927 -0
  156. package/docs/show/modal.md +517 -0
  157. package/docs/show/overflow-list.md +272 -0
  158. package/docs/show/popover.md +534 -0
  159. package/docs/show/scroll-list.md +156 -0
  160. package/docs/show/side-sheet.md +274 -0
  161. package/docs/show/table.md +5437 -0
  162. package/docs/show/tag.md +428 -0
  163. package/docs/show/timeline.md +277 -0
  164. package/docs/show/tooltip.md +442 -0
  165. package/docs/show/user-guide.md +419 -0
  166. package/docs/start/getting-started.md +234 -0
  167. package/docs/start/introduction.md +57 -0
  168. package/docs/start/overview.md +21 -0
  169. package/package.json +5 -4
@@ -0,0 +1,584 @@
1
+ # Resizable
2
+
3
+ > The component size is adjusted based on the user's mouse drag, supporting both resizing of a single component and combined resizing.
4
+
5
+ Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/basic/resizable/
6
+
7
+ ## Demos
8
+
9
+ ### How to import
10
+
11
+ ```svelte
12
+ <script lang="ts">
13
+ import { Resizable } from '@fibrae/semi-ui-svelte';
14
+ import { ResizeItem, ResizeHandler, ResizeGroup } from '@fibrae/semi-ui-svelte';
15
+ </script>
16
+ ```
17
+
18
+ ### Single Component
19
+
20
+ Basic Usage and Callbacks You can set the initial size using defaultSize, and set drag callbacks with `onResizeStart`, `onChange`, and `onResizeEnd`.
21
+
22
+ `onResizeStart`, `onChange` and `onResizeEnd` are all callback props, and returning `false` from `onResizeStart` cancels the resize; `style` only accepts a string.
23
+
24
+ ```tsx
25
+ interface Size {
26
+ width?: string | number;
27
+ height?: string | number;
28
+ }
29
+ ```
30
+
31
+ ```svelte
32
+ <script lang="ts">
33
+ import { Resizable, Toast } from '@fibrae/semi-ui-svelte';
34
+
35
+ const opts_1 = {
36
+ content: 'resize start',
37
+ duration: 1,
38
+ stack: true,
39
+ };
40
+ const opts_2 = {
41
+ content: 'resize end',
42
+ duration: 1,
43
+ stack: true,
44
+ };
45
+
46
+ let text = $state('Drag edge to resize');
47
+ </script>
48
+
49
+ <div style="width: 500px">
50
+ <Resizable
51
+ defaultSize={{ width: '60%', height: 300 }}
52
+ onChange={() => (text = 'resizing')}
53
+ onResizeEnd={() => {
54
+ Toast.info(opts_2);
55
+ text = 'Drag edge to resize';
56
+ }}
57
+ onResizeStart={() => {
58
+ Toast.info(opts_1);
59
+ }}
60
+ style="background-color: var(--semi-grey-1)"
61
+ >
62
+ <div style="margin-inline-start: 20%">{text}</div>
63
+ </Resizable>
64
+ </div>
65
+ ```
66
+
67
+ ### Controlling Resize Directions
68
+
69
+ You can enable or disable specific resizing directions by setting the value of enable. All directions are enabled by default. A direction that is left out counts as enabled, so to enable only some directions, set the others to `false` explicitly. Passing `false` for `enable` renders no handles.
70
+
71
+ ```tsx
72
+ interface Enable {
73
+ left?: boolean;
74
+ right?: boolean;
75
+ top?: boolean;
76
+ bottom?: boolean;
77
+ topLeft?: boolean;
78
+ topRight?: boolean;
79
+ bottomLeft?: boolean;
80
+ bottomRight?: boolean;
81
+ }
82
+ ```
83
+
84
+ ```svelte
85
+ <script lang="ts">
86
+ import { Resizable, Switch, Typography } from '@fibrae/semi-ui-svelte';
87
+
88
+ let enabled = $state(false);
89
+ </script>
90
+
91
+ <div style="width: 500px; height: 60%">
92
+ <div style="display: flex; align-items: center; margin: 8px">
93
+ <Switch aria-labelledby="resizable-enable-state" bind:checked={enabled} />
94
+ <Typography.Title heading={6} id="resizable-enable-state" style="margin: 8px">
95
+ {enabled ? 'able' : 'disable'}
96
+ </Typography.Title>
97
+ </div>
98
+ <Resizable defaultSize={{ width: 200, height: 200 }} enable={{ left: enabled }} style="background-color: var(--semi-grey-1)">
99
+ <div style="margin-inline-start: 20%">{'enable.left:' + enabled}</div>
100
+ </Resizable>
101
+ </div>
102
+ ```
103
+
104
+ ### Setting Resizing Ratio
105
+
106
+ You can set the drag and resize ratio using ratio.
107
+
108
+ ```svelte
109
+ <script lang="ts">
110
+ import { Resizable } from '@fibrae/semi-ui-svelte';
111
+ </script>
112
+
113
+ <div style="width: 500px; height: 60%">
114
+ <Resizable defaultSize={{ width: 200, height: 200 }} ratio={2} style="background-color: var(--semi-grey-1)">
115
+ <div style="margin-inline-start: 20%">ratio=2</div>
116
+ </Resizable>
117
+ </div>
118
+ ```
119
+
120
+ ### Locking Aspect Ratio
121
+
122
+ You can lock the aspect ratio by setting lockAspectRatio. It can be a boolean or a number. If true, it locks to the initial aspect ratio; if a number, it locks to the given ratio.
123
+
124
+ ```svelte
125
+ <script lang="ts">
126
+ import { Resizable } from '@fibrae/semi-ui-svelte';
127
+ </script>
128
+
129
+ <div style="width: 500px; height: 60%">
130
+ <Resizable defaultSize={{ width: 400, height: 300 }} lockAspectRatio style="background-color: var(--semi-grey-1); margin-block-end: 10px">
131
+ <div style="margin-inline-start: 20%">lock</div>
132
+ </Resizable>
133
+ <Resizable defaultSize={{ width: 200, height: (200 * 9) / 16 }} lockAspectRatio={16 / 9} style="background-color: var(--semi-grey-1)">
134
+ <div style="margin-inline-start: 20%">16 / 9</div>
135
+ </Resizable>
136
+ </div>
137
+ ```
138
+
139
+ ### Setting Maximum and Minimum Width/Height
140
+
141
+ You can set the maximum and minimum width and height using maxHeight, maxWidth, minHeight, and minWidth.
142
+
143
+ ```svelte
144
+ <script lang="ts">
145
+ import { Resizable } from '@fibrae/semi-ui-svelte';
146
+ </script>
147
+
148
+ <div style="width: 500px; height: 60%">
149
+ <Resizable defaultSize={{ width: 100, height: 100 }} maxHeight={300} maxWidth={200} minHeight={50} minWidth={50} style="background-color: var(--semi-grey-1)">
150
+ <div style="margin-inline-start: 20%">width在50到200之间,height在50到300之间</div>
151
+ </Resizable>
152
+ </div>
153
+ ```
154
+
155
+ ### Control Width/Height
156
+
157
+ You can control the size of the element through the size prop.
158
+
159
+ `size` is a one-way prop and cannot be bound with `bind:size`: while dragging, write the new size back in `onChange` to the state passed to `size`; otherwise the size stays at the value of `size`.
160
+
161
+ ```svelte
162
+ <script lang="ts">
163
+ import { Button, Resizable, type ResizableProps } from '@fibrae/semi-ui-svelte';
164
+
165
+ let size = $state<NonNullable<ResizableProps['size']>>({ width: 200, height: 100 });
166
+
167
+ const onButtonClick = () => {
168
+ size = { width: Number(size.width) + 10, height: Number(size.height) + 10 };
169
+ };
170
+ </script>
171
+
172
+ <div style="width: 500px; height: 60%">
173
+ <Button onclick={onButtonClick}>set += 10</Button>
174
+ <Resizable onChange={(next) => (size = next)} {size} style="background-color: var(--semi-grey-1); margin-block-start: 10px">
175
+ <div style="margin-inline-start: 20%">受控</div>
176
+ </Resizable>
177
+ </div>
178
+ ```
179
+
180
+ ### Setting Scale
181
+
182
+ You can scale the entire element by setting the scale prop.
183
+
184
+ ```svelte
185
+ <script lang="ts">
186
+ import { Resizable } from '@fibrae/semi-ui-svelte';
187
+ </script>
188
+
189
+ <div style="width: 500px; height: 60%; transform: scale(0.5); transform-origin: 0 0">
190
+ <Resizable defaultSize={{ width: '60%', height: '60%' }} scale={0.5} style="background-color: var(--semi-grey-1)">
191
+ <div style="margin-inline-start: 20%">scale 0.5</div>
192
+ </Resizable>
193
+ </div>
194
+ ```
195
+
196
+ ### Restricting Width/Height by an Element
197
+
198
+ You can restrict the width and height by setting the boundElement, which supports `'parent'`, `'window'` or an HTMLElement.
199
+
200
+ ```svelte
201
+ <script lang="ts">
202
+ import { Resizable } from '@fibrae/semi-ui-svelte';
203
+ </script>
204
+
205
+ <div style="width: 300px; height: 300px; border: var(--semi-color-border) 1px solid">
206
+ <Resizable boundElement="parent" defaultSize={{ width: '60%', height: 200 }} style="margin-inline-start: 20%; background-color: var(--semi-grey-1)">
207
+ <div style="margin-inline-start: 20%">bound:parent</div>
208
+ </Resizable>
209
+ </div>
210
+ ```
211
+
212
+ ### Customizing Corner Handler Styles
213
+
214
+ You can customize the drag handle content for each direction with the `handle` snippet. It renders once for each enabled direction, and its argument `{ direction }` is that handle's direction, so render the content for the direction you want. A direction that renders nothing keeps its handle element. Apply different styles with handleStyle and handleClass; the style values are strings.
215
+
216
+ ```ts
217
+ type HandleStyle = {
218
+ left?: string;
219
+ right?: string;
220
+ top?: string;
221
+ bottom?: string;
222
+ topLeft?: string;
223
+ topRight?: string;
224
+ bottomLeft?: string;
225
+ bottomRight?: string;
226
+ };
227
+
228
+ type HandleClass = {
229
+ left?: string;
230
+ right?: string;
231
+ top?: string;
232
+ bottom?: string;
233
+ topLeft?: string;
234
+ topRight?: string;
235
+ bottomLeft?: string;
236
+ bottomRight?: string;
237
+ };
238
+ ```
239
+
240
+ ```svelte
241
+ <script lang="ts">
242
+ import { IconTransfer } from '@fibrae/semi-icons-svelte/lab';
243
+ import { Resizable } from '@fibrae/semi-ui-svelte';
244
+ </script>
245
+
246
+ <div style="width: 500px; height: 60%">
247
+ <Resizable defaultSize={{ width: '60%', height: 300 }} style="margin-inline-start: 20%; background-color: var(--semi-grey-1); border: var(--semi-color-border) 1px solid">
248
+ <div style="margin-inline-start: 20%">right</div>
249
+ {#snippet handle({ direction })}
250
+ {#if direction === 'right'}
251
+ <div style="height: 100%; display: flex; align-items: center; width: fit-content">
252
+ <IconTransfer />
253
+ </div>
254
+ {/if}
255
+ {/snippet}
256
+ </Resizable>
257
+ </div>
258
+ ```
259
+
260
+ ### Allowing Incremental Width and Height Adjustment
261
+
262
+ You can allow gradual adjustments in width and height using the grid and snap properties. The grid property specifies the increments to which resizing should snap. The default value is \[1, 1]. The snap property specifies the absolute pixel values to which resizing should snap. Both x and y are optional, allowing you to define only the desired axis. These two parameters can be combined with the snapGap property, which specifies the minimum gap required to move to the next target. The default is 0, meaning the target defined by grid/snap is always used.
263
+
264
+ ```tsx
265
+ interface Snap {
266
+ x?: number[];
267
+ y?: number[];
268
+ }
269
+ ```
270
+
271
+ ```svelte
272
+ <script lang="ts">
273
+ import { Resizable } from '@fibrae/semi-ui-svelte';
274
+ </script>
275
+
276
+ <div style="width: 500px; height: 60%">
277
+ <Resizable defaultSize={{ width: '60%', height: 300 }} grid={[100, 100]} snapGap={20} style="margin-inline-start: 20%; background-color: var(--semi-grey-1); border: var(--semi-color-border) 1px solid">
278
+ <div style="margin-inline-start: 20%">snap</div>
279
+ </Resizable>
280
+ </div>
281
+ ```
282
+
283
+ ### Group Component
284
+
285
+ > **notice**
286
+ >
287
+ > The parent element of `ResizeGroup` needs to have a size in the main axis direction.
288
+ >
289
+ > It's best not to set padding for ResizeItem, as it may cause the minimum size to not match the expected value. You can set padding for child elements instead.
290
+ >
291
+ > `ResizeItem` and `ResizeHandler` must be placed inside a `ResizeGroup`; using them outside one throws an error.
292
+
293
+ Use the direction prop to set the resizing direction. Options are `horizontal` and `vertical`, defaulting to `horizontal`. Supports `onResizeStart`, `onChange`, and `onResizeEnd` callbacks, as well as setting `min` and `max` to control the maximum and minimum width/height.
294
+
295
+ `onResizeStart`, `onChange` and `onResizeEnd` of `ResizeItem` are callback props as well.
296
+
297
+ ```svelte
298
+ <script lang="ts">
299
+ import { ResizeGroup, ResizeHandler, ResizeItem } from '@fibrae/semi-ui-svelte';
300
+
301
+ const itemStyle = 'background-color: var(--semi-grey-1); border: var(--semi-color-border) 1px solid';
302
+
303
+ let text = $state('Drag to resize');
304
+ </script>
305
+
306
+ <div style="width: 1000px; height: 100px">
307
+ <ResizeGroup direction="horizontal">
308
+ <ResizeItem defaultSize="400px" min="10%" onChange={() => (text = 'resizing')} onResizeEnd={() => (text = 'Drag to resize')} style={itemStyle}>
309
+ <div style="margin-inline-start: 20%">{text + ' min:10%'}</div>
310
+ </ResizeItem>
311
+ <ResizeHandler />
312
+ <ResizeItem defaultSize="20%" max="30%" min="10%" onChange={() => (text = 'resizing')} style={itemStyle}>
313
+ <div style="margin-inline-start: 20%">{text + ' min:10% max:30%'}</div>
314
+ </ResizeItem>
315
+ <ResizeHandler />
316
+ <ResizeItem defaultSize="0.5" onChange={() => (text = 'resizing')} style={itemStyle}>
317
+ <div style="margin-inline-start: 20%">{text}</div>
318
+ </ResizeItem>
319
+ <ResizeHandler />
320
+ <ResizeItem defaultSize={1} onChange={() => (text = 'resizing')} style={itemStyle}>
321
+ <div style="margin-inline-start: 20%">{text}</div>
322
+ </ResizeItem>
323
+ </ResizeGroup>
324
+ </div>
325
+ ```
326
+
327
+ ### Nested
328
+
329
+ Set the resizing direction using the direction prop. Options are horizontal and vertical.
330
+
331
+ ```svelte
332
+ <script lang="ts">
333
+ import { ResizeGroup, ResizeHandler, ResizeItem, Toast } from '@fibrae/semi-ui-svelte';
334
+
335
+ const opts_1 = {
336
+ content: 'resize start',
337
+ duration: 1,
338
+ stack: true,
339
+ };
340
+ const opts = {
341
+ content: 'resize end',
342
+ duration: 1,
343
+ stack: true,
344
+ };
345
+ const itemStyle = 'background-color: var(--semi-grey-1); border: var(--semi-color-border) 1px solid';
346
+
347
+ let text = $state('Drag to resize');
348
+ </script>
349
+
350
+ <div style="width: 1000px; height: 600px">
351
+ <ResizeGroup direction="vertical">
352
+ <ResizeItem
353
+ defaultSize="20%"
354
+ onChange={() => (text = 'resizing')}
355
+ onResizeEnd={() => {
356
+ Toast.info(opts);
357
+ text = 'Drag to resize';
358
+ }}
359
+ onResizeStart={() => {
360
+ Toast.info(opts_1);
361
+ }}
362
+ style="background-color: var(--semi-grey-1)"
363
+ >
364
+ <div style="margin-inline-start: 20%">header</div>
365
+ </ResizeItem>
366
+ <ResizeHandler />
367
+ <ResizeItem defaultSize="80%" onChange={() => (text = 'resizing')}>
368
+ <ResizeGroup direction="horizontal">
369
+ <ResizeItem
370
+ defaultSize="25%"
371
+ onChange={() => (text = 'resizing')}
372
+ onResizeEnd={() => {
373
+ Toast.info(opts);
374
+ text = 'Drag to resize';
375
+ }}
376
+ onResizeStart={() => {
377
+ Toast.info(opts_1);
378
+ }}
379
+ style={itemStyle}
380
+ >
381
+ <div style="margin-inline-start: 20%">tab</div>
382
+ </ResizeItem>
383
+ <ResizeHandler />
384
+ <ResizeItem defaultSize="75%" onChange={() => (text = 'resizing')} style={itemStyle}>
385
+ <div style="margin-inline-start: 20%">{text}</div>
386
+ </ResizeItem>
387
+ </ResizeGroup>
388
+ </ResizeItem>
389
+ </ResizeGroup>
390
+ </div>
391
+ ```
392
+
393
+ ```svelte
394
+ <script lang="ts">
395
+ import { ResizeGroup, ResizeHandler, ResizeItem } from '@fibrae/semi-ui-svelte';
396
+
397
+ const itemStyle = 'background-color: var(--semi-grey-1); border: var(--semi-color-border) 1px solid';
398
+ const borderStyle = 'border: var(--semi-color-border) 1px solid';
399
+
400
+ let text = $state('Drag to resize');
401
+ </script>
402
+
403
+ <div style="width: 1000px; height: 600px">
404
+ <ResizeGroup direction="vertical">
405
+ <ResizeItem defaultSize="80%">
406
+ <ResizeGroup direction="horizontal">
407
+ <ResizeItem defaultSize="25%" max="30%" min="10%" style={itemStyle}>
408
+ <div style="margin-inline-start: 20%">{text + ' min:10% max:30%'}</div>
409
+ </ResizeItem>
410
+ <ResizeHandler />
411
+ <ResizeItem defaultSize="50%" style={borderStyle}>
412
+ <div style="height: 100%">
413
+ <ResizeGroup direction="vertical">
414
+ <ResizeItem defaultSize="33%" min="10%" onChange={() => (text = 'resizing')} onResizeEnd={() => (text = 'Drag to resize')} style={itemStyle}>
415
+ <div style="margin-inline-start: 20%">{text + ' min:10%'}</div>
416
+ </ResizeItem>
417
+ <ResizeHandler />
418
+ <ResizeItem defaultSize="33%" max="40%" min="10%" style={itemStyle}>
419
+ <div style="margin-inline-start: 20%">{text + ' min:10% max:40%'}</div>
420
+ </ResizeItem>
421
+ <ResizeHandler />
422
+ <ResizeItem style={itemStyle}>
423
+ <div style="margin-inline-start: 20%">{text}</div>
424
+ </ResizeItem>
425
+ </ResizeGroup>
426
+ </div>
427
+ </ResizeItem>
428
+ <ResizeHandler />
429
+ <ResizeItem defaultSize="1" max="30%" style={itemStyle}>
430
+ <div style="margin-inline-start: 20%">{text + ' max:30%'}</div>
431
+ </ResizeItem>
432
+ </ResizeGroup>
433
+ </ResizeItem>
434
+ <ResizeHandler />
435
+ <ResizeItem defaultSize="20%" onChange={() => (text = 'resizing')}>
436
+ <ResizeGroup direction="horizontal">
437
+ <ResizeItem defaultSize="50%" style={itemStyle}>
438
+ <div style="margin-inline-start: 20%">tab</div>
439
+ </ResizeItem>
440
+ <ResizeHandler />
441
+ <ResizeItem defaultSize="50%" style={itemStyle}>
442
+ <div style="margin-inline-start: 20%">content</div>
443
+ </ResizeItem>
444
+ </ResizeGroup>
445
+ </ResizeItem>
446
+ </ResizeGroup>
447
+ </div>
448
+ ```
449
+
450
+ ### Dynamic Direction
451
+
452
+ ```svelte
453
+ <script lang="ts">
454
+ import { Button, ResizeGroup, ResizeHandler, ResizeItem } from '@fibrae/semi-ui-svelte';
455
+
456
+ const itemStyle = 'background-color: var(--semi-grey-1)';
457
+ const contentStyle = 'margin-inline-start: 20%; padding: 5px';
458
+
459
+ let text = $state('drag to resize');
460
+ let direction = $state<'horizontal' | 'vertical'>('horizontal');
461
+
462
+ const changeDirection = () => {
463
+ direction = direction === 'horizontal' ? 'vertical' : 'horizontal';
464
+ };
465
+ </script>
466
+
467
+ <div style="width: 400px; height: 300px">
468
+ <Button onclick={changeDirection}>{direction}</Button>
469
+ <ResizeGroup {direction}>
470
+ <ResizeItem defaultSize={5} onChange={() => (text = 'resizing')} onResizeEnd={() => (text = 'drag to resize')}>
471
+ <ResizeGroup direction="horizontal">
472
+ <ResizeItem onChange={() => (text = 'resizing')} onResizeEnd={() => (text = 'drag to resize')} style={itemStyle}>
473
+ <div style={contentStyle}>{text}</div>
474
+ </ResizeItem>
475
+ <ResizeHandler />
476
+ <ResizeItem onChange={() => (text = 'resizing')} style={itemStyle}>
477
+ <div style={contentStyle}>{text}</div>
478
+ </ResizeItem>
479
+ </ResizeGroup>
480
+ </ResizeItem>
481
+ <ResizeHandler />
482
+ <ResizeItem defaultSize={1.3} onChange={() => (text = 'resizing')} style={itemStyle}>
483
+ <div style={contentStyle}>{text}</div>
484
+ </ResizeItem>
485
+ </ResizeGroup>
486
+ </div>
487
+ ```
488
+
489
+ ## API
490
+
491
+ ### Resizable
492
+
493
+ A single resizable box.
494
+
495
+ **Props**
496
+
497
+ | Property | Description | Type | Default |
498
+ | - | - | - | - |
499
+ | boundElement | Element that bounds the size: 'parent', 'window' or an HTMLElement. | `'parent' \| 'window' \| HTMLElement` | - |
500
+ | boundsByDirection | Whether bounds are computed by drag direction. When true, dragging from a left or top handle limits the size by the distance from the side that stays put to the opposite edge of the bound element. | `boolean` | - |
501
+ | children | Content of the resizable box. | `Snippet` | - |
502
+ | defaultSize | Initial width and height, as a number or a string (px/vw/vh/%). It is also the fallback of an axis that `size` leaves unset. | `Size` | - |
503
+ | enable | Directions that can be resized. A direction not set to false is enabled; false renders no handles. | `Enable \| false` | `{ top: true, right: true, bottom: true, left: true, topRight: true, bottomRight: true, bottomLeft: true, topLeft: true }` |
504
+ | grid | Increment that resizing snaps to. | `[number, number]` | `[1, 1]` |
505
+ | handle | Snippet for the content of the handle in each enabled direction. It renders once per enabled direction, with `{ direction }` set to that handle's direction. | `Snippet<[ResizableHandleSnippetProps]>` | - |
506
+ | handleClass | Class names of the handle in each direction. | `HandleClassName` | - |
507
+ | handleStyle | Styles of the handle in each direction, as style strings. | `HandleStyle` | - |
508
+ | handleWrapperClass | Class name of the element that wraps all handles. | `string` | - |
509
+ | handleWrapperStyle | Style string of the element that wraps all handles. | `string` | - |
510
+ | lockAspectRatio | Locks the aspect ratio: true keeps the initial one, a number is the width to height ratio. | `boolean \| number` | `false` |
511
+ | lockAspectRatioExtraHeight | Extra height in pixels (such as padding) left out of the ratio when the aspect ratio is locked. | `number` | `0` |
512
+ | lockAspectRatioExtraWidth | Extra width in pixels (such as padding) left out of the ratio when the aspect ratio is locked. | `number` | `0` |
513
+ | maxHeight | Maximum height. | `string \| number` | - |
514
+ | maxWidth | Maximum width. | `string \| number` | - |
515
+ | minHeight | Minimum height. | `string \| number` | - |
516
+ | minWidth | Minimum width. | `string \| number` | - |
517
+ | onChange | Called when a drag or arrow key changes the size, with the new size, the event and the direction. | `ResizeCallback` | - |
518
+ | onResizeEnd | Called when resizing ends, with the final size, the event and the direction. | `ResizeCallback` | - |
519
+ | onResizeStart | Called when resizing starts. Return false to cancel. | `ResizeStartCallback` | - |
520
+ | ratio | Ratio of pointer movement to size change; pass \[width, height] for per-axis ratios. Arrow keys always change the size by 10px, regardless of ratio and scale. | `number \| [number, number]` | `1` |
521
+ | scale | Scale applied to the element from outside, used to correct the pointer movement. | `number` | `1` |
522
+ | size | Controlled size, applied per axis: an axis left unset follows the drag. A one-way prop that cannot be bound with `bind:size`: write the new size back in `onChange`. | `Size` | - |
523
+ | snap | Absolute pixel values that resizing snaps to. Both x and y are optional. | `{ x?: number[]; y?: number[] }` | - |
524
+ | snapGap | Minimum gap required to move to the next snap target. | `number` | `0` |
525
+
526
+ `class`, `style` (a string) and native attributes land on the root element. The root `style` is applied before the size the component computes, so a `width` or `height` you pass does not freeze the drag.
527
+
528
+ ### ResizeGroup
529
+
530
+ **Props**
531
+
532
+ | Property | Description | Type | Default |
533
+ | - | - | - | - |
534
+ | children | ResizeItem and ResizeHandler children, which register themselves with the group once mounted. | `Snippet` | - |
535
+ | direction | Resize direction within the group: horizontal lays items side by side, vertical stacks them. | `'horizontal' \| 'vertical'` | `"horizontal"` |
536
+
537
+ `class`, `style` (a string) and native attributes land on the root element. `flex-direction` is always decided by `direction`.
538
+
539
+ ### ResizeHandler
540
+
541
+ **Props**
542
+
543
+ | Property | Description | Type | Default |
544
+ | - | - | - | - |
545
+ | children | Replaces the default grip icon. | `Snippet` | - |
546
+
547
+ `class`, `style` (a string) and native attributes land on the handle element; an `aria-label` you pass overrides the locale name.
548
+
549
+ ### ResizeItem
550
+
551
+ **Props**
552
+
553
+ | Property | Description | Type | Default |
554
+ | - | - | - | - |
555
+ | children | Content of the item. | `Snippet` | - |
556
+ | defaultSize | Initial size. A string supports %, px, vw and vh; a number or numeric string takes a proportional share of the remaining space. | `string \| number` | - |
557
+ | max | Maximum size (%, px, vw or vh). | `string` | - |
558
+ | min | Minimum size (%, px, vw or vh). | `string` | - |
559
+ | onChange | Called when a drag or arrow key changes the size, with the new size, the event and the direction. | `ResizeCallback` | - |
560
+ | onResizeEnd | Called when resizing ends, with the final size, the event and the direction. | `ResizeCallback` | - |
561
+ | onResizeStart | Called when resizing starts. If the item on either side of the handler returns false, the resize is cancelled. | `ResizeStartCallback` | - |
562
+
563
+ `class`, `style` and native attributes land on the root element. ResizeGroup writes the size straight onto the element's `style.width` and `style.height`, and a Svelte `style` can only be a string, which is written again whole when it changes and drops the size, so keep `style` a constant value.
564
+
565
+ ## Accessibility
566
+
567
+ - Each axis of a single resizable box has one focusable `separator` handle: the right and bottom handles always are; when the right or bottom side is turned off in `enable`, the left or top handle takes over that axis. They are named from the locale pack and adjust the width and the height. Arrow keys change the size by a fixed 10px per press, regardless of `ratio` and `scale`, and are ignored while Alt, Ctrl or Meta is held. Pressing a handle with the right or middle mouse button does not start a resize.
568
+ - `ResizeHandler` is a focusable `separator`. Its name also comes from the locale pack, and an `aria-label` you pass overrides it. Arrow keys along the group's direction move the items on either side of it by 1% of the group per press, or 10% with Shift; `Home` and `End` take the item before it to its smallest and largest size.
569
+ - The root elements of `Resizable`, `ResizeGroup` and `ResizeItem` carry no semantics. When you pass `aria-label` or `aria-labelledby`, the root gets `role="group"`.
570
+
571
+ ## Design Tokens
572
+
573
+ The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/basic/resizable/>
574
+
575
+ ## Changes from Semi Design
576
+
577
+ From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
578
+
579
+ - 破坏性(类型):`onResizeStart`、`onChange`、`onResizeEnd` 的事件统一为 `PointerEvent`,键盘缩放时为 `KeyboardEvent`,读 `clientX` 等需先判断类型;`HandlerCallback` 改为 `PointerEvent`,删除 `ResizeEventType`、`ResizableState`、`ResizeGroupState`。
580
+ - 拖拽条为 `role="separator"` 和 Tab 停靠点,方向键调整大小;ResizeItem 的 `min`、`max` 统一按 border-box px 计算,支持 `vw`、`vh`(`rem`、`em` 仍得 NaN);`onResizeStart` 任一侧返回 `false` 取消调整;`size` 只传一个轴时另一轴用 `defaultSize`;ResizeGroup 中途插入的 ResizeItem、ResizeHandler 按 DOM 顺序参与拖动与键盘调整。
581
+ - Svelte:`children` 与 `handle` snippet 对应 Vue 的默认插槽与 `handle` 插槽,`handle` 的参数是 `{ direction }`;回调为 `onChange`、`onResizeEnd`;`style`、`handleStyle` 只接受字符串;`size` 是单向 prop(按轴受控),不能 `bind:size`,`defaultSize` 保留为各轴的回退值。
582
+ - 受控 `size` 拖动时立即显示 `onChange` 中同步写回的尺寸,不落后一次指针移动(四个框架)。
583
+ - ResizeGroup 不卸载、只移除正在拖动的 ResizeHandler 时结束这次拖动,透明背景层随之移除,不再挡住页面;这次拖动不调用 `onResizeEnd`(四个框架)。
584
+ - `snap.x` 或 `snap.y` 为空数组时按没有吸附点处理;原来 `snapGap` 为 0 时尺寸变成 `undefined`。