import React from 'react'; import DocumentTitle from 'react-document-title'; import classNames from 'classnames'; import { Row, Col, Icon, Affix } from 'antd'; import { getChildren } from 'jsonml.js/lib/utils'; import Demo from './Demo'; export default class ComponentDoc extends React.Component { static contextTypes = { intl: React.PropTypes.object, } constructor(props) { super(props); this.state = { expandAll: false, }; } handleExpandToggle = () => { this.setState({ expandAll: !this.state.expandAll, }); } render() { const props = this.props; const { doc, location } = props; const { content, meta } = doc; const locale = this.context.intl.locale; const demos = Object.keys(props.demos).map((key) => props.demos[key]) .filter((demoData) => !demoData.meta.hidden); const expand = this.state.expandAll; const isSingleCol = meta.cols === 1; const leftChildren = []; const rightChildren = []; demos.sort((a, b) => a.meta.order - b.meta.order) .forEach((demoData, index) => { if (index % 2 === 0 || isSingleCol) { leftChildren.push( ); } else { rightChildren.push( ); } }); const expandTriggerClass = classNames({ 'code-box-expand-trigger': true, 'code-box-expand-trigger-active': expand, }); const jumper = demos.map((demo) => { const title = demo.meta.title; const localizeTitle = title[locale] || title; return (
  • {localizeTitle}
  • ); }); const { title, subtitle, chinese, english } = meta; return (
      {jumper}

    {meta.title || meta.english} {meta.subtitle || meta.chinese}

    { props.utils.toReactComponent( ['section', { className: 'markdown' }] .concat(getChildren(content)) ) }

    代码演示

    {leftChildren} { isSingleCol ? null : {rightChildren} } { props.utils.toReactComponent( ['section', { className: 'markdown api-container', }].concat(getChildren(doc.api || ['placeholder'])) ) }
    ); } }