Skip to content

[do not merge] add a rightSidebar option #1288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cypress/integration/sidebar/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ context('sidebar.configurations', () => {
'loadnavbar',
'loadsidebar',
'hidesidebar',
// 'rightSidebar', // This would require updated snapshots. I think we should get playwright in first.
'submaxlevel',
'auto2top',
'homepage',
Expand Down
9 changes: 8 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ window.$docsify = {
## hideSidebar

- Type : `Boolean`
- Default: `true`
- Default: `false`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrong


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

Expand All @@ -118,6 +118,13 @@ window.$docsify = {
};
```

## rightSidebar

- Type: `Boolean|String`
- Default: `false`

If true, the sidebar will be on the right side instead of the left.

## subMaxLevel

- Type: `Number`
Expand Down
2 changes: 2 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
coverpage: true,
executeScript: true,
loadSidebar: true,
rightSidebar: true, // TODO remove before merging
repo: 'http://foo.bar', // TODO remove before merging
loadNavbar: true,
mergeNavbar: true,
maxLevel: 4,
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
coverpage: true,
executeScript: true,
loadSidebar: true,
rightSidebar: true, // TODO remove before merging
repo: 'http://foo.bar', // TODO remove before merging
loadNavbar: true,
mergeNavbar: true,
maxLevel: 4,
Expand Down
5 changes: 5 additions & 0 deletions src/core/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { initRouter } from '../router';
import { initEvent } from '../event';
import { initFetch } from '../fetch';
import { isFn } from '../util/core';
import { body } from '../util/dom';
import { initLifecycle, callHook } from './lifecycle';

export function initMixin(proto) {
proto._init = function() {
const vm = this;
vm.config = config(vm);

if (vm.config.rightSidebar) {
body.classList.add('right-sidebar');
}

initLifecycle(vm); // Init hooks
initPlugin(vm); // Install plugins
callHook(vm, 'init');
Expand Down
85 changes: 69 additions & 16 deletions src/themes/basic/_layout.styl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ li input[type='checkbox']
vertical-align middle

/* navbar */
body.right-sidebar .app-nav
margin 25px 0 0 60px
left 0
right unset

& > ul
padding-inline-start: 0;
padding-inline-end: 40px; // Chrome's default value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhildenbiddle I aimed to make all the changes in here non-breaking for the end user.

You may have some opinion on how better to organize this change. Happy to hear if you do!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for padding-inline-end: 40px; thing is to flip it to the other side when the menu is on the left, otherwise it has a default style in Chrome's user-agent style of padding-inline-start: 40px;.

Maybe padding-inline-start: 40px should be hard-coded for nonright-sidebar` mode, otherwise that one can vary from browser to browser (I don't know if they settled on the same values, haven't checked).

.app-nav
margin 25px 60px 0 0
position absolute
Expand Down Expand Up @@ -159,6 +168,10 @@ li input[type='checkbox']
display block

/* github corner */
body.right-sidebar .github-corner
right unset
transform scaleX(-1)

.github-corner
border-bottom 0
position fixed
Expand Down Expand Up @@ -199,6 +212,11 @@ main.hidden
text-decoration underline

/* sidebar */
body.right-sidebar .sidebar
left 100%
border-left 1px solid rgba(0, 0, 0, 0.07)
border-right none

.sidebar
border-right 1px solid rgba(0, 0, 0, 0.07)
overflow-y auto
Expand Down Expand Up @@ -265,6 +283,11 @@ main.hidden
background rgba(136, 136, 136, 0.1)

/* sidebar toggle */
body.right-sidebar .sidebar-toggle
left unset
right 0
transform scaleX(-1) // keeps toggle button on the right

.sidebar-toggle
background-color transparent
background-color rgba($color-bg, 0.8)
Expand Down Expand Up @@ -295,14 +318,18 @@ body.sticky
position fixed

/* main content */
body.right-sidebar .content
right $sidebar-width
left 0

.content
padding-top 60px
position absolute
top 0
right 0
bottom 0
left $sidebar-width
transition left 250ms ease
transition left 250ms ease, right 250ms ease

/* markdown content found on pages */
.markdown-section
Expand Down Expand Up @@ -391,16 +418,25 @@ body.sticky
.markdown-section ul.task-list > li
list-style-type none

body.close
.sidebar
body
&.close .sidebar
transform translateX(- $sidebar-width)

.sidebar-toggle
&.right-sidebar .sidebar
transform translateX(- $sidebar-width)

&.close.right-sidebar .sidebar
transform translateX(0)

&.close .sidebar-toggle
width auto

.content
$.close .content
left 0

&.close.right-sidebar .content
right 0

@media print
.github-corner, .sidebar-toggle, .sidebar, .app-nav
display none
Expand All @@ -419,6 +455,9 @@ body.close
height auto
overflow-x hidden

body.right-sidebar .sidebar
left 100%

.sidebar
left - $sidebar-width
transition transform 250ms ease-out
Expand All @@ -438,21 +477,35 @@ body.close
width auto
padding 30px 30px 10px 10px

body.close
.sidebar
body
// Note, on mobile .close means open, because mobile starts with the sidebar
// closed (opposite of desktop which starts with sidebar open), and the
// `close` class is toggled by the toggle button.

&.close .sidebar
transform translateX($sidebar-width)

.sidebar-toggle
background-color rgba($color-bg, 0.8)
transition 1s background-color
width $sidebar-width - 16px
padding 10px
&.right-sidebar .sidebar
transform translateX(0)

.content
transform translateX($sidebar-width)
&.close.right-sidebar .sidebar
transform translateX(- $sidebar-width)

.app-nav, .github-corner
display none
&.close
.sidebar-toggle
background-color rgba($color-bg, 0.8)
transition 1s background-color
width $sidebar-width - 16px
padding 10px

.content
transform translateX($sidebar-width)

&.right-sidebar .content
transform translateX(- $sidebar-width)

.app-nav, .github-corner
display none

.github-corner
&:hover .octo-arm
Expand Down