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

84 lines
2.7 KiB
React
Raw Normal View History

2016-02-29 14:08:40 +08:00
import React from 'react';
import { Link } from 'react-router';
2016-02-29 14:08:40 +08:00
import { Row, Col, Menu } from '../../../';
2016-03-01 11:46:18 +08:00
import * as utils from '../utils';
2016-02-29 14:08:40 +08:00
import componentsList from '../../../_site/data/components-list';
2016-03-01 11:46:18 +08:00
const componentMenuItems = [];
['基本', '表单', '展示', '导航', '其它'].forEach((category) => {
const grandChildren = componentsList[category].map((item) => {
const key = item.english.toLowerCase();
return (
<Menu.Item key={key}>
<Link to={`/components/${key}`}>{item.title}</Link>
</Menu.Item>
);
});
componentMenuItems.push(
<Menu.ItemGroup title={category} key={category} mode="vertical">
{ grandChildren }
</Menu.ItemGroup>
);
});
2016-02-29 14:08:40 +08:00
export default class ReactComponents extends React.Component {
2016-03-01 11:46:18 +08:00
getTopLevelMenuItems() {
return [
<Menu.Item key="introduce">
<Link to="/components/introduce">Ant Design of React</Link>
</Menu.Item>,
<Menu.Item key="getting-started">
<Link to="/components/getting-started">快速上手</Link>
</Menu.Item>,
<Menu.Item key="install">
<Link to="/components/install">安装</Link>
</Menu.Item>,
<Menu.Item key="upgrade-notes">
<Link to="/components/upgrade-notes">升级指南</Link>
</Menu.Item>,
<Menu.Item key="changelog">
<Link to="/components/changelog">更新日志</Link>
</Menu.Item>,
];
}
2016-02-29 14:08:40 +08:00
render() {
2016-03-01 11:46:18 +08:00
const routes = this.props.routes;
const activeMenuItem = routes[routes.length - 1].path;
const topLevelMenuItems = this.getTopLevelMenuItems();
const menuItems = topLevelMenuItems.concat(
utils.flattenMenu(componentMenuItems)
);
2016-02-29 14:08:40 +08:00
2016-03-01 11:46:18 +08:00
const activeMenuItemIndex = menuItems.findIndex((menuItem) => {
return menuItem.key === activeMenuItem;
2016-02-29 14:08:40 +08:00
});
2016-03-01 11:46:18 +08:00
const prev = menuItems[activeMenuItemIndex - 1];
const next = menuItems[activeMenuItemIndex + 1];
2016-02-29 14:08:40 +08:00
return (
<Row className="main-wrapper">
<Col span="4">
<Menu className="sidebar" mode="inline"
2016-03-01 11:46:18 +08:00
defaultOpenKeys={['components']}
selectedKeys={[activeMenuItem]}>
{ topLevelMenuItems }
2016-02-29 14:08:40 +08:00
<Menu.SubMenu title="Components" key="components">
{ componentMenuItems }
</Menu.SubMenu>
</Menu>
</Col>
<Col span="20" className="main-container">
{ this.props.children }
2016-03-01 11:46:18 +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>
);
}
}