Skip to content

Commit a97f6c3

Browse files
authored
Merge pull request #23 from Codebrahma/docs-fixes
Docs fixes
2 parents 5b0c810 + 342abbe commit a97f6c3

File tree

9 files changed

+52
-32
lines changed

9 files changed

+52
-32
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# How to include in playground
2+
3+
Once the component is added in the ```src``` folder,
4+
5+
1. Add default code in ```client/common/DefaultCode```
6+
2. Import it in the ```index.js``` file of ```DefaultCode folder```
7+
3. Import these components in the ```common/componentList.js```

docs/client/components/PlaygroundPage/PlaygroundWithPreview/Preview.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import PropTypes from 'prop-types';
44
import { transform } from 'babel-standalone';
5-
import Card from '../../../../../src/card';
6-
import Button from '../../../../../src/button';
5+
import components from '../../../../../src';
76
import theme from '../../../components/common/DefaultCode/theme.scss';
87
import styles from './styles.scss';
98

9+
console.log('components ', components);
10+
1011
class Preview extends React.Component {
1112
constructor(props) {
1213
super(props);
@@ -54,31 +55,47 @@ class Preview extends React.Component {
5455
executeCode () {
5556
const mountNode = this.refs.mount;
5657
const scope = this.buildScope(mountNode);
57-
58+
if (this.state.error) {
59+
this.setState({ error: null });
60+
}
61+
5862
try {
5963
ReactDOM.unmountComponentAtNode(mountNode);
6064
} catch (e) {
61-
console.log(e);
65+
6266
}
67+
6368
try {
64-
6569
const x = eval(this.compileCode())(...scope);
6670
ReactDOM.render(x, mountNode);
6771
if (this.state.error) {
6872
this.setState({ error: null });
6973
}
7074
} catch (err) {
71-
console.log(err);
72-
this.setTimeout(() => {
73-
this.setState({ error: err.toString() });
74-
}, 500);
75+
this.setTimeout(() => {
76+
this.setState({
77+
error: err.message,
78+
});
79+
}, 100);
7580
}
7681
}
7782

7883
render () {
79-
console.log('theme ', theme);
84+
8085
return (
8186
<div className={styles.preview}>
87+
{
88+
this.state.error !== null ? (
89+
<React.Fragment>
90+
<div className="header">
91+
Error
92+
</div>
93+
<div className="error">
94+
{this.state.error}
95+
</div>
96+
</React.Fragment>
97+
) : null
98+
}
8299
<div ref="mount" />
83100
</div>
84101
);
@@ -91,7 +108,11 @@ Preview.propTypes = {
91108
};
92109

93110
Preview.defaultProps = {
94-
scope: { React, Card, Button, theme },
111+
scope: {
112+
React,
113+
...components,
114+
theme,
115+
},
95116
};
96117

97118
export default Preview;

docs/client/components/PlaygroundPage/PlaygroundWithPreview/styles.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@
3434
left: 60%;
3535
width: 35%;
3636
height: 100%;
37-
}
37+
.error {
38+
color: red;
39+
}
40+
}

docs/client/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:local(.app-wrapper) {
22
width: 100%;
33
.content-wrapper {
4-
margin-top: 75px;
4+
margin-top: 100px;
55
}
66
}

docs/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
</head>
88
<body>
99
<div id="app"></div>
10-
<script src="./docs.js"></script>
10+
<script src="/docs.js"></script>
1111
</body>
1212
</html>

docs/webpack.config.development.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ module.exports = {
5555
},
5656
plugins: [
5757
new ExtractTextPlugin('docs.css', { allChunks: true }),
58-
new TransferWebpackPlugin([{
59-
from: 'public/images',
60-
to: 'images'
61-
}], path.resolve(__dirname, './')),
6258
new webpack.HotModuleReplacementPlugin(),
6359
new webpack.DefinePlugin({
6460
'process.env.NODE_ENV': JSON.stringify('development')

src/card/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { themr } from 'react-css-themr';
44
import classnames from 'classnames';
5-
import defaultTheme from './defaultTheme.scss';
5+
import defaultTheme from './theme.scss';
66

77
const Card = ({
88
children,
File renamed without changes.

src/index.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
1+
import Button from './button';
2+
import Card from './card';
33

4-
import CardExample from './examples/card';
5-
import ButtonExample from './examples/button';
6-
7-
const Index = () => (
8-
<div>
9-
<CardExample />
10-
<ButtonExample />
11-
</div>
12-
);
13-
14-
ReactDOM.render(<Index />, document.getElementById('index'));
4+
export default {
5+
Button,
6+
Card,
7+
}

0 commit comments

Comments
 (0)