forked from styleguidist/react-styleguidist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (37 loc) · 1.31 KB
/
index.js
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
/* eslint-disable import/first */
import './polyfills';
import './styles';
import ReactDOM from 'react-dom';
import renderStyleguide from './utils/renderStyleguide';
// Examples code revision to rerender only code examples (not the whole page) when code changes
// eslint-disable-next-line no-unused-vars
let codeRevision = 0;
/** Scrolls to origin when current window location hash points to an isolated view. */
const scrollToOrigin = () => {
if (window.location.hash.indexOf('#!/') === 0) {
window.scrollTo(0, 0);
}
};
const render = () => {
// eslint-disable-next-line import/no-unresolved
const styleguide = require('!!../loaders/styleguide-loader!./index.js');
let containerId = 'rsg-root';
if (document.getElementById('app')) {
// eslint-disable-next-line no-console
console.warn(
"The use of 'app' element id in the template is deprecated. Please, update your template file to use 'rsg-root' as the container id."
);
containerId = 'app';
}
ReactDOM.render(renderStyleguide(styleguide, codeRevision), document.getElementById(containerId));
};
window.addEventListener('hashchange', render);
window.addEventListener('hashchange', scrollToOrigin);
/* istanbul ignore if */
if (module.hot) {
module.hot.accept('!!../loaders/styleguide-loader!./index.js', () => {
codeRevision += 1;
render();
});
}
render();