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';
|
2022-05-07 22:37:50 +08:00
|
|
|
import type { MenuProps } from 'antd';
|
2022-05-07 17:39:37 +08:00
|
|
|
import { MenuOutlined } from '@ant-design/icons';
|
2020-02-27 10:53:30 +08:00
|
|
|
import { Menu } from 'antd';
|
|
|
|
import { getEcosystemGroup } from './More';
|
|
|
|
import * as utils from '../../utils';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { SharedProps } from './interface';
|
2020-02-27 10:53:30 +08:00
|
|
|
|
|
|
|
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) => {
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:37:50 +08:00
|
|
|
let additional: MenuProps['items'];
|
|
|
|
|
|
|
|
const additionalItems: MenuProps['items'] = [
|
|
|
|
{
|
|
|
|
label: (
|
|
|
|
<a
|
|
|
|
href="https://github.com/ant-design/ant-design"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
Github
|
|
|
|
</a>
|
|
|
|
),
|
|
|
|
key: 'github',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <FormattedMessage id="app.header.lang" />,
|
|
|
|
onClick: onLangChange,
|
|
|
|
key: 'switch-lang',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: directionText,
|
|
|
|
onClick: onDirectionChange,
|
|
|
|
key: 'switch-direction',
|
|
|
|
},
|
2022-05-09 20:48:12 +08:00
|
|
|
...getEcosystemGroup(),
|
2020-02-27 10:53:30 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
if (isMobile) {
|
|
|
|
additional = additionalItems;
|
|
|
|
} else if (responsive === 'crowded') {
|
2022-05-07 22:37:50 +08:00
|
|
|
additional = [
|
|
|
|
{
|
|
|
|
label: <MenuOutlined />,
|
|
|
|
key: 'additional',
|
|
|
|
children: [...additionalItems],
|
|
|
|
},
|
|
|
|
];
|
2020-02-27 10:53:30 +08:00
|
|
|
}
|
|
|
|
|
2022-05-07 22:37:50 +08:00
|
|
|
const items: MenuProps['items'] = [
|
|
|
|
{
|
|
|
|
label: (
|
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>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
|
|
|
key: 'docs/spec',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
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>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
|
|
|
key: 'docs/react',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
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>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
|
|
|
key: 'components',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
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>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
|
|
|
key: 'docs/resources',
|
|
|
|
},
|
|
|
|
showTechUIButton
|
|
|
|
? {
|
|
|
|
label: (
|
|
|
|
<a href="https://techui.alipay.com" target="__blank" rel="noopener noreferrer">
|
|
|
|
TechUI
|
|
|
|
</a>
|
|
|
|
),
|
|
|
|
key: 'tech-ui',
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
isZhCN &&
|
|
|
|
typeof window !== 'undefined' &&
|
2022-05-11 13:44:19 +08:00
|
|
|
window.location.host !== 'ant-design.antgroup.com' &&
|
|
|
|
window.location.host !== 'ant-design.gitee.io'
|
2022-05-07 22:37:50 +08:00
|
|
|
? {
|
|
|
|
label: '国内镜像',
|
|
|
|
key: 'mirror',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: <a href="https://ant-design.antgroup.com">官方镜像</a>,
|
|
|
|
icon: (
|
|
|
|
<img
|
|
|
|
alt="logo"
|
|
|
|
src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
|
|
|
|
width={16}
|
|
|
|
style={{ verticalAlign: 'text-bottom' }}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
key: 'antgroup',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <a href="https://ant-design.gitee.io">Gitee 镜像</a>,
|
|
|
|
icon: (
|
|
|
|
<img
|
|
|
|
alt="gitee"
|
|
|
|
src="https://gw.alipayobjects.com/zos/bmw-prod/9e91e124-9bab-4113-b500-301412f6b370.svg"
|
|
|
|
width={16}
|
|
|
|
style={{ verticalAlign: 'text-bottom' }}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
key: 'gitee',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
...(additional ?? []),
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Menu
|
|
|
|
className={classNames('menu-site')}
|
|
|
|
mode={menuMode}
|
|
|
|
selectedKeys={[activeMenuItem]}
|
|
|
|
id="nav"
|
|
|
|
disabledOverflow
|
|
|
|
items={items}
|
|
|
|
/>
|
2020-02-27 10:53:30 +08:00
|
|
|
);
|
|
|
|
};
|