2016-02-29 14:08:40 +08:00
|
|
|
import React from 'react';
|
2016-03-01 14:53:32 +08:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { Row, Col, Icon } from '../../../';
|
2016-02-29 14:08:40 +08:00
|
|
|
import Demo from '../Demo';
|
|
|
|
import * as utils from '../utils';
|
|
|
|
|
|
|
|
export default class ComponentDoc extends React.Component {
|
2016-03-01 14:53:32 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
expandAll: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleExpandToggle() {
|
|
|
|
this.setState({
|
|
|
|
expandAll: !this.state.expandAll,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-29 14:08:40 +08:00
|
|
|
render() {
|
|
|
|
const { demos = [], doc } = this.props;
|
2016-03-01 14:53:32 +08:00
|
|
|
const expand = this.state.expandAll;
|
2016-02-29 15:56:15 +08:00
|
|
|
const isSingleCol = doc.meta.cols === '1';
|
2016-02-29 14:08:40 +08:00
|
|
|
|
|
|
|
const leftChildren = [];
|
|
|
|
const rightChildren = [];
|
|
|
|
demos.forEach((demoData, index) => {
|
2016-02-29 15:56:15 +08:00
|
|
|
if (index % 2 === 0 || isSingleCol) {
|
2016-03-01 14:53:32 +08:00
|
|
|
leftChildren.push(<Demo {...demoData} expand={expand} key={index} />);
|
2016-02-29 14:08:40 +08:00
|
|
|
} else {
|
2016-03-01 14:53:32 +08:00
|
|
|
rightChildren.push(<Demo {...demoData} expand={expand} key={index} />);
|
2016-02-29 14:08:40 +08:00
|
|
|
}
|
|
|
|
});
|
2016-03-01 14:53:32 +08:00
|
|
|
const expandTriggerClass = classNames({
|
|
|
|
'code-box-expand-trigger': true,
|
|
|
|
'code-box-expand-trigger-active': expand,
|
|
|
|
});
|
2016-02-29 14:08:40 +08:00
|
|
|
|
|
|
|
return (
|
2016-03-01 11:46:18 +08:00
|
|
|
<article>
|
2016-02-29 15:56:15 +08:00
|
|
|
<section className="markdown">
|
2016-03-03 12:07:28 +08:00
|
|
|
<h1>{doc.meta.chinese || doc.meta.english}</h1>
|
2016-02-29 15:56:15 +08:00
|
|
|
{ doc.description.map(utils.objectToComponent) }
|
2016-03-01 14:53:32 +08:00
|
|
|
<h2>
|
|
|
|
代码演示
|
|
|
|
<Icon type="appstore" className={expandTriggerClass}
|
|
|
|
title="展开全部代码" onClick={this.handleExpandToggle.bind(this)} />
|
|
|
|
</h2>
|
2016-02-29 15:56:15 +08:00
|
|
|
</section>
|
2016-02-29 14:08:40 +08:00
|
|
|
<Row>
|
2016-02-29 15:56:15 +08:00
|
|
|
<Col span={ isSingleCol ? '24' : '12' }>{ leftChildren }</Col>
|
|
|
|
{ isSingleCol ? null : <Col span="12">{ rightChildren }</Col> }
|
2016-02-29 14:08:40 +08:00
|
|
|
</Row>
|
2016-02-29 15:56:15 +08:00
|
|
|
<section className="markdown">
|
2016-03-03 12:07:28 +08:00
|
|
|
{ (doc.api || []).map(utils.objectToComponent) }
|
2016-02-29 15:56:15 +08:00
|
|
|
</section>
|
2016-03-01 11:46:18 +08:00
|
|
|
</article>
|
2016-02-29 14:08:40 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|