13
13
:alt =" $siteTitle"
14
14
>
15
15
<span
16
+ ref =" siteName"
16
17
class =" site-name"
17
18
v-if =" $siteTitle"
18
19
:class =" { 'can-hide': $site.themeConfig.logo }"
19
20
>{{ $siteTitle }}</span >
20
21
</router-link >
21
22
22
- <div class =" links" >
23
+ <div
24
+ class =" links"
25
+ :style =" {
26
+ 'max-width': linksWrapMaxWidth + 'px'
27
+ }"
28
+ >
23
29
<AlgoliaSearchBox
24
30
v-if =" isAlgoliaSearch"
25
31
:options =" algolia"
@@ -39,6 +45,26 @@ import NavLinks from './NavLinks.vue'
39
45
export default {
40
46
components: { SidebarButton, NavLinks, SearchBox, AlgoliaSearchBox },
41
47
48
+ data () {
49
+ return {
50
+ linksWrapMaxWidth: null
51
+ }
52
+ },
53
+
54
+ mounted () {
55
+ const MOBILE_DESKTOP_BREAKPOINT = 719 // refer to config.styl
56
+ const NAVBAR_VERTICAL_PADDING = parseInt (css (this .$el , ' paddingLeft' )) + parseInt (css (this .$el , ' paddingRight' ))
57
+ const handleLinksWrapWidth = () => {
58
+ if (document .documentElement .clientWidth < MOBILE_DESKTOP_BREAKPOINT ) {
59
+ this .linksWrapMaxWidth = null
60
+ } else {
61
+ this .linksWrapMaxWidth = this .$el .offsetWidth - NAVBAR_VERTICAL_PADDING - this .$refs .siteName .offsetWidth
62
+ }
63
+ }
64
+ handleLinksWrapWidth ()
65
+ window .addEventListener (' resize' , handleLinksWrapWidth, false )
66
+ },
67
+
42
68
computed: {
43
69
algolia () {
44
70
return this .$themeLocaleConfig .algolia || this .$site .themeConfig .algolia || {}
@@ -49,13 +75,23 @@ export default {
49
75
}
50
76
}
51
77
}
78
+
79
+ function css (el , property ) {
80
+ // NOTE: Known bug, will return 'auto' if style value is 'auto'
81
+ const win = el .ownerDocument .defaultView
82
+ // null means not to return pseudo styles
83
+ return win .getComputedStyle (el, null )[property]
84
+ }
52
85
</script >
53
86
54
87
<style lang="stylus">
55
88
@import './styles/config.styl'
56
89
90
+ $navbar-vertical-padding = 0.7rem
91
+ $navbar-horizontal-padding = 1.5rem
92
+
57
93
.navbar
58
- padding 0.7 rem 1.5 rem
94
+ padding $navbar-vertical-padding $navbar-horizontal-padding
59
95
line-height $navbarHeight - 1.4rem
60
96
position relative
61
97
a , span , img
@@ -71,14 +107,26 @@ export default {
71
107
color $textColor
72
108
position relative
73
109
.links
110
+ padding-left 1.5rem
111
+ box-sizing border-box
112
+ background-color white
113
+ white-space nowrap
74
114
font-size 0.9rem
75
115
position absolute
76
- right 1.5rem
77
- top 0.7rem
116
+ right $navbar-horizontal-padding
117
+ top $navbar-vertical-padding
118
+ display flex
119
+ .search-box
120
+ flex : 0 0 auto
121
+ vertical-align top
122
+ .nav-links
123
+ flex 1
78
124
79
125
@media (max-width : $MQMobile)
80
126
.navbar
81
127
padding-left 4rem
82
128
.can-hide
83
129
display none
130
+ .links
131
+ padding-left 1.5rem
84
132
</style >
0 commit comments