Skip to content

Commit 7079145

Browse files
committed
add a rightSidebar option
1 parent 7ea391b commit 7079145

File tree

6 files changed

+87
-17
lines changed

6 files changed

+87
-17
lines changed

cypress/integration/sidebar/config.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ context('sidebar.configurations', () => {
3232
'loadnavbar',
3333
'loadsidebar',
3434
'hidesidebar',
35+
// 'rightSidebar', // This would require updated snapshots. I think we should get playwright in first.
3536
'submaxlevel',
3637
'auto2top',
3738
'homepage',

docs/configuration.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ window.$docsify = {
108108
## hideSidebar
109109

110110
- Type : `Boolean`
111-
- Default: `true`
111+
- Default: `false`
112112

113113
This option will completely hide your sidebar and wont render any content of the side even .
114114

@@ -118,6 +118,13 @@ window.$docsify = {
118118
};
119119
```
120120

121+
## rightSidebar
122+
123+
- Type: `Boolean|String`
124+
- Default: `false`
125+
126+
If true, the sidebar will be on the right side instead of the left.
127+
121128
## subMaxLevel
122129

123130
- Type: `Number`

docs/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
coverpage: true,
4040
executeScript: true,
4141
loadSidebar: true,
42+
rightSidebar: true, // TODO remove before merging
43+
repo: 'http://foo.bar', // TODO remove before merging
4244
loadNavbar: true,
4345
mergeNavbar: true,
4446
maxLevel: 4,

index.html

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
coverpage: true,
3535
executeScript: true,
3636
loadSidebar: true,
37+
rightSidebar: true, // TODO remove before merging
38+
repo: 'http://foo.bar', // TODO remove before merging
3739
loadNavbar: true,
3840
mergeNavbar: true,
3941
maxLevel: 4,

src/core/init/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import { initRouter } from '../router';
44
import { initEvent } from '../event';
55
import { initFetch } from '../fetch';
66
import { isFn } from '../util/core';
7+
import { body } from '../util/dom';
78
import { initLifecycle, callHook } from './lifecycle';
89

910
export function initMixin(proto) {
1011
proto._init = function() {
1112
const vm = this;
1213
vm.config = config(vm);
1314

15+
if (vm.config.rightSidebar) {
16+
body.classList.add('right-sidebar');
17+
}
18+
1419
initLifecycle(vm); // Init hooks
1520
initPlugin(vm); // Install plugins
1621
callHook(vm, 'init');

src/themes/basic/_layout.styl

+69-16
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ li input[type='checkbox']
7979
vertical-align middle
8080

8181
/* navbar */
82+
body.right-sidebar .app-nav
83+
margin 25px 0 0 60px
84+
left 0
85+
right unset
86+
87+
& > ul
88+
padding-inline-start: 0;
89+
padding-inline-end: 40px; // Chrome's default value.
90+
8291
.app-nav
8392
margin 25px 60px 0 0
8493
position absolute
@@ -159,6 +168,10 @@ li input[type='checkbox']
159168
display block
160169

161170
/* github corner */
171+
body.right-sidebar .github-corner
172+
right unset
173+
transform scaleX(-1)
174+
162175
.github-corner
163176
border-bottom 0
164177
position fixed
@@ -199,6 +212,11 @@ main.hidden
199212
text-decoration underline
200213

201214
/* sidebar */
215+
body.right-sidebar .sidebar
216+
left 100%
217+
border-left 1px solid rgba(0, 0, 0, 0.07)
218+
border-right none
219+
202220
.sidebar
203221
border-right 1px solid rgba(0, 0, 0, 0.07)
204222
overflow-y auto
@@ -265,6 +283,11 @@ main.hidden
265283
background rgba(136, 136, 136, 0.1)
266284

267285
/* sidebar toggle */
286+
body.right-sidebar .sidebar-toggle
287+
left unset
288+
right 0
289+
transform scaleX(-1) // keeps toggle button on the right
290+
268291
.sidebar-toggle
269292
background-color transparent
270293
background-color rgba($color-bg, 0.8)
@@ -295,14 +318,18 @@ body.sticky
295318
position fixed
296319

297320
/* main content */
321+
body.right-sidebar .content
322+
right $sidebar-width
323+
left 0
324+
298325
.content
299326
padding-top 60px
300327
position absolute
301328
top 0
302329
right 0
303330
bottom 0
304331
left $sidebar-width
305-
transition left 250ms ease
332+
transition left 250ms ease, right 250ms ease
306333

307334
/* markdown content found on pages */
308335
.markdown-section
@@ -391,16 +418,25 @@ body.sticky
391418
.markdown-section ul.task-list > li
392419
list-style-type none
393420

394-
body.close
395-
.sidebar
421+
body
422+
&.close .sidebar
396423
transform translateX(- $sidebar-width)
397424

398-
.sidebar-toggle
425+
&.right-sidebar .sidebar
426+
transform translateX(- $sidebar-width)
427+
428+
&.close.right-sidebar .sidebar
429+
transform translateX(0)
430+
431+
&.close .sidebar-toggle
399432
width auto
400433

401-
.content
434+
$.close .content
402435
left 0
403436

437+
&.close.right-sidebar .content
438+
right 0
439+
404440
@media print
405441
.github-corner, .sidebar-toggle, .sidebar, .app-nav
406442
display none
@@ -419,6 +455,9 @@ body.close
419455
height auto
420456
overflow-x hidden
421457

458+
body.right-sidebar .sidebar
459+
left 100%
460+
422461
.sidebar
423462
left - $sidebar-width
424463
transition transform 250ms ease-out
@@ -438,21 +477,35 @@ body.close
438477
width auto
439478
padding 30px 30px 10px 10px
440479

441-
body.close
442-
.sidebar
480+
body
481+
// Note, on mobile .close means open, because mobile starts with the sidebar
482+
// closed (opposite of desktop which starts with sidebar open), and the
483+
// `close` class is toggled by the toggle button.
484+
485+
&.close .sidebar
443486
transform translateX($sidebar-width)
444487

445-
.sidebar-toggle
446-
background-color rgba($color-bg, 0.8)
447-
transition 1s background-color
448-
width $sidebar-width - 16px
449-
padding 10px
488+
&.right-sidebar .sidebar
489+
transform translateX(0)
450490

451-
.content
452-
transform translateX($sidebar-width)
491+
&.close.right-sidebar .sidebar
492+
transform translateX(- $sidebar-width)
453493

454-
.app-nav, .github-corner
455-
display none
494+
&.close
495+
.sidebar-toggle
496+
background-color rgba($color-bg, 0.8)
497+
transition 1s background-color
498+
width $sidebar-width - 16px
499+
padding 10px
500+
501+
.content
502+
transform translateX($sidebar-width)
503+
504+
&.right-sidebar .content
505+
transform translateX(- $sidebar-width)
506+
507+
.app-nav, .github-corner
508+
display none
456509

457510
.github-corner
458511
&:hover .octo-arm

0 commit comments

Comments
 (0)