mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-17 15:40:53 +08:00
site: simplify bug reason & adjust padding (#48277)
* site: simplify bug reason * Update .dumi/theme/common/ComponentChangelog/ComponentChangelog.tsx Signed-off-by: kiner-tang <1127031143@qq.com> --------- Signed-off-by: kiner-tang <1127031143@qq.com> Co-authored-by: kiner-tang <1127031143@qq.com>
This commit is contained in:
parent
d62d51a76c
commit
448cb81a7c
@ -1,7 +1,8 @@
|
|||||||
/* eslint-disable global-require */
|
/* eslint-disable global-require */
|
||||||
import React, { useMemo } from 'react';
|
import React from 'react';
|
||||||
import { BugOutlined, HistoryOutlined } from '@ant-design/icons';
|
import { BugOutlined, HistoryOutlined } from '@ant-design/icons';
|
||||||
import { Button, Drawer, Grid, Popover, Timeline, Typography } from 'antd';
|
import { Button, Drawer, Grid, Popover, Timeline, Typography } from 'antd';
|
||||||
|
import type { TimelineItemProps } from 'antd';
|
||||||
import { createStyles } from 'antd-style';
|
import { createStyles } from 'antd-style';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
@ -10,18 +11,16 @@ import useFetch from '../../../hooks/useFetch';
|
|||||||
import useLocale from '../../../hooks/useLocale';
|
import useLocale from '../../../hooks/useLocale';
|
||||||
import Link from '../Link';
|
import Link from '../Link';
|
||||||
|
|
||||||
type MatchDeprecatedResult = {
|
interface MatchDeprecatedResult {
|
||||||
match?: string;
|
match?: string;
|
||||||
reason: string[];
|
reason: string[];
|
||||||
};
|
}
|
||||||
|
|
||||||
function matchDeprecated(v: string): MatchDeprecatedResult {
|
function matchDeprecated(v: string): MatchDeprecatedResult {
|
||||||
const match = Object.keys(deprecatedVersions).find((depreciated) =>
|
const match = Object.keys(deprecatedVersions).find((depreciated) =>
|
||||||
semver.satisfies(v, depreciated),
|
semver.satisfies(v, depreciated),
|
||||||
);
|
);
|
||||||
|
|
||||||
const reason = deprecatedVersions[match as keyof typeof deprecatedVersions] || [];
|
const reason = deprecatedVersions[match as keyof typeof deprecatedVersions] || [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
match,
|
match,
|
||||||
reason: Array.isArray(reason) ? reason : [reason],
|
reason: Array.isArray(reason) ? reason : [reason],
|
||||||
@ -45,16 +44,27 @@ const useStyle = createStyles(({ token, css }) => ({
|
|||||||
bug: css`
|
bug: css`
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #aaa;
|
color: #aaa;
|
||||||
padding-inline-start: ${token.paddingXXS}px;
|
margin-inline-start: ${token.marginXS}px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: inherit;
|
vertical-align: inherit;
|
||||||
|
cursor: pointer;
|
||||||
&:hover {
|
&:hover {
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
bugList: css`
|
bugReasonTitle: css`
|
||||||
|
padding: ${token.paddingXXS}px ${token.paddingXS}px;
|
||||||
|
`,
|
||||||
|
bugReasonList: css`
|
||||||
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
li {
|
li {
|
||||||
padding-block: ${token.paddingXS}px;
|
padding: ${token.paddingXXS}px ${token.paddingXS}px;
|
||||||
|
a {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: ${token.marginXXS}px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
}));
|
}));
|
||||||
@ -80,7 +90,7 @@ const locales = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function ParseChangelog(props: { changelog: string; refs: string[]; styles: any }) {
|
const ParseChangelog: React.FC<{ changelog: string; refs: string[]; styles: any }> = (props) => {
|
||||||
const { changelog = '', refs = [], styles } = props;
|
const { changelog = '', refs = [], styles } = props;
|
||||||
|
|
||||||
const parsedChangelog = React.useMemo(() => {
|
const parsedChangelog = React.useMemo(() => {
|
||||||
@ -115,7 +125,6 @@ function ParseChangelog(props: { changelog: string; refs: string[]; styles: any
|
|||||||
<>
|
<>
|
||||||
{/* Changelog */}
|
{/* Changelog */}
|
||||||
<span>{parsedChangelog}</span>
|
<span>{parsedChangelog}</span>
|
||||||
|
|
||||||
{/* Refs */}
|
{/* Refs */}
|
||||||
{refs?.map((ref) => (
|
{refs?.map((ref) => (
|
||||||
<a className={styles.ref} key={ref} href={ref} target="_blank" rel="noreferrer">
|
<a className={styles.ref} key={ref} href={ref} target="_blank" rel="noreferrer">
|
||||||
@ -124,39 +133,29 @@ function ParseChangelog(props: { changelog: string; refs: string[]; styles: any
|
|||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
type ChangelogInfo = {
|
interface ChangelogInfo {
|
||||||
version: string;
|
version: string;
|
||||||
changelog: string;
|
changelog: string;
|
||||||
refs: string[];
|
refs: string[];
|
||||||
};
|
}
|
||||||
|
|
||||||
function useChangelog(componentPath: string, lang: 'cn' | 'en'): ChangelogInfo[] {
|
const useChangelog = (componentPath: string, lang: 'cn' | 'en'): ChangelogInfo[] => {
|
||||||
const data: any = useFetch(
|
const data = useFetch({
|
||||||
lang === 'cn'
|
key: `component-changelog-${lang}`,
|
||||||
? {
|
request: () => import(`../../../preset/components-changelog-${lang}.json`),
|
||||||
key: 'component-changelog-cn',
|
});
|
||||||
request: () => import('../../../preset/components-changelog-cn.json'),
|
return React.useMemo(() => {
|
||||||
}
|
|
||||||
: {
|
|
||||||
key: 'component-changelog-en',
|
|
||||||
request: () => import('../../../preset/components-changelog-en.json'),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return useMemo(() => {
|
|
||||||
const component = componentPath.replace(/-/g, '');
|
const component = componentPath.replace(/-/g, '');
|
||||||
|
|
||||||
const componentName = Object.keys(data).find(
|
const componentName = Object.keys(data).find(
|
||||||
(name) => name.toLowerCase() === component.toLowerCase(),
|
(name) => name.toLowerCase() === component.toLowerCase(),
|
||||||
);
|
);
|
||||||
|
return data[componentName as keyof typeof data] as ChangelogInfo[];
|
||||||
return data[componentName!];
|
|
||||||
}, [data, componentPath]);
|
}, [data, componentPath]);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function ComponentChangelog(props: ComponentChangelogProps) {
|
const ComponentChangelog: React.FC<ComponentChangelogProps> = (props) => {
|
||||||
const { pathname = '' } = props;
|
const { pathname = '' } = props;
|
||||||
const [locale, lang] = useLocale(locales);
|
const [locale, lang] = useLocale(locales);
|
||||||
const [show, setShow] = React.useState(false);
|
const [show, setShow] = React.useState(false);
|
||||||
@ -167,7 +166,7 @@ export default function ComponentChangelog(props: ComponentChangelogProps) {
|
|||||||
|
|
||||||
const list = useChangelog(componentPath, lang);
|
const list = useChangelog(componentPath, lang);
|
||||||
|
|
||||||
const timelineItems = React.useMemo(() => {
|
const timelineItems = React.useMemo<TimelineItemProps[]>(() => {
|
||||||
const changelogMap: Record<string, ChangelogInfo[]> = {};
|
const changelogMap: Record<string, ChangelogInfo[]> = {};
|
||||||
|
|
||||||
list?.forEach((info) => {
|
list?.forEach((info) => {
|
||||||
@ -178,30 +177,40 @@ export default function ComponentChangelog(props: ComponentChangelogProps) {
|
|||||||
return Object.keys(changelogMap).map((version) => {
|
return Object.keys(changelogMap).map((version) => {
|
||||||
const changelogList = changelogMap[version];
|
const changelogList = changelogMap[version];
|
||||||
const bugVersionInfo = matchDeprecated(version);
|
const bugVersionInfo = matchDeprecated(version);
|
||||||
const bugContent = (
|
|
||||||
<ul className={styles.bugList}>
|
|
||||||
{bugVersionInfo.reason.map((reason, index) => (
|
|
||||||
<li key={index}>
|
|
||||||
<a type="link" target="_blank" rel="noreferrer" href={reason}>
|
|
||||||
<BugOutlined /> {reason}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
children: (
|
children: (
|
||||||
<Typography>
|
<Typography>
|
||||||
<h4>
|
<Typography.Title level={4}>
|
||||||
{version}{' '}
|
{version}
|
||||||
{bugVersionInfo.match && (
|
{bugVersionInfo.match && (
|
||||||
<Popover placement="right" title={locale.bugList} content={bugContent}>
|
<Popover
|
||||||
|
destroyTooltipOnHide
|
||||||
|
placement="right"
|
||||||
|
title={<span className={styles.bugReasonTitle}>{locale.bugList}</span>}
|
||||||
|
content={
|
||||||
|
<ul className={styles.bugReasonList}>
|
||||||
|
{bugVersionInfo.reason.map<React.ReactNode>((reason, index) => (
|
||||||
|
<li key={`reason-${index}`}>
|
||||||
|
<a type="link" target="_blank" rel="noreferrer" href={reason}>
|
||||||
|
<BugOutlined />
|
||||||
|
{reason
|
||||||
|
?.replace(/#.*$/, '')
|
||||||
|
?.replace(
|
||||||
|
/^https:\/\/github\.com\/ant-design\/ant-design\/(issues|pull)\//,
|
||||||
|
'#',
|
||||||
|
)}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
>
|
||||||
<BugOutlined className={styles.bug} />
|
<BugOutlined className={styles.bug} />
|
||||||
</Popover>
|
</Popover>
|
||||||
)}
|
)}
|
||||||
</h4>
|
</Typography.Title>
|
||||||
<ul>
|
<ul>
|
||||||
{changelogList.map((info, index) => (
|
{changelogList.map<React.ReactNode>((info, index) => (
|
||||||
<li key={index} className={styles.li}>
|
<li key={index} className={styles.li}>
|
||||||
<ParseChangelog {...info} styles={styles} />
|
<ParseChangelog {...info} styles={styles} />
|
||||||
</li>
|
</li>
|
||||||
@ -249,4 +258,6 @@ export default function ComponentChangelog(props: ComponentChangelogProps) {
|
|||||||
</Drawer>
|
</Drawer>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default ComponentChangelog;
|
||||||
|
Loading…
Reference in New Issue
Block a user