mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 19:50:05 +08:00
refactor website
This commit is contained in:
parent
844a132cfe
commit
7fbb2ddc47
@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import { Row, Col, Menu } from '../../../';
|
||||
import * as utils from '../utils';
|
||||
const SubMenu = Menu.SubMenu;
|
||||
|
||||
function dashed(name) {
|
||||
@ -15,6 +14,11 @@ export default class MainContent extends React.Component {
|
||||
this.generateMenuItem = this.generateMenuItem.bind(this);
|
||||
}
|
||||
|
||||
getActiveMenuItem(props, index) {
|
||||
const routes = props.routes;
|
||||
return routes[routes.length - 1].path || index;
|
||||
}
|
||||
|
||||
generateMenuItem(item) {
|
||||
const key = dashed(item.english);
|
||||
const text = item.chinese || item.english;
|
||||
@ -29,7 +33,7 @@ export default class MainContent extends React.Component {
|
||||
</a>;
|
||||
|
||||
return (
|
||||
<Menu.Item key={key} disabled={disabled}>
|
||||
<Menu.Item key={key} disabled={disabled}>
|
||||
{ child }
|
||||
</Menu.Item>
|
||||
);
|
||||
@ -53,10 +57,34 @@ export default class MainContent extends React.Component {
|
||||
return [...topLevel, ...subMenu];
|
||||
}
|
||||
|
||||
flattenMenu(menu) {
|
||||
if (menu.type === Menu.Item) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
if (Array.isArray(menu)) {
|
||||
return menu.reduce((acc, item) => {
|
||||
return acc.concat(this.flattenMenu(item));
|
||||
}, []);
|
||||
}
|
||||
|
||||
return this.flattenMenu(menu.props.children);
|
||||
}
|
||||
|
||||
getFooterNav(menuItems, activeMenuItem) {
|
||||
const menuItemsList = this.flattenMenu(menuItems);
|
||||
const activeMenuItemIndex = menuItemsList.findIndex((menuItem) => {
|
||||
return menuItem.key === activeMenuItem;
|
||||
});
|
||||
const prev = menuItemsList[activeMenuItemIndex - 1];
|
||||
const next = menuItemsList[activeMenuItemIndex + 1];
|
||||
return { prev, next };
|
||||
}
|
||||
|
||||
render() {
|
||||
const activeMenuItem = utils.getActiveMenuItem(this.props);
|
||||
const activeMenuItem = this.getActiveMenuItem(this.props);
|
||||
const menuItems = this.getMenuItems();
|
||||
const { prev, next } = utils.getFooterNav(menuItems, activeMenuItem);
|
||||
const { prev, next } = this.getFooterNav(menuItems, activeMenuItem);
|
||||
|
||||
return (
|
||||
<Row className="main-wrapper">
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import hljs from 'highlight.js';
|
||||
import antd, { Menu } from '../../';
|
||||
import antd from '../../';
|
||||
|
||||
function isHeading(type) {
|
||||
return /h[1-6]/i.test(type);
|
||||
@ -63,32 +63,3 @@ export function objectToComponent(object, index) {
|
||||
children && children.map(objectToComponent) // `hr` has no children
|
||||
);
|
||||
}
|
||||
|
||||
export function flattenMenu(menu) {
|
||||
if (menu.type === Menu.Item) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
if (Array.isArray(menu)) {
|
||||
return menu.reduce((acc, item) => {
|
||||
return acc.concat(flattenMenu(item));
|
||||
}, []);
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user