Skip to content

Commit 15dca31

Browse files
authored
Merge pull request #7274 from nextcloud-libraries/backport/7273/stable8
[stable8] feat(NcAppNavigationItem): add `active` as slot property to the "icon"-slot
2 parents c2e6d40 + a7ca350 commit 15dca31

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/components/NcAppNavigationItem/NcAppNavigationItem.vue

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,37 @@
4646
</ul>
4747
```
4848

49+
* Using different icons based on the active state (e.g. using vue-router and showing the filled variant for the current route):
50+
51+
```vue
52+
<template>
53+
<ul>
54+
<NcAppNavigationItem name="Current page" :active="true">
55+
<template #icon="{ active }">
56+
<NcIconSvgWrapper :path="active ? mdiFolder : mdiFolderOutline" />
57+
</template>
58+
</NcAppNavigationItem>
59+
<NcAppNavigationItem name="Other page">
60+
<template #icon="{ active }">
61+
<NcIconSvgWrapper :path="active ? mdiFolder : mdiFolderOutline" />
62+
</template>
63+
</NcAppNavigationItem>
64+
</ul>
65+
</template>
66+
<script>
67+
import { mdiFolder, mdiFolderOutline } from '@mdi/js'
68+
69+
export default {
70+
setup() {
71+
return {
72+
mdiFolder,
73+
mdiFolderOutline,
74+
}
75+
},
76+
}
77+
</script>
78+
```
79+
4980
#### Element with actions
5081
Wrap the children in a template. If you have more than 2 actions, a popover menu and a menu
5182
button will be automatically created.
@@ -289,8 +320,8 @@ Just set the `pinned` prop.
289320
<div :class="{ [icon]: icon }"
290321
class="app-navigation-entry-icon">
291322
<NcLoadingIcon v-if="loading" />
292-
<!-- @slot Slot for the optional leading icon -->
293-
<slot v-else name="icon" />
323+
<!-- @slot Slot for the optional leading icon. This slots get the `active`-slot attribute passed which is based on the vue-routers active route or the `active` prop. -->
324+
<slot v-else name="icon" :active="active || (to && isActive)" />
294325
</div>
295326
<span v-if="!editingActive" class="app-navigation-entry__name">
296327
{{ name }}

0 commit comments

Comments
 (0)