@fibrae/semi-ui-svelte 0.9.1 → 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 (165) 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/interface.d.ts +57 -0
  16. package/dist/components/checkbox/interface.d.ts +19 -0
  17. package/dist/components/code-highlight/interface.d.ts +3 -0
  18. package/dist/components/collapse/interface.d.ts +16 -0
  19. package/dist/components/collapsible/interface.d.ts +10 -0
  20. package/dist/components/color-picker/interface.d.ts +10 -0
  21. package/dist/components/config-provider/interface.d.ts +7 -0
  22. package/dist/components/cropper/interface.d.ts +11 -0
  23. package/dist/components/date-picker/interface.d.ts +47 -0
  24. package/dist/components/descriptions/interface.d.ts +6 -0
  25. package/dist/components/divider/interface.d.ts +4 -0
  26. package/dist/components/dropdown/interface.d.ts +8 -0
  27. package/dist/components/empty/interface.d.ts +7 -0
  28. package/dist/components/feedback/interface.d.ts +16 -0
  29. package/dist/components/float-button/interface.d.ts +14 -0
  30. package/dist/components/form/interface.d.ts +47 -0
  31. package/dist/components/grid/interface.d.ts +13 -0
  32. package/dist/components/highlight/interface.d.ts +7 -0
  33. package/dist/components/hot-keys/interface.d.ts +3 -0
  34. package/dist/components/image/interface.d.ts +59 -0
  35. package/dist/components/input/interface.d.ts +67 -0
  36. package/dist/components/input-number/interface.d.ts +24 -0
  37. package/dist/components/json-viewer/interface.d.ts +7 -0
  38. package/dist/components/layout/interface.d.ts +3 -0
  39. package/dist/components/list/interface.d.ts +18 -0
  40. package/dist/components/locale/interface.d.ts +4 -0
  41. package/dist/components/lottie/interface.d.ts +2 -0
  42. package/dist/components/markdown-render/interface.d.ts +5 -0
  43. package/dist/components/modal/interface.d.ts +29 -0
  44. package/dist/components/navigation/interface.d.ts +47 -0
  45. package/dist/components/overflow-list/interface.d.ts +11 -0
  46. package/dist/components/pagination/interface.d.ts +12 -0
  47. package/dist/components/pincode/interface.d.ts +8 -0
  48. package/dist/components/popconfirm/interface.d.ts +12 -0
  49. package/dist/components/popover/interface.d.ts +30 -0
  50. package/dist/components/progress/interface.d.ts +13 -0
  51. package/dist/components/radio/interface.d.ts +22 -0
  52. package/dist/components/rating/interface.d.ts +12 -0
  53. package/dist/components/resizable/interface.d.ts +30 -0
  54. package/dist/components/scroll-list/interface.d.ts +6 -0
  55. package/dist/components/select/interface.d.ts +63 -0
  56. package/dist/components/side-sheet/interface.d.ts +19 -0
  57. package/dist/components/skeleton/interface.d.ts +7 -0
  58. package/dist/components/slider/interface.d.ts +23 -0
  59. package/dist/components/space/interface.d.ts +4 -0
  60. package/dist/components/spin/interface.d.ts +7 -0
  61. package/dist/components/steps/interface.d.ts +9 -0
  62. package/dist/components/switch/interface.d.ts +7 -0
  63. package/dist/components/table/interface.d.ts +48 -0
  64. package/dist/components/tabs/interface.d.ts +29 -0
  65. package/dist/components/tag/interface.d.ts +22 -0
  66. package/dist/components/tag-input/interface.d.ts +29 -0
  67. package/dist/components/time-picker/interface.d.ts +31 -0
  68. package/dist/components/timeline/interface.d.ts +5 -0
  69. package/dist/components/tooltip/interface.d.ts +20 -0
  70. package/dist/components/transfer/interface.d.ts +18 -0
  71. package/dist/components/tree/interface.d.ts +45 -0
  72. package/dist/components/tree-select/interface.d.ts +55 -0
  73. package/dist/components/typography/interface.d.ts +33 -0
  74. package/dist/components/upload/interface.d.ts +64 -0
  75. package/dist/components/user-guide/interface.d.ts +15 -0
  76. package/dist/components/video-player/interface.d.ts +22 -0
  77. package/docs/advanced/dark-mode.md +288 -0
  78. package/docs/basic/button.md +605 -0
  79. package/docs/basic/divider.md +103 -0
  80. package/docs/basic/float-button.md +246 -0
  81. package/docs/basic/grid.md +427 -0
  82. package/docs/basic/layout.md +459 -0
  83. package/docs/basic/resizable.md +584 -0
  84. package/docs/basic/space.md +163 -0
  85. package/docs/basic/tokens.md +425 -0
  86. package/docs/basic/typography.md +615 -0
  87. package/docs/changes-from-semi.md +105 -0
  88. package/docs/ecosystem/tailwind.md +210 -0
  89. package/docs/experience/accessibility.md +82 -0
  90. package/docs/experience/content-guidelines.md +819 -0
  91. package/docs/experience/internationalization.md +7 -0
  92. package/docs/feedback/banner.md +198 -0
  93. package/docs/feedback/feedback.md +294 -0
  94. package/docs/feedback/notification.md +401 -0
  95. package/docs/feedback/popconfirm.md +243 -0
  96. package/docs/feedback/progress.md +389 -0
  97. package/docs/feedback/skeleton.md +388 -0
  98. package/docs/feedback/spin.md +172 -0
  99. package/docs/feedback/toast.md +393 -0
  100. package/docs/input/auto-complete.md +399 -0
  101. package/docs/input/cascader.md +1558 -0
  102. package/docs/input/checkbox.md +408 -0
  103. package/docs/input/color-picker.md +175 -0
  104. package/docs/input/date-picker.md +942 -0
  105. package/docs/input/form.md +2550 -0
  106. package/docs/input/input-number.md +451 -0
  107. package/docs/input/input.md +640 -0
  108. package/docs/input/pincode.md +191 -0
  109. package/docs/input/radio.md +337 -0
  110. package/docs/input/rating.md +214 -0
  111. package/docs/input/select.md +1230 -0
  112. package/docs/input/slider.md +347 -0
  113. package/docs/input/switch.md +206 -0
  114. package/docs/input/tag-input.md +465 -0
  115. package/docs/input/time-picker.md +358 -0
  116. package/docs/input/transfer.md +1061 -0
  117. package/docs/input/tree-select.md +1300 -0
  118. package/docs/input/upload.md +1811 -0
  119. package/docs/llms.txt +147 -0
  120. package/docs/navigation/anchor.md +377 -0
  121. package/docs/navigation/backtop.md +100 -0
  122. package/docs/navigation/breadcrumb.md +284 -0
  123. package/docs/navigation/navigation.md +851 -0
  124. package/docs/navigation/pagination.md +217 -0
  125. package/docs/navigation/steps.md +315 -0
  126. package/docs/navigation/tabs.md +754 -0
  127. package/docs/navigation/tree.md +1956 -0
  128. package/docs/other/config-provider.md +599 -0
  129. package/docs/other/locale.md +353 -0
  130. package/docs/plus/audio-player.md +155 -0
  131. package/docs/plus/code-highlight.md +150 -0
  132. package/docs/plus/drag-move.md +214 -0
  133. package/docs/plus/hot-keys.md +174 -0
  134. package/docs/plus/json-viewer.md +392 -0
  135. package/docs/plus/lottie.md +176 -0
  136. package/docs/plus/markdown-render.md +240 -0
  137. package/docs/plus/video-player.md +325 -0
  138. package/docs/show/avatar.md +475 -0
  139. package/docs/show/badge.md +276 -0
  140. package/docs/show/calendar.md +352 -0
  141. package/docs/show/card.md +485 -0
  142. package/docs/show/carousel.md +592 -0
  143. package/docs/show/collapse.md +289 -0
  144. package/docs/show/collapsible.md +216 -0
  145. package/docs/show/cropper.md +285 -0
  146. package/docs/show/descriptions.md +325 -0
  147. package/docs/show/dropdown.md +466 -0
  148. package/docs/show/empty.md +225 -0
  149. package/docs/show/highlight.md +144 -0
  150. package/docs/show/image.md +433 -0
  151. package/docs/show/list.md +927 -0
  152. package/docs/show/modal.md +517 -0
  153. package/docs/show/overflow-list.md +272 -0
  154. package/docs/show/popover.md +534 -0
  155. package/docs/show/scroll-list.md +156 -0
  156. package/docs/show/side-sheet.md +274 -0
  157. package/docs/show/table.md +5437 -0
  158. package/docs/show/tag.md +428 -0
  159. package/docs/show/timeline.md +277 -0
  160. package/docs/show/tooltip.md +442 -0
  161. package/docs/show/user-guide.md +419 -0
  162. package/docs/start/getting-started.md +234 -0
  163. package/docs/start/introduction.md +57 -0
  164. package/docs/start/overview.md +21 -0
  165. package/package.json +5 -4
