2016-02-29 14:08:40 +08:00
|
|
|
import React from 'react';
|
2016-03-04 18:06:34 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import antd, { Collapse } from '../../../';
|
|
|
|
import BrowserDemo from '../BrowserDemo';
|
2016-02-29 14:08:40 +08:00
|
|
|
import * as utils from '../utils';
|
|
|
|
import hljs from 'highlight.js';
|
|
|
|
|
|
|
|
export default class Demo extends React.Component {
|
2016-03-01 14:53:32 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
activeKey: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange(activeKey) {
|
|
|
|
this.setState({
|
|
|
|
activeKey: this.state.activeKey === activeKey ?
|
|
|
|
'' : activeKey
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-29 14:08:40 +08:00
|
|
|
render() {
|
2016-03-01 17:42:23 +08:00
|
|
|
const { id, preview, title, intro, code, style, expand } = this.props;
|
2016-02-29 14:08:40 +08:00
|
|
|
const introChildren = intro.map(utils.objectToComponent);
|
|
|
|
const highlightedCode = hljs.highlight('javascript', code).value;
|
|
|
|
return (
|
|
|
|
<section className="code-box" id={id}>
|
|
|
|
<section className="code-box-demo">
|
2016-03-04 18:06:34 +08:00
|
|
|
{ preview(React, ReactDOM, antd, BrowserDemo) }
|
2016-03-01 17:42:23 +08:00
|
|
|
{
|
|
|
|
!!style ?
|
|
|
|
<style dangerouslySetInnerHTML={{ __html: style }} /> :
|
|
|
|
null
|
|
|
|
}
|
2016-02-29 14:08:40 +08:00
|
|
|
</section>
|
|
|
|
<section className="code-box-meta markdown">
|
|
|
|
<div className="code-box-title">
|
|
|
|
<a>{ title }</a>
|
|
|
|
</div>
|
2016-03-01 14:53:32 +08:00
|
|
|
<Collapse activeKey={expand ? 'code' : this.state.activeKey}
|
|
|
|
onChange={this.handleChange.bind(this)}>
|
|
|
|
<Collapse.Panel key="code" header={introChildren}>
|
2016-02-29 14:08:40 +08:00
|
|
|
<div className="highlight">
|
|
|
|
<pre>
|
|
|
|
<code className="javascript" dangerouslySetInnerHTML={{
|
|
|
|
__html: highlightedCode,
|
2016-02-29 14:34:51 +08:00
|
|
|
}} />
|
2016-03-01 17:42:23 +08:00
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
!!style ?
|
|
|
|
<div className="highlight">
|
|
|
|
<pre>
|
|
|
|
<code className="css" dangerouslySetInnerHTML={{
|
|
|
|
__html: hljs.highlight('css', style).value,
|
|
|
|
}} />
|
|
|
|
</pre>
|
|
|
|
</div> :
|
|
|
|
null
|
|
|
|
}
|
|
|
|
</Collapse.Panel>
|
|
|
|
</Collapse>
|
2016-02-29 14:08:40 +08:00
|
|
|
</section>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|