Skip to content

Ensure that all the dropdown's style are consistent #156

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

Merged
merged 4 commits into from
Apr 20, 2018
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
57 changes: 30 additions & 27 deletions lib/default-theme/DropdownLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,37 @@
<div class="dropdown-wrapper" :class="{ open }">
<a class="dropdown-title" @click="toggle">
<span class="title">{{ item.text }}</span>
<span class="arrow"></span>
<span class="arrow" :class="open ? 'down' : 'right'"></span>
</a>
<ul class="nav-dropdown">
<li
<DropdownTransition>
<ul class="nav-dropdown" v-show="open">
<li
class="dropdown-item"
v-for="subItem in item.items"
:key="subItem.link">
<h4 v-if="subItem.type === 'links'">{{ subItem.text }}</h4>
<ul class="dropdown-subitem-wrapper" v-if="subItem.type === 'links'">
<li
<h4 v-if="subItem.type === 'links'">{{ subItem.text }}</h4>
<ul class="dropdown-subitem-wrapper" v-if="subItem.type === 'links'">
<li
class="dropdown-subitem"
v-for="childSubItem in subItem.items"
:key="childSubItem.link">
<NavLink :item="childSubItem"/>
</li>
</ul>
<NavLink v-else :item="subItem"/>
</li>
</ul>
<NavLink :item="childSubItem"/>
</li>
</ul>
<NavLink v-else :item="subItem"/>
</li>
</ul>
</DropdownTransition>
</div>
</template>

<script>
import { isExternal, ensureExt } from './util'
import NavLink from './NavLink.vue'
import DropdownTransition from './DropdownTransition.vue'

export default {
components: { NavLink },
components: { NavLink, DropdownTransition },
data() {
return {
open: false
Expand All @@ -54,16 +57,12 @@ export default {
.dropdown-wrapper
.dropdown-title
display block
&:hover
border-color transparent
.arrow
display inline-block
vertical-align middle
margin-top -1px
margin-left 0.4rem
width 0
height 0
border-left 4px solid transparent
border-right 4px solid transparent
border-top 5px solid #ccc
.nav-dropdown
.dropdown-item
color inherit
Expand Down Expand Up @@ -109,14 +108,9 @@ export default {
.dropdown-wrapper
&.open .dropdown-title
margin-bottom 0.5rem
&:not(.open)
.dropdown-title .arrow
border-top 4px solid transparent
border-bottom 4px solid transparent
border-left 5px solid #ccc
.nav-dropdown
display none
.nav-dropdown
transition height .1s ease-out
overflow hidden
.dropdown-item
h4
border-top 0
Expand All @@ -133,9 +127,18 @@ export default {
@media (min-width: $MQMobile)
.dropdown-wrapper
&:hover .nav-dropdown
display block
// override the inline style.
display block !important
.dropdown-title .arrow
// make the arrow always down at desktop
border-left 4px solid transparent
border-right 4px solid transparent
border-top 6px solid $arrowBgColor
border-bottom 0
.nav-dropdown
display none
// Avoid height shaked by clicking
height auto !important
box-sizing border-box;
max-height calc(100vh - 2.7rem)
overflow-y auto
Expand Down
29 changes: 29 additions & 0 deletions lib/default-theme/DropdownTransition.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<transition name="dropdown"
@enter="setHeight"
@after-enter="unsetHeight"
@before-leave="setHeight">
<slot></slot>
</transition>
</template>

<script>
export default {
name: 'SidebarGroup',
methods: {
setHeight (items) {
// explicitly set height so that it can be transitioned
items.style.height = items.scrollHeight + 'px'
},
unsetHeight (items) {
items.style.height = ''
}
}
}
</script>

<style lang="stylus">
.dropdown-enter, .dropdown-leave-to
height 0 !important

</style>
24 changes: 5 additions & 19 deletions lib/default-theme/SidebarGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,26 @@
<span>{{ item.title }}</span>
<span class="arrow"
v-if="collapsable"
:class="open ? 'up' : 'down'"></span>
:class="open ? 'down' : 'right'"></span>
</p>
<transition name="sidebar-group"
@enter="setHeight"
@after-enter="unsetHeight"
@before-leave="setHeight">
<DropdownTransition>
<ul class="sidebar-group-items" ref="items" v-if="open || !collapsable">
<li v-for="child in item.children">
<SidebarLink :item="child"/>
</li>
</ul>
</transition>
</DropdownTransition>
</div>
</template>

<script>
import SidebarLink from './SidebarLink.vue'
import DropdownTransition from './DropdownTransition.vue'

export default {
name: 'SidebarGroup',
props: ['item', 'first', 'open', 'collapsable'],
components: { SidebarLink },
methods: {
setHeight (items) {
// explicitly set height so that it can be transitioned
items.style.height = items.scrollHeight + 'px'
},
unsetHeight (items) {
items.style.height = ''
}
}
components: { SidebarLink, DropdownTransition }
}
</script>

Expand Down Expand Up @@ -71,7 +60,4 @@ export default {
.sidebar-group-items
transition height .1s ease-out
overflow hidden

.sidebar-group-enter, .sidebar-group-leave-to
height 0 !important
</style>
8 changes: 4 additions & 4 deletions lib/default-theme/styles/arrow.styl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
&.up
border-left 4px solid transparent
border-right 4px solid transparent
border-bottom 6px solid $textColor
border-bottom 6px solid $arrowBgColor
&.down
border-left 4px solid transparent
border-right 4px solid transparent
border-top 6px solid $textColor
border-top 6px solid $arrowBgColor
&.right
border-top 4px solid transparent
border-bottom 4px solid transparent
border-left 6px solid $textColor
border-left 6px solid $arrowBgColor
&.left
border-top 4px solid transparent
border-bottom 4px solid transparent
border-right 6px solid $textColor
border-right 6px solid $arrowBgColor
1 change: 1 addition & 0 deletions lib/default-theme/styles/config.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ $accentColor = #3eaf7c
$textColor = #2c3e50
$borderColor = #eaecef
$codeBgColor = #282c34
$arrowBgColor = #ccc

// layout
$navbarHeight = 3.6rem
Expand Down