DropdownLink.vue 3.5 KB
Newer Older
U
ULIVZ 已提交
1 2
<template>
  <div class="dropdown-wrapper" :class="{ open }">
E
Evan You 已提交
3
    <a class="dropdown-title" @click="toggle">
U
ULIVZ 已提交
4 5
      <span class="title">{{ item.text }}</span>
      <span class="arrow"></span>
E
Evan You 已提交
6
    </a>
U
ULIVZ 已提交
7 8 9 10 11 12 13 14 15 16 17
    <ul class="nav-dropdown">
      <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
            class="dropdown-subitem"
            v-for="childSubItem in subItem.items"
            :key="childSubItem.link">
18
            <NavLink :item="childSubItem"/>
U
ULIVZ 已提交
19 20
          </li>
        </ul>
21
        <NavLink v-else :item="subItem"/>
U
ULIVZ 已提交
22 23 24 25 26 27
      </li>
    </ul>
  </div>
</template>

<script>
28 29
import { isExternal, ensureExt } from './util'
import NavLink from './NavLink.vue'
U
ULIVZ 已提交
30

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
export default {
  components: { NavLink },
  data() {
    return {
      open: false
    }
  },
  props: {
    item: {
      required: true
    }
  },
  methods: {
    toggle() {
      this.open = !this.open
U
ULIVZ 已提交
46 47
    }
  }
48
}
U
ULIVZ 已提交
49 50 51 52 53 54 55
</script>

<style lang="stylus">
@import './styles/config.styl'

.dropdown-wrapper
  .dropdown-title
E
Evan You 已提交
56
    display block
U
ULIVZ 已提交
57 58 59 60
    .arrow
      display inline-block
      vertical-align middle
      margin-top -1px
E
Evan You 已提交
61
      margin-left 0.4rem
U
ULIVZ 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
      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
      line-height 1.7rem
      h4
        margin 0.45rem 0 0
        border-top 1px solid #eee
        padding 0.45rem 1.5rem 0 1.25rem
      .dropdown-subitem-wrapper
        padding 0
        list-style none
        .dropdown-subitem
          font-size 0.9em
      a
        display block
        height 1.7rem
        line-height 1.7rem
        position relative
        border-bottom none
        font-weight 400
        margin-bottom 0
        padding 0 1.5rem 0 1.25rem
        &:hover
          color $accentColor
        &.router-link-active
          color $accentColor
          &::after
            content ""
            width 0
            height 0
            border-left 5px solid $accentColor
E
Evan You 已提交
98 99
            border-top 3px solid transparent
            border-bottom 3px solid transparent
U
ULIVZ 已提交
100
            position absolute
E
Evan You 已提交
101 102
            top calc(50% - 2px)
            left 9px
U
ULIVZ 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
      &:first-child h4
        margin-top 0
        padding-top 0
        border-top 0

@media (max-width: $MQMobile)
  .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
      .dropdown-item
        h4
          border-top 0
          margin-top 0
          padding-top 0
        h4, & > a
          font-size 15px
          height 2rem
          line-height 2rem
        .dropdown-subitem
          font-size 14px
          padding-left 1rem

@media (min-width: $MQMobile)
  .dropdown-wrapper
    &:hover .nav-dropdown
      display block
    .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>