-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Changes from 7 commits
0494566
121e6ca
3ddca36
72be30c
4bccf3a
5ac3c2a
dbb7a08
50689ea
6de2efa
7eb2563
94c2236
6c9e1a4
5ca1d02
7c6d462
96c30c5
3397dc2
5030421
96a6cc6
7f440d0
4bf15cb
650089d
b3e0583
bf13baa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better put the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you use a mixin here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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" | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe something more readable like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 () { | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
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
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed at 50689ea, thanks