Skip to content

Commit

Permalink
Merge pull request #1939 from nextcloud/fix/1859/tabs-md-icon
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored May 10, 2021
2 parents 0792858 + a3bc8b9 commit 01fd135
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
32 changes: 22 additions & 10 deletions src/components/AppSidebar/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,28 @@ include a standard-header like it's used by the files app.
### Standard usage

```vue
<AppSidebar
title="cat-picture.jpg"
subtitle="last edited 3 weeks ago">
<AppSidebarTab icon="icon-settings" name="Settings" id="settings">
Settings tab content
</AppSidebarTab>
<AppSidebarTab icon="icon-share" name="Sharing" id="share">
Sharing tab content
</AppSidebarTab>
</AppSidebar>
<template>
<AppSidebar
title="cat-picture.jpg"
subtitle="last edited 3 weeks ago">
<AppSidebarTab icon="icon-settings" name="Settings" id="settings">
<Cog slot="icon" :size="24" decorative />
Settings tab content
</AppSidebarTab>
<AppSidebarTab icon="icon-share" name="Sharing" id="share">
Sharing tab content
</AppSidebarTab>
</AppSidebar>
</template>
<script>
import Cog from 'vue-material-design-icons/Cog.vue'

export default {
components: {
Cog,
},
}
</script>
```

### Editable title
Expand Down
26 changes: 24 additions & 2 deletions src/components/AppSidebar/AppSidebarTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
:tabindex="activeTab === tab.id ? null : -1"
role="tab"
@click.prevent="setActive(tab.id)">
<span :class="tab.icon" class="app-sidebar-tabs__tab-icon" />
<span class="app-sidebar-tabs__tab-icon">
<VNodes v-if="hasMdIcon(tab)" :vnodes="tab.$slots.icon[0]" />
<span v-else :class="tab.icon" />
</span>
{{ tab.name }}
</a>
</li>
Expand Down Expand Up @@ -73,6 +76,15 @@ const IsValidStringWithoutSpaces = function(value) {

export default {
name: 'AppSidebarTabs',

components: {
// Component to render the material design icon (vnodes)
VNodes: {
functional: true,
render: (h, context) => context.props.vnodes,
},
},

props: {
/**
* Id of the tab to activate
Expand Down Expand Up @@ -208,6 +220,10 @@ export default {
: ''
},

hasMdIcon(tab) {
return tab?.$slots?.icon
},

/**
* Manually update the sidebar tabs according to $slots.default
*/
Expand All @@ -227,7 +243,7 @@ export default {
// Make sure all required props are provided and valid
if (IsValidString(tab?.name)
&& IsValidStringWithoutSpaces(tab?.id)
&& IsValidStringWithoutSpaces(tab?.icon)) {
&& (IsValidStringWithoutSpaces(tab?.icon) || tab?.$slots?.icon)) {
tabs.push(tab)
} else {
invalidTabs.push(tabNode)
Expand Down Expand Up @@ -331,6 +347,12 @@ export default {
opacity: $opacity_normal;
background-position: center 8px;
background-size: 16px;

& > span {
display: flex;
align-items: center;
justify-content: center;
}
}

&__content {
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppSidebarTab/AppSidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default {
},
icon: {
type: String,
required: true,
default: '',
},
order: {
type: Number,
Expand Down

0 comments on commit 01fd135

Please sign in to comment.