2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2022-11-30 11:05:41 +08:00
|
|
|
import { FormattedMessage, Link, useFullSidebarData, useLocation } from 'dumi';
|
|
|
|
import type { MenuProps } from 'antd';
|
2020-02-27 10:53:30 +08:00
|
|
|
import { Menu } from 'antd';
|
2022-11-30 11:05:41 +08:00
|
|
|
import { MenuOutlined } from '@ant-design/icons';
|
2023-07-20 19:27:33 +08:00
|
|
|
import { createStyles, css } from 'antd-style';
|
2020-02-27 10:53:30 +08:00
|
|
|
import { getEcosystemGroup } from './More';
|
|
|
|
import * as utils from '../../utils';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { SharedProps } from './interface';
|
2022-11-27 20:25:59 +08:00
|
|
|
import useLocale from '../../../hooks/useLocale';
|
2020-02-27 10:53:30 +08:00
|
|
|
|
2022-11-27 20:25:59 +08:00
|
|
|
// ============================= Theme =============================
|
|
|
|
const locales = {
|
|
|
|
cn: {
|
|
|
|
design: '设计',
|
|
|
|
development: '研发',
|
|
|
|
components: '组件',
|
|
|
|
resources: '资源',
|
|
|
|
blog: '博客',
|
|
|
|
},
|
|
|
|
en: {
|
|
|
|
design: 'Design',
|
|
|
|
development: 'Development',
|
|
|
|
components: 'Components',
|
|
|
|
resources: 'Resources',
|
|
|
|
blog: 'Blog',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================= Style =============================
|
2023-07-20 19:27:33 +08:00
|
|
|
const useStyle = createStyles(({ token }) => {
|
2022-11-09 12:28:04 +08:00
|
|
|
const { antCls, iconCls, fontFamily, headerHeight, menuItemBorder, colorPrimary } = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
nav: css`
|
|
|
|
height: 100%;
|
|
|
|
font-size: 14px;
|
|
|
|
font-family: Avenir, ${fontFamily}, sans-serif;
|
|
|
|
border: 0;
|
|
|
|
|
|
|
|
&${antCls}-menu-horizontal {
|
|
|
|
border-bottom: none;
|
|
|
|
|
|
|
|
& > ${antCls}-menu-item, & > ${antCls}-menu-submenu {
|
2023-03-22 13:53:54 +08:00
|
|
|
min-width: ${40 + 12 * 2}px;
|
2022-11-09 12:28:04 +08:00
|
|
|
height: ${headerHeight}px;
|
|
|
|
padding-right: 12px;
|
|
|
|
padding-left: 12px;
|
|
|
|
line-height: ${headerHeight}px;
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
top: 0;
|
|
|
|
right: 12px;
|
|
|
|
bottom: auto;
|
|
|
|
left: 12px;
|
|
|
|
border-width: ${menuItemBorder}px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
& ${antCls}-menu-submenu-title ${iconCls} {
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
& > ${antCls}-menu-item-selected {
|
|
|
|
a {
|
|
|
|
color: ${colorPrimary};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
& > ${antCls}-menu-item, & > ${antCls}-menu-submenu {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
popoverMenuNav: css`
|
|
|
|
${antCls}-menu-item,
|
|
|
|
${antCls}-menu-submenu {
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
|
|
|
|
${antCls}-menu-item-group-title {
|
|
|
|
padding-left: 24px;
|
|
|
|
}
|
|
|
|
|
|
|
|
${antCls}-menu-item-group-list {
|
|
|
|
padding: 0 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
${antCls}-menu-item,
|
|
|
|
a {
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
};
|
2023-07-20 19:27:33 +08:00
|
|
|
});
|
2020-02-27 10:53:30 +08:00
|
|
|
|
|
|
|
export interface NavigationProps extends SharedProps {
|
|
|
|
isMobile: boolean;
|
2022-11-09 12:28:04 +08:00
|
|
|
isClient: boolean;
|
2020-02-27 10:53:30 +08:00
|
|
|
responsive: null | 'narrow' | 'crowded';
|
|
|
|
directionText: string;
|
|
|
|
onLangChange: () => void;
|
|
|
|
onDirectionChange: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ({
|
|
|
|
isZhCN,
|
2022-11-09 12:28:04 +08:00
|
|
|
isClient,
|
2020-02-27 10:53:30 +08:00
|
|
|
isMobile,
|
|
|
|
responsive,
|
|
|
|
directionText,
|
|
|
|
onLangChange,
|
|
|
|
onDirectionChange,
|
|
|
|
}: NavigationProps) => {
|
2022-11-09 12:28:04 +08:00
|
|
|
const { pathname, search } = useLocation();
|
2022-11-27 20:25:59 +08:00
|
|
|
const [locale] = useLocale(locales);
|
|
|
|
|
|
|
|
const sidebarData = useFullSidebarData();
|
|
|
|
const blogList = sidebarData['/docs/blog']?.[0]?.children || [];
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2023-07-20 19:27:33 +08:00
|
|
|
const { styles } = useStyle();
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2020-02-27 10:53:30 +08:00
|
|
|
const menuMode = isMobile ? 'inline' : 'horizontal';
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
const module = pathname
|
|
|
|
.split('/')
|
2022-11-15 22:55:01 +08:00
|
|
|
.filter((path) => path)
|
2022-11-09 12:28:04 +08:00
|
|
|
.slice(0, -1)
|
|
|
|
.join('/');
|
2020-02-27 10:53:30 +08:00
|
|
|
let activeMenuItem = module || 'home';
|
2022-11-09 12:28:04 +08:00
|
|
|
if (pathname.startsWith('/changelog')) {
|
2020-02-27 10:53:30 +08:00
|
|
|
activeMenuItem = 'docs/react';
|
2022-11-09 12:28:04 +08:00
|
|
|
} else if (pathname.startsWith('/docs/resources')) {
|
2020-02-27 10:53:30 +08:00
|
|
|
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"
|
|
|
|
>
|
2022-12-01 19:10:37 +08:00
|
|
|
GitHub
|
2022-05-07 22:37:50 +08:00
|
|
|
</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: (
|
2022-11-09 12:28:04 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/docs/spec/introduce', isZhCN, search)}>
|
2022-11-27 20:25:59 +08:00
|
|
|
{locale.design}
|
2020-02-27 10:53:30 +08:00
|
|
|
</Link>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
|
|
|
key: 'docs/spec',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
2022-11-09 12:28:04 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/docs/react/introduce', isZhCN, search)}>
|
2022-11-27 20:25:59 +08:00
|
|
|
{locale.development}
|
2020-02-27 10:53:30 +08:00
|
|
|
</Link>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
|
|
|
key: 'docs/react',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: (
|
2022-11-09 12:28:04 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/components/overview/', isZhCN, search)}>
|
2022-11-27 20:25:59 +08:00
|
|
|
{locale.components}
|
2020-02-27 10:53:30 +08:00
|
|
|
</Link>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
|
|
|
key: 'components',
|
|
|
|
},
|
2022-11-27 20:25:59 +08:00
|
|
|
blogList.length
|
|
|
|
? {
|
|
|
|
label: (
|
2022-12-08 16:46:48 +08:00
|
|
|
<Link
|
|
|
|
to={utils.getLocalizedPathname(
|
|
|
|
blogList.sort((a, b) => (a.frontmatter.date > b.frontmatter.date ? -1 : 1))[0].link,
|
|
|
|
isZhCN,
|
|
|
|
search,
|
|
|
|
)}
|
|
|
|
>
|
2022-11-27 20:25:59 +08:00
|
|
|
{locale.blog}
|
|
|
|
</Link>
|
|
|
|
),
|
|
|
|
key: 'docs/blog',
|
|
|
|
}
|
|
|
|
: null,
|
2022-05-07 22:37:50 +08:00
|
|
|
{
|
|
|
|
label: (
|
2022-11-09 12:28:04 +08:00
|
|
|
<Link to={utils.getLocalizedPathname('/docs/resources', isZhCN, search)}>
|
2022-11-27 20:25:59 +08:00
|
|
|
{locale.resources}
|
2020-02-27 10:53:30 +08:00
|
|
|
</Link>
|
2022-05-07 22:37:50 +08:00
|
|
|
),
|
2022-11-15 22:55:01 +08:00
|
|
|
key: 'docs/resources',
|
2022-05-07 22:37:50 +08:00
|
|
|
},
|
|
|
|
isZhCN &&
|
2022-11-09 12:28:04 +08:00
|
|
|
isClient &&
|
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
|
|
|
|
mode={menuMode}
|
|
|
|
selectedKeys={[activeMenuItem]}
|
2023-07-20 19:27:33 +08:00
|
|
|
className={styles.nav}
|
2022-05-07 22:37:50 +08:00
|
|
|
disabledOverflow
|
|
|
|
items={items}
|
2023-01-03 14:06:57 +08:00
|
|
|
style={{ borderRight: 0 }}
|
2022-05-07 22:37:50 +08:00
|
|
|
/>
|
2020-02-27 10:53:30 +08:00
|
|
|
);
|
|
|
|
};
|