Skip to content

Commit a04bd01

Browse files
authored
Merge branch 'master' into patch-1
2 parents aad0dd4 + a731cb6 commit a04bd01

File tree

8 files changed

+102
-39
lines changed

8 files changed

+102
-39
lines changed

components/footer/footer.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import './footer-style';
77

88
export default (props) => {
99
return (
10-
<div className="footer">
10+
<footer className="footer">
1111
<Container className="footer__inner">
1212
<section className="footer__left">
1313
<Link className="footer__link" to="/get-started">Get Started</Link>
@@ -30,6 +30,6 @@ export default (props) => {
3030
<CC />
3131
</section>
3232
</Container>
33-
</div>
33+
</footer>
3434
);
3535
};

components/page/page-style.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
}
1010

1111
// XXX: Temporary hack to fix sidebar width
12-
.page div:first-of-type {
12+
.page > div:first-of-type {
1313
flex: 0 0 auto;
14-
overflow: auto;
14+
position: relative;
1515

1616
@include break {
1717
flex:0 0 30%;

components/sidebar-item/sidebar-item-style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
cursor: pointer;
2525
color: getColor(dusty-grey);
2626
transition: color 250ms;
27+
margin-left: 1.5rem;
2728

2829
&:hover {
2930
color: getColor(mine-shaft);

components/sidebar-item/sidebar-item.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ export default class SidebarItem extends React.Component {
3636
}
3737

3838
toggle(e) {
39+
let { onToggle } = this.props;
40+
3941
this.setState({
4042
open: !this.state.open
43+
}, () => {
44+
if (typeof onToggle === 'function') {
45+
onToggle();
46+
}
4147
});
4248
}
4349
}

components/sidebar/sidebar-style.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
@import 'mixins';
33

44
.sidebar {
5-
position: relative;
5+
position: absolute;
66
display: none;
7-
flex: 1;
8-
min-height: 100%;
7+
width: 100%;
8+
max-height: 100%;
9+
overflow: auto;
910

1011
@include break {
1112
display:block;
@@ -14,6 +15,5 @@
1415

1516
.sidebar__inner {
1617
padding: 1.5em;
17-
overflow-y: auto;
18-
overflow-x: hidden;
18+
overflow: hidden;
1919
}

components/sidebar/sidebar.jsx

Lines changed: 84 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,87 @@
1-
import React from 'react';
1+
import React, { Component } from 'react';
22
import SidebarItem from '../sidebar-item/sidebar-item';
33

4-
export default props => {
5-
let { sectionName, pages, currentPage } = props;
6-
7-
return (
8-
<nav className="sidebar">
9-
<div className="sidebar__inner">
10-
<h3 className="sidebar-item__version">Version 2.2</h3>
11-
<SidebarItem
12-
url={ `/${sectionName}` }
13-
title="Introduction"
14-
currentPage= { currentPage }
15-
/>
16-
{
17-
pages.map(({ url, title, anchors }, i) =>
4+
export default class Sidebar extends Component {
5+
constructor(props) {
6+
super(props);
7+
8+
this.state = {
9+
fixed: false,
10+
top: 0
11+
};
12+
}
13+
14+
componentDidMount() {
15+
document.addEventListener('scroll', this._recalculate.bind(this));
16+
}
17+
18+
componentWillUnmount() {
19+
document.removeEventListener('scroll', this._recalculate.bind(this));
20+
}
21+
22+
/**
23+
* Re-calculate fixed state and position
24+
*
25+
*/
26+
_recalculate() {
27+
let { scrollY, innerHeight } = window;
28+
let { scrollHeight } = document.body;
29+
let { offsetHeight } = this._container;
30+
let distToBottom = scrollHeight - scrollY - innerHeight;
31+
let headerHeight = document.querySelector('header').offsetHeight;
32+
let footerHeight = document.querySelector('footer').offsetHeight;
33+
let allowedHeight = distToBottom < footerHeight ? innerHeight - (footerHeight - distToBottom) : offsetHeight;
34+
let extraHeight = offsetHeight > allowedHeight ? offsetHeight - allowedHeight : 0;
35+
let fixed = scrollY >= headerHeight;
36+
37+
this.setState({
38+
fixed,
39+
top: scrollY - headerHeight - extraHeight
40+
});
41+
}
42+
43+
render() {
44+
let { sectionName, pages, currentPage } = this.props;
45+
let { fixed, top, allowedHeight } = this.state;
46+
let isGuides = sectionName === 'guides';
47+
48+
return (
49+
<nav
50+
className="sidebar"
51+
ref={ ref => this._container = ref }
52+
style={ fixed ? {
53+
top: top
54+
} : null }>
55+
56+
<div className="sidebar__inner">
57+
<h3 className="sidebar-item__version">Version 2.2</h3>
58+
59+
<SidebarItem
60+
url={ `/${sectionName}` }
61+
title="Introduction"
62+
currentPage= { currentPage }
63+
/>
64+
65+
{ isGuides ? (
1866
<SidebarItem
19-
key={ `sidebar-item-${i}` }
20-
index={i}
21-
url={ `/${url}` }
22-
title={ title }
23-
anchors={ anchors }
24-
currentPage= { currentPage }
25-
/>
26-
)
27-
}
28-
</div>
29-
</nav>
30-
);
31-
};
67+
url={ `/get-started` }
68+
title="Get Started" />
69+
) : null }
70+
{
71+
pages.map(({ url, title, anchors }, i) =>
72+
<SidebarItem
73+
key={ `sidebar-item-${i}` }
74+
index={i}
75+
url={ `/${url}` }
76+
title={ title }
77+
anchors={ anchors }
78+
currentPage= { currentPage }
79+
onToggle={ this._recalculate.bind(this) } />
80+
)
81+
}
82+
</div>
83+
84+
</nav>
85+
);
86+
}
87+
}

content/development/how-to-write-a-loader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This function is called when a resource should be transformed by this loader.
99

1010
In the simple case, when only a single loader is applied to the resource, the loader is called with one parameter: the content of the resource file as string.
1111

12-
The loader can access the [loader API](api/loaders/) on the `this` context in the function.
12+
The loader can access the [loader API](/api/loaders/) on the `this` context in the function.
1313

1414
A sync loader that only wants to give a one value can simply `return` it. In every other case the loader can give back any number of values with the `this.callback(err, values...)` function. Errors are passed to the `this.callback` function or thrown in a sync loader.
1515

content/pluginsapi/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ It must accept arguments from the previous plugin that was executed. The value f
6767

6868
`applyPluginsAsync(name: string, args: any..., callback: (err?: Error) -> void)`
6969

70-
The plugin handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. The hander functions are called in order of registration.`callback` is called after all the handlers are called.
70+
The plugin handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. The handler functions are called in order of registration.`callback` is called after all the handlers are called.
7171
This is also a commonly used pattern for events like `"emit"`, `"run"`.
7272

7373
- __async waterfall__ The plugins will be applied asynchronously in the waterfall manner.

0 commit comments

Comments
 (0)