Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow material design icons in AppSidebarTab #1939

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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