mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 19:49:59 +08:00
docs: move change-log link to meta part (#51085)
This commit is contained in:
parent
39509d4e85
commit
0ed8d61ff6
@ -1,12 +1,13 @@
|
||||
import React from 'react';
|
||||
import { EditOutlined, GithubOutlined } from '@ant-design/icons';
|
||||
import { EditOutlined, GithubOutlined, HistoryOutlined } from '@ant-design/icons';
|
||||
import type { GetProp } from 'antd';
|
||||
import { Descriptions, theme, Tooltip, Typography } from 'antd';
|
||||
import { Descriptions, theme, Tooltip, Typography, Space } from 'antd';
|
||||
import { createStyles, css } from 'antd-style';
|
||||
import kebabCase from 'lodash/kebabCase';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
|
||||
import useLocale from '../../../hooks/useLocale';
|
||||
import ComponentChangelog from '../../common/ComponentChangelog';
|
||||
|
||||
const locales = {
|
||||
cn: {
|
||||
@ -16,6 +17,7 @@ const locales = {
|
||||
source: '源码',
|
||||
docs: '文档',
|
||||
edit: '编辑此页',
|
||||
changelog: '更新日志',
|
||||
version: '版本',
|
||||
},
|
||||
en: {
|
||||
@ -25,6 +27,7 @@ const locales = {
|
||||
source: 'Source',
|
||||
docs: 'Docs',
|
||||
edit: 'Edit this page',
|
||||
changelog: 'Changelog',
|
||||
version: 'Version',
|
||||
},
|
||||
};
|
||||
@ -179,14 +182,22 @@ const ComponentMeta: React.FC<ComponentMetaProps> = (props) => {
|
||||
filename && {
|
||||
label: locale.docs,
|
||||
children: (
|
||||
<Typography.Link
|
||||
className={styles.code}
|
||||
href={`${branchUrl}${filename}`}
|
||||
target="_blank"
|
||||
>
|
||||
<EditOutlined style={{ marginInlineEnd: 4 }} />
|
||||
<span>{locale.edit}</span>
|
||||
</Typography.Link>
|
||||
<Space size="middle">
|
||||
<Typography.Link
|
||||
className={styles.code}
|
||||
href={`${branchUrl}${filename}`}
|
||||
target="_blank"
|
||||
>
|
||||
<EditOutlined style={{ marginInlineEnd: 4 }} />
|
||||
<span>{locale.edit}</span>
|
||||
</Typography.Link>
|
||||
<ComponentChangelog>
|
||||
<Typography.Link className={styles.code}>
|
||||
<HistoryOutlined style={{ marginInlineEnd: 4 }} />
|
||||
<span>{locale.changelog}</span>
|
||||
</Typography.Link>
|
||||
</ComponentChangelog>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
isVersionNumber(version) && {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { BugOutlined, HistoryOutlined } from '@ant-design/icons';
|
||||
import { Button, Drawer, Grid, Popover, Timeline, Typography } from 'antd';
|
||||
import React, { cloneElement, isValidElement } from 'react';
|
||||
import { BugOutlined } from '@ant-design/icons';
|
||||
import { Drawer, Grid, Popover, Timeline, Typography } from 'antd';
|
||||
import type { TimelineItemProps } from 'antd';
|
||||
import { createStyles } from 'antd-style';
|
||||
import semver from 'semver';
|
||||
@ -8,6 +8,7 @@ import semver from 'semver';
|
||||
import deprecatedVersions from '../../../../BUG_VERSIONS.json';
|
||||
import useFetch from '../../../hooks/useFetch';
|
||||
import useLocale from '../../../hooks/useLocale';
|
||||
import useLocation from '../../../hooks/useLocation';
|
||||
import Link from '../Link';
|
||||
|
||||
interface MatchDeprecatedResult {
|
||||
@ -76,7 +77,7 @@ const useStyle = createStyles(({ token, css }) => ({
|
||||
}));
|
||||
|
||||
export interface ComponentChangelogProps {
|
||||
pathname: string;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const locales = {
|
||||
@ -199,9 +200,10 @@ const useChangelog = (componentPath: string, lang: 'cn' | 'en'): ChangelogInfo[]
|
||||
};
|
||||
|
||||
const ComponentChangelog: React.FC<ComponentChangelogProps> = (props) => {
|
||||
const { pathname = '' } = props;
|
||||
const { children } = props;
|
||||
const [locale, lang] = useLocale(locales);
|
||||
const [show, setShow] = React.useState(false);
|
||||
const { pathname } = useLocation();
|
||||
|
||||
const { styles } = useStyle();
|
||||
|
||||
@ -263,15 +265,16 @@ const ComponentChangelog: React.FC<ComponentChangelogProps> = (props) => {
|
||||
const screens = Grid.useBreakpoint();
|
||||
const width = screens.md ? '48vw' : '90vw';
|
||||
|
||||
if (!list || !list.length) {
|
||||
if (!pathname.startsWith('/components/') || !list || !list.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button icon={<HistoryOutlined />} onClick={() => setShow(true)}>
|
||||
{locale.changelog}
|
||||
</Button>
|
||||
{isValidElement(children) &&
|
||||
cloneElement(children as React.ReactElement, {
|
||||
onClick: () => setShow(true),
|
||||
})}
|
||||
<Drawer
|
||||
destroyOnClose
|
||||
className={styles.drawerContent}
|
||||
|
@ -18,7 +18,6 @@ const DocAnchor = React.lazy(() => import('./DocAnchor'));
|
||||
const DocMeta = React.lazy(() => import('./DocMeta'));
|
||||
const Footer = React.lazy(() => import('../Footer'));
|
||||
const PrevAndNext = React.lazy(() => import('../../common/PrevAndNext'));
|
||||
const ComponentChangelog = React.lazy(() => import('../../common/ComponentChangelog'));
|
||||
const EditButton = React.lazy(() => import('../../common/EditButton'));
|
||||
|
||||
const Content: React.FC<React.PropsWithChildren> = ({ children }) => {
|
||||
@ -70,11 +69,6 @@ const Content: React.FC<React.PropsWithChildren> = ({ children }) => {
|
||||
)}
|
||||
</Space>
|
||||
</Typography.Title>
|
||||
{pathname.startsWith('/components/') && (
|
||||
<InViewSuspense fallback={null}>
|
||||
<ComponentChangelog pathname={pathname} />
|
||||
</InViewSuspense>
|
||||
)}
|
||||
</Flex>
|
||||
) : null}
|
||||
<InViewSuspense fallback={null}>
|
||||
|
Loading…
Reference in New Issue
Block a user