You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.7 KiB
98 lines
2.7 KiB
9 years ago
|
import React from 'react';
|
||
9 years ago
|
import { Link } from 'react-router';
|
||
9 years ago
|
import classNames from 'classnames';
|
||
9 years ago
|
import * as utils from '../utils';
|
||
|
|
||
9 years ago
|
const isLocal = location.port;
|
||
|
|
||
9 years ago
|
export default class Demo extends React.Component {
|
||
9 years ago
|
static contextTypes = {
|
||
|
intl: React.PropTypes.object,
|
||
|
}
|
||
|
|
||
9 years ago
|
constructor(props) {
|
||
|
super(props);
|
||
|
|
||
|
this.state = {
|
||
9 years ago
|
codeExpand: false,
|
||
9 years ago
|
};
|
||
|
}
|
||
|
|
||
9 years ago
|
componentWillReceiveProps(nextProps) {
|
||
|
if (nextProps.expand === undefined) return;
|
||
|
|
||
9 years ago
|
this.setState({
|
||
9 years ago
|
codeExpand: nextProps.expand,
|
||
9 years ago
|
});
|
||
|
}
|
||
|
|
||
9 years ago
|
handleCodeExapnd = () => {
|
||
9 years ago
|
this.setState({ codeExpand: !this.state.codeExpand });
|
||
|
}
|
||
|
|
||
9 years ago
|
render() {
|
||
9 years ago
|
const { id, className, meta, intro, preview, style, src,
|
||
9 years ago
|
highlightedCode, highlightedStyle, pathname } = this.props;
|
||
|
const codeExpand = this.state.codeExpand;
|
||
|
const codeBoxClass = classNames({
|
||
|
'code-box': true,
|
||
|
[className]: className,
|
||
|
expand: codeExpand,
|
||
|
});
|
||
9 years ago
|
|
||
|
const locale = this.context.intl.locale;
|
||
|
const localizeIntro = intro[locale] || intro;
|
||
|
const introChildren = utils.jsonmlToComponent(pathname, ['div'].concat(localizeIntro));
|
||
|
const localizedTitle = typeof meta.title === 'object' ?
|
||
|
meta.title[locale] : meta.title;
|
||
9 years ago
|
return (
|
||
9 years ago
|
<section className={codeBoxClass} id={id}>
|
||
9 years ago
|
<section className="code-box-demo">
|
||
9 years ago
|
{
|
||
9 years ago
|
meta.iframe ?
|
||
9 years ago
|
<iframe src={isLocal ? src : src.replace('./_site', '')} /> :
|
||
9 years ago
|
preview
|
||
|
}
|
||
9 years ago
|
{
|
||
|
!!style ?
|
||
|
<style dangerouslySetInnerHTML={{ __html: style }} /> :
|
||
|
null
|
||
|
}
|
||
9 years ago
|
</section>
|
||
|
<section className="code-box-meta markdown">
|
||
|
<div className="code-box-title">
|
||
9 years ago
|
<Link to={{ pathname, query: { scrollTo: id } }}>
|
||
9 years ago
|
{localizedTitle}
|
||
9 years ago
|
</Link>
|
||
9 years ago
|
</div>
|
||
9 years ago
|
{introChildren}
|
||
9 years ago
|
<span className="collapse anticon anticon-circle-o-right"
|
||
9 years ago
|
onClick={this.handleCodeExapnd}
|
||
9 years ago
|
unselectable="none" />
|
||
9 years ago
|
</section>
|
||
9 years ago
|
<section className={`highlight-wrapper ${codeExpand ? 'highlight-wrapper-expand' : ''}`}
|
||
|
key="code">
|
||
|
<div className="highlight">
|
||
|
<pre>
|
||
|
<code className="javascript" dangerouslySetInnerHTML={{
|
||
|
__html: highlightedCode,
|
||
|
}} />
|
||
|
</pre>
|
||
|
</div>
|
||
9 years ago
|
{
|
||
9 years ago
|
highlightedStyle ?
|
||
9 years ago
|
<div key="style" className="highlight">
|
||
|
<pre>
|
||
|
<code className="css" dangerouslySetInnerHTML={{
|
||
|
__html: highlightedStyle,
|
||
|
}} />
|
||
|
</pre>
|
||
|
</div> :
|
||
|
null
|
||
9 years ago
|
}
|
||
9 years ago
|
</section>
|
||
9 years ago
|
</section>
|
||
|
);
|
||
|
}
|
||
|
}
|