@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.
- package/README.md +8 -4
- package/README.zh-CN.md +8 -4
- package/dist/components/anchor/interface.d.ts +14 -0
- package/dist/components/audio-player/interface.d.ts +5 -0
- package/dist/components/auto-complete/interface.d.ts +29 -0
- package/dist/components/avatar/interface.d.ts +24 -0
- package/dist/components/backtop/interface.d.ts +2 -0
- package/dist/components/badge/interface.d.ts +7 -0
- package/dist/components/banner/interface.d.ts +7 -0
- package/dist/components/breadcrumb/interface.d.ts +10 -0
- package/dist/components/button/interface.d.ts +18 -0
- package/dist/components/calendar/interface.d.ts +16 -0
- package/dist/components/card/interface.d.ts +18 -0
- package/dist/components/carousel/interface.d.ts +16 -0
- package/dist/components/cascader/cascader.svelte +1 -0
- package/dist/components/cascader/interface.d.ts +57 -0
- package/dist/components/checkbox/interface.d.ts +19 -0
- package/dist/components/code-highlight/interface.d.ts +3 -0
- package/dist/components/collapse/interface.d.ts +16 -0
- package/dist/components/collapsible/interface.d.ts +10 -0
- package/dist/components/color-picker/interface.d.ts +10 -0
- package/dist/components/config-provider/interface.d.ts +7 -0
- package/dist/components/cropper/interface.d.ts +11 -0
- package/dist/components/date-picker/interface.d.ts +47 -0
- package/dist/components/descriptions/interface.d.ts +6 -0
- package/dist/components/divider/interface.d.ts +4 -0
- package/dist/components/dropdown/interface.d.ts +8 -0
- package/dist/components/empty/interface.d.ts +7 -0
- package/dist/components/feedback/interface.d.ts +16 -0
- package/dist/components/float-button/interface.d.ts +14 -0
- package/dist/components/form/interface.d.ts +47 -0
- package/dist/components/form/label.svelte +2 -2
- package/dist/components/grid/interface.d.ts +13 -0
- package/dist/components/highlight/interface.d.ts +7 -0
- package/dist/components/hot-keys/interface.d.ts +3 -0
- package/dist/components/image/interface.d.ts +59 -0
- package/dist/components/input/interface.d.ts +67 -0
- package/dist/components/input-number/interface.d.ts +24 -0
- package/dist/components/json-viewer/interface.d.ts +7 -0
- package/dist/components/layout/interface.d.ts +3 -0
- package/dist/components/list/interface.d.ts +18 -0
- package/dist/components/locale/interface.d.ts +4 -0
- package/dist/components/lottie/interface.d.ts +2 -0
- package/dist/components/markdown-render/interface.d.ts +5 -0
- package/dist/components/modal/interface.d.ts +29 -0
- package/dist/components/navigation/interface.d.ts +47 -0
- package/dist/components/overflow-list/interface.d.ts +11 -0
- package/dist/components/pagination/interface.d.ts +12 -0
- package/dist/components/pincode/interface.d.ts +8 -0
- package/dist/components/popconfirm/interface.d.ts +12 -0
- package/dist/components/popover/interface.d.ts +30 -0
- package/dist/components/progress/interface.d.ts +13 -0
- package/dist/components/radio/interface.d.ts +22 -0
- package/dist/components/rating/interface.d.ts +12 -0
- package/dist/components/resizable/interface.d.ts +30 -0
- package/dist/components/scroll-list/interface.d.ts +6 -0
- package/dist/components/select/interface.d.ts +63 -0
- package/dist/components/side-sheet/interface.d.ts +19 -0
- package/dist/components/skeleton/interface.d.ts +7 -0
- package/dist/components/slider/interface.d.ts +23 -0
- package/dist/components/space/interface.d.ts +4 -0
- package/dist/components/spin/interface.d.ts +7 -0
- package/dist/components/steps/interface.d.ts +9 -0
- package/dist/components/switch/interface.d.ts +7 -0
- package/dist/components/table/interface.d.ts +48 -0
- package/dist/components/tabs/interface.d.ts +29 -0
- package/dist/components/tag/interface.d.ts +22 -0
- package/dist/components/tag-input/interface.d.ts +29 -0
- package/dist/components/time-picker/interface.d.ts +31 -0
- package/dist/components/timeline/interface.d.ts +5 -0
- package/dist/components/tooltip/interface.d.ts +20 -0
- package/dist/components/tooltip/tooltip.svelte +3 -0
- package/dist/components/transfer/interface.d.ts +18 -0
- package/dist/components/tree/interface.d.ts +45 -0
- package/dist/components/tree-select/interface.d.ts +55 -0
- package/dist/components/typography/interface.d.ts +33 -0
- package/dist/components/upload/interface.d.ts +64 -0
- package/dist/components/user-guide/interface.d.ts +15 -0
- package/dist/components/video-player/interface.d.ts +22 -0
- package/dist/styles.css +1 -1
- package/docs/advanced/dark-mode.md +288 -0
- package/docs/basic/button.md +605 -0
- package/docs/basic/divider.md +103 -0
- package/docs/basic/float-button.md +246 -0
- package/docs/basic/grid.md +427 -0
- package/docs/basic/layout.md +459 -0
- package/docs/basic/resizable.md +584 -0
- package/docs/basic/space.md +163 -0
- package/docs/basic/tokens.md +425 -0
- package/docs/basic/typography.md +615 -0
- package/docs/changes-from-semi.md +105 -0
- package/docs/ecosystem/tailwind.md +210 -0
- package/docs/experience/accessibility.md +82 -0
- package/docs/experience/content-guidelines.md +819 -0
- package/docs/experience/internationalization.md +7 -0
- package/docs/feedback/banner.md +198 -0
- package/docs/feedback/feedback.md +294 -0
- package/docs/feedback/notification.md +401 -0
- package/docs/feedback/popconfirm.md +243 -0
- package/docs/feedback/progress.md +389 -0
- package/docs/feedback/skeleton.md +388 -0
- package/docs/feedback/spin.md +172 -0
- package/docs/feedback/toast.md +393 -0
- package/docs/input/auto-complete.md +399 -0
- package/docs/input/cascader.md +1558 -0
- package/docs/input/checkbox.md +408 -0
- package/docs/input/color-picker.md +175 -0
- package/docs/input/date-picker.md +942 -0
- package/docs/input/form.md +2550 -0
- package/docs/input/input-number.md +451 -0
- package/docs/input/input.md +640 -0
- package/docs/input/pincode.md +191 -0
- package/docs/input/radio.md +337 -0
- package/docs/input/rating.md +214 -0
- package/docs/input/select.md +1230 -0
- package/docs/input/slider.md +347 -0
- package/docs/input/switch.md +206 -0
- package/docs/input/tag-input.md +465 -0
- package/docs/input/time-picker.md +358 -0
- package/docs/input/transfer.md +1061 -0
- package/docs/input/tree-select.md +1300 -0
- package/docs/input/upload.md +1811 -0
- package/docs/llms.txt +147 -0
- package/docs/navigation/anchor.md +377 -0
- package/docs/navigation/backtop.md +100 -0
- package/docs/navigation/breadcrumb.md +284 -0
- package/docs/navigation/navigation.md +851 -0
- package/docs/navigation/pagination.md +217 -0
- package/docs/navigation/steps.md +315 -0
- package/docs/navigation/tabs.md +754 -0
- package/docs/navigation/tree.md +1956 -0
- package/docs/other/config-provider.md +599 -0
- package/docs/other/locale.md +353 -0
- package/docs/plus/audio-player.md +155 -0
- package/docs/plus/code-highlight.md +150 -0
- package/docs/plus/drag-move.md +214 -0
- package/docs/plus/hot-keys.md +174 -0
- package/docs/plus/json-viewer.md +392 -0
- package/docs/plus/lottie.md +176 -0
- package/docs/plus/markdown-render.md +240 -0
- package/docs/plus/video-player.md +325 -0
- package/docs/show/avatar.md +475 -0
- package/docs/show/badge.md +276 -0
- package/docs/show/calendar.md +352 -0
- package/docs/show/card.md +485 -0
- package/docs/show/carousel.md +592 -0
- package/docs/show/collapse.md +289 -0
- package/docs/show/collapsible.md +216 -0
- package/docs/show/cropper.md +285 -0
- package/docs/show/descriptions.md +325 -0
- package/docs/show/dropdown.md +466 -0
- package/docs/show/empty.md +225 -0
- package/docs/show/highlight.md +144 -0
- package/docs/show/image.md +433 -0
- package/docs/show/list.md +927 -0
- package/docs/show/modal.md +517 -0
- package/docs/show/overflow-list.md +272 -0
- package/docs/show/popover.md +534 -0
- package/docs/show/scroll-list.md +156 -0
- package/docs/show/side-sheet.md +274 -0
- package/docs/show/table.md +5437 -0
- package/docs/show/tag.md +428 -0
- package/docs/show/timeline.md +277 -0
- package/docs/show/tooltip.md +442 -0
- package/docs/show/user-guide.md +419 -0
- package/docs/start/getting-started.md +234 -0
- package/docs/start/introduction.md +57 -0
- package/docs/start/overview.md +21 -0
- package/package.json +5 -4
|
@@ -0,0 +1,1061 @@
|
|
|
1
|
+
# Transfer
|
|
2
|
+
|
|
3
|
+
> A more intuitive and efficient multiple-selection selector, which can reveal more information about options, and supports search functions. The disadvantage is that it takes up more space
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/input/transfer/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Transfer } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic Usage
|
|
18
|
+
|
|
19
|
+
dataSource should have value、label、key.
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import { Transfer, type TransferDataItem, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
24
|
+
|
|
25
|
+
const data = Array.from({ length: 100 }, (_v, i) => ({
|
|
26
|
+
label: `选项名称 ${i}`,
|
|
27
|
+
value: i,
|
|
28
|
+
disabled: false,
|
|
29
|
+
key: `key-${i}`,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const onChange = (values: TransferValue, items: TransferDataItem[]) => console.log(values, items);
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<Transfer dataSource={data} {onChange} style="width: 568px; height: 416px" />
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Grouped
|
|
39
|
+
|
|
40
|
+
Set type to `groupList`
|
|
41
|
+
|
|
42
|
+
For grouped dataSource, the first-level child elements must have title and children attributes, structure reference \<GroupItem>
|
|
43
|
+
|
|
44
|
+
Does not support multi-level nesting
|
|
45
|
+
|
|
46
|
+
```svelte
|
|
47
|
+
<script lang="ts">
|
|
48
|
+
import { Transfer } from '@fibrae/semi-ui-svelte';
|
|
49
|
+
|
|
50
|
+
const dataWithGroup = [
|
|
51
|
+
{
|
|
52
|
+
title: '类别A',
|
|
53
|
+
children: [
|
|
54
|
+
{ label: 'A-1', value: 1, disabled: false, key: 1 },
|
|
55
|
+
{ label: 'A-2', value: 2, disabled: false, key: 2 },
|
|
56
|
+
{ label: 'A-3', value: 3, disabled: false, key: 3 },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
title: '类别B',
|
|
61
|
+
children: [
|
|
62
|
+
{ label: 'B-1', value: 4, disabled: false, key: 4 },
|
|
63
|
+
{ label: 'B-2', value: 5, disabled: false, key: 5 },
|
|
64
|
+
{ label: 'B-3(disabled)', value: 6, disabled: true, key: 6 },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
title: '类别C',
|
|
69
|
+
children: [
|
|
70
|
+
{ label: 'C-1', value: 7, disabled: false, key: 7 },
|
|
71
|
+
{ label: 'C-2', value: 8, disabled: false, key: 8 },
|
|
72
|
+
{ label: 'C-3', value: 9, disabled: false, key: 9 },
|
|
73
|
+
{ label: 'C-4', value: 10, disabled: false, key: 10 },
|
|
74
|
+
{ label: 'C-5', value: 11, disabled: false, key: 11 },
|
|
75
|
+
{ label: 'C-6', value: 12, disabled: false, key: 12 },
|
|
76
|
+
{ label: 'C-7', value: 13, disabled: false, key: 13 },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<Transfer dataSource={dataWithGroup} onChange={(values, items) => console.log(values, items)} style="width: 568px" type="groupList" value={[6]} />
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Custom filtering logic, custom option data rendering
|
|
86
|
+
|
|
87
|
+
Use `filter` to customize the search logic. When it returns true, it means that the current item meets the filter rules and keeps the display of the current item in the list. If it returns false, it means it does not match, and the current item will be hidden.\
|
|
88
|
+
When type is `treeList`, if you need to customize search logic, you need to set `filter` to true and set a custom search function through `filterTreeNode` of `treeProps`.
|
|
89
|
+
|
|
90
|
+
Using the `sourceItem` snippet, you can customize the rendering structure of each source data on the left.\
|
|
91
|
+
Using the `selectedItem` snippet you can customize the rendering structure of each selected item on the right.\
|
|
92
|
+
The custom fields of an item (such as `abbr` and `color` in the demo) are all on the `item` snippet parameter. To replace only the text of the rows, the `label` snippet is simpler: it applies to the source row, the selected row and the drag copy.
|
|
93
|
+
|
|
94
|
+
```svelte
|
|
95
|
+
<script lang="ts">
|
|
96
|
+
import { IconClose } from '@fibrae/semi-icons-svelte';
|
|
97
|
+
import { Avatar, Button, Checkbox, Highlight, Transfer, type AvatarColor, type TransferDataItem, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
98
|
+
|
|
99
|
+
interface Person extends TransferDataItem {
|
|
100
|
+
abbr: string;
|
|
101
|
+
color: AvatarColor;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let searchText = $state('');
|
|
105
|
+
|
|
106
|
+
const customFilter = (searchValue: string, item: TransferDataItem) => String(item.value).includes(searchValue) || String(item.label).includes(searchValue);
|
|
107
|
+
|
|
108
|
+
const data = [
|
|
109
|
+
{ label: '夏可漫', value: 'xiakeman@example.com', abbr: '夏', color: 'amber', area: 'US', key: 1 },
|
|
110
|
+
{ label: '申悦', value: 'shenyue@example.com', abbr: '申', color: 'indigo', area: 'UK', key: 2 },
|
|
111
|
+
{ label: '文嘉茂', value: 'wenjiamao@example.com', abbr: '文', color: 'cyan', area: 'HK', key: 3 },
|
|
112
|
+
{ label: '曲晨一', value: 'quchenyi@example.com', abbr: '曲', color: 'blue', area: 'India', key: 4 },
|
|
113
|
+
{ label: '曲晨二', value: 'quchener@example.com', abbr: '二', color: 'blue', area: 'India', key: 5 },
|
|
114
|
+
{ label: '曲晨三', value: 'quchensan@example.com', abbr: '三', color: 'blue', area: 'India', key: 6 },
|
|
115
|
+
] satisfies Person[];
|
|
116
|
+
|
|
117
|
+
const inputProps = { placeholder: '搜索姓名或邮箱' };
|
|
118
|
+
|
|
119
|
+
const onChange = (values: TransferValue, items: TransferDataItem[]) => console.log(values, items);
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<Transfer dataSource={data} filter={customFilter} {inputProps} {onChange} onSearch={(value) => (searchText = value)} style="width: 568px" value={['xiakeman@example.com', 'shenyue@example.com']}>
|
|
123
|
+
{#snippet sourceItem(source)}
|
|
124
|
+
{@const person = source.item as Person}
|
|
125
|
+
<div class="components-transfer-demo-source-item">
|
|
126
|
+
<Checkbox checked={source.checked} onChange={source.onChange} style="height: 52px; align-items: center">
|
|
127
|
+
<Avatar color={person.color} size="small">{person.abbr}</Avatar>
|
|
128
|
+
<div class="info">
|
|
129
|
+
<div class="name">
|
|
130
|
+
<Highlight searchWords={[searchText]} sourceString={String(source.item.label)} />
|
|
131
|
+
</div>
|
|
132
|
+
<div class="email">
|
|
133
|
+
<Highlight searchWords={[searchText]} sourceString={String(source.item.value)} />
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
</Checkbox>
|
|
137
|
+
</div>
|
|
138
|
+
{/snippet}
|
|
139
|
+
{#snippet selectedItem(selected)}
|
|
140
|
+
{@const person = selected.item as Person}
|
|
141
|
+
<div class="components-transfer-demo-selected-item">
|
|
142
|
+
<Avatar color={person.color} size="small">{person.abbr}</Avatar>
|
|
143
|
+
<div class="info">
|
|
144
|
+
<div class="name">{selected.item.label}</div>
|
|
145
|
+
<div class="email">{selected.item.value}</div>
|
|
146
|
+
</div>
|
|
147
|
+
<Button aria-label={`移除 ${selected.item.label}`} class="remove" size="small" theme="borderless" type="tertiary" onclick={selected.onRemove}>
|
|
148
|
+
{#snippet icon()}<IconClose />{/snippet}
|
|
149
|
+
</Button>
|
|
150
|
+
</div>
|
|
151
|
+
{/snippet}
|
|
152
|
+
</Transfer>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
```css
|
|
156
|
+
.components-transfer-demo-selected-item {
|
|
157
|
+
.remove {
|
|
158
|
+
opacity: 0;
|
|
159
|
+
}
|
|
160
|
+
&:hover,
|
|
161
|
+
&:focus-within {
|
|
162
|
+
.remove {
|
|
163
|
+
opacity: 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.components-transfer-demo-selected-item,
|
|
169
|
+
.components-transfer-demo-source-item {
|
|
170
|
+
height: 52px;
|
|
171
|
+
box-sizing: border-box;
|
|
172
|
+
display: flex;
|
|
173
|
+
align-items: center;
|
|
174
|
+
justify-content: space-between;
|
|
175
|
+
padding: 10px 12px;
|
|
176
|
+
&:hover {
|
|
177
|
+
background-color: var(--semi-color-fill-0);
|
|
178
|
+
}
|
|
179
|
+
.info {
|
|
180
|
+
margin-left: 8px;
|
|
181
|
+
flex-grow: 1;
|
|
182
|
+
}
|
|
183
|
+
.name {
|
|
184
|
+
font-size: 14px;
|
|
185
|
+
line-height: 20px;
|
|
186
|
+
}
|
|
187
|
+
.email {
|
|
188
|
+
font-size: 12px;
|
|
189
|
+
line-height: 16px;
|
|
190
|
+
color: var(--semi-color-text-2);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Disabled
|
|
196
|
+
|
|
197
|
+
```svelte
|
|
198
|
+
<script lang="ts">
|
|
199
|
+
import { Transfer, type TransferDataItem, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
200
|
+
|
|
201
|
+
const data = Array.from({ length: 20 }, (_v, i) => ({
|
|
202
|
+
label: `选项名称 ${i}`,
|
|
203
|
+
value: i,
|
|
204
|
+
disabled: false,
|
|
205
|
+
key: `key-${i}`,
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
const onChange = (values: TransferValue, items: TransferDataItem[]) => console.log(values, items);
|
|
209
|
+
</script>
|
|
210
|
+
|
|
211
|
+
<Transfer dataSource={data} disabled {onChange} style="width: 568px; height: 416px" value={[2, 4]} />
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Drag and drop sort
|
|
215
|
+
|
|
216
|
+
Set `draggable` to true to enable the drag sort function.
|
|
217
|
+
|
|
218
|
+
```svelte
|
|
219
|
+
<script lang="ts">
|
|
220
|
+
import { Transfer } from '@fibrae/semi-ui-svelte';
|
|
221
|
+
|
|
222
|
+
const data = Array.from({ length: 30 }, (_, i) => ({
|
|
223
|
+
label: `选项名称 ${i}`,
|
|
224
|
+
value: i,
|
|
225
|
+
disabled: false,
|
|
226
|
+
key: `key-${i}`,
|
|
227
|
+
}));
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<Transfer dataSource={data} draggable onChange={(values, items) => console.log(values, items)} style="width: 568px; height: 416px" value={[2, 4]} />
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Left panel pagination
|
|
234
|
+
|
|
235
|
+
When there are many options on the left, you can enable pagination through the `pagination` prop.
|
|
236
|
+
|
|
237
|
+
`pagination` accepts an object with the following properties:
|
|
238
|
+
|
|
239
|
+
- `pageSize`: Number of items per page, default is 10
|
|
240
|
+
- `currentPage`: Current page number (controlled mode)
|
|
241
|
+
- `defaultCurrentPage`: Default current page number (uncontrolled mode)
|
|
242
|
+
- `onPageChange`: Callback when page changes
|
|
243
|
+
|
|
244
|
+
```svelte
|
|
245
|
+
<script lang="ts">
|
|
246
|
+
import { Transfer } from '@fibrae/semi-ui-svelte';
|
|
247
|
+
|
|
248
|
+
const data = Array.from({ length: 100 }, (_, i) => ({
|
|
249
|
+
label: `选项名称 ${i}`,
|
|
250
|
+
value: i,
|
|
251
|
+
disabled: false,
|
|
252
|
+
key: `key-${i}`,
|
|
253
|
+
}));
|
|
254
|
+
</script>
|
|
255
|
+
|
|
256
|
+
<Transfer dataSource={data} onChange={(values, items) => console.log(values, items)} pagination={{ pageSize: 10 }} style="width: 568px; height: 416px" />
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Left panel pagination + controlled page
|
|
260
|
+
|
|
261
|
+
You can control the current page number through `pagination.currentPage`.
|
|
262
|
+
|
|
263
|
+
```svelte
|
|
264
|
+
<script lang="ts">
|
|
265
|
+
import { Button, ButtonGroup, Transfer } from '@fibrae/semi-ui-svelte';
|
|
266
|
+
|
|
267
|
+
let currentPage = $state(1);
|
|
268
|
+
const data = Array.from({ length: 100 }, (_, i) => ({
|
|
269
|
+
label: `选项名称 ${i}`,
|
|
270
|
+
value: i,
|
|
271
|
+
disabled: false,
|
|
272
|
+
key: `key-${i}`,
|
|
273
|
+
}));
|
|
274
|
+
</script>
|
|
275
|
+
|
|
276
|
+
<div>
|
|
277
|
+
<ButtonGroup style="margin-bottom: 12px">
|
|
278
|
+
<Button onclick={() => (currentPage = 1)}>第1页</Button>
|
|
279
|
+
<Button onclick={() => (currentPage = 2)}>第2页</Button>
|
|
280
|
+
<Button onclick={() => (currentPage = 5)}>第5页</Button>
|
|
281
|
+
<Button onclick={() => (currentPage = 10)}>第10页</Button>
|
|
282
|
+
</ButtonGroup>
|
|
283
|
+
<div>当前页码: {currentPage}</div>
|
|
284
|
+
<Transfer dataSource={data} onChange={(values, items) => console.log(values, items)} pagination={{ pageSize: 10, currentPage, onPageChange: (page) => (currentPage = page) }} style="width: 568px; height: 416px" />
|
|
285
|
+
</div>
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Drag and drop + custom selected rendering
|
|
289
|
+
|
|
290
|
+
Set `draggable` to true to enable the drag and drop sorting function; use the `selectedItem` snippet to customize the rendering of the selected items on the right; You can define the trigger as any content you want and add styles. With `draggable`, the snippet parameter `handle` is a `Snippet<[Snippet]>`: write the trigger as a snippet (such as `grip`) and wrap it with `{@render handle?.(grip)}`. Declare `grip` outside the `<Transfer>` tag; inside it, it would be taken as a prop of Transfer. Without `draggable`, `handle` is not provided.
|
|
291
|
+
|
|
292
|
+
```svelte
|
|
293
|
+
<script lang="ts">
|
|
294
|
+
import { IconClose, IconHandle } from '@fibrae/semi-icons-svelte';
|
|
295
|
+
import { Avatar, Button, Checkbox, Transfer, type AvatarColor, type TransferDataItem, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
296
|
+
|
|
297
|
+
interface Person extends TransferDataItem {
|
|
298
|
+
abbr: string;
|
|
299
|
+
color: AvatarColor;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const customFilter = (searchValue: string, item: TransferDataItem) => String(item.value).includes(searchValue) || String(item.label).includes(searchValue);
|
|
303
|
+
|
|
304
|
+
const data = [
|
|
305
|
+
{ label: '夏可漫', value: 'xiakeman@example.com', abbr: '夏', color: 'amber', area: 'US', key: 1 },
|
|
306
|
+
{ label: '申悦', value: 'shenyue@example.com', abbr: '申', color: 'indigo', area: 'UK', key: 2 },
|
|
307
|
+
{ label: '文嘉茂', value: 'wenjiamao@example.com', abbr: '文', color: 'cyan', area: 'HK', key: 3 },
|
|
308
|
+
{ label: '曲晨一', value: 'quchenyi@example.com', abbr: '曲', color: 'blue', area: 'India', key: 4 },
|
|
309
|
+
{ label: '曲晨二', value: 'quchener@example.com', abbr: '二', color: 'blue', area: 'India', key: 5 },
|
|
310
|
+
{ label: '曲晨三', value: 'quchensan@example.com', abbr: '三', color: 'blue', area: 'India', key: 6 },
|
|
311
|
+
] satisfies Person[];
|
|
312
|
+
|
|
313
|
+
const inputProps = { placeholder: '搜索姓名或邮箱' };
|
|
314
|
+
|
|
315
|
+
const onChange = (values: TransferValue, items: TransferDataItem[]) => console.log(values, items);
|
|
316
|
+
</script>
|
|
317
|
+
|
|
318
|
+
{#snippet grip()}
|
|
319
|
+
<IconHandle class="semi-right-item-drag-handler" />
|
|
320
|
+
{/snippet}
|
|
321
|
+
|
|
322
|
+
<Transfer dataSource={data} draggable filter={customFilter} {inputProps} {onChange} style="width: 568px" value={['xiakeman@example.com', 'shenyue@example.com']}>
|
|
323
|
+
{#snippet sourceItem(source)}
|
|
324
|
+
{@const person = source.item as Person}
|
|
325
|
+
<div class="components-transfer-demo-source-item">
|
|
326
|
+
<Checkbox checked={source.checked} onChange={source.onChange} style="height: 52px; align-items: center">
|
|
327
|
+
<Avatar color={person.color} size="small">{person.abbr}</Avatar>
|
|
328
|
+
<div class="info">
|
|
329
|
+
<div class="name">{source.item.label}</div>
|
|
330
|
+
<div class="email">{source.item.value}</div>
|
|
331
|
+
</div>
|
|
332
|
+
</Checkbox>
|
|
333
|
+
</div>
|
|
334
|
+
{/snippet}
|
|
335
|
+
{#snippet selectedItem(selected)}
|
|
336
|
+
{@const person = selected.item as Person}
|
|
337
|
+
{#if selected.handle}
|
|
338
|
+
<div class="components-transfer-demo-selected-item">
|
|
339
|
+
{@render selected.handle(grip)}
|
|
340
|
+
<Avatar color={person.color} size="small">{person.abbr}</Avatar>
|
|
341
|
+
<div class="info">
|
|
342
|
+
<div class="name">{selected.item.label}</div>
|
|
343
|
+
<div class="email">{selected.item.value}</div>
|
|
344
|
+
</div>
|
|
345
|
+
<Button aria-label={`移除 ${selected.item.label}`} class="remove" size="small" theme="borderless" type="tertiary" onclick={selected.onRemove}>
|
|
346
|
+
{#snippet icon()}<IconClose />{/snippet}
|
|
347
|
+
</Button>
|
|
348
|
+
</div>
|
|
349
|
+
{/if}
|
|
350
|
+
{/snippet}
|
|
351
|
+
</Transfer>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Custom rendering header information in panel
|
|
355
|
+
|
|
356
|
+
The `sourceHeader` and `selectedHeader` snippets allow users to customize the header information of the left and right panels. The snippet parameter types are `TransferSourceHeaderSnippetProps` and `TransferSelectedHeaderSnippetProps`:
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
type TransferSourceHeaderSnippetProps = {
|
|
360
|
+
num: number; // The total number of data or the number of filtered results
|
|
361
|
+
showButton: boolean; // Whether to show select all/unselect all buttons
|
|
362
|
+
allChecked: boolean; // Whether the current data has been selected
|
|
363
|
+
onAllClick: () => void; // Function that should be called after clicking the select/unselect all button
|
|
364
|
+
leafOnlyNum?: number; // Only provided when type is treeList, represents the number of leaf nodes
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
type TransferSelectedHeaderSnippetProps = {
|
|
368
|
+
num: number; // The total number of selected data
|
|
369
|
+
showButton: boolean; // Whether to show the clear button
|
|
370
|
+
onClear: () => void; // Function that should be called after clicking the clear button
|
|
371
|
+
};
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
The example is as follows:
|
|
375
|
+
|
|
376
|
+
```svelte
|
|
377
|
+
<script lang="ts">
|
|
378
|
+
import { Button, Transfer } from '@fibrae/semi-ui-svelte';
|
|
379
|
+
|
|
380
|
+
const data = Array.from({ length: 30 }, (_v, i) => ({
|
|
381
|
+
label: `选项名称 ${i}`,
|
|
382
|
+
value: i,
|
|
383
|
+
disabled: false,
|
|
384
|
+
key: `key-${i}`,
|
|
385
|
+
}));
|
|
386
|
+
|
|
387
|
+
const headerStyle = 'margin: 10px 0 0 10px; height: 24px; display: flex; align-items: center';
|
|
388
|
+
</script>
|
|
389
|
+
|
|
390
|
+
<Transfer dataSource={data} style="width: 568px; height: 416px">
|
|
391
|
+
{#snippet sourceHeader(header)}
|
|
392
|
+
<div style={headerStyle}>
|
|
393
|
+
<span>共 {header.num} 项</span>
|
|
394
|
+
{#if header.showButton}
|
|
395
|
+
<Button size="small" theme="borderless" type="tertiary" onclick={header.onAllClick}>
|
|
396
|
+
{header.allChecked ? '取消全选' : '全选'}
|
|
397
|
+
</Button>
|
|
398
|
+
{/if}
|
|
399
|
+
</div>
|
|
400
|
+
{/snippet}
|
|
401
|
+
{#snippet selectedHeader(header)}
|
|
402
|
+
<div style={headerStyle}>
|
|
403
|
+
<span>{header.num} 项已选</span>
|
|
404
|
+
{#if header.showButton}
|
|
405
|
+
<Button size="small" theme="borderless" type="tertiary" onclick={header.onClear}>清空</Button>
|
|
406
|
+
{/if}
|
|
407
|
+
</div>
|
|
408
|
+
{/snippet}
|
|
409
|
+
</Transfer>
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Fully custom rendering
|
|
413
|
+
|
|
414
|
+
Semi provides the `sourcePanel` and `selectedPanel` snippets, allowing you to completely customize the rendering structure of the left and right panels. With this function, you can directly reuse the logic capabilities inside the Transfer to implement the `Transfer` component with a highly customized style structure\
|
|
415
|
+
The parameter type of `sourcePanel` is `TransferSourcePanelSnippetProps`, from which you can get data to render your Panel structure
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
interface TransferSourcePanelSnippetProps {
|
|
419
|
+
value: Array<string | number>; // value of all selected items
|
|
420
|
+
loading?: boolean; // Whether loading
|
|
421
|
+
noMatch: boolean; // Whether there is no matching item that matches the current search value
|
|
422
|
+
filterData: Array<Item>; // items that match the current search value
|
|
423
|
+
sourceData: Array<Item>; // All items
|
|
424
|
+
propsDataSource: Array<Item> | Array<GroupItem> | Array<TreeItem>; // The dataSource of Transfer
|
|
425
|
+
allChecked: boolean; // Whether to select all
|
|
426
|
+
showNumber: number; // Filter the number of results
|
|
427
|
+
inputValue: string; // the value of the input search box
|
|
428
|
+
selectedItems: Map<string | number, Item>; // collection of all selected items, the key of the Map is item.key
|
|
429
|
+
onSearch: (searchString: string) => void; // The function that should be called when the search box changes, the input parameter is the search value
|
|
430
|
+
onAllClick: () => void; // The function that should be called when all the buttons on the left are clicked
|
|
431
|
+
onSelectOrRemove: (item: Item) => void; // The function that should be called when selecting or deleting a single option, the input should be the current operation item
|
|
432
|
+
onSelect: (values: Array<string | number>) => void; // controlled batch selection, the input is the values of the selected items
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
The parameter type of `selectedPanel` is `TransferSelectedPanelSnippetProps`
|
|
437
|
+
|
|
438
|
+
```ts
|
|
439
|
+
interface TransferSelectedPanelSnippetProps {
|
|
440
|
+
length: number; // number of selected options
|
|
441
|
+
selectedData: Array<Item>; // All selected items collection
|
|
442
|
+
onClear: () => void; // The callback function that should be called when clicking to clear
|
|
443
|
+
onRemove: (item: Item) => void; // The function that should be called when deleting a single option
|
|
444
|
+
onSortEnd: (payload: { oldIndex: number; newIndex: number }) => void; // The function that should be called when reordering the results
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
```svelte
|
|
449
|
+
<script lang="ts">
|
|
450
|
+
import { IconSearch } from '@fibrae/semi-icons-svelte';
|
|
451
|
+
import { Button, Input, Spin, Transfer, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
452
|
+
|
|
453
|
+
const dataSource = Array.from({ length: 100 }, (_v, i) => ({
|
|
454
|
+
label: `海底捞门店 ${i}`,
|
|
455
|
+
value: i,
|
|
456
|
+
disabled: false,
|
|
457
|
+
key: `key-${i}`,
|
|
458
|
+
}));
|
|
459
|
+
|
|
460
|
+
const onChange = (values: TransferValue) => console.log(values);
|
|
461
|
+
</script>
|
|
462
|
+
|
|
463
|
+
<Transfer class="component-transfer-demo-custom-panel" {dataSource} {onChange}>
|
|
464
|
+
{#snippet sourcePanel(panel)}
|
|
465
|
+
<section class="source-panel">
|
|
466
|
+
<div class="panel-header sp-font">门店列表</div>
|
|
467
|
+
<div class="panel-main">
|
|
468
|
+
<Input aria-label="搜索门店" onChange={(value) => panel.onSearch(value)} showClear style="width: 454px; margin: 12px 14px">
|
|
469
|
+
{#snippet prefix()}<IconSearch />{/snippet}
|
|
470
|
+
</Input>
|
|
471
|
+
<div class="panel-controls sp-font">
|
|
472
|
+
<span>待选门店: {panel.filterData.length}</span>
|
|
473
|
+
<Button size="small" theme="borderless" onclick={panel.onAllClick}>
|
|
474
|
+
{panel.allChecked ? '取消全选' : '全选'}
|
|
475
|
+
</Button>
|
|
476
|
+
</div>
|
|
477
|
+
<div class="panel-list">
|
|
478
|
+
{#if panel.loading}
|
|
479
|
+
<Spin />
|
|
480
|
+
{:else if panel.noMatch}
|
|
481
|
+
<div class="empty sp-font">
|
|
482
|
+
{panel.inputValue ? '无搜索结果' : '暂无内容'}
|
|
483
|
+
</div>
|
|
484
|
+
{:else}
|
|
485
|
+
{#each panel.filterData as item (item.key)}
|
|
486
|
+
<div class="semi-transfer-item panel-item">
|
|
487
|
+
<p>{item.label}</p>
|
|
488
|
+
<Button class="panel-item-remove" size="small" theme="borderless" type="primary" onclick={() => panel.onSelectOrRemove(item)}>
|
|
489
|
+
{panel.selectedItems.has(item.key) ? '删除' : '添加'}
|
|
490
|
+
</Button>
|
|
491
|
+
</div>
|
|
492
|
+
{/each}
|
|
493
|
+
{/if}
|
|
494
|
+
</div>
|
|
495
|
+
</div>
|
|
496
|
+
</section>
|
|
497
|
+
{/snippet}
|
|
498
|
+
{#snippet selectedPanel(panel)}
|
|
499
|
+
<section class="selected-panel">
|
|
500
|
+
<div class="panel-header sp-font">
|
|
501
|
+
<div>已选同步门店: {panel.selectedData.length}</div>
|
|
502
|
+
<Button size="small" theme="borderless" type="primary" onclick={panel.onClear}>清空</Button>
|
|
503
|
+
</div>
|
|
504
|
+
<div class="panel-main">
|
|
505
|
+
{#if !panel.selectedData.length}
|
|
506
|
+
<div class="empty sp-font">暂无数据,请从左侧筛选</div>
|
|
507
|
+
{:else}
|
|
508
|
+
{#each panel.selectedData as item (item.key)}
|
|
509
|
+
<div class="semi-transfer-item panel-item">
|
|
510
|
+
<p>{item.label}</p>
|
|
511
|
+
<Button class="panel-item-remove" size="small" theme="borderless" type="primary" onclick={() => panel.onRemove(item)}>删除</Button>
|
|
512
|
+
</div>
|
|
513
|
+
{/each}
|
|
514
|
+
{/if}
|
|
515
|
+
</div>
|
|
516
|
+
</section>
|
|
517
|
+
{/snippet}
|
|
518
|
+
</Transfer>
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
```scss
|
|
522
|
+
.component-transfer-demo-custom-panel {
|
|
523
|
+
.sp-font {
|
|
524
|
+
color: var(--semi-grey-9);
|
|
525
|
+
font-size: 12px;
|
|
526
|
+
font-weight: 500;
|
|
527
|
+
line-height: 20px;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
.empty {
|
|
531
|
+
width: 100%;
|
|
532
|
+
height: 100%;
|
|
533
|
+
display: flex;
|
|
534
|
+
align-items: center;
|
|
535
|
+
justify-content: center;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.panel-item {
|
|
539
|
+
flex-shrink: 0;
|
|
540
|
+
height: 56px;
|
|
541
|
+
border-radius: 4px;
|
|
542
|
+
padding: 8px 12px;
|
|
543
|
+
flex-wrap: wrap;
|
|
544
|
+
background-color: rgba(22, 24, 35, 0.03);
|
|
545
|
+
|
|
546
|
+
&-main {
|
|
547
|
+
flex-grow: 1;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
p {
|
|
551
|
+
margin: 0 12px;
|
|
552
|
+
flex-basis: 100%;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
.panel-item-remove {
|
|
556
|
+
cursor: pointer;
|
|
557
|
+
color: var(--semi-color-primary);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
.panel-header {
|
|
562
|
+
padding: 10px 12px;
|
|
563
|
+
border: 1px solid rgba(22, 24, 35, 0.16);
|
|
564
|
+
border-radius: 4px 4px 0 0;
|
|
565
|
+
height: 38px;
|
|
566
|
+
box-sizing: border-box;
|
|
567
|
+
background-color: var(--semi-color-tertiary-light-default);
|
|
568
|
+
display: flex;
|
|
569
|
+
align-items: center;
|
|
570
|
+
justify-content: space-between;
|
|
571
|
+
|
|
572
|
+
.clear {
|
|
573
|
+
cursor: pointer;
|
|
574
|
+
color: var(--semi-color-primary);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
.source-panel {
|
|
579
|
+
display: flex;
|
|
580
|
+
flex-direction: column;
|
|
581
|
+
width: 482px;
|
|
582
|
+
height: 353px;
|
|
583
|
+
|
|
584
|
+
.panel-main {
|
|
585
|
+
border: 1px solid var(--semi-color-border);
|
|
586
|
+
border-top: none;
|
|
587
|
+
|
|
588
|
+
.panel-list {
|
|
589
|
+
display: flex;
|
|
590
|
+
flex-wrap: wrap;
|
|
591
|
+
row-gap: 8px;
|
|
592
|
+
column-gap: 8px;
|
|
593
|
+
overflow-y: auto;
|
|
594
|
+
height: 214px;
|
|
595
|
+
margin-left: 12px;
|
|
596
|
+
margin-right: 12px;
|
|
597
|
+
padding-bottom: 8px;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.panel-controls {
|
|
602
|
+
margin: 10px 12px;
|
|
603
|
+
font-size: 12px;
|
|
604
|
+
line-height: 20px;
|
|
605
|
+
|
|
606
|
+
.semi-button {
|
|
607
|
+
margin-left: 8px;
|
|
608
|
+
font-size: 12px;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
.panel-item {
|
|
613
|
+
width: 176px;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
margin-right: 16px;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
.selected-panel {
|
|
620
|
+
width: 200px;
|
|
621
|
+
height: 353px;
|
|
622
|
+
|
|
623
|
+
.panel-main {
|
|
624
|
+
display: flex;
|
|
625
|
+
flex-direction: column;
|
|
626
|
+
overflow-y: auto;
|
|
627
|
+
padding: 12px;
|
|
628
|
+
border: 1px solid var(--semi-color-border);
|
|
629
|
+
border-top: none;
|
|
630
|
+
height: 323px;
|
|
631
|
+
box-sizing: border-box;
|
|
632
|
+
row-gap: 8px;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
### Fully custom rendering, drag and drop sorting
|
|
639
|
+
|
|
640
|
+
In a completely custom rendering scene, since the rendering of the drag area has also been completely taken over by you, you do not need to declare draggable. But you need to implement the drag and drop logic yourself, You can use the drag-and-drop tool library [dnd-kit](https://github.com/clauderic/dnd-kit) to quickly realize the function.
|
|
641
|
+
|
|
642
|
+
Besides, To support drag sorting, you need to call onSortEnd with oldIndex and newIndex as the input parameters after the drag sorting is over
|
|
643
|
+
|
|
644
|
+
Example using dnd-kit. The core dependencies that need to be used are @dnd-kit/svelte and @dnd-kit/dom. `DragDropProvider` provides the drag and drop context, and every selected item gets a `Sortable` exported from `@dnd-kit/dom/sortable`. Its parameters are as follows
|
|
645
|
+
|
|
646
|
+
```
|
|
647
|
+
1. Function: Obtain the necessary information during the drag and drop process through the unique id and the current index
|
|
648
|
+
2. Core input parameters:
|
|
649
|
+
- id: unique identifier, which can be a number or a string
|
|
650
|
+
- index: the current position of the item in the list; keep it up to date when the list changes
|
|
651
|
+
- element: the draggable dom node
|
|
652
|
+
- handle: optional, the drag handle element; the whole node is draggable when omitted
|
|
653
|
+
3. The second argument is the DragDropManager instance; call destroy on every Sortable when the component unmounts
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
The example creates the `Sortable` of each row with `{@attach}`, destroys it in the cleanup function, and keeps the selected values in `bind:value`. The order shown during a drag is driven by the example's own `preview` state, so the `OptimisticSortingPlugin` is removed: it moves DOM nodes itself, which collides with the keyed each of Svelte.
|
|
657
|
+
|
|
658
|
+
In `onDragOver` of `DragDropProvider` the preview order is adjusted from `source` and `target`; in `onDragEnd` the positions before and after the drag are worked out from the id of `event.operation.source`, then `onSortEnd` from the parameters of `selectedPanel` is called; `event.canceled` being true means the drag was canceled.
|
|
659
|
+
|
|
660
|
+
```svelte
|
|
661
|
+
<script lang="ts">
|
|
662
|
+
import { untrack, type ComponentProps } from 'svelte';
|
|
663
|
+
import { DragDropManager } from '@dnd-kit/dom';
|
|
664
|
+
import { isSortable, OptimisticSortingPlugin, Sortable } from '@dnd-kit/dom/sortable';
|
|
665
|
+
import { DragDropProvider } from '@dnd-kit/svelte';
|
|
666
|
+
import { IconHandle, IconSearch } from '@fibrae/semi-icons-svelte';
|
|
667
|
+
import { Button, Input, Spin, Transfer, type TransferDataItem, type TransferOnSortEnd, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
668
|
+
|
|
669
|
+
type ProviderProps = ComponentProps<typeof DragDropProvider>;
|
|
670
|
+
|
|
671
|
+
const dataSource = Array.from({ length: 100 }, (_v, i) => ({
|
|
672
|
+
label: `海底捞门店 ${i}`,
|
|
673
|
+
value: i,
|
|
674
|
+
disabled: false,
|
|
675
|
+
key: `key-${i}`,
|
|
676
|
+
}));
|
|
677
|
+
|
|
678
|
+
let value = $state<TransferValue>([2, 4]);
|
|
679
|
+
// The order shown while dragging; cleared on drop, so Transfer's value stays the only truth
|
|
680
|
+
let preview = $state.raw<TransferDataItem[] | null>(null);
|
|
681
|
+
|
|
682
|
+
// The default plugins keep the Accessibility one, which gives each handle a button role and Tab stop for keyboard sorting
|
|
683
|
+
const manager = new DragDropManager();
|
|
684
|
+
// OptimisticSortingPlugin moves DOM nodes itself, which collides with Svelte's keyed each; `preview` drives the order instead
|
|
685
|
+
const sortablePlugins: ConstructorParameters<typeof Sortable>[0]['plugins'] = (defaults) => defaults.filter((plugin) => plugin !== OptimisticSortingPlugin);
|
|
686
|
+
|
|
687
|
+
// Only the handle drags; it is found inside the row once the row's children are rendered
|
|
688
|
+
const sortable = (id: string | number, position: () => number) => (row: HTMLElement) => {
|
|
689
|
+
const item = new Sortable({ id, index: untrack(position), element: row, handle: row.querySelector<HTMLElement>('[data-sort-handle]') ?? undefined, plugins: sortablePlugins }, manager);
|
|
690
|
+
$effect(() => {
|
|
691
|
+
item.index = position();
|
|
692
|
+
});
|
|
693
|
+
return () => item.destroy();
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const onDragOver = (selectedData: TransferDataItem[]): ProviderProps['onDragOver'] => {
|
|
697
|
+
return ({ operation: { source, target } }) => {
|
|
698
|
+
if (!isSortable(source) || !isSortable(target) || source.id === target.id) return;
|
|
699
|
+
const next = [...(preview ?? selectedData)];
|
|
700
|
+
const from = next.findIndex((item) => item.key === source.id);
|
|
701
|
+
const to = next.findIndex((item) => item.key === target.id);
|
|
702
|
+
if (from < 0 || to < 0) return;
|
|
703
|
+
next.splice(to, 0, ...next.splice(from, 1));
|
|
704
|
+
preview = next;
|
|
705
|
+
};
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
const onDragEnd = (selectedData: TransferDataItem[], onSortEnd: TransferOnSortEnd): ProviderProps['onDragEnd'] => {
|
|
709
|
+
return ({ canceled, operation: { source } }) => {
|
|
710
|
+
if (!canceled && preview && source) {
|
|
711
|
+
const oldIndex = selectedData.findIndex((item) => item.key === source.id);
|
|
712
|
+
const newIndex = preview.findIndex((item) => item.key === source.id);
|
|
713
|
+
if (oldIndex !== newIndex) onSortEnd({ oldIndex, newIndex });
|
|
714
|
+
}
|
|
715
|
+
preview = null;
|
|
716
|
+
};
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
const onChange = (next: TransferValue) => console.log(next);
|
|
720
|
+
</script>
|
|
721
|
+
|
|
722
|
+
<Transfer bind:value class="component-transfer-demo-custom-panel" {dataSource} {onChange}>
|
|
723
|
+
{#snippet sourcePanel(panel)}
|
|
724
|
+
<section class="source-panel">
|
|
725
|
+
<div class="panel-header sp-font">门店列表</div>
|
|
726
|
+
<div class="panel-main">
|
|
727
|
+
<Input aria-label="搜索门店" onChange={(text) => panel.onSearch(text)} showClear style="width: 454px; margin: 12px 14px">
|
|
728
|
+
{#snippet prefix()}<IconSearch />{/snippet}
|
|
729
|
+
</Input>
|
|
730
|
+
<div class="panel-controls sp-font">
|
|
731
|
+
<span>待选门店: {panel.filterData.length}</span>
|
|
732
|
+
<Button size="small" theme="borderless" onclick={panel.onAllClick}>
|
|
733
|
+
{panel.allChecked ? '取消全选' : '全选'}
|
|
734
|
+
</Button>
|
|
735
|
+
</div>
|
|
736
|
+
<div class="panel-list">
|
|
737
|
+
{#if panel.loading}
|
|
738
|
+
<Spin />
|
|
739
|
+
{:else if panel.noMatch}
|
|
740
|
+
<div class="empty sp-font">
|
|
741
|
+
{panel.inputValue ? '无搜索结果' : '暂无内容'}
|
|
742
|
+
</div>
|
|
743
|
+
{:else}
|
|
744
|
+
{#each panel.filterData as item (item.key)}
|
|
745
|
+
<div class="semi-transfer-item panel-item">
|
|
746
|
+
<div class="panel-item-main" style="flex-grow: 1">
|
|
747
|
+
<p style="margin: 0 12px">{item.label}</p>
|
|
748
|
+
<Button class="panel-item-remove" size="small" theme="borderless" type="primary" onclick={() => panel.onSelectOrRemove(item)}>
|
|
749
|
+
{panel.selectedItems.has(item.key) ? '删除' : '添加'}
|
|
750
|
+
</Button>
|
|
751
|
+
</div>
|
|
752
|
+
</div>
|
|
753
|
+
{/each}
|
|
754
|
+
{/if}
|
|
755
|
+
</div>
|
|
756
|
+
</div>
|
|
757
|
+
</section>
|
|
758
|
+
{/snippet}
|
|
759
|
+
{#snippet selectedPanel(panel)}
|
|
760
|
+
{@const ordered = preview ?? panel.selectedData}
|
|
761
|
+
<section class="selected-panel">
|
|
762
|
+
<div class="panel-header sp-font">
|
|
763
|
+
<div>已选同步门店: {panel.selectedData.length}</div>
|
|
764
|
+
<Button size="small" theme="borderless" type="primary" onclick={panel.onClear}>清空</Button>
|
|
765
|
+
</div>
|
|
766
|
+
<div class="panel-main" style="display: block">
|
|
767
|
+
<DragDropProvider {manager} onDragEnd={onDragEnd(panel.selectedData, panel.onSortEnd)} onDragOver={onDragOver(panel.selectedData)}>
|
|
768
|
+
<div style="overflow: auto; display: flex; flex-direction: column; row-gap: 8px">
|
|
769
|
+
<!-- Keyed by key: dnd-kit reorders the rows mid-drag, and the keyed each moves them with their data -->
|
|
770
|
+
{#each ordered as item, position (item.key)}
|
|
771
|
+
<div {@attach sortable(item.key, () => position)}>
|
|
772
|
+
<div class="semi-transfer-item panel-item">
|
|
773
|
+
<span aria-label={String(item.label)} data-sort-handle style="line-height: 0">
|
|
774
|
+
<IconHandle class="pane-item-drag-handler" />
|
|
775
|
+
</span>
|
|
776
|
+
<div class="panel-item-main" style="flex-grow: 1">
|
|
777
|
+
<p style="margin: 0 12px">{item.label}</p>
|
|
778
|
+
<Button class="panel-item-remove" size="small" theme="borderless" type="primary" onclick={() => panel.onRemove(item)}>删除</Button>
|
|
779
|
+
</div>
|
|
780
|
+
</div>
|
|
781
|
+
</div>
|
|
782
|
+
{/each}
|
|
783
|
+
</div>
|
|
784
|
+
</DragDropProvider>
|
|
785
|
+
</div>
|
|
786
|
+
</section>
|
|
787
|
+
{/snippet}
|
|
788
|
+
</Transfer>
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
### Tree Transfer
|
|
792
|
+
|
|
793
|
+
The input type is `treeList`, and the [`Tree`](../navigation/tree.md) component is used as a custom rendering list.
|
|
794
|
+
|
|
795
|
+
The properties of the default tree can be overridden by treeProps([TreeProps](../navigation/tree.md)). The default properties of the tree on the left are
|
|
796
|
+
|
|
797
|
+
```
|
|
798
|
+
{
|
|
799
|
+
multiple:true,
|
|
800
|
+
disableStrictly:true,
|
|
801
|
+
leafOnly:true,
|
|
802
|
+
filterTreeNode:true,
|
|
803
|
+
defaultExpandAll:true,
|
|
804
|
+
}
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
The Tree's own search box is hidden, and the search box of Transfer drives the filtering. Of the Tree snippets only `label` is forwarded, through the `label` snippet of Transfer, and it applies to both the tree rows on the left and the selected items on the right. A leaf node writes `children: []`.
|
|
808
|
+
|
|
809
|
+
```svelte
|
|
810
|
+
<script lang="ts">
|
|
811
|
+
import { Transfer, type TransferTreeItem, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
812
|
+
|
|
813
|
+
const treeData: TransferTreeItem[] = [
|
|
814
|
+
{
|
|
815
|
+
label: 'Asia',
|
|
816
|
+
value: 'Asia',
|
|
817
|
+
key: '0',
|
|
818
|
+
children: [
|
|
819
|
+
{
|
|
820
|
+
label: 'China',
|
|
821
|
+
value: 'China',
|
|
822
|
+
key: '0-0',
|
|
823
|
+
children: [
|
|
824
|
+
{ label: 'Beijing', value: 'Beijing', key: '0-0-0', children: [] },
|
|
825
|
+
{ label: 'Shanghai', value: 'Shanghai', key: '0-0-1', children: [] },
|
|
826
|
+
{ label: 'Chengdu', value: 'Chengdu', key: '0-0-2', children: [] },
|
|
827
|
+
],
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
label: 'Japan',
|
|
831
|
+
value: 'Japan',
|
|
832
|
+
key: '0-1',
|
|
833
|
+
children: [{ label: 'Osaka', value: 'Osaka', key: '0-1-0', children: [] }],
|
|
834
|
+
},
|
|
835
|
+
],
|
|
836
|
+
},
|
|
837
|
+
{
|
|
838
|
+
label: 'North America',
|
|
839
|
+
value: 'North America',
|
|
840
|
+
key: '1',
|
|
841
|
+
children: [
|
|
842
|
+
{ label: 'United States', value: 'United States', key: '1-0', children: [] },
|
|
843
|
+
{ label: 'Canada', value: 'Canada', key: '1-1', children: [] },
|
|
844
|
+
{ label: 'Mexico', value: 'Mexico', disabled: true, key: '1-2', children: [] },
|
|
845
|
+
{ label: 'Cuba', value: 'Cuba', key: '1-3', children: [] },
|
|
846
|
+
],
|
|
847
|
+
},
|
|
848
|
+
];
|
|
849
|
+
|
|
850
|
+
let value = $state<TransferValue>(['Shanghai']);
|
|
851
|
+
</script>
|
|
852
|
+
|
|
853
|
+
<div style="margin: 10px; padding: 10px; width: 600px">
|
|
854
|
+
<Transfer bind:value dataSource={treeData} type="treeList" />
|
|
855
|
+
</div>
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
### Tree Transfer with Custom Header Showing Leaf Node Count
|
|
859
|
+
|
|
860
|
+
When type is `treeList`, the `TransferSourceHeaderSnippetProps` parameter of `sourceHeader` provides an additional `leafOnlyNum` field, which represents the number of leaf nodes. This is useful in scenarios like file selection, where you can display only the file count instead of the total including folders.
|
|
861
|
+
|
|
862
|
+
```svelte
|
|
863
|
+
<script lang="ts">
|
|
864
|
+
import { Button, Transfer, type TransferValue } from '@fibrae/semi-ui-svelte';
|
|
865
|
+
|
|
866
|
+
const treeData = [
|
|
867
|
+
{
|
|
868
|
+
label: '文件夹 1',
|
|
869
|
+
value: 'folder1',
|
|
870
|
+
key: 'folder1',
|
|
871
|
+
children: [
|
|
872
|
+
{ label: '文件 1-1', value: 'file1-1', key: 'file1-1', children: [] },
|
|
873
|
+
{ label: '文件 1-2', value: 'file1-2', key: 'file1-2', children: [] },
|
|
874
|
+
{
|
|
875
|
+
label: '子文件夹 1',
|
|
876
|
+
value: 'subfolder1',
|
|
877
|
+
key: 'subfolder1',
|
|
878
|
+
children: [
|
|
879
|
+
{ label: '文件 1-1-1', value: 'file1-1-1', key: 'file1-1-1', children: [] },
|
|
880
|
+
{ label: '文件 1-1-2', value: 'file1-1-2', key: 'file1-1-2', children: [] },
|
|
881
|
+
],
|
|
882
|
+
},
|
|
883
|
+
],
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
label: '文件夹 2',
|
|
887
|
+
value: 'folder2',
|
|
888
|
+
key: 'folder2',
|
|
889
|
+
children: [
|
|
890
|
+
{ label: '文件 2-1', value: 'file2-1', key: 'file2-1', children: [] },
|
|
891
|
+
{ label: '文件 2-2', value: 'file2-2', key: 'file2-2', children: [] },
|
|
892
|
+
],
|
|
893
|
+
},
|
|
894
|
+
{ label: '独立文件', value: 'file3', key: 'file3', children: [] },
|
|
895
|
+
];
|
|
896
|
+
|
|
897
|
+
let value = $state<TransferValue>([]);
|
|
898
|
+
</script>
|
|
899
|
+
|
|
900
|
+
<Transfer bind:value dataSource={treeData} style="width: 600px" type="treeList">
|
|
901
|
+
{#snippet sourceHeader(header)}
|
|
902
|
+
<div style="display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--semi-color-border)">
|
|
903
|
+
<span>
|
|
904
|
+
<strong>文件总数:</strong>
|
|
905
|
+
{header.leafOnlyNum !== undefined ? header.leafOnlyNum : header.num} 个文件
|
|
906
|
+
{#if header.leafOnlyNum !== undefined}
|
|
907
|
+
<span style="color: var(--semi-color-text-2); margin-inline-start: 8px; font-size: 12px"> (总节点数:{header.num}) </span>
|
|
908
|
+
{/if}
|
|
909
|
+
</span>
|
|
910
|
+
{#if header.showButton}
|
|
911
|
+
<Button size="small" theme="borderless" type="tertiary" onclick={header.onAllClick}>
|
|
912
|
+
{header.allChecked ? '取消全选' : '全选'}
|
|
913
|
+
</Button>
|
|
914
|
+
{/if}
|
|
915
|
+
</div>
|
|
916
|
+
{/snippet}
|
|
917
|
+
</Transfer>
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
## Accessibility
|
|
921
|
+
|
|
922
|
+
### ARIA
|
|
923
|
+
|
|
924
|
+
- The container of the search box is a native `search` element (the search landmark), named from the locale
|
|
925
|
+
- When the root element has `aria-label` or `aria-labelledby` and no `role`, it gets `role` `group`
|
|
926
|
+
- Add `role` `list` to the option list on the left and `listitem` to its options; in `groupList` every group is a `listitem` of the outer list, and its title names the nested `list` that holds the options
|
|
927
|
+
- Add `role` `list` to the selected list on the right, add `role` `listitem` to the selected item; custom rendered items on either side are wrapped in an element with `role` `listitem`
|
|
928
|
+
|
|
929
|
+
### Keyboard
|
|
930
|
+
|
|
931
|
+
- The default filter ignores case
|
|
932
|
+
- When disabled, the two lists are Tab stops so the keyboard can scroll their content
|
|
933
|
+
- With `draggable`, the drag handle is a native `button` with a name: Tab focuses the handle, Space picks up, the arrow keys move, Space drops; the sort is announced to screen readers. Mouse dragging is unchanged
|
|
934
|
+
- Until the dnd-kit needed for sorting has loaded, the handle is a placeholder with `aria-disabled="true"`
|
|
935
|
+
|
|
936
|
+
## API Reference
|
|
937
|
+
|
|
938
|
+
### Transfer
|
|
939
|
+
|
|
940
|
+
**Props**
|
|
941
|
+
|
|
942
|
+
| Property | Description | Type | Default |
|
|
943
|
+
| - | - | - | - |
|
|
944
|
+
| dataSource | Data source: an array of items for list, an array of groups for groupList, or tree data with children for treeList (a leaf writes `children: []`). The tree of a treeList only updates when a new array is passed, changes made in place are not seen. | `TransferDataSource` | `[]` |
|
|
945
|
+
| disabled | Whether the whole transfer is disabled. | `boolean` | `false` |
|
|
946
|
+
| draggable | Enables drag sorting of the selected items on the right. After a sort, value and onChange carry the new order. | `boolean` | `false` |
|
|
947
|
+
| emptyLeft | Shown when the left list has no data. The locale text appears when it is not provided; false hides the empty state. | `Snippet \| false` | - |
|
|
948
|
+
| emptyRight | Shown when nothing is selected. The locale text appears when it is not provided; false hides the empty state. | `Snippet \| false` | - |
|
|
949
|
+
| emptySearch | Shown when the search matches nothing. The locale text appears when it is not provided; false hides the empty state. | `Snippet \| false` | - |
|
|
950
|
+
| filter | Filtering logic. false hides the search box; a function replaces the default case-insensitive label match and returns true to keep an item. For a custom search in treeList, set it to true and pass the matching function as filterTreeNode in treeProps. | `boolean \| ((searchValue: string, item: TransferDataItem) => boolean)` | - |
|
|
951
|
+
| inputProps | Props passed to the search Input, see Input for the options. Transfer owns its value and onChange; to search from outside, call the search method. | `TransferInputProps` | - |
|
|
952
|
+
| label | Content of an item, used by the source row (the tree row in treeList), the selected row and the drag copy; the label of the item by default. | `Snippet<[TransferLabelSnippetProps]>` | - |
|
|
953
|
+
| loading | Whether the options on the left are loading. | `boolean` | - |
|
|
954
|
+
| onBlur | Called once when the focus moves from inside the Transfer to outside it, with the FocusEvent; moving between the search box, checkboxes, items, remove buttons and drag handles does not call it, and a window blur (empty relatedTarget) does. | `(event: FocusEvent) => void` | - |
|
|
955
|
+
| onChange | Called when the selection changes, including after a drag sort, with the array of values and the array of their items. This is the callback of Transfer, not the native change of the root element. | `(values: TransferValue, items: TransferDataItem[]) => void` | - |
|
|
956
|
+
| onDeselect | Called when an item is unchecked, with that item. | `(item: TransferDataItem) => void` | - |
|
|
957
|
+
| onSearch | Called when the text of the search box changes, with the search value. A search driven by the search method does not call it. | `(searchValue: string) => void` | - |
|
|
958
|
+
| onSelect | Called when an item is checked, with that item. | `(item: TransferDataItem) => void` | - |
|
|
959
|
+
| pagination | Paging of the left panel, for list and groupList only. onPageChange lives inside the object. | `TransferPagination` | - |
|
|
960
|
+
| selectedHeader | Replaces the header of the right panel. | `Snippet<[TransferSelectedHeaderSnippetProps]>` | - |
|
|
961
|
+
| selectedItem | Replaces one selected item on the right. With draggable, handle is a `Snippet<[Snippet]>`: write the drag icon as a snippet and wrap it with `{@render handle?.(grip)}`. With treeList and showPath, fullPath holds the whole path. | `Snippet<[TransferSelectedItemSnippetProps]>` | - |
|
|
962
|
+
| selectedPanel | Replaces the whole right panel. Call onSortEnd after a drag sort you implemented has finished. | `Snippet<[TransferSelectedPanelSnippetProps]>` | - |
|
|
963
|
+
| showPath | treeList only: whether the selected items on the right show their path from the root. | `boolean` | `false` |
|
|
964
|
+
| sourceHeader | Replaces the header of the left panel. leafOnlyNum is provided for treeList only. | `Snippet<[TransferSourceHeaderSnippetProps]>` | - |
|
|
965
|
+
| sourceItem | Replaces one item on the left. index is the position among the shown items after filtering and paging, not the position in dataSource. | `Snippet<[TransferSourceItemSnippetProps]>` | - |
|
|
966
|
+
| sourcePanel | Replaces the whole left panel, reusing the filtering and selection logic of Transfer. | `Snippet<[TransferSourcePanelSnippetProps]>` | - |
|
|
967
|
+
| treeProps | treeList only: props passed to the Tree on the left, overriding the defaults multiple, disableStrictly, leafOnly, filterTreeNode and defaultExpandAll. Transfer decides the selection and the tree data, so value, onChange, keyMaps, treeData, treeDataSimpleJson and onChangeWithObject are ignored; of the Tree snippets only label is forwarded. | `TransferTreeProps` | - |
|
|
968
|
+
| type | Transfer type: list, groupList or treeList. | `TransferType` | `"list"` |
|
|
969
|
+
| value | Array of the values of the selected items, two-way bindable with bind:value. A plain value is the initial selection, which Transfer then maintains itself; `bind:value={get, set}` makes it fully controlled. Its order is the order on the right. | `TransferValue` | - |
|
|
970
|
+
| virtualize | Virtualizes the selected list on the right, only with the default right panel and draggable off. A numeric height applies as is; a string such as 100% is measured from the remaining panel height. | `TransferVirtualize` | - |
|
|
971
|
+
|
|
972
|
+
**Methods**
|
|
973
|
+
|
|
974
|
+
| Method | Description | Type |
|
|
975
|
+
| - | - | - |
|
|
976
|
+
| search | Searches as if the value were typed into the search box; onSearch is not called. | `(input: string) => void` |
|
|
977
|
+
|
|
978
|
+
`class`, `style`, `aria-*` and other undeclared attributes land on the root element of Transfer; with `aria-label` or `aria-labelledby` and no `role`, the root element gets `role="group"`. `value` can be bound with `bind:value`, or given a plain value as the initial selection; there is no `defaultValue`. Pass the props of the search box through `inputProps`, and those of the Tree on the left of a treeList through `treeProps`.
|
|
979
|
+
|
|
980
|
+
The types of the interfaces below are exported from `@fibrae/semi-ui-svelte` as: `TransferDataItem` for Item, `TransferGroupItem` for GroupItem, `TransferTreeItem` for TreeItem, `TransferVirtualize` for VirtualizeProps and `TransferPagination` for TransferPaginationProps.
|
|
981
|
+
|
|
982
|
+
### Item Interface
|
|
983
|
+
|
|
984
|
+
An item can carry any custom fields; they appear unchanged on `item` in the snippet parameters and callback payloads.
|
|
985
|
+
|
|
986
|
+
| props | description | data type | default |
|
|
987
|
+
| - | - | - | - |
|
|
988
|
+
| disabled | Whether to disable | boolean | false |
|
|
989
|
+
| key | Required, unique identification of each option, no repetition is allowed | string \| number | |
|
|
990
|
+
| label | Option display text, matched by the default filter; use the `label` snippet for other content | string | |
|
|
991
|
+
| fullPath | When `type="treeList"` and `showPath` is `true`, returns the full path node array from the root node to the current node | Array\<Item> | |
|
|
992
|
+
| value | The value represented by the option | string \| number | |
|
|
993
|
+
|
|
994
|
+
### GroupItem Interface
|
|
995
|
+
|
|
996
|
+
A group is not an item itself, it only has the following properties
|
|
997
|
+
|
|
998
|
+
| props | description | data type | default |
|
|
999
|
+
| - | - | - | - |
|
|
1000
|
+
| children | Elements of the group | array\<Item> | |
|
|
1001
|
+
| title | Group Name | string | |
|
|
1002
|
+
|
|
1003
|
+
### TreeItem Interface
|
|
1004
|
+
|
|
1005
|
+
TreeItem inherits all the properties of Item
|
|
1006
|
+
|
|
1007
|
+
| props | description | data type | default |
|
|
1008
|
+
| - | - | - | - |
|
|
1009
|
+
| children | Children Items | array\<TreeItem> | |
|
|
1010
|
+
|
|
1011
|
+
### VirtualizeProps Interface
|
|
1012
|
+
|
|
1013
|
+
| props | description | data type | default |
|
|
1014
|
+
| - | - | - | - |
|
|
1015
|
+
| height | Height of the virtualized list. If it is a `number`, it takes effect directly. If it is a `string` (e.g. `100%`), it adapts to remaining height | number \| string | |
|
|
1016
|
+
| width | Width of the virtualized list | number \| string | |
|
|
1017
|
+
| itemSize | Fixed height of each item row | number | |
|
|
1018
|
+
|
|
1019
|
+
### TransferPaginationProps Interface
|
|
1020
|
+
|
|
1021
|
+
| props | description | data type | default |
|
|
1022
|
+
| - | - | - | - |
|
|
1023
|
+
| currentPage | Current page number (controlled mode) | number | |
|
|
1024
|
+
| defaultCurrentPage | Default current page number (uncontrolled mode) | number | 1 |
|
|
1025
|
+
| pageSize | Number of items per page | number | 10 |
|
|
1026
|
+
| onPageChange | Callback when page changes | (currentPage: number) => void | |
|
|
1027
|
+
|
|
1028
|
+
## Methods
|
|
1029
|
+
|
|
1030
|
+
Transfer exposes `search` through `export function`; get the instance with `bind:this` and call it. Its type is `TransferHandle`.
|
|
1031
|
+
|
|
1032
|
+
```svelte
|
|
1033
|
+
<script lang="ts">
|
|
1034
|
+
import { Transfer, type TransferHandle } from '@fibrae/semi-ui-svelte';
|
|
1035
|
+
|
|
1036
|
+
let transfer = $state<TransferHandle>();
|
|
1037
|
+
</script>
|
|
1038
|
+
|
|
1039
|
+
<Transfer bind:this={transfer} />
|
|
1040
|
+
<button onclick={() => transfer?.search('Option 1')}>Search</button>
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
## Design Tokens
|
|
1044
|
+
|
|
1045
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/input/transfer/>
|
|
1046
|
+
|
|
1047
|
+
## Changes from Semi Design
|
|
1048
|
+
|
|
1049
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
1050
|
+
|
|
1051
|
+
- 破坏性(类型):删除 `DraggableResolvedDataItem`、`DataItem`/`FullPathItem` 的 `style`、`BasicDataItem` 的 `className`、`style` 与 `ResolvedDataItem._optionKey`;`RenderSelectedItemProps.sortableHandle` 改为 `SortableHandle`;`treeProps` 类型去掉 `value`、`ref`、`onChange`、`keyMaps`、`treeData` 等,运行时也忽略。
|
|
1052
|
+
- 新增 blur 事件(React `onBlur`、Vue `blur`、Solid `onBlur`、Svelte `onBlur`),焦点从 Transfer 内部移到外部时触发一次,参数为 FocusEvent;在搜索框、复选框、列表项、移除按钮、拖拽手柄之间移动不触发;窗口失焦(`relatedTarget` 为空)也触发,与 TreeSelect 一致。行为变化(React):根元素不再直接透传使用方的 `onBlur`(原为内部任一控件的 focusout 冒泡都会触发),改为上述语义。
|
|
1053
|
+
- 受控值(Vue `modelValue`)从数组变回 `undefined` 时,已选项重置为 `defaultValue`(未设置则清空),不再残留转为受控之前的非受控选择(表单 reset 后右侧仍显示旧选项)。
|
|
1054
|
+
- 非受控时只记录已选 value 并按当前 `dataSource` 解析:不在新 `dataSource` 中的已选项不再显示,也不进 `onChange`,需要保留时改用受控 `value`;条目以 `value` 识别,缺失或重复的不能被正确选中。`value={null}` 视同未传。
|
|
1055
|
+
- 条目 DOM 变化:`renderSourceItem`、`renderSelectedItem` 的内容外包 `role="listitem"` 的 div,groupList 改为嵌套列表,筛选框改为原生 `search` 元素,移除按钮与拖拽句柄改为原生 `button`(支持键盘排序),依赖旧结构的选择器需调整。默认过滤不区分大小写;ref 改为 `TransferHandle { search }`。
|
|
1056
|
+
- treeList 左侧的 Tree 以语言包的 `optionList` 命名,与左侧普通列表一致;`treeProps['aria-label']` 仍可覆盖。
|
|
1057
|
+
- 根元素(`role="group"`)不再带 `aria-required`:group 不支持该属性,必填的 FormTransfer 原先会被 axe 报 `aria-allowed-attr`。
|
|
1058
|
+
- Svelte:`value` 可绑定,没有 `defaultValue`;插槽改为同名 snippet:`label`、`sourceItem`、`selectedItem`、`sourceHeader`、`selectedHeader`、`sourcePanel`、`selectedPanel`、`emptyLeft`、`emptyRight`、`emptySearch`,空状态传 `false` 隐藏,传空 snippet 只留空容器。
|
|
1059
|
+
- 破坏性(类型):React、Solid 的分页配置类型 `PaginationProps` 改名 `TransferPaginationProps`,并从包根导出(原来与 Pagination 的 `PaginationProps` 重名,包根没有导出)。React 内部的表头配置 `HeaderConfig` 用 `side: 'left' | 'right'` 代替 `type: string`(不对外导出)。
|
|
1060
|
+
- React、Solid:`inputProps` 的类型去掉 `value`、`onChange`,运行时也在展开前去掉,搜索框始终由 Transfer 控制(原来传入同名属性会接管搜索框,筛选不再跟随输入)。Vue:`inputProps` 里的 `modelValue`、`defaultValue` 同样被忽略。
|
|
1061
|
+
- Svelte:`selectedItem` 参数里的 `handle` 是 `Snippet<[Snippet]>`,写 `{@render handle?.(grip)}`,不可拖拽时为 `undefined`;`treeProps` 里的 `value`、`onChange`、`keyMaps`、`treeData`、`treeDataSimpleJson`、`onChangeWithObject`、`search`、`label` 由 Transfer 接管,`inputProps` 不含 `value`、`onChange`;`search` 方法经 `bind:this` 调用,只认小写 `tabindex`。
|