Skip to content

Commit 914871d

Browse files
author
Dobromir Hristov
authored
Change the sidenav breakpoints to use Medium instead (swiftlang#61)
* refactor: change the sidenav breakpoints to use Medium instead * fix: emitter scope * fix: head spacing
1 parent fc0656f commit 914871d

File tree

8 files changed

+52
-44
lines changed

8 files changed

+52
-44
lines changed

src/components/AdjustableSidebarWidth.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
<div class="content">
3737
<slot />
3838
</div>
39-
<BreakpointEmitter @change="breakpoint = $event" />
39+
<BreakpointEmitter :scope="BreakpointScopes.nav" @change="breakpoint = $event" />
4040
</div>
4141
</template>
4242

4343
<script>
4444
import { storage } from 'docc-render/utils/storage';
4545
import debounce from 'docc-render/utils/debounce';
4646
import BreakpointEmitter from 'docc-render/components/BreakpointEmitter.vue';
47-
import { BreakpointName } from 'docc-render/utils/breakpoints';
47+
import { BreakpointName, BreakpointScopes } from 'docc-render/utils/breakpoints';
4848
import { waitFrames } from 'docc-render/utils/loading';
4949
import scrollLock from 'docc-render/utils/scroll-lock';
5050
import FocusTrap from 'docc-render/utils/FocusTrap';
@@ -137,6 +137,7 @@ export default {
137137
dragging: isDragging, 'force-open': openExternally, 'no-transition': noTransition,
138138
}),
139139
scrollLockID: () => SCROLL_LOCK_ID,
140+
BreakpointScopes: () => BreakpointScopes,
140141
},
141142
async mounted() {
142143
window.addEventListener('keydown', this.onEscapeKeydown);
@@ -166,15 +167,13 @@ export default {
166167
}, 250, true, true),
167168
},
168169
windowWidth: 'getWidthInCheck',
169-
async breakpoint(value, oldValue) {
170+
async breakpoint(value) {
170171
// adjust the width, so it does not go outside of limits
171172
this.getWidthInCheck();
172173
// make sure we close the nav
173-
if (oldValue === BreakpointName.small) {
174+
if (value === BreakpointName.large) {
174175
this.closeMobileSidebar();
175176
}
176-
// if we are not going into the `small` breakpoint, return early
177-
if (oldValue !== BreakpointName.small && value !== BreakpointName.small) return;
178177
// make sure we dont apply transitions for a few moments, to prevent flashes
179178
this.noTransition = true;
180179
// await for a few moments
@@ -276,15 +275,15 @@ export default {
276275
277276
.adjustable-sidebar-width {
278277
display: flex;
279-
@include breakpoint(small) {
278+
@include breakpoint(medium, nav) {
280279
display: block;
281280
position: relative;
282281
}
283282
}
284283
285284
.sidebar {
286285
position: relative;
287-
@include breakpoint(small) {
286+
@include breakpoint(medium, nav) {
288287
position: static;
289288
}
290289
}
@@ -299,7 +298,7 @@ export default {
299298
transition: none !important;
300299
}
301300
302-
@include breakpoint(small) {
301+
@include breakpoint(medium, nav) {
303302
width: 0 !important;
304303
overflow: hidden;
305304
min-width: 0;
@@ -355,7 +354,7 @@ export default {
355354
width: 10px;
356355
}
357356
358-
@include breakpoint(small) {
357+
@include breakpoint(medium, nav) {
359358
display: none;
360359
}
361360

src/components/DocumentationTopic/DocumentationNav.vue

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<template>
1212
<NavBase
13-
:breakpoint="isWideFormat ? BreakpointName.small: BreakpointName.medium"
13+
:breakpoint="BreakpointName.medium"
1414
:hasOverlay="false"
1515
hasSolidBackground
1616
:hasNoBorder="hasNoBorder"
@@ -164,7 +164,7 @@ $sidenav-icon-size: 19px;
164164
.nav-title {
165165
@include font-styles(documentation-nav);
166166
167-
@include breakpoint(small, $scope: nav) {
167+
@include breakpoint(medium, $scope: nav) {
168168
padding-top: 0;
169169
}
170170
@@ -183,12 +183,4 @@ $sidenav-icon-size: 19px;
183183
width: $sidenav-icon-size;
184184
height: $sidenav-icon-size;
185185
}
186-
187-
// make sure toggle is not visible, from medium up, in default scope.
188-
// Sidenav is only toggle-able at small, in default scope.
189-
.sidenav-toggle {
190-
@include breakpoints-from(medium) {
191-
display: none;
192-
}
193-
}
194186
</style>

src/components/NavBase.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ $content-max-width: map-deep-get($breakpoint-attributes, (nav, large, content-wi
516516
517517
.pre-title {
518518
display: none;
519-
@include breakpoint(small, $scope: nav) {
519+
@include nav-in-breakpoint() {
520520
display: flex;
521521
padding: 0;
522522
}
@@ -636,15 +636,15 @@ $content-max-width: map-deep-get($breakpoint-attributes, (nav, large, content-wi
636636
padding-top: 0;
637637
height: $nav-height-small;
638638
width: 90%;
639-
640-
@include nav-is-wide-format() {
641-
width: 100%;
642-
justify-content: center;
643-
}
644639
}
645640
646641
@include nav-in-breakpoint {
647642
grid-area: title;
643+
644+
@include nav-is-wide-format(true) {
645+
width: 100%;
646+
justify-content: center;
647+
}
648648
}
649649
650650
/deep/ span {

src/components/Navigator.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default {
204204
transition: height 0.3s linear;
205205
border-left: 1px solid var(--color-grid);
206206
207-
@include breakpoint(small) {
207+
@include breakpoint(medium, nav) {
208208
position: static;
209209
height: 100%;
210210
border-left: none;

src/components/Navigator/NavigatorCard.vue

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="navigator-card">
1313
<div class="head-wrapper">
1414
<button class="close-card-mobile" @click="$emit('close')">
15-
<InlineCloseIcon class="icon-inline close-icon" />
15+
<SidenavIcon class="icon-inline close-icon" />
1616
</button>
1717
<Reference :url="technologyPath" class="navigator-head" :id="INDEX_ROOT_KEY">
1818
<NavigatorLeafIcon :type="type" with-colors class="card-icon" />
@@ -86,7 +86,7 @@ import { INDEX_ROOT_KEY, SIDEBAR_ITEM_SIZE } from 'docc-render/constants/sidebar
8686
import { safeHighlightPattern } from 'docc-render/utils/search-utils';
8787
import NavigatorLeafIcon from 'docc-render/components/Navigator/NavigatorLeafIcon.vue';
8888
import NavigatorCardItem from 'docc-render/components/Navigator/NavigatorCardItem.vue';
89-
import InlineCloseIcon from 'theme/components/Icons/InlineCloseIcon.vue';
89+
import SidenavIcon from 'theme/components/Icons/SidenavIcon.vue';
9090
import FilterIcon from 'theme/components/Icons/FilterIcon.vue';
9191
import ClearRoundedIcon from 'theme/components/Icons/ClearRoundedIcon.vue';
9292
import Reference from 'docc-render/components/ContentNode/Reference.vue';
@@ -109,7 +109,7 @@ export default {
109109
components: {
110110
ClearRoundedIcon,
111111
FilterIcon,
112-
InlineCloseIcon,
112+
SidenavIcon,
113113
NavigatorCardItem,
114114
NavigatorLeafIcon,
115115
RecycleScroller,
@@ -519,8 +519,13 @@ $navigator-card-vertical-spacing: 8px !default;
519519
background: var(--color-fill-gray-quaternary);
520520
}
521521
522-
@include breakpoint(small) {
522+
@include breakpoint(medium, nav) {
523523
justify-content: center;
524+
padding: 14px $navigator-card-horizontal-spacing;
525+
}
526+
527+
@include breakpoint(small, nav) {
528+
padding: 12px $navigator-card-horizontal-spacing;
524529
}
525530
}
526531
@@ -529,7 +534,7 @@ $navigator-card-vertical-spacing: 8px !default;
529534
height: 19px;
530535
}
531536
532-
@include breakpoint(small) {
537+
@include breakpoint(medium, nav) {
533538
.filter-wrapper {
534539
order: 2;
535540
}
@@ -548,18 +553,23 @@ $navigator-card-vertical-spacing: 8px !default;
548553
.close-card-mobile {
549554
display: none;
550555
position: absolute;
551-
left: 20px;
552556
top: 50%;
553557
z-index: 1;
554558
transform: translateY(-50%);
555559
color: var(--color-link);
556560
557-
@include breakpoint(small) {
561+
@include breakpoint(medium, nav) {
558562
display: flex;
563+
left: $nav-padding-wide;
564+
}
565+
566+
@include breakpoint(small, nav) {
567+
left: $nav-padding-small;
559568
}
560569
561570
.close-icon {
562-
width: 1em;
571+
width: 19px;
572+
height: 19px;
563573
}
564574
}
565575
@@ -572,7 +582,7 @@ $navigator-card-vertical-spacing: 8px !default;
572582
padding-right: 0;
573583
flex: 1 1 auto;
574584
min-height: 0;
575-
@include breakpoint(small) {
585+
@include breakpoint(medium, nav) {
576586
--card-horizontal-spacing: 20px;
577587
--card-vertical-spacing: 0px;
578588
}
@@ -589,7 +599,7 @@ $navigator-card-vertical-spacing: 8px !default;
589599
padding: 14px 30px;
590600
border-top: 1px solid var(--color-grid);
591601
592-
@include breakpoint(small) {
602+
@include breakpoint(medium, nav) {
593603
border: none;
594604
padding: 10px 20px;
595605
}

src/views/DocumentationTopic.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export default {
337337
.doc-topic-aside {
338338
height: 100%;
339339
box-sizing: border-box;
340-
@include breakpoint(small) {
340+
@include breakpoint(medium, nav) {
341341
background: var(--color-fill);
342342
}
343343
}

tests/unit/components/AdjustableSidebarWidth.spec.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { waitFrames } from '@/utils/loading';
2121
import FocusTrap from '@/utils/FocusTrap';
2222
import scrollLock from 'docc-render/utils/scroll-lock';
2323
import changeElementVOVisibility from 'docc-render/utils/changeElementVOVisibility';
24-
import { BreakpointName } from '@/utils/breakpoints';
24+
import { BreakpointName, BreakpointScopes } from '@/utils/breakpoints';
2525
import { createEvent, flushPromises } from '../../../test-utils';
2626

2727
jest.mock('docc-render/utils/debounce');
@@ -110,7 +110,14 @@ describe('AdjustableSidebarWidth', () => {
110110
const wrapper = createWrapper();
111111
const aside = wrapper.find('.aside');
112112
expect(aside.classes()).not.toContain('no-transition');
113-
wrapper.find(BreakpointEmitter).vm.$emit('change', 'small');
113+
const emitter = wrapper.find(BreakpointEmitter);
114+
expect(emitter.props('scope')).toEqual(BreakpointScopes.nav);
115+
emitter.vm.$emit('change', 'small');
116+
expect(aside.classes()).toContain('no-transition');
117+
await waitFrames(5);
118+
expect(aside.classes()).not.toContain('no-transition');
119+
// try going back to large now
120+
emitter.vm.$emit('change', 'large');
114121
expect(aside.classes()).toContain('no-transition');
115122
await waitFrames(5);
116123
expect(aside.classes()).not.toContain('no-transition');
@@ -194,18 +201,18 @@ describe('AdjustableSidebarWidth', () => {
194201
expect(AdjustableSidebarWidth.watch.$route).toEqual('closeMobileSidebar');
195202
});
196203

197-
it('closes the nav, on breakpoint change from small to medium', async () => {
204+
it('closes the nav, on breakpoint change from medium to large', async () => {
198205
const wrapper = createWrapper({
199206
propsData: {
200207
openExternally: true,
201208
},
202209
});
203210
// setup
204-
wrapper.find(BreakpointEmitter).vm.$emit('change', BreakpointName.small);
211+
wrapper.find(BreakpointEmitter).vm.$emit('change', BreakpointName.medium);
205212
await wrapper.vm.$nextTick();
206213
expect(wrapper.emitted('update:openExternally')).toBeFalsy();
207214
// true test
208-
wrapper.find(BreakpointEmitter).vm.$emit('change', BreakpointName.medium);
215+
wrapper.find(BreakpointEmitter).vm.$emit('change', BreakpointName.large);
209216
expect(wrapper.emitted('update:openExternally')).toEqual([[false]]);
210217
});
211218
});

tests/unit/components/DocumentationTopic/DocumentationNav.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('DocumentationNav', () => {
7676
expect(nav.props()).toHaveProperty('hasNoBorder', false);
7777
expect(nav.props()).toHaveProperty('hasFullWidthBorder', true);
7878
expect(nav.props()).toHaveProperty('hasOverlay', false);
79-
expect(nav.props()).toHaveProperty('breakpoint', BreakpointName.small);
79+
expect(nav.props()).toHaveProperty('breakpoint', BreakpointName.medium);
8080
expect(nav.props()).toHaveProperty('isWideFormat', true);
8181
});
8282

0 commit comments

Comments
 (0)