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

Dropdown Items in Navbar #13

Merged
merged 23 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ https://vuepress.vuejs.org/

VuePress is still a work in progress. There are a few things that it currently does not support but are planned:

- Dropdown Items in Navbar
- Multi-Language Support
- Algolia DocSearch Integration
- Blogging support
Expand Down
22 changes: 22 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ module.exports = {
{
text: 'Default Theme Config',
link: '/default-theme-config/'
},
{
text: 'Links',
type: 'dropdown',
items: [
{
text: 'Vue',
link: 'https://vuejs.org/',
},
{
text: 'Vue-Router',
link: 'https://router.vuejs.org/en/',
},
{
text: 'Vue-CLI',
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/README.md',
},
{
text: 'Vue-Press',
link: '/',
},
]
}
],
sidebar: {
Expand Down
19 changes: 19 additions & 0 deletions docs/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ module.exports = {
}
```

The item in `themeConfig.nav` could also be a dropdown menu:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those links can also be dropdown menus, add nested items via items:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed at 50689ea, thanks


```js
module.exports = {
themeConfig: {
nav: [
{
text: 'Languages',
type: 'dropdown',
items: [
{ text: 'Chinese', link: '/language/chinese' },
{ text: 'Japanese', link: '/language/japanese' }
]
}
]
}
}
```

## Sidebar

To enable the sidebar, use `themeConfig.sidebar`. The basic configuration expects an Array of links:
Expand Down
1 change: 0 additions & 1 deletion docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Each markdown file is compiled into HTML with [markdown-it](https://github.com/m

VuePress is still a work in progress. There are a few things that it currently does not support but are planned:

- Dropdown Items in Navbar
- Multi-Language Support
- Algolia DocSearch Integration
- Blogging support
Expand Down
33 changes: 33 additions & 0 deletions lib/default-theme/NavLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<router-link
class="router-link"
:to="item.link"
v-if="!isExternal(item.link)">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better put the > on the next line, stuck to {{ item.text }} and stick the next router-link to the end of it too. But I see it comes this way from the original code 🤔

Copy link
Member Author

@ulivz ulivz Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, when I checked existing code, I found that the original code is always this way:

<!-- lib/default-theme/SidebarGroup.vue -->
 <span class="arrow"
        v-if="collapsable"
        :class="open ? 'up' : 'down'"></span>

And Is that what you say?

  <router-link
    class="router-link"
    :to="item.link"
    v-if="!isExternal(item.link)"
  >{{ item.text }}</router-link>

But I cannot find this style at existing code. or these two following styles would be better? it's most likely to original style.

  <router-link class="router-link"
    :to="item.link"
    v-if="!isExternal(item.link)">
    {{ item.text }}
  </router-link>

or

  <router-link class="router-link"
    :to="item.link"
    v-if="!isExternal(item.link)">{{ item.text }}</router-link>

Can you give a code snippet that you think is reasonable? Thank you.

Copy link
Member

@posva posva Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's pretty much what I said

The reasonable one would be:

  <router-link
    class="router-link"
    :to="item.link"
    v-if="!isExternal(item.link)"
  >{{ item.text }}</router-link>

which doesn't create any extra white space around the text, but, let's wait for Evan input on this one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, fixed at 7eb2563

{{ item.text }}
</router-link>
<a
v-else
:href="item.link"
target="_blank"
class="router-link">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

{{ item.text }}
</a>
</template>

<script>
import { isExternal } from './util'
export default {
props: {
item: {
required: true
}
},
mixins: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you use a mixin here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, using a mixin here is to reuse the existing method. or you would have a better way to do it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just put the methods object without the mixins, it would also work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, long time to write Vue, I just forgot some important thing, thanks.

{
methods: {
isExternal
}
}
]
}
</script>
116 changes: 98 additions & 18 deletions lib/default-theme/NavLinks.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<template>
<nav class="nav-links" v-if="userLinks.length || githubLink">
<!-- user links -->
<router-link v-for="item in userLinks"
:to="item.link"
<div
class="nav-item"
v-for="item in userLinks"
:key="item.link">
{{ item.text }}
</router-link>
<div
v-if="item.type === 'dropdown'"
class="dropdown-wrapper">
<span class="dropdown-title">{{ item.text }}</span>
<span class="arrow"></span>
<ul class="nav-dropdown">
<li
v-for="subItem in item.items"
:key="subItem.link">
<nav-link :item="subItem"></nav-link>
</li>
</ul>
</div>
<nav-link v-else :item="item"></nav-link>
</div>
<!-- github link -->
<a v-if="githubLink"
:href="githubLink"
Expand All @@ -20,15 +34,18 @@

<script>
import OutboundLink from './OutboundLink.vue'
import NavLink from './NavLink.vue'
import { isActive, ensureExt } from './util'

export default {
components: { OutboundLink },
components: { OutboundLink, NavLink },
computed: {
userLinks () {
return (this.$site.themeConfig.nav || []).map(item => ({
text: item.text,
link: ensureExt(item.link)
return (this.$site.themeConfig.nav || []).map(({ text, link, type, items }) => ({
text,
type,
link: link ? ensureExt(link) : void 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something more readable like null instead of void 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed at 50689ea, thanks

items: (items || []).map(({ text, link }) => ({ text, link: ensureExt(link) }))
}))
},
githubLink () {
Expand All @@ -52,21 +69,84 @@ export default {
.nav-links
display inline-block
a
color inherit
font-weight 500
line-height 1.25rem
margin-left 1.5rem
color inherit
&:hover, &.router-link-active
color $accentColor
.nav-item
position relative
display inline-block
margin-left 1.5rem
font-weight 500
line-height 2rem
.dropdown-wrapper
cursor pointer
padding-right 15
&:hover .nav-dropdown
display block
.arrow
display inline-block
vertical-align middle
margin-top -1px
margin-left 6px
width 0
height 0
border-left 4px solid transparent
border-right 4px solid transparent
border-top 5px solid #ccc
.nav-dropdown
li
color inherit
line-height 1.7rem
padding: 0 1.5rem 0 1.25rem
a
position relative
border-bottom: none
font-weight 400
&.router-link-active
color: $accentColor
&:after
content: ""
width: 0
height: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no :

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed at 50689ea, thanks

border-left 5px solid $accentColor
border-top 4px solid transparent
border-bottom 4px solid transparent
position absolute
top calc(50% - 3px)
left -10px
&:hover
margin-bottom 0
Copy link
Contributor

@egoist egoist Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be moved to a

Copy link
Member Author

@ulivz ulivz Apr 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWESOME! fixed at 6de2efa, thank for finding it out.

color $accentColor
.github-link
margin-left 1.5rem

@media (max-width: $MQMobile)
.nav-links a
margin-left 0
.nav-links
.nav-item, .github-link
margin-left 0

@media (min-width: $MQMobile)
.nav-links a
&:hover, &.router-link-active
color $textColor
margin-bottom -2px
border-bottom 2px solid lighten($accentColor, 5%)
.nav-links
a
&:hover, &.router-link-active
color $textColor
margin-bottom -2px
border-bottom 2px solid lighten($accentColor, 5%)
.nav-dropdown
display none
box-sizing border-box;
max-height calc(100vh - 2.7rem)
overflow-y auto
position absolute
top 100%
right 0
background-color #fff
padding 10px 0
border 1px solid #ddd
border-bottom-color #ccc
text-align left
border-radius 0.25rem
white-space nowrap
margin 0
</style>
10 changes: 9 additions & 1 deletion lib/default-theme/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,19 @@ function resolveOpenGroupIndex (route, items) {
display none
border-bottom 1px solid $borderColor
padding 0.5rem 0 0.75rem 0
a
.nav-item, .github-link
display block
line-height 1.25rem
font-weight 600
font-size 1.1em
padding 0.5rem 0 0.5rem 1.5rem
.nav-item .dropdown-wrapper
.dropdown-title
display inline-block
margin-bottom 5px
.nav-dropdown li
font-size 15px
line-height 1.7rem
.sidebar-links
margin-top 1.5rem

Expand Down
6 changes: 5 additions & 1 deletion lib/default-theme/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ export function getHash (path) {
}
}

export function isExternal (path) {
return outboundRE.test(path)
}

export function ensureExt (path) {
if (outboundRE.test(path)) {
if (isExternal(path)) {
return path
}
const hashMatch = path.match(hashRE)
Expand Down