@@ -0,0 +1,605 @@
1
+ # Button
2
+
3
+ > Users use buttons to trigger an operation or jump.
4
+
5
+ Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/basic/button/
6
+
7
+ ## Demos
8
+
9
+ ### How to import
10
+
11
+ ```svelte
12
+ <script lang="ts">
13
+ import { Button, ButtonGroup, SplitButtonGroup } from '@fibrae/semi-ui-svelte';
14
+ </script>
15
+ ```
16
+
17
+ ### Button Type
18
+
19
+ Buttons support the following types:
20
+
21
+ - Primary button ("primary", default)
22
+ - Secondary button ("secondary")
23
+ - Tertiary button ("tertiary")
24
+ - Warning button ("warning")
25
+ - Danger button ("danger")
26
+
27
+ ```svelte
28
+ <script lang="ts">
29
+ import { Button } from '@fibrae/semi-ui-svelte';
30
+ </script>
31
+
32
+ <div class="btn-margin-right">
33
+ <Button>主要按钮</Button>
34
+ <Button type="secondary">次要按钮</Button>
35
+ <Button type="tertiary">第三按钮</Button>
36
+ <Button type="warning">警告按钮</Button>
37
+ <Button type="danger">危险按钮</Button>
38
+ </div>
39
+ ```
40
+
41
+ #### About the Font Color
42
+
43
+ [CSS Variables](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Using_CSS_custom_properties) are used with the button:
44
+
45
+ - `var(--semi-color-primary)`: main
46
+ - `var(--semi-color-secondary)`: secondary
47
+ - `var(--semi-color-tertiary)`: third
48
+ - `var(--semi-color-warning)`: warning
49
+ - `var(--semi-color-danger)`: danger
50
+
51
+ You can define your elements directly using these theme colors.
52
+
53
+ ```svelte
54
+ <script lang="ts">
55
+ const types = [
56
+ ['primary', '主要'],
57
+ ['secondary', '次要'],
58
+ ['tertiary', '第三'],
59
+ ['warning', '警告'],
60
+ ['danger', '危险'],
61
+ ];
62
+ </script>
63
+
64
+ <article>
65
+ {#each types as [type, label] (type)}
66
+ <strong style={`color: var(--semi-color-${type}); margin-inline-end: 10px`}>
67
+ {label}
68
+ </strong>
69
+ {/each}
70
+ </article>
71
+ ```
72
+
73
+ ### Button Theme
74
+
75
+ The themes currently available are:
76
+
77
+ - `light`: light background
78
+ - `solid`: dark background
79
+ - `borderless`: no background
80
+ - `outline`: border mode
81
+
82
+ The default theme is `light`
83
+
84
+ #### Light Background
85
+
86
+ ```svelte
87
+ <script lang="ts">
88
+ import { Button } from '@fibrae/semi-ui-svelte';
89
+ </script>
90
+
91
+ <Button style="margin-inline-end: 8px" theme="light" type="primary">浅色主要</Button>
92
+ <Button style="margin-inline-end: 8px" theme="light" type="secondary">浅色次要</Button>
93
+ <Button style="margin-inline-end: 8px" theme="light" type="tertiary">浅色第三</Button>
94
+ <Button style="margin-inline-end: 8px" theme="light" type="warning">浅色警告</Button>
95
+ <Button style="margin-inline-end: 8px" theme="light" type="danger">浅色危险</Button>
96
+ ```
97
+
98
+ #### Dark Background
99
+
100
+ ```svelte
101
+ <script lang="ts">
102
+ import { Button } from '@fibrae/semi-ui-svelte';
103
+ </script>
104
+
105
+ <Button style="margin-inline-end: 8px" theme="solid" type="primary">深色主要</Button>
106
+ <Button style="margin-inline-end: 8px" theme="solid" type="secondary">深色次要</Button>
107
+ <Button style="margin-inline-end: 8px" theme="solid" type="tertiary">深色第三</Button>
108
+ <Button style="margin-inline-end: 8px" theme="solid" type="warning">深色警告</Button>
109
+ <Button style="margin-inline-end: 8px" theme="solid" type="danger">深色危险</Button>
110
+ ```
111
+
112
+ #### No Background
113
+
114
+ ```svelte
115
+ <script lang="ts">
116
+ import { Button } from '@fibrae/semi-ui-svelte';
117
+ </script>
118
+
119
+ <Button style="margin-inline-end: 8px" theme="borderless" type="primary">主要</Button>
120
+ <Button style="margin-inline-end: 8px" theme="borderless" type="secondary">次要</Button>
121
+ <Button style="margin-inline-end: 8px" theme="borderless" type="tertiary">第三</Button>
122
+ <Button style="margin-inline-end: 8px" theme="borderless" type="warning">警告</Button>
123
+ <Button style="margin-inline-end: 8px" theme="borderless" type="danger">危险</Button>
124
+ ```
125
+
126
+ #### Border Mode
127
+
128
+ ```svelte
129
+ <script lang="ts">
130
+ import { Button } from '@fibrae/semi-ui-svelte';
131
+ </script>
132
+
133
+ <Button style="margin-inline-end: 8px" theme="outline" type="primary">主要</Button>
134
+ <Button style="margin-inline-end: 8px" theme="outline" type="secondary">次要</Button>
135
+ <Button style="margin-inline-end: 8px" theme="outline" type="tertiary">第三</Button>
136
+ <Button style="margin-inline-end: 8px" theme="outline" type="warning">警告</Button>
137
+ <Button style="margin-inline-end: 8px" theme="outline" type="danger">危险</Button>
138
+ ```
139
+
140
+ ### Size
141
+
142
+ Three sizes are defined by default:
143
+
144
+ - Big: "Large"
145
+ - Default: "default."
146
+ - Small: "Small"
147
+
148
+ ```svelte
149
+ <script lang="ts">
150
+ import { Button } from '@fibrae/semi-ui-svelte';
151
+ </script>
152
+
153
+ <div>
154
+ <Button size="large" style="margin-inline-end: 8px">大尺寸</Button>
155
+ <Button size="default" style="margin-inline-end: 8px">默认尺寸</Button>
156
+ <Button size="small">小尺寸</Button>
157
+ </div>
158
+ ```
159
+
160
+ ### Block Button
161
+
162
+ The block button has a predefined width, and its width is independent of the width of the contents of the button.
163
+
164
+ ```svelte
165
+ <script lang="ts">
166
+ import { Button } from '@fibrae/semi-ui-svelte';
167
+ </script>
168
+
169
+ <div>
170
+ <Button block>块级按钮</Button>
171
+ </div>
172
+ ```
173
+
174
+ ### Icon Button
175
+
176
+ An icon that defines a button.
177
+
178
+ Pass the icon through the `icon` snippet; `iconPosition` decides where it goes. The rest of the tag content is the text (`children`). Without `children` the button is treated as icon-only, so pass an `aria-label`.
179
+
180
+ ```svelte
181
+ <script lang="ts">
182
+ import { IconCamera, IconChevronDown, IconSidebar } from '@fibrae/semi-icons-svelte';
183
+ import { Button } from '@fibrae/semi-ui-svelte';
184
+ </script>
185
+
186
+ {#snippet camera()}
187
+ <IconCamera />
188
+ {/snippet}
189
+
190
+ <div>
191
+ <strong>默认状态:</strong>
192
+ <Button aria-label="截屏" icon={camera} />
193
+ <br />
194
+ <br />
195
+ <strong>禁用状态:</strong>
196
+ <Button aria-label="截屏" disabled icon={camera} />
197
+ <br />
198
+ <br />
199
+ <strong>复合类型:</strong>
200
+ <span class="btn-margin-inline-end">
201
+ <Button aria-label="截屏" icon={camera} type="primary" />
202
+ <Button aria-label="截屏" icon={camera} type="secondary" />
203
+ <Button aria-label="截屏" icon={camera} type="warning" />
204
+ <Button aria-label="截屏" icon={camera} type="danger" />
205
+ </span>
206
+ <br />
207
+ <br />
208
+ <strong>更改主题:</strong>
209
+ <Button aria-label="截屏" icon={camera} style="margin-inline-end: 10px" theme="solid" />
210
+ <Button aria-label="截屏" icon={camera} theme="light" />
211
+ <br />
212
+ <br />
213
+ <strong>更改图标位置:</strong>
214
+ <Button style="margin-inline-end: 10px" theme="solid">
215
+ {#snippet icon()}
216
+ <IconSidebar />
217
+ {/snippet}
218
+ 收起
219
+ </Button>
220
+ <Button iconPosition="right" theme="solid">
221
+ {#snippet icon()}
222
+ <IconChevronDown />
223
+ {/snippet}
224
+ 展开选项
225
+ </Button>
226
+ <br />
227
+ <br />
228
+ </div>
229
+ ```
230
+
231
+ ### Link Button
232
+
233
+ We recommend using Typography to achieve link text button. Refer to [Typography](../basic/typography.md) for more information.
234
+
235
+ ```svelte
236
+ <script lang="ts">
237
+ import { IconLink } from '@fibrae/semi-icons-svelte';
238
+ import { Typography } from '@fibrae/semi-ui-svelte';
239
+ </script>
240
+
241
+ <div>
242
+ <Typography.Text link={{ href: 'https://semi-design-next.pages.dev/' }}>链接文本</Typography.Text>
243
+ <br />
244
+ <br />
245
+ <Typography.Text link={{ href: 'https://semi-design-next.pages.dev/' }}>打开网站</Typography.Text>
246
+ <br />
247
+ <br />
248
+ <Typography.Text link underline>
249
+ {#snippet icon()}
250
+ <IconLink />
251
+ {/snippet}
252
+ 带下划线的网页链接
253
+ </Typography.Text>
254
+ </div>
255
+ ```
256
+
257
+ ### Prohibited Status
258
+
259
+ ```svelte
260
+ <script lang="ts">
261
+ import { Button } from '@fibrae/semi-ui-svelte';
262
+ </script>
263
+
264
+ <div>
265
+ <Button disabled>禁用</Button>
266
+ <Button disabled theme="borderless">无背景禁用</Button>
267
+ <Button disabled theme="light">浅色禁用</Button>
268
+ <Button disabled theme="borderless" type="primary">无背景主要禁用</Button>
269
+ <Button disabled theme="solid" type="warning">深色警告禁用</Button>
270
+ </div>
271
+ ```
272
+
273
+ ### Loading State
274
+
275
+ The button supports the Loading state, by setting the loading parameter value to true, note: the disabled state takes precedence over the loading state.
276
+
277
+ ```svelte
278
+ <script lang="ts">
279
+ import { IconDelete } from '@fibrae/semi-icons-svelte';
280
+ import { Button } from '@fibrae/semi-ui-svelte';
281
+
282
+ let saveLoading = $state(false);
283
+ let delLoading = $state(true);
284
+ let repLoading = $state(true);
285
+
286
+ const reset = (status: boolean) => {
287
+ saveLoading = status;
288
+ delLoading = status;
289
+ repLoading = status;
290
+ };
291
+ </script>
292
+
293
+ <div>
294
+ <div>
295
+ <div class="btn-margin-inline-end" style="display: inline-flex; align-items: center; padding-block-end: 14px">
296
+ <Button onclick={() => reset(false)}>关闭加载态</Button>
297
+ <Button onclick={() => reset(true)}>开启加载态</Button>
298
+ </div>
299
+ </div>
300
+ <hr />
301
+ <Button loading={saveLoading} style="margin-inline-end: 14px" onclick={() => (saveLoading = true)}>保存</Button>
302
+ <Button loading={delLoading} style="margin-inline-end: 14px" type="danger" onclick={() => (delLoading = true)}>
303
+ {#snippet icon()}
304
+ <IconDelete />
305
+ {/snippet}
306
+ 删除
307
+ </Button>
308
+ <div style="width: 200px; display: inline-block">
309
+ <Button block loading={repLoading} theme="solid" type="warning" onclick={() => (repLoading = true)}>撤销</Button>
310
+ </div>
311
+ </div>
312
+ ```
313
+
314
+ ### AI style - Colorful buttons
315
+
316
+ Set `colorful` to get colorful buttons. Colorful buttons support all `theme`, and `type` only supports `primary` and `tertiary`.
317
+
318
+ A colorful button gives the `icon` snippet the argument `{ fill }`, which you need to pass to the icon component: `{#snippet icon({ fill })}<IconAIFilledLevel1 {fill} />{/snippet}`.
319
+
320
+ ```svelte
321
+ <script lang="ts">
322
+ import { IconAIFilledLevel1, IconAIFilledLevel2, IconAIFilledLevel3 } from '@fibrae/semi-icons-svelte';
323
+ import { Button } from '@fibrae/semi-ui-svelte';
324
+
325
+ const contents = ['Colorful', undefined];
326
+ const rows = [
327
+ { theme: 'solid', primaryIcon: IconAIFilledLevel1, tertiaryIcon: IconAIFilledLevel3 },
328
+ { theme: 'light', primaryIcon: IconAIFilledLevel3, tertiaryIcon: IconAIFilledLevel2 },
329
+ { theme: 'outline', primaryIcon: IconAIFilledLevel1, tertiaryIcon: IconAIFilledLevel2 },
330
+ { theme: 'borderless', primaryIcon: IconAIFilledLevel3, tertiaryIcon: IconAIFilledLevel2 },
331
+ ] as const;
332
+ const variants = [
333
+ { type: 'primary', state: 'default' },
334
+ { type: 'primary', state: 'loading' },
335
+ { type: 'primary', state: 'disabled' },
336
+ { type: 'tertiary', state: 'default' },
337
+ { type: 'tertiary', state: 'loading' },
338
+ { type: 'tertiary', state: 'disabled' },
339
+ ] as const;
340
+ </script>
341
+
342
+ <!-- The text is the children snippet; leaving it out makes the button icon-only, so the label is passed or omitted as a whole. -->
343
+ {#each contents as content (content ?? 'icon-only')}
344
+ {#snippet text()}{content}{/snippet}
345
+ <div style="display: flex; row-gap: 16px; margin-block-start: 20px; margin-inline-start: 10px; flex-direction: column">
346
+ {#each rows as row (row.theme)}
347
+ <div style="display: flex; column-gap: 16px">
348
+ {#each variants as variant (`${variant.type}-${variant.state}`)}
349
+ {@const Icon = variant.type === 'primary' ? row.primaryIcon : row.tertiaryIcon}
350
+ {#snippet icon({ fill }: { fill?: string[] })}
351
+ <Icon {fill} />
352
+ {/snippet}
353
+ <Button aria-label={content ? undefined : 'AI'} children={content ? text : undefined} colorful disabled={variant.state === 'disabled'} {icon} loading={variant.state === 'loading'} theme={row.theme} type={variant.type} />
354
+ {/each}
355
+ </div>
356
+ {/each}
357
+ </div>
358
+ {/each}
359
+ ```
360
+
361
+ ### Button Combination
362
+
363
+ You can put multiple buttons in a `ButtonGroup` container and set `size`, `disabled`, `type`, `theme` and `colorful` on it to give the buttons a shared size, disabled state, type, theme and colorful style. These props are only defaults: a value set on a button itself wins. Other props such as `data-*`, `id`, `aria-*` and event handlers go to the group's root element (`role="group"`).
364
+
365
+ #### Combined Dimensions
366
+
367
+ ```svelte
368
+ <script lang="ts">
369
+ import { Button, ButtonGroup } from '@fibrae/semi-ui-svelte';
370
+
371
+ const sizes = ['large', 'default', 'small'] as const;
372
+ </script>
373
+
374
+ <div style="display: flex">
375
+ {#each sizes as size (size)}
376
+ <div style="margin-inline-end: 10px">
377
+ <ButtonGroup aria-label="操作按钮组" {size}>
378
+ <Button>拷贝</Button>
379
+ <Button>查询</Button>
380
+ <Button>剪切</Button>
381
+ </ButtonGroup>
382
+ </div>
383
+ {/each}
384
+ </div>
385
+ ```
386
+
387
+ #### Combined Disabled
388
+
389
+ ```svelte
390
+ <script lang="ts">
391
+ import { Button, ButtonGroup } from '@fibrae/semi-ui-svelte';
392
+ </script>
393
+
394
+ <div style="display: flex">
395
+ <div style="margin-inline-end: 10px">
396
+ <ButtonGroup disabled>
397
+ <Button>拷贝</Button>
398
+ <Button>查询</Button>
399
+ <Button>剪切</Button>
400
+ </ButtonGroup>
401
+ </div>
402
+ </div>
403
+ ```
404
+
405
+ #### Combined Type
406
+
407
+ ```svelte
408
+ <script lang="ts">
409
+ import { Button, ButtonGroup } from '@fibrae/semi-ui-svelte';
410
+
411
+ const types = ['primary', 'secondary', 'tertiary', 'warning', 'danger'] as const;
412
+ </script>
413
+
414
+ <div style="display: flex">
415
+ {#each types as type (type)}
416
+ <div style="margin-inline-end: 10px">
417
+ <ButtonGroup aria-label="操作按钮组" {type}>
418
+ <Button>拷贝</Button>
419
+ <Button>查询</Button>
420
+ <Button>剪切</Button>
421
+ </ButtonGroup>
422
+ </div>
423
+ {/each}
424
+ </div>
425
+ ```
426
+
427
+ ### Split Button Group
428
+
429
+ In the scene where `Button` and `Dropdown` are combined, split buttons can be used. The split buttons add the space between the buttons and change the rounded corners of the buttons.
430
+
431
+ #### Basic Usage
432
+
433
+ ```svelte
434
+ <script lang="ts">
435
+ import { IconTreeTriangleDown } from '@fibrae/semi-icons-svelte';
436
+ import { Button, Dropdown, SplitButtonGroup, type DropdownMenuItem } from '@fibrae/semi-ui-svelte';
437
+
438
+ const menu: DropdownMenuItem[] = [
439
+ { node: 'item', name: '编辑项目', onclick: () => console.log('编辑项目点击') },
440
+ { node: 'item', name: '重置项目' },
441
+ { node: 'divider' },
442
+ { node: 'item', name: '复制项目' },
443
+ { node: 'item', name: '从项目创建模版' },
444
+ { node: 'divider' },
445
+ { node: 'item', name: '删除项目', type: 'danger' },
446
+ ];
447
+
448
+ const btnVisible = $state<Record<number, boolean>>({ 1: false, 2: false, 3: false });
449
+
450
+ const handleVisibleChange = (key: number, visible: boolean) => {
451
+ btnVisible[key] = visible;
452
+ };
453
+ </script>
454
+
455
+ <div>
456
+ <SplitButtonGroup aria-label="项目操作按钮组" style="margin-inline-end: 10px">
457
+ <Button theme="solid" type="primary">分裂按钮</Button>
458
+ <Dropdown {menu} onVisibleChange={(visible) => handleVisibleChange(1, visible)} position="bottomRight" trigger="click">
459
+ {#snippet child({ props })}
460
+ <Button {...props} aria-label="更多操作" style={`${btnVisible[1] ? 'background: var(--semi-color-primary-hover); ' : ''}padding: 8px 4px`} theme="solid" type="primary">
461
+ {#snippet icon()}
462
+ <IconTreeTriangleDown />
463
+ {/snippet}
464
+ </Button>
465
+ {/snippet}
466
+ </Dropdown>
467
+ </SplitButtonGroup>
468
+ <SplitButtonGroup aria-label="项目操作按钮组" style="margin-inline-end: 10px">
469
+ <Button theme="light" type="primary">分裂按钮</Button>
470
+ <Dropdown {menu} onVisibleChange={(visible) => handleVisibleChange(2, visible)} position="bottomRight" trigger="click">
471
+ {#snippet child({ props })}
472
+ <Button {...props} aria-label="更多操作" style={`${btnVisible[2] ? 'background: var(--semi-color-fill-1); ' : ''}padding: 8px 4px`} theme="light" type="primary">
473
+ {#snippet icon()}
474
+ <IconTreeTriangleDown />
475
+ {/snippet}
476
+ </Button>
477
+ {/snippet}
478
+ </Dropdown>
479
+ </SplitButtonGroup>
480
+ <SplitButtonGroup aria-label="项目操作按钮组">
481
+ <Button style={btnVisible[3] ? 'background: var(--semi-color-fill-0)' : undefined} theme="borderless" type="primary">分裂按钮</Button>
482
+ <Dropdown {menu} onVisibleChange={(visible) => handleVisibleChange(3, visible)} position="bottomRight" trigger="click">
483
+ {#snippet child({ props })}
484
+ <Button {...props} aria-label="更多操作" style={`${btnVisible[3] ? 'background: var(--semi-color-fill-1); ' : ''}padding: 8px 4px`} theme="borderless" type="primary">
485
+ {#snippet icon()}
486
+ <IconTreeTriangleDown />
487
+ {/snippet}
488
+ </Button>
489
+ {/snippet}
490
+ </Dropdown>
491
+ </SplitButtonGroup>
492
+ </div>
493
+ ```
494
+
495
+ ## API Reference
496
+
497
+ ### Button
498
+
499
+ **Props**
500
+
501
+ | Property | Description | Type | Default |
502
+ | - | - | - | - |
503
+ | block | Renders the button as a block-level button. | `boolean` | `false` |
504
+ | children | Snippet for the button text. Without `children`, a button that shows an icon or is loading is treated as an icon-only button. | `Snippet` | - |
505
+ | classNames | Class names of the inner parts, keyed by content; values take anything class takes (string, array or object) and merge with the built-in classes. | `Partial<Record<ButtonPart, ClassValue>>` | - |
506
+ | colorful | Colorful button, supported for the primary and tertiary types only. Falls back to the ButtonGroup it is in, and finally to false. | `boolean` | - |
507
+ | disabled | Disabled state, which takes precedence over loading. Falls back to the ButtonGroup it is in, and finally to false. | `boolean` | - |
508
+ | htmlType | Native type of the button: button, reset or submit. | `HtmlType` | `"button"` |
509
+ | icon | Snippet for the button icon, placed by iconPosition. Its argument is `{ fill }`: a colorful button supplies the fill, which has to be passed to the icon component. | `Snippet<[ButtonIconArgs]>` | - |
510
+ | iconPosition | Icon position: left or right. | `'left' \| 'right'` | `"left"` |
511
+ | loading | Loading state. A loading button stays focusable, its onclick is not called, and a submit button does not submit its form. | `boolean` | `false` |
512
+ | noHorizontalPadding | Removes horizontal padding: true, left, right or an array of both. Applies only to a button that shows an icon or the loading spinner. | `boolean \| HorizontalPaddingType \| HorizontalPaddingType[]` | `false` |
513
+ | size | Button size: large, default or small. Falls back to the ButtonGroup it is in, and finally to default. | `Size` | - |
514
+ | styles | Style strings of the inner parts, keyed like classNames. | `Partial<Record<ButtonPart, string>>` | - |
515
+ | theme | Button theme: solid, borderless, light or outline. Falls back to the ButtonGroup it is in, and finally to light. | `Theme` | - |
516
+ | type | Button type: primary, secondary, tertiary, warning or danger. Falls back to the ButtonGroup it is in, and finally to primary. | `Type` | - |
517
+
518
+ `class`, `style` and native attributes and events (such as `id`, `aria-*`, `onclick` and `onmousedown`) land on the native `<button>`; `style` only accepts a string. `onclick` is not called while `loading`.
519
+
520
+ ### ButtonGroup
521
+
522
+ **Props**
523
+
524
+ | Property | Description | Type | Default |
525
+ | - | - | - | - |
526
+ | children | Buttons in the group. | `Snippet` | - |
527
+ | colorful | Colorful style, used as the default of the buttons in the group. | `boolean` | - |
528
+ | disabled | Disabled state, used as the default of the buttons in the group. | `boolean` | - |
529
+ | size | Button size, used as the default of the buttons in the group. | `Size` | - |
530
+ | theme | Button theme, used as the default of the buttons in the group. | `Theme` | - |
531
+ | type | Button type, used as the default of the buttons in the group. | `Type` | - |
532
+
533
+ `class`, `style` and native attributes (such as `data-*` and `aria-*`) land on the root element of the group (`role="group"`); a `role` you pass replaces the default `group`. Any descendant Button of the group gets a separator, not only direct children; the separators are added after mounting, so the server-rendered first frame has none.
534
+
535
+ ### SplitButtonGroup
536
+
537
+ **Props**
538
+
539
+ | Property | Description | Type | Default |
540
+ | - | - | - | - |
541
+ | children | A Button followed by a Dropdown that wraps a Button. | `Snippet` | - |
542
+
543
+ `class`, `style` and native attributes (such as `aria-*`) land on the root element of the split button group (`role="group"`).
544
+
545
+ ## Accessibility
546
+
547
+ ### ARIA
548
+
549
+ - `aria-label` is used to indicate the function of the button. For icon buttons, we recommend using this attribute
550
+ - `aria-disabled` is true when the button is disabled or loading, indicating that the button cannot be operated
551
+
552
+ ### Keyboard and Focus
553
+
554
+ - `Button`'s focus management is consistent with native `button`, keyboard users can use `Tab` and `Shift + Tab` to switch focus
555
+ - The trigger of `Button` is the same as the native `button`, when the `button` is focused, it can be activated by `Enter` or `Space` key
556
+ - The buttons in the `ButtonGroup` are managed in the same way as the focus of a single `button`, and can be switched by `Tab` and `Shift + Tab`
557
+
558
+ ## Content Guidelines
559
+
560
+ - Buttons need to be clear and predictable, users should be able to predict what will happen when they click the button
561
+ - Buttons should always start with a strong verb that encourages action
562
+ - To give the user enough context, use {verb}+{noun} content formulas on buttons; in addition to common actions like "Done", "Close", "Cancel" or "OK"
563
+
564
+ | ✅ Recommended usage | ❌ Deprecated usage |
565
+ | - | - |
566
+ | | |
567
+
568
+ - When the button is combined with other components, the button can only display {verb}, such as "Add", "Create", if the other components (such as Modal and Sidesheet) already provide enough context for the information
569
+
570
+ | ✅ Recommended usage | ❌ Deprecated usage |
571
+ | - | - |
572
+ | | |
573
+
574
+ - Always write in Sentence case
575
+
576
+ | ✅ Recommended usage | ❌ Deprecated usage |
577
+ | - | - |
578
+ | Create project | Create Create a project |
579
+ | Edit profile | Edit |
580
+
581
+ ## Design Tokens
582
+
583
+ The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/basic/button/>
584
+
585
+ ## FAQ
586
+
587
+ - ### Why is the icon of Button not shown?
588
+ The icon is passed through the `icon` snippet, not an `icon` component prop: `<Button>{#snippet icon()}<IconCamera />{/snippet}</Button>`.
589
+
590
+ ## Changes from Semi Design
591
+
592
+ From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
593
+
594
+ - 破坏性:Button 与 IconButton 删除 `contentClassName`,改用 `classNames.content`、`styles.content`,落在内容 span 上。
595
+ - 破坏性:`--semi-button-colorful-*` 改为只读写法,默认值写在 `var()` 回退里,可在 body 或祖先上设置;删除 `--semi-button-colorful-disabled-fill`。
596
+ - 破坏性(类型):`IconButtonProps` 删除 `iconSize`、`iconStyle`;删除 `circle` 属性及 `semi-button-circle` 类,继续传入时落到原生 `button`。
597
+ - `loading` 时点击不再触发 `onClick`(submit 不提交),按钮带 `aria-disabled="true"` 并保持可聚焦;带 `icon` 的 Button 只读取 `overrideDefaultProps.Button`。Vue:`icon` 为 `#icon` 插槽,`children` 为默认插槽,回调为 `@click` 等原生事件;`OverrideDefaultProps` 删除 `SplitButtonGroup` 键。
598
+ - Svelte:`icon` 是 snippet,参数 `{ fill }`,彩色按钮给出填充色,需传给图标组件(`{#snippet icon({ fill })}<IconEdit {fill} />{/snippet}`);内容为 `children`,没有 `children` 即按纯图标按钮处理;回调为原生事件属性(`onclick` 等)。
599
+ - IconButton 放在 InputGroup 里时继承组的 `size`、`disabled`,自身显式传的值优先。
600
+ - `loading` 的按钮不再设 `pointer-events: none`:鼠标点击停在按钮上,不再穿透到外层元素,悬停时显示 `not-allowed` 光标(同 Ant Design 在点击处理中直接返回)。
601
+
602
+ - `disabled`、`size`、`type`、`theme`、`colorful` 只是子按钮的默认值,子按钮自己的值优先(`theme` 原为组优先),显式传 `undefined` 视同未传;ButtonGroup 与其中的 Button 放在 InputGroup 里时,未设置的 `size`、`disabled` 取 InputGroup 的(见 Input、TextArea)。ButtonGroup 的全局默认值(`overrideDefaultProps.ButtonGroup`)排在外层 ButtonGroup 与 InputGroup 之后,不再盖过组的值。
603
+ - `data-*`、`id`、`aria-*`、事件等其余属性落在 `role="group"` 根元素,不再传给每个子按钮,传入的 `role` 覆盖默认的 `group`;组值经 context 下发,被 Tooltip、Popover 包住的后代按钮也继承,弹层内容与组内 Modal、SideSheet 里的按钮不继承;Fragment 与数组子节点被展开。
604
+ - Svelte:分隔线服务端首帧没有,挂载后补上;组内任意后代 Button 都画分隔线,不限直接子项。
605
+ - Svelte 破坏性(深路径导入):`button/context` 的 `getButtonGroupContext` 改为返回原始 context(含弹层内容里收到的外层组),排除弹层的版本改名 `getButtonGroupInScope`。