@fibrae/semi-ui-svelte 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +8 -4
  2. package/README.zh-CN.md +8 -4
  3. package/dist/components/anchor/interface.d.ts +14 -0
  4. package/dist/components/audio-player/interface.d.ts +5 -0
  5. package/dist/components/auto-complete/interface.d.ts +29 -0
  6. package/dist/components/avatar/interface.d.ts +24 -0
  7. package/dist/components/backtop/interface.d.ts +2 -0
  8. package/dist/components/badge/interface.d.ts +7 -0
  9. package/dist/components/banner/interface.d.ts +7 -0
  10. package/dist/components/breadcrumb/interface.d.ts +10 -0
  11. package/dist/components/button/interface.d.ts +18 -0
  12. package/dist/components/calendar/interface.d.ts +16 -0
  13. package/dist/components/card/interface.d.ts +18 -0
  14. package/dist/components/carousel/interface.d.ts +16 -0
  15. package/dist/components/cascader/cascader.svelte +1 -0
  16. package/dist/components/cascader/interface.d.ts +57 -0
  17. package/dist/components/checkbox/interface.d.ts +19 -0
  18. package/dist/components/code-highlight/interface.d.ts +3 -0
  19. package/dist/components/collapse/interface.d.ts +16 -0
  20. package/dist/components/collapsible/interface.d.ts +10 -0
  21. package/dist/components/color-picker/interface.d.ts +10 -0
  22. package/dist/components/config-provider/interface.d.ts +7 -0
  23. package/dist/components/cropper/interface.d.ts +11 -0
  24. package/dist/components/date-picker/interface.d.ts +47 -0
  25. package/dist/components/descriptions/interface.d.ts +6 -0
  26. package/dist/components/divider/interface.d.ts +4 -0
  27. package/dist/components/dropdown/interface.d.ts +8 -0
  28. package/dist/components/empty/interface.d.ts +7 -0
  29. package/dist/components/feedback/interface.d.ts +16 -0
  30. package/dist/components/float-button/interface.d.ts +14 -0
  31. package/dist/components/form/interface.d.ts +47 -0
  32. package/dist/components/form/label.svelte +2 -2
  33. package/dist/components/grid/interface.d.ts +13 -0
  34. package/dist/components/highlight/interface.d.ts +7 -0
  35. package/dist/components/hot-keys/interface.d.ts +3 -0
  36. package/dist/components/image/interface.d.ts +59 -0
  37. package/dist/components/input/interface.d.ts +67 -0
  38. package/dist/components/input-number/interface.d.ts +24 -0
  39. package/dist/components/json-viewer/interface.d.ts +7 -0
  40. package/dist/components/layout/interface.d.ts +3 -0
  41. package/dist/components/list/interface.d.ts +18 -0
  42. package/dist/components/locale/interface.d.ts +4 -0
  43. package/dist/components/lottie/interface.d.ts +2 -0
  44. package/dist/components/markdown-render/interface.d.ts +5 -0
  45. package/dist/components/modal/interface.d.ts +29 -0
  46. package/dist/components/navigation/interface.d.ts +47 -0
  47. package/dist/components/overflow-list/interface.d.ts +11 -0
  48. package/dist/components/pagination/interface.d.ts +12 -0
  49. package/dist/components/pincode/interface.d.ts +8 -0
  50. package/dist/components/popconfirm/interface.d.ts +12 -0
  51. package/dist/components/popover/interface.d.ts +30 -0
  52. package/dist/components/progress/interface.d.ts +13 -0
  53. package/dist/components/radio/interface.d.ts +22 -0
  54. package/dist/components/rating/interface.d.ts +12 -0
  55. package/dist/components/resizable/interface.d.ts +30 -0
  56. package/dist/components/scroll-list/interface.d.ts +6 -0
  57. package/dist/components/select/interface.d.ts +63 -0
  58. package/dist/components/side-sheet/interface.d.ts +19 -0
  59. package/dist/components/skeleton/interface.d.ts +7 -0
  60. package/dist/components/slider/interface.d.ts +23 -0
  61. package/dist/components/space/interface.d.ts +4 -0
  62. package/dist/components/spin/interface.d.ts +7 -0
  63. package/dist/components/steps/interface.d.ts +9 -0
  64. package/dist/components/switch/interface.d.ts +7 -0
  65. package/dist/components/table/interface.d.ts +48 -0
  66. package/dist/components/tabs/interface.d.ts +29 -0
  67. package/dist/components/tag/interface.d.ts +22 -0
  68. package/dist/components/tag-input/interface.d.ts +29 -0
  69. package/dist/components/time-picker/interface.d.ts +31 -0
  70. package/dist/components/timeline/interface.d.ts +5 -0
  71. package/dist/components/tooltip/interface.d.ts +20 -0
  72. package/dist/components/tooltip/tooltip.svelte +3 -0
  73. package/dist/components/transfer/interface.d.ts +18 -0
  74. package/dist/components/tree/interface.d.ts +45 -0
  75. package/dist/components/tree-select/interface.d.ts +55 -0
  76. package/dist/components/typography/interface.d.ts +33 -0
  77. package/dist/components/upload/interface.d.ts +64 -0
  78. package/dist/components/user-guide/interface.d.ts +15 -0
  79. package/dist/components/video-player/interface.d.ts +22 -0
  80. package/dist/styles.css +1 -1
  81. package/docs/advanced/dark-mode.md +288 -0
  82. package/docs/basic/button.md +605 -0
  83. package/docs/basic/divider.md +103 -0
  84. package/docs/basic/float-button.md +246 -0
  85. package/docs/basic/grid.md +427 -0
  86. package/docs/basic/layout.md +459 -0
  87. package/docs/basic/resizable.md +584 -0
  88. package/docs/basic/space.md +163 -0
  89. package/docs/basic/tokens.md +425 -0
  90. package/docs/basic/typography.md +615 -0
  91. package/docs/changes-from-semi.md +105 -0
  92. package/docs/ecosystem/tailwind.md +210 -0
  93. package/docs/experience/accessibility.md +82 -0
  94. package/docs/experience/content-guidelines.md +819 -0
  95. package/docs/experience/internationalization.md +7 -0
  96. package/docs/feedback/banner.md +198 -0
  97. package/docs/feedback/feedback.md +294 -0
  98. package/docs/feedback/notification.md +401 -0
  99. package/docs/feedback/popconfirm.md +243 -0
  100. package/docs/feedback/progress.md +389 -0
  101. package/docs/feedback/skeleton.md +388 -0
  102. package/docs/feedback/spin.md +172 -0
  103. package/docs/feedback/toast.md +393 -0
  104. package/docs/input/auto-complete.md +399 -0
  105. package/docs/input/cascader.md +1558 -0
  106. package/docs/input/checkbox.md +408 -0
  107. package/docs/input/color-picker.md +175 -0
  108. package/docs/input/date-picker.md +942 -0
  109. package/docs/input/form.md +2550 -0
  110. package/docs/input/input-number.md +451 -0
  111. package/docs/input/input.md +640 -0
  112. package/docs/input/pincode.md +191 -0
  113. package/docs/input/radio.md +337 -0
  114. package/docs/input/rating.md +214 -0
  115. package/docs/input/select.md +1230 -0
  116. package/docs/input/slider.md +347 -0
  117. package/docs/input/switch.md +206 -0
  118. package/docs/input/tag-input.md +465 -0
  119. package/docs/input/time-picker.md +358 -0
  120. package/docs/input/transfer.md +1061 -0
  121. package/docs/input/tree-select.md +1300 -0
  122. package/docs/input/upload.md +1811 -0
  123. package/docs/llms.txt +147 -0
  124. package/docs/navigation/anchor.md +377 -0
  125. package/docs/navigation/backtop.md +100 -0
  126. package/docs/navigation/breadcrumb.md +284 -0
  127. package/docs/navigation/navigation.md +851 -0
  128. package/docs/navigation/pagination.md +217 -0
  129. package/docs/navigation/steps.md +315 -0
  130. package/docs/navigation/tabs.md +754 -0
  131. package/docs/navigation/tree.md +1956 -0
  132. package/docs/other/config-provider.md +599 -0
  133. package/docs/other/locale.md +353 -0
  134. package/docs/plus/audio-player.md +155 -0
  135. package/docs/plus/code-highlight.md +150 -0
  136. package/docs/plus/drag-move.md +214 -0
  137. package/docs/plus/hot-keys.md +174 -0
  138. package/docs/plus/json-viewer.md +392 -0
  139. package/docs/plus/lottie.md +176 -0
  140. package/docs/plus/markdown-render.md +240 -0
  141. package/docs/plus/video-player.md +325 -0
  142. package/docs/show/avatar.md +475 -0
  143. package/docs/show/badge.md +276 -0
  144. package/docs/show/calendar.md +352 -0
  145. package/docs/show/card.md +485 -0
  146. package/docs/show/carousel.md +592 -0
  147. package/docs/show/collapse.md +289 -0
  148. package/docs/show/collapsible.md +216 -0
  149. package/docs/show/cropper.md +285 -0
  150. package/docs/show/descriptions.md +325 -0
  151. package/docs/show/dropdown.md +466 -0
  152. package/docs/show/empty.md +225 -0
  153. package/docs/show/highlight.md +144 -0
  154. package/docs/show/image.md +433 -0
  155. package/docs/show/list.md +927 -0
  156. package/docs/show/modal.md +517 -0
  157. package/docs/show/overflow-list.md +272 -0
  158. package/docs/show/popover.md +534 -0
  159. package/docs/show/scroll-list.md +156 -0
  160. package/docs/show/side-sheet.md +274 -0
  161. package/docs/show/table.md +5437 -0
  162. package/docs/show/tag.md +428 -0
  163. package/docs/show/timeline.md +277 -0
  164. package/docs/show/tooltip.md +442 -0
  165. package/docs/show/user-guide.md +419 -0
  166. package/docs/start/getting-started.md +234 -0
  167. package/docs/start/introduction.md +57 -0
  168. package/docs/start/overview.md +21 -0
  169. package/package.json +5 -4
