ant-design/site/component/MainContent/index.jsx

57 lines
1.7 KiB
React
Raw Normal View History

2016-02-29 14:08:40 +08:00
import React from 'react';
import { Link } from 'react-router';
import { Row, Col, Menu } from '../../../';
2016-03-01 17:05:24 +08:00
import * as utils from '../utils';
2016-02-29 14:08:40 +08:00
2016-03-02 17:12:43 +08:00
function dashed(name) {
return name.toLowerCase().trim().replace(/\s+/g, '-');
}
2016-03-02 11:57:37 +08:00
export default class MainContent extends React.Component {
2016-03-01 17:05:24 +08:00
getMenuItems() {
2016-03-02 11:57:37 +08:00
const props = this.props;
return props.menuItems.map((item) => {
2016-03-02 17:12:43 +08:00
const key = dashed(item.english);
2016-03-02 11:57:37 +08:00
const text = item.chinese || item.english;
2016-03-02 12:10:18 +08:00
const disabled = item.disabled === 'true';
2016-03-02 11:57:37 +08:00
const child = !item.link ?
2016-03-02 12:10:18 +08:00
<Link to={`/${props.category}/${key}`} disabled={disabled}>
2016-03-02 11:57:37 +08:00
{ text }
</Link> :
2016-03-02 12:10:18 +08:00
<a href={item.link} target="_blank" disabled={disabled}>
2016-03-02 11:57:37 +08:00
{ text }
</a>;
return (
2016-03-02 12:10:18 +08:00
<Menu.Item key={key} disabled={disabled}>
{ child }
2016-03-02 11:57:37 +08:00
</Menu.Item>
);
});
2016-03-01 17:05:24 +08:00
}
2016-02-29 14:08:40 +08:00
render() {
2016-03-02 11:57:37 +08:00
const activeMenuItem = utils.getActiveMenuItem(this.props);
2016-03-01 17:05:24 +08:00
const menuItems = this.getMenuItems();
const { prev, next } = utils.getFooterNav(menuItems, activeMenuItem);
2016-03-01 16:20:32 +08:00
2016-02-29 14:08:40 +08:00
return (
<Row className="main-wrapper">
<Col span="4">
2016-03-02 12:10:18 +08:00
<Menu mode="inline" selectedKeys={[activeMenuItem]} className="sidebar">
2016-03-01 17:05:24 +08:00
{ menuItems }
2016-02-29 14:08:40 +08:00
</Menu>
</Col>
<Col span="20" className="main-container">
{ this.props.children }
2016-03-01 17:05:24 +08:00
<section className="prev-next-nav">
{ !!prev ? React.cloneElement(prev.props.children, { className: 'prev-page' }) : null }
{ !!next ? React.cloneElement(next.props.children, { className: 'next-page' }) : null }
</section>
2016-02-29 14:08:40 +08:00
</Col>
</Row>
);
}
}