2020-02-27 10:53:30 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { Link } from 'bisheng/router';
|
|
|
|
import { UnorderedListOutlined } from '@ant-design/icons';
|
|
|
|
import { Menu } from 'antd';
|
|
|
|
import { getEcosystemGroup } from './More';
|
|
|
|
import * as utils from '../../utils';
|
|
|
|
import { SharedProps } from './interface';
|
|
|
|
|
|
|
|
import './Navigation.less';
|
|
|
|
|
|
|
|
export interface NavigationProps extends SharedProps {
|
|
|
|
isMobile: boolean;
|
2020-04-21 10:49:59 +08:00
|
|
|
isRTL: boolean;
|
2020-02-27 10:53:30 +08:00
|
|
|
pathname: string;
|
|
|
|
responsive: null | 'narrow' | 'crowded';
|
2020-09-14 10:48:08 +08:00
|
|
|
location: { pathname: string; query: any };
|
2020-02-27 10:53:30 +08:00
|
|
|
directionText: string;
|
2020-10-30 20:02:43 +08:00
|
|
|
showTechUIButton: boolean;
|
2020-02-27 10:53:30 +08:00
|
|
|
onLangChange: () => void;
|
|
|
|
onDirectionChange: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ({
|
|
|
|
isZhCN,
|
|
|
|
isMobile,
|
|
|
|
pathname,
|
|
|
|
responsive,
|
|
|
|
location,
|
|
|
|
directionText,
|
2020-10-30 20:02:43 +08:00
|
|
|
showTechUIButton,
|
2020-02-27 10:53:30 +08:00
|
|
|
onLangChange,
|
|
|
|
onDirectionChange,
|
|
|
|
}: NavigationProps) => {
|
2020-04-27 15:02:07 +08:00
|
|
|
const [isGitee, setIsGitee] = React.useState(false);
|
2020-02-27 10:53:30 +08:00
|
|
|
const menuMode = isMobile ? 'inline' : 'horizontal';
|
|
|
|
|
2020-04-21 10:49:59 +08:00
|
|
|
const module = pathname.split('/').slice(0, -1).join('/');
|
2020-02-27 10:53:30 +08:00
|
|
|
let activeMenuItem = module || 'home';
|
|
|
|
if (location.pathname === 'changelog' || location.pathname === 'changelog-cn') {
|
|
|
|
activeMenuItem = 'docs/react';
|
|
|
|
} else if (location.pathname === 'docs/resources' || location.pathname === 'docs/resources-cn') {
|
|
|
|
activeMenuItem = 'docs/resources';
|
|
|
|
}
|
|
|
|
|
|
|
|
let additional: React.ReactNode = null;
|
|
|
|
const additionalItems = [
|
|
|
|
<Menu.Item key="github">
|
|
|
|
<a href="https://github.com/ant-design/ant-design" target="_blank" rel="noopener noreferrer">
|
|
|
|
Github
|
|
|
|
</a>
|
|
|
|
</Menu.Item>,
|
|
|
|
<Menu.Item key="switch-lang" onClick={onLangChange}>
|
|
|
|
<FormattedMessage id="app.header.lang" />
|
|
|
|
</Menu.Item>,
|
|
|
|
<Menu.Item key="switch-direction" onClick={onDirectionChange}>
|
|
|
|
{directionText}
|
|
|
|
</Menu.Item>,
|
2021-07-12 18:06:27 +08:00
|
|
|
getEcosystemGroup(),
|
2020-02-27 10:53:30 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
if (isMobile) {
|
|
|
|
additional = additionalItems;
|
|
|
|
} else if (responsive === 'crowded') {
|
|
|
|
additional = (
|
|
|
|
<Menu.SubMenu key="additional" title={<UnorderedListOutlined />}>
|
|
|
|
{additionalItems}
|
|
|
|
</Menu.SubMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-27 15:02:07 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
setIsGitee(document.location.host.indexOf('gitee') !== -1);
|
|
|
|
}, []);
|
2020-04-27 11:36:04 +08:00
|
|
|
|
2020-02-27 10:53:30 +08:00
|
|
|
return (
|
|
|
|
<Menu
|
|
|
|
className={classNames('menu-site')}
|
|
|
|
mode={menuMode}
|
|
|
|
selectedKeys={[activeMenuItem]}
|
|
|
|
id="nav"
|
2021-05-25 17:24:18 +08:00
|
|
|
disabledOverflow
|
2020-02-27 10:53:30 +08:00
|
|
|
>
|
|
|
|
<Menu.Item key="docs/spec">
|
2020-09-14 10:48:08 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/docs/spec/introduce', isZhCN, location.query)}>
|
2020-02-27 10:53:30 +08:00
|
|
|
<FormattedMessage id="app.header.menu.spec" />
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="docs/react">
|
2020-09-14 10:48:08 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/docs/react/introduce', isZhCN, location.query)}>
|
2020-02-27 10:53:30 +08:00
|
|
|
<FormattedMessage id="app.header.menu.documentation" />
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="components">
|
2020-09-14 10:48:08 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/components/overview/', isZhCN, location.query)}>
|
2020-02-27 10:53:30 +08:00
|
|
|
<FormattedMessage id="app.header.menu.components" />
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="docs/resources">
|
2020-09-14 10:48:08 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/docs/resources', isZhCN, location.query)}>
|
2020-02-27 10:53:30 +08:00
|
|
|
<FormattedMessage id="app.header.menu.resource" />
|
|
|
|
</Link>
|
|
|
|
</Menu.Item>
|
2020-10-30 20:02:43 +08:00
|
|
|
{showTechUIButton && (
|
|
|
|
<Menu.Item key="tech-ui">
|
|
|
|
<a href="https://techui.alipay.com" target="__blank" rel="noopener noreferrer">
|
|
|
|
TechUI
|
|
|
|
</a>
|
|
|
|
</Menu.Item>
|
|
|
|
)}
|
2020-04-27 11:36:04 +08:00
|
|
|
{isZhCN && !isGitee && (
|
2020-04-24 17:17:03 +08:00
|
|
|
<Menu.Item key="mirror">
|
|
|
|
<a href="https://ant-design.gitee.io">国内镜像</a>
|
|
|
|
</Menu.Item>
|
|
|
|
)}
|
2020-02-27 10:53:30 +08:00
|
|
|
{additional}
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
};
|