Skip to content

Commit 15532f9

Browse files
authored
docs: add docs edit link in meta (ant-design#48034)
* docs: add docs edit link in meta * Apply suggestions from code review Signed-off-by: afc163 <[email protected]> * Apply suggestions from code review Signed-off-by: afc163 <[email protected]> --------- Signed-off-by: afc163 <[email protected]>
1 parent 72a7d86 commit 15532f9

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

.dumi/theme/builtins/ComponentMeta/index.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { GithubOutlined } from '@ant-design/icons';
2+
import { EditOutlined, GithubOutlined } from '@ant-design/icons';
33
import { Descriptions, theme, Tooltip, Typography, type GetProp } from 'antd';
44
import { createStyles, css } from 'antd-style';
55
import kebabCase from 'lodash/kebabCase';
@@ -13,15 +13,21 @@ const locales = {
1313
copy: '复制',
1414
copied: '已复制',
1515
source: '源码',
16+
docs: '文档',
17+
edit: '编辑此页',
1618
},
1719
en: {
1820
import: 'Import',
1921
copy: 'Copy',
2022
copied: 'Copied',
2123
source: 'Source',
24+
docs: 'Docs',
25+
edit: 'Edit this page',
2226
},
2327
};
2428

29+
const branchUrl = 'https://github.com/ant-design/ant-design/edit/master/';
30+
2531
const useStyle = createStyles(({ token }) => ({
2632
code: css`
2733
cursor: pointer;
@@ -32,9 +38,16 @@ const useStyle = createStyles(({ token }) => ({
3238
border-radius: 4px;
3339
padding-inline: ${token.paddingXS}px;
3440
transition: all ${token.motionDurationSlow} !important;
41+
font-family: ${token.codeFamily};
42+
color: ${token.colorTextSecondary} !important;
43+
3544
&:hover {
3645
background: ${token.controlItemBgHover};
3746
}
47+
48+
a&:hover {
49+
text-decoration: underline !important;
50+
}
3851
`,
3952
import: css`
4053
color: ${token.magenta8};
@@ -56,10 +69,11 @@ const useStyle = createStyles(({ token }) => ({
5669
export interface ComponentMetaProps {
5770
component: string;
5871
source: string | true;
72+
filename?: string;
5973
}
6074

6175
const ComponentMeta: React.FC<ComponentMetaProps> = (props) => {
62-
const { component, source } = props;
76+
const { component, source, filename } = props;
6377
const { token } = theme.useToken();
6478
const [locale] = useLocale(locales);
6579

@@ -118,7 +132,7 @@ const ComponentMeta: React.FC<ComponentMetaProps> = (props) => {
118132
colon={false}
119133
column={1}
120134
style={{ marginTop: token.margin }}
121-
labelStyle={{ paddingInlineEnd: token.padding }}
135+
labelStyle={{ paddingInlineEnd: token.padding, width: 54 }}
122136
items={
123137
[
124138
{
@@ -143,7 +157,21 @@ const ComponentMeta: React.FC<ComponentMetaProps> = (props) => {
143157
label: locale.source,
144158
children: (
145159
<Typography.Link className={styles.code} href={filledSource} target="_blank">
146-
<GithubOutlined /> {abbrSource}
160+
<GithubOutlined style={{ marginInlineEnd: 4 }} />
161+
<span>{abbrSource}</span>
162+
</Typography.Link>
163+
),
164+
},
165+
filename && {
166+
label: locale.docs,
167+
children: (
168+
<Typography.Link
169+
className={styles.code}
170+
href={`${branchUrl}${filename}`}
171+
target="_blank"
172+
>
173+
<EditOutlined style={{ marginInlineEnd: 4 }} />
174+
<span>{locale.edit}</span>
147175
</Typography.Link>
148176
),
149177
},

.dumi/theme/slots/Content/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ const Content: React.FC<React.PropsWithChildren> = ({ children }) => {
9797
{/* Import Info */}
9898
{meta.frontmatter.category === 'Components' &&
9999
String(meta.frontmatter.showImport) !== 'false' && (
100-
<ComponentMeta component={meta.frontmatter.title} source />
100+
<ComponentMeta
101+
component={meta.frontmatter.title}
102+
source
103+
filename={meta.frontmatter.filename}
104+
/>
101105
)}
102-
103106
<div style={{ minHeight: 'calc(100vh - 64px)' }}>{children}</div>
104107
<InViewSuspense>
105108
<ColumnCard

0 commit comments

Comments
 (0)