forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentationNav.vue
265 lines (235 loc) · 6.64 KB
/
DocumentationNav.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
98
99
100
101
102
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!--
This source file is part of the Swift.org open source project
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->
<template>
<NavBase
:breakpoint="BreakpointName.medium"
:hasOverlay="false"
:hasNoBorder="hasNoBorder"
:isDark="isDark"
isWideFormat
hasFullWidthBorder
class="documentation-nav"
:aria-label="$t('api-reference')"
:showActions="hasMenuItems"
>
<template #pre-title="{ closeNav, isOpen, currentBreakpoint, className }" v-if="displaySidenav">
<div :class="className">
<div class="sidenav-toggle-wrapper">
<button
:aria-label="$t('navigator.open-navigator')"
:id="baseNavOpenSidenavButtonId"
class="sidenav-toggle"
:tabindex="isOpen ? -1 : null"
@click.prevent="handleSidenavToggle(closeNav, currentBreakpoint)"
>
<span class="sidenav-icon-wrapper">
<SidenavIcon class="icon-inline sidenav-icon" />
</span>
</button>
</div>
</div>
</template>
<template #default>
<slot name="title" className="nav-title" />
</template>
<template #tray="{ closeNav }">
<NavMenuItems
v-if="hasMenuItems"
class="nav-menu-settings"
>
<LanguageToggle
v-if="hasLanguageToggle"
:interfaceLanguage="interfaceLanguage"
:objcPath="objcPath"
:swiftPath="swiftPath"
:closeNav="closeNav"
/>
<slot name="menu-items" />
</NavMenuItems>
<slot name="tray-after" />
</template>
<template #after-content>
<slot name="after-content" />
</template>
</NavBase>
</template>
<script>
import NavBase from 'docc-render/components/NavBase.vue';
import NavMenuItems from 'docc-render/components/NavMenuItems.vue';
import { BreakpointName } from 'docc-render/utils/breakpoints';
import SidenavIcon from 'theme/components/Icons/SidenavIcon.vue';
import { SIDEBAR_HIDE_BUTTON_ID } from 'docc-render/constants/sidebar';
import { baseNavOpenSidenavButtonId } from 'docc-render/constants/nav';
import LanguageToggle from './DocumentationNav/LanguageToggle.vue';
export default {
name: 'DocumentationNav',
components: {
SidenavIcon,
NavBase,
NavMenuItems,
LanguageToggle,
},
props: {
isDark: {
type: Boolean,
default: false,
},
hasNoBorder: {
type: Boolean,
default: false,
},
interfaceLanguage: {
type: String,
required: false,
},
objcPath: {
type: String,
required: false,
},
swiftPath: {
type: String,
required: false,
},
displaySidenav: {
type: Boolean,
default: false,
},
},
computed: {
baseNavOpenSidenavButtonId: () => baseNavOpenSidenavButtonId,
BreakpointName: () => BreakpointName,
hasLanguageToggle: ({ interfaceLanguage, swiftPath, objcPath }) => (
!!(interfaceLanguage && (swiftPath || objcPath))),
hasMenuItems: ({ hasLanguageToggle, $slots }) => !!(hasLanguageToggle || $slots['menu-items']),
},
methods: {
async handleSidenavToggle(closeNav, currentBreakpoint) {
// close the navigation
await closeNav();
// toggle the sidenav
this.$emit('toggle-sidenav', currentBreakpoint);
await this.$nextTick();
const trigger = document.getElementById(SIDEBAR_HIDE_BUTTON_ID);
if (trigger) {
trigger.focus();
}
},
},
};
</script>
<style scoped lang="scss">
@import 'docc-render/styles/_core.scss';
$sidenav-icon-size: 19px;
$sidenav-icon-padding-size: 5px;
// overwrite the typography of menu items outside of breakpoint only
:deep() .nav-menu {
@include font-styles(documentation-nav);
&-settings {
// ensure settings can get smaller if needed
min-width: 0;
@include font-styles(nav-toggles);
@include breakpoint-only-largenav() {
margin-left: $nav-space-between-elements;
}
.nav-menu-setting {
display: flex;
align-items: center;
color: var(--color-nav-current-link);
margin-left: 0;
min-width: 0;
.nav-menu-link {
font-weight: $font-weight-semibold;
@include underline-text;
}
&:first-child:not(:only-child) {
margin-right: $nav-space-between-elements;
@include nav-in-breakpoint() {
margin-right: 0;
}
}
@include nav-dark() {
color: var(--color-nav-dark-current-link);
}
@include nav-in-breakpoint() {
&:not(:first-child) {
border-top: 1px solid var(--color-fill-gray-tertiary);
}
}
}
}
}
.documentation-nav {
--color-nav-background: var(--color-fill);
:deep() {
.nav-title {
@include font-styles(nav-title-large);
}
}
}
.sidenav-toggle-wrapper {
display: flex;
margin-top: 1px;
margin-right: $nav-padding / 2;
// This is a hack to enforce the toggle to be visible when in breakpoint,
// even if already toggled off on desktop. Conditionally checking the current breakpoint,
// would trigger animations when switching between breakpoints.
@include nav-in-breakpoint() {
display: flex !important;
}
}
// desktop only animation for the toggle
@include breakpoints-from(large, nav) {
.sidenav-toggle-enter-active, .sidenav-toggle-leave-active {
transition: margin $adjustable-sidebar-hide-transition-duration ease-in 0s;
}
.sidenav-toggle-enter, .sidenav-toggle-leave-to {
// 2x the nav padding, 1px border, and the size of the icon
margin-left: (rem($sidenav-icon-size + 1px) + $nav-padding * 2) * -1;
}
}
.sidenav-toggle {
align-self: center;
color: var(--color-nav-link-color);
position: relative;
margin: 0 (-$sidenav-icon-padding-size);
border-radius: $nano-border-radius;
@include nav-dark {
color: var(--color-nav-dark-link-color);
}
&:hover .sidenav-icon-wrapper {
background: var(--color-fill-gray-quaternary);
.theme-dark & {
background: dark-color(fill-gray-quaternary);
}
}
&__separator {
height: .8em;
width: 1px;
background: var(--color-nav-color);
align-self: center;
margin: 0 $nav-padding;
}
@include nav-in-breakpoint() {
&__separator {
display: none;
}
}
}
.sidenav-icon-wrapper {
padding: $sidenav-icon-padding-size;
display: flex;
align-items: center;
justify-content: center;
border-radius: $nano-border-radius;
}
.sidenav-icon {
display: flex;
width: $sidenav-icon-size;
height: $sidenav-icon-size;
}
</style>