Skip to content

Commit 1fe97fc

Browse files
committed
update react component insertion method, using prepare hooks per spec page
1 parent 2cd2075 commit 1fe97fc

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/index.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { setComponentsNames, globalizeComponents } from './utils/utils';
4-
import StyleGuide from 'components/StyleGuide';
5-
6-
import './styles.css';
4+
import Playground from 'components/Playground';
75

86
global.React = React;
97

@@ -14,7 +12,33 @@ if (module.hot) {
1412
// Load styleguide
1513
let { config, components } = require('styleguide!');
1614

15+
function getSpecName() {
16+
var specName = window.location.pathname;
17+
18+
specName = specName.split('/');
19+
specName.splice(specName.length - 1, 1);
20+
specName = specName.join('/').replace(/^\//, '');
21+
22+
return specName.toLowerCase();
23+
}
24+
1725
components = setComponentsNames(components);
1826
globalizeComponents(components);
1927

20-
ReactDOM.render(<StyleGuide config={config} components={components}/>, document.getElementById('app'));
28+
var hooks = Array.prototype.slice.call(document.querySelectorAll('.source_styleguidist_example'));
29+
var component = components[getSpecName()];
30+
31+
if (component.examples) {
32+
hooks.forEach((hook) => {
33+
var exampleIndex = hook.getAttribute('data-jsx-example');
34+
var example = component.examples[exampleIndex];
35+
36+
ReactDOM.render(
37+
<Playground code={example.content} evalInContext={example.evalInContext} highlightTheme={config.highlightTheme} key={exampleIndex} index={exampleIndex} />,
38+
hook
39+
);
40+
});
41+
}
42+
else {
43+
console.log('Styleguidist didn\'t fount any code examples for this spec.');
44+
}

0 commit comments

Comments
 (0)