diff --git a/site/component/ReactComponents/index.jsx b/site/component/ReactComponents/index.jsx index bff98a58c2..5e1819ed7e 100644 --- a/site/component/ReactComponents/index.jsx +++ b/site/component/ReactComponents/index.jsx @@ -44,19 +44,13 @@ export default class ReactComponents extends React.Component { } render() { - const routes = this.props.routes; - const activeMenuItem = routes[routes.length - 1].path || 'introduce'; - + const activeMenuItem = utils.getActiveMenuItem(this.props, 'introduce'); const topLevelMenuItems = this.getTopLevelMenuItems(); const menuItems = topLevelMenuItems.concat( utils.flattenMenu(componentMenuItems) ); - const activeMenuItemIndex = menuItems.findIndex((menuItem) => { - return menuItem.key === activeMenuItem; - }); - const prev = menuItems[activeMenuItemIndex - 1]; - const next = menuItems[activeMenuItemIndex + 1]; + const { prev, next } = utils.getFooterNav(menuItems, activeMenuItem); return ( diff --git a/site/component/Resource/index.jsx b/site/component/Resource/index.jsx index ec2304cfc5..8c59578255 100644 --- a/site/component/Resource/index.jsx +++ b/site/component/Resource/index.jsx @@ -1,35 +1,47 @@ import React from 'react'; import { Link } from 'react-router'; import { Row, Col, Menu } from '../../../'; +import * as utils from '../utils'; export default class Resource extends React.Component { + getMenuItems() { + return [ + + + 资源下载 + + , + + + 文献素材 + + , + + + GitHub + + , + ]; + } + render() { - const routes = this.props.routes; - const activeMenuItem = routes[routes.length - 1].path || 'download'; + const activeMenuItem = utils.getActiveMenuItem(this.props, 'download'); + const menuItems = this.getMenuItems(); + const { prev, next } = utils.getFooterNav(menuItems, activeMenuItem); return ( - - - 资源下载 - - - - - 文献素材 - - - - - GitHub - - + { menuItems } { this.props.children } +
+ { !!prev ? React.cloneElement(prev.props.children, { className: 'prev-page' }) : null } + { !!next ? React.cloneElement(next.props.children, { className: 'next-page' }) : null } +
); diff --git a/site/component/Spec/index.jsx b/site/component/Spec/index.jsx index 7e78299862..74b79bb21c 100644 --- a/site/component/Spec/index.jsx +++ b/site/component/Spec/index.jsx @@ -1,62 +1,78 @@ import React from 'react'; import { Link } from 'react-router'; import { Row, Col, Menu } from '../../../'; +import * as utils from '../utils'; const SubMenu = Menu.SubMenu; export default class Spec extends React.Component { + getMenuItems() { + return [ + + + Ant Design + + , + 基础}> + + + 字体 + + + + + 排版 + + + + + 色彩 + + + + + 常用布局 + + + , + 动画}> + + + 自然运动 + + + + + 互动转换 + + + + + 组件动画 + + + , + ]; + } + render() { - const routes = this.props.routes; - const activeMenuItem = routes[routes.length - 1].path || 'introduce'; + const activeMenuItem = utils.getActiveMenuItem(this.props, 'introduce'); + const menuItems = this.getMenuItems(); + const { prev, next } = utils.getFooterNav(menuItems, activeMenuItem); return ( - - - Ant Design - - - 基础}> - - - 字体 - - - - - 排版 - - - - 色彩 - - - 常用布局 - - - 动画}> - - - 自然运动 - - - - - 互动转换 - - - - - 组件动画 - - - + { menuItems } { this.props.children } +
+ { !!prev ? React.cloneElement(prev.props.children, { className: 'prev-page' }) : null } + { !!next ? React.cloneElement(next.props.children, { className: 'next-page' }) : null } +
); diff --git a/site/component/utils.js b/site/component/utils.js index be10a28186..8a437f2e59 100644 --- a/site/component/utils.js +++ b/site/component/utils.js @@ -68,3 +68,18 @@ export function flattenMenu(menu) { return flattenMenu(menu.props.children); } + +export function getActiveMenuItem(props, index) { + const routes = props.routes; + return routes[routes.length - 1].path || index; +} + +export function getFooterNav(menuItems, activeMenuItem) { + const menuItemsList = flattenMenu(menuItems); + const activeMenuItemIndex = menuItemsList.findIndex((menuItem) => { + return menuItem.key === activeMenuItem; + }); + const prev = menuItemsList[activeMenuItemIndex - 1]; + const next = menuItemsList[activeMenuItemIndex + 1]; + return { prev, next }; +}