Skip to content

Commit 1171193

Browse files
committed
doc features, redo tab, demo fixs
1 parent 570726a commit 1171193

File tree

10 files changed

+147
-130
lines changed

10 files changed

+147
-130
lines changed

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"version": "0.4.0",
1212
"icon": "http://weui.github.io/weui/images/icon_nav_actionSheet.png",
1313
"preview" : "ActionSheet",
14-
"component" : "actionsheet/actionsheet"
14+
"component" : "actionsheet/actionsheet",
15+
"guide" : "actionsheet.md"
1516
},
1617
{
1718
"name": "Button",

docs/guide/actionsheet.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Guide
3+
-------------
4+
5+
#### Visibility
6+
To use `ActionSheet`, you want to first setup a state variable to toggle it's visibility for `show` property and a callback function `onRequestClose` property when users wants to hide the `ActionSheet`.
7+
8+
```javascript
9+
//inside your component state
10+
state = {
11+
show: false
12+
}
13+
14+
//button to toggle the ActionSheet
15+
<Button
16+
onClick={ e => this.setState({ show: true }) }
17+
/>
18+
19+
//inside the render function
20+
<ActionSheet
21+
show={ this.state.show }
22+
onRequestClose={
23+
//function to hide ActionSheet
24+
e => this.setState({ show: false })
25+
}
26+
/>
27+
```

docs/langs.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"article" : {
1111
"detail": "Detail",
1212
"code": "Code",
13-
"srcCode": "Source Code",
14-
"loading": "Loading..."
13+
"srcCode": "Sample Code",
14+
"loading": "Loading...",
15+
"guide": "Guide"
1516
},
1617
"nopreview" : {
1718
"nopreview": "No Preview"
@@ -30,7 +31,8 @@
3031
"detail": "具体",
3132
"code": "代码",
3233
"srcCode": "源码",
33-
"loading": "读取中..."
34+
"loading": "读取中...",
35+
"guide": "教程"
3436
},
3537
"nopreview" : {
3638
"nopreview": "没有预览"

docs/pages/articles.js

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import React, { Component } from 'react';
22
import ReactDOM from 'react-dom';
33
import Remarkable from 'react-remarkable';
44
import { Article, Toast, Tab, NavBarItem } from '../../src';
5-
import generateMarkdown from './generateMarkdown';
65
import CodeMirror from 'codemirror/lib/codemirror.js';
6+
import hljs from 'highlight.js'
7+
8+
//bunch of css
9+
import 'highlight.js/styles/github.css';
710
import 'codemirror/lib/codemirror.css';
811
import 'codemirror/theme/monokai.css';
912
import 'codemirror/mode/jsx/jsx';
1013
import 'codemirror/addon/display/autorefresh';
1114
import 'github-markdown-css';
1215
import './home.less';
1316

14-
const reactDocs = require('react-docgen');
15-
1617
class Articles extends Component {
1718
static defaultProps = {
1819
langs: {
@@ -22,56 +23,72 @@ class Articles extends Component {
2223
}
2324
};
2425

25-
constructor(props){
26-
super(props);
27-
this.state = {
28-
loading: true,
29-
content: null
26+
componentDidMount(){
27+
28+
if(this.props.code){
29+
let el = ReactDOM.findDOMNode(this.refs.codeblock);
30+
31+
this.editor = CodeMirror.fromTextArea(el, {
32+
mode: 'jsx',
33+
lineNumbers: false,
34+
lineWrapping: true,
35+
smartIndent: false, // javascript mode does bad things with jsx indents
36+
matchBrackets: true,
37+
readOnly: true,
38+
autoRefresh: true,
39+
theme: 'monokai'
40+
});
3041
}
31-
}
3242

33-
componentDidMount(){
34-
let el = ReactDOM.findDOMNode(this.refs.codeblock);
35-
this.editor = CodeMirror.fromTextArea(el, {
36-
mode: 'jsx',
37-
lineNumbers: false,
38-
lineWrapping: true,
39-
smartIndent: false, // javascript mode does bad things with jsx indents
40-
matchBrackets: true,
41-
readOnly: true,
42-
autoRefresh: true,
43-
theme: 'monokai'
44-
});
45-
this.componentWillReceiveProps(this.props)
4643
}
4744

4845
componentDidUpdate(){
49-
this.editor.setValue(this.props.code)
50-
}
5146

52-
componentWillReceiveProps(nextProps){
53-
this.setState({loading: true, content: null});
54-
let article = this.props.docs[nextProps.params.id].items[nextProps.params.aid]
5547

56-
let src = require(`!!raw!../../src/components/${article.component}`)
57-
let content = generateMarkdown(article.name, article.version, reactDocs.parse(src));
58-
//article.doc
59-
this.setState({loading: false, content});
48+
if(this.props.guide){
49+
let $guide = ReactDOM.findDOMNode(this.refs.guide);
50+
let $codes = $guide.querySelectorAll('pre code')
51+
52+
Array.from($codes).forEach( $code => {
53+
hljs.highlightBlock($code);
54+
})
55+
56+
}
57+
58+
59+
if(!this.editor){
60+
let el = ReactDOM.findDOMNode(this.refs.codeblock);
61+
62+
this.editor = CodeMirror.fromTextArea(el, {
63+
mode: 'jsx',
64+
lineNumbers: false,
65+
lineWrapping: true,
66+
smartIndent: false, // javascript mode does bad things with jsx indents
67+
matchBrackets: true,
68+
readOnly: true,
69+
autoRefresh: true,
70+
theme: 'monokai'
71+
});
72+
}
73+
74+
if(this.props.code) this.editor.setValue(this.props.code)
75+
76+
6077
}
6178

6279
render(){
63-
const { code, langs } = this.props;
80+
const { code, langs, guide, content } = this.props;
81+
6482
return (
6583
<Tab type="navbar">
66-
<NavBarItem label={langs.detail}>
84+
<NavBarItem label={langs.detail} >
6785
<Article>
68-
{
69-
this.state.loading ?
70-
<Toast icon="loading" show={true}>{langs.loading}.</Toast> :
7186
<div className="markdown-body">
72-
<Remarkable source={this.state.content} />
87+
<Remarkable source={content} />
88+
{
89+
guide ? <Remarkable ref="guide" source={guide} /> : false
90+
}
7391
</div>
74-
}
7592
</Article>
7693
</NavBarItem>
7794
{ code ?
@@ -86,4 +103,3 @@ class Articles extends Component {
86103
}
87104

88105
export default Articles;
89-
//<SyntaxHighlighter language='javascript' style={SyntaxStyle}>{code.replace('../../../src/index','react-weui')}</SyntaxHighlighter>

docs/pages/docs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import ReactDOM from 'react-dom';
44
import SplitPane from 'react-split-pane';
55
import Preview from "../components/preview";
66
import NoPreview from './nopreview';
7+
import generateMarkdown from './generateMarkdown';
8+
const reactDocs = require('react-docgen');
79
import WeUI from '../../src';
810
import iconSrc from '../logo.svg';
911
import Demos from '../../example';
@@ -29,6 +31,8 @@ class Docs extends Component {
2931
}
3032

3133
}
34+
let src = article.component ? require(`!!raw!../../src/components/${article.component}`) : false
35+
let content = src ? generateMarkdown(article.name, article.version, reactDocs.parse(src)) : false
3236

3337
return (
3438
<SplitPane split="vertical" minSize={20} defaultSize="60%" primary="second">
@@ -45,6 +49,8 @@ class Docs extends Component {
4549
docs: this.props.docs,
4650
aid: this.props.params.aid,
4751
langs: this.props.langs.article,
52+
guide: article.guide ? require(`!!raw!../guide/${article.guide}`) : false,
53+
content,
4854
code
4955
})}
5056
</div>

example/pages/input/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export default class inputDemo extends React.Component {
229229
</Button>
230230
</ButtonArea>
231231

232-
<Toptips warn
232+
<Toptips type="warn"
233233
show={this.state.showToptips}
234234
>
235235
Oops, something is wrong!

example/pages/toptips/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class ToptipsDemo extends React.Component {
2626
<Button onClick={this.showSuccess.bind(this)} type="default">Primary Toptip</Button>
2727
<Button onClick={this.showInfo.bind(this)} type="default">Info Toptip</Button>
2828

29-
<Toptips warn show={this.state.showWarn}> Oops, something is wrong! </Toptips>
30-
<Toptips primary show={this.state.showSuccess}> Success submited! </Toptips>
31-
<Toptips info show={this.state.showInfo}> Thanks for coming! </Toptips>
29+
<Toptips type="warn" show={this.state.showWarn}> Oops, something is wrong! </Toptips>
30+
<Toptips type="primary" show={this.state.showSuccess}> Success submited! </Toptips>
31+
<Toptips type="info" show={this.state.showInfo}> Thanks for coming! </Toptips>
3232
</Page>
3333
);
3434
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"fastclick": "^1.0.6",
6868
"file-loader": "^0.8.5",
6969
"github-markdown-css": "^2.4.1",
70+
"highlight.js": "^9.8.0",
7071
"history": "^1.17.0",
7172
"html-webpack-plugin": "^2.14.0",
7273
"ignore-styles": "^5.0.1",

0 commit comments

Comments
 (0)