Skip to content

Commit 2b1956e

Browse files
committed
enh(NcAppNavigationItem): Allow to pass SVG or path as icon property
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 415f697 commit 2b1956e

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed

src/components/NcAppNavigationItem/NcAppNavigationItem.vue

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,33 @@
3333

3434
```vue
3535
<template>
36-
<NcAppNavigationItem name="My name">
37-
<template #icon>
38-
<Check :size="20" />
39-
</template>
40-
</NcAppNavigationItem>
36+
<ul>
37+
<NcAppNavigationItem name="With icon slot">
38+
<template #icon>
39+
<Check :size="20" />
40+
</template>
41+
</NcAppNavigationItem>
42+
<NcAppNavigationItem name="With icon class" icon="icon-group-white" />
43+
<NcAppNavigationItem name="With svg icon" :icon="iconAccountSvg" />
44+
<NcAppNavigationItem name="With @mdi/js icon" :icon="mdiAbacus" />
45+
</ul>
4146
</template>
4247
<script>
48+
import { mdiAbacus } from '@mdi/js'
49+
4350
import Check from 'vue-material-design-icons/Check'
51+
import iconAccountSvg from '@mdi/svg/svg/account.svg?raw'
4452

4553
export default {
4654
components: {
4755
Check,
4856
},
57+
data() {
58+
return {
59+
iconAccountSvg,
60+
mdiAbacus,
61+
}
62+
},
4963
}
5064
</script>
5165
```
@@ -285,10 +299,18 @@ Just set the `pinned` prop.
285299

286300
<!-- icon if not collapsible -->
287301
<!-- never show the icon over the collapsible if mobile -->
288-
<div :class="{ [icon]: icon }"
289-
class="app-navigation-entry-icon">
302+
<div class="app-navigation-entry-icon">
290303
<NcLoadingIcon v-if="loading" />
304+
<<<<<<< Updated upstream
291305
<slot v-else name="icon" />
306+
=======
307+
<!-- @slot Slot for the optional leading icon -->
308+
<slot v-else name="icon">
309+
<NcIconSvgWrapper v-if="iconPath" :path="iconPath" />
310+
<NcIconSvgWrapper v-else-if="iconSvg" :svg="iconSvg" />
311+
<span v-else :class="{ [icon]: icon }" />
312+
</slot>
313+
>>>>>>> Stashed changes
292314
</div>
293315
<span v-if="!editingActive" class="app-navigation-entry__name">
294316
{{ name }}
@@ -369,6 +391,7 @@ Just set the `pinned` prop.
369391
import NcActions from '../NcActions/index.js'
370392
import NcActionButton from '../NcActionButton/index.js'
371393
import NcLoadingIcon from '../NcLoadingIcon/index.js'
394+
import NcIconSvgWrapper from '../NcIconSvgWrapper/index.js'
372395
import NcVNodes from '../NcVNodes/index.js'
373396
import NcAppNavigationIconCollapsible from './NcAppNavigationIconCollapsible.vue'
374397
import { useIsMobile } from '../../composables/useIsMobile/index.js'
@@ -386,6 +409,7 @@ export default {
386409
NcActions,
387410
NcActionButton,
388411
NcAppNavigationIconCollapsible,
412+
NcIconSvgWrapper,
389413
NcInputConfirmCancel,
390414
NcLoadingIcon,
391415
NcVNodes,
@@ -429,8 +453,8 @@ export default {
429453
},
430454
431455
/**
432-
* Refers to the icon on the left, this prop accepts a class
433-
* like 'icon-category-enabled'.
456+
* Refers to the icon on the left
457+
* Either pass an icon as raw SVG string, path from `@mdi/js` or icon class like 'icon-category-enabled'.
434458
*/
435459
icon: {
436460
type: String,
@@ -619,6 +643,20 @@ export default {
619643
},
620644
621645
computed: {
646+
/**
647+
* Check if icon property might be an SVG as it starts with < which is not a valid class nor a valid path
648+
*/
649+
iconSvg() {
650+
return this.icon.startsWith('<') ? this.icon : undefined
651+
},
652+
653+
/**
654+
* Check if icon property is not an SVG and contains a space so it is not an css class
655+
*/
656+
iconPath() {
657+
return !this.iconSvg && this.icon.includes(' ') ? this.icon : undefined
658+
},
659+
622660
isRouterLink() {
623661
return this.to && !this.href
624662
},

0 commit comments

Comments
 (0)