@@ -0,0 +1,353 @@
1
+ # LocaleProvider
2
+
3
+ > Internationalized components to provide multilingual support for Semi components
4
+
5
+ Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/other/locale/
6
+
7
+ ## Built-in languages
8
+
9
+ | Language | Export |
10
+ | - | - |
11
+ | Simplified Chinese | `zh_CN` |
12
+ | English (US) | `en_US` |
13
+
14
+ Both packs come from the `/locale` entry of the UI package, for example `import { en_US } from '@fibrae/semi-ui-react/locale'`. For any other language, write your own pack; see [Custom locale packs](#custom-locale-packs).
15
+
16
+ ## Components supported
17
+
18
+ Calendar、Cascader、Chat、DatePicker、Form、Image、List、Modal、Navigation、Nav、Pagination、Popconfirm、Select、Table、TimePicker、Transfer、Tree、TreeSelect、Typography、Upload
19
+
20
+ ## How to use
21
+
22
+ `LocaleProvider` passes the locale pack to its descendants through context, and you only need to wrap the periphery of the application once to take effect globally.\
23
+ When you need to switch the language, bind `locale` to state that changes; the subtree updates automatically.
24
+
25
+ ```svelte
26
+ <script lang="ts">
27
+ import { LocaleProvider } from '@fibrae/semi-ui-svelte';
28
+ import { en_US } from '@fibrae/semi-ui-svelte/locale';
29
+ </script>
30
+
31
+ <LocaleProvider locale={en_US}>
32
+ <App />
33
+ </LocaleProvider>
34
+ ```
35
+
36
+ When `locale` is omitted, LocaleProvider inherits the language of the outer LocaleProvider; without any outer provider, `zh_CN` is used. The `locale` of ConfigProvider takes precedence over LocaleProvider.
37
+
38
+ ### date-fns locale of date components
39
+
40
+ DatePicker, TimePicker and Calendar format and parse dates with date-fns. Locale packs hold only text, not date-fns locale data: these components pick the built-in zh-CN or en-US by the current locale's `code`, and use enUS for other languages. For another language, import it from `date-fns/locale` and pass it to the `dateFnsLocale` of ConfigProvider, for example `ja` from `date-fns/locale/ja` alongside a Japanese locale pack. Only the imported languages reach the bundle, and server rendering and the first client render use the same locale object.
41
+
42
+ ## Code example
43
+
44
+ ### Internationalization
45
+
46
+ ```svelte
47
+ <script lang="ts">
48
+ import { LocaleProvider, Pagination } from '@fibrae/semi-ui-svelte';
49
+ import { en_US, zh_CN } from '@fibrae/semi-ui-svelte/locale';
50
+ </script>
51
+
52
+ <LocaleProvider locale={en_US}>
53
+ <Pagination showSizeChanger showTotal style="margin: 20px" total={100} />
54
+ </LocaleProvider>
55
+ <LocaleProvider locale={zh_CN}>
56
+ <Pagination showSizeChanger showTotal style="margin: 20px" total={100} />
57
+ </LocaleProvider>
58
+ ```
59
+
60
+ ### Custom locale packs
61
+
62
+ For a language that is not built in, write your own pack after the `Locale` type and pass it to the `locale` of ConfigProvider or LocaleProvider. `locale` is typed `LocaleInput`, exported from the UI package alongside `Locale`: only `code` is required, so write just the components and keys you translate. Every text or `currency` the pack leaves out falls back to `en_US`.
63
+
64
+ - `code` picks the built-in date-fns locale of the date components, and is the `localeCode` that LocaleConsumer and `useLocale` read.
65
+ - The date-fns locale of the date components goes separately through the `dateFnsLocale` of ConfigProvider; see the previous section.
66
+ - Create the pack object once, at module level or memoized. Components cache the filled-in text per object, so mutating it in place has no effect; pass a new object instead.
67
+
68
+ The example translates only the page buttons and jump text of Pagination and the placeholder of DatePicker; the total, the page size and the text in the date panel fall back to English.
69
+
70
+ ```svelte
71
+ <script lang="ts">
72
+ import { ja } from 'date-fns/locale/ja';
73
+ import { ConfigProvider, DatePicker, Pagination } from '@fibrae/semi-ui-svelte';
74
+ import type { LocaleInput } from '@fibrae/semi-ui-svelte/locale';
75
+
76
+ const ja_JP: LocaleInput = {
77
+ code: 'ja-JP',
78
+ currency: 'JPY',
79
+ Pagination: { prev: '前へ', next: '次へ', jumpTo: 'ページへ', page: 'ページ' },
80
+ DatePicker: { placeholder: { date: '日付を選択してください' } },
81
+ };
82
+ </script>
83
+
84
+ <ConfigProvider dateFnsLocale={ja} locale={ja_JP}>
85
+ <Pagination showQuickJumper showSizeChanger showTotal style="margin: 20px" total={100} />
86
+ <DatePicker style="margin: 20px; width: 250px" />
87
+ </ConfigProvider>
88
+ ```
89
+
90
+ ### Custom Internationalization Component
91
+
92
+ When your custom component also wants to consume the localeCode in the Semi LocaleProvider or read the i18n text of a specific component, use LocaleConsumer. Its `children` snippet receives `{ locale, localeCode, currency }`. During component initialisation, you can also call `useLocale(componentName)`, which returns a getter; call it to read the same three fields. The language priority is ConfigProvider, LocaleProvider, then `zh_CN`. Custom namespaces (`ComponentA` in the example) extend the `Locale` type through declaration merging.
93
+
94
+ ```svelte
95
+ <script lang="ts" module>
96
+ // Custom component text joins the Locale type through declaration merging
97
+ declare module '@fibrae/semi-foundation/locale/interface' {
98
+ export interface Locale {
99
+ ComponentA: { customKey: string };
100
+ }
101
+ }
102
+ </script>
103
+
104
+ <script lang="ts">
105
+ import { LocaleConsumer, LocaleProvider } from '@fibrae/semi-ui-svelte';
106
+ import { en_US, zh_CN } from '@fibrae/semi-ui-svelte/locale';
107
+
108
+ const locales = [
109
+ { ...zh_CN, ComponentA: { customKey: 'semi' } },
110
+ { ...en_US, ComponentA: { customKey: 'design' } },
111
+ ];
112
+ </script>
113
+
114
+ {#each locales as locale (`semi-${locale.code}`)}
115
+ <LocaleProvider {locale}>
116
+ <LocaleConsumer componentName="TimePicker">
117
+ {#snippet children(consumer)}
118
+ <div>{consumer.localeCode} : {consumer.locale.begin}</div>
119
+ {/snippet}
120
+ </LocaleConsumer>
121
+ </LocaleProvider>
122
+ {/each}
123
+ {#each locales as locale (`custom-${locale.code}`)}
124
+ <LocaleProvider {locale}>
125
+ <LocaleConsumer componentName="ComponentA">
126
+ {#snippet children(consumer)}
127
+ <div>{consumer.locale.customKey}</div>
128
+ {/snippet}
129
+ </LocaleConsumer>
130
+ </LocaleProvider>
131
+ {/each}
132
+ ```
133
+
134
+ ### Components that support multilingualism
135
+
136
+ The example gives all the current multilingual components
137
+
138
+ When your site needs RTL support, use ConfigProvider directly: besides `locale`, it also configures `direction='rtl'`/`'ltr'`.\
139
+ Without RTL needs, LocaleProvider is enough.
140
+
141
+ ```svelte
142
+ <script lang="ts">
143
+ import { IconSemiLogo, IconStar, IconUser } from '@fibrae/semi-icons-svelte';
144
+ import { Button, Calendar, Cascader, ConfigProvider, DatePicker, Form, FormInput, Image, ImagePreview, List, LocaleProvider, Modal, Nav, Pagination, Select, Table, TimePicker, Transfer, TreeSelect, Typography, type ColumnProps, type NavItems } from '@fibrae/semi-ui-svelte';
145
+ import { en_US, zh_CN } from '@fibrae/semi-ui-svelte/locale';
146
+
147
+ const treeData = [
148
+ {
149
+ label: 'Asia',
150
+ value: 'asia',
151
+ key: '1',
152
+ children: [
153
+ {
154
+ label: 'China',
155
+ value: 'china',
156
+ key: '1-0',
157
+ children: [
158
+ { label: 'Beijing', value: 'beijing', key: '1-0-0' },
159
+ { label: 'Shanghai', value: 'shanghai', key: '1-0-1' },
160
+ ],
161
+ },
162
+ {
163
+ label: 'Japan',
164
+ value: 'japan',
165
+ key: '1-1',
166
+ children: [{ label: 'Osaka', value: 'osaka', key: '1-1-0' }],
167
+ },
168
+ ],
169
+ },
170
+ ];
171
+
172
+ const columns: ColumnProps[] = [
173
+ { title: 'Name', width: 250, dataIndex: 'name' },
174
+ { title: 'Age', width: 150, dataIndex: 'age' },
175
+ { title: 'Address', dataIndex: 'address' },
176
+ ];
177
+ const dataSource = Array.from({ length: 46 }, (_, i) => ({
178
+ key: String(i),
179
+ name: `Example ${i}`,
180
+ age: 32,
181
+ address: `Beijing, Haidian. Zhichun Road ${i}`,
182
+ }));
183
+ const transferData = Array.from({ length: 100 }, (_, i) => ({
184
+ label: `选项名称 ${i}`,
185
+ value: i,
186
+ disabled: false,
187
+ key: i,
188
+ }));
189
+ const srcList = ['/assets/root-web-sites/abstract.jpg', '/assets/root-web-sites/sky.jpg', '/assets/root-web-sites/greenleaf.jpg', '/assets/root-web-sites/colorful.jpg'];
190
+ const navItems: NavItems = [
191
+ { itemKey: 'user', text: '用户管理' },
192
+ { itemKey: 'union', text: '活动管理' },
193
+ ];
194
+ const navIcons = { user: IconUser, union: IconStar };
195
+
196
+ const languageOptions = [
197
+ { value: 'zh_CN', label: '简体中文' },
198
+ { value: 'en_US', label: '英语(美)' },
199
+ ];
200
+
201
+ let localeCode = $state('zh_CN');
202
+ const locale = $derived(localeCode === 'en_US' ? en_US : zh_CN);
203
+ let modalVisible = $state(false);
204
+ const closeModal = () => {
205
+ modalVisible = false;
206
+ };
207
+ </script>
208
+
209
+ <div>
210
+ <div style="border-block-end: 1px solid var(--semi-color-border); padding-block-end: 20px">
211
+ <Select aria-label="切换语言" onChange={(value) => (localeCode = String(value))} optionList={languageOptions} style="width: 250px" value={localeCode}>
212
+ {#snippet prefix()}切换语言{/snippet}
213
+ </Select>
214
+ </div>
215
+ <LocaleProvider {locale}>
216
+ <ConfigProvider {locale}>
217
+ {#key localeCode}
218
+ <div>
219
+ <h5>Pagination</h5>
220
+ <Pagination showQuickJumper showSizeChanger showTotal style="margin: 10px" total={100} />
221
+ <h5>Modal</h5>
222
+ <div style="margin: 10px">
223
+ <Button onclick={() => (modalVisible = true)}>Show Modal</Button>
224
+ <Modal bind:visible={modalVisible} onCancel={closeModal} onOk={closeModal} title="Modal">
225
+ <p>This is the content of a basic modal.</p>
226
+ <p>More content...</p>
227
+ </Modal>
228
+ </div>
229
+ <h5>Select &amp; Cascader</h5>
230
+ <div style="margin: 10px">
231
+ <Select
232
+ aria-label="Select"
233
+ filter
234
+ optionList={[
235
+ { value: 'abc', label: 'abc' },
236
+ { value: 'vigo', label: 'vigo', disabled: true },
237
+ { value: 'hotsoon', label: 'hotsoon' },
238
+ ]}
239
+ style="width: 180px"
240
+ />
241
+ <Cascader filterTreeNode style="width: 300px; margin: 10px" {treeData}>
242
+ {#snippet prefix()}Cascader{/snippet}
243
+ </Cascader>
244
+ </div>
245
+ <h5>DatePicker</h5>
246
+ <DatePicker style="margin: 10px; width: 250px" />
247
+ <DatePicker style="margin: 10px; width: 300px" type="dateTime" />
248
+ <DatePicker style="margin: 10px; width: 300px" type="dateRange" />
249
+ <DatePicker style="margin: 10px; width: 450px" type="dateTimeRange" />
250
+ <h5>TimePicker</h5>
251
+ <TimePicker style="margin: 10px" />
252
+ <TimePicker style="margin: 10px" use12Hours />
253
+ <br />
254
+ <br />
255
+ <h5>TreeSelect</h5>
256
+ <TreeSelect filterTreeNode style="margin: 10px; width: 300px" styles={{ dropdown: 'max-height: 400px; overflow: auto' }} {treeData} />
257
+ <h5>Table</h5>
258
+ <Table {columns} {dataSource} scroll={{ y: 320 }} />
259
+ <h5>Table - Empty</h5>
260
+ <Table {columns} dataSource={[]} scroll={{ y: 320 }} />
261
+ <h5>List - Empty</h5>
262
+ <List dataSource={[]}>
263
+ {#snippet header()}
264
+ <div>List</div>
265
+ {/snippet}
266
+ </List>
267
+ <h5>Calendar</h5>
268
+ <Calendar displayValue={new Date(2024, 4, 6, 12)} mode="month" />
269
+ <h5>Typography - Copyable</h5>
270
+ <Typography.Paragraph copyable>Click to copy text.</Typography.Paragraph>
271
+ <h5>Typography - Collapsible</h5>
272
+ <Typography.Paragraph ellipsis={{ rows: 3, expandable: true, collapsible: true }} style="width: 300px">
273
+ 支持展开和折叠:Semi Design Next 是 Semi Design 的社区版设计系统,一套组件在 React、Vue、Solid、Svelte 中原生可用。设计系统包含设计语言以及一整套可复用的前端组件,帮助设计师与开发者更容易地打造高质量的、用户体验一致的、符合设计规范的 Web 应用。
274
+ </Typography.Paragraph>
275
+ <h5>Transfer</h5>
276
+ <Transfer dataSource={transferData} style="width: 568px; height: 416px" />
277
+ <h5>Image</h5>
278
+ <ImagePreview showTooltip src={srcList}>
279
+ {#each srcList as src, index (src)}
280
+ <Image alt="lamp{index + 1}" {src} style="margin-inline-end: 5px" width={200} />
281
+ {/each}
282
+ </ImagePreview>
283
+ <h5>Form</h5>
284
+ <Form layout="horizontal" onValueChange={(values) => console.log(values)}>
285
+ <FormInput field="UserName" label={{ text: '角色', optional: true }} style="width: 200px" />
286
+ </Form>
287
+ <h5>Navigation</h5>
288
+ <Nav footer={{ collapseButton: true }} items={navItems} styles={{ body: 'height: 320px' }}>
289
+ {#snippet header()}
290
+ <Nav.Header text="Semi 数据后台">
291
+ {#snippet logo()}
292
+ <IconSemiLogo style="height: 36px; font-size: 36px" />
293
+ {/snippet}
294
+ </Nav.Header>
295
+ {/snippet}
296
+ {#snippet icon({ item, size })}
297
+ {@const Icon = navIcons[item.itemKey as keyof typeof navIcons]}
298
+ {#if Icon}
299
+ <Icon {size} />
300
+ {/if}
301
+ {/snippet}
302
+ </Nav>
303
+ </div>
304
+ {/key}
305
+ </ConfigProvider>
306
+ </LocaleProvider>
307
+ </div>
308
+ ```
309
+
310
+ ## API Reference
311
+
312
+ ---
313
+
314
+ ### LocaleProvider
315
+
316
+ **Props**
317
+
318
+ | Property | Description | Type | Default |
319
+ | - | - | - | - |
320
+ | children | Subtree that uses the locale pack. | `Snippet` | - |
321
+ | locale | Locale pack. When omitted, undefined or null, the language of the outer LocaleProvider is inherited; without any outer provider, components fall back to zh\_CN. The locale of ConfigProvider takes precedence over it. Takes the built-in zh\_CN or en\_US, or a custom pack with at least code, whose missing text and currency fall back to en\_US. | `LocaleInput \| null` | - |
322
+
323
+ LocaleProvider renders no DOM element, so `class`, `style` and native attributes and events are not applied to the page.
324
+
325
+ ### LocaleConsumer
326
+
327
+ **Props**
328
+
329
+ | Property | Description | Type | Default |
330
+ | - | - | - | - |
331
+ | children | Snippet receiving `{ locale, localeCode, currency }`, where locale is the text of componentName. | `Snippet<[result: LocaleResult<Locale[K]>]>` | - |
332
+ | componentName | Namespace of the locale pack to read, such as TimePicker. Only component names declared in Locale are accepted; extend Locale by declaration merging for custom namespaces. | `K` | - |
333
+
334
+ LocaleConsumer renders no element of its own, so `class`, `style` and native attributes and events are not applied to the page.
335
+
336
+ ### useLocale
337
+
338
+ `useLocale(componentName)` returns a `() => LocaleResult` getter; call it to read the result. `componentName` can be a string or a function that returns a string.
339
+
340
+ | Field | Description | Type |
341
+ | - | - | - |
342
+ | locale | Text of the namespace named by `componentName` | `Locale[K]` |
343
+ | localeCode | Language code | string |
344
+ | currency | ISO 4217 currency code of the language's region | string |
345
+
346
+ ## Changes from Semi Design
347
+
348
+ From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
349
+
350
+ - 破坏性:LocaleProvider 不传 `locale` 时继承外层语言,不再重置为 zh_CN;最外层不传时 context 值为 `undefined`(Vue、Solid 为 `null`)。
351
+ - 破坏性:语言包与 `Locale` 类型删除 `dateFnsLocale`,`useLocale` 的返回值与 LocaleConsumer 的回调参数(Vue 的作用域插槽、Svelte 的 snippet 参数)不再提供它;React、Solid 的 LocaleConsumer children 改为 `(componentLocale, localeCode, currency)`。DatePicker、TimePicker、Calendar 按语言包的 `code` 取内置的 zh-CN、en-US date-fns 语言,其他语言回落 enUS(月份、星期、上下午与 Calendar 的可访问名称显示为英文);需要其他语言时从 `date-fns/locale` 导入并传给 ConfigProvider 的 `dateFnsLocale`。只用文案的组件不再打包 date-fns 语言数据。
352
+ - 破坏性(类型):LocaleConsumer 的 `componentName` 必填,只接受 `LocaleComponentName`,泛型参数改为组件名(`<LocaleConsumer<Locale['Chat']>>` 改为 `<'Chat'>`)。`useLocale` 不再接受 `'code'`、`'currency'`,改读返回值的 `localeCode`、`currency`。
353
+ - Svelte:`useLocale(name)` 返回函数,读取写成 `locale().locale.xxx`;`LocaleConsumer` 的内容写在 `children` snippet 中。最外层不传 `locale` 时 context 值为 `null`(同 Vue)。
@@ -0,0 +1,155 @@
1
+ # AudioPlayer
2
+
3
+ > Used to play audio
4
+
5
+ Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/plus/audio-player/
6
+
7
+ ## Demos
8
+
9
+ ### How to import
10
+
11
+ ```svelte
12
+ <script lang="ts">
13
+ import { AudioPlayer } from '@fibrae/semi-ui-svelte';
14
+ </script>
15
+ ```
16
+
17
+ ### Basic Usage
18
+
19
+ Basic usage by passing audio URL through `audioUrl`.\
20
+ audioUrl supports string, string array, object, and object array. See [AudioPlayer](#AudioPlayer) for detailed parameters.
21
+
22
+ ```svelte
23
+ <script lang="ts">
24
+ import { AudioPlayer } from '@fibrae/semi-ui-svelte';
25
+
26
+ const audioUrl = '/assets/components/audio2.mp3';
27
+ const audioUrlArr = ['/assets/components/audio1.mp3', '/assets/components/audio2.mp3'];
28
+ const audioUrlObj = {
29
+ src: '/assets/components/audio1.mp3',
30
+ title: '音频标题',
31
+ cover: '/assets/root-web-sites/abstract.jpg',
32
+ };
33
+ const audioUrlArrObj = [
34
+ {
35
+ src: '/assets/components/audio1.mp3',
36
+ title: '音频标题1',
37
+ cover: '/assets/root-web-sites/abstract.jpg',
38
+ },
39
+ {
40
+ src: '/assets/components/audio2.mp3',
41
+ title: '音频标题2',
42
+ cover: '/assets/root-web-sites/abstract.jpg',
43
+ },
44
+ ];
45
+ </script>
46
+
47
+ <div style="width: 100%">
48
+ <div style="margin-block-start: 10px">
49
+ <AudioPlayer {audioUrl} autoPlay={false} />
50
+ </div>
51
+ <div style="margin-block-start: 10px">
52
+ <AudioPlayer audioUrl={audioUrlObj} autoPlay={false} />
53
+ </div>
54
+ <div style="margin-block-start: 10px">
55
+ <AudioPlayer audioUrl={audioUrlArr} autoPlay={false} />
56
+ </div>
57
+ <div style="margin-block-start: 10px">
58
+ <AudioPlayer audioUrl={audioUrlArrObj} autoPlay={false} />
59
+ </div>
60
+ </div>
61
+ ```
62
+
63
+ ### Hide Toolbar
64
+
65
+ Set `showToolbar` to `false` to hide the toolbar: the volume, backward, forward, speed and reload buttons.
66
+
67
+ ```svelte
68
+ <script lang="ts">
69
+ import { AudioPlayer } from '@fibrae/semi-ui-svelte';
70
+
71
+ const audioUrlObj = {
72
+ src: '/assets/components/audio1.mp3',
73
+ title: '音频标题',
74
+ };
75
+ </script>
76
+
77
+ <div style="width: 100%">
78
+ <AudioPlayer audioUrl={audioUrlObj} autoPlay={false} showToolbar={false} />
79
+ </div>
80
+ ```
81
+
82
+ ### Theme
83
+
84
+ Set the audio player theme through `theme`, supports `light` and `dark`, default is `dark`. The speed menu and the volume popup render outside the player, so each carries its own theme modifier class matching `theme` (such as `semi-audio-player-control-volume-light`) and follows the theme
85
+
86
+ ```svelte
87
+ <script lang="ts">
88
+ import { AudioPlayer } from '@fibrae/semi-ui-svelte';
89
+
90
+ const audioUrlArrObj = [
91
+ {
92
+ src: '/assets/components/audio1.mp3',
93
+ title: '音频标题1',
94
+ cover: '/assets/root-web-sites/abstract.jpg',
95
+ },
96
+ {
97
+ src: '/assets/components/audio2.mp3',
98
+ title: '音频标题2',
99
+ cover: '/assets/root-web-sites/abstract.jpg',
100
+ },
101
+ ];
102
+ </script>
103
+
104
+ <div style="width: 100%">
105
+ <AudioPlayer audioUrl={audioUrlArrObj} theme="light" />
106
+ </div>
107
+ ```
108
+
109
+ ## Keyboard and focus
110
+
111
+ - Play (pause), previous, next, backward, forward, volume and reload are native buttons. Each is one Tab stop, triggered with Enter or Space; the volume button toggles mute.
112
+ - The progress bar is a native range and one Tab stop: the arrow keys change it by 1 second, PageUp and PageDown by a tenth of the duration, and Home and End jump to the ends.
113
+ - The volume popup, a dialog named "Volume", opens when the volume button receives focus. Down Arrow or Up Arrow moves focus to the volume slider inside it, which takes the same keys as the progress bar, with the arrow keys changing it by 1%. Escape closes the popup and returns focus to the volume button.
114
+ - The speed menu opens when the speed button receives focus. Down Arrow and Up Arrow move focus to the first and last item; inside the menu, the up and down arrow keys, Home and End move between items, Enter or Space selects one, and Escape closes the menu. The speed button is named by its purpose followed by the current speed (such as "Playback speed 1.0x"), and its items are radio items (`menuitemradio`) that mark the current speed with `aria-checked`.
115
+
116
+ ## API Reference
117
+
118
+ ### AudioPlayer
119
+
120
+ **Props**
121
+
122
+ | Property | Description | Type | Default |
123
+ | - | - | - | - |
124
+ | audioUrl | Audio address: a string, an AudioInfo object, or an array of them. An array shows the previous and next track buttons. | `AudioUrl` | - |
125
+ | autoPlay | Whether to play automatically. | `boolean` | `false` |
126
+ | showToolbar | Whether to display the toolbar. | `boolean` | `true` |
127
+ | skipDuration | Seconds skipped by each backward or forward button press. | `number` | `10` |
128
+ | theme | Player theme: dark or light. | `AudioPlayerTheme` | `"dark"` |
129
+
130
+ `class` (a string, array or object) and native attributes land on the root `div`, and `style` is a string. AudioPlayer has no callback props, and native media events of the `audio` element (such as `onended`) cannot be listened to: they do not bubble to the root, so the listener never fires.
131
+
132
+ The root gets `role="group"` when it has `aria-label` or `aria-labelledby`.
133
+
134
+ ### AudioInfo
135
+
136
+ | Property | Description | Type | Default |
137
+ | - | - | - | - |
138
+ | src | Audio address | string | - |
139
+ | title | Audio title | string | - |
140
+ | cover | Cover image | string | - |
141
+
142
+ ## Changes from Semi Design
143
+
144
+ From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
145
+
146
+ - 破坏性(类型):Props 不再接受 `onTimeUpdate`、`onEnded` 等 23 个 React 媒体事件回调及 Capture 变体(从不触发);VideoPlayer 的 `controlsList` 收窄为 `VideoControl[]`,`theme` 收窄为 `'dark' | 'light'`;删除无效的 `forwardRef`,改用 `ref`。
147
+ - VideoPlayer 进度条手柄用 `translate` 居中,`VideoProgressFoundation.getHandleLeft` 返回纯百分比(原 `calc(<百分比> - 8px)`)。
148
+ - 破坏性(深路径导入):删除 `semi-ui-react/video-player/utils`,改从 `@fibrae/semi-foundation/video-player/utils` 导入。
149
+ - VideoPlayer 新增 `onNext`,「下一个」按钮只在传了 `onNext` 且 `controlsList` 允许时显示(原来默认显示);静音改由 `muted` 承载,不再把音量写成 0;`onVolumeChange` 在拖动音量或切换静音时触发。AudioPlayer 时间统一为 `mm:ss`,超 1 小时为 `h:mm:ss`(原 `75:00`),封面不再可预览。AudioPlayer 挂载前音频元数据已加载完(服务端渲染后 hydration、缓存命中)时,挂载时直接读出时长,进度条可拖动、可点击跳转(原来时长停在 0,拖到哪里都跳回开头)。
150
+ - AudioPlayer 进度条圆点与 VideoPlayer 一致,中心对准进度末端,两端时盖住轨道圆角(原来圆点限制在轨道内),进度条两侧留出半个圆点的间距,圆点不压住时间文字;指针按下进度条不再显示键盘焦点环。VideoPlayer 音量与菜单弹层改为不透明深灰底,音量弹层底部增加 12px 留白(高度 160px 改为 168px);两者的弹层与菜单项样式不再依赖样式表加载顺序(原来可能被 Dropdown、Popover 的默认底色与文字色覆盖)。
151
+ - VideoPlayer 进度条圆点在悬停、键盘聚焦或拖动时显示,与轨道同心,进度为 0 时也显示(原来只在悬停播放头所在分段时显示,进度为 0 时不显示,拖动后移出可能一直残留);轨道悬停变粗改为以中心线上下对称的高度过渡;时间预览 Tooltip 不再拦截指针(原来箭头伸进进度条热区,指针移到箭头下时悬停中断,轨道粗细闪烁)。
152
+ - VideoPlayer 的初始 `volume` 取整并夹到不小于 0,音量为 0 时同时静音;销毁时清除计时器,重新显示时按当前状态重新应用音量与倍速。
153
+ - VideoPlayer 传了 `captionsSrc` 时 Safari 也默认显示字幕(原来 Safari 按系统字幕偏好不启用 `default` 字幕轨,播放器又没有字幕开关,字幕始终不显示)。
154
+ - Svelte:`class` 接受 clsx 值,`style` 只接受字符串;媒体事件(play、pause 等)不再透传到根元素,AudioPlayer 没有回调 props;VideoPlayer 的回调为 `onPlay`、`onPause`、`onQualityChange`、`onRateChange`、`onRouteChange`、`onVolumeChange`、`onNext`,经 `bind:this` 后调用 `getVideo()` 取得原生 `<video>`。
155
+ - Svelte:`defaultPlaybackRate`、`defaultQuality`、`defaultRoute` 只在挂载时读取一次,之后变化不再生效;进度条和按钮的 Tooltip 通过 `child` snippet 接入,按钮外层没有额外的 span。
@@ -0,0 +1,150 @@
1
+ # CodeHighlight
2
+
3
+ > Highlight code blocks in the page according to syntax
4
+
5
+ Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/plus/code-highlight/
6
+
7
+ ## When to use
8
+
9
+ Semi `CodeHighlight` component is built on [Shiki](https://shiki.style), which uses the same TextMate grammars as VS Code. The languages to highlight are registered by the application, so the bundle only contains the grammars it registers; an unregistered language is shown as plain text. Colors default to Shiki's built-in `github-light` and `github-dark` themes, follow Semi's light and dark mode, and can be replaced with other themes.
10
+
11
+ ## Demos
12
+
13
+ ### How to introduce
14
+
15
+ ```svelte
16
+ <script lang="ts">
17
+ import { CodeHighlight } from '@fibrae/semi-ui-svelte';
18
+ </script>
19
+ ```
20
+
21
+ ### Register languages and themes
22
+
23
+ Grammars and themes come from the `shiki` package, so install `shiki` in the project first. Call `CodeHighlight.register` once at the application entry: every CodeHighlight can then use those languages.
24
+
25
+ A language passed as `() => import(...)` is fetched when the first code block is highlighted, and then every registered language is fetched, not only the one that block uses. Available languages, their names and aliases are listed in the [Shiki language list](https://shiki.style/languages), and themes in the [Shiki theme list](https://shiki.style/themes). Blocks mounted before the registration highlight again once it happens.
26
+
27
+ The Svelte version has no `CodeHighlight.register`: use the named export `registerCodeHighlight` instead, with the same arguments and the same registry as the other frameworks.
28
+
29
+ ```ts
30
+ import { registerCodeHighlight } from '@fibrae/semi-ui-svelte';
31
+
32
+ registerCodeHighlight({
33
+ languages: [() => import('shiki/langs/javascript.mjs'), () => import('shiki/langs/css.mjs')],
34
+ // Optional, replaces the default github-light and github-dark
35
+ themes: { light: () => import('shiki/themes/min-light.mjs'), dark: () => import('shiki/themes/nord.mjs') },
36
+ });
37
+ ```
38
+
39
+ ### Basic usage
40
+
41
+ Pass the code plain text to `code`, and the name or alias of a registered language to `language`.
42
+
43
+ ```svelte
44
+ <script lang="ts">
45
+ import { CodeHighlight } from '@fibrae/semi-ui-svelte';
46
+
47
+ const code = `
48
+ import * as React from 'react'
49
+ const Test = ()=>{
50
+ const handleClick = ()=>{
51
+ alert("Click")
52
+ }
53
+ return <div onClick={handleClick}>test</div>
54
+ }`;
55
+ </script>
56
+
57
+ <CodeHighlight {code} language="javascript" />
58
+ ```
59
+
60
+ **CSS**
61
+
62
+ ```svelte
63
+ <script lang="ts">
64
+ import { CodeHighlight } from '@fibrae/semi-ui-svelte';
65
+
66
+ const code = `.grid {
67
+ .semi-row {
68
+ text-align: center;
69
+ .semi-col {
70
+ min-height: 30px;
71
+ line-height: 30px;
72
+ background: var(--semi-color-primary-light-default);
73
+ outline: 1px solid var(--semi-color-primary-light-active);
74
+ }
75
+ }
76
+ }
77
+ `;
78
+ </script>
79
+
80
+ <CodeHighlight {code} language="css" />
81
+ ```
82
+
83
+ ### Languages for a single block
84
+
85
+ A language only a few blocks need can be passed to those blocks through `languages` instead of being registered for the whole application; `themes` likewise replaces the themes of one block. Declare both values outside the component, so a new array or object on every render does not trigger another highlight. For example, to highlight the Vala language used to write the front-end UI of GTK programs
86
+
87
+ ```svelte
88
+ <script lang="ts">
89
+ import { CodeHighlight } from '@fibrae/semi-ui-svelte';
90
+
91
+ const languages = [() => import('shiki/langs/vala.mjs')];
92
+
93
+ const code = `public class ExampleApp : Gtk.Application {
94
+ public ExampleApp () {
95
+ Object (application_id: "com.example.App");
96
+ }
97
+
98
+ public override void activate () {
99
+ var win = new Gtk.ApplicationWindow (this);
100
+
101
+ var btn = new Gtk.Button.with_label ("Hello World");
102
+ btn.clicked.connect (win.close);
103
+
104
+ win.child = btn;
105
+ win.present ();
106
+ }
107
+
108
+ public static int main (string[] args) {
109
+ var app = new ExampleApp ();
110
+ return app.run (args);
111
+ }
112
+ }
113
+ `;
114
+ </script>
115
+
116
+ <CodeHighlight {code} language="vala" {languages} />
117
+ ```
118
+
119
+ ### API
120
+
121
+ **Props**
122
+
123
+ | Property | Description | Type | Default |
124
+ | - | - | - | - |
125
+ | code | Plain text of the code, treated as an empty string when omitted. After code changes the new text shows first and is replaced once highlighting finishes. | `string` | - |
126
+ | language | Language, which must be registered or passed through languages. | `string` | - |
127
+ | languages | Extra Shiki grammars for this block; once loaded, other blocks can use them too. Declare it at the top level of the script, not as an inline array in the template, which would highlight again on every render. | `LanguageInput[]` | - |
128
+ | lineNumber | Whether to show line numbers. | `boolean` | `true` |
129
+ | themes | Replaces the Shiki themes of this block for light and dark mode. | `CodeHighlightThemes` | - |
130
+
131
+ `class`, `style` (a string) and native attributes such as `id` and `aria-label` land on the root element (`div`). The component has no static methods: register languages and themes with the named export `registerCodeHighlight`, see "Register languages and themes" above.
132
+
133
+ ### Static methods
134
+
135
+ | Method | Description | Type |
136
+ | - | - | - |
137
+ | CodeHighlight.register | Registers languages for every CodeHighlight and replaces the default themes; can be called repeatedly, languages add up and themes override | (options: { languages?: LanguageInput\[]; themes?: { light?: ThemeInput; dark?: ThemeInput } }) => void |
138
+
139
+ ## Accessibility
140
+
141
+ - With `aria-label` or `aria-labelledby` and no `role` on the root, the root gets `role="group"` (a generic element cannot be named); a `role` you pass wins
142
+
143
+ ## Design Tokens
144
+
145
+ ## Changes from Semi Design
146
+
147
+ From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
148
+
149
+ - 由 prismjs 改用 shiki:`language` 取 shiki 语言名与别名,未知语言按纯文本;配色为 `github-light`、`github-dark`;删除 `defaultTheme`,`.token.*` 类名不再存在,基于 Prism 的自定义主题 CSS 失效;高亮异步完成,首帧为纯文本。不再内置语言,经 `CodeHighlight.register({ languages, themes })` 或 `languages`、`themes` 属性提供;`code` 改为可选。
150
+ - Svelte:注册改用命名导出 `registerCodeHighlight({ languages, themes })`,没有 `CodeHighlight.register`,与其他框架共用注册表。