@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.
- 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/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/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/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/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,851 @@
|
|
|
1
|
+
# Navigation
|
|
2
|
+
|
|
3
|
+
> A menu list that provides navigation for pages and features.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/navigation/navigation/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Nav } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`NavItem`, `SubNav`, `NavHeader` and `NavFooter` stand for Nav.Item, Nav.Sub, Nav.Header and Nav.Footer, and are imported by name.
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
|
|
21
|
+
By passing `items` Parameters, you can quickly get a navigation bar.
|
|
22
|
+
|
|
23
|
+
- `itemKey`: Unique identifier of the navigation item (required)
|
|
24
|
+
- `text`: Navigation copywriting
|
|
25
|
+
|
|
26
|
+
`items` holds data only. Icons are provided through the `icon` snippet of Nav, whose parameter is `{ item, level, size }`; pass `size` to the icon: `<Icon {size} />`. You can pick icons from `@fibrae/semi-icons-svelte` and `@fibrae/semi-icons-svelte/lab`, see the [Icon documentation](https://semi-design-next.pages.dev/en-US/svelte/basic/icon/). The shown text and the toggle and expand arrows come from the `text`, `toggleIcon` and `expandIcon` snippets in the same way.
|
|
27
|
+
|
|
28
|
+
For the meaning of the parameters, see [Nav.Item](#Nav.Item) Or [Nav.Sub](#Nav.Sub)
|
|
29
|
+
|
|
30
|
+
Developers may often define the Logo area and the put away button area, while Navigation provides such a container for developers to quickly define the navigation head and bottom, and you only need to pass in the `header` or `footer` as required.
|
|
31
|
+
|
|
32
|
+
For `footer`, semi-ui extra encapsulates a pull-up feature button that developers can pass through `collapseButton = true` to turn on the function, but the parameter takes effect only with `mode = "vertical"` (Vertical navigation).
|
|
33
|
+
|
|
34
|
+
`header` and `footer` can be a data configuration or a snippet. A configuration object holds data only, and the `logo` of `header` is a snippet. For other nodes, use `NavHeader` and `NavFooter` inside a snippet (they are not picked up from the children of Nav).
|
|
35
|
+
|
|
36
|
+
For the parameters, see [Nav.Header](#Nav.Header) and [Nav.Footer](#Nav.Footer).
|
|
37
|
+
|
|
38
|
+
```svelte
|
|
39
|
+
<script lang="ts">
|
|
40
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
41
|
+
import { IconAvatar, IconDescriptions, IconTree } from '@fibrae/semi-icons-svelte/lab';
|
|
42
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
43
|
+
|
|
44
|
+
const items: NavItems = [
|
|
45
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
46
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
47
|
+
{ itemKey: 'job', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
48
|
+
];
|
|
49
|
+
const icons = { user: IconAvatar, union: IconDescriptions, job: IconTree };
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
{#snippet header()}
|
|
53
|
+
<Nav.Header text="Semi 运营后台">
|
|
54
|
+
{#snippet logo()}
|
|
55
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
56
|
+
{/snippet}
|
|
57
|
+
</Nav.Header>
|
|
58
|
+
{/snippet}
|
|
59
|
+
|
|
60
|
+
<Nav footer={{ collapseButton: true }} {header} {items} onClick={(data) => console.log('trigger onClick: ', data)} onSelect={(data) => console.log('trigger onSelect: ', data)} styles={{ body: 'height: 320px' }}>
|
|
61
|
+
{#snippet icon(renderProps)}
|
|
62
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
63
|
+
{#if Icon}
|
|
64
|
+
<Icon size={renderProps.size} />
|
|
65
|
+
{/if}
|
|
66
|
+
{/snippet}
|
|
67
|
+
</Nav>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Navigation Indentation
|
|
71
|
+
|
|
72
|
+
> Navigation indentation is currently effective only for first-level navigation.
|
|
73
|
+
|
|
74
|
+
#### Pure Copywriting Navigation
|
|
75
|
+
|
|
76
|
+
The `icon` snippet of Svelte always keeps the icon column, and empty content does not remove the icon box. When no icons are needed, do not provide an `icon` snippet.
|
|
77
|
+
|
|
78
|
+
```svelte
|
|
79
|
+
<script lang="ts">
|
|
80
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
81
|
+
|
|
82
|
+
const items: NavItems = [
|
|
83
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
84
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
85
|
+
{ itemKey: 'union-management', text: '任务管理', items: ['公告设置', '任务查询', '信息录入'] },
|
|
86
|
+
{ text: '任务平台', itemKey: 'task', items: ['任务管理', '用户任务查询'] },
|
|
87
|
+
];
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<Nav {items} onClick={(data) => console.log('trigger onClick: ', data)} onSelect={(data) => console.log('trigger onSelect: ', data)} openKeys={['task']} styles={{ body: 'height: 300px' }} />
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Define The Head And Bottom
|
|
94
|
+
|
|
95
|
+
Use `header` and `footer` to quickly define the navigation head and bottom. `collapseButton` in `footer` takes effect only with `mode = "vertical"` (vertical navigation).
|
|
96
|
+
|
|
97
|
+
```svelte
|
|
98
|
+
<script lang="ts">
|
|
99
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
100
|
+
import { IconBadge, IconBanner, IconForm } from '@fibrae/semi-icons-svelte/lab';
|
|
101
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
102
|
+
|
|
103
|
+
const items: NavItems = [
|
|
104
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
105
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
106
|
+
{ itemKey: 'task', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
107
|
+
];
|
|
108
|
+
const icons = { user: IconBadge, union: IconBanner, task: IconForm };
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
{#snippet header()}
|
|
112
|
+
<Nav.Header text="Semi 运营后台">
|
|
113
|
+
{#snippet logo()}
|
|
114
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
115
|
+
{/snippet}
|
|
116
|
+
</Nav.Header>
|
|
117
|
+
{/snippet}
|
|
118
|
+
|
|
119
|
+
<Nav footer={{ collapseButton: true }} {header} {items} onSelect={(key) => console.log(key)} openKeys={['task']} styles={{ body: 'height: 300px' }}>
|
|
120
|
+
{#snippet icon(renderProps)}
|
|
121
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
122
|
+
{#if Icon}
|
|
123
|
+
<Icon size={renderProps.size} />
|
|
124
|
+
{/if}
|
|
125
|
+
{/snippet}
|
|
126
|
+
</Nav>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Navigation Style Definition
|
|
130
|
+
|
|
131
|
+
Navigation provides two parameters to define navigation styles: `style` and `styles.body`. `style` lands on the outermost layer of the navigation component, while `styles.body` defines the style of the navigation list (its class name is `classNames.body`); both are strings. (Both the navigation head and the bottom accept their own `style`.)
|
|
132
|
+
|
|
133
|
+
For example, you need a navigation list to scroll, navigate the head and bottom fixed navigation components, which can be used this way:
|
|
134
|
+
|
|
135
|
+
```svelte
|
|
136
|
+
<script lang="ts">
|
|
137
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
138
|
+
import { IconBadge, IconBanner, IconForm, IconNavigation, IconNotification, IconSteps, IconTabs, IconTree, IconTreeSelect } from '@fibrae/semi-icons-svelte/lab';
|
|
139
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
140
|
+
|
|
141
|
+
const items: NavItems = [
|
|
142
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
143
|
+
{ itemKey: '2', text: '订单管理' },
|
|
144
|
+
{ itemKey: '3', text: '资源管理' },
|
|
145
|
+
{ itemKey: '4', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
146
|
+
{ itemKey: '5', text: '推送通知' },
|
|
147
|
+
{ itemKey: '6', text: '任务' },
|
|
148
|
+
{ itemKey: '7', text: '活动管理' },
|
|
149
|
+
{ itemKey: '8', text: '内容工具' },
|
|
150
|
+
{ itemKey: '9', text: '快捷导航' },
|
|
151
|
+
];
|
|
152
|
+
const icons = {
|
|
153
|
+
user: IconBadge,
|
|
154
|
+
'2': IconBanner,
|
|
155
|
+
'3': IconTreeSelect,
|
|
156
|
+
'4': IconForm,
|
|
157
|
+
'5': IconNotification,
|
|
158
|
+
'6': IconSteps,
|
|
159
|
+
'7': IconTree,
|
|
160
|
+
'8': IconTabs,
|
|
161
|
+
'9': IconNavigation,
|
|
162
|
+
};
|
|
163
|
+
</script>
|
|
164
|
+
|
|
165
|
+
{#snippet header()}
|
|
166
|
+
<Nav.Header text="Semi 运营后台">
|
|
167
|
+
{#snippet logo()}
|
|
168
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
169
|
+
{/snippet}
|
|
170
|
+
</Nav.Header>
|
|
171
|
+
{/snippet}
|
|
172
|
+
|
|
173
|
+
<Nav footer={{ collapseButton: true }} {header} {items} onSelect={(key) => console.log(key)} style="height: 520px" styles={{ body: 'height: 300px' }}>
|
|
174
|
+
{#snippet icon(renderProps)}
|
|
175
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
176
|
+
{#if Icon}
|
|
177
|
+
<Icon size={renderProps.size} />
|
|
178
|
+
{/if}
|
|
179
|
+
{/snippet}
|
|
180
|
+
</Nav>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Children Writing
|
|
184
|
+
|
|
185
|
+
`NavItem` and `SubNav` can be written as the children of Nav, and the head and bottom as `header` and `footer` snippets that hold `NavHeader` and `NavFooter`. Icons are provided through the `icon` snippet of each child component, and the text snippet is named `label` (it corresponds to the `text` slot of Vue and is renamed because it shares its name with the `text` prop). The children read their parent through context. This form does not open the ancestors of the selected item automatically, and a top-level Sub gets no selected mark; use `items` when you need either.
|
|
186
|
+
|
|
187
|
+
```svelte
|
|
188
|
+
<script lang="ts">
|
|
189
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
190
|
+
import { IconBadge, IconForm, IconTree } from '@fibrae/semi-icons-svelte/lab';
|
|
191
|
+
import { Nav } from '@fibrae/semi-ui-svelte';
|
|
192
|
+
</script>
|
|
193
|
+
|
|
194
|
+
{#snippet header()}
|
|
195
|
+
<Nav.Header text="Semi 运营后台">
|
|
196
|
+
{#snippet logo()}
|
|
197
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
198
|
+
{/snippet}
|
|
199
|
+
</Nav.Header>
|
|
200
|
+
{/snippet}
|
|
201
|
+
|
|
202
|
+
{#snippet footer()}
|
|
203
|
+
<Nav.Footer collapseButton />
|
|
204
|
+
{/snippet}
|
|
205
|
+
|
|
206
|
+
<Nav {footer} {header} onClick={(data) => console.log('trigger onClick: ', data)} onSelect={(data) => console.log('trigger onSelect: ', data)} openKeys={['user']} styles={{ body: 'height: 300px' }}>
|
|
207
|
+
<Nav.Item itemKey="union" text="活动管理">
|
|
208
|
+
{#snippet icon(renderProps)}
|
|
209
|
+
<IconForm size={renderProps.size} />
|
|
210
|
+
{/snippet}
|
|
211
|
+
</Nav.Item>
|
|
212
|
+
<Nav.Sub itemKey="user" text="用户管理">
|
|
213
|
+
{#snippet icon(renderProps)}
|
|
214
|
+
<IconBadge size={renderProps.size} />
|
|
215
|
+
{/snippet}
|
|
216
|
+
<Nav.Item itemKey="active" text="活跃用户" />
|
|
217
|
+
<Nav.Item itemKey="negative" text="非活跃用户" />
|
|
218
|
+
</Nav.Sub>
|
|
219
|
+
<Nav.Sub itemKey="union-management" text="任务管理">
|
|
220
|
+
{#snippet icon(renderProps)}
|
|
221
|
+
<IconTree size={renderProps.size} />
|
|
222
|
+
{/snippet}
|
|
223
|
+
<Nav.Item itemKey="notice" text="任务设置" />
|
|
224
|
+
<Nav.Item itemKey="query" text="任务查询" />
|
|
225
|
+
<Nav.Item itemKey="info" text="信息录入" />
|
|
226
|
+
</Nav.Sub>
|
|
227
|
+
</Nav>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Use router lib
|
|
231
|
+
|
|
232
|
+
To wrap navigation items in links when using a router such as SvelteKit, so that clicking an item triggers navigation, customize the rendering.
|
|
233
|
+
|
|
234
|
+
Use the `wrapper` snippet to wrap each item in a custom element. `itemElement` is the `li` of the item; render it with `{@render itemElement()}`, exactly once.
|
|
235
|
+
|
|
236
|
+
```svelte
|
|
237
|
+
<script lang="ts">
|
|
238
|
+
import { Nav } from '@fibrae/semi-ui-svelte';
|
|
239
|
+
|
|
240
|
+
const routerMap = {
|
|
241
|
+
Home: '/',
|
|
242
|
+
About: '/about',
|
|
243
|
+
Dashboard: '/dashboard',
|
|
244
|
+
'Nothing Here': '/nothing-here',
|
|
245
|
+
};
|
|
246
|
+
const items = [
|
|
247
|
+
{ itemKey: 'Home', text: 'Home' },
|
|
248
|
+
{ itemKey: 'About', text: 'About' },
|
|
249
|
+
{ itemKey: 'Sub', text: 'Sub', items: ['Dashboard', 'Nothing Here'] },
|
|
250
|
+
];
|
|
251
|
+
</script>
|
|
252
|
+
|
|
253
|
+
<Nav {items}>
|
|
254
|
+
{#snippet wrapper({ itemElement, props })}
|
|
255
|
+
<a href={routerMap[props.itemKey as keyof typeof routerMap]} style="text-decoration: none">
|
|
256
|
+
{@render itemElement()}
|
|
257
|
+
</a>
|
|
258
|
+
{/snippet}
|
|
259
|
+
</Nav>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Navigation Direction
|
|
263
|
+
|
|
264
|
+
Navigation currently offers navigation in two directions:
|
|
265
|
+
|
|
266
|
+
- Vertical (default)
|
|
267
|
+
- Horizontal
|
|
268
|
+
|
|
269
|
+
You can pass `mode = "vertical"` (default) or `mode = "horizontal"` to control.
|
|
270
|
+
|
|
271
|
+
In particular, there are some functions (parameters) only in `mode = "vertical"` effective:
|
|
272
|
+
|
|
273
|
+
- `isCollapsed` (Navigation put away to the side)
|
|
274
|
+
- `openKeys` (Specifies the initial and controlled array of expanded subnavigation items key, which is valid only in `mode = "vertical"` and `isCollapsed = false`)
|
|
275
|
+
- `collapseButton` of `NavFooter`
|
|
276
|
+
|
|
277
|
+
#### Vertical Direction
|
|
278
|
+
|
|
279
|
+
```svelte
|
|
280
|
+
<script lang="ts">
|
|
281
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
282
|
+
import { IconBadge, IconBanner, IconForm, IconTreeSelect } from '@fibrae/semi-icons-svelte/lab';
|
|
283
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
284
|
+
|
|
285
|
+
const items: NavItems = [
|
|
286
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
287
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
288
|
+
{ itemKey: 'union-management', text: '任务管理', items: ['任务设置', '任务查询', '信息录入'] },
|
|
289
|
+
{ itemKey: 'job', text: '公告管理', items: ['推送管理', '已推送查询'] },
|
|
290
|
+
];
|
|
291
|
+
const icons = { user: IconBadge, union: IconTreeSelect, 'union-management': IconForm, job: IconBanner };
|
|
292
|
+
</script>
|
|
293
|
+
|
|
294
|
+
{#snippet header()}
|
|
295
|
+
<Nav.Header text="Semi 运营后台">
|
|
296
|
+
{#snippet logo()}
|
|
297
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
298
|
+
{/snippet}
|
|
299
|
+
</Nav.Header>
|
|
300
|
+
{/snippet}
|
|
301
|
+
|
|
302
|
+
<div style="width: 100%">
|
|
303
|
+
<Nav footer={{ collapseButton: true }} {header} {items} onSelect={(key) => console.log(key)} styles={{ body: 'height: 300px' }}>
|
|
304
|
+
{#snippet icon(renderProps)}
|
|
305
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
306
|
+
{#if Icon}
|
|
307
|
+
<Icon size={renderProps.size} />
|
|
308
|
+
{/if}
|
|
309
|
+
{/snippet}
|
|
310
|
+
</Nav>
|
|
311
|
+
</div>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
#### Horizontal Direction
|
|
315
|
+
|
|
316
|
+
```svelte
|
|
317
|
+
<script lang="ts">
|
|
318
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
319
|
+
import { IconBadge, IconBreadcrumb, IconSteps, IconTreeSelect } from '@fibrae/semi-icons-svelte/lab';
|
|
320
|
+
import { Avatar, Dropdown, Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
321
|
+
|
|
322
|
+
const items: NavItems = [
|
|
323
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
324
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
325
|
+
{
|
|
326
|
+
itemKey: 'approve-management',
|
|
327
|
+
text: '审批管理',
|
|
328
|
+
items: ['入驻审核', { itemKey: 'operation-management', text: '运营管理', items: ['人员管理', '人员变更'] }],
|
|
329
|
+
},
|
|
330
|
+
{ itemKey: 'job', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
331
|
+
];
|
|
332
|
+
const icons = { user: IconBadge, union: IconTreeSelect, 'approve-management': IconBreadcrumb, job: IconSteps };
|
|
333
|
+
</script>
|
|
334
|
+
|
|
335
|
+
{#snippet header()}
|
|
336
|
+
<Nav.Header text="Semi 运营后台">
|
|
337
|
+
{#snippet logo()}
|
|
338
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
339
|
+
{/snippet}
|
|
340
|
+
</Nav.Header>
|
|
341
|
+
{/snippet}
|
|
342
|
+
|
|
343
|
+
{#snippet footer()}
|
|
344
|
+
<Nav.Footer>
|
|
345
|
+
<Dropdown position="bottomRight">
|
|
346
|
+
<Avatar color="light-blue" size="small" style="margin: 4px">SD</Avatar>
|
|
347
|
+
<span>Semi</span>
|
|
348
|
+
{#snippet content()}
|
|
349
|
+
<Dropdown.Menu>
|
|
350
|
+
<Dropdown.Item>详情</Dropdown.Item>
|
|
351
|
+
<Dropdown.Item>退出</Dropdown.Item>
|
|
352
|
+
</Dropdown.Menu>
|
|
353
|
+
{/snippet}
|
|
354
|
+
</Dropdown>
|
|
355
|
+
</Nav.Footer>
|
|
356
|
+
{/snippet}
|
|
357
|
+
|
|
358
|
+
<div style="width: 100%">
|
|
359
|
+
<Nav {footer} {header} {items} mode="horizontal" onSelect={(key) => console.log(key)}>
|
|
360
|
+
{#snippet icon(renderProps)}
|
|
361
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
362
|
+
{#if Icon}
|
|
363
|
+
<Icon size={renderProps.size} />
|
|
364
|
+
{/if}
|
|
365
|
+
{/snippet}
|
|
366
|
+
</Nav>
|
|
367
|
+
</div>
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### Horizontal Plus Vertical
|
|
371
|
+
|
|
372
|
+
The general platform design will adopt the mode of horizontal and vertical navigation. Here is a common example.
|
|
373
|
+
|
|
374
|
+
```svelte
|
|
375
|
+
<script lang="ts">
|
|
376
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
377
|
+
import { IconBadge, IconBreadcrumb, IconSteps, IconTreeSelect } from '@fibrae/semi-icons-svelte/lab';
|
|
378
|
+
import { Avatar, Breadcrumb, Dropdown, Layout, Nav, Skeleton, type NavIconArgs, type NavItemConfig, type NavItemRenderProps, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
379
|
+
|
|
380
|
+
const currentYear = 2024;
|
|
381
|
+
|
|
382
|
+
const operationItem: NavItemConfig = {
|
|
383
|
+
itemKey: 'operation-management',
|
|
384
|
+
text: '运营管理',
|
|
385
|
+
items: ['人员管理', '人员变更'],
|
|
386
|
+
};
|
|
387
|
+
const topItems: NavItems = [
|
|
388
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
389
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
390
|
+
{ itemKey: 'approve-management', text: '审批管理', items: ['入驻审核', operationItem] },
|
|
391
|
+
{ itemKey: 'job', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
392
|
+
];
|
|
393
|
+
const leftItems: NavItems = [
|
|
394
|
+
{ itemKey: 'approve-management', text: '审批管理', items: ['入驻审核', operationItem] },
|
|
395
|
+
{ itemKey: 'job', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
396
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
397
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
398
|
+
];
|
|
399
|
+
const icons = { user: IconBadge, union: IconTreeSelect, 'approve-management': IconBreadcrumb, job: IconSteps };
|
|
400
|
+
const routes = ['首页', '当这个页面标题很长时需要省略', '上一页', '详情页'];
|
|
401
|
+
</script>
|
|
402
|
+
|
|
403
|
+
{#snippet header()}
|
|
404
|
+
<Nav.Header text="Semi 运营后台">
|
|
405
|
+
{#snippet logo()}
|
|
406
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
407
|
+
{/snippet}
|
|
408
|
+
</Nav.Header>
|
|
409
|
+
{/snippet}
|
|
410
|
+
|
|
411
|
+
{#snippet footer()}
|
|
412
|
+
<Nav.Footer>
|
|
413
|
+
<Dropdown position="bottomRight">
|
|
414
|
+
<Avatar color="light-blue" size="small" style="margin: 4px">SD</Avatar>
|
|
415
|
+
<span>Semi</span>
|
|
416
|
+
{#snippet content()}
|
|
417
|
+
<Dropdown.Menu>
|
|
418
|
+
<Dropdown.Item>详情</Dropdown.Item>
|
|
419
|
+
<Dropdown.Item>退出</Dropdown.Item>
|
|
420
|
+
</Dropdown.Menu>
|
|
421
|
+
{/snippet}
|
|
422
|
+
</Dropdown>
|
|
423
|
+
</Nav.Footer>
|
|
424
|
+
{/snippet}
|
|
425
|
+
|
|
426
|
+
{#snippet icon(renderProps: NavIconArgs & NavItemRenderProps)}
|
|
427
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
428
|
+
{#if Icon}
|
|
429
|
+
<Icon size={renderProps.size} />
|
|
430
|
+
{/if}
|
|
431
|
+
{/snippet}
|
|
432
|
+
|
|
433
|
+
<Layout style="border: 1px solid var(--semi-color-border)">
|
|
434
|
+
<Layout.Header style="background-color: var(--semi-color-bg-1)">
|
|
435
|
+
<div>
|
|
436
|
+
<Nav aria-label="顶部导航" {footer} {header} {icon} items={topItems} mode="horizontal" onSelect={(key) => console.log(key)} />
|
|
437
|
+
</div>
|
|
438
|
+
</Layout.Header>
|
|
439
|
+
<Layout>
|
|
440
|
+
<Layout.Sider style="background-color: var(--semi-color-bg-1)">
|
|
441
|
+
<Nav aria-label="侧边导航" footer={{ collapseButton: true }} {icon} items={leftItems} style="max-width: 220px; height: 100%" />
|
|
442
|
+
</Layout.Sider>
|
|
443
|
+
<Layout.Content style="padding: 24px; background-color: var(--semi-color-bg-0)">
|
|
444
|
+
<Breadcrumb {routes} style="margin-block-end: 24px" />
|
|
445
|
+
<div style="border-radius: 10px; border: 1px solid var(--semi-color-border); height: 376px; padding: 32px">
|
|
446
|
+
<Skeleton loading>
|
|
447
|
+
{#snippet placeholder()}
|
|
448
|
+
<Skeleton.Paragraph rows={2} />
|
|
449
|
+
{/snippet}
|
|
450
|
+
<p>Hi, Semi dance dance.</p>
|
|
451
|
+
<p>Hi, Semi dance dance.</p>
|
|
452
|
+
</Skeleton>
|
|
453
|
+
</div>
|
|
454
|
+
</Layout.Content>
|
|
455
|
+
</Layout>
|
|
456
|
+
<Layout.Footer style="display: flex; justify-content: space-between; padding: 20px; color: var(--semi-color-text-2); background-color: var(--semi-grey-0)">
|
|
457
|
+
<span style="display: flex; align-items: center">
|
|
458
|
+
<IconSemiLogo size="large" style="margin-inline-end: 8px" />
|
|
459
|
+
<span>Copyright © {currentYear} Semi Design Next. All Rights Reserved. </span>
|
|
460
|
+
</span>
|
|
461
|
+
<span>
|
|
462
|
+
<span style="margin-inline-end: 24px">平台客服</span>
|
|
463
|
+
<span>反馈建议</span>
|
|
464
|
+
</span>
|
|
465
|
+
</Layout.Footer>
|
|
466
|
+
</Layout>
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Expand and collapse arrow position
|
|
470
|
+
|
|
471
|
+
`toggleIconPosition` set 'left' or 'right', default right
|
|
472
|
+
|
|
473
|
+
```svelte
|
|
474
|
+
<script lang="ts">
|
|
475
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
476
|
+
import { IconBadge, IconBanner, IconForm } from '@fibrae/semi-icons-svelte/lab';
|
|
477
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
478
|
+
|
|
479
|
+
const items: NavItems = [
|
|
480
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
481
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
482
|
+
{ itemKey: 'job', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
483
|
+
];
|
|
484
|
+
const icons = { user: IconBadge, union: IconBanner, job: IconForm };
|
|
485
|
+
</script>
|
|
486
|
+
|
|
487
|
+
{#snippet header()}
|
|
488
|
+
<Nav.Header text="Semi 运营后台">
|
|
489
|
+
{#snippet logo()}
|
|
490
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
491
|
+
{/snippet}
|
|
492
|
+
</Nav.Header>
|
|
493
|
+
{/snippet}
|
|
494
|
+
|
|
495
|
+
<Nav footer={{ collapseButton: true }} {header} {items} onSelect={(key) => console.log(key)} openKeys={['job']} styles={{ body: 'height: 300px' }} toggleIconPosition="left">
|
|
496
|
+
{#snippet icon(renderProps)}
|
|
497
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
498
|
+
{#if Icon}
|
|
499
|
+
<Icon size={renderProps.size} />
|
|
500
|
+
{/if}
|
|
501
|
+
{/snippet}
|
|
502
|
+
</Nav>
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Indentation limit
|
|
506
|
+
|
|
507
|
+
No indentation by default. If you need to indent the navigation items according to the level, please set limitIndent to false
|
|
508
|
+
|
|
509
|
+
Object method No need to care about level when passing in navigation items.
|
|
510
|
+
|
|
511
|
+
limitIndent only takes effect in the vertical direction.
|
|
512
|
+
|
|
513
|
+
- When passing navigation items with `NavItem` as children, pass the `level` prop to `NavItem` manually.
|
|
514
|
+
- When passing navigation items with `items`, you do not need to care about level.
|
|
515
|
+
|
|
516
|
+
```svelte
|
|
517
|
+
<script lang="ts">
|
|
518
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
519
|
+
import { IconBadge, IconBanner, IconForm, IconTabs } from '@fibrae/semi-icons-svelte/lab';
|
|
520
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
521
|
+
|
|
522
|
+
const items: NavItems = [
|
|
523
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
524
|
+
{
|
|
525
|
+
text: '任务平台',
|
|
526
|
+
itemKey: 'job',
|
|
527
|
+
items: [
|
|
528
|
+
'任务管理',
|
|
529
|
+
{
|
|
530
|
+
text: '任务1',
|
|
531
|
+
itemKey: 'mission1',
|
|
532
|
+
items: ['任务2', { text: '任务3拆解', itemKey: 'mission3', items: ['子任务1', '子任务2'] }],
|
|
533
|
+
},
|
|
534
|
+
],
|
|
535
|
+
},
|
|
536
|
+
];
|
|
537
|
+
const icons = { user: IconBadge, job: IconBanner, mission1: IconForm, mission3: IconTabs };
|
|
538
|
+
</script>
|
|
539
|
+
|
|
540
|
+
{#snippet header()}
|
|
541
|
+
<Nav.Header text="Semi 运营后台">
|
|
542
|
+
{#snippet logo()}
|
|
543
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
544
|
+
{/snippet}
|
|
545
|
+
</Nav.Header>
|
|
546
|
+
{/snippet}
|
|
547
|
+
|
|
548
|
+
<Nav footer={{ collapseButton: true }} {header} {items} limitIndent={false} onSelect={(key) => console.log(key)} openKeys={['job', 'mission1']} styles={{ body: 'height: 300px' }}>
|
|
549
|
+
{#snippet icon(renderProps)}
|
|
550
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
551
|
+
{#if Icon}
|
|
552
|
+
<Icon size={renderProps.size} />
|
|
553
|
+
{/if}
|
|
554
|
+
{/snippet}
|
|
555
|
+
</Nav>
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
### Uncontrolled Properties
|
|
559
|
+
|
|
560
|
+
Including:
|
|
561
|
+
|
|
562
|
+
- `defaultSelectedKeys` (default selected navigation item `key` array)
|
|
563
|
+
- `defaultOpenKeys` (default expanded navigation item `key` array, valid only with `mode = "vertical"` and `isCollapsed = false` | `defaultIsCollapsed = false`)
|
|
564
|
+
- `defaultIsCollapsed` (whether the sidebar is closed by default, valid only when `mode = "vertical"`)
|
|
565
|
+
|
|
566
|
+
Svelte has no `default*` props: a one-way `selectedKeys`, `openKeys` or `isCollapsed` is only the initial value, and `undefined` means uncontrolled. Write `defaultSelectedKeys`, `defaultOpenKeys` and `defaultIsCollapsed` above as `selectedKeys`, `openKeys` and `isCollapsed`.
|
|
567
|
+
|
|
568
|
+
```svelte
|
|
569
|
+
<script lang="ts">
|
|
570
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
571
|
+
import { IconBadge, IconBanner, IconForm, IconTree } from '@fibrae/semi-icons-svelte/lab';
|
|
572
|
+
import { Nav, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
573
|
+
|
|
574
|
+
const items: NavItems = [
|
|
575
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
576
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
577
|
+
{ itemKey: 'union-management', text: '任务管理', items: ['公告设置', '任务查询', '信息录入'] },
|
|
578
|
+
{ itemKey: 'job', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
579
|
+
];
|
|
580
|
+
const icons = { user: IconBadge, union: IconBanner, 'union-management': IconForm, job: IconTree };
|
|
581
|
+
</script>
|
|
582
|
+
|
|
583
|
+
{#snippet header()}
|
|
584
|
+
<Nav.Header text="Semi 运营后台">
|
|
585
|
+
{#snippet logo()}
|
|
586
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
587
|
+
{/snippet}
|
|
588
|
+
</Nav.Header>
|
|
589
|
+
{/snippet}
|
|
590
|
+
|
|
591
|
+
<Nav footer={{ collapseButton: true }} {header} isCollapsed {items} openKeys={['job']} selectedKeys={['信息录入']} styles={{ body: 'height: 300px' }}>
|
|
592
|
+
{#snippet icon(renderProps)}
|
|
593
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
594
|
+
{#if Icon}
|
|
595
|
+
<Icon size={renderProps.size} />
|
|
596
|
+
{/if}
|
|
597
|
+
{/snippet}
|
|
598
|
+
</Nav>
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### Controlled Properties
|
|
602
|
+
|
|
603
|
+
The Navigation component provides several bindable properties. Use `bind:` to control the navigation easily, and combine it with callbacks if needed.
|
|
604
|
+
|
|
605
|
+
The bindable properties are:
|
|
606
|
+
|
|
607
|
+
- `bind:isCollapsed` (whether the sidebar is collapsed, effective only when `mode = "vertical"`)
|
|
608
|
+
- `bind:selectedKeys` (currently selected navigation item `key` array, holding only the selected item itself)
|
|
609
|
+
- `bind:openKeys` (currently expanded array of navigation items, valid only when `mode = "vertical"` and `isCollapsed = false`)
|
|
610
|
+
|
|
611
|
+
The corresponding callbacks are:
|
|
612
|
+
|
|
613
|
+
- `onCollapseChange(isCollapsed: boolean): void`
|
|
614
|
+
- `onSelect({ itemKey, selectedKeys, selectedItems, domEvent }): void`
|
|
615
|
+
- `onOpenChange({ itemKey, openKeys, domEvent, isOpen }): void`
|
|
616
|
+
|
|
617
|
+
`null` is a controlled empty value.
|
|
618
|
+
|
|
619
|
+
```svelte
|
|
620
|
+
<script lang="ts">
|
|
621
|
+
import { IconSemiLogo } from '@fibrae/semi-icons-svelte';
|
|
622
|
+
import { IconBadge, IconBanner, IconForm, IconTree } from '@fibrae/semi-icons-svelte/lab';
|
|
623
|
+
import { Nav, type NavItemKey, type NavItems } from '@fibrae/semi-ui-svelte';
|
|
624
|
+
|
|
625
|
+
let openKeys = $state<NavItemKey[]>(['union-management', 'job']);
|
|
626
|
+
let selectedKeys = $state<NavItemKey[]>(['公告设置']);
|
|
627
|
+
let isCollapsed = $state(true);
|
|
628
|
+
|
|
629
|
+
const items: NavItems = [
|
|
630
|
+
{ itemKey: 'user', text: '用户管理' },
|
|
631
|
+
{ itemKey: 'union', text: '活动管理' },
|
|
632
|
+
{ itemKey: 'union-management', text: '任务管理', items: ['公告设置', '任务查询', '信息录入'] },
|
|
633
|
+
{ itemKey: 'job', text: '任务平台', items: ['任务管理', '用户任务查询'] },
|
|
634
|
+
];
|
|
635
|
+
const icons = { user: IconBadge, union: IconBanner, 'union-management': IconForm, job: IconTree };
|
|
636
|
+
</script>
|
|
637
|
+
|
|
638
|
+
{#snippet header()}
|
|
639
|
+
<Nav.Header text="Semi 运营后台">
|
|
640
|
+
{#snippet logo()}
|
|
641
|
+
<IconSemiLogo style="height: 36px; font-size: 36px" />
|
|
642
|
+
{/snippet}
|
|
643
|
+
</Nav.Header>
|
|
644
|
+
{/snippet}
|
|
645
|
+
|
|
646
|
+
<Nav bind:isCollapsed bind:openKeys bind:selectedKeys footer={{ collapseButton: true }} {header} {items} onOpenChange={(data) => console.log('trigger onOpenChange: ', data)} onSelect={(data) => console.log('trigger onSelect: ', data)} styles={{ body: 'height: 300px' }}>
|
|
647
|
+
{#snippet icon(renderProps)}
|
|
648
|
+
{@const Icon = icons[renderProps.item.itemKey as keyof typeof icons]}
|
|
649
|
+
{#if Icon}
|
|
650
|
+
<Icon size={renderProps.size} />
|
|
651
|
+
{/if}
|
|
652
|
+
{/snippet}
|
|
653
|
+
</Nav>
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
## API Reference
|
|
657
|
+
|
|
658
|
+
### Nav
|
|
659
|
+
|
|
660
|
+
**Props**
|
|
661
|
+
|
|
662
|
+
| Property | Description | Type | Default |
|
|
663
|
+
| - | - | - | - |
|
|
664
|
+
| children | `NavItem` and `SubNav`, placed after the entries generated from items. | `Snippet` | - |
|
|
665
|
+
| classNames | Class names of the inner parts, keyed by `body` (the navigation item list); merged with the built-in classes. | `Partial<Record<NavPart, ClassValue>>` | - |
|
|
666
|
+
| expandIcon | Expand arrow of a sub navigation generated from items. The parameter holds item, level, size and the class to put on the icon element. | `Snippet<[NavItemRenderProps & NavExpandIconArgs]>` | - |
|
|
667
|
+
| footer | Footer area: a config object (collapseButton, class, style, and `data-*` and `aria-*` attributes), or a snippet that holds a `NavFooter`. | `NavFooterConfig \| Snippet` | - |
|
|
668
|
+
| header | Header area: a config object (text, link, linkOptions, logo, class, style, and `data-*` and `aria-*` attributes), or a snippet that holds a `NavHeader`. | `NavHeaderConfig \| Snippet` | - |
|
|
669
|
+
| icon | Icon of an entry of items. The parameter holds item, level and size. The icon column always stays; empty content does not remove the icon box. | `Snippet<[NavItemRenderProps & NavIconArgs]>` | - |
|
|
670
|
+
| isCollapsed | Whether the navigation is collapsed. Applies only when mode is vertical. Bind it with `bind:isCollapsed`; a one-way value is only the initial one, and `undefined` means uncontrolled. | `boolean` | - |
|
|
671
|
+
| items | Navigation item data. Each entry may carry nested items, and a string entry is both the text and the itemKey. Only the props declared by Item and Sub, class, style, onmouseenter, onmouseleave, `data-*` and `aria-*` reach the item; other fields such as path are ignored. Icons, text nodes and arrow icons use the `icon`, `text`, `toggleIcon` and `expandIcon` snippets. | `NavItems` | - |
|
|
672
|
+
| limitIndent | Whether to limit indentation. When false, nested items indent by level. Applies only when mode is vertical; horizontal mode always limits indentation. | `boolean` | `true` |
|
|
673
|
+
| mode | Orientation of the navigation: vertical or horizontal. | `Mode` | `"vertical"` |
|
|
674
|
+
| onClick | Called when any item is clicked. The data carries text for an item, and openKeys and isOpen for a sub navigation title. domEvent is the native event. | `(data: NavClickData) => void` | - |
|
|
675
|
+
| onCollapseChange | Called when the collapsed state changes. | `(isCollapsed: boolean) => void` | - |
|
|
676
|
+
| onOpenChange | Called when a sub navigation opens or closes. domEvent is missing when a popup opens by hover. | `(data: NavOpenChangeData) => void` | - |
|
|
677
|
+
| onSelect | Called when a selectable item is selected for the first time. selectedKeys holds only the key of the selected item, and domEvent is the native event. | `(data: OnSelectedData) => void` | - |
|
|
678
|
+
| openKeys | itemKeys of the open sub navigations. Applies only when mode is vertical and the sidebar is expanded. Bind it with `bind:openKeys`; a one-way value is only the initial one, and `null` is a controlled empty value. | `ItemKey[] \| null` | - |
|
|
679
|
+
| selectedKeys | itemKeys of the selected items. Bind it with `bind:selectedKeys`; a one-way value is only the initial one, and `null` is a controlled empty value. | `ItemKey[] \| null` | - |
|
|
680
|
+
| styles | Inline style strings of the inner parts, keyed like `classNames`. | `Partial<Record<NavPart, string>>` | - |
|
|
681
|
+
| subDropdownProps | Dropdown props for the sub navigations generated from items, used in horizontal mode or when the vertical navigation is collapsed. | `SubDropdownProps` | - |
|
|
682
|
+
| subNavCloseDelay | Delay in milliseconds before a sub navigation popup closes. Applies when collapsed or horizontal. | `number` | `100` |
|
|
683
|
+
| subNavMotion | Whether the sub navigation animates when it expands and collapses. | `boolean` | `true` |
|
|
684
|
+
| subNavOpenDelay | Delay in milliseconds before a sub navigation popup opens. Applies when collapsed or horizontal. | `number` | `0` |
|
|
685
|
+
| text | Text of an entry of items. The parameter holds item and level. Without it the entry's text shows. | `Snippet<[NavItemRenderProps]>` | - |
|
|
686
|
+
| toggleIcon | Icon at the toggle position of an entry of items. The parameter holds item, level and size. | `Snippet<[NavItemRenderProps & NavIconArgs]>` | - |
|
|
687
|
+
| toggleIconPosition | Position of the arrow of an item with sub navigation: left or right. | `'left' \| 'right'` | `"right"` |
|
|
688
|
+
| tooltipHideDelay | Delay in milliseconds before the Tooltip hides when collapsed. | `number` | `100` |
|
|
689
|
+
| tooltipShowDelay | Delay in milliseconds before the Tooltip shows when collapsed. | `number` | `0` |
|
|
690
|
+
| wrapper | Wraps each item. Render the li of the item exactly once with `{@render itemElement()}`. The parameter holds itemElement, isSubNav, isInSubNav and props. | `Snippet<[NavWrapperArgs]>` | - |
|
|
691
|
+
|
|
692
|
+
`class`, `style` and native attributes (such as `aria-label`) land on the outermost `nav`.
|
|
693
|
+
|
|
694
|
+
#### items data entries
|
|
695
|
+
|
|
696
|
+
`items` is `(string | NavItemConfig)[]`. A string entry is both the `text` and the `itemKey`. An entry with non-empty `items` renders as a Nav.Sub, any other entry as a Nav.Item. Entries hold data only; nodes are provided through the `icon`, `text`, `toggleIcon` and `expandIcon` snippets of Nav, whose parameters include `{ item, level }`.
|
|
697
|
+
|
|
698
|
+
| Properties | Description | Type | Default |
|
|
699
|
+
| - | - | - | - |
|
|
700
|
+
| itemKey | Unique item identifier | string \| number | |
|
|
701
|
+
| text | Navigation item copy | string \| number | |
|
|
702
|
+
| items | Child entries; an entry with non-empty `items` renders as a Nav.Sub | (string \| NavItemConfig)\[] | |
|
|
703
|
+
| disabled | Disabled state | boolean | |
|
|
704
|
+
| indent | If there is no icon, keep its space or not. Only effective for first level navigation | boolean \| number | |
|
|
705
|
+
| link | Navigation item href link, Nav.Item only | string | |
|
|
706
|
+
| linkOptions | Parameters transparently passed to the a tag, Nav.Item only | HTMLAnchorAttributes | |
|
|
707
|
+
| tooltipHideDelay | Delay for hiding the tooltip of this item, Nav.Item only | number | |
|
|
708
|
+
| tooltipShowDelay | Delay for showing the tooltip of this item, Nav.Item only | number | |
|
|
709
|
+
| dropdownProps | Popup layer `dropdown` parameter configuration, Nav.Sub only | SubDropdownProps | |
|
|
710
|
+
| classNames | Key `dropdown`: class name of the dropdown content, Nav.Sub only | `Partial<Record<'dropdown', ClassValue>>` | |
|
|
711
|
+
| styles | Key `dropdown`: style of the dropdown content, Nav.Sub only | `Partial<Record<'dropdown', string>>` | |
|
|
712
|
+
| class | Class name of the `li` of the item | ClassValue | |
|
|
713
|
+
| style | Custom style of the `li` of the item | string | |
|
|
714
|
+
| onmouseenter | Callback of mouse enter event | (event: MouseEvent) => void | |
|
|
715
|
+
| onmouseleave | Callback of mouse leave event | (event: MouseEvent) => void | |
|
|
716
|
+
| data-\*, aria-\* | `data-*` land on the `li`, `aria-*` on the link or button that takes focus | unknown | |
|
|
717
|
+
|
|
718
|
+
Other fields (such as `path`) are ignored.
|
|
719
|
+
|
|
720
|
+
### Nav.Item
|
|
721
|
+
|
|
722
|
+
**Props**
|
|
723
|
+
|
|
724
|
+
| Property | Description | Type | Default |
|
|
725
|
+
| - | - | - | - |
|
|
726
|
+
| disabled | Whether the item is disabled. | `boolean` | - |
|
|
727
|
+
| icon | Icon of the item. The parameter holds size. | `Snippet<[NavIconArgs]>` | - |
|
|
728
|
+
| indent | Whether to keep the icon's space when there is no icon. Applies to the first level only. | `boolean` | - |
|
|
729
|
+
| isCollapsed | Whether the item is collapsed, combined with the collapsed state of the Nav. | `boolean` | - |
|
|
730
|
+
| itemKey | Unique key of the item. | `ItemKey` | - |
|
|
731
|
+
| label | Replaces the text shown for the item. Named `label` because `text` is already a prop. | `Snippet` | - |
|
|
732
|
+
| level | Nesting level of the item. Determines the indentation when limitIndent is false. The SubNav above gives it, so this only overrides. | `number` | - |
|
|
733
|
+
| link | href of the item. When given the item renders as an a element. | `string` | - |
|
|
734
|
+
| linkOptions | Attributes passed to the a element. | `NavLinkOptions` | - |
|
|
735
|
+
| onClick | Called when the item is clicked, with itemKey, text and the native event domEvent. The native `onclick` still reaches the li. | `(data: SelectedData) => void` | - |
|
|
736
|
+
| text | Text of the item and part of the click payload. The `label` snippet replaces what is shown. | `string \| number` | - |
|
|
737
|
+
| toggleIcon | Icon at the toggle position, which Nav's toggleIconPosition decides. The parameter holds size. | `Snippet<[NavIconArgs]>` | - |
|
|
738
|
+
| tooltipHideDelay | Delay in milliseconds before this item's Tooltip hides. Wins over the same prop of the Nav. | `number` | - |
|
|
739
|
+
| tooltipShowDelay | Delay in milliseconds before this item's Tooltip shows. Wins over the same prop of the Nav. | `number` | - |
|
|
740
|
+
|
|
741
|
+
`aria-*` land on the link or button that takes focus; `class`, `style`, `data-*`, `onmouseenter`, `onmouseleave` and other attributes land on the `li`, and a passed `class` replaces the default `semi-navigation-item-normal`. `tabindex` lands on the link or button.
|
|
742
|
+
|
|
743
|
+
### Nav.Sub
|
|
744
|
+
|
|
745
|
+
**Props**
|
|
746
|
+
|
|
747
|
+
| Property | Description | Type | Default |
|
|
748
|
+
| - | - | - | - |
|
|
749
|
+
| children | The `NavItem` and `SubNav` entries of the sub navigation. | `Snippet` | - |
|
|
750
|
+
| classNames | Class names of the inner parts, keyed by `dropdown` (the popup content `.semi-dropdown`); merged with the built-in classes. | `Partial<Record<SubNavPart, ClassValue>>` | - |
|
|
751
|
+
| disabled | Whether the sub navigation is disabled. | `boolean` | - |
|
|
752
|
+
| dropdownProps | Props of the popup Dropdown, used in horizontal mode and when collapsed. | `SubDropdownProps` | - |
|
|
753
|
+
| expandIcon | Expand arrow icon. The parameter holds size and the class to put on the icon element. | `Snippet<[NavExpandIconArgs]>` | - |
|
|
754
|
+
| icon | Icon of the sub navigation. The parameter holds size. | `Snippet<[NavIconArgs]>` | - |
|
|
755
|
+
| indent | Whether to keep the icon's space when there is no icon. Applies to the first level only. | `boolean` | - |
|
|
756
|
+
| itemKey | Unique key of the sub navigation. | `ItemKey` | - |
|
|
757
|
+
| label | Replaces the title text shown. Named `label` because `text` is already a prop. | `Snippet` | - |
|
|
758
|
+
| level | Nesting level of the item. Determines the indentation when limitIndent is false. The SubNav above gives it, so this only overrides. | `number` | - |
|
|
759
|
+
| styles | Inline style strings of the inner parts, keyed like `classNames`; `dropdown` wins over the style in dropdownProps. | `Partial<Record<SubNavPart, string>>` | - |
|
|
760
|
+
| subDropdownProps | Props of the popup Dropdown, used when dropdownProps is not given. | `SubDropdownProps` | - |
|
|
761
|
+
| text | Title text of the sub navigation. The `label` snippet replaces what is shown. | `string \| number` | - |
|
|
762
|
+
|
|
763
|
+
`aria-*` land on the title button that takes focus; `class`, `style`, `data-*`, `onmouseenter`, `onmouseleave` and other attributes land on the `li`.
|
|
764
|
+
|
|
765
|
+
### Nav.Header
|
|
766
|
+
|
|
767
|
+
**Props**
|
|
768
|
+
|
|
769
|
+
| Property | Description | Type | Default |
|
|
770
|
+
| - | - | - | - |
|
|
771
|
+
| children | Other content of the header. | `Snippet` | - |
|
|
772
|
+
| link | href of the header. When given the header content sits inside an a element. | `string` | - |
|
|
773
|
+
| linkOptions | Attributes passed to the a element. | `NavLinkOptions` | - |
|
|
774
|
+
| logo | Logo. | `Snippet` | - |
|
|
775
|
+
| text | Logo text. It is hidden when collapsed, and then names the header link. | `string \| number` | - |
|
|
776
|
+
|
|
777
|
+
`class`, `style` and native attributes land on the outermost `div`.
|
|
778
|
+
|
|
779
|
+
### Nav.Footer
|
|
780
|
+
|
|
781
|
+
**Props**
|
|
782
|
+
|
|
783
|
+
| Property | Description | Type | Default |
|
|
784
|
+
| - | - | - | - |
|
|
785
|
+
| children | Footer content. When present the collapse button does not show. | `Snippet` | - |
|
|
786
|
+
| collapseButton | Whether to show the collapse button. Applies only when mode is vertical and the Footer has no children. A snippet replaces the built-in button and shows under the same conditions. | `boolean \| Snippet` | `false` |
|
|
787
|
+
| collapseText | Text of the built-in collapse button, with collapsed as the parameter. A text-only result also names the icon-only button. | `Snippet<[{ collapsed: boolean }]>` | - |
|
|
788
|
+
|
|
789
|
+
`class`, `style` and native attributes (including `onclick`) land on the outermost `div`. When collapsed, the accessible name of the collapse button always comes from the locale.
|
|
790
|
+
|
|
791
|
+
## Accessibility
|
|
792
|
+
|
|
793
|
+
### ARIA
|
|
794
|
+
|
|
795
|
+
Navigation follows the WAI-ARIA APG [Disclosure Navigation](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-navigation/) example and does not use the `menu` role.
|
|
796
|
+
|
|
797
|
+
- The root element is a `nav` (navigation landmark). When a page has several Navigations, give each a different `aria-label`, such as "Top navigation" and "Side navigation"
|
|
798
|
+
- The items are a plain `ul` / `li` list. Header and Footer are outside the list; other children that are not items are wrapped in a `li` that renders no box
|
|
799
|
+
- A Nav.Item with `link` is a link (`a href`), any other Nav.Item is a native `button`. The selected item has `aria-current="page"`, a disabled item has `aria-disabled="true"`
|
|
800
|
+
- In the expanded vertical mode, the title of a Nav.Sub is a native `button` with `aria-expanded` telling whether its list is shown and `aria-controls` pointing to that list
|
|
801
|
+
- In horizontal and collapsed mode, the title of a Nav.Sub is a menu button with `aria-haspopup="menu"` and an `aria-expanded` that follows the popup. The popup is a `menu` whose items are `menuitem`s; the selected one has `aria-current="page"`
|
|
802
|
+
- `aria-*` passed to Nav.Item or Nav.Sub land on the link or button that takes focus, other undeclared props on the `li`
|
|
803
|
+
- When the Nav is collapsed, the link of Nav.Header is named by its `text`
|
|
804
|
+
|
|
805
|
+
### Keyboard and Focus
|
|
806
|
+
|
|
807
|
+
- Every item and every inline sub title is a `Tab` stop; `Tab` and `Shift + Tab` move between them. Items in a closed sub are not in the Tab sequence
|
|
808
|
+
- On an item, `Enter` follows its link; an item without `link` is selected with `Enter` or `Space`
|
|
809
|
+
- On the title of an inline sub, `Enter` or `Space` expands or collapses its list
|
|
810
|
+
- In collapsed mode, a focused top level item shows its text in a Tooltip, which also describes the item
|
|
811
|
+
- The title of a sub in horizontal or collapsed mode:
|
|
812
|
+
- Opens its popup when it gets focus (hover trigger); `Down Arrow` and `Up Arrow` move focus to the first and last item of the menu
|
|
813
|
+
- In the menu, `Up Arrow`, `Down Arrow`, `Home` and `End` move focus, `Enter` or `Space` selects an item, `Right Arrow` opens a nested submenu and `Left Arrow` closes it and returns to the parent item (swapped on RTL pages)
|
|
814
|
+
- `Esc` closes the current menu and returns focus to the title that opened it; `Tab` closes all menus and moves focus as usual
|
|
815
|
+
|
|
816
|
+
* The return value of the `wrapper` snippet is placed directly in the `ul`; when it is not a `li`, the list structure is invalid, so make sure it renders a `li` or content that is allowed in a `ul`. When `wrapper` wraps an item in a router link, the link contains the item's own button, which nests interactive elements. For client-side routing, prefer `link` with `linkOptions.onclick`
|
|
817
|
+
|
|
818
|
+
## Content Guidelines
|
|
819
|
+
|
|
820
|
+
- Navigation bar menu uses sentence case format
|
|
821
|
+
- Keep it as simple as possible
|
|
822
|
+
|
|
823
|
+
## Design Tokens
|
|
824
|
+
|
|
825
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/navigation/navigation/>
|
|
826
|
+
|
|
827
|
+
## FAQ
|
|
828
|
+
|
|
829
|
+
- **Lost item when subNav is too height >=999px ?** Please refer to [this issue](https://github.com/DouyinFE/semi-design/issues/563)
|
|
830
|
+
|
|
831
|
+
## Changes from Semi Design
|
|
832
|
+
|
|
833
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
834
|
+
|
|
835
|
+
- 破坏性:删除 `bodyStyle` 与 Sub 的 `dropdownStyle`,改用 `classNames`、`styles`:Navigation 的 `body` 落在列表容器上,Sub 的 `dropdown` 落在下拉浮层 `.semi-dropdown` 上;`items` 配置项同样使用 `classNames`、`styles`。
|
|
836
|
+
- 破坏性:删除 `getPopupContainer`(改用 `subDropdownProps` 或 Sub 的 `dropdownProps`)与 `Navigation`、`Navigation.Header` 的 `prefixCls`,类名前缀固定为 `semi-navigation`;公开的 `Nav.Item` 不再渲染 children;`toggleIconPosition` 收窄为 `'left' | 'right'`;删除 `NavState`(改用 foundation 的 `NavigationState`)。
|
|
837
|
+
- 破坏性:根元素由 `div` 改为 `<nav>`,`ref` 类型改为 `Ref<HTMLElement>`;导航项不再是 `menuitem`,内部渲染原生 `button` 或 `<a href>`,按 `menuitem` 查询的测试改为 `link` 或 `button`。`onSelect`、`onClick` 的 `domEvent` 由 React 合成事件改为原生事件,读 `domEvent.nativeEvent` 的代码直接用 `domEvent`。
|
|
838
|
+
- 破坏性:受控 `openKeys`、`selectedKeys` 为 `null` 按空数组处理;`mode="horizontal"` 忽略 `isCollapsed`、`defaultIsCollapsed`。React:Fragment 里的 Item、Sub 作为导航项渲染,不再套 `li.semi-navigation-list-extra`;`renderWrapper` 返回非 li 内容时需把 `itemElement` 放进返回值。
|
|
839
|
+
- 破坏性(类型):删除 Nav 的 `multiple`、`onDeselect` 与 Nav.Sub 的 `isCollapsed`、`isOpen`、`maxHeight`(原来声明而不生效);Nav.Item、Nav.Sub 的 `indent` 收窄为 `boolean`。
|
|
840
|
+
- 折叠或水平模式的弹层中,嵌套 Sub 的外层 li 为 `role="none"`,只有标题是 `menuitem`,不再两层 `menuitem` 嵌套。
|
|
841
|
+
- 行为变化:折叠或水平模式下弹出的子菜单,鼠标斜着移向已打开的子菜单时,途经其他 Sub 不再关闭它或打开别的子菜单(指针宽限,见 Tooltip、Popover 一节)。
|
|
842
|
+
- 展开侧边栏时文字的淡入改为 keyframes 动画 `semi-navigation-text-fade-in`,Firefox、Safari 上同样淡入。
|
|
843
|
+
- Solid 破坏性:`items` 的条目只放数据:`text` 收为 `string | number`,删除条目上的 `icon`、`toggleIcon`、`expandIcon`;类型 `NavItemPropsWithItems`、`SubNavPropsWithItems` 删除,改为 `NavItemConfig`(`NavItems = (string | NavItemConfig)[]`)。图标、显示的文案与箭头由 Nav 的 `renderItemIcon`、`renderItemText`、`renderItemToggleIcon`、`renderItemExpandIcon` 提供,入参 `{ item, level }`(类型 `NavItemRenderProps`,与 Vue 的 `#icon`、`#text`、`#toggleIcon`、`#expandIcon` 插槽一致),只在该项显示时调用;`renderItemExpandIcon` 传入后替代 Nav 的 `expandIcon`。用了 `renderItemText` 时,`onClick`、`onSelect` 回调里的 `text` 是渲染结果(Vue 为条目数据)。Nav.Sub 的 `expandIcon` 只在箭头显示时读取,收起状态下不再创建。
|
|
844
|
+
- Solid 破坏性:`header`、`footer` 的配置对象只放数据(同 Vue 的 `NavHeaderConfig`、`NavFooterConfig`):`header.logo` 改为渲染函数 `() => JSX.Element`,只在显示时调用;`footer.collapseButton` 收为 `boolean | (() => JSX.Element)`,`true` 为内置按钮,渲染函数替换它,水平模式或底部有子元素时不调用。新增类型 `NavHeaderConfig`、`NavFooterConfig`,Nav 的 `header`、`footer` 类型改为 `JSX.Element | NavHeaderConfig`、`JSX.Element | NavFooterConfig`。Nav.Header 的 `text` 与配置对象的 `text` 收为 `string | number`(同 Vue),其他内容放在 Nav.Header 的 children 中;Nav.Header 的 `logo`、Nav.Footer 的 `collapseButton` 仍接受 JSX,`collapseButton` 只在按钮位置显示时读取。迁移:`header={{ logo: <IconSemiLogo /> }}` 改为 `header={{ logo: () => <IconSemiLogo /> }}`。
|
|
845
|
+
- Svelte:`Nav` 的 `selectedKeys`、`openKeys`、`isCollapsed` 可绑定,没有 `default*` 属性,单向传值只作初值,`undefined` 表示不受控;子项用 `items` 数据 prop 加 snippet(`icon`、`toggleIcon`、`expandIcon`、`text`),整体包装用 `wrapper` snippet。
|
|
846
|
+
- Svelte:`NavItem`、`SubNav` 也可写成 children,经 context 读父级,但这种写法下不会自动展开选中项的祖先、顶层 Sub 没有选中标记,需要这两项时用 `items`;两者的文字 snippet 叫 `label`(对应 Vue 的 `text` 插槽,因与 `text` prop 同名而改名)。
|
|
847
|
+
- Svelte:`header`、`footer` 是配置对象或 snippet,`NavHeader`、`NavFooter` 放在这两个 snippet 里使用,不会从 Nav 的 children 中提取;`icon` snippet 始终保留图标列,不能用空内容去掉图标框,收到 `{ size }`;折叠态下折叠按钮的可访问名称固定取语言包 `expandText`。
|
|
848
|
+
- Svelte:`children` 直接渲染在列表 `ul` 内,自定义内容要自带 `li`(Vue 会把非导航项内容包进列表项,Svelte 读不到 snippet 内容)。
|
|
849
|
+
- Svelte:子项写法下 `openKeys` 变回 `undefined` 时展开状态清空。
|
|
850
|
+
- `onSelect` 的 `selectedItems`:`items` 写法为该项的配置对象原样加 `level`(含 `path` 等业务字段);`Nav.Item` 写法为使用方传给该项的 props,不再补默认值。纯对象、数组、`Date`、`Map`、`Set`、`RegExp` 深拷贝,函数、元素、DOM 节点与其他类实例保留引用。Vue:为声明的 props 加 attrs,`click` 事件监听不在其中;Svelte:为传给 `NavItem` 的全部属性,含 snippet;Solid:`items` 写法下其中的 `text` 是条目数据,不是 `renderItemText` 的结果。
|
|
851
|
+
- `items`、children 变化时保留非受控的选中与展开;`selectedKeys` 变化不再收起手动展开的项,竖向模式下补上选中项的祖先。Nav.Sub 的 `class`(React 为 `className`)落在外层 li。